|< Day Day Up >|
As a prelude to system-wide customization, we want to emphasize that bash can be installed as if it were the standard Bourne shell, /bin/sh. Indeed, some systems, such as Linux, come with bash installed instead of the Bourne shell.
If you want to do this with your system, you can just save the original Bourne shell to another filename (in case someone needs to use it) and either install bash as sh in the /bin directory, or better yet install bash in the /bin directory and create a symbolic link from /bin/sh to /bin/bash using the command ln -s /bin/bash /bin/sh. The reason we think that the second option is better is because bash changes its behavior slightly if started as sh, as we will see shortly.
As detailed in Appendix A, bash is backward-compatible with the Bourne shell, except that it doesn't support ^ as a synonym for the pipe character (|). Unless you have an ancient UNIX system, or you have some very, very old shell scripts, you needn't worry about this.
But if you want to be absolutely sure, simply search through all shell scripts in all directories in your PATH. An easy way to perform the search is to use the file command, which we saw in Chapter 5 and Chapter 9. file prints "executable shell script" when given the name of one. Here is a script that looks for ^ in shell scripts in every directory in your PATH:
IFS=: for d in $PATH; do echo checking $d: cd $d scripts=$(file * | grep 'shell script' | cut -d: -f1) for f in $scripts; do grep '\^' $f /dev/null done done
The first line of this script makes it possible to use $PATH as an item list in the for loop. For each directory, it cds there and finds all shell scripts by piping the file command into grep and then, to extract the filename only, into cut. Then for each shell script, it searches for the ^ character.
If you run this script, you will probably find several occurrences of ^ but these carets should be used within regular expressions in grep, sed, or awk commands, not as pipe characters. As long as carets are never used as pipes, it is safe for you to install bash as /bin/sh.
As we mentioned earlier, if bash is started as sh (because the executable file has been renamed sh or there is a link from sh to bash) its startup behavior will change slightly to mimic the Bourne shell as closely as possible. For login shells it only attempts to read /etc/profile and ~/.profile, ignoring any other startup files like ~/.bash_profile. For interactive shells it won't read the initialization file ~/.bashrc.
10.1.1. POSIX Mode
Besides its native operating mode, bash can also be switched into POSIX mode. The POSIX (Portable Operating System Interface) standard, described in detail in Appendix A, defines guidelines for standardizing UNIX. One part of the POSIX standard covers shells.
bash is nearly 100% POSIX-compliant in its native mode. If you want strict POSIX adherence, you can either start bash with the posix option, or set it from within the shell with set -o posix.
Only in very rare circumstances would you ever have to use POSIX mode. The differences, outlined in Appendix A, are small and are mostly concerned with the command lookup order and how functions are handled. Most bash users should be able to get through life without ever having to use this option.
10.1.2. Command-Line Options
bash has several command-line options that change the behavior of and pass information to the shell. The options fall into two sets: single character options, like we've seen in previous chapters of this book, and multicharacter options, which are a relatively recent improvement to UNIX utilities. Table 10-1 lists all of the options.
The multicharacter options have to appear on the command line before the single-character options. In addition to these, any set option can be used on the command line. Like shell built-ins, using a + instead of - turns an option off.
Of these options, the most useful are -i (interactive), -r (restricted), -s (read from standard input), -p (privileged), and -m (enable job control). Login shells are usually run with the -i, -s, and -m flags. We'll look at restricted and privileged modes later in this chapter.
|< Day Day Up >|