Important note

These pages are deprecated (latest changes date from end 2001). More recent information may be found at http://www.coresequence.com/training.php. I leave the old pages here as they are because lots of people are still visiting them (eventhough they aren't spell-checked), and because the basics are still useful.

Customizing your account

In this section we will discuss some of the most common setup features of the shell and look at the shell configuration files.

As a practical exercise, we will experiment on setting the prompt and, just to show that Unix is not boring, you will be introduced to the graphical environment.

Shell setup files

When entering the ls -al (long listing of all files, including the ones starting with a ".") in your homedirectory, you will see one or more files starting with a . and ending in "rc". These are the configuration files for your shell(s), e.g. .bashrc and .tcshrc.

Other configuration files are .login (or .bash_login) and .logout (or .bash_logout) and .profile (or .bash_profile).

These files contain commands, just as you would enter them on the command line. The shell reads the file or "script" one line at the time and executes all commands listed. The exact names of the configuration files depend on the shell that you are using and on your system setup.

In these files you can define the behaviour of your own shell. All these configuration files have their match in the /etc directory, e.g. /etc/profile and /etc/bashrc, where they are applicable to every user that logs in, before that user's own configuration files are checked. Note that they only start with a dot in your own homedirectory.

All of these files are checked at logintime and the commands they contain are executed (except for .logout and /etc/logout which are, of course, checked at logout time).

The contents of these files can be rather confusing, so let's look at a few:

A .profile for bash might look like this:


tille:~>cat .profile
#This is a simple profile
 PATH=/bin:/usr/bin:/usr/local/bin:
 export PATH
 /usr/games/fortune
 date
 umask 002
 setterm -background blue

A .login for a csh might look like this:


tille:~>cat .login
 set path = (/bin /usr/bin /usr/local/bin .)
 /usr/games/fortune
 date
 umask 002
 setterm -background blue

As long as you can set your path yourself, you are able to install your own software in your homedirectory - provided, of course, that the system has enough diskspace to fit your purposes.

Both these files execute the programs date and fortune, as you will see in the exercises(Appendix 3).

The line containing the PATH= or set path = defines the directories to search for Unix commands when no absolute path is given. Whenever you enter a command that doesn't start with a slash, the system will go through the listed paths until it finds the command. This shortens commands bacause the user can now directly enter any command from these directories without having to enter the full pathname. Note that /usr/games is not present in the declaration of the PATH or path variable.

Note

Some System V Unices (e.g. Solaris) use BSD binaries now and then, which are stored in the directory /usr/ucb. The commands in this directory often have the same name as some commonly used ones in other directories. In order not to mess up your system, you should always put /usr/ucb as the last path to follow.

The umask command is a shell built-in command (see appendix 1) and sets the default permissions on a freshly created file or directory. It uses the same values as the chmod command. The umask of 022 takes the permission with value 2 (write) from the group that owns the file and from any other user.

The setterm sets the background of X-terminals to blue.

These files demonstrate that you can run commands at login time just as if you would execute them from the command line. There are many more than we can discuss here, see Appendix 2 for a readinglist. Keep in mind that running interactive commands (e.g. those for which you need to enter passwords) is not advised.

Other useful entries to put in your configuration files are aliases. Aliases prevent painstaking retyping of commonly used or long commands.

Some C shell examples:


alias dir ls					# for (ex-)MS Windows users
alias lll ls -la 				# long listing
alias netschaap 'netscape-communicator &' 	# start browser as a 
						# background job

Some Bash examples:


alias ls='ls --color=tty'			# sets color ls
alias which='type'				# for systems that don't recognize which

For a beginning user, this may all seem awfully frightening. Experiment, make yourself at home with the features of your particular shell. Be careful, you'll be a nerd before you know it. I've included my own .bashrc as an example below:


#################################################################
#   .bashrc file                                                #
#   Executed from non-login interactive bash shells.            #
#################################################################

function new_file {
  local FILE FULLNAME SOURCE

  FILE="$1"
  FULLNAME="$2"
  SOURCE="$3"

  BASE="$HOME/.Shell/${DOMAIN}/${LOCAL_MACHINE}.$FILE"
  if test "$1" = "-f" -o ! -f "$BASE" -o "$HOME/.ShellDiscover/$FILE" 
		-nt "$BASE"; then
    case "$BASH_NEW" in # (((
      0)
        mkdir "$HOME/.Shell"		2>/dev/null
        mkdir "$HOME/.Shell/${DOMAIN}"	2>/dev/null
        echo "Creating new $FULLNAME. Please be patient..."
        BASH_NEW=1
        ;;
      1)
        echo "Creating new $FULLNAME. Please be doctor..."
        BASH_NEW=2
        ;;
      *)
        echo "Creating new $FULLNAME. Please nurse your patients..."
        ;;
    esac
    (. ${HOME}/.ShellDiscover/$FILE > "$BASE.$$")
    if test "`tail -1 \"$BASE.$$\"`" = "# THIS MUST BE THE LAST LINE"; 
      then
      mv "$BASE.$$" "$BASE"
    else
      echo "Could not write $FULLNAME to $BASE.$$. 
	Are you over your quota ?" 1>&2
      rm "$BASE.$$"
    fi
  fi
  if test "$SOURCE"; then
    source "$BASE"
    if test -x "$HOME/.Shell/$FILE""_user_always"; then
      source "$HOME/.Shell/$FILE""_user_always"
    fi
  fi
}

if test -z "$OS" -o -z "$LOCAL_MACHINE" -o -z "$DOMAIN"; then
  # set path variable
  # Throw in lots of stuff to get initial command working. 
  # We clean up later
  export PATH="/bin:/usr/lib/mh:/lib:/usr/bin:/usr/local/bin\
	:/usr/ucb:/usr/dbin:$PATH"
  export OS=`uname`
  case "$OS" in
    world) OS = "Sco"	# Do this kind of sick stuff on SCO machines
    ;;
  esac
  LOCAL_MACHINE=`hostname | sed -e "s/\..*//"`
  if test -z "$LOCAL_MACHINE"; then
    LOCAL_MACHINE=`uname -n`
  fi
  export LOCAL_MACHINE
  DOMAIN=`dnsdomainname 2>/dev/null`
  if test "$DOMAIN" = "" -o "$DOMAIN" = "$LOCAL_MACHINE"; then
    DOMAIN=`grep "^domain[ 	]" /etc/resolv.conf | sed -e "s/^domain[ 	]*//" -e "s/\.*$//"`
    if test -z "$DOMAIN"; then
      DOMAIN=`domainname 2>/dev/null`
    fi
  fi
  if test -z "$DOMAIN" -o "$DOMAIN" = "(none)"; then
    if ! DOMAIN=`cat /etc/defaultdomain 2>/dev/null`; then
      DOMAIN=`grep "^domain" 2>/dev/null < /etc/resolv.conf | \
	sed -e "s/domain[ 	][ 	]*//"`
      if test -z "$DOMAIN"; then
        DOMAIN=`hostname | sed -e "s/[^.]*.//"`
        if test -z "$DOMAIN"; then
          DOMAIN="reboot"
        fi
      fi
    fi
  fi
  export DOMAIN
fi
umask 002

BASH_NEW=0
new_file env     environment 1
new_file aliases aliases     1
# new_file "fvwmrc"  "fvwmrc"
unset BASH_NEW
echo -n "$XTERMID"