Skip to content

Instantly share code, notes, and snippets.

@mrqaidi
Created September 14, 2016 13:29
Show Gist options
  • Save mrqaidi/7511d189caefd5fbce95f0a641bd4f6d to your computer and use it in GitHub Desktop.
Save mrqaidi/7511d189caefd5fbce95f0a641bd4f6d 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