Manipulating your Environment
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).
Okay, so what exactly goes into one of these environment setup files? Let the following table begin your brain cells churning
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.
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:
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 set 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
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 use/modify.
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)
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