bug-bash
[Top][All Lists]
Advanced

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

Re: Dynamic variable failure & equiv-const strings compare unequal


From: Chet Ramey
Subject: Re: Dynamic variable failure & equiv-const strings compare unequal
Date: Thu, 22 Oct 2015 09:00:40 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0

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    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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