How do I set the locale in the current terminal session?

I am trying to change the encoding in the current urxvt session by changing a variable LANG

. Be that as it may, it looks like it doesn't apply right away. That's what I'm doing:

Available locales:

$ locale -a
C
en_US.utf8
POSIX
ru_RU.koi8r
ru_RU.utf8

      

Before installing a new locale:

$ echo "" | od -t x1
0000000 d0 b0 0a # good! UTF-8
#       | a ||NL|

      

After:

$ export LANG=ru_RU.KOI8-R
$ echo "" | od -t x1
0000000 d0 b0 0a # hm..expect 'c1 0a'

      

Inject a new urxvt instance by running $ urxvt &

and finally get what I want:

$ echo "" | od -t x1
0000000 c1 0a

      

Why LANG

not change behavior in the first place?

+3


source to share


1 answer


There are two factors:

  • you can use a shell with inline echo (and don't tell the shell that you are changing locale)
  • LANG

    the first environment variable is not checked. According to locale(7)

    , it will be checked and . the first: LC_ALL

    LC_CTYPE

       If the second argument to setlocale (3) is an empty string, "", for
       the default locale, it is determined using the following steps:

       1. If there is a non-null environment variable LC_ALL, the value
              of LC_ALL is used.

       2. If an environment variable with the same name as one of the
              categories above exists and is non-null, its value is used for
              that category.

       3. If there is a non-null environment variable LANG, the value of
              LANG is used.

For the latter, view the output of the command locale

, which lists all the environment variables that will be used:



$ export LANG=ru_RU.KOI8-R
$ locale
LANG=ru_RU.KOI8-R
LANGUAGE=
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=en_US.UTF-8

      

A simple change shouldn't change other variables, but a change usually does. LANG

LC_ALL

$ export LC_ALL=ru_RU.KOI8-R
$ locale
LANG=ru_RU.KOI8-R
LANGUAGE=
LC_CTYPE="ru_RU.KOI8-R"
LC_NUMERIC="ru_RU.KOI8-R"
LC_TIME="ru_RU.KOI8-R"
LC_COLLATE="ru_RU.KOI8-R"
LC_MONETARY="ru_RU.KOI8-R"
LC_MESSAGES="ru_RU.KOI8-R"
LC_PAPER="ru_RU.KOI8-R"
LC_NAME="ru_RU.KOI8-R"
LC_ADDRESS="ru_RU.KOI8-R"
LC_TELEPHONE="ru_RU.KOI8-R"
LC_MEASUREMENT="ru_RU.KOI8-R"
LC_IDENTIFICATION="ru_RU.KOI8-R"
LC_ALL=ru_RU.KOI8-R

      

+4


source







All Articles