only set W_HASQUOTEDNULL in the returned word flags if the word is
a quoted null string AND had_quoted_null is set. Rest of fix
+ 5/9
+ ---
+variables.c
+ - bind_variable_internal: if we get an array variable here (implicit
+ assignment to index 0), call make_array_variable_value, which
+ dummies up a fake SHELL_VAR * from array[0]. This matters when
+ we're appending and have to use the current value
+ - bind_variable_internal: after computing the new value, treat assoc
+ variables with higher precedence than simple array variables; it
+ might be that a variable has both attributes set
+
+arrayfunc.c
+ - bind_array_var_internal: break code out that handles creating the
+ new value to be assigned to an array variable index into a new
+ function, make_array_variable_value. This handles creating a
+ dummy SHELL_VAR * for implicit array[0] assignment. Fixes bug
+ reported by Dan Douglas <ormaaj@gmail.com>
+
+arrayfunc.h
+ - make_array_variable_value: new extern declaration
tests/alias1.sub f
tests/alias.right f
tests/appendop.tests f
+tests/appendop1.sub f
tests/appendop.right f
tests/arith-for.tests f
tests/arith-for.right f
return var;
}
-static SHELL_VAR *
-bind_array_var_internal (entry, ind, key, value, flags)
+char *
+make_array_variable_value (entry, ind, key, value, flags)
SHELL_VAR *entry;
arrayind_t ind;
char *key;
else
newval = make_variable_value (entry, value, flags);
+ return newval;
+}
+
+static SHELL_VAR *
+bind_array_var_internal (entry, ind, key, value, flags)
+ SHELL_VAR *entry;
+ arrayind_t ind;
+ char *key;
+ char *value;
+ int flags;
+{
+ char *newval;
+
+ newval = make_array_variable_value (entry, ind, key, value, flags);
+
if (entry->assign_func)
(*entry->assign_func) (entry, newval, ind, key);
else if (assoc_p (entry))
extern SHELL_VAR *convert_var_to_array __P((SHELL_VAR *));
extern SHELL_VAR *convert_var_to_assoc __P((SHELL_VAR *));
+extern char *make_array_variable_value __P((SHELL_VAR *, arrayind_t, char *, char *, int));
+
extern SHELL_VAR *bind_array_variable __P((char *, arrayind_t, char *, int));
extern SHELL_VAR *bind_array_element __P((SHELL_VAR *, arrayind_t, char *, int));
extern SHELL_VAR *assign_array_element __P((char *, char *, int));
Indexed arrays are referenced using integers (including arithmetic
expressions) and are zero-based; associative arrays are referenced
using arbitrary strings.
+Unless otherwise noted, indexed array indices must be non-negative integers.
.PP
An indexed array is created automatically if any variable is assigned to
using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The
Indexed arrays are referenced using integers (including arithmetic
expressions (@pxref{Shell Arithmetic})) and are zero-based;
associative arrays use arbitrary strings.
+Unless otherwise noted, indexed array indices must be non-negative integers.
An indexed array is created automatically if any variable is assigned to
using the syntax
}
if (command_line == 0)
- command_line = savestring (the_printed_command_except_trap);
+ command_line = savestring (the_printed_command_except_trap ? the_printed_command_except_trap : "");
#if defined (PROCESS_SUBSTITUTION)
if ((subshell_environment & SUBSHELL_COMSUB) && (simple_command->flags & CMD_NO_FORK) && fifos_pending() > 0)
-BUILD_DIR=/usr/local/build/bash/bash-current
+BUILD_DIR=/usr/local/build/chet/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
9
16
./appendop.tests: line 83: x: readonly variable
+declare -A foo='([one]="bar" [two]="baz" [three]="quux" )'
+declare -A foo='([one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
+declare -A foo='([four]="four" [one]="bar" [two]="baz" [0]="zero" [three]="quux" )'
+declare -ai iarr='([0]="3" [1]="2" [2]="3")'
+declare -ai iarr='([0]="3" [1]="2" [2]="3" [3]="4" [4]="5" [5]="6")'
echo $x
x+=5
+
+${THIS_SH} ./appendop1.sub
--- /dev/null
+typeset -A foo=([one]=bar [two]=baz [three]=quux)
+typeset -p foo
+
+foo+=zero
+typeset -p foo
+
+foo+=([four]=four)
+typeset -p foo
+
+typeset -ia iarr=(2 2 3)
+iarr+=1
+typeset -p iarr
+
+iarr+=(4 5 6)
+typeset -p iarr
--- /dev/null
+# See whether or not we can use `diff -a'
+( diff -a ./printf.tests ./printf.tests >/dev/null 2>&1 ) && AFLAG=-a
+
+${THIS_SH} ./printf.tests > /tmp/xx 2>&1
+diff $AFLAG /tmp/xx printf.right && rm -f /tmp/xx
/* Variables which are bound are visible. */
VUNSETATTR (entry, att_invisible);
+#if defined (ARRAY_VARS)
+ if (assoc_p (entry) || array_p (entry))
+ newval = make_array_variable_value (entry, 0, "0", value, aflags);
+ else
+#endif
+
newval = make_variable_value (entry, value, aflags); /* XXX */
/* Invalidate any cached export string */
/* If an existing array variable x is being assigned to with x=b or
`read x' or something of that nature, silently convert it to
x[0]=b or `read x[0]'. */
- if (array_p (entry))
+ if (assoc_p (entry))
{
- array_insert (array_cell (entry), 0, newval);
+ assoc_insert (assoc_cell (entry), savestring ("0"), newval);
free (newval);
}
- else if (assoc_p (entry))
+ else if (array_p (entry))
{
- assoc_insert (assoc_cell (entry), savestring ("0"), newval);
+ array_insert (array_cell (entry), 0, newval);
free (newval);
}
else