943,923 Members | Top Members by Rank

Ad:
Oct 8th, 2008
0

Shell script accepting input from a pipe AND the keyboard

Expand Post »
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!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Robert72 is offline Offline
2 posts
since Mar 2008
Oct 8th, 2008
0

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

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
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008
Oct 12th, 2008
0

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

Heya Robert72! Did you find what you were looking for, or did you need more specific examples?

-G
Reputation Points: 46
Solved Threads: 28
Junior Poster
Gromit is offline Offline
183 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: PR Jobs
Next Thread in Shell Scripting Forum Timeline: How to bulk resize JPG files in folder and subfolder





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC