bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unexpected result of array assignment


From: Léa Gris
Subject: Re: Unexpected result of array assignment
Date: Fri, 19 Jul 2019 03:38:59 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]