Created
January 17, 2015 18:09
-
-
Save yuanqing/52155a2eecbfbe8d8617 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
error() { | |
echo "foo: $1" | |
exit 1 | |
} | |
while [ $# -gt 0 ]; do | |
case "$1" in | |
-v) | |
# option with value | |
if [ -z "$2" ]; then | |
error "option $1 expects a value" | |
fi | |
echo "$1: $2" | |
shift | |
;; | |
-o) | |
# option without value | |
echo "$1: true" | |
;; | |
*) | |
# non-option argument | |
if [[ $1 == -* ]] ; then | |
error "option $1 is invalid" | |
fi | |
echo "$1" | |
;; | |
esac | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment