Search code examples
bashparallel-processinggnu-parallel

How to run 2 or more scripts from different directory in parallel


As of now I a using time parallel to run scripts in parallel. Example... First, I'll go to the directory where the scripts are located.

cd $DIR

Then, execute scripts

time parallel ::: $script1 $script2 $script3

This works well.

But what if the scripts are in different directory?


Solution

  • You can use an ampersand (&) for background execution in bash, and (command) to run command in a subshell:

    (cd $DIR1; $script1) &
    (cd $DIR2; $script2) &