How to Create Infinite while Loop in Bash Script
Abstract: In case we need to terminate an infinite while loop on matching certain condition’swe can use break keyword to exit from running loop. while
Command:
while true;do echo 「Press CTRL+C to Exit」; done
Some times we are required to execute some commands or processes continuously until stop it forcefully or conditionally. The following example of while loop will run continuously until stopped forcefully using ctrl + c.
while true do echo "Press CTRL+C to Exit" doneExample 2:
We can also use colon 「:」 in place of 「true」 with while loop for creating infinite loop in bash script.
while : do echo "Press CTRL+C to Exit" doneStopping Loop on Condition:
In case we need to terminate an infinite while loop on matching certain condition’s, we can use break keyword to exit from running loop.
while : do echo "Press CTRL+C to Exit" if [ condition ] then break fi done