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.
- Open Terminal desktop application
- By default, the user account [nvarun] is logged in.
- Execute following command;
$> grep nvarun /etc/passwd nvarun:x:500:500:Varun Nischal:/home/nvarun:/bin/bash
- As you would notice, the entry is colon-delimited and the last delimited field tells you the default shell for user account.
- 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
- 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;
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 :)