Wednesday, May 6, 2020

How to repeat a Linux command until it succeeds

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.

To read this article in full, please click here


Thanks to Sandra Henry-Stocker (see source)

No comments:

Post a Comment