Solved

Shell script question

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

Suggested Solutions

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

735 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