How do I find out what shell I’m using?
Asked by Chetan Joshi
Q. What is the best way to find out what shell I'm using. echo $SHELL is not so reliable. Please let me know any tiny command or trick.
A. Chetan, echo $SHELL should work. But here is old good UNIX trick. Use the command ps with -p {pid} option, which selects the processes whose process ID numbers appear in pid. Use following command to find out what shell you are in:
ps -p $$
So what is $ argument passed to -p option? Remember $ returns the PID (process identification number) of the current process, and the current process is your shell. So running a ps on that number displays a process status listing of your shell. In that listing you will find the name of your shell (look for CMD column) .
$ ps -p $$
Output:
PID TTY TIME CMD 6453 pts/0 00:00:00 csh
From my Linux box:
$ ps -p $$
Output:
PID TTY TIME CMD 5866 pts/0 00:00:00 bash
You can store your shell name in a variable as follows :
MYSHELL=`ps -hp $$|awk '{echo $5}'`
Please note those are backquotes, not apostrophes
Or better try out following if you have a bash shell:
MYSHELL=$(ps -hp $$|awk '{echo $5}')
Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
You may also be interested in other helpful articles:
- Linux / UNIX: Determine where a binary command is stored / located on file system
- An Interview With Chet Ramey - Maintainer Of Bash Shell
- Finding all .mp3 files and move to new directory from shell prompt
- Tutorial: Working with UNIX and Linux Shell
- Shell scripting tip: Find the length of a string under UNIX / Linux oses
Discussion on This Article:
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: bash, bash_shell, csh, find_my_shell_name, ps_command, UNIX



thanks this is what i looking for
you can also use
echo $0