Zsh Mailing List Archive
Messages sorted by:
Re: [PATCH (not final)] (take three?) unset "array[$anything]"
- X-seq: zsh-workers 49026
- From: Stephane Chazelas <stephane@xxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH (not final)] (take three?) unset "array[$anything]"
- Date: Sat, 5 Jun 2021 18:05:31 +0100
- Archived-at: <https://zsh.org/workers/49026>
- In-reply-to: <CAH+w=7b4WzOfHs6z9yhGukHtuxe8ac5Yk+sL6i2J2PeCJXCGQg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- Mail-followup-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- References: <CAH+w=7a3hgsag-1WsLxn1yTUja8ooZ+K4eFQhNzHKc32o4a3yg@mail.gmail.com> <CAH+w=7ZMDn-_sfr_5ebDXhNeqC33traLow_hqu6y2=+Rbkij2g@mail.gmail.com> <CAH+w=7ZQ40EeuaNvLdFPzysHzvQe_QKKAeLjY9kbR23OJqK1KQ@mail.gmail.com> <firstname.lastname@example.org> <email@example.com> <CAH+w=7bjefwczt_YaUFK+aGno4G6mJKjnozgj280KBdBH94awA@mail.gmail.com> <firstname.lastname@example.org> <CAH+w=7ZXkFCJN+n4oxosudicJqNOCCts40xwaX4qW=kg+vrWAg@mail.gmail.com> <email@example.com> <CAH+w=7b4WzOfHs6z9yhGukHtuxe8ac5Yk+sL6i2J2PeCJXCGQg@mail.gmail.com>
2021-06-04 17:20:29 -0700, Bart Schaefer:
> > array[1 + 1]=4
> > That is pretty annoying.
> That's just shell whitespace rules, though. If you have nobadpattern
> set, you get
> zsh: command not found: array[1
> And if the parser doesn't eventually find ]= then what? Re-parse the
> whole thing to word-split it?
Note that all other shells that support a=value (ksh, pdksh,
bash) do it.
In effect that makes them non-POSIX as there's nothing in the
spec POSIX that says
a[1 + 1]=2
May not run the a[1 with +] and =2 as arguments.
I did bring that up a few years ago at:
(see also https://austingroupbugs.net/view.php?id=1279)
There is variation in behaviour between shells if the first word
starts with name[ and either a matching ] or matching ] followed
by = is not found, and how that matching is done or what kind of
quoting are supported inside the [...].
But all in all, even if it may not be pretty when you look closely,
that does work fine there as long as you're not trying to fool
In zsh, that would be even less problematic as (at least when
not in sh emulation), zsh complains about unmatched [s or ]s
(except for [ alone)
$ /bin/[ a = a ]
zsh: bad pattern: /bin/[
So we wouldn't be breaking anything if we started to accept:
hash[foo bar; baz]=x
array[1 + 1]=x
We would if we started to accept.
like ksh93/bash do though.
For literal hash[key]=value assignment, I never remember what needs
to be quoted and how. I generally resort to doing
which I know are fine.
Messages sorted by: