Re: [minor] Space after last element on assoc print
On 10/20/16 5:25 PM, Dan Douglas wrote: > By the way, that space at the end has been pointed out a number of > times lately. I think Chet clarified at some point that that's just > the way the serializer prints it - so it's nothing. Apparently a lot > of people think it's meaningful. I should add a space at the beginning for symmetry. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/
Re: [minor] Space after last element on assoc print
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
Re: [minor] Space after last element on assoc print
By the way, that space at the end has been pointed out a number of times lately. I think Chet clarified at some point that that's just the way the serializer prints it - so it's nothing. Apparently a lot of people think it's meaningful.
Re: [minor] Space after last element on assoc print
On Wed, Oct 19, 2016 at 11:47 PM, Quentin L'Hourswrote: > 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".
[minor] Space after last element on assoc print
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" ) Fix: Maybe just rlen-- just after looping on all elements in assoc.c -- Quentin L'Hours