Skip to content

Commit 8678f63

Browse files
authored
Ch09: add a warning about locale's influence on sort (#63)
1 parent 8ae277b commit 8678f63

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/Ch09/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ $ sort -n numbers
6969
15
7070
```
7171

72+
!!! warning "sort 的结果会受到本地化配置的影响"
73+
74+
在使用 sort 时,一个比如容易忽视的问题是当前的本地化配置对结果的影响。
75+
76+
```shell
77+
$ echo -e 'a b\naa' | LC_ALL=C sort
78+
a b
79+
aa
80+
$ echo -e 'a b\naa' | LC_ALL=en_US.UTF-8 sort
81+
aa
82+
a b
83+
```
84+
85+
为了获得传统意义上逐字节比较的结果,可以指定环境变量 `LC_ALL=C`。
86+
7287
!!! tip "小知识"
7388

7489
为什么有必要存在 `-o` 参数?试试重定向输出到原文件会发生什么吧。

0 commit comments

Comments
 (0)