LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Read the output from a pipe with bash ? (http://www.linuxquestions.org/questions/linux-software-2/read-the-output-from-a-pipe-with-bash-134305/)

fluppi 01-13-2004 08:30 AM

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

druuna 01-13-2004 11:38 AM

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.

fluppi 01-13-2004 12:41 PM

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 ?

druuna 01-13-2004 12:59 PM

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.


All times are GMT -5. The time now is 09:22 AM.