diff options
Diffstat (limited to 'vest/parallelize.pl')
-rwxr-xr-x | vest/parallelize.pl | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/vest/parallelize.pl b/vest/parallelize.pl index 6a2da1bb..28260155 100755 --- a/vest/parallelize.pl +++ b/vest/parallelize.pl @@ -35,6 +35,7 @@ my $randp=300; my $tryp=50; my $no_which; my $no_cd; + my $DEBUG=$ENV{DEBUG}; sub debug { if ($DEBUG) { @@ -48,6 +49,17 @@ sub abspath($) { chomp $a; $a } +my $is_shell_special=qr.[ \t\n\\><|&;"'`~*?{}$!()].; +my $shell_escape_in_quote=qr.[\\"\$`!].; +sub escape_shell { + my ($arg)=@_; + return undef unless defined $arg; + if ($arg =~ /$is_shell_special/) { + $arg =~ s/($shell_escape_in_quote)/\\$1/g; + return "\"$arg\""; + } + return $arg; +} my $abscwd=abspath(&getcwd); sub print_help; @@ -81,12 +93,8 @@ if ($no_which) { die "$prog not found - $cmd" unless $cmd; } #$cmd=abspath($cmd); -for my $arg (@ARGV){ - if ($arg=~ /\s/){ - $cmd .= " \"$arg\""; - } else { - $cmd .= " $arg" - } +for my $arg (@ARGV) { + $cmd .= " ".shell_escape($arg); } die "Please specify a command to parallelize\n" if $cmd eq ''; |