2 cases of exporting Environment Variable
Run these commands on a terminal:
$ export x=hello
$ xterm & # this is xterm 1. "echo $x" we have hello
$ x=$x' add more here'
$ xterm & # this is xterm 2. "echo $x" we have "hello add more here"
So, it means I don't have to export the variable x a second time. The same holds for PATH env var. However, the following situation is different:
$ PS1="\T; \j jobs> "
$ xterm & # the bash prompt was the default (not change).
In this case, I have to export PS1 for it to work. In my opinion, I think PS1 is an environment variable, so it was exported already at start up. Thus, I don't have to export it a second time when I changed its value.
Can anyone help me to explain this? Thanks a bundle.
I think when you execute xterm your PS1 will be set again (taken from ~/.bashrc).
Thanks for your information. In addition, I have noticed people use this:
According to what I said, I think it's unnecessary to use 'export' there. We only need:
Is this correct? Am I missing something?
More or less you are right. The problem is (in general) that [almost] noone knows if a given variable already exported, and reexporting will not cause any trouble.
|All times are GMT -5. The time now is 07:23 PM.|