-->
Previous Table of Contents Next


Customizing bash

Many ways of customizing bash have already been described in this chapter. Until now, the changes that you made affected only the current bash session. As soon as you quit, all of the customizations will be lost. You can, however, make the customizations more permanent by storing them in a bash initialization file.

You can put any commands that you want to be executed each time bash is started into this initialization file. Commands that are typically found in this file are alias commands and variable initializations.

The bash initialization file is named either .profileor .bash_profile, depending on the version of Linux you are using. For simplicity’s sake, we’ll assume .profile is used, although you should substitute the name your Linux system uses. Each user who uses bash has a .profile file in his home directory. This file is read by bash each time it starts, and all of the commands contained within it are executed.

Many Linux systems use a default profile file (note the lack of a period before the filename). This file is located in the /etc directory and is read when you start bash. If you want to add your own customizations to bash, you must copy this file into your home directory (if it is not already there) and call it .profile.


Note:  
Some setup programs automatically make a copy of the .profile file in your home directory for you when they create your login. However, not all routines do this, so you should check your home directory first. Remember that all files starting with a period are hidden and can only be displayed with the ls -A or ls -a command.

bash Command Summary

Some of the most useful commands built into the bash shell are summarized in Table 11.2.

Table 11.2. The bash commands we’ve used in this chapter.

bash command What it’s used for

alias Used to set bash aliases (command nicknames that can be defined by the user).
bg Background command. Forces a suspended process to continue to execute in the background.
cd Change working directory. This command changes the current working directory to the directory specified as an argument.
exit Terminates the shell.
export Causes the value of a variable to be made visible to all subprocesses that belong to the current shell.
fc Fix command. Used to edit the commands in the current history list.
fg Foreground command. Forces a suspended process to continue to execute in the foreground.
help Displays help information for bash built-in commands.
history Brings up a list of the last n commands that were entered at the command prompt, where n is a configurable variable specifying the number of commands to remember.
Kill Used to terminate another process.
pwd Print working directory. Prints the directory in which the user is currently working.
unalias Used to remove aliases that have been defined using the alias command.

bash has many more commands than are listed here, but these are the most frequently used ones. To see the other commands bash offers and for more details of the commands listed, refer to the bash man page (type man bash).

bash Variables

There are a lot of variables used by bash. Some of the most useful of these variables, including the variable name and a brief description, are shown in Table 11.3.

Table 11.3. the most commonly used bash variables.

Variable name What it’s used for

EDITOR, FCEDIT The default editor for the fc bash command.
HISTFILE The file used to store the command history.
HISTSIZE The size of the history list.
HOME The HOME directory of the current user.
OLDPWD The previous working directory (the one that was current before the current directory was entered).
PATH The search path that bash uses when looking for executable files.
PS1 The first-level prompt that is displayed on the command line.
PS2 The second-level prompt that is displayed when a command is expecting more input.
PWD The current working directory.
SECONDS The number of seconds that have elapsed since the current bash session was started.

bash has many more variables than are listed here, but the most commonly used ones are shown. To find out the other variables bash offers, call up the man page with the command man bash.

Summary

In this chapter you looked at some of the useful features of the Bourne Again Shell, bash. You have seen how command completion, aliasing, and job control can all combine to make you more productive and efficient when working with bash.

In the next chapter we’ll look at another popular Linux shell, the Public Domain Korn Shell (pdksh). It offers many useful features, too, providing you with a choice of shells. If you want to skip ahead to learn about other subjects, feel free:

Learn about shell programming and how you can use it to make your experience with bash more powerful, in Chapter 14, “Shell Programming.”
Learn about using editors to create and edit files, in Chapter 16, “Text Editors: vi and emacs.”


Previous Table of Contents Next