zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@zanshin.com>
To: zsh-workers@sunsite.dk
Subject: Re: [bug?] test adf -ge 0
Date: Tue, 31 Aug 2004 14:16:09 -0700 (PDT)	[thread overview]
Message-ID: <Pine.LNX.4.61.0408311400290.9105@toltec.zanshin.com> (raw)
In-Reply-To: <20040831203341.GA8463@DervishD>

On Tue, 31 Aug 2004, James William Pye wrote:

> Using 4.2.0, why does this return successful?
> 
> Both sh(freebsd) and bash echo an error message and return 2.
> 
> > flaw@void:~ % echo $ZSH_VERSION
> > 4.2.0
> > flaw@void:~ % test sdf -ge 0
> > flaw@void:~ % echo $?
> > 0

It's because of this:

zsh% sdf=-1
zsh% test sdf -ge 0
zsh% echo $?
1
zsh% sdf=1
zsh% test sdf -gt 0
zsh% echo $?
0

That is, zsh's builtin test is interpreting "sdf" as a variable name and 
using the corresponding value, just as (( sdf > 0 )) would do.  The value 
of an unset variable in math context is 0.

To forestall the inevitable question about what happens when the value of
the variable is not a number:

zsh% sdf=auq
zsh% auq=42
zsh% echo $(( sdf ))
42

If you wonder why _that_ works, consider this:

zsh% sdf='[#13]qua'
zsh% qua='6 * 9'
zsh% echo $(( sdf ))
13#42


  reply	other threads:[~2004-08-31 21:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-31 18:22 James William Pye
2004-08-31 19:11 ` Dan Nelson
2004-08-31 20:33   ` DervishD
2004-08-31 21:16     ` Bart Schaefer [this message]
2004-08-31 23:21   ` James William Pye

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=Pine.LNX.4.61.0408311400290.9105@toltec.zanshin.com \
    --to=schaefer@zanshin.com \
    --cc=zsh-workers@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).