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


Groups > gnu.bash.bug > #15193

Re: Unexpected result of array assignment

From Léa Gris <lea.gris@noiraude.net>
Newsgroups gnu.bash.bug
Subject Re: Unexpected result of array assignment
Date 2019-07-19 03:38 +0200
Message-ID <mailman.1714.1563500355.2688.bug-bash@gnu.org> (permalink)
References <c918f5ca-b34d-4a35-9a51-cfecc9063e36@noiraude.net>

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

On 18/07/2019 14:12, Greg Wooledge wrote:
> 
>     On Thu, Jul 18, 2019 at 10:58:52AM +0200, Henning wrote:
> 
>                 eval 'foo=(["key"]="'"${foo["key"]}"' value2")'
> 
> 
>     If you just want to work around the bug, why not do it in the simplest
>     way possible?
> 
>     foo["key"]+=" value2"
> 
> Of course, you are right.


Can be done safely with storing the intermediate value.

declare -A foo
foo=(["key"]="value1")
declare -p foo
_v="${foo["key"]}"
declare -p _v
foo=(["key"]="${_v} value2")
declare -p foo

Still safer than eval for an extra intermediary assignment.
And allow you to insert the old value of ${foo=["key"]} anywhere 
in-between. The += string concatenation would not work in this case.

-- 
Léa Gris

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Unexpected result of array assignment Léa Gris <lea.gris@noiraude.net> - 2019-07-19 03:38 +0200

csiph-web