LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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


Reply
  Search this Thread
Old 11-16-2005, 03:19 AM   #1
iansoundz
Member
 
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:

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!
 
Old 11-16-2005, 04:37 AM   #2
BrianK
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, 04:37 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
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.
 
Old 11-16-2005, 11:28 AM   #4
iansoundz
Member
 
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:

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.
 
Old 11-16-2005, 08:29 PM   #5
IBall
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:
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
 
Old 11-17-2005, 01:20 AM   #6
iansoundz
Member
 
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, 02:06 AM   #7
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,793

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

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


Reply


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 10:19 AM
when to use environment variables? mark_2811 Programming 2 02-23-2004 07:09 PM
environment variables kakridge Linux - Newbie 1 07-14-2003 07:25 PM
environment variables. jISV Linux - General 0 04-05-2002 07:01 AM
environment variables aethereal Linux - Newbie 7 12-19-2001 10:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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