History lists for the C shell
The history list saves commands that the shell reads from the command line that consist of one or more words. History substitution reintroduces sequences of words from these saved commands into the input stream.
9 write michael
10 ed write.c
11 cat oldwrite.c
12 diff *write.c
The shell displays the command strings with their event
numbers. The event number appears to the left of the command and represent
when the command was entered in relation to the other commands in the history.
It is not usually necessary to use event numbers to refer to events, but you
can have the current event number displayed as part of your system prompt
by placing an exclamation mark (!
) in the prompt string assigned
to the PROMPT environment variable.
Event[.]Word:Modifier[:Modifier] . . .
In the previous sample of history command output, the current event number is 13. Using this example, the following refer to previous events:
Item | Description |
---|---|
!10 |
Event number 10. |
!-2 |
Event number 11 (the current event minus 2). |
!d |
Command word beginning with d (event number 12). |
!?mic? |
Command word containing the string mic (event number
9). |
These forms, without further modification, simply reintroduce
the words of the specified events, each separated by a single blank. As a
special case, !!
refers to the previous command; the command !! alone
on an input line reruns the previous command.