Learning the Korn Shell

Learning the Korn ShellSearch this book
Previous: 2.6 Finger HabitsChapter 3Next: 3.2 Aliases

3. Customizing Your Environment

The .profile File
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:


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


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


Place-holders 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 will 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 will concentrate 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, Reference Lists 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, Korn Shell Basics; other common hidden files include .X11Startup (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 will see towards the end of this chapter, will be the source of practically all of the customizations we will 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. [1] Of course, you need not immediately add customization commands to your .profile-you can always just test them by typing them in yourself.

[1] 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:

stty stop ^S intr ^C erase ^? 
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.

Previous: 2.6 Finger HabitsLearning the Korn ShellNext: 3.2 Aliases
2.6 Finger HabitsBook Index3.2 Aliases

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System