TRIES=0 until ./iperf ... do if [ "$TRIES" -ge 5 ] then echo "Too many tries" break fi echo "retrying" TRIES=`expr $TRIES + 1` done