Get wget output to a variable

The preferred way would be

result=$(wget -qO- http://example.com)
echo "$result"

(lowercase variable name, $() instead of `` and quoted expansion of the result variable).

For shell scripting with bash and/or POSIX sh, http://mywiki.wooledge.org/BashGuide is the guide to read. And there's a lot more useful resources on that wiki, and on http://wiki.bash-hackers.org/. I'm afraid most other resources on shell scripting are garbage, so it's best to stick with those two.


How about:

RESULT="`wget -qO- http://example.com`"
echo $RESULT

Edit: Yeah, that works.

Tags:

Wget

Scripts