From 4873b26787d37d9ef5c27d5c0852fcb7543fbc07 Mon Sep 17 00:00:00 2001 From: David Schroeder Date: Tue, 2 Oct 2018 08:36:16 -0500 Subject: [PATCH] Update test.sh --- test.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/test.sh b/test.sh index dcba843..a18125e 100755 --- a/test.sh +++ b/test.sh @@ -1,20 +1,12 @@ #!/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 +array[color,red]=100 +array[color,blue]=200 +array[style,bold]=300 +array[style,underline]=400 - #the loop contents are the same - echo "$key : y1 = ${array[$key,y1]}" - echo "$key : y2 = ${array[$key,y2]}" -done -done + +echo ${array[color,blue]} exit 0 \ No newline at end of file