-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassociative_array.sh
More file actions
31 lines (21 loc) · 974 Bytes
/
associative_array.sh
File metadata and controls
31 lines (21 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
#=========================================================================================================
#Script name : associative_array.sh
#Description: demonstarates associative arrays (Key value pair) in shell scripting
# Shows how to decalre, iterate and access array element
#Author : Sana
#Date : Oct 2025
#==========================================================================================================
#declaring an associative array with key value pair
declare -A person=([name]="Sana" [age]=40 [city]="Paris")
echo "Please find the employee details"
# Loop through all keys in the associative array
# "${!person[@]}" gets all the KEYS (name, age, city)
# "i" represents each key during iteration
for i in "${!person[@]}"
do
echo "$i = ${person[$i]}"
done
# Display total number of elements in the array
# ${#person[@]} gives the count of key-value pairs
echo "no of elements in the array ${#person[@]}"