Skip to content

Instantly share code, notes, and snippets.

@wraithmonster
Created February 17, 2012 14:53
Show Gist options
  • Save wraithmonster/1853903 to your computer and use it in GitHub Desktop.
Save wraithmonster/1853903 to your computer and use it in GitHub Desktop.
Parse command line options (parameters) in bash.
################################################################################
# Command line processing
################################################################################
# Parse the command line arguments.
while [ "$#" -gt "0" ]; do
case "$1" in
# TODO: Create some script options.
# EXAMPLE: Uncomment below to assign a 'destination directory', DST_DIR,
# to the arg given after a '-d' or '--dst' on the command line.
#
# -d|--dst)
# shift 1 # eat the '-d' or '--dst'
# DST_DIR="$1" # assign the next arg as this variable
# shift 1 # eat the arg you just assigned
# ;;
-r|--remove)
shift 1
removePackages
;;
-h|--help)
outputUsage
;;
-*|--*)
errorMessage "Unknown option $1"
;;
*)
errorMessage "Unknown parameter $1"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment