Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Oct 2016 16:36:54 +0100
From:      Matthew Seaman <matthew@FreeBSD.org>
To:        freebsd-questions@freebsd.org
Subject:   Re: Interesting $0 Problem
Message-ID:  <d66271c8-b7dd-9262-1c9a-7d8f5c58db79@FreeBSD.org>
In-Reply-To: <5a4f0424-cdfa-bd44-9de2-b4860d121584@tundraware.com>
References:  <b859f7a3-51d1-06f4-e793-332edd212068@tundraware.com> <516bc76f-f14c-e9a5-a246-2e915a5369ce@qeng-ho.org> <5a4f0424-cdfa-bd44-9de2-b4860d121584@tundraware.com>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--ReLnXHWTLma1RUjELW3cqIecNHdKw8OR3
Content-Type: multipart/mixed; boundary="xWQt2FIbEuhNPKDOCLEMup8mntPMKR2FX";
 protected-headers="v1"
From: Matthew Seaman <matthew@FreeBSD.org>
To: freebsd-questions@freebsd.org
Message-ID: <d66271c8-b7dd-9262-1c9a-7d8f5c58db79@FreeBSD.org>
Subject: Re: Interesting $0 Problem
References: <b859f7a3-51d1-06f4-e793-332edd212068@tundraware.com>
 <516bc76f-f14c-e9a5-a246-2e915a5369ce@qeng-ho.org>
 <5a4f0424-cdfa-bd44-9de2-b4860d121584@tundraware.com>
In-Reply-To: <5a4f0424-cdfa-bd44-9de2-b4860d121584@tundraware.com>

--xWQt2FIbEuhNPKDOCLEMup8mntPMKR2FX
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

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 sh=
ell?

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
  PID  PGID COMMAND
88932 88932 -tcsh (tcsh)
89001 89001 ps -o pid,pgid,command
lucid-nonsense:~:% tcsh
lucid-nonsense:~:% ps -o pid,pgid,command
  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 =3D=3D PGID)

	Cheers,

	Matthew




--xWQt2FIbEuhNPKDOCLEMup8mntPMKR2FX--

--ReLnXHWTLma1RUjELW3cqIecNHdKw8OR3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - https://gpgtools.org

iQJ8BAEBCgBmBQJYE3CfXxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w
ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXQxOUYxNTRFQ0JGMTEyRTUwNTQ0RTNGMzAw
MDUxM0YxMEUwQTlFNEU3AAoJEABRPxDgqeTnmHUP/0yBL0sA2yH95a92rfhL0F63
MHW7hYX96nRdQwaaQpLcShdq5NoHaCpO5l+bPGmdMI8/m/1lRlN1huMvPbR6XR/g
wdGykWJoJgomYAvmRUqjG85ti301L9Mm6ygdKtdEIFwD2/7fCdRKRJ4yCR2F8eht
DvmFaxIbY6muHhj2q2fN2YfnPLnQiITKxTpSFiqUd1BCH382H3cf8WnUlAoDElxN
pWk9VXYYRx1bR5K0tVoNFrBf+fLBawK2ATTQvQJ6dBZRbfUKysmbutUQfc4PSQbL
eU2guY2JUY2MJnSgxkkZEilgAT2hHDacHFYJvT97b/u3CghYoV5lHRMWShTLT2Di
xbrfPHlwSFSR51I9xlTtoX3ifDUUyaHPgQaPhNTlDuU1blKC99suXCeZpbLwzQRt
e0KBzaoyuIaStM4fesvHXiuFT/Ewds+B7515f3ND0VurkbBRfFTI7hj5raSPvPEV
3QG0XzWN1BTBztr21ciT/Eth0B83XMeS30LQZMgZXPsRqAUvRg3SBRRVqe9S4+NN
HjxXFh24xw4SRJpwL1cCebcHP6tjM8l9MZtOIwH936eCzPlzOjxfRcQy8+Lbk6wm
NPOM/g4EqNPumG/l/b/DeqpcVvUbuAN65+kbmp2g1Mw843wl+yuGYPLZ+xrAR2oJ
kPC/NH7uGckiKWZAIg+T
=LdzX
-----END PGP SIGNATURE-----

--ReLnXHWTLma1RUjELW3cqIecNHdKw8OR3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?d66271c8-b7dd-9262-1c9a-7d8f5c58db79>