PDA

View Full Version : [SOLVED] run command x amount of times



Dr Small
January 6th, 2008, 06:35 PM
In bash, I want to make a while loop (I guess?) that runs a command x amount of times, until it finishes. I've been reading up on it at google, but can't find any down to earth examples (I have no idea about while).

Is there any way to do this?
I was just curious.

Dr Small

nhandler
January 6th, 2008, 06:54 PM
In this case, a for loop would be more appropriate (however, you could also use a while loop).

Here is the code you will use:


#!/bin/bash
for ((i=1;i<=5;i+=1)); do
YOUR CODE HERE
done

ghostdog74
January 7th, 2008, 03:18 AM
In bash, I want to make a while loop (I guess?) that runs a command x amount of times, until it finishes. I've been reading up on it at google, but can't find any down to earth examples (I have no idea about while).

Is there any way to do this?
I was just curious.

Dr Small



num=0
while [ $num -lt 5 ]
do
function
num=$(( num+1 ))
done



Read here (http://tldp.org/LDP/abs/html/)from start to end.

Dr Small
January 7th, 2008, 03:26 AM
Ok, thanks for the info. That worked :)

Dr Small