[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dubious parse in builtin 'test' command
From: |
Eric Blake |
Subject: |
Re: Dubious parse in builtin 'test' command |
Date: |
Sun, 09 Dec 2007 08:32:11 -0700 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Finn Wilcox on 12/8/2007 7:34 AM:
> $ test ! -a /dev/null ; echo $?
> 0
>
> $ /bin/test ! -a /dev/null ; echo $?
> 1
>
> The fourth case is surprising.
> Is -a supposed to be equivalent to -e and why is it needed?
In general, the use of -a is non-portable. POSIX does not mention the
unary -a (although bash provides it as a traditional synonym for -e), and
states that binary -a (logic and of two tests) is optional in general
(although binary -a is required on XSI implementations). For this reason,
the next version of POSIX is marking -a as obsolescent, and the
replacement is to use -e when you mean file existence, and 'test cond1 &&
test cond2' when you mean logical and.
For more details, read Austin Interpretation 107:
http://www.opengroup.org/austin/interps/uploads/40/10043/AI-107.txt
Therefore, I see no bug in bash, even though it differs from coreutils in
its interpretation of 'test ! -a file'.
- --
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
iD8DBQFHXAp784KuGfSFAYARAlAHAKDGyZqiZ9YEuxNIJS+hccvGsUItRQCfXpKF
ll6kuEIgPnYt/cfS/qxupis=
=BwY5
-----END PGP SIGNATURE-----