1*a45ae5f8SJohn Marino@ignore 2*a45ae5f8SJohn MarinoThis file documents the user interface to the GNU History library. 3*a45ae5f8SJohn Marino 4*a45ae5f8SJohn MarinoCopyright (C) 1988--2011 Free Software Foundation, Inc. 5*a45ae5f8SJohn MarinoAuthored by Brian Fox and Chet Ramey. 6*a45ae5f8SJohn Marino 7*a45ae5f8SJohn MarinoPermission is granted to make and distribute verbatim copies of this manual 8*a45ae5f8SJohn Marinoprovided the copyright notice and this permission notice are preserved on 9*a45ae5f8SJohn Marinoall copies. 10*a45ae5f8SJohn Marino 11*a45ae5f8SJohn MarinoPermission is granted to process this file through Tex and print the 12*a45ae5f8SJohn Marinoresults, provided the printed document carries copying permission notice 13*a45ae5f8SJohn Marinoidentical to this one except for the removal of this paragraph (this 14*a45ae5f8SJohn Marinoparagraph not being relevant to the printed manual). 15*a45ae5f8SJohn Marino 16*a45ae5f8SJohn MarinoPermission is granted to copy and distribute modified versions of this 17*a45ae5f8SJohn Marinomanual under the conditions for verbatim copying, provided also that the 18*a45ae5f8SJohn MarinoGNU Copyright statement is available to the distributee, and provided that 19*a45ae5f8SJohn Marinothe entire resulting derived work is distributed under the terms of a 20*a45ae5f8SJohn Marinopermission notice identical to this one. 21*a45ae5f8SJohn Marino 22*a45ae5f8SJohn MarinoPermission is granted to copy and distribute translations of this manual 23*a45ae5f8SJohn Marinointo another language, under the above conditions for modified versions. 24*a45ae5f8SJohn Marino@end ignore 25*a45ae5f8SJohn Marino 26*a45ae5f8SJohn Marino@node Using History Interactively 27*a45ae5f8SJohn Marino@chapter Using History Interactively 28*a45ae5f8SJohn Marino 29*a45ae5f8SJohn Marino@c GDB bundling modification: 30*a45ae5f8SJohn Marino@c @ifclear BashFeatures 31*a45ae5f8SJohn Marino@c @defcodeindex bt 32*a45ae5f8SJohn Marino@c @end ifclear 33*a45ae5f8SJohn Marino 34*a45ae5f8SJohn Marino@ifset BashFeatures 35*a45ae5f8SJohn MarinoThis chapter describes how to use the @sc{gnu} History Library 36*a45ae5f8SJohn Marinointeractively, from a user's standpoint. 37*a45ae5f8SJohn MarinoIt should be considered a user's guide. 38*a45ae5f8SJohn MarinoFor information on using the @sc{gnu} History Library in other programs, 39*a45ae5f8SJohn Marinosee the @sc{gnu} Readline Library Manual. 40*a45ae5f8SJohn Marino@end ifset 41*a45ae5f8SJohn Marino@ifclear BashFeatures 42*a45ae5f8SJohn MarinoThis chapter describes how to use the @sc{gnu} History Library interactively, 43*a45ae5f8SJohn Marinofrom a user's standpoint. It should be considered a user's guide. For 44*a45ae5f8SJohn Marinoinformation on using the @sc{gnu} History Library in your own programs, 45*a45ae5f8SJohn Marino@c GDB bundling modification: 46*a45ae5f8SJohn Marino@pxref{Programming with GNU History, , , history, GNU History Library}. 47*a45ae5f8SJohn Marino@end ifclear 48*a45ae5f8SJohn Marino 49*a45ae5f8SJohn Marino@ifset BashFeatures 50*a45ae5f8SJohn Marino@menu 51*a45ae5f8SJohn Marino* Bash History Facilities:: How Bash lets you manipulate your command 52*a45ae5f8SJohn Marino history. 53*a45ae5f8SJohn Marino* Bash History Builtins:: The Bash builtin commands that manipulate 54*a45ae5f8SJohn Marino the command history. 55*a45ae5f8SJohn Marino* History Interaction:: What it feels like using History as a user. 56*a45ae5f8SJohn Marino@end menu 57*a45ae5f8SJohn Marino@end ifset 58*a45ae5f8SJohn Marino@ifclear BashFeatures 59*a45ae5f8SJohn Marino@menu 60*a45ae5f8SJohn Marino* History Interaction:: What it feels like using History as a user. 61*a45ae5f8SJohn Marino@end menu 62*a45ae5f8SJohn Marino@end ifclear 63*a45ae5f8SJohn Marino 64*a45ae5f8SJohn Marino@ifset BashFeatures 65*a45ae5f8SJohn Marino@node Bash History Facilities 66*a45ae5f8SJohn Marino@section Bash History Facilities 67*a45ae5f8SJohn Marino@cindex command history 68*a45ae5f8SJohn Marino@cindex history list 69*a45ae5f8SJohn Marino 70*a45ae5f8SJohn MarinoWhen the @option{-o history} option to the @code{set} builtin 71*a45ae5f8SJohn Marinois enabled (@pxref{The Set Builtin}), 72*a45ae5f8SJohn Marinothe shell provides access to the @dfn{command history}, 73*a45ae5f8SJohn Marinothe list of commands previously typed. 74*a45ae5f8SJohn MarinoThe value of the @env{HISTSIZE} shell variable is used as the 75*a45ae5f8SJohn Marinonumber of commands to save in a history list. 76*a45ae5f8SJohn MarinoThe text of the last @env{$HISTSIZE} 77*a45ae5f8SJohn Marinocommands (default 500) is saved. 78*a45ae5f8SJohn MarinoThe shell stores each command in the history list prior to 79*a45ae5f8SJohn Marinoparameter and variable expansion 80*a45ae5f8SJohn Marinobut after history expansion is performed, subject to the 81*a45ae5f8SJohn Marinovalues of the shell variables 82*a45ae5f8SJohn Marino@env{HISTIGNORE} and @env{HISTCONTROL}. 83*a45ae5f8SJohn Marino 84*a45ae5f8SJohn MarinoWhen the shell starts up, the history is initialized from the 85*a45ae5f8SJohn Marinofile named by the @env{HISTFILE} variable (default @file{~/.bash_history}). 86*a45ae5f8SJohn MarinoThe file named by the value of @env{HISTFILE} is truncated, if 87*a45ae5f8SJohn Marinonecessary, to contain no more than the number of lines specified by 88*a45ae5f8SJohn Marinothe value of the @env{HISTFILESIZE} variable. 89*a45ae5f8SJohn MarinoWhen an interactive shell exits, the last 90*a45ae5f8SJohn Marino@env{$HISTSIZE} lines are copied from the history list to the file 91*a45ae5f8SJohn Marinonamed by @env{$HISTFILE}. 92*a45ae5f8SJohn MarinoIf the @code{histappend} shell option is set (@pxref{Bash Builtins}), 93*a45ae5f8SJohn Marinothe lines are appended to the history file, 94*a45ae5f8SJohn Marinootherwise the history file is overwritten. 95*a45ae5f8SJohn MarinoIf @env{HISTFILE} 96*a45ae5f8SJohn Marinois unset, or if the history file is unwritable, the history is 97*a45ae5f8SJohn Marinonot saved. After saving the history, the history file is truncated 98*a45ae5f8SJohn Marinoto contain no more than @env{$HISTFILESIZE} 99*a45ae5f8SJohn Marinolines. If @env{HISTFILESIZE} is not set, no truncation is performed. 100*a45ae5f8SJohn Marino 101*a45ae5f8SJohn MarinoIf the @env{HISTTIMEFORMAT} is set, the time stamp information 102*a45ae5f8SJohn Marinoassociated with each history entry is written to the history file, 103*a45ae5f8SJohn Marinomarked with the history comment character. 104*a45ae5f8SJohn MarinoWhen the history file is read, lines beginning with the history 105*a45ae5f8SJohn Marinocomment character followed immediately by a digit are interpreted 106*a45ae5f8SJohn Marinoas timestamps for the previous history line. 107*a45ae5f8SJohn Marino 108*a45ae5f8SJohn MarinoThe builtin command @code{fc} may be used to list or edit and re-execute 109*a45ae5f8SJohn Marinoa portion of the history list. 110*a45ae5f8SJohn MarinoThe @code{history} builtin may be used to display or modify the history 111*a45ae5f8SJohn Marinolist and manipulate the history file. 112*a45ae5f8SJohn MarinoWhen using command-line editing, search commands 113*a45ae5f8SJohn Marinoare available in each editing mode that provide access to the 114*a45ae5f8SJohn Marinohistory list (@pxref{Commands For History}). 115*a45ae5f8SJohn Marino 116*a45ae5f8SJohn MarinoThe shell allows control over which commands are saved on the history 117*a45ae5f8SJohn Marinolist. The @env{HISTCONTROL} and @env{HISTIGNORE} 118*a45ae5f8SJohn Marinovariables may be set to cause the shell to save only a subset of the 119*a45ae5f8SJohn Marinocommands entered. 120*a45ae5f8SJohn MarinoThe @code{cmdhist} 121*a45ae5f8SJohn Marinoshell option, if enabled, causes the shell to attempt to save each 122*a45ae5f8SJohn Marinoline of a multi-line command in the same history entry, adding 123*a45ae5f8SJohn Marinosemicolons where necessary to preserve syntactic correctness. 124*a45ae5f8SJohn MarinoThe @code{lithist} 125*a45ae5f8SJohn Marinoshell option causes the shell to save the command with embedded newlines 126*a45ae5f8SJohn Marinoinstead of semicolons. 127*a45ae5f8SJohn MarinoThe @code{shopt} builtin is used to set these options. 128*a45ae5f8SJohn Marino@xref{Bash Builtins}, for a description of @code{shopt}. 129*a45ae5f8SJohn Marino 130*a45ae5f8SJohn Marino@node Bash History Builtins 131*a45ae5f8SJohn Marino@section Bash History Builtins 132*a45ae5f8SJohn Marino@cindex history builtins 133*a45ae5f8SJohn Marino 134*a45ae5f8SJohn MarinoBash provides two builtin commands which manipulate the 135*a45ae5f8SJohn Marinohistory list and history file. 136*a45ae5f8SJohn Marino 137*a45ae5f8SJohn Marino@table @code 138*a45ae5f8SJohn Marino 139*a45ae5f8SJohn Marino@item fc 140*a45ae5f8SJohn Marino@btindex fc 141*a45ae5f8SJohn Marino@example 142*a45ae5f8SJohn Marino@code{fc [-e @var{ename}] [-lnr] [@var{first}] [@var{last}]} 143*a45ae5f8SJohn Marino@code{fc -s [@var{pat}=@var{rep}] [@var{command}]} 144*a45ae5f8SJohn Marino@end example 145*a45ae5f8SJohn Marino 146*a45ae5f8SJohn MarinoFix Command. In the first form, a range of commands from @var{first} to 147*a45ae5f8SJohn Marino@var{last} is selected from the history list. Both @var{first} and 148*a45ae5f8SJohn Marino@var{last} may be specified as a string (to locate the most recent 149*a45ae5f8SJohn Marinocommand beginning with that string) or as a number (an index into the 150*a45ae5f8SJohn Marinohistory list, where a negative number is used as an offset from the 151*a45ae5f8SJohn Marinocurrent command number). If @var{last} is not specified it is set to 152*a45ae5f8SJohn Marino@var{first}. If @var{first} is not specified it is set to the previous 153*a45ae5f8SJohn Marinocommand for editing and @minus{}16 for listing. If the @option{-l} flag is 154*a45ae5f8SJohn Marinogiven, the commands are listed on standard output. The @option{-n} flag 155*a45ae5f8SJohn Marinosuppresses the command numbers when listing. The @option{-r} flag 156*a45ae5f8SJohn Marinoreverses the order of the listing. Otherwise, the editor given by 157*a45ae5f8SJohn Marino@var{ename} is invoked on a file containing those commands. If 158*a45ae5f8SJohn Marino@var{ename} is not given, the value of the following variable expansion 159*a45ae5f8SJohn Marinois used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the 160*a45ae5f8SJohn Marinovalue of the @env{FCEDIT} variable if set, or the value of the 161*a45ae5f8SJohn Marino@env{EDITOR} variable if that is set, or @code{vi} if neither is set. 162*a45ae5f8SJohn MarinoWhen editing is complete, the edited commands are echoed and executed. 163*a45ae5f8SJohn Marino 164*a45ae5f8SJohn MarinoIn the second form, @var{command} is re-executed after each instance 165*a45ae5f8SJohn Marinoof @var{pat} in the selected command is replaced by @var{rep}. 166*a45ae5f8SJohn Marino 167*a45ae5f8SJohn MarinoA useful alias to use with the @code{fc} command is @code{r='fc -s'}, so 168*a45ae5f8SJohn Marinothat typing @samp{r cc} runs the last command beginning with @code{cc} 169*a45ae5f8SJohn Marinoand typing @samp{r} re-executes the last command (@pxref{Aliases}). 170*a45ae5f8SJohn Marino 171*a45ae5f8SJohn Marino@item history 172*a45ae5f8SJohn Marino@btindex history 173*a45ae5f8SJohn Marino@example 174*a45ae5f8SJohn Marinohistory [@var{n}] 175*a45ae5f8SJohn Marinohistory -c 176*a45ae5f8SJohn Marinohistory -d @var{offset} 177*a45ae5f8SJohn Marinohistory [-anrw] [@var{filename}] 178*a45ae5f8SJohn Marinohistory -ps @var{arg} 179*a45ae5f8SJohn Marino@end example 180*a45ae5f8SJohn Marino 181*a45ae5f8SJohn MarinoWith no options, display the history list with line numbers. 182*a45ae5f8SJohn MarinoLines prefixed with a @samp{*} have been modified. 183*a45ae5f8SJohn MarinoAn argument of @var{n} lists only the last @var{n} lines. 184*a45ae5f8SJohn MarinoIf the shell variable @env{HISTTIMEFORMAT} is set and not null, 185*a45ae5f8SJohn Marinoit is used as a format string for @var{strftime} to display 186*a45ae5f8SJohn Marinothe time stamp associated with each displayed history entry. 187*a45ae5f8SJohn MarinoNo intervening blank is printed between the formatted time stamp 188*a45ae5f8SJohn Marinoand the history line. 189*a45ae5f8SJohn Marino 190*a45ae5f8SJohn MarinoOptions, if supplied, have the following meanings: 191*a45ae5f8SJohn Marino 192*a45ae5f8SJohn Marino@table @code 193*a45ae5f8SJohn Marino@item -c 194*a45ae5f8SJohn MarinoClear the history list. This may be combined 195*a45ae5f8SJohn Marinowith the other options to replace the history list completely. 196*a45ae5f8SJohn Marino 197*a45ae5f8SJohn Marino@item -d @var{offset} 198*a45ae5f8SJohn MarinoDelete the history entry at position @var{offset}. 199*a45ae5f8SJohn Marino@var{offset} should be specified as it appears when the history is 200*a45ae5f8SJohn Marinodisplayed. 201*a45ae5f8SJohn Marino 202*a45ae5f8SJohn Marino@item -a 203*a45ae5f8SJohn MarinoAppend the new 204*a45ae5f8SJohn Marinohistory lines (history lines entered since the beginning of the 205*a45ae5f8SJohn Marinocurrent Bash session) to the history file. 206*a45ae5f8SJohn Marino 207*a45ae5f8SJohn Marino@item -n 208*a45ae5f8SJohn MarinoAppend the history lines not already read from the history file 209*a45ae5f8SJohn Marinoto the current history list. These are lines appended to the history 210*a45ae5f8SJohn Marinofile since the beginning of the current Bash session. 211*a45ae5f8SJohn Marino 212*a45ae5f8SJohn Marino@item -r 213*a45ae5f8SJohn MarinoRead the current history file and append its contents to 214*a45ae5f8SJohn Marinothe history list. 215*a45ae5f8SJohn Marino 216*a45ae5f8SJohn Marino@item -w 217*a45ae5f8SJohn MarinoWrite out the current history to the history file. 218*a45ae5f8SJohn Marino 219*a45ae5f8SJohn Marino@item -p 220*a45ae5f8SJohn MarinoPerform history substitution on the @var{arg}s and display the result 221*a45ae5f8SJohn Marinoon the standard output, without storing the results in the history list. 222*a45ae5f8SJohn Marino 223*a45ae5f8SJohn Marino@item -s 224*a45ae5f8SJohn MarinoThe @var{arg}s are added to the end of 225*a45ae5f8SJohn Marinothe history list as a single entry. 226*a45ae5f8SJohn Marino 227*a45ae5f8SJohn Marino@end table 228*a45ae5f8SJohn Marino 229*a45ae5f8SJohn MarinoWhen any of the @option{-w}, @option{-r}, @option{-a}, or @option{-n} options is 230*a45ae5f8SJohn Marinoused, if @var{filename} 231*a45ae5f8SJohn Marinois given, then it is used as the history file. If not, then 232*a45ae5f8SJohn Marinothe value of the @env{HISTFILE} variable is used. 233*a45ae5f8SJohn Marino 234*a45ae5f8SJohn Marino@end table 235*a45ae5f8SJohn Marino@end ifset 236*a45ae5f8SJohn Marino 237*a45ae5f8SJohn Marino@node History Interaction 238*a45ae5f8SJohn Marino@section History Expansion 239*a45ae5f8SJohn Marino@cindex history expansion 240*a45ae5f8SJohn Marino 241*a45ae5f8SJohn MarinoThe History library provides a history expansion feature that is similar 242*a45ae5f8SJohn Marinoto the history expansion provided by @code{csh}. This section 243*a45ae5f8SJohn Marinodescribes the syntax used to manipulate the history information. 244*a45ae5f8SJohn Marino 245*a45ae5f8SJohn MarinoHistory expansions introduce words from the history list into 246*a45ae5f8SJohn Marinothe input stream, making it easy to repeat commands, insert the 247*a45ae5f8SJohn Marinoarguments to a previous command into the current input line, or 248*a45ae5f8SJohn Marinofix errors in previous commands quickly. 249*a45ae5f8SJohn Marino 250*a45ae5f8SJohn MarinoHistory expansion takes place in two parts. The first is to determine 251*a45ae5f8SJohn Marinowhich line from the history list should be used during substitution. 252*a45ae5f8SJohn MarinoThe second is to select portions of that line for inclusion into the 253*a45ae5f8SJohn Marinocurrent one. The line selected from the history is called the 254*a45ae5f8SJohn Marino@dfn{event}, and the portions of that line that are acted upon are 255*a45ae5f8SJohn Marinocalled @dfn{words}. Various @dfn{modifiers} are available to manipulate 256*a45ae5f8SJohn Marinothe selected words. The line is broken into words in the same fashion 257*a45ae5f8SJohn Marinothat Bash does, so that several words 258*a45ae5f8SJohn Marinosurrounded by quotes are considered one word. 259*a45ae5f8SJohn MarinoHistory expansions are introduced by the appearance of the 260*a45ae5f8SJohn Marinohistory expansion character, which is @samp{!} by default. 261*a45ae5f8SJohn Marino@ifset BashFeatures 262*a45ae5f8SJohn MarinoOnly @samp{\} and @samp{'} may be used to escape the history expansion 263*a45ae5f8SJohn Marinocharacter. 264*a45ae5f8SJohn Marino@end ifset 265*a45ae5f8SJohn Marino 266*a45ae5f8SJohn Marino@ifset BashFeatures 267*a45ae5f8SJohn MarinoSeveral shell options settable with the @code{shopt} 268*a45ae5f8SJohn Marinobuiltin (@pxref{Bash Builtins}) may be used to tailor 269*a45ae5f8SJohn Marinothe behavior of history expansion. If the 270*a45ae5f8SJohn Marino@code{histverify} shell option is enabled, and Readline 271*a45ae5f8SJohn Marinois being used, history substitutions are not immediately passed to 272*a45ae5f8SJohn Marinothe shell parser. 273*a45ae5f8SJohn MarinoInstead, the expanded line is reloaded into the Readline 274*a45ae5f8SJohn Marinoediting buffer for further modification. 275*a45ae5f8SJohn MarinoIf Readline is being used, and the @code{histreedit} 276*a45ae5f8SJohn Marinoshell option is enabled, a failed history expansion will be 277*a45ae5f8SJohn Marinoreloaded into the Readline editing buffer for correction. 278*a45ae5f8SJohn MarinoThe @option{-p} option to the @code{history} builtin command 279*a45ae5f8SJohn Marinomay be used to see what a history expansion will do before using it. 280*a45ae5f8SJohn MarinoThe @option{-s} option to the @code{history} builtin may be used to 281*a45ae5f8SJohn Marinoadd commands to the end of the history list without actually executing 282*a45ae5f8SJohn Marinothem, so that they are available for subsequent recall. 283*a45ae5f8SJohn MarinoThis is most useful in conjunction with Readline. 284*a45ae5f8SJohn Marino 285*a45ae5f8SJohn MarinoThe shell allows control of the various characters used by the 286*a45ae5f8SJohn Marinohistory expansion mechanism with the @code{histchars} variable, 287*a45ae5f8SJohn Marinoas explained above (@pxref{Bash Variables}). The shell uses 288*a45ae5f8SJohn Marinothe history comment character to mark history timestamps when 289*a45ae5f8SJohn Marinowriting the history file. 290*a45ae5f8SJohn Marino@end ifset 291*a45ae5f8SJohn Marino 292*a45ae5f8SJohn Marino@menu 293*a45ae5f8SJohn Marino* Event Designators:: How to specify which history line to use. 294*a45ae5f8SJohn Marino* Word Designators:: Specifying which words are of interest. 295*a45ae5f8SJohn Marino* Modifiers:: Modifying the results of substitution. 296*a45ae5f8SJohn Marino@end menu 297*a45ae5f8SJohn Marino 298*a45ae5f8SJohn Marino@node Event Designators 299*a45ae5f8SJohn Marino@subsection Event Designators 300*a45ae5f8SJohn Marino@cindex event designators 301*a45ae5f8SJohn Marino 302*a45ae5f8SJohn MarinoAn event designator is a reference to a command line entry in the 303*a45ae5f8SJohn Marinohistory list. 304*a45ae5f8SJohn MarinoUnless the reference is absolute, events are relative to the current 305*a45ae5f8SJohn Marinoposition in the history list. 306*a45ae5f8SJohn Marino@cindex history events 307*a45ae5f8SJohn Marino 308*a45ae5f8SJohn Marino@table @asis 309*a45ae5f8SJohn Marino 310*a45ae5f8SJohn Marino@item @code{!} 311*a45ae5f8SJohn Marino@ifset BashFeatures 312*a45ae5f8SJohn MarinoStart a history substitution, except when followed by a space, tab, 313*a45ae5f8SJohn Marinothe end of the line, @samp{=} or @samp{(} (when the 314*a45ae5f8SJohn Marino@code{extglob} shell option is enabled using the @code{shopt} builtin). 315*a45ae5f8SJohn Marino@end ifset 316*a45ae5f8SJohn Marino@ifclear BashFeatures 317*a45ae5f8SJohn MarinoStart a history substitution, except when followed by a space, tab, 318*a45ae5f8SJohn Marinothe end of the line, or @samp{=}. 319*a45ae5f8SJohn Marino@end ifclear 320*a45ae5f8SJohn Marino 321*a45ae5f8SJohn Marino@item @code{!@var{n}} 322*a45ae5f8SJohn MarinoRefer to command line @var{n}. 323*a45ae5f8SJohn Marino 324*a45ae5f8SJohn Marino@item @code{!-@var{n}} 325*a45ae5f8SJohn MarinoRefer to the command @var{n} lines back. 326*a45ae5f8SJohn Marino 327*a45ae5f8SJohn Marino@item @code{!!} 328*a45ae5f8SJohn MarinoRefer to the previous command. This is a synonym for @samp{!-1}. 329*a45ae5f8SJohn Marino 330*a45ae5f8SJohn Marino@item @code{!@var{string}} 331*a45ae5f8SJohn MarinoRefer to the most recent command 332*a45ae5f8SJohn Marinopreceding the current position in the history list 333*a45ae5f8SJohn Marinostarting with @var{string}. 334*a45ae5f8SJohn Marino 335*a45ae5f8SJohn Marino@item @code{!?@var{string}[?]} 336*a45ae5f8SJohn MarinoRefer to the most recent command 337*a45ae5f8SJohn Marinopreceding the current position in the history list 338*a45ae5f8SJohn Marinocontaining @var{string}. 339*a45ae5f8SJohn MarinoThe trailing 340*a45ae5f8SJohn Marino@samp{?} may be omitted if the @var{string} is followed immediately by 341*a45ae5f8SJohn Marinoa newline. 342*a45ae5f8SJohn Marino 343*a45ae5f8SJohn Marino@item @code{^@var{string1}^@var{string2}^} 344*a45ae5f8SJohn MarinoQuick Substitution. Repeat the last command, replacing @var{string1} 345*a45ae5f8SJohn Marinowith @var{string2}. Equivalent to 346*a45ae5f8SJohn Marino@code{!!:s/@var{string1}/@var{string2}/}. 347*a45ae5f8SJohn Marino 348*a45ae5f8SJohn Marino@item @code{!#} 349*a45ae5f8SJohn MarinoThe entire command line typed so far. 350*a45ae5f8SJohn Marino 351*a45ae5f8SJohn Marino@end table 352*a45ae5f8SJohn Marino 353*a45ae5f8SJohn Marino@node Word Designators 354*a45ae5f8SJohn Marino@subsection Word Designators 355*a45ae5f8SJohn Marino 356*a45ae5f8SJohn MarinoWord designators are used to select desired words from the event. 357*a45ae5f8SJohn MarinoA @samp{:} separates the event specification from the word designator. It 358*a45ae5f8SJohn Marinomay be omitted if the word designator begins with a @samp{^}, @samp{$}, 359*a45ae5f8SJohn Marino@samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning 360*a45ae5f8SJohn Marinoof the line, with the first word being denoted by 0 (zero). Words are 361*a45ae5f8SJohn Marinoinserted into the current line separated by single spaces. 362*a45ae5f8SJohn Marino 363*a45ae5f8SJohn Marino@need 0.75 364*a45ae5f8SJohn MarinoFor example, 365*a45ae5f8SJohn Marino 366*a45ae5f8SJohn Marino@table @code 367*a45ae5f8SJohn Marino@item !! 368*a45ae5f8SJohn Marinodesignates the preceding command. When you type this, the preceding 369*a45ae5f8SJohn Marinocommand is repeated in toto. 370*a45ae5f8SJohn Marino 371*a45ae5f8SJohn Marino@item !!:$ 372*a45ae5f8SJohn Marinodesignates the last argument of the preceding command. This may be 373*a45ae5f8SJohn Marinoshortened to @code{!$}. 374*a45ae5f8SJohn Marino 375*a45ae5f8SJohn Marino@item !fi:2 376*a45ae5f8SJohn Marinodesignates the second argument of the most recent command starting with 377*a45ae5f8SJohn Marinothe letters @code{fi}. 378*a45ae5f8SJohn Marino@end table 379*a45ae5f8SJohn Marino 380*a45ae5f8SJohn Marino@need 0.75 381*a45ae5f8SJohn MarinoHere are the word designators: 382*a45ae5f8SJohn Marino 383*a45ae5f8SJohn Marino@table @code 384*a45ae5f8SJohn Marino 385*a45ae5f8SJohn Marino@item 0 (zero) 386*a45ae5f8SJohn MarinoThe @code{0}th word. For many applications, this is the command word. 387*a45ae5f8SJohn Marino 388*a45ae5f8SJohn Marino@item @var{n} 389*a45ae5f8SJohn MarinoThe @var{n}th word. 390*a45ae5f8SJohn Marino 391*a45ae5f8SJohn Marino@item ^ 392*a45ae5f8SJohn MarinoThe first argument; that is, word 1. 393*a45ae5f8SJohn Marino 394*a45ae5f8SJohn Marino@item $ 395*a45ae5f8SJohn MarinoThe last argument. 396*a45ae5f8SJohn Marino 397*a45ae5f8SJohn Marino@item % 398*a45ae5f8SJohn MarinoThe word matched by the most recent @samp{?@var{string}?} search. 399*a45ae5f8SJohn Marino 400*a45ae5f8SJohn Marino@item @var{x}-@var{y} 401*a45ae5f8SJohn MarinoA range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}. 402*a45ae5f8SJohn Marino 403*a45ae5f8SJohn Marino@item * 404*a45ae5f8SJohn MarinoAll of the words, except the @code{0}th. This is a synonym for @samp{1-$}. 405*a45ae5f8SJohn MarinoIt is not an error to use @samp{*} if there is just one word in the event; 406*a45ae5f8SJohn Marinothe empty string is returned in that case. 407*a45ae5f8SJohn Marino 408*a45ae5f8SJohn Marino@item @var{x}* 409*a45ae5f8SJohn MarinoAbbreviates @samp{@var{x}-$} 410*a45ae5f8SJohn Marino 411*a45ae5f8SJohn Marino@item @var{x}- 412*a45ae5f8SJohn MarinoAbbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word. 413*a45ae5f8SJohn Marino 414*a45ae5f8SJohn Marino@end table 415*a45ae5f8SJohn Marino 416*a45ae5f8SJohn MarinoIf a word designator is supplied without an event specification, the 417*a45ae5f8SJohn Marinoprevious command is used as the event. 418*a45ae5f8SJohn Marino 419*a45ae5f8SJohn Marino@node Modifiers 420*a45ae5f8SJohn Marino@subsection Modifiers 421*a45ae5f8SJohn Marino 422*a45ae5f8SJohn MarinoAfter the optional word designator, you can add a sequence of one or more 423*a45ae5f8SJohn Marinoof the following modifiers, each preceded by a @samp{:}. 424*a45ae5f8SJohn Marino 425*a45ae5f8SJohn Marino@table @code 426*a45ae5f8SJohn Marino 427*a45ae5f8SJohn Marino@item h 428*a45ae5f8SJohn MarinoRemove a trailing pathname component, leaving only the head. 429*a45ae5f8SJohn Marino 430*a45ae5f8SJohn Marino@item t 431*a45ae5f8SJohn MarinoRemove all leading pathname components, leaving the tail. 432*a45ae5f8SJohn Marino 433*a45ae5f8SJohn Marino@item r 434*a45ae5f8SJohn MarinoRemove a trailing suffix of the form @samp{.@var{suffix}}, leaving 435*a45ae5f8SJohn Marinothe basename. 436*a45ae5f8SJohn Marino 437*a45ae5f8SJohn Marino@item e 438*a45ae5f8SJohn MarinoRemove all but the trailing suffix. 439*a45ae5f8SJohn Marino 440*a45ae5f8SJohn Marino@item p 441*a45ae5f8SJohn MarinoPrint the new command but do not execute it. 442*a45ae5f8SJohn Marino 443*a45ae5f8SJohn Marino@ifset BashFeatures 444*a45ae5f8SJohn Marino@item q 445*a45ae5f8SJohn MarinoQuote the substituted words, escaping further substitutions. 446*a45ae5f8SJohn Marino 447*a45ae5f8SJohn Marino@item x 448*a45ae5f8SJohn MarinoQuote the substituted words as with @samp{q}, 449*a45ae5f8SJohn Marinobut break into words at spaces, tabs, and newlines. 450*a45ae5f8SJohn Marino@end ifset 451*a45ae5f8SJohn Marino 452*a45ae5f8SJohn Marino@item s/@var{old}/@var{new}/ 453*a45ae5f8SJohn MarinoSubstitute @var{new} for the first occurrence of @var{old} in the 454*a45ae5f8SJohn Marinoevent line. Any delimiter may be used in place of @samp{/}. 455*a45ae5f8SJohn MarinoThe delimiter may be quoted in @var{old} and @var{new} 456*a45ae5f8SJohn Marinowith a single backslash. If @samp{&} appears in @var{new}, 457*a45ae5f8SJohn Marinoit is replaced by @var{old}. A single backslash will quote 458*a45ae5f8SJohn Marinothe @samp{&}. The final delimiter is optional if it is the last 459*a45ae5f8SJohn Marinocharacter on the input line. 460*a45ae5f8SJohn Marino 461*a45ae5f8SJohn Marino@item & 462*a45ae5f8SJohn MarinoRepeat the previous substitution. 463*a45ae5f8SJohn Marino 464*a45ae5f8SJohn Marino@item g 465*a45ae5f8SJohn Marino@itemx a 466*a45ae5f8SJohn MarinoCause changes to be applied over the entire event line. Used in 467*a45ae5f8SJohn Marinoconjunction with @samp{s}, as in @code{gs/@var{old}/@var{new}/}, 468*a45ae5f8SJohn Marinoor with @samp{&}. 469*a45ae5f8SJohn Marino 470*a45ae5f8SJohn Marino@item G 471*a45ae5f8SJohn MarinoApply the following @samp{s} modifier once to each word in the event. 472*a45ae5f8SJohn Marino 473*a45ae5f8SJohn Marino@end table 474