Re: space-separated paths
Manage your shell environment variables and aliases
Brought to you by:
leomania,
xdelaruelle
From: Simon B. <ba...@ga...> - 2000-02-18 19:01:04
|
Thanks, but this is a variation on what we have at present. The problem is that when you puts -nonewline "setenv $var '$envtmp';" for example, this causes setenv to be executed by the shell. Unfortunately, sh and ksh don't have a setenv command so an error is generated. I imagine the same would go for Perl and any other non-C-shell-like environments. It's possible to emulate the setenv command, more or less, with a ksh function, but it's not as easy as it sounds to pass spaces through layers of shells and evals. I tried one version published in a Korn shell book which did _not_ work. 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} > } >} |