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