Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Possible Duplicate:
Difference between “a=b” and “export a=b” in bash

It is hard to admit, but I have never really understood what exactly export does to an environment variable. I know that if I don't export a variable I sometimes can't see it in child processes, but sometimes it seems like I can. What is really going on when I say

export foo=5

and when should I not export a variable?

share|improve this question

marked as duplicate by Dennis Williamson, Ivo Flipse Jun 17 '10 at 7:13

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Here's a link to at least one other helpful question on this topic: ... since ironically this question was the first one that popped up on Google for my query on export in bash. – Ogre Psalm33 Apr 13 '11 at 18:07
Also:… – Ogre Psalm33 Apr 13 '11 at 18:31
One common use is to add export statements to .bashrc/.bash_profile to create persistent global variables similar to $HOME. – Evan Plaice Jun 10 at 5:16
up vote 12 down vote accepted

From man bash:


When a program is invoked it is given an array of strings called the environment. This is a list of name-value pairs, of the form name=value.

The shell provides several ways to manipulate the environment. On invocation, the shell scans its own environment and creates a parameter for each name found, automatically marking it for export to child processes. Executed commands inherit the environment. The export and declare -x commands allow parameters and functions to be added to and deleted from the environment. If the value of a parameter in the environment is modified, the new value becomes part of the environment, replacing the old. The environment inherited by any executed command consists of the shell's initial environment, whose values may be modified in the shell, less any pairs removed by the unset command, plus any additions via the export and declare -x commands.

share|improve this answer
IMHO copy-pasting an excerpt from documentation without any additional effort of explaining should not be upvoted. – Artur Oct 3 '13 at 16:59
That excerpt is not very clear and frankly I didn't understand what is going on. – Trismegistos Jan 10 '14 at 15:14
@Artur: on the contrary: if the (excerpt from the) documentation answers a question, I'd rather not have additional explanations. – René Nyffenegger Oct 10 '14 at 7:07
@RenéNyffenegger but it seems, it doesn't. At least, I didn't get it until I read an answer by BloodPhilia which should be marked as accepted. – Vladislav Rastrusny Nov 20 '14 at 13:34

Exported variables get passed on to child processes, not-exported variables do not.

share|improve this answer
Can you point to any documentation to that affect. I am looking for more information than that. For instance, does a variable only need to be exported once, or do you need to export it after every change, etc. – Chas. Owens Jun 16 '10 at 20:09
You could check this out:… – BloodPhilia Jun 16 '10 at 20:17
You can verify this by adding something to a path (say to PYTHONPATH) and then noting that though you can echo $PYTHONPATH it does not get recognized by python or bash scripts until you export it – Kaushik Ghose Jul 28 '14 at 18:49

When you use export, you are adding the variable to the environment variables list of the shell in which the export command was called and all the environment variables of a shell are passed to the child processes, thats why you can use it.

When you finish the shell its environment is destroyed, thats why the environment variables are declared and exported at login, in the .bashrc file for example

share|improve this answer
I cannot understand either of these sentences. – Jonathan Hartley Jul 11 '14 at 13:06

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