--- embedaddon/readline/doc/hsuser.texi 2014/07/30 08:16:45 1.1.1.1 +++ embedaddon/readline/doc/hsuser.texi 2021/03/17 01:01:01 1.1.1.2 @@ -1,7 +1,7 @@ @ignore This file documents the user interface to the GNU History library. -Copyright (C) 1988--2014 Free Software Foundation, Inc. +Copyright (C) 1988--2020 Free Software Foundation, Inc. Authored by Brian Fox and Chet Ramey. Permission is granted to make and distribute verbatim copies of this manual @@ -102,7 +102,7 @@ associated with each history entry is written to the h marked with the history comment character. When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted -as timestamps for the previous history line. +as timestamps for the following history entry. The builtin command @code{fc} may be used to list or edit and re-execute a portion of the history list. @@ -124,7 +124,7 @@ The @code{lithist} shell option causes the shell to save the command with embedded newlines instead of semicolons. The @code{shopt} builtin is used to set these options. -@xref{Bash Builtins}, for a description of @code{shopt}. +@xref{The Shopt Builtin}, for a description of @code{shopt}. @node Bash History Builtins @section Bash History Builtins @@ -149,8 +149,15 @@ Both @var{first} and @var{last} may be specified as a string (to locate the most recent command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the -current command number). If @var{last} is not specified it is set to -@var{first}. If @var{first} is not specified it is set to the previous +current command number). + +When listing, a @var{first} or @var{last} of 0 is equivalent to -1 +and -0 is equivalent to the current command (usually the @code{fc} +command); +otherwise 0 is equivalent to -1 and -0 is invalid. + +If @var{last} is not specified, it is set to +@var{first}. If @var{first} is not specified, it is set to the previous command for editing and @minus{}16 for listing. If the @option{-l} flag is given, the commands are listed on standard output. The @option{-n} flag suppresses the command numbers when listing. The @option{-r} flag @@ -164,7 +171,7 @@ When editing is complete, the edited commands are echo In the second form, @var{command} is re-executed after each instance of @var{pat} in the selected command is replaced by @var{rep}. -@var{command} is intepreted the same as @var{first} above. +@var{command} is interpreted the same as @var{first} above. A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so that typing @samp{r cc} runs the last command beginning with @code{cc} @@ -176,6 +183,7 @@ and typing @samp{r} re-executes the last command (@pxr history [@var{n}] history -c history -d @var{offset} +history -d @var{start}-@var{end} history [-anrw] [@var{filename}] history -ps @var{arg} @end example @@ -198,13 +206,22 @@ with the other options to replace the history list com @item -d @var{offset} Delete the history entry at position @var{offset}. -@var{offset} should be specified as it appears when the history is -displayed. +If @var{offset} is positive, it should be specified as it appears when +the history is displayed. +If @var{offset} is negative, it is interpreted as relative to one greater +than the last history position, so negative indices count back from the +end of the history, and an index of @samp{-1} refers to the current +@code{history -d} command. +@item -d @var{start}-@var{end} +Delete the history entries between positions @var{start} and @var{end}, +inclusive. Positive and negative values for @var{start} and @var{end} +are interpreted as described above. + @item -a -Append the new -history lines (history lines entered since the beginning of the -current Bash session) to the history file. +Append the new history lines to the history file. +These are history lines entered since the beginning of the current +Bash session, but not already appended to the history file. @item -n Append the history lines not already read from the history file @@ -249,6 +266,13 @@ the input stream, making it easy to repeat commands, i arguments to a previous command into the current input line, or fix errors in previous commands quickly. +@ifset BashFeatures +History expansion is performed immediately after a complete line +is read, before the shell breaks it into words, and is performed +on each line individually. Bash attempts to inform the history +expansion functions about quoting still in effect from previous lines. +@end ifset + History expansion takes place in two parts. The first is to determine which line from the history list should be used during substitution. The second is to select portions of that line for inclusion into the @@ -260,14 +284,26 @@ that Bash does, so that several words surrounded by quotes are considered one word. History expansions are introduced by the appearance of the history expansion character, which is @samp{!} by default. + +History expansion implements shell-like quoting conventions: +a backslash can be used to remove the special handling for the next character; +single quotes enclose verbatim sequences of characters, and can be used to +inhibit history expansion; +and characters enclosed within double quotes may be subject to history +expansion, since backslash can escape the history expansion character, +but single quotes may not, since they are not treated specially within +double quotes. + @ifset BashFeatures -Only @samp{\} and @samp{'} may be used to escape the history expansion -character. +When using the shell, only @samp{\} and @samp{'} may be used to escape the +history expansion character, but the history expansion character is +also treated as quoted if it immediately precedes the closing double quote +in a double-quoted string. @end ifset @ifset BashFeatures Several shell options settable with the @code{shopt} -builtin (@pxref{Bash Builtins}) may be used to tailor +builtin (@pxref{The Shopt Builtin}) may be used to tailor the behavior of history expansion. If the @code{histverify} shell option is enabled, and Readline is being used, history substitutions are not immediately passed to @@ -341,11 +377,13 @@ containing @var{string}. The trailing @samp{?} may be omitted if the @var{string} is followed immediately by a newline. +If @var{string} is missing, the string from the most recent search is used; +it is an error if there is no previous search string. @item @code{^@var{string1}^@var{string2}^} Quick Substitution. Repeat the last command, replacing @var{string1} with @var{string2}. Equivalent to -@code{!!:s/@var{string1}/@var{string2}/}. +@code{!!:s^@var{string1}^@var{string2}^}. @item @code{!#} The entire command line typed so far. @@ -397,7 +435,8 @@ The first argument; that is, word 1. The last argument. @item % -The word matched by the most recent @samp{?@var{string}?} search. +The first word matched by the most recent @samp{?@var{string}?} search, +if the search string begins with a character that is part of a word. @item @var{x}-@var{y} A range of words; @samp{-@var{y}} abbreviates @samp{0-@var{y}}. @@ -412,6 +451,7 @@ Abbreviates @samp{@var{x}-$} @item @var{x}- Abbreviates @samp{@var{x}-$} like @samp{@var{x}*}, but omits the last word. +If @samp{x} is missing, it defaults to 0. @end table @@ -423,6 +463,7 @@ previous command is used as the event. After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a @samp{:}. +These modify, or edit, the word or words selected from the history event. @table @code @@ -449,15 +490,25 @@ Quote the substituted words, escaping further substitu @item x Quote the substituted words as with @samp{q}, but break into words at spaces, tabs, and newlines. +The @samp{q} and @samp{x} modifiers are mutually exclusive; the last one +supplied is used. @end ifset @item s/@var{old}/@var{new}/ Substitute @var{new} for the first occurrence of @var{old} in the -event line. Any delimiter may be used in place of @samp{/}. +event line. +Any character may be used as the delimiter in place of @samp{/}. The delimiter may be quoted in @var{old} and @var{new} with a single backslash. If @samp{&} appears in @var{new}, it is replaced by @var{old}. A single backslash will quote -the @samp{&}. The final delimiter is optional if it is the last +the @samp{&}. +If @var{old} is null, it is set to the last @var{old} +substituted, or, if no previous history substitutions took place, +the last @var{string} +in a !?@var{string}@code{[?]} +search. +If @var{new} is is null, each matching @var{old} is deleted. +The final delimiter is optional if it is the last character on the input line. @item & @@ -470,6 +521,7 @@ conjunction with @samp{s}, as in @code{gs/@var{old}/@v or with @samp{&}. @item G -Apply the following @samp{s} modifier once to each word in the event. +Apply the following @samp{s} or @samp{&} modifier once to each word +in the event. @end table