Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing GNU Parallel within a script

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?

like image 999
memecs Avatar asked Jan 13 '14 11:01

memecs


People also ask

How do you run two commands in parallel shell?

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.

How do I run a parallel job in Unix?

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.

Do bash scripts run in parallel?

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.


1 Answers

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
like image 183
user000001 Avatar answered Oct 06 '22 08:10

user000001