-3

I have:

MY_FOLDER=`jq '.results_folder' ./conf.json`

FOLDER_WITHOUT_QUOTES=$MY_FOLDER | sed 's/"//g'

python my_code.py > $FOLDER_WITHOUT_QUOTES/log.log

So, there is a json file with a folder name. But jsons demand strings to be inside ". And reading the json with bash returns me ", which I want to remove

Passing it to a variable and then applying sed isn't working. What's the correct syntax for doing it?

Thank you!

Rafael Higa
  • 655
  • 1
  • 8
  • 17

1 Answers1

2

Posix shell would need:

FOLDER_WITHOUT_QUOTES="$(printf '%s\n' "$MY_FOLDER" | sed 's/"//g')"

With Bash you can use the here-document syntax:

FOLDER_WITHOUT_QUOTES=$(sed 's/"//g' <<< "$MY_FOLDER")

... and you can even get rid off a call to sed with the special substitution:

FOLDER_WITHOUT_QUOTES=${MY_FOLDER//\"}

Note: prefer the $(command) syntax to the backquotes which are less readable and cannot be nested as easily.

xhienne
  • 5,738
  • 1
  • 15
  • 34