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