
AUnix shell is ashell that provides acommand-lineuser interface for aUnix-likeoperating system. A Unix shell provides acommand language that can be used eitherinteractively or for writing ashell script.[2] A user typically works within a Unix shell via aterminal emulator; however, direct access via serial hardware connections or aSecure Shell are common for server systems. Although use of a Unix shell is popular with some users, others prefer to use agraphical shell in awindowing system, such as those provided in desktopLinux distributions ormacOS, instead of a command-line interface (CLI).
A user may have access to multiple Unix shells with one configured to run by default when the userlogs in interactively. Thedefault selection is typically stored in a user's profile; for example, in the localpasswd file or in a distributed configuration system such asNIS orLDAP. A user may use other shellsnested inside the default shell.
A Unix shell may provide many features including:variable definition and substitution,command substitution,filename wildcarding,stream piping,control flow structures (condition-testing anditeration),working directory context, andhere document.
The first Unix shell was theThompson shell,sh, written byKen Thompson atBell Labs and distributed with Versions 1 through 6 of Unix, from 1971 to 1975.[3] Though rudimentary by modern standards, it introduced many of the basic features common to all later Unix shells, including piping, simple control structures usingif andgoto, and filenameGLOBbing. Though not in current use, it is still available as part of someAncient UNIX systems and is the default shell on currentFreeBSD systems.[citation needed]
It was modeled after theMultics shell, developed in 1965 by American software engineerGlenda Schroeder. Schroeder's Multics shell was itself modeled after theRUNCOM programLouis Pouzin showed to the Multics Team. The "rc" suffix on some Unix configuration files (e.g. ".bashrc" or ".vimrc"), is a remnant of the RUNCOM ancestry of Unix shells.[1][4]
ThePWB shell or Mashey shell,sh, was an upward-compatible version of the Thompson shell, augmented byJohn Mashey and others and distributed with theProgrammer's Workbench UNIX, circa 1975–1977. It focused on making shell programming practical, especially in large shared computing centers. It added shell variables (precursors ofenvironment variables, including the search path mechanism that evolved into $PATH), user-executable shell scripts, and interrupt-handling. Control structures were extended from if/goto to if/then/else/endif, switch/breaksw/endsw, and while/end/break/continue. As shell programming became widespread, these external commands were incorporated into the shell itself for performance.
But the most widely distributed and influential of the early Unix shells were theBourne shell and theC shell. Both shells have been used as the coding base and model for many derivative and work-alike shells with extended feature sets.[5]
TheBourne shell,sh, was a new Unix shell byStephen Bourne at Bell Labs.[6] Distributed as the shell for UNIX Version 7 in 1979, it introduced the rest of the basic features considered common to all the later Unix shells, includinghere documents,command substitution, more genericvariables and more extensive builtincontrol structures. The language, including the use of a reversed keyword to mark the end of a block, was influenced byALGOL 68.[7] Traditionally, the Bourne shell program name issh and its path in the Unix file system hierarchy is/bin/sh. But a number of compatible work-alikes are also available with various improvements and additional features. On many systems, sh may be asymbolic link orhard link to one of these alternatives:
ThePOSIX standard specifies its standard shell as a strict subset of theKorn shell, an enhanced version of the Bourne shell. From a user's perspective the Bourne shell was immediately recognized when active by its characteristic default command line prompt character, the dollar sign ($).
TheC shell,csh, was modeled on theC programming language, including the control structures and the expression grammar. It was written byBill Joy as a graduate student atUniversity of California, Berkeley, and was widely distributed withBSD Unix.[9][better source needed]
The C shell also introduced many features for interactive work, including thehistory andediting mechanisms,aliases,directory stacks,tilde notation,cdpath,job control andpath hashing. On many systems, csh may be asymbolic link orhard link toTENEX C shell (tcsh), an improved version of Joy's original version. Although the interactive features of csh have been copied to most other shells, the language structure has not been widely copied. The only work-alike isHamilton C shell, written by Nicole Hamilton, first distributed onOS/2 in 1988 and onWindows since 1992.[10]
Shells read configuration files in various circumstances. These files usually contain commands for the shell and are executed when loaded; they are usually used to set important variables used to find executables, like$PATH, and others that control the behavior and appearance of the shell. The table in this section shows the configuration files for popular shells.[11]
| Configuration file | sh | ksh | csh | tcsh | bash | zsh |
|---|---|---|---|---|---|---|
| /etc/.login | login | login | ||||
| /etc/csh.cshrc | yes | yes | ||||
| /etc/csh.login | login | login | ||||
| ~/.tcshrc | yes | |||||
| ~/.cshrc | yes | yes[a] | ||||
| /etc/ksh.kshrc | int. | |||||
| /etc/sh.shrc | int.[b] | |||||
| $ENV (typically~/.kshrc)[12] | int.[c][d] | int. | int.[e] | |||
| ~/.login | login | login | ||||
| ~/.logout | login | login | ||||
| /etc/profile | login | login | login | login[f] | ||
| ~/.profile | login | login | login[g] | login[f] | ||
| ~/.bash_profile | login[g] | |||||
| ~/.bash_login | login[g] | |||||
| ~/.bash_logout | login | |||||
| ~/.bashrc | int.+n/login | |||||
| /etc/zshenv | yes | |||||
| /etc/zprofile | login | |||||
| /etc/zshrc | int. | |||||
| /etc/zlogin | login | |||||
| /etc/zlogout | login | |||||
| ~/.zshenv | yes | |||||
| ~/.zprofile | login | |||||
| ~/.zshrc | int. | |||||
| ~/.zlogin | login | |||||
| ~/.zlogout | login |
Explanation:
Variations on the Unix shell concept that don't derive from Bourne shell or C shell include the following:[15]
Instead of inventing a new script language, we built a form entry system by modifying the Bourne shell, adding built-in commands as necessary.