Re: test incorrectly rejecting valid expression with confusing ! placement

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

 



On 09/03/2013 07:56 PM, Herbert Xu wrote:
> Harald van Dijk <harald@xxxxxxxxxxx> wrote:
>> Hi,
>>
>> Now that Herbert fixed the reported crash in test (in a far simpler
>> manner than I had suggested, which I like), I did some more testing, and
>> came across one case that does not currently work, and did not work in
>> the past, but is perfectly valid:
>>
>> $ src/dash -c 'test ! ! = !'
>> src/dash: 1: test: =: unexpected operator
> 
> Agreed.
>  
>> $ src/dash -c 'test ! -o !'
>> src/dash: 1: test: -o: unexpected operator
> 
> Nope, the rule is quite clear that it only applies to binary
> primaries, not operators.  -o is an operator.

Huh?
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html
states that there are only two operators "!" and "()", and specifically
mentions that -a and -o are binary primaries:

expression1 -a  expression2
    [OB XSI] [Option Start]
    True if both expression1 and expression2 are true; otherwise, false.
The -a binary primary is left associative. It has a higher precedence
than -o. [Option End]
expression1 -o  expression2
    [OB XSI] [Option Start]
    True if either expression1 or expression2 is true; otherwise, false.
The -o binary primary is left associative. [Option End]

"test ! -o !" is a three-argument test, where $2 (-o) is a binary
primary, so it is the binary test of $1 and $3, and the end result is an
exit status of 0.  Bash and ksh get it right, dash fails.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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

  Powered by Linux