Re: space-separated paths
Manage your shell environment variables and aliases
Brought to you by:
leomania,
xdelaruelle
From: Don M. <dp...@sg...> - 2000-02-18 18:42:55
|
Simon Barnes wrote: > > Are there any good techniques for dealing with space-separated > paths in modules? $INC_PATH is an example. We have a > shell-specific solution but dealing with multiple shells > is harder and would seem to call for some new functionality > in modules itself. You can't just use setenv because this causes > $INC_PATH to be wiped out when the module is unloaded. > > TIA > Simon Simon, Try this in your modulefile. I use this to modify environment variables for compiler options. If the module command does not have it, you can use tcl to extend it capabilities. regards, Don -------------------------------------- cut ----------------------------- # author: dpm # usage: prepend-env VAR arg # append-env VAR arg # arg must be double quoted if it contains whitespace # proc ldelete { l v } { set ix [lsearch -exact $l $v] if {$ix >= 0} { return [lreplace $l $ix $ix] } else { return $l } } proc remove-env {var {rem_val ""} } { global env envtmp foreach i $rem_val { set envtmp [ldelete $envtmp $i] } if {[string compare $envtmp ""] == 0} { puts -nonewline "unsetenv $var ;" } else { puts -nonewline "setenv $var '$envtmp';" } } proc prepend-env {var {new_val ""} } { global env envtmp if { ! [info exists env($var)]} { set envtmp "" } else { set envtmp $env($var) } if {[module-info mode load]} { foreach i $new_val { set ix [lsearch -exact $envtmp $i] if {$ix < 0} { set envtmp "$i $envtmp" } } } puts stderr "envtmp is $envtmp" case [module-info mode] in { "load" {puts -nonewline "setenv $var '$envtmp';"} "remove" {remove-env $var $new_val} } } proc append-env {var {new_val ""} } { global env envtmp if { ! [info exists envtmp]} { set envtmp $env($var) } if {[module-info mode load]} { foreach i $new_val { set ix [lsearch -exact $envtmp $i] if {$ix < 0} { puts stderr "$i does not exist in $var" set envtmp "$i $envtmp" } } } case [module-info mode] in { "load" {puts -nonewline "setenv $var '$envtmp';"} "remove" {remove-env $var $new_val} } } |