1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc. 4 5Permission is granted to copy, distribute and/or modify this document 6under the terms of the GNU Free Documentation License, Version 1.3 or 7any later version published by the Free Software Foundation; with the 8Invariant Sections being "Free Software" and "Free Software Needs 9Free Documentation", with the Front-Cover Texts being "A GNU Manual," 10and with the Back-Cover Texts as in (a) below. 11 12(a) The FSF's Back-Cover Text is: "You are free to copy and modify 13this GNU Manual. Buying copies from GNU Press supports the FSF in 14developing GNU and promoting software freedom." --> 15<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ --> 16<head> 17<title>Debugging with GDB: Shell Commands</title> 18 19<meta name="description" content="Debugging with GDB: Shell Commands"> 20<meta name="keywords" content="Debugging with GDB: Shell Commands"> 21<meta name="resource-type" content="document"> 22<meta name="distribution" content="global"> 23<meta name="Generator" content="makeinfo"> 24<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 25<link href="index.html#Top" rel="start" title="Top"> 26<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index"> 27<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> 28<link href="Invocation.html#Invocation" rel="up" title="Invocation"> 29<link href="Logging-Output.html#Logging-Output" rel="next" title="Logging Output"> 30<link href="Quitting-GDB.html#Quitting-GDB" rel="previous" title="Quitting GDB"> 31<style type="text/css"> 32<!-- 33a.summary-letter {text-decoration: none} 34blockquote.smallquotation {font-size: smaller} 35div.display {margin-left: 3.2em} 36div.example {margin-left: 3.2em} 37div.indentedblock {margin-left: 3.2em} 38div.lisp {margin-left: 3.2em} 39div.smalldisplay {margin-left: 3.2em} 40div.smallexample {margin-left: 3.2em} 41div.smallindentedblock {margin-left: 3.2em; font-size: smaller} 42div.smalllisp {margin-left: 3.2em} 43kbd {font-style:oblique} 44pre.display {font-family: inherit} 45pre.format {font-family: inherit} 46pre.menu-comment {font-family: serif} 47pre.menu-preformatted {font-family: serif} 48pre.smalldisplay {font-family: inherit; font-size: smaller} 49pre.smallexample {font-size: smaller} 50pre.smallformat {font-family: inherit; font-size: smaller} 51pre.smalllisp {font-size: smaller} 52span.nocodebreak {white-space:nowrap} 53span.nolinebreak {white-space:nowrap} 54span.roman {font-family:serif; font-weight:normal} 55span.sansserif {font-family:sans-serif; font-weight:normal} 56ul.no-bullet {list-style: none} 57--> 58</style> 59 60 61</head> 62 63<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000"> 64<a name="Shell-Commands"></a> 65<div class="header"> 66<p> 67Next: <a href="Logging-Output.html#Logging-Output" accesskey="n" rel="next">Logging Output</a>, Previous: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="p" rel="previous">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 68</div> 69<hr> 70<a name="Shell-Commands-1"></a> 71<h3 class="section">2.3 Shell Commands</h3> 72 73<p>If you need to execute occasional shell commands during your 74debugging session, there is no need to leave or suspend <small>GDB</small>; you can 75just use the <code>shell</code> command. 76</p> 77<dl compact="compact"> 78<dd><a name="index-shell"></a> 79<a name="index-_0021"></a> 80<a name="index-shell-escape"></a> 81</dd> 82<dt><code>shell <var>command-string</var></code></dt> 83<dt><code>!<var>command-string</var></code></dt> 84<dd><p>Invoke a standard shell to execute <var>command-string</var>. 85Note that no space is needed between <code>!</code> and <var>command-string</var>. 86On GNU and Unix systems, the environment variable <code>SHELL</code>, if it 87exists, determines which shell to run. Otherwise <small>GDB</small> uses 88the default shell (<samp>/bin/sh</samp> on GNU and Unix systems, 89<samp>cmd.exe</samp> on MS-Windows, <samp>COMMAND.COM</samp> on MS-DOS, etc.). 90</p></dd> 91</dl> 92 93<p>The utility <code>make</code> is often needed in development environments. 94You do not have to use the <code>shell</code> command for this purpose in 95<small>GDB</small>: 96</p> 97<dl compact="compact"> 98<dd><a name="index-make"></a> 99<a name="index-calling-make"></a> 100</dd> 101<dt><code>make <var>make-args</var></code></dt> 102<dd><p>Execute the <code>make</code> program with the specified 103arguments. This is equivalent to ‘<samp>shell make <var>make-args</var></samp>’. 104</p></dd> 105</dl> 106 107<dl compact="compact"> 108<dd><a name="index-pipe"></a> 109<a name="index-_007c"></a> 110<a name="index-send-the-output-of-a-gdb-command-to-a-shell-command"></a> 111<a name="pipe"></a></dd> 112<dt><code>pipe [<var>command</var>] | <var>shell_command</var></code></dt> 113<dt><code>| [<var>command</var>] | <var>shell_command</var></code></dt> 114<dt><code>pipe -d <var>delim</var> <var>command</var> <var>delim</var> <var>shell_command</var></code></dt> 115<dt><code>| -d <var>delim</var> <var>command</var> <var>delim</var> <var>shell_command</var></code></dt> 116<dd><p>Executes <var>command</var> and sends its output to <var>shell_command</var>. 117Note that no space is needed around <code>|</code>. 118If no <var>command</var> is provided, the last command executed is repeated. 119</p> 120<p>In case the <var>command</var> contains a <code>|</code>, the option <code>-d <var>delim</var></code> 121can be used to specify an alternate delimiter string <var>delim</var> that separates 122the <var>command</var> from the <var>shell_command</var>. 123</p> 124<p>Example: 125</p><div class="smallexample"> 126<pre class="smallexample">(gdb) p var 127$1 = { 128 black = 144, 129 red = 233, 130 green = 377, 131 blue = 610, 132 white = 987 133} 134</pre><pre class="smallexample">(gdb) pipe p var|wc 135 7 19 80 136(gdb) |p var|wc -l 1377 138</pre><pre class="smallexample">(gdb) p /x var 139$4 = { 140 black = 0x90, 141 red = 0xe9, 142 green = 0x179, 143 blue = 0x262, 144 white = 0x3db 145} 146(gdb) ||grep red 147 red => 0xe9, 148</pre><pre class="smallexample">(gdb) | -d ! echo this contains a | char\n ! sed -e 's/|/PIPE/' 149this contains a PIPE char 150(gdb) | -d xxx echo this contains a | char!\n xxx sed -e 's/|/PIPE/' 151this contains a PIPE char! 152(gdb) 153</pre></div> 154</dd> 155</dl> 156 157<p>The convenience variables <code>$_shell_exitcode</code> and <code>$_shell_exitsignal</code> 158can be used to examine the exit status of the last shell command launched 159by <code>shell</code>, <code>make</code>, <code>pipe</code> and <code>|</code>. 160See <a href="Convenience-Vars.html#Convenience-Vars">Convenience Variables</a>. 161</p> 162<hr> 163<div class="header"> 164<p> 165Next: <a href="Logging-Output.html#Logging-Output" accesskey="n" rel="next">Logging Output</a>, Previous: <a href="Quitting-GDB.html#Quitting-GDB" accesskey="p" rel="previous">Quitting GDB</a>, Up: <a href="Invocation.html#Invocation" accesskey="u" rel="up">Invocation</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p> 166</div> 167 168 169 170</body> 171</html> 172