Search code examples
bashcurlquotessoql

how can I pass a variable to a SoQL query using Bash


I need to pass a variable to a SoQL query to then make a Curl request. This is an example of code.

day=$(date -d "yesterday" +'%d/%m/%Y')
query1="SELECT name WHERE data=${day}"
query1=${query_1/ / /%20}

curl "https://url/file.json?\$query=${query1}"

I receive the following error:

{"message":Invalid SoQL query","error code":"query.soql.invalid","data":{}}

In the 'Where' I have tried with $day, "$day","${day}".

But if I introduce for example query1='SELECT name WHERE data=24/05/2020' works correctly.

I need help because I don't understand what is going on.


Solution

  • query1="SELECT name WHERE data=${day}"
    

    or

    query1="SELECT name WHERE data=`day`"