Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 3/3] Documentation for named references
- X-seq: zsh-workers 51382
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 3/3] Documentation for named references
- Date: Wed, 8 Feb 2023 13:28:46 -0800
- Archived-at: <https://zsh.org/workers/51382>
- In-reply-to: <CAH+w=7ZBjhMVmLk=Rgf6PSF91nd_5OSoW=o068Rg4r4F39poJA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7acQRScHA6_94O2Mi2_f+CnbQPsjk+4zO6X+9VhiStoyQ@mail.gmail.com> <20230207005647.GA5789@tarpaulin.shahaf.local2> <CAH+w=7YAvAVOiUzj_tyc=Amgs1N0S50FrrBHsuVWiO10Q3cY+A@mail.gmail.com> <20230207105105.GB14216@tarpaulin.shahaf.local2> <CAH+w=7ZBjhMVmLk=Rgf6PSF91nd_5OSoW=o068Rg4r4F39poJA@mail.gmail.com>
On Tue, Feb 7, 2023 at 8:53 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> ${(P)name} is defined to expand $name and then treat the string value
> as a further parameter name. What would it mean to expand a named
> reference without resolving it? Just ignore that it's a named
> reference and treat it as a scalar?
That last is in fact what bash does with ${!name} (when not a nameref,
it's like ${(P)name}. I suppose it would be nice to have a way to
expand the name to which a named reference points, but I'm not sure
overloading (P) is the best way.
There's a slew of other special bash meanings of parameter references
that start with "!":
${!name*} == ${(k)parameters[(I)name*]}
${!name@} == ${(@k)parameters[(I)name*]}
${!name[*]} == ${(k)name} (but indexes of ordinary arrays, too)
${!name[@]} == ${(@k)name} (ditto)
Indexes of ordinary arrays aren't very useful in zsh because arrays
are not sparse, every element is at least empty string, but you can
get the indexes of all non-empty elements with
${(*)name//(#m)?*/${name[(ie)$MATCH]}}
Messages sorted by:
Reverse Date,
Date,
Thread,
Author