views:

51

answers:

2

And why is an export needed? Where is it exporting to?

+6  A: 

Exported variables are passed on to new processes invoked.

Try setting A=1, then invoking a new shell by entering "bash", then echo $A - an empty line.

Do the same, but then export A=1, invoke a new shell, then echo $A - voila!

edit on the technical side, and looking at your question, B=1 doesn't actually set an environment variable. To get the real environment of your shell (in linux), try

$ xargs -n 1 -0 echo < /proc/$$/environ

which differs from the output of export. And as a sidenote, this question touches on the internals of bash and its environment handling.

mvds
A: 

The PS1 environment variable is pre-defined by the bash shell; consequently, it doesn't need to be exported, merely set.

Steve Emmerson
Nope, it doesn't need to be exported, because the only one needing it is bash itself, and not it's (grand)children.
mvds
@mvds No, it doesn't need to be exported because it's already an environment variable.
Steve Emmerson
mvds
@mvds Good lord, you're right! My mistake.
Steve Emmerson