Path: csiph.com!xmission!news.glorb.com!usenet.stanford.edu!not-for-mail From: Chet Ramey Newsgroups: gnu.bash.bug Subject: Re: Dynamic variable failure & equiv-const strings compare unequal Date: Thu, 22 Oct 2015 09:00:40 -0400 Lines: 54 Approved: bug-bash@gnu.org Message-ID: References: <5628B3E2.70405@tlinx.org> <20151022105816.GA11057@thinkpad> <5628D2F9.9090101@tlinx.org> Reply-To: chet.ramey@case.edu NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1445518861 24617 208.118.235.17 (22 Oct 2015 13:01:01 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash , chet.ramey@case.edu To: Linda Walsh , Oleg Popov Envelope-to: bug-bash@gnu.org User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 In-Reply-To: <5628D2F9.9090101@tlinx.org> X-Junkmail-Status: score=10/60, host=mpv5.cwru.edu X-Junkmail-Whitelist: YES (by domain whitelist at mpv2.tis.cwru.edu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 129.22.105.37 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:11746 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/