LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 09-09-2008, 05:08 PM   #1
zirtik
Member
 
Registered: Jul 2005
Posts: 33

Rep: Reputation: 15
Beginner question on using pipes


Hi, I'm trying to write a script that is going to use another program's stdout. For example if I type:

echo hello!|myscript.sh

I want myscript.sh to use the string "hello!". I tried to use $1 but it does not work. So I'm confused a little bit. I thought the output of "echo hello!" which clearly is "hello!" should have been redirected to myscript.sh as standard input but it didn't. What am I doing wrong here?

Thanks in advance.
 
Old 09-09-2008, 05:27 PM   #2
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,341

Rep: Reputation: 73
use read function in myscript.sh:
Code:
while read line; do
   echo $line
done
 
Old 09-09-2008, 06:09 PM   #3
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 60
In your script you need to read from the standard input. $1 is just the first argument presented to the script at start time in the command line. It is not the standard in, it's a very different thing.
 
Old 09-09-2008, 06:14 PM   #4
zirtik
Member
 
Registered: Jul 2005
Posts: 33

Original Poster
Rep: Reputation: 15
Thank you both
 
  


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
Question about reading/writing into a Named Pipes(FIFO) Sathya Programming 21 05-05-2008 08:39 AM
question from a beginner: install robzane Linux - Hardware 3 09-01-2006 07:14 PM
qt beginner question fakie_flip Programming 1 08-30-2005 06:10 PM
Question regarding pipes alltime Programming 3 04-15-2005 07:54 PM
Beginner question Ephack Linux - Networking 3 10-26-2001 03:40 AM


All times are GMT -5. The time now is 10:47 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration