.login, .chsrc (summary of answers)

J. Mark Noworolski jmn at power.berkeley.edu
Wed Nov 21 11:36:54 AEST 1990


macq at miguel.llnl.gov (Don MacQueen) writes:
>What then are some general guidelines as to what goes in .cshrc and what goes in .login and why?  I've been wondering...
I happened to be asking the same question a while back- here's the summary
of replies which I posted:

(Thanks again to everybody who helped out)

From: Mark Ferraretto <mferrare at physics.adelaide.edu.au>
Your .login should contain only things you want executed on login; eg setting
environment variables, displaying login messages etc.  Your .cshrc should
contain stuff you want in each shell; eg shell variables, aliases, prompts etc.

---------------------
From: bbx!yenta!dt at unmvax.cs.unm.edu (David B. Thomas)
The answer is very simple.  .login is executed when your login shell is
started, i.e. when you log in, and never again.  .cshrc is executed at
the beginning of any shell, including the login shell, and any subshells.

Therefore, something that prints a message if you have mail should probably
go in .login, whereas you favorite aliases should go in .cshrc, so you can
have them in your subshells, too.

                                        David

-----------------------
From: schaefer at cse.ogi.edu (Barton E. Schaefer)
It really isn't all that hard -- the names are quite descriptive.
Anything that should be done whenever a login shell is run, should go
in .login; anything that should be done whenever ANY shell is run, should
go in .cshrc.  That means that things like setting your terminal type,
establishing various environment settings, etc. should go in .login,
and almost everything else should go in .cshrc.

One caveat about .cshrc is that some things should be differentiated
based on whether the shell is interactive.  For example, you should never
set the variable $prompt in a non-interactive shell.  You can detect an
interactive shell by testing whether $prompt is already set:

    if ( $?prompt ) then
        # interactive stuff, including changing $prompt and most aliases
    endif
    # everything else.

Things like rsh and logging in through X windows fuzz the neat line that
used to be drawn between .login/.cshrc.  Csh was designed in the days
when there was only one "login session" -- connected to your single-
"window" tty terminal -- and all other shells were "subshells" that
didn't need to set up the environment once the login shell was in place.
It's usually a good idea to specify (to xterm for example) whether the
shell should be run as a login shell or not.  Think carefully about what
you're using each type of shell for, and you should be able to decide
what needs to go where.  If in doubt, put it in .cshrc but wrap it in
"if ( $?prompt )" to avoid confusing non-interactive uses.


--------------------
From: dce at smsc.Sony.COM (David Elliott)
The .cshrc file is run for any non-interactive csh started
without -f.  The .login file is read for all login csh sessions.

In general, the .login should contain settings of environment variables
(these get inherited by subprocesses), check your mail and news, set
up the tty (mesg, biff, stty), and set up the basic terminal session
(tset, terminal-specific environment).  If you have a special prompt
for your top-level shell, this is where you can set it.

The .cshrc should contain two parts: the interactive stuff and the
general stuff.  

The interactive stuff consists of setting the prompt (don't set it
otherwise unless you like to confuse editors and things), setting up
variables and aliases that are only important when you type them, and
setting other interactive modes (filename completion, history, cdpath,
etc.).  The general stuff consists of setting your path (you need this
for rsh) and variables and aliases that you might need from inside of
subshells (like when you use :! from vi).

Never put stty, biff, or mesg in your .cshrc.  That's not where it
belongs.  If you use X, make sure to start xterm with -ls so that
each window looks like a login shell.
--
"There's a really fine line between clever and stupid"
				Nigel- Lead Guitar (Spinal Tap)
jmn at united.berkeley.edu, or jmn at power.berkeley.edu



More information about the Comp.unix.questions mailing list