Configuring and Building bash

To compile bash "straight out of the box" is easy;[2] you just type configure and then make! The bash configure script attempts to work out if you have various utilities and C library functions, and whereabouts they reside on your system. It then stores the relevant information in the file config.h. It also creates a file called config.status that is a script you can run to recreate the current configuration information. While the configure is running, it prints out information on what it is searching for and where it finds it.

The configure script also sets the location that bash will be installed; the default is the /usr/local area (/usr/local/bin for the executable, /usr/local/man for the manual entries etc.). If you don't have root privileges and want it in your own home directory, or you wish to install bash in some other location, you'll need to specify a path to configure. You can do this with the —exec-prefix option. For example:

广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

$ configure --exec-prefix=/usr

specifies that the bash files will be placed under the /usr directory. Note that configure prefers option arguments be given with an equals sign (=).

After the configuration finishes and you type make, the bash executable is built. A script called bashbug is also generated, which allows you to report bugs in the format the bash maintainers want. We'll look at how you use it later in this chapter.

Once the build finishes, you can see if the bash executable works by typing ./bash. If it doesn't, turn to the Section 11.3 in Chapter 11.

To install bash, type make install. This will create all of the necessary directories (bin, info, man and its subdirectories) and copy the files to them.

If you've installed bash in your home directory, be sure to add your own bin path to your PATH and your own man path to MANPATH.

bash comes preconfigured with nearly all of its features enabled, but it is possible to customize your version by specifying what you want with the —enable- feature and —disable- feature command-line options to configure.

Table 12-1 is a list of the configurable features and a short description of what those features do.

Table 12-1. Configurable features

Feature

Description

alias

Support for aliases.

arith-for-command

Support for the alternate form of the `for' command that behaves like the C language for statement.

array-variables

Support for one dimensional arrays.

bang-history

C-shell-like history expansion and editing.

brace-expansion

Brace expansion.

command-timing

Support for the time command.

cond-command

Support for the [[ conditional command.

cond-regexp

Support for matching POSIX regular expressions using the =~ binary operator in the [[ conditional command.

directory-stack

Support for the pushd, popd, and dirs directory manipulation commands .

disabled-builtins

Whether a built-in can be run with the builtin command, even if it has been disabled with enable -n.

dparen-arithmetic

Support for ((...)) .

help-builtin

Support for the help built-in.

history

History via the fc and history commands .

job-control

Job control via fg, bg, and jobs if supported by the operating system.

multibyte

Support for multibyte characters if the operating system provides the necessary support.

net-redirections

Special handling of filenames of the form /dev/tcp/HOST/PORT and /dev/udp/HOST/PORT when used in redirections.

process-substitution

Whether process substitution occurs, if supported by the operating system.

prompt-string-decoding

Whether backslash escaped characters in PS1, PS2, PS3, and PS4 are allowed .

progcomp

Programmable completion facilities. If readline is not enabled, this option has no effect .

readline

readline editing and history capabilities.

restricted

Support for the restricted shell, the -r option to the shell, and rbash.

select

The select construct.

usg-echo-default

xpg-echo-default

Make echo expand backslash-escaped characters by default, without requiring the -e option. This sets the default value of the xpg_echo shell option to on, which makes the bash echo behave more like the version specified in the Single Unix Specification, Version 2.

The options disabled-builtins and xpg-echo-default are disabled by default. The others are enabled.

Many other shell features can be turned on or off by modifying the file config-.top.h. For further details on this file and configuring bash in general, see INSTALL.

Finally, to clean up the source directory and remove all of the object files and executables, type make clean. Make sure you run make install first, otherwise you'll have to rerun the installation from scratch.