Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

locale - get locale-specific information

&pagelevel(4)&pagelevel

The locale command writes information about the current locale or other public locales to the standard output. In the following section, a public environment is an environment provided by the implementation that the application can access.

If locale is called without any arguments, it summarizes the current locale for each environment category as determined by the settings of the environment variables.

If the command is called with operands, it outputs values assigned to the keywords in the environment categories as follows:

  • If a keyword name is specified, the keyword as well as the category containing the keyword is output.

  • If a category name is specified, the category as well as all the keywords contained in it are output.


Syntax


Format 1:locale[ -a| -m]
Format 2:locale[ -ck] name...

Options

-a

Outputs information about all available public locales. The locales available include POSIX.

-c

Outputs the selected environment categories (see “Standard ouptput (stdout)”).
The -c option improves legibility if several categories are selected (e.g. using several keyword names or a category name). This option is valid with or without the specification of the -k option.

-k

Outputs the names and values of the selected keywords.

-m

Outputs the character map name.

name

The name of the environment category (see localedef on "localedef define local environment"), the name of a keyword in an environment category or the reserved name charmap. The specified category or the specified keyword can be specified as name operands in any order.

Locale

The following environment variables affect the execution of locale:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

File

Standard ouptput (stdout)

If locale is called without options or operands, the names and values of the LANG and LC_* environment variables are written to the standard output. One line is used for every variable, LANG is output first. Only variables set in the environment and not overwritten by LC_ALL are output in the following format:

"%s=%s\n", variable_name, value

The names of the LC_* variables not set in the environment or overwritten by the LC_ALL variable are output in the following format:

"%s=\"%s\"\n", variable_name, implied_value

implied_value is the name of the locale selected by the implementation for this category based on the values in LANG and LC_ALL.

value and implied_value are enclosed in single quotes so they can be reused as an entry some time in the future. value is not enclosed in double quotes (to differentiate it from implied_value, which is always enclosed in double quotes).

The LC_ALL variable is output last, using the first format outlined above. If this variable is not set, it is output in the following format:

"LC_ALL=\n"


The following points apply when specifying arguments:

  1. If the -a option is set, the names of all the public locales are output in the following format:

    "%s\n", locale_name

  2. If the -c option is specified, the names of all the selected categories are output in the following format:

    "%s\n", category_name

    If keywords were also selected, these are output immediately after the category to which they belong.

    If the -c option is not specified, only the keywords and not the category names are output.

  3. If the -k option is specified, the names and values of the selected keywords are output. If the value is non-numeric, it is output in the following format:

    "%s=\"%s=\"\n", keyword_name, keyword_value

    For the charmap keyword, the name of the character map is output if a character map was specified using the localedef -f option during the creation of the locale.
    charmap is used as keyword_name here.

    Numeric values are output in one of the following formats:

    "%s=%d\n", keyword_name, keyword_value
    "%s=%c%o\n", keyword_name, escape_character, keyword_value
    "%s=%cx%x\n", keyword_name, escape_character, keyword_value
    

    escape_character is the character defined by the escape_char keyword in the current locale.

    Keyword values that are combined (list entries) are separated by semicolons in the output. If the keyword values contain semicolons, double quotes, backslashes, and/or control characters, these characters are escaped using a preceding escape character.

  4. If the -k option is not specified, the values of all the keywords are output in the following format:

    "%s\n", keyword_value

    For the charmap keyword, the name of the character map is output (if available).

  5. If the -m option is specified, a list of all the available character maps is output in the following format:

    "%s\n", charmap

    The output can be used as an argument for the localedef -f option.

Exit status

0All the information requested was found and output.
>0An error occured.

Example

The examples are based on the following locales:

LANG=locale_x

LC_COLLATE=locale_Y

The locale command would have the following output:

LANG=locale_x
LC_CTYPE="locale_x"
LC_COLLATE=locale_Y
LC_TIME="locale_x"
LC_NUMERIC="locale_x"
LC_MONETARY="locale_x"
LC_MESSAGES="locale_x"
LC_ALL=

The LC_ALL=POSIX locale -ck decimal_point command would create the following output:

LC_NUMERIC

decimal_point="."

The following command shows a locale application that can be used to determine whether a response entered by a user is a yes-response (affirmation):

if printf "%s\n" "$response" | grep -Eq "$(locale yesexpr)"
then
      affirmative processing goes here
else
      non-affirmative processing goes here
fi

See also

localedef