On Tue, May 26, 2015 at 05:47:30PM +0200, Geir Hauge wrote: [...] > The surprising part is that it keeps the -n flag, but partially loses > the nameref ability: > > $ var=foo; declare -n ref > $ ref=var > $ printf '%s - ' "$ref"; declare -p ref > foo - declare -n ref="var" > $ unset ref > $ ref=var > $ printf '%s - ' "$ref"; declare -p ref > var - declare -n ref="var" > $ ref=baz > baz - declare -n ref="var"
I'm not so sure about that. Let's see it, step by step: # Here, we setup the whole thing, and everything works as expected. 'ref' points to 'var', and the value printed is that of 'var'. dualbus@hp:~$ var=foo; declare -n ref=var; echo "$ref"; declare -p ref foo declare -n ref="var" # Here we 'unset ref', which actually unsets 'var'. Then, we assign 'var' to # 'ref', but since 'ref' is still a nameref, it instead assigns 'var' to 'var'. dualbus@hp:~$ unset ref; ref=var; echo "$ref"; declare -p ref var declare -n ref="var" dualbus@hp:~$ declare -p var declare -- var="var" # Here you assign 'baz' to 'var', through 'ref'. It works as documented. dualbus@hp:~$ ref=baz; echo "$ref"; declare -p ref var baz declare -n ref="var" declare -- var="baz" -- Eduardo Bustamante https://dualbus.me/