if I have a for each statement like this:
for i in 1 2 3 4
fairly large script here with lots of logic and stuff and $i is in many areas..the code in ehre also needs to run in a sequence...
how can I spawn the 4 loops in parallel and not run in serial
Best How To :
I think I understand what you mean now. You want 4 pairs of jobs to run in parallel and the 2 halves of each pair need to run sequentially. So, in essence, you have
Job 1A followed sequentially by Job 1B
Job 2A followed seuqentially by Job 2B
Job 3A followed sequentially by Job 3B
Job 4A followed sequentially by Job 4B
and the 4 lines above can all be run in parallel.
If that is the case, you need:
for i in 1 2 3 4 ; do
( echo $i A start; sleep 5; echo $i A end; echo $i B start; sleep 5; echo $i B end ) &