Created
October 25, 2019 04:37
-
-
Save sodonnell/969d1ef08126e4b20e502eed344d785f to your computer and use it in GitHub Desktop.
Basic Bash Options/Argument Boilerplate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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