Agora tenho um modelo funcional para todos os caracteres, exceto \ n:
sub shell_quote_scalar {
# Quote the string so shell will not expand any special chars
# Returns:
# string quoted with \ as needed by the shell
my $a = shift;
$a =~ s/([sub shell_quote_scalar {
# Quote the string so shell will not expand any special chars
# Returns:
# string quoted with \ as needed by the shell
my $a = shift;
$a =~ s/([%pre%2-13-2\\#\?\'\(\)\{\}\[\]\*\>\<\~\|\; \"\!\$\&\'2-7])/\$1/g;
$a =~ s/[\n]/'\n'/g; # filenames with '\n' is quoted using \'
return $a;
}
sub env_quote {
my $v = shift;
$v =~ s/([ \n\&\<\>\(\)\;\'\{\}\t\"\$\'\*4\!\?\~])/\$1/g;
return $v;
}
my @qcsh = map { my $a=$_; "setenv $a " . env_quote($ENV{$a}) } @vars;
my @qbash = map { my $a=$_; "export $a=" . env_quote($ENV{$a}) } @vars;
$Global::envvar =
join"",
(q{echo $SHELL | grep -E "/t?csh" > /dev/null && }
. join(" && ", @qcsh)
. q{ || }
. join(" && ", @qbash)
.q{;});
print shell_quote_scalar($Global::envvar);
2-13-2\\#\?\'\(\)\{\}\[\]\*\>\<\~\|\; \"\!\$\&\'2-7])/\$1/g;
$a =~ s/[\n]/'\n'/g; # filenames with '\n' is quoted using \'
return $a;
}
sub env_quote {
my $v = shift;
$v =~ s/([ \n\&\<\>\(\)\;\'\{\}\t\"\$\'\*4\!\?\~])/\$1/g;
return $v;
}
my @qcsh = map { my $a=$_; "setenv $a " . env_quote($ENV{$a}) } @vars;
my @qbash = map { my $a=$_; "export $a=" . env_quote($ENV{$a}) } @vars;
$Global::envvar =
join"",
(q{echo $SHELL | grep -E "/t?csh" > /dev/null && }
. join(" && ", @qcsh)
. q{ || }
. join(" && ", @qbash)
.q{;});
print shell_quote_scalar($Global::envvar);