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 [email protected] http://cnswww.cns.cwru.edu/~chet/
*** /usr/src/local/bash/bash-4.3-patched/arrayfunc.c 2014-10-01 13:08:48.000000000 -0400
--- arrayfunc.c 2015-02-19 14:33:05.000000000 -0500
***************
*** 405,408 ****
--- 405,411 ----
else
array_insert (a, i, l->word->word);
+
+ VUNSETATTR (var, att_invisible); /* no longer invisible */
+
return var;
}
***************
*** 635,638 ****
--- 638,645 ----
if (nlist)
dispose_words (nlist);
+
+ if (var)
+ VUNSETATTR (var, att_invisible); /* no longer invisible */
+
return (var);
}