Iterating over arrays
📖 Scenario: You are managing a list of fruits in a small fruit shop. You want to write a script that goes through each fruit in your list and shows it on the screen.
🎯 Goal: Build a Bash script that creates an array of fruits, sets up a counter, loops through the array to print each fruit with its number, and finally displays all the fruits one by one.
📋 What You'll Learn
Create an array called
fruits with the exact values: Apple, Banana, Cherry, Date, ElderberryCreate a variable called
count and set it to 1Use a
for loop with the variable fruit to iterate over the fruits arrayInside the loop, print the current
count and fruit, then increase count by 1Print each fruit on its own line as the final output
💡 Why This Matters
🌍 Real World
Automating tasks like listing items, processing lists of files, or managing simple inventories.
💼 Career
Basic scripting skills like looping over arrays are essential for system administrators, DevOps engineers, and anyone working with automation.
Progress0 / 4 steps