external (GNU tar 1.34)

Previous: interactive, Up: tar invocation [Contents][Index]

### 3.11 Running External Commands

Certain GNU `tar` operations imply running external commands that you supply on the command line. One of such operations is checkpointing, described above (see checkpoint exec). Another example of this feature is the `-I` option, which allows you to supply the program to use for compressing or decompressing the archive (see use-compress-program).

Whenever such operation is requested, `tar` first splits the supplied command into words much like the shell does. It then treats the first word as the name of the program or the shell script to execute and the rest of words as its command line arguments. The program, unless given as an absolute file name, is searched in the shell’s `PATH`.

Any additional information is normally supplied to external commands in environment variables, specific to each particular operation. For example, the `--checkpoint-action=exec` option, defines the `TAR_ARCHIVE` variable to the name of the archive being worked upon. You can, should the need be, use these variables in the command line of the external command. For example:

    $ tar -x -f archive.tar \
        --checkpoint-action=exec='printf "%04d in %32s\r" $TAR_CHECKPOINT $TAR_ARCHIVE'

This command prints for each checkpoint its number and the name of the archive, using the same output line on the screen.

Notice the use of single quotes to prevent variable names from being expanded by the shell when invoking `tar`.