Wednesday, September 3, 2014

[Quick Tips] : Temporarily change the shell after login

Temporarily change the shell after login

This is a useful trick to temporarily change the shell after login. The user can change its shell without doing logoff and restart the machine.For eg. a user require to change the shell in system to perform various commands.

What is shell ?

A Unix shell is a command-line interpreter or shell that provides a traditional user interface for the Unix operating system and for Unix-like systems. Users direct the operation of the computer by entering commands as text for a command line interpreter to execute or by creating text scripts of one or more such commands.(Reference taken from Wikipedia)
You can find supporting shell in your Linux system,by typing below given command
cat /etc/shells
Below given is reference from my system
From above command you can see there are many types of shell are listed.Actually there are still many shell which are not listed in my system.
The above command only give output that linux system supports these shell but it does not mean it is installed.
For eg. in list ksh is given but by default it is not installed in linux. Linux has default shell as bash.
I have already installed ksh in my system by this method.
Hence ksh(Korn shell) is installed in my system

How user can temporarily change its shell

User can change its shell temporarily(except in case user is not allowed to rn exec command by sudoers control)
Step 1: To change the shell ,login into system and run below command
Syntax :
exec /path/of/shell
For eg. I want to change to ksh shell, first I will check what is the absolute path of ksh in system. We will use the command whereis or which.
See the below example from my system
Hence,I got the path. I will select one absolute path. I will use the path /usr/bin/ksh (Because we got two path , you can select as per your requirement)
As a user now I will switch to new shell i.e ksh. Now run the below given command
exec /usr/bin/ksh
eg.

How to verify which shell user is login with

Run the below given command,to know user is using which shell
echo $0
Example.
To revert back to bash shell
To revert back to bash shell,run same exec command with the path of bash shell
See below given example.
First I find the absolute path of bash shell. Then I used it in exec command and later verified the shell of user

No comments: