read-waiting for user response


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting read-waiting for user response
# 1  
Old 05-12-2003
read-waiting for user response

Would there be any reason for why a 'read ans' would not wait for a user's response (i.e user has to hit a key to continue)? I know for sure that it is doing everything else in that part of my 'if' statement but it doesn't wait for me to hit a key before continuing.

The strange thing is that for ans1 - ans3, it waits, then beginning with ans4 - ans7, it just continues as if I had hit a key and I've put breakpoints in but can't figure it out.

I'm not sure what would cause this anomaly. I've written many interactive scripts (ksh) with over 5-10 prompts in them and they've always worked fine.

I just can't figure out what could cause this one to be so different that it would ignore the wait prompt (read ans4). The code is identical to how I got ans1 - ans3 so I'm just wondering if any of you know/heard of this...this script has lots of validation going on using regexp, grep, etc to validate fields in a file but this should not be causing my problem....
# 2  
Old 05-12-2003
Is it possible for you to post your script?? It does sound weird.
# 3  
Old 05-12-2003
It's impossible to say what is happening without looking at the script. But you have probably redirected stdin at the time that the "read" statement is executed. Try something like:

read ians4 < /dev/tty
# 4  
Old 05-12-2003
Thanks! That did it. All is working now. So is this the most definite way to ensure that the user is prompted?

As soon as I added the < /dev/tty, all my prompts worked as they should at specified points.

Is it good practice then to always do this for every read statement in an interactive script?
Would there be a reason why one should not use the redirection every time?

Gianni
# 5  
Old 05-12-2003
The " < /dev/tty" opens the file called /dev/tty and attaches it to stdin. That is an expensive operation. You don't want to do that needlessly.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell read command is not waiting for user input

Hi, i am working on one automation , for that i have writing one shell program that take user input in "while read line" block. but read command is taking value that is readed by While block. while read line; do command 1; command 2 echo -n "Do you want to continute > " read rsp... (2 Replies)
Discussion started by: ranvijaidba
2 Replies

2. UNIX for Dummies Questions & Answers

passing input into a cmd line that's waiting for a response

Hi, I am writing a little script to update a parameters on JMQ. however the JMQ requires a "y" confirmation to be input as part of the cmd I am running. However I want run this script to offline with no input from a user. it works if a I create a file with with just y in it and pass that in... (3 Replies)
Discussion started by: shropshirehobbi
3 Replies

3. Shell Programming and Scripting

read command not waiting

Dear All, read command not waiting for my input, please suggest. code: while read line do echo "$line " | grep -i .par$ if ; then cd ../par echo " Do you want to proceed" read else cd ../sql read fi done <inp.txt Its not asking me any input? (2 Replies)
Discussion started by: mahendra singh
2 Replies

4. Shell Programming and Scripting

How to skip command if it is hanging while waiting for response

Hello, I have a script that contains the command "whois 1.2.3.4" Sometimes this command takes far too long to produce any output and as a result the rest of the script is not executed. Can anyone suggest a method so that if no output is produced after say 2 seconds the script skips that... (2 Replies)
Discussion started by: colinireland
2 Replies

5. Shell Programming and Scripting

Extracting first character from a user response

I am using the following code in a CShell script to get a yes/no response from the user: echo "" echo -n "Do you want to archive your main level directory? <y> or n: " set main_answer = $< Is there a way to extract the first letter from the user's response and then perhaps convert that... (4 Replies)
Discussion started by: phudgens
4 Replies

6. UNIX and Linux Applications

waiting for ssh response for seconds

Hi All, I have to make an alert that'll wait for ssh response from the server for certain seconds, if no response is there in between it'll raise an alarm. Havn't found any option for this yet, pls. help if anyone knows abt this. Any suggestion is welcome. :) Best Regards, VG (3 Replies)
Discussion started by: vguleria
3 Replies

7. Shell Programming and Scripting

Taking user response in perl

I was wondering if it was possible to take in a user's response in a perl program. For example. Ask user a yes or no question, and then depending on the response, print out a corresponding answer? Thanks! (2 Replies)
Discussion started by: silkiechicken
2 Replies

8. Shell Programming and Scripting

Script not waiting for user responce

hi all, Im fairly new to scripting and am having a noobish issue. Ive got a script that checks for certain directories and if they dont exist, prompts the user to do a mkdir. heres trouble spot in the script: cat dirlsttemp.dat | while read dir; do echo "$dir does not exist, would you... (3 Replies)
Discussion started by: rdudejr
3 Replies

9. Shell Programming and Scripting

need to read a file and keep waiting till it satisfies some condition

In my script i am writing to a counter file the no of processes i had started, that is each time i start a process, i will increment the content of counter file and also when the process ends i will decrement the content of the file. after this i do some other activities, by now i want to... (1 Reply)
Discussion started by: senthilk615
1 Replies

10. UNIX for Dummies Questions & Answers

booting up but the system was waiting for user interaction at console

Hi all, My ssytem is mounted on a rack and not connected with any console. When I rebooted it remotely, it didn't go thru the bootup process. when I connect my laptop to the system locally and found that it was waiting for user interaction. Do you know how to disable it, so that it will boot... (1 Reply)
Discussion started by: stancwong
1 Replies
Login or Register to Ask a Question