Differences between revisions 16 and 21 (spanning 5 versions)
Revision 16 as of 2013-08-14 11:16:31
Size: 3492
Editor: host-84-82
Comment: spelling fix
Revision 21 as of 2022-06-20 20:43:14
Size: 3666
Editor: emanuele6
Comment: the format specification is optional in sequence expressions.
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
||'''Feature'''||'''Description'''||
||{n1..n2[ ..n3]%fmt}||Sequence expression with a printf format specification applied to each generated argument.||
||{n[,m]}(pattern-list)||ERE-style arbitrary quantification of extended globs.||
||varname=([typeset [options]] assignment ...)||Compound and nested variable assignment. Similar to C structs. Bash arrays can only be homogenous datatypes.||
||%n$ and *n$||SUS printf extensions for addressing individual arguments||
||Floating point numeric types|| - ||
||print (built-in)||allows for reliably printing arbitrary characters.||
||'''Feature''' ||'''Description''' ||
||{n1..n2[ ..n3][%fmt]} ||Sequence expression with a printf format specification applied to each generated argument. ||
||{n[,m]}(pattern-list) ||ERE-style arbitrary quantification of extended globs. ||
||varname=([typeset [options]] assignment ...) ||Compound and nested variable assignment. Similar to C structs. Bash arrays can only be homogenous datatypes. ||
||%n$ and *n$ ||SUS printf extensions for addressing individual arguments ||
||Floating point numeric types ||- ||
||print (built-in) ||allows for reliably printing arbitrary characters. ||


Line 20: Line 23:
||'''Feature''' ||'''Description''' ||
||;;& ||case...esac delimiter, like ;&, but additionally only continue if the next pattern list matches ||
||pushd/popd/dirs/~[+|-]N ||Ksh93 has external functions in /usr/share/ksh/fun to provide the pushd, popd and dirs commmands. Tilde expansion supports only one level. ||
Line 21: Line 27:
||'''Feature'''||'''Description'''||
||;;&||case...esac delimiter, like ;&, but additionally only continue if the next pattern list matches||
||pushd/popd/dirs/~[+|-]N|| Ksh has no directory stack. Tilde expansion supports only one level.||

Line 26: Line 31:
Line 28: Line 34:
 * $SECONDS in ksh93 has millisecond precision. Bash only counts seconds and has no high-resolution timestamp mechanism.  * $SECONDS in ksh93 has millisecond precision. Bash only counts seconds and had no high-resolution timestamp mechanism until version 5.0 where $EPOCHSECONDS and $EPOCHREALTIME were introduced.

Korn Shell

The KornShell is a reimplementation of the Bourne shell. It is downward compatible, but adds many features intended to simplify programming. Most of the features are part of POSIX shell too, and therefore are available on any POSIX compliant system. In the universe of shells it might be said that the Ksh family is Bash's closest relative. Bash implements much of the Korn shell's functionality and both share many common conventions. If care is taken it is possible to write polyglot code portable between these shells while still using a superset of POSIX sh features. For example, the (( arithmetic keyword. Incompatibilities do exist in many shared features. For instance, the Bash builtin read -a is equivalent to Ksh's read -A.

ksh88, and its successor ksh93, is David Korn's "original" Korn shell. Now part of the ast-open package since being open-sourced by AT&T in 2000 under the CPL license, ksh93 is still actively developed and is probably what someone is referring to if using the term "ksh" without further qualification. It is also currently the most featureful. Additionally, there exist several variants under the name "Korn shell". Some of the most common and actively developed include mksh - the MirBSD Korn shell, and pdksh ("Public Domain Korn Shell") - intended to be ksh93's open-source replacement while it was still proprietary software.

The Korn shell (either ksh88 or ksh93, depending on the age of the system) is a standard part of any modern (commercial) Unix system, e.g. Solaris, AIX, HP-UX. pdksh is often available on BSD or GNU/Linux systems, and a growing number of GNU/Linux systems now offer ksh93, either instead of or in addition to pdksh.

Incomplete list of ksh93 features with no direct BashShell equivalent (as of version 4.2), (i.e., no same feature with same syntax by a different name). Some are trivial to accomplish in Bash by other means:

(Below is a work in progress)

Feature

Description

{n1..n2[ ..n3][%fmt]}

Sequence expression with a printf format specification applied to each generated argument.

{n[,m]}(pattern-list)

ERE-style arbitrary quantification of extended globs.

varname=([typeset [options]] assignment ...)

Compound and nested variable assignment. Similar to C structs. Bash arrays can only be homogenous datatypes.

%n$ and *n$

SUS printf extensions for addressing individual arguments

Floating point numeric types

-

print (built-in)

allows for reliably printing arbitrary characters.

Incomplete list of BashShell features with no direct ksh93 equivalent:

Feature

Description

;;&

case...esac delimiter, like ;&, but additionally only continue if the next pattern list matches

pushd/popd/dirs/~[+|-]N

Ksh93 has external functions in /usr/share/ksh/fun to provide the pushd, popd and dirs commmands. Tilde expansion supports only one level.

Other important notes:

  • Bash co-processes are considerably different and weren't available in Bash at all until version 4. (process |& versus the coproc keyword)

  • Ksh has always executed the last command of a pipeline in the parent shell's environment. Bash has always used a subshell for all pipeline commands. Bash 4.2 adds the lastpipe shopt option, but it isn't enabled by default.

  • $SECONDS in ksh93 has millisecond precision. Bash only counts seconds and had no high-resolution timestamp mechanism until version 5.0 where $EPOCHSECONDS and $EPOCHREALTIME were introduced.


CategoryShell

KornShell (last edited 2022-06-20 20:47:27 by emanuele6)