Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Pipe data to shell script

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 03-14-2007   -   Original Discussion by tomjones07
tomjones07 tomjones07 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 14 March 2007, 7:50 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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?
Sponsored Links
    #2  
Old Unix and Linux 03-14-2007   -   Original Discussion by tomjones07
sb008 sb008 is offline Forum Advisor  
Registered User
 
Join Date: Jan 2007
Last Activity: 12 January 2013, 3:37 AM EST
Posts: 398
Thanks: 1
Thanked 3 Times in 3 Posts
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

Sponsored Links
    #3  
Old Unix and Linux 03-14-2007   -   Original Discussion by tomjones07
Ygor's Unix or Linux Image
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 15 May 2015, 11:55 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 114 Times in 99 Posts
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  
Old Unix and Linux 03-14-2007   -   Original Discussion by tomjones07
tomjones07 tomjones07 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 14 March 2007, 7:50 PM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
cheers guys Linux
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Data pipe lost when using ssh in shell script siavash Shell Programming and Scripting 2 02-01-2012 07:28 AM
Using Named pipe in shell script sudvishw Shell Programming and Scripting 2 09-12-2011 06:21 AM
Reading from blocking fifo pipe in shell script victorin Shell Programming and Scripting 4 05-08-2007 12:39 PM
Need help capturing pipe to a file in shell script heinz Shell Programming and Scripting 6 11-03-2005 08:27 AM



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