Last active
October 24, 2016 15:26
-
-
Save lktslionel/fbf49ef83e3e39553f702a6eefd96cce to your computer and use it in GitHub Desktop.
Snippet : bash script startup - getopt
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
unset OPTIND | |
while getopts ":s:d:c:a:hv" opt; do | |
case $opt in | |
h) | |
usage | |
exit 0 | |
;; | |
v) | |
GLOBAL_VERBOSE_ENABLED=$TRUE | |
;; | |
s) | |
service=$OPTARG | |
;; | |
d) | |
domain=$OPTARG | |
;; | |
c) | |
_config_file=${OPTARG} | |
;; | |
a) | |
action=${OPTARG} | |
;; | |
\?) | |
echo "Invalid option: -$OPTARG" >&2 | |
exit 1 | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done && shift $(($OPTIND - 1)) | |
# Other form --- | |
if test $# -eq 0 | |
then | |
usage | |
fi | |
while test $# -gt 0; do | |
case "$1" in | |
-h|--help) | |
usage | |
exit 0 | |
;; | |
-c|--client) | |
shift | |
_USR_EMAIL=$1 | |
shift | |
;; | |
-v|--verbose) | |
_VERBOSE=1 | |
shift | |
;; | |
-f|--from) | |
shift | |
_FROM_DATE=$1 | |
shift | |
;; | |
-t|--to) | |
shift | |
_TO_DATE=$1 | |
shift | |
;; | |
--today) | |
_TODAY_FLAG=1 | |
shift | |
;; | |
*) | |
err "Option [$1] is not supported!" | |
usage | |
exit 1 | |
break | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment