Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Somebody told me that:

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

What's the difference?

share|improve this question
up vote 11 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 of environment variables see Environment Variables in Ubuntu Help.

share|improve this answer
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
$ env | grep SOME # note: no output
$ export SOME # turn $SOME into an environment variable
$ env | grep SOME

Another way to define an environment variable:

$ echo $ANOTHER
$ env | grep ANOTHER
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

Your Answer


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.