0

I tried to use CloudFlare API with strings in Bash script:

curl -X POST \
-H "X-Auth-Email: email" \
-H "X-Auth-Key: key" \
-H "Content-Type: application/json" \
     -d '[
{"expression": "(http.cookie contains \"ID=$MYSTRING\")", "description":"Login from office"}
]' "https://api.cloudflare.com/client/v4/zones/ZONE_ID/filters"

I want to use $MYSTRING but cannot do this because of single quotes. I tried to use " and \ but CloudFlare show me error. Can I use $MYSTRING with this CURL request? Please help!

J.Mae
  • 73
  • 1
  • 5
  • What single quotes? Single quotes in the value of `MYSTRING` won't affect the syntactic single quotes surrounding the argument of `-d`. That said, use something like `jq` to generate the JSON rather than relying on string interpolation. – chepner Dec 02 '21 at 22:43
  • 1
    Does this answer your question? [Expansion of variables inside single quotes in a command in Bash](https://stackoverflow.com/questions/13799789/expansion-of-variables-inside-single-quotes-in-a-command-in-bash) – rchome Dec 02 '21 at 22:45

0 Answers0