Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15186
| From | Darren 'Tadgy' Austin <darren@afterdark.org.uk> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Unexpected result of array assignment |
| Date | 2019-07-18 09:12 +0100 |
| Message-ID | <mailman.1628.1563437554.2688.bug-bash@gnu.org> (permalink) |
| References | <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> <5D300798.1040708@tlinx.org> <nycvar.YAK.7.76.1907180909000.95422@nzl.bcra-fbhepr.pb.hx> |
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.
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Unexpected result of array assignment Darren 'Tadgy' Austin <darren@afterdark.org.uk> - 2019-07-18 09:12 +0100
csiph-web