On 10/22/15 8:13 AM, Linda Walsh wrote: > > > Oleg Popov wrote: >> On Thu, Oct 22, 2015 at 03:01:06AM -0700, Linda Walsh wrote: >>> [cut] >>> I.e. test output was: >>> Case 2 got/Expected: >>> "222" >>> "1\ 222\ .3\ .4" >>> [cut] >> >> You didn't initialize the array. By the time you do "parts[1]=222" it's >> still empty. And in your previous message you tried to initialize it in a >> subshell. Variables don't retain their values after returning from >> subshells. > ---- > I was testing if dynamic scoping included subshells, I didn't think so, > but that doesn't mean I don't test it. I removed > it though, as it confused the example.
You don't show what you `removed', so I am looking at the original script you posted. > ip and 'parts' are both initialized in global. Yes. parts is assigned the empty array at the global scope. > testor calls (tst0, tst1, tst2 & tst3). In subshells started to run command substitution. Those subshells modify `parts', but the changed value is not reflected in the parent shell. > > tst0 & tst1 both call "assignparts" which uses the global > value of $ip to set the global value of parts. I.e. since > neither "ip" nor 'parts' are declared inside of any of the functions, they > should use the top-level global values, no? You. Run. Your. Tests. In. Subshells. > tst2, using the last global value set in tst1, only tries to > change 1 value in 'parts'... i.e. why would 'ip' reference the > global value of 'ip', but not parts? You modify parts in a subshell. The global value of parts is initialized to and remains an empty array. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/