KornShell, usually invoked as ksh, is a Unix command interpreter and scripting language created by David Korn at Bell Labs in the early 1980s, combining the scripting syntax of the Bourne shell with interactive features borrowed from the C shell. On Linux, it is an optional shell installed from distribution packages, valued mainly for running legacy enterprise scripts and for its strict, fast, standards-oriented behavior.
KornShell matters beyond its own user base because much of its design became the POSIX shell standard. Features that Bash and Zsh users take for granted, such as $(...) command substitution, arithmetic expansion and command-line editing modes, were popularized or first standardized through ksh.
How KornShell evolved into its current versions
KornShell exists in several distinct implementations, and knowing which one is installed explains most behavioral differences. The original ksh88 became the reference for the POSIX shell specification, while ksh93 added floating-point arithmetic, associative arrays, compound variables and a built-in library model. Because AT&T code was long proprietary, free clones appeared, most notably the Public Domain Korn Shell (pdksh) and its descendant mksh.
The table below summarizes the main variants an administrator may meet on Linux and other Unix systems.
| Implementation | Origin | Typical use today |
|---|---|---|
| ksh88 | Bell Labs, 1988 | Basis of POSIX sh; found on older commercial Unix |
| ksh93 | AT&T Research, 1993 onward | Default ksh package on most Linux distributions |
| ksh93u+m | Community maintenance fork | Actively maintained ksh93 with bug fixes |
| pdksh | Public domain clone | Historical; replaced by successors |
| mksh | MirBSD Korn Shell | Android system shell and lightweight systems |
| OpenBSD ksh | pdksh derivative | Default user shell on OpenBSD |
After AT&T released ksh93 under an open source license, development stalled for years, and a short-lived rewrite was abandoned. The ksh93u+m project now carries the original code forward, and current Linux packages generally ship it as /bin/ksh.
Core features of the KornShell language
KornShell provides a full programming language inside the shell, which reduces the need to call external utilities such as expr, awk or sed for routine work. Its built-in arithmetic with `(( ))`, typed variables via `typeset`, and pattern matching with `[[ ]]` let scripts run faster because fewer processes are created.
- Command-line editing in vi or emacs mode, enabled with
set -o viorset -o emacs. - Command history stored in a file named by
HISTFILE, with thefcbuilt-in for editing and re-running commands. - Indexed and associative arrays in ksh93, declared with
typeset -aandtypeset -A. - Coprocesses started with
|&, allowing a script to exchange data with a background process throughprint -pandread -p. - Discipline functions in ksh93 that run code when a variable is read or assigned.
- Floating-point arithmetic in ksh93, which Bash lacks without external tools.
The print built-in is a KornShell idiom that avoids the portability problems of `echo`, whose handling of backslashes differs between systems. Interactive startup is controlled by the `ENV` variable, which names a file, conventionally ~/.kshrc, read by every interactive shell, while login shells first read /etc/profile and ~/.profile.
KornShell compared with Bash and Zsh
KornShell, Bash and Zsh share a common Bourne-family syntax, so simple scripts often run unchanged in all three, but their priorities differ. Bash dominates Linux as the default login shell, Zsh focuses on interactive comfort, and ksh93 emphasizes execution speed and language features for scripting.
| Aspect | ksh93 | Bash | Zsh |
|---|---|---|---|
| Default on Linux | Rarely | Usually | Rarely; default on macOS |
| Floating-point math | Built in | Not available | Built in |
| Associative arrays | Yes | Yes, since 4.0 | Yes |
| Subshell for last pipe stage | No; runs in current shell | Yes, unless lastpipe is set | No |
| Interactive extras | Basic editing and history | Moderate | Extensive completion and themes |
| Script startup speed | Fast | Moderate | Moderate |
One practical difference surprises many migrating users: in KornShell, the last command of a pipeline runs in the current shell, so command | read var leaves var set afterward. In Bash, the same construct sets the variable inside a subshell and the value is lost unless the lastpipe option is enabled.
Using KornShell on a Linux system
Installing KornShell on Linux is a single package operation, after which scripts select it through a shebang line such as #!/bin/ksh or #!/usr/bin/env ksh. A user can make it the login shell with chsh -s /bin/ksh, provided the path is listed in /etc/shells.
The following decision table helps choose when ksh is the right tool rather than Bash or a plain POSIX shell.
| Situation | Recommended shell | Reason |
|---|---|---|
| Migrating scripts from AIX, Solaris or HP-UX | ksh93 | Those systems used ksh as the default shell |
| New script for many Linux hosts | Bash or POSIX sh | Bash is preinstalled almost everywhere |
| Heavy arithmetic in a shell script | ksh93 | Native floating-point avoids calls to bc |
| Embedded or minimal system | mksh or dash | Small binaries with low memory use |
| Daily interactive work | Zsh or Bash | Richer completion and plugin ecosystems |
Before relying on ksh-specific features, check the installed version with echo ${.sh.version} in ksh93 or ksh --version. Scripts meant for broad portability should avoid ksh93-only syntax such as compound variables and stick to the POSIX subset that every Bourne-family shell supports.
Limitations and common pitfalls of KornShell
The biggest operational risk with KornShell is assuming that every `ksh` is the same program. A script written for ksh93 may fail under mksh or OpenBSD ksh, which do not implement floating-point arithmetic, compound variables or several ksh93 built-ins.
| Symptom | Likely cause | Fix |
|---|---|---|
| Script works on AIX but fails on Linux | ksh88 versus ksh93 differences | Test under ksh93 and adjust deprecated constructs |
| Arithmetic error on decimal values | Running under mksh or pdksh | Install ksh93 or use awk for decimals |
~/.kshrc settings ignored | `ENV` variable not set | Export ENV=$HOME/.kshrc in ~/.profile |
| Bash script misbehaves under ksh | Bash-only syntax such as {1..5} assumptions | Rewrite with portable loops or keep Bash |
| Function variables leak to caller | POSIX-style function definition | Use function name { } syntax for local scope |
Another subtle point concerns function scoping. In ksh93, only functions declared with the function keyword get local variables through typeset; functions written as name() { } follow POSIX rules and share variables with the caller. Finally, ksh offers a smaller interactive ecosystem than Zsh or Bash, with fewer completion scripts and community frameworks.
Explained without jargon
A shell is the program that reads the commands you type and tells the computer what to do. KornShell is one of these programs, created at Bell Labs decades ago. It sits in the same family as Bash, the shell most Linux users meet first, and it understands mostly the same commands.
Its special strength is writing automated scripts that run quickly and reliably. Many large companies built years of automation on it, so it is still installed today to keep those scripts working. Think of it as an experienced older sibling of Bash: less fashionable, but dependable and fast.
A typical use case
A bank is moving its nightly batch jobs from an aging AIX server to Red Hat Enterprise Linux. The jobs consist of about 300 KornShell scripts that move files, check totals and load data into a database. Rewriting them in Bash would take months and introduce risk, so the team installs the ksh package, which provides ksh93u+m, and keeps the #!/bin/ksh shebang lines unchanged.
Testing reveals that around 15 scripts rely on ksh88 behavior, such as old-style arithmetic and obsolete options, and these are corrected in a week. The rest run unmodified, and several jobs finish faster because ksh93 handles decimal calculations internally instead of calling bc. The migration completes on schedule with the existing automation intact.