Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11746

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

From Chet Ramey <chet.ramey@case.edu>
Newsgroups gnu.bash.bug
Subject Re: Dynamic variable failure & equiv-const strings compare unequal
Date 2015-10-22 09:00 -0400
Message-ID <mailman.788.1445518861.7904.bug-bash@gnu.org> (permalink)
References <5628B3E2.70405@tlinx.org> <20151022105816.GA11057@thinkpad> <5628D2F9.9090101@tlinx.org>

Show all headers | View raw


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/

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: Dynamic variable failure & equiv-const strings compare unequal Chet Ramey <chet.ramey@case.edu> - 2015-10-22 09:00 -0400

csiph-web