The UNIX and Linux Forums  


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
Shell script to format a .CSV data Uday1982 Shell Programming and Scripting 8 02-04-2008 05:28 AM
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 12:39 PM
shell script for log files data! rvrao77 Shell Programming and Scripting 6 11-30-2006 10:03 AM
Pipe Data From Grep Into A File katinicsdad Shell Programming and Scripting 4 09-08-2006 12:20 PM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 08:27 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-14-2007
tomjones07 tomjones07 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 2
Pipe data to shell script

Sorry about the noobish question but...

How do I capture data thats piped to my script?

For instance,

Code:
ls -al | myscript.sh

How do I access the output from ls -al in myscript.sh?
  #2 (permalink)  
Old 03-14-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by tomjones07
Sorry about the noobish question but...

How do I capture data thats piped to my script?

For instance,

Code:
ls -al | myscript.sh

How do I access the output from ls -al in myscript.sh?
A basic simple way


Code:
#!/usr/bin/ksh
cat - | while read LINE
do
  echo aa${LINE}bb
done

  #3 (permalink)  
Old 03-14-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
The first command in your script will accept the input from the pipe. So if you just want to capture it to a file, then try...
Code:
cat > file1

  #4 (permalink)  
Old 03-14-2007
tomjones07 tomjones07 is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 2
cheers guys
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 09:26 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