2017-03-17 09:50:02 +0100, Jean Delvare:
[...]
> > It depends on context and the type of variable involved. Arrays complicate
> > things and namerefs _really_ complicate things. In bash, declaring a
> > simple local scalar, assigning it a value, then unsettling it within
> > the same scope brings the variable back to the same "hidden local"
> > state it is in when declared local but not given a value. However,
> > unsetting the local from a child scope does fully destroy the local,
> > uncovering the variables in parent scopes.
> 
> For the least educated of us, of which I am, can you explain what you
> mean by "child scope"?
[...]

Dan is describing what I can only explain as a bug or at least a
very surprising feature:

$ bash -c 'f() { local a=2; unset a; echo "$a"; }; a=1; f'

$

Above, the unset resulted in $a being unset in that scope. But:

$ bash -c 'u() { unset "$@"; }; f() { local a=2; u a; echo "$a"; }; a=1; f'
1

Because the "unset" was done in a separate function, instead of
having an unset $a, we've got the $a of the outer scope.

I think that's why Dan says it's more flexible. By using that
/bug/, one can get either one or the other behaviour.

-- 
Stephane

Reply via email to