On 05/01/2012 06:35 PM, Peng Yu wrote:
> Hi,
> 
> 'sort' behaves differently on linux and Mac OS X (see below). Does
> anybody know why there is a difference and how to make them the same?

Most likely due to a difference in the locale definitions on the two
machines, in which case 'LC_ALL=C sort' will make them behave the same,
or you can define a custom locale (with localedef) that has the same
rules for both machines instead of relying on the pre-built en_US.UTF-8
locale.  See the FAQ:
https://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021

> 
> ~$ uname
> Linux
> ~$ (echo AA;echo Aa)|sort
> Aa
> AA
> ~$ locale
> LANG=en_US.UTF-8

> LC_COLLATE="en_US.UTF-8"


> 
> ~$ uname
> Darwin
> ~$ (echo AA;echo Aa)|sort
> AA
> Aa
> ~$ locale
> LANG="en_US.UTF-8"
> LC_COLLATE="en_US.UTF-8"

You are indeed using the same locale name on both machines, but since
the two machines do not have the same locale definitions (one is from
glibc, the other from BSD heritage), they are not identical definitions,
and apparently they differ on whether 'a' comes before or after 'A' in
English.

-- 
Eric Blake   [email protected]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to