LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-05-2007, 09:57 AM   #1
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,891

Rep: Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569Reputation: 569
Using piped input in a BASH script


I have a program written in BASH which is usually run
like this:
./program-name OPTIONS INPUT

I'd like to be able to be able to use it like a filter by using piped input like this

echo INPUT | ./program-name OPTIONS

Does anyone know how to do this?
 
Old 08-05-2007, 10:50 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392Reputation: 2392
Hi,

Something like this:
Code:
#!/bin/bash

while read SomeString
do
  echo "=> $SomeString"
done
The above puts input (one line) in 1 variable ($SomeString), if you want to split a line into seperate variables:
Code:
!/bin/bash

while read String_1 String_2 String_3 String_N
do
  echo "=> $String_1"
  echo "=> $String_2"
  echo "=> $String_3"
  echo "=> $String_N"
done
Hope this helps.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
Trying to write a BASH script which allows input of paragraphs ChrisScott Linux - General 6 11-26-2006 05:32 PM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration