Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl: (3) Illegal characters found in URL : ${...%?} doesn't work [duplicate]

Tags:

bash

curl

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:

screenshot of file + results in terminal

Any ideas?

like image 817
Héloïse Chauvel Avatar asked Apr 25 '17 11:04

Héloïse Chauvel


1 Answers

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
like image 157
Socowi Avatar answered Oct 29 '22 22:10

Socowi