Pages

Environment variable in unix(ubuntu)

An Environment variable is a dynamic "object" on a computer that stores a value, which in turn can be referenced by one or more software programs.

 The value of an environmental variable can the location of all executable files in the file system, the default editor that should be used, or the system local settings.

 An environment variable defines some aspect of a user's or a program's environment that can vary.

 Environment variables are dynamic because they can change. The values they store can be changed to match the current computer system's setup and design (environment). They can also differ between computer systems because each computer can have a different setup and design (environment).

List of some well known environment variables on Ubuntu

  • PATH Contains a colon-separated list of directories in which our system looks for executable files and commands. When we execute a command, the shell searches through each of these directories, one by one, until it finds a directory where the executable exists. A command whose path added to the PATH environment variable can be access directly without typing the full path. Here is the sample of PATH environment variable.
$ echo $PATH
                /usr/local/bin:/bin:/usr/bin:/sbin:/usr/sbi

  • HOME Contains the path to the home directory of the current user. 
  • PWD Contains the path to your current working directory. 
               $ echo $PWD
                 /home/techie/Desktop/storm-jar
  • TERM Contains the name of the running terminal, i.e xterm
  • EDITOR Contains the path to the lightweight program used for editing files, i.e. /usr/bin/nano, or an interactive switch (between gedit under X or nano in this example):
 export EDITOR="$(if [[ -n $DISPLAY ]]; then echo 'gedit'; else echo 'nano'; fi)"
  • VISUAL Contains the path to full-fledged editor that is used for more demanding tasks, such as editing mail; e.g., vi, vim, emacs, etc.
  • MAIL Contains the location of incoming email. The traditional setting is /var/spool/mail/$LOGNAME.
  • ftp_proxy Contains FTP  proxy server,
  • http_proxy Contains HTTP proxy server, 
  • HISTFILE This environment variable contains the location and name of the file in which command typed in terminal prompt saved.
  • HISTFILESIZE Maximun no of line contain in history file
  • HOSTNAME Contains system's host name
  • USER Contains login user name
  • OSTYPE : Contains description about OS.
  • LD_LIBRARY_PATH Contains colon separated list of directory where libraries should be searched for.
  • LOGNAME : contains login name

NOTE: Use printenv command to see the current environment variable and those value

echo $ printev
SSH_AGENT_PID=1702
GPG_AGENT_INFO=/tmp/keyring-nnUEcy/gpg:0:1
TERM=xterm
SHELL=/bin/bash
XDG_SESSION_COOKIE=a84bfeb2ec960f26863997bc0000000d-1379048055.358900-1791728848
WINDOWID=54525958