Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-16-2005, 03:19 AM
|
#1
|
Member
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77
Rep:
|
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:
env
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!
|
|
|
11-16-2005, 04:37 AM
|
#2
|
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334
Rep:
|
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. 
|
|
|
11-16-2005, 04:37 AM
|
#3
|
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307
Rep:
|
Setting a variable as export like
export dummy=1
Then the subshells will inherit the variable.
$export toto=1
$titi=2
$xterm&
in the new shell
$echo $toto
1
$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.
|
|
|
11-16-2005, 11:28 AM
|
#4
|
Member
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77
Original Poster
Rep:
|
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:
JRE1_4=/var/lib/alternatives/jre_1.4.2
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!
Last edited by iansoundz; 11-16-2005 at 11:29 AM.
|
|
|
11-16-2005, 08:29 PM
|
#5
|
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
|
Environment variables are set by adding the line to one of bash's config files that BrianK put above:
Code:
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
--Ian
|
|
|
11-17-2005, 01:20 AM
|
#6
|
Member
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77
Original Poster
Rep:
|
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?
|
|
|
11-17-2005, 02:06 AM
|
#7
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,793
|
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.
|
|
|
11-17-2005, 03:27 AM
|
#8
|
Member
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77
Original Poster
Rep:
|
jlliagre,
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 12:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|