Created
July 27, 2014 12:44
-
-
Save jadedgnome/2f5f656bc519f27407bc to your computer and use it in GitHub Desktop.
retry bash function, copied from http://redd.it/25tgqg
This file contains 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
retry(){ | |
# FROM http://redd.it/25tgqg | |
local delay=1 n | |
if ! [[ $1 = *[^0-9]* ]]; then | |
if (($1 > 0)); then | |
delay=$1 | |
fi | |
shift | |
fi | |
# run command | |
while ! "$@"; do | |
echo "retrying in ${delay}s" >&2 | |
for ((n=delay; n>0; n--)); do | |
sleep 1 || return | |
done | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment