Nancy E. Davis (ne...@fa...) wrote:
> Hi Modules-interest,
>
> I am working with modules version 3.1.6 on Tru64 Unix, Tcl 8.4a1.
> I want to evaluate a users env var and use the module file to
> manipulate it. The env var in question is a space delimited list
> of compiler options, i.e.,
>
> me@host> echo $DEC_CC
> -L/usr/local/lib -L/var/shlib |
>
> When a user loads a particular module, I want to evaluate if they
> have DEC_CC set, what it is set to, and make certain more paths
> are included. When said user unloads a module, I want to recall
> the previous env var and give them back what they had.
>
> Is this possible? I'm having trouble getting the env var out of
> the users environment in any form. If this isn't possible, can I
> source a script at the end of the modulefile to do this?
Hello, Nancy.
You can try something like this:
if {([module-info mode load] || [module-info mode switch2]) && [info exists
env(DEC_CC)]} {
setenv _SAVE_DEC_CC $env(DEC_CC)
# Now do some regexp stuff in here to process DEC_CC
} else {
# Remove specific items added during loading of this module
}
Remember to think about the unload case carefully; putting Tcl flow
control statements around modules commands using [module-info mode
"load"] and the like can hide those modules commands. Use some
"puts stderr" statements in your code for debugging; it helps a lot.
The thing I think you'll have trouble with is the spaces. The
append-path statement uses colons, so I think you're stuck using
setenv to add/subtract from DEC_CC. But the "undo" of setenv
(which occurs when you "module unload) is to completely remove the
variable, independent of what it was set to in the first place. For
example, put "setenv DEC_CC blah" inside the else statement above
and you'll find that DEC_CC isn't defined after an unload, even
though it wasn't equal to "blah" during the unload.
So I don't think you can have DEC_CC exist when loading your
modulefile, add to it via a setenv during load (which is the
only way to get a space as a delimiter), and get back the original
after doing an unload.
Hmmm... something I just hacked into a test seems to have worked,
although I'd love for someone to weigh in as to just how bad an
idea it might be to do this.
puts -nonewline "setenv DEC_CC \"-L/usr/lib -L/shlib\";"
flush stdout ;
You can output your own custom commands using this, even during
an unload. Scary, but it may work for you. ;-) Note that this
string will be put up front of any output from modules (which will
be passed to "eval" in the shell).
Hope this helps,
- Leo
|