From 53297b1441539efdc44fc9c8f4f19fb6ba8290c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= Date: Thu, 21 Nov 2013 12:03:32 +0100 Subject: [PATCH] Fix setting undefined variable in CSH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Písař --- lib/local/lib.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/local/lib.pm b/lib/local/lib.pm index 289e13b..d4f8e2a 100644 --- a/lib/local/lib.pm +++ b/lib/local/lib.pm @@ -343,7 +343,24 @@ sub build_bourne_env_declaration { sub build_csh_env_declaration { my $class = shift; my($name, $value) = @_; - return defined($value) ? qq{setenv ${name} "${value}";\n} : qq{unsetenv ${name};\n}; + if (defined($value)) { + if ($value =~ /(.*)(\A|\Q$Config{path_sep}\E)(\$)(.+?)(\z|\Q$Config{path_sep}\E)(.*)/) { + # If a variable reference exists in the value, we have to delimit it and + # dereference it only if it is defined. + return + qq{test 1 == \$\{?$4\} && } . + qq{setenv ${name} "${1}${2}${3}\{${4}\}${5}${6}"} . + qq{ || } . + qq{setenv ${name} "${1}} . + (($2 ne '' and $5 ne '') ? qq{${2}} : '') . + qq{${6}"} . + qq{;\n}; + } else { + return qq{setenv ${name} "${value}";\n}; + } + } else { + return qq{unsetenv ${name};\n}; + } } sub build_win32_env_declaration { -- 1.8.3.1