Bash:即使在将语言环境设置为 UTF-8 后仍出现奇怪的字符:“•”打印为“ΓÇó”

Bash: Strange characters even after setting locale to UTF-8: "•" prints as "ΓÇó"

我们有一些 Groovy 脚本,我们 运行 来自 Git Bash (MINGW64) Windows。 一些脚本会打印项目符号字符 •(或类似字符)。 为了让它工作,我们设置了这个变量:

export LC_ALL=en_US.UTF-8

但是,对于某些人来说,这还不够。它的控制台打印 ΓÇó 而不是 .

关于如何使其正确打印以及为什么即使在设置 LC_ALL 变量后打印它的任何想法?

更新

关键部分是 Groovy 脚本的输出打印不正确,但普通 bash 脚本没有问题。

查询系统区域设置使用的当前字符映射locale charmap,并使用重新编码过滤输出以使用兼容字符映射呈现它的示例:

#!/usr/bin/env sh

cat <<EOF | recode -qf "UTF-8...$(locale charmap)"
• These are
• UTF-8 bullets in source
• But it can gracefully degrade with recode
EOF

使用 charmap=ISO-8859-1 它呈现为:

o These are
o UTF-8 bullets in source
o But it can gracefully degrade with recode

使用 iconv 而不是 recode 的替代方法,结果可能会更好。

#!/usr/bin/env sh

cat <<EOF | iconv -f 'UTF-8' -t "$(locale charmap)//TRANSLIT"
• These are
• UTF-8 bullets followed by a non-breaking space in source
• But it can gracefully degrade with iconv
• Europe's currency sign is € for Euro.
EOF

iconv 使用 fr_FR.iso-8859-15@Euro 语言环境的输出:

o These are
o UTF-8 bullets followed by a non-breaking space in source
o But it can gracefully degrade with iconv
o Europe's currency sign is € for Euro.