RSS Forums RSS

Shell script accepting input from a pipe AND the keyboard

Please support our Shell Scripting advertiser: Programming Forums
Reply
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

  #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:

echo "Ann Bob Charlie" | checkuser.sh
  checkuser.sh starting
    Ann is OK.
    Bob is not in the system. Add Bob? (y/n): 

I know a couple ways to read from a pipe:
names="`cat`"
and
names=""
while read myline; do
  names="$names\n$myline"
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!
AddThis Social Bookmark Button
Reply With Quote  
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

  #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  
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

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Shell Scripting Forum
Views: 1395 | Replies: 2 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:07 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC