What is the proper way of inserting a copyright symbol ©
and a pound sterling symbol £
into a bash script.
I am using nano
as my editor and am running Debian Squeeze.
If I copy and paste the symbol from windows, it works but it seems to paste hidden characters that nano
cannot display and it makes it hard to edit code in the shell script then.
So for example I want to be able to do this:-
text="£15.00"
text2="© John Doe"
It seems you are using a locale that doesn't support these symbols (in the olden days it could have also been a bad font). Since you are using UTF-8 characters (default on windows), you also need to be in a UTF-8 aware environment on linux. You can check that with the locale
command:
$ locale
LANG=en_US.UTF-8
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=
So my system is fine, but yours had the default, ASCII C locale set. These are simple bash
variables, so you could export
them individually or override them all (by setting LC_ALL
). However, that would only affect the current shell, so you need to make it part of shell initialisation to work everytime automatically.
This is usually done through profile scripts in /etc
globally, but .bash_profile
or .bashrc
would work just as well. In your version of Debian the locale is stored in /etc/default/locale
and you can get the list of available choices with locale -a
, eg.:
$ locale -a
C
en_US
en_US.iso88591
en_US.utf8
POSIX
sl_SI.utf8
Pick one with an utf8 suffix. If you need other locales (for example japanese), they can be generated with localedef/locale-gen (comes with glibc
or as a separate package).