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.
Repeat-By:
$ 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