Fix texinfo-3.12 problems:
[deliverable/binutils-gdb.git] / readline / doc / inc-hist.texinfo
1 @ignore
2 This file documents the user interface to the GNU History library.
3
4 Copyright (C) 1988, 1991, 1996 Free Software Foundation, Inc.
5 Authored by Brian Fox and Chet Ramey.
6
7 Permission is granted to make and distribute verbatim copies of this manual
8 provided the copyright notice and this permission notice are preserved on
9 all copies.
10
11 Permission is granted to process this file through Tex and print the
12 results, provided the printed document carries copying permission notice
13 identical to this one except for the removal of this paragraph (this
14 paragraph not being relevant to the printed manual).
15
16 Permission is granted to copy and distribute modified versions of this
17 manual under the conditions for verbatim copying, provided also that the
18 GNU Copyright statement is available to the distributee, and provided that
19 the entire resulting derived work is distributed under the terms of a
20 permission notice identical to this one.
21
22 Permission is granted to copy and distribute translations of this manual
23 into another language, under the above conditions for modified versions.
24 @end ignore
25
26 @ifclear GDBN
27 @node Using History Interactively
28 @chapter Using History Interactively
29 @end ifclear
30
31 @ifset BashFeatures
32 This chapter describes how to use the GNU History Library interactively,
33 from a user's standpoint. It should be considered a user's guide. For
34 information on using the GNU History Library in other programs,
35 see the GNU Readline Library Manual.
36 @end ifset
37 @ifclear BashFeatures
38 This chapter describes how to use the GNU History Library interactively,
39 from a user's standpoint. It should be considered a user's guide.
40 @c For
41 @c information on using the GNU History Library in your own programs,
42 @c @pxref{Programming with GNU History}.
43 @end ifclear
44
45 @ifset BashFeatures
46 @menu
47 * Bash History Facilities:: How Bash lets you manipulate your command
48 history.
49 * Bash History Builtins:: The Bash builtin commands that manipulate
50 the command history.
51 * History Interaction:: What it feels like using History as a user.
52 @end menu
53 @end ifset
54 @ifclear BashFeatures
55 @menu
56 * History Interaction:: What it feels like using History as a user.
57 @end menu
58 @end ifclear
59
60 @ifset BashFeatures
61 @node Bash History Facilities
62 @section Bash History Facilities
63 @cindex command history
64 @cindex history list
65
66 When the @samp{-o history} option to the @code{set} builtin
67 is enabled (@pxref{The Set Builtin}),
68 the shell provides access to the @var{command history},
69 the list of commands previously typed. The text of the last
70 @code{HISTSIZE}
71 commands (default 500) is saved in a history list. The shell
72 stores each command in the history list prior to parameter and
73 variable expansion
74 but after history expansion is performed, subject to the
75 values of the shell variables
76 @code{HISTIGNORE} and @code{HISTCONTROL}.
77 When the shell starts up, the history is initialized from the
78 file named by the @code{HISTFILE} variable (default @file{~/.bash_history}).
79 @code{HISTFILE} is truncated, if necessary, to contain no more than
80 the number of lines specified by the value of the @code{HISTFILESIZE}
81 variable. When an interactive shell exits, the last
82 @code{HISTSIZE} lines are copied from the history list to @code{HISTFILE}.
83 If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
84 the lines are appended to the history file,
85 otherwise the history file is overwritten.
86 If @code{HISTFILE}
87 is unset, or if the history file is unwritable, the history is
88 not saved. After saving the history, the history file is truncated
89 to contain no more than @code{$HISTFILESIZE}
90 lines. If @code{HISTFILESIZE} is not set, no truncation is performed.
91
92 The builtin command @code{fc} may be used to list or edit and re-execute
93 a portion of the history list.
94 The @code{history} builtin can be used to display or modify the history
95 list and manipulate the history file.
96 When using the command-line editing, search commands
97 are available in each editing mode that provide access to the
98 history list.
99
100 The shell allows control over which commands are saved on the history
101 list. The @code{HISTCONTROL} and @code{HISTIGNORE}
102 variables may be set to cause the shell to save only a subset of the
103 commands entered.
104 The @code{cmdhist}
105 shell option, if enabled, causes the shell to attempt to save each
106 line of a multi-line command in the same history entry, adding
107 semicolons where necessary to preserve syntactic correctness.
108 The @code{lithist}
109 shell option causes the shell to save the command with embedded newlines
110 instead of semicolons.
111 @xref{Bash Builtins}, for a description of @code{shopt}.
112
113 @node Bash History Builtins
114 @section Bash History Builtins
115 @cindex history builtins
116
117 Bash provides two builtin commands that allow you to manipulate the
118 history list and history file.
119
120 @table @code
121
122 @item fc
123 @c btindex fc
124 @example
125 @code{fc [-e @var{ename}] [-nlr] [@var{first}] [@var{last}]}
126 @code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
127 @end example
128
129 Fix Command. In the first form, a range of commands from @var{first} to
130 @var{last} is selected from the history list. Both @var{first} and
131 @var{last} may be specified as a string (to locate the most recent
132 command beginning with that string) or as a number (an index into the
133 history list, where a negative number is used as an offset from the
134 current command number). If @var{last} is not specified it is set to
135 @var{first}. If @var{first} is not specified it is set to the previous
136 command for editing and @minus{}16 for listing. If the @samp{-l} flag is
137 given, the commands are listed on standard output. The @samp{-n} flag
138 suppresses the command numbers when listing. The @samp{-r} flag
139 reverses the order of the listing. Otherwise, the editor given by
140 @var{ename} is invoked on a file containing those commands. If
141 @var{ename} is not given, the value of the following variable expansion
142 is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
143 value of the @code{FCEDIT} variable if set, or the value of the
144 @code{EDITOR} variable if that is set, or @code{vi} if neither is set.
145 When editing is complete, the edited commands are echoed and executed.
146
147 In the second form, @var{command} is re-executed after each instance
148 of @var{pat} in the selected command is replaced by @var{rep}.
149
150 A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so
151 that typing @samp{r cc} runs the last command beginning with @code{cc}
152 and typing @samp{r} re-executes the last command (@pxref{Aliases}).
153
154 @item history
155 @c btindex history
156 @example
157 history [-c] [@var{n}]
158 history [-anrw] [@var{filename}]
159 history -ps @var{arg}
160 @end example
161
162 Display the history list with line numbers. Lines prefixed with
163 with a @samp{*} have been modified. An argument of @var{n} says
164 to list only the last @var{n} lines. Options, if supplied, have
165 the following meanings:
166
167 @table @code
168 @item -w
169 Write out the current history to the history file.
170
171 @item -r
172 Read the current history file and append its contents to
173 the history list.
174
175 @item -a
176 Append the new
177 history lines (history lines entered since the beginning of the
178 current Bash session) to the history file.
179
180 @item -n
181 Append the history lines not already read from the history file
182 to the current history list. These are lines appended to the history
183 file since the beginning of the current Bash session.
184
185 @item -c
186 Clear the history list. This may be combined
187 with the other options to replace the history list completely.
188
189 @item -s
190 The @var{arg}s are added to the end of
191 the history list as a single entry.
192
193 @item -p
194 Perform history substitution on the @var{arg}s and display the result
195 on the standard output, without storing the results in the history list.
196 @end table
197
198 When the @samp{-w}, @samp{-r}, @samp{-a}, or @samp{-n} option is
199 used, if @var{filename}
200 is given, then it is used as the history file. If not, then
201 the value of the @code{HISTFILE} variable is used.
202
203 @end table
204 @end ifset
205
206 @node History Interaction
207 @section History Expansion
208 @cindex history expansion
209
210 The History library provides a history expansion feature that is similar
211 to the history expansion provided by @code{csh}. This section
212 describes the syntax used to manipulate the history information.
213
214 History expansions introduce words from the history list into
215 the input stream, making it easy to repeat commands, insert the
216 arguments to a previous command into the current input line, or
217 fix errors in previous commands quickly.
218
219 History expansion takes place in two parts. The first is to determine
220 which line from the history list should be used during substitution.
221 The second is to select portions of that line for inclusion into the
222 current one. The line selected from the history is called the
223 @dfn{event}, and the portions of that line that are acted upon are
224 called @dfn{words}. Various @dfn{modifiers} are available to manipulate
225 the selected words. The line is broken into words in the same fashion
226 that Bash does, so that several words
227 surrounded by quotes are considered one word.
228 History expansions are introduced by the appearance of the
229 history expansion character, which is @samp{!} by default.
230 @ifset BashFeatures
231 Only @samp{\} and @samp{'} may be used to escape the history expansion
232 character.
233 @end ifset
234
235 @ifset BashFeatures
236 Several shell options settable with the @code{shopt}
237 builtin (@pxref{Bash Builtins}) may be used to tailor
238 the behavior of history expansion. If the
239 @code{histverify} shell option is enabled, and Readline
240 is being used, history substitutions are not immediately passed to
241 the shell parser.
242 Instead, the expanded line is reloaded into the Readline
243 editing buffer for further modification.
244 If Readline is being used, and the @code{histreedit}
245 shell option is enabled, a failed history expansion will be
246 reloaded into the Readline editing buffer for correction.
247 The @samp{-p} option to the @code{history} builtin command
248 may be used to see what a history expansion will do before using it.
249 The @samp{-s} option to the @code{history} builtin may be used to
250 add commands to the end of the history list without actually executing
251 them, so that they are available for subsequent recall.
252 This is most useful in conjunction with Readline.
253
254 The shell allows control of the various characters used by the
255 history expansion mechanism with the @code{histchars} variable.
256 @end ifset
257
258 @menu
259 * Event Designators:: How to specify which history line to use.
260 * Word Designators:: Specifying which words are of interest.
261 * Modifiers:: Modifying the results of substitution.
262 @end menu
263
264 @node Event Designators
265 @subsection Event Designators
266 @cindex event designators
267
268 An event designator is a reference to a command line entry in the
269 history list.
270 @cindex history events
271
272 @table @asis
273
274 @item @code{!}
275 Start a history substitution, except when followed by a space, tab,
276 the end of the line, @samp{=} or @samp{(}.
277
278 @item @code{!@var{n}}
279 Refer to command line @var{n}.
280
281 @item @code{!-@var{n}}
282 Refer to the command @var{n} lines back.
283
284 @item @code{!!}
285 Refer to the previous command. This is a synonym for @samp{!-1}.
286
287 @item @code{!@var{string}}
288 Refer to the most recent command starting with @var{string}.
289
290 @item @code{!?@var{string}[?]}
291 Refer to the most recent command containing @var{string}. The trailing
292 @samp{?} may be omitted if the @var{string} is followed immediately by
293 a newline.
294
295 @item @code{^@var{string1}^@var{string2}^}
296 Quick Substitution. Repeat the last command, replacing @var{string1}
297 with @var{string2}. Equivalent to
298 @code{!!:s/@var{string1}/@var{string2}/}.
299
300 @item @code{!#}
301 The entire command line typed so far.
302
303 @end table
304
305 @node Word Designators
306 @subsection Word Designators
307
308 Word designators are used to select desired words from the event.
309 A @samp{:} separates the event specification from the word designator. It
310 may be omitted if the word designator begins with a @samp{^}, @samp{$},
311 @samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning
312 of the line, with the first word being denoted by 0 (zero). Words are
313 inserted into the current line separated by single spaces.
314
315 @table @code
316
317 @item 0 (zero)
318 The @code{0}th word. For many applications, this is the command word.
319
320 @item @var{n}
321 The @var{n}th word.
322
323 @item ^
324 The first argument; that is, word 1.
325
326 @item $
327 The last argument.
328
329 @item %
330 The word matched by the most recent @samp{?@var{string}?} search.
331
332 @item @var{x}-@var{y}
333 A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}.
334
335 @item *
336 All of the words, except the @code{0}th. This is a synonym for @samp{1-$}.
337 It is not an error to use @samp{*} if there is just one word in the event;
338 the empty string is returned in that case.
339
340 @item @var{x}*
341 Abbreviates @samp{@var{x}-$}
342
343 @item @var{x}-
344 Abbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word.
345
346 @end table
347
348 If a word designator is supplied without an event specification, the
349 previous command is used as the event.
350
351 @node Modifiers
352 @subsection Modifiers
353
354 After the optional word designator, you can add a sequence of one or more
355 of the following modifiers, each preceded by a @samp{:}.
356
357 @table @code
358
359 @item h
360 Remove a trailing pathname component, leaving only the head.
361
362 @item t
363 Remove all leading pathname components, leaving the tail.
364
365 @item r
366 Remove a trailing suffix of the form @samp{.@var{suffix}}, leaving
367 the basename.
368
369 @item e
370 Remove all but the trailing suffix.
371
372 @item p
373 Print the new command but do not execute it.
374
375 @ifset BashFeatures
376 @item q
377 Quote the substituted words, escaping further substitutions.
378
379 @item x
380 Quote the substituted words as with @samp{q},
381 but break into words at spaces, tabs, and newlines.
382 @end ifset
383
384 @item s/@var{old}/@var{new}/
385 Substitute @var{new} for the first occurrence of @var{old} in the
386 event line. Any delimiter may be used in place of @samp{/}.
387 The delimiter may be quoted in @var{old} and @var{new}
388 with a single backslash. If @samp{&} appears in @var{new},
389 it is replaced by @var{old}. A single backslash will quote
390 the @samp{&}. The final delimiter is optional if it is the last
391 character on the input line.
392
393 @item &
394 Repeat the previous substitution.
395
396 @item g
397 Cause changes to be applied over the entire event line. Used in
398 conjunction with @samp{s}, as in @code{gs/@var{old}/@var{new}/},
399 or with @samp{&}.
400
401 @end table
This page took 0.039583 seconds and 4 git commands to generate.