I have a bash array:
nodes=(
"command"
"command arg"
...
)
and I want to run all the commands with all the arguments that are already attached to them using GNU parallel.
I've tried
printf '%s\n' "${nodes[@]}" | parallel python
and
parallel python ::: "${nodes[@]}"
The output command is
python path_to_file\ arg
and the error it gives is "can't open file 'path_to_file arg'"
I think the problem has to do that backslash - I get the same error when I run the command without parallel.
How do I prevent it from putting the backslash in?
Try:
printf '%s\n' "${nodes[@]}" | parallel eval python
eval
is a shell command that evals the string as shell expression. I typically used it to "de-quote" a string.
or:
printf '%s\n' "${nodes[@]}" | parallel python {=uq=}
Newer versions of GNU Parallel have uq()
which leaves the value unquoted. Normally GNU Parallel will quote values.
or:
printf '%s\n' "${nodes[@]}" | parallel
The exception to the rule above is when there is no command. Then the value is unquoted.