The "asort" extension (Was: feature proposal: expand associative arrays in lexicographic order ...)
Stan Marsh <[email protected]>
| Newsgroups | gmane.comp.shells.bash.bugs |
|---|---|
| Message-ID | <[email protected]> |
From: Greg Wooledge Subject: Re: The "asort" extension (Was: feature proposal: expand associative arrays in lexicographic order ...) Date: Tue, 25 Aug 2026 17:03:29 -0400 >On Tue, Aug 25, 2026 at 16:20:03 -0400, Zachary Santer wrote: >> On Tue, Aug 25, 2026 at 2:31'PM Stan Marsh <[email protected]> wrote: >> > >> > Rather, the sorting is a functionality associated with the "for" >> > statement. That's how it works in GAWK, and I think that should be the >> > model for how it should work in bash. >gawk's for-in loop does not sort the array indices. >hobbit:~$ gawk 'BEGIN {a["foo"]=1; a["bar"]=2; for (i in a) {print i} }' >foo >bar >If they were sorted, bar would have come first. $ gawk 'BEGIN { > split("the quick brown fox jumps over the lazy dog",A) > for (i in A) B[A[i]] > PROCINFO["sorted_in"] = "@ind_str_asc" > for (i in B) print i > }' brown dog fox jumps lazy over quick the $ ================================================================================= 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)