Sample Header Ad - 728x90

Bash variable substitution into yq command

3 votes
2 answers
11709 views
Given a YAML file, example.yaml: node: sub_node: get_this: I'd like to get a variable containing get_this using Mike Farah's yq and the string sub_node yaml="$(cat example.yaml)" nodename=sub_node sub_yaml= "$(echo "$yaml" | yq -r '.$nodename' )"; # also tried -> sub_yaml= "$(echo "$yaml" | yq -r '.'"$nodename" )"; Note this is a contrived example, in reality, the sub_node string is not known in advance so I need to substitute the $nodename string. I can't seem to figure out how to escape out of the single quote query string required by yq. How might I do this?
Asked by Lee (549 rep)
Mar 13, 2023, 11:47 AM
Last activity: Apr 23, 2024, 05:29 PM