Created
January 4, 2016 17:34
-
-
Save asears/839ac3ebcc18e7eae51f to your computer and use it in GitHub Desktop.
This file contains hidden or 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/bash | |
showopts () { | |
while getopts ":pq:" optname | |
do | |
case "$optname" in | |
"p") | |
echo "Option $optname is specified" | |
;; | |
"q") | |
echo "Option $optname has value $OPTARG" | |
;; | |
"?") | |
echo "Unknown option $OPTARG" | |
;; | |
":") | |
echo "No argument value for option $OPTARG" | |
;; | |
*) | |
# Should not occur | |
echo "Unknown error while processing options" | |
;; | |
esac | |
done | |
return $OPTIND | |
} | |
showargs () { | |
for p in "$@" | |
do | |
echo "[$p]" | |
done | |
} | |
optinfo=$(showopts "$@") | |
argstart=$? | |
arginfo=$(showargs "${@:$argstart}") | |
echo "Arguments are:" | |
echo "$arginfo" | |
echo "Options are:" | |
echo "$optinfo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment