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

Re: [PATCH] Enable further expansion of parameter name by ${!...}

2015-01-27 0:48 GMT-05:00 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>:
> On Jan 26,  3:00pm, Tomoki Sekiyama wrote:
> }
> }                     # ksh       bash     zsh(default)       zsh(KSH)
> } echo $aaa           # bbb       bbb      bbb                bbb
> } echo ${!aaa}        # aaa       ccc      bad substitution   bbb
> OK, but the point is that ideally in that last row the zsh(KSH) case
> would be "aaa".  I guess this is no worse than the difference of
> ${array[1]} with or without ksharrays set.  (If "nameref aaa=bbb",
> then the first column of the last row would be "bbb".)

I agree. So until nameref is introduced, ${!aaa} should always be "aaa" in
ksh emulation mode.

> My question is, why choose the bash behavior for the zsh default and
> not the ksh behavior?  If we make the bash behavior the default, then
> also adding namerefs as a default leaves us deviating from ksh on the
> meaning of ${!aaa} for identifiers that are not namerefs.

I'm not familiar with zsh policy to determine default behaviors, but if
there is future plan (or possibility) to introduce nameref, we certainly
should provide this bash-like indication under an option.
For example:

  $ unsetopt banghist
  $ typeset -A foo
  $ foo[bar]=qux
  $ foo[baz]=piyo
  $ baz=BAZ
  $ echo ${foo[@]}
  qux piyo
  $ echo ${!foo[@]}
  bar baz
  $ setopt bashindirection
  $ echo ${!foo[bar]}
  $ emulate -R ksh
  $ echo ${!foo[bar]}

Without these options, we might only support '!' for ${!foo[@]}
getting arrays of the keys of foo.
How do you think of this?

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