bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

nameref subscript assignment with unset target var


From: Grisha Levit
Subject: nameref subscript assignment with unset target var
Date: Tue, 17 May 2016 16:40:30 -0400

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 ref
declare -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 ref
declare -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 ref
declare -a ref=([0]="foo2")
$ unset ref; declare -p ref
declare -a ref=([0]="foo1")
$ unset ref; declare -p ref
declare -- ref="global"
‚Äč

reply via email to

[Prev in Thread] Current Thread [Next in Thread]