1. Home
  2. Linux
  3. Switch from bash to korn shell linux

How to switch from Bash to Korn Shell on Linux

Korn Shell is a popular alternative to the Bash Shell that is commonly used as the default command-line system on Linux. The shell is backward compatible with Bash and borrows a lot of useful features found in C Shell.  Korn goes by Ksh for short and is very popular in the community. With a little know-how, it’s easy to get it working as the default shell on Linux! Follow along with our tutorial below and learn how!

Note: to use Ksh on Linux, you must be running Ubuntu, Debian, Arch Linux, Fedora or OpenSUSE. If not, building Ksh from its source code may be required.

Installi Ksh

Korn Shell is readily available for installation on all major Linux distributions. In this guide, we’ll focus on the MirBSD version of Ksh on Linux. The reason we’re talking about this version of Ksh is that the AT&T version of Korn Shell doesn’t enjoy support on all Linux distros (operating systems like Arch Linux and others). If you must use the AT&T release of Korn Shell, download it here.

To install the Korn Shell alternative to Bash on Linux, open up a terminal window and follow the instructions that correspond to your operating system.

Ubuntu

sudo apt install mksh

Debian

sudo apt-get install mksh

Arch Linux

sudo pacman -S mksh

Fedora

sudo dnf install mksh

OpenSUSE

sudo zypper install mksh

Generic Linux

Need to get the MirBSD release of Korn Shell on your Linux PC? If you’re having issues finding it in your OS’s package manager, you’ll need to download the shell’s source code and compile it manually. For information regarding the MirBSD Korn Shell, visit the official website’s download page.

Not sure how to build the source code? Information on making MirBSD’s Ksh from source can be found here.

Access Korn Shell

Did you know that you can access the Korn Shell on your Linux PC without making it the default command system? It’s true! By running the ksh command in a terminal window, it’s possible to jump from the default Bash shell instantly.

ksh

Want to use MirBSD’s Korn Shell as the root user? Here’s how! First, go to the terminal and access the root account. The best way to access the root account (for this case) is to use the su command. However, if you cannot run susudo -s also works.

su -

or

sudo -s

Once you’ve logged into the root user, it’s safe to switch from Bash to the Korn Shell.  Run the run the ksh command to access the shell.

ksh

List available shells

Before it’s possible to set Korn Shell as the default command-line system on Linux, you’ll need to figure out the location of it. The easiest way to determine the exact location of the Korn Shell binary is to take a look at the /etc/shells file.

To view the /etc/shells file, open up a terminal window and use the cat command.

cat /etc/shells

Look through the output of /etc/shells, find the location of Korn Shell and highlight it. Alternatively, pipe the output to a text file for easy access with the command below.

Note: there are many different entries for Korn Shell in the shells file. Ignore all entries with “static” in them.

cat /etc/shells  >> /home/username/Documents/location-of-ksh.txt

Alternatively, if you’d like to pipe only the Korn Shell entries to a text file, skip the command above and run this one instead:

cat /etc/shells | grep mksh >> /home/username/Documents/location-of-ksh.txt

Set Korn Shell as default

Want the Korn Shell to open up when you launch a terminal instead of Bash? Launch a command-line window on the Linux desktop, then run the chsh command.

Note: please understand that chsh is meant to swap the default command shell for the current user. Do not run it as root! You could accidentally switch your Linux PC’s root shell!

chsh

Running chsh will print an output that says “Enter the new value or press ENTER for the default.” Take a look at the location-of-ksh.txt text file in your favorite text editor and copy the location of Korn Shell to your clipboard. You can also view the text file in the terminal with:

cat /home/username/Documents/location-of-ksh.txt

Once the Korn Shell location is written into the chsh prompt window, press the Enter key on the keyboard to confirm your choice. Then, enter your user’s password to apply the change.

After running the chsh command, close the terminal session and restart your Linux PC. When it finishes rebooting, log back in and launch a terminal. Korn Shell should now be the default command-line interface.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.