bug-bash
[Top][All Lists]
Advanced

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

Re: [BUG] false positive: [ ! -o optname ]


From: Martijn Dekker
Subject: Re: [BUG] false positive: [ ! -o optname ]
Date: Sun, 25 Sep 2016 22:57:10 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

Op 25-09-16 om 22:40 schreef isabella parakiss:
> On 9/25/16, Martijn Dekker <martijn@inlv.org> wrote:
>> The '!' operator in the legacy test/[ builtin does not invert the result
>> of the -o operator. Consequently the command
>>
>>      [ ! -o noclobber ]
>>
>> amounts to a no-op, always returning exit status 0.
[...]
> [ ! -o noclobber ] means
> is '!' a non empty string?  if not, is 'noclobber' a non empty string?

Wow. Yeah, I suppose that's one possible interpretation. I was going for
the POSIX one:

| These primaries can be combined with the following operators:
|
| !  expression
|     True if expression is false. False if expression is true.
Ref:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html#tag_20_128

And indeed your interpretation does not apply to something like
"[ ! -e /tmp ]":

$ [ -e /tmp ]; echo $?
0
$ [ ! -e /tmp ]; echo $?
1

However, the supposed synonym -a acts differently:

$ [ -a /tmp ]; echo $?
0
$ [ ! -a /tmp ]; echo $?
0

Well, one more entry in the long list of arguments to avoid test/[...

Thanks,

- M.



reply via email to

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