[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected result of array assignment

From: Chet Ramey
Subject: Re: Unexpected result of array assignment
Date: Fri, 19 Jul 2019 15:21:45 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.8.0

On 7/17/19 9:16 PM, Darren 'Tadgy' Austin wrote:

> Bash Version: 5.0
> Patch Level: 3
> Release Status: release
> Description:
>         There seems to be unexpect (a bug?) behaviour with bash's handling of 
> array assignments.
>         Specifically, if you try to assign an array element a value 
> containing that same array value, it fails to work.
>         See example below :)
>         Bug confirmed by the folks in #bash on Freenode - unable to explain 
> what is happening.

Thanks for the report.

This changed between bash-4.2 and bash-4.3 as part of changes to avoid
scanning the subscript in an associative array reference multiple times:
before and after expansion, and for compatibility with ksh93 (which
behaves the same as bash-4.3+).

It's obliquely referenced in the documentation:

"When  +=  is  applied  to an array variable using compound
 assignment (see Arrays below), the variable's value is not unset (as it
 is when using =)"

However, I agree that it would be more consistent to let the expansion
of the rhs use the existing value of the array before clearing it, since
that's what indexed arrays do. I'll make associative array assignment
do that.


``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]