LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-18-2001, 06:38 AM   #1
aethereal
Member
 
Registered: Dec 2000
Location: Seattle
Distribution: Red Hat 8.0
Posts: 41

Rep: Reputation: 15
Question environment variables


Where exactly are environment variables stored? (It would be great if they were stored in a file somewhere, which I could then *permanently* modify.)

I have three books on Linux/Unix and each gives very poor/cursory coverage on this topic.

I notice that environment variables can be changed with a command such as "setenv" in csh, but how can they be modified using bash?

What I really want to fix is my PATH environment variable. I can temporarily amend it in bash using "export PATH=$PATH:/blahblah" but then if I open a new terminal window, I notice my modifications are not saved in any way.

Boy oh boy, all of this is SO needlessly frustrating... *sigh*
 
Old 12-18-2001, 06:53 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
The file used to set your personal login environment can vary depending on what you are using.

Most likely the file .bash_profile in your home directory will work. Files starting with a . are considerd hidden files. So in your home directory try doing something like "ls -ld .*" in your home directory. It should reveal plenty of files which you can edit to change your environment.
 
Old 12-18-2001, 07:43 AM   #3
aethereal
Member
 
Registered: Dec 2000
Location: Seattle
Distribution: Red Hat 8.0
Posts: 41

Original Poster
Rep: Reputation: 15
I was just reading about my .bash_profile file, but actually it simply *modifies* PATH as follows:
PATH=$PATH:$HOME/bin

At this point, I really want to know where PATH itself is stored! What file holds environment variables???

Thanks,
Ben
 
Old 12-18-2001, 10:42 AM   #4
bluecadet
Member
 
Registered: Oct 2001
Distribution: MD81 RH71
Posts: 555

Rep: Reputation: 30
it's not in a file, it's in memory.

don't take this the wrong way, but maybe you think the issue is covered very poorly because you think it's perhaps something else than it actually is..?

in the bashrc files, that will create the path if there isn't one already, as do other files which are processed before it.

the best place to set a global variable is normally to add it to /etc/rc.local but there are dozens of files that could be used. rc.init, /etc/bashrc /etc/profile and so on...

the only thing abuot csh is that bash just doesn't need the setenv command, it's implicit in the command you run in bash, just like old fortran used to have to use

LET X = X + 1
but soon got replaced by
X = X + 1

due to the way the commands were parsed.

but well.. there's no VARIABLES.INI file or something lying around.
 
Old 12-18-2001, 01:43 PM   #5
entm
Member
 
Registered: Oct 2001
Location: Atlanta, GA
Distribution: Red Hat 7.0
Posts: 45

Rep: Reputation: 15
You might check out the book "Running Linux" from O'Reilly. I think that shell variables and how to permanently modify them are discussed. I'll have to check when I get home tonight.
 
Old 12-18-2001, 03:18 PM   #6
aethereal
Member
 
Registered: Dec 2000
Location: Seattle
Distribution: Red Hat 8.0
Posts: 41

Original Poster
Rep: Reputation: 15
bluecadet writes:
"it's not in a file, it's in memory.
don't take this the wrong way, but maybe you think the issue is covered very
poorly because you think it's perhaps something else than it actually is..?"

It's interesting that you write that, because that is what I was beginning
to wonder. (The very absence of any mention of any kind of explicit
'initialization file' in the books I have did lead me to wonder.) However...

bluecadet writes:
"in the bashrc files, that will create the path if there isn't one already, as
do other files which are processed before it."

I do understand what you're saying. But, as you wrote, somewhere the path does
have to be created "if there isn't one already." By now, largely out of
curiosity, I have looked pretty hard for the first instance of PATH being set.
But every reference to PATH that I have come across does seem to
include some modification of a previously existing PATH (i.e., $PATH). The
closest I have come to finding the genesis of PATH is /etc/profile. I do think
it has to be set somewhere to begin with. : ) But I haven't found
it quite found it yet.

Btw: You are definitely right about ~many~ files (at various
levels) modifying such environment variables as PATH.

Still, every environment variable does have to be initialized ~somewhere~ by a
file. It has to get into memory somehow. : )

Re: no need for setenv in bash
Yes, I think you are right. What I have just read about bash agrees.

entm writes:
"You might check out the book "Running Linux" from O'Reilly. I think that shell
variables and how to permanently modify them are discussed. I'll have to check
when I get home tonight."

Believe it or not, that is one of my books. (It's a great
book, too, imo. I really like it.) However, beyond the "export" trick I
mentioned earlier, it does not seem to delve too much more into setting
(or the initialization locations of) environment variables, such as PATH, in
bash. (p. 107, Third Edition)

Thanks guys,
Ben
 
Old 12-18-2001, 04:58 PM   #7
bluecadet
Member
 
Registered: Oct 2001
Distribution: MD81 RH71
Posts: 555

Rep: Reputation: 30
probably the earliest refence to PATH (obviously this is only an example..) is /etc/rc.sysinit. my one there doesn't have a PATH=$PATH thing there, so if it did get done earlier, it'd get nuked.

but... if it wasn't already set there, it really wouldn't matter if it wasn't there, apart from some of the program between rc.sysint and the next setting mightn't work.

my normal PATH is.... EEKKK!!!
/usr/X11R6/bin:/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/games:/usr/local/netscape:/usr/bin/mozilla:/usr/local/staroffice6.0/program:/usr/X11R6/bin:/usr/games:/usr/local/netscape:/usr/bin/mozilla:/usr/local/staroffice6.0/program:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin:/usr/local/bin
so it's a bit of a mess, but the first PATH def of
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:
has been repeated once or twice anyway...

but there's no BIG BANG or such with variables, they don't get defined or anything like in other programming languages... you canalways invent your own, add to others or remove others at a whim.
 
Old 12-19-2001, 09:34 AM   #8
entm
Member
 
Registered: Oct 2001
Location: Atlanta, GA
Distribution: Red Hat 7.0
Posts: 45

Rep: Reputation: 15
When I got home last night, I tried the following commands in a terminal window when I booted up Linux:

ls -a

less .bashrc

(not much here)

q

less .bash_profile

(gives your path variable and references to /etc/.bashrc)

q

I think to change your path permanently you will want to edit /etc/.bashrc. I'm not sure if it is /etc/.bashrc or /etc/bashrc. I can't remember exactly what the filename was, but this should be enough for you to find it in /etc.

If you only want to change your $PATH for a single user, then it looks like editing .bash_profile in your user account will be sufficient. Changing anything in /etc will be a global change that affects any new user accounts that are made on the machine.

Check 'Running Linux' pages 90-110 for the important files that are accessed when you boot-up.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environment Variables - where do they go!?! iansoundz Linux - General 7 11-17-2005 02:27 AM
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:08 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