How can I do it? I am trying it like this RESULT=`wget $URL`
P.S. - Also any recommended sources for learning shell scripting?
How about:
RESULT="`wget -qO- http://example.com`"
echo $RESULT
Edit: Yeah, that works.
O
tells it to output somewhere, -
tells O
to output it to the current stream. And q
tells wget not to include any of its "Connecting to xxx..." information.
-q
is the quiet switch & -O
is used for giving the name to file where we want the output to be saved. From what I have been reading, we can write multiple switches together if all of them don't require arguments. So -qO
makes sense but then what does the last dash do?
-O
's argument. It tells it where to write the output of the download (in this case: back to the current stream).
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.
in WGET (for WINDOWS BATCH), there is like this:
OtherApplication -arg1 -arg2 > temp.txt
set /p MyVariable=<temp.txt