Unix Shell Tips: Change Login Shell From Bash to Others

by Ramesh Natarajan on October 9, 2009

Question: How do I find out what Unix shell I’m currently running? Can you also explain how can I change my Unix shell both temporarily and permanently? (For example, from bash to tsh).

Answer: You can achieve these using $0, exec, chsh -s. In this article, let us review how to do these in detail.

1. What is my current Unix shell?

Use echo $0 command to get your current shell name as shown below.

$ echo $0
/bin/bash

2. How to change my current shell to another type – temporarily ?

Use exec command to change your shell temporarily as shown below.

$ echo $0
/bin/bash

$ exec /bin/sh

$ echo $0
/bin/sh

Note: The above change is temporary. When you relogin, you’ll go back to the original shell.

3. How to change my current shell to another type – permanently ?

To change your shell permanently, use chsh command as shown below.

$ chsh -s /bin/sh
Password:

Note: The above change is permanent. Even after relogin, you’ll see only the new shell.

4. How can I find out all available shells in my system ?

All available shells are located in the /etc/shells file.

$ 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
/usr/bin/screen
/bin/ksh93

For changing your login shell, you can do only from the above output. But for changing the current shell, you can go to any available shell.

5. Installing New Shell

You can install a new shell (for example, ksh) as shown below. After installing new shell, you can use it as your permanent login shell, or temporary shell for your command line operations.

$ sudo apt-get install ksh

Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 8 comments… read them below or add one }

1 NetSpider October 9, 2009 at 12:58 am

actually “exec” is not necessary to change your shell (run new one).

/bin/sh
or
/bin/tcsh
or something else to run a new shell.
hit ^D to close new shell and return to old shell.

tcsh on FreeBSD:
~ ~> echo $0
-csh
~ ~> echo $SHELL
/bin/csh

2 Phaniraj October 9, 2009 at 2:25 am

To get list of shells supported.

chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh

3 Bob October 9, 2009 at 4:43 pm

Why do you use debian/ubuntu specific commands in an article named Unix shell tips? Is there an aptitude port for unix? Can you use that on freebsd? Or maybe type apt-get on an Irix system?

4 nick January 10, 2010 at 9:41 am

Is there a way to replace the current shell with sh (bourne) AND execute .profile (or some other file)? ksh can do this with the cmd ‘exec ksh’ if the ENV variable is set. The current shell is replaced with ksh and the file specified by ENV is run. I’m hoping to do the reverse (exec sh and have a script file run).

5 chetan September 18, 2011 at 10:15 am

pls give ans how can know login shell?

6 ben September 23, 2011 at 4:00 pm

echo $SHELL
is login
echo $0
is current

7 K.Santhosh September 5, 2012 at 3:37 am

We have multiple ways to check the current shell.

ps $$
echo $SHELL
echo $0

8 Rabaya khatun September 14, 2013 at 6:16 pm

I edit /etc/hosts file and try to save the changes but I cannot it gives an error massages /sbin/sh: wq! not found. when I checked the shell it is sh
I try to change the shell as /sbin/sh
it does not work. it saybad command.

Leave a Comment

Previous post:

Next post: