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

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



On Mon, Mar 25, 2024 at 9:38 AM Peter Stephenson
<p.w.stephenson@xxxxxxxxxxxx> wrote:
>
> > I suppose as long as we only look for ")" when we know there's one to
> > match we can probably get away with it without being too clever.  If
> > there's a ")" that logically needs to be treated as a string following a
> > "(" we're stuck but I think that's fair game.

So in other words you're intentionally breaking this:

% test \( ! -a \) \)
test: too many arguments

In the name of "fixing" this:

% test \) -a \( ! -a \)

If we're arguing here based on spec, POSIX says the below should
return 1 because $2 is a "binary primary" which takes precedence over
parens, but it's broken with or without this patch:

% test \( -a \(
test: parse error

To be fair, /bin/test on MacOS and /usr/bin/test on Ubuntu both choke
(or not) in exactly those same cases.

> Feel free to argue that the current behaviour of simply parsing
> parentheses in order and blindly trusting the result is actually a
> better bet

That's not how I'd describe the current behavior, but I'm arguing that
it's no worse and anything with more than 4 arguments is unspecified
anyway.




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