home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Unix Power ToolsUnix Power ToolsSearch this book

30.2. History in a Nutshell

Summary Box

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) (Section 35.9) or command substitution ('command') (Section 28.14): the shell replaces what you type (like !$) with something else (in this case, part or all of a previous command line).

 

Section 30.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 -- Section 30.3, Section 30.4, Section 30.5, and Section 30.6.

  • Section 30.8 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 Section 28.5 are examples of csh/tcsh and bash operators such as :r. Many of these can be used to edit history substitutions.)

  • See an easy way to repeat a set of csh/tcsh or bash commands in Section 30.9.

  • Each shell saves its own history. To pass a shell's history to another shell, see Section 30.12 and Section 30.13.

  • You don't have to use an exclamation point (!) for history. Section 30.15 shows how to use some other character.

  • The Korn shell does history in a different way. Section 30.14 introduces part of that: command-line editing in ksh and bash.

One last note: putting the history number in your prompt (Section 4.3) makes it easy to reuse commands that haven't scrolled off your screen.

 

-- JP



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.