Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh -n does not detect incorrect associative array declaration
- X-seq: zsh-workers 38210
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: zsh -n does not detect incorrect associative array declaration
- Date: Wed, 23 Mar 2016 09:23:38 +0000
- In-reply-to: <CAH+w=7bkphoEdbFzXbU4_UXNWjr8M1UMUuO0QAiOfh=QR--1Ww@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <56F1C3D7.6020800@redhat.com> <CAH+w=7YDbbw_J2G6BJKqi9=MtymqAQo1Zhv-19FGK0RqFnyScA@mail.gmail.com> <56F1FF5F.6060907@redhat.com> <CAH+w=7bkphoEdbFzXbU4_UXNWjr8M1UMUuO0QAiOfh=QR--1Ww@mail.gmail.com>
On Tue, 22 Mar 2016 23:40:54 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Contrast this with ksh where associative array assignments look like
>
> fn=( [foo_key]=foo_val [bar_key]= )
>
> There the parser doesn't need to know the type of fn because the
> association is explicit in the format of the parenthesized list. If
> we ever get around to implementing that bit of ksh syntax your
> assertion would become valid. (But in that case the assignment
> forcibly changes the type of "fn" to become an associative array so
> the typeset is irrelevant.)
Off the original topic, but actually it doesn't, at least not in bash.
$ a=(1 2 3)
$ echo ${a[2]}
3
$ a=([one]=1 [two]=2)
$ echo ${a[*]}
2
This has been interpreted as a[one]=1 then a[two]=2 with "a" still an
array, so "one" and "two" are treated as 0. This version was quite old
(4.1.7).
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author