Timed keyboard input 

Newsgroups: comp.unix.shell
Date: 1997/05/31

http://groups.google.com/groups?hl=en&safe=off&th=8a5975360c80c043,5&seekm=WOLKOWSB.97Jun1085100%40dec.cuug.ab.ca#p

>Is there an equivalent of 'read' that gives up after a specified wait
>for user input?

Yes indeed. To start off there is 'read -t' in ksh93. Or you can use somthing like this

#!/bin/sh
exec </dev/tty
old=`stty -g`
stty raw -echo min 0 time ${1:-10}
echo -n How old are you?
IFS='' read -r a
stty $old
echo I think you are $a

which will wait a number of tenths of a second to get the user input. Or you can use the 'timed-read' command which comes with 'expect'. or you can use

#!/bin/sh
exec 2>/dev/null
( sleep ${1:-10) ; kill $$ ; ) </dev/null &
exec line

if you have 'line' available (or try replacing it with 'head -1' or 'sed 1q', but these tend to eat up too much input). Use as var=`scriptname timeout`.

Icarus

Timed keyboard input 

The following is an example that I think does exactly what you want:

stty raw
stty min 0 time 40      #'40' is for 4 seconds timeout
stty -echo
echo "Enter somthing : \c"
read var
stty -raw
stty echo
echo ${var}

Brian Wolkowski