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 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..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 7 comments… read them below or add one }
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
To get list of shells supported.
chsh -l
/bin/sh
/bin/bash
/sbin/nologin
/bin/zsh
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?
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).
pls give ans how can know login shell?
echo $SHELL
is login
echo $0
is current
We have multiple ways to check the current shell.
ps $$
echo $SHELL
echo $0