Click to See Complete Forum and Search --> : looping a script endlessly


maxthree
12-04-2002, 11:31 PM
Hi,

just finished a script
works fine

only thing is, I want to loop it X times

tried with the 'for' command' but cannot maky it work.

anybody know how I can easily put it in a loop ?



I am running Unix, bourne shell.


Tks

bwkaz
12-05-2002, 01:35 AM
Bourne shell as in the normal sh, right? I don't know if this works in sh, but I know it works in bash. You can try something like:

for (( i=0 ; i < 10 ; i=i+1 )) ; do
<loop body>
done Again, I don't know if the original sh supports this or not, but it might be worth a shot.

apeekaboo
12-06-2002, 05:26 PM
Is this what your after?:

while true
do
... your code here
done

This will cause an endless loop, since true is always 'true'... ;)
This will work in bash and probably bourne as well.

apeekaboo
12-06-2002, 05:33 PM
Some clarification might be appropriate.

On most system you'll find the commands
/bin/true
and
/bin/false

true alway exits with status 0 which indicates a clean run.
false alway exits with status 1 which indicates an unclean run.

Try this at in a terminal:
# true
# echo $?
0

Try also:
# false
# echo $?
1

# indicates your prompt in the examples above
$? is a variable containing the exit status from the previous command.