In the
Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser 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, and ot ...
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
, shar (an abbreviation of ''shell archive'') is an
archive format
In computing, an archive file is a computer file that is composed of one or more files along with metadata. Archive files are used to collect multiple data files together into a single file for easier portability and storage, or simply to compress ...
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 contains compressed data in an archive file combined with machine-executable program instructions to extract this information on a compatible operating system and wi ...
, 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 scripting languages. Typical operations performed by shell scripts include file manip ...
, and executing it will recreate the files. To extract the files, only the standard
Unix
Unix (; trademarked as UNIX) is a family of multitasking, multiuser 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, and ot ...
Bourne shell
The Bourne shell (sh) is a Shell (computing), shell Command-line interface#Command-line interpreter, command-line interpreter for computer operating systems.
The Bourne shell was the default Unix shell, shell for Version 7 Unix. Unix-like syste ...
''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.
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 limit ...
, it poses a risk due to being
executable
In computing, 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), instructi ...
; for this reason the older and more general
tar file format
In computing, tar is a computer software utility for collecting many files into one archive file, often referred to as a tarball, for distribution or backup purposes. The name is derived from "tape archive", as it was originally developed to ...
is usually preferred even for transferring text files.
GNU
GNU () is an extensive collection of free software (383 packages as of January 2022), 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 operat ...
provides its own version of shar in the
GNU Sharutils GNU Sharutils is a set of utilities to handle shar, shell archives. The GNU shar utility produces a single Computer file, file out of many files and prepares them for transmission by electronic mail services, for example by converting binary files i ...
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 first-person arena shooter video 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 Microsoft Windows, and later r ...
'' 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
James Gosling (born May 19, 1955) is a Canadian computer scientist, best known as the founder and lead designer behind the Java programming language.
Gosling was elected a member of the National Academy of Engineering in 2004 for the conceptio ...
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
A creative work is a manifestation of creative effort including fine artwork (sculpture, paintings, drawing, sketching, performance art), dance, writing (literature), filmmaking, ...
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 scripting languages. Typical operations performed by shell scripts include file manip ...
.
** Current
FreeBSD
FreeBSD is a free and open-source Unix-like operating system descended from the Berkeley Software Distribution (BSD), which was based on Research Unix. The first version of FreeBSD was released in 1993. In 2005, FreeBSD was the most popular ...
''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
GNU () is an extensive collection of free software (383 packages as of January 2022), 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 operat ...
''sharutils''.
GPLv3
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general u ...
, C program.
* ''cshar'' (1984) by Michael A. Thompson and Mark Smith, now lost to bitrot. C program.
* ''cshar'' (1988) by
Rich Salz
InterNetNews (INN) is a Usenet news server package, originally released by Rich Salz in 1991, and presented at the Summer 1992 USENIX conference in San Antonio, Texas. It was the first news server with integrated NNTP functionality.
While pr ...
, 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 group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
as part of the
UnxUtils
UnxUtils is a collection of ports of common GNU Unix-like utilities to native Win32, with executables only depending on the Microsoft C- runtime msvcrt.dll. The collection was last updated externally on April 15, 2003, by Karl M. Syring. The mo ...
collection of
native
Native may refer to:
People
* Jus soli, citizenship by right of birth
* Indigenous peoples, peoples with a set of specific rights based on their historical ties to a particular territory
** Native Americans (disambiguation)
In arts and entert ...
Win32
The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. The name Windows API collectively refers to several different platform implementations th ...
ports
A port is a maritime facility comprising one or more wharves or loading areas, where ships load and discharge cargo and passengers. Although usually situated on a sea coast or estuary, ports can also be found far inland, such as H ...
of common
GNU
GNU () is an extensive collection of free software (383 packages as of January 2022), 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 operat ...
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
as a
DCL script, VMS_SHAR.COM. This was later maintained and extended by James A. Gray from
Xerox
Xerox Holdings Corporation (; also known simply as Xerox) is an American corporation that sells print and electronic document, digital document products and services in more than 160 countries. Xerox is headquartered in Norwalk, Connecticut (ha ...
, and Andy Harper from
King's College London
King's College London (informally King's or KCL) is a public research university located in London, England. King's was established by royal charter in 1829 under the patronage of King George IV and the Duke of Wellington. In 1836, King's ...
.
''makeself'' (2001–) is a shell script that generates self-extracting
tarball Tarball may refer to:
* Tarball (computing), a type of archive file
* Tarball (oil), a blob of semi-solid oil found on or near the ocean
{{Disambiguation ...
s (, ) 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 Unix commands as specified by IEEE Std 1003.1-2008, which is part of the Single UNIX Specification (SUS). These commands can be found on Unix operating systems and most Unix-like operating systems.
List
See also
* List of G ...
References
External links
*
Information about shar files (Carnegie Mellon)GNU sharutils{{Archive formats
Unix archivers and compression-related utilities
Archive formats