How to feed a command in GNU parallel with an array? For example, I have this array:
x=(0.1 0.2 0.5)
and now I want to feed it to some command in parallel
parallel echo ::: $x
This does not work. It is feeding all the arguments to a single call, since it prints
0.1 0.2 0.5
instead of
0.1
0.2
0.5
which is the output of
parallel echo ::: 0.1 0.2 0.5
How can I do it right?
If you want to provide all the elements in the array use:
parallel echo ::: ${x[@]}
From: http://www.gnu.org/software/parallel/man.html
EXAMPLE: Using shell variables When using shell variables you need to quote them correctly as they may otherwise be split on spaces.
Notice the difference between:
V=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
parallel echo ::: ${V[@]} # This is probably not what you want
and:
V=("My brother's 12\" records are worth <\$\$\$>"'!' Foo Bar)
parallel echo ::: "${V[@]}"
When using variables in the actual command that contains special characters (e.g. space) you can quote them using '"$VAR"' or using "'s and -q:
V="Here are two "
parallel echo "'$V'" ::: spaces
parallel -q echo "$V" ::: spaces
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With