Clearing the input buffer before a read.
Alan Chantler CS
csx040 at cck.cov.ac.uk
Fri Nov 30 20:26:53 AEST 1990
In article <1990Nov26.001425.15563 at massey.ac.nz> K.Spagnolo at massey.ac.nz (Ken Spagnolo) writes:
>I have an sh script that asks the user a question and reads
>the answer into a variable in the usual method. I want to
>be able to flush the input buffer just before the read so
>that any slips or double key bounces get ignored, rather than
>used as the answer. I realize this disables type ahead, but
>I can live with that. Anyone know how to do this?
OK This is not quite the answer that you seek, but it may help.
Whenever I want a script to read into a variable (say 'fubar')
then I use:
read fubar junk
This will capture any 'extras' into 'junk', which I ignore.
Of course it doesn't work unless there is whitespace after
legitimate input, but it can be extended for any number
of inputs on a line:
read x y z junk
etc.
--
AlanC at coventry.ac.uk | Post: Coventry Polytechnic
JANET: AlanC at uk.ac.coventry | Priory Street
INET : AlanC%coventry.ac.uk at nsfnet-relay.ac.uk | Coventry, UK
Phone: +44 203 838332 | CV1 5FB
More information about the Comp.unix.shell
mailing list