Skip to content
Advertisement

Getting curl: (3) URL using bad/illegal format

My bash code is simply this. I am trying to learn docker but also a newbie with bash scripting. I type in something simple like google.com for the read command but it gives me curl: (3) URL using bad/illegal format or missing URL. Anyone know what I am doing wrong?

docker exec -it missingDependencies sh -c "echo 'Input Website:'; read website; echo 'Searching..'; sleep 1; curl http://$website;"

Advertisement

Answer

Curl will give that warning when invoked like this (without a domain):

JavaScript

let’s define an image that has curl.

JavaScript

and assemble it:

JavaScript

So now we can run your script.

JavaScript

Solution

JavaScript

The problem is that when you run bash -c “echo whatever $website”, the $website variable will be taken from your current environment and not from the docker environment (from read website). To counteract that the $website variable is interpolated, you could use single quotes like sh -c ‘read foo; echo $foo’, or escape the dollar sign: sh -c “read foo; echo $foo”

Advertisement