Skip to content

Instantly share code, notes, and snippets.

@andersy005
Last active July 5, 2018 23:21
Show Gist options
  • Save andersy005/2901025c2f460326a9bd7613357a36bc to your computer and use it in GitHub Desktop.
Save andersy005/2901025c2f460326a9bd7613357a36bc to your computer and use it in GitHub Desktop.
#!/bin/bash
usage="$(basename "$0") [-h] [-s n] -- program to calculate the answer to life, the universe and everything
where:
-h show this help text
-s set the seed value (default: 42)"
seed=42
while getopts ':hs:' option; do
case "$option" in
h) echo "$usage"
exit
;;
s) seed=$OPTARG
;;
:) printf "missing argument for -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
echo "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment