In the
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
, shar (from "shell archive") is an
archive format
In computing, an archive file stores the content of one or more computer file, files, possibly lossless compression, compressed, with associated metadata such as file name, directory structure, error detection and correction information, commentary ...
created with the Unix
shar
utility. A shar file is a type of
self-extracting archive
A self-extracting archive (SFX or SEA) is a computer executable program which combines compressed data in an archive file with machine-executable code to extract the information. Running on a compatible operating system, it does not need a ...
, because it is a valid
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
, and executing it will recreate the files. To extract the files, only the standard
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
Bourne shell
The Bourne shell (sh) is a shell command-line interpreter for computer operating systems. It first appeared on Version 7 Unix, as its default shell. Unix-like systems continue to have /bin/sh—which will be the Bourne shell, or a symbolic lin ...
''sh'' is usually required.
shar files are also sometimes called "sharchives" (from "/bin/sh archive").
Note that the shar command is not specified by the
Single Unix Specification
The Single UNIX Specification (SUS) is a standard for computer operating systems, compliance with which is required to qualify for using the "UNIX" trademark. The standard specifies programming interfaces for the C language, a command-line shell, ...
, 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
In computing, plain text is a loose term for data (e.g. file contents) that represent only characters of readable material but not its graphical representation nor other objects ( floating-point numbers, images, etc.). It may also include a lim ...
, it poses a risk due to being
executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
; for this reason the older and more general
tar file format is usually preferred even for transferring text files.
GNU
GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
provides its own version of shar in the
GNU Sharutils GNU Sharutils is a set of utilities to handle shell archives. The GNU shar utility produces a single file out of many files and prepares them for transmission by electronic mail services, for example by converting binary files into plain ASCII tex ...
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'', for example, the original ''
Unreal Tournament
''Unreal Tournament'' is a 1999 first-person shooter game developed by Epic Games and Digital Extremes. The second installment in the '' Unreal'' series, it was first published by GT Interactive in 1999 for Windows, and later released on the P ...
'' for Linux installer, fails to run on bash 3.x due to a change in how missing arguments to
trap
built-in command
In computing, a shell builtin is a command or a function, exposed by a shell, that is implemented in the shell itself, instead of an external program which the shell would load and execute.
A shell builtin starts faster than an external program ...
are handled.
History and variants
James Gosling
James Arthur Gosling (born 19 May 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java (programming language), Java programming language.
Gosling was elected a member of the National Academy of E ...
is credited with writing the first version of the ''shar'' utility in 1982,
and also wrote an early example (allegedly 1978-79) of the concept in the form of this simple shell script:
# 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:
* ''shar 1.x'' (1982) by Gosling.
Public domain
The public domain (PD) consists of all the creative work to which no Exclusive exclusive intellectual property rights apply. Those rights may have expired, been forfeited, expressly Waiver, waived, or may be inapplicable. Because no one holds ...
shell script
A shell script is a computer program designed to be run by a Unix shell, a command-line interpreter. The various dialects of shell scripts are considered to be command languages. Typical operations performed by shell scripts include file manipu ...
.
** Current
FreeBSD
FreeBSD is a free-software Unix-like operating system descended from the Berkeley Software Distribution (BSD). The first version was released in 1993 developed from 386BSD, one of the first fully functional and free Unix clones on affordable ...
''shar''.
3-clause BSD license
BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD licen ...
, 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
GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
''sharutils''.
GPLv3
The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
, 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 is available as a separate package for
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
as part of the
UnxUtils
UnxUtils is a collection of utility programs that provide popular Unix-based shell commands ported from GNU implementations as native Windows programs that depend only on Win32 and the Microsoft C- runtime ( msvcrt.dll). The collection wa ...
collection of
native
Native may refer to:
People
* '' Jus sanguinis'', nationality by blood
* '' Jus soli'', nationality by location of birth
* Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory
** Nat ...
Win32
The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
ports Ports collections (or ports trees, or just ports) are the sets of makefiles and Patch (Unix), patches provided by the BSD-based operating systems, FreeBSD, NetBSD, and OpenBSD, as a simple method of installing software or creating binary packages. T ...
of common
GNU
GNU ( ) is an extensive collection of free software (394 packages ), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operating systems popu ...
Unix-like 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. This was later maintained and extended by James A. Gray from
Xerox
Xerox Holdings Corporation (, ) is an American corporation that sells print and electronic document, digital document products and services in more than 160 countries. Xerox was the pioneer of the photocopier market, beginning with the introduc ...
, and Andy Harper from
King's College London
King's College London (informally King's or KCL) is a public university, public research university in London, England. King's was established by royal charter in 1829 under the patronage of George IV of the United Kingdom, King George IV ...
.
''makeself'' (2001–) is a shell script that generates self-extracting
tarballs (, ) 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.
See also
*
List of Unix commands
This is a list of the shell commands of the most recent version of the Portable Operating System Interface (POSIX) IEEE Std 1003.1-2024 which is part of the Single UNIX Specification (SUS). These commands are implemented in many shells on moder ...
References
External links
*
Information about shar files (Carnegie Mellon)GNU sharutils
{{Archive formats
Unix archivers and compression-related utilities
Archive formats