[comp.unix.questions] how can .cshrc know if session is a login?

brian@caen.engin.umich.edu (Brian Holtz) (05/19/89)

Howw can .cshrc know if a session is a login session?

khera@juliet.cs.duke.edu (Vick Khera) (05/20/89)

In article <434ccc08.bea3@mach1.engin.umich.edu> brian@caen.engin.umich.edu (Brian Holtz) writes:
>Howw can .cshrc know if a session is a login session?

A simple way I do this is to test for the existence of an environment
variable that gets set in .login such as NAME.  if it exists, then it is
most likely a sub-shell, otherwise, .login has not been executed yet, so it
should be a login shell.  This has worked for me so far under SunOS 3.x and
4.0. 

							vick.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
ARPA:	khera@cs.duke.edu		Department of Computer Science
CSNET:	khera@duke			Duke University
UUCP:	{mcnc,decvax}!duke!khera	Durham, NC 27706

madd@bu-cs.BU.EDU (Jim Frost) (05/22/89)

In article <14551@duke.cs.duke.edu> khera@cs.duke.edu (Vick Khera) writes:
|In article <434ccc08.bea3@mach1.engin.umich.edu> brian@caen.engin.umich.edu (Brian Holtz) writes:
|>Howw can .cshrc know if a session is a login session?
|
|A simple way I do this is to test for the existence of an environment
|variable that gets set in .login such as NAME.

My solution is:

  if ($?SUBSHELL) then
    # do things that a non-login shell should do
  else
    # do things a login shell should do
    setenv SUBSHELL "yes"
  endif

This is particularly useful if you use SysV and don't have job
control, but regularly use something like Emacs which exits as if job
control existed:

  if ($?SUBSHELL) then
    alias % exit
    alias fg exit
  else
    alias % echo No current job.
    alias fg echo No current job.
    setenv SUBSHELL "yes"
  endif
  alias bg echo "Open the pod bay doors HAL.  I can't do that, Dave"

Just aliasing "%" and "fg" to "exit" has the annoying habit of logging
you out.

jim frost
madd@bu-it.bu.edu

heilpern@ibd.BRL.MIL (Mark A. Heilpern ) (05/22/89)

In article <31552@bu-cs.BU.EDU> madd@bu-it.bu.edu (Jim Frost) writes:

  >  if ($?SUBSHELL) then
  >    alias % exit
  >    alias fg exit
  >  else
  >    alias % echo No current job.
-->    alias fg echo No current job.
  >    setenv SUBSHELL "yes"
  >  endif
-->  alias bg echo "Open the pod bay doors HAL.  I can't do that, Dave"

**>Just aliasing "%" and "fg" to "exit" has the annoying habit of logging
  >you out.

Yes, Jim, but by alias-ing fg and bg to 'echo' statements, as in the
arrowed lines, you are removing the ability to get back to any suspended
jobs stopped with the use of control-Z.
(Try it, it works :)

	--M.

madd@bu-cs.BU.EDU (Jim Frost) (05/25/89)

In article <264@ibd.BRL.MIL> heilpern@brl.arpa (Mark A. Heilpern (IBD) <heilpern>) writes:
|In article <31552@bu-cs.BU.EDU> madd@bu-it.bu.edu (Jim Frost) writes:
|-->    alias fg echo No current job.
|-->  alias bg echo "Open the pod bay doors HAL.  I can't do that, Dave"
|
|**>Just aliasing "%" and "fg" to "exit" has the annoying habit of logging
|  >you out.
|
|Yes, Jim, but by alias-ing fg and bg to 'echo' statements, as in the
|arrowed lines, you are removing the ability to get back to any suspended
|jobs stopped with the use of control-Z.
|(Try it, it works :)

Only on BSD-style UNIXs, which I prefer but don't happen to have
sitting on my desk at work.  Instead of trying to remember to get out
of job-control mode when using SysV braindamage, I lie to myself.

Which reminds me, does anyone know of a BSD-compatible system which
runs on the 80386 (excepting SunOS for obvious reasons)?  I'd kill for
one.

jim frost
madd@bu-it.bu.edu