[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: declare in a function makes a variable unable to be found with decla
From: |
Chet Ramey |
Subject: |
Re: declare in a function makes a variable unable to be found with declare -p in some cases |
Date: |
Thu, 19 Feb 2015 14:36:41 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 |
On 2/16/15 3:38 PM, SN wrote:
> Hello all,
>
> I have found a problem with the declare builtin.
>
> Patch Level: 33
> Release Status: release
>
> Description:
> Apparently, there is a problem with how bash interprets some
> variable assignments.
> It only happens in a function (probably related to `declare'
> making variables local).
Yes, that's part of it.
> Repeat-By:
> # OK
> $ x() { declare -a var=(); declare -p var; }; x
> declare -a var='()'
> # not OK
> $ y() { declare -a var='()'; declare -p var; }; y
> bash: declare: var: not found
>
> Note that the format used in y is what `declare -p' displays.
Yes. The issue is that the assignment doesn't make the variable visible,
when it clearly should. I've attached a patch that will fix that.
The next version of bash will do things differently, as noted in a couple
of followups to this message. The proposal that prompted the changes is
part of a long thread from December:
http://lists.gnu.org/archive/html/bug-bash/2014-12/msg00115.html
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/
compound-array-assign-visible.patch
Description: Text Data
Re: declare in a function makes a variable unable to be found with declare -p in some cases,
Chet Ramey <=
Re: declare in a function makes a variable unable to be found with declare -p in some cases, Chet Ramey, 2015/02/19