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

Viewed 703

We have some Groovy scripts that we run from Git Bash (MINGW64) in Windows. Some scripts prints the bullet character • (or similar). To make it work we set this variable:

export LC_ALL=en_US.UTF-8

But, for some people, this is not enough. Its console prints ΓÇó instead of •.

Any idea about how to make it prints properly and why is printing that even after setting the LC_ALL variable?

Update

The key part is that the output from Groovy scripts is printing incorrectly, but there are no problems with the plain bash scripts.

1 Answers

An example with querying the current characters mapping locale charmap used by the system locale, and filtering the output with recode to render it with compatible characters mapping:

#!/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

With a charmap=ISO-8859-1 it renders as:

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

Alternate method using iconv instead of recode and results may even be better.

#!/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 output with an fr_FR.iso-8859-15@Euro locale:

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.
Related