[comp.unix.questions] Identifying .login Shells

david@wubios.wustl.edu (David J. Camp) (02/11/89)

Does anyone know a way to determine whether you are in the login shell
from .cshrc?  -David-

-- 
Bitnet:   david@wubios.wustl                ^      Mr. David J. Camp
Internet: david%wubios@wucs1.wustl.edu    < * >    Box 8067, Biostatistics
uucp:     uunet!wucs1!wubios!david          v      660 South Euclid
Washington University Medical School               Saint Louis, MO 63110

dg@lakart.UUCP (David Goodenough) (02/13/89)

From article <309@wubios.wustl.edu>, by david@wubios.wustl.edu (David J. Camp):
> Does anyone know a way to determine whether you are in the login shell
> from .cshrc?  -David-

In .cshrc say:

set login=0

and in .login say:

set login=1

Now

if ($login == 1)

you have a login shell. This relies on the fact that .cshrc is executed
by every csh, but .login is only execute by your login csh, AND after
.cshrc has done it's bit.
-- 
	dg@lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp@xait.xerox.com		  	  +---+

maart@cs.vu.nl (Maarten Litmaath) (02/14/89)

#! /bin/sh
# @(#)loginsh 2.0 89/02/14 Maarten Litmaath @ VU Amsterdam (maart@cs.vu.nl)
#
# determine if the parent is a loginshell: if it is either a child of
# /etc/init (process id 1), or /usr/etc/in.rlogind or /etc/rlogind
# (note: it's unsafe to assume the parent is a loginshell iff (sic) its name
# starts with a `-')
# note: loginsh is BSD-specific; a SysV variant should be straightforward
# if invoked with any argument, loginsh will produce some diagnostics

# first find out if `sps' (the fast variant of `ps') exists - if you already
# know the answer, you could replace the test either by the `sps' or the `ps'
# assignments
# close stderr, to prevent complaints from sh if `sps' doesn't exist

exec 2>&-

[ "`sps N`" ] && {
	PPS='sps fp '
	PS='sps p '
	S=
} || {
	PPS='/bin/ps l'
	PS='/bin/ps '
	S=..
}

PSED="sed -n '2s/................. *\([^ ]*\).*/\1/p'"
SED="sed -n '2s/$S..................\([^ ]*\).*/\1/p'"

ppid=`$PPS$$ | eval $PSED`

[ $# != 0 ] && /bin/echo -n "my ppid is $ppid, of which the ppid is "

ppid=`$PPS$ppid | eval $PSED`

[ $ppid = 1 ] && {
	[ $# != 0 ] && echo "1: init"
	exit 0
}

cmd=`$PS$ppid | eval $SED`

[ $# != 0 ] && echo "$ppid: $cmd"

case "$cmd" in
	in.rlogind|rlogind)
		exit 0
esac

exit 1
-- 
 "I love it                            |Maarten Litmaath @ VU Amsterdam:
          when a plan comes together." |maart@cs.vu.nl, mcvax!botter!maart