Shell script accepting input from a pipe AND the keyboard

Reply

Join Date: Mar 2008
Posts: 2
Reputation: Robert72 is an unknown quantity at this point 
Solved Threads: 0
Robert72 Robert72 is offline Offline
Newbie Poster

Shell script accepting input from a pipe AND the keyboard

 
0
  #1
Oct 8th, 2008
I'd like to write a shell script that'd parse data from a pipe and then ask the user questions.
ie:

Shell Scripting Syntax (Toggle Plain Text)
  1. echo "Ann Bob Charlie" | checkuser.sh
  2. checkuser.sh starting
  3. Ann is OK.
  4. Bob is not in the system. Add Bob? (y/n):

I know a couple ways to read from a pipe:
Shell Scripting Syntax (Toggle Plain Text)
  1. names="`cat`"
and
Shell Scripting Syntax (Toggle Plain Text)
  1. names=""
  2. while read myline; do
  3. names="$names\n$myline"
  4. done

But I don't know how to make the script start looking to he keyboard for input from the pipe's exhausted. I'd love to know exactly how the machine thinks of these kinds of things. I mean, is the terminal file (ie /dev/pts/12) still "attached" to the session? Is the logical definition of "stdin" or "file descriptor 0" changed in some way?

Many thanks for any insightful insights!
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 61
Reputation: Gromit is an unknown quantity at this point 
Solved Threads: 7
Gromit's Avatar
Gromit Gromit is offline Offline
Junior Poster in Training

Re: Shell script accepting input from a pipe AND the keyboard

 
0
  #2
Oct 8th, 2008
I think you're looking for read -p

I have some examples, but running to a meeting... If you still need help, I'll post it later!

-G
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 61
Reputation: Gromit is an unknown quantity at this point 
Solved Threads: 7
Gromit's Avatar
Gromit Gromit is offline Offline
Junior Poster in Training

Re: Shell script accepting input from a pipe AND the keyboard

 
0
  #3
Oct 12th, 2008
Heya Robert72! Did you find what you were looking for, or did you need more specific examples?

-G
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Shell Scripting Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC