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

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



On 2024-03-21 11:29:39 +0000, Peter Stephenson 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.
> 
> Something simple like: if we find a (, look for a matching ), so blindly
> count intervening ('s and )'s regardless of where they occur, and then
> NULL out the matching ) temporarily until we've parsed the expression
> inside.  If we don't find a matching one treat the ( as as a string.

But be careful with the simple

  test \( = \)

which you may not want to change. This is currently the equality test,
thus returning false (1).

In POSIX, this special case is unspecified, but if the obsolescent
XSI option is supported, this should be the unary test of "=", thus
true (0) instead of false (1).

In practice, all implementations (including zsh) does

$ test \( = \) ; echo $?
1

i.e. seeing it as an equality test. This is rather surprising (but
perhaps more useful), as the goal of the XSI option was to support
parentheses, which implementations do; thus one could expect 0.

However, zsh differs for

  test true -a \( = \) ; echo $?

zsh still sees \( = \) as an equality test (it outputs 1), while
the other implementations output 0, probably because they perform
the unary test on "=" (which returns true, i.e. 0).

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)




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