Here is my post with a question about getopts. I am running korn shell on Solaris 5.8. I am trying to ensure that certain options require a parameter, which is easy enough. I have found that if multiple options are entered on the command line together, but the parameter for one of the options is missing, getopts will simply take the next option letter as the parameter. Example:
#!/bin/ksh
USAGE=$([-a] [-b file_b] [-c] [-d] [-e file_e] [-f]);
while getopts "ab:cde:f" opt
do
case $opt in
a) minusa=$opt;;
b) minusb=$opt
file_b=$OPTARG;;
c) minusc=$opt;;
d) minusd=$opt;;
e) minuse=$opt
file_e=$OPTARG;;
f) minusf=$opt''
/?) echo Unrecognized parameter
exit 1;;
esac
If I run the example script with any one of the options which require a parameter, or if the option with the required parameter is the last in the list, getopts will tell me that the option requires a parameter.
$example.shl -b or
$example.shl -ab
Both will return an error to standard output stating the option requires a parameter.
But, if I enter the option in the following manner, it will not tell me when the parameter is required, it will take the next option as the parameter:
$example.shl -abc or
$example.shl -a -b -c
How can I force getopts to recognize the difference between an option and a parameter?
Thanks,
Randy