| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
1.2 Controlling ar with a Script
ar -M [ <script ] |
If you use the single command-line option ‘-M’ with ar, you
can control its operation with a rudimentary command language. This
form of ar operates interactively if standard input is coming
directly from a terminal. During interactive use, ar prompts for
input (the prompt is ‘AR >’), and continues executing even after
errors. If you redirect standard input to a script file, no prompts are
issued, and ar abandons execution (with a nonzero exit code)
on any error.
The ar command language is not 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 GNU ar for developers who already have scripts
written for the MRI “librarian” program.
The syntax for the ar command language is straightforward:
-
commands are recognized in upper or lower case; for example,
LISTis the same aslist. In the following descriptions, commands are shown in upper case for clarity. - a single command may appear on each line; it is the first word on the line.
- empty lines are allowed, and have no effect.
- comments are allowed; text after either of the characters ‘*’ or ‘;’ is ignored.
-
Whenever you use a list of names as part of the argument to an
arcommand, you can separate the individual names with either commas or blanks. Commas are shown in the explanations below, for clarity. - ‘+’ is used as a line continuation character; if ‘+’ appears at the end of a line, the text on the following line is considered part of the current command.
Here are the commands you can use in ar scripts, or when using
ar interactively. Three of them have special significance:
OPEN or CREATE specify a current archive, which is
a temporary file required for most of the other commands.
SAVE commits the changes so far specified by the script. Prior
to SAVE, commands affect only the temporary copy of the current
archive.
-
ADDLIB archive -
ADDLIB archive (module, module, … module) Add all the contents of archive (or, if specified, each named module from archive) to the current archive.
Requires prior use of
OPENorCREATE.-
ADDMOD member, member, … member Add each named member as a module in the current archive.
Requires prior use of
OPENorCREATE.-
CLEAR Discard the contents of the current archive, canceling the effect of any operations since the last
SAVE. May be executed (with no effect) even if no current archive is specified.-
CREATE archive 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 archive until you use
SAVE. You can overwrite existing archives; similarly, the contents of any existing file named archive will not be destroyed untilSAVE.-
DELETE module, module, … module Delete each listed module from the current archive; equivalent to ‘ar -d archive module … module’.
Requires prior use of
OPENorCREATE.-
DIRECTORY archive (module, … module) -
DIRECTORY archive (module, … module) outputfile List each named module present in archive. The separate command
VERBOSEspecifies the form of the output: when verbose output is off, output is like that of ‘ar -t archive module…’. When verbose output is on, the listing is like ‘ar -tv archive module…’.Output normally goes to the standard output stream; however, if you specify outputfile as a final argument,
ardirects the output to that file.-
END Exit from
ar, with a0exit code to indicate successful completion. This command does not save the output file; if you have changed the current archive since the lastSAVEcommand, those changes are lost.-
EXTRACT module, module, … module Extract each named module from the current archive, writing them into the current directory as separate files. Equivalent to ‘ar -x archive module…’.
Requires prior use of
OPENorCREATE.-
LIST Display full contents of the current archive, in “verbose” style regardless of the state of
VERBOSE. The effect is like ‘ar tv archive’. (This single command is a GNUarenhancement, rather than present for MRI compatibility.)Requires prior use of
OPENorCREATE.-
OPEN archive 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 archive until you next use
SAVE.-
REPLACE module, module, … module In the current archive, replace each existing module (named in the
REPLACEarguments) 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.Requires prior use of
OPENorCREATE.-
VERBOSE Toggle an internal flag governing the output from
DIRECTORY. When the flag is on,DIRECTORYoutput matches output from ‘ar -tv ’….-
SAVE Commit your changes to the current archive, and actually save it as a file with the name specified in the last
CREATEorOPENcommand.Requires prior use of
OPENorCREATE.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
