![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| capturing line from script output and appending to a file | wally_welder | Shell Programming and Scripting | 6 | 08-31-2007 12:03 AM |
| Reading from blocking fifo pipe in shell script | victorin | Shell Programming and Scripting | 4 | 05-08-2007 08:39 AM |
| Pipe data to shell script | tomjones07 | Shell Programming and Scripting | 3 | 03-14-2007 04:50 PM |
| Capturing a ret val of C obj file in ksh script | k_bijitesh | High Level Programming | 5 | 05-16-2006 04:20 AM |
| Capturing shell script command output | designflaw | Shell Programming and Scripting | 2 | 03-01-2006 01:24 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help capturing pipe to a file in shell script
The command:
echo "this is some text" | shellscript abc def ghi My problem: How to capture "this is some text" so that I can process it, I.e. capture to a file. What I'm attemting to do is process the text echo'd into a file after writing the parameters passed first. No problem capturing abc, def, ghi into environment variables. I just can't get the text that's being piped to shellscript. I'm trying to simulate mail/mailx in shellscript. Thanks in advance for your help. Heinz |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
It sounds like you're trying to use a shell script to read from stdin (this is what you must do to capture "this is some text" from the echo command.)
Try inserting this line into your shell script. This captures the text from echo "this is some text" and stores it into $TEXT ------------------------------------ #!/bin/sh TEXT="" for foo in `cat /dev/stdin` do TEXT=$foo done echo "Captured Text: $TEXT" ------------------------------------------- A helpful article can be found here: http://lists.debian.org/debian-user/.../msg01220.html |
|
#3
|
|||
|
|||
|
Thank you flyingpenguin. Close, but no cigars yet.
No /dev/stdin in interix (MS Win2003 Services for Unix). Searching for equivilant. At least now I have something to search for. heinz |
|
#4
|
||||
|
||||
|
The first command in the script must do something with the piped input. So maybe use something like this....
Code:
#!/usr/bin/ksh cat > /tmp/captured.txt : |
|
#5
|
|||
|
|||
|
That did it Ygor.
I could've sworn I tried that early in the game, but guess not. Thank you very much. |
|
#6
|
|||
|
|||
|
Use tee command
Something like this would work
Code:
echo "this is some text" | tee file_name | shellscript abc def ghi |
|
#7
|
|||
|
|||
|
Yes, that would work, but not in may case as I can't change the command structure itself. I had to replace mailx as for some reason it broke and I found it easier to replace it than to dig into why it broke. That will be done some other time when we can risk possible downtime.
The cat > /tmp/file.txt did the trick. I'm still shaking my head as to what I did (or didn't) do right initially as I knew that should work. Maybe I didn't have it in as first command. Anyways, don't care as I have it working now :-) In case you're wondering, I found eemailer that runs as a service on Win2003 Server so I replaced mailx with my own, I.e. the script, which just builds the mail message and deposits it into the directory eemailer watches. Unix (interix) on Win Server is turning out to be a good platform for us (knock on wood). Thanks again everyone, especially Ygor who had the winner :-) |
|||
| Google The UNIX and Linux Forums |