taT4Nix | Setting up Korn Shell in Linux OS

Having spent over a year at work place, working on AIX Server, I end up doing overtime writing tools using shell scripting in Korn Shell environment. I was wondering if there is some way possible, so that I could setup similar environment at home using Linux Desktop, like Ubuntu, Fedora, etc and avoid doing overtime :)

AIX Server uses ksh as the default shell for every user account, whereas most of the Linux OS (I guess) have bash as the default shell. As AIX is proprietary server made by IBM, so I opted for Virtual Box instead, where I could do all my exploration.

Why Fedora 12?

Just download the ISO Image for suitable flavor of Linux OS available in the Open Source community. Thankfully, I had Fedora 12 ISO Image, which I downloaded back in 2010. To save time, I used the same to setup VM using Virtual Box. 

While installing the Fedora 12 VM (on Windows 7 Host OS), I created user account [nvarun], which by default has bash shell environment loaded whenever I open the Terminal desktop application to do command line operations.

Setting up Korn Shell

I have spent past few weeks, trying to figure out how to change default shell for user account and loading ksh environment, whenever I open Terminal desktop application and user account [nvarun] logs in by default.

  1. Open Terminal desktop application
  2. By default, the user account [nvarun] is logged in.
  3. Execute following command;
    $> grep nvarun /etc/passwd
    nvarun:x:500:500:Varun Nischal:/home/nvarun:/bin/bash
  4. As you would notice, the entry is colon-delimited and the last delimited field tells you the default shell for user account.
  5. Now to change the default shell to /bin/ksh, execute following command;
    $> sudo chsh -s /bin/ksh nvarun
    Changing shell for nvarun.
    Shell changed.
    $> exit
  6. As you exit from Terminal and re-open it again, you won’t see the change yet.

Before we proceed further, it is important to understand what AIX Server does with user accounts.

The shell uses two types of profile files when you log in to the operating system.

The shell evaluates the commands contained in the files and then runs the commands to set up your system environment.

The files have similar functions except that the /etc/profile file controls profile variables for all users on a system whereas the .profile file allows you to customize your own environment.

As we need to customize the our environment, in that case, use vi editor to edit the $HOME/.profile file and add following line;

export ENV=/etc/kshrc

The /etc/kshrc file is a shell script that customizes the Korn Shell environment and often contains list of environment variables, aliases and function definitions, etc.

Each time you start a new instance of the Korn shell, the ksh command examines the value of the ENV environment variable set in the $HOME/.profile file.

If the ENV environment variable contains the name of an existing, readable file, the ksh command runs this file as a script.

By convention, this file is named $HOME/.kshrc. You can use another name, but you must set the ENV environment variable to point to it.

Now, you may exit from Terminal and re-open it again, the changes would be reflected and this lets nvarun create aliases, functions, etc. to customize the environment further.

I am already excited to explore further, hope this helps :)

About these ads

One thought on “taT4Nix | Setting up Korn Shell in Linux OS

  1. Pingback: taT4Nix | Setting up Git repository in Fedora 12 | PrayogShala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s