What is the export command supposed to do in Linux?

link|improve this question
feedback

3 Answers

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.

link|improve this answer
feedback

Export a shell variable as environment variable.

link|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
feedback

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.