Shell script: Lendo yml com chave de propriedade dinâmica

Shell script: Lendo yml com chave de propriedade dinâmica

Ajuda obtida para ler o yml(código do analisador):https://gist.github.com/pkuczynski/8665367

Meu arquivo YML é:

marketVal:
  envVal:
    hostVal: ipValue

E no arquivo .sh estou lendo como

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"

Agora, se estou fazendo algo assim no script:

key="config_${market}_${env}_hostVal"
echo ${key}
ip_value=${key}
echo ${ip_value}

Está imprimindo. config_${market}_${env}_hostVal *nothing get printed for echo ${ip_value}* Considerando que o resultado esperado é:

config_marketValue_envValue_hostVal
ipValue

Alguém pode sugerir o que fazer aqui para ler este valor, sou muito novo em shell script, qualquer ajuda será apreciada.

informação relacionada