On Wed, Apr 25, 2012 at 04:46:02PM -0700, Linda Walsh wrote: > I would guess (without looking at the codE), that > when you do a local, it creates another copy of 'var' at the end of an > array. > like var[0][1] > so global is at 0, and local is at 1.
I'm pretty sure bash doesn't use a multidimensional array to do variable scoping. I'd expect some sort of a stack. > As to whether or not it is "correct" by some arbitrarily set standard or > definition of "correct" -- that's a matter for nit-pickers and POSIXies. > :-) Bash uses "dynamic scoping", which is a somewhat controversial choice, and has led to a whole lot of confusion in the past. Most other shells use static scoping. POSIX has nothing to say on the matter; "local" is not defined in POSIX, and POSIX does not even require functions to implement local variables at all (let alone dictate what kind of scoping to use). POSIX on functions: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_09_05 Wikipedia on dynamic scoping: http://en.wikipedia.org/wiki/Scope_%28computer_science%29#Dynamic_scoping