I have been charged with fixing a ksh93 script which runs on AIX and LINUX. It currently uses getopt to parse command line options, and relies on syntax like:

case $1 in

-g) FOO =$2

if ($3 == "bar") then
BAR= $4


Unfortunately, if it is called with an option which is supposed to take an argument and the argument is missing, getopt hangs (the usage statement following the getopt line is never reached). This would be a minor nuisance, except that it happens in a situation where the user can't ctrl-C out.

I thought it might be worth using getopts instead, but I can't figure out how to parse the multiple arguments to an option - can I just treat OPTARG as an array?