Sams Teach Yourself Shell Programming in 24 Hours
(Publisher: Macmillan Computer Publishing)
Author(s): Sriranga Veeraraghavan
ISBN: 0672314819
Publication Date: 01/01/99
The Bourne Again Shell
The Bourne Again shell, bash, was developed as part of the GNU project and has replaced the Bourne shell, sh, for GNU-based systems like Linux. All major Linux distributions, including Red Hat, Slackware, and Caldera, ship with bash as their sh replacement.
Although it includes C shell (csh and tcsh) and Korn shell (ksh) features, bash retains syntax compatibility with the Bourne shell, enabling it to run almost all Bourne shell scripts.
bash was written by Brian Fox (bfox@gnu.ai.mit.edu) of the Free Software Foundation and is currently maintained by Chester Ramey (chet@ins.cwru.edu) of Case Western Reserve University.
bash is available for anonymous FTP from any of the GNU archive sites, including the main GNU archive site:
ftp://prep.ai.mit.edu/pub/gnu/
As of this writing, the most recent release version of bash is 2.02.1.
Because bash is an implementation of the IEEE POSIX 1003.2/ISO 9945.2 Shell and Tools specification, it is extremely portable and can be built on most UNIX systems. It has also been ported to QNX, Minix, OS/2, and Windows 95/NT.
Currently, only Linux ships with the Bourne Again shell. It is installed as /bin/bash. On most Linux systems, it is also installed as /bin/sh.
Some features that bash includes in addition to those of the Korn shell are
- Name completion for variable names, usernames, host names, commands, and filenames
- Spelling correction for pathnames in the cd command
- Arrays of unlimited size
- Integer arithmetic in any base between 2 and 64
Summary
In this chapter, you looked at the shell basics. You saw how to execute simple commands, complex commands, and compound commands. You also covered the concept of a shell along with descriptions of the different shells that you are likely to encounter.
In the next chapter, Script Basics, you explore the function of the shell in greater detail, starting with its use, interactively. I then show you how to use the shell for shell scripts.
One chapter down, only 23 more to go until you are a shell programming expert.
Questions
- 1. Classify each of the following as simple, complex, or compound commands:
$ ls
$ date ; uptime
$ ls l
$ echo "hello world"
If you havent seen some of these commands before, try them out on your system. As you progress through the book, each will be formally introduced.
- 2. What is the effect of putting a semicolon at the end of a single simple command or a complex command?
For example, will the output of the following commands be different?
$ who am i
$ who am i ;
- 3. What are the two major types of shells? Give an example of a shell that falls into each type.
Terms
- Commands
- A command is a program you can run. To run a command, type its name and press Enter.
- Prompts
- When you see a prompt, type the name of a command and press Enter. In this book, the $ character is used to indicate the prompt.
- Simple Commands
- A simple command is a command that you can execute by giving its name at the prompt.
- Default Behavior
- The output that is generated when a command runs as a simple command is called the default behavior of that command.
- Complex Commands
- A complex command is a command that consists of a command name and a list of arguments.
- Arguments
- Arguments are command modifiers that change the behavior of a command.
- Compound Commands
- A compound command consists of a list of simple and complex commands separated by the semicolon character (;).
- Command Separators
- A command separator indicates where one command ends and another begins. The most common command separator is the semicolon character (;).
- Shell
- The shell provides you with an interface to the UNIX system. It gathers input from you and executes programs based on that input. When a program has finished executing, it displays that programs output. The shell is sometimes called a command interpreter.
- Words
- A word is an unbroken set of characters. The shell uses spaces and tabs to separate words.