Star tup and Shutdown Files

The shell reads one or more files from your home directory when it starts up, and possibly one file when it terminates. The files are described in the following table. No error occurs if any given file does not exist.

File

Description

˜/.cshrc

Read at startup

˜/.tcshrc

Read instead of ˜/.cshrc if it exists (tcsh only—if you're using tcsh, read references to ˜/.cshrc as "˜/.tcshrc if it exists, ˜/.cshrc otherwise.")

˜/.login

Read by login shells at startup

˜/.history

Read by login shells at startup to initialize the history list

˜/.cshdirs

Read by login shells at startup to initialize the directory stack (tcsh only)

˜/.logout

Read by login shells at termination

At startup, a login shell reads, in order, ˜/.cshrc, ˜/.history, ˜/.login, and (for tcsh only) ˜/.cshdirs. A non-login shell reads only ˜/.cshrc at startup.

At termination, a login shell reads ˜/.logout and writes ˜/.history and (for tcsh only) ˜/.cshdirs if the appropriate variables are set. (˜/.history is saved if savehist is set. In tcsh, ˜/.cshdirs is saved if savedirs is set.) A non-login shell simply exits.

To execute commands in ˜/.cshrc that will only apply to interactive shells, place them inside the following construct:

if ($?prompt) then
    commands
endif

To execute commands only for tcsh, place them inside this construct:

if ($?tcsh) then
    commands
endif

Get Using csh & tcsh now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.