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.
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 cshFrom my Linux box:
$ ps -p $$
Output:
PID TTY TIME CMD 5866 pts/0 00:00:00 bashYou 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}')
Post a Comment