[EnglishFrontPage] [TitleIndex] [WordIndex

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 it's 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

Ksh has no directory stack. Tilde expansion supports only one level.

Other important notes:


CategoryShell


2012-07-01 04:09