0
0
Bash Scriptingscripting~15 mins

Why arrays handle lists of data in Bash Scripting - See It in Action

Choose your learning style9 modes available
Why arrays handle lists of data
📖 Scenario: You are organizing a list of your favorite fruits to share with friends using a Bash script.
🎯 Goal: Create a Bash script that uses an array to store a list of fruits, then prints them out one by one.
📋 What You'll Learn
Create an array called fruits with the exact values: apple, banana, cherry
Create a variable called count that stores the number of fruits in the array
Use a for loop with the variable fruit to iterate over the fruits array
Print each fruit on its own line
💡 Why This Matters
🌍 Real World
Arrays help you organize and manage lists of data easily in scripts, like keeping track of files, users, or settings.
💼 Career
Knowing how to use arrays in Bash is important for automating tasks and managing data efficiently in many IT and DevOps roles.
Progress0 / 4 steps
1
Create the fruits array
Create an array called fruits with these exact values: apple, banana, cherry
Bash Scripting
Need a hint?

Use parentheses () to create an array in Bash.

2
Count the number of fruits
Create a variable called count that stores the number of items in the fruits array using ${#fruits[@]}
Bash Scripting
Need a hint?

Use ${#array[@]} to get the length of an array in Bash.

3
Loop through the fruits array
Use a for loop with the variable fruit to iterate over the fruits array
Bash Scripting
Need a hint?

Use "${fruits[@]}" to access all elements of the array.

4
Print the fruits
Print each fruit on its own line inside the for loop using echo "$fruit"
Bash Scripting
Need a hint?

Use echo to print text in Bash.