Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Unix shell

From Wikipedia, the free encyclopedia
Command-line interpreter for Unix operating system
tcsh and sh shell windows on aMac OS X Leopard[1] desktop

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.

History

[edit]

Early shells

[edit]

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]

Bourne shell

[edit]

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 ($).

C shell

[edit]

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]

Configuration files

[edit]

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 fileshkshcshtcshbashzsh
/etc/.loginloginlogin
/etc/csh.cshrcyesyes
/etc/csh.loginloginlogin
~/.tcshrcyes
~/.cshrcyesyes[a]
/etc/ksh.kshrcint.
/etc/sh.shrcint.[b]
$ENV (typically~/.kshrc)[12]int.[c][d]int.int.[e]
~/.loginloginlogin
~/.logoutloginlogin
/etc/profileloginloginloginlogin[f]
~/.profileloginloginlogin[g]login[f]
~/.bash_profilelogin[g]
~/.bash_loginlogin[g]
~/.bash_logoutlogin
~/.bashrcint.+n/login
/etc/zshenvyes
/etc/zprofilelogin
/etc/zshrcint.
/etc/zloginlogin
/etc/zlogoutlogin
~/.zshenvyes
~/.zprofilelogin
~/.zshrcint.
~/.zloginlogin
~/.zlogoutlogin

Explanation:

  • blank means a file is not read by a shell at all.
  • "yes" means a file is always read by a shell upon startup.
  • "login" means a file is read if the shell is a login shell.
  • "n/login" means a file is read if the shell is not a login shell.
  • "int." means a file is read if the shell is interactive.
  1. ^only if~/.tcshrc not found
  2. ^Newer versions of the Bourne Shell only
  3. ^Available on systems that support the "User Portability Utilities option"; value of the variable must be anabsolute path, and it is ignored "if the user's real and effective user IDs or real and effective group IDs are different."[13]
  4. ^$ENV is$HOME/.shrc in newer versions of the Bourne Shell
  5. ^Same behavior assh, but only if invoked assh (bash 2+) or, since bash 4.2, also if invokedexplicitly in POSIX compatibility mode (with options--posix or-o posix).[14]
  6. ^abOnly in sh/ksh compatibility mode (when invoked as bash, sh, ksh)
  7. ^abcThe first readable file in order of~/.bash_profile,~/.bash_login and~/.profile; and only~/.profile if invoked assh or, as of at least Bash 4.2, if invokedexplicitly in POSIX compatibility mode (with options--posix or-o posix)

Other shells

[edit]

Variations on the Unix shell concept that don't derive from Bourne shell or C shell include the following:[15]

See also

[edit]

References

[edit]
  1. ^abTom Van Vleck (1995-02-05)."Unix and Multics". Multicians.org. Retrieved2012-08-14.
  2. ^Bourne, Stephen R. (October 1983)."The Unix Shell".BYTE. p. 187. Retrieved30 January 2015.
  3. ^"V6 Thompson Shell Port - History". V6shell.org. Retrieved2012-08-14.
  4. ^Louis Pouzin (2000-11-25)."The Origin of the Shell". Multicians.org. Retrieved2012-08-14.
  5. ^Nikolai Bezroukov (2015-08-13)."Introduction to the Unix shell history". Softpanorama. Archived fromthe original on 2022-06-08. Retrieved2016-08-21.
  6. ^Bourne, Stephen (2009-03-05)."The A-Z of Programming Languages: Bourne shell, or sh" (Interview). Interviewed by Howard Dahdah.Computerworld. Retrieved2022-08-16.
  7. ^"Re: Late Bloomers Revisited". Retrieved20 September 2014.
  8. ^Korn, David G. (October 26, 1994),"ksh - An Extensible High Level Language",Proceedings of the USENIX 1994 Very High Level Languages Symposium, USENIX Association, retrievedFebruary 5, 2015,Instead of inventing a new script language, we built a form entry system by modifying the Bourne shell, adding built-in commands as necessary.
  9. ^Harley Hahn."Unix/Linux Timeline".Harley Hahn's Guide to Unix and Linux.
  10. ^"Hamilton C shell for Windows Release Notes 4.0". Retrieved20 September 2014.
  11. ^"Different UNIX Shells". unixnote.com. 2010. Archived fromthe original on 2016-04-03. Retrieved2016-08-21.
  12. ^Harley Hahn."Exercises and Answers for Chapter 14... Using The Shell: Initialization Files".Harley Hahn's Guide to Unix and Linux.
  13. ^"Shell Command Language".opengroup.org. Retrieved15 June 2015.
  14. ^"Bash Reference Manual: Bash Startup Files".gnu.org. Retrieved15 June 2015.
  15. ^"FreeBSD Ports: Shells". Freebsd.org. 2014-03-30. Archived fromthe original on 2021-01-12. Retrieved2014-04-05.
Operating
systems
BSD
Linux
System V
Other
Compatibility
layers
Retrieved from "https://en.wikipedia.org/w/index.php?title=Unix_shell&oldid=1320651818"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp