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

Re: [PATCH 1/3]: Add named references



Bart Schaefer wrote:
> On Sun, Feb 12, 2023 at 1:02 AM Oliver Kiddle <opk@xxxxxxx> wrote:
> >
> >   % typeset -n ref=arr[1]whatever
> >   % echo $ref
> >   onewhatever
>
> Aha.  OK, that's pretty easy to fix.

That still leaves the oddities with a second subscript:

  typeset -n ref='arr[2][1]'
  arr=( one two three )
  echo $ref
  echo ${ref}
  ref=Z
  typeset -p arr

Only case where the second subscript works is when ref is in braces.

> What about adding ${(K)array) to return array[1] array[2] ... ?
>
> for ref in ${(K)hash}; do ...

That'd work. There's been a few times when I've wished (k) and (kv)
would work for normal arrays. the former is just {1..$#arr} but would
work in nested expansions.

Oliver




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