LC_ALL=C的含义

在不少的shell脚本中,咱们常常会看见某一句命令的前面有一句“LC_ALL=C”
SAR_CMD="LC_ALL=C sar -u -b 1 5 | grep -i average "
这究竟是什么意思?
LC_ALL=C 是为了去除全部本地化的设置,让命令能正确执行。
---------------------------------

在Linux中经过locale来设置程序运行的不一样语言环境,locale由ANSI C提供支持。locale的命名规则为<语言>_<地区>.<字符集编码>,如zh_CN.UTF-8,zh表明中文,CN表明大陆地区,UTF-8表示字符集。html

 

在locale环境中,有一组变量,表明国际化环境中的不一样设置linux

1.    LC_COLLATE
定义该环境的排序和比较规则shell

2.    LC_CTYPE
用于字符分类和字符串处理,控制全部字符的处理方式,包括字符编码,字符是单字节仍是多字节,如何打印等。是最重要的一个环境变量。app

3.    LC_MONETARY
货币格式ide

4.    LC_NUMERIC
非货币的数字显示格式ui

5.    LC_TIME
时间和日期格式this

6.    LC_MESSAGES
提示信息的语言。另外还有一个LANGUAGE参数,它与LC_MESSAGES类似,但若是该参数一旦设置,则LC_MESSAGES参数就会失效。LANGUAGE参数可同时设置多种语言信息,如LANGUANE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"。编码

7.    LANG
LC_*的默认值,是最低级别的设置,若是LC_*没有设置,则使用该值。相似于 LC_ALL。spa

8.    LC_ALL
它是一个宏,若是该值设置了,则该值会覆盖全部LC_*的设置值。注意,LANG的值不受该宏影响orm

"C"是系统默认的locale,"POSIX"是"C"的别名。因此当咱们新安装完一个系统时,默认的locale就是C或POSIX

 

"POSIX" :Specifies the minimal environment for C-language translation called the POSIX locale. If setlocale() is not invoked, the POSIX locale is the default "C"  Equivalent to "POSIX".-----------------------------------
How to view the current locale setting?
# locale
How to change the locale setting?
* Via the CDE login locale
* As a user-specific locale
* As a system default locale
To change the current locale setting, first confirm that the desired locale is
installed on the system with:
# locale -a
de
en_AU
en_CA
en_UK
C
If the desired locale is not in the list, you will need to install the
appropriate packages for that locale. See the Note below for more information
about locale packages.

How to change the locale via the CDE login locale?
On the CDE login banner:
Choose options - languages
Under languages - choose the new locale
The CDE banner will re-cycle and then you can login to the selected locale.

NOTE: If a user has a different default locale set in their environment, the
that locale setting will override the selected CDE login locale.

How to set a user-specific locale?
Note:
For sh, ksh:
# LANG=C; export LANG
# LC_ALL=C; export LC_ALL
For csh:
# setenv LANG C
# setenv LC_ALL C

Note: To set a default locale for a user's environment, set the LANG or LC_*
variables in a user's shell intialization file such as $HOME/.profile or
$HOME/.cshrc
How to change the locale by setting the system default locale?
LANG=C
LC_ALL=C

Example from the /etc/default/init file:

# Lines of this file should be of the form VAR=value, where VAR is one of
# TZ, LANG, or any of the LC_* environment variables.
LANG=C
LC_ALL=C

Note: The system must be rebooted after making changes to the
/etc/default/init file in order for the changes to take effect.

How to verify the locale setting?
After setting or changing the locale, verify that the locale is set correctly:
Check if the locale is set correctly by running the locale command without any
options:
# locale
LANG=C
LC_CTYPE= "C"
LC_NUMERIC= "C"
LC_TIME= "C"
LC_COLLATE= "C"
LC_MONETARY= "C"
LC_MESSAGES= "C"
LC_ALL=C

Locale是某一个地域内的人们的语言习惯和文化传统和生活习惯,是根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统所定义的一个软件运行时的语言环境。 
Locale是软件在运行时的语言环境, 它包括语言(Language), 地域 (Territory) 和字符集(Codeset)。一个locale的书写格式为: 语言[_地域[.字符集]]。彻底的locale表达方式是 [语言[_地域][.字符集] [@修正值]。zh_CN.GB2312=中文_中华人民共和国+国标2312字符集。 


locale的设定:   
LC_ALL和LANG优先级的关系: LC_ALL > LC_* >LANG   
一、若是须要一个纯中文的系统的话,设定LC_ALL= zh_CN.XXXX,或者LANG=zh_CN.XXXX均可以。  
二、若是只想要一个能够输入中文的环境,而保持菜单、标题,系统信息等等为英文界面,那么只须要设定 LC_CTYPE=zh_CN.XXXX,LANG=en_US.XXXX就能够了。  
三、假如什么也不作的话,也就是LC_ALL,LANG和LC_*均不指定特定值的话,系统将采用POSIX做为lcoale,也就是C locale。  
LANG和LANGUAGE的区别:   
LANG - Specifies the default locale for all unset locale variables  
LANGUAGE - Most programs use this for the language of its interface  
LANGUAGE是设置应用程序的界面语言。而LANG是优先级很低的一个变量,它指定全部与locale有关的变量的默认值  
相关文章
相关标签/搜索