PepeHands
PepeHands

Reputation: 1406

get linux shell name

In my program I need to output to user which shell he is using. So in file /etc/udate-motd.d/00-header I wrote printf "$SHELL" but the problem is that even when I switching my shell to zsh, $SHELL is still equal to /bin/bash. I searched through the internet and found that I can bo it by using MyShell='ps -hp $$', and here is again a problem. When I use it MyShell is a string with number of processes (/etc/update-motd.d/00-header is also there) but there no word zsh.

So how can I understand which shell use the logging in person.

Upvotes: 1

Views: 1806

Answers (2)

Matthias
Matthias

Reputation: 3556

The users shell is determined in /etc/passwd. Why not take the information from there? You could

grep $USER /etc/passwd | cut -f7 -d:

to get the shell.

Upvotes: 0

Rob Latham
Rob Latham

Reputation: 5223

"the internet" gave you one kind of ps syntax. You've tagged this linux, so don't use BSD syntax. Try this:

ps hp $$ -o cmd

no dash

Upvotes: 2

Related Questions