GNU bug report logs -
#69939
test utility bug: "test -a -a -a" and "test -o -o -o" fail
Previous Next
Full log
Message #8 received at 69939 <at> debbugs.gnu.org (full text, mbox):
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.