LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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: 31
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: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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: 31
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: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
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



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
pipe output to append to a text file davee Linux - Newbie 5 03-22-2016 07:44 PM
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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:44 PM.

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
Open Source Consulting | Domain Registration