我有包含非 ascii 字符的目录,当我diff
使用它们时,diff 输出显示转义序列而不是 utf8 字符:
robert@saaz:~$ mkdir foo föö
robert@saaz:~$ echo 1 > foo/bar
robert@saaz:~$ echo 2 > föö/bar
robert@saaz:~$ diff -r f??
diff -r foo/bar "f\303\266\303\266/bar"
1c1
< 1
---
> 2
我期望的不是f\303\266\303\266/bar
diff 输出的第一行föö
。
我使用的是 Ubuntu 20.04,diff 3.7:
robert@saaz:~$ diff --version
diff (GNU diffutils) 3.7
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.
当我使用ls
(即使使用clearing LS_OPTIONS
)查看目录时,它们按预期显示为 utf8 字符:
robert@saaz:~$ LS_OPTIONS=x ls -ld f??
drwxrwxr-x 2 robert robert 4.0K 2020-08-06 17:38 foo
drwxrwxr-x 2 robert robert 4.0K 2020-08-06 17:39 föö
我的语言环境都是 utf8:
robert@saaz:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=en_US.UTF-8
如何diff
同时显示非 ASCII 字符?
答案1
这是 GNU diff 实现中的一个问题。
您可以使用 UNIX diff 实现来代替gdiff
。
UNIX diff 命令的便携版本是 schilytools 的一部分,请检查:
/usr/bin/diff -r f??
diff -r foo/a "f\366\366/a"
1c1
< a
---
> b
与:
/opt/schily/ccs/bin/diff -r f??
diff -r foo/a föö/a
1c1
< a
---
> b
/opt/schily/ccs/bin/diff -version
diff schily-SCCS version 5.09 2020/07/14 (x86_64-unknown-linux-gnu)