I wonder if someone could help me here. I am trying to find a way of exiting from a loop but not exiting me from the script for example
#!/bin/ksh
# ************* FUNCTIONS ******************
function1() { #ping test
ping $1 2 > /dev/null
if [ $? != 0 ] ; then
echo "Couldn't ping $1, skipping"
exit
else
echo "ping to $1 successful, continuing to function2"
fi
}
function2() { # now we can ping ...check the location
location=`ssh $1 'cat /etc/location'`
if [ $location = "London" ] ; then
loc=ldn
echo "Location is London, passing on to function3"
else
echo "location is NOT London, Skipping"
exit
fi
}
#### main script body ####
for n in list
do
function1 $n
function2 $n
etc
etc
done
hopefully youll get the general idea, i have a load of functions to perform for each item in my for loop, if they dont "pass" the first function, id like to not have to run through every subsequent function in the loop, id like it to quit there and move onto the next item in the for loop
I tried putting an "exit" and an "exit 0" into the fail criteria of the first function, but that quits me out of the whole script and not just that loop item,
Is there any way of doing this ?