[news.newusers.questions] Difference between .cshrc and .login

jik@athena.mit.edu (Jonathan I. Kamens) (04/10/91)

  (Note the Followup-To -- this has little to do with News, and much to do
with Unix shells.)
In article <yLVTZ2w164w@timeless.UUCP>, jgostin@timeless.UUCP (Jeff Gostin) writes:
|> rothstei@Rothstei.kent.edu (Michael Rothstein) writes:
|> > .cshrc is read and executed by EVERY instantiation of your C-shell ( even, an
|> > specially those instantiations generated by a shell escape, lower fork, etc.)
|> Given this situation, am I following you correctly?:
|>   I respond to a LOGIN: prompt. After the usualy rigamarole, UNIX looks
|> up my .login file, and follows it through. It then (after some other 
|> processes, but before the login sequence is complete (IE: system news, etc)) 
|> looks for and executes my .cshrc file. No problem, right>
|> (er, right?)

  No.  The .cshrc is always executed first (when it is executed -- the "-f"
flag to the shell prevents its execution).  .login is executed after .cshrc
has finished.

  This is easily verified by making your .cshrc file contain nothing but "echo
cshrc" and your .login file contain nothing but "echo login".  When you log
in, "cshrc" and then "login" will be printed.

|> Then I execute a command, say, "ps aux | grep jgostin", and subshell is 
|> spawned. .cshrc is executed again?

  No.  What Michael Rothstein said above is somewhat misleading.  Your .cshrc
is only executed when a new instantiation of the C shell starts up.  It is not
executed whenever the C shell does a fork for any reason, i.e. to run
subprocesses in a pipe or to run commands inside parentheses.  A "lower fork"
(I'm not even sure what is meant by that.) does not cause your .cshrc to be
sourced.

  So, when you just run "/bin/csh" to start up an interactive shell, or if you
run a shell script that uses csh and doesn't use the "-f" flag (all shell
scripts *should* use -f, unless they are personal scripts and you specifically
want them to have your environment when running, but that's another argument
entirely), or if you do shell escape from a program and the shell escape
starts up csh, then your .cshrc is executed.

|> So it would be MUCH more practical, if I 
|> understand this, and the past rhetoric was correct, that it would be better 
|> to put aliases, et al, in the .login file.

  Wrong.  If you put aliases in the .login file, then only your login shell
will have your aliases in it.  If you start a new shell using any of the
methods I mentioned above, the aliases will be missing.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710