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


Groups > gnu.bash.bug > #15186

Re: Unexpected result of array assignment

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Darren 'Tadgy' Austin <darren@afterdark.org.uk>
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 <mailman.1628.1563437554.2688.bug-bash@gnu.org> (permalink)
References <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> <5D300798.1040708@tlinx.org> <nycvar.YAK.7.76.1907180909000.95422@nzl.bcra-fbhepr.pb.hx>
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 <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <https://lists.gnu.org/archive/html/bug-bash>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
X-Mailman-Original-Message-ID <nycvar.YAK.7.76.1907180909000.95422@nzl.bcra-fbhepr.pb.hx>
X-Mailman-Original-References <nycvar.YAK.7.76.1907180212120.95422@nzl.bcra-fbhepr.pb.hx> <5D300798.1040708@tlinx.org>
Xref csiph.com gnu.bash.bug:15186

Show key headers only | View raw


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.

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


Thread

Re: Unexpected result of array assignment Darren 'Tadgy' Austin <darren@afterdark.org.uk> - 2019-07-18 09:12 +0100

csiph-web