- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- scripts problem
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
04-07-2004 01:35 AM
04-07-2004 01:35 AM
if some one knows how to do it it will be great
thanx.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 01:47 AM
04-07-2004 01:47 AM
Re: scripts problem
There are no shell tools for this. I once wrote a little C program which did this and returned the ascii value of the character pressed but can't find it :(
You can do it in C and set the terminal to raw mode and a few other bits and bobs. If you want to do it the simple way, a small C program that uses "curses". Curses has a function to achieve this for you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 01:53 AM
04-07-2004 01:53 AM
Solutione.g.
CH=$(onechar -L)
STAT=${?}
case ${STAT} in
0) echo "You pressed ${CH}"
;;
255) echo "This is an error" >&2
;;
*) echo "The ASCII value pressed is \c"
echo "${STAT} (dec)"
;;
esac
The idea is if 0 is returned, a printable character is output on stdout, a return of 255 indicates an error, any other returns indicates that a non-pritable ASCII character was received and the return value is the decimal equivalent and no character is output to stdout.
If you need to recognize function keys or arrow-keys then you really need to use curses. Man curses for details.
This is onechar.c. Compile it like this:
cc onechar.c -o onechar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 01:58 AM
04-07-2004 01:58 AM
Re: scripts problem
Here is a pure shell method but I consider it much less robust:
#!/usr/bin/sh
echo "Enter character: \c"
stty raw
CH=$(dd if=/dev/tty bs=1 count=1 2>/dev/null)
stty -raw
echo "You entered ${CH}"
The reason this is not so nice is that no mechanism is present to easily recognize non-ASCII characters. Whatever you do, make sure that the second stty gets called because terminal settings affect not just the process but ALL processes for which this terminal is the controlling terminal.
The C program makes certain that this is done and easily tells you when a control character was entered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 01:58 AM
04-07-2004 01:58 AM
Re: scripts problem
but i cannot see the c program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 02:04 AM
04-07-2004 02:04 AM
Re: scripts problem
###########################################
function GetChar1
{
# Read 1 character and return as first argument
# example: GetChar1 MYCHAR
stty raw
eval $1='"$(dd bs=1 count=1 2>/dev/null)"'
stty cooked
}
Just call this when you need one character.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 02:09 AM
04-07-2004 02:09 AM
Re: scripts problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 02:20 AM
04-07-2004 02:20 AM
Re: scripts problem
I just sat here and re-coded a raw mode getc and found A.Clay got in there well before hand and then Bill comes along with a cute Korn version.
I'll get my coat :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2004 03:31 AM
04-07-2004 03:31 AM
Re: scripts problem
GetChar1 "MYCHAR"
# Search for an acceptable response. Since just CR
# (or other control chars) might be entered, convert
# MYCHAR to hex and test accordingly.
HEX=$(echo "$MYCHAR" \
| xd \
| head -1 \
| awk '{print $2}' \
| cut -c 1-2)
# CR or CTRL-D? Bail out.
if [ "$HEX" = "0d" -o "$HEX" = "04" ]
then
echo "\n\n"
exit
...and so on...
Bill Hassell, sysadmin