Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Pass bash variable to jq filter and echo the whole command to another variable

$
0
0

I have a sample json like this /tmp/test.json

{"foo" : "val1","bar" : "val2"}

Setting the key in a variable

key=foocat /tmp/test.json | jq --arg k $key '.[$k]'# Output is fine"val1"

Now if I want to store the whole command into a variable CMD so that I can echo "$CMD and eval "$CMD" later:

CMD=`echo cat /tmp/test.json | jq --arg k $key '.[$k]'`# Error outoutjq: parse error: Invalid numeric literal at line 1, column 4

How do I escape these special chars?


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>