Using Commands from Your History
Use the !
character to begin a reference to an event in the history list. The shell sees the !
, determines from the characters following it which event you want to use, performs a history substitution on the command line, and then executes the command. To keep you informed, the shell echoes the resulting command before executing it. Here's a simple example using !!
, the "repeat previous command" operator:
%date
Type a command Tue Mar 7 13:01:25 CST 1995 Output from the command %!!
Repeat the command date Shell shows the resulting command Tue Mar 7 13:01:32 CST 1995 Output from the command
The full syntax for a history reference looks like this:
!event
:words
:modifiers
That's a mouthful, but most of it is optional. In practice, history references tend to be simple, such as !!
to repeat the previous command or !$
to repeat its last argument. Here's what the parts of a history reference mean:
| The event (command) you want to refer to. |
| Which words to select from the command. |
| How to modify the selected event or words. |
The following sections describe the parts of history references in more detail.
Get Using csh & tcsh now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.