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.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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).

share|improve this answer
add comment

"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

share|improve this answer
    
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 '12 at 5:49
add comment

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.