[ale] keystrokes

R I Feigenblatt docdtv at ilinks.net
Wed Oct 30 10:43:00 EST 1996


>Jim Lynch, System Engineer,  SGI/Cray Research, Inc., wrote:
> } Is there any shell command in bash that will allow me to grab keystrokes
other
> } than read.  I would like to do a read command but give a time limit of 
> } 60 seconds.  Ne1 know how.  Or does ne1 have a C program that will take
> } the time length on the command line and return the input on STDOUT?

Jim, I had the same problem and wrote a little ("unsupported") shell script.
I enclose the top (documentation) of this script. Let me know if you want a
copy: I call the script "YesOrNo", but it captures a fairly general string.

Ron Feigenblatt

ENCLOSURE FOLLOWS:

##############################################################################
#
# Solicit string input, but abort if time limit is exceeded
#
# Command format:
#	YesOrNo [Timelimit [DefaultReply [Prompt ]]]
# Default args:		     5		"N"	"Hit ENTER to go on"
# Return codes: 0 (no entry made); 1 (entry made); 2 ($1=-?)
#
# Sample invocations:
#	YesOrNo 5 "Y" "Y/N" > /tmp/reply.$$ (captures answer string)
#	YesOrNo 5 "Y" "Y/N"; RC=$?	    (captures return code)
#	Do NOT try to backquote: If ENTER is never hit, process hangs!
##############################################################################
# Spawn background process (BGP). After a time delay,  BGP will signal
#	foreground process (FGP) to interrupt "read" to set reply & exit.
#	If user completes "read" quickly, FGP kills BGP and exits by itself.
# By using pipes vs. files, pipe-reads auto-block til pipe-writes complete; 
#	no "sync" and "[ ! -s filename ]" are needed.
##############################################################################






More information about the Ale mailing list