![]() |
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 |
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. |
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 ? |
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 10:09 AM. |