Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Oleg Popov Newsgroups: gnu.bash.bug Subject: Re: Dynamic variable failure & equiv-const strings compare unequal Date: Thu, 22 Oct 2015 15:40:09 +0300 Lines: 56 Approved: bug-bash@gnu.org Message-ID: References: <5628B3E2.70405@tlinx.org> <20151022105816.GA11057@thinkpad> <5628D2F9.9090101@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1445518709 24465 208.118.235.17 (22 Oct 2015 12:58:29 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash To: Linda Walsh Envelope-to: bug-bash@gnu.org X-Yandex-ForeignMX: US Content-Disposition: inline In-Reply-To: <5628D2F9.9090101@tlinx.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 87.250.241.131 X-Mailman-Approved-At: Thu, 22 Oct 2015 08:58:28 -0400 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:11745 On Thu, Oct 22, 2015 at 05:13:45AM -0700, 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. > > ip and 'parts' are both initialized in global. > > testor calls (tst0, tst1, tst2 & tst3). > > 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? > > 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? > > ip and parts are declared at the same scope (global), so why > wouldn't the global 'parts' be initialized as well? $(...) is a subshell. Variables cannot be passed back from a subshell, no matter how and where they are declared. > > Bash uses unquoted characters on the right side of == and != as > > wildcard patterns. For example, [ipaddr] in $exp means "any of i, p, > > a, d, r". You should quote the right operand. > --- > Ahh... or if I quote both sides > using 'printf "%q"' first, that should do the same, no? No. Just use double quotes: [[ $var1 == "$var2" ]] > So, ok, I get that one -- but the first looks sketchy, > as ip and parts are both, only defined at the global level, > thus my expectation that just like it used the global value of > 'ip' for tst0 & tsts1 -- it should have stored the split version > of it in the global value of parts... I really don't get why > it would use the global value as a dynamic in 1 case but not > the other...?