Bash – How to run a program multiple times with different arguments using a loop in a bash script

bash

I'm looking to run multiple instances of a python script with each instance being fed an incremental argument. So the bash script would do something like that :

for i from 1 to 10 do
    python script.py i

All scripts should run at the same time from one console of course. Any idea how to do that ?

Best Answer

To simply run the program ten times, with the (incremented) iteration number as an argument, do this:

for ((i=1; i<=10; i++))
do
    python script.py "$i"
done

As Kamaraj says, to get the ten processes to run at the same time (i.e., simultaneously / concurrently), add & to the command:

for ((i=1; i<=10; i++))
do
    python script.py "$i" &
done
Related Question