• Contact Us
  • Home
  • About Us
  • News
    • Entertainment
    • Trending
  • IT
    • Code
    • Cloud
    • Linux
    • Splunk
  • Login
  • Register
Upgrade
CloudiBee
  • Contact Us
  • Home
  • About Us
  • News
    • Entertainment
    • Trending
  • IT
    • Code
    • Cloud
    • Linux
    • Splunk
No Result
View All Result
  • Contact Us
  • Home
  • About Us
  • News
    • Entertainment
    • Trending
  • IT
    • Code
    • Cloud
    • Linux
    • Splunk
No Result
View All Result
CloudiBee
No Result
View All Result
Home Linux

Getting Familiar With The Bash For Loop Statement

cloudibee by cloudibee
May 27, 2022
in Linux
0
0
SHARES
32
VIEWS
Share on FacebookShare on Twitter

One of the fundamental concepts in programming languages is looping. Loops come in handy when you need to run a series of commands repeatedly until a particular condition is met.

Loops are also useful for automating repetitive tasks, particularly in scripting languages like Bash. Basically, a ‘for loop’ is known as an iteration statement, specifically a repetition of a process within a Bash script.

Table of Contents

    • You might also like
    • Linux Change Password Command: Change password expiry in Linux
    • Top Open Source Email Servers
  • Bash scripting language
  • Standard Bash for loop

You might also like

Linux Change Password Command: Change password expiry in Linux

April 7, 2021
Email Servers

Top Open Source Email Servers

September 7, 2021

Bash scripting language

Bash is a Unix shell and command language. Originally, it written as a free software replacement for the Bourne shell. Bash is also a command language interpreter widely used in different operating systems. It is typically the acronym for Bourne-Again Shell.

Bash scripts can be used for different purposes, including the execution of a shell command, running of multiple commands together, customization of administrative tasks, and automation of tasks, among others.

For a Linux user, basic knowledge of Bash programming is essential.

Standard Bash for loop

For loop will iterate a list of items and perform a set of commands. The list of items can be a series of strings separated by spaces, range of numbers, output of a command, or array elements.

  • Loop over strings

This type of loop will iterate over every item in the list of strings. For instance, if you have a series of string elements under a particular variable, the for loop will iterate each item on the list as specified in the statement.

  • Loop over a number range

If you want to specify a range of numbers or characters, you can use the sequence expression by defining a start and end point of the range. A sample syntax is {start..end} wherein you have to specify a number or character to begin and another to end.

So if you are going to assign a particular number to begin, like 0, and end it with a number 3. Your output will increment until the starting number reaches the value specified in your loop. In this case, 0, 1, 2, and 3.

You can also specify an increment when you are using ranges. The expression will take the form {start..end..increment} so if your loop starts at 0 and ends in 20, and your increment is 5, then your output will increment from value 0-20 by 5. In this case, 0, 5, 10, 15, and 20.

  • Loop over array elements

An array of elements can also be iterated using a for loop statement. Just like in the ‘for loop’ statement used for strings, you can use it for your array elements. This means that more than one word can be displayed separated by spaces.

  • C-style Bash for loop

The ‘for loop’ statement is composed of the Initialization, Test, and Step values, following the form ((Initialization; Test; Step)). The Initialization part is executed once after the loop starts.

Then, the Test part will be evaluated and if it is false, the loop will be terminated. If the Test part is true, the commands in the body of the ‘for loop’ statement will be executed. Likewise, the Step part will be updated. In this case, the form ((i=0; i<= 10; i++)) will iterate 11 times.

Overall, the Bash ‘for loop’ will execute a set of commands for a fixed number of times in a repeated manner.

Tags: Bashbash historyLoop
Previous Post

RAID 5 vs RAID 10: Which Level Is More Advantageous?

Next Post

OnApp Federation Grows Stronger with SolusVM Acquisition

cloudibee

cloudibee

Related Posts

Linux

Linux Change Password Command: Change password expiry in Linux

by cloudibee
April 7, 2021
Email Servers
Linux

Top Open Source Email Servers

by cloudibee
September 7, 2021
Linux

How to Determine Redhat Versions Command

by cloudibee
May 27, 2022
Linux

How-to Linux List Processes in 3 Simple Commands

by cloudibee
May 27, 2022
Linux

What is Cron Job in Linux?

by cloudibee
May 27, 2022
Next Post

OnApp Federation Grows Stronger with SolusVM Acquisition

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Premium Content

Vmware 1.x server : vmware-cmd management utility

December 8, 2008

OnApp Federation Grows Stronger with SolusVM Acquisition

May 27, 2022

Pocket guide for netapp commands

March 3, 2013

Browse by Category

  • Business
  • Cloud
  • Code
  • Debt
  • Entertainment
  • finance
  • Game
  • Health
  • IT
  • Lawyers
  • Lifestyle
  • Linux
  • Marketing
  • Misc
  • News
  • SEO
  • Services
  • Splunk
  • Sports
  • Tech
  • Technology
  • Tipes
  • Tips
  • Uncategorized

Browse by Tags

algorithm Apache Apache2 AWS Bash bash history Bind Blacklists Buffer C C++ CentOS Cerner chage Cloud Cloud Computing Cloud jobs Cloud Storage Cloud Suite Commands Compliance Cron job Debian Directory DMS DNS Docker Dovecot drop cache Email servers Enteprise Cloud Enterprise External FAT32 Format kernel Linux linux kernel Nirvanix passwd Sendmail SSH SSL Terminal Ubuntu

About CloudiBee

cloudibee logo


CloudiBee is an open-source for people who love technology. Here we will be sharing lots of technical information over the web so that a lot of people visit us and gain some knowledge. We are a completely open to all platform. We assure you that you can easily get any info and updated news about the tech world from us. Let's begin with us!

Hot Topic

What are the best internet options for lawyers?

by samanvya
August 15, 2022
0
What are the best internet options for lawyers?

Meeting clients, questioning possible witnesses and getting in contact with other people in the case, or preparing for hearings with...

Read more

Recent News

Lifestyle

Best Gifts To Offer A Friend Who Owned A New House

July 22, 2022
Business

The main reasons for the startup fails. How to avoid failure?

July 21, 2022
Business

Hacks for packing wine glasses so they don’t break

July 21, 2022

CloudiBee. © 2021. All Rights Reserved

No Result
View All Result
  • Contact Us
  • Home
  • About Us
  • News
    • Entertainment
    • Trending
  • IT
    • Code
    • Cloud
    • Linux
    • Splunk

CloudiBee. © 2021. All Rights Reserved

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In