env_parallel.{bash,ksh,pdksh,zsh}: Minimal --record-env.

This commit is contained in:
Ole Tange 2016-11-06 12:29:48 +01:00
parent e458f35453
commit 3e440983e7
11 changed files with 112 additions and 55 deletions

View file

@ -63,6 +63,13 @@ env_parallel() {
' -- "$@" ' -- "$@"
)" )"
# --record-env
if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then
(compgen -a; compgen -A function; compgen -A variable) |
cat > $HOME/.parallel/ignored_vars
return 0
fi
# Grep alias names # Grep alias names
local _alias_NAMES="$(compgen -a | local _alias_NAMES="$(compgen -a |
grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )" grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )"

View file

@ -63,6 +63,13 @@ env_parallel() {
' -- "$@" ' -- "$@"
)" )"
# --record-env
if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then
(compgen -a; compgen -A function; compgen -A variable) |
cat > $HOME/.parallel/ignored_vars
return 0
fi
# Grep alias names # Grep alias names
_alias_NAMES="$(alias | perl -pe 's/=.*//' | _alias_NAMES="$(alias | perl -pe 's/=.*//' |
grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )" grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )"

View file

@ -63,6 +63,13 @@ env_parallel() {
' -- "$@" ' -- "$@"
)" )"
# --record-env
if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then
(compgen -a; compgen -A function; compgen -A variable) |
cat > $HOME/.parallel/ignored_vars
return 0
fi
# Grep alias names # Grep alias names
_alias_NAMES="$(alias | perl -pe 's/=.*//' | _alias_NAMES="$(alias | perl -pe 's/=.*//' |
grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )" grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )"

View file

@ -63,6 +63,13 @@ env_parallel() {
' -- "$@" ' -- "$@"
)" )"
# --record-env
if ! perl -e 'exit grep { /^--record-env$/ } @ARGV' -- "$@"; then
(compgen -a; compgen -A function; compgen -A variable) |
cat > $HOME/.parallel/ignored_vars
return 0
fi
# Grep alias names # Grep alias names
_alias_NAMES="$(print -l ${(k)aliases} | _alias_NAMES="$(print -l ${(k)aliases} |
grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )" grep -E "^$_grep_REGEXP"\$ | grep -vE "^$_ignore_UNDERSCORE"\$ )"

View file

@ -74,11 +74,14 @@ if($opt::skip_first_line) {
my $fh = $input_source_fh[0]; my $fh = $input_source_fh[0];
<$fh>; <$fh>;
} }
if($opt::header and not $opt::pipe) {
set_input_source_header();
sub set_input_source_header {
if($opt::header and not $opt::pipe) {
# split with colsep or \t # split with colsep or \t
# $header force $colsep = \t if undef? # $header force $colsep = \t if undef?
my $delimiter = $opt::colsep; my $delimiter = defined $opt::colsep ? $opt::colsep : "\t";
$delimiter ||= "\t";
# regexp for {= # regexp for {=
my $left = "\Q$Global::parensleft\E"; my $left = "\Q$Global::parensleft\E";
my $l = $Global::parensleft; my $l = $Global::parensleft;
@ -102,12 +105,13 @@ if($opt::header and not $opt::pipe) {
$id++; $id++;
} }
} }
} else { } else {
my $id = 1; my $id = 1;
for my $fh (@input_source_fh) { for my $fh (@input_source_fh) {
$Global::input_source_header{$id} = $id; $Global::input_source_header{$id} = $id;
$id++; $id++;
} }
}
} }
if($opt::filter_hosts and (@opt::sshlogin or @opt::sshloginfile)) { if($opt::filter_hosts and (@opt::sshlogin or @opt::sshloginfile)) {
@ -187,10 +191,8 @@ if($Global::semaphore) {
} }
$SIG{TERM} = \&start_no_new_jobs; $SIG{TERM} = \&start_no_new_jobs;
start_more_jobs(); start_more_jobs();
if(not $opt::pipepart) { if($opt::pipe and not $opt::pipepart) {
if($opt::pipe) {
spreadstdin(); spreadstdin();
}
} }
::debug("init", "Start draining\n"); ::debug("init", "Start draining\n");
drain_job_queue(); drain_job_queue();
@ -206,14 +208,10 @@ if($opt::pipe and @opt::a) {
} }
} }
::debug("init", "Cleaning\n"); ::debug("init", "Cleaning\n");
cleanup();
if($Global::semaphore) { if($Global::semaphore) {
$sem->release(); $sem->release();
} }
for(keys %Global::sshmaster) { cleanup();
# If 'ssh -M's are running: kill them
kill "TERM", $_;
}
::debug("init", "Halt\n"); ::debug("init", "Halt\n");
if($opt::halt and $Global::halt_when ne "never") { if($opt::halt and $Global::halt_when ne "never") {
if(not defined $Global::halt_exitstatus) { if(not defined $Global::halt_exitstatus) {
@ -1820,6 +1818,10 @@ sub cleanup {
unlink keys %Global::unlink; unlink keys %Global::unlink;
map { rmdir $_ } keys %Global::unlink; map { rmdir $_ } keys %Global::unlink;
if(@opt::basefile and $opt::cleanup) { cleanup_basefile(); } if(@opt::basefile and $opt::cleanup) { cleanup_basefile(); }
for(keys %Global::sshmaster) {
# If 'ssh -M's are running: kill them
kill "TERM", $_;
}
} }
sub __QUOTING_ARGUMENTS_FOR_SHELL__ {} sub __QUOTING_ARGUMENTS_FOR_SHELL__ {}
@ -9459,7 +9461,7 @@ sub new {
if($opt::sqlworker) { if($opt::sqlworker) {
# Open SQL table # Open SQL table
$arg_sub_queue = SQLRecordQueue->new(); $arg_sub_queue = SQLRecordQueue->new();
} elsif($colsep) { } elsif(defined $colsep) {
# Open one file with colsep # Open one file with colsep
$arg_sub_queue = RecordColQueue->new($fhs); $arg_sub_queue = RecordColQueue->new($fhs);
} else { } else {

View file

@ -807,7 +807,9 @@ soon,fail=1-99%
Use regexp as header. For normal usage the matched header (typically Use regexp as header. For normal usage the matched header (typically
the first line: B<--header '.*\n'>) will be split using B<--colsep> the first line: B<--header '.*\n'>) will be split using B<--colsep>
(which will default to '\t') and column names can be used as (which will default to '\t') and column names can be used as
replacement variables: B<{column name}>. replacement variables: B<{column name}>, B<{column name/}>, B<{column
name//}>, B<{column name/.}>, B<{column name.}>, B<{=column name perl
expression =}>, ..
For B<--pipe> the matched header will be prepended to each output. For B<--pipe> the matched header will be prepended to each output.

View file

@ -27,8 +27,8 @@ echo 'bug #40135: FreeBSD: sem --fg does not finish under /bin/sh'
sem --fg 'sleep 1; echo The job finished' sem --fg 'sleep 1; echo The job finished'
echo 'bug #40133: FreeBSD: --round-robin gives no output' echo 'bug #40133: FreeBSD: --round-robin gives no output'
jot 1000000 | parallel --round-robin --pipe -kj3 wc | sort jot 1000000 | parallel --round-robin --pipe -kj3 cat | wc
jot 1000000 | parallel --round-robin --pipe -kj4 wc | sort jot 1000000 | parallel --round-robin --pipe -kj4 cat | wc
echo 'bug #40134: FreeBSD: --shebang not working' echo 'bug #40134: FreeBSD: --shebang not working'
(echo '#!/usr/bin/env -S parallel --shebang -rk echo'; echo It; echo worked) > shebang; (echo '#!/usr/bin/env -S parallel --shebang -rk echo'; echo It; echo worked) > shebang;

View file

@ -647,10 +647,22 @@ echo '### bug #48658: --linebuffer --files'
echo '**' echo '**'
bug #49538: --header and {= =} echo 'bug #49538: --header and {= =}'
parallel --header : echo '{=v2=}{=v1 $_=Q($_)=}' ::: v1 K ::: v2 O parallel --header : echo '{=v2=}{=v1 $_=Q($_)=}' ::: v1 K ::: v2 O
parallel --header : echo '{2}{=1 $_=Q($_)=}' ::: v2 K ::: v1 O parallel --header : echo '{2}{=1 $_=Q($_)=}' ::: v2 K ::: v1 O
parallel --header : echo {var/.} ::: var sub/dir/file.ext
parallel --header : echo {var//} ::: var sub/dir/file.ext
parallel --header : echo {var/.} ::: var sub/dir/file.ext
parallel --header : echo {var/} ::: var sub/dir/file.ext
parallel --header : echo {var.} ::: var sub/dir/file.ext
echo '**'
echo 'bug --colsep 0'
parallel --colsep 0 echo {2} ::: a0OK0c
parallel --header : --colsep 0 echo {ok} ::: A0ok0B a0OK0b
echo '**' echo '**'

View file

@ -26,7 +26,7 @@ p_wrapper() {
$DEBUG && sort -u $T1 $T2; $DEBUG && sort -u $T1 $T2;
rm $T1 $T2 rm $T1 $T2
p_showsqlresult $SERVERURL $TABLE p_showsqlresult $SERVERURL $TABLE
$DEBUG || sql $SERVERURL "drop table $TABLE;" >/dev/null $DEBUG || sql $SERVERURL "drop table $TABLE;" >/dev/null 2>/dev/null
} }
p_template() { p_template() {

View file

@ -28,15 +28,10 @@ bug #40135: FreeBSD: sem --fg does not finish under /bin/sh
The job finished The job finished
echo 'bug #40133: FreeBSD: --round-robin gives no output' echo 'bug #40133: FreeBSD: --round-robin gives no output'
bug #40133: FreeBSD: --round-robin gives no output bug #40133: FreeBSD: --round-robin gives no output
jot 1000000 | parallel --round-robin --pipe -kj3 wc | sort jot 1000000 | parallel --round-robin --pipe -kj3 cat | wc
299592 299592 2097144 1000000 1000000 6888896
299592 299592 2097144 jot 1000000 | parallel --round-robin --pipe -kj4 cat | wc
400816 400816 2694608 1000000 1000000 6888896
jot 1000000 | parallel --round-robin --pipe -kj4 wc | sort
149796 149796 1048572
235148 235148 1646037
299592 299592 2097144
315464 315464 2097143
echo 'bug #40134: FreeBSD: --shebang not working' echo 'bug #40134: FreeBSD: --shebang not working'
bug #40134: FreeBSD: --shebang not working bug #40134: FreeBSD: --shebang not working
(echo '#!/usr/bin/env -S parallel --shebang -rk echo'; echo It; echo worked) > shebang; chmod 755 ./shebang; ./shebang (echo '#!/usr/bin/env -S parallel --shebang -rk echo'; echo It; echo worked) > shebang; chmod 755 ./shebang; ./shebang

View file

@ -1765,11 +1765,29 @@ echo '### bug #48658: --linebuffer --files'
10 10
echo '**' echo '**'
** **
echo 'bug #49538: --header and {= =}'
bug #49538: --header and {= =} bug #49538: --header and {= =}
/bin/bash: bug: command not found
parallel --header : echo '{=v2=}{=v1 $_=Q($_)=}' ::: v1 K ::: v2 O parallel --header : echo '{=v2=}{=v1 $_=Q($_)=}' ::: v1 K ::: v2 O
OK OK
parallel --header : echo '{2}{=1 $_=Q($_)=}' ::: v2 K ::: v1 O parallel --header : echo '{2}{=1 $_=Q($_)=}' ::: v2 K ::: v1 O
OK
parallel --header : echo {var/.} ::: var sub/dir/file.ext
file
parallel --header : echo {var//} ::: var sub/dir/file.ext
sub/dir
parallel --header : echo {var/.} ::: var sub/dir/file.ext
file
parallel --header : echo {var/} ::: var sub/dir/file.ext
file.ext
parallel --header : echo {var.} ::: var sub/dir/file.ext
sub/dir/file
echo '**'
**
echo 'bug --colsep 0'
bug --colsep 0
parallel --colsep 0 echo {2} ::: a0OK0c
OK
parallel --header : --colsep 0 echo {ok} ::: A0ok0B a0OK0b
OK OK
echo '**' echo '**'
** **