Venkatesh Muthuswamy
Venkatesh Muthuswamy

Reputation: 43

Identify the shell running in my system

Can anyone please tell me what shell has installed in my system?

Because when I am logging into my system using my username it is initially showing bash shell but later it is showing korn shell after doing sudo.

Please see below for details.

-bash-3.2$ pwd
/home/w4x2spxt
-bash-3.2$ echo $SHELL
/bin/bash
-bash-3.2$ su - XXXXXXX
Password:
You have new mail.
The Oracle base remains unchanged with value /apps/oracle
abc0300ab123:/a30/home/XXXXXXX >> echo $SHELL
/bin/ksh

Upvotes: 0

Views: 139

Answers (4)

riteshtch
riteshtch

Reputation: 8769

SHELL environment variable gives you your login shell.

check the shell path mentioned(last column) against your username or XXXXXXX(for su) in /etc/passwd like this: grep ^XXXXXXX /etc/passwd.

The shell mentioned in that file will be your default shell when you login or su to that user.

To check all installed shells on your system use this: cat /etc/shells

Upvotes: 1

Mark Reed
Mark Reed

Reputation: 95242

When you do this:

-bash-3.2$ su - XXXXXXX

you are starting whatever shell is assigned to user XXXXXXX. This is usually a good thing for su -, since that runs their shell as a login process so you get their normal shell startup initialization (profile, *shrc, etc). If you run a different shell from the one their account is set up for, you probably miss out on all their customization.

You can see what shell is associated with an account by looking them up in the password database. This is pretty reliable across different types of systems and authentication schemes:

perl -MUser::pwent -le 'print( (getpwnam "XXXXXXX")->shell || "/bin/sh" )'

You can always run a shell explicitly as the other user if you have one in mind that you want:

su XXXXXXX -c "bash --login"

or

sudo -u XXXXXXX bash --login # if you have sudo privs

To see what shell you're currently running, look at $0:

echo $0

To see what shell you get by default as you, look at $SHELL.

Upvotes: 0

heemayl
heemayl

Reputation: 41987

The environment variable SHELL always contains the login shell of the user logged in, defined in /etc/passwd.

If the user changes his/her shell after login by e.g. exec bash (bash), the SHELL will still expand to the login shell.

In your case, the user XXXXXXX has the login shell /bin/ksh, do:

grep '<user_name>' /etc/passwd

to match the results.

To find the current shell:

echo $0

Or

ps -p $$

Upvotes: 0

fedorqui
fedorqui

Reputation: 289495

  • Your user is using /bin/bash as default shell.

  • root is using /bin/ksh as its default shell.

The default shell is a user-specific setting, so there is nothing picky in having different ones among users. Just check the last column in /etc/passwd and surprise yourself with a variety of values.

Note by the way that when you do su, you log in as root. If you add the dash and say su - you are loading the root profile, so that you have its environment.

Upvotes: 0

Related Questions