[wplug] Managing Environment Variables - Follow-up

Weber, Lawrence A Lawrence.Weber at ansaldo-sts.us
Tue Dec 1 12:25:52 EST 2009


I am currently trying out Environment Modules on a spare PC.  So far it
looks good.  It is not that I am not interested in an answer.  Since I
rebooted, I don't know if I can recreate the problem.

>From the beginning, in order, here is what I did:

1. Opened terminal.
2. Edited .bashrc, added three env vars.
3. Closed terminal.
4. Opened terminal.
5. Checked vars:  env | grep DIR  (where DIR was a part of the vars
names)
6. That checked out fine but it was a pain to have to edit/close/open
each time I changed projects.

So --

1. Opened terminal.,
2. Edited .bashrc, removed three env vars.
3. Closed terminal
4. Opened terminal
5. wrote a shell script to export the vars
6. sourced the script
7. Checked vars: as above and they were good.
8. Built program, watched output and saw many (but not all) called
makefiles using env var values removed in step 2.

Then  --

1.  Exited terminal
2.  Opened terminal (did not source script)
3.  Check vars as above and found that they existed with the value they
were first given months ago.
4.  Set them to null and rechecked to see that they were changed.
5.  Closed / open terminal and they were back to the old values again.
6.  Recursively searched home directory and /etc for any occurrence of
the vars or the values of these vars and found none.
7.  Verified .bash_profile had never been changed, by date.
8.  Rebooted
9.  Opened terminal and checked vars, they were not set.
10  Sourced shell script and rebuilt, all went well.

And all continues to work fine.  I have no idea why or how it was
setting those old values or why they were being used.  I don't think the
build process was opening sub shells but maybe it was.


-----Original Message-----
From: wplug-bounces+lawrence.weber=ansaldo-sts.us at wplug.org
[mailto:wplug-bounces+lawrence.weber=ansaldo-sts.us at wplug.org] On Behalf
Of Jonathan Billings
Sent: Tuesday, December 01, 2009 12:01 PM
To: General user list
Subject: Re: [wplug] Managing Environment Variables - Follow-up

On Tue, Dec 01, 2009 at 11:23:05AM -0500, Weber, Lawrence A wrote:
> That's how I understand it.  So when I started a terminal, that 
> subshell and all of the subshells it creates should have used the 
> value that I sourced in my script.  The script set values of 
> environment variables that were no longer in .bashrc or any other 
> file.  Somehow (I hate to use that word) the makefiles that my main 
> makefile was calling were able to access very old values of the 
> environment variables.  This feature went away after a reboot.  So I 
> have two questions that will never be answered, why did the called 
> makefiles not use the current values, and where did they find the old 
> values?  Thanks for your help.  I am going to have to let it drop as
it is working now and I have lots to do.

You asked a question, but don't want to know an answer.  For the benefit
of the community, though, I think I'll take a stab at answering and you
can simply delete this email.

I think you're still misunderstanding how environment variables work.
It sounds like you removed the variable definitions from your .bashrc,
and then sourced a file with new definitions of the same variables.

Unless you changed your .bashrc to set the variables to something else,
they will continue to be set in new shells to whatever value they were
set in your .bashrc when you first logged in.  Sourcing a file where
they're set again will temporarily change the values in the executing
shell, but once you terminate that shell any new shells you start will
continue to have their environment from their parent shell with the old
values.

If you're still reading, I do suggest you look into Environment Modules,
it was written to solve the problem you're encountering now.
We use then quite often to set up build environments for researchers who
want to have access to different libraries, compilers and executables,
installed next to each other, and still be able to use the same
makefiles.

--
Jonathan Billings <billings at negate.org>
_______________________________________________
wplug mailing list
wplug at wplug.org
http://www.wplug.org/mailman/listinfo/wplug



More information about the wplug mailing list