I just spent more time than I should have trying to figure out why wget was not retrieving web pages correctly. I’ve been using wget for ages with no problems. It turns out the ampersand & in the URL was behaving badly. The solution is obvious, once I found it buried deep in a discussion at RedHat.com. Enclose the URL in single quotes. Works like a charm.
I agree, this was not clearly mentioned in the manual – that I saw anyway and I followed some other poor suggestions about encoding or double quotes before reading this.
Single quotes and all is good.
Oh my god thank you so much!!! I Spent AGES trying to get this to work (using encoding and double quotes etc) and I can’t believe I didn’t try single quotes, such an obvious solution, why isn’t it mentioned in the manual?
Granted this is an old, but for those who come here via Google; the reason that this isn’t mentioned in the manual is that this is not a wget problem; this is a bash problem. Bash interprets ampersands as a control operator. Everything before, and separately after the ampersand gets passed as a single standalone command.
Informative post, i made sure that I followed suggestions about encoding or double quotes and it really worked well for me. Thanks 😀
You can also use a backslash before the ampersand. This is useful if the URL contains a variable that you’d need substituted, such as
http://server“$n”.company.com/control?active=true\&password=password
Very useful post! Charles, you got it right with the backslash before the ampersand. Thanks for sharing the info.
Spot on! This is exactly what I was looking for. The backslash before the ampersand works a treat.
Harry
i know this is very old threads but …
Thanks.
Just recently moved to perl/bash for some quick cooking and spent almost 2 hours looking wget downloading 2 files when using & char.
you saved the day 🙂
By the way \& didn’t worked for me
Here’s another technique:
URL=”http://example.com/some/query?ENTRY=something&this&that”; wget “$URL”