Created
June 3, 2013 01:01
-
-
Save crazy-max/5695596 to your computer and use it in GitHub Desktop.
retry a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
MAX_RETRIES=3 | |
function sayHelloTo() { | |
echo "Hello $1!" | |
if [ -z "$2" ]; then local retry=0; else local retry=$2; fi | |
# Make something and test | |
if [ -d "/tmp/" ] | |
then | |
# Ok it works! | |
elif [ $retry -lt $MAX_RETRIES ] | |
then | |
# Else retry | |
echo "ERROR. Retry $retry/$MAX_RETRIES..." | |
sayHelloTo "$1" "$retry" | |
else | |
# Too many retries | |
echo "ERROR. Too many retries..." | |
fi | |
} | |
sayHelloTo "Crazy" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment