getopts_long
getopts_long copied to clipboard
An "upgrade" to BASH built-in getopts, with support for GNU-style long option.
This PR adds a check that prevents an error when nounset is enabled (`set -u`) and `!OPTIND` is unbound, i.e. when there are no more arguments left to process and...
This PR redeclares OPTARG when `getopts_long` encounters a valid long option without a required argument (e.g. `foo --alpha`). I believe this matches the behavior of the builtin `getopts` command for...
Terminate further argument parsing when '--' is encountered.
This PR updates the logic executed when arguments are not explicitly passed to `getopts_long` and instead they are determined from the call stack (using `BASH_ARGV`), which attempts to match the...
I have this code: ```bash while getopts_long ':remoteHost: toDir:' OPTKEY; do case ${OPTKEY} in 'remoteHost') REMOTE_HOST="${OPTARG}" ;; 'toDir') TO_DIR="${OPTARG}" ;; '?') echo "INVALID OPTION -- ${OPTARG}" >&2 exit 1 ;;...
Try ```bash _usage () { echo "usage" 1>&2; exit ${1:-0}; } _die () { printf "\n$1\n" 1>&2; _usage ${2:-1}; } while read args ; do OPTIND=1 while getopts_long ":hvab: alpha...