[comp.unix.questions] how do I tell inside .cshrc if I'm a login shell?

holtz@strawdog.Eng.Sun.COM (Brian Holtz) (08/04/90)

It's not on the frequently-asked questions list, but maybe it ought to be.
--
Brian Holtz (holtz@netcord.Eng.Sun.COM)

maart@cs.vu.nl (Maarten Litmaath) (08/04/90)

I use a scheme like this.
----------------------------------------

# .cshrc

if (! $?CSHLEVEL) then
	setenv	CSHLEVEL	0
	set	home = ~username	# just to be sure
	source ~/.env			# environment stuff we always want
else
	set	tmp = $CSHLEVEL
	@ tmp++
	setenv	CSHLEVEL	$tmp
endif

# exit from .cshrc if not interactive, e.g. under rsh (BSD)
if (! $?prompt) exit

# aliases
# set variables

----------------------------------------

# .env

# umask
# setenv variables

----------------------------------------

# .login

# terminal setup
# startup favourite window environment
--
   "UNIX was never designed to keep people from doing stupid things, because
    that policy would also keep them from doing clever things."  (Doug Gwyn)

kseshadr@quasar.intel.com (Kishore Seshadri) (08/04/90)

echo $$ gives you the pid of the current shell.

ps `echo $$` | tail -1 | awk '{print $5}' on my Sun system gives me the
name of the shell I'm running. If it has a '-' before the name it usually
indicates a login shell.

Kishore Seshadri
----------------------------------------------------------------------------
Kishore Seshadri <kseshadr@mipos3.intel.com> or <..!intelca!mipos3!kseshadr>
"The nice thing about standards is that you have so many to choose from."

ergo@netcom.UUCP (Isaac Rabinovitch) (08/04/90)

In <614@exodus.Eng.Sun.COM> holtz@strawdog.Eng.Sun.COM (Brian Holtz) writes:
 >how do I tell inside .cshrc if I'm a login shell?

>It's not on the frequently-asked questions list, but maybe it ought to be.
>--
>Brian Holtz (holtz@netcord.Eng.Sun.COM)

Why do you need to?  You can put login-specific commands in your
.login.

Perhaps the question I'm reading is not quite the question you meant
to ask.  (Nitpicking is one of my more obnoxious habits, but in this
case it's the right thing to do.)  Maybe you meant, "how do I tell if
I'm executing the shell I get when I login instead of a shell script."
If so, what you *should* ask is "how do I tell if the shell's
interactive".  The answer to that is, check to see if the shell has
set the prompt variable.   For example:

	if ($?prompt) ....

Obviously, if you define your own prompt variable (which is probably
why you're asking this question in the first place; that's why *I* did)
you want to put the "if ($?prompt)" statement before the "set prompt="
statement.

-- 

ergo@netcom.uucp			Isaac Rabinovitch
atina!pyramid!apple!netcom!ergo		Silicon Valley, CA
uunet!mimsy!ames!claris!netcom!ergo

	"I hate quotations.  Tell me what you know!"
			-- Ralph Waldo Emerson