Go to the previous, next section.

Major Differences from the Bourne Shell

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

Bash includes brace expansion (see section Brace Expansion).

Bash includes the Posix and ksh-style pattern removal %% and ## constructs to remove leading or trailing substrings from variables.

The Posix and ksh-style $() form of command substitution is implemented, 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.

The expansion ${#xx}, which returns the length of $xx, is supported.

The IFS variable is used to split only the results of expansion, not all words. 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, and thus useful recursive functions may be written.

The noclobber option is available to avoid overwriting existing files with output redirection.

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.

The command builtin allows selective disabling of functions when command lookup is performed.

Individual builtins may be enabled or disabled using the enable builtin.

Functions may be exported to children via the environment.

The Bash read builtin 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 return builtin may be used to abort execution of scripts executed with the . or source builtins.

The umask builtin allows symbolic mode arguments similar to those accepted by chmod.

The test builtin is slightly different, as it implements the Posix 1003.2 algorithm, which specifies the behavior based on the number of arguments.

Go to the previous, next section.