Created
October 30, 2017 07:40
-
-
Save sumimakito/b27f8b2abbc7c63a20c4794165c9c74a to your computer and use it in GitHub Desktop.
loop.sh [--expected EXIT_CODE] COMMANDS...
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
expected=0 | |
command=$@ | |
re='^[0-9]+$' | |
if [[ $1 == '--expected' ]] ; then | |
if ! [[ $2 =~ $re ]] ; then | |
echo "Error: expected exit code '$2' is invalid." | |
exit 1 | |
else | |
expected=$2 | |
command=${@:3} | |
fi | |
fi | |
$command | |
ret=$? | |
echo "Got exit code: $ret" | |
while [ $ret -ne $expected ]; do | |
echo "Not good! Try again!" | |
sleep 1 | |
$command | |
ret=$? | |
echo "Got exit code: $ret" | |
done | |
echo "Exiting ..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment