[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash stuck in a loop defining arrays
From: |
Pierre Gaston |
Subject: |
Re: bash stuck in a loop defining arrays |
Date: |
Wed, 25 Feb 2009 17:08:03 +0200 |
On Wed, Feb 25, 2009 at 4:46 PM, Chet Ramey <chet.ramey@case.edu> wrote:
>> Machine Type: i386-unknown-openbsd4.4
>>
>> Bash Version: 4.0
>> Patch Level: 0
>>
>> Description:
>> playing with the associative arrays, bash ends up in what appears
>> to be a busy loop that I cannot interupt with C-c
>>
>> Repeat-By:
>>
>>
>> bash-4.0$ declare -A array
>> bash-4.0$ declare array["foo[bar"]=bleh
>> bash-4.0$ array["foo"]=bleh
>
> You tricked the shell. Bash isn't smart enough to realize you're assigning
> to an associative array, and performs quote removal on the assignment
> before running `declare'.
>
> What ends up happening is that the shell tries to create a variable named
> 'array[foo[bar]=bleh', since the dequoted word is no longer a valid
> assignment statement. This leads to all sorts of weird behavior, since
> some of the code's assumptions are violated.
>
> The attached patch should catch the attempts to create invalid variables
> and flag them as errors.
>
> Chet
>
>
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
>
> Chet Ramey, ITS, CWRU chet@case.edu http://tiswww.tis.case.edu/~chet/
>
>
Thanks, unfortunately it seems that this patch isn't enough as it
also happens with a simpler test case:
bash-4.0$ declare -A array
bash-4.0$ declare array[foo]=bar