I am new to getopts command. I wonder the if there is any built in way to detect that if both options occurred from [ a | b] where only on them is expected.
command [-a | -b]
Correct
command -a
command -b
Incorrect
command -a -b
command -ab
Please clarify my doubt.
birei
September 18, 2011, 10:38am
2
Hi tamil.pamaran,
What about checking them after getopts loop?
if [[ -n "$aflag" ]] && [[ -n "$bflag" ]]; then
echo "Incorrect"
exit 1
fi
Regards,
Birei
birei,
Appreciate your response. just wanted to know if "getopts" provides any utilities t do the same.
Thanks,
Tamil Pamaran
I don't think getopts is that flexible. Lets wait for others response too.
--ahamed
No it doesnt...as birei noted you will have to check after getopts has parsed the command line arguments.
Oh ok then. Thanks for your response friends !!!