- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Reading a single character ... then what?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2003 11:09 AM
01-13-2003 11:09 AM
I see here a clever trick:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1be0fef4d250d611abdb0090277a778c,00.html
This is where stty/dd/tty are used to read a single character from the keyboard.
stty raw
readchar=$(dd if=$(tty) bs=1 count=1 2>/dev/null)
stty -raw
But now, in our cut-and-paste world, what happens if someone pastes a string? How does one nullify or clear the remaining input before accepting another keystroke? Especially if the remaining characters are of a random nature and may or may not be \n-terminated?
In other words, how do I clear the keyboard buffer in ksh?
Thanks in advnace.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2003 03:43 PM
01-13-2003 03:43 PM
SolutionSee if this would begin to address your needs:
#!/usr/bin/sh
stty -echo
stty raw
#
readchar=$(dd if=$(tty) bs=1 count=1 2>/dev/null)
stty -raw
echo "you typed '${readchar}'"
#
stty raw
line -t 1 RSVP #...bit_bucket anything more...
#
stty sane
stty erase "^H"
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2003 04:00 PM
01-13-2003 04:00 PM
Re: Reading a single character ... then what?
Almost exactly what I had in mind!
Any ideas on how to get the timeout down to null?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2003 05:41 PM
01-13-2003 05:41 PM
Re: Reading a single character ... then what?
Sorry, the timeout value for 'line' must be an integer greater than zero for this hack to work.
The following is a little shorter, safer prototype and will restore sensible shell terminal I/O behavior should the process be killed:
#!/usr/bin/sh
trap 'stty sane erase "^H"; exit 2' 0 1 2 3 15
#
stty -echo raw
readchar=$(dd if=$(tty) bs=1 count=1 2>/dev/null)
#
stty -raw
echo "you typed '${readchar}'"
#
stty raw
line -t 1 RSVP #...bit_bucket anything more...
#
exit 0
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 02:43 PM
01-15-2003 02:43 PM
Re: Reading a single character ... then what?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2003 04:14 PM
01-15-2003 04:14 PM
Re: Reading a single character ... then what?
/No_Points_Please/
You bring interesting questions! Thank you; it's my pleasure.
Warmest regards!
...JRF...