Skip to content

Instantly share code, notes, and snippets.

@jadedgnome
Created July 27, 2014 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadedgnome/2f5f656bc519f27407bc to your computer and use it in GitHub Desktop.
Save jadedgnome/2f5f656bc519f27407bc to your computer and use it in GitHub Desktop.
retry bash function, copied from http://redd.it/25tgqg
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