7
Bug-Reported-by: Bill Gradwohl <bill@ycc.com>
8
Bug-Reference-ID: <CAFyvKis-UfuOWr5THBRKh=vYHDoKEEgdW8hN1RviTuYQ00Lu5A@mail.gmail.com>
9
Bug-Reference-URL: http://lists.gnu.org/archive/html/help-bash/2012-03/msg00078.html
13
When used in a shell function, `declare -g -a array=(compound assignment)'
14
creates a local variable instead of a global one.
16
Patch (apply with `patch -p0'):
18
Index: b/bash/command.h
19
===================================================================
23
#define W_HASCTLESC 0x200000 /* word contains literal CTLESC characters */
24
#define W_ASSIGNASSOC 0x400000 /* word looks like associative array assignment */
25
#define W_ARRAYIND 0x800000 /* word is an array index being expanded */
26
+#define W_ASSNGLOBAL 0x1000000 /* word is a global assignment to declare (declare/typeset -g) */
28
/* Possible values for subshell_environment */
29
#define SUBSHELL_ASYNC 0x01 /* subshell caused by `command &' */
30
Index: b/bash/execute_cmd.c
31
===================================================================
32
--- a/bash/execute_cmd.c
33
+++ b/bash/execute_cmd.c
34
@@ -3580,13 +3580,13 @@
48
for (w = words; w; w = w->next)
49
if (w->word->flags & W_ASSIGNMENT)
50
@@ -3603,12 +3603,17 @@
51
#if defined (ARRAY_VARS)
53
w->word->flags |= W_ASSIGNASSOC;
55
+ w->word->flags |= W_ASSNGLOBAL;
58
#if defined (ARRAY_VARS)
59
/* Note that we saw an associative array option to a builtin that takes
60
assignment statements. This is a bit of a kludge. */
61
- else if (w->word->word[0] == '-' && strchr (w->word->word, 'A'))
62
+ else if (w->word->word[0] == '-' && (strchr (w->word->word+1, 'A') || strchr (w->word->word+1, 'g')))
64
+ else if (w->word->word[0] == '-' && strchr (w->word->word+1, 'g'))
69
@@ -3618,10 +3623,11 @@
70
else if (b && (b->flags & ASSIGNMENT_BUILTIN))
71
words->word->flags |= W_ASSNBLTIN;
73
- if (words->word->flags & W_ASSNBLTIN)
74
+ if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'A'))
76
+ if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'g'))
82
/* Return 1 if the file found by searching $PATH for PATHNAME, defaulting
83
Index: b/bash/patchlevel.h
84
===================================================================
85
--- a/bash/patchlevel.h
86
+++ b/bash/patchlevel.h
88
regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
89
looks for to find the patch level (for the sccs version string). */
91
-#define PATCHLEVEL 24
92
+#define PATCHLEVEL 25
94
#endif /* _PATCHLEVEL_H_ */
96
===================================================================
101
fprintf (stderr, "W_ASSNBLTIN%s", f ? "|" : "");
103
+ if (f & W_ASSNGLOBAL)
105
+ f &= ~W_ASSNGLOBAL;
106
+ fprintf (stderr, "W_ASSNGLOBAL%s", f ? "|" : "");
108
if (f & W_COMPASSIGN)
111
@@ -2803,7 +2808,7 @@
113
else if (assign_list)
115
- if (word->flags & W_ASSIGNARG)
116
+ if ((word->flags & W_ASSIGNARG) && (word->flags & W_ASSNGLOBAL) == 0)
117
aflags |= ASS_MKLOCAL;
118
if (word->flags & W_ASSIGNASSOC)
119
aflags |= ASS_MKASSOC;