LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-15-2005, 03:05 AM   #1
Basta
LQ Newbie
 
Registered: Jun 2004
Posts: 15

Rep: Reputation: 0
Use pipe with wget


I'm writing a shell script but having difficulties wit the following. I want to use a pipe for wget, however this doesn't seem to work. This is what I try:

$ echo "www.google.com" | wget
wget: missing URL
Usage: wget [OPTION]... [URL]...

Try `wget --help' for more options.

Actually I will use another script that return an url instead of the echo command but to keep it simple I thought this should also work. What am I doing wrong? The output of the echo command should be used as input for wget? Yet wget doesn't get any input.

Your help is appreciated.
 
Old 04-15-2005, 03:38 AM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Standard input to a program is not the same thing as an argument on the command line. You have two options:
Code:
wget $( echo "www.google.com" )

Or you can use the xargs command:
Code:
echo "www.google.com" | xargs wget
In the first option, everything inside "$( )" is considered a command, and the whole sequence is replaced with the command's output.
 
Old 04-15-2005, 03:39 AM   #3
wilho
LQ Newbie
 
Registered: Apr 2005
Distribution: Gentoo
Posts: 9

Rep: Reputation: 0
You don't get concept of pipes exactly right. Pipe redirects standard output stream of command to a input stream of another command. Wget in other hand excepts URL as _parameter_, which is not a stream at all.

One way is to use xargs -command to translate:
echo "www.google.com" |xargs wget

or another example with multiple parameters:
ls | xargs echo

So xargs translates its standard input into its first parameters parameters and executes it.

edit:
too slow

Last edited by wilho; 04-15-2005 at 03:40 AM.
 
Old 04-15-2005, 06:42 AM   #4
Basta
LQ Newbie
 
Registered: Jun 2004
Posts: 15

Original Poster
Rep: Reputation: 0
Thanx guys, I'm glad this is the newbie section. I'm learning
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regarding mail pipe hinetvenkat Linux - Networking 0 07-16-2005 03:31 AM
2-way pipe saiz66 Programming 3 11-22-2004 08:54 AM
pipe jelly Slackware 2 03-05-2003 04:07 AM
pipe using no pipe soathana Programming 2 02-22-2003 05:33 PM
who with a pipe blown99GT Linux - General 5 07-16-2002 03:58 PM


All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration