[Top][All Lists]

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

Re: [minor] Space after last element on assoc print

From: Quentin L'Hours
Subject: Re: [minor] Space after last element on assoc print
Date: Thu, 20 Oct 2016 23:25:26 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0

On 10/20/2016 10:40 PM, Dan Douglas wrote:
On Wed, Oct 19, 2016 at 11:47 PM, Quentin L'Hours
Useless space after last item of a declare -p on an assoc array (indexed
arrays don't print it, and neither does ksh typeset on assoc arrays).
It doesn't seem to have any consequence though.


$ declare -A capital[fr]=Paris
$ declare -p capital
declare -A capital=([fr]="Paris" )

You cannot assign an attribute to an individual element of any array. The
behaviour for indexed arrays is described in the manual:

"declare -a name[subscript] is also accepted; the subscript is ignored."

In the case of a previously declared associative array in the current
scope, one might argue that bash should throw an error instead. I think
what you're seeing is bash taking a "reasonable default" instead of
throwing an error in response to a nonsensical assignment.

I think you misunderstood what I was really talking about, I was just pointing out a useless space printed by declare -p on an assoc array (which isn't present for indexed arrays). I'm not trying to add any attribute to an individual element, I'm just printing the contents of the array.

Sorry if the example was misleading,

Quentin L'Hours

reply via email to

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