Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Bad math expression due to parameters
- X-seq: zsh-users 9377
- From: DervishD <zsh@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Bad math expression due to parameters
- Date: Sat, 3 Sep 2005 10:28:35 +0200
- Cc: Zsh Users <zsh-users@xxxxxxxxxx>
- In-reply-to: <1050903035308.ZM22998@xxxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh Users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- Organization: DervishD
- References: <20050902231650.GB289@DervishD> <1050903035308.ZM22998@xxxxxxxxxxxxxxxxxxxxxxx>
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