/bin/test asdf -ge 0

James William Pye flaw at rhid.com
Tue Sep 7 07:17:53 PDT 2004


FreeBSD's test--and likely BSD's in general--use strtol to parse number
strings to catch errors. Other shells and test implementations do not.
zsh, pdksh, and, allegedly, GNU's test being notable implementations
that more than likely use atoi, which just renders 0 for strings that
don't make sense to it.
That is, test asdf -ge 0 succeeds in some shells, and fails in others.

I am curious if anyone knows if this behavior conforms to a
specification. Personally, I find FreeBSD's behavior "correct", so I
find the implementation differences disturbing. If it is conforming to a
specification, I think it would be possible to convince some developers
to change their implementations, which would be a good thing(tm).

I first noticed this when zsh did not give me an error on test asdf -ge
0. I contacted the zsh developers about the apparent behavioral error,
and Dan Nelson responded with examples of other shells that do the same
thing("/bin/sh on Tru64 5.1, AIX 5.2, and Solaris 9 all succeed."). (I
sent in my report after checking only /bin/sh and bash. =\)

In short, does anyone know if this behavior conforms to a specification
or does it fall into the range of "undefined behavior" that Dan figured
it is in? (I'm betting on what Dan figured, but I wanted to check with
standards to see if anyone else could confirm it).

test(1) says it "implements a superset of the IEEE Std 1003.2", which
I'm not sure if that's the same thing as or part of what's accessible at
unix.org.

-- 
Regards,
        James William Pye
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 479 bytes
Desc: This is a digitally signed message part
Url : http://lists.freebsd.org/pipermail/freebsd-standards/attachments/20040907/d7a9f4b7/attachment.bin


More information about the freebsd-standards mailing list