Although most of you may know how to do this, it’s just a personal note for myself and for others who might get something out of it.
There are a few ways to do this, we will not be depending on environment variables to tell us what shell we are on, since it’s a variable that echoes anything that it’s set to and hence is not always right.
1. $ echo $0 # prints the name of the current program running. So when entered on shell prompt, returns the name of the shell.
nits@excalibur:~$ echo $0 bash nits@excalibur:~$ ksh $ echo $0 ksh
2. $ ps -p $$ # uses the PID of the currently running program to get information for the ps tool for it. The last column, CMD, can be used to identify which shell you’re on.
nits@excalibur:~$ ps -p $$ PID TTY TIME CMD 6426 pts/7 00:00:00 bash nits@excalibur:~$ ksh $ ps -p $$ PID TTY TIME CMD 6609 pts/7 00:00:00 ksh
If you already haven’t figured out what $0 and $$ do,
nits@excalibur:~$ echo $0;echo $$ bash 6426 nits@excalibur:~$ ksh $ echo $0; echo $$ ksh 6609
Download the official 2buntu app for both Android and Ubuntu Touch.