Environment variables (Linux)

– display current environment
$ set
$ printenv
– display the value of a variable
$echo $JAVA_HOME
printf "$HOME"
– set environment variable
export PATH=${PATH}:/home/path1/bin
export PATH=${PATH}:${HOME}/bin
The $PATH defined the search path for commands. It is a colon-separated list of directories in which the shell looks for commands.
– make changes permanent
Consider at least these situations:
1. Login/Non-login shell
2. Interactive/Non-interactive shell
bash
1. Bash as login shell will load /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile in the order
2. Bash as non-login interactive shell will load ~/.bashrc
3. Bash as non-login non-interactive shell will load the configuration specified in environment variable $BASH_ENV

– create .bash_profile in your home dir
– edit .bash_proflle, add variable
– run .bash_profile

$ cd ~
$ touch .bash_proflle
$ vi ~/.bash_proflle


write;
export JAVA_HOME=/Library/Java/JavaVirtualMachines
export JDK_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_191.jdk

$ source ~/.bash_profile
$ printenv


Common environment variables
MANPATH=/usr/local/share/man:/usr/share/man
HOSTNAME=localhost
SHELL=/bin/bash
TERM=xterm
XTERM_SHELL=/bin/bash
PATH=/usr/java/j2sdk1.4.2_01/bin:/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin/::/usr/local/sbin
EDITOR=/bin/nano
BASH_ENV=/home/zymos/.bashrc
INFOPATH=/usr/share/info:/usr/share/binutils-data/i686-pc-linux-gnu/2.16.1/info:/usr/share/gcc-data/i686-pc-linux-gnu/3.4.5/info
DISPLAY=:0.0
PKG_CONFIG_PATH=/usr/X11R6/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/qt/3/lib/