Hilfe zum Lesen des YML (Parsercode) benötigt:https://gist.github.com/pkuczynski/8665367
Meine YML-Datei ist:
marketVal:
envVal:
hostVal: ipValue
Und in der .sh-Datei lese ich es als
market $1
env $2
parse_yaml() {
local prefix=$2
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
sed -ne "s|^\($s\)\($w\)$s:$s\"\(.*\)\"$s\$|\1$fs\2$fs\3|p" \
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
awk -F$fs '{
indent = length($1)/2;
vname[indent] = $2;
for (i in vname) {if (i > indent) {delete vname[i]}}
if (length($3) > 0) {
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
}
}'
}
eval $(parse_yaml hostList.yml "config_")
#Here my property key is "config_marketValue_envValue_hostVal"
# so the value of "config_marketValue_envValue_hostVal" is properly coming as "ipValue"
echo ${config_marketValue_envValue_hostVal}
#As I can not hard code the marketVal etc so the key will be like
# "config_${market}_${env}_hostVal"
Wenn ich jetzt so etwas im Skript mache:
key="config_${market}_${env}_hostVal"
echo ${key}
ip_value=${key}
echo ${ip_value}
Es wird gedruckt.
config_${market}_${env}_hostVal *nothing get printed for echo ${ip_value}*
Die erwartete Ausgabe ist:
config_marketValue_envValue_hostVal
ipValue
Kann mir jemand einen Tipp geben, was ich tun kann, um diesen Wert zu lesen? Ich bin ein Neuling im Bereich Shell-Skripting und bin für jede Hilfe dankbar.