Index Previous: ar cmdline Up: ar

1.2 Controlling ar with a Script

     ar -M [ <script ]

If you use the single command-line option -M with ar, youcan 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 non zero 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:

Here are the commands you can use in ar scripts, or when usingar interactively. Three of them have special significance:

OPEN or CREATE specify a current archive, which isa temporary file required for most of the other commands.

SAVE commits the changes so far specified by the script. Priorto SAVE, commands affect only the temporary copy of the currentarchive.

ADDLIB archive ADDLIB archive ( module , module , ... module ) Add all the contents of archive (or, if specified, each namedmodule from archive) to the current archive.

Requires prior use of OPEN or CREATE.

ADDMOD member , member , ... member Add each named member as a module in the current archive.

Requires prior use of OPEN or CREATE.

CLEAR Discard the contents of the current archive, canceling the effect ofany operations since the last SAVE. May be executed (with noeffect) even if no current archive is specified.
CREATE archive Creates an archive, and makes it the current archive (required for manyother commands). The new archive is created with a temporary name; itis not actually saved as archive until you use SAVE. You can overwrite existing archives; similarly, the contents of anyexisting file named archive will not be destroyed until SAVE.
DELETE module , module , ... module Delete each listed module from the current archive; equivalent toar -d archive module ... module.

Requires prior use of OPEN or CREATE.

DIRECTORY archive ( module , ... module ) DIRECTORY archive ( module , ... module ) outputfile List each named module present in archive. The separatecommand VERBOSE specifies the form of the output: when verboseoutput is off, output is like that of ar -t archive module .... When verbose output is on, the listing is likear -tv archive module ....

Output normally goes to the standard output stream; however, if youspecify outputfile as a final argument, ar directs theoutput to that file.

END Exit from ar, with a 0 exit code to indicate successfulcompletion. This command does not save the output file; if you havechanged the current archive since the last SAVE command, thosechanges are lost.
EXTRACT module , module , ... module Extract each named module from the current archive, writing theminto the current directory as separate files. Equivalent to ar -x archive module ....

Requires prior use of OPEN or CREATE.

LIST Display full contents of the current archive, in “verbose” styleregardless of the state of VERBOSE. The effect is like artv archive. (This single command is a gnu arenhancement, rather than present for MRI compatibility.)

Requires prior use of OPEN or CREATE.

OPEN archive Opens an existing archive for use as the current archive (required formany other commands). Any changes as the result of subsequent commandswill not actually affect archive until you next use SAVE.
REPLACE module , module , ... module In the current archive, replace each existing module (named inthe REPLACE arguments) from files in the current working directory. To execute this command without errors, both the file, and the module inthe current archive, must exist.

Requires prior use of OPEN or CREATE.

VERBOSE Toggle an internal flag governing the output from DIRECTORY. When the flag is on, DIRECTORY output matches output fromar -tv ....
SAVE Commit your changes to the current archive, and actually save it as afile with the name specified in the last CREATE or OPENcommand.

Requires prior use of OPEN or CREATE.

Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.