Differences between revisions 22 and 23
Revision 22 as of 2022-06-20 20:44:11
Size: 3665
Editor: emanuele6
Comment: remove extra space
Revision 23 as of 2022-06-20 20:47:27
Size: 3663
Editor: emanuele6
Comment: actually, remove [] around %fmt since the table is describing that in bash, as opposed to ksh, a format specification cannot be used.
Deletions are marked like this. Additions are marked like this.
Line 12: Line 12:
||{n1..n2[..n3][%fmt]} ||Sequence expression with a printf format specification applied to each generated argument. || ||{n1..n2[..n3]%fmt} ||Sequence expression with a printf format specification applied to each generated argument. ||

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)




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


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:




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


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.


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