diff --git a/src/parallel b/src/parallel index a4ee96eb..6fb75e60 100755 --- a/src/parallel +++ b/src/parallel @@ -631,7 +631,7 @@ sub get_options_from_array { sub parse_options { # Returns: N/A # Defaults: - $Global::version = 20130131; + $Global::version = 20130212; $Global::progname = 'parallel'; $Global::infinity = 2**31; $Global::debug = 0; @@ -4739,6 +4739,7 @@ sub simple_replace_placeholders { # Merge arguments from records into args for easy access CORE::push @args, @$record; } + my $n = $#args+1; # Which replace strings are used? # {#} {} {/} {//} {.} {/.} {n} {n/} {n//} {n.} {n/.} for my $used (keys %{$self->{'replacecount'}}) { @@ -4747,9 +4748,9 @@ sub simple_replace_placeholders { # {} {/} {//} {.} {/.} $replace{$Global::replace{$used}} = join(" ", map { $_->replace($used) } @args); - } elsif($used =~ /^\{(\d+)(|\/|\/\/|\.|\/\.)\}$/) { - # {n} {n/} {n//} {n.} {n/.} - my $positional = $1; # number if any + } elsif($used =~ /^\{(-?\d+)(|\/|\/\/|\.|\/\.)\}$/) { + # {n} {n/} {n//} {n.} {n/.} {-n} {-n/} {-n//} {-n.} {-n/.} + my $positional = $1 > 0 ? $1 : $n+$1+1; my $replacementfunction = "{".::undef_as_empty($2)."}"; # {} {/} {//} {.} or {/.} # If -q then the replacementstrings will be quoted, too # {1.} -> \{1.\} diff --git a/testsuite/tests-to-run/parallel-local164.sh b/testsuite/tests-to-run/parallel-local164.sh index 997ad026..9ae789c6 100644 --- a/testsuite/tests-to-run/parallel-local164.sh +++ b/testsuite/tests-to-run/parallel-local164.sh @@ -129,8 +129,10 @@ echo '### --resume -k' parallel -k --resume --joblog /tmp/joblog-resume echo job{}id\;exit 0 ::: 0 1 2 3 0 5 6 7 echo '### Negative replacement strings' - parallel -N 6 echo {-1}orrec{1} ::: t B C D E c - parallel -N 6 echo {-1}orrect ::: A B C D E c + parallel -X -j1 -N 6 echo {-1}orrec{1} ::: t B X D E c + parallel -N 6 echo {-1}orrect ::: A B X D E c + parallel --colsep ' ' echo '{2} + {4} = {2} + {-1}=' '$(( {2} + {-1} ))' ::: "1 2 3 4" + parallel --colsep ' ' echo '{-3}orrect' ::: "1 c 3 4" EOF