start page | rating of books | rating of authors | reviews | copyrights

Book HomeBook TitleSearch this book

Chapter 3. Customizing Your Environment

Contents:

The .profile File
Aliases
Options
Shell Variables
Customization and Subprocesses
Customization Hints

A common synonym for a Unix shell, or for the interface any computer program presents, is an environment. An environment is typically a collection of concepts that expresses the things a computer does in terms designed to be understandable and coherent, and a look and feel that is comfortable.

For example, your desk at work is an environment. Concepts involved in desk work usually include memos, phone calls, letters, forms, etc. The tools on or in your desk that you use to deal with these things include paper, staples, envelopes, pens, a telephone, a calculator, etc. Every one of these has a set of characteristics that express how you use it; such characteristics range from location on your desk or in a drawer (for simple tools) to more sophisticated things like which numbers the memory buttons on your phone are set to. Taken together, these characteristics make up your desk's look and feel.

You customize the look and feel of your desk environment by putting pens where you can most easily reach them, programming your phone buttons, etc. In general, the more customization you have done, the more tailored to your personal needs -- and therefore the more productive -- your environment is.

Similarly, Unix shells present you with such concepts as files, directories, and standard input and output, while Unix itself gives you tools to work with these, such as file manipulation commands, text editors, and print queues. Your Unix environment's look and feel is determined by your keyboard and display, of course, but also by how you set up your directories, where you put each kind of file, and what names you give to files, directories, and commands. There are also more sophisticated ways of customizing your shell environment.

The most basic means of customization that the Korn shell provides are these:

Aliases
Synonyms for commands or command strings that you can define for convenience.

Options
Controls for various aspects of your environment, which you can turn on and off.

Variables
Placeholders for information that tell the shell and other programs how to behave under various circumstances.

There are also more complex ways to customize your environment, mainly the ability to program the shell, which we will see in later chapters. In this chapter, we cover the techniques listed above.

While most of the customizations obtainable with the above techniques are straightforward and apply to everyday Unix use, others are rather arcane and require in-depth technical knowledge to understand. Most of this chapter concentrates on the former. Because we want to explain things from the perspective of tasks you may want to perform, rather than that of the specific features of the Korn shell, a few little details may fall through the cracks (such as miscellaneous options to certain commands). We suggest you look in Appendix B for this type of information.

3.1. The .profile File

If you want to customize your environment, it is most important to know about a file called .profile in your home (login) directory. This is a file of shell commands, also called a shell script, that the Korn shell reads and runs whenever you log in to your system.

If you use a large machine in an office or department, the odds are good that your system administrator has already set up a .profile file for you that contains a few standard things. This is one of the "hidden" files mentioned in Chapter 1; other common hidden files include .xinitrc (for the X Window System), .emacs (for the GNU Emacs editor), and .mailrc (for the Unix mail program).

Your .profile, together with the environment file that we discuss towards the end of this chapter, will be the source of practically all of the customizations we discuss here as well as in subsequent chapters. Therefore, it is very important for you to become comfortable with a text editor like vi or Emacs so that you can try whatever customization techniques strike your fancy.

Bear in mind, however, that if you add commands to your .profile, they will not take effect until you log out and log back in again, or type the command login.[34] Of course, you need not immediately add customization commands to your .profile -- you can always just test them by typing them in yourself. (Be sure you test your changes though: it is possible to set things up in your .profile such that you can't log back in! Test your changes before logging out, by logging in again, perhaps from a new window or virtual console.)

[34] This has the same effect as logging out and logging in again, although it actually replaces your login session with a new one without explicitly terminating the old session.

If you already have a .profile, it's likely to contain lines similar to some of these:

PATH=/sbin:/usr/sbin:/usr/bin:/etc:/usr/ucb:/local/bin:
stty stop ^S intr ^C erase ^?
EDITOR=/usr/local/bin/emacs
SHELL=/bin/ksh
export EDITOR

These commands set up a basic environment for you, so you probably shouldn't change them until you learn about what they do -- which you will by the end of this chapter. When you edit your .profile, just put your additional lines in afterwards.

3.1.1. The /etc/profile File

Every user has a personal .profile file in the home directory. While your system administrator may have provided you with an initial .profile file when your account was first set up, you are free to customize it as you see fit.

There is an additional, system-wide, customization file known as /etc/profile. If this file exists, the Korn shell reads and executes it as the very first thing it does, even before reading your personal .profile file. This is where your system administrator places commands that should be executed by every user upon login, and where he or she places system-wide defaults, such as adding extra directories to the PATH variable (which, as you will see later in this chapter, tells the shell where to look for programs to run).

It pays to be aware of this file, since it may have settings in it that you might wish to override in your own .profile file. (At least, once you understand what it's doing!) If the file exists, it will be readable and will contain shell commands in it, just like your .profile. It may be worthwhile to peruse the version on your system; you may learn something that way.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.