ar-scripts.html 11 KB

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