Using C-style for loop in Bash scripting
📖 Scenario: You are managing a small inventory system using a Bash script. You want to count from 1 to 5 to simulate checking five items in stock.
🎯 Goal: Build a Bash script that uses a C-style for loop to count from 1 to 5 and print each number.
📋 What You'll Learn
Create a variable called
start and set it to 1Create a variable called
end and set it to 5Use a C-style
for loop with i starting from start to endPrint the value of
i inside the loop💡 Why This Matters
🌍 Real World
Counting or iterating a fixed number of times is common in automation scripts, like processing files or checking system status.
💼 Career
Knowing how to write loops in Bash helps in system administration, DevOps, and automation roles where scripts manage repetitive tasks.
Progress0 / 4 steps