Last active
June 29, 2016 15:35
-
-
Save Ham5ter/f4a3b268cbab33abfeca to your computer and use it in GitHub Desktop.
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
usage() { | |
cat 1>&2 <<EOF | |
Usage $(basename $0) [POSITIONAL_ARGUMENT] [OPTIONS] | |
Describe here what the script does. | |
-v|--verbose Make the Script verbose. | |
-h|--help Print this help message. | |
-l X|--logfile X Set the output Logfile to X | |
EOF | |
} | |
parse_arguments(){ | |
PARAMS="" | |
while (( "$#" )); do | |
case "$1" in | |
-v|--verbose) | |
VERBOSE_OUTPUT=true | |
shift 1 | |
;; | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
-l|--logfile) | |
LOG_TO_FILE=true | |
LOGFILE=$2 | |
shift 2 | |
;; | |
--) # end Argument parsing | |
shift | |
break | |
;; | |
-*|--*=) # unsupported Argument | |
echo "Error: Unsupported Argument '$1'" >&2 | |
usage | |
exit 1 | |
;; | |
*) # preserve positional Arguments | |
PARG="$PARAMS$1" | |
shift | |
;; | |
esac | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment