When you first login, UNIX will
provide you with a default "environment". An environment simply describes
the specifics about your online world. These specifics might be the type
of monitor you use, the location of your applications, or
perhaps the type of prompt you want to use.
Often, the default environment will be bleak and limited
because, it is ... well it is default. In many cases, you will want to begin
to modify the base environment to suit your individual needs
and preferences. Maybe you will want your prompt to look
differently. Maybe you will want to be notified when you get new mail.
Whatever the case, modifying your environment is pretty simple.
For the most part, customizing your environment
is the job of the shell environment setup file in your home directory. Do an
"ls -a" command in your home directory and you should see one or more of them.
If you don't see any, that is okay, you can make one.
Of course, since there are several shells, there
are also several environment setup files. The following table reviews
each shell and it's associated environment setup file(s).
||Environment Setup File(s)
||Any setup info you want to use will be placed in a .profile file.
||The C Shell uses the .cshrc file every time a new shell is
started. This is an excellent place for aliases, paths and
prompt modifications (we'll discuss those later). The C Shell
also uses the .login file that is run at login time only. Finally,
the .logout file is read when you logout. This is a good place to store
cleanup routines like the deletion of temp files.
||The Korn shell also uses the .profile file but unlike the
Bourne Shell, the Korn Shell uses the .profile file
to set environment variables (we'll discuss those more later)
||Bash is a complete motley. A Bash login shell will
read .bash_profile, .bash_login or .profile. A Bash subshell will
read .bashrc. Finally .bash_logout is read on exit.
||Just like the C Shell except that it uses a .tcshrc instead of .cshrc
Okay, so what exactly goes into one of these environment
Let the following table begin your brain cells churning
|login or profile file
||Define path, environment variables, terminal type or programs
that you find useful at the time of login such as "date",
"cal", "w", "fortune", etc... Remember that this file is loaded
only when you log in.
|rc file (like .tcshrc)
||This type of file is run every time a new shell is opened up
even if it is not a login shell. Thus, you want to define things
here that should apply to all shells such as aliases.
||Put things that you want done each time you logout such as
deleting temp files.
Take a look at the following image that shows several
environment setup files in my home directory
The intricacies of defining your environment
can get pretty complex. In fact, whole books are written about shells and environments
alone. So we will not get too involved here. After all, for the most part
web development will take place on your local machine and you
will use UNIX primarily to store pre designed HTML files.
However, a word should be said about a couple
of common customizations.
The first thing to get a grasp of is your
environment variables. Environment variables are variables that hold
information that should be made available to all programs running
in your shells.
Such information might include default information
such as what type of terminal you are using or where your executable
files are stored, but it can also include variables that you define just
for yourself. When you define an environment variable, this info will
be available to anyone who needs it and this can be very important
because, for example, you do not want to have to explicitly inform every darn program
what type of terminal you are using every time you run a program.
So how do you know what environment variables are
set and how do you set them?
To get a list of the environment variables
currently in effect, use the "printenv" utility.
As you can see, there are many environment variables that are
probably set by default. in fact, the following environment
variables are pretty much standard:
- EDITOR defines the word processing program
that you use.
- HOME defines the absolute pathname of your
- MANPATH contains a lists of directories to find
- PAGER defines your favorite utility for paging through
screens worth of information such as "more"
- PATH specifies a list of directories that
UNIX will look through when you type a command at the prompt. By default
your path should include the usual suspects such as "/usr/bin" and
- PRINTER defines the default printer you
are using. That way, when you use the "lpr" command you do not
have to specify which printer on the network to use.
- PS1 and PS2 contain your primary
and secondary prompts.
- PWD defines the absolute pathname
of your current directory.
- SHELL defines the absolute pathname of the
shell you are using.
- TERM defines the terminal type you are using.
- TZ specifies your time zone.
- USER is set to your username. Sometimes this
variable is called LOGNAME
Below is a screen shot of my environment variables
You can also look at, or edit, your environment setup files.
In my case, all of my environment variables are defined in .bash_profile as
you can see below. (We'll discuss more about what everything means in
just a bit. I just want to show you where the printenv utility
got its info from.)
Notice that in the above example, environment variables are
by listing them and setting them equal to some value. This is true for BASH but not
necessarily true for other shells... For example, a C Shell environment setup file
might contain a line such as:
set history = 100
setenv PATH /bin:/usr/bin:$HOME/bin
In this case, not only are we using "setenv" and "set" keywords,
but we access another environment variable to define PATH. Your best bet is to pick up a book
that describes the specifics of your own shell.
Of course, regardless of how many environment variables
are set, there are really only a few that you will really ever
The most commonly modified environment variable
is the PATH
variable that defines the location of directories that contain
executables. The benefit of the PATH variable is that it makes it easier
to run commands. For example, if you included "/usr/home/selena/bin" in your
PATH you would not need to type "/usr/home/selena/bin/selena.cgi"
to run "selena.cgi" in the "/usr/home/selena/bin" directory.
Instead, you would just type "selena.cgi". When you include
"/usr/home/selena/bin" in your PATH, the shell will know to look there if
it is instructed to run an application but it cannot find
the application in the usual places.
As you can see above, PATH is defined as a colon delimited
list of directories.
Finally, you should know that you can create your
own environment variables by simply defining them as the others are defined such as
MYNAME = Selena Sol (for Bourne Shell)
set MYNAME Selena Sol (for C Shell)
You can also redefine your prompt in the environment setup
file. Why would you want to do this? Well the default prompt given to
you by most UNIX shells is something like a single "%" sign. This is
enough to signal you to start typing but it is not extremely useful. Fortunately
shells give you the ability to modify your prompt to provide other useful bits
of information by setting the PROMPT environment variable.
If you skip above to my own environment listing, you will se
that my prompt is defined to show my host name (eff.org). However, watch what
happens when I change it!
Notice that I changed my prompt definition to include the
"pwd" present working directory and sure enough, my prompt changed in the other
window from "eff.org" to "/home/eff/erict"
Here are some prompt mods that are commonly seen
Table of Contents