bug-bash
[Top][All Lists]
Advanced

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

Re: -a vs -e


From: Eric Blake
Subject: Re: -a vs -e
Date: Thu, 05 Sep 2013 10:33:52 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130805 Thunderbird/17.0.8

On 09/04/2013 11:06 PM, kneufeld@gmail.com wrote:
> According to the man page, [ -a ] and [ -e ] should have the same behaviour.

Not a bug.  -a behaves like -e only when it is unambiguously parsed as a
unary operator, because it is bash extension as a unary operator.

> 
> -a file
>     True if file exists.
> ...
> -e file
>     True if file exists.
> 
> $ touch stuff.txt
> $ [ -a stuff.txt ]; echo $?
> 0
> $ [ -e stuff.txt ]; echo $?
> 0
> $ [ ! -e stuff.txt ]; echo $?
> 1
> $ [ ! -a stuff.txt ]; echo $?
> 0     # what?

But _this_ is an instance where -a is parsed as a binary operator (ie.
it was parsed as "\( ! \) -a \( stuff.txt \)", not "! \( -a stuff.txt
\)".  -a as a binary operator is required by POSIX for XSI, therefore it
takes priority over -a as a unary operator as a bash extension.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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