Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

read doesnt work ... when dealing with stdin 1

Status
Not open for further replies.

OieL

MIS
Sep 6, 2002
17
0
0
US
Hi,

I have a shell script that takes strings from stdin as parameters. i.e. it runs like this:

find . | mycscript

But in it I want to be able to interact with the user. "read" can't work now. How should I do to get user's feed back form the keyboard?

 
read should work in that example. which shell is your script running in?
 
I am using bash here..

read works in " while read var ; "

but under it's loop I want to interact with the user ie. I need an input that wil come from the keyboard ...

someone tells me to use /dev/tty , but I don't know how it works ...

any help ?

thnks
 
This example could get you started

find . | while read var
do
echo "show this var? \c"
read ans < /dev/tty
case $ans in
[yY]) echo &quot;var is $var&quot;
;; esac
done Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Or you can change the file descriptor that read uses to something other than the default which it is trying to use (stdin).

Example:

find . -print > /tmp/$$

while read -u3 var
do
echo &quot;show this var? \c&quot;
read ans
case $ans in
[yY]) echo &quot;var is $var&quot;
;; esac
done 3< /tmp/$$
Regards,
Chuck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top