GNU bug report logs -
#15278
test: favor -a as binary op, with three arguments and !
Previous Next
Reported by: Eric Blake <eblake <at> redhat.com>
Date: Thu, 5 Sep 2013 17:43:01 UTC
Severity: normal
Tags: confirmed, fixed
Merged with 33097
Done: Bernhard Voelker <mail <at> bernhard-voelker.de>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15278 in the body.
You can then email your comments to 15278 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-coreutils <at> gnu.org
:
bug#15278
; Package
coreutils
.
(Thu, 05 Sep 2013 17:43:01 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Eric Blake <eblake <at> redhat.com>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Thu, 05 Sep 2013 17:43:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
[moving to the coreutils list, as coreutils has a bug here]
On 09/05/2013 10:33 AM, Eric Blake wrote:
> On 09/04/2013 11:06 PM, kneufeld <at> gmail.com wrote:
>> According to the man page, [ -a ] and [ -e ] should have the same behaviour.
>
> Not a bug. -a behaves like -e only when it is unambiguously parsed as a
> unary operator, because it is bash extension as a unary operator.
>
>>
>> -a file
>> True if file exists.
>> ...
>> -e file
>> True if file exists.
>>
>> $ touch stuff.txt
>> $ [ -a stuff.txt ]; echo $?
>> 0
>> $ [ -e stuff.txt ]; echo $?
>> 0
>> $ [ ! -e stuff.txt ]; echo $?
>> 1
>> $ [ ! -a stuff.txt ]; echo $?
>> 0 # what?
>
> But _this_ is an instance where -a is parsed as a binary operator (ie.
> it was parsed as "\( ! \) -a \( stuff.txt \)", not "! \( -a stuff.txt
> \)". -a as a binary operator is required by POSIX for XSI, therefore it
> takes priority over -a as a unary operator as a bash extension.
>
The POSIX wording states for 3-argument tests
(http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html):
• If $2 is a binary primary, perform the binary test of $1 and $3.
• If $1 is ’!’, negate the two-argument test of $2 and $3.
• If $1 is ’(’ and $3 is ’)’, perform the unary test of $2.
The first two bullets both apply to your situation, but it can be
assumed that the ordering of the bullets is significant. Why? Because
"test \( = \)" is a case of both the first and third bullet applying,
and on that case, both bash and coreutils agree that it returns false
(3-argument string comparison of different strings) rather than true
(parenthesized 1-argument test of non-empty =).
Coreutils therefore should fix its test to favor binary -a over unary
-a, when there are three arguments and the first is !.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[signature.asc (application/pgp-signature, attachment)]
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#15278
; Package
coreutils
.
(Thu, 05 Sep 2013 19:49:02 GMT)
Full text and
rfc822 format available.
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 9/5/13 12:45 PM, Eric Blake wrote:
> The POSIX wording states for 3-argument tests
> (http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html):
>
> ? If $2 is a binary primary, perform the binary test of $1 and $3.
> ? If $1 is ?!?, negate the two-argument test of $2 and $3.
> ? If $1 is ?(? and $3 is ?)?, perform the unary test of $2.
>
> The first two bullets both apply to your situation, but it can be
> assumed that the ordering of the bullets is significant.
Bash assumes that the order of the bullet points in the Posix description
of `test' implies prioritization.
- --
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet <at> case.edu http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iEYEARECAAYFAlIo3HMACgkQu1hp8GTqdKs9ygCfRp7ouDNHqgi0/7wGQLOOBa34
JWIAmwTKHIgeM0pCYAGP56x55dsmSo0L
=xMCV
-----END PGP SIGNATURE-----
Added tag(s) confirmed.
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Fri, 19 Oct 2018 23:01:01 GMT)
Full text and
rfc822 format available.
Changed bug title to 'test: favor -a as binary op, with three arguments and !' from '-a vs -e'
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Fri, 19 Oct 2018 23:01:01 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-coreutils <at> gnu.org
:
bug#15278
; Package
coreutils
.
(Sun, 28 Oct 2018 08:09:01 GMT)
Full text and
rfc822 format available.
Message #15 received at 15278 <at> debbugs.gnu.org (full text, mbox):
tags 15278 fixed
forcemerge 33097 15278
close 15278
stop
(triaging old bugs)
On 2013-09-05 10:45 a.m., Eric Blake wrote:
[...]
> Coreutils therefore should fix its test to favor binary -a over unary
> -a, when there are three arguments and the first is !.
Just last week Bernhard committed
test: remove support for the ambigous -a unary operator
https://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=88c32fa68ee7057744bfb6d41f6e8eb68801306f
So closing this as "fixed".
-assaf
Added tag(s) fixed.
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sun, 28 Oct 2018 08:09:02 GMT)
Full text and
rfc822 format available.
Forcibly Merged 15278 33097.
Request was from
Assaf Gordon <assafgordon <at> gmail.com>
to
control <at> debbugs.gnu.org
.
(Sun, 28 Oct 2018 08:09:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Sun, 25 Nov 2018 12:24:11 GMT)
Full text and
rfc822 format available.
This bug report was last modified 5 years and 165 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.