On Wed, Oct 19, 2016 at 11:47 PM, Quentin L'Hours <lhoursquen...@gmail.com> wrote: > Hi, > > Bash Version: 4.4 > Release Status: release > > Description: > > 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. Note that ksh93 is different in some respects because it allows "nested variables".