Let say I have YAML file that looks like this:
FOO: somefoo
BAR: somebar
I would like to convert this (using yq
) into the following so that I can source the contents into environment variables:
export BAR='somebar'
export FOO='somefoo'
I can do it it with jq
by converting the input to JSON first, but I can't seem to figure out how to do it with yq
only. (I am using yq
4.x, <4.18).
So, concretely, how could I do the following using just yq
?
INPUT="FOO: somefoo
BAR: somebar"
echo "$INPUT" | yq e 'to_json' - | jq -r 'keys[] as $k | "export \($k)='\''\(.[$k])'\''"'