The Tech Edvocate

Top Menu

  • Advertisement
  • Apps
  • Home Page
  • Home Page Five (No Sidebar)
  • Home Page Four
  • Home Page Three
  • Home Page Two
  • Home Tech2
  • Icons [No Sidebar]
  • Left Sidbear Page
  • Lynch Educational Consulting
  • My Account
  • My Speaking Page
  • Newsletter Sign Up Confirmation
  • Newsletter Unsubscription
  • Our Brands
  • Page Example
  • Privacy Policy
  • Protected Content
  • Register
  • Request a Product Review
  • Shop
  • Shortcodes Examples
  • Signup
  • Start Here
    • Governance
    • Careers
    • Contact Us
  • Terms and Conditions
  • The Edvocate
  • The Tech Edvocate Product Guide
  • Topics
  • Write For Us
  • Advertise

Main Menu

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings

logo

The Tech Edvocate

  • Start Here
    • Our Brands
    • Governance
      • Lynch Educational Consulting, LLC.
      • Dr. Lynch’s Personal Website
        • My Speaking Page
      • Careers
    • Write For Us
    • The Tech Edvocate Product Guide
    • Contact Us
    • Books
    • Edupedia
    • Post a Job
    • The Edvocate Podcast
    • Terms and Conditions
    • Privacy Policy
  • Topics
    • Assistive Technology
    • Child Development Tech
    • Early Childhood & K-12 EdTech
    • EdTech Futures
    • EdTech News
    • EdTech Policy & Reform
    • EdTech Startups & Businesses
    • Higher Education EdTech
    • Online Learning & eLearning
    • Parent & Family Tech
    • Personalized Learning
    • Product Reviews
  • Advertise
  • Tech Edvocate Awards
  • The Edvocate
  • Pedagogue
  • School Ratings
  • The AI Job Apocalypse: Are Companies Hiding The Real Reason For Mass Layoffs?

  • One Crucial Factor Could Decimate Your US Auto Insurance Rates in 2026

  • Unbelievable: Meta Hit With $25 Billion Fine — Is Your Health Data Next?

  • 10 Crucial AI Literacy Courses Every Parent Needs Now

  • The Unseen Force Quietly Reshaping Rural Life: 7 Satellite Internet Providers Battling for Supremacy

  • Best Buy’s Gamers Hub: The Unbelievable Truth About Its “Rewards” And Discounts

  • 8 Crucial Reasons Why MAI-DxO Just Obliterated Doctors in a Head-to-Head Diagnosis Battle

  • The Brutal Truth About Student Loan Refinancing for New Grads in 2024

  • The Brutal Truth: AI Just Blew Up PHP Security – Here’s How to Survive ‘Black October’

  • Sodium-ion storage maker Peak Energy raises $108 million in GM-led round – PV Magazine

Assistive Technology
Home›Assistive Technology›How to Use the for Loop in a Linux Bash Shell Script

How to Use the for Loop in a Linux Bash Shell Script

By Matthew Lynch
June 14, 2023
0
Spread the love

A for loop is a type of control structure commonly used in programming languages to perform repetitive tasks. In a Linux Bash shell script, the for loop is used to iterate through a set of values and perform a specific action for each value in the set. This article will provide a simple guide to using the for loop in a Linux Bash shell script.

  1. Basic syntax

The basic syntax for a for loop in a Linux Bash shell script is as follows:

for variable in value1 value2 value3 … valuen

do

command1

command2

…

commandN

done

In this syntax, the ‘variable’ is a placeholder for the current value being displayed in the loop. ‘Value1’ to ‘valuen’ are the values that the loop will iterate through. ‘Command1’ to ‘CommandN’ are the actions or commands to be performed in each iteration of the loop.

  1. Iterating through a list of values

One common use of the for loop in a Linux Bash shell script is to iterate through a list of values. This is done by specifying the list of values after the ‘in’ keyword. For example, to iterate through the list of fruits, the script would look like this:

#!/bin/bash

for fruit in apple banana orange

do

echo “I like $fruit”

done

In this script, the loop iterates through the values ‘apple’, ‘banana’, and ‘orange’. For each value, the script executes the command ‘echo “I like $fruit”‘ which prints the message “I like apple”, “I like banana” and “I like orange” respectively.

  1. Iterating through a range of values

Another use of the for loop in a Linux Bash shell script is to iterate through a range of numerical values. This is done using the ‘seq’ command, which generates a sequence of numbers. For example, to iterate through the numbers 1 to 10, the script would look like this:

#!/bin/bash

for number in $(seq 1 10)

do

echo $number

done

In this script, the loop iterates through the numbers 1 to 10, generating the sequence using the ‘seq’ command. For each number, the command ‘echo $number’ is executed, which prints the number to the console.

  1. Using the for loop with arrays

Finally, the for loop can also be used to iterate through arrays in a Linux Bash shell script. An array is a collection of values stored in a single variable. Here is an example of how to use the for loop with an array:

#!/bin/bash

fruits=(“apple” “banana” “orange”)

for fruit in “${fruits[@]}”

do

echo “I like $fruit”

done

In this script, the array is defined using the syntax ‘fruits=(“apple” “banana” “orange”)’. The for loop iterates through each value in the array using the ‘@’ symbol and the ‘[]’ brackets: “${fruits[@]}”. For each value, the script executes the command ‘echo “I like $fruit”‘, which prints the message “I like apple”, “I like banana” and “I like orange” respectively.

Previous Article

How to Play Retro Nintendo Games on ...

Next Article

Free Ways to Crop a Video on ...

Matthew Lynch

Related articles More from author

  • Assistive Technology

    How to Unlink Your Epic Games Account

    June 10, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Clear the DNS Cache in Chrome, Edge, Firefox, Safari, and Opera

    June 15, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Display the Menu Bar in Internet Explorer

    June 15, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Uninstall Steam on a Mac

    June 14, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Save a Location on Google Maps

    June 6, 2023
    By Matthew Lynch
  • Assistive Technology

    How to Remove Android Status Bar Icons

    June 6, 2023
    By Matthew Lynch

Search

Login & Registration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

About Us

Since technology is not going anywhere and does more good than harm, adapting is the best course of action. That is where The Tech Edvocate comes in. We plan to cover the PreK-12 and Higher Education EdTech sectors and provide our readers with the latest news and opinion on the subject. From time to time, I will invite other voices to weigh in on important issues in EdTech. We hope to provide a well-rounded, multi-faceted look at the past, present, the future of EdTech in the US and internationally.

We started this journey back in June 2016, and we plan to continue it for many more years to come. I hope that you will join us in this discussion of the past, present and future of EdTech and lend your own insight to the issues that are discussed.

Newsletter

Signup for The Tech Edvocate Newsletter and have the latest in EdTech news and opinion delivered to your email address!

Contact Us

The Tech Edvocate
910 Goddin Street
Richmond, VA 23231
(601) 630-5238
[email protected]

Copyright © 2026 Matthew Lynch. All rights reserved.