Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15194 > unrolled thread

Re: Unexpected result of array assignment

Started byChet Ramey <chet.ramey@case.edu>
First post2019-07-19 15:21 -0400
Last post2019-07-19 15:21 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Unexpected result of array assignment Chet Ramey <chet.ramey@case.edu> - 2019-07-19 15:21 -0400

#15194 — Re: Unexpected result of array assignment

FromChet Ramey <chet.ramey@case.edu>
Date2019-07-19 15:21 -0400
SubjectRe: Unexpected result of array assignment
Message-ID<mailman.1798.1563564870.2688.bug-bash@gnu.org>
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.

Chet

-- 
``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/

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web