个人工具

UbuntuWiki:environment variables

来自Ubuntu中文

Oneleaf讨论 | 贡献2007年5月14日 (一) 02:54的版本 (New page: {{From|https://wiki.ubuntu.com/environment_variables}} {{Languages|php5}} == Global Environment Variables == These may be put in one of these files: */etc/environment (try this file fir...)

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索


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 in /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

Some of what is mentioned below may be specific to Ubuntu only.

  • when starting a shell after you've logged in already, either from the console or thru 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.

Display contents of $PATH

Just `echo $PATH'

References

See Also

OneTruePath


CategoryDocumentation