How to determine if a shell is a login shell

Is there a command to determine if a shell is a login or non-login shell?

First, welcome to the SUSECon forum; this forum is specifically for
SUSECon-related discussions, so in order to get the best possible feedback
I would recommend creating this thread in another forum, such as the SLES
forums for ‘applications’ or configuration/administration.

To quickly answer your question, determine if your PID matches up with a
‘bash’ or a ‘-bash’ process. For example:

ps u| awk "\\$2 == $$"

If the ‘bash’ is actually ‘-bash’ then you are in a login shell. You
could build this into a single command that returns true of false I
suppose which you could then check with the ‘$?’ bash variable (0 if true,
1 if false):

ps u | awk "\\$2 == $$" | grep -- '-bash'


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…

On 10/04/2016 02:14 PM, ab wrote:
Easier solution using the /proc filesystem:

grep -- '-bash' /proc/$$/cmdline


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…

I’ve moved this thread to the SLES Configure/Administer forum.

The answer, then, for the NNTP side to stall Mr. Automatic:

To quickly answer your question, determine if your PID matches up with a
‘bash’ or a ‘-bash’ process. For example:

ps u| awk "\\$2 == $$"

If the ‘bash’ is actually ‘-bash’ then you are in a login shell. You
could build this into a single command that returns true of false I
suppose which you could then check with the ‘$?’ bash variable (0 if true,
1 if false):

ps u | awk "\\$2 == $$" | grep -- '-bash'

Easier solution using the /proc filesystem:

grep -- '-bash' /proc/$$/cmdline


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…