What Is Kornshell or 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.
We can install Kornshell for most of the Linux, Unix and BSD operating systems. Here are some of them.
Fedora, CentOS, RedHat
$ yum install ksh
Ubuntu, Debian, Kali
$ apt install ksh
ksh is very easy. We will just run
ksh command in the current shell like below.
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.
echo "This is ksh shell script"
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
AGE = 33
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 file in $(ls)
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.
print "This is myprint function"