Skip to content

Commit

Permalink
Ch09: add a warning about locale's influence on sort
Browse files Browse the repository at this point in the history
  • Loading branch information
kxxt committed Dec 27, 2024
1 parent 8ae277b commit a3b1541
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/Ch09/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ $ sort -n numbers
15
```

!!! warning "sort 的结果会受到本地化配置的影响"

在使用 sort 时,一个比如容易忽视的问题是当前的本地化配置对结果的影响。

```shell
$ echo -e 'a b\naa' | LC_ALL=C sort
a b
aa
$ echo -e 'a b\naa' | LC_ALL=en_US.UTF-8 sort
aa
a b
```

为了获得传统意义上逐字节比较的结果,可以指定环境变量 `LC_ALL=C`。

!!! tip "小知识"

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

0 comments on commit a3b1541

Please sign in to comment.