Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created December 29, 2020 16:05
Show Gist options
  • Save BetterProgramming/f4be71e27bf8b3809412b82686275fb3 to your computer and use it in GitHub Desktop.
Save BetterProgramming/f4be71e27bf8b3809412b82686275fb3 to your computer and use it in GitHub Desktop.
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