How do I change a shell scripts character encoding?

Slowly, the Unix world is moving from ASCII and other regional encodings to UTF-8. You need to be running a UTF terminal, such as a modern xterm or putty.

In your ~/.bash_profile set you language to be one of the UTF-8 variants.

export LANG=C.UTF-8
or
export LANG=en_AU.UTF-8
etc..

You should then be able to write UTF-8 characters in the terminal, and include them in bash scripts.

#!/bin/bash
echo "UTF-8 is græat ☺"

See also: https://serverfault.com/questions/11015/utf-8-and-shell-scripts

Leave a Comment