Skip to content

Instantly share code, notes, and snippets.

@oscarkramer
Last active March 20, 2020 14:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarkramer/d497c54d33c75646e408562938d65bbf to your computer and use it in GitHub Desktop.
Save oscarkramer/d497c54d33c75646e408562938d65bbf to your computer and use it in GitHub Desktop.
#!/bin/bash
usage() {
echo;
echo "Description here."
echo
echo "Usage: $0 [options] <arg1> "
echo
echo " <arg1> Arg1 blah blah"
echo
echo "Options:"
echo
echo " --alpha <target> Alpha blah blah."
echo " -h, --help Prints usage. "
echo " -z, --zeta Zeta blah blah."
echo
exit 1;
}
alphaTarget=""
arg1=""
zeta=false
# Parse command line
POSITIONAL=()
while [ $# -gt 0 ]; do
case $1 in
--alpha) alphaTarget=$2 ; shift ;;
-h|--help) usage ;;
-z|--zeta) zeta=true ;;
--) break ;;
-*|--*) echo "$0: ERROR - unrecognized option $1" 1>&2; usage ;;
*) POSITIONAL+=("$1") ;;
esac
shift
done
set -- "${POSITIONAL[@]}"
if [[ $# -ne 1 ]]; then
echo "$0: Missing <arg1>."
usage
fi
arg1=$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment