On Fri, Oct 31, 2025 at 14:25:05 +0100, Nicolas George wrote:
> ls can sort the list differently; printf cannot. Zsh can at globbing, sh
> cannot, bash I do not know.
Bash 5.3 can, but that's not in any released version of Debian yet
(bash 5.3 was released during Trixie's freeze).
>From the bash 5.3 man page:
GLOBSORT
Controls how the results of pathname expansion are sorted. The
value of this variable specifies the sort criteria and sort or-
der for the results of pathname expansion. If this variable is
unset or set to the null string, pathname expansion uses the
historical behavior of sorting by name, in ascending lexico-
graphic order as determined by the LC_COLLATE shell variable.
If set, a valid value begins with an optional +, which is ig-
nored, or -, which reverses the sort order from ascending to de-
scending, followed by a sort specifier. The valid sort speci-
fiers are name, numeric, size, mtime, atime, ctime, and blocks,
which sort the files on name, names in numeric rather than lexi-
cographic order, file size, modification time, access time, in-
ode change time, and number of blocks, respectively. If any of
the non-name keys compare as equal (e.g., if two files are the
same size), sorting uses the name as a secondary sort key.
For example, a value of -mtime sorts the results in descending
order by modification time (newest first).
The numeric specifier treats names consisting solely of digits
as numbers and sorts them using their numeric value (so "2"
sorts before "10", for example). When using numeric, names con-
taining non-digits sort after all the all-digit names and are
sorted by name using the traditional behavior.
A sort specifier of nosort disables sorting completely; bash re-
turns the results in the order they are read from the file sys-
tem, ignoring any leading -.
If the sort specifier is missing, it defaults to name, so a
value of + is equivalent to the null string, and a value of -
sorts by name in descending order. Any invalid value restores
the historical sorting behavior.
Versions of bash before 5.3 have no way to control the order of glob
expansion, other than changing LC_COLLATE or the like.