DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Sample shell startup files

The C-shell .login and .cshrc

The C shell, like the Korn shell, uses one file to set up the login environment and a different file to set up environments for every subsequent C shell. In C shell, .login is the file read only at login, and .cshrc is the file read each time a csh is started.

While both the Bourne shell and the Korn shell use Bourne shell startup scripts, the C shell uses C-shell startup scripts, so you will notice that variables are set and tests are performed slightly differently. C-shell scripts do not start with a ``:'' because they are intended for use with C shells, not Bourne shells.

A typical C-shell .login might look something like this:

1  #	@(#) login 23.1 91/04/03
2  #
3  # .login	-- Commands executed only by a login C-shell
4  #
5  # Copyright (c) 1985-1995 The Santa Cruz Operation, Inc.
6  # All rights reserved.
7  #
8  # This Module contains Proprietary Information of the Santa Cruz
9  # Operation, Inc., and should be treated as Confidential.
10 #
11 setenv SHELL /bin/csh
12 set ignoreeof				# don't let control-d logout
13 set path = ($path $home/bin .)	# execution search path
14 set noglob
15 set term = (`tset -m ansi:ansi -m :\?ansi -r -S -Q`)
16 if ( $status == 0 ) then
17 	setenv TERM "$term"
18 endif
19 unset term noglob
20 /tcb/bin/prwarn		# issue a warning if password due to expire


lines 1-10
Contain comments.

line 11
Sets the environment variable SHELL to be /bin/csh.

line 12
Tells csh to ignore single end-of-file (EOF) characters; in other words, do not let <Ctrl>D log out, as the comment says.

line 13
Sets the path definition in the same way as the preceding Bourne shell .profile: ``set the path equal to the current path, the bin in the home directory, and the current directory.''

line 14
Turns on the noglob setting. The noglob setting, which prevents filename expansion, is turned on before a tset(C) command is attempted (on line 15). Without noglob, the tset command would be read incorrectly.

lines 15-19
Set up your terminal type using tset. Line 15 is the tset command you have seen before. Line 16 tests to make sure the tset command succeeded and, if it did, line 17 sets the environment variable TERM. Line 18 closes the if statement. Line 19 unsets the term variable and turns off noglob, so filenames now expand as expected when wildcard characters are used.

line 20
Runs prwarn to warn you if your password is due to expire.

A typical .cshrc might look like this:

1  #
2  # .cshrc	-- Commands executed by the C-shell each time it runs
3  #
4  #	@(#) cshrc 3.1 89/06/02
5  #
6  # Copyright (c) 1985-1995 The Santa Cruz Operation, Inc.
7  # All rights reserved.
8  #
9  # This Module contains Proprietary Information of the Santa Cruz
10 # Operation, Inc., and should be treated as Confidential.
11 #

12 set noclobber # don't allow '>' to overwrite 13 set history=20 # save last 20 commands 14 if ($?prompt) then 15 set prompt=\!%\ # set prompt string 16 # some BSD lookalikes that maintain a directory stack 17 if (! $?_d) set _d = () 18 alias popd 'cd $_d[1]; echo ${_d[1]}:; shift _d' 19 alias pushd 'set _d = (`pwd` $_d); cd \!*' 20 alias swapd 'set _d = ($_d[2] $_d[1] $_d[3-])' 21 alias flipd 'pushd .; swapd ; popd' 22 endif 23 alias print 'pr -n \!:* | lp' # print command alias


lines 1-11
Contain comments.

line 12
Turns on noclobber, which prevents you from unintentionally overwriting files using output redirection.

line 13
Sets the length of the command history to 20 commands. Both ksh and csh keep track of old commands and allow you to re-use them.

lines 14-15
Check to see if the prompt string is set, and, if it is not, set it to be a ``%''.

lines 16-22
Set up some command aliases to perform directory stack manipulation. These commands are familiar to users of the Berkeley (Berkeley Standard Distribution -- BSD) UNIX system.

line 23
Sets up the print alias, which runs files through the pr(C) print program before sending them to the printer.

Previous topic: The Korn shell .profile and .kshrc

© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003