Interesting $0 Problem

Matthew Seaman matthew at
Fri Oct 28 15:37:10 UTC 2016

On 2016/10/28 15:40, Tim Daneliuk wrote:
> When is it useful for a script to know it's running in a login context vs.
> a child of the login shell?

For scripts in general, there probably isn't much utility in
distinguishing a login shell from any other shell.  What this does do is
signal to the shell itself that it needs to run ~/.login or
~/.bash_login or ~/.logout or whatever other (shell specific)
initialization or shutdown code is wanted.

> Is there another way to determine if your current shell is the login shell?

I can't think of one off hand.  I thought you might be able to tell if
the shell was a process group leader, but it turns out that any
interactive shell makes itself into a group leader:

lucid-nonsense:~:% ps -o pid,pgid,command
88932 88932 -tcsh (tcsh)
89001 89001 ps -o pid,pgid,command
lucid-nonsense:~:% tcsh
lucid-nonsense:~:% ps -o pid,pgid,command
88932 88932 -tcsh (tcsh)
89003 89003 tcsh
89007 89007 ps -o pid,pgid,command

(The test for being a group leader is where PID == PGID)



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 972 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the freebsd-questions mailing list