views:

58

answers:

2

what is difference between shell and environment variable & what are storage location for each of them ?

+2  A: 

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.

Adam Matan
sunil
What do you mean by 'Where the variables are located'? Where do you set their value, or where are the (technically) stored in the computer's memory?
Adam Matan
sunil
when we use set or env command from where the output is called from(i mean whatz the designation file or memory )
sunil
how can we diffrentiate between env and set ....
sunil
@sunil: http://answers.yahoo.com/question/index?qid=20080110095845AAuiIbk
Adam Matan
A: 

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

pixelbeat