Shar

Last updated
shar
Original author(s) James Gosling
Developer(s) Various open-source and commercial developers
Operating system Unix, Unix-like, VMS, Windows
Type Command
shar
Filename extension
.shar
Type of format Archive format, shell script
Open format?Yes [1]

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.

Contents

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 trap built-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

The following variants of shar are known: [8]

GNU 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. [9]

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

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]

See also

Related Research Articles

<span class="mw-page-title-main">Bash (Unix shell)</span> GNU replacement for the Bourne shell

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell. The shell's name is an acronym for Bourne Again Shell, a pun on the name of the Bourne shell that it replaces and the notion of being "born again". First released in 1989, it has been used as the default login shell for most Linux distributions and it was one of the first programs Linus Torvalds ported to Linux, alongside GCC. A version is also available for Windows 10 and Windows 11 via the Windows Subsystem for Linux. It is also the default user shell in Solaris 11. Bash was also the default shell in BeOS, and in versions of Apple macOS from 10.3 to 10.15, which changed the default shell to zsh, although Bash remains available as an alternative shell.

The Portable Operating System Interface is a family of standards specified by the IEEE Computer Society for maintaining compatibility between operating systems. POSIX defines both the system and user-level application programming interfaces (APIs), along with command line shells and utility interfaces, for software compatibility (portability) with variants of Unix and other operating systems. POSIX is also a trademark of the IEEE. POSIX is intended to be used by both application and system developers.

uniq is a utility command on Unix, Plan 9, Inferno, and Unix-like operating systems which, when fed a text file or standard input, outputs the text with adjacent identical lines collapsed to one, unique line of text.

<span class="mw-page-title-main">Z shell</span> Unix shell

The Z shell (Zsh) is a Unix shell that can be used as an interactive login shell and as a command interpreter for shell scripting. Zsh is an extended Bourne shell with many improvements, including some features of Bash, ksh, and tcsh.

Almquist shell is a lightweight Unix shell originally written by Kenneth Almquist in the late 1980s. Initially a clone of the System V.4 variant of the Bourne shell, it replaced the original Bourne shell in the BSD versions of Unix released in the early 1990s.

basename is a standard computer program on Unix and Unix-like operating systems. When basename is given a pathname, it will delete any prefix up to the last slash ('/') character and return the result. basename is described in the Single UNIX Specification and is primarily used in shell scripts.

In computing, touch is a command used to update the access date and/or modification date of a computer file or directory. It is included in Unix and Unix-like operating systems, TSC's FLEX, Digital Research/Novell DR DOS, the AROS shell, the Microware OS-9 shell, and ReactOS. The command is also available for FreeDOS and Microsoft Windows.

dd is a command-line utility for Unix, Plan 9, Inferno, and Unix-like operating systems and beyond, the primary purpose of which is to convert and copy files. On Unix, device drivers for hardware and special device files appear in the file system just like normal files; dd can also read and/or write from/to these files, provided that function is implemented in their respective driver. As a result, dd can be used for tasks such as backing up the boot sector of a hard drive, and obtaining a fixed amount of random data. The dd program can also perform conversions on the data as it is copied, including byte order swapping and conversion to and from the ASCII and EBCDIC text encodings.

join is a command in Unix and Unix-like operating systems that merges the lines of two sorted text files based on the presence of a common field. It is similar to the join operator used in relational databases but operating on text files.

tr (Unix) Unix text formatting utility

tr is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. It is an abbreviation of translate or transliterate, indicating its operation of replacing or removing specific characters in its input data set.

wc (Unix) Unix command utility

wc is a command in Unix, Plan 9, Inferno, and Unix-like operating systems. The program reads either standard input or a list of computer files and generates one or more of the following statistics: newline count, word count, and byte count. If a list of files is provided, both individual file and total statistics follow.

nl is a Unix utility for numbering lines, either from a file or from standard input, reproducing output on standard output.

cmp (Unix)

In computing, cmp is a command-line utility on Unix and Unix-like operating systems that compares two files of any type and writes the results to the standard output. By default, cmp is silent if the files are the same; if they differ, the byte and line number at which the first difference occurred is reported. The command is also available in the OS-9 shell.

rm (Unix) Unix command utility

rm is a basic command on Unix and Unix-like operating systems used to remove objects such as computer files, directories and symbolic links from file systems and also special files such as device nodes, pipes and sockets, similar to the del command in MS-DOS, OS/2, and Microsoft Windows. The command is also available in the EFI shell.

yes (Unix) Unix command

yes is a command on Unix and Unix-like operating systems, which outputs an affirmative response, or a user-defined string of text, continuously until killed.

test is a command-line utility found in Unix, Plan 9, and Unix-like operating systems that evaluates conditional expressions. test was turned into a shell builtin command in 1981 with UNIX System III and at the same time made available under the alternate name [.

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 most recent release package available as of December 2016 was an open-source project, UnxUtils at SourceForge, with the latest binary release in March, 2007. The independent distribution included a main zip archive complemented by more recent updates, but the SourceForge project has no UnxUpdates.zip package. An alternative source of Unix-like utilities for Windows is GnuWin32; it has later versions of many programs, but requires supporting files in many cases.

In computing, which is a command for various operating systems used to identify the location of executables. The command is available in Unix and Unix-like systems, the AROS shell, for FreeDOS and for Microsoft Windows. The functionality of the which command is similar to some implementations of the type command. POSIX specifies a command named command that also covers this functionality.

dirname is a standard computer program on Unix and Unix-like operating systems. When dirname is given a pathname, it will delete any suffix beginning with the last slash ('/') character and return the result. dirname is described in the Single UNIX Specification and is primarily used in shell scripts.

The csplit command in Unix and Unix-like operating systems is a utility that is used to split a file into two or more smaller files determined by context lines.

References

  1. 1 2 "GNU 'shar' utilities". gnu.org. Free Software Foundation. Retrieved 8 December 2019.
  2. "sharchive". ftp.informatik.rwth-aachen.de. Retrieved 2024-01-02.
  3. Apple (1993-06-06). "Mac OS X shar(1) Man Page". Apple. Archived from the original on 2009-11-07. Retrieved 2009-11-07.
  4. "makeself "trap" command fix". Svn.icculus.org. 2000-11-20. Archived from the original on 2012-07-14. Retrieved 2011-08-30.
  5. uw-beave!jim (April 2, 1983). "Re: program to separate xlisp distribution files". Newsgroup:  net.sources. message-id:bnews.uw-beave.451. Retrieved March 27, 2017.
  6. "shar: a blast from the past". James Gosling: on the Java Road. Archived from the original on March 27, 2017. Retrieved 26 March 2017.
  7. An almost identical script, 'bundle', is described in "The UNIX Programming Environment", Kernighan and Pike, 1984, on page 97
  8. Dickey, Thomas E. "Comments on Shar/Utils". invisible-island.net.
  9. Native Win32 ports of some GNU utilities
  10. Michael Bednarek (9 June 1987). "shar (sort of) for VMS". Newsgroup:  comp.os.vms. Usenet:   1261@murdu.OZ . Retrieved 2008-02-09.
  11. Jim Gray (8 May 1988). "VMS_SHARE V6.0". Newsgroup:  comp.os.vms. Usenet:   880508-073131-5929@Xerox . Retrieved 2008-02-09.
  12. Andy Harper (6 July 1989). "VMS_SHARE version 7". Newsgroup:  comp.os.vms. Usenet:   8907061417.AA16991@ucbvax.Berkeley.EDU . Retrieved 2008-02-09.
  13. Andy Harper (5 July 1995). "Announcing VMS_SHARE 8.5". Newsgroup:  vmsnet.sources.d. Usenet:   1994Jul5.164105.3667@bay.cc.kcl.ac.uk . Retrieved 2008-02-09.
  14. "makeself - Make self-extractable archives on Unix".