Prosody Logo Greg Kochanski Prosody Logo

What is "export" in a Linux shell?

Question:

ZZZ wrote: > Thanks. I know how to set the environment variables. But is export a Unix > command? I can't find it in my reference book. Sorry to be so naive.

Answer:

It's not a command in the sense of an executable program. (That's why you may not find it in your book!) It's an instruction to the shell. It tells the shell to make these environment variables available to other programs. Without the export, they are only available within the shell itself. You could do this:
x="foo"
and
echo $x
will print "foo", but if you ran some program that used an environment variable, it wouldn't see it. Now, things like PATH and LD_LIBRARY_PATH need to be seen by other programs, so they must be exported. Watch this! I set a variable (x or y) echo it to show that I have nothing up my sleeves. Then I start another shell. X has not been exported, so the other shell cannot see it, whereas y *has* been exported so the other shell *can* see it.
$ x=foo
$ echo $x
foo
$ sh
sh-3.1$ echo $x

sh-3.1$ exit
$
$ y=foo
$ export y
$ echo $y
foo
$ sh
sh-3.1$ echo $y
foo
sh-3.1$ exit
$

[ Papers | kochanski.org | Phonetics Lab | Oxford ] Last Modified Wed Mar 5 18:08:31 2008 Greg Kochanski: [ ]