|
|
The Korn and C shells provide facilities for making it easier to enter commands:
Every time you issue a command to the Korn shell, in addition to executing the command, the shell adds it to a list of previously executed commands.
To view the list of previously executed commands, issue the history command. This displays a number (up to the number set in $HISTSIZE) of previously issued commands. $HISTSIZE is set in .profile.
Before you can recall and edit the history list directly, you must
issue the ksh command
set -o vi
to set the vi editing mode in the shell. Similarly, the
following command line sets emacs editing mode in the
shell:
set -o emacs
Either of these commands may be issued automatically by your .profile file. set -o on its own displays all the current ksh options; you may want to see what options are available.
To enable history editing permanently, add the following to your
.profile file:
if [ -z "$VISUAL" -a -z "$EDITOR ]
then
set -o vi
fi
(This may also be found in your .kshrc file.) See
ksh(C)
for details of the VISUAL and EDITOR variables;
see
test(C)
for an explanation of the [ ... ] notation and
the options used in the example.
Once the vi option, for example, is available, you can edit your command history using the vi editing keys. The shell initially behaves like vi in text insertion mode; if you type a command it inserts text, and when you press <Enter> it executes the line you just typed. Here is a quick overview:
A full list of the available vi mode command editing keystrokes is given in the ksh(C) manual page. For an introduction to the vi editing keystrokes, see ``A quick tour of vi''.
Note that the contents of the history file are maintained across
logouts and environment resettings. Accordingly, previously executed
command lines are still available for editing or re-execution even
after something like the following:
. $HOME/.profile
The C shell does not let you edit previous commands interactively. However, you can recall entire command lines or portions of commands, and make changes to them.
To repeat the last command you typed, use the following command:
% !!
The exclamation mark (!) tells csh to expect a
history command, and the second exclamation mark specifically refers
to the last command entered.
To display your command history, use the following command:
% history
The C shell lists out the last few commands (the precise number
being controlled by the history environment
variable). Each command is listed with an event number. For example:
9 vi chapter.6 10 wc -l chapter.6 11 l ch 12 diff chapter.6 chapter.6.old | more 13 vi chapter.7To recall a given event, type an exclamation mark followed by the event number; for example, to edit chapter.6 again, the command would be !9.
To alter a command, you can follow the event number with a colon (:) and a modifier which is applied to the word.
For example, to edit chapter.8 using the above history, you could issue the instruction !9:s/8/6/, which substitutes ``8'' for ``6''.
A full list of modifiers is provided in the csh(C) manual page.