Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bad math expression due to parameters

    Hi Bart :)

 * Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> dixit:
> On Sep 3,  1:16am, DervishD wrote:
> }     [[ $OPTARG -lt 8 ]] && OPTARG=8
> } 
> }     [when] $OPTARG is "--" and that gives a "bad math expression" in
> } the test above.
> } 
> }     How can I solve this? Must I validate $OPTARG before messing with
> } it on a math expression?
> Either that, or cheat by not using math at all.
>     [[ $OPTARG = <-7> ]] && OPTARG=8

    Very GOOD trick, Bart :) As always, I'm not aware of the pattern
comparisons. I use them sometimes, but...
> However, I would think you want to treat "--" as a special case before
> you get as far as doing other stuff with OPTARG.

    It is treated specially in the script, but the problem is that if
the caller passes '--' just after an option which requires an
argument, it is consumed as the argument :( If I have to do special
processing of every option and argument, I better get rid of getopts
and do the processing by hand. I prefer to eat '--' in OPTARG, test
if it is a valid argument for the option and issue a fail.

    Anyway you're right, I should 'search' for '--' just before doing
any processing (just the same I search for '--help' at the very
beginning of the script) and pass 'getopts' only the set of options
before the '--', while consider the others as non options (filenames
in this particular case). As far as I know, the SUS standard require
'getopts' to treat '--' specially as marking the end of options

    Doing the job by hand is something I've been considering, because
that way I will have full control, and the only thing I loose is the
ability of doing "script -xyz" meaning "script -x -y -z" (I can
implement that, but I'm not sure if it is worth the effort).

    Thanks for all your help Bart :)

    Raúl Núñez de Arenas Coronado

Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...

Messages sorted by: Reverse Date, Date, Thread, Author