The command parallel echo {} ::: A B C
executed from the command line return the correct result, while when invoked within a bash script return the error:
This is the script:
#script.bash
#!/usr/bin/env bash
parallel echo {} ::: A B C
This is the output:
bash script.bash
/bin/bash: {}: command not found
/bin/bash: ::: command not found
/bin/bash: A: command not found
/bin/bash: B: command not found
/bin/bash: C: command not found
Any idea why and how to correctly call GNU parallel within a bash script?
For instance, if there are two commands: command A and command B, using the semicolon operator in between them ensures that both the first and the second command get executed sequentially regardless of the output of the first command.
The next method that we can use to run processes in parallel is our regular xargs command. Xargs supports an option to specify the number of processes that you want to run simultaneously. See below. seq command will simply give 1, 2, and 3 as output in three lines.
To run script in parallel in bash, you must send individual scripts to background. So the loop will not wait for the last process to exit and will immediately process all the scripts.
Apparently the --tollef
switch (that does not support the :::
syntax) gets enabled when you run it from a script.
You can fix it either by enabling the --gnu
switch as with
parallel --gnu echo {} ::: A B C
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