Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | No |
Requirements | apt-get |
Time | 10m |
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
OR
Sample outputs:
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: ksh 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 http://mirrors.service.networklayer.com/ubuntu/ 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:
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):
$ echo $SHELL
Sample outputs:
/bin/ksh93
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:
#!/bin/ksh # Name: test.ksh (Debian/Ubuntu edition) # 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)" 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 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} 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:
- CentOS / RHEL / Fedora Linux: Install KSH
- See man pages for more info whereis(1)
🐧 0 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 |