From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 833 invoked from network); 3 Sep 2005 08:24:59 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Sep 2005 08:24:59 -0000 Received: (qmail 91102 invoked from network); 3 Sep 2005 08:24:42 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Sep 2005 08:24:41 -0000 Received: (qmail 7818 invoked by alias); 3 Sep 2005 08:24:34 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9377 Received: (qmail 7807 invoked from network); 3 Sep 2005 08:24:34 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Sep 2005 08:24:34 -0000 Received: (qmail 90060 invoked from network); 3 Sep 2005 08:24:33 -0000 Received: from ns9.hostinglmi.net (213.194.149.146) by a.mx.sunsite.dk with SMTP; 3 Sep 2005 08:24:25 -0000 Received: from 212.red-80-35-44.pooles.rima-tde.net ([80.35.44.212]:32769 helo=localhost) by ns9.hostinglmi.net with esmtpa (Exim 4.52) id 1EBTKB-0000ZS-QJ; Sat, 03 Sep 2005 10:24:32 +0200 Date: Sat, 3 Sep 2005 10:28:35 +0200 From: DervishD To: Bart Schaefer Cc: Zsh Users Subject: Re: Bad math expression due to parameters Message-ID: <20050903082835.GA65@DervishD> Mail-Followup-To: Bart Schaefer , Zsh Users References: <20050902231650.GB289@DervishD> <1050903035308.ZM22998@candle.brasslantern.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1050903035308.ZM22998@candle.brasslantern.com> User-Agent: Mutt/1.4.2.1i Organization: DervishD X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns9.hostinglmi.net X-AntiAbuse: Original Domain - sunsite.dk X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - dervishd.net X-Source: X-Source-Args: X-Source-Dir: X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Hi Bart :) * Bart Schaefer 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...