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*
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.
I was just reading about my .bash_profile file, but actually it simply *modifies* PATH as follows:
At this point, I really want to know where PATH itself is stored! What file holds environment variables???
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.
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.
"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...
"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.
"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)
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!!!
so it's a bit of a mess, but the first PATH def of
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.
When I got home last night, I tried the following commands in a terminal window when I booted up Linux:
(not much here)
(gives your path variable and references to /etc/.bashrc)
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.
|All times are GMT -5. The time now is 07:07 PM.|