Last active
September 30, 2015 14:58
-
-
Save h2onda/1811258 to your computer and use it in GitHub Desktop.
getopts usage sample
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 | |
| usage() { | |
| echo "$(basename $0) [options] args" | |
| } | |
| while getopts 'p:fh' args "$@" | |
| do | |
| case $args in | |
| p) | |
| PARAM=$OPTARG | |
| ;; | |
| f) | |
| FLAG=true | |
| ;; | |
| h|?) | |
| usage | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| shift $(($OPTIND - 1)) | |
| echo "\$PARAM=$PARAM \$FLAG=$FLAG \$*=\"$*\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment