ToxicCode     =Home= / =Config Files= / =Shell Scripts= / =Articles= / =Text Files= / =Misc= /

Register | Login | Submit new shell script

Title: Retry
Submitted by: Fingel on 2009-03-16
Function: Retry a command numerous times

#!/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



Comments



Nothing Copyrighted