From ece798a75250cf3621e37b22926d5137d0c99b71 Mon Sep 17 00:00:00 2001 From: Adam Moody Date: Fri, 3 Nov 2017 13:03:02 -0700 Subject: [PATCH] scr_param.pm: escape braces in regex (#105) --- scripts/common/scr_param.pm.in | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/scripts/common/scr_param.pm.in b/scripts/common/scr_param.pm.in index 26ddea15..41d8e1da 100644 --- a/scripts/common/scr_param.pm.in +++ b/scripts/common/scr_param.pm.in @@ -114,16 +114,18 @@ sub read_config_file exit 1; } -# my $value = shift @parts; - my $raw_value = shift @parts; - my $value = ''; - my @value_parts = split(/(\$\w+)|(\${\w+})/, $raw_value); - foreach my $seg (@value_parts) - { - next if (not defined($seg)); - $seg = ($ENV{$1} || '') if ($seg =~ m/\${?(\w+)}?/); - $value .= $seg; - } + # expand any embedded environment variable names as in + # key=$ENVVAR or key=/home/${USER}/${SLURM_JOBID} + # replaces variable with its value from the environment + my $value = ''; + my $raw_value = shift @parts; + my @value_parts = split(/(\$\w+)|(\$\{\w+\})/, $raw_value); + foreach my $seg (@value_parts) + { + next if (not defined($seg)); + $seg = ($ENV{$1} || '') if ($seg =~ m/\$\{?(\w+)\}?/); + $value .= $seg; + } # record the key value pair in the hash if (defined $master_key) {