[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Conditional expression problem: both "-a file" and "! -a file" retur
From: |
Eric Blake |
Subject: |
Re: Conditional expression problem: both "-a file" and "! -a file" return true |
Date: |
Thu, 12 Jan 2006 06:43:47 -0700 |
User-agent: |
Mozilla Thunderbird 1.0.2 (Windows/20050317) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Eric Blake on 1/7/2006 8:17 AM:
>
> Now, in this case, you have three arguments, and POSIX requires that the
> binary operator "-a" have higher precedence than the "!" negation operator
> on a 2-argument test. And the one-argument test of "!" and of "testFile"
> both return true (since neither is the empty string), so the overall
> expression returns 0.
Correcting myself, POSIX does not require any precedence between the two
forms (it looks like an editorial oversight from the OPERANDS section).
But the RATIONALE (XCU line 35443) states that "The ! operator has higher
precedence than the -a operator, and the -a operator has higher precedence
than the -o operator." Therefore, when -a is defined as a unary operator,
an XSI compliant test is required to return failure for "test ! -a file"
if file exists. Bash got this wrong, so indeed it is a bug.
- --
Life is short - so eat dessert first!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDxl0S84KuGfSFAYARAj6WAJ44nX0B2O5D+LvuiT3NNJ+c3GljugCdGOA5
UCxNICnejGO98ZJFlKDjZqo=
=FNG7
-----END PGP SIGNATURE-----