shar (file format)

{{Short description|Unix file format}}

{{Lowercase}}

{{Infobox software

| name = shar

| logo =

| screenshot =

| screenshot size =

| caption =

| author = James Gosling

| developer = Various open-source and commercial developers

| released =

| latest release version =

| latest release date =

| operating system = Unix, Unix-like, VMS, Windows

| genre = Command

| license =

| website =

}}

{{Infobox file format

| name = shar

| icon =

| logo =

| screenshot =

| caption =

| extension = .shar

| mime =

| type code =

| uniform type =

| magic =

| owner =

| released =

| latest release version =

| latest release date =

| genre = Archive format, shell script

| container for =

| contained by =

| extended from =

| extended to =

| standard =

| url =

| open = Yes

}}

In the Unix operating system, shar (from "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.

shar files are also sometimes called "sharchives" (from "/bin/sh archive").{{

Cite web

| access-date=2024-01-02

| title=sharchive

| url=http://ftp.informatik.rwth-aachen.de/jargon300/sharchive.html

| website=ftp.informatik.rwth-aachen.de

}}

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;{{

Cite web

| access-date=2009-11-07

| archive-date=2009-11-07

| archive-url=https://web.archive.org/web/20091107190211/http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/shar.1.html

| author=Apple

| date=1993-06-06

| publisher=Apple

| title=Mac OS X shar(1) Man Page

| url-status=dead

| url=https://developer.apple.com/mac/library/DOCUMENTATION/Darwin/Reference/ManPages/man1/shar.1.html

}} 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,{{cite web |url=http://svn.icculus.org/loki_setup/trunk/makeself/makeself.sh?r1=303&r2=304 |archive-url=https://archive.today/20120714133930/http://svn.icculus.org/loki_setup/trunk/makeself/makeself.sh?r1=303&r2=304 |url-status=dead |archive-date=2012-07-14 |title=makeself "trap" command fix |publisher=Svn.icculus.org |date=2000-11-20 |access-date=2011-08-30 }} 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 variants

James Gosling is credited with writing the first version of the shar utility in 1982,{{cite web|title=GNU 'shar' utilities|url=https://www.gnu.org/software/sharutils/manual/sharutils.html|website=gnu.org|publisher=Free Software Foundation|access-date=8 December 2019}}{{rp|at=§1}} and also wrote an early example (allegedly 1978-79) of the concept in the form of this simple shell script:{{

Cite newsgroup

| access-date=March 27, 2017

| author=uw-beave!jim

| date=April 2, 1983

| id=message-id:bnews.uw-beave.451|url=https://groups.google.com/forum/#!original/net.sources/HqA3E612vNg/vCiJELRlTGgJ

| newsgroup=net.sources

| title=Re: program to separate xlisp distribution files

}}{{cite web|title=shar: a blast from the past|url=https://blogs.oracle.com/jag/entry/shar_a_blast_from_the|website=James Gosling: on the Java Road|access-date=26 March 2017|archiveurl=https://web.archive.org/web/20170327173633/https://blogs.oracle.com/jag/entry/shar_a_blast_from_the|archivedate=March 27, 2017}}An almost identical script, 'bundle', is described in "The UNIX Programming Environment", Kernighan and Pike, 1984, on page 97

  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

The following variants of shar are known:{{cite web |last1=Dickey |first1=Thomas E. |title=Comments on Shar/Utils |url=https://invisible-island.net/personal/sharutils.html |website=invisible-island.net}}

  • shar 1.x (1982) by Gosling. Public domain shell script.
  • Current FreeBSD shar. 3-clause BSD license, shell script. Adds md5sum.
  • shar2 or xshar (1988) by William Davidsen. Public domain, C program.
  • shar3 (1989) by Warren Tucker.
  • shar 3.49 (1990) by Richard H. Gumpertz. Adds uuencode support.
  • Current GNU sharutils. GPLv3, C program.
  • cshar (1984) by Michael A. Thompson and Mark Smith, now lost to bitrot. C program.
  • cshar (1988) by Rich Salz, C program. Likely influenced shar 3.49.
  • ccshar (1996), a modification to output a csh script instead. Rarely used on Usenet.

GNU {{code|shar}} 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.[http://unxutils.sourceforge.net/ Native Win32 ports of some GNU utilities]

Similar formats

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.{{

Cite newsgroup

| access-date = 2024-09-04

| author = Michael Bednarek

| date = 9 June 1987

| message-id= 1261@murdu.OZ

| newsgroup = comp.os.vms

| title = shar (sort of) for VMS

| url = https://groups.google.com/g/comp.os.vms/c/uLrc-7zo5iU/m/L7S0I8gjpJsJ

}} This was later maintained and extended by James A. Gray from Xerox,{{

Cite newsgroup

| access-date = 2024-09-04

| author = Jim Gray

| date = 8 May 1988

| message-id= 880508-073131-5929@Xerox

| newsgroup = comp.os.vms

| title = VMS_SHARE V6.0

| url = https://groups.google.com/g/comp.os.vms/c/aMlcSF1L5vU/m/08pfx38YqlEJ

}} and Andy Harper from King's College London.{{

Cite newsgroup

| access-date = 2024-09-04

| author = Andy Harper

| date = 7 July 1989

| message-id= 8907061417.AA16991@ucbvax.Berkeley.EDU

| newsgroup = comp.os.vms

| title = VMS_SHARE version 7

| url = https://groups.google.com/g/comp.os.vms/c/UCt6eBKcNwM/m/1Ra3iZe18xAJ

}}{{

Cite newsgroup

| access-date = 2024-09-04

| author = Andy Harper

| date = 6 July 1995

| message-id= 1994Jul5.164105.3667@bay.cc.kcl.ac.uk

| newsgroup = vmsnet.sources.d

| title = Announcing VMS_SHARE 8.5

| url = https://groups.google.com/g/vmsnet.sources.d/c/kNWtBG94U6g/m/Wp5CKqY-6swJ

}}

makeself (2001–) is a shell script that generates self-extracting tarballs ({{code|*.run}}, {{code|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.{{cite web |title=makeself – Make self-extractable archives on Unix |url=https://makeself.io}}

See also

References

{{Reflist}}