Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Shell script question

Posted on 2001-09-16
3
Medium Priority
?
238 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

636 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