Home > Software engineering >  running list of bash commands in a file in parallel
running list of bash commands in a file in parallel

Time:03-01

I have a simple text file (command_script.txt) that I am executing as a bash script.

The content of command_script.txt is something like this:

#!/bin/bash
some_command -flags input1 output1
some_command -flags input2 output2
some_command -flags input3 output3
...
some_command -flags input1000 output1000

I execute it on the command line (./command_script.txt) and it runs through one line at a time. Is there an easy way I can run 20 lines at a time in parallel?

Thanks!

CodePudding user response:

By appending "&" at the end of a line a process is launched in background. Hence, the next one is started immediately such that both are running in parallel.

CodePudding user response:

#!/usr/bin/parallel --shebang -j20
some_command -flags input1 output1
some_command -flags input2 output2
some_command -flags input3 output3
...
some_command -flags input1000 output1000
  • Related