How do I check which shell I am using?
I read that terminal is nothing but shell, and Unix provides different flavors of shells:
- Bourne shell (sh)
- C shell (csh)
- TC shell (tcsh)
- Korn shell (ksh)
- Bourne Again shell (bash)
Questions:
- When I open a terminal window, which shell is opened by default?
- How do I check how many shells are installed?
- How do I change the shell used from my account?
You can type the following command in your terminal to see which shell you are using:
echo $0
The result will look something similar to the below if you are using the bash (Bourne Again Shell) terminal:
-bash
To find the shell you have on the default environment you can check the value of the SHELL
environment variable:
echo $SHELL
To find the current shell instance, look for the process (shell) having the PID of the current shell instance.
To find the PID of the current instance of shell:
echo "$$"
Now to find the process having the PID:
ps -p <PID>
Putting it together:
ps -p "$$"
$SHELL
gives you the default shell.
$0
gives you the current shell.
For example: I have bash as my default shell, which I use for my Terminal App. But for my iTerm2 app, I use the command as the window opens: /bin/ksh
.
So my
$0
gives me /bin/ksh
on iTerm2.
$SHELL
gives me /bin/bash
on iTerm2.
$0
,$SHELL
gives me /bin/bash
on Terminal