diff --git a/src/parallel b/src/parallel index 933641dd..a9837571 100755 --- a/src/parallel +++ b/src/parallel @@ -1248,7 +1248,7 @@ sub read_options { while(<$in_fh>) { /^\s*\#/ and next; chomp; - push @ARGV_profile, shell_unquote(split/(? (q("'""), 'foo bar"', '\" quux'); + my $s = shift; + my (@words); + while($s =~ s{^ + ( + ( + [^\\'"\s]+ | # Not quoted + '[^']*' | # '....' - inside ' + \\. | # \? - quote single char + "( # Begin " + [^"\\]* | # Not quoted + (\\.)* # \? - quote single char + )*" # End " + )+ + ) + (\s+|$) + }{}xs + ) { + # split into words + push @words, $1; + } + for my $w (@words) { + my @wordpart; + while($w =~ s{^ + ( + [^\\'"\s]+ | # Not quoted + '[^']*' | # '....' - inside ' + \\. | # \? - quote single char + "( # Begin " + [^"\\]* | # Not quoted + (\\.)* # \? - quote single char + )*" # End " + ) }{}xs) { + my $wp = $1; + while($wp =~ s{^ + ([^\\'"\s]+) | # Not quoted + '([^']*)' | # '....' - inside ' + \\(.) | # \? - quote single char + "( # Begin " + [^"\\]* | # Not quoted + (\\.)* # \? - quote single char + )*" # End " + }{}xs) { + push @wordpart, $1, $2, $3; + my $doubleq = $4; + while($doubleq =~ s{^ + ([^"\\]+) | # Not quoted + \\(.) # \? - quote single char + }{}x) { + push @wordpart, $1, $2; + } + } + } + $w = join("",@wordpart); + } + return @words; +} + +sub shellwords { + $Global::use{"Text::ParseWords"} ||= eval "use Text::ParseWords; 1;"; + return Text::ParseWords::shellwords(@_); +} + +sub _shell_unquote { # Unquote strings from shell_quote # Inputs: # @strings = strings to be unquoted @@ -6978,6 +7041,7 @@ sub replace { $perlexpr =~ s/^-?\d+ //; # Positional replace treated as normal replace if(not defined $self->{"rpl",0,$perlexpr}) { local $_; + # TODO disable warnings if($Global::trim eq "n") { $_ = $self->{'orig'}; } else { @@ -6987,11 +7051,13 @@ sub replace { if(not $Global::perleval{$perlexpr}) { # Make an anonymous function of the $perlexpr # And more importantly: Compile it only once - if($Global::perleval{$perlexpr} = eval('sub { my $job = shift; '.$perlexpr.' }')) { + if($Global::perleval{$perlexpr} = + eval('sub { no strict; no warnings; my $job = shift; '. + $perlexpr.' }')) { # All is good } else { # The eval failed. Maybe $perlexpr is invalid perl? - ::error("Cannot use $perlexpr\n"); + ::error("Cannot use $perlexpr: $@\n"); ::wait_and_exit(255); } } @@ -7000,7 +7066,8 @@ sub replace { $self->{"rpl",0,$perlexpr} = $_; } if(not defined $self->{"rpl",$quote,$perlexpr}) { - $self->{"rpl",1,$perlexpr} = ::shell_quote_scalar($self->{"rpl",0,$perlexpr}); + $self->{"rpl",1,$perlexpr} = + ::shell_quote_scalar($self->{"rpl",0,$perlexpr}); } return $self->{"rpl",$quote,$perlexpr}; }