After reading two articles/post (I put the links below) I decided to parallelize my commands to be more effective. I would like use a For loop to run multiple commands parallel.
FIRST: For example, I create a file, basically a list of multiple commands that I want to run parallel:
> list
echo $'echo 123\necho 456' > list
so I have this file, in which the "echo 123..." is the one that I will replace with my future command, which is more complex, this is just for test. (maybe I will put here BLAST, BWA mapping or STRUCTURE analysis commands...etc. doesn't matter at the moment)
SECOND: I create a bash script which will run them parallel:
#!/bin/bash
for task in "$list"; do {
$task &
} done
However, this bash script doesn't work, I don't clearly understand how and why should work.
Please look at these articles/posts where I found this:
https://unix.stackexchange.com/questions/103920/parallelize-a-bash-for-loop (look at the comment with 258 vote) https://www.slashroot.in/how-run-multiple-commands-parallel-linux (look at the fourth screenshot)
I would like to kindly request help how to design this, since I'm not an expert in bash scripting. (I often face the situation that I have multiple processors/cores and commands run sequentially, one after the other. I see this by hitting the htop
command)