I am using getopt and want to have an option -l that takes an optional value. I am finding that when matching -l by itself with no argument value provided, I still have to use shift 2 rather than
just one shift. What is going on and how does this happen?
opts=$( getopt -o "$shortopts" -l "$longopts" -n "${0##*/}" -- "$@" )
eval "set -- ${opts}"
while (( $# > 0 )); do
case $1 in
("-l")
case "$2" in
(+([[:digit:]]))
# matches -lNUM, optional argument value
nl="$2"; shift 2 ;;
(*)
# matches -l, no argument value provided
nl=1 ; shift ;;
esac
;;
("--") shift ; break ;;
(*) opt_error=1 ; break ;;
esac
done