]> git.ipfire.org Git - thirdparty/bash.git/blob - lib/readline/doc/hsuser.texinfo
Imported from ../bash-2.0.tar.gz.
[thirdparty/bash.git] / lib / readline / doc / hsuser.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 @node Using History Interactively
27 @chapter Using History Interactively
28
29 @ifset BashFeatures
30 This chapter describes how to use the GNU History Library interactively,
31 from a user's standpoint. It should be considered a user's guide. For
32 information on using the GNU History Library in your own programs,
33 see the GNU Readline Library Manual.
34 @end ifset
35 @ifclear BashFeatures
36 This chapter describes how to use the GNU History Library interactively,
37 from a user's standpoint. It should be considered a user's guide. For
38 information on using the GNU History Library in your own programs,
39 @pxref{Programming with GNU History}.
40 @end ifclear
41
42 @ifset BashFeatures
43 @menu
44 * Bash History Facilities:: How Bash lets you manipulate your command
45 history.
46 * History Interaction:: What it feels like using History as a user.
47 @end menu
48 @end ifset
49 @ifclear BashFeatures
50 @menu
51 * History Interaction:: What it feels like using History as a user.
52 @end menu
53 @end ifclear
54
55 @ifset BashFeatures
56 @node Bash History Facilities
57 @section Bash History Facilities
58 @cindex command history
59 @cindex history list
60
61 When the @samp{-o history} option to the @code{set} builtin
62 is enabled (@pxref{The Set Builtin}),
63 the shell provides access to the @var{command history},
64 the list of commands previously typed. The text of the last
65 @code{HISTSIZE}
66 commands (default 500) is saved in a history list. The shell
67 stores each command in the history list prior to parameter and
68 variable expansion
69 but after history expansion is performed, subject to the
70 values of the shell variables
71 @code{HISTIGNORE} and @code{HISTCONTROL}.
72 When the shell starts up, the history is initialized from the
73 file named by the @code{HISTFILE} variable (default @file{~/.bash_history}).
74 @code{HISTFILE} is truncated, if necessary, to contain no more than
75 the number of lines specified by the value of the @code{HISTFILESIZE}
76 variable. When an interactive shell exits, the last
77 @code{HISTSIZE} lines are copied from the history list to @code{HISTFILE}.
78 If the @code{histappend} shell option is set (@pxref{Bash Builtins}),
79 the lines are appended to the history file,
80 otherwise the history file is overwritten.
81 If @code{HISTFILE}
82 is unset, or if the history file is unwritable, the history is
83 not saved. After saving the history, the history file is truncated
84 to contain no more than @code{$HISTFILESIZE}
85 lines. If @code{HISTFILESIZE} is not set, no truncation is performed.
86
87 The builtin command @code{fc} (@pxref{Korn Shell Builtins})
88 may be used to list or edit and re-execute a portion of
89 the history list. The @code{history} builtin (@pxref{C Shell Builtins})
90 can be used to display or modify the history list and
91 manipulate the history file.
92 When using the command-line editing, search commands
93 are available in each editing mode that provide access to the
94 history list.
95
96 The shell allows control over which commands are saved on the history
97 list. The @code{HISTCONTROL} and @code{HISTIGNORE}
98 variables may be set to cause the shell to save only a subset of the
99 commands entered.
100 The @code{cmdhist}
101 shell option, if enabled, causes the shell to attempt to save each
102 line of a multi-line command in the same history entry, adding
103 semicolons where necessary to preserve syntactic correctness.
104 The @code{lithist}
105 shell option causes the shell to save the command with embedded newlines
106 instead of semicolons.
107 @xref{Bash Builtins} for a description of @code{shopt}.
108 @end ifset
109
110 @node History Interaction
111 @section Interactive History Expansion
112 @cindex history expansion
113
114 The History library provides a history expansion feature that is similar
115 to the history expansion provided by @code{csh}. This section
116 describes the syntax used to manipulate the history information.
117
118 History expansions introduce words from the history list into
119 the input stream, making it easy to repeat commands, insert the
120 arguments to a previous command into the current input line, or
121 fix errors in previous commands quickly.
122
123 History expansion takes place in two parts. The first is to determine
124 which line from the previous history should be used during substitution.
125 The second is to select portions of that line for inclusion into the
126 current one. The line selected from the previous history is called the
127 @dfn{event}, and the portions of that line that are acted upon are
128 called @dfn{words}. Various @dfn{modifiers} are available to manipulate
129 the selected words. The line is broken into words in the same fashion
130 that Bash does, so that several English (or Unix) words
131 surrounded by quotes are considered as one word.
132 History expansions are introduced by the appearance of the
133 history expansion character, which is @samp{!} by default.
134 @ifset BashFeatures
135 Only @samp{\} and @samp{'} may be used to escape the history expansion
136 character.
137 @end ifset
138
139 @ifset BashFeatures
140 Several shell options settable with the @code{shopt}
141 builtin (@pxref{Bash Builtins}) may be used to tailor
142 the behavior of history expansion. If the
143 @code{histverify} shell option is enabled, and Readline
144 is being used, history substitutions are not immediately passed to
145 the shell parser.
146 Instead, the expanded line is reloaded into the Readline
147 editing buffer for further modification.
148 If Readline is being used, and the @code{histreedit}
149 shell option is enabled, a failed history expansion will be
150 reloaded into the Readline editing buffer for correction.
151 The @samp{-p} option to the @code{history} builtin command
152 may be used to see what a history expansion will do before using it.
153 The @samp{-s} option to the @code{history} builtin may be used to
154 add commands to the end of the history list without actually executing
155 them, so that they are available for subsequent recall.
156
157 The shell allows control of the various characters used by the
158 history expansion mechanism with the @code{histchars} variable.
159 @end ifset
160
161 @menu
162 * Event Designators:: How to specify which history line to use.
163 * Word Designators:: Specifying which words are of interest.
164 * Modifiers:: Modifying the results of substitution.
165 @end menu
166
167 @node Event Designators
168 @subsection Event Designators
169 @cindex event designators
170
171 An event designator is a reference to a command line entry in the
172 history list.
173 @cindex history events
174
175 @table @asis
176
177 @item @code{!}
178 Start a history substitution, except when followed by a space, tab,
179 the end of the line, @key{=} or @key{(}.
180
181 @item @code{!@var{n}}
182 Refer to command line @var{n}.
183
184 @item @code{!-@var{n}}
185 Refer to the command @var{n} lines back.
186
187 @item @code{!!}
188 Refer to the previous command. This is a synonym for @samp{!-1}.
189
190 @item @code{!@var{string}}
191 Refer to the most recent command starting with @var{string}.
192
193 @item @code{!?@var{string}[?]}
194 Refer to the most recent command containing @var{string}. The trailing
195 @samp{?} may be omitted if the @var{string} is followed immediately by
196 a newline.
197
198 @item @code{^@var{string1}^@var{string2}^}
199 Quick Substitution. Repeat the last command, replacing @var{string1}
200 with @var{string2}. Equivalent to
201 @code{!!:s/@var{string1}/@var{string2}/}.
202
203 @item @code{!#}
204 The entire command line typed so far.
205
206 @end table
207
208 @node Word Designators
209 @subsection Word Designators
210
211 Word designators are used to select desired words from the event.
212 A @samp{:} separates the event specification from the word designator. It
213 can be omitted if the word designator begins with a @samp{^}, @samp{$},
214 @samp{*}, @samp{-}, or @samp{%}. Words are numbered from the beginning
215 of the line, with the first word being denoted by 0 (zero). Words are
216 inserted into the current line separated by single spaces.
217
218 @table @code
219
220 @item 0 (zero)
221 The @code{0}th word. For many applications, this is the command word.
222
223 @item @var{n}
224 The @var{n}th word.
225
226 @item ^
227 The first argument; that is, word 1.
228
229 @item $
230 The last argument.
231
232 @item %
233 The word matched by the most recent @samp{?@var{string}?} search.
234
235 @item @var{x}-@var{y}
236 A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}.
237
238 @item *
239 All of the words, except the @code{0}th. This is a synonym for @samp{1-$}.
240 It is not an error to use @samp{*} if there is just one word in the event;
241 the empty string is returned in that case.
242
243 @item @var{x}*
244 Abbreviates @samp{@var{x}-$}
245
246 @item @var{x}-
247 Abbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word.
248
249 @end table
250
251 If a word designator is supplied without an event specification, the
252 previous command is used as the event.
253
254 @node Modifiers
255 @subsection Modifiers
256
257 After the optional word designator, you can add a sequence of one or more
258 of the following modifiers, each preceded by a @samp{:}.
259
260 @table @code
261
262 @item h
263 Remove a trailing pathname component, leaving only the head.
264
265 @item t
266 Remove all leading pathname components, leaving the tail.
267
268 @item r
269 Remove a trailing suffix of the form @samp{.@var{suffix}}, leaving
270 the basename.
271
272 @item e
273 Remove all but the trailing suffix.
274
275 @item p
276 Print the new command but do not execute it.
277
278 @ifset BashFeatures
279 @item q
280 Quote the substituted words, escaping further substitutions.
281
282 @item x
283 Quote the substituted words as with @samp{q},
284 but break into words at spaces, tabs, and newlines.
285 @end ifset
286
287 @item s/@var{old}/@var{new}/
288 Substitute @var{new} for the first occurrence of @var{old} in the
289 event line. Any delimiter may be used in place of @samp{/}.
290 The delimiter may be quoted in @var{old} and @var{new}
291 with a single backslash. If @samp{&} appears in @var{new},
292 it is replaced by @var{old}. A single backslash will quote
293 the @samp{&}. The final delimiter is optional if it is the last
294 character on the input line.
295
296 @item &
297 Repeat the previous substitution.
298
299 @item g
300 Cause changes to be applied over the entire event line. Used in
301 conjunction with @samp{s}, as in @code{gs/@var{old}/@var{new}/},
302 or with @samp{&}.
303
304 @end table