linux的sort命令的异常行为 [英] Unusual behaviour of linux's sort command
本文介绍了linux的sort命令的异常行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Linux shell上,echo -e "arrays2 2\narrays 2\narrays3 2" | sort
的结果为
On Linux shell the result of echo -e "arrays2 2\narrays 2\narrays3 2" | sort
is
arrays 2
arrays2 2
arrays3 2
,echo -e "arrays2 28\narrays 28\narrays3 28" | sort
的结果是
arrays2 28
arrays 28
arrays3 28
为什么在第二种情况下字符串arrays2 28
出现在第一行.
这是一个错误,还是我错过了什么?
Why in the second case the string arrays2 28
appears on first line.
Is this a bug, or I miss something?
我在RHEL4和Ubuntu 11.04上进行了尝试.
I tried this on RHEL4 and Ubuntu 11.04.
谢谢.
推荐答案
行为与语言环境有关:
echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=C sort
打印
arrays 28
arrays2 28
arrays3 28
而
echo -e "arrays2 28\narrays 28\narrays3 28" | LANG=de_DE.UTF-8 sort
打印
arrays2 28
arrays 28
arrays3 28
(请注意,必须安装语言环境才能产生此效果,如果该语言环境不存在,其行为将与LANG=C
相同).
(Note that the locale must be installed for this to have this effect, if the locale doesn't exist, the behaviour will be the same as with LANG=C
).
这篇关于linux的sort命令的异常行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文