环境变量

Persistent environment variables 
So far we've only discussed ways set an environment variable value
temporarily until the shell session in which it was set is closed. One
may wonder if there is a way to somehow permanently set an environment
variable to a certain value.
The way to achieve that is to place a command setting on an environment
variable value in one of the script files that get executed
automatically in one of the stages of the system and user's session
startup processes. Along with the inheritance principle , this ensures the value is seen by applications loaded at later stages.
Session-wide environment variables 
In order to set environment variables in a way that effects a user's
entire desktop session, one may place commands to set their values in
one of the "hidden" script files in the user's home directory. The more
common such files are outlined below.

  • ~/.profile' - This is probably the best file for placing
    environment variable assignments in, since it gets executed
    automatically by the Display'
    Manager during the startup process desktop session as well as by the login shell when one logs-in from the textual console.
  • ~/.bash_profile  or ~./bash_login  - If one of
    these file exist, bash executes it rather then "~/.profile" when it is
    started as a login shell. (Bash will prefer "~/.bash_profile" to
    "~/.bash_login"). However, these files won't influence a graphical
    session by default.
  • ~/.bashrc  - Because of the way Ubuntu currently sets
    up the various script files by default, this may be the easiest place
    to set variables in. The default configuration nearly guarantees that
    this file will be executed in each and every invocation of bash as well
    as while logging in to the graphical environment. However,
    performance-wise this may not be the best thing to do since it will
    cause values to be unnecessarily set many times.


System-wide environment variables 
Environment variable settings that effect the system as a whole
(rather then just a particular user's desktop session) can be placed in
any of the many system-level scripts that get executed when the system
or the desktop session are loaded. Ubuntu defines several locations
dedicated to placing such settings:

  • /etc/profile' - This file gets executed whenever a bash
    login shell is entered (e.g. when logging in from the console or over
    ssh), as well well as by the Display'
    Manager when the desktop
    session loads. This is probably the file you will get referred to when
    asking veteran UNIX system administrators about environment variables.
    In Ubuntu, however this file does little more then invoke the /etc/bash.bashrc  file.
  • /etc/bash.bashrc  - This is is the system-wide version of the ~/.bashrc  file. Ubuntu is configured by default to execute this file whenever a user enters a shell or the desktop environment.
  • /etc/environment  - This file is specifically meant for
    system-wide environment variable settings. It is not a script file, but
    rather consists of assignment expressions, one per line. Specifically,
    this file stores the system-wide locale and path settings.

 


Note:  When dealing with end-user/home desktop systems it is
probably best to place settings in the session-wide files discussed
above rather then the system-wide ones since those files do not require
one to utilize root privileges in order to edit.
List of common environment variables 
Each application is free to define and use its own environment
variables. Many manual pages include long lists of environment
variables that can effect the behaviour of the application they
describe. However, the most useful variables are common to many
applications.
File-location related variables 
The following variables determine how the system locates various files in order to operate. 
Variable Value Examples What it's for
PATH/usr/sbin:/usr/bin:/sbin:/binWhen you type a command to run, the system looks for it in the directories specified by PATH in the order specified
MANPATH/usr/share/man:/usr/local/manList of directories for the system to search manual pages in
LD_LIBRARY_PATH/opt/app/oracle/libList of directories where the system searches for runtime libraries in addition to those hard-defined in ld  and in /etc/ld.so.conf
TMPDIR/var/tmpThe directory used for temporary file creation by several programs
Locale setting variables 
The following environment variables determine the locale-related
behavior of the systems such as the language of messages sent to the
user and the way times and dates are presented.
The values that can assigned to the locale environment variables are
names of locale setting packages installed on the systems. To see which
such packages are installed on the system, one can use the locale -a command. Locale setting packages can be generated with the locale-gen
command. However, Ubuntu includes pre-generated locale setting packages
in the language-pack packages available within the package management
system.
Variable What it's for
LANGThe basic language setting used by applications on the
system, unless overridden by one of the other locale environment
variables
LC_CTYPEThe character set used to display and input text
LC_NUMERICHow non-monetary numeric values are formatted on screen
LC_TIMEHow date and time values are formatted
LC_COLLATEHow to sort various information items (e.g. defines the order of the alphabet so items can be ordered alphabetically by the sort  command)
LC_MONETARYHow monetary numeric values are formatted
LC_MESSAGESWhich language is to display messages to the end user
LC_PAPERDefinitions of paper formats and standards
LC_NAMEHow names are formatted
LC_ADDRESSHow to display address information
LC_TELEPHONEHow telephone numbers are structured
LC_MEASUREMENTWhat units of measurement are used
LC_IDENTIFICATION
LC_ALLThis variable serves as a powerful override over all
the other locale environment variables. When its value is set,
applications use that value to determine which locale settings to use
regardless of the values of the other variables
By utilizing various combinations of settings for the locale
variables, you can make interesting tweaks to the behaviour of your
system. For example, you can make your system display message in
US-English while using number, date, and measurement formats that are
more common to European countries.
The locale variables can effectively override each other's value in
some combinations. Therefore examining the values of the variables
themselves my not always provide clear indication of how the system
will behave. The locale  command can be used to examine what the effective values are to the applications.

 

 

转自:http://blog.chinaunix.net/u3/93889/showart_1914525.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值