From: Chet Ramey
Subject: Re: The "asort" extension (Was: feature proposal: expand associative
arrays in lexicographic order ...)
Date: Wed, 26 Aug 2026 14:58:30 -0400
>On 8/26/26 12:32 PM, Stan Marsh wrote:
>> *Somebody* must have requested it, or else the "asort" extension (the
>> subject of this thread) would never have been dreamed up and/or
>> implemented.
>I didn't write it. It was contributed back in 2020, and it wasn't due to
>any request. The original author had written it for his own use several
>years before, mostly to learn how loadable builtins worked, and asked if
>I wanted it.
Understood. That's why it is not "built by default".
>> Surely, the need for traversing a bash associative array in alphabetical
>> order (or something like that) is not *that* new or novel. I myself
>> discussed this with you (over email) a few years back - which is what
>> led to my creating the idiom that I posted earlier (because the asort
>> extension didn't make any sense to me).
>You mean 2022, right? You asked about asort, said you didn't understand it,
>and said you'd use a different solution. This doesn't rise to the level of
>requesting some new feature.
Right you are. Just to be clear, I never did request this as a new
feature (OP did, not me). I'm quite happy with the idiom I have.
Finally, a few notes on misc topics raised elsethread:
1) Sorting an indexed array on the subscripts makes no sense. As
Z has pointed out, it is already sorted. All that's needed is a
documentation update clarifying this fact.
2) So, the only sense in which sorting an indexed array makes
sense is sorting the values. This is trivially done and needs no
further exposition.
3) Thus, the only thing left to discuss is sorting an associative
array on the keys.
And note that, in all cases, when I talk about "sorting" an array,
what I am really talking about is traversing it in a specified order
with a (bash) "for" statement.
The internal representation of the array is in all cases unchanged.
=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.
When responding to my posts, please try to refrain from giving bureaucratic
answers. If you have nothing useful to say, then just click Next and go on.
BTW, ain't interested in kludgey workarounds - got enough of my own!
(YT id: 6H1lcubN0oE)