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 | ea089f538ee7e55a3059341901daac8f11eb94c1 (patch) | |
tree | c0e9a55f2c76f4c722dbd1e2ad08bf3a0400979c | |
parent | d282b34a66f19de28f22b5c5145c639ebf2a105a (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 ''; |