Issue
I'm trying to use jq within a Makefile to generate a json file. Here is a sample Makefile
foo.json:
jq -n --arg x "bar" '{"foo": "$$x"}' > foo.json
@cat foo.json
@rm foo.json
When I run this with GNU Make v4.3 and jq v1.6 I get the following
make
jq -n --arg x "bar" '{"foo": "$x"}' > foo.json
{
"foo": "$x"
}
Notice that $x
shows up literally and doesn't get interpolated by jq. How do I achieve the following...
make
jq -n --arg x "bar" '{"foo": "$x"}' > foo.json
{
"foo": "bar"
}
Solution
You simply don't need to wrap your variable in quotes:
jq -n --arg x "bar" '{foo: $x}'
Or use string interpolation:
jq -n --arg x "bar" '{foo: "\($x)"}'
Answered By - customcommander