Bash For Loop,The Standard Bash for Loop

Loops are one of the fundamental concepts of programming languages. Loops are handy when you want to run a series of commands over and over again until a certain condition is reached.

In scripting languages such as Bash, loops are useful for automating repetitive tasks.

There are three basic loop constructs in Bash scripting, for loop, [while]( loop, and [until]( loop.

In this tutorial, we will cover the basics of for loops in Bash. We will also show you how to use the break and continue statements to alter the flow of a loop.

The Standard Bash for Loop

The for loop iterates over a list of items and performs the given set of commands.

The Bash for loop takes the following form:

for item in [LIST]


The list can be a series of strings separated by spaces, a range of numbers, output of a command, an array, and so on.

Loop over strings

In the example below, the loop will iterate over each item in the list of strings, and the variable element will be set to the current item:

for element in Hydrogen Helium Lithium Beryllium
  echo "Element: $element"

#bash #loop #bash for loop

Bash For Loop,The Standard Bash for Loop
1.60 GEEK