Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!dogie.macc.wisc.edu!indri!aplcen!bink From: bink@aplcen.apl.jhu.edu (Ubben Greg) Newsgroups: comp.unix.questions Subject: Re: SYSV version of \"grabchars.c\". Summary: Use head instead Keywords: shell script GNU head stty Message-ID: <1201@aplcen.apl.jhu.edu> Date: 6 May 89 06:30:28 GMT References: <19462@adm.BRL.MIL> Reply-To: bink@aplcen.apl.jhu.edu (Greg Ubben) Organization: The Johns Hopkins University, Baltimore MD Lines: 28 In article <19462@adm.BRL.MIL> mark@ria-emh2.army.mil (Mark D. McKamey) writes: > I have recently recieved a copy of Mr. Dan Smith's "grabchars" program > which allows you to get one or more keystrokes from the user, without > requiring them to hit RETURN within a shell script. The problem I have is > that the program was written for BSD UNIX. Has anyone ported said program > to SYSV UNIX? If so, would you please send me the SYSV patches. Thank You. I wrote a System V script to allow single-keystroke input too, and came up with a more general solution (not requiring the "grabchars" program). I first used the stty command to allow reading single character responses. Something like "stty -icanon min '^a'" but I don't have AFSVM handy, so this is probably wrong. Be sure to use stty -g to save the current modes in a variable first, and set up a trap to restore them. Then the only way I found to actually read one character without a newline was to use a "head" program I wrote (before I gnu about knew). The code looked something like: case `head -1c` in [Yy]) ... [Nn]) ... I would expect that GNU head could be used the same way. Multi-sequence keys would fool it (such as function keys) -- does grabchars handle this? Is there a better way yet (in shell)? -- Greg Ubben bink@aplcen.apl.jhu.edu