zsh-users
 help / color / mirror / code / Atom feed
From: DervishD <zsh@dervishd.net>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@sunsite.dk>
Subject: Re: Bad math expression due to parameters
Date: Sat, 3 Sep 2005 10:28:35 +0200	[thread overview]
Message-ID: <20050903082835.GA65@DervishD> (raw)
In-Reply-To: <1050903035308.ZM22998@candle.brasslantern.com>

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> 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...


      reply	other threads:[~2005-09-03  8:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-02 23:16 DervishD
2005-09-03  3:53 ` Bart Schaefer
2005-09-03  8:28   ` DervishD [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050903082835.GA65@DervishD \
    --to=zsh@dervishd.net \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).