From: Colm Buckley (colm at domain tuatha.org)
Date: Tue 12 Jun 2001 - 17:56:16 IST
On Tuesday 12 June 2001 17:46, Breathnach, Proinnsias (Dublin) wrote:
> Anyone know how to have a timed-out question in a shell script ?
> Scenario:
> Ask user do they want to run an interactive session.
> If no reply in 3 seconds assume the answer is no and continue
>
> All suggestions welcome :o)
Probably your best bet is to write a little C or perl program which
sets up an alarm() with a handler, waits for input, and writes it to
output unless the alarm went off.
For example, if you put:
#!/usr/bin/perl
alarm($ARGV[0]) if $ARGV[0];
while (<STDIN>) {
chomp;
print;
exit;
}
into "timedread", then something like:
echo -n "Enter some data : "
a=`timedread 10`
echo You entered ${a:=DEFAULT}
into a shell script, $a would be the data entered if the user entered
it before ten seconds were up, or DEFAULT if not.
Hope this helps,
Colm
-- Colm Buckley at domain NewWorld Commerce Business: +353 1 4334334 / colm at domain nwcgroup.com / http://www.nwcgroup.com/ Personal: +353 87 2469146 / colm at domain tuatha.org / http://www.tuatha.org/~colm/ CPU wise; pen and paper foolish.
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:10:38 GMT