Datasheet

Task 1.8: Manage the Shell Environment
41
Suppose you don’t want to use Vi as your default editor, though; perhaps you prefer nano.
You can adjust your default editor by changing the environment variable:
$ export EDITOR="/usr/bin/nano"
Check that /usr/bin/nano exists before typing this command. If it doesn’t
exist, locate the file’s true location or substitute another editor, such as /usr/
bin/emacs or /usr/bin/jed.
You must use the export command to set the environment variable, not simply a variable
for the current bash session, since $EDITOR is used by programs other than bash. Once the
environment variable has been set, test it by typing crontab -e again. You should see the
same (probably empty) file you saw before appear in your new editor.
Making Your Changes Permanent
Chances are you don’t want to type a series of commands to adjust your environment variables every
time you log into your Linux system or launch a new xterm window. You can automate the process
by modifying bash configuration files. Table 1.4 summarizes the locations and names of these files.
The bash configuration files can be either global (they apply to all users) or user (they apply
to individual users), and either login files (they apply to login sessions, such as those initiated
from a text-mode login prompt) or non-login files (they apply to non-login sessions, such as
those started in xterm windows). The precise names used for these files varies from one distri-
bution to another. The most common user configuration files are ~/.bashrc and ~/.profile,
so look for those files. To make your changes permanent, you must locate existing lines that set
the environment variables you want to modify or add new lines.
Whatever the name or location, bash configuration files are actually shell scripts, as described
in more detail in Task 1.9. For now, you can simply add or modify existing export commands.
Type the commands in the shell script just as you’d type them at a command prompt. If you need
to add a line rather than modify an existing one, be careful to keep it out of command structures,
such as if statements. Your best bet is to add new lines to the very end of the file.
Try modifying an appropriate bash login script to change the shell prompt or default editor.
Log out, log in again, and test your changes. If they didn’t work, restore the file to its original
TABLE 1.4 Common bash Configuration Files
Type of File Login File Location Non-Login File Location
Global /etc/profile and files in /etc/
profile.d
/etc/bashrc or /etc/bash.bashrc
User ~/.bash_login, ~/.profile, or
~/.bash_profile
~/.bashrc
83484.book Page 41 Monday, September 18, 2006 8:58 AM