Ubuntu – Bash CLI remove quotes from output of a command

command linejsontext processing

I am trying to load a JSON file using jq per here. It is quite straightforward and this works:

$ cat ~/Downloads/json.txt | jq '.name'

However, I need to assign the output of this variable to a command. I tried to do this and this works:

$ my_json=`cat ~/Downloads/json.txt | jq '.name'`
$ myfile=~/Downloads/$my_json.txt
$ echo $myfile

But I want /home/qut/Downloads/web.txt.

How do I remove the quotes, i.e. change "web" to web?

Best Answer

You can use the tr command to remove the quotes:

my_json=$(cat ~/Downloads/json.txt | jq '.name' | tr -d \")