Last active
May 1, 2020 15:28
-
-
Save alexfornuto/2d8a4834abfa1175f0d7edc10564253c to your computer and use it in GitHub Desktop.
A bash function that tries a command 3 times before failing with exit code 1
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
try3 () { | |
for ((n=1;n<4;n++)); do | |
if ! "$@" | |
then | |
echo "failed $n times..." | |
if [[ $n = 3 ]] | |
then exit 1 | |
fi | |
sleep 1 | |
else | |
echo "Completed after $n tries" | |
break | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment