Skip to content

Instantly share code, notes, and snippets.

@sodonnell
Created October 25, 2019 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sodonnell/969d1ef08126e4b20e502eed344d785f to your computer and use it in GitHub Desktop.
Save sodonnell/969d1ef08126e4b20e502eed344d785f to your computer and use it in GitHub Desktop.
Basic Bash Options/Argument Boilerplate.
#!/usr/bin/env bash
function helper() { echo -e "\nOptions:\n\n\t-a <app>\n\t-v <version>\n"; exit; }
while getopts "a:v:h" opt; do
case $opt in
c) APP=$OPTARG; echo "APP: ${APP}";;
v) VER=$OPTARG; echo "VER: ${VER}";;
h|*) helper;;
esac
done
# force user to pass all opts and args.
if [ "$#" -ne 4 ]; then
helper;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment