Tip: Commands To Find Out The Shell You Are Using
Blog | Tech Blog | Secure Coding | Twitter | RSS Feed | Get Email Updates
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.):
CODE:
-
echo $SHELL
Output on my system:
CODE:
-
/bin/bash
Command:
CODE:
-
echo $0
Output on my system:
CODE:
-
bash
Command:
CODE:
-
ps -p $$
Output on my system:
CODE:
-
7772 pts/0 00:00:00 bash
© Shantanu Goel | Tip: Commands To Find Out The Shell You Are Using
Custom Search
|
Liked this post? Get FREE Updates Subscribe to RSS feed |






This post has 6 comments
February 2nd, 2009
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.
February 3rd, 2009
Nice Tip Man !
Thanks
and good to see ur posts being referred by Linux today
February 3rd, 2009
Tip#1 isn't always correct; the SHELL environment variable isn't alway correctly set..
I use 'ps -p $$' myself.
February 4th, 2009
@Shantanu, renoX: Thanks for pointing it out. I'll update the post to reflect this.
February 13th, 2009
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?"
February 13th, 2009
@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).