Computing.Net > Forums > Unix > shellscript help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

shellscript help

Reply to Message Icon

Name: J
Date: September 25, 2003 at 13:27:59 Pacific
OS: Unix
CPU/Ram: 256
Comment:

How can I write a shellscript to accept a character from the terminal as soon as it is typed (don't wait for user to hit return)?



Sponsored Link
Ads by Google

Response Number 1
Name: Nails
Date: September 25, 2003 at 13:48:49 Pacific
Reply:

There's really no way of doing it without changing the unix terminal driver which this function does:

#!/bin/ksh

readkey() {
oldstty=`stty -g`
stty -icanon -echo min 1 time 0
dd bs=1 count=1 <&0 2>/dev/null
# the line above reads after count=1:
# less than sign, ampersand, space,
# the number 2, greater than sign,
# /dev/null
stty $oldstty
}

x=$(readkey)
echo $x

Regards,

Nails


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: shellscript help

Help with Bourne Shellscript (More) www.computing.net/answers/unix/help-with-bourne-shellscript-more/5005.html

Help with Bourne Shellscript www.computing.net/answers/unix/help-with-bourne-shellscript/4997.html

need help in unix shellscripting www.computing.net/answers/unix/need-help-in-unix-shellscripting/7492.html