I need to execute a command and also check if it was successful. If there was an error, I should try again and the following code is working as expected.
But what if I need to try the same command 3 or 4 times till it gets successfully executed? The if / else clause will become pretty complicated.
some command
if [ $? -eq 0 ];then
echo "success"
else
echo "failed first attempt trying again"
some command
if [ $? -eq 0 ];then
echo "success in second attempt"
else
echo "failed second attempt"
fi
fi
Is there better way to write a script that will try the command 4 times before quitting?