Shar


In the Unix operating system, shar is an archive format created with the Unix shar utility. A shar file is a type of self-extracting archive, because it is a valid shell script, and executing it will recreate the files. To extract the files, only the standard Unix Bourne shell sh is usually required.
Note that the shar command is not specified by the Single Unix Specification, so it is not formally a component of Unix, but a legacy utility.

Details

While the shar format has the advantage of being plain text, it poses a risk due to being executable; for this reason the older and more general tar file format is usually preferred even for transferring text files. GNU provides its own version of shar in the GNU Sharutils collection.
unshar programs have been written for other operating systems but are not always reliable; shar files are shell scripts and can theoretically do anything that a shell script can do, limiting their utility outside the Unix world.
The drawback of self-extracting shell scripts is that they may rely on a particular implementation of programs; shell archives created with older versions of makeself, for example, the original Unreal Tournament for Linux installer, fails to run on bash 3.x due to a change in how missing arguments to trap built-in command are handled.

History and similar formats

is credited with writing the first version of the shar utility, and also wrote an early example of the concept in the form of this simple shell script:

  1. shar -- Shell archiver
AR=$1
shift
for i do
echo a - $i
echo "echo x - $i" >>$AR
echo "cat >$i <<'!Funky!Stuff!'" >>$AR
cat $i >>$AR
echo "!Funky!Stuff!" >>$AR
done

A version of the same concept, but for the VMS operating system, was written in 1987 by Michael Bednarek from The Melbourne Institute of Applied Economic and Social Research as a DCL script, VMS_SHAR.COM. This was later maintained and extended by James A. Gray from Xerox, and Andy Harper from King's College London.
The command is available as a separate package for Microsoft Windows as part of the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.