bug-bash
[Top][All Lists]
Advanced

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

Re: sourcing script file from inside a function doesn't work anymore


From: Chet Ramey
Subject: Re: sourcing script file from inside a function doesn't work anymore
Date: Mon, 12 May 2014 11:31:12 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

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 error
>> message:
>>> 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")'
>>> EOF
>>
>> The 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

-- 
``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/

Attachment: bind-compound-array.patch
Description: Source code patch


reply via email to

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