Computer Languages A to Z: Korn Shell

by Gary L. Ratliff Sr. (eronstuc)

I would like to dedicate this article to my wife Trudy, as this is being written on her birthday. This is the same day on which Hurricane Ida landed on the coast of Alabama: Nov. 10, 2009. — Gary L. Ratliff, Sr.

The Korn Shell was written in 1982 by David Korn, who was then working at the AT&T Bell Laboratories. It was soon a standard feature of the Unix environment and was the most used shell, just as the bash shell is the standard shell on Linux systems. For the earliest years, it existed as a proprietary shell, and a similar shell was written for Linux called pdksh, for the public domain korn shell. In fact, if you search the repositories, the pdksh shell is the one you will obtain.

However, in the year 2000, AT&T decided to place the Korn Shell in Open Source Software. Now, as the Korn Shell is one of the most powerful shells available to the Nixes family of operating systems, it was soon included in the default installations of many versions of Linux. However, if you install the pdksh version and then later chose to install then true ksh shell from AT&T, then you, like me, will want to rename it to ksh1 once it is installed. That is because the pdksh shell will install and be launched if you give the ksh command.

The uses of a shell are currently being explored in a series of articles which are in the magazine. See Command Line Interface Intro: Part 1, and Command Line Interface Intro: Part 2. You can also refer to Chapter 13 of "UNIX Unleashed, System Administrator's Edition," which gives three reasons for using a shell.

pic

Obtaining and installing the Korn Shell

As was mentioned earlier, you may obtain the pdksh shell from the repositories. Run the synaptic command and do a search for "korn shell." This should produce two results: bash and pdksh. If you wish to launch the shell with its proper name ksh, then it is recommended that you forgo the install of pdksh and instead opt for the official version. As I mentioned, I did not do this and had to change the name of the AT&T version to ksh1 to avoid conflicts. Therefore, I am going to use apt-get remove pdksh to remove the conflict, and then install the official AT&T version.

To begin the process use firefox to visit the AT&T web site: http://www2.research.att.com/~gsf/download/. Now you will see a list of files. This will contain packages and single files. We want to down load the file "ksh" (standalone AT&T ksh executable). This file will go to your Downloads folder in your home directory. But first, you will be asked for a user name and password. You will find these by clicking the cancel button when the window shows up asking for a password. Go to the bottom of the page. The user name is “I accept the password etc." You may want to highlight this and copy it. Then, just use the Control V key to paste it into the password request form. The password is just a single period (.). Once this is done, the file will download to the mentioned folder.

If you read the directions on the page, they suggest that you just need to copy or move the downloaded file to the bin directory. WRONG, since doing this will only get a permission denied message.

You must become root and then move back to the /home/username/Downloads/ folder. Now, execute a gunzip ksh.2009-05-05.linux.i386.gz command. Follow this with the command: cp ksh.2009-05-05.linux.i386 /bin/ksh. Then move to /bin, and make the file executable with chmod +x ksh.

You may now use exit to return to the normal user. Now, you may verify that this works by getting into terminal or xterm and executing the command ksh. You should just receive a $ prompt, indicating that ksh is now ready to accept your commands.

Learning to use the Korn Shell

pic

Here, we see just the first page of many which are devoted to teaching the new user the features of the Korn shell. As you already have bash as the default shell, you may also wish to follow the instructions for learning the bash shell. The shells are very similar. Here are the initial pages of two of the tutorials, which I found easy to follow:

pic
pic

As you can see there is a world of information available on how to begin to learn using the shells. It only takes a while to learn the basics, and once you do this, you may enjoy creating your own scripts to automate the tasks you do every day.

Then, you may add shell scripting to the arsenal of tools you may use to make working with the computer more productive and also easier.

About Gary L. Ratliff, Sr.: Gary retired from work in Quality Control, and introduced computers to his company in 1981. Besides writing articles in PCLinuxOS Magazine, Gary has had articles appear in COMPUTE!, Dr. Dobb's Journal, kilobaub, and Personal Computing magazines. He also served as Associate Editor of the SUPERPET Gazette.


Dedication

pic

Gary lost his wife, Trudy, on January 24, 2010. As he stated when he led off his article, he wrote this on her last birthday. As such, Gary wishes to dedicate this article to the memory of his departed wife. Here is the email from him on January 24, 2010:

I reviewed the article which I dedicated to Trudy, as it was written on her last birthday, Nov. 10, 2009. She passed this morning at about 12:45 am. She was a wife, mother, artist and poet. On several times her work was nominated for awards from poetry.com.

I would like the dedication to be in memoriam and to include this poem which appeared in the book: The Enchantment of Memory (part of the Silence Within series by The International Library of Poetry). Copyright 2001 as a compilation.

A Yellow Rose

Yellow is the color of the rose of friendly cheer.
Yellow is the symbol for a friend I hold dear.
There is yellow in the rainbow,
And yellow in the sun.
There are yellows in the sunsets;
God paints them everyone.
I enjoy the shades of yellow
In everything I see,
But none could be more precious
Or mean as much to me
As the yellow in a single rose
Placed on my grave someday
By a friend I truly cherish
In a very special way.
Yellow is the color of the rose of friendly cheer.
Yellow is a symbol for a friend I hold dear.

Trudy Ratliff

(This is found on page 47 of the above sited work.)