How to read a single character from the keyboard?

How to read a single character from the keyboard?

Post by Peter van Leeuwe » Wed, 13 Nov 1996 04:00:00



Can someone tell me how to read a single character input from the
keyboard from a ksh script? I'm tired searching in the manuals without
any success...

--

R&H Zuid-West B.V.
tel (010) 4477229

 
 
 

How to read a single character from the keyboard?

Post by Bob Sha » Wed, 13 Nov 1996 04:00:00



Quote:>Can someone tell me how to read a single character input from the
>keyboard from a ksh script? I'm tired searching in the manuals without
>any success...

There's always brute force:  getone.c
#include <stdio.h>
int main() {
unsigned int c;
c = getchar ();
printf ("%c", c);  }

J=`getone`
echo $J
--
Bob Shair                          Open Systems Consultant

Champaign, IL 61821                217/356-2684
< Not employed by or representing the University of Illinois >

 
 
 

How to read a single character from the keyboard?

Post by Manuel Mora » Wed, 13 Nov 1996 04:00:00


Try: REPLY=`dd bs=1 count=1`

Manuel Morais


>Can someone tell me how to read a single character input from the
>keyboard from a ksh script? I'm tired searching in the manuals without
>any success...
>--

>R&H Zuid-West B.V.
>tel (010) 4477229

 
 
 

How to read a single character from the keyboard?

Post by Bob Sha » Wed, 13 Nov 1996 04:00:00



Quote:>Can someone tell me how to read a single character input from the
>keyboard from a ksh script? I'm tired searching in the manuals without
>any success...

Or, since you've specified ksh, use the Korn shell "typeset" command:

typeset -L1 J
read J

will pull the leftmost character from the keyboard into variable J
and discard the rest.
--
Bob Shair                          Open Systems Consultant

Champaign, IL 61821                217/356-2684
< Not employed by or representing the University of Illinois >