And why is an export
needed? Where is it exporting to?
views:
51answers:
2
+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
2010-08-05 02:06:18
A:
The PS1
environment variable is pre-defined by the bash
shell; consequently, it doesn't need to be exported, merely set.
Steve Emmerson
2010-08-05 02:22:02
Nope, it doesn't need to be exported, because the only one needing it is bash itself, and not it's (grand)children.
mvds
2010-08-05 02:25:14
@mvds No, it doesn't need to be exported because it's already an environment variable.
Steve Emmerson
2010-08-05 02:59:32
mvds
2010-08-05 10:28:17
@mvds Good lord, you're right! My mistake.
Steve Emmerson
2010-08-05 20:44:03