Created
February 17, 2012 14:53
-
-
Save wraithmonster/1853903 to your computer and use it in GitHub Desktop.
Parse command line options (parameters) in bash.
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
################################################################################ | |
# 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