Go to the first, previous, next, last section, table of contents.


Bourne Shell Style Features

This section briefly summarizes things which Bash inherits from the Bourne Shell: builtins, variables, and other features. It also lists the significant differences between Bash and the Bourne Shell.

Bourne Shell Builtins

The following shell builtin commands are inherited from the Bourne Shell. These commands are implemented as specified by the POSIX 1003.2 standard.

:
: [arguments]
Do nothing beyond expanding arguments and performing redirections.
.
. filename
Read and execute commands from the filename argument in the current shell context.
break
break [n]
Exit from a for, while, until, or select loop. If n is supplied, the nth enclosing loop is exited.
cd
cd [-LP] [directory]
Change the current working directory to directory. If directory is not given, the value of the HOME shell variable is used. If the shell variable CDPATH exists, it is used as a search path. If directory begins with a slash, CDPATH is not used. The `-P' option means to not follow symbolic links; symlinks are followed by default or with the `-L' option.
continue
continue [n]
Resume the next iteration of an enclosing for, while, until, or select loop. If n is supplied, the execution of the nth enclosing loop is resumed.
eval
eval [arguments]
The arguments are concatenated together into a single command, which is then read and executed.
exec
exec [-cl] [-a name] [command] [arguments]
If command is supplied, it replaces the shell. If the `-l' option is supplied, the shell places a dash in the zeroth arg passed to command. This is what the login program does. The `-c' option causes command to be executed with an empty environment. If `-a' is supplied, the shell passes name as the zeroth argument to command. If no command is specified, redirections may be used to affect the current shell environment.
exit
exit [n]
Exit the shell, returning a status of n to the shell's parent.
export
export [-fn] [-p] [name[=value]]
Mark each name to be passed to child processes in the environment. If the `-f' option is supplied, the names refer to shell functions. The `-n' option means to no longer mark each name for export. If no names are supplied, or if the `-p' option is given, a list of exported names is displayed.
getopts
getopts optstring name [args]
getopts is used by shell scripts to parse positional parameters. optstring contains the option letters to be recognized; if a letter is followed by a colon, the option is expected to have an argument, which should be separated from it by white space. Each time it is invoked, getopts places the next option in the shell variable name, initializing name if it does not exist, and the index of the next argument to be processed into the variable OPTIND. OPTIND is initialized to 1 each time the shell or a shell script is invoked. When an option requires an argument, getopts places that argument into the variable OPTARG. The shell does not reset OPTIND automatically; it must be manually reset between multiple calls to getopts within the same shell invocation if a new set of parameters is to be used. getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In normal operation diagnostic messages are printed when illegal options or missing option arguments are encountered. If the variable OPTERR is set to 0, no error message will be displayed, even if the first character of optstring is not a colon. If an illegal option is seen, getopts places `?' into name and, if not silent, prints an error message and unsets OPTARG. If getopts is silent, the option character found is placed in OPTARG and no diagnostic message is printed. If a required argument is not found, and getopts is not silent, a question mark (`?') is placed in name, OPTARG is unset, and a diagnostic message is printed. If getopts is silent, then a colon (`:') is placed in name and OPTARG is set to the option character found. getopts normally parses the positional parameters, but if more arguments are given in args, getopts parses those instead.
hash
hash [-r] [-p filename] [name]
Remember the full filenames of commands specified as arguments, so they need not be searched for on subsequent invocations. The commands are found by searching through the directories listed in $PATH. The `-p' option inhibits the path search, and filename is used as the location of name. The `-r' option causes the shell to forget all remembered locations. If no arguments are given, information about remembered commands is printed.
pwd
pwd [-LP]
Print the current working directory. If the `-P' option is supplied, the path printed will not contain symbolic links. If the `-L' option is supplied, the path printed may contain symbolic links.
readonly
readonly [-apf] [name] ...
Mark each name as unchangable. The values of these names may not be changed by subsequent assignment. If the `-f' option is supplied, each name refers to a shell function. The `-a' option means each name refers to an array variable. If no name arguments are given, or if the `-p' option is supplied, a list of all readonly names is printed.
return
return [n]
Cause a shell function to exit with value n. This may also be used to terminate execution of a script being executed with the . builtin.
shift
shift [n]
Shift positional parameters to the left by n. The positional parameters from n+1 ... are renamed to $1 ... . Parameters represented by the numbers $# to n+1 are unset. n must be a non-negative number less than or equal to $#.
test
[
Evaluate a conditional expression (see section Bash Conditional Expressions).
times
times
Print out the user and system times used by the shell and its children.
trap
trap [-lp] [arg] [sigspec ...]
The commands in arg are to be read and executed when the shell receives signal sigspec. If arg is absent or equal to `-', all specified signals are reset to the values they had when the shell was started. If arg is the null string, then the signal specified by each sigspec is ignored by the shell and commands it invokes. If arg is `-p', the shell displays the trap commands associated with each sigspec. If no arguments are supplied, or only `-p' is given, trap prints the list of commands associated with each signal number. Each sigspec is either a signal name such as SIGINT (with or without the SIG prefix) or a signal number. If a sigspec is 0 or EXIT, arg is executed when the shell exits. If a sigspec is DEBUG, the command arg is executed after every simple command. The `-l' option causes the shell to print a list of signal names and their corresponding numbers. Signals ignored upon entry to the shell cannot be trapped or reset. Trapped signals are reset to their original values in a child process when it is created.
umask
umask [-S] [mode]
Set the shell process's file creation mask to mode. If mode begins with a digit, it is interpreted as an octal number; if not, it is interpreted as a symbolic mode mask similar to that accepted by the chmod command. If mode is omitted, the current value of the mask is printed. If the `-S' option is supplied without a mode argument, the mask is printed in a symbolic format.
unset
unset [-fv] [name]
Each variable or function name is removed. If no options are supplied, or the `-v' option is given, each name refers to a shell variable. If the `-f' option is given, the names refer to shell functions, and the function definition is removed. Read-only variables and functions may not be unset.

Bourne Shell Variables

Bash uses certain shell variables in the same way as the Bourne shell. In some cases, Bash assigns a default value to the variable.

IFS
A list of characters that separate fields; used when the shell splits words as part of expansion.
PATH
A colon-separated list of directories in which the shell looks for commands.
HOME
The current user's home directory; the default for the cd builtin command.
CDPATH
A colon-separated list of directories used as a search path for the cd command.
MAILPATH
A colon-separated list of files which the shell periodically checks for new mail. You can also specify what message is printed by separating the file name from the message with a `?'. When used in the text of the message, $_ stands for the name of the current mailfile.
MAIL
If this parameter is set to a filename and the MAILPATH variable is not set, Bash informs the user of the arrival of mail in the specified file.
PS1
The primary prompt string. The default value is `\s-\v\$ '.
PS2
The secondary prompt string. The default value is `> '.
OPTIND
The index of the last option processed by the getopts builtin.
OPTARG
The value of the last option argument processed by the getopts builtin.

Other Bourne Shell Features

Bash implements essentially the same grammar, parameter and variable expansion, redirection, and quoting as the Bourne Shell. Bash uses the POSIX 1003.2 standard as the specification of how these features are to be implemented. There are some differences between the traditional Bourne shell and the POSIX standard; this section quickly details the differences of significance. A number of these differences are explained in greater depth in subsequent sections.

Major Differences From The SVR4.2 Bourne Shell

Bash is POSIX-conformant, even where the POSIX specification differs from traditional sh behavior.

Bash has multi-character invocation options (see section Invoking Bash).

Bash has command-line editing (see section Command Line Editing) and the bind builtin.

Bash has command history (see section Bash History Facilities) and the history and fc builtins to manipulate it.

Bash implements csh-like history expansion (see section Interactive History Expansion).

Bash has one-dimensional array variables (see section Arrays), and the appropriate variable expansions and assignment syntax to use them. Some of the Bash builtins take options to act on arrays. Bash provides some built-in array variables.

Bash implements the ! keyword to negate the return value of a pipeline (see section Pipelines). Very useful when an if statement needs to act only if a test fails.

Bash includes the select compound command, which allows the generation of simple menus (see section Korn Shell Constructs).

Bash includes brace expansion (see section Brace Expansion) and tilde expansion (see section Tilde Expansion).

Bash implements command aliases and the alias and unalias builtins (see section Aliases).

Bash provides shell arithmetic and arithmetic expansion (see section Shell Arithmetic).

The POSIX and ksh-style $() form of command substitution is implemented (see section Command Substitution), and preferred to the Bourne shell's " (which is also implemented for backwards compatibility).

Variables present in the shell's initial environment are automatically exported to child processes. The Bourne shell does not normally do this unless the variables are explicitly marked using the export command.

Bash includes the POSIX and ksh-style pattern removal `%', `#', `%%' and `##' constructs to remove leading or trailing substrings from variable values (see section Shell Parameter Expansion).

The expansion ${#xx}, which returns the length of $xx, is supported (see section Shell Parameter Expansion).

The $'...' quoting syntax, which expands ANSI-C backslash-escaped characters in the text between the single quotes, is supported (see section ANSI-C Quoting).

Bash supports the $"..." quoting syntax to do locale-specific translation of the characters between the double quotes. The `-D' and `--dump-strings' invocation options list the translatable strings found in a script (see section Locale-Specific Translation).

The expansion ${var:offset[:length]}, which expands to the substring of var's value of length length, optionally beginning at offset, is present (see section Shell Parameter Expansion).

The expansion ${var/[/]pattern[/replacement]}, which matches pattern and replaces it with replacement in the value of var, is available (see section Shell Parameter Expansion).

Bash has indirect variable expansion using ${!word} (see section Shell Parameter Expansion).

Bash can expand positional parameters beyond $9 using ${num}.

Bash has process substitution (see section Process Substitution).

Bash automatically assigns variables that provide information about the current user (UID, EUID, and GROUPS), the current host (HOSTTYPE, OSTYPE, MACHTYPE, and HOSTNAME), and the instance of Bash that is running (BASH, BASH_VERSION, and BASH_VERSINFO. See section Bash Variables, for details.

The IFS variable is used to split only the results of expansion, not all words (see section Word Splitting). This closes a longstanding shell security hole.

It is possible to have a variable and a function with the same name; sh does not separate the two name spaces.

Bash functions are permitted to have local variables using the local builtin, and thus useful recursive functions may be written.

Variable assignments preceding commands affect only that command, even builtins and functions (see section Environment). In sh, all variable assignments preceding commands are global unless the command is executed from the file system.

Bash performs filename expansion on filenames specified as operands to output redirection operators.

Bash contains the `<>' redirection operator, allowing a file to be opened for both reading and writing, and the `&>' redirection operator, for directing standard output and standard error to the same file (see section Redirections).

The noclobber option is available to avoid overwriting existing files with output redirection (see section The Set Builtin). The `>|' redirection operator may be used to override noclobber.

Bash interprets special backslash-escaped characters in the prompt strings when interactive (see section Controlling the Prompt).

Bash allows you to write a function to override a builtin, and provides access to that builtin's functionality within the function via the builtin and command builtins (see section Bash Builtin Commands).

The command builtin allows selective disabling of functions when command lookup is performed (see section Bash Builtin Commands).

Individual builtins may be enabled or disabled using the enable builtin (see section Bash Builtin Commands).

The Bash hash builtin allows a name to be associated with an arbitrary filename, even when that filename cannot be found by searching the $PATH, using `hash -p'.

Shell functions may be exported to children via the environment (see section Shell Functions).

Bash includes a help builtin for quick reference to shell facilities (see section Bash Builtin Commands).

The Bash read builtin (see section Bash Builtin Commands) will read a line ending in `\' with the `-r' option, and will use the REPLY variable as a default if no arguments are supplied. The Bash read builtin also accepts a prompt string with the `-p' option and will use Readline to obtain the line when given the `-e' option.

Bash includes the shopt builtin, for finer control of shell optional capabilities (see section Bash Builtin Commands).

Bash has much more optional behavior controllable with the set builtin (see section The Set Builtin).

The disown builtin can remove a job from the internal shell job table (see section Job Control Builtins).

The return builtin may be used to abort execution of scripts executed with the . or source builtins (see section Bourne Shell Builtins).

The test builtin (see section Bourne Shell Builtins) is slightly different, as it implements the POSIX 1003.2 algorithm, which specifies the behavior based on the number of arguments.

The trap builtin (see section Bourne Shell Builtins) allows a DEBUG pseudo-signal specification, similar to EXIT. Commands specified with a DEBUG trap are executed after every simple command. The DEBUG trap is not inherited by shell functions.

The Bash export, readonly, and declare builtins can take a `-f' option to act on shell functions, a `-p' option to display variables with various attributes set in a format that can be used as shell input, a `-n' option to remove various variable attributes, and `name=value' arguments to set variable attributes and values simultaneously.

The Bash cd and pwd builtins (see section Bourne Shell Builtins) each take `-L' and `-P' builtins to switch between logical and physical modes.

The Bash type builtin is more extensive and gives more information about the names it finds (see section Bash Builtin Commands).

Bash implements a csh-like directory stack, and provides the pushd, popd, and dirs builtins to manipulate it (see section C Shell Builtins). Bash also makes the directory stack visible as the value of the DIRSTACK shell variable.

The Bash restricted mode is more useful (see section The Restricted Shell); the SVR4.2 shell restricted mode is too limited.

Bash has the time reserved word and command timing (see section Pipelines). The display of the timing statistics may be controlled with the TIMEFORMAT variable.

The SVR4.2 shell has two privilege-related builtins (mldmode and priv) not present in Bash.

Bash does not have the stop or newgrp builtins.

Bash does not use the SHACCT variable or perform shell accounting.

The SVR4.2 sh uses a TIMEOUT variable like Bash uses TMOUT.

More features unique to Bash may be found in section Bash Features.

Implementation Differences From The SVR4.2 Shell

Since Bash is a completely new implementation, it does not suffer from many of the limitations of the SVR4.2 shell. For instance:


Go to the first, previous, next, last section, table of contents.