-   Linux - General (
-   -   2 cases of exporting Environment Variable (

echipbk 02-05-2013 05:27 AM

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.

pan64 02-05-2013 05:30 AM

I think when you execute xterm your PS1 will be set again (taken from ~/.bashrc).

echipbk 02-05-2013 05:00 PM

Thanks for your information. In addition, I have noticed people use this:

export PATH=$PATH:......

According to what I said, I think it's unnecessary to use 'export' there. We only need:

Is this correct? Am I missing something?

pan64 02-06-2013 12:38 AM

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 04:10 AM.