Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | yum |
Time | 10m |
Steps to install ksh in Linux
- Open the Terminal app.
- Type the ‘yum install ksh‘ command on CentOS/RHEL.
- Type the ‘dnf install ksh‘ command on Fedora Linux.
- Update your shell in /etc/passwd
- Start using your ksh shell.
Let us see steps in detailed to install KornShell (KSH) on a RHEL/CentOS Linux based system.
How to install the Korn Shell (KSH)
Open a terminal and then type the following yum command to install the ksh shell:
$ sudo yum install ksh
OR
# yum install ksh
Sample outputs:
Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin, security This system is receiving updates from RHN Classic or RHN Satellite. 0 packages excluded due to repository protections Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package ksh.x86_64 0:20100621-19.el6_4.4 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: ksh x86_64 20100621-19.el6_4.4 rhel-x86_64-server-6 687 k Transaction Summary ================================================================================ Install 1 Package(s) Total download size: 687 k Installed size: 0 Is this ok [y/N]: y Downloading Packages: ksh-20100621-19.el6_4.4.x86_64.rpm | 687 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : ksh-20100621-19.el6_4.4.x86_64 1/1 Verifying : ksh-20100621-19.el6_4.4.x86_64 1/1 Installed: ksh.x86_64 0:20100621-19.el6_4.4 Complete!
A note about Fedora Linux users
Type the following command to install ksh on Fedora Linux:
$ sudo dnf install ksh
How can I find out path for ksh shell?
To find out path to the ksh, type:
$ whereis ksh
OR use the grep command as follows:
$ grep --color ksh /etc/shells
Sample outputs:
$ cat /etc/shells
Sample outputs:
/bin/bash /bin/csh /bin/ksh /bin/sh /bin/tcsh /bin/zsh
How do I set 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
OR
# chsh -s /bin/ksh UserNameHere
In this example, set default login shell to /bin/ksh for nixcraft user:
# chsh -s /bin/ksh nixcraft
Regular user can type the following command to change their shell to the ksh:
$ chsh -s /bin/ksh
Logout and login again. Verify your shell with the following command:
$ echo $SHELL
Sample outputs:
/bin/ksh
To see ksh version, type:
$ ksh --version
Sample outputs:
version sh (AT&T Research) 93t+ 2010-06-21
Sample ksh program
Create a file called test.ksh using a text editor:
#!/bin/ksh # Name: test.ksh # Purpose: My first ksh script # Author: nixCraft <www.cyberciti.biz> under GPL v2.x+ # ------------------------------------------------------------------------ # set variables FILE="/etc/passwd" NOW="$(date)" HOSTNAME="`hostname`" USERS_ACCOUNT="$(wc -l $FILE)" # Greet user print "Hi, $USER. I'm $0. I'm $SHELL script running on $HOSTNAME at $NOW." print print "*** User accounts: $USERS_ACCOUNT" print "*** Current working directory: $PWD" print "*** Running for loop test just for fun:" for x in {1..3} do print "Welcome $x times." done
Save and close the file. Run it as follows:
chmod +x test.sh ./test.sh
Sample outputs:
See also:
- Debian / Ubuntu Linux: Install KSH
- See man pages for more info whereis(1)
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Hi,
thanks a lot
Very Good! tks