GNU bug report logs - #69939
test utility bug: "test -a -a -a" and "test -o -o -o" fail

Previous Next

Package: coreutils;

Reported by: Vincent Lefevre <vincent <at> vinc17.net>

Date: Fri, 22 Mar 2024 12:11:02 UTC

Severity: normal

To reply to this bug, email your comments to 69939 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-coreutils <at> gnu.org:
bug#69939; Package coreutils. (Fri, 22 Mar 2024 12:11:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Vincent Lefevre <vincent <at> vinc17.net>:
New bug report received and forwarded. Copy sent to bug-coreutils <at> gnu.org. (Fri, 22 Mar 2024 12:11:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Vincent Lefevre <vincent <at> vinc17.net>
To: bug-coreutils <at> gnu.org
Subject: test utility bug: "test -a -a -a" and "test -o -o -o" fail
Date: Fri, 22 Mar 2024 12:20:25 +0100
With GNU Coreutils 9.4, both "test -a -a -a" and "test -o -o -o" fail:

$ export POSIXLY_CORRECT=1
$ /usr/bin/test -a -a -a ; echo $?
/usr/bin/test: ‘-a’: unary operator expected
2
$ /usr/bin/test -o -o -o ; echo $?
/usr/bin/test: ‘-o’: unary operator expected
2

According to POSIX, they should return 0.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
says for 3 arguments:

  If $2 is a binary primary, perform the binary test of $1 and $3.

Here, $2 is -a and -o respectively, which are binary primaries.
And both $1 and $3 are non-null strings.

-- 
Vincent Lefèvre <vincent <at> vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




Information forwarded to bug-coreutils <at> gnu.org:
bug#69939; Package coreutils. (Fri, 22 Mar 2024 17:11:02 GMT) Full text and rfc822 format available.

Message #8 received at 69939 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Vincent Lefevre <vincent <at> vinc17.net>, 69939 <at> debbugs.gnu.org
Subject: Re: bug#69939: test utility bug: "test -a -a -a" and "test -o -o -o"
 fail
Date: Fri, 22 Mar 2024 16:45:19 +0000
On 22/03/2024 11:20, Vincent Lefevre wrote:
> With GNU Coreutils 9.4, both "test -a -a -a" and "test -o -o -o" fail:
> 
> $ export POSIXLY_CORRECT=1
> $ /usr/bin/test -a -a -a ; echo $?
> /usr/bin/test: ‘-a’: unary operator expected
> 2
> $ /usr/bin/test -o -o -o ; echo $?
> /usr/bin/test: ‘-o’: unary operator expected
> 2
> 
> According to POSIX, they should return 0.
> 
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
> says for 3 arguments:
> 
>    If $2 is a binary primary, perform the binary test of $1 and $3.
> 
> Here, $2 is -a and -o respectively, which are binary primaries.
> And both $1 and $3 are non-null strings.

Agreed. Any leading '-' triggers this:

  $ env test -. -a -.
  test: ‘-.’: unary operator expected

Note we already advise (as does POSIX) to avoid '-a' and '-o':
https://debbugs.gnu.org/22909

BTW POSIX advises to use parenthesis to avoid some parsing ambiguities,
and it helps in this case too:

  $ env test \( -a \) -a \( -a \); echo $?
  0

Though I see bash 5.2.26 has issue with it :/

  $ test \( -a \) -a \( -a \)
  bash: test: `)' expected

bash doesn't like the -a in particular, and is ok with other strings:

  $ test \( -. \) -a \( -. \); echo $?
  0

cheers,
Pádraig




Information forwarded to bug-coreutils <at> gnu.org:
bug#69939; Package coreutils. (Fri, 22 Mar 2024 17:41:02 GMT) Full text and rfc822 format available.

Message #11 received at 69939 <at> debbugs.gnu.org (full text, mbox):

From: Andreas Schwab <schwab <at> linux-m68k.org>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: Vincent Lefevre <vincent <at> vinc17.net>, 69939 <at> debbugs.gnu.org
Subject: Re: bug#69939: test utility bug: "test -a -a -a" and "test -o -o
 -o" fail
Date: Fri, 22 Mar 2024 18:24:41 +0100
On Mär 22 2024, Pádraig Brady wrote:

> Though I see bash 5.2.26 has issue with it :/
>
>   $ test \( -a \) -a \( -a \)
>   bash: test: `)' expected
>
> bash doesn't like the -a in particular, and is ok with other strings:

That's because in bash -a is ambiguous:

      -a FILE        True if file exists.

-- 
Andreas Schwab, schwab <at> linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."




This bug report was last modified 40 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.