?
Solved

Shell script question

Posted on 2001-09-16
3
Medium Priority
?
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 200 total points
ID: 6487788
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
ID: 6488435
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
ID: 6488679
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
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…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

741 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