Linux - Environment Variable

About

Environment variables in the bash shell help you in several ways. Certain built-in variables change the shell in ways that make your life a little easier, and you can define other variables to suit your own purposes. Here are some examples of built-in shell variables:

  • PS1 defines the shell's command-line prompt.
  • HOME defines the home directory for a user.
  • PATH defines a list of directories to search through when looking for a command to execute.

Articles Related

How to see their value ?

For one

To see an environment variable, you make use of the echo command as :

[root@oel11g ~]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

or with the env command

$ env | grep PATH

For all environment variables

To list the current values of all environment variables, issue the command

[root@ebs121 lib]# env
HOSTNAME=ebs121.localdomain
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.2.2 3886 22
SSH_TTY=/dev/pts/1
USER=root
.........

or

$ env | more

How to change it ?

For a session

The syntax depends of your shell:

  • for the Bourne, Bash, or Korn shell:

To add /sbin to the path, type the export command in a console :

export PATH=$PATH:/sbin

or with two variable

$ TMP=/mount_point/tmp
$ TMPDIR=/mount_point/tmp
$ export TMP TMPDIR
  • For the C shell:
% setenv TMP /mount_point/tmp
% setenv TMPDIR /mount_point/tmp

Permanently for a session

You must change the shell startup script.

How to delete it

unset myEnvironmentVariable

Creating Your Own Shell Variables

To create your own shell variables. First issue the command

newdir=$HOME/mynewdirectory

and then, regardless of what directory you are in, you can issue

cd $newdir
  • Bookmark "Linux - Environment Variable" at del.icio.us
  • Bookmark "Linux - Environment Variable" at Digg
  • Bookmark "Linux - Environment Variable" at Ask
  • Bookmark "Linux - Environment Variable" at Google
  • Bookmark "Linux - Environment Variable" at StumbleUpon
  • Bookmark "Linux - Environment Variable" at Technorati
  • Bookmark "Linux - Environment Variable" at Live Bookmarks
  • Bookmark "Linux - Environment Variable" at Yahoo! Myweb
  • Bookmark "Linux - Environment Variable" at Facebook
  • Bookmark "Linux - Environment Variable" at Yahoo! Bookmarks
  • Bookmark "Linux - Environment Variable" at Twitter
  • Bookmark "Linux - Environment Variable" at myAOL
 
linux/environment_variable.txt · Last modified: 2012/01/27 11:20 by gerardnico