|
From: | thioroup8 |
Subject: | Re: sourcing script file from inside a function doesn't work anymore |
Date: | Mon, 12 May 2014 19:15:59 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
Hi all, Chet, I compiled a 4.3.11 from scratch. Then I applied your fix and compiled again.I executed my test program I attached in my bug report and it works like a charm and like bash 4.2.
Now I'm going to try with several scripts I wrote which were affected by this bug...
Thank you all for your time Best regards Jean-Philippe Le 12/05/2014 17:31, Chet Ramey a écrit :
On 5/12/14, 9:33 AM, Geir Hauge wrote:2014-05-12 14:11 GMT+02:00 Greg Wooledge <wooledg@eeg.ccf.org>:On Sat, May 10, 2014 at 12:22:40PM +0200, thioroup8 wrote:Now, I source it from inside a function: I obtain following errormessage:bash: declare: tmp: not found I think this problem raises in the particular case of involving array variables definitions inside sourced bash script file... cat << "EOF" > "${file_to_be_sourced}" declare -a tmp='([0]="1" [1]="2")' EOFThe problem is that you are using "declare" within the file-to-be-sourced. When you source the file inside a function, Bash runs the declare command within the context of the function, where declare has the same meaning as "local". Thus, it makes the variable local to the function.There really is a bug here, a weird one. Using a simplified script, we see that this works as expected:Yep. Thanks for the report. The issue is that the `placeholder' attribute doesn't get unset when the argument is quoted -- it takes a different code path than when it's unquoted. I've attached a patch for people to experiment with. Chet
[Prev in Thread] | Current Thread | [Next in Thread] |