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

linux@tuxworld:~$ cat /etc/shells 
# /etc/shells: valid login shells
/bin/csh
/bin/sh
/usr/bin/es
/usr/bin/ksh
/bin/ksh
/usr/bin/rc
/usr/bin/tcsh
/bin/tcsh
/usr/bin/esh
/bin/dash
/bin/bash
/bin/rbash
/bin/ksh93
linux@tuxworld:~$ 

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

linux@tuxworld:~$ whereis ksh
ksh: /bin/ksh /usr/bin/ksh /usr/bin/X11/ksh /usr/share/ksh /usr/share/man/man1/ksh.1.gz
linux@tuxworld:~$ 
linux@tuxworld:~$ which ksh
/usr/bin/ksh
linux@tuxworld:~$

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.

linux@tuxworld:~$ exec /usr/bin/ksh
$ 

How to verify which shell user is login with

Run the below given command,to know user is using which shell

echo $0

Example.

linux@tuxworld:~$ exec /usr/bin/ksh
$ 
$ echo $0
/usr/bin/ksh
$ 
$ 

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

$ which bash
/bin/bash
$ exec /bin/bash
linux@tuxworld:~$ 
linux@tuxworld:~$ echo $0
/bin/bash
linux@tuxworld:~$

Read Some More Articles

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.