I'm trying to edit a config file with jq with some environment variables, but I'm getting stuck on the double quote escaping and formatting.
For example...
Inside test.conf
is:
{
"log_level":"INFO"
}
I can edit the file with a new hardcoded value without issue by running:
jq -e '.station_conf.log_level="WARN"' test.conf > test.conf.tmp && cp test.conf.tmp test.conf
Which results in test.conf
:
{
"log_level":"WARN"
}
But trying to call the env variable:
jq -e '.station_conf.log_level="$LOG_LEVEL"' test.conf > test.conf.tmp && cp test.conf.tmp test.conf
Results in:
{
"log_level":"$LOG_LEVEL"
}
Which of course is because of the double quotes in the jq command. How do I escape them to let the variable through, but still end up with properly formatted json with the double quotes around the value?