previous contents up next

Unix for Advanced Users

3. The Shell

3.3. Dot files

Many unix programs read start-up files that provide parameters that are used to customize program execution. The files usually have names that begin with a period such .cshrc or .mailrc. The leading periods in the file names prevent the names from appearing in listings of directory contents unless the -a command line flag is used with ls. Hence, the name ``dotfiles". Shells are just programs, and they read ``dotfiles" when they start up.

Shell dotfiles contain commands that shells execute. They can contain most constructs such as aliasing and I/O redirection from the previous section and more advanced features discussed in the next section on shell scripting.

Simple dotfiles set the path, environment variables and command aliases. Here, is a simple .profile from a Sun user's home directory. Recall that .profile is used for borne shell logins and for bash shell logins if a .bash_profile file is unavailable.

#       Set the mail message file

MAIL=/usr/mail/${LOGNAME:?}

#	Set path to search for commands

PATH=/opt/SUNWspro/bin:/usr/openwin/bin:/usr/local/bin:$PATH

#	Set path to search for manual pages

MANPATH=/opt/SUNSspro/man:/usr/openwin/man:/usr/local/man:/usr/share/man:/usr/ma
n

#	Set path to search for dynamically loaded libraries

LD_LIBRARY_PATH=/opt/SUNWspro/lib:/usr/dt/lib:/usr/openwin/lib:/usr/lib:/lib
Commands .cshrc and .bashrc are executed each time that their respective shells are invoked. Below is an example of a .cshrc in which the user sets the umask, a path and an alias.
# My .cshrc

source /etc/cshrc   	# get system-wide cshrc
			
			# set path
set path=(~/bin /usr/bin/X11 $path)

			# set permissions on new files
umask 066
			# alias ls to ls with my favorite options
alias ls 'ls -FC'
Dotfiles can contain more complex constructs such as if-then statements that we cover in the next section. Here is a portion of a .cshrc file of a frustrated linux user whose terminal types are not appreciated on the mother ship when she connects to it. These statements are from the .cshrc file on the mother ship.
# host sunflower can't deal with linux terminal
# or color xterms.

# First, check to see that terminal type is
# defined.

if ( $?term ) then
   if ($term == xterm-color) then
      set term=xterm
   endif
   if ($term == linux) then
      set term=vt100
   endif
endif
previous contents up next