The Syntax of a while loop in BASH Scripting
while [ condition ];
do
# statements
# commands
done
If the condition is true then the commands inside the while block are executed and are iterated again after checking the condition. Also if the condition is false the statements inside the while block are skipped and the statements after the while block are executed.
Bash Scripting – While Loop
A while loop is a statement that iterates over a block of code till the condition specified is evaluated to false. We can use this statement or loop in our program when do not know how many times the condition is going to evaluate to true before evaluating to false.
Table of Content
- The Syntax of a while loop in BASH Scripting
- Looping Example using while statement in Linux
- Reading a file with a while loop
- Infinite while loop
- While loop to iterate for a fixed number of times
- Read the command-line argument with getopts options
- C-style while loop
- While loop to perform operations on a file
- Writing to a file using a while loop
- Break and continue Using while Loop
- Frequeltly Asked Questions