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


Groups > gnu.bash.bug > #14724

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

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Martin Schulte <gnu@schrader-schulte.de>
Newsgroups gnu.bash.bug
Subject Strange (wrong?) behaviour of "test ! -a file"
Date Sun, 21 Oct 2018 11:32:11 +0200
Lines 50
Approved bug-bash@gnu.org
Message-ID <mailman.2537.1540114557.1284.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-Trace usenet.stanford.edu 1540114558 12576 208.118.235.17 (21 Oct 2018 09:35:58 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Mailer Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From 91.184.37.130
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14724

Show key headers only | View raw


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

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web