5

I never understand what "export" does. For example, what's the difference between these two?

  1. PYTHONPATH=/home/myaccount/ & export PYTHONPATH and
  2. PYTHONPATH=/home/myaccount/

One with export and the other without.

2 Answers 2

6

If you don't export, then the environment variable will only be visible locally. Exporting makes them available to other programs and shells you might launch (from that shell).

3

"Exporting" a variable in the shell makes it available to all subshells and processes created by that shell.

It does not make it available everywhere in the system, only by processes created from that shell.

Here is an example you can try to prove the point.

("set" will list all the variables set in the terminal)

   $ ZZZ=test
   $ bash # this runs bash in bash, you can also type 'xterm' to see it work there too.
   $ set |grep ZZZ # You will not see ZZZ=test
   $ exit # Lets get out of the subshell and try export!
   $ export ZZZ
   $ bash
   $ set |grep ZZZ # and there we go! our variable is set in the subshell/process.

You can open another terminal, and see that it is not set there, however.

http://ss64.com/bash/export.html

1
  • Thanks for your explanation and especially the example. I gave best answer to the other guy because he came a little earlier.
    – Shen
    Jul 20, 2012 at 5:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .