Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 11-16-2005, 02:19 AM   #1
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77

Rep: Reputation: 15
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!
Old 11-16-2005, 03:37 AM   #2
Senior Member
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
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.
Old 11-16-2005, 03:37 AM   #3
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
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.
Old 11-16-2005, 10:28 AM   #4
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77

Original Poster
Rep: Reputation: 15
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!

Last edited by iansoundz; 11-16-2005 at 10:29 AM.
Old 11-16-2005, 07:29 PM   #5
Senior Member
Registered: Nov 2003
Location: Perth, Western Australia
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088

Rep: Reputation: 62
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
Old 11-17-2005, 12:20 AM   #6
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77

Original Poster
Rep: Reputation: 15
Question 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?
Old 11-17-2005, 01:06 AM   #7
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.3, Oracle Linux, Mint, Tribblix
Posts: 9,742

Rep: Reputation: 455Reputation: 455Reputation: 455Reputation: 455Reputation: 455
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.
Old 11-17-2005, 02:27 AM   #8
Registered: Jul 2005
Location: Arlington, VA
Distribution: CentOS 4.1 Kernel 2.6.9-11.EL
Posts: 77

Original Poster
Rep: Reputation: 15

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!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
environment variables in c++ s3b0 Programming 6 08-27-2004 09:19 AM
when to use environment variables? mark_2811 Programming 2 02-23-2004 06:09 PM
environment variables kakridge Linux - Newbie 1 07-14-2003 06:25 PM
environment variables. jISV Linux - General 0 04-05-2002 06:01 AM
environment variables aethereal Linux - Newbie 7 12-19-2001 09:34 AM > Forums > Linux Forums > Linux - General

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration