≡ Menu

Explains: echo Command (echo $”string”) Double-quoted String Preceded By a Dollar Sign

I noticed that many shell scripts in /etc/init.d/ directory use the following syntax:

echo $“Usage $prog start|stop|reload|restart”

Why a double-quoted string preceded by a dollar sign ($”string”) using the echo command under Linux / UNIX bash scripts?

Short answer – this is done to translate given string according to the current locale.

More About Locale

Your Linux script (or UNIX commands) may be used by all over the world in various languages other than English. Linux offers support different languages. You can setup local by editing your ~/.bashrc or ~/.bash_profile file. You need to set environment variables. You can set these variables to be system-wide, or on a per-session basis as follows:

  1. LC_ALL : Overrides all LC_* environment variables with the given value.
  2. LC_CTYPE : Character classification and case conversion.
  3. LC_COLLATE : Collation (sort) order.
  4. LC_TIME : Date and time formats.
  5. LANG :

See locale(7) man page for more information.

Say Hello To Unicode

The Unicode Consortium enables people around the world to use computers in any language. The specifications set by Unicode Consortium foundation for software internationalization are used in all major operating systems, search engines, applications, and the Web. Unicode solves the problems of multiple encodings by assigning unique code points to the letters and ideographs of all of the world’s modern language scripts and commonly used symbols. UTF-8 is a serialization method for Unicode that is the de facto standard for encoding Unicode on UNIX-based operating systems, notably Linux. See unicode.org for more information.

How Do I Display Current Settings?

Type the following command:
$ locale
Sample outputs:


Task: Find Out All Available Local Settings

To determine what other locale settings are available to you, type the following command:
$ locale -a
Sample outputs:


I’ve installed and using the following:

  1. hi_IN – Hindi is the official languages of the Indian Union Government and of many states in India.
  2. mr_IN – Marathi language spoken by the Marathi people of western and central India.
  3. en_IN – English (default) spoken and used by the Government and Business in India.

How Do I Change My Settings?

In this example, set it to a en_US.UTF-8 (change it from Indian English to US English i.e. en_US sets the language, and utf-8 sets the code page) environment set the following values in the profile:


Try to display the system date and time, enter:
$ date
Sample outputs:

Thu Oct 21 23:39:43 IST 2010

Now, run an application in UTF-8 Hindi locale then with bash shell, enter:
$ LANG=hi_IN.UTF-8
Display the system date and time, enter:
$ date
Sample outputs:

गुरु  अक्टूबर 21 23:41:07 IST 2010

In this example, mr_IN sets the language, and utf-8 sets the code page:
$ LANG=mr_IN.UTF-8
$ gedit

Sample outputs:

Fig.01: gedit using local Marathi language

Fig.01: gedit using local Marathi language

Shell Scripting Example

Create a shell script as follows :

### The location of the message catalog files ###
### our .mo file name ###
### Translate Hello!  string according to the current locale ###
echo $"Hello!"

(Code listing – 01: greet)

Note echo command with $”…” syntax. Save and close the file. Type the following commands to create language specific files:
$ bash --dump-po-strings greet > greet.pot
Create hi (Hindi), fr (French), and es (Spanish) language specific dirs:
$ mkdir {hi,fr,es}
Copy master greet.pot, enter:
$ cp greet.pot hi/
$ cp greet.pot fr/
$ cp greet.pot es/

Update Hindi language specific file as follows:
$ cat hi/greet.pot
Sample outputs:

#: greet:2
msgid "Hello!"
msgstr "नमस्ते!"

Update French language specific file as follows:
$ cat fr/greet.pot
Sample outputs:

#: greet:2
msgid "Hello!"
msgstr "Bonjour!"

Update Spanish language specific file as follows:
cat es/greet.pot
Sample outputs:

#: greet:2
msgid "Hello!"
msgstr "Hola!"

Compile message catalog to binary format, enter:
$ sudo msgfmt -o /usr/share/locale/hi/LC_MESSAGES/greet.mo hi/greet.pot
$ sudo msgfmt -o /usr/share/locale/fr/LC_MESSAGES/greet.mo fr/greet.pot
$ sudo msgfmt -o /usr/share/locale/es/LC_MESSAGES/greet.mo es/greet.pot

Test it as follows, set execute permission on your greet:
$ chmod +x greet
Test Hindi locale version
$ LANG=hi_IN ./greet
$ LANGUAGE=hi_IN ./greet
Test French locale version, enter:
$ LANGUAGE=fr_FR ./greet
Test Spanish locale version, enter:
$ LANGUAGE=es_ES ./greet
Sample outputs:

Fig.02: greet - a Bash shell script with localization support

Fig.02: greet - a Bash shell script with localization support


See the following man / info pages:
$ info gettext
$ man bash
$ man 7 locale
$ man 1 locale
$ man 1 msgfmt

Also see:

Share this tutorial on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 3 comments… add one }
  • Stefan Lasiewski October 22, 2010, 5:33 pm

    Why do I get question marks, and how can I resolve this? This is MacOSX 10.5 running Terminal.

    $ date
    ?? ?????? 22 10:32:49 PDT 2010

    • Pankaj Patel November 14, 2010, 4:05 pm

      This can be case that either that hindi character set is not present in the MacOSX.
      Try to see the help of MacOSX that it is having hindi char set or not.

  • Sepahrad Salour January 18, 2015, 6:31 am

    Thank you for your great and helpful post.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,