Thursday, October 18, 2012

How to find the current shell in UNIX Solaris Linux?

This method works perfectly in any shell.

NOTE: $$ holds the process id of current shell.

[penguin@cheetah:/home/penguin]#ps | grep -i `echo $$`
 18530             0:00 ksh

[penguin@cheetah:/home/penguin]#bash
bash-3.00$ ps | grep -i `echo $$`
 18574 pts/196     0:00 bash

bash-3.00$ csh
cheetah% ps | grep -i `echo $$`
 18578 pts/196     0:00 csh

cheetah% tcsh
> ps | grep -i `echo $$`
 18590             0:00 tcsh


3 comments:

Sujay Kumar said...

To find the current shell and display the shell name alone:

[penguin@cheetah:/home/penguin]# ps | grep `echo $$` | awk '{print $NF}'
ksh

Chennai Chweet said...
This comment has been removed by the author.
Chennai Chweet said...

http://2.bp.blogspot.com/-xh3sW85RWS4/UJCVGRQ7zzI/AAAAAAAAOKQ/ltY9quzfpZY/s1600/10.jpg