ok, after some thinking, this one seems certain: 1. forbid adding nameref when the value is not a valid identifier: # declare -n reference=/ should be forbidden, as well as later assignments to nameref with strings being illegal identifiers, as we discussed/patched.
what remains (rest of the reports by Grisha and others can be brought to this): 2. creating a reference that "masks" the readonly variable: # bash -c 'declare -r T=a; echo $T; declare -n ref=a T; ref=bbbb; echo $T; declare -p T;' a bbbb declare -nr T="a" a. we can patch to expand always to the readonly variable value: # echo $T would not follow references but first resolve to value of T, as expected by most and introduce another way to dereference at expansion for those who did create the namref on purpose. b. we can forbid # declare -n T when T is a readonly variable c. we can forbid the assignment: # ref=bbbb d. try to detect the "nameref loop" 2.b-d seem illogical to me, and against the decision behind introducing the namerefs. cheers, pg On 28 Apr 2016, at 02:36, Grisha Levit wrote: > > On Wed, Apr 27, 2016 at 6:47 PM, Piotr Grzybowski <narsil...@gmail.com> wrote: > + if (v == 0 && onref || ( onref && !legal_identifier(value))) > > Shouldn't this (and the other patch) check valid_array_reference as well to > support declare -n ref=a[x] ?