Newer sort also comes with a --debug option that would help explain your
predicament (5.97 is YEARS old; the latest is 8.13, with numerous bug
fixes, although none of the behavior you show is affected by any of
those bug fixes).
$ printf 'b101 512\nb1 512\n' | LC_ALL=C sort -k1 --debug
sort: using simple byte comparison
b1 512
______
______
b101 512
________
________
$ printf 'b101 512\nb1 512\n' | sort -k1 --debug
sort: using `en_US.UTF-8' sorting rules
sort: leading blanks are significant in key 1; consider also specifying `b'
b101 512
________
________
b1 512
______
______
$ printf 'b101 512\nb1 512\n' | sort -k1,1 --debug
sort: using `en_US.UTF-8' sorting rules
sort: leading blanks are significant in key 1; consider also specifying `b'
b1 512
__
______
b101 512
____
________
In the en_US.UTF-8 locale, collation is done by dictionary ordering,
where whitespace is insignificant to the collation; and specification of
-k1 instead of the more precise k1,1 means that you are sorting the
entire line instead of the first field of the line. Since "b1512"
collates greater than "b101512" in en_US collation rules, the same
applies to "b1 512" and "b101 512". Notice how use of -k1,1 changed the
output by comparing only "b1" and "b101", or how use of LC_ALL=C changed
the output by switching to bytewise collation with no ditionary sorting,
where space becomes significant.
--
Eric Blake address@hidden +1-801-349-2682
Libvirt virtualization library http://libvirt.org