bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#16778: Neither ls nor sort do a correct lexicographic sort


From: Pádraig Brady
Subject: bug#16778: Neither ls nor sort do a correct lexicographic sort
Date: Mon, 17 Feb 2014 15:10:58 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2

tag 16778 notabug
close 16778
stop

On 02/17/2014 02:40 PM, Jarosław Rzeszótko wrote:
> Hi,
> 
> Please contemplate the following shell session:
> 
> /home/jarek # mkdir test
> 
> /home/jarek # cd test
> 
> /home/jarek/test # touch x_y.c xs.c
> 
> /home/jarek/test # ls -1
> razem 0
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 xs.c
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 x_y.c
> 
> /home/jarek/test # ls -1 | sort
> razem 0
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 xs.c
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 x_y.c
> 
> /home/jarek/test # ls -1 | perl -e 'print(sort(<STDIN>))'
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 x_y.c
> -rw-r--r-- 1 jarek jarek 0 02-17 15:34 xs.c
> razem 0

> /home/jarek/test # ls --version
> ls (GNU coreutils) 8.22
> 
> The ordering that is produced by both ls and sort is incorrect, according
> to a widely accepted convention "x_y.c" preceeds "xs.c", as the perl
> example illustrates. I checked this on two different distributions, so it
> should not be an distribution-specific issue, rather seems a logical
> mistake in coreutils itself.

coreutils is just honoring your locale collating order.
http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#Sort-does-not-sort-in-normal-order_0021

You can disable that like:

$ ls -1 | LANG=C sort
x_y.c
xs.c

$ LANG=C ls -1
x_y.c
xs.c

thanks,
Pádraig.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]