Linux - What is the best way to identify currently used Linux Shell?
In Linux, there is a convenience environment variable SHELL which may tell what is the current shell. However, please do not be confused by it, because, $SHELL only tells us the about the SHELL of the user (and likely the SHELL used when the user log in) and does not necessary tell the runtime shell the user is currently using.
In such runtime case, "ps -p $$" is a better choice
Below is an example
$ echo $SHELL
/bin/bash
$ ps -p $$
PID TTY TIME CMD
6364 pts/0 00:00:00 bash
$ ksh
$ echo $SHELL
/bin/bash
$ ps -p $$
PID TTY TIME CMD
26970 pts/0 00:00:00 ksh
As you can see, $SHELL consistently say it is /bin/bash even after I had change to ksh shell during runtime. But, ps -p $$ provide consistent result.
ps is the command to list process
-p mean Select by process ID
$$ mean current shell PID. It is a special shell variable.
Comments
Post a Comment