Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Shell Scripting Tutorials: Looping & Iteration statatement using for loop



Loopsย are a programming construct which allow us to repeat a command or set of commands for each item in a list. As such they are key to productivity improvements through automation. Similar to wildcards and tab completion, using loops also reduces the amount of typing required (and hence reduces the number of typing mistakes).

Syntax of For Loop

Example of For Loop

There are some key points of ‘for loop’ statement:

  • Each block of ‘for loop’ in bash starts with ‘do’ keyword followed by the commands inside the block. The ‘for loop’ statement is closed by ‘done’ keyword.
  • The number of time for which a ‘for loop’ will iterate depends on the declared list variables.
  • The loop will select one item from the list and assign the value on a variable which will be used within the loop.
  • After the execution of commands between ‘do’ and ‘done’, the loop goes back to the top and select the next item from the list and repeat the whole process.
  • The list can contain numbers or string etc. separated by spaces.

How For Loop works?

Write Simple Shell Script using For Loop


#!/bin/bash
for i in 1 2 3 4 5
do
 echo "Hello $i"
doneCode language: PHP (php)

Letโ€™s inspect each element:

  • #!/bin/bash โ€“ shows that the code is a bash script
  • i โ€“ is a placeholder for a variable. Meanwhile, $i is the individual value of the variable. You can also write it as c/$c or by any other name
  • in โ€“ separates the variable and the items that follow
  • 1 2 3 4 5 โ€“  is an example of items you want to perform the instruction on
  • do โ€“ is the keyword that starts the loops. It will then execute the instruction n times, with n being the total number of items. Here, the value of n is 5
  • echo โ€œHello: $iโ€ โ€“ is the code which we will repeat n times. Remember quotation marks turn anything inside it into one variable.
  • done โ€“ stops the loop

Example Program

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Top 10 Accounting Software Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, the importance of accounting software continues to grow, helping businesses of all sizes streamline financial management, improve accuracy, and stay compliant with ever-changing regulations….

Read More

Top 10 Endpoint Management Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, businesses of all sizes are increasingly reliant on a variety of devicesโ€”laptops, desktops, mobile devices, and other endpointsโ€”that connect to their networks. With the…

Read More

Top 10 Order Management Systems Tools in 2026: Features, Pros, Cons & Comparison

Introduction In 2026, managing orders has become a sophisticated process, requiring advanced tools to handle large volumes, multiple sales channels, and intricate supply chains. Order Management Systems…

Read More

What is Veracode and use cases of Veracode?

What is Veracode? Veracode is a leading application security (AppSec) platform that helps organizations identify and remediate vulnerabilities in their software throughout the development lifecycle. By integrating…

Read More

Terraform Backend Tutorial

Terraform is a popular open-source infrastructure as code tool used to create and manage infrastructure resources. The state of the infrastructure resources managed by Terraform is stored…

Read More

Best Tools for Software Composition Analysis (SCA)

Hereโ€™s a clear and professional explanation of the three related concepts you asked about โ€” all of which are critical parts of secure software development, especially in…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x