Terminal GuideTerminal Guide

Ksh

Korn Shell

Powerful shell combining features of sh and csh, popular in enterprise

POSIX CompliantReleased: 1983Official Site

Overview

The Korn Shell (ksh) was developed by David Korn at Bell Labs in 1983. It combines the best features of the Bourne shell and C shell, adding many improvements. Ksh is the default shell on many commercial Unix systems like AIX, HP-UX, and Solaris.

Quick Facts

Full NameKorn Shell
CategorySpecialized
POSIX CompliantYes
Config File.kshrc
Default OnAIX, HP-UX, Solaris
First Release1983

Who Should Use Ksh?

  • Enterprise Unix users - Default on AIX, HP-UX, Solaris
  • Legacy system admins - Maintaining existing ksh scripts
  • Advanced scripters - Powerful scripting features
  • POSIX-plus needs - POSIX with useful extensions

Installation

Install Korn Shell on various systems.

bash
# Install on macOS
brew install ksh

# Install on Debian/Ubuntu
sudo apt install ksh

# Install on Fedora
sudo dnf install ksh

# Install ksh93 (original AT&T version)
# Now open source at https://github.com/ksh93/ksh

# Set as default shell
chsh -s $(which ksh)

Basic Usage

Ksh scripting features.

bash
#!/bin/ksh

# Variables with types
typeset -i num=42      # Integer
typeset -l lower="ABC" # Lowercase
echo "$lower"          # abc

# Associative arrays (ksh93)
typeset -A colors
colors[red]="#FF0000"
colors[green]="#00FF00"
echo "${colors[red]}"

# Coprocesses
cmd |&
read -p line  # Read from coprocess

# Built-in arithmetic
(( result = 5 + 3 ))
echo "$result"

# Pattern matching
[[ "hello" == h* ]] && echo "Match!"

Configuration

Ksh configuration files.

bash
# ~/.kshrc - Interactive shell configuration
# Set ENV to point to this file in ~/.profile:
# export ENV=~/.kshrc

# Custom prompt
PS1='$(whoami)@$(hostname):$(pwd)$ '

# Aliases
alias ll='ls -la'
alias h='fc -l'  # History

# Enable vi mode (default) or emacs mode
set -o vi
# set -o emacs

# History settings
HISTSIZE=1000
HISTFILE=~/.ksh_history

Key Features

Associative Arrays

Hash tables built into the shell (ksh93)

Floating Point

Native floating-point arithmetic support

Coprocesses

Two-way communication with background processes

Discipline Functions

Custom getter/setter for variables

FAQ

What is the difference between ksh88 and ksh93?

ksh93 added many features including associative arrays, floating-point math, and compound variables. ksh88 is older but still common on legacy systems.

Is ksh still relevant today?

Yes, especially in enterprise Unix environments. Many critical systems run ksh scripts, and ksh93 is now open source and actively maintained.

Summary

Key takeaways for Ksh:

  • Default shell on commercial Unix systems (AIX, HP-UX, Solaris)
  • Advanced features like associative arrays and floating-point math
  • Excellent backward compatibility with Bourne shell
  • Now open source (ksh93)

Official Documentation

For authoritative information, refer to the official documentation:

Written by Dai AokiPublished: 2026-01-20

Related Articles