Created
September 4, 2019 13:19
-
-
Save aprell/d790229f13287e5b156d1dbca596469c to your computer and use it in GitHub Desktop.
Repeat a command until it fails with a non-zero exit code
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
#!/usr/bin/env bash | |
# ShellChecked with no issues detected | |
# | |
# Example usage for debugging a sporadically failing program: | |
# repeat.sh -- gdb --eval-command=run --eval-command=quit --args ./a.out | |
while [[ $1 != "--" ]]; do | |
n=$1 | |
shift | |
done | |
shift | |
if [[ -n $n ]]; then | |
i=0 | |
ret=0 | |
while [[ $i -lt $n && $ret -eq 0 ]]; do | |
eval "$@" | |
ret=$? | |
i=$((i + 1)) | |
done | |
else | |
ret=0 | |
while [[ $ret -eq 0 ]]; do | |
eval "$@" | |
ret=$? | |
done | |
fi |
Author
aprell
commented
Sep 4, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment