The C shell and
bash
can save copies of the previous command lines
you type.
Later, you can ask for a copy of some or all of a previous command line.
That can save time and retyping.
This feature is called
history substitution
, and it's done when you type a string
that starts with an exclamation point (
!
command
).
You can think of it like
variable substitution (
$
varname
) (
6.8
)
or
command substitution (
`
command
`
) (
9.16
)
:
the shell replaces what you type (like
!$
) with something else
(in this case, part or all of a previous command line).
Article
11.1
is an introduction to shell history.
These articles show lots of ways to use history substitution:
-
We start with favorite uses from several contributors - articles
11.3
,
11.4
,
11.5
,
11.6
.
-
Article
11.7
starts with a quick introduction, then covers the
full range of history substitutions with a series of examples that show the
different kinds of things you can do with history.
(Back in article
9.6
are examples of
csh
and
bash
operators like
:r
.
Many of these can be used to edit history substitutions.)
-
See an easy way to repeat a set of
csh
or
bash
commands in article
11.8
.
-
Each shell saves its own history.
To pass a shell's history to another shell, see articles
11.11
and
11.12
.
-
You don't have to use an exclamation point (
!
) for history.
Article
11.15
shows how to use some other character.
-
The Korn shell does history in a different way.
Article
11.13
introduces part of that: command-line editing in
ksh
and
bash
.
One last note:
putting the history number in your prompt (
7.2
)
makes it easy to re-use commands that haven't scrolled off your screen.