19 lines
442 B
Bash
Executable File
19 lines
442 B
Bash
Executable File
#!/bin/bash
|
|
|
|
declare -A array
|
|
array[x1,y1]=100
|
|
array[x1,y2]=200
|
|
array[x2,y1]=300
|
|
array[x2,y2]=400
|
|
#alternative 1, extract all the main keys with sort
|
|
for key in $(printf '%s\n' "${!array[@]}" | sed 's/,.*//' | sort -u); do
|
|
#alternative 2, keeping track of the main keys
|
|
keys=(x1 x2)
|
|
for key in "${keys[@]}"; do
|
|
|
|
#the loop contents are the same
|
|
echo "$key : y1 = ${array[$key,y1]}"
|
|
echo "$key : y2 = ${array[$key,y2]}"
|
|
done
|
|
|
|
exit 0 |