Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

How can I do it? I am trying it like this RESULT=`wget $URL`

P.S. - Also any recommended sources for learning shell scripting?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

How about:

RESULT="`wget -qO-`"
echo $RESULT

Edit: Yeah, that works.

share|improve this answer
Why another dash after -qO? – Ashfame Feb 10 '11 at 12:06
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. – Oli Feb 10 '11 at 12:12
What I meant was that when -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? – Ashfame Feb 10 '11 at 14:32
It's -O's argument. It tells it where to write the output of the download (in this case: back to the current stream). – Oli Feb 10 '11 at 14:37
I got it now. Thanks a lot :) – Ashfame Feb 10 '11 at 15:09

The preferred way would be

result=$(wget -qO-
echo "$result"

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

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

share|improve this answer
Thanks for your input! Can you explain it a bit what's wrong with quotes here? – Ashfame Feb 11 '11 at 21:39
@Ashfame This explains the main reason of why you should always quote expansions: – geirha Feb 11 '11 at 22:19
Thanks! I have bookmarked the resources. I will learn from there. :) – Ashfame Feb 12 '11 at 7:18
Why are most other resources on shell scripting garbage? – Dave Kennedy Sep 19 at 20:00
@Koveras how should I know? People probably read the ABS guide and then decide they'll share their newfound knowledge with the world with yet another crappy tutorial. – geirha Oct 3 at 8:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.