Fixed bug #42725: csh with \n in variables

This commit is contained in:
Ole Tange 2014-07-15 15:58:31 +02:00
parent 597bae74af
commit 9c58321482
9 changed files with 58 additions and 11 deletions

View file

@ -220,13 +220,15 @@ Subject: GNU Parallel 20140722 ('Eyal Gilad Naftali') released
GNU Parallel 20140722 ('Eyal Gilad Naftali') has been released. It is available for download at: http://ftp.gnu.org/gnu/parallel/
This release contains a major change in central parts of the code and should be considered alpha quality. As always it passes the testsuite, so most functionality clearly works.
This release contains a major change in central parts of the code and should be considered beta quality. As always it passes the testsuite, so most functionality clearly works.
Thanks to Malcolm Cook for the brilliant idea to use a general perl expression as a replacement string.
Haiku of the month:
Programs very slow.
Multiple can run at once.
Use GNU Parallel.
Are you tired of
inflexible replacements?
Use Perl expressions.
-- Ole Tange
New in this release:

View file

@ -1006,6 +1006,7 @@ sub parse_env_var {
# Parse --env and set $Global::envvar
# Returns: N/A
$Global::envvar = "";
$Global::envwarn = "";
my @vars = ();
for my $varstring (@opt::env) {
# Split up --env VAR1,VAR2
@ -1039,10 +1040,16 @@ sub parse_env_var {
}
push @qbash, map { my $a=$_; "eval $a\"\$$a\"" } @bash_functions;
# Check if any variables contain \n
if(grep /\n/, @ENV{@vars}) {
# \n is bad for csh and will cause it to fail.
$Global::envwarn .= ::shell_quote_scalar(q{echo $SHELL | egrep "/t?csh" > /dev/null && echo CSH/TCSH DO NOT SUPPORT newlines IN VARIABLES/FUNCTIONS && exec false;}."\n");
}
# Create lines like:
# echo $SHELL | grep "/t\\{0,1\\}csh" >/dev/null && setenv V1 val1 && setenv V2 val2 || export V1=val1 && export V2=val2 ; echo "$V1$V2"
if(@vars) {
$Global::envvar =
$Global::envvar .=
join"",
(q{echo $SHELL | grep "/t\\{0,1\\}csh" > /dev/null && }
. join(" && ", @qcsh)
@ -1787,7 +1794,8 @@ sub progress {
my $rev = '';
my $reset = '';
my $terminal_width = terminal_columns();
my $s = sprintf("%-${terminal_width}s",$bar_text);
my $s = sprintf("%-${terminal_width}s",
substr($bar_text,0,$terminal_width));
my $width = int($terminal_width * $pctcomplete);
$s =~ s/^(.{$width})/$1$reset/;
$s = "\r# ".int($this_eta)." sec $arg" . "\r". $pctcomplete*100 # Prefix with zenity header
@ -4880,7 +4888,8 @@ sub sshlogin_wrap {
# We cannot use parse_env_var(), as PARALLEL_SEQ changes
# for each command
my $parallel_env =
(q{ 'eval `echo $SHELL | grep "/t\\{0,1\\}csh" > /dev/null }
($Global::envwarn
. q{ 'eval `echo $SHELL | grep "/t\\{0,1\\}csh" > /dev/null }
. q{ && echo setenv PARALLEL_SEQ '$PARALLEL_SEQ'\; }
. q{ setenv PARALLEL_PID '$PARALLEL_PID' }
. q{ || echo PARALLEL_SEQ='$PARALLEL_SEQ'\;export PARALLEL_SEQ\; }

Binary file not shown.

View file

@ -1338,6 +1338,15 @@ used as a positional replacement string (like B<{2.}>).
It is recommended to only change $_ but you have full access to all
of GNU B<parallel>'s internal functions and data structures.
Here are a few examples:
Remove 2 extensions (e.g. .tar.gz)
--rpl '{..} s:\.[^/.]+$::;s:\.[^/.]+$::;'
Keep only the extension
--rpl '{ext} s:.*\.::'
Is the job sequence even or odd?
--rpl '{odd} $_=$job->seq()%2?"odd":"even"'
See also: B<{= perl expression =}> B<--parens>

View file

@ -1494,6 +1494,17 @@ used as a positional replacement string (like @strong{@{2.@}}).
It is recommended to only change $_ but you have full access to all
of GNU @strong{parallel}'s internal functions and data structures.
Here are a few examples:
@verbatim
Remove 2 extensions (e.g. .tar.gz)
--rpl '{..} s:\.[^/.]+$::;s:\.[^/.]+$::;'
Keep only the extension
--rpl '{ext} s:.*\.::'
Is the job sequence even or odd?
--rpl '{odd} $_=$job->seq()%2?"odd":"even"'
@end verbatim
See also: @strong{@{= perl expression =@}} @strong{--parens}
@item @strong{--max-chars}=@emph{max-chars}
@ -2653,7 +2664,8 @@ these chunks. To parallelize both reading of bigfile and regexp.txt
combine the two using --fifo:
@verbatim
parallel --pipepart --block 100M -a bigfile --fifo cat regexp.txt \| parallel --pipe -L1000 --round-robin grep -f - {}
parallel --pipepart --block 100M -a bigfile --fifo cat regexp.txt \
\| parallel --pipe -L1000 --round-robin grep -f - {}
@end verbatim
@node EXAMPLE: Using remote computers

View file

@ -58,7 +58,7 @@ installparallel: ../src/parallel
startdb:
#echo shutdown abort | sudo su - oracle -c "sqlplus / as sysdba"
sudo parallel /etc/init.d/{} restart ::: postgresql mysql oracle-xe
sudo parallel /etc/init.d/{} restart ::: postgresql mysql # oracle-xe
VBoxManage startvm OracleXE || true
clean:

View file

@ -10,4 +10,13 @@ echo '### --wd no-such-dir - tcsh'
stdout parallel --wd /no-such-dir -S tcsh@localhost echo ::: "ERROR IF PRINTED"; echo Exit code $?
echo '### --wd no-such-dir - bash'
stdout parallel --wd /no-such-dir -S parallel@localhost echo ::: "ERROR IF PRINTED"; echo Exit code $?
echo '### bug #42725: csh with \n in variables'
not_csh() { echo This is not csh/tcsh; };
export -f not_csh;
parallel --env not_csh -S csh@lo not_csh ::: 1;
parallel --env not_csh -S tcsh@lo not_csh ::: 1;
parallel --env not_csh -S parallel@lo not_csh ::: 1;
EOF

View file

@ -14,8 +14,8 @@ done
echo "### Test if --load blocks. Bug.";
seq 1 1000 | parallel -kj2 --load 300% --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum
seq 1 1000 | parallel -kj0 --load 300% --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum
seq 1 1000 | parallel -kj240 --load 300% --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum
echo "### Test reading load from PARALLEL"
seq 1 1000000 | parallel -kj0 --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum
seq 1 1000000 | parallel -kj240 --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum
seq 1 1000000 | parallel -kj20 --recend "\n" --spreadstdin gzip -1 | zcat | sort -n | md5sum

View file

@ -20,3 +20,9 @@ echo '### --wd no-such-dir - bash'
mkdir: cannot create directory /no-such-dir: Permission denied
bash: line 0: cd: /no-such-dir: No such file or directory
Exit code 1
echo '### bug #42725: csh with \n in variables'
### bug #42725: csh with \n in variables
not_csh() { echo This is not csh/tcsh; }; export -f not_csh; parallel --env not_csh -S csh@lo not_csh ::: 1; parallel --env not_csh -S tcsh@lo not_csh ::: 1; parallel --env not_csh -S parallel@lo not_csh ::: 1;
CSH/TCSH DO NOT SUPPORT newlines IN VARIABLES/FUNCTIONS
CSH/TCSH DO NOT SUPPORT newlines IN VARIABLES/FUNCTIONS
This is not csh/tcsh