什么是Kornshell或ksh?

Linux and Unix provides different flavors of command line interface. bashis the most popular and use one. But we have alternatives too. kshor Korn Shell is one of them. Kornshell is mainly developed for shell based application development. ksh provides better performance for shell script.

Linux和Unix提供了不同类型的命令行界面。 bash是最受欢迎和使用的一种。 但是我们也有其他选择。 ksh或Korn Shell就是其中之一。 Kornshell主要针对基于外壳的应用程序开发而开发。 ksh为shell脚本提供了更好的性能。

安装Kornshell (Install Kornshell)

We can install Kornshell for most of the Linux, Unix and BSD operating systems. Here are some of them.

我们可以为大多数Linux,Unix和BSD操作系统安装Kornshell。 这里是其中的一些。

Fedora,CentOS,RedHat (Fedora, CentOS, RedHat)

$ yum install ksh

Ubuntu,Debian,Kali (Ubuntu, Debian, Kali)

$  apt install ksh
Install Ksh Ubuntu, Debian, Kali
Install Ksh Ubuntu, Debian, Kali
安装Ksh Ubuntu,Debian,Kali

启动Kornshell (Start Kornshell)

Starting ksh is very easy. We will just run ksh command in the current shell like below.

启动ksh非常容易。 我们将只在当前shell中运行ksh命令,如下所示。

$ ksh

Kornshell脚本示例 (Kornshell Script Examples)

We can create scripts like in bash. We have to specify the ksh path on the system. In this case we use Ubuntu and the ksh shell is locate at  /usr/bin/ksh. alternative and more clean path is /bin/ksh . We can run this script from bash too because the interpreter line will change current shell to the Korn Shell.

我们可以在bash中创建脚本。 我们必须在系统上指定ksh路径。 在这种情况下,我们使用Ubuntu,而ksh shell位于/ usr / bin / ksh。 另一种更干净的路径是/ bin / ksh。 我们也可以从bash运行此脚本,因为解释器行会将当前的shell更改为Korn Shell。

#!/bin/ksh

echo "This is ksh shell script"

变数 (Variables)

If you have used bash for programming both scripting languages are very similar. Variables can be simply defined with the variable name and related value equation. In this example we will define integer variable named ÀGE which holds 33 .

如果您使用bash进行编程,则两种脚本语言都非常相似。 可以使用变量名称和相关值方程式简单地定义变量。 在此示例中,我们将定义名为33整数变量ÀGE。

AGE = 33

对于循环 (For Loop)

For loop is very similar to the bashfor loop we can use following example in order to loop though files in the current working directory.

For循环与bash for循环非常相似,我们可以使用以下示例来循环浏览当前工作目录中的文件。

for file in $(ls)
do
   print $file
done

功能定义 (Function Definition)

We can create functions by using functionkeyword and the function name we want to use. In this example we will create function named myprint. Function body is surrounded with curly braces.

我们可以使用function关键字和要使用的函数名称来创建函数。 在此示例中,我们将创建名为myprint函数。 功能主体被大括号包围。

function myprint
{
   print "This is myprint function"
}
LEARN MORE  Linux Bashrc File and Usage Examples
了解更多Linux Bashrc文件和用法示例

翻译自: https://www.poftut.com/what-is-kornshell-or-ksh/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值