Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Darren 'Tadgy' Austin Newsgroups: gnu.bash.bug Subject: Re: Unexpected result of array assignment Date: Thu, 18 Jul 2019 09:12:23 +0100 Lines: 35 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=US-ASCII X-Trace: usenet.stanford.edu 1563437555 17519 209.51.188.17 (18 Jul 2019 08:12:35 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org In-Reply-To: <5D300798.1040708@tlinx.org> User-Agent: Alpine 2.21 (LNX 202 2017-01-01) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 83.170.98.46 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: X-Mailman-Original-References: <5D300798.1040708@tlinx.org> Xref: csiph.com gnu.bash.bug:15186 Hi, Thanks for the quick reply. :) [I tried to cc bash@tlinx.org on this email, but get a SERVFAIL from both DNS servers, so couldn't copy you in directly, sorry!] On Wed, 17 Jul 2019, L A Walsh wrote: > 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" ) Indeed. I found a couple of ways of achieving what I wanted, using the += operator being one of them - but this is only available in bash 4.4+ and I need to support older versions (back to 4.0). > I think that without the update it becomes an assign and clears > the value assigned to 'key' before using it to form the string. But the 'wipe before assignment' is inconsistent with how bash handles any other assignment. For example: FOO=bar FOO="$bar baz" will result in FOO = "bar baz", not simply " baz" as happens with the array assignment. I can work around the issue using a different syntax, but I thought it might be worth reporting the inconsistency :) Cheers, Darren.