Is the behavior below expected? In the presence of a local $var, the global $var can be modified by assigning a value to a local nameref that points to a global nameref that points to $var. However, the local nameref expands to the local value of $var.
lref --> gref --> var
Example:
var=G
f() {
local var=L
declare -gn gref=var
declare -n lref=gref
echo "Writing 'F' to lref"
lref=F
echo "lref points to \$${!lref} and expands to '$lref'"
}
echo "Global \$var expands to '$var'"
f
echo "Global \$var expands to '$var'"
Global $var expands to 'G'
Writing 'F' to lref
lref points to $var and expands to 'L'
Global $var expands to 'F'