Accessing array elements
📖 Scenario: You are organizing a small fruit basket. You have a list of fruits and want to pick specific fruits by their position in the list.
🎯 Goal: Learn how to create an array, set a position variable, access an element from the array using that position, and display the chosen fruit.
📋 What You'll Learn
Create an array called
fruits with the exact values: apple, banana, cherry, date, elderberryCreate a variable called
position and set it to 2Access the fruit at the index stored in
position from the fruits array and store it in a variable called chosen_fruitPrint the value of
chosen_fruit💡 Why This Matters
🌍 Real World
Arrays are useful to store lists of items like filenames, user inputs, or configuration options. Accessing elements by position helps automate tasks like selecting specific files or options.
💼 Career
Knowing how to work with arrays and variables in bash scripting is essential for system administrators, DevOps engineers, and anyone automating tasks on Linux or Unix systems.
Progress0 / 4 steps