Bash Beginner Series #8: Loops in Bash

Beware of infinite loops.

The ability to loop is a very powerful feature of bash scripting. Loops have a variety of use cases. .

In this tutorial you will explore the three different bash loop structures. You will also learn how to use loops to traverse array elements. .

Furthermore you will learn how to use break and continue statements to control loops and finally you will learn how to create infinite loops.

For loops are one of three different types of loop structures that you can use in bash. There are two different styles for writing a for loop.

If you are familiar with a C or C like programming language then you will recognize the following for loop syntax.

Using the aforementioned C-style syntax the following for loop will print out Hello Friend ten times.

The for loop first initialized the integer variable i to zero then it tests the condition i lt10 if true then the loop executes the line echo Hello Friend and increments the variable i by 1 and then the loop runs again and again until i is no longer less than 10.

...

Read Full Post

News Link: https://linuxhandbook.com/bash-loops/.
RSS Link: https://linuxhandbook.com/feed/.

Linux Chatter is a news aggregator service that curates some of the best Linux, Cloud, Technical Guides, Hardware and Security news. We display just enough content from the original post to spark your interest. If you like the topic, then click on the 'read full post' button to visit the author's website. Use Linux Chatter to find content from amazing authors!

Note: The content provided has been modified and is not displayed as intended by the author. Any trademarks, copyrights and rights remain with the source.

Disclaimer: Linux Chatter sources content from RSS feeds and personal content submissions. The views and opinions expressed in these articles are those of the authors and do not necessarily reflect those of Linux Chatter.