-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Description
As a debugging aide it would be nice if jq would have a flag to just print a given expression with env.
|ENV.
statements interpolated.
e.g.
$ echo $SHELL
/bin/bash
$ jq -n '{ foo: env.SHELL }'
{
"foo": "/bin/bash"
}
$ jq --interpolate-only '{ foo: env.SHELL }'
{ foo: "/bin/bash" }
I wrote a small script to do this, but if jq
did that one could be sure the logic is correct.
(e.g. this one only works for env.
and not ENV.
:))
interpolate_jq_expression() {
local expression="$1"
local value var
for var in $(echo "$expression" | grep -o 'env\.[A-Za-z_][A-Za-z0-9_]*' | sed 's/env\.//')
do
value=$(jq -R <<< "${!var}")
expression=$(echo "$expression" | sed "s/env\.$var/$value/g")
done
echo "$expression"
}
Metadata
Metadata
Assignees
Labels
No labels