Date: Fri, 10 Sep 2004 12:05:41 -0700 From: James William Pye <flaw@rhid.com> To: FreeBSD Standards <freebsd-standards@freebsd.org> Subject: Re: /bin/test asdf -ge 0 Message-ID: <1094843141.488.69.camel@localhost> In-Reply-To: <1094566670.80264.78.camel@localhost> References: <1094566670.80264.78.camel@localhost>
next in thread | previous in thread | raw e-mail | index | archive | help
--=-8zHU2d9nIA4XC0U6zsxo Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Here is the aardvark defect submission that I made: --------------------------------------------------------------- 7. Please describe the problem in the box below: test asdf -ge 0 $((asdf + 1)) What constitutes a number in both of these cases, test(1) and shell arithmetic expansion, does not appear to be specified. This was brought to my attention when I noticed the differing implementations. Firstly, zsh, which will return 0 on the first command, and the arithmetic expansion will expand to 1. As opposed to FreeBSD's--and likely BSDs in general--/bin/sh, which will cause an error to be echoed to stderr and a non-zero result in both cases. At first I contacted the zsh developers, as I assumed this was specified behaviour after checking /bin/sh's and bash's test implementation. This was not the case, and Dan Nelson on the zsh work list responded with examples of other shells that behaved the same way as zsh. (A couple notable examples being GNU's test and pdksh). He also said that he believed this fell into undefined behaviour, and, therefore, zsh was not incorrect. I then contacted the FreeBSD-standards list to try to confirm that this was undefined behaviour. Those who responded believed that this was undefined, and thought that I should at least bring this question to the austin group mailing list. In case you are interested in the threads that led up to this clarification request, here are their URIs: http://www.zsh.org/mla/workers/2004/msg00937.html http://lists.freebsd.org/pipermail/freebsd-standards/2004-September/000673.= html 8. Please describe the desired action to be taken in the box below: Clarification of what constitutes a number in XCU's test(1) and shell arithmetic expansion, and perhaps other related locations. Specifically, a given number should be considered valid if strtol(str, &end, 0) accepts str as a valid number. This would allow the usage of hexadecimal and octal numbers in test and arithmetic expansion, which is likely a feature that would be welcomed by all. (See http://www.opengroup.org/onlinepubs/000095399/functions/strtol.html) In the case of an invalid number, the utility should throw an error and return non-zero, perhaps a standard error code for an invalid numbers should be allocated, if one is not already. An invalid number in arithmetic expansion should cause an error to be thrown before the command is executed, and result in a non-zero value, and perhaps a different value than the former so that a distinction can be made between where the invalid number error occurred--before or during the execution of a command. An important note to make is the contrast between test(1) and expr(1), where expr defines a valid integer, and test does not. =46rom http://www.opengroup.org/onlinepubs/000095399/utilities/expr.html: integer - An argument consisting only of an (optional) unary minus followed by digits. I also recommend that expr(1) be updated to allow hexadecimal and octal numbers in the format that strtol(str, &end, 0) accepts, so as to be consistent with the newly defined behaviour in test(1) and shell arithmetic expansion. (Props to Garrett Wollman on freebsd-standards for the notice of this contrast!) ------------------------------------------------------------------- I hope I wasn't a bit too ambitious with strtol(str, &end, 0).. =3D\ --=20 Regards, James William Pye --=-8zHU2d9nIA4XC0U6zsxo 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) iQEVAwUAQUH7BaZpiPNPvu8yAQJkkwf7BA2SCU01uAqkvxdCYUEjKkTzksHheOnE /P5BvvyMsQcCychNL9PabRaWClDmvmTDuUteUR8PLPqedYvQoHmYznXMu/PorN92 mpemghJpGJ0Mr8cx0IDJA2sEAW6oNfMpMFsbdRjiPuCTjYmrCXLiOlPual2VFGSR UbWF8EzgjXklCA/BPzPWVoMwWzDLgRe5HxNlFdTUbJvZq/ODsT8qA4PqzrJ+28T0 LY9qa78SpmCxUzC9ArF63DawDhlJyVh/KlkctmB7b54Z8txnLSjidJzHRbRFDEMh 5Q5usz4DjQcN4BxJ1+5K5iFs1f2cUzTtpTDmpt0sooB3YyAvA+YL7w== =Bce6 -----END PGP SIGNATURE----- --=-8zHU2d9nIA4XC0U6zsxo--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1094843141.488.69.camel>