On 1/24/10 5:13 AM, Mart Frauenlob wrote:
> Hello,
>
> I'd like to ask, if the behavior of indexed array assignment using the
> form: 'array[${#arr...@]}]=' is as expected.
Thanks for the report. The question is what ${#arr...@]} should return
when it refers to a scalar variable that has not been assigned a value.
Previous versions of bash returned 1, not checking whether or not the
variable is set; the right answer is 0 if the variable is not set and 1
otherwise.
Any official change will probably wait until bash-4.2. I have attached a
patch to evaluate, though.
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/
*** ../bash-4.1-patched/subst.c 2009-12-30 08:24:28.000000000 -0500
--- subst.c 2010-01-24 14:57:19.000000000 -0500
***************
*** 5244,5247 ****
--- 5244,5248 ----
char *t, c;
ARRAY *array;
+ HASH_TABLE *h;
SHELL_VAR *var;
***************
*** 5267,5279 ****
array = array_p (var) ? array_cell (var) : (ARRAY *)NULL;
if (ALL_ELEMENT_SUB (t[0]) && t[1] == ']')
{
if (assoc_p (var))
! return (assoc_num_elements (assoc_cell (var)));
else if (array_p (var))
! return (array_num_elements (array));
else
! return 1;
}
--- 5268,5281 ----
array = array_p (var) ? array_cell (var) : (ARRAY *)NULL;
+ h = assoc_p (var) ? assoc_cell (var) : (HASH_TABLE *)NULL;
if (ALL_ELEMENT_SUB (t[0]) && t[1] == ']')
{
if (assoc_p (var))
! return (h ? assoc_num_elements (h) : 0);
else if (array_p (var))
! return (array ? array_num_elements (array) : 0);
else
! return (value_cell (var) ? 1 : 0);
}