Skip to content
  • About
  • CoursesExpand
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • BooksExpand
    • Books Authored
  • Patents
Download 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

Advance AI PPT

Read More Advance AI PPTContinue

Latest

Prompts for Image Descriptions

Describe the scene using three vivid sensory details — one for sight, one for sound, and one for touch. Summarize the mood of the image…

Read More Prompts for Image DescriptionsContinue

Latest

Dimensionality Reduction

Dimensionality reduction is the process of reducing the number of features (variables) in a dataset while preserving important information. It helps in: ✅ Reducing computational…

Read More Dimensionality ReductionContinue

Artificial Intelligence

Tanh Function in Neural Network

The tanh function, short for hyperbolic tangent function, is another commonly used activation function in neural networks. It maps any real-valued number into a value…

Read More Tanh Function in Neural NetworkContinue

Latest

Why Initialize Weights in Neural Network

Initializing weights and biases is a crucial step in building a neural network. Proper initialization helps ensure that the network converges to a good solution…

Read More Why Initialize Weights in Neural NetworkContinue

Nishant Munjal

Coding Humanity’s Future </>

Facebook Twitter Linkedin YouTube Github Email

Tools

  • SIP Calculator
  • Write with AI
  • SamplePHP
  • Image Converter

Resources

  • Blog
  • Contact
  • Refund and Returns

Legal

  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

© 2025 - All Rights Reserved

  • About
  • Courses
    • Problem Solving using C Language
    • Mastering Database Management
    • Linux System Administration
    • Linux and Shell Programming
  • Publications
  • Professional Certificates
  • Books
    • Books Authored
  • Patents
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.Ok