The starting and ending block of while loop are defined by do and done keywords in bash script. In the previous article entitled "Basic Linux Shell Scripting Language : Introduction to 'For' Loops", we have observed how a loop works.Loop is nothing but a control flow statement which executes a block of commands repeatedly till certain condition stays true, once the condition becomes false, the loop is … In scripting languages such as Bash, loops are useful for automating repetitive tasks. How to Loop Between a Start and End Point . while : do echo "Press CTRL+C to Exit" done Stopping Loop on Condition: We’ve got some built-in keywords in shell scripting, and while, do, and done, they’re among those. The while loop works based on the condition supplied to it. While loop statement continually executes a block of statements while a particular condition is true. Shortest? Infinite loop. Syntax for while loop in shell script is: After evaluating shell command, if the resulting value is true then the given statement(s) inside the while are executed. While loop is one of them. while true; do echo 'Press CTRL+C to stop the script execution'; done Shell Scripting for loop. Termination condition is defined at the starting of the loop. There are three basic loop constructs in Bash scripting, for loop, while loop, and until loop. Once condition becomes false, loop terminates. For example, the following 3x10.sh script uses a while loop that … Let's break it down: Line 4 - We'll initialise the variable counter with it's starting value. The select loop construct in bash is not part of the posix standard. ; Line 5 - While the test is true (counter is less than or equal to 10) let's do the following commands. The general syntax for a while loop is as follows: while [ condition ]; do [COMMANDS] done. by Steve Parker Buy this tutorial as a PDF for only $5. There is a condition in while. An infinite loop is used for running a set of instruction with never ending repeat. What's the correct way to exit from the shell script entirely while in a loop? On the other hand, in some cases using an infinite loop on purpose can make our program more simple to write, and easier to read. You can run a shell script in infinite loop by using while loop. Sometimes you may need to exit from a never ending loop based on a condition. Syntax of While Loop in Shell Scripts. In this shell script I have created nested while loop; The main while loop will continue to look for files under /tmp and once the number of files reaches greater than or equal to 5 Instead, specify a start and endpoint: A WHILE loop is used to check for the exit status of a condition and run a statement if the condition turns true. Will iterate the fastest?