A shell archive or
file is a single file that contains one or
more other files.
Files are extracted from the archive with the standard UNIX
Bourne shell (
A shell archive usually doesn't let you save and restore complete directory
it is completely portable and, as a result, is used
an international network with many UNIX systems.
In the Bourne shell,
to take the following lines, up to a specified string,
as input to a command.
(This is often called a
Using this syntax and the
commands, you can write a simple shell archiver (
like the one below.
systems already have
in place; there
freely available versions,
including the one on the CD-ROM.
Just about any of them are likely to be more sophisticated than the
version shown here - but this version shows the essence of how they work:
echo "echo restoring $file"
echo "cat > $file << 'XxXxXxXxXx-EOF-XxXxXxXxXx'"
entirely arbitrary - it just needs to be a string that
won't otherwise appear in the input and can be used
by the shell to recognize when the here document is
When you give
a list of filenames, it will
string those files together on standard output, separating them with that
arbitrary string and the commands to split them up again.
Simply redirect this
output stream to a file to create the archive.
example, the command:
shar file1 file2 > archive.shar
will produce a file called
the following data:
echo restoring file1
cat > file1 << 'XxXxXxXxXx-EOF-XxXxXxXxXx'
Text of file1 will be stored here
echo restoring file2
cat > file2 << 'XxXxXxXxXx-EOF-XxXxXxXxXx'
Text of file2 will be stored here
When this archive is run through
, the commands
it contains will be executed.
Each here document
(the lines from each
up to the next
) will be output
to a file:
program does essentially the same thing.
You should never blindly run
a shell archive supplied by someone you don't know
An unscrupulous prankster could easily
include a "Trojan horse" command (like
the middle of a seemingly innocuous archive, and
cause you a lot of trouble.
An easy way to do this is by browsing through the archive with the search
command in a program like
Use the search command (in
, the command is
to find each end-of-file string (like
look carefully at the commands between it and the
that starts the next file.
Of course, if the files in the shell archive are programs themselves,
you should also check them before they're executed.