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


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

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

Started byChet Ramey <chet.ramey@case.edu>
First post2018-10-21 13:03 -0400
Last post2018-10-21 13:03 -0400
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Strange (wrong?) behaviour of "test ! -a file" Chet Ramey <chet.ramey@case.edu> - 2018-10-21 13:03 -0400

#14725 — Re: Strange (wrong?) behaviour of "test ! -a file"

FromChet Ramey <chet.ramey@case.edu>
Date2018-10-21 13:03 -0400
SubjectRe: Strange (wrong?) behaviour of "test ! -a file"
Message-ID<mailman.2548.1540141403.1284.bug-bash@gnu.org>
On 10/21/18 5:32 AM, Martin Schulte wrote:
> 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.

This is documented behavior consistent with the POSIX standard. It's been
this way for so long, there is even a question in the long-dormant FAQ
about it (E1).

The `test' command's behavior is determined by the number of arguments,
as specified by POSIX:

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128

The help text for test says

"The behavior of test depends on the number of arguments.  Read the
bash manual page for the complete specification."

The man page says:

      3 arguments
             The following conditions are applied in the order listed.
             If  the  second argument is one of the binary conditional
             operators listed above under CONDITIONAL EXPRESSIONS, the
             result of the expression is the result of the binary test
             using the first and third arguments as operands.  The  -a
             and  -o  operators  are  considered binary operators when
             there are three arguments.

This is the order in which the POSIX algorithm specifies the conditions.

> It looks as if "! -a file" results in "( ! ) -a ( file )" in bash while
> it results in "! ( -a file )" in coreutils' test.

Coreutils does the tests in a different order than they appear in the POSIX
standard.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

[toc] | [standalone]


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


csiph-web