If you want to run a command on a Linux system until it succeeds, there are some really easy ways to do it that don’t require you to retype the command repeatedly or sit in front of your screen pressing !! (repeat the previous command) until the command works. In this post, we’ll look at two options available with bash.
Using while !
First, we’ll look at an easy example of trying to display the contents of a file. This trick is to use the bash while command to create a loop, but preface the command that you want to run with a ! sign so that it loops until the command succceeds. Here’s how it works.
Thanks to Sandra Henry-Stocker (see source)