what is difference between shell and environment variable & what are storage location for each of them ?
Citing this source,
Standard UNIX variables are split into two categories, environment variables and shell variables. In broad terms, shell variables apply only to the current instance of the shell and are used to set short-term working conditions; environment variables have a farther reaching significance, and those set at login are valid for the duration of the session. By convention, environment variables have UPPER CASE and shell variables have lower case names.
To list all environment variables, use printenv
and to list all shell variables, use set
.
You'll note that the environment variables store more permanent value, e.g.:
HOME=/home/adam
Which changes quite seldom, while the shell variables stores local, temporary, shell-specific values, e.g.:
PWD=/tmp
which changes every time you change your current directory.
For most practical tasks, set environment values by adding export VARIABLE_NAME=VALUE
to your ~/.bashrc file.
A shell variable is just a special case of an environment variable. shell variables are inherited from the environment and possibly copied to the environment of children of the shell depending on syntax used: http://www.pixelbeat.org/docs/env.html