Перейти к содержимому

Lc all c что это

  • автор:

International Language Environments Guide for Oracle ® Solaris 11.4

A key concept for application programs is that of a program’s locale. The locale is an explicit model and definition of a native-language environment. The notion of a locale is explicitly defined and included in the POSIX standard which can be accessed through https://www.opengroup.org/.

A locale consists of a number of categories for which country-dependent formatting or other specifications exist. A program’s locale defines its code sets, date and time formatting conventions, monetary conventions, decimal formatting conventions, and collation (sort) order.

A locale name can be composed of a base language, country (territory) of use, and codeset. For example, German language is de, an abbreviation for Deutsch, while Swiss German is de_CH, CH being an abbreviation for Confederation Helvetica. This convention allows for specific differences by country, such as currency unit notation. In Oracle Solaris 11, the default locale codeset is UTF-8, an ASCII compatible 8-bit encoding form of Unicode. The fully defined locale name for Swiss German would thus be de_CH.UTF-8.

More than one locale can be associated with a particular language, which allows for regional differences. For example, an English-speaking user in the United States can select the en_US.UTF-8 locale (English for the United States), while an English-speaking user in Great Britain can select en_GB.UTF-8 (English for Great Britain).

Generally, the locale name is specified by the LANG environment variable. Locale categories are subordinate to LANG but can be set separately, in which case they override LANG. If the LC_ALL environment variable is set, it overrides LANG and all the separate locale categories.

The locale naming convention is:

where language is a two-letter code from ISO 639, territory is a two-letter code from ISO 3166, codeset is the name of the codeset that is being used in the locale, and modifier is the name of the characteristics that differentiate the locale from the locale without the modifier.

All Oracle Solaris product locales preserve the Portable Character Set characters with US-ASCII code values.

For more information about the portable character set, refer to X/Open CAE Specification: System Interface Definitions, Issue 5″ (ISBN 1-85912-186-1).

A single locale can have more than one locale name. For example, POSIX is the same locale as C.

C, POSIX, and C.UTF-8 Locales

The C locale, also known as the POSIX locale, is the default system locale for all POSIX-compliant systems. The Oracle Solaris operating system is a POSIX system. The Single UNIX Specification, Version 3, defines the C locale. You can register at http://www.unix.org/version3/online.html to read and download the specification.

The C.UTF-8 locale is an update to the POSIX standards-compliant C locale that adds the UTF-8 character set. Only the following environment variable values differ from the C locale:

LC_CTYPE – Covers all Unicode characters

LC_COLLATION – Sorts based on the Unicode character code points

To specify your internationalized programs to run in the C locale, perform one of the following:

Unset all locale environment variables. Runs the application in the C locale.

Explicitly set the locale to C or POSIX.

Some applications check the LANG environment variables without actually calling setlocale(3C) to reference the current locale. In this case, the shell is explicitly set to the C locale by specifying the LC_ALL and LANG locale environment variables. For the precedence relationship among locale environment variables, see the setlocale(3C) man page.

To check the current locale settings in a terminal environment, run the locale(1) command.

Locale Categories

The following list describes the types of locale categories:

Specifies character classification and case conversion.

Specifies date and time formats, including month names, days of the week, and common full and abbreviated representations.

Specifies monetary formats, including the currency symbol for the locale, thousands separator, sign position, the number of fractional digits, and so forth.

Specifies the decimal delimiter (or radix character), the thousands separator, and the grouping.

Specifies a collation order and regular expression definition for the locale.

Specifies the language in which the localized messages are written, and affirmative and negative responses of the locale (yes and no strings and expressions).

Specifies the layout engine that provides information about language rendering. Language rendering (or text rendering) depends on the shape and direction attributes of a script.

What does "LC_ALL=C" do?

What does the C value for LC_ALL do in Unix-like systems?

I know that it forces the same locale for all aspects but what does C do?

/.bashrc file — export LC_ALL=C.UTF-8

6 Answers 6

LC_ALL is the environment variable that overrides all the other localisation settings (except $LANGUAGE under some circumstances).

Different aspects of localisations (like the thousand separator or decimal point character, character set, sorting order, month, day names, language or application messages like error messages, currency symbol) can be set using a few environment variables.

You’ll typically set $LANG to your preference with a value that identifies your region (like fr_CH.UTF-8 if you’re in French speaking Switzerland, using UTF-8). The individual LC_xxx variables override a certain aspect. LC_ALL overrides them all. The locale command, when called without argument gives a summary of the current settings.

For instance, on a GNU system, I get:

I can override an individual setting with for instance:

Or override everything with LC_ALL.

In a script, if you want to force a specific setting, as you don’t know what settings the user has forced (possibly LC_ALL as well), your best, safest and generally only option is to force LC_ALL.

The C locale is a special locale that is meant to be the simplest locale. You could also say that while the other locales are for humans, the C locale is for computers. In the C locale, characters are single bytes, the charset is ASCII (well, is not required to, but in practice will be in the systems most of us will ever get to use), the sorting order is based on the byte values¹, the language is usually US English (though for application messages (as opposed to things like month or day names or messages by system libraries), it’s at the discretion of the application author) and things like currency symbols are not defined.

On some systems, there’s a difference with the POSIX locale where for instance the sort order for non-ASCII characters is not defined.

You generally run a command with LC_ALL=C to avoid the user’s settings to interfere with your script. For instance, if you want [a-z] to match the 26 ASCII characters from a to z , you have to set LC_ALL=C .

On GNU systems, LC_ALL=C and LC_ALL=POSIX (or LC_MESSAGES=C|POSIX ) override $LANGUAGE , while LC_ALL=anything-else wouldn’t.

A few cases where you typically need to set LC_ALL=C :

sort -u or sort . | uniq. . In many locales other than C, on some systems (notably GNU ones), some characters have the same sorting order. sort -u doesn’t report unique lines, but one of each group of lines that have equal sorting order. So if you do want unique lines, you need a locale where characters are byte and all characters have different sorting order (which the C locale guarantees).

the same applies to the = operator of POSIX compliant expr or == operator of POSIX compliant awk s ( mawk and gawk are not POSIX in that regard), that don’t check whether two strings are identical but whether they sort the same.

Character ranges like in grep . If you mean to match a letter in the user’s language, use grep ‘[[:alpha:]]’ and don’t modify LC_ALL . But if you want to match the a-zA-Z ASCII characters, you need either LC_ALL=C grep ‘[[:alpha:]]’ or LC_ALL=C grep ‘[a-zA-Z]’ ². [a-z] matches the characters that sort after a and before z (though with many APIs it’s more complicated than that). In other locales, you generally don’t know what those are. For instance some locales ignore case for sorting so [a-z] in some APIs like bash patterns, could include [B-Z] or [A-Y] . In many UTF-8 locales (including en_US.UTF-8 on most systems), [a-z] will include the latin letters from a to y with diacritics but not those of z (since z sorts before them) which I can’t imagine would be what you want (why would you want to include é and not ź ?).

floating point arithmetic in ksh93 . ksh93 honours the decimal_point setting in LC_NUMERIC . If you write a script that contains a=$((1.2/7)) , it will stop working when run by a user whose locale has comma as the decimal separator:

Then you need things like:

As a side note: the , decimal separator conflicts with the , arithmetic operator which can cause even more confusion.

When you need characters to be bytes. Nowadays, most locales are UTF-8 based which means characters can take up from 1 to 6 bytes³. When dealing with data that is meant to be bytes, with text utilities, you’ll want to set LC_ALL=C. It will also improve performance significantly because parsing UTF-8 data has a cost.

a corollary of the previous point: when processing text where you don’t know what character set the input is written in, but can assume it’s compatible with ASCII (as virtually all charsets are). For instance grep ‘<.*>’ to look for lines containing a < , > pair will no work if you’re in a UTF-8 locale and the input is encoded in a single-byte 8-bit character set like iso8859-15. That’s because . only matches characters and non-ASCII characters in iso8859-15 are likely not to form a valid character in UTF-8. On the other hand, LC_ALL=C grep ‘<.*>’ will work because any byte value forms a valid character in the C locale.

Any time where you process input data or output data that is not intended from/for a human. If you’re talking to a user, you may want to use their convention and language, but for instance, if you generate some numbers to feed some other application that expects English style decimal points, or English month names, you’ll want to set LC_ALL=C:

That also applies to things like case insensitive comparison (like in grep -i ) and case conversion ( awk ‘s toupper() , dd conv=ucase . ). For instance:

is not guaranteed to match on I in the user’s locale. In some Turkish locales for instance, it doesn’t as upper-case i is İ (note the dot) there and lower-case I is ı (note the missing dot).

Notes

¹ again, only on ASCII based systems (the immense majority of systems). POSIX requires the collation order for the C locale to be that of the order of characters in the ASCII charset, even on EBCDIC systems which are not allowed to do the strcoll() === strcmp() optimisation in the C locale.

² Depending on the encoding of the text, that’s not necessarily the right thing to do though. That’s valid for UTF-8 or single-byte character sets (like iso-8859-1), but not necessarily non-UTF-8 multibyte character sets.

For instance, if you’re in a zh_HK.big5hkscs locale (Hong Kong, using the Hong Kong variant of the BIG5 Chinese character encoding), and you want to look for English letters in a file encoded in that charsets, doing either:

would be wrong, because in that charset (and many others, but hardly used since UTF-8 came out), a lot of characters contain bytes that correspond to the ASCII encoding of A-Za-z characters. For instance, all of A䨝䰲丕乙乜你再劀劈呸哻唥唧噀噦嚳坽 (and many more) contain the encoding of A . 䨝 is 0x96 0x41, and A is 0x41 like in ASCII. So our LC_ALL=C grep ‘[a-zA-Z]’ would match on those lines that contain those characters as it would misinterpret those sequences of bytes.

would work, but only if LC_ALL is not otherwise set (which would override LC_COLLATE ). So you may end up having to do:

if you wanted to look for English letters in a file encoded in the locale’s encoding.

³ some would argue it’s rather 1 to 4 bytes these days now that Unicode code points (and the libraries that encode/decode UTF-8 data) have been arbitrarily restricted to code points U+0000 to U+10FFFF (0xD800 to 0xDFFF excluded) down from U+7FFFFFFF to accommodate the UTF-16 encoding, but some applications will still happily encode/decode 6-byte UTF-8 sequences (including the ones that fall in the 0xD800 .. 0xDFFF range).

Запуск программ без перевода (без локализации) в Linux

Запуск программ в Linux без локализации

Если у вас Linux на русском языке, например, вы используете Ubuntu с русской локализацией, тогда все программы будут запускаться на русском языке, которые переведены, конечно. Но иногда нужно запустить программу на родном языке (это почти всегда английский).

Например, если программа переведена не полностью и половинная локализация только все портит или, например, вы читаете руководство по программе, которое написано на основе английской версии и вам трудно понять какие пункты меню соответствуют аналогам на английском. Иногда, отсутствие перевода программы на нужный язык может приводить к серьезным проблемам. Подобных примеров можно привести много. Рассмотрим, как запустить программу без перевода на русский (или другой) язык.

Есть несколько способов запуска программы без перевода, но я рассмотрю самый простой. Для этого в начале выполняемой в терминале команды вам нужно добавить выражение «LC_ALL=C». Это указывает на то, что программу нужно запустить в так называемой POSIX локализации. Например, чтобы запустить GIMP на английском языке выполните в терминале:

Или, например, чтобы запустить калькулятор в Ubuntu 12.04 без перевода на русский язык, выполните команду:

Кстати, без перевода на русский язык программы смотрятся более компактно. Посмотрите на картинку в начале статьи, в английской версии GIMP уместилось 6 пунктов меню, а в русской только 4.

Locale

Locales are used by glibc and other locale-aware programs or libraries for rendering text, correctly displaying regional monetary values, time and date formats, alphabetic idiosyncrasies, and other locale-specific standards.

Generating locales

Locale names are typically of the form language[_territory][.codeset][@modifier] , where language is an ISO 639 language code, territory is an ISO 3166 country code, and codeset is a character set or encoding identifier like ISO-8859-1 or UTF-8. See setlocale(3) .

For a list of enabled locales, run:

Before a locale can be enabled on the system, it must be generated. This can be achieved by uncommenting applicable entries in /etc/locale.gen , and running locale-gen. Equivalently, commenting entries disables their respective locales. While making changes, consider any localisations required by other users on the system, as well as specific #Variables.

For example, uncomment en_US.UTF-8 UTF-8 for American-English:

Save the file, and generate the locale:

  • locale-gen also runs with every update of glibc . [1]
  • UTF-8 is recommended over other character sets. [2]

Setting the locale

To display the currently set locale and its related environmental settings, type:

The locale to be used, chosen among the previously generated ones, is set in locale.conf files. Each of these files must contain a new-line separated list of environment variable assignments, having the same format as output by locale.

To list available locales which have been previously generated, run:

Setting the system locale

To set the system locale, write the LANG variable to /etc/locale.conf , where en_US.UTF-8 belongs to the first column of an uncommented entry in /etc/locale.gen :

Overriding system locale per user session

The system-wide locale can be overridden in each user session by creating or editing $XDG_CONFIG_HOME/locale.conf (usually

The precedence of these locale.conf files is defined in /etc/profile.d/locale.sh .

  • This can also allow keeping the logs in /var/log/ in English while using the local language in the user environment.
  • You can create a /etc/skel/.config/locale.conf file so that any new users added using useradd and the -m option will have

Make locale changes immediate

Once system and user locale.conf files have been created or edited, their new values will take effect for new sessions at login. To have the current environment use the new settings unset LANG and source /etc/profile.d/locale.sh :

Other uses

Locale variables can also be defined with the standard methods as explained in Environment variables.

For example, in order to test or debug a particular application during development, it could be launched with something like:

Similarly, to set the locale for all processes run from the current shell (for example, during system installation):

Variables

locale.conf files support the following environment variables.

Full meaning of the above LC_* variables can be found on manpage locale(7) , whereas details of their definition are described on locale(5) .

LANG: default locale

The locale set for this variable will be used for all the LC_* variables that are not explicitly set.

LANGUAGE: fallback locales

Programs which use gettext for translations respect the LANGUAGE option in addition to the usual variables. This allows users to specify a list of locales that will be used in that order. If a translation for the preferred locale is unavailable, another from a similar locale will be used instead of the default. For example, an Australian user might want to fall back to British rather than US spelling:

LC_TIME: date and time format

If LC_TIME is set to en_US.UTF-8 , for example, the date format will be «MM/DD/YYYY». If wanting to use the ISO 8601 date format of «YYYY-MM-DD» use:

You can print the current timestamp using your locale date and time format with date +»%c» .

glibc 2.29 fixed a bug, en_US.UTF-8 started showing in 12-hour format, as was intended. If wanting to use 24-hour format, use LC_TIME=C.UTF-8 .

LC_COLLATE: collation

This variable governs the collation rules used for sorting and regular expressions.

Setting the value to C can for example make the ls command sort dotfiles first, followed by uppercase and lowercase filenames:

To get around potential issues, Arch used to set LC_COLLATE=C in /etc/profile , but this method is now deprecated.

LC_ALL: troubleshooting

The locale set for this variable will always override LANG and all the other LC_* variables, whether they are set or not. If LC_ALL is set to C , it will also override LANGUAGE .

LC_ALL is the only LC_* variable which cannot be set in locale.conf files: it is meant to be used only for testing or troubleshooting purposes, for example in /etc/profile .

Troubleshooting

My system is still using wrong language

It is possible that the environment variables are redefined in other files than locale.conf . See Environment variables#Defining variables for details.

If you are using a desktop environment, such as GNOME, its language settings may be overriding the settings in locale.conf .

KDE Plasma also allows to change the UI’s language through the system settings. If the desktop environment is still using the default language after the modification, deleting the file at

/.config/plasma-locale-settings.sh ) should resolve the issue.

If you are using a display manager in combination with accountsservice , follow the instructions in Display manager#Set language for user session.

LightDM will automatically use accountsservice to set a user’s locale if it is installed. Otherwise, LightDM stores the user session configuration in

/.dmrc . It is possible that an unwanted locale setting is retrieved from there as well.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *