zsh-workers
 help / color / mirror / code / Atom feed
* [bug?] test adf -ge 0
@ 2004-08-31 18:22 James William Pye
  2004-08-31 19:11 ` Dan Nelson
  0 siblings, 1 reply; 5+ messages in thread
From: James William Pye @ 2004-08-31 18:22 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 584 bytes --]

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
> flaw@void:~ % /bin/sh
> flaw@void $ test sdf -ge 0
> test: sdf: bad number
> flaw@void $ echo $?
> 2
> flaw@void:~ % bash
> bash-2.05b$ test sdf -ge 0
> bash: test: sdf: integer expression expected
> bash-2.05b$ echo $?
> 2

I know zsh is not bash or sh, but this is a fairly serious inconsistency, IMO.

-- 
Regards,
        James William Pye

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 479 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug?] test adf -ge 0
  2004-08-31 18:22 [bug?] test adf -ge 0 James William Pye
@ 2004-08-31 19:11 ` Dan Nelson
  2004-08-31 20:33   ` DervishD
  2004-08-31 23:21   ` James William Pye
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Nelson @ 2004-08-31 19:11 UTC (permalink / raw)
  To: James William Pye; +Cc: zsh-workers

In the last episode (Aug 31), James William Pye said:
> Using 4.2.0, why does this return successful?

Probably because atoi("sdf") returns 0, so the test succeeds.
 
> Both sh(freebsd) and bash echo an error message and return 2.

/bin/sh on Tru64 5.1, AIX 5.2, and Solaris 9 all succeed.

> I know zsh is not bash or sh, but this is a fairly serious
> inconsistency, IMO.

It's probably in the range of "undefined behaviour".  I can't find any
manpages or standards docs that say that test must verify that numeric
arguments are really numbers.

-- 
	Dan Nelson
	dnelson@allantgroup.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug?] test adf -ge 0
  2004-08-31 19:11 ` Dan Nelson
@ 2004-08-31 20:33   ` DervishD
  2004-08-31 21:16     ` Bart Schaefer
  2004-08-31 23:21   ` James William Pye
  1 sibling, 1 reply; 5+ messages in thread
From: DervishD @ 2004-08-31 20:33 UTC (permalink / raw)
  To: Dan Nelson; +Cc: James William Pye, zsh-workers

    Hi Dan & James :)

 * Dan Nelson <dnelson@allantgroup.com> dixit:
> In the last episode (Aug 31), James William Pye said:
> > Both sh(freebsd) and bash echo an error message and return 2.
> /bin/sh on Tru64 5.1, AIX 5.2, and Solaris 9 all succeed.

    But /bin/test in GNU coreutils fails too...
 
> > I know zsh is not bash or sh, but this is a fairly serious
> > inconsistency, IMO.
> It's probably in the range of "undefined behaviour".  I can't find any
> manpages or standards docs that say that test must verify that numeric
> arguments are really numbers.

    You're true, at least SUSv3 doesn't specify anything. I suppose
that's because atoi() behaviour...

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736
http://www.pleyades.net & http://raul.pleyades.net/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug?] test adf -ge 0
  2004-08-31 20:33   ` DervishD
@ 2004-08-31 21:16     ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2004-08-31 21:16 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [bug?] test adf -ge 0
  2004-08-31 19:11 ` Dan Nelson
  2004-08-31 20:33   ` DervishD
@ 2004-08-31 23:21   ` James William Pye
  1 sibling, 0 replies; 5+ messages in thread
From: James William Pye @ 2004-08-31 23:21 UTC (permalink / raw)
  To: Dan Nelson; +Cc: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 962 bytes --]

On Tue, 2004-08-31 at 12:11, Dan Nelson wrote:
> Probably because atoi("sdf") returns 0, so the test succeeds.
Indeed, without errno being set too, as you are probably aware.

FreeBSD(likely, NetBSD as well) uses strtol, which is how they catch the
error.

> /bin/sh on Tru64 5.1, AIX 5.2, and Solaris 9 all succeed.
Wow, just when I thought I was writing portable scripts! /;

> It's probably in the range of "undefined behaviour".  I can't find any
> manpages or standards docs that say that test must verify that numeric
> arguments are really numbers.
I looked at what OpenGroup.org had, but nothing regarding the subject
seemed to be specified.

http://www.opengroup.org/onlinepubs/009695399/utilities/test.html

This doesn't match up to the version FreeBSD's test is said to comply
to, so I don't know for sure if FreeBSD's test is complying specified
behaviour or just historic on BSDs. =\

-- 
Regards,
        James William Pye

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 479 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-08-31 23:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31 18:22 [bug?] test adf -ge 0 James William Pye
2004-08-31 19:11 ` Dan Nelson
2004-08-31 20:33   ` DervishD
2004-08-31 21:16     ` Bart Schaefer
2004-08-31 23:21   ` James William Pye

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).