[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Strange (wrong?) behaviour of "test ! -a file"
From: |
Martin Schulte |
Subject: |
Strange (wrong?) behaviour of "test ! -a file" |
Date: |
Sun, 21 Oct 2018 11:32:11 +0200 |
Hello,
"help test" states that "-a file" and "-e file" do them same ("True if
file exists.")
This is not true when negating the result as you can see from the output
below. The bash builtin even behaves different than the test from
coreutils.
It looks as if "! -a file" results in "( ! ) -a ( file )" in bash while
it results in "! ( -a file )" in coreutils' test.
Given all the problems with "-a" as the AND and the fact that POSIX
doesn't have a "-a" filetest I suggest to mark "-a file" as strongly
deprecated in the help page or remove it at all from test rather than
thinking about if this is a bug and how to fix it.
There's a related discussion in the coreutils mailing list:
http://lists.gnu.org/archive/html/bug-coreutils/2018-10/msg00117.html
Regards,
Martin
address@hidden:~/langs/sh$ cat minus-a
#!/bin/bash
set -o nounset
file=/etc/passwd
echo $BASH_VERSION
/usr/bin/[ --version | head -1
for cmd in test /usr/bin/test
do
for op in -a -e
do
printf "%-30s -> " "$cmd ! $op $file" ; $cmd ! $op $file ; echo $?
done
done | cat -n
address@hidden:~/langs/sh$ ./minus-a
4.4.12(1)-release
[ (GNU coreutils) 8.26
1 test ! -a /etc/passwd -> 0
2 test ! -e /etc/passwd -> 1
3 /usr/bin/test ! -a /etc/passwd -> 1
4 /usr/bin/test ! -e /etc/passwd -> 1
- Strange (wrong?) behaviour of "test ! -a file",
Martin Schulte <=