← 返回命令列表

Linux command

ksh 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

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

说明

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.

参数

-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).

FAQ

What is the ksh command used for?

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.

How do I run a basic ksh example?

Run `ksh` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c _CMD_ do in ksh?

Execute command string.