The locale program will print the locale variables of the process that launched it, this is a sample output of locale when launched from the shell:


Where does locale get this information from (I know that this information is not locale's inherited environment variables from the shell, because the shell only has 4 locale environment variables)?

2 Answers 2


It gets it by knowing how locale settings are processed, based on the values of the corresponding environment variables.

Taking the GNU version as an example, it starts by calling setlocale (LC_ALL, "") to set the current locale. Then it goes through all the locale categories, printing the value of each one in turn, with special exceptions for LANG (printed first) and LC_ALL (printed last). The values are determined by looking at the environment values and following the rules which apply to the locale settings:

  • if LC_ALL is set, all categories take the corresponding value;
  • if a category has no value set in the environment, it takes the value of LANG if it has one, “POSIX” otherwise and the value is enclosed in double-quotes.
  • So if a process have its current locale variables different from its locale variables in the environment variables, and the process launched the locale program, then the locale program will only output the locale variables in the environment variables, correct?
    – James
    Jun 12, 2018 at 17:09
  • @James more or less. Locale settings aren’t inherited, yes, in particular because all processes run the equivalent of setlocale(LC_ALL, "C") when they start. The locale program will output the locales corresponding to whatever variables are present in the environment it was given (which is determined by the program which starts locale). Jun 12, 2018 at 17:15

The locale program prints it's results based on the environment variables.

The output you listed contains non-standard locales that may be Linux specific.

In order to understand how this works, it may be important to know:

  • LC_ALL overwrites all other explicit LC_* variables in the environment.

  • LANG is used as a fallback if a specific LC_XXX variable is not in the environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.