# KornShell

KornShell (ksh) is a Unix shell which was developed by David Korn at Bell Labs in the early 1980s and announced at USENIX on July 14, 1983. The initial development was based on Bourne shell source code. Other early contributors were Bell Labs developers Mike Veach and Pat Sullivan, who wrote the Emacs and vi-style line editing modes' code, respectively. KornShell is backward-compatible with the Bourne shell and includes many features of the C shell, inspired by the requests of Bell Labs users.

## Features

KornShell complies with POSIX.2, Shell and Utilities, Command Interpreter (IEEE Std 1003.2-1992.) Major differences between KornShell and the traditional Bourne shell include:
* job control, command aliasing, and command history designed after the corresponding C shell features; job control was added to the Bourne Shell in 1989
* a choice of three command line editing styles based on vi, Emacs, and Gosling Emacs
* associative arrays and built-in floating-point arithmetic operations (only available in the ksh93 version of KornShell)
* dynamic search for functions
* mathematical functions
* process substitution and process redirection
* C-language-like expressions
* enhanced expression-oriented for and while loops
* dynamic extensibility of (dynamically loaded) built-in commands (since ksh93)
* reference variables
* hierarchically nested variables
* variables can have member functions associated with them
* object-oriented-programming (since ksh93t)
** variables can be objects with member (sub-)variables and member methods
** object methods are called with the object variable name followed (after a dot character) by the method name
** special object methods are called on: object initialization or assignment, object abandonment (unset)
** composition and aggregation is available, as well as a form of inheritance

## History

KornShell was originally proprietary software. In 2000 the source code was released under a license particular to AT&T, but since the ksh93q release in early 2005 it has been licensed under the Eclipse Public License. KornShell is available as part of the AT&T Software Technology (AST) Open Source Software Collection. As KornShell was initially only available through a proprietary license from AT&T, a number of free and open source alternatives were created. These include pdksh, mksh, Bash, and Z shell.
The functionality of the original KornShell, ksh88, was used as a basis for the standard POSIX.2, Shell and Utilities, Command Interpreter (IEEE Std 1003.2-1992).
Some vendors still ship their own versions of the older ksh88 variant, sometimes with extensions. ksh93 is maintained on GitHub.
As "Desktop KornShell" (dtksh), ksh93 is distributed as part of the Common Desktop Environment. This version also provides shell-level mappings for Motif widgets. It was intended as a competitor to Tcl/Tk.
The original KornShell, ksh88, became the default shell on AIX in version 4, with ksh93 being available separately.
UnixWare 7 includes both ksh88 and ksh93. The default Korn shell is ksh93, which is supplied as /usr/bin/ksh, and the older version is available as /usr/bin/ksh88. UnixWare also includes dtksh when CDE is installed.
The ksh93 distribution underwent a less stable fate after the authors left AT&T around 2012 at stable version ksh93u+. The primary authors continued working on a ksh93v- beta branch until around 2014. That work was eventually taken up primarily by Red Hat in 2017 (due to customer requests) and resulted in the eventual initial release of ksh2020 in the fall of 2019. That initial release (although fixing several prior stability issues) introduced breakage and compatibility issues. In March 2020, AT&T decided to roll back the community changes, stash them in a branch, and restart from ksh93u+, as the changes were too broad and too ksh-focused for the company to absorb into a project in maintenance mode. ksh2020 was released as a "major release for several reasons" such as removal of EBCDIC support, dropping support for binary plugins written for ksh93u+ and removal of some broken math functions, but has never been maintained or supported by AT&T (not even on its initial release date). The ksh2020 source code has received no commits since February 2020 and it was archived read only in October 2021.
Following the issues with the ksh2020 branch and its abandonment, a new repository was created in May 2020 for the ksh93u+m branch, based on the last stable AT&T release (ksh93u+ 2012-08-01) where bugfix development actively continues.

## Primary contributions to the main software branch

For the purposes of the lists below, the main software branch of KSH is defined as the original program, dating from July 1983, up and through the release of KSH2020 in late 2019. Continuing development of follow-on versions (branches) of KSH have split into different groups starting in 2020 and are not elaborated on below.

### Primary individual contributors

The following are listed in a roughly ascending chronological order of their contributions:
* David G. Korn (AT&T Bell Laboratories, AT&T Laboratories, and Google; and creator)
* Glenn S. Fowler (AT&T Bell Laboratories, AT&T Laboratories)
* Kiem-Phong Vo (AT&T Bell Laboratories, AT&T Laboratories)
* Adam Edgar (AT&T Bell Laboratories)
* Michael T. Veach (AT&T Bell Laboratories)
* Patrick D. Sullivan (AT&T Bell Laboratories)
* Matthijs N. Melchior (AT&T Network Systems International)
* Karsten-Fleischer (Omnium Software Engineering)
* Boyer-Moore
* Siteshwar Vashisht (Red Hat)
* Kurtis Raider

### Integration consultant

* Roland Mainz

### Primary corporate contributors

The following are listed in a roughly ascending chronological order of their contributions:
* AT&T Bell Laboratories
* AT&T Network Systems International
* AT&T Laboratories (now AT&T Labs)
* Omnium Software Engineering
* Oracle Corporation
* Google
* Red Hat

### Donated corporate resources

Besides the primary major contributing corporations (listed above), some companies have contributed free resources to the development of KSH. These are listed below (alphabetically ordered):
* Coverity
* GitHub
* Travis CI

## Variants

There are several forks and clones of KornShell:
* dtksh – a fork of ksh93 included as part of CDE.
* tksh – a fork of ksh93 that provides access to the Tk widget toolkit.
* oksh – a port of OpenBSD's variant of KornShell, intended to be maximally portable across operating systems. It was used as the default shell in DeLi Linux 7.2.
* loksh – a Linux port of OpenBSD's variant of KornShell, with minimal changes.
* mksh – a free implementation of the KornShell language, forked from OpenBSD pdksh. It was originally developed for MirOS BSD and is licensed under permissive (though not public domain) terms; specifically, the MirOS Licence. In addition to its usage on BSD, this variant has replaced pdksh on Debian, and is the default shell on Android.
* SKsh – an AmigaOS variant that provides several Amiga-specific features, such as ARexx interoperability. In this tradition MorphOS uses pdksh in its SDK.
* MKS Inc.'s MKS Korn shell – a proprietary implementation of the KornShell language from Microsoft Windows Services for UNIX (SFU) up to version 2.0; according to David Korn, the MKS Korn shell was not fully compatible with KornShell in 1998. In SFU version 3.0 Microsoft replaced the MKS Korn shell with a new POSIX.2-compliant shell as part of Interix.
* KornShell is included in UWIN, a Unix compatibility package by David Korn.
* /bin/sh in Doug Gwyn's (US Army BRL) System V on BSD package included Ron Natalie's version of the SVR2 /bin/sh that had both job control and command line editing. This was a contemporary of the original ksh at a time when it had not escaped AT&T. This was subsequently the /bin/sh that shipped with all the CMU Mach-derived systems.