Many times you might not be sure about which shell you are currently using. Especially if you are not on your system and logging into someone else’s, or maybe ssh’ing into a remote server. Worry not, because here are few simple commands that you can use to find out which shell you are using currently.
Command (Note: This one is a bit unreliable as it might not work with non-bash shells or on redirection. Pls check the comments for details. Thanks to Shantanu Kumar and renoX for pointing this out.):
echo $SHELL
Output on my system:
/bin/bash
Command:
echo $0
Output on my system:
bash
Command:
ps -p $$
Output on my system:
7772 pts/0 00:00:00 bash
[tags]linux, bash, shell, commands, ssh[/tags]


Tip #1 is wrong. It does not work on redirection.
On machines that drop me into a non-BASH shell, I usually write a .rc file and execute bash there to launch BASH. For example, when one of the machines drops me into TCSH, I write a .tcshrc file containing this:
alias | awk -F’ ‘ ‘{ print “alias “$1″=\”"$2″ “$3″ “$4″ “$5″ “$6″ \”"$7″”; }’ > .bash_aliases
bash
and in .bashrc file, I write the following
export PS1=[\\u@\\h:\\w]\$\
export PS2=\>
export PS4=+
. .bash_aliases
This brings me inside a BASH shell, but echo $SHELL still prints /bin/tcsh.
Nice Tip Man !
Thanks
and good to see ur posts being referred by Linux today
Tip#1 isn’t always correct; the SHELL environment variable isn’t alway correctly set..
I use ‘ps -p $$’ myself.
@Shantanu, renoX: Thanks for pointing it out. I’ll update the post to reflect this.
Why not just ENSURE that you’re running a specific (preferred) shell by calling:
exec /bin/bash
?
That avoids any question of “to which shell must i adapt myself for this session?”
@Stephan: Thats because you might not have a choice to choose your shell if you are logging onto a remote server. The admin might not have even installed bash (or your preferred shell).