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

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


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

Also see:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Stefan Lasiewski Oct 22, 2010 @ 17:33

    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 Nov 14, 2010 @ 16:05

      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 Jan 18, 2015 @ 6:31

    Thank you for your great and helpful post.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum