nyxnor/scripts

getopts should accept short options combined

Opened this issue · 1 comments

example is grep -qE. -q and -E are two options combined, they can't require argument, or probably just the last one can.
The script should loop all these options instead of erroring out if the options are valid.

This is the only opt strip case that is valid

-*) opt="${1#*-}"; arg="${2}";; ## short option '-s 1'

Opt case should be inside a for loop

scripts/getopts.sh

Lines 87 to 98 in 0f03783

case "${opt}" in
s|s=*|sleep|sleep=*) ## main action, require argument
## option requires argument
get_arg sleep_n
## check if argument is within the range we need
#range_arg sleep_n "1" "2" "3" "4" "5"
range_arg sleep_n "1-5"
;;
q|quiet) quiet=1;; ## helpful messages can be omitted
d|debug) set -x;; ## useful for debugging
h|help|*) usage;; ## help is calling
esac

Lets take options -abc as an example.
Strip that option will transform it into solely abc. And that combination is not an option, but a, b and c are options