bug-bash
[Top][All Lists]
Advanced

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

Global variable modification by nameref chain


From: Grisha Levit
Subject: Global variable modification by nameref chain
Date: Wed, 27 Apr 2016 09:05:59 -0400

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'

reply via email to

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