On 9/20/07, David Korn <dgk at research.att.com> wrote: > cc: rbtneville at gmail.com > Subject: Re: [ksh93-integration-discuss] Dereferencing an array name reference > -------- > > > > While educating myself about the new ksh features I stumbled over a > > behaviour which I do not understand. The example below tries to > > dereference a name reference but only returns the name of the variable > > but not the array index: > > % ksh93 > > $ typeset -A a > > $ a[x]=5 > > $ nameref l=a[x] > > echo "${!l}"' > > a > > > > I expected a[x] as output. Is this a bug or do name references only > > apply to variables and not their index? > > -- > > robert neville - it consultant > > > I will classify this as a bug and it also uncovers another bug > or at least undocumented behavior.
How do nameref variables work internally? I had the impression that a nameref variable only remembers the name of the variable and places this string in place of the nameref name during execution. > Currently, > ${!x} > should provide the name for variable x following references, so > it should have displayed a[x] in this case. (I will fix this > and also will not allow the [..] to be treated as a character class > even if not quoted. > > Currently ${...@]} or ${!x[*]} expand to the subscripts (or 0 if x is > not subscripted). > > However, the behavior of > ${!x[foo]} > is currently undocumented and currently outputs foo. This will be changed Why do you think that this is undocumented? I'd expect that if x is an element in an array [foo] describes the 2nd dimension, expanding to a[x][foo]. Or am I wrong? -- robert neville - it consultant