Examples of several methods for shell to realize program dead cycle



Sometimes it is necessary to create a dead loop in the script, or let the program run continuously until a certain condition exits the loop.

For ape people familiar with C language, the simplest dead cycle should be written as follows:



//do something


Or you can use the for statement and the do… While statement to implement it, not to mention here!

Implementation method

But how to write a loop in a shell script? While is also used at this time. It summarizes several ways to keep the shell script running:

Here’s an example: use while: to keep the program running until you press Q or Q to exit

Script output:


The above is the whole content of this article. I hope that the content of this article can bring some help to your study or work. If you have any questions, you can leave a message and communicate with us. Thank you for your support for developpaer.