Created
February 2, 2012 02:46
-
-
Save jlintz/1721082 to your computer and use it in GitHub Desktop.
parsing command line arguments 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
function usage() { | |
echo ".$0 --argument=foo --argument-two=bar" | |
exit 1 | |
} | |
while [ "$1" != "" ]; do | |
param=${1%=*} | |
value=${1#*=} | |
case $param in | |
--argument) argument=$value | |
;; | |
--argument-two) argument_two=$value | |
;; | |
* ) usage | |
;; | |
esac | |
shift | |
done |
@nmilford the pain of getopts is that single variable options are cryptic. They work great for tools like grep that are used by a million people, but they are absolutely terrible for custom scripts. long args foster clear and descriptive (translation: useful) shell scripts.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Y U NO GETOPT?