shar files are also sometimes called "sharchives" (from "/bin/sh archive").[2]
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;[3] 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 may rely on a particular implementation of programs; shell archives created with older versions of makeself,[4] 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 trapbuilt-in command are handled.
History and variants
James Gosling is credited with writing the first version of the shar utility in 1982,[1]: §1 and also wrote an early example (allegedly 1978-79) of the concept in the form of this simple shell script:[5][6][7]
# shar -- Shell archiverAR=$1shiftforidoechoa-$iecho"echo x - $i">>$ARecho"cat >$i <<'!Funky!Stuff!'">>$ARcat$i>>$ARecho"!Funky!Stuff!">>$ARdone
makeself (2001–) is a shell script that generates self-extracting tarballs (*.run, application/x-makeself) using the same shell script header technique. Using tar precludes makeself from being used in plain text directly, but the better compression and other functionalities has made it more popular in the 21st century among software vendors seeking to package Linux software.[14]