gnu-arch-users
[Top][All Lists]
Advanced

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

Re: [Gnu-arch-users] bash scripting conditionals: "-a" vs "-e"


From: Zenaan Harkness
Subject: Re: [Gnu-arch-users] bash scripting conditionals: "-a" vs "-e"
Date: Sat, 13 Nov 2004 08:04:57 +1100

Matthias, can you confirm if this is a doco bug?


On Fri, 2004-11-12 at 21:41, Jan Hudec wrote:
> On Fri, Nov 12, 2004 at 12:24:59 +1100, Zenaan Harkness wrote:
> > Is -a historical - or why is it there?
> 
> It's the "and" operator.
> 
> > I converted a bunch of -f to -a in my build scripts, because I realised
> > I didn't want to distinguish between sylinks and 'regular' files.
> 
> You mean -e, not -a, right? -e is existence test without restriction on
> entry type...

Well that seems to be the functionality, but the docs tell otherwise,
both info and man include the following:

...
       -a file
              True if file exists.
       -b file
              True if file exists and is a block special file.
       -c file
              True if file exists and is a character special file.
       -d file
              True if file exists and is a directory.
       -e file
              True if file exists.
       -f file
              True if file exists and is a regular file.
...

Of course, they both also include documentation about -a being &&. My
suspicion is that -a might be unary-file-test (can't add ! to negate the
condition for example)?? but I haven't tested this... it could just be a
doco bug.

> > Then I discovered that this broke when inside the construction
> > "[ ! -a file ]" since the -a becomes like &&.
> 
> Because -a IS and. [ \! -a $file ] is false by definition (I'd think
> it's an error, but it is just always false).
> 
> > So I went reading again and found out that -e appears the same as -a,
> > and -a is like &&.
> 
> No, -e is NOT the same as -a. -e is what you want. -a is not.

See doco cut and paste above...

> -a is not quite like &&. That is:
> [ expr1 -a expr2 ]
> [ expr1 ] && [ expr2 ]
> are equivalent, except the former is faster (just one test invocation),
> but only the second has shortcut evaluation (expr2 is not evaluated if
> expr1 is false).
> 
> > So why -a at all?
> 
> Because you need an and operator sometimes.
> 
> -------------------------------------------------------------------------------
>                                                Jan 'Bulb' Hudec 
> <address@hidden>




reply via email to

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