Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: behavior of test true -a \( ! -a \)
- X-seq: zsh-workers 52801
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: behavior of test true -a \( ! -a \)
- Date: Sat, 23 Mar 2024 14:48:36 -0700
- Archived-at: <https://zsh.org/workers/52801>
- In-reply-to: <CAH+w=7a+P6d_D3BxiO7hqPji9LbduYcu53ZFOSbg8DkL4QK8og@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20240321100710.GA164665@qaa.vinc17.org> <CAH+w=7a+P6d_D3BxiO7hqPji9LbduYcu53ZFOSbg8DkL4QK8og@mail.gmail.com>
On Thu, Mar 21, 2024 at 10:39 AM Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> I'm guessing the change is from commit 2afa556d8 (workers/31696).
That commit includes this comment:
+ /*
+ * In "test" compatibility mode, "! -a ..." and "! -o ..."
+ * are treated as "[string] [and] ..." and "[string] [or] ...".
+ */
The way this is tested was changed first at commit cb596a55
(workers/35306) and again at commit daa208e9 (workers/49269) to end up
with this:
if (!(n_testargs > 2 && (check_cond(*testargs, "a") ||
check_cond(*testargs, "o"))))
So this means that in the original example:
% test true -a \( ! -a \) ; echo $?
test: argument expected
The closing \) is being treated as the string argument of [ ! -a \) ]
rather than as a match for the opening \(.
Which you can see by:
% test \( ! -a \) \)
% echo $?
0
% test \( ! -a \) \) \)
test: too many arguments
I'd therefore argue that it's actually
% test \( ! -a \)
that is wrong: It should be complaining of a missing close paren,
rather than magically reverting to treating "!" as "not" (and also
"-a" as a plain string). It's entirely dependent on the count of
arguments rather than on treating parens as tokens.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author