Unix/Linux

How do I find out what shell I’m using?

steloflute 2012. 7. 18. 15:22
http://www.cyberciti.biz/tips/how-do-i-find-out-what-shell-im-using.html

 

How do I find out what shell I’m using?

by on November 15, 2005 · 17 comments· Last updated December 14, 2007

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}')

 

'Unix/Linux' 카테고리의 다른 글

The origin of the name POSIX.  (0) 2012.07.30
How to disable telnet on solaris  (0) 2012.07.19
safe rm  (0) 2012.07.18
On Ubuntu `sudo halt` doesn't poweroff the box  (0) 2012.07.15
Cygwin SSHD HowTo (On Windows)  (0) 2012.07.13