Bash local variables aren't as local as you'd like them to be:
function b() {
local bvar
echo "In b: '${avar}' '${bvar}'"
avar=B # modifies a's "local" variable
bvar=B
}
function a() {
local avar bvar
avar=A
bvar=A
echo "In a before: '${avar}' '{$bvar}'"
b
echo "In a after: '{$avar}' '{$bvar}'"
}
a
#---------------------- Prints --------------------------------
In a before: 'A' '{A}'
In b: 'A' ''
In a after: '{B}' '{A}'
No comments:
Post a Comment