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!
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:
( 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. ;)
Setting a variable as export like
Then the subshells will inherit the variable.
in the new shell
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.
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!
Environment variables are set by adding the line to one of bash's config files that BrianK put above:
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
The saga continues....
I am just about ready to give up. I put this in my etc/profile:
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?
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.
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 09:44 AM.|