Skip to content
  • About
  • Courses
  • ResearchExpand
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • ToolsExpand
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
One Page CV
Unix

Shell For Loops

For Loops

The while loop enables you to execute a set of commands repeatedly until some condition occurs. It is usually used when you need to manipulate the value of a variable repeatedly.

Syntax

for var in word1 word2 ... wordN
do
   Statement(s) to be executed for every word.
done

Example

#!/bin/sh

for var in 0 1 2 3 4 5 6 7 8 9
do
   echo $var
done
#!/bin/bash

for table in {2}
do
echo "table for 2: $table"
done
#!/bin/bash

for table in {2,3,4,5,6}
do
echo "table for 2: $table"
done
#!/bin/bash
for table in {2..20}
do
echo "table for 2: $table"
done
#!/bin/bash
for ((i=0; i<5; i++ ))
do
echo "the value is $i"
done
The list of values (Mon, Tue, Wed, Thu and Fri) are directly given after the keyword โ€œinโ€ in the bash for loop.

#!/bin/bash
i=1
for day in Mon Tue Wed Thu Fri
do
echo "Weekday $((i++)) : $day"
done
#!/bin/bash
i=1
for day
do
 echo "Weekday $((i++)) : $day"
done

$ ./forweek1.sh Mon Tue Wed Thu Fri

Post navigation

Previous Previous
Shell While Loops
NextContinue
Shell Until Loop
  • Latest

    [professional_resume]

    Read More Continue

  • Latest

    Explore Generative AI with the Gemini API in Vertex AI

    Read More Explore Generative AI with the Gemini API in Vertex AIContinue

  • Latest

    Inspect Rich Documents with Gemini Multimodality and Multimodal RAG

    Read More Inspect Rich Documents with Gemini Multimodality and Multimodal RAGContinue

  • Latest

    ๐ŸŽ“ Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)

    In engineering colleges across the country, final year projects are often treated as just another academic task. But what many students fail to realize is…

    Read More ๐ŸŽ“ Why Original Work Matters in Your Final Year Project (And How It Can Shape Your Career)Continue

  • Latest

    ๐ŸŽ“ How to Choose Your Final Year Project: A Practical Guide for BTech Students

    Choosing the right final year project is one of the most important decisions of your engineering journey. Itโ€™s more than just a submission โ€” itโ€™s…

    Read More ๐ŸŽ“ How to Choose Your Final Year Project: A Practical Guide for BTech StudentsContinue

Nishant Munjal

Coding Humanityโ€™s Future </>


Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • EMI Calculator
  • Creative QR Code
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
  • Research
    • Research Publications
    • Books
    • Patents
    • Ph.D. Supervised
  • Workshop/Conferences
  • Tools
    • Creative Image Converter
    • Creative QRCode Generator
    • Creative QR Code Generator Tool
    • EMI Calculator
    • SIP Calculator
  • Blog
  • Resume
Download CV
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.