1 |
On Sun, 2 Jun 2013 03:09:31 -0400 |
2 |
Mike Frysinger <vapier@g.o> wrote: |
3 |
|
4 |
> there's no way to undo the local thus it affects the rest of the |
5 |
> func. this makes sure the change is actually localized to where it |
6 |
> is needed. -mike |
7 |
|
8 |
In other languages you can freely introduce local scopes { ... }, this |
9 |
isn't possible in Bash since a local corresponds to a function; but |
10 |
it's not really that hard to replicate, now consider this instead: |
11 |
|
12 |
test() |
13 |
{ |
14 |
local test="FUNCTION" |
15 |
echo ${test} |
16 |
|
17 |
x(){ |
18 |
local test="LOCAL SCOPE 1" |
19 |
echo ${test} |
20 |
};x |
21 |
|
22 |
echo ${test} |
23 |
|
24 |
x(){ |
25 |
local test="LOCAL SCOPE 2" |
26 |
echo ${test} |
27 |
};x |
28 |
|
29 |
echo ${test} |
30 |
} |
31 |
|
32 |
test |
33 |
|
34 |
Now 'x' is vague, you could replace 'x' by a name documenting the scope. |
35 |
|
36 |
I consider this to be more clean than using a variable to remember it, |
37 |
especially when multiple local scopes are to be used after each other. |
38 |
|
39 |
-- |
40 |
With kind regards, |
41 |
|
42 |
Tom Wijsman (TomWij) |
43 |
Gentoo Developer |
44 |
|
45 |
E-mail address : TomWij@g.o |
46 |
GPG Public Key : 6D34E57D |
47 |
GPG Fingerprint : C165 AF18 AB4C 400B C3D2 ABF0 95B2 1FCD 6D34 E57D |