korn和bash shell之间的区别

时间:2022-02-07 11:22:59

I am completely new to Unix. Presently, I have been asked to learn about both KornShell (ksh) and Bash shell. Can some one please give me a short overview about the two?

我是Unix新手。目前,我被要求了解KornShell(ksh)和Bash shell。有人可以给我一个关于这两个的简短概述吗?

Is the term "shell" synonymous to "terminal"?

术语“shell”是“终端”的同义词吗?

I understand that I can read documents about both online. But I believe that an overview from an experienced Unix programmer will help me better understand.

我知道我可以在线阅读有关这两个文件。但我相信经验丰富的Unix程序员的概述将帮助我更好地理解。

2 个解决方案

#1


24  

Post from UNIX.COM

从UNIX.COM发布

Shell features

外壳功能

This table below lists most features that I think would make you choose one shell over another. It is not intended to be a definitive list and does not include every single possible feature for every single possible shell. A feature is only considered to be in a shell if in the version that comes with the operating system, or if it is available as compiled directly from the standard distribution. In particular the C shell specified below is that available on SUNOS 4.*, a considerable number of vendors now ship either tcsh or their own enhanced C shell instead (they don't always make it obvious that they are shipping tcsh.

下表列出了我认为可以让您选择一个shell而不是另一个shell的大多数功能。它不是一个明确的列表,并不包含每个可能的shell的每个可能的功能。如果在操作系统附带的版本中,或者如果可以直接从标准分发编译,则该功能仅被视为在shell中。特别是下面指定的C shell是SUNOS 4上提供的。*,相当多的供应商现在提供tcsh或他们自己的增强型C shell(他们并不总是明确表示他们正在运送tcsh。

Code:

码:

                                     sh   csh  ksh  bash tcsh zsh  rc   es
Job control                          N    Y    Y    Y    Y    Y    N    N
Aliases                              N    Y    Y    Y    Y    Y    N    N
Shell functions                      Y(1) N    Y    Y    N    Y    Y    Y
"Sensible" Input/Output redirection  Y    N    Y    Y    N    Y    Y    Y
Directory stack                      N    Y    Y    Y    Y    Y    F    F
Command history                      N    Y    Y    Y    Y    Y    L    L
Command line editing                 N    N    Y    Y    Y    Y    L    L
Vi Command line editing              N    N    Y    Y    Y(3) Y    L    L
Emacs Command line editing           N    N    Y    Y    Y    Y    L    L
Rebindable Command line editing      N    N    N    Y    Y    Y    L    L
User name look up                    N    Y    Y    Y    Y    Y    L    L
Login/Logout watching                N    N    N    N    Y    Y    F    F
Filename completion                  N    Y(1) Y    Y    Y    Y    L    L
Username completion                  N    Y(2) Y    Y    Y    Y    L    L
Hostname completion                  N    Y(2) Y    Y    Y    Y    L    L
History completion                   N    N    N    Y    Y    Y    L    L
Fully programmable Completion        N    N    N    N    Y    Y    N    N
Mh Mailbox completion                N    N    N    N(4) N(6) N(6) N    N
Co Processes                         N    N    Y    N    N    Y    N    N
Builtin artithmetic evaluation       N    Y    Y    Y    Y    Y    N    N
Can follow symbolic links invisibly  N    N    Y    Y    Y    Y    N    N
Periodic command execution           N    N    N    N    Y    Y    N    N
Custom Prompt (easily)               N    N    Y    Y    Y    Y    Y    Y
Sun Keyboard Hack                    N    N    N    N    N    Y    N    N
Spelling Correction                  N    N    N    N    Y    Y    N    N
Process Substitution                 N    N    N    Y(2) N    Y    Y    Y
Underlying Syntax                    sh   csh  sh   sh   csh  sh   rc   rc
Freely Available                     N    N    N(5) Y    Y    Y    Y    Y
Checks Mailbox                       N    Y    Y    Y    Y    Y    F    F
Tty Sanity Checking                  N    N    N    N    Y    Y    N    N
Can cope with large argument lists   Y    N    Y    Y    Y    Y    Y    Y
Has non-interactive startup file     N    Y    Y(7) Y(7) Y    Y    N    N
Has non-login startup file           N    Y    Y(7) Y    Y    Y    N    N
Can avoid user startup files         N    Y    N    Y    N    Y    Y    Y
Can specify startup file             N    N    Y    Y    N    N    N    N
Low level command redefinition       N    N    N    N    N    N    N    Y
Has anonymous functions              N    N    N    N    N    N    Y    Y
List Variables                       N    Y    Y    N    Y    Y    Y    Y
Full signal trap handling            Y    N    Y    Y    N    Y    Y    Y
File no clobber ability              N    Y    Y    Y    Y    Y    N    F
Local variables                      N    N    Y    Y    N    Y    Y    Y
Lexically scoped variables           N    N    N    N    N    N    N    Y
Exceptions                           N    N    N    N    N    N    N    Y

Key to the table above.

上表的关键。

Y Feature can be done using this shell.

Y功能可以使用此shell完成。

N Feature is not present in the shell.

外壳中不存在N功能。

F Feature can only be done by using the shells function mechanism.

F功能只能通过使用shell功能机制来完成。

L The readline library must be linked into the shell to enable this Feature.

L必须将readline库链接到shell以启用此功能。

Notes to the table above

上表的注释

1. This feature was not in the original version, but has since become
   almost standard.
2. This feature is fairly new and so is often not found on many
   versions of the shell, it is gradually making its way into
   standard distribution.
3. The Vi emulation of this shell is thought by many to be
   incomplete.
4. This feature is not standard but unofficial patches exist to
   perform this.
5. A version called 'pdksh' is freely available, but does not have
   the full functionality of the AT&T version.
6. This can be done via the shells programmable completion mechanism.
7. Only by specifying a file via the ENV environment variable.

#2


4  

There are open source versions of ksh. You can run it on Linux. There was an older ksh for OSS called pdksh that acted somewhat differently than the newer ksh and that may be why folks didn't like it.

有开源版本的ksh。你可以在Linux上运行它。有一个较旧的OSS称为pdksh,它的行为与新的ksh有些不同,这可能就是为什么人们不喜欢它。

There are several differences - bash has most of what ksh does and then some extra stuff. A script written to run in ksh would likely run in bash just fine. A lot of the differences deal with math, variables, arrays, functions etc... - bash just seems to have a hell of lot more of this than ksh

有几个不同之处 - bash具有ksh所做的大部分功能,还有一些额外的功能。编写为在ksh中运行的脚本很可能在bash中运行。很多差异涉及数学,变量,数组,函数等...... - bash似乎比ksh还要多得多

ksh is available on multiple platforms by default but bash would have to be specifically added. On the flip side though, most Linux distros come with bash and you have to add ksh if you want it.

The vi style editing that ksh used by default but not bash. However, you can type "set -o vi" in bash to get that same functionality.

vi样式编辑默认使用ksh而不是bash。但是,您可以在bash中键入“set -o vi”以获得相同的功能。

one reason for using ksh for scripting is, this shell is available on nearly all existing flavours of *nix. Bash is not installed by default on all *nix.

#1


24  

Post from UNIX.COM

从UNIX.COM发布

Shell features

外壳功能

This table below lists most features that I think would make you choose one shell over another. It is not intended to be a definitive list and does not include every single possible feature for every single possible shell. A feature is only considered to be in a shell if in the version that comes with the operating system, or if it is available as compiled directly from the standard distribution. In particular the C shell specified below is that available on SUNOS 4.*, a considerable number of vendors now ship either tcsh or their own enhanced C shell instead (they don't always make it obvious that they are shipping tcsh.

下表列出了我认为可以让您选择一个shell而不是另一个shell的大多数功能。它不是一个明确的列表,并不包含每个可能的shell的每个可能的功能。如果在操作系统附带的版本中,或者如果可以直接从标准分发编译,则该功能仅被视为在shell中。特别是下面指定的C shell是SUNOS 4上提供的。*,相当多的供应商现在提供tcsh或他们自己的增强型C shell(他们并不总是明确表示他们正在运送tcsh。

Code:

码:

                                     sh   csh  ksh  bash tcsh zsh  rc   es
Job control                          N    Y    Y    Y    Y    Y    N    N
Aliases                              N    Y    Y    Y    Y    Y    N    N
Shell functions                      Y(1) N    Y    Y    N    Y    Y    Y
"Sensible" Input/Output redirection  Y    N    Y    Y    N    Y    Y    Y
Directory stack                      N    Y    Y    Y    Y    Y    F    F
Command history                      N    Y    Y    Y    Y    Y    L    L
Command line editing                 N    N    Y    Y    Y    Y    L    L
Vi Command line editing              N    N    Y    Y    Y(3) Y    L    L
Emacs Command line editing           N    N    Y    Y    Y    Y    L    L
Rebindable Command line editing      N    N    N    Y    Y    Y    L    L
User name look up                    N    Y    Y    Y    Y    Y    L    L
Login/Logout watching                N    N    N    N    Y    Y    F    F
Filename completion                  N    Y(1) Y    Y    Y    Y    L    L
Username completion                  N    Y(2) Y    Y    Y    Y    L    L
Hostname completion                  N    Y(2) Y    Y    Y    Y    L    L
History completion                   N    N    N    Y    Y    Y    L    L
Fully programmable Completion        N    N    N    N    Y    Y    N    N
Mh Mailbox completion                N    N    N    N(4) N(6) N(6) N    N
Co Processes                         N    N    Y    N    N    Y    N    N
Builtin artithmetic evaluation       N    Y    Y    Y    Y    Y    N    N
Can follow symbolic links invisibly  N    N    Y    Y    Y    Y    N    N
Periodic command execution           N    N    N    N    Y    Y    N    N
Custom Prompt (easily)               N    N    Y    Y    Y    Y    Y    Y
Sun Keyboard Hack                    N    N    N    N    N    Y    N    N
Spelling Correction                  N    N    N    N    Y    Y    N    N
Process Substitution                 N    N    N    Y(2) N    Y    Y    Y
Underlying Syntax                    sh   csh  sh   sh   csh  sh   rc   rc
Freely Available                     N    N    N(5) Y    Y    Y    Y    Y
Checks Mailbox                       N    Y    Y    Y    Y    Y    F    F
Tty Sanity Checking                  N    N    N    N    Y    Y    N    N
Can cope with large argument lists   Y    N    Y    Y    Y    Y    Y    Y
Has non-interactive startup file     N    Y    Y(7) Y(7) Y    Y    N    N
Has non-login startup file           N    Y    Y(7) Y    Y    Y    N    N
Can avoid user startup files         N    Y    N    Y    N    Y    Y    Y
Can specify startup file             N    N    Y    Y    N    N    N    N
Low level command redefinition       N    N    N    N    N    N    N    Y
Has anonymous functions              N    N    N    N    N    N    Y    Y
List Variables                       N    Y    Y    N    Y    Y    Y    Y
Full signal trap handling            Y    N    Y    Y    N    Y    Y    Y
File no clobber ability              N    Y    Y    Y    Y    Y    N    F
Local variables                      N    N    Y    Y    N    Y    Y    Y
Lexically scoped variables           N    N    N    N    N    N    N    Y
Exceptions                           N    N    N    N    N    N    N    Y

Key to the table above.

上表的关键。

Y Feature can be done using this shell.

Y功能可以使用此shell完成。

N Feature is not present in the shell.

外壳中不存在N功能。

F Feature can only be done by using the shells function mechanism.

F功能只能通过使用shell功能机制来完成。

L The readline library must be linked into the shell to enable this Feature.

L必须将readline库链接到shell以启用此功能。

Notes to the table above

上表的注释

1. This feature was not in the original version, but has since become
   almost standard.
2. This feature is fairly new and so is often not found on many
   versions of the shell, it is gradually making its way into
   standard distribution.
3. The Vi emulation of this shell is thought by many to be
   incomplete.
4. This feature is not standard but unofficial patches exist to
   perform this.
5. A version called 'pdksh' is freely available, but does not have
   the full functionality of the AT&T version.
6. This can be done via the shells programmable completion mechanism.
7. Only by specifying a file via the ENV environment variable.

#2


4  

There are open source versions of ksh. You can run it on Linux. There was an older ksh for OSS called pdksh that acted somewhat differently than the newer ksh and that may be why folks didn't like it.

有开源版本的ksh。你可以在Linux上运行它。有一个较旧的OSS称为pdksh,它的行为与新的ksh有些不同,这可能就是为什么人们不喜欢它。

There are several differences - bash has most of what ksh does and then some extra stuff. A script written to run in ksh would likely run in bash just fine. A lot of the differences deal with math, variables, arrays, functions etc... - bash just seems to have a hell of lot more of this than ksh

有几个不同之处 - bash具有ksh所做的大部分功能,还有一些额外的功能。编写为在ksh中运行的脚本很可能在bash中运行。很多差异涉及数学,变量,数组,函数等...... - bash似乎比ksh还要多得多

ksh is available on multiple platforms by default but bash would have to be specifically added. On the flip side though, most Linux distros come with bash and you have to add ksh if you want it.

The vi style editing that ksh used by default but not bash. However, you can type "set -o vi" in bash to get that same functionality.

vi样式编辑默认使用ksh而不是bash。但是,您可以在bash中键入“set -o vi”以获得相同的功能。

one reason for using ksh for scripting is, this shell is available on nearly all existing flavours of *nix. Bash is not installed by default on all *nix.