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: Conditional Init Constructs</title> 18 19<meta name="description" content="Debugging with GDB: Conditional Init Constructs"> 20<meta name="keywords" content="Debugging with GDB: Conditional Init Constructs"> 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="Readline-Init-File.html#Readline-Init-File" rel="up" title="Readline Init File"> 29<link href="Sample-Init-File.html#Sample-Init-File" rel="next" title="Sample Init File"> 30<link href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" rel="previous" title="Readline Init File Syntax"> 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="Conditional-Init-Constructs"></a> 65<div class="header"> 66<p> 67Next: <a href="Sample-Init-File.html#Sample-Init-File" accesskey="n" rel="next">Sample Init File</a>, Previous: <a href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" accesskey="p" rel="previous">Readline Init File Syntax</a>, Up: <a href="Readline-Init-File.html#Readline-Init-File" accesskey="u" rel="up">Readline Init File</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="Conditional-Init-Constructs-1"></a> 71<h4 class="subsection">32.3.2 Conditional Init Constructs</h4> 72 73<p>Readline implements a facility similar in spirit to the conditional 74compilation features of the C preprocessor which allows key 75bindings and variable settings to be performed as the result 76of tests. There are four parser directives used. 77</p> 78<dl compact="compact"> 79<dt><code>$if</code></dt> 80<dd><p>The <code>$if</code> construct allows bindings to be made based on the 81editing mode, the terminal being used, or the application using 82Readline. The text of the test, after any comparison operator, 83extends to the end of the line; 84unless otherwise noted, no characters are required to isolate it. 85</p> 86<dl compact="compact"> 87<dt><code>mode</code></dt> 88<dd><p>The <code>mode=</code> form of the <code>$if</code> directive is used to test 89whether Readline is in <code>emacs</code> or <code>vi</code> mode. 90This may be used in conjunction 91with the ‘<samp>set keymap</samp>’ command, for instance, to set bindings in 92the <code>emacs-standard</code> and <code>emacs-ctlx</code> keymaps only if 93Readline is starting out in <code>emacs</code> mode. 94</p> 95</dd> 96<dt><code>term</code></dt> 97<dd><p>The <code>term=</code> form may be used to include terminal-specific 98key bindings, perhaps to bind the key sequences output by the 99terminal’s function keys. The word on the right side of the 100‘<samp>=</samp>’ is tested against both the full name of the terminal and 101the portion of the terminal name before the first ‘<samp>-</samp>’. This 102allows <code>sun</code> to match both <code>sun</code> and <code>sun-cmd</code>, 103for instance. 104</p> 105</dd> 106<dt><code>version</code></dt> 107<dd><p>The <code>version</code> test may be used to perform comparisons against 108specific Readline versions. 109The <code>version</code> expands to the current Readline version. 110The set of comparison operators includes 111‘<samp>=</samp>’ (and ‘<samp>==</samp>’), ‘<samp>!=</samp>’, ‘<samp><=</samp>’, ‘<samp>>=</samp>’, ‘<samp><</samp>’, 112and ‘<samp>></samp>’. 113The version number supplied on the right side of the operator consists 114of a major version number, an optional decimal point, and an optional 115minor version (e.g., ‘<samp>7.1</samp>’). If the minor version is omitted, it 116is assumed to be ‘<samp>0</samp>’. 117The operator may be separated from the string <code>version</code> and 118from the version number argument by whitespace. 119The following example sets a variable if the Readline version being used 120is 7.0 or newer: 121</p><div class="example"> 122<pre class="example">$if version >= 7.0 123set show-mode-in-prompt on 124$endif 125</pre></div> 126 127</dd> 128<dt><code>application</code></dt> 129<dd><p>The <var>application</var> construct is used to include 130application-specific settings. Each program using the Readline 131library sets the <var>application name</var>, and you can test for 132a particular value. 133This could be used to bind key sequences to functions useful for 134a specific program. For instance, the following command adds a 135key sequence that quotes the current or previous word in Bash: 136</p><div class="example"> 137<pre class="example">$if Bash 138# Quote the current or previous word 139"\C-xq": "\eb\"\ef\"" 140$endif 141</pre></div> 142 143</dd> 144<dt><code>variable</code></dt> 145<dd><p>The <var>variable</var> construct provides simple equality tests for Readline 146variables and values. 147The permitted comparison operators are ‘<samp>=</samp>’, ‘<samp>==</samp>’, and ‘<samp>!=</samp>’. 148The variable name must be separated from the comparison operator by 149whitespace; the operator may be separated from the value on the right hand 150side by whitespace. 151Both string and boolean variables may be tested. Boolean variables must be 152tested against the values <var>on</var> and <var>off</var>. 153The following example is equivalent to the <code>mode=emacs</code> test described 154above: 155</p><div class="example"> 156<pre class="example">$if editing-mode == emacs 157set show-mode-in-prompt on 158$endif 159</pre></div> 160</dd> 161</dl> 162 163</dd> 164<dt><code>$endif</code></dt> 165<dd><p>This command, as seen in the previous example, terminates an 166<code>$if</code> command. 167</p> 168</dd> 169<dt><code>$else</code></dt> 170<dd><p>Commands in this branch of the <code>$if</code> directive are executed if 171the test fails. 172</p> 173</dd> 174<dt><code>$include</code></dt> 175<dd><p>This directive takes a single filename as an argument and reads commands 176and bindings from that file. 177For example, the following directive reads from <samp>/etc/inputrc</samp>: 178</p><div class="example"> 179<pre class="example">$include /etc/inputrc 180</pre></div> 181</dd> 182</dl> 183 184<hr> 185<div class="header"> 186<p> 187Next: <a href="Sample-Init-File.html#Sample-Init-File" accesskey="n" rel="next">Sample Init File</a>, Previous: <a href="Readline-Init-File-Syntax.html#Readline-Init-File-Syntax" accesskey="p" rel="previous">Readline Init File Syntax</a>, Up: <a href="Readline-Init-File.html#Readline-Init-File" accesskey="u" rel="up">Readline Init File</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> 188</div> 189 190 191 192</body> 193</html> 194