| < Day Day Up > |
12.1. Obtaining bash
If you have a direct connection to the Internet, you should have no trouble obtaining
bash
;
The bash home page is located at http://www.gnu.org/software/bash/bash.html and you can find the very latest details of the current distribution and where to obtain it from there. You can also get bash on CD-ROM by ordering it directly from the Free Software Foundation, either via the web ordering page at http://order.fsf.org or from: The Free Software Foundation (FSF) 59 Temple Place - Suite 330 Boston, MA 02111-1307 USA Phone: +1-617-542-5942 Fax: +1-617-542-2652 Email: order@fsf.org |
| < Day Day Up > |
| < Day Day Up > |
12.2. Unpacking the Archive
Having obtained the archive file by one of the above
The archive contains all of the source code needed to compile bash and a large amount of documentation and examples. We'll look at these things and how you go about making a bash executable in the rest of this chapter. |
| < Day Day Up > |
| < Day Day Up > |
12.3. What's in the ArchiveThe bash archive contains a main directory ( bash-3.0 for the current version) and a set of files and subdirectories. Among the first files you should examine are:
You should also be aware of two directories:
The other files and directories in the archive are mostly things that are needed during the build. Unless you are going to go hacking into the internal workings of the shell, they shouldn't concern you. 12.3.1. DocumentationThe doc directory contains a few articles that are worth reading. Indeed, it would be well worth printing out the manual entry for bash so you can use it in conjunction with this book. The README file gives a short summary of the files. The document you'll most often use is the manual page entry ( bash.1 ). The file is in troff formatthat used by the manual pages. You can read it by processing it with the text-formatter nroff and piping the output to a pager utility: nroff -man bash.1 more should do the trick. You can also print it off by piping it to the lineprinter ( lp ). This summarizes all of the facilities your version of bash has and is the most up-to-date reference you can get. This document is also available through the man facility once you've installed the package, but sometimes it's nice to have a hard copy so you can write notes all over it. Of the other documents, FAQ is a Frequently Asked Questions document with answers, readline.3 is the manual entry for the readline facility, and article.ms is an article about the shell that appeared in Linux Journal , by the current bash maintainer, Chet Ramey. 12.3.2. Configuring and Building bashTo 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
$ 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
Once the build finishes, you can see if the
bash
executable works by typing
./bash
. If it doesn't,
To install
bash
, type
make install
. This will create all of the necessary directories (
bin
,
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
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,
12.3.3. Testing bash
There are a series of tests that can be run on your newly built version of
bash
to see if it is running correctly. The tests are scripts that are derived from problems
To run the tests just type
make tests
in the main
bash
directory. The
If any of the tests fail, you'll see a list of things that represent differences between what is expected and what
12.3.4. Potential ProblemsAlthough bash has been installed on a large number of different machines and operating systems, there are occasionally problems. Usually the problems aren't serious and a bit of investigation can result in a quick solution. If bash didn't compile, the first thing to do is check that configure guessed your machine and operating system correctly. Then check the file NOTES , which contains some information on specific UNIX systems. Also look in INSTALL for additional information on how to give configure specific compilation instructions. 12.3.5. Installing bash as a Login Shell
Having installed
bash
and made sure it is working correctly, the
Individual users can use the
chsh
(change shell) command after they log in to their accounts.
chsh
asks for their password and displays a list of
Another way to change the login shell is to edit the password file directly. On most systems, /etc/passwd will have lines of the form: cam:pK1Z9BCJbzCrBNrkjRUdUiTtFOh/:501:100:Cameron Newham:/home/cam:/bin/bash cc:kfDKDjfkeDJKJySFgJFWErrElpe/:502:100:Cheshire Cat:/home/cc:/bin/bash As root you can just edit the last field of the lines in the password file to the pathname of whatever shell you choose. If you don't have root access and chsh doesn't work, you can still make bash your login shell. The trick is to replace your current shell with bash by using exec from within one of the startup files for your current shell. If your current shell is similar to sh (e.g., ksh ), you have to add the line: [ -f / pathname /bash ] && exec / pathname /bash --login to your .profile , where pathname is the path to your bash executable.
You will also have to create an empty file called
.bash_profile
. The existence of this file
If your current shell is similar to csh (e.g., tcsh ) things are slightly easier. You just have to add the line: if (-f / pathname /bash) exec / pathname /bash --login to your .login , where pathname is the path to your bash executable. 12.3.6. ExamplesThe bash archive also includes an examples directory. This directory contains some subdirectories for scripts, functions, and examples of startup files. The startup files in the startup-files directory provide many examples of what you can put in your own startup files. In particular, bash_aliases gives many useful aliases. Bear in mind that if you copy these files wholesale, you'll have to edit them for your system because many of the paths will be different. Refer to Chapter 3 for further information on changing these files to suit your needs. The functions directory contains about 50 files with function definitions that you might find useful. Among them are:
Especially helpful, if you come from a Korn shell background, is kshenv . This contains function definitions for some common Korn facilities such as whence , print , and the two-parameter cd builtins.
The
scripts
directory contains over 20 examples of
bash
scripts. The two largest scripts are examples of the complex things you can do with shell scripts. The first is a (rather amusing) adventure game interpreter and the second is a C shell interpreter. The other scripts include examples of precedence rules, a scrolling text display, a "spinning wheel" progress display, and how to prompt the
Not only are the script and function examples useful for including in your environment, they also provide many alternative examples that you can learn from when reading this book. We
|
| < Day Day Up > |