Using curl in a bash script and getting curl: (3) Illegal characters found in URL

Solution 1:

The $URL contains a \r (CR) at the end (0d). Remove it with

URL=${URL%$'\r'}

before using it with curl.

Solution 2:

I had the same problem, but it was caused by me having created the script through Windows, which meant that the end of line had an unnecessary \r.

A simple dos to unix conversion fixed it.

dos2unix <scriptname>

Solution 3:

stripping away training \r

tr -d '\r' < test.sh > testWithoutR.sh