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