Yeah, you can trick getopts into doing it with something like this:
Code:
while getopts ':a:b:v-:' opt
do
case "$opt" in
a) of_a=1 ; oarg_a=$OPTARG ;;
b) of_b=1 ; oarg_b=$OPTARG ;;
v) of_v=1 ;;
-) case "$OPTARG" in
long-opt) of_long_opt=1 ;;
esac
;;
\?) echo "Unexpected option: -$OPTARG"
exit 1 ;;
:) echo "Missing operand for option -$OPTARG"
exit 1 ;;
esac
done
.. but it's very fragile and I wouldn't recommend it.
If you want long-options and portability is not a concern then stick with gnu getopt.
If portability is a concern then you'll most likely want to stick with the POSIX rules: short-options only, and no optional option arguments, in which case getopts is a good choice.