Test -a and -e

View: New views
3 Messages — Rating Filter:   Alert me  

Test -a and -e

by Jan Schampera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello list,

Code:
$ [ ! -e /bin/bash ] && echo "Doesn't exist"; [ -e /bin/bash ] && echo
"Exists"

Output:
Exists


Code:
$ [ ! -a /bin/bash ] && echo "Doesn't exist"; [ -a /bin/bash ] && echo
"Exists"

Output:
Doesn't exist
Exists


It seems there's a difference between -a and -e, though they are (as far
as I can see) documented to do the same thing.

Anybody knows what's going on? May it be confused by the test
functionality to default to "non-empty string" and a AND (-a)?

Jan



Re: Test -a and -e

by Chet Ramey :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Jan Schampera wrote:

> Hello list,
>
> Code:
> $ [ ! -e /bin/bash ] && echo "Doesn't exist"; [ -e /bin/bash ] && echo
> "Exists"
>
> Output:
> Exists
>
>
> Code:
> $ [ ! -a /bin/bash ] && echo "Doesn't exist"; [ -a /bin/bash ] && echo
> "Exists"
>
> Output:
> Doesn't exist
> Exists
>
>
> It seems there's a difference between -a and -e, though they are (as far
> as I can see) documented to do the same thing.

Please read the Bash FAQ, question E1.  The behavior of test depends on
the number of arguments; the rules are in the manual page.

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



Parent Message unknown Re: Test -a and -e

by Jan Schampera :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Chet Ramey schrieb:

>> Code:
>> $ [ ! -a /bin/bash ] && echo "Doesn't exist"; [ -a /bin/bash ] && echo
>> "Exists"
>>
>> Output:
>> Doesn't exist
>> Exists


> Please read the Bash FAQ, question E1.  The behavior of test depends on
> the number of arguments; the rules are in the manual page.
>
> Chet

"The operators -a and -o are considered binary operators for the purpose
of the 3 Arg case."

Forgive my ignorance :)

Jan