Variables Within the UNIX Shell - Environment Variables and the start of the shell
(Page 4 of 5 )
Besides the variables that you can create, there are collections of variables that describe the environment. These are automatically collected by the shell when you start a terminal (for example), and are written entirely in capital letters. This way, you can differentiate them from your variables, as it is generally advised that you use only lower case letters for your variables.
You can use them just like any other variables. You can get a full list of them by using the printenv command. This will list both the environment variable name and its content. The table below describes a few of them:
Variable Name
What it means
Example
HOSTNAME
The full domain name of the computer
mari.sak.com
TERM
The type of the terminal
xterm
SHELL
The full path of the shell that is by default used for the current user
/bin/bash
USER
The login name of the user
gaborj
MAIL
The address mail of the user
/var/spool/mail/gaborj
PATH
The path where the shell should look for executable programs / tools
/bin:/usr/local/bin:.
PWD
The current working directory
/home/gaborj
EDITOR
The implicit text editor of the user
/usr/bin/vim
LANG
The used language and character set
en_US.UTF-8
HOME
The home folder of the user
home/gaborj
When you start the shell, it will read a couple of configuration files. This will set variables and run programs that will determine how the environment of the shell will look. Between these are files that work for all users, like the /etc/profile or /etc/bashrc. Besides this, there is a corresponding file (.profil, .bash_profile) in the home folder of each user. We use this to make custom settings.
Modify the environment variables. Set aliases. Task like this should be done here. A .profile and the .bash_profile file will be interpreted at the start of the shell in the given order. We can add a variable to the environment variables with the export command. The child shell I was speaking of will only get the environment variable via inheritance. If you do not know what a child shell is, go back to my previous article and read it.
For example, we will extend the PATH environment variable with the current directory:
PATH=$PATH:./
export Path
This is what you should add to those configuration files. For settings that should be executed when you close the shell, use the .bash_logout configuration file. Naturally, these file names are for the bash Shell.