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 4How do I escape these special chars?