PDA

View Full Version : How to determine if a shell is a login shell



oriveron
04-Oct-2016, 20:28
Is there a command to determine if a shell is a login or non-login shell?

ab
04-Oct-2016, 21:14
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...

ab
04-Oct-2016, 21:16
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...

kgroneman
04-Oct-2016, 21:49
I've moved this thread to the SLES Configure/Administer forum.

ab
04-Oct-2016, 22:01
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...