Using Associative Arrays in Bash
📖 Scenario: You are managing a small store's inventory. You want to keep track of product prices using a simple script.
🎯 Goal: Create a Bash script that uses an associative array to store product names and their prices, then display the price of each product.
📋 What You'll Learn
Use an associative array declared with
declare -AStore exact product-price pairs as given
Use a
for loop to iterate over the associative arrayPrint each product and its price in the format:
Product: Price💡 Why This Matters
🌍 Real World
Associative arrays help store and manage key-value pairs like product prices, user settings, or configuration options in scripts.
💼 Career
Knowing associative arrays is useful for automating tasks, managing data in scripts, and writing efficient shell scripts in system administration or DevOps roles.
Progress0 / 4 steps