Hello Patrick, All, 

[email protected] (patrick keshishian), 2014.06.04 (Wed) 12:02 (CEST):
> On 6/4/14, Marcus MERIGHI <[email protected]> wrote:
> > Hello,
> >
> > In my attempts to write a simple script that lets the user select
> > options with a single key stroke I found no other way than to use bash
> > and its built-in read command with -n 1.
> >
> > I am looking for a way to do this in ksh(1). Any ideas? Please...
> 
> maybe something like this:

works, and feels a little bit deeper down the rabbit hole than I could
go myself. Thanks so much for taking me there!

Bye, Marcus

> --- 8< ---
> #!/bin/sh
> 
> # TODO handle signals!
> stty -icanon
> 
> # ask question
> echo "1. Sing a song."
> echo "2. Read a book."
> echo "3. Go to sleep."
> echo -n "Make a choice: "
> # read answer
> ans=`dd count=1 2>/dev/null`
> 
> # TODO validation
> 
> # print answer
> echo ""
> echo "ans=$ans"
> 
> # reset
> stty icanon
> --- >8 ---
> 
> --patrick
> 
> 
> > Some snippets from the bash(1) man page:
> >
> > read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p
> >         prompt] [-t timeout] [-u fd] [name ...]
> >         One line is read from the standard input, or from the file [...]
> >         -n nchars
> >                 read returns after reading nchars characters rather than
> >                 waiting for a complete line of input, but honor a
> >                 delimiter if fewer than nchars characters are read
> >                 before the delimiter.
> >
> > Thanks in advance, Marcus
> 
> 
> !DSPAM:538eef49152732022416572!

Reply via email to