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?

Tutorial details
Difficulty level Easy
Root privileges No
Requirements apt-get
Est. reading time 10m
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: nixCraft <> 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:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum