mirror of
https://github.com/envmodules/modules.git
synced 2026-05-30 00:12:31 +08:00
Enclose variable value within single quote for shells
When setting an environment variable on sh and fish shells, enclose the value within single quote rather escaping any special characters. With this change is its possible to have newline character included in environment variable value. Exception is made for csh shells where unsupported newline character in variable value is chopped. Other language supported where already enclosing variable values in single quotes (python, ruby, etc). Fixes #557 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
This commit is contained in:
@@ -232,7 +232,11 @@ proc renderSettings {} {
|
||||
new {
|
||||
switch -- [getState shelltype] {
|
||||
csh {
|
||||
set val [charEscaped $::env($var)]
|
||||
# cannot handle newline character in env var value with csh
|
||||
# shells: chop newline character in value (as done on
|
||||
# Modules v3 for all shells)
|
||||
set val [string map {\n {}} $::env($var)]
|
||||
set val [charEscaped $val]
|
||||
# csh barfs on long env vars
|
||||
if {[getState shell] eq {csh} && [string length $val] >\
|
||||
[getConf csh_limit]} {
|
||||
@@ -251,18 +255,18 @@ proc renderSettings {} {
|
||||
lappend g_shcode_out "setenv $var $val;"
|
||||
}
|
||||
sh {
|
||||
lappend g_shcode_out "$var=[charEscaped $::env($var)];\
|
||||
export $var;"
|
||||
set val [string map {' '\\''} $::env($var)]
|
||||
lappend g_shcode_out "$var='$val'; export $var;"
|
||||
}
|
||||
fish {
|
||||
set val [charEscaped $::env($var)]
|
||||
set val [charEscaped $::env($var) ']
|
||||
# fish shell has special treatment for PATH variable
|
||||
# so its value should be provided as a list separated
|
||||
# by spaces not by semi-colons
|
||||
if {$var eq {PATH}} {
|
||||
regsub -all : $val { } val
|
||||
set val [join [split $val :] {' '}]
|
||||
}
|
||||
lappend g_shcode_out "set -xg $var $val;"
|
||||
lappend g_shcode_out "set -xg $var '$val';"
|
||||
}
|
||||
tcl {
|
||||
set val $::env($var)
|
||||
|
||||
Reference in New Issue
Block a user