[Toybox] Would someone please explain what bash is doing here?
Chet Ramey
chet.ramey at case.edu
Thu Apr 2 08:22:38 PDT 2020
On 4/1/20 6:20 PM, Chet Ramey wrote:
> Dynamic variables only have their value functions called when the variable
> is referenced. When the variables are simply fetched (declare -p, and
> similar) or enumerated (building an export array), you get the value
> stored in the variable, which is the result of the last time the value
> function was called.
OK, this isn't right. `declare -p' and setting attributes (export RANDOM)
both end up calling the value function. I was testing something else when
I thought I was testing this.
Bash builds the environment lazily: when it needs to. Building the
environment means walking the variable hash table and building an array
from it. That process just uses the values associated with each variable,
with one exception (LINENO), and doesn't call the value function. That's
why you see the value in the environment "sticking".
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet at case.edu http://tiswww.cwru.edu/~chet/
More information about the Toybox
mailing list