diff options
author | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-28 18:35:54 +0000 |
---|---|---|
committer | graehl <graehl@ec762483-ff6d-05da-a07a-a48fb63a330f> | 2010-06-28 18:35:54 +0000 |
commit | 5c9419697fa7bfb77e40948ada16f8ec395a31e1 (patch) | |
tree | 50a2c7bb7dd3129401730523ee04bba8f8efc650 | |
parent | 277c981498170d1a0b43ea6fd3d7045badd9fb82 (diff) |
shell escape
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@39 ec762483-ff6d-05da-a07a-a48fb63a330f
-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 ''; |