BASH – Run command until success

How to run a command repeatedly until it succeeds:


passwd
while [ $? -ne 0 ]; do !!; done

The !! is a shortcut to the last command run. Run the command once and then the while loop will execute until the command succeeds (i.e. returns 0)

From here:

http://stackoverflow.com/questions/5274294/how-can-you-run-a-command-in-bash-over-until-success

Leave a Reply

Your email address will not be published. Required fields are marked *