I've been looking for a solution to my problem all the morning, especially in the 4 posts in https://stackoverflow.com having the same error name in their title but the solutions don't work for me.
I want to do several simple cURL requests put together in a Bash script. The request at the end of the file always works, whatever request it is. However the requests before return an error:
curl: (3) Illegal characters found in URL
I am pretty sure that it has something to do with the carriage return in my file. But I don't know how to deal with it. As I show in the picture below I tried to use ${url1%?}
. I also tried ${url1%$'\r'}
, but it doesn't change anything.
Screenshot of file + results in terminal:
Any ideas?
If your lines end with \r
, stripping away the \r
from the $url
won't work, because the line
curl -o NUL "{url1%?}
also ends with a \r
, which is appended to the url argument again.
Comment out the \r
, that is
url1="www.domain.tld/file"
curl -o NUL "${url1%?}" #
or
url1="www.domain.tld/file" #
curl -o NUL "$url1" #
or convert the file before executing it
tr -d '\r' < test.sh > testWithoutR.sh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With