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

Full log


View this message in rfc822 format

From: Pádraig Brady <P <at> draigBrady.com>
To: Vincent Lefevre <vincent <at> vinc17.net>, 69939 <at> debbugs.gnu.org
Subject: 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




This bug report was last modified 1 year and 84 days ago.

Previous Next


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