linux的sort命令的异常行为 [英] Unusual behaviour of linux's sort command

查看:167
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆