< Day Day Up > |
13.1. IntroductionWith an interactive shell, the standard input, output, and error are tied to a terminal. When using the Bourne Again shell (Bash) interactively, you type UNIX/Linux commands at the bash prompt and wait for a response. Bash provides you with a large assortment of built-in commands and command-line shortcuts, such as history, aliases, file and command completion, command-line editing, and many more. Some of the features were present in the standard UNIX Bourne shell and Korn shell, but the GNU project has expanded the shell to include a number of new features as well adding POSIX compliancy. With the release of Bash 2.x, so many features of the UNIX Korn shell and C shell have been included that the bash shell is a fully functional shell at both the interactive and programming level, while upwardly compatible with the standard Bourne shell. For UNIX users, bash offers an alternative to the standard shells, sh, csh, and ksh.[1]
This chapter focuses on how you interact with bash at the command line and how to customize your working environment. You will learn how to take advantage of all shortcuts and built-in features in order to create an efficient and fun working environment. Chapter 14 takes you a step further. Then you will be ready to write bash shell scripts to further tailor the working environment for yourself by automating everyday tasks and developing sophisticated scripts, and if you are an administrator, doing the same not only for yourself but also for whole groups of users. 13.1.1 Versions of bashThe Bourne Again shell is a Capricorn, born on January 10, 1988, fathered by Brian Fox and later adopted by Chet Ramey, who now officially maintains bash, enhances it, and fixes bugs. The first version of bash was 0.99. The current version (as of this writing) is version 2.05. Major enhancements were completed in version 2.0, but some operating systems are still using version 1.14.7. All versions are freely available under the GNU public license.[2] There is even bash for Windows! To see what version you are using, use the ––version option to bash or print the value of the BASH_VERSION environment variable.
Example 13.1.(UNIX) $ bash --version GNU bash, version 2.05.0(1)-release (sparc-sun-solaris) Copyright 2000 Free Software Foundation, Inc. $ echo $BASH_VERSION 2.05.0(1)-release Example 13.2.(Linux) $ bash --version GNU bash, version 2.05.0(1)-release (i386-redhat-linux-gnu) Copyright 2000 Free Software Foundation, Inc. 13.1.2 StartupIf the bash shell is your login shell, it follows a chain of processes before you see a shell prompt. See Figure 13.1. Figure 13.1. Starting the bash shell.When the system boots, the first process to run is called init, PID #1. It spawns a getty process. This process opens up the terminal ports, providing a place where standard input comes from and a place where standard output and errors go, and puts a login prompt on your screen. The /bin/login program is then executed. The login program prompts for a password, encrypts and verifies the password, sets up an initial environment, and starts up the login shell, /bin/bash, the last entry in the passwd file. The bash process looks for the system file, /etc/profile, and executes its commands. It then looks in the user's home directory for an initialization file called .bash_profile. After executing commands from .bash_profile,[3] it will execute a command from the user's ENV file, usually called .bashrc, and finally the default dollar sign ($) prompt appears on your screen and the shell waits for commands. (For more on initialization files, see "The Environment" on page 756.)
Changing the Shell at the Command LineIf you want to start another shell from the command line temporarily (without changing the /etc/passwd file), just type the name of the shell. For example, if you are currently using the standard Bourne shell and would rather have bash as your shell, you can change the shell at the command line simply by typing bash. Example 13.3.1 $ ps PID TTY TIME CMD 1574 pts/6 0:00 sh 2 $ bash bash-2.05$ 3 bash-2.05$ ps PID TTY TIME CMD 1574 pts/6 0:00 sh 1576 pts/6 0:00 bash EXPLANATION
|
< Day Day Up > |