The Korn Shell (executable binary ksh) was engineered in the early 1980s by computer scientist David Korn at AT&T Bell Laboratories. Formally presented at the 1983 USENIX conference, the Korn Shell was born out of a critical Unix need: combine the bulletproof, POSIX-standard scripting architecture of the Bourne Shell (sh) with the rich, interactive terminal ergonomics of the C Shell (csh) into a single, cohesive, high-performance binary.
Unlike the C Shell—which broke compatibility with Bourne scripts—the Korn Shell is 100% upward-compatible with the Bourne Shell. Any valid sh script runs flawlessly inside ksh without modification. For interactive users, the default unprivileged prompt character remains the standard dollar sign ($), switching to the hash sign (#) for root.
Throughout Unix history, the Korn Shell evolved through two historic official versions and several popular open-source derivatives:
| Variant / Version | Key Architecture & Enterprise Role |
|---|---|
| ksh88 (1988) | The foundational version standardized as the bedrock of the POSIX.2 Shell and Utilities standard (IEEE 1003.2). Adopted as the default system shell in commercial enterprise Unix platforms: IBM AIX, HP-UX, and Sun Solaris. |
| ksh93 (1993–Present) | A massive, ground-up architectural rewrite written in C. Introduced native floating-point math, true associative arrays, discipline functions, compound hierarchical structures, and advanced regular expression pattern manipulation. Later open-sourced under the Eclipse Public License. |
| pdksh (Public Domain ksh) | An independent open-source recreation created for early Linux and BSD distributions when AT&T's official ksh was still under proprietary licensing. |
| mksh (MirBSD Korn Shell) | The modern, actively maintained successor to pdksh. Renowned for its extreme security, tiny footprint, and clean code. Notably serves as the default system shell inside the Android Open Source Project (AOSP) terminal! |
Ksh introduced computational paradigms that later shells (such as GNU Bash and Zsh) borrowed and popularized:
| Feature Innovation | Syntax / Notation | Technical Advantage |
|---|---|---|
| Native Arithmetic Evaluation | (( x = 12 * 45 ))let "y = x + 10" |
Performs high-speed math directly in C memory without forking slow external sub-processes (like expr or bc). Supports decimal floating-point numbers in ksh93! |
| Associative Arrays (Hash Tables) | typeset -A capitalscapitals[USA]="Washington" |
Allows key-value dictionary mappings natively inside shell scripts. |
| Ksh Co-Processes | daemon_script.sh |&print -p "request"read -p response |
Launches a background process with a bi-directional two-way pipe, allowing synchronous question-and-answer communication between parent and child scripts. |
| Advanced String Trimming | ${path#*/}, ${path%%/*} |
Blazing-fast prefix and suffix removal from strings without calling external sed or awk. |
| Strict Variable Typing | typeset -u text (uppercase)typeset -l name (lowercase)typeset -i num (integer) |
Enforces automatic string normalization and data types upon assignment. |
Many BCA and computer science students wonder: "Why do Wall Street trading desks, telecom billing engines, and enterprise ERP systems on IBM AIX and Oracle Solaris still specify ksh?"
The answer lies in execution speed and strict backward compatibility. Because ksh93 implements string parsing, regular expressions, and floating-point math internally inside the shell process, batch processing jobs that loop millions of times run 5x to 20x faster in ksh than in older shell architectures that fork hundreds of thousands of independent sub-processes.
Let us install ksh and test its advanced arithmetic, typed variables, and associative arrays:
# Install on Ubuntu / Debian:
sudo apt update && sudo apt install ksh -y
# Install on RHEL / Fedora / Rocky Linux:
sudo dnf install ksh -y
# Verify installed ksh version:
ksh --version 2>&1 || ksh -c 'echo ${KSH_VERSION}'
# Launch ksh:
ksh
# Enable Vi-style command line editing mode:
set -o vi
# (Press Esc, then 'k' to scroll back through history, or 'h/l' to move cursor!)
# Perform native floating point arithmetic (ksh93):
val=$(( 355.0 / 113.0 ))
print "Approximation of Pi: $val"
# Prints: Approximation of Pi: 3.1415929203539823
Create a script named inventory.ksh:
#!/bin/ksh
# Korn Shell Script demonstrating typeset and associative arrays
# Enforce uppercase string normalization automatically:
typeset -u SERVER_NAME
SERVER_NAME="production-db-01"
print "Normalized Server: $SERVER_NAME" # Prints: PRODUCTION-DB-01
# Declare an Associative Array (Hash Table):
typeset -A port_map
port_map[HTTP]=80
port_map[HTTPS]=443
port_map[SSH]=22
port_map[DNS]=53
# Iterate through keys and values:
print "Enterprise Port Mappings:"
for service in "${!port_map[@]}"; do
print "Service: $service → Port: ${port_map[$service]}"
done
chmod +x inventory.ksh
./inventory.ksh
| Feature Dimension | Bourne Shell (sh) |
C Shell (csh) |
Korn Shell (ksh) |
|---|---|---|---|
| Original Creator | Stephen Bourne (1979) | Bill Joy (1978) | David Korn (1983) |
| Bourne Compatibility | Native / Standard | Incompatible | 100% Upward Compatible |
| Interactive Job Control | No | Yes (Ctrl+Z, jobs) |
Yes (Ctrl+Z, jobs) |
| Native Arithmetic | External (expr required) |
Yes (@ x = 5) |
Yes ((( x = 5 * 2 )), floats in ksh93) |
| Associative Arrays | No | No | Yes (typeset -A) |
| Co-Processes | No | No | Yes (|&, print -p) |
sh) with the interactive user conveniences of the C Shell (csh), while introducing advanced programming capabilities like built-in arithmetic and arrays.
|&) that maintains a two-way communication channel with the parent shell. The parent can send input to the co-process using print -p and read output back using read -p without creating temporary files or named pipes.
$) as its prompt (identical to the Bourne Shell and Bash), while for the root administrative superuser, it switches to the hash sign (#).
David Korn's innovations set the gold standard for high-performance scripting. In the next tutorial, we explore the undisputed king of modern Linux command lines: Class 28: GNU Bash Shell (Bourne Again Shell).