# KornShell

**KornShell** 是用于 Unix 及类 Unix 系统的命令与脚本语言，由大卫·科恩（David Korn）在贝尔电话实验室（Bell Telephone Laboratories）编写，由程序 `ksh` 实现；它是 System V UNIX shell——又称伯恩shell（Bourne shell，即 `sh`）——的超集。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 该 shell 于 1983 年首次发布，在兼容伯恩shell的基础上加入了 [C shell](https://www.edgepedia.org/zh/c-shell) 的交互式便利功能，后来成为 POSIX shell 标准的源文献之一。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup><sup> • </sup><sup>[2](https://www.iso.org/standard/17841.html)</sup>

| 关键事实 | 详情 |
|---|---|
| 作者与起源 | 大卫·科恩，贝尔电话实验室（后为 AT&T 实验室）；第一版于 1983 年问世<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> |
| 语言关系 | 伯恩shell（`sh`）的超集；1988 年版是 IEEE POSIX 与 ISO shell 标准的源文献<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> |
| 首创 | 第一个同时提供 emacs 与 vi 两种风格命令行编辑的 shell（1983）；第一个支持多字节字符的 shell（1986）<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> |
| ksh93 新增特性 | 浮点运算、关联数组、完整的 ANSI-C printf、名称引用变量、复合变量与活动变量、内建命令的动态加载<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> |
| 标准符合性 | 1993 年版应当符合 1992 年的 POSIX/ISO shell 标准，并曾一度通过 X/OPEN 测试套件<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> |
| 当前开发 | ksh93u+m 项目从 AT&T 最后一个稳定版本（93u+，2012-08-01）继续推进 ksh93；1.0.0 版于 2022 年发布，1.0.10 版于 2024 年发布<sup>[3](https://github.com/ksh93/ksh)</sup><sup> • </sup><sup>[4](https://github.com/ksh93/ksh/releases)</sup> |
| 厂商采用 | Oracle Solaris 11 将 ksh93（u 版）作为默认 shell 提供；IBM AIX 7.1 提供 ksh93t<sup>[5](https://www.oracle.com/a/tech/docs/aix-solaris-mapping-guide.pdf)</sup> |

## 历史

大卫·科恩在默里山（Murray Hill）的贝尔实验室工作期间，于 1983 年夏季 USENIX 会议上发表了第一个版本，题为“KSH——一种 shell 编程语言”。<sup>[6](https://www.usenix.org/legacy/publications/bibliography/byDate.html)</sup> 据该项目的 FAQ 所述，1983 年的这个版本是第一个提供 emacs 与 vi 两种风格交互式命令行编辑的 shell，1986 年的版本则是第一个支持多字节字符的。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 科恩曾描述自己构建这个 shell 的做法：从一种表单脚本语言出发，删去专用于表单的代码，再加入 C shell 的特性，如历史记录、别名和作业控制。<sup>[7](https://www.oilshell.org/archive/ksh-usenix.pdf)</sup>

1988 年版被 System V Release 4 UNIX 采用，并成为 IEEE POSIX 与 ISO shell 标准的源文献。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> ISO/IEC 9945-2:1993《Shell 与实用工具》标准在列举其各项设施所依据的历史模型时，将 KornShell 的文档与 System V 接口定义、BSD 用户手册以及 X/Open 可移植性指南并列。<sup>[2](https://www.iso.org/standard/17841.html)</sup> 1993 年的版本 ksh93 是对 1988 年版的一次重大重写，更侧重于脚本编程。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

这门语言由莫里斯·博尔斯基（Morris Bolsky）与大卫·科恩合著的两本书加以阐述，均由普伦蒂斯·霍尔出版社（Prentice Hall）出版：针对 1988 年版的《KornShell 命令与编程语言》（*The KornShell Command and Programming Language*），以及针对 1993 年版的《新 KornShell 命令与编程语言》（*The New KornShell Command and Programming Language*）。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

## 语言特性

**脚本扩展。** ksh93 在语言层面的主要新增内容包括：浮点运算、关联数组、仿照 [ANSI C](https://www.edgepedia.org/zh/ansi-c) 的完整 printf、用作名称引用的变量、新增的展开运算符、动态加载内建命令的能力、活动变量以及复合变量。活动变量与复合变量使 shell 变量能够像对象一样运作。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 在交互方面，1993 年版唯一的主要新特性是键绑定。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

**内建命令。** 在提供动态加载的系统上（如 System V Release 4），KSH-93 允许在运行过程中将命令并入为内建命令，从而缩短命令的启动时间。<sup>[3](https://github.com/ksh93/ksh)</sup>

**可移植性。** 由于编写时便考虑到可移植性，这个 shell 几乎可以在所有现存的 UNIX 变体上使用，也能在 UNIX 之外运行，包括 IBM 的 MVS 配 OpenEdition，以及微软的 Windows 9X、[Windows NT](https://www.edgepedia.org/zh/windows-nt) 和 [Windows 2000](https://www.edgepedia.org/zh/windows-2000)；ksh 作为 UWIN（Unix for Windows）软件包的组件一同发布。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

## 标准与许可

1993 年版应当符合 1992 年的 POSIX 与 ISO shell 标准，并曾一度通过 X/OPEN 编写的测试套件。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 为 KornShell 88 编写的脚本在几乎所有情况下都能在 KornShell 93 下运行。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

许可方式塑造了这个 shell 的生态。使用 ksh93 须从朗讯或 AT&T 获得单独许可，该 FAQ 曾表示希望开源发布能改变这一局面。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 这一限制促成了独立的重新实现：pdksh 是一个与 ksh 无关的公有领域 UNIX shell，支持 1988 年 KornShell 的大部分语言特性以及 1993 年版的部分特性，不过有些 KornShell 脚本无法在它上面运行；MKS 工具包 Kornshell 则是一个完全独立的实现，支持 1988 年版语言的一个子集。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup> 商业支持可由全球技术有限公司（Global Technologies, Ltd）提供，该公司在众多系统上分发并支持“通用操作环境”（Common Operating Environment），其中包括 ksh 以及 ast-open 的其他工具；ksh 的作者本人不提供官方支持。<sup>[1](https://www.kornshell.com/doc/faq.html)</sup>

## 以 ksh93u+m 之名重生

在 AT&T 最后一个稳定版本（日期为 2012-08-01 的 93u+）之后，开发陷入停滞；ksh93u+m 项目从该版本起步——它此前由 AT&T 软件技术部门（AT&T Software Technology，AST）开发——如今在 GitHub 上开发缺陷修复与新特性。<sup>[3](https://github.com/ksh93/ksh)</sup> 1.0.0 版于 2022 年发布，此后该系列持续推出缺陷修复版本；第十个版本 1.0.10 恰好在 1.0.0 发布两年后、93u+ 发布十二年后问世。<sup>[4](https://github.com/ksh93/ksh/releases)</sup> 这些版本修复了长期存在的缺陷，包括一个自 2005 年起便存在的算术错误——在 ARM 等非 Intel 处理器上，整数除以负整数会抛出虚假的“除以零”错误——以及子 shell 内管道破裂时信号处理的回归问题。<sup>[4](https://github.com/ksh93/ksh/releases)</sup> 1.0.9 版将 Android/Termux 新增为受支持的平台，并重新引入了构建动态链接 ksh 的能力，使 libast、libdll、libcmd 和 libshell 可供其他应用程序使用。<sup>[4](https://github.com/ksh93/ksh/releases)</sup>

## 诸 shell 之中的 KornShell

由于 POSIX shell 标准大量借鉴了 Korn shell，ksh 与 bash、dash 及其他 POSIX shell 所实现的可移植脚本基线十分接近。<sup>[2](https://www.iso.org/standard/17841.html)</sup> 在 Baeldung 进行的一项基准测试中，使用 shell 自身的算术功能执行 1000 次迭代的循环，Korn shell 约用 0.37 秒完成，而 Bash 为 0.761 秒；文章以此作为证据，说明 Korn 在脚本任务上可以胜过 Bash，代价是可读性降低、维护更困难。<sup>[8](https://www.baeldung.com/linux/korn-vs-bash)</sup> 各厂商的 ksh 版本在不同平台之间略有差异，这给统一用户环境带来了摩擦。<sup>[9](https://www.hep.phy.cam.ac.uk/lhcb/LHCbSoftTraining/documents/ShellChoice.pdf)</sup>

企业级 Unix 让这个 shell 仍处于日常使用之中：Oracle Solaris 11 在 /usr/bin/ksh 中提供 ksh93（u 版）作为默认 shell，为兼容性在 /usr/sunos/bin/ksh 中保留 ksh88；AIX 7.1 则提供 ksh93t shell。<sup>[5](https://www.oracle.com/a/tech/docs/aix-solaris-mapping-guide.pdf)</sup> [红帽企业Linux](https://www.edgepedia.org/zh/red-hat-enterprise-linux)（Red Hat Enterprise Linux）一直随附 KSH-93，并将其描述为 AT&T 贝尔实验室的大卫·科恩所开发的 KornShell 的最新版本，兼容最初的伯恩shell，且已为其发布缺陷修复更新。<sup>[10](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/pdf/6.2_technical_notes/62-technical-notes.pdf)</sup>

## References

1. [KSH-93 Frequently Asked Questions, kornshell.com](https://www.kornshell.com/doc/faq.html)
2. [ISO/IEC 9945-2:1993, Shell and Utilities, ISO](https://www.iso.org/standard/17841.html)
3. [ksh93/ksh: ksh 93u+m, GitHub](https://github.com/ksh93/ksh)
4. [Releases, ksh93/ksh, GitHub](https://github.com/ksh93/ksh/releases)
5. [IBM AIX to Oracle Solaris Technology Mapping Guide, Oracle](https://www.oracle.com/a/tech/docs/aix-solaris-mapping-guide.pdf)
6. [USENIX bibliography listing by date](https://www.usenix.org/legacy/publications/bibliography/byDate.html)
7. [ksh - An Extensible High Level Language, David G. Korn](https://www.oilshell.org/archive/ksh-usenix.pdf)
8. [Differences Between Bash and Korn Shells, Baeldung on Linux](https://www.baeldung.com/linux/korn-vs-bash)
9. [Shell Choice comparison, LHCb Software Training](https://www.hep.phy.cam.ac.uk/lhcb/LHCbSoftTraining/documents/ShellChoice.pdf)
10. [Red Hat Enterprise Linux 6.2 Technical Notes](https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/6/pdf/6.2_technical_notes/62-technical-notes.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › C-family and imperative languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/kornshell

English original: https://www.edgepedia.org/kornshell
