当“LANG”未设置时,为什么“sort”表现得很奇怪?

时间:2015-01-31 08:22:16

标签: linux sorting

在我的bash中," LANG"被设置为" en_us.UTF-8"和"排序"工作良好。但是,如果我解开" LANG",那么" sort"很奇怪。即使用" LC_ALL = C"或" LC_ALL = POSIX"。任何人都知道为什么"排序" " LANG"" LANG"没设置?

$ echo $LANG
en_US.UTF-8

$ sort -t$'\t' -k1,3 -gr
-4.445905   1   0.965933
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152
-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702

-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   1   0.965933
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152

$ unset LANG

$ sort -t$'\t' -k1,3 -gr
-4.445905   1   0.965933
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152
-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702

-4.445905   1   0.965933
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152
-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702

$ LC_ALL=POSIX sort -t$'\t' -k1,3 -gr
-4.445905   1   0.965933
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152
-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702

-4.445905   1   0.965933
-4.445905   1   0.76126
-4.445905   1   0.74816
-4.445905   1   0.633251
-4.445905   1   0.596921
-4.445905   1   0.464271
-4.445905   1   0.406553
-4.445905   1   0.350968
-4.445905   1   0.307701
-4.445905   1   0.188411
-4.445905   1   0.0377354
-4.445905   1   0.0221152
-4.445905   -1  0.999663
-4.445905   -1  0.987287
-4.445905   -1  0.97882
-4.445905   -1  0.969835
-4.445905   -1  0.96705
-4.445905   -1  0.964982
-4.445905   -1  0.920791
-4.445905   -1  0.901001
-4.445905   -1  0.877351
-4.445905   -1  0.87702

1 个答案:

答案 0 :(得分:1)

显然我没有正确理解排序键选项" -k"。它实际上是从POS1到POS2包括"所以" -k 1,3"表示使用键column1 + column2 + column3进行排序。因此,后两个"排序"正在做正确的事情,而第一个实际上很奇怪。