7.5. Command Historybash lets you display or modify previous commands. Commands in the history list can be modified using:
In addition, the command substitutions described in Chapter 8 also work in bash. 7.5.1. Line-Edit ModeLine-edit mode lets you emulate many features of the vi and Emacs editors. The history list is treated like a file. When the editor is invoked, you type editing keystrokes to move to the command line you want to execute. On most terminals, arrow keys work in both Emacs mode and vi command mode. You can also change the line before executing it. See Table 7-23 for some examples of common line-edit commands. When you're ready to issue the command, press Return. The default line-edit mode is Emacs. To enable vi mode, enter: $ set -o vi Note that vi starts in input mode; to type a vi command, press Esc first. The mode you use for editing bash commands is entirely separate from the editor that is invoked for you automatically within many commands (for instance, the editor invoked by mail readers when you ask them to create a new mail message). To change the default editor, set the VISUAL or EDITOR variable to the filename or full pathname of your favorite editor: $ export EDITOR=emacs Table 7-23. Common editing keystrokes
7.5.2. The fc CommandUse fc -l to list history commands, and fc -e to edit them. See the fc built-in command for more information. 7.5.2.1. Examples$ history Display the command history list $ fc -l 20 30 List commands 20 through 30 $ fc -l -5 List the last five commands $ fc -l cat List the last command beginning with cat $ fc -ln 5 > doit Save command 5 to file doit $ fc -e vi 5 20 Edit commands 5 through 20 using vi $ fc -e emacs Edit previous command using Emacs $ !! Reexecute previous command $ !cat Reexecute last cat command $ !cat foo-file Reexecute last command, adding foo-file to the end of the argument list 7.5.3. Command Substitution
7.5.4. Variables in PromptUsing the following variables, you can display information about the current state of the shell or the system in your bash prompt. Set the PS1 variable to a string including the desired variables. For instance, the following command sets PS1 to a string that includes the \w variable to display the current working directory, and the \! variable to display the number of the current command. The next line is the prompt displayed by the change. $ PS1='\w: Command \!$ ' ~/book/linux: Command 504$
Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|