Hi all,
I am parsing command line options using getopts.
The problem is that mandatory argument options following ":" is taking next option as argument if it is not followed by any argument.
Below is the script:
while getopts :hd:t:s:l
:f: opt
do
case "$opt" in
-h|-\?) usage;;
-d) DEBUG=true;export SCRIPT_LOG_LEVEL=DEBUG ;;
-t) DEVTYPE="$OPTARG" ;;
-s) SIG_IP="$OPTARG"; export SOCKS5_SERVER="$OPTARG:9001" ;;
-l) HOST_LOGIN="$OPTARG";;
-p) PASSWORD="$OPTARG" ;;
-f) cl_cfile_specd=1
export RUNNING_CONFIG_FILE="$OPTARG" ;;
*) logmsg "Unrecognized param usage";;
esac
done
if I run the script as:
$./script.sh -d -t rdsk -s 12.3.4.5 -l guru -p -f /usr/local/sc.conf
the option -p is taking -f as argument.
Please help me how to throw an error and exit the script if mandatory argument is not passed to the script.
Also how to deal with options having -- ie --logfile.
Please help with the above problem