Display my actual used shell

Here a short blog post… if you work in several companies or with different accounts, it’s useful to know, which shell you’re currently using (not the default shell from /etc/passwd). Of course, you can simply change the shell and choose your favorite one, but if you just want to know the actual shell, you can run one of the following two commands.

The special variable $0 contains the name of the running “script” itself. The brackets {} are optional, but I recommend to always set them in shell scripts.

echo ${0}    # recommendation in shell scripts.
echo $0      # short version.
# recommendation in shell scripts. echo $0 # short version.
">bash ksh sh

In the special variable $$ is the process id of the parent process of your session saved. And with the command ps -p informations about the process is printed out. Here again, the brackets are optional.

ps -p ${$}    # recommendation in shell scripts.
ps -p $$      # short version.

Here are three sample outputs:

15912 pts/2 00:00:00 sh
15886 pts/3 00:00:00 ksh
15574 pts/1 00:00:00 bash

On this page or the bash man page are more special variables listed, which can be useful for scripting.
Stay tuned, soon we’re launching a scripting guideline series on this blog and there, we’ll describe the brackets in detail….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.