<HTML> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- Created on March, 27 2008 by texi2html 1.64 --> <!-- Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author) Karl Berry <karl@freefriends.org> Olaf Bachmann <obachman@mathematik.uni-kl.de> and many others. Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de> Send bugs and suggestions to <texi2html@mathematik.uni-kl.de> --> <HEAD> <TITLE>Debugging with GDB: Using History Interactively</TITLE> <META NAME="description" CONTENT="Debugging with GDB: Using History Interactively"> <META NAME="keywords" CONTENT="Debugging with GDB: Using History Interactively"> <META NAME="resource-type" CONTENT="document"> <META NAME="distribution" CONTENT="global"> <META NAME="Generator" CONTENT="texi2html 1.64"> </HEAD> <BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"> <A NAME="SEC679"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_28.html#SEC678"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC680"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_4.html#SEC14"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H1> 28. Using History Interactively </H1> <!--docid::SEC679::--> <P> This chapter describes how to use the GNU History Library interactively, from a user's standpoint. It should be considered a user's guide. For information on using the GNU History Library in other programs, see the GNU Readline Library Manual. </P><P> <BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_29.html#SEC680">28.1 History Expansion</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">What it feels like using History as a user.</TD></TR> </TABLE></BLOCKQUOTE> <P> <A NAME="History Interaction"></A> <HR SIZE="6"> <A NAME="SEC680"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC681"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H2> 28.1 History Expansion </H2> <!--docid::SEC680::--> <P> The History library provides a history expansion feature that is similar to the history expansion provided by <CODE>csh</CODE>. This section describes the syntax used to manipulate the history information. </P><P> History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly. </P><P> 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 current one. The line selected from the history is called the <EM>event</EM>, and the portions of that line that are acted upon are called <EM>words</EM>. Various <EM>modifiers</EM> are available to manipulate the selected words. The line is broken into words in the same fashion 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>`!'</SAMP> by default. </P><P> <BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_29.html#SEC681">28.1.1 Event Designators</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">How to specify which history line to use.</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_29.html#SEC682">28.1.2 Word Designators</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Specifying which words are of interest.</TD></TR> <TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_29.html#SEC683">28.1.3 Modifiers</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Modifying the results of substitution.</TD></TR> </TABLE></BLOCKQUOTE> <P> <A NAME="Event Designators"></A> <HR SIZE="6"> <A NAME="SEC681"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC680"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC682"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC680"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 28.1.1 Event Designators </H3> <!--docid::SEC681::--> <P> An event designator is a reference to a command line entry in the history list. <A NAME="IDX1510"></A> </P><P> <DL COMPACT> <DT><CODE>!</CODE> <DD>Start a history substitution, except when followed by a space, tab, the end of the line, or <SAMP>`='</SAMP>. <P> <DT><CODE>!<VAR>n</VAR></CODE> <DD>Refer to command line <VAR>n</VAR>. <P> <DT><CODE>!-<VAR>n</VAR></CODE> <DD>Refer to the command <VAR>n</VAR> lines back. <P> <DT><CODE>!!</CODE> <DD>Refer to the previous command. This is a synonym for <SAMP>`!-1'</SAMP>. <P> <DT><CODE>!<VAR>string</VAR></CODE> <DD>Refer to the most recent command starting with <VAR>string</VAR>. <P> <DT><CODE>!?<VAR>string</VAR>[?]</CODE> <DD>Refer to the most recent command containing <VAR>string</VAR>. The trailing <SAMP>`?'</SAMP> may be omitted if the <VAR>string</VAR> is followed immediately by a newline. <P> <DT><CODE>^<VAR>string1</VAR>^<VAR>string2</VAR>^</CODE> <DD>Quick Substitution. Repeat the last command, replacing <VAR>string1</VAR> with <VAR>string2</VAR>. Equivalent to <CODE>!!:s/<VAR>string1</VAR>/<VAR>string2</VAR>/</CODE>. <P> <DT><CODE>!#</CODE> <DD>The entire command line typed so far. <P> </DL> <P> <A NAME="Word Designators"></A> <HR SIZE="6"> <A NAME="SEC682"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC681"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC683"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC683"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC680"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 28.1.2 Word Designators </H3> <!--docid::SEC682::--> <P> Word designators are used to select desired words from the event. A <SAMP>`:'</SAMP> separates the event specification from the word designator. It may be omitted if the word designator begins with a <SAMP>`^'</SAMP>, <SAMP>`$'</SAMP>, <SAMP>`*'</SAMP>, <SAMP>`-'</SAMP>, or <SAMP>`%'</SAMP>. Words are numbered from the beginning of the line, with the first word being denoted by 0 (zero). Words are inserted into the current line separated by single spaces. </P><P> For example, </P><P> <DL COMPACT> <DT><CODE>!!</CODE> <DD>designates the preceding command. When you type this, the preceding command is repeated in toto. <P> <DT><CODE>!!:$</CODE> <DD>designates the last argument of the preceding command. This may be shortened to <CODE>!$</CODE>. <P> <DT><CODE>!fi:2</CODE> <DD>designates the second argument of the most recent command starting with the letters <CODE>fi</CODE>. </DL> <P> Here are the word designators: <DL COMPACT> <DT><CODE>0 (zero)</CODE> <DD>The <CODE>0</CODE>th word. For many applications, this is the command word. <P> <DT><CODE><VAR>n</VAR></CODE> <DD>The <VAR>n</VAR>th word. <P> <DT><CODE>^</CODE> <DD>The first argument; that is, word 1. <P> <DT><CODE>$</CODE> <DD>The last argument. <P> <DT><CODE>%</CODE> <DD>The word matched by the most recent <SAMP>`?<VAR>string</VAR>?'</SAMP> search. <P> <DT><CODE><VAR>x</VAR>-<VAR>y</VAR></CODE> <DD>A range of words; <SAMP>`-<VAR>y</VAR>'</SAMP> abbreviates <SAMP>`0-<VAR>y</VAR>'</SAMP>. <P> <DT><CODE>*</CODE> <DD>All of the words, except the <CODE>0</CODE>th. This is a synonym for <SAMP>`1-$'</SAMP>. It is not an error to use <SAMP>`*'</SAMP> if there is just one word in the event; the empty string is returned in that case. <P> <DT><CODE><VAR>x</VAR>*</CODE> <DD>Abbreviates <SAMP>`<VAR>x</VAR>-$'</SAMP> <P> <DT><CODE><VAR>x</VAR>-</CODE> <DD>Abbreviates <SAMP>`<VAR>x</VAR>-$'</SAMP> like <SAMP>`<VAR>x</VAR>*'</SAMP>, but omits the last word. <P> </DL> <P> If a word designator is supplied without an event specification, the previous command is used as the event. </P><P> <A NAME="Modifiers"></A> <HR SIZE="6"> <A NAME="SEC683"></A> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC682"> < </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> > </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC680"> Up </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <H3> 28.1.3 Modifiers </H3> <!--docid::SEC683::--> <P> After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a <SAMP>`:'</SAMP>. </P><P> <DL COMPACT> <DT><CODE>h</CODE> <DD>Remove a trailing pathname component, leaving only the head. <P> <DT><CODE>t</CODE> <DD>Remove all leading pathname components, leaving the tail. <P> <DT><CODE>r</CODE> <DD>Remove a trailing suffix of the form <SAMP>`.<VAR>suffix</VAR>'</SAMP>, leaving the basename. <P> <DT><CODE>e</CODE> <DD>Remove all but the trailing suffix. <P> <DT><CODE>p</CODE> <DD>Print the new command but do not execute it. <P> <DT><CODE>s/<VAR>old</VAR>/<VAR>new</VAR>/</CODE> <DD>Substitute <VAR>new</VAR> for the first occurrence of <VAR>old</VAR> in the event line. Any delimiter may be used in place of <SAMP>`/'</SAMP>. The delimiter may be quoted in <VAR>old</VAR> and <VAR>new</VAR> with a single backslash. If <SAMP>`&'</SAMP> appears in <VAR>new</VAR>, it is replaced by <VAR>old</VAR>. A single backslash will quote the <SAMP>`&'</SAMP>. The final delimiter is optional if it is the last character on the input line. <P> <DT><CODE>&</CODE> <DD>Repeat the previous substitution. <P> <DT><CODE>g</CODE> <DD><DT><CODE>a</CODE> <DD>Cause changes to be applied over the entire event line. Used in conjunction with <SAMP>`s'</SAMP>, as in <CODE>gs/<VAR>old</VAR>/<VAR>new</VAR>/</CODE>, or with <SAMP>`&'</SAMP>. <P> <DT><CODE>G</CODE> <DD>Apply the following <SAMP>`s'</SAMP> modifier once to each word in the event. <P> </DL> <P> <A NAME="Formatting Documentation"></A> <HR SIZE="6"> <TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0> <TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_29.html#SEC679"> << </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_30.html#SEC684"> >> </A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD> </TR></TABLE> <BR> <FONT SIZE="-1"> <address> <p>Please send FSF & GNU inquiries & questions to <a href="mailto:gnu@gnu.org">gnu@gnu.org</a>. There are also <a href="http://www.gnu.org/home.html#ContactInfo">other ways to contact</a> the FSF.</p> <p>These pages are maintained by <a href="http://www.gnu.org/software/gdb/">the GDB developers</a>.</p> <p>Copyright Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.</p> <p>Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.</p> </address> This document was generated by <I>GDB Administrator</I> on <I>March, 27 2008</I> using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html "><I>texi2html</I></A> </BODY> </HTML>