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

Re: [PATCH 3/3] Documentation for named references

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

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