/** * vBulletin 3.8.8 Beta 1 CSS * Style: 'LQ Style - child of default'; Style ID: 7 */ @import url("http://www.linuxquestions.org/questions/clientscript/vbulletin_css/style-7eb8640c-00007.css"); Read the output from a pipe with bash ?
LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-13-2004, 08:30 AM   #1
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Rep: Reputation: 30
Read the output from a pipe with bash ?


Hello

I want to read the output from a pipe with bash.

To read a normal parameter works good:
"myscript.sh abc"

myscript.sh
#!/bin/sh
echo $1;
echo $*;


But i want do this with a pipe:
"echo abc | myscript.sh"

All I get with Google was "Use C" or "Use perl".

Thanks in advance.
Fluppi
 
Old 01-13-2004, 11:38 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
This might work for you:

echo "Test" | xargs somescript.sh

This is the content of somescript.sh:

#!/bin/sh
echo "------------------------------------------------------------------------------------"
echo " From within :" $1
echo "------------------------------------------------------------------------------------"

And this the happens when executed:

$ echo "Test" | xargs somescript.sh
------------------------------------------------------------------------------------
From within : Test
------------------------------------------------------------------------------------


Hope this helps.
 
Old 01-13-2004, 12:41 PM   #3
fluppi
Member
 
Registered: Oct 2003
Location: Switzerland (Europe)
Distribution: OpenSuSE, RedHat, Knoppix, IRIX + MacOSX
Posts: 198

Original Poster
Rep: Reputation: 30
Thanks you, it works!
But, with xargs its "not the real thing", I mean, it looks not so beautiful.

Do I really have to use C or Perl ?
 
Old 01-13-2004, 12:59 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
Although I don't angree with the choice of words (I think xargs is very real and a very handy tool, but that's a very personal opinion ), I can relate to the 'not so beautifull'.

You don't specify why the first part of the pipe cannot be started/read from within the script, any particular reason??

If incorporating the first part into the shellscript isn't possible, then you have to use C or Perl.
 
  


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
how to pipe and parse output of a command learnfast Linux - Newbie 2 06-15-2005 04:55 AM
how to pipe output from make BBB Programming 2 05-20-2005 06:14 AM
pipe xine output to file sohmc Linux - Software 0 01-01-2005 10:03 PM
Output truncated when using pipe tells Linux - General 1 12-16-2003 08:06 PM
pipe output to append to a text file davee Linux - Newbie 3 08-27-2003 05:03 AM


All times are GMT -5. The time now is 03:52 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration