/bin/test asdf -ge 0

Harti Brandt harti at freebsd.org
Tue Sep 7 07:46:30 PDT 2004


On Tue, 7 Sep 2004, James William Pye wrote:

JWP>FreeBSD's test--and likely BSD's in general--use strtol to parse number
JWP>strings to catch errors. Other shells and test implementations do not.
JWP>zsh, pdksh, and, allegedly, GNU's test being notable implementations
JWP>that more than likely use atoi, which just renders 0 for strings that
JWP>don't make sense to it.
JWP>That is, test asdf -ge 0 succeeds in some shells, and fails in others.
JWP>
JWP>I am curious if anyone knows if this behavior conforms to a
JWP>specification. Personally, I find FreeBSD's behavior "correct", so I
JWP>find the implementation differences disturbing. If it is conforming to a
JWP>specification, I think it would be possible to convince some developers
JWP>to change their implementations, which would be a good thing(tm).
JWP>
JWP>I first noticed this when zsh did not give me an error on test asdf -ge
JWP>0. I contacted the zsh developers about the apparent behavioral error,
JWP>and Dan Nelson responded with examples of other shells that do the same
JWP>thing("/bin/sh on Tru64 5.1, AIX 5.2, and Solaris 9 all succeed."). (I
JWP>sent in my report after checking only /bin/sh and bash. =\)
JWP>
JWP>In short, does anyone know if this behavior conforms to a specification
JWP>or does it fall into the range of "undefined behavior" that Dan figured
JWP>it is in? (I'm betting on what Dan figured, but I wanted to check with
JWP>standards to see if anyone else could confirm it).
JWP>
JWP>test(1) says it "implements a superset of the IEEE Std 1003.2", which
JWP>I'm not sure if that's the same thing as or part of what's accessible at
JWP>unix.org.

I just checked the TC1 of Posix and it doesn't say anything in the 
description of test about this. Also the 'utility argument syntax' section 
talks only about range errors of numeric operands in point 6. So the 
behaviour seems to be unspecified. It's not clear whether this is an
oversight or intended.

I would recommend you to send a mail to the Austin Group with this 
question (probably austin-group-l at opengroup.org).

harti


More information about the freebsd-standards mailing list