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
Download Free eBook - Linux 101 Hacks

Get free Unix tutorials, tips and tricks straight to your email in-box.

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

  1. Bash Shell: Take Control of PS1, PS2, PS3, PS4 and PROMPT_COMMAND
  2. Bash Shell PS1: 10 Examples to Make Your Linux Prompt like Angelina Jolie
  3. Bash Scripting Introduction Tutorial with 5 Practical Examples
  4. Shell Script Execution Guidelines for Newbies
  5. Ubuntu Tips: How to Login Without Entering Username and Password
  

Vim 101 Hacks Book

{ 1 trackback }

Destillat KW42-2009 | duetsch.info - GNU/Linux, Open Source, Softwareentwicklung, Selbstmanagement, Vim ...
October 16, 2009 at 3:36 am

{ 4 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).

Leave a Comment

Previous post:

Next post: