[ Team LiB ] Previous Section Next Section

The Bourne-Again Shell

The Bourne-Again shell, bash, is a Bourne-shell-compatible language interpreter that executes commands read from the standard input or from a file. bash incorporates useful features from the Korn and C shells. bash is a conformant implementation of the IEEE POSIX Shell and Tools specification (IEEE Working Group 1003.2).

Reviewing Bourne-Again Shell Initialization Files

bash, when invoked as an interactive login shell or as a non-interactive shell with the --login option, first reads and executes commands from the /etc/profile file if that file exists. After reading /etc/profile, bash looks for ~/.bash_profile, ~/.bash-login, and ~/.profile, in that order. It reads and executes commands from the first file that exists and is readable. To prevent the shell from reading these files, you can invoke bash with the --noprofile option.

When a login shell exits, bash reads and executes commands from the ~/.bash_logout file if it exists.

When you start an interactive shell that is not a login shell, bash reads and executes commands from ~/.bashrc if it exists. You can inhibit this behavior by using the --norc option when you start the interactive shell. Alternatively, you can force bash to read and execute commands from another file by specifying the --rcfile file option.

When you start bash interactively, for example, to run a shell script, bash looks for the BASH_ENV environment variable, expands its value, and uses the expanded value as the name of a file to read and execute. bash behaves as if you executed the following command, but the value of the PATH variable is not used in the search for the file name.


if [ -n "$BASH_ENV" }; then . "$BASH_ENV"; fi

Refer to the bash(1) manual page for complete information.

graphics/new.gif

An excellent bash shell programming reference is Learning the Bash Shell, by Cameron Newham and Bill Rosenblatt, O'Reilly & Associates, 1998.

    [ Team LiB ] Previous Section Next Section