簡體   English   中英

Bash:如何排序路徑?

[英]Bash: how does 'sort' sort paths?

sort如何工作? 我有這個文件:

/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/ ...而我卻得不到它。 我想理解為什么排序認為這是排序的。


注意:它適用於其他樣本:

/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嘗試在本地化方面很聰明。 它會忽略一些非字母數字字符,如/等等。 該手冊頁有一個簡短的句子:

*警告*環境指定的區域設置會影響排序順序。 設置LC_ALL = C以獲取使用本機字節值的傳統排序順序。

那么,要解決您的問題:

$ cat foobar | LC_ALL=C sort

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM