Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: behavior of test true -a \( ! -a \)



On Sat, Mar 23, 2024, at 6:41 PM, Bart Schaefer wrote:
> On Sat, Mar 23, 2024 at 3:20 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
>>
>> On 2024-03-23 14:48:36 -0700, Bart Schaefer wrote:
>> > I'd therefore argue that it's actually
>> >
>> > % test \( ! -a \)
>> >
>> > that is wrong
>>
>> POSIX specifies what happens with up to 4 arguments.

The next version of POSIX will only specify what happens with four
arguments if the very first one is "!".  The "-a" and "-o" primaries
and the "(" and ")" operators have been removed.

> Ok, but
>
> % test \( ! -a \) \)
>
> has five and
>
> % test \( ! -a \) -a true
>
> has six, and in neither case are the "first four" interpreted as you
> would have the "last four" interpreted in
>
> % test true -a \( ! -a \)
>
>> The idea is to
>> interpret the operators in a way so that the expression is meaningful
>
> The only way to do that is to (in effect) start counting arguments
> again when \( is encountered.  That changes the meaning of everything
> with an open paren and more than four words.  At what point do we
> stop?

The current version of POSIX leaves test(1) behavior with more than
4 arguments unspecified but says that:

	On XSI-conformant systems, combinations of primaries and
	operators shall be evaluated using the precedence and
	associativity rules described previously.  In addition, the
	string comparison binary primaries '=' and "!=" shall have
	a higher precedence than any unary primary.

I suspect that the Austin Group gave up on the whole thing once
they realized its general intractability.

-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author