In this article we will learn how to temporarily change the shell after login in Linux. The user can change its shell without doing logoff and restart the machine.For example a user require to change the shell in system to perform various commands.
What is Unix shell ?
The Unix shell is the command line interpreter between the user interface and the Operating System. The user write the commands on terminal as an instruction to the Operating System.
As the Linux is derived from the Unix hence the further steps will work in Linux and Unix Like Operating system.
Find the available supporting shell in the Linux
Run the given below command, to read the /etc/shell file. It will show the number of shells available to support in the system.
cat /etc/shells
Given below is reference from our 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 example in list ksh is given but by default it is not installed in Linux. Linux has default shell as bash.
We have already installed ksh in our system by this method.
Hence ksh (Korn shell) is installed in our system.
How user can temporarily change its shell
User can change its shell temporarily (except in case user is not allowed to run exec command by sudoers control).
Step 1: To change the shell ,login into system and run below command.
Syntax :
exec /path/of/shell
For example we want to change to ksh shell, first we will check what is the absolute path of ksh in system. We will use the command whereis
or which
.
See the given below example from our 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,we got the path. we will select one absolute path. we will use the path /usr/bin/ksh (Because we got two path , you can select as per your requirement).
As a user now we will switch to new shell i.e ksh. Now run the below given command.
exec /usr/bin/ksh
Example –
linux@tuxworld:~$ exec /usr/bin/ksh
$
How to verify which shell user is login with
Run the given below command to know user is using which shell.
echo $0
Example.
linux@tuxworld:~$ exec /usr/bin/ksh
$
$ echo $0
/usr/bin/ksh
$
$
How to revert back to bash shell
To revert back to bash shell,run same exec
command with the path of bash shell.
Syntax:
exec <SHELL PATH>
Example: reverting to bash shell
First we find the absolute path of bash shell. Then we 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:~$