Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What is the export command supposed to do in Linux?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Here is an example to demonstrate the behavior.

$ # set testvar to be a value
$ testvar=asdf
$ # demonstrate that it is set in the current shell
$ echo $testvar
$ # create a bash subprocess and examine the environment.
$ bash -c "export | grep 'testvar'"

$ bash -c 'echo $testvar'

$ # export testvar and set it to the a value of foo
$ export testvar=foo
$ # create a bash subprocess and examine the environment.
$ bash -c "export | grep 'testvar'"
declare -x testvar="foo"
$ bash -c 'echo $testvar'
foo
$ # mark testvar to not be exported
$ export -n testvar
$ bash -c "export | grep 'testvar'"

$ bash -c 'echo $testvar'

You will notice that without the export the new bash process you created was not able to see testvar. When testvar was exported, the new process was able to test var.

share|improve this answer

Export a shell variable as environment variable.

share|improve this answer
    
The net result is that when you 'export' a variable, it becomes available as an environment variable within any applications you run within that shell. –  McJeff Mar 19 '10 at 20:52
    
Can you show an example usage? –  bstpierre Mar 19 '10 at 20:55
1  
Have you tried the man page? ss64.com/bash/export.html –  ceejayoz Mar 19 '10 at 20:58

Please see this Bash by example tutorial from IBM. It even includes an example of using export.

share|improve this answer

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.