Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 07 Sep 2004 07:17:51 -0700
From:      James William Pye <flaw@rhid.com>
To:        FreeBSD Standards <freebsd-standards@freebsd.org>
Cc:        Dan Nelson <dnelson@allantgroup.com>
Subject:   /bin/test asdf -ge 0
Message-ID:  <1094566670.80264.78.camel@localhost>

next in thread | raw e-mail | index | archive | help

--=-vnjDFZ++OAcpD3br6Rx3
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

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. =3D\)

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.

--=20
Regards,
        James William Pye

--=-vnjDFZ++OAcpD3br6Rx3
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (FreeBSD)

iQEVAwUAQT3DDqZpiPNPvu8yAQL3Swf/fMBsIY/ZFWyailyDOgLHCI3Xu8kPtAwl
uOwAGjjXp1XxbKQZ2WbX19jUEhjpQd/Vt+8vFw7xRY8OIsvNFiul2otZwSHO5Z5L
2vDNIfaendZXzXEdwDibWNYPuzCmNzUSe0Z9JPtphq3EsbWA1g6E20zGsNsFAibj
Uw/Qdtca3uQbMlSuzbl9wSWZDRXA1n211314pOrHtqm0OjrMnnS5AluLe4Yy57us
GosuHp3waiBjvv9KwB6P4AUm/G7b01UZm8pgJGT/NbCLxmRIXkQBr/lUl/rRP8Gn
3J2SSRkTtC1rVdZbcCE7O+472tIQOr2JTveAn3/UILtGqgcOhUPjFw==
=7Caq
-----END PGP SIGNATURE-----

--=-vnjDFZ++OAcpD3br6Rx3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1094566670.80264.78.camel>