View Issue Details

IDProjectCategoryView StatusLast Update
0017711CentOS-7coreutilspublic2020-09-03 09:46
Reporterogeffert 
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionno change required 
Product Version 
Target VersionFixed in Version 
Summary0017711: /usr/bin/sort cannot sort numbers correctly,
Description/usr/bin/sort cannot sort numbers correctly, this is reproducable

# uname -a
Linux nordisch 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@nordisch og]# sort -n
0.30375
0.2287
0.94745
1.10819
0.8501
0.89386


0.2287
0.8501
0.30375
0.89386
0.94745
1.10819

Steps To Reproduce-bash-4.2$ sort -n
0.30375
0.2287
0.94745
1.10819
0.8501
0.89386
Tagscentos 7
abrt_hash
URL

Activities

ManuelWolfshant

ManuelWolfshant

2020-09-02 23:49

manager   ~0037625

Last edited: 2020-09-02 23:55

View 3 revisions

I cannot confirm that. On my system -n , d and -g all work. For instance:
[wolfy@wolfy ~]$ sort -n
0.30375
0.2287
0.94745
1.10819
0.8501
0.89386


0.2287
0.30375
0.8501
0.89386
0.94745
1.10819

What do the commands echo $LC_ALL, echo $LC_NUMERIC , rpm -q coreutils and rpm -V coreutils come back with on your system ?

ogeffert

ogeffert

2020-09-03 08:42

reporter   ~0037628

I guess you mean that LC_ALL ( locale setting) has an influence on
how numbers are interpreted - e.g. the decimal point.

This is the what it looks like:
[og@nordisch ~]$ echo $LC_ALL

[og@nordisch ~]$ rpm -q coreutils
coreutils-8.22-24.el7.x86_64
[og@nordisch ~]$ rpm -V coreutils
[og@nordisch ~]$
ogeffert

ogeffert

2020-09-03 08:47

reporter   ~0037630

[og@nordisch ~]$ locale
LANG=de_DE.UTF-8
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
ManuelWolfshant

ManuelWolfshant

2020-09-03 08:54

manager   ~0037632

Indeed, I was looking for a modification on the interpretation of the decimal point. Prior to my previous post I spent 20 min trying different locale settings ( German / Norway / Sweden / Russia / Island / Finland / Israel and half a dozen more ) in my attempt to replicate the behavior you see, without success. On 4-5 systems I had handy sort always behaved correctly when using -n/-h/-g and various -k options.
Could sort point on your system to another application, maybe ? Or an alias ? What do "set | grep sort", "alias sort" and "which sort" come back with ?

I am asking because I am 100% certain that the issue is on your end, in the 6 years since CentOS 7 is out this problem would have been reported already.
ogeffert

ogeffert

2020-09-03 08:58

reporter   ~0037634

Thanks for pointing to the right spot :-)

Setting LC_ALL=C does it - sorting works correctly than.

I am really asking myself, if it would be wiser to use LC_NUMERIC ?

[og@nordisch ~]$ LC_ALL=C sort -n
0.30375
0.2287
0.94745
1.10819
0.8501
0.89386


0.2287
0.30375
0.8501
0.89386
0.94745
1.10819
[og@nordisch ~]$
ogeffert

ogeffert

2020-09-03 09:02

reporter   ~0037635

[og@nordisch ~]$ which sort
/usr/bin/sort

[og@nordisch ~]$ ls -altr /usr/bin/sort
-rwxr-xr-x. 1 root root 117704 20. Aug 2019 /usr/bin/sort

[og@nordisch ~]$ file /usr/bin/sort
/usr/bin/sort: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, BuildID[sha1]=ee2f1ebcdae9af94274d353f576ad5cd0ca2c20f, stripped
ogeffert

ogeffert

2020-09-03 09:03

reporter   ~0037636

This here - from the man page - made me set LC_ALL:

       *** WARNING *** The locale specified by the environment affects sort order. Set LC_ALL=C to
       get the traditional sort order that uses native byte values.
ManuelWolfshant

ManuelWolfshant

2020-09-03 09:07

manager   ~0037637

Ref " This here - from the man page - made me set LC_ALL:" I know. That is why I looked at that in the first place. But even with your settings ( ie. All LC_* being set to de_DE). I was not able to replicate the problem. Truth is I did NOT try "de_DE.UTF-8" but "de_DE".

Issue History

Date Modified Username Field Change
2020-09-02 20:55 ogeffert New Issue
2020-09-02 20:55 ogeffert Tag Attached: centos 7
2020-09-02 23:49 ManuelWolfshant Note Added: 0037625
2020-09-02 23:55 ManuelWolfshant Note Edited: 0037625 View Revisions
2020-09-02 23:55 ManuelWolfshant Note Edited: 0037625 View Revisions
2020-09-03 08:42 ogeffert Note Added: 0037628
2020-09-03 08:47 ogeffert Note Added: 0037630
2020-09-03 08:54 ManuelWolfshant Note Added: 0037632
2020-09-03 08:58 ogeffert Note Added: 0037634
2020-09-03 09:02 ogeffert Note Added: 0037635
2020-09-03 09:03 ogeffert Note Added: 0037636
2020-09-03 09:07 ManuelWolfshant Note Added: 0037637
2020-09-03 09:46 ManuelWolfshant Status new => closed
2020-09-03 09:46 ManuelWolfshant Resolution open => no change required