user12033492
user12033492

Reputation:

can not set linux environment variables as I expect

I open two terminals. In first terminal:

export CLASSPATH="abc"
printenv CLASSPATH   ---> output is abc

then in second terminal:

printenv CLASSPATH   ---> no output 

why in second terminal I dont have the variable?

Upvotes: 0

Views: 1662

Answers (2)

Arkadiusz Drabczyk
Arkadiusz Drabczyk

Reputation: 12363

It's not going to work because each program inherits environment, that is a list of environment variables and their values from their parent process. Environment is not automatically propagated to all other programs on the system but is only inherited by children of the given program. To set a global environment that would work in all newly opened terminals you need set it in the file that is sourced each time you open the terminal. What file would that be depends on what shell you use and your system local setup. For example, if you use bash you should put export CLASSPATH="abc" in ~/.bashrc.

Upvotes: 2

ARK
ARK

Reputation: 802

For accessing global variable you need to put $ before it. Are you doing that?

try echo $CLASSPATH

I think you will find this helpful.

Upvotes: 0

Related Questions