Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15185
| From | L A Walsh <bash@tlinx.org> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: Unexpected result of array assignment |
| Date | 2019-07-17 22:46 -0700 |
| Message-ID | <mailman.1622.1563428772.2688.bug-bash@gnu.org> (permalink) |
| References | <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> <5D300798.1040708@tlinx.org> |
On 2019/07/17 18:16, Darren 'Tadgy' Austin wrote:
> Repeat-By:
> declare -A foo
> foo=(["key"]="value1")
> declare -p foo
> foo=(["key"]="${foo["key"]} value2")
> declare -p foo
>
> The above should result in 'foo["key"]' having a value of 'value1 value2', but the result is simply ' value2', which I believe to be incorrect behaviour.
>
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" )
or w/quotes:
foo+=(["key"]="${foo["key"]} value3")
> my -p foo
declare -A foo=([key]="value1 value2 value3" )
I think that without the update it becomes an assign and clears
the value assigned to 'key' before using it to form the string.
It certainly isn't intuitive, but I don't know if there is a
guarantee of it picking up the value of "foo[key]" before initializing
the target space.
Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: Unexpected result of array assignment L A Walsh <bash@tlinx.org> - 2019-07-17 22:46 -0700
csiph-web