Created
April 14, 2026 12:11
-
-
Save meyt/de86e868a8d893f287efd633d1572ab9 to your computer and use it in GitHub Desktop.
Retry the command until its done (zsh compatible)
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
| # Retry the command until its done. | |
| # install: put it in .zshrc or .bashrc | |
| # usage: | |
| # untilok rsync ... | |
| # RETRY_DELAY=2 untilok rsync ... | |
| untilok() { | |
| retrydelay=${RETRY_DELAY:-10} # seconds; override by exporting RETRY_DELAY | |
| while true; do | |
| "$@" | |
| cmdstatus=$? | |
| if [[ $cmdstatus -eq 0 ]]; then | |
| echo "✅ Command succeeded." | |
| break | |
| else | |
| echo "⚠️ Command failed with exit code $cmdstatus. Retrying in $retrydelay seconds..." | |
| sleep "$retrydelay" | |
| fi | |
| done | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment