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=9
Procedure
Log on to a Unix machine and start this lab from your home
directory.
- Display the contents of your PWD environment variable. Change to your bin
subdirectory and display the same variable. How did it change?
- Change back to your home directory.
- 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?
- 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.
- 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?
- Export the variable GREETING and use env to verify it's there.
- Invoke a new bash shell process by typing:
bash
Now use the unset command to unset the variable PS1.
What Happened?
- Reset the PS1 variable by entering the following command:
PS1="Yes master: "
What happens to your primary prompt?
- 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?
- 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.
- 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.
- 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
- Now that you have made these changes, run your .bashrc file using
the UNIX dot source command:
source .bashrc
- Try out your new rm command by removing some file you
don't need anymore.
- run your bill command. What happens?
- 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