ToxicCode =Home= / =Config Files= / =Shell Scripts= / =Articles= / =Text Files= / =Misc= /
Register | Login | Submit new shell script#!/bin/bash
#retry.sh
#Originally by Mashi from http://bbs.archlinux.org/viewtopic.php?id=56646
#Retry a command N number of times.
#Example: retry echo "hello" 5 will print "hello" 5 times.
####
COUNT=-1
if [[ $1 =~ ^[0-9]+$ ]]; then
COUNT=$1
shift
fi
STATUS=0
while [ "$COUNT" -ne 0 ]; do
let COUNT-=1
$*
STATUS=$?
if [ $STATUS -eq 0 ]; then
exit $STATUS
fi
done
exit $STATUS