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