Department of Computing Imperial College
Linux files: .cshrc

This file is executed every time you execute a new shell (i.e. every time you log in or open a new xterm window). It is normally used to configure aliases and environment variables.

The standard lab .cshrc contains the lines:


# before changing read the comments at
# start of /usr/local/etc/default.cshrc

# set your default printer here
setenv PRINTER redshift 

if ( -f /usr/local/etc/default.cshrc ) then
        source /usr/local/etc/default.cshrc
endif

# put your aliases here, e.g.
alias pd pushd

Do not modify this file unless you know what you are doing.

The normal permissions for this file are read and write for the owner only, and can be set with the command:

	chmod 700 .cshrc

Useful things to put in your .cshrc

Since your .cshrc will be loaded every time you execute a shell it is a useful place to put command aliases, add directories to your command search path, set various shell resources, and set environment variables.

Adding command search paths

The path environment variable informs the shell where to search for its commands. You can display your current path using the command:
	echo $PATH
You can change you current search path by appending your new path to the current path, in this way you do not destroy your current setup. For example to add the directory ~/bin (i.e. a directory called bin in your own home directory) to your search path, then include the following command in your .cshrc:
	setenv PATH ~/bin:$PATH
Your shell will now execute commands in your ~/bin directory, in preference to other commands on the system.

Adding aliases

Aliases allow you to perform a series of complex actions with a single command. They can also be used to supply flags (modifiers) to frequently used commands. For example, this will override the ls command to automatically execute ls -F.
	alias ls '/bin/ls -F'
The next example shows how parameters can be passed into the middle of an alias, in this case to finger a user at doc.ic.ac.uk:
	alias f "finger /:\!:1@doc.ic.ac.uk"
Aliases are very powerful, and can be used to pass paramaters to multiple commands, for a fuller explanation read the manual pages:

Conditional execution of commands

You may want some commands to execute depending on some condition. For example, you may want extra search paths added if you are on a particular machine, or you may not want to add some aliases if you are on an X-terminal.

The following is an example of only executing a set of commands on a certain machine.


	#hostname must be in path.
		
	if (`hostname` == "fuji.doc.ic.ac.uk") then
  		#The following commands with be executed on fuji ONLY
  		source /usr/cap/etc/default.env
  		source /usr/cap/etc/casim.env
	endif
This is an example of how to run a command on an xterm only.
	if( $TERM == xterms || $TERM == xterm ) then
		#Commands here will be executed 
		#ONLY on an xterm.
	else
		#Commands here will be executed 
		#ONLY if not on an xterm.
	endif
© CSG / 2000 / help@doc.ic.ac.uk