Last active
August 5, 2025 14:16
-
-
Save maurofaccenda/2b4a6c40ca4a5539c721a9cfdf7c7c33 to your computer and use it in GitHub Desktop.
retry in bash/zsh
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
| # 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