Multiple variables with the same name are created at the same scope when doing assignments to subscripts of nameref variables that point to variables that are unset.
$ unset var; declare -n ref=var; ref[0]=foo $ declare -p refdeclare -a ref=([0]="foo") I think the more reasonable thing would be to create a new array variable $var. But the even weirder thing is that the original $ref is still there! $ unset ref; declare -p refdeclare -n ref="var" Even more values can be piled up with functions: $ ref=global $ f() { declare -n ref=var; ref[0]=foo1; }; f $ f() { declare -n ref=var; ref[0]=foo2; }; f $ declare -p refdeclare -a ref=([0]="foo2") $ unset ref; declare -p refdeclare -a ref=([0]="foo1") $ unset ref; declare -p refdeclare -- ref="global"