Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14724 > unrolled thread

Strange (wrong?) behaviour of "test ! -a file"

Started byMartin Schulte <gnu@schrader-schulte.de>
First post2018-10-21 11:32 +0200
Last post2018-10-21 11:32 +0200
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug


Contents

  Strange (wrong?) behaviour of "test ! -a file" Martin Schulte <gnu@schrader-schulte.de> - 2018-10-21 11:32 +0200

#14724 — Strange (wrong?) behaviour of "test ! -a file"

FromMartin Schulte <gnu@schrader-schulte.de>
Date2018-10-21 11:32 +0200
SubjectStrange (wrong?) behaviour of "test ! -a file"
Message-ID<mailman.2537.1540114557.1284.bug-bash@gnu.org>
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

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web