I receive from "somewhere" an array of stuff that looks like a dictionary
and I need to access the value of a specific one (e.g. the value for the key "FOO")
what is the best way to access it?
Do I need to "parse" the string (or whatever it is) to dictionary or I have a shortcut?
#!/bin/bash
# GNU bash, version 4.4.20
ARR=(FOO='hello' BAR='world')
for index in "${!ARR[@]}"
do
echo "${index}"
I_WISH_WAS_A_DICTIONARY=${ARR[$index]}
echo "${I_WISH_WAS_A_DICTIONARY}"
if [ -v ${I_WISH_WAS_A_DICTIONARY[FOO]} ]; then
break
fi
done
here is a runnable code sample
note about foo bar syntax:
I do not have control over the syntax of FOO='hello', BAR='world'
in the real world those come from dart define
I'm trying to use those in running a "Pre-action" script on a iOS build
function entry_decode() { echo "${*}" | base64 --decode; }
IFS=',' read -r -a define_items <<< "$DART_DEFINES"
for index in "${!define_items[@]}"
do
define_items[$index]=$(entry_decode "${define_items[$index]}");
done