From Wikipedia, the free encyclopedia
Filename extension .shar
Type of format Archive format, shell script

In the Unix operating system, shar (an abbreviation of shell archive) 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.


While the shar format has the advantage of being plain text, it poses a risk due to being executable;[1] 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 (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,[2] 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

James Gosling is generally credited with writing the first version of the shar utility,[3] and also wrote an early example of the concept in the form of this simple shell script:[4][5][6]

# shar -- Shell archiver
for i do
	echo a - $i
	echo "echo x - $i" >>$AR
	echo "cat >$i <<'!Funky!Stuff!'" >>$AR
	cat $i >>$AR
	echo "!Funky!Stuff!" >>$AR

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.[7] This was later maintained and extended by James A. Gray from Xerox,[8] and Andy Harper from King's College London.[9][10]

See also


  1. ^ Apple (June 6, 1993). "Mac OS X shar(1) Man Page". Apple. Retrieved 2009-11-07. 
  2. ^ "makeself "trap" command fix". 2000-11-20. Retrieved 2011-08-30. 
  3. ^ "Introduction to this toolset". GNU `shar' utilities. Free Software Foundation. Retrieved 26 March 2017. 
  4. ^ uw-beave!jim (April 2, 1983). "Re: program to separate xlisp distribution files". Newsgroupnet.sources. message-id:bnews.uw-beave.451. Retrieved March 27, 2017. 
  5. ^ "shar: a blast from the past". James Gosling: on the Java Road. Retrieved 26 March 2017. 
  6. ^ An almost identical script, 'bundle', is described in "The UNIX Programming Environment", Kernighan and Pike, 1984, on page 97
  7. ^ Michael Bednarek (9 June 1987). "shar (sort of) for VMS". Newsgroupcomp.os.vms. Usenet: [email protected]. Retrieved 2008-02-09. 
  8. ^ Jim Gray (8 May 1988). "VMS_SHARE V6.0". Newsgroupcomp.os.vms. Usenet: [email protected]. Retrieved 2008-02-09. 
  9. ^ Andy Harper (6 July 1989). "VMS_SHARE version 7". Newsgroupcomp.os.vms. Usenet: [email protected]. Retrieved 2008-02-09. 
  10. ^ Andy Harper (5 July 1995). "Announcing VMS_SHARE 8.5". Newsgroupvmsnet.sources.d. Usenet: [email protected]. Retrieved 2008-02-09. 

External links

  • shar(1) – Linux User Commands Manual
  • Information about shar files (Carnegie Mellon)
  • GNU sharutils
Retrieved from ""
This content was retrieved from Wikipedia :
This page is based on the copyrighted Wikipedia article "shar"; it is used under the Creative Commons Attribution-ShareAlike 3.0 Unported License (CC-BY-SA). You may redistribute it, verbatim or modified, providing that you comply with the terms of the CC-BY-SA