Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!island!daniel From: daniel@island.COM (Daniel Smith - part of the caffeine generation) Newsgroups: comp.unix.questions Subject: Re: timeout on read; Bourne Shell Message-ID: <4124@island.COM> Date: 30 May 91 16:19:55 GMT References: <1991May26.165314.21533@midway.uchicago.edu> <1153@mwtech.UUCP> Organization: Island Graphics, Marin County, California Lines: 26 In <1153@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: > In article <1991May26.165314.21533@midway.uchicago.edu> goer@ellis.uchicago.edu (Richard L. Goerwitz) writes: > >Is there any elegant way to achive a timeout on a read within > >a shell script? Perhaps even "fairly elegant" would do. Even > >a kludge? One way is to get the grabchars package, which allows for timeouts and default answers (and more). A line such as: score=`grabchars -d0 -b -n5 -t10 -r -q 'enter your score >> '` Will set $score to 0 if return is pressed as the first character, or if 10 seconds go by. -b means output to stdout and stderr (so that you can see what you are typing, -t is # of seconds to time out, -n is # of (up to) chars to get, -r means "allow return key". You can get if from comp.sources.misc archives on uunet and elsewhere, or directly from me. Daniel -- daniel@island.com Daniel Smith, Island Graphics, (415) 491 0765 x 250(w) daniel@world.std.com 4000 CivicCenterDrive SanRafael MarinCounty CA 94903 dansmith@well.sf.ca.us Fax: 491 0402 Disclaimer: Hey, I wrote it, not IG! falling/yes I'm falling/and she keeps calling/me back again - IJSaF, Beatles