bug-bash
[Top][All Lists]
Advanced

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

Re: extension of file-test primitives?


From: dethrophes
Subject: Re: extension of file-test primitives?
Date: Wed, 23 Aug 2017 16:58:08 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0



Am 23.08.2017 um 16:46 schrieb Greg Wooledge:
On Wed, Aug 23, 2017 at 04:24:55PM +0200, Dethrophes wrote:
Which I always understood as the correct way of doing this in the
first place...

It's not as good as multiple test commands: test -f file && test -x
file.
There's no ambiguity and you get short-circuiting.
Only if you are using the test built-in, otherwise the latter means 2 
spawns/forks however the shell in question calls the test exec.
The comparison was against "test -f file -a -x file" which is deprecated.
The use of "-a" as a logical AND is not mandated by POSIX except in
"obsolescent XSI" mode.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
http://pubs.opengroup.org/onlinepubs/9699919799/help/codes.html#OB%20XSI

So if you're using test ... -a ... then you're almost certainly relying
on test being bash's builtin version.  And since this is bug-bash, we
generally assume you are using bash.

There is also test(1) in GNU coreutils, which currently still supports
the binary -a, but the coreutils 8.26 man page says "NOTE:  Binary  -a
and -o are inherently ambiguous.  Use 'test EXPR1 && test EXPR2' or
'test EXPR1 || test EXPR2' instead."

But, writing a script that relies on test being the one provided by
GNU coreutils (or any other version which implements the obsolescent
XSI deprecated feature set) is also extremely silly.
Ok I wasn't aware of that it is depricated.
Having said that it is pretty widely supported. I make use of this in pdksh, bash, dash, ksh and in a couple of test implementations not just the gnu one.




reply via email to

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