Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: L A Walsh Newsgroups: gnu.bash.bug Subject: Re: Unexpected result of array assignment Date: Wed, 17 Jul 2019 22:46:00 -0700 Lines: 38 Approved: bug-bash@gnu.org Message-ID: References: <5D300798.1040708@tlinx.org> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: usenet.stanford.edu 1563428773 11732 209.51.188.17 (18 Jul 2019 05:46:13 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: "Darren 'Tadgy' Austin" Envelope-to: bug-bash@gnu.org User-Agent: Thunderbird In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 173.164.175.65 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <5D300798.1040708@tlinx.org> X-Mailman-Original-References: Xref: csiph.com gnu.bash.bug:15185 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.