environment_variables

Differences between revisions 10 and 11
Revision 10 as of 2006-11-19 06:10:18
Size: 2221
Editor: c-68-61-204-103
Comment:
Revision 11 as of 2006-11-19 06:20:13
Size: 2231
Editor: c-68-61-204-103
Comment:
Deletions are marked like this. Additions are marked like this.
Line 9: Line 9:
To append 'testbin' to the PATH environment variable and to set a variable called JAVA_HOME and append it to PATH: For example, to set a variable called JAVA_HOME and append it to PATH:
Line 16: Line 16:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME/bin:" PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11:/usr/games:$JAVA_HOME:"
Line 23: Line 23:
export PATH="$PATH:/home/user/testbin:$JAVA_HOME/bin:"
export PATH="$PATH:$JAVA_HOME:"
Line 41: Line 40:
Some of what is mentioned below may be specific to Ubuntu only.
Line 44: Line 44:
 * when the user starts a bash shell by logging into a console, this starts a login shell, which will read /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order. Bash reads and executes commands from the first one that exists and is readable. The `--noprofile' option may be used when the shell is started to inhibit this behavior.  * when the user starts a bash shell by logging into a console, this starts a login shell, which will read /etc/environment, /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order. Bash reads and executes commands from the first one that exists and is readable. The `--noprofile' option may be used when the shell is started to inhibit this behavior.

TableOfContents

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:"

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 for only your current session:

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, and only reads /etc/bash.bashrc and ~/.bashrc.
  • when the user starts a bash shell by logging into a console, this starts a login shell, which will read /etc/environment, /etc/profile, ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order. Bash reads and executes commands from the first one that exists and is readable. The `--noprofile' option may be used when the shell is started to inhibit this behavior.
  • 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: OneTruePath]

environment_variables (last edited 2008-08-06 17:01:23 by localhost)