Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Somebody told me that:

BASH isn't an environment variable, it's a shell variable

What's the difference?

share|improve this question

3 Answers 3

up vote 6 down vote accepted

BASH is a local variable that is valid in the current (bash) shell only.

Environment variables such as SHELL are valid systemwide. In a current Bash shell BASH points to the execution path of bash, whereas SHELL points to the shell defined as default (which may be of the same value).

For an explanation fo environment variables see: Help Ubuntu.

share|improve this answer
1  
A great link (+1) :) –  Peter.O Feb 14 '11 at 14:42

An environment variable is a globally available, in a program and it child programs. A shell variable is only available in the current shell. To make a shell variable available as an environment variable, use export VARNAME (without dollar $).

Examples for clarification:

$ SOME=VAR # define shell variable $SOME
$ echo $SOME
VAR
$ env | grep SOME # note: no output
$ export SOME # turn $SOME into an environment variable
$ env | grep SOME
SOME=VAR

Another way to define an environment variable:

$ export ANOTHER=VALUE
$ echo $ANOTHER
VALUE
$ env | grep ANOTHER
ANOTHER=VALUE
share|improve this answer

There is a difference. Shell Variables and Environment Variables will explain it better that I can, but here is an excerpt from it:

If a change is made to a shell variable, it must be explicitly "exported" to the corresponding environment variable in order for any forked subprocesses to see the change. Recall that shell variables are local to the shell in which they were defined.

share|improve this answer
    
I'm commenting my own answer.. I really like the Help Ubuntu link in Takkat's answer... (it's better than mine) –  Peter.O Feb 14 '11 at 14:46
    
The link is dead. –  Francis Potter Dec 8 '13 at 2:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.