Skip to content

Instantly share code, notes, and snippets.

@Ham5ter
Last active June 29, 2016 15:35
Show Gist options
  • Save Ham5ter/f4a3b268cbab33abfeca to your computer and use it in GitHub Desktop.
Save Ham5ter/f4a3b268cbab33abfeca to your computer and use it in GitHub Desktop.
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