You are currently viewing Shell Scripting – Loops
Shell Scripting – Loops

Shell Scripting – Loops

Shell Scripting – Loops

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed shell operators.

In this blog post, we will discuss loops. Like any other programming language, bash also supports loop. A loop in a nut shell is a way to repeat a command until a certain condition is met. Bash supports while, for, until and select loops.

Shell Scripting – Loops

While Loop:

The while construct allows for repetitive execution of a list of commands, as long as the condition is true. Once the condition is false, while loop stop execution.

For Loop:

The for construct allowed for iterate over a list. As long as it finds an item in the list, for loop continue to iterate over the list and stops iteration once it reaches to the end of the list.

Until Loop:

The until loop is almost equal to the while loop, except that the code is executed while the condition evaluates to false.

Select Loop:

The select construct generates a menu from the list of items that are passed into it. The select command is often used with switch-case statements to generate a menu in bash.

Hope you have enjoyed this article, in the next blog post we will discuss conditions in bash.


Leave a Reply