Hello. Could we possibly modify or create an additional variant of "typeset -n" which produces "real" references rather than just dynamic references by name? In other words, I'd like to be able to create reference variables that always point to the instance of a variable that was visible at the time the reference was created, similar to the way ksh93's nameref works.
While the current nameref implementation is tremendously valuable in writing functions that manipulate non-local arrays, it does very little else that couldn't already be done with Bash's indirect parameter expansion, or to solve the encapsulation problem. $ bash+ -c 'function f { typeset -n y=$1; typeset x=bar; echo "$y"; }; x=foo; f x' bar $ mksh -c 'function f { typeset -n y=$1; typeset x=bar; echo "$y"; }; x=foo; f x' bar $ ksh -c 'function f { typeset -n y=$1; typeset x=bar; echo "$y"; }; x=foo; f x' foo I can't think of a reason this couldn't coexist with dynamic scope in principle, with some modification. For instance, Bash won't require a check that forces variable names to be passed through the positional parameters as in ksh. This feature would have similarities to "declare -g" in its ability to tunnel around overloaded variable names in outer scopes, except would allow both reading and writing to any scope from any deeper scope (provided the reference itself hasn't been covered up). This would be extremely useful for shell libraries. -- Dan Douglas