Korn shell (ksh)
What is Korn shell (ksh)?
The Korn shell (ksh) is an operating system (OS) command shell that was developed for Unix by David Korn at Bell Labs. A shell is a command execution program, or command interpreter, that interfaces with an OS to run commands or to run scripts that contain commands. The Korn shell is one of many types of command shells available for different operating systems.
The Korn shell, also referred to as KornShell, was introduced in 1983 and included its own scripting language. It combined many of the best features of the two most widely used shells at the time: the C shell (csh) developed by Bill Joy at the University of California, Berkley, and the Bourne shell developed by Stephen Bourne at Bell Labs. The Korn shell was more efficient than the other two and offered better performance.
The Korn shell is highly compatible with the Bourne shell. The Korn shell uses the same dollar sign ($) prompt for user input, and most scripts written for the Bourne shell can run in the Korn shell. Users familiar with the Bourne shell typically have little problem switching to the Korn shell. The Korn shell is also easier to use, which is why inexperienced users often prefer the Korn shell over the Bourne shell.
Korn shell history and improvements
After its introduction in 1983, the Korn shell was updated in 1986, then in 1988, and again in 1993. The 1993 version represented a major rewrite of the 1988 version. In addition to improving performance and security, the 1993 edition also added or enhanced several important features, including the following:
- Extended input/output (I/O) capabilities and greater support for arrays.
- Improved command history support.
- In-line editing though EMACS-TC or vi functions.
- Enhanced support for shell functions and aliases.
- Improved substring capabilities and pattern matching.
- Improved debugging and job control functionality.
- Greater extensibility.
At the time, the 1993 version (ksh93) was owned by both Lucent and AT&T and was considered proprietary software. However, the Korn source code was eventually released under the Eclipse Public License and made available as open source software.
The last stable release (93u+ 2012-08-01) is available on GitHub, where it continues to receive bug fixes and patches. The releases that incorporate these fixes are referred to as reboots and include the letter "m" after the plus sign, as in 93u+m. The reboots include fixes and patches from Solaris, Red Hat and OpenSUSE, along with contributions from the development community. The latest reboot to incorporate these fixes is ksh 93u+m/1.0.4.
Ksh2020 and beyond
Between 2017 and 2020, a group of developers attempted to revitalize the Korn shell, an effort dubbed ksh2020. Their goal was to extensively refactor one of the beta versions (93v-) to address bug and stability issues. However, the project never got off the ground and was eventually abandoned.
The Korn shell is still in use today on both Unix and Unix-like systems such as Linux and macOS, although many users now rely on Bash and other command shells instead of Korn. For example, Bash is currently the default shell in many Linux systems, such as Ubuntu and Fedora, and until 2019, it was also the default shell in macOS (the default shell is now zsh). Despite this trend, the Korn shell is still being used and is the default shell on systems such as IBM AIX.
Learn shell scripts in this sys admin's guide to automation and explore advanced shell scripting for IT ops professionals.