1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1991-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
7or any later version published by the Free Software Foundation;
8with no Invariant Sections, with no Front-Cover Texts, and with no
9Back-Cover Texts.  A copy of the license is included in the
10section entitled "GNU Free Documentation License".
11 -->
12<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
13<head>
14<title>GNU Binary Utilities: ar scripts</title>
15
16<meta name="description" content="GNU Binary Utilities: ar scripts">
17<meta name="keywords" content="GNU Binary Utilities: ar scripts">
18<meta name="resource-type" content="document">
19<meta name="distribution" content="global">
20<meta name="Generator" content="makeinfo">
21<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
22<link href="index.html#Top" rel="start" title="Top">
23<link href="Binutils-Index.html#Binutils-Index" rel="index" title="Binutils Index">
24<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
25<link href="ar.html#ar" rel="up" title="ar">
26<link href="nm.html#nm" rel="next" title="nm">
27<link href="ar-cmdline.html#ar-cmdline" rel="previous" title="ar cmdline">
28<style type="text/css">
29<!--
30a.summary-letter {text-decoration: none}
31blockquote.smallquotation {font-size: smaller}
32div.display {margin-left: 3.2em}
33div.example {margin-left: 3.2em}
34div.indentedblock {margin-left: 3.2em}
35div.lisp {margin-left: 3.2em}
36div.smalldisplay {margin-left: 3.2em}
37div.smallexample {margin-left: 3.2em}
38div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
39div.smalllisp {margin-left: 3.2em}
40kbd {font-style:oblique}
41pre.display {font-family: inherit}
42pre.format {font-family: inherit}
43pre.menu-comment {font-family: serif}
44pre.menu-preformatted {font-family: serif}
45pre.smalldisplay {font-family: inherit; font-size: smaller}
46pre.smallexample {font-size: smaller}
47pre.smallformat {font-family: inherit; font-size: smaller}
48pre.smalllisp {font-size: smaller}
49span.nocodebreak {white-space:nowrap}
50span.nolinebreak {white-space:nowrap}
51span.roman {font-family:serif; font-weight:normal}
52span.sansserif {font-family:sans-serif; font-weight:normal}
53ul.no-bullet {list-style: none}
54-->
55</style>
56
57
58</head>
59
60<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
61<a name="ar-scripts"></a>
62<div class="header">
63<p>
64Previous: <a href="ar-cmdline.html#ar-cmdline" accesskey="p" rel="previous">ar cmdline</a>, Up: <a href="ar.html#ar" accesskey="u" rel="up">ar</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
65</div>
66<hr>
67<a name="Controlling-ar-with-a-Script"></a>
68<h3 class="section">1.2 Controlling <code>ar</code> with a Script</h3>
69
70<div class="smallexample">
71<pre class="smallexample">ar -M [ &lt;<var>script</var> ]
72</pre></div>
73
74<a name="index-MRI-compatibility_002c-ar"></a>
75<a name="index-scripts_002c-ar"></a>
76<p>If you use the single command-line option &lsquo;<samp>-M</samp>&rsquo; with <code>ar</code>, you
77can control its operation with a rudimentary command language.  This
78form of <code>ar</code> operates interactively if standard input is coming
79directly from a terminal.  During interactive use, <code>ar</code> prompts for
80input (the prompt is &lsquo;<samp>AR &gt;</samp>&rsquo;), and continues executing even after
81errors.  If you redirect standard input to a script file, no prompts are
82issued, and <code>ar</code> abandons execution (with a nonzero exit code)
83on any error.
84</p>
85<p>The <code>ar</code> command language is <em>not</em> designed to be equivalent
86to the command-line options; in fact, it provides somewhat less control
87over archives.  The only purpose of the command language is to ease the
88transition to <small>GNU</small> <code>ar</code> for developers who already have scripts
89written for the MRI &ldquo;librarian&rdquo; program.
90</p>
91<p>The syntax for the <code>ar</code> command language is straightforward:
92</p><ul>
93<li> commands are recognized in upper or lower case; for example, <code>LIST</code>
94is the same as <code>list</code>.  In the following descriptions, commands are
95shown in upper case for clarity.
96
97</li><li> a single command may appear on each line; it is the first word on the
98line.
99
100</li><li> empty lines are allowed, and have no effect.
101
102</li><li> comments are allowed; text after either of the characters &lsquo;<samp>*</samp>&rsquo;
103or &lsquo;<samp>;</samp>&rsquo; is ignored.
104
105</li><li> Whenever you use a list of names as part of the argument to an <code>ar</code>
106command, you can separate the individual names with either commas or
107blanks.  Commas are shown in the explanations below, for clarity.
108
109</li><li> &lsquo;<samp>+</samp>&rsquo; is used as a line continuation character; if &lsquo;<samp>+</samp>&rsquo; appears
110at the end of a line, the text on the following line is considered part
111of the current command.
112</li></ul>
113
114<p>Here are the commands you can use in <code>ar</code> scripts, or when using
115<code>ar</code> interactively.  Three of them have special significance:
116</p>
117<p><code>OPEN</code> or <code>CREATE</code> specify a <em>current archive</em>, which is
118a temporary file required for most of the other commands.
119</p>
120<p><code>SAVE</code> commits the changes so far specified by the script.  Prior
121to <code>SAVE</code>, commands affect only the temporary copy of the current
122archive.
123</p>
124<dl compact="compact">
125<dt><code>ADDLIB <var>archive</var></code></dt>
126<dt><code>ADDLIB <var>archive</var> (<var>module</var>, <var>module</var>, &hellip; <var>module</var>)</code></dt>
127<dd><p>Add all the contents of <var>archive</var> (or, if specified, each named
128<var>module</var> from <var>archive</var>) to the current archive.
129</p>
130<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
131</p>
132</dd>
133<dt><code>ADDMOD <var>member</var>, <var>member</var>, &hellip; <var>member</var></code></dt>
134<dd><p>Add each named <var>member</var> as a module in the current archive.
135</p>
136<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
137</p>
138</dd>
139<dt><code>CLEAR</code></dt>
140<dd><p>Discard the contents of the current archive, canceling the effect of
141any operations since the last <code>SAVE</code>.  May be executed (with no
142effect) even if  no current archive is specified.
143</p>
144</dd>
145<dt><code>CREATE <var>archive</var></code></dt>
146<dd><p>Creates an archive, and makes it the current archive (required for many
147other commands).  The new archive is created with a temporary name; it
148is not actually saved as <var>archive</var> until you use <code>SAVE</code>.
149You can overwrite existing archives; similarly, the contents of any
150existing file named <var>archive</var> will not be destroyed until <code>SAVE</code>.
151</p>
152</dd>
153<dt><code>DELETE <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
154<dd><p>Delete each listed <var>module</var> from the current archive; equivalent to
155&lsquo;<samp>ar -d <var>archive</var> <var>module</var> &hellip; <var>module</var></samp>&rsquo;.
156</p>
157<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
158</p>
159</dd>
160<dt><code>DIRECTORY <var>archive</var> (<var>module</var>, &hellip; <var>module</var>)</code></dt>
161<dt><code>DIRECTORY <var>archive</var> (<var>module</var>, &hellip; <var>module</var>) <var>outputfile</var></code></dt>
162<dd><p>List each named <var>module</var> present in <var>archive</var>.  The separate
163command <code>VERBOSE</code> specifies the form of the output: when verbose
164output is off, output is like that of &lsquo;<samp>ar -t <var>archive</var>
165<var>module</var>&hellip;</samp>&rsquo;.  When verbose output is on, the listing is like
166&lsquo;<samp>ar -tv <var>archive</var> <var>module</var>&hellip;</samp>&rsquo;.
167</p>
168<p>Output normally goes to the standard output stream; however, if you
169specify <var>outputfile</var> as a final argument, <code>ar</code> directs the
170output to that file.
171</p>
172</dd>
173<dt><code>END</code></dt>
174<dd><p>Exit from <code>ar</code>, with a <code>0</code> exit code to indicate successful
175completion.  This command does not save the output file; if you have
176changed the current archive since the last <code>SAVE</code> command, those
177changes are lost.
178</p>
179</dd>
180<dt><code>EXTRACT <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
181<dd><p>Extract each named <var>module</var> from the current archive, writing them
182into the current directory as separate files.  Equivalent to &lsquo;<samp>ar -x
183<var>archive</var> <var>module</var>&hellip;</samp>&rsquo;.
184</p>
185<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
186</p>
187
188</dd>
189<dt><code>LIST</code></dt>
190<dd><p>Display full contents of the current archive, in &ldquo;verbose&rdquo; style
191regardless of the state of <code>VERBOSE</code>.  The effect is like &lsquo;<samp>ar
192tv <var>archive</var></samp>&rsquo;.  (This single command is a <small>GNU</small> <code>ar</code>
193enhancement, rather than present for MRI compatibility.)
194</p>
195<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
196</p>
197</dd>
198<dt><code>OPEN <var>archive</var></code></dt>
199<dd><p>Opens an existing archive for use as the current archive (required for
200many other commands).  Any changes as the result of subsequent commands
201will not actually affect <var>archive</var> until you next use <code>SAVE</code>.
202</p>
203</dd>
204<dt><code>REPLACE <var>module</var>, <var>module</var>, &hellip; <var>module</var></code></dt>
205<dd><p>In the current archive, replace each existing <var>module</var> (named in
206the <code>REPLACE</code> arguments) from files in the current working directory.
207To execute this command without errors, both the file, and the module in
208the current archive, must exist.
209</p>
210<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
211</p>
212</dd>
213<dt><code>VERBOSE</code></dt>
214<dd><p>Toggle an internal flag governing the output from <code>DIRECTORY</code>.
215When the flag is on, <code>DIRECTORY</code> output matches output from
216&lsquo;<samp>ar -tv </samp>&rsquo;&hellip;.
217</p>
218</dd>
219<dt><code>SAVE</code></dt>
220<dd><p>Commit your changes to the current archive, and actually save it as a
221file with the name specified in the last <code>CREATE</code> or <code>OPEN</code>
222command.
223</p>
224<p>Requires prior use of <code>OPEN</code> or <code>CREATE</code>.
225</p>
226</dd>
227</dl>
228
229
230<hr>
231<div class="header">
232<p>
233Previous: <a href="ar-cmdline.html#ar-cmdline" accesskey="p" rel="previous">ar cmdline</a>, Up: <a href="ar.html#ar" accesskey="u" rel="up">ar</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
234</div>
235
236
237
238</body>
239</html>
240