On 3/11/24 12:08 AM, Kerin Millar wrote:

Speaking of which, to do both of these things has some interesting effects ...

$ z() { local -g a; unset -v a; a=123; echo "innermost: $a"; }; unset -v a; x; 
declare -p a
innermost: 123
inner: 123
outer: 123
declare -- a

$ z() { local -g a; unset -v a; unset -v a; a=123; echo "innermost: $a"; }; 
unset -v a; x; declare -p a
innermost: 123
inner: 123
outer: 123
declare -- a="123"

These show the normal effects of unset combined with dynamic scoping. This
ability to unset local variables in previous function scopes has been the
subject of, um, spirited discussion.

$ x() { local a; y; local +g a; a=456; echo "outer: $a"; }; unset -v a; x; 
declare -p a
innermost: 123
inner: 123
outer: 456
declare -- a="123"

Let's assume the previous function definitions remain in effect here. In
that case, z continues to unset the local variable definitions in previous
scopes, but the `local +g a' is basically a no-op -- it implies not using
the global scope for a, which is the same as not using the option at all.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to