From 5e8445febf71a30a13a07e559e5c034b6699e41a Mon Sep 17 00:00:00 2001 From: Aadhavan Srinivasan Date: Thu, 11 Jan 2024 10:18:47 -0500 Subject: [PATCH] Started working on converting the regular arrays into an associative array --- build.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 247ff4c..1a2b2c5 100755 --- a/build.sh +++ b/build.sh @@ -46,9 +46,19 @@ read_metadata() { } convert_to_array() { -# Converts the metadata into two arrays: one with the key, and the other with the value +# Converts the metadata into two arrays: one with the key, and the other with the value. readarray -t meta_key < <(echo -e "$1" | awk -F: '{print $1}') readarray -t meta_value < <(echo -e "$1" | awk -F: '{st = index($0,":"); values = substr($0,st+1); print values}' | cut -c 2-) + +# Merge both arrays into an associative array + declare -A meta_array + for index in $(seq 0 `expr "${#meta_key[@]}" - 1`); do + meta_array["${meta_key[$index]}"]="${meta_value[$index]}" + done + +# for array_key in "${!meta_array[@]}"; do +# printf "[%s] = %s\n" "$array_key" "${meta_array[$array_key]}" +# done } add_date_to_array() {