Categories
Linux Mastering Development

curl –data-binary $’ inside a shell script

I have tried everything to do a curl from within a shell script. This curl has a

--data-binary $'

part which I just can not get my script to recreate. It will move the $ inside the single quote for some weird reason. Any ideas how to fix it?

--data-binary '$
curl -s  -H 'Connection: keep-alive' \
  -H 'Cache-Control: max-age=0' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'Origin: https://url.com' \
  -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundary6AiBMw0TyIybreRa' \
  -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36' \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-Mode: navigate' \
  -H 'Sec-Fetch-User: ?1' \
  -H 'Sec-Fetch-Dest: document' \
  -H 'Referer: https://url.com' \
  -H 'Accept-Language: en-US,en;q=0.9,es;q=0.8' \
  -H "Cookie: JSESSIONID=$jsession; __utmc=35664418; __utmz=35664418.1593348512.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); BALANCEID=balancer.apphpgal01; acceta_default=im10snhiask7qic85vrr1dr4i2; __utma=35664418.1302973562.1593348512.1593372701.1593378049.6; __utmt=1; __utmb=35664418.5.10.1593378049" \
  --data-binary $"------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name=\"$var1\"\r\n\r"$var2"\r\n------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name=\"$var3\"\r\n\r\n\r\n------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name=\"g-recaptcha-response\"\r\n\r\n$recaptcha\r\n------WebKitFormBoundary6AiBMw0TyIybreRa--\r\n" \
  --compressed "https://url.com"

It is driving me crazy. I have tried everything. Escaping the $, putting it in single quotes. Double quotes. Changing every " for ‘. I’m definitely missing something guys.

EDIT: Someone pointed out that I’m not explaining myself that clearly. Rightly so:
I’m running the script like this "bash curl.sh".
The content of curl.sh would be

curl -s -H "Cookie: JSESSIONID=$jsession" \
  --data-binary $"------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name=\"$var1\"\r\n\r"$var2"\r\n------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name=\"g-recaptcha-response\"\r\n\r\n$recaptcha\r\n------WebKitFormBoundary6AiBMw0TyIybreRa--\r\n" \
  --compressed "https://url.com"

However when I execute it, the –data-binary part puts the dollar sign $ inside the quotes

I have also tried this per suggestion of @St├ęphane Chazelas without success

--data-binary $'------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name="'"$var1"'"\r\n\r'"$var2"'\r\n------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name="'"$var3"'"\r\n\r\n\r\n------WebKitFormBoundary6AiBMw0TyIybreRa\r\nContent-Disposition: form-data; name="g-recaptcha-response"\r\n\r\n'"$recaptcha"'\r\n------WebKitFormBoundary6AiBMw0TyIybreRa--\r\n' \
  --compressed "https://url.com"

Leave a Reply

Your email address will not be published. Required fields are marked *