I'm writing a Bash script to access an API using cURL, but I'm having trouble passing in a variable.
I pass 2 parameters into the function, and then I'm using curl like this:
curl --request POST \
--url "${baseUrl}/$2?userId=$1"
When I echo "${baseUrl}/$2?userId=$1"
it looks like this:
https://correct-url.com/api/correct/path/PARAM2?userId=PARAM1
with the correct values of PARAM1 and PARAM 2.
However, when I try to execute the function I get the following error:
curl: (3) URL using bad/illegal format or missing URL
If I replace the userId=$1
part of the curl request with userId=PARAM1
then it works ok - it seems to be the variable that's causing the issue. PARAM1 consists entirely of letters and numbers (although potentially it may have hyphens and colons too, but I'm getting the error without that).
I'm on Windows and using Git Bash.
Everything I've seen online has said that I need to use double quotes instead of single, but I think I'm already doing that.