On Wed, Apr 27, 2016 at 08:41:20AM -0400, Grisha Levit wrote: [...] > The above works when the readonly variable has a value that is also a valid > identifier. In my previous example I worked around this using the fact > that ref=<whatever>; > declare -n ref does not check to make sure that $ref is a valid identifier. [...]
It does seem to check, but only when you do: declare -n ref=<whatever> | dualbus@hp ...src/gnu/bash % gdb ./bash --batch -ex 'b sh_invalidid' -ex r --args bash -c 'declare -n r=@' | Breakpoint 1 at 0x493107: file common.c, line 236. | | Breakpoint 1, sh_invalidid (s=0x7dd26a "@") at common.c:236 | 236 builtin_error (_("`%s': not a valid identifier"), s); | | dualbus@hp ...src/gnu/bash % gdb ./bash --batch -ex 'b sh_invalidid' -ex r --args bash -c 'declare -n r; r=@' | Breakpoint 1 at 0x493107: file common.c, line 236. | [Inferior 1 (process 5609) exited normally] As you can see, in the first case, it hits the sh_invalidid breakpoint, and bash actually complains about the invalid identifier. -- Eduardo Bustamante https://dualbus.me/