bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: short-circuit test ... -a ...


From: Eric Blake
Subject: Re: short-circuit test ... -a ...
Date: Thu, 23 Aug 2007 15:25:52 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070728 Thunderbird/2.0.0.6 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Yakov Lerner on 8/23/2007 11:24 AM:
> 
> Description:
>     x=; test "$x" != "" -a "$x" -le 60
>     prints error:
>     bash: test: : integer expression expected
>     Shall not this *silently* short-circuit to false after
> subexpressio n '"$x" != ""' evaluated
>     to false ?

According to POSIX,
http://www.opengroup.org/onlinepubs/009695399/utilities/test.html, there
is no requirement for -a to be short-circuiting, and the results of
testing more than 4 arguments (you had 7) is unspecified.  So there is no
compelling reason to change the current behavior.

If you want short-circuiting, do this instead:

x=; test "$x" != "" && test "$x" -le 60

- --
Don't work too hard, make some time for fun as well!

Eric Blake             ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGzftf84KuGfSFAYARArlOAJ9knaEbvPmpdfB9oR0JIav/IF/cUwCfUN9Y
mRmMA4z/S9/MQ+vdxgPDYmo=
=wKmK
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]