bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: builtin test command file existence fails with negation


From: Andreas Schwab
Subject: Re: builtin test command file existence fails with negation
Date: Tue, 21 Jul 2009 17:53:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.96 (gnu/linux)

Lynn Kerby <lfk@kerbit.net> writes:

>       Use of the '-a' option to the builtin test command fails to
>       produce the correct result when used with negation. The specific
>       error the case where the file exists and a "test ! -a file" is
>       executed.  If the script is changed to use '-e' for file
>       existence the result is correct as expected.  If the script is
>       modified to place parenthesis around the '-a file' expression,
>       the result is also correct.

This is not a bug, but consistent with the POSIX rules.  Better avoid
the (nonstandard) -a unary operator and use -e instead.  The problem is
that -a is also a binary operator, and POSIX says that if test is called
with three arguments and the second argument is a binary operator it
should be parsed as such.

See
<http://opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128_05>
for details.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




reply via email to

[Prev in Thread] Current Thread [Next in Thread]