Skip to content

Instantly share code, notes, and snippets.

@maurofaccenda
Last active August 5, 2025 14:16
Show Gist options
  • Save maurofaccenda/2b4a6c40ca4a5539c721a9cfdf7c7c33 to your computer and use it in GitHub Desktop.
Save maurofaccenda/2b4a6c40ca4a5539c721a9cfdf7c7c33 to your computer and use it in GitHub Desktop.
retry in bash/zsh
# one-liner for adding a retry function in bash
# usage:
# retry <number of tries> <delay between each try> <command>
retry () { tries=0 ; max_tries="$1" ; delay="$2" ; shift 2 ; while [ "$tries" -lt "$max_tries" ] && ! $* ; do sleep "$delay" ; >&2 echo "Retrying..." ; ((tries++)) ; done }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment