≡ Menu

Unix Shell Tips: Change Login Shell From Bash to Others

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
Add your comment

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

Comments on this entry are closed.

  • NetSpider October 9, 2009, 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

  • Phaniraj October 9, 2009, 2:25 am

    To get list of shells supported.

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

  • Bob October 9, 2009, 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?

  • nick January 10, 2010, 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).

  • chetan September 18, 2011, 10:15 am

    pls give ans how can know login shell?

  • ben September 23, 2011, 4:00 pm

    echo $SHELL
    is login
    echo $0
    is current

  • K.Santhosh September 5, 2012, 3:37 am

    We have multiple ways to check the current shell.

    ps $$
    echo $SHELL
    echo $0

  • Rabaya khatun September 14, 2013, 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.

  • Shaikh Afshan February 11, 2015, 4:02 am

    Can anyone tell me how to communicate between bash shell and kclockwork shell i.e kwshell?

  • Anonymous June 10, 2015, 5:39 am

    ps $$ will not give shell information

  • kiran June 14, 2017, 7:16 am

    I want to switch my user to other user automatically without sudo changes in linux for that i used echo passward | su oracle but its won’t work could you please help for on these.