Gabriel
Gabriel

Reputation: 9432

Foward empty arguments to GNU parallel does not work?

I have the following

function doit() { echo "'$1', '$2', '$3'"; }
export -f doit
args=("a" "") # Empty argument
echo -e "1\n2" | parallel -k "doit" "${args[@]}" {}

Which does not forward the empty argument:

'a', '1', ''
'a', '2', ''

instead it should be

'a', '', '1'
'a', '', '2'

Why does parallel do this and how to fix it?

Upvotes: 1

Views: 261

Answers (1)

KamilCuk
KamilCuk

Reputation: 140960

parallel passed strings to bash -c - they are interpreted according to shell rules, empty arguments are just concatenated and subject to word splitting expansion.

If you want to preserve arguments, quote them. Either "$(printf "%q " "${args[@]}")" manually or just parallel -q or parallel --quote.

Upvotes: 2

Related Questions