Category:UNIX Shell Implementations: Difference between revisions

m
→‎Comparison table: Use nowiki tags for a literal [[
m (Proofreading, links)
m (→‎Comparison table: Use nowiki tags for a literal [[)
 
(6 intermediate revisions by one other user not shown)
Line 1:
{{implementation cat|UNIX Shell}}
 
There are many [[UNIX Shell]]s and most of them canbelong be categorized intoto two families. For purposes of the Rosette Code, all examples are in Bourne-compatible syntax. The other family of shells, with a markedly different syntax, are ''csh'' and it'sits ''tcsh'' (Tenex C Shell) "clone." Common Bourne compatible shells include the original [[Bourne Shell]] (''/bin/sh'' on most versions of [[UNIX]]), the [[GNU]] [[Bourne Again SHell]] (''bash'' --- which is linked to ''/bin/sh'' on many distributions of [[Linux]], making it their default shell), the [[Korn Shell]] (''ksh''), the [[Public Domain Korn SHell]] (''pdksh''), the [[Almquist SHell]] (''ash'') and the [[Debian Almquist SHell]] (''dash'') and the [[Z SHell]] (''zsh'').
 
== Bourne-compatible shells ==
Common Bourne compatible shells include
 
* the original [[Bourne Shell]] (''/bin/sh'' on most versions of [[UNIX]]),
* the [[GNU]] [[Bourne Again SHell]] (''bash'' --- which is linked to ''/bin/sh'' on many distributions of [[Linux]], making it their default shell),
* the [[Korn Shell]] (''ksh''),
* the [[Public Domain Korn SHell]] (''pdksh'' --- which is ''/bin/ksh'' on some systems, ''/bin/sh'' on [[OpenBSD]]),
* the [[MirBSD Korn Shell]] (''mksh'' -- which is ''/bin/sh'' on some systems)
* the [[Almquist SHell]] (''ash'' --- which is ''/bin/sh'' on some systems),
* the [[Debian Almquist SHell]] (''dash''),
* and the [[Z SHell]] (''zsh'').
 
=== Comparison table ===
{| class="wikitable"
! Feature
! Bourne ''sh''
! ''ash, dash''
! ''pdksh, mksh''
! ''bash''
|-
! Manual page
| [http://heirloom.sourceforge.net/sh/sh.1.html Heirloom sh]
|
* [http://netbsd.gw.com/cgi-bin/man-cgi?sh++NetBSD-current NetBSD sh]
* [http://man.cx/dash dash]
|
* [http://www.openbsd.org/cgi-bin/man.cgi?query=ksh&apropos=0&sektion=0&manpath=OpenBSD+Current&arch=i386&format=html OpenBSD ksh]
* [http://www.mirbsd.org/htman/i386/man1/mksh.htm mksh]
| [http://man.cx/bash bash]
|-
| <tt> `''command''`</tt>
| {{yes}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>''func''() { ''list''; }</tt>
| {{yes}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>[ -n "$''param''" ]</tt>
| {{yes}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>''PARAM''=''value''<br />export ''PARAM''</tt>
| {{yes}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>export ''PARAM''=''value''</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>local ''param''</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>${''param''##*/}<br />${''param''%/*}</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>ls ~</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>$(''command'')</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>$(( ''i = 2 + 3'' ))</tt>
| {{no}}
| {{yes}}
| {{yes}}
| {{yes}}
|-
| <tt>(( ''i = 2 + 3'' ))</tt>
| {{no}}
| {{no}}
| {{yes}}
| {{yes}}
|-
| <tt><nowiki>[[</nowiki> -n $''param'' ]]</tt>
| {{no}}
| {{no}}
| {{yes}}
| {{yes}}
|-
| <tt>function ''name'' { ''list''; }</tt>
| {{no}}
| {{no}}
| {{yes}}
| {{yes}}
|-
| <tt>${''array''[''2'']}</tt>
| {{no}}
| {{no}}
| {{yes}}
| {{yes}}
|-
| <tt>set -A ''array 11 22 33''</tt>
| {{no}}
| {{no}}
| {{yes}}
| {{no}}
|-
| <tt>''array''=(''11 22 33'')</tt>
| {{no}}
| {{no}}
| {{optional|mksh}}
| {{yes}}
|-
| <tt>$' \t\n'</tt>
| {{no}}
| {{no}}
| {{optional|mksh}}
| {{yes}}
|}
 
=== Portability notes ===
The original Bourne shell went through a number of revisions in the early years of UNIX, and support for some features varies considerably. By the time the SUSv3 (Single Unix Specification, version 3) features stabilized, all versions of the various Bourne-compatible shells should support a common set of features. This is denoted in Rosette Code examples with the phrase: "SUSv3" features. The Korn shell (originally written by David Korn of AT&T) and its "public domain" clone offer extensions (such as co-processes, and "associative arrays" --- called "hash arrays" by [[Perl]], "dictionaries" by [[Python]], "maps" by [[Lua]], etc).
 
Line 42 ⟶ 176:
 
==Comparison of various shells==
[http://athenawww.vvsumath.ruiitb.ac.in/resources/docsmanuals/unixUnix_Unleashed/unix_admVol_1/ch13.htm An excerpt] from "UNIX Unleashed, System Administrator's Edition", has a decent discussion of how to choose a shell. The article focuses on three areas: command line usage, shell scripting for personal use and shell scripting for others to use.