-   Linux - General (
-   -   Environment Variables - where do they go!?! (

iansoundz 11-16-2005 02:19 AM

Environment Variables - where do they go!?!
I have been trying to figure this out for a while now. When I do this:

JRE1_4=/var/lib/alternatives/jre_1.4.2 export JRE1_4

And then do:


I see the variable in that terminal tht I am working from but when I open up another terminal, it is not there. Why? I though the export command makes setting the variable global. Also, where does it actually write this too?? I checked /etc/profile and it is not there! For that matter, the output from "env" looks noting like wht I see in /etc/profile. "env" shows numerous paths and various variables, etc/profile doesn't. I guess I am confused....can anyone shed some light? And pathmunge?? (from /etc/profile)......what the heck is pathmunge mean?

Thanks to any/all who answer!

BrianK 11-16-2005 03:37 AM

you can always put environement variables in your shell's resource file. If you're using bash, it's ~/.bashrc ; likewise, tcsh uses ~/.tcshrc

If you're using bash (and it sounds like you are - check with "echo $SHELL"), if a .bashrc file doesn't already exist in your homedir, create one and add the line:

export JRE1_4=/var/lib/alternatives/jre_1.4.2

( in tcsh, it would be "setenv JRE1_4 /var/lib/alternatives/jre_1.4.2")

now everytime you open a shell, the variable will be set.

Environment variables are always local to the process running them and all processes spawned from that guy. In other words if you set a var in a shell, it will only be set in applications launched from that shell - there's no such thing a a global variable. Of course, now that I've said that, I'll also say there are ways to make variable show up for everyone, all the time... but I don't know how to do them. ;)

nx5000 11-16-2005 03:37 AM

Setting a variable as export like
export dummy=1

Then the subshells will inherit the variable.

$export toto=1

in the new shell
$echo $toto
$echo $titi

if you open a shell seperatly (not a child, from the icon for example), then toto is not seen!

->profile files are only executed for login shells.

if you look at it, it sets the PATH and at the end exports the PATH so other subshells of this login shell (== all the shell you will launch) will have the PATH set

->bashrc is executed for all shells (login and non login ones). If you launch a shell using "sh" then this file is not executed.

iansoundz 11-16-2005 10:28 AM

Still confused...
Ok. I am using bash. And bashrc is for aliases. I need to know where I can set environment variables permanently. Not just for the instance of my shell.

I must set the JRE1_4 environment variable to the JRE installation directory.

From what I read, this should look like this:


But were does it go?? I read that this stuff goes in etc/profile but does it matter where exactly I put it? Also, I am doubly confused because I am expecting the "env" command to output the same stuff I see in my /etc/profile but It doesn't. Where does "env" command get it's info from???? Is it a file that I can write too? Because I'd really like to find it.....Heeeeeelp!

IBall 11-16-2005 07:29 PM

Environment variables are set by adding the line to one of bash's config files that BrianK put above:

export JRE1_4=/var/lib/alternatives/jre_1.4.4
You can add this line to ~/.bashrc (For one user only) or /etc/profile for system wide. The environment variable $JRE1_4 will be available in all shells that you open.

The env command outputs ALL the environment variables defined on your system. They are defined in /etc/profile, ~/.bashrc, ~/.profile, ~/.bash_profile and many other places. /etc/profile does many other things other that set environment variables. It can also be use to set aliases, set your prompt string, etc. So can all of the bash config files in your home directory. The difference between these files is the order in which bash reads them on invocation. See "man bash" for details.

I hope this helps

iansoundz 11-17-2005 12:20 AM

The saga continues....
I am just about ready to give up. I put this in my etc/profile:

export JRE1_4=$JRE1_4:/var/lib/alternative/jre_1.4.2

When I run env or do echo $JRE1_4, I only see that it "took" in the particular instance of the terminal that I updated etc/profile from. As soon as I open another terminal and do echo $JRE1_4, I see an empty space. I do env and it doesnot display the variable. What gives!?! I though etc/profile was global. I am worried that when I invoke a program tht depends on the variable to definite it's directory to the necessary file (jre_1.4.2), it won't work. I am logged in as root. on a far stretch, I decided to update the variable to my /root/.bash_profile but the same thing happens again. I open another terminal and run env and I don't see the variable. What does it take to get this variable global?

jlliagre 11-17-2005 01:06 AM

As the new terminal is not launching a login shell, it won't read /etc/profile.

Logout and login again in your graphic environment, and then the variable should be set in all its child processes.

iansoundz 11-17-2005 02:27 AM


Then next time I am in Paris, I will find you so I can shake your hand! Heck, I might even buy you a beer! Thanks so much!!

All times are GMT -5. The time now is 02:39 PM.