Re: test incorrectly rejecting valid expression with confusing ! placement

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

 



On 26/08/13 13:19, Thorsten Glaser wrote:
> Harald van Dijk dixit:
> 
>> $ src/dash -c 'test ! ! = !'
>> src/dash: 1: test: =: unexpected operator
>>
>> POSIX requires special behaviour for four-argument tests:
> 
> Right but…
> 
>> There are also some cases where test gives incorrect results when
>> combining ! with -o
> 
> … ‘-o’ is XSI, not POSIX. Do not expect…
>
>> $ src/dash -c 'test ! "" -o !'; echo $?
> 
> … this to work.
>
>> This is covered by the special rule for four arguments, there ! as the
>> first argument evaluates the remaining three-argument test and negates
>> the result. In this special case, ! does not have higher precedence than
>> -o, so the correct exit status is 1, which bash's test gives.
> 
> Only for a shell implementing the XSI ‘-o’ for POSIX test.

That is correct, but dash is such a shell. It attempts to implement -o,
-a, and \( ... \), and does so mostly correctly.

> You shouldn’t use -o anyway as it’s deprecated.

Indeed. I made a note that it has been obsoleted. I wrote:
> There are also some cases where test gives incorrect results when
> combining ! with -o, but ( ), -a and -o have been obsoleted in favour of
> the built-in shell operators ( ), && and ||, so I am not sure if that is
> worth fixing.

Even if it had not been obsoleted, it would be better not to use -a and
-o. In fact, I have trouble imagining why ! has not also been obsoleted
in favour of a simple logical negation of the test (test x != y instead
of test ! x == y, which is only possible for some of the tests), or the
shell's built-in ! (! test x == y instead of test ! x == y, which is
always possible).

Cheers,
Harald
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux