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


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

Re: Unexpected result of array assignment

Started byLéa Gris <lea.gris@noiraude.net>
First post2019-07-19 03:38 +0200
Last post2019-07-19 03:38 +0200
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 Léa Gris <lea.gris@noiraude.net> - 2019-07-19 03:38 +0200

#15193 — Re: Unexpected result of array assignment

FromLéa Gris <lea.gris@noiraude.net>
Date2019-07-19 03:38 +0200
SubjectRe: Unexpected result of array assignment
Message-ID<mailman.1714.1563500355.2688.bug-bash@gnu.org>

[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

[toc] | [standalone]


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


csiph-web