Created
December 29, 2020 16:05
-
-
Save BetterProgramming/f4be71e27bf8b3809412b82686275fb3 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
parse_user_options() { | |
local -r args=("${@}") | |
local opts | |
# The following code works perfectly for | |
opts=$(getopt --options a:,f,h --long abc:,help,flag -- "${args[@]}" 2> /dev/null) || { | |
usage | |
die "error: parsing options" "${error_parsing_options}" | |
} | |
eval set -- "${opts}" | |
while true; do | |
case "${1}" in | |
--abc) | |
abc_option_flag=1 | |
readonly abc_arg="${2}" | |
shift | |
shift | |
;; | |
-a) | |
a_option_flag=1 | |
readonly a_arg="${2}" | |
shift | |
shift | |
;; | |
--help|-h) | |
usage | |
exit 0 | |
shift | |
;; | |
--flag|-f) | |
flag_option_flag=1 | |
shift | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
break | |
;; | |
esac | |
done | |
} | |
parse_user_options "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment