bug-parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GNU Parallel Bug Reports why is parallel invoking a shell **by defau


From: Stephane Chazelas
Subject: Re: GNU Parallel Bug Reports why is parallel invoking a shell **by default** and associated bugs
Date: Tue, 2 Jun 2015 20:46:23 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

2015-05-25 22:08:03 +0200, Ole Tange:
[...]
> > There are of course contexts that parallel can't always get
> > right like typeset -A a; a[{1}]=1... (though of course one can
> > find work-arounds).
> 
> Let us find these contexts that work without GNU Parallel and document
> them . Your backtick example above does not qualify, because if the
> user runs the command outside GNU Parallel it also will not work. It
> has to be examples that start to fail when prepending 'parallel'.
[...]

A few examples for Bourne-like shells

That's comparing {} with using "$1" or $1 as you'd do with a
xargs -P based solution:

--------------------------------------------------------------------
$ echo './`uname`.txt' | xargs -P0 -n1 sh -c 'b=`basename -- "$1"`; echo "$b"' 
sh                                                                             |
`uname`.txt
$ echo './`uname`.txt' | parallel 'b=`basename -- {}`; echo "$b"'               
                                                                              |
Linux.txt

Can become serious if run as:

parallel '... `...{}`' ::: *

in a directory where files with arbitrary names can be uploaded by 3rd parties.

Work around:
 - use $(...) instead of `...` where available.
 - use parallel 'var={}; ...`with "$var"`'

--------------------------------------------------------------------
$ printf '%s\n' foo -f | xargs -P0 -n1 bash -c '[[ $1 = foo ]] && echo yes || 
echo no' bash                                                                   
|
yes
no
$ printf '%s\n' foo -f | PARALLEL_SHELL=bash parallel '[[ {} = foo ]] && echo 
yes || echo no'                                                            |
yes
bash: -c: line 0: syntax error in conditional expression
bash: -c: line 0: syntax error near `foo'
bash: -c: line 0: `[[ -f = foo ]] && echo yes || echo no'

Work around:
 - use parallel 'var={}; [[ $var = foo ]]...'
--------------------------------------------------------------------
$ printf '%s\n' foo 2 | xargs -P0 -n1 sh -c 'echo "$1">/dev/tty' sh
foo
2
$ printf '%s\n' foo 2 | PARALLEL_SHELL=sh parallel 'echo {}>/dev/tty'
foo

$

Work arounds:
 - use parallel 'var={}; ...'
 - make sure to leave a space between {} and a redirection operator

--------------------------------------------------------------------
zsh doesn't like newline characters in literal hash keys:

$ export a=$'a\nb'
$ printf '%s\0' "$a" | PARALLEL_SHELL=zsh  parallel -0 'typeset -A h; h[$a]=1; 
echo "${h[{}]}"'

$ printf '%s\0' "$a" | xargs -0P0 -n1 zsh -c 'typeset -A h; h[$a]=1; echo 
"${h[$1]}"' sh
1

bash doesn't like empty hash keys but that's a bug in bash which
I'll report shortly, nothing to do with parallel.
--------------------------------------------------------------------

-- 
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]