Kph (Korn shell)

From Bauman National Library
This page was last modified on 1 June 2016, at 17:09.
Korn Shell
Paradigm imperative , scripting
Designed by David Korn
First appeared 1983
License Common Public License (AT&T ksh), mostly public domain with some GPL (pdksh), proprietary (dtksh), MirOS Licence (mksh)
Influenced by
Bourne Shell, C Shell

Korn Shell (ksh) — UNIX shell. Developed by David Korn in 1983. Ksh saves full backward-compatible with the Bourne shell and includes a number of C Shell functions. The main advantage of Korn Shell is a possibility of using it as a programming language.

General characteristics

  • interactive command language for high-level programing
  • platform-independent
  • matching the POSIX standard
  • working with scripts


Default login shell

  • AIX - proprietary UNIX-based operating system developed by IBM
  • HP_UX - proprietary UNIX-based operating system developed by Hewlett-Packard

Default script shell

  • Open Solaris — open source operating system based on Solaris created by Sun Microsystems

Korn Shell also uses in QNX — commercial Unix-like real-time operating system designed for embedded systems. According to Kornshell, 80% AT&T Bell Laboratories clients uses Korn Shell.


Korn Shell was designed and developed in 1983 by David Korn at AT&T Bell Labs. Other contributors were Bell Labs developers. Before 2000 Korn Shell was AT&T proprietary software. Ksh88 is original version of Korn Shell. Ksh93 is extended version of Korn Shell, it is still maintained by its authors.

New functionality of ksh93

  • Extended arithmetic operations
  • Compound variables (structure analog) and discipline functions (method analog)
  • Associative arrays
  • Variable name references
  • Parameter expansions
  • Function environments (namespace analog)
  • Reserved variables .sh and built-in commands
  • Command history
  • No function and aliases export with built-in commands

Next versions ksh93

  1. Ksh93t
  2. Ksh93t+
  3. Ksh93u — last version, released at 8/02/2011.
  4. Ksh93v — beta-verson

Functionality of ksh93t+

Interactive features

  • Scripts
  • Redirect streams to file descriptors.
  • Support Unicode
  • Command name completion and promt
  • Command history and completion using history
  • Extended command line interface by using variables $PS1
  • Command aliasing
  • Job control
  • Hotkeys

Programming features

  • Functions
  • Exception handling
  • Search and replace on variable substitutions
  • Variable name references
  • Functions with variable number of parameters
  • Default arguments in functions
  • Custom types
  • Eval function to execute something
  • Pseudo-random number generation
  • Associative arrays
  • Built-in floating point arithmetic operations
  • Dynamic extensibility of built-in commands
  • Ability to use the shrcomp compiler for byte-code
  • Built-in regular expressions and patterns
  • Compound variables (structure analog) and discipline functions (method analog)
  • Function environments (namespace analog)
  • Reserved variables .sh and built-in commands
  • Command history

Inter-process communication

  • Transfer bytes by pipes including serialized objects
  • Command substitution (output of one command can be used as arguments to another)
  • Process substitution if system supports /dev/fd/<n>
  • Support using TCP/UDP connections as streams and SCTP client


Example of using compound variable

Variable initialization

now = "May 20 2001 19:44:57"
now.hour = 19
now.minute = 44

Variable using

$ print ${now.hour}
$ print $now.hour
May 20 2001 19:44:57.hour

Example of using reserved compound variable .sh and compound

$ print ${.sh.version}
Version M 1993-12-28 m

Example of using variable name references

Variable initialization and reference creation

$ name = "bill"                    
$ nameref firstname = name

Reference using

$ print $firstname                  

Value changing by reference

$ firstname = "arnold"              
$ print $name                       

Exapmple of using types to create object

#! /usr/bin/ksh93typeset -T Point_t=(
     integer -h 'x coordinate' x = 0
     integer -h 'y coordinate' y = 0
     typeset -h 'point color'  color = "red"     function getcolor {
          print -r ${_.color}
     }     function setcolor {
     }     setxy() {
          _.x=$1; _.y=$2
     }     getxy() {
          print -r "(${_.x},${_.y})"
)Point_t point

echo "Initial coordinates are (${point.x},${point.y}). Color is ${point.color}"point.setxy 5 6
point.setcolor blueecho "New coordinates are ${point.getxy}. Color is ${point.getcolor}"exit 0

Script result

$ ./example1
Initial coordinates are (0,0). Color is red
New coordinates are (5,6). Color is blue

Other shell influence

Bourne Shell and CShell had a major influence on Kern Shell.

Bourne Shell

Initial ksh version was based on Bourne shell. Ksh saves full backward-compatible with the Bourne shell, it means that all programs developed on Bourne Shell can be used with Korn Shell. Bourne Shell was developed in 1977 by Stephen Bourne at AT&T Bell Labs. Bourne Shell is a script language based on algol 68 commands. It released in the Version 7 Unix, and still used by a number of distributions as default shell and root shell.

Difference between Kern Shell and Bourne Shell

  • Platform-independent
  • Command name completion
  • Command history
  • Bulit-in commands aliasing
  • Great software capability extension
  • Process substitution
  • Support TCP, UDP connection as streams

C shell

C shell — UNIX-shell with built-in script language. It was developed in 1979 by Bill Joy at University of California. Bill Joy takes part in BSD UNIX creation, he co-founded Sun Microsystems and create the Vi text processor.

Сsh based on POSIX standard and C language standard. Csh is a part of freeBsd and OpenBSD and it can be used as programming language.

Difference between Korn Shell and C Shell

  • Functions
  • Exception handler and other opportunities associated with functions using
  • Built-in search with regular expressions
  • Process substitution
  • Support TCP, UDP connection as streams
  • No implicit directory change (if command is directory name then changes to it)


Before 2000 Korn Shell was proprietary software of AT&T company. In 2000 Korn Shell became open-source software. In 2005 it gets Eclipse Public Licence (EPL). It is free open source license based on Common Public License but using more flexible rules of copyright deiclaimer.

Other versions of ksh

Before orn Shell source code opening a number of free and open source alternatives were created:

  • pdksh
  • mksh — a fork of pdksh
  • GNU bash
  • zsh

Other shells related to Korn Shell

  • dtksh — Desktop Korn Shell — a fork of ksh93, developed as part of CDE desktop environment.
  • tksh — a fork of ksh93, provides access to the Tk widget toolkit
  • MKS Korn Shell — proprietary version developed by Microsoft. Included in Microsoft Windows Services for UNIX — related software package wich provides a Unix subsystem on Windows.


  1. Learning the Korn Shell, 2nd Edition
  2. IBM Knowledge Center, Korn Shell


  1. KornShell
  2. Using Types To Create Object Orientated Korn Shell
  3. Comparison of command shells