${array[@]@A} splits the values. $ a=("a b" "c d"); printf "<%s>" "${a[@]@A}" <declare><-a><a=([0]="a><b"><[1]="c><d")>
diff --git a/subst.c b/subst.c index 2a7366f..d7258b8 100644 --- a/subst.c +++ b/subst.c @@ -4796,18 +4796,26 @@ array_var_assignment (v, itype, quoted) { char *ret, *val, flags[MAX_ATTRIBUTES]; int i; + ARRAY *a; + HASH_TABLE *h; + WORD_LIST *list; if (v == 0) return (char *)NULL; - val = array_p (v) ? array_to_assign (array_cell (v), 0) - : assoc_to_assign (assoc_cell (v), 0); - if (val == 0) + a = (v && array_p (v)) ? array_cell (v) : 0; + h = (v && assoc_p (v)) ? assoc_cell (v) : 0; + + list = a ? array_to_word_list (a) : (h ? assoc_to_word_list (h) : 0); + if (list == 0) { val = (char *)xmalloc (3); val[0] = '('; val[1] = ')'; val[2] = 0; } + else + val = list_transform ('Q', (SHELL_VAR *)0, list, itype, quoted); + dispose_words (list); i = var_attribute_string (v, 0, flags); ret = (char *)xmalloc (i + strlen (val) + strlen (v->name) + 16); sprintf (ret, "declare -%s %s=%s", flags, v->name, val); --- xoxo iza