Skip to content

Instantly share code, notes, and snippets.

@crazy-max
Created June 3, 2013 01:01
Show Gist options
  • Save crazy-max/5695596 to your computer and use it in GitHub Desktop.
Save crazy-max/5695596 to your computer and use it in GitHub Desktop.
retry a function
#! /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