排序
是如何工作的?我有这个文件:
/test# cat foobar
html/lib/ORM/aaa.php
html/lib/ORMBase/ormbase_aaa.php
html/lib/ORM/zzz.php
html/lib/ORMBase/ormbase_zzz.php
这是sort
的输出:
/test# cat foobar | sort
html/lib/ORM/aaa.php
html/lib/ORMBase/ormbase_aaa.php
html/lib/ORMBase/ormbase_zzz.php
html/lib/ORM/zzz.php
我尝试了很多选项:-f
、-i
、-t/
...但我不明白。我想了解为什么 sort 认为这是已排序的。
注意:它适用于其他示例:
/test# cat foobar2
a/a/a
a/ab/a
a/ab/b
a/a/ab
a/abc/a
/test# cat foobar2 | sort
a/a/a
a/a/ab
a/ab/a
a/ab/b
a/abc/a
最佳答案
sort
试图在本地化方面变得聪明。它会忽略一些非字母数字字符,如 /
等。手册页对此有一个简短的句子:
* 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.
因此,要解决您的问题:
$ cat foobar | LC_ALL=C sort
关于Bash: 'sort' 如何对路径进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31938751/