-->
Previous Table of Contents Next


Configuring Your Login Environment

Before you see the shell prompt, Linux sets up your default environment. The Linux environment contains settings and data that control your session while you’re logged in. Of course, as with all things in Linux, you’re completely free to change any of these settings to suit your needs.

Your session environment is divided into two components:

  The first component, called the terminal environment, controls your terminal (more properly, the behavior of the computer’s port to which you connect the cable from your terminal).


NOTE:  Because Linux runs on a PC, the “terminal” is actually your monitor and keyboard. You may or may not have other terminals connected to your Linux system. Of course, you do have six virtual terminals that you can log in from.
  The second component, called the shell environment, controls various aspects of the shell and any programs you run.

You should first know about your terminal environment.

Setting the Terminal Environment

Your login session actually consists of two separate programs that run side by side to give you the appearance of having the machine to yourself. Although the shell is the program that receives your instructions and executes them, before the shell ever sees your commands, everything you type must first pass through the relatively transparent program called the device driver.

The device driver controls your terminal. It receives the characters you type and determines what to do with them—if anything—before passing them on to the shell for interpretation. Likewise, every character generated by the shell must pass through the device driver before being delivered to the terminal. This section is first concerned with how to control the behavior of your device driver.

Linux is unique in that every device connected to the system looks, to a program, just like every other device, and all devices look like files. It’s the task of the different device drivers in your system to accomplish this transformation. A hard disk in the system behaves very differently from your terminal, yet it’s the job of their respective device drivers to make them look identical to a program.

For example, a disk has blocks, sectors, and cylinders, all of which must be properly addressed when reading and writing data. Your terminal, on the other hand, accepts a continuous stream of characters, but those characters must be delivered to the terminal in an ordered and relatively slow manner. The device driver orders this data and sends it to you at 1200, 2400, 9600, or higher bits per second (bps) and inserts stop, start, and parity bits in the data stream.

Because your terminal is always connected to the system, the device driver allows you to define special characters, called control characters, that serve as end-of-file and end-of-line markers for your shell. The device driver also allows you to define control characters that send signals to a running process (such as the interrupt signal, which can, in most cases, stop a running process and return you to the shell). Figure 18.1 shows one way that the Linux kernel, shell, and device driver behave.


FIG. 18.1  You can understand how Linux interacts with the user through the command shell.

You can set dozens of parameters for your terminal, but most of them are handled automatically. However, you should know about a few parameters and modes.

The device driver has two modes of operation, called cooked and raw. In raw mode, all the characters you type pass directly to the shell or to a program run by the shell. Programs such as editors and spreadsheets require raw mode and set it up automatically. When such programs end, they normally reset your terminal to cooked mode—but not always. When your terminal is in raw mode, it doesn’t respond to control keys such as the interrupt key.

When your terminal is in cooked mode, every key you type is interpreted by the device driver. Normal keys are stored in a buffer until the end-of-line key is pressed. In most cases, the end-of-line key is the <Enter> or <Return> key (however, this key can be changed). When the device driver receives the end-of-line character, it interprets the entire line before passing the interpreted or parsed line on to the shell or application program. Table 18.1 lists the most important control keys.

Table 18.1 Control Keys

Key Name Description

Interrupt Interrupts the execution of a running program. When you give Linux a command and press the end-of-line key, a program normally runs until normal completion. If you press the interrupt key, you send a signal to the running program, telling it to stop. Some programs ignore this signal; if your terminal is in raw mode, the interrupt key passes directly to the program and may not have the desired effect. The UNIX convention is to use the <Del> key as the interrupt key, but Linux changes this key to <Ctrl-c> for the convenience of people familiar with MS-DOS and other systems that use this key combination.
Erase Deletes the last character in the buffer. This key is defined as the <Backspace> key. The erase key works just like the Backspace key on a typewriter. On some terminals and systems, there’s confusion between the <Delete> and <Backspace> keys.
Kill Deletes everything in the buffer before it passes to the shell or application program. This key is normally defined as the @ character. Unlike pressing the interrupt key, you don’t see a new shell prompt when you press the kill key—the device driver simply waits for you to type more text.
End-of-line Tells the device driver that you’ve finished entering text and want the text interpreted and passed on to the shell or application program. Linux uses the <Enter> or <Return> key.
End-of-file Tells the shell to exit and display the login prompt. The end-of-file character is the <Ctrl-d> character. Linux treats all devices as though they were files; because your terminal is a source of virtually unlimited characters, Linux uses the end-of-file key as a way for you to signal that you’re done with your login session.


Previous Table of Contents Next