If you make a typing mistake in your shell command line and press
RETURN, it's gone. After you get the pesky error message, you'll
have to type the whole thing in again - unless you happen to be
using the C shell
happen to remember its
However, fewer people know that the Korn shell has another editing mode, one that emulates theeditor. The emacs mode editing commands act like a natural extension to traditional, simple shell editing commands (like Delete or Backspace for character erase), so even if you aren't familiar with the emacs editor, you should find emacs mode useful. To use emacs mode, put this line in your .profile :
set -o emacs
We'll cover only the most useful emacs mode commands here. For a more complete description, see O'Reilly & Associates' Learning the Korn Shell , by Bill Rosenblatt.
Emacs mode figures out what your Table 11.1 .is and lets you use it in the same way. In addition, it gives you the basic commands for editing a line listed in
In addition, emacs mode maintains a history file that enables you to recall previous commands. The commands in Table 11.2 are the most important of those that let you navigate the history file.
The first of these is the most useful by far - it's the "I made
a mistake, so I'll go back and fix it" key. The search capability
lets you bring back specific commands you may have typed awhile
ago without having to go through the history file line by line
with CTRL-p. Just enter CTRL-r followed by a search string and RETURN,
and the Korn shell will bring back the
that contains the search string (or beep at you if it finds no match).
Assuming it is the command you want, you would then press RETURN
again to run the command.
If you begin your search string with a caret (
Another extremely useful feature of emacs mode is the filename completion facility, which should be familiar to C shell experts as well as Emacs users (see article 9.8 ). Emacs mode supports two completion commands, the most useful of which is ESC ESC (the Escape key pressed twice). If you type in a word and press ESC ESC, the shell will search for a filename that begins with what you typed and try to finish it. If there is only one filename that begins with your word, the shell will complete the name. If there is more than one, it will only complete out as far as it can without having to make a choice.
For example, if your directory contained the file
and you typed
[Another way to do history editing is with your own editor: the. -JP ]