Skip to content

Instantly share code, notes, and snippets.

@todd-dsm
Created August 19, 2015 20:40
Show Gist options
  • Save todd-dsm/b07ebcb4c97e2a216aef to your computer and use it in GitHub Desktop.
Save todd-dsm/b07ebcb4c97e2a216aef to your computer and use it in GitHub Desktop.
the first argument behaves as expected but the second won't play ball
###-----------------------------------------------------------------------------
### VARIABLES
###-----------------------------------------------------------------------------
# ENV Stuff
# Reset all variables that might be set
file=
# Variables evaluated as shell arithmetic should be initialized to a default or
# validated beforehand:
verbose=0
###-----------------------------------------------------------------------------
### FUNCTIONS
###-----------------------------------------------------------------------------
# FUNCTION:
show_help() {
printf '\n\n%s\n\n' 'Please review this help information and try again.'
}
###-----------------------------------------------------------------------------
### MAIN PROGRAM
###-----------------------------------------------------------------------------
### Parse Arguments
###---
set -x
while :; do
case "$1" in
-h|-\?|--help) # Call "show_help" function; display and exit.
show_help
exit
;;
--group-name)
echo "group-name=${2##*=}"
;;
--group-desc)
echo "group-desc=${4##*=}"
;;
--more-opts)
;;
-v|--verbose)
verbose=$((verbose + 1)) # Each -v argument adds 1 to verbosity.
;;
--) # End of all options.
shift
break
;;
-?*)
printf '\n%s\n' ' WARN: Unknown option (ignored):' "$1" >&2
exit
;;
*) # Default case: If no more options then break out of the loop.
break
esac
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment