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


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

Re: Unexpected result of array assignment

Started byDarren 'Tadgy' Austin <darren@afterdark.org.uk>
First post2019-07-18 09:12 +0100
Last post2019-07-18 09:12 +0100
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 Darren 'Tadgy' Austin <darren@afterdark.org.uk> - 2019-07-18 09:12 +0100

#15186 — Re: Unexpected result of array assignment

FromDarren 'Tadgy' Austin <darren@afterdark.org.uk>
Date2019-07-18 09:12 +0100
SubjectRe: Unexpected result of array assignment
Message-ID<mailman.1628.1563437554.2688.bug-bash@gnu.org>
Hi,
  Thanks for the quick reply. :)

[I tried to cc bash@tlinx.org on this email, but get a SERVFAIL from both DNS 
servers, so couldn't copy you in directly, sorry!]

On Wed, 17 Jul 2019, L A Walsh wrote:
> In bash4.4.12, Using:
> I think you need to tell bask that you are updating 'foo'
> instead of assigning to it:
> This seems to do what you want:
> foo+=([key]="${foo[key]} value2")
> > my -p foo
> declare -A foo=([key]="value1 value2" )

Indeed.  I found a couple of ways of achieving what I wanted, using the += 
operator being one of them - but this is only available in bash 4.4+ and I 
need to support older versions (back to 4.0).

> I think that without the update it becomes an assign and clears
> the value assigned to 'key' before using it to form the string.

But the 'wipe before assignment' is inconsistent with how bash handles any 
other assignment.  For example:
  FOO=bar
  FOO="$bar baz"
will result in FOO = "bar baz", not simply " baz" as happens with the array 
assignment.

I can work around the issue using a different syntax, but I thought it might 
be worth reporting the inconsistency :)

Cheers,
Darren.

[toc] | [standalone]


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


csiph-web