bug-bash
[Top][All Lists]
Advanced

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

Re: declare a="$b" if $a previously set as array


From: Stephane Chazelas
Subject: Re: declare a="$b" if $a previously set as array
Date: Tue, 9 Dec 2014 11:22:53 +0000
User-agent: Mutt/1.5.21 (2010-09-15)

2014-12-09 10:59:14 +0000, Stephane Chazelas:
[...]
> $ a=0 ksh -c 'function f { typeset a=1; g; h; echo "f: $a"; }; function g { 
> a=2; }; function h { typeset a=3; };f'
> f: 1
> 
> "f" doesn't have to worry about alien functions changing its
> local variables under its feet.
[...]

(for clarification)

It still has to worry about alien functions declared using the
Bourne syntax though (as those are interpreted in their parent's
scope and don't have a separate scope except for the positional
parameters):

$ ksh -c 'function f { typeset a=1; g; echo $a; }; g() a=2; f'
2

(or sourced scripts or "eval"ed variables...).

-- 
Stephane



reply via email to

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