Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

running a program

Status
Not open for further replies.

revit

Programmer
Oct 27, 2001
36
IL
I want to run a program several times , for example some thing like that:

for i=1 to 200
run program > out.txt
done

how do i write it correctly?
thanks

 
Hi Revit,

Try the following:
------------------

#!/bin/ksh

CNT=0

while (( CNT < 200 ))
do
run_program > out.txt
(( CNT = CNT + 1 ))
done


Thanks,

Gyan
 
Small corrections:

#!/bin/ksh

CNT=0

while (( CNT < 200 ))
do
run_program >> out.txt
(( CNT = $CNT + 1 ))
done
==============================
&quot;>>&quot; syntax is required to append to file,otherwise it will keep only the latest record.

CNT = $CNT + 1

&quot;$CNT&quot; MUSTbe used on the right side of the &quot;=&quot;.
&quot;Long live king Moshiach !&quot;
 
Hello Levw,

a) It depends, on user, whether he wants all (>>) or only the latest logs (>).

b) (( CNT = CNT + 1)) will do the job.
If you want to use $CNT, then use the following:

CNT = $CNT + 1

The (( )) is not required.

Thanks,

Gyan
 
shouldn't that be CNT=`expr $CNT+1` ? Sivakumar Kandaraj
web system programmer
Melbourne
 
Consider saving the output with the following minor change. This saves stdout to file as a single stream instead of 200 open-append-closes.

#!/bin/ksh
# OLD SCRIPT
CNT=0
while (( CNT < 200 ))
do
run_program >> out.txt
(( CNT = $CNT + 1 ))
done
# END OF SCRIPT

change to

#! /usr/bin/ksh
# NEW SCRIPT
CNT=0

while (( CNT < 8 ))
do
ls
(( CNT = $CNT + 1 ))
done > out.txt
# END OF SCRIPT

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top