全部博文(25)
分类: LINUX
2009-04-29 18:50:02
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.
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.
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:
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.
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.
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:/bin | When 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/man | List of directories for the system to search manual pages in |
LD_LIBRARY_PATH | /opt/app/oracle/lib | List 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/tmp | The directory used for temporary file creation by several programs |
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 |
LANG | The basic language setting used by applications on the system, unless overridden by one of the other locale environment variables |
LC_CTYPE | The character set used to display and input text |
LC_NUMERIC | How non-monetary numeric values are formatted on screen |
LC_TIME | How date and time values are formatted |
LC_COLLATE | How to sort various information items (e.g. defines the order of the alphabet so items can be ordered alphabetically by the sort command) |
LC_MONETARY | How monetary numeric values are formatted |
LC_MESSAGES | Which language is to display messages to the end user |
LC_PAPER | Definitions of paper formats and standards |
LC_NAME | How names are formatted |
LC_ADDRESS | How to display address information |
LC_TELEPHONE | How telephone numbers are structured |
LC_MEASUREMENT | What units of measurement are used |
LC_IDENTIFICATION |
|
LC_ALL | This 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.