bash: History Interaction

1 
1 9.3 History Expansion
1 =====================
1 
1 The History library provides a history expansion feature that is similar
1 to the history expansion provided by 'csh'.  This section describes the
1 syntax used to manipulate the history information.
1 
1    History expansions introduce words from the history list into the
1 input stream, making it easy to repeat commands, insert the arguments to
1 a previous command into the current input line, or fix errors in
1 previous commands quickly.
1 
1    History expansion is performed immediately after a complete line is
1 read, before the shell breaks it into words.
1 
1    History expansion takes place in two parts.  The first is to
1 determine which line from the history list should be used during
1 substitution.  The second is to select portions of that line for
1 inclusion into the current one.  The line selected from the history is
1 called the "event", and the portions of that line that are acted upon
1 are called "words".  Various "modifiers" are available to manipulate the
1 selected words.  The line is broken into words in the same fashion that
1 Bash does, so that several words surrounded by quotes are considered one
1 word.  History expansions are introduced by the appearance of the
1 history expansion character, which is '!' by default.  Only '\' and '''
1 may be used to escape the history expansion character, but the history
1 expansion character is also treated as quoted if it immediately precedes
1 the closing double quote in a double-quoted string.
1 
11    Several shell options settable with the 'shopt' builtin (⇒Bash
 Builtins) may be used to tailor the behavior of history expansion.  If
1 the 'histverify' shell option is enabled, and Readline is being used,
1 history substitutions are not immediately passed to the shell parser.
1 Instead, the expanded line is reloaded into the Readline editing buffer
1 for further modification.  If Readline is being used, and the
1 'histreedit' shell option is enabled, a failed history expansion will be
1 reloaded into the Readline editing buffer for correction.  The '-p'
1 option to the 'history' builtin command may be used to see what a
1 history expansion will do before using it.  The '-s' option to the
1 'history' builtin may be used to add commands to the end of the history
1 list without actually executing them, so that they are available for
1 subsequent recall.  This is most useful in conjunction with Readline.
1 
1    The shell allows control of the various characters used by the
1 history expansion mechanism with the 'histchars' variable, as explained
1 above (⇒Bash Variables).  The shell uses the history comment
1 character to mark history timestamps when writing the history file.
1 

Menu