0

I'm getting the URL from the curl respond and assigning it to a variable. After that, I try to wrap the variable in different ways in single quotes inside which the URL is located to make a curl request. But when I try to do this, the second quote goes to the beginning of the string and not to the end of the variable value

EXAMPLE:

request1=$(curl ...)
echo $request1 
https://exapmle.com/....realybigurl
# try wrap url
echo "'"$requestq1"'" # or "'""$request1""'" or \'"$request1"\'
#and getting
**'**https://example.com/auth/realms/blabla.....
.....redirect_uri=https......
**'**scope=openid

The second quote goes to the beginning of the new line, not the end of variable. how to put it there? but the interesting thing is that this request works fine in git-bash but not in linux console (bash version 4.4 and 5.0.17)

  • 1
    There's probably a newline at the end of the variable contents – Shawn Dec 27 '22 at 17:23
  • More likely a carriage return, since `$()` removes a trailing newline. – Barmar Dec 27 '22 at 17:24
  • You also probably don't want to add single-quotes -- certainly not if you're going to use it in a `curl` request. Quotes go *around* data, not *in* data, and anything stored in a variable is treated as data. Generally, you just put double-quotes around the variable reference (e.g. `curl "$urlwithweirdcharacters"`). – Gordon Davisson Dec 28 '22 at 01:36

0 Answers0