Connecting Tech Pros Worldwide Forums | Help | Site Map

bash script to run program N times

Newbie
 
Join Date: Sep 2009
Posts: 6
#1: Sep 22 '09
wasn't sure what forum to put this in, but I'm sure someone here can help me.

I have a program that I want to run N times. I'd like to make a bash script that, when run like this:

./script.sh 5

will run my program 5 times, where my program can be run like this:

./myprogram

Basically I just need a loop that will execute my program, then iterate when the execution exits.

Any tips?

sumittyagi's Avatar
Expert
 
Join Date: Mar 2007
Location: New Delhi, India
Posts: 198
#2: Sep 23 '09

re: bash script to run program N times


use for loop construct, or while loop construct.. whichever you like.

Google -> using loops in shell script

Hope this helps

Best Regards,
Sumit.
vl4kn0's Avatar
Newbie
 
Join Date: Feb 2009
Location: Topolcany, Slovakia
Posts: 5
#3: Oct 3 '09

re: bash script to run program N times


Expand|Select|Wrap|Line Numbers
  1. #!/bin/bash
  2.  
  3. for i in `seq 1 $1`; do
  4.         ./myprogram
  5. done
  6.  
Reply