At global scope this works as expected:

$ declare -n ref=var; declare -a ref=(X); declare -p ref var
declare -n ref="var"
declare -a var=([0]="X")

But in a function, we end up with the nameref variable having both the
`a' and `n' attributes and nothing in the target:

$ f() { declare -n ref=var; declare ref=(X); declare -p ref var; }; f
declare -an ref=([0]="X")
-bash: declare: var: not found

And a slight modification ends up modifying a global variable instead:

$  f() { declare -n ref=var; declare -a ref; ref=(X); declare -p ref
var; }; f; declare -p ref var
declare -an ref=()
-bash: declare: var: not found
declare -a ref=([0]="X")
-bash: declare: var: not found

Reply via email to