An infinite loop is used for running a set of instruction with never ending repeat. In this we create a loop which runs endlessly and keep executing the instructions until force stopped externally.

Bash Infinite While Loop

In this scenario, which loop is the best option. The following syntax is used for create infinite while loop in a shell script. Loop Example:

You can also Unix true command with while loop to run it endlessly. The while loop syntax with true command will look like below example. Loop Example:

Add Exist Instruction in Infinite Loop

Sometimes you may need to exit from a never ending loop based on a condition. If a specific condition meet and your want that infinite loop should break on that condition.

Add a if statement in above loop to break on matching condition.