> I did a stupid thing. Tried to read into an array--which is indexed--but
> the variable is already an associative array.
>
> declare -A foo
> read -a foo <<<bar
>
> The above should error instead of Segfault, yes?
Yes. It certainly shouldn't crash the shell. Try the attached patch and
let me know that it works for you. Thanks for the report.
Chet
*** ../bash-4.2-patched/builtins/read.def 2011-01-04 11:43:36.000000000
-0500
--- builtins/read.def 2011-06-21 10:31:02.000000000 -0400
***************
*** 456,460 ****
add_unwind_protect (xfree, input_string);
interrupt_immediately++;
- terminate_immediately++;
unbuffered_read = (nchars > 0) || (delim != '\n') || input_is_pipe;
--- 456,459 ----
***************
*** 513,516 ****
--- 512,516 ----
if (retval <= 0)
{
+ CHECK_TERMSIG;
eof = 1;
break;
***************
*** 623,627 ****
interrupt_immediately--;
- terminate_immediately--;
#if defined (ARRAY_VARS)
--- 623,626 ----
***************
*** 643,646 ****
--- 642,651 ----
return EXECUTION_FAILURE; /* readonly or noassign */
}
+ if (assoc_p (var))
+ {
+ builtin_error (_("%s: cannot convert associative to indexed
array"), arrayname);
+ xfree (input_string);
+ return EXECUTION_FAILURE; /* existing associative array */
+ }
array_flush (array_cell (var));
``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/