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