Timing READ command - any key to exit


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Timing READ command - any key to exit
# 1  
Old 01-27-2013
Timing READ command - any key to exit

Hello everyone,
I would like some help on an issue I have related to the read command with ksh93 (Unix AIX).
I want to implement a 'press any key to exit' scenario.
I have the following code:

Code:
STTY=$(stty -g)
if [ -t 0 ];then 
    stty -echo -icanon time 0 min 0
fi
k=""
while [[ "x$k" = "x" ]];do
read k

# following is a group of command that retrieve data from several files
# and process the data summarizing and filtering it (using awk).
# This section could possibly take 1 to 2 seconds to complete its job
# the final command does a cat of the generated data file to the screen
# then the loop would start again retrieving fresh stats from files....
........
done
stty $STTY

When I execute the code and press any key while it is executing, sometimes it exits properly, other times it takes more than one key press to exit, maybe because the key got pressed while the processing section of the loop was running. What could be 'chewing up' the pressed keystroke?
Do you have suggestions on how to guarantee termination on a single key stroke?
Maybe I need to redesign my loop logic ?
I am open to any advice and suggestion.
Thanks to all!
# 2  
Old 01-27-2013
Did you try the -t0 -n1 options to the read command?
# 3  
Old 01-27-2013
When I try the
Code:
 -t0 -n1

options to the read then I can only exit by CTRL+C. ...
Thanks
# 4  
Old 01-27-2013
Try -t0.1
# 5  
Old 01-27-2013
I do not think I can use decimals ....
Code:
ksh[22]: read: -t: numeric.
 timeout argument expected
Usage: .
read [-Aprs] [-d delim] [-u filenum] [-t timeout] [-n nbytes] [name...].

# 6  
Old 01-27-2013
Try -t1 But this may unacceptably lengthen your execution time.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX Pipe -Exit when there are no bytes to read

Hi All, I'm creating a program which reads millions of bytes from the PIPE and do some processing. As the data is more, the idea is to read the pipe parallely. Sun Solaris 8 See the code below: #!/bin/sh MAXTHREAD=30 awk '{print $1}' metadata.csv > nvpipe & while do ... (3 Replies)
Discussion started by: mr_manii
3 Replies

2. Shell Programming and Scripting

Exit to while read

Hi expert, How do i exit to while read, below is the script. I need to exit after execute echo or command. or any scripts that can search two patterns and if they found any patterns execute the command and exit. Thanks a lot.. tail -fn0 /tmp/test.log | \ while read line ; do ... (12 Replies)
Discussion started by: lxdorney
12 Replies

3. Shell Programming and Scripting

Read exit value from Shell script

Hi all, I have a situation to read exit value of a command (not exit code) and process further. bash-4.2$ returnvalue=`ssh DOMAIN\\\\user1@10.7.7.68 'cmd /c "del C:\Users\user1\db_test.bak"'` Could Not Find C:\Users\user1\db_test.bak bash-4.2$ echo $? 0 bash-4.2$ echo $returnvalue... (3 Replies)
Discussion started by: baluchen
3 Replies

4. UNIX for Advanced & Expert Users

Returning exit code from a while read $inputline

Hi searched hi and wide for this with no luck. Maintaining a bash script that #!/usr/bin/bash #does some stuff like setting env etc. f_do_dbwork ... .. #Now I want to exit with the value of $err however $err is re-initialised to 0 on exiting the function Always 0 .... ... (3 Replies)
Discussion started by: StevePr
3 Replies

5. UNIX for Advanced & Expert Users

Equivalents of tee command to find exit status of command

Hi, Want to log the output of command & check the exit status to find whether it succeeded or failed. > ls abc ls: abc: No such file or directory > echo $? 1 > ls abc 2>&1 | tee log ls: abc: No such file or directory > echo $? 0 Tee commands changes my exit status to be always... (7 Replies)
Discussion started by: vibhor_agarwali
7 Replies

6. Shell Programming and Scripting

Read/Search file being written to giving error due to timing issues

The following is a piece of code to rename LOG_FILE_NEW to LOG_FILE once you get a result (either RUNNING or SHUTDOWN) RESULT="" sleep 30 while ; do sleep 10 RESULT=`sed -n '/RUNNING/'p ${LOG_FILE_NEW}` if ; then RESULT=`sed -n '/SHUTTING_DOWN/'p ${LOG_FILE_NEW}` fi done mv... (3 Replies)
Discussion started by: sonorous
3 Replies

7. Shell Programming and Scripting

Want read and an built in enter key stroke

i have script like: echo "enter name" read a I do not want to press enter key i have tried with ascill of enter as (\013) but still it wait for enter , please resolve my problem (2 Replies)
Discussion started by: RahulJoshi
2 Replies

8. Shell Programming and Scripting

urgent -read exit status

i have written a shell script that invokes main class of a java prg. the java prg does a System.exit(0) or (1) based on condition. how can i read or check the status in unix.... (4 Replies)
Discussion started by: iamcool
4 Replies

9. Shell Programming and Scripting

read the ENTER key

Hi , I do the following : ]echo "Do you want to say yes or no ?(y/n):\c" read ans here 'n' is the default value.that means if the user press ENTER key then it should be 'n' . Now how do i know that the user has pressed ENTER key.What will be stored in my variable 'ans'. (4 Replies)
Discussion started by: sars
4 Replies

10. Shell Programming and Scripting

Read line with a single key press...

I would really like to have a script that will accept the key press from the user with out having to press the enter key afterwards. i.e. echo "Press Y to print \c" read YesNo At this point the user has to press the enter key to continue. Is there a way to accept the key press from the... (3 Replies)
Discussion started by: jagannatha
3 Replies
Login or Register to Ask a Question