Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ch09: add a warning about locale's influence on sort #63

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading