Category:UNIX Shell Implementations: Difference between revisions

Content added Content deleted
No edit summary
(Fixed a few spelling mistakes and readability)
Line 3: Line 3:
There are many [[UNIX Shell|UNIX Shells]] and most of them can be categorized into 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's ''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'').
There are many [[UNIX Shell|UNIX Shells]] and most of them can be categorized into 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's ''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'').


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 stablized, 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).
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).


Note that even when using a common subset of supported features there are subtle implementation differences, and in some cases parsing bugs, which can affect the portability of shell script examples. For example in ''bash'' before version 2.0 the following was tolerated:
Note that even when using a common subset of supported features there are subtle implementation differences, and in some cases parsing bugs, which can affect the portability of shell script examples. For example in ''bash'' versions before 2.0 the following was tolerated:


{ echo foo; echo bar } ## Bug!!!
{ echo foo; echo bar } ## Bug!!!


... though this is technically a bug in the language parsing (The braces used for command grouping are not delimiters in the same class as semicolons nor parentheses; so this example is ambiguous because ''echo }'' (outside of any command grouping) should work the same as ''echo "}"'' --- but in bash 1.x it behave inconsistently). In ''bash'' versions newer than 2.0 this was fixed and the follow is required:
... though this is technically a bug in the language parsing (The braces used for command grouping are not delimiters in the same class as semicolons nor parentheses; so this example is ambiguous because ''echo }'' (outside of any command grouping) should work the same as ''echo "}"'' --- but in bash versions 1.x it behaves inconsistently). In ''bash'' versions newer than 2.0 this was fixed and the following is required:


{ echo foo; echo bar; } ## Note the required semicolon
{ echo foo; echo bar; } ## Note the required semicolon