Here's a toy example that shows what I mean:
while getopts "sf:e:" opt; foundOpts="${foundOpts}${opt}" ; done
echo $foundOpts
problem is that getopts
isn't particularly smart when it comes to arguments. for example, ./myscript.sh -ssssf
will output option requires an argument -- f
. That's good.
But if someone does ./myscript.sh -ssfss
by mistake, it parses that like -ss -f ss
, which is NOT desirable behavior!
How can I detect this? Ideally, I'd like to force that f
parameter to be defined separately, and allow -f foo
or -f=foo
, but not -sf=foo
or -sf foo
.
Is this possible without doing something hairy? I imagine I could do something with a RegEx, along the lines of match $@
against something like -[^ef[:space:]]*[ef]{1}[ =](.*)
, but I'm worried about false positives (that regex might not be exactly right)
Thanks!