Solved

Shell script question

Posted on 2001-09-16
3
231 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 50 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
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…

734 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