I am trying to execute a bash script but I am getting this error:
curl: (3) URL using bad/illegal format or missing URL
curl: (3) unmatched close brace/bracket in URL position 1
I have tried several things, like escaping the " in json, using -g in curl request, using `` around Req variable instead of using eval, but I am unable to fix this.
#!/bin/bash
filename="$1"
URL='http://localhost:8983/contentCleaner?action=clean'
while read -r requestParam; do
Req="curl ${URL} -X POST -H 'Accept:application/json' -H 'Content-Type:application/json' --data \"$requestParam\""
Res=eval $Req
echo "Res:$Res"
done < "$filename"
The file I am passing as param to the bash command contains a list of json data which is separated by new line. The bash script loops through the json and populates the curl request. Here is a sample of one request:
{ \"batchRequest\": { \"requests\": [ { \"contentData\": { \"contentText\": { \"ingestedContentSummary\": { \"provider\": { \"url\": \"twitter.com\" }, \"title\": \"Trump\" } } }, \"contentSource\": \"twitter\", } ] } }