Bash script multithread in group of 3

I Have an script like

./bang 1
./bang 2
./bang 3
./bang 4
./bang 5
./bang 6
./bang 7
./bang 8
./bang 9
./bang 10
./bang 11
./bang 12

and i wanna execute him in groups of 3 , i mean he execute bang 1 , bang 2 and bang 3 after it finish the next 3 commands it will be executed and so on , in groups of 3.

Regards
John Hardey

Do you mean to say executing each set of three simultaneously ? ( background) and wait for them to finish before executing next three?
if not so, they are anyway will be executed one by one. no matters set of three!!!

for first case, you can try something like,

#!/usr/bin/ksh

i=1
while [ $i -le 12 ]
do
 ./bang $i &
 ./bang $(( i+1 )) &
 ./bang $(( i+2 )) &
 wait 
 i=$(( i+3 ))
done

I mean in set of three it will be faster or in set of ten .

Can u help me anchal khare ?

i need to execute in groups of lets say ten because it`s faster then one by one .

Thanks

Again, that depends on how they are going to be executed ( sequential or parallel ).
if they are "independent" of each other, you can run them in parallel mode. (taking consideration of how bulky they are to handle the CPU utilization)

if you can only run the script when previous finishes, I don't think you can do anything to make it faster by grouping of them.

Also, if they are taking time, may be you can do something to tune them.

they are independent of each other and i want sequential because it has 200 lines and i wanna execute them faster. like 20 30 at once.

Can you post the script? what are you doing inside that?