On 8/2/23 2:11 AM, Grisha Levit wrote:
If an indexed array is set via compound assignment, its values are
cleared at the start so any arithmetic expansions in the assignment
that reference the array and any [ind]+= assignments are evaluated
using the newly assigned values.  However, when assigning associative
arrays, any previously existing values are (re)used during assignment
instead.

The NHASH implementation came in in July 2019 to solve this problem:

https://lists.gnu.org/archive/html/bug-bash/2019-07/msg00112.html

Variable references on the rhs of an assignment statement should resolve
to the values they had before the assignment. Indexed arrays behave the
same way.

The += operator is special, in that it's basically equivalent to x=x+v,
but without a step evaluating X on the rhs. Without that evaluation step,
computing the new value won't use the original pre-assignment value.

I made the change for associative arrays and the += behavior came as a
side effect. I didn't go back and make the same change to indexed arrays,
nor did I special-case += to use NHASH when computing the new value.

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


Reply via email to