Cabrillo College


Objectives

In this lab you will customize your login environment to suit your needs and preferences. By modifying environment variables and editing your .bash_profile and .bashrc files, you will customize your shell environment in a number of different ways.

Forum

If you get stuck, have a question or want to share something you learned with this lab then use the CIS 90 Forum at http://simms-teach.com/forum/viewforum.php?f=17

Procedure

Log on to a Unix machine and start this lab from your home directory.


  1. Display the contents of your PWD environment variable. Change to your bin subdirectory and display the same variable. How did it change?
  2. Change back to your home directory.
  3. Display the contents of your PATH environment variable. Note the colon (:) separating the different directory names. What is the last directory in which the system searches for commands?
  4. Make a new environment variable called GREETING and assign it an appropriate salutation. Don't forget to use quotes if your message has whitespace in it.
  5. Use the env command to see if it is in your environment. Is it there? What must you do to put it in the environment?
  6. Export the variable GREETING and use env to verify it's there.
  7. Invoke a new bash shell process by typing:
    bash
    Now use the unset command to unset the variable PS1. What Happened?
  8. Reset the PS1 variable by entering the following command:
    PS1="Yes master: "
    What happens to your primary prompt?
  9. Now exit out of the child shell by typing Ctrl-d. What is the prompt now? What does this tell you about the effect changes made by children have on their parents?
  10. Try to exit from your login shell by typing Ctrl-d
    This is a shell feature that protects you from accidentally logging out. You can turn it off using the set command:
    set +o ignoreeof
    Type the above command and then try to exit the shell with Ctrl-d

.bashrc and .bash_profile


Aliasing is a mechanism provided by the bash shell that allows you to define your own commands, or to redefine UNIX commands. Alias definitions should be stored in your .bashrc file.

  1. Edit the .bashrc file in your home directory by adding the following three lines to the bottom of the file:
    alias bye="clear;exit"
    alias rm="rm -i"
    alias bill="cd /home/cis90/$LOGNAME/poems/Shakespeare"

    Note that there is no UNIX bye or bill commands.
Your .bash_profile, like your .bashrc file, is a shell script that is run once each time you log in. It establishes your working environment by defining environment variables, setting your terminal type and setting other shell characteristics, like ignoreeof.
  1. Edit your .bash_profile and make the following changes:
    • Replace the directory, $HOME/../bin with the directory, /home/cis90/bin to your PATH environment variable.
    • Change the command that sets your umask to: umask 006
    • Below the umask command line, turn messaging off with the command:
      mesg n
    • Add a shell environment variable named, BIRTHDAY and set it equal to the date of your birth using the form mm/dd/yy.
      Export this variable, since you will want your children to know when your birthday is.
    • At the bottom of the file add as the last line: riddle
  2. Now that you have made these changes, run your .bashrc file using the UNIX dot source command:
    source .bashrc
  3. Try out your new rm command by removing some file you don't need anymore.
  4. run your bill command. What happens?
  5. Try out your bye command.
    When you log back in again, you should be confronted with a riddle.
    Try out the riddle and then submit your lab by following the instructions below.

To turn in your lab, combine your .bashrc file, your .bash_profile file, and the output of the env command into a new file called lab10. Then copy this file as follows:
cp lab10 /home/rsimms/cis90/lab10.$LOGNAME