In the Unix operating system, shar (an abbreviation of shell archive) is an archive format. A shar file is a shell script, and executing it will recreate the files. This is a type of self-extracting archive file. It can be created with the Unix shar utility. To extract the files, only the standard Unix Bourne shell sh is usually required.

Note that shar isn't specified by the Single Unix Specification, so it isn't formally a component of Unix, but a legacy utility.


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 programmes have been written for additional operating systems but aren't always reliable; shar files are shell scripts and can theoretically do anything that a shell script can do (including using incompatible features of enhanced or workalike shells), limiting their utility outside the Unix world.

The drawback of self-extracting shell scripts (any kind, not just shar) is that they 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.

Similar formats

In 1987, Michael Bednarek from The Melbourne Institute of Applied Economic and Social Research at the University of Melbourne developed a script for a similar purpose in the DIGITAL Command Language for the VMS operating system under the name "VMS_Shar version 2".

The main purpose of this script was to allow the distribution of formatted programme code through e-mail and Usenet newsgroups because:

  1. Mail transfer agents and NNTP server software only allowed printable ASCII characters (32–126);
  2. They tended to strip leading and trailing blanks and TAB characters;
  3. And they usually broke lines longer than 80 characters. VMS_SHAR protected leading blanks, and it split long files into parts of less than 16,000 bytes.

Version 4 introduced the protection of trailing blanks using the TPU text editor which then became the main engine of the script. Version 5 protected control characters like TAB, ESC, BEL. In 1988, beginning with version 6, the script was then extended by James A. Gray from Xerox. Starting with version 7, Andy Harper from King's College London continued the development;. The current version (as of 2008) is 8.5 (1994)