Выбрать главу

► TERM — To set the type of terminal in use, such as vt100, which can be important when using screen-oriented programs, such as text editors

► MACHINE — To declare system type, system architecture, and so on

NOTE

Each shell can have its own feature set and language syntax, as well as a unique set of default environment variables. See Chapter 15, "Remote Access with SSH," for more information about using the different shells included with Fedora.

At the command line, you can use the env or printenv commands to display these environment variables, like so:

$ env

SSH_AGENT_PID=2881

HOSTNAME=teletran.hudson.com

SHELL=/bin/bash

TERM=xterm

DESKTOP_STARTUP_ID=

USERNAME=andrew

MAIL=/var/spool/mail/andrew

PATH=/usr/kerberos/bin:/usr/lib/ccache:/usr/local/bin:\

/usr/bin:/bin:/home/andrew/bin

DESKTOP_SESSION=default

INPUTRC=/etc/inputrc

PWD=/home/andrew

KDEDIRS=/usr

SSH_ASKPASS=/usr/libexec/openssh/gnome-ssh-askpass

SHLVL=2

HOME=/home/andrew

DISPLAY=:0.0

This abbreviated list shows a few common variables. These variables are set by configuration or resource files contained in the /etc, /etc/skel, or user /home directory. You can find default settings for bash, for example, in /etc/profile, /etc/bashrc, .bashrc, or .bash_profile files installed in your home directory. Read the man page for bash for details about using these configuration files.

One of the most important environment variables is $PATH, which defines the location of executable files. For example, if, as a regular user, you try to use a command that is not located in your $PATH (such as the ifconfig command), you will see something like this:

$ ifconfig

-bash: ifconfig: command not found

However, you might know that ifconfig is definitely installed on your system, and you can verify this by using the whereis command, like so:

$ whereis ifconfig

ifconfig: /sbin/ifconfig /usr/share/man/man8/ifconfig.8.gz

You can also run the command by typing its full pathname, or complete directory specification like this:

$ /sbin/ifconfig

As you can see in this example, the ifconfig command is indeed installed. What happened is that by default, the /sbin directory is not in your $PATH. One of the reasons for this is that commands under the /sbin directory are normally intended to be run only by root. You can add /sbin to your $PATH by editing the file .bash_profile in your home directory (if you use the bash shell by default, like most Linux users). Look for the following line:

PATH=$PATH:$HOME/bin

You can then edit this file, perhaps using the vi editor (discussed in this chapter), to add the /sbin directory like so:

PATH=$PATH:/sbin:$HOME/bin

Save the file. The next time you log in, the /sbin directory is in your $PATH. One way to use this change right away is to read in the new settings in .bash_profile by using the bash shell's source command as follows:

$ source .bash_profile

You can now run ifconfig without the need to explicitly type its full pathname.

Some Linux commands also use environment variables — for example, to acquire configuration information (such as a communications program looking for a variable such as BAUD_RATE, which might denote a default modem speed).

To experiment with the environment variables, you can modify the PS1 variable to manipulate the appearance of your shell prompt. If you are working with bash, you can use its built-in export command to change the shell prompt. For example, if your default shell prompt looks like

[andrew@teletran ~]$

you can change its appearance by using the PS1 variable like this:

$ PS1='$OSTYPE r001z ->'

After you press Enter, you see the following:

linux-gnu r001z ->

NOTE

See the bash man page for other variables you can use for prompt settings.

Using the Text Editors

Linux distributions include a number of applications known as text editors that you can use to create text files or edit system configuration files. Text editors are similar to word processing programs, but generally have fewer features, work only with text files, and might or might not support spell checking or formatting. The text editors range in features and ease of use, but are found on nearly every Linux distribution. The number of editors installed on your system depends on what software packages you've installed on the system.

Some of the console-based text editors are as follows:

► emacs — The comprehensive GNU emacs editing environment, which is much more than an editor; see the section "Working with emacs" later in this chapter

► joe — Joe's Own Editor, a text editor, which can be used to emulate other editors

► nano — A simple text editor similar to the pico text editor included with the pine email program

► vim—An improved, compatible version of the vi text editor (which we call vi in the rest of this chapter because it has a symbolic link named vi and a symbolically linked manual page)

Note that not all text editors described here are screen oriented. Some of the text editors for the X Window System, which provide a graphical interface, such as menu bars, buttons, scrollbars and so on, are the following:

► gedit — A GUI text editor for GNOME

► kate — A simple KDE text editor

► kedit — Another simple KDE text editor

A good reason to learn how to use a text-based editor, such as vi, is that system maintenance and recovery operations generally never take place during X Window sessions (negating the use of a GUI editor). Many larger, more complex and capable editors do not work when Linux is booted to its single-user or maintenance mode. See Chapter 11 for more information about how Fedora boots. If anything does go wrong with your system, you probably won't be able to get into the X Window System, making knowledge and experience of using both the command line and text editors such as vi important. Make a point of opening some of the editors and playing around with them; you never know — you might just thank me someday!

Another reason to learn how to use a text-based editor under the Linux console mode is so that you can edit text files through dialup or network shell sessions because many servers do not host graphical desktops.