ksh

Korn shell, combining features of sh and csh

TLDR

Start Korn shell
$ ksh
Run a script
$ ksh [script.ksh]
Run a command string
$ ksh -c "[command]"
Start a login shell
$ ksh -l
Start a restricted shell
$ ksh -r
Enable POSIX compliance mode
$ ksh -o posix
Enable vi-style line editing
$ ksh -o vi

SYNOPSIS

ksh [options] [script] [args...]

DESCRIPTION

ksh is the Korn shell, combining features of the Bourne shell (sh) and C shell (csh). It provides advanced scripting capabilities with interactive command-line editing, command history, job control, and aliases.The shell supports both vi and emacs editing modes, associative and indexed arrays, arithmetic evaluation, coprocesses, and pattern matching. ksh93 is the most widely used version; ksh2020 is a more recent release.

PARAMETERS

SCRIPT

Script file to execute.
-c CMD
Execute command string.
-l
Login shell (reads profile files).
-r
Restricted shell (limits `cd`, path changes, and redirections). Equivalent to invoking as `rksh`.
-s
Read commands from standard input.
-o OPTION
Set shell option (e.g., `vi`, `emacs`, `posix`, `noclobber`, `errexit`, `noglob`, `pipefail`).
+o OPTION
Unset the given shell option.
-i
Force interactive shell mode.
-n
Read commands but do not execute them (syntax check).
-x
Print commands and arguments as they are executed (trace mode).
-e
Exit immediately if a command exits with non-zero status.
-v
Print shell input lines as they are read.
-a
Export all assigned variables automatically.
-u
Treat unset variables as an error when substituting.
-R file
Write a cross-reference listing to file (ksh93 only).

INSTALL

sudo dnf install ksh
sudo pacman -S ksh
sudo apk add loksh
sudo zypper install ksh
brew install ksh
nix profile install nixpkgs#loksh

CAVEATS

Multiple implementations exist (ksh88, ksh93, mksh, pdksh). Behavior may differ subtly between implementations and from bash. POSIX compatible when invoked with `-o posix`.

HISTORY

The Korn shell was created by David Korn at Bell Labs in the early 1980s, influencing many modern shells including bash and zsh.

SEE ALSO

bash(1), sh(1), zsh(1), tcsh(1)