start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 11.6 Using !$ for Safety with Wildcards Chapter 11
The Lessons of History
Next: 11.8 Repeating a Cycle of Commands
 

11.7 History Substitutions

[Although most of the examples here use echo to demonstrate clearly just what is going on, you'll normally use history with other UNIX commands. -JP]

The exclamation point (!) is the C shell's default (11.15) history substitution character. (It's used in bash, too.) This allows you to recall previously entered commands and re-execute them without retyping. The number of commands saved is up to you. To set this number, put a line in your shell setup file (2.2) like this:

set history=40   ...C shell

HISTSIZE=40   ...bash, ksh

This means that the C shell will save the last 40 commands. To list out these 40 commands use:

% history

To see just the last ten commands in csh or bash, use history 10. In the C shell, you can also list out the commands in reverse with history -r.

To use the ! in a command line, you have several choices. Some of the following examples are more of a headache than they may be worth. But they are used mostly to select arguments from the command line in aliases (10.3). Here they are:

- DR


Previous: 11.6 Using !$ for Safety with Wildcards UNIX Power ToolsNext: 11.8 Repeating a Cycle of Commands
11.6 Using !$ for Safety with Wildcards Book Index11.8 Repeating a Cycle of Commands

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System