Debian / Ubuntu Linux: Install KornShell (KSH)

I am porting ksh script from Sun/Oracle Unix to Debian / Ubuntu Linux based server hosted on AWS cloud. How do I install ksh (KornShell) in Debian or Ubuntu Linux server? How do I run and test ksh scripts?

KSH was developed by David Korn at Bell Labs in 1980s. KSH is is quite popular is quite useful automate everyday tasks on Unix or Linux based systems. You can install ksh on Ubuntu or Debian Linux.

Installing KSH on Debian / Ubuntu serer or desktop

Open a terminal and then type the following apt-get command to install the package:
$ sudo apt-get install ksh

Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,527 kB of archives.
After this operation, 3,191 kB of additional disk space will be used.
Get:1 precise/universe ksh amd64 93u-1 [1,527 kB]
Fetched 1,527 kB in 0s (1,988 kB/s)
Selecting previously unselected package ksh.
(Reading database ... 82257 files and directories currently installed.)
Unpacking ksh (from .../archives/ksh_93u-1_amd64.deb) ...
Processing triggers for man-db ...
Setting up ksh (93u-1) ...
update-alternatives: using /bin/ksh93 to provide /bin/ksh (ksh) in auto mode.

Task: Finding ksh location

To find out path to the ksh, type:
$ whereis ksh
OR use the grep command as follows:
$ grep --color ksh /etc/shells
Sample outputs:

Fig.01: Finding ksh path

Task: Setting ksh as a default shell

The superuser (root) may change the login shell for any account using any one of the following syntax:
$ sudo chsh -s /bin/ksh UserNameHere
In this example, set default login shell to /bin/ksh for nixcraft user:
$ sudo chsh -s /bin/ksh nixcraft
Regular user can type the following command to change their shell to the ksh:
$ chsh -s /bin/ksh
$ grep nixcraft /etc/passwd

Sample outputs (when prompted enter your own password):

Fig.02: Attempt to change the user’s shell to /bin/ksh (/bin/ksh93)

Logout and login again. Verify your shell with the following command:
$ echo $SHELL
Sample outputs:


To see ksh version, type:
$ ksh --version
Sample outputs:

  version         sh (AT&T Research) 93u 2011-02-08

Writing your first ksh script

Create a file called test.ksh using a text editor:

# Name: test.ksh (Debian/Ubuntu edition)
# Purpose: My first ksh script 
# Author: SXI LLC <> under GPL v2.x+
# ------------------------------------------------------------------------
# set variables 
OS="$(lsb_release -d | awk  '{ print $2 " version " $3}')"
#OS="$(lsb_release -d | awk -F':' '{ print $2 }')"
# Greet user
print "Hi, $USER. I'm $0. I'm $SHELL script running on $HOSTNAME at $NOW." 
print "*** User accounts: $USERS_ACCOUNT"
print "*** Current working directory: $PWD"
print "*** OS: $OS"
print "*** Running for loop test just for fun:"
for x in {1..3}
    print "Welcome $x times."

Save and close the file. Run it as follows:

chmod +x

Sample outputs:

Fig.03: Running your first KSH script

See also:

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post

How to Make Website WCAG Compliant?

Next Post

Link download Kali Linux 2020.1 (ISO + Torrent)

Related Posts