“UbuntuHelp:EnvironmentVariables”的版本间的差异
来自Ubuntu中文
小 (新页面: {{From|https://help.ubuntu.com/community/EnvironmentVariables}} {{Languages|UbuntuHelp:EnvironmentVariables}} #title Environment Variables == Global Environment Variables == These may ...) |
小 |
||
第2行: | 第2行: | ||
{{Languages|UbuntuHelp:EnvironmentVariables}} | {{Languages|UbuntuHelp:EnvironmentVariables}} | ||
#title Environment Variables | #title Environment Variables | ||
− | |||
− | |||
== Global Environment Variables == | == Global Environment Variables == | ||
− | |||
These may be put in one of these files: | These may be put in one of these files: | ||
* <code><nowiki>/etc/environment</nowiki></code> (try this file first) | * <code><nowiki>/etc/environment</nowiki></code> (try this file first) | ||
* <code><nowiki>/etc/profile</nowiki></code> | * <code><nowiki>/etc/profile</nowiki></code> | ||
− | |||
For example, to set a variable called <code><nowiki>JAVA_HOME</nowiki></code> and append it to <code><nowiki>PATH</nowiki></code>: | For example, to set a variable called <code><nowiki>JAVA_HOME</nowiki></code> and append it to <code><nowiki>PATH</nowiki></code>: | ||
− | |||
for <code><nowiki>/etc/environment</nowiki></code>: | for <code><nowiki>/etc/environment</nowiki></code>: | ||
<pre><nowiki> | <pre><nowiki> | ||
第20行: | 第15行: | ||
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME:" | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME:" | ||
</nowiki></pre> | </nowiki></pre> | ||
− | |||
for <code><nowiki>/etc/profile</nowiki></code>: | for <code><nowiki>/etc/profile</nowiki></code>: | ||
<pre><nowiki> | <pre><nowiki> | ||
export JAVA_HOME="/usr/lib/j2sdk1.5-sun" | export JAVA_HOME="/usr/lib/j2sdk1.5-sun" | ||
− | |||
export PATH="$PATH:$JAVA_HOME:" | export PATH="$PATH:$JAVA_HOME:" | ||
</nowiki></pre> | </nowiki></pre> | ||
− | |||
− | |||
=== Locale Environment variables === | === Locale Environment variables === | ||
− | |||
Some programs rely on the value of <code><nowiki>$LANG</nowiki></code>, which defaults to <code><nowiki>en_US.UTF-8</nowiki></code>. (For example, Thunderbird changes the displayed date format based on this). The variable is set in '''both''' <code><nowiki>/etc/enviroment</nowiki></code> and <code><nowiki>/etc/default/locale</nowiki></code>. To make a system-wide change that is certain to take effect, both of these must be modified; it's also necessary to log out and back in again. | Some programs rely on the value of <code><nowiki>$LANG</nowiki></code>, which defaults to <code><nowiki>en_US.UTF-8</nowiki></code>. (For example, Thunderbird changes the displayed date format based on this). The variable is set in '''both''' <code><nowiki>/etc/enviroment</nowiki></code> and <code><nowiki>/etc/default/locale</nowiki></code>. To make a system-wide change that is certain to take effect, both of these must be modified; it's also necessary to log out and back in again. | ||
− | |||
== Session Specific Environment Variables == | == Session Specific Environment Variables == | ||
− | |||
You may sometimes want variables defined locally (eg.: restricted to your accounts shell only) and not globally (all users). | You may sometimes want variables defined locally (eg.: restricted to your accounts shell only) and not globally (all users). | ||
So just append whatever variables you need defined to your <code><nowiki>~/.bashrc</nowiki></code> file. | So just append whatever variables you need defined to your <code><nowiki>~/.bashrc</nowiki></code> file. | ||
− | |||
If instead you want a temporary variable created only for your current shell session, then do this inside the shell: | If instead you want a temporary variable created only for your current shell session, then do this inside the shell: | ||
<pre><nowiki> | <pre><nowiki> | ||
第43行: | 第30行: | ||
export SOMEVALUE="500" | export SOMEVALUE="500" | ||
</nowiki></pre> | </nowiki></pre> | ||
− | |||
== Bash Shell Environment Variables == | == Bash Shell Environment Variables == | ||
− | |||
* When starting a shell after you have logged in already, either from the console or though an X display manager, that shell will be an interactive non-login shell, which will read <code><nowiki>/etc/bash.bashrc</nowiki></code> and <code><nowiki>~/.bashrc</nowiki></code>. | * When starting a shell after you have logged in already, either from the console or though an X display manager, that shell will be an interactive non-login shell, which will read <code><nowiki>/etc/bash.bashrc</nowiki></code> and <code><nowiki>~/.bashrc</nowiki></code>. | ||
− | |||
* When the user starts a bash shell by logging into a console or via SSH, this starts a login shell, which will read <code><nowiki>/etc/environment</nowiki></code>, <code><nowiki>/etc/profile</nowiki></code>, <code><nowiki>/etc/bash.bashrc</nowiki></code>, <code><nowiki>~/.bash_profile</nowiki></code>, <code><nowiki>~/.bash_login</nowiki></code>, and <code><nowiki>~/.profile</nowiki></code>. | * When the user starts a bash shell by logging into a console or via SSH, this starts a login shell, which will read <code><nowiki>/etc/environment</nowiki></code>, <code><nowiki>/etc/profile</nowiki></code>, <code><nowiki>/etc/bash.bashrc</nowiki></code>, <code><nowiki>~/.bash_profile</nowiki></code>, <code><nowiki>~/.bash_login</nowiki></code>, and <code><nowiki>~/.profile</nowiki></code>. | ||
− | |||
* If Bash is invoked with the name <code><nowiki>sh</nowiki></code>, whether as an interactive login shell, or as a non-interactive shell with the <code><nowiki>--login</nowiki></code> option, it first attempts to read and execute commands from <code><nowiki>/etc/profile</nowiki></code> and <code><nowiki>~/.profile</nowiki></code>, in that order. | * If Bash is invoked with the name <code><nowiki>sh</nowiki></code>, whether as an interactive login shell, or as a non-interactive shell with the <code><nowiki>--login</nowiki></code> option, it first attempts to read and execute commands from <code><nowiki>/etc/profile</nowiki></code> and <code><nowiki>~/.profile</nowiki></code>, in that order. | ||
− | |||
== Displaying contents of $PATH == | == Displaying contents of $PATH == | ||
In a shell type: | In a shell type: | ||
第57行: | 第39行: | ||
echo $PATH | echo $PATH | ||
</nowiki></pre> | </nowiki></pre> | ||
− | |||
== References == | == References == | ||
* [http://www.gnu.org/software/bash/manual/bashref.html Bash Reference] | * [http://www.gnu.org/software/bash/manual/bashref.html Bash Reference] | ||
* [http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=5 Environment Variables @Gentoo Wiki] | * [http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=5 Environment Variables @Gentoo Wiki] | ||
− | |||
---- | ---- | ||
[[category:CategoryDocumentation]] [[category:CategoryCleanup]] | [[category:CategoryDocumentation]] [[category:CategoryCleanup]] | ||
[[category:UbuntuHelp]] | [[category:UbuntuHelp]] |
2007年11月30日 (五) 17:09的版本
点击翻译: |
English |
请不要直接编辑翻译本页,本页将定期与来源同步。 |
- title Environment Variables
目录
Global Environment Variables
These may be put in one of these files:
-
/etc/environment
(try this file first) -
/etc/profile
For example, to set a variable called JAVA_HOME
and append it to PATH
:
for /etc/environment
:
JAVA_HOME="/usr/lib/j2sdk1.5-sun"
(A colon followed by no directory is treated as the current working directory)
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME:"
for /etc/profile
:
export JAVA_HOME="/usr/lib/j2sdk1.5-sun" export PATH="$PATH:$JAVA_HOME:"
Locale Environment variables
Some programs rely on the value of $LANG
, which defaults to en_US.UTF-8
. (For example, Thunderbird changes the displayed date format based on this). The variable is set in both /etc/enviroment
and /etc/default/locale
. To make a system-wide change that is certain to take effect, both of these must be modified; it's also necessary to log out and back in again.
Session Specific Environment Variables
You may sometimes want variables defined locally (eg.: restricted to your accounts shell only) and not globally (all users).
So just append whatever variables you need defined to your ~/.bashrc
file.
If instead you want a temporary variable created only for your current shell session, then do this inside the shell:
export SOMEDIRECTORY="/some/location" export SOMEVALUE="500"
Bash Shell Environment Variables
- When starting a shell after you have logged in already, either from the console or though an X display manager, that shell will be an interactive non-login shell, which will read
/etc/bash.bashrc
and~/.bashrc
. - When the user starts a bash shell by logging into a console or via SSH, this starts a login shell, which will read
/etc/environment
,/etc/profile
,/etc/bash.bashrc
,~/.bash_profile
,~/.bash_login
, and~/.profile
. - If Bash is invoked with the name
sh
, whether as an interactive login shell, or as a non-interactive shell with the--login
option, it first attempts to read and execute commands from/etc/profile
and~/.profile
, in that order.
Displaying contents of $PATH
In a shell type:
echo $PATH