The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
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 03:03 AM
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 11:39 AM
Pipe data to shell script tomjones07 Shell Programming and Scripting 3 03-14-2007 07:50 PM
Capturing a ret val of C obj file in ksh script k_bijitesh High Level Programming 5 05-16-2006 07:20 AM
Capturing shell script command output designflaw Shell Programming and Scripting 2 03-01-2006 04:24 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-02-2005
heinz heinz is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
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
  #2 (permalink)  
Old 11-02-2005
flyingpenguin flyingpenguin is offline
Registered User
  
 

Join Date: Oct 2005
Posts: 9
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 (permalink)  
Old 11-02-2005
heinz heinz is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
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 (permalink)  
Old 11-02-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
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 (permalink)  
Old 11-02-2005
heinz heinz is offline
Registered User
  
 

Join Date: Nov 2005
Posts: 4
That did it Ygor.

I could've sworn I tried that early in the game, but guess not.

Thank you very much.
  #6 (permalink)  
Old 11-03-2005
jerardfjay jerardfjay is offline
Registered User
  
 

Join Date: Feb 2005
Posts: 146
Use tee command

Something like this would work

Code:
echo "this is some text" | tee file_name | shellscript abc def ghi
Jerardfjay
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:56 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0