Home > Mobile >  How to add single quotes while parsing with jq?
How to add single quotes while parsing with jq?

Time:06-18

Trying to parse a value from AWS CLI command using jq which should be in the following format: MY_KEY='MY_VALUE'

Using the below command: <cli command> | jq -r 'to_entries[] | [.value["Name"], "=", "\"", .value["Value"], "\""] | @tsv' | tr -d "\t"

With the above command, getting the output in double-quotes: MY_KEY="MY_VALUE". However, I want the values to be enclosed in single quotes. What modifications can be done in the above command to achieve the same?

Syntax tried and not working: '\'', "'"

CodePudding user response:

If you need it to escape for the shell, just use @sh:

<cli> | jq -r '.[] | "\(.Name)=\(.Value | @sh)"'
  • Related