Tuesday, July 5, 2016

What Shell am I using?


Very simple, use any of the following methods:

Method# 1

$ echo $SHELL

Example:

[demo@localhost ~]$ echo $SHELL
/bin/bash

Note: SHELL is an environment or system variable, echoing its output will reveal what it contains.

Method# 2

$ echo $0

Example:

[demo@localhost ~]$ echo $0
bash


Note: The digit zero - "0" contains the name of the currently running program or script. So, at Shell Prompt, it will tell you the name of the Shell running. In a Shell Script, it will tell you the name of the Shell Script you are running.


Method# 3

$ grep ^user_name /etc/passwd

Example:

[demo@localhost ~]$ grep ^demo /etc/passwd
demo:x:500:500:demo user:/home/demo:/bin/bash


Note: The file "/etc/passwd" contains user accounts information, so the last field will contain the Shell Name with its path.

Method# 4

$ getent passwd user_name

Example:

[demo@localhost ~]$ getent passwd demo
demo:x:500:500:demo user:/home/demo:/bin/bash

Note: The command "getent" gets entries from administrative database. Here, we have specified "passwd" as the database to be used. This will list a non-local user account as well.