Solved

Shell script question

Posted on 2001-09-16
3
224 Views
Last Modified: 2012-05-04
Hi all,

How do i read a function key (eg F3) in a shell scripts.

tq
0
Comment
Question by:joekwchen
3 Comments
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 50 total points
Comment Utility
Basically you can't.  Shell script expect input to be in
lines, and pressing a function key is usually something
you want to see right away.

There are some tricks for getting single key events in the
shell, but these basically have to do with remapping
the terminal settings so that certain ASCII characters
will produce a program signal event.  But the problem is
that you can't do this for function keys because they're
usually represented as a sequence of ASCII characters,
not as a single character.

You might be able to do such things in Perl, though.
0
 
LVL 2

Expert Comment

by:bedot
Comment Utility
a function key send a sequence described in terminfo, depending on the TERM variable.
try the command infocmp (if present on your UNIX): the sequence sended by F1 is described in KF1 ;
BUT normally, the read function of the shell read the entry buffer after you send a CR;
you must modify with a stty command the entry parameters to resize the buffer at 1 character, so the shell will be able to read the buffer character by character;
see for more details the TERMIO chapter of tha manual.
have a good trip !
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
it's as chris_calabrese already described: you need to map a string (terminated by the terminals EOL-character) to the function key. This might be more easy if your shell runs in a X environment, rather than from a console, there you can use ~/.Xdefaults, xmodmap, etc.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now