Bash shell scripting while syntax and example

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

The bash shell use the while statement as a control flow statement that allows code or commands to be executed repeatedly based on a given condition. The syntax is as follows:

while [ condition ]
do
   command1
   command2
   command3
done

See our while loop wiki page in Linux shell scripting guide for more information and examples.