home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Learning the Korn Shell

Learning the Korn ShellSearch this book
Previous: A.4 pdksh Appendix A
Related Shells
Next: A.6 Workalikes on PC Platforms
 

A.5 bash

bash is another popular "third-party" shell that is available on the Internet, via anonymous FTP on prep.ai.mit.edu in the directory /pub/gnu . You can also order it from its maker: The Free Software Foundation (FSF) 675 Massachusetts Avenue Cambridge MA 02139, phone (617) 876-3296.

Bash was written by Brian Fox and Chet Ramey. Its name is in line with the FSF's penchant for bad puns: it stands for Bourne-Again Shell. Although bash is easily available and you don't have to pay for it (other than the cost of media, phone calls, etc.), it's not really public domain software. While public domain software doesn't have licensing restrictions, the FSF's software does. But those restrictions are diametrically opposed to those in a commercial license: [3] instead of agreeing not to distribute the software further, you agree not to prevent it from being distributed further! In other words, you enjoy unrestricted use of the software as long as you agree not to inhibit others from doing the same. Richard Stallman, the founder of the FSF, invented this intriguing and admirable concept.

[3] Accordingly, the document that spells out these restrictions is called a copyleft .

You may have heard that public domain software tends to be buggy, poorly maintained and documented, etc. Let us emphasize that this is absolutely not the case with software from the FSF. It is among the finest, most full-featured, best-maintained, and most technically advanced software in existence.

The FSF has been developing a complete, UNIX-compatible operating system called GNU, which stands for GNU's Not UNIX. [4] They have already written lots of utilities and software tools for GNU that also run on most varieties of UNIX, the most famous of which is the GNU Emacs editor. The shell for GNU is bash .

[4] This is an example of a recursive acronym , in which the first letter stands for the acronym itself. It is the result of a mental disorder caused by a rare brain parasite endemic to the southern part of Cambridge, MA.

bash is fully compatible with the Bourne shell. It has several of the most important Korn shell features and the C shell features that the Korn shell has appropriated, including aliases, functions, tilde notation, emacs and vi editing modes, arithmetic expressions, job control, etc.

Yet bash is not really a Korn shell workalike. Various aspects of its syntax are different, e.g.:

  • Arithmetic expressions have the form $[ ...] .

  • Functions conform to the alternate syntax we didn't use in this book (see Chapter 4 ), although you may use the function keyword in addition to the parentheses.

  • Condition tests are in the old, Bourne shell style.

  • The command type does what whence does, only better.

  • print is not supported; you must use echo .

Some of these will change as the POSIX 1003.2 standard evolves. Bash also doesn't implement various small Korn shell features, including most of those listed above for pdksh , and it doesn't support the DEBUG fake signal.

However, bash has many features of its own that make it a very powerful and flexible environment. Here are some of the highlights:

  • You can put backslash-escapes in the primary prompt string (PS1 ) for which bash substitutes things like the date, time, current working directory, machine name, user name, shell, etc.

  • The commands builtin , command , and enable give you more control over the steps bash goes through to look for commands-i.e., bash 's analog to the list of command search steps in Chapter 7 .

  • The emacs editing mode is customizable, even more so than its equivalent in pdksh . You can use the bind command to set up your own keystroke preferences, and there are several more commands available-including the ability to undo your last command.

  • You can also rebind keystrokes in vi editing mode.

  • bash supports ! as a keyword, a la POSIX 1003.2 (see page 297).

  • bash has online help for built-in commands.

  • pushd and popd are built-in, as they are in the C shell.

  • Many new options and variables let you customize your environment with unprecedented flexibility.

We're compelled to say that many users prefer bash to the Korn shell. Although the latter is probably used by more people, because of the commercial channels through which it's distributed, bash is clearly an excellent choice.


Previous: A.4 pdksh Learning the Korn Shell Next: A.6 Workalikes on PC Platforms
A.4 pdksh Book Index A.6 Workalikes on PC Platforms

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System