This is bashref.info, produced by makeinfo version 4.0f from
bashref.texi.

INFO-DIR-SECTION Utilities
START-INFO-DIR-ENTRY
* Bash: (bash).                     The GNU Bourne-Again SHell.
END-INFO-DIR-ENTRY

This text is a brief description of the features that are present in
the Bash shell.

This is Edition 2.5a, last updated 13 November 2001,
of `The GNU Bash Reference Manual',
for `Bash', Version 2.05a.

Copyright (C) 1991-2001 Free Software Foundation, Inc.

Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.

Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.

Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.


File: bashref.info,  Node: Shell Parameter Expansion,  Next: Command Substitution,  Prev: Tilde Expansion,  Up: Shell Expansions

Shell Parameter Expansion
-------------------------

   The `$' character introduces parameter expansion, command
substitution, or arithmetic expansion.  The parameter name or symbol to
be expanded may be enclosed in braces, which are optional but serve to
protect the variable to be expanded from characters immediately
following it which could be interpreted as part of the name.

   When braces are used, the matching ending brace is the first `}' not
escaped by a backslash or within a quoted string, and not within an
embedded arithmetic expansion, command substitution, or parameter
expansion.

   The basic form of parameter expansion is ${PARAMETER}.  The value of
PARAMETER is substituted.  The braces are required when PARAMETER is a
positional parameter with more than one digit, or when PARAMETER is
followed by a character that is not to be interpreted as part of its
name.

   If the first character of PARAMETER is an exclamation point, a level
of variable indirection is introduced.  Bash uses the value of the
variable formed from the rest of PARAMETER as the name of the variable;
this variable is then expanded and that value is used in the rest of
the substitution, rather than the value of PARAMETER itself.  This is
known as `indirect expansion'.  The exception to this is the expansion
of ${!PREFIX*} described below.

   In each of the cases below, WORD is subject to tilde expansion,
parameter expansion, command substitution, and arithmetic expansion.

   When not performing substring expansion, Bash tests for a parameter
that is unset or null; omitting the colon results in a test only for a
parameter that is unset.  Put another way, if the colon is included,
the operator tests for both existence and that the value is not null;
if the colon is omitted, the operator tests only for existence.

`${PARAMETER:-WORD}'
     If PARAMETER is unset or null, the expansion of WORD is
     substituted.  Otherwise, the value of PARAMETER is substituted.

`${PARAMETER:=WORD}'
     If PARAMETER is unset or null, the expansion of WORD is assigned
     to PARAMETER.  The value of PARAMETER is then substituted.
     Positional parameters and special parameters may not be assigned
     to in this way.

`${PARAMETER:?WORD}'
     If PARAMETER is null or unset, the expansion of WORD (or a message
     to that effect if WORD is not present) is written to the standard
     error and the shell, if it is not interactive, exits.  Otherwise,
     the value of PARAMETER is substituted.

`${PARAMETER:+WORD}'
     If PARAMETER is null or unset, nothing is substituted, otherwise
     the expansion of WORD is substituted.

`${PARAMETER:OFFSET}'
`${PARAMETER:OFFSET:LENGTH}'
     Expands to up to LENGTH characters of PARAMETER starting at the
     character specified by OFFSET.  If LENGTH is omitted, expands to
     the substring of PARAMETER starting at the character specified by
     OFFSET.  LENGTH and OFFSET are arithmetic expressions (*note Shell
     Arithmetic::).  This is referred to as Substring Expansion.

     LENGTH must evaluate to a number greater than or equal to zero.
     If OFFSET evaluates to a number less than zero, the value is used
     as an offset from the end of the value of PARAMETER.  If PARAMETER
     is `@', the result is LENGTH positional parameters beginning at
     OFFSET.  If PARAMETER is an array name indexed by `@' or `*', the
     result is the LENGTH members of the array beginning with
     `${PARAMETER[OFFSET]}'.  Substring indexing is zero-based unless
     the positional parameters are used, in which case the indexing
     starts at 1.

`${!PREFIX*}'
     Expands to the names of variables whose names begin with PREFIX,
     separated by the first character of the `IFS' special variable.

`${#PARAMETER}'
     The length in characters of the expanded value of PARAMETER is
     substituted.  If PARAMETER is `*' or `@', the value substituted is
     the number of positional parameters.  If PARAMETER is an array
     name subscripted by `*' or `@', the value substituted is the
     number of elements in the array.

`${PARAMETER#WORD}'
`${PARAMETER##WORD}'
     The WORD is expanded to produce a pattern just as in filename
     expansion (*note Filename Expansion::).  If the pattern matches
     the beginning of the expanded value of PARAMETER, then the result
     of the expansion is the expanded value of PARAMETER with the
     shortest matching pattern (the `#' case) or the longest matching
     pattern (the `##' case) deleted.  If PARAMETER is `@' or `*', the
     pattern removal operation is applied to each positional parameter
     in turn, and the expansion is the resultant list.  If PARAMETER is
     an array variable subscripted with `@' or `*', the pattern removal
     operation is applied to each member of the array in turn, and the
     expansion is the resultant list.

`${PARAMETER%WORD}'
`${PARAMETER%%WORD}'
     The WORD is expanded to produce a pattern just as in filename
     expansion.  If the pattern matches a trailing portion of the
     expanded value of PARAMETER, then the result of the expansion is
     the value of PARAMETER with the shortest matching pattern (the `%'
     case) or the longest matching pattern (the `%%' case) deleted.  If
     PARAMETER is `@' or `*', the pattern removal operation is applied
     to each positional parameter in turn, and the expansion is the
     resultant list.  If PARAMETER is an array variable subscripted
     with `@' or `*', the pattern removal operation is applied to each
     member of the array in turn, and the expansion is the resultant
     list.

`${PARAMETER/PATTERN/STRING}'
`${PARAMETER//PATTERN/STRING}'
     The PATTERN is expanded to produce a pattern just as in filename
     expansion.  PARAMETER is expanded and the longest match of PATTERN
     against its value is replaced with STRING.  In the first form,
     only the first match is replaced.  The second form causes all
     matches of PATTERN to be replaced with STRING.  If PATTERN begins
     with `#', it must match at the beginning of the expanded value of
     PARAMETER.  If PATTERN begins with `%', it must match at the end
     of the expanded value of PARAMETER.  If STRING is null, matches of
     PATTERN are deleted and the `/' following PATTERN may be omitted.
     If PARAMETER is `@' or `*', the substitution operation is applied
     to each positional parameter in turn, and the expansion is the
     resultant list.  If PARAMETER is an array variable subscripted
     with `@' or `*', the substitution operation is applied to each
     member of the array in turn, and the expansion is the resultant
     list.


File: bashref.info,  Node: Command Substitution,  Next: Arithmetic Expansion,  Prev: Shell Parameter Expansion,  Up: Shell Expansions

Command Substitution
--------------------

   Command substitution allows the output of a command to replace the
command itself.  Command substitution occurs when a command is enclosed
as follows:
     $(COMMAND)

or
     `COMMAND`

Bash performs the expansion by executing COMMAND and replacing the
command substitution with the standard output of the command, with any
trailing newlines deleted.  Embedded newlines are not deleted, but they
may be removed during word splitting.  The command substitution `$(cat
FILE)' can be replaced by the equivalent but faster `$(< FILE)'.

   When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by `$', ``', or `\'.
The first backquote not preceded by a backslash terminates the command
substitution.  When using the `$(COMMAND)' form, all characters between
the parentheses make up the command; none are treated specially.

   Command substitutions may be nested.  To nest when using the
backquoted form, escape the inner backquotes with backslashes.

   If the substitution appears within double quotes, word splitting and
filename expansion are not performed on the results.


File: bashref.info,  Node: Arithmetic Expansion,  Next: Process Substitution,  Prev: Command Substitution,  Up: Shell Expansions

Arithmetic Expansion
--------------------

   Arithmetic expansion allows the evaluation of an arithmetic
expression and the substitution of the result.  The format for
arithmetic expansion is:

     $(( EXPRESSION ))

   The expression is treated as if it were within double quotes, but a
double quote inside the parentheses is not treated specially.  All
tokens in the expression undergo parameter expansion, command
substitution, and quote removal.  Arithmetic substitutions may be
nested.

   The evaluation is performed according to the rules listed below
(*note Shell Arithmetic::).  If the expression is invalid, Bash prints
a message indicating failure to the standard error and no substitution
occurs.


File: bashref.info,  Node: Process Substitution,  Next: Word Splitting,  Prev: Arithmetic Expansion,  Up: Shell Expansions

Process Substitution
--------------------

   Process substitution is supported on systems that support named
pipes (FIFOs) or the `/dev/fd' method of naming open files.  It takes
the form of
     <(LIST)

or
     >(LIST)

The process LIST is run with its input or output connected to a FIFO or
some file in `/dev/fd'.  The name of this file is passed as an argument
to the current command as the result of the expansion.  If the
`>(LIST)' form is used, writing to the file will provide input for
LIST.  If the `<(LIST)' form is used, the file passed as an argument
should be read to obtain the output of LIST.  Note that no space may
appear between the `<' or `>' and the left parenthesis, otherwise the
construct would be interpreted as a redirection.

   When available, process substitution is performed simultaneously with
parameter and variable expansion, command substitution, and arithmetic
expansion.


File: bashref.info,  Node: Word Splitting,  Next: Filename Expansion,  Prev: Process Substitution,  Up: Shell Expansions

Word Splitting
--------------

   The shell scans the results of parameter expansion, command
substitution, and arithmetic expansion that did not occur within double
quotes for word splitting.

   The shell treats each character of `$IFS' as a delimiter, and splits
the results of the other expansions into words on these characters.  If
`IFS' is unset, or its value is exactly `<space><tab><newline>', the
default, then any sequence of `IFS' characters serves to delimit words.
If `IFS' has a value other than the default, then sequences of the
whitespace characters `space' and `tab' are ignored at the beginning
and end of the word, as long as the whitespace character is in the
value of `IFS' (an `IFS' whitespace character).  Any character in `IFS'
that is not `IFS' whitespace, along with any adjacent `IFS' whitespace
characters, delimits a field.  A sequence of `IFS' whitespace
characters is also treated as a delimiter.  If the value of `IFS' is
null, no word splitting occurs.

   Explicit null arguments (`""' or `''') are retained.  Unquoted
implicit null arguments, resulting from the expansion of parameters
that have no values, are removed.  If a parameter with no value is
expanded within double quotes, a null argument results and is retained.

   Note that if no expansion occurs, no splitting is performed.


File: bashref.info,  Node: Filename Expansion,  Next: Quote Removal,  Prev: Word Splitting,  Up: Shell Expansions

Filename Expansion
------------------

* Menu:

* Pattern Matching::	How the shell matches patterns.

   After word splitting, unless the `-f' option has been set (*note The
Set Builtin::), Bash scans each word for the characters `*', `?', and
`['.  If one of these characters appears, then the word is regarded as
a PATTERN, and replaced with an alphabetically sorted list of file
names matching the pattern. If no matching file names are found, and
the shell option `nullglob' is disabled, the word is left unchanged.
If the `nullglob' option is set, and no matches are found, the word is
removed.  If the shell option `nocaseglob' is enabled, the match is
performed without regard to the case of alphabetic characters.

   When a pattern is used for filename generation, the character `.' at
the start of a filename or immediately following a slash must be
matched explicitly, unless the shell option `dotglob' is set.  When
matching a file name, the slash character must always be matched
explicitly.  In other cases, the `.' character is not treated specially.

   See the description of `shopt' in *Note Bash Builtins::, for a
description of the `nocaseglob', `nullglob', and `dotglob' options.

   The `GLOBIGNORE' shell variable may be used to restrict the set of
filenames matching a pattern.  If `GLOBIGNORE' is set, each matching
filename that also matches one of the patterns in `GLOBIGNORE' is
removed from the list of matches.  The filenames `.' and `..' are
always ignored, even when `GLOBIGNORE' is set.  However, setting
`GLOBIGNORE' has the effect of enabling the `dotglob' shell option, so
all other filenames beginning with a `.' will match.  To get the old
behavior of ignoring filenames beginning with a `.', make `.*' one of
the patterns in `GLOBIGNORE'.  The `dotglob' option is disabled when
`GLOBIGNORE' is unset.


File: bashref.info,  Node: Pattern Matching,  Up: Filename Expansion

Pattern Matching
................

   Any character that appears in a pattern, other than the special
pattern characters described below, matches itself.  The NUL character
may not occur in a pattern.  The special pattern characters must be
quoted if they are to be matched literally.

   The special pattern characters have the following meanings:
`*'
     Matches any string, including the null string.

`?'
     Matches any single character.

`[...]'
     Matches any one of the enclosed characters.  A pair of characters
     separated by a hyphen denotes a RANGE EXPRESSION; any character
     that sorts between those two characters, inclusive, using the
     current locale's collating sequence and character set, is matched.
     If the first character following the `[' is a `!'  or a `^' then
     any character not enclosed is matched.  A `-' may be matched by
     including it as the first or last character in the set.  A `]' may
     be matched by including it as the first character in the set.  The
     sorting order of characters in range expressions is determined by
     the current locale and the value of the `LC_COLLATE' shell
     variable, if set.

     For example, in the default C locale, `[a-dx-z]' is equivalent to
     `[abcdxyz]'.  Many locales sort characters in dictionary order,
     and in these locales `[a-dx-z]' is typically not equivalent to
     `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
     example.  To obtain the traditional interpretation of ranges in
     bracket expressions, you can force the use of the C locale by
     setting the `LC_COLLATE' or `LC_ALL' environment variable to the
     value `C'.

     Within `[' and `]', CHARACTER CLASSES can be specified using the
     syntax `[:'CLASS`:]', where CLASS is one of the following classes
     defined in the POSIX 1003.2 standard:
          alnum   alpha   ascii   blank   cntrl   digit   graph   lower
          print   punct   space   upper   xdigit

     A character class matches any character belonging to that class.

     Within `[' and `]', an EQUIVALENCE CLASS can be specified using
     the syntax `[='C`=]', which matches all characters with the same
     collation weight (as defined by the current locale) as the
     character C.

     Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
     collating symbol SYMBOL.

   If the `extglob' shell option is enabled using the `shopt' builtin,
several extended pattern matching operators are recognized.  In the
following description, a PATTERN-LIST is a list of one or more patterns
separated by a `|'.  Composite patterns may be formed using one or more
of the following sub-patterns:

`?(PATTERN-LIST)'
     Matches zero or one occurrence of the given patterns.

`*(PATTERN-LIST)'
     Matches zero or more occurrences of the given patterns.

`+(PATTERN-LIST)'
     Matches one or more occurrences of the given patterns.

`@(PATTERN-LIST)'
     Matches exactly one of the given patterns.

`!(PATTERN-LIST)'
     Matches anything except one of the given patterns.


File: bashref.info,  Node: Quote Removal,  Prev: Filename Expansion,  Up: Shell Expansions

Quote Removal
-------------

   After the preceding expansions, all unquoted occurrences of the
characters `\', `'', and `"' that did not result from one of the above
expansions are removed.


File: bashref.info,  Node: Redirections,  Next: Executing Commands,  Prev: Shell Expansions,  Up: Basic Shell Features

Redirections
============

   Before a command is executed, its input and output may be REDIRECTED
using a special notation interpreted by the shell.  Redirection may
also be used to open and close files for the current shell execution
environment.  The following redirection operators may precede or appear
anywhere within a simple command or may follow a command.  Redirections
are processed in the order they appear, from left to right.

   In the following descriptions, if the file descriptor number is
omitted, and the first character of the redirection operator is `<',
the redirection refers to the standard input (file descriptor 0).  If
the first character of the redirection operator is `>', the redirection
refers to the standard output (file descriptor 1).

   The word following the redirection operator in the following
descriptions, unless otherwise noted, is subjected to brace expansion,
tilde expansion, parameter expansion, command substitution, arithmetic
expansion, quote removal, filename expansion, and word splitting.  If
it expands to more than one word, Bash reports an error.

   Note that the order of redirections is significant.  For example,
the command
     ls > DIRLIST 2>&1

directs both standard output (file descriptor 1) and standard error
(file descriptor 2) to the file DIRLIST, while the command
     ls 2>&1 > DIRLIST

directs only the standard output to file DIRLIST, because the standard
error was duplicated as standard output before the standard output was
redirected to DIRLIST.

   Bash handles several filenames specially when they are used in
redirections, as described in the following table:

`/dev/fd/FD'
     If FD is a valid integer, file descriptor FD is duplicated.

`/dev/stdin'
     File descriptor 0 is duplicated.

`/dev/stdout'
     File descriptor 1 is duplicated.

`/dev/stderr'
     File descriptor 2 is duplicated.

`/dev/tcp/HOST/PORT'
     If HOST is a valid hostname or Internet address, and PORT is an
     integer port number or service name, Bash attempts to open a TCP
     connection to the corresponding socket.

`/dev/udp/HOST/PORT'
     If HOST is a valid hostname or Internet address, and PORT is an
     integer port number or service name, Bash attempts to open a UDP
     connection to the corresponding socket.

   A failure to open or create a file causes the redirection to fail.

Redirecting Input
-----------------

   Redirection of input causes the file whose name results from the
expansion of WORD to be opened for reading on file descriptor `n', or
the standard input (file descriptor 0) if `n' is not specified.

   The general format for redirecting input is:
     [n]<WORD

Redirecting Output
------------------

   Redirection of output causes the file whose name results from the
expansion of WORD to be opened for writing on file descriptor `n', or
the standard output (file descriptor 1) if `n' is not specified.  If
the file does not exist it is created; if it does exist it is truncated
to zero size.

   The general format for redirecting output is:
     [n]>[|]WORD

   If the redirection operator is `>', and the `noclobber' option to
the `set' builtin has been enabled, the redirection will fail if the
file whose name results from the expansion of WORD exists and is a
regular file.  If the redirection operator is `>|', or the redirection
operator is `>' and the `noclobber' option is not enabled, the
redirection is attempted even if the file named by WORD exists.

Appending Redirected Output
---------------------------

   Redirection of output in this fashion causes the file whose name
results from the expansion of WORD to be opened for appending on file
descriptor `n', or the standard output (file descriptor 1) if `n' is
not specified.  If the file does not exist it is created.

   The general format for appending output is:
     [n]>>WORD

Redirecting Standard Output and Standard Error
----------------------------------------------

   Bash allows both the standard output (file descriptor 1) and the
standard error output (file descriptor 2) to be redirected to the file
whose name is the expansion of WORD with this construct.

   There are two formats for redirecting standard output and standard
error:
     &>WORD

and
     >&WORD

Of the two forms, the first is preferred.  This is semantically
equivalent to
     >WORD 2>&1

Here Documents
--------------

   This type of redirection instructs the shell to read input from the
current source until a line containing only WORD (with no trailing
blanks) is seen.  All of the lines read up to that point are then used
as the standard input for a command.

   The format of here-documents is as follows:
     <<[-]WORD
             HERE-DOCUMENT
     DELIMITER

   No parameter expansion, command substitution, arithmetic expansion,
or filename expansion is performed on WORD.  If any characters in WORD
are quoted, the DELIMITER is the result of quote removal on WORD, and
the lines in the here-document are not expanded.  If WORD is unquoted,
all lines of the here-document are subjected to parameter expansion,
command substitution, and arithmetic expansion.  In the latter case,
the character sequence `\newline' is ignored, and `\' must be used to
quote the characters `\', `$', and ``'.

   If the redirection operator is `<<-', then all leading tab
characters are stripped from input lines and the line containing
DELIMITER.  This allows here-documents within shell scripts to be
indented in a natural fashion.

Duplicating File Descriptors
----------------------------

   The redirection operator
     [n]<&WORD

is used to duplicate input file descriptors.  If WORD expands to one or
more digits, the file descriptor denoted by `n' is made to be a copy of
that file descriptor.  If the digits in WORD do not specify a file
descriptor open for input, a redirection error occurs.  If WORD
evaluates to `-', file descriptor `n' is closed.  If `n' is not
specified, the standard input (file descriptor 0) is used.

   The operator
     [n]>&WORD

is used similarly to duplicate output file descriptors.  If `n' is not
specified, the standard output (file descriptor 1) is used.  If the
digits in WORD do not specify a file descriptor open for output, a
redirection error occurs.  As a special case, if `n' is omitted, and
WORD does not expand to one or more digits, the standard output and
standard error are redirected as described previously.

Opening File Descriptors for Reading and Writing
------------------------------------------------

   The redirection operator
     [n]<>WORD

causes the file whose name is the expansion of WORD to be opened for
both reading and writing on file descriptor `n', or on file descriptor
0 if `n' is not specified.  If the file does not exist, it is created.


File: bashref.info,  Node: Executing Commands,  Next: Shell Scripts,  Prev: Redirections,  Up: Basic Shell Features

Executing Commands
==================

* Menu:

* Simple Command Expansion::	How Bash expands simple commands before
				executing them.

* Command Search and Execution::	How Bash finds commands and runs them.

* Command Execution Environment::	The environment in which Bash
					executes commands that are not
					shell builtins.

* Environment::		The environment given to a command.

* Exit Status::		The status returned by commands and how Bash
			interprets it.

* Signals::		What happens when Bash or a command it runs
			receives a signal.


File: bashref.info,  Node: Simple Command Expansion,  Next: Command Search and Execution,  Up: Executing Commands

Simple Command Expansion
------------------------

   When a simple command is executed, the shell performs the following
expansions, assignments, and redirections, from left to right.

  1. The words that the parser has marked as variable assignments (those
     preceding the command name) and redirections are saved for later
     processing.

  2. The words that are not variable assignments or redirections are
     expanded (*note Shell Expansions::).  If any words remain after
     expansion, the first word is taken to be the name of the command
     and the remaining words are the arguments.

  3. Redirections are performed as described above (*note
     Redirections::).

  4. The text after the `=' in each variable assignment undergoes tilde
     expansion, parameter expansion, command substitution, arithmetic
     expansion, and quote removal before being assigned to the variable.

   If no command name results, the variable assignments affect the
current shell environment.  Otherwise, the variables are added to the
environment of the executed command and do not affect the current shell
environment.  If any of the assignments attempts to assign a value to a
readonly variable, an error occurs, and the command exits with a
non-zero status.

   If no command name results, redirections are performed, but do not
affect the current shell environment.  A redirection error causes the
command to exit with a non-zero status.

   If there is a command name left after expansion, execution proceeds
as described below.  Otherwise, the command exits.  If one of the
expansions contained a command substitution, the exit status of the
command is the exit status of the last command substitution performed.
If there were no command substitutions, the command exits with a status
of zero.


File: bashref.info,  Node: Command Search and Execution,  Next: Command Execution Environment,  Prev: Simple Command Expansion,  Up: Executing Commands

Command Search and Execution
----------------------------

   After a command has been split into words, if it results in a simple
command and an optional list of arguments, the following actions are
taken.

  1. If the command name contains no slashes, the shell attempts to
     locate it.  If there exists a shell function by that name, that
     function is invoked as described in *Note Shell Functions::.

  2. If the name does not match a function, the shell searches for it
     in the list of shell builtins.  If a match is found, that builtin
     is invoked.

  3. If the name is neither a shell function nor a builtin, and
     contains no slashes, Bash searches each element of `$PATH' for a
     directory containing an executable file by that name.  Bash uses a
     hash table to remember the full pathnames of executable files to
     avoid multiple `PATH' searches (see the description of `hash' in
     *Note Bourne Shell Builtins::).  A full search of the directories
     in `$PATH' is performed only if the command is not found in the
     hash table.  If the search is unsuccessful, the shell prints an
     error message and returns an exit status of 127.

  4. If the search is successful, or if the command name contains one
     or more slashes, the shell executes the named program in a
     separate execution environment.  Argument 0 is set to the name
     given, and the remaining arguments to the command are set to the
     arguments supplied, if any.

  5. If this execution fails because the file is not in executable
     format, and the file is not a directory, it is assumed to be a
     SHELL SCRIPT and the shell executes it as described in *Note Shell
     Scripts::.

  6. If the command was not begun asynchronously, the shell waits for
     the command to complete and collects its exit status.



File: bashref.info,  Node: Command Execution Environment,  Next: Environment,  Prev: Command Search and Execution,  Up: Executing Commands

Command Execution Environment
-----------------------------

   The shell has an EXECUTION ENVIRONMENT, which consists of the
following:

   * open files inherited by the shell at invocation, as modified by
     redirections supplied to the `exec' builtin

   * the current working directory as set by `cd', `pushd', or `popd',
     or inherited by the shell at invocation

   * the file creation mode mask as set by `umask' or inherited from
     the shell's parent

   * current traps set by `trap'

   * shell parameters that are set by variable assignment or with `set'
     or inherited from the shell's parent in the environment

   * shell functions defined during execution or inherited from the
     shell's parent in the environment

   * options enabled at invocation (either by default or with
     command-line arguments) or by `set'

   * options enabled by `shopt'

   * shell aliases defined with `alias' (*note Aliases::)

   * various process IDs, including those of background jobs (*note
     Lists::), the value of `$$', and the value of `$PPID'


   When a simple command other than a builtin or shell function is to
be executed, it is invoked in a separate execution environment that
consists of the following.  Unless otherwise noted, the values are
inherited from the shell.

   * the shell's open files, plus any modifications and additions
     specified by redirections to the command

   * the current working directory

   * the file creation mode mask

   * shell variables marked for export, along with variables exported
     for the command, passed in the environment (*note Environment::)

   * traps caught by the shell are reset to the values inherited from
     the shell's parent, and traps ignored by the shell are ignored


   A command invoked in this separate environment cannot affect the
shell's execution environment.

   Command substitution and asynchronous commands are invoked in a
subshell environment that is a duplicate of the shell environment,
except that traps caught by the shell are reset to the values that the
shell inherited from its parent at invocation.  Builtin commands that
are invoked as part of a pipeline are also executed in a subshell
environment.  Changes made to the subshell environment cannot affect
the shell's execution environment.

   If a command is followed by a `&' and job control is not active, the
default standard input for the command is the empty file `/dev/null'.
Otherwise, the invoked command inherits the file descriptors of the
calling shell as modified by redirections.


File: bashref.info,  Node: Environment,  Next: Exit Status,  Prev: Command Execution Environment,  Up: Executing Commands

Environment
-----------

   When a program is invoked it is given an array of strings called the
ENVIRONMENT.  This is a list of name-value pairs, of the form
`name=value'.

   Bash provides several ways to manipulate the environment.  On
invocation, the shell scans its own environment and creates a parameter
for each name found, automatically marking it for EXPORT to child
processes.  Executed commands inherit the environment.  The `export'
and `declare -x' commands allow parameters and functions to be added to
and deleted from the environment.  If the value of a parameter in the
environment is modified, the new value becomes part of the environment,
replacing the old.  The environment inherited by any executed command
consists of the shell's initial environment, whose values may be
modified in the shell, less any pairs removed by the `unset' and
`export -n' commands, plus any additions via the `export' and `declare
-x' commands.

   The environment for any simple command or function may be augmented
temporarily by prefixing it with parameter assignments, as described in
*Note Shell Parameters::.  These assignment statements affect only the
environment seen by that command.

   If the `-k' option is set (*note The Set Builtin::), then all
parameter assignments are placed in the environment for a command, not
just those that precede the command name.

   When Bash invokes an external command, the variable `$_' is set to
the full path name of the command and passed to that command in its
environment.


File: bashref.info,  Node: Exit Status,  Next: Signals,  Prev: Environment,  Up: Executing Commands

Exit Status
-----------

   For the shell's purposes, a command which exits with a zero exit
status has succeeded.  A non-zero exit status indicates failure.  This
seemingly counter-intuitive scheme is used so there is one well-defined
way to indicate success and a variety of ways to indicate various
failure modes.  When a command terminates on a fatal signal whose
number is N, Bash uses the value 128+N as the exit status.

   If a command is not found, the child process created to execute it
returns a status of 127.  If a command is found but is not executable,
the return status is 126.

   If a command fails because of an error during expansion or
redirection, the exit status is greater than zero.

   The exit status is used by the Bash conditional commands (*note
Conditional Constructs::) and some of the list constructs (*note
Lists::).

   All of the Bash builtins return an exit status of zero if they
succeed and a non-zero status on failure, so they may be used by the
conditional and list constructs.  All builtins return an exit status of
2 to indicate incorrect usage.


File: bashref.info,  Node: Signals,  Prev: Exit Status,  Up: Executing Commands

Signals
-------

   When Bash is interactive, in the absence of any traps, it ignores
`SIGTERM' (so that `kill 0' does not kill an interactive shell), and
`SIGINT' is caught and handled (so that the `wait' builtin is
interruptible).  When Bash receives a `SIGINT', it breaks out of any
executing loops.  In all cases, Bash ignores `SIGQUIT'.  If job control
is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
and `SIGTSTP'.

   Commands started by Bash have signal handlers set to the values
inherited by the shell from its parent.  When job control is not in
effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' as well.
Commands run as a result of command substitution ignore the
keyboard-generated job control signals `SIGTTIN', `SIGTTOU', and
`SIGTSTP'.

   The shell exits by default upon receipt of a `SIGHUP'.  Before
exiting, an interactive shell resends the `SIGHUP' to all jobs, running
or stopped.  Stopped jobs are sent `SIGCONT' to ensure that they receive
the `SIGHUP'.  To prevent the shell from sending the `SIGHUP' signal to
a particular job, it should be removed from the jobs table with the
`disown' builtin (*note Job Control Builtins::) or marked to not
receive `SIGHUP' using `disown -h'.

   If the  `huponexit' shell option has been set with `shopt' (*note
Bash Builtins::), Bash sends a `SIGHUP' to all jobs when an interactive
login shell exits.

   When Bash receives a signal for which a trap has been set while
waiting for a command to complete, the trap will not be executed until
the command completes.  When Bash is waiting for an asynchronous
command via the `wait' builtin, the reception of a signal for which a
trap has been set will cause the `wait' builtin to return immediately
with an exit status greater than 128, immediately after which the trap
is executed.


File: bashref.info,  Node: Shell Scripts,  Prev: Executing Commands,  Up: Basic Shell Features

Shell Scripts
=============

   A shell script is a text file containing shell commands.  When such
a file is used as the first non-option argument when invoking Bash, and
neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
Bash reads and executes commands from the file, then exits.  This mode
of operation creates a non-interactive shell.  The shell first searches
for the file in the current directory, and looks in the directories in
`$PATH' if not found there.

   When Bash runs a shell script, it sets the special parameter `0' to
the name of the file, rather than the name of the shell, and the
positional parameters are set to the remaining arguments, if any are
given.  If no additional arguments are supplied, the positional
parameters are unset.

   A shell script may be made executable by using the `chmod' command
to turn on the execute bit.  When Bash finds such a file while
searching the `$PATH' for a command, it spawns a subshell to execute
it.  In other words, executing
     filename ARGUMENTS

is equivalent to executing
     bash filename ARGUMENTS

if `filename' is an executable shell script.  This subshell
reinitializes itself, so that the effect is as if a new shell had been
invoked to interpret the script, with the exception that the locations
of commands remembered by the parent (see the description of `hash' in
*Note Bourne Shell Builtins::) are retained by the child.

   Most versions of Unix make this a part of the operating system's
command execution mechanism.  If the first line of a script begins with
the two characters `#!', the remainder of the line specifies an
interpreter for the program.  Thus, you can specify Bash, `awk', Perl,
or some other interpreter and write the rest of the script file in that
language.

   The arguments to the interpreter consist of a single optional
argument following the interpreter name on the first line of the script
file, followed by the name of the script file, followed by the rest of
the arguments.  Bash will perform this action on operating systems that
do not handle it themselves.  Note that some older versions of Unix
limit the interpreter name and argument to a maximum of 32 characters.

   Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
been installed in `/bin'), since this ensures that Bash will be used to
interpret the script, even if it is executed under another shell.


File: bashref.info,  Node: Shell Builtin Commands,  Next: Shell Variables,  Prev: Basic Shell Features,  Up: Top

Shell Builtin Commands
**********************

* Menu:

* Bourne Shell Builtins::	Builtin commands inherited from the Bourne
				Shell.
* Bash Builtins::		Table of builtins specific to Bash.
* The Set Builtin::		This builtin is so overloaded it
				deserves its own section.
* Special Builtins::		Builtin commands classified specially by
				POSIX.2.

   Builtin commands are contained within the shell itself.  When the
name of a builtin command is used as the first word of a simple command
(*note Simple Commands::), the shell executes the command directly,
without invoking another program.  Builtin commands are necessary to
implement functionality impossible or inconvenient to obtain with
separate utilities.

   This section briefly the builtins which Bash inherits from the
Bourne Shell, as well as the builtin commands which are unique to or
have been extended in Bash.

   Several builtin commands are described in other chapters:  builtin
commands which provide the Bash interface to the job control facilities
(*note Job Control Builtins::), the directory stack (*note Directory
Stack Builtins::), the command history (*note Bash History Builtins::),
and the programmable completion facilities (*note Programmable
Completion Builtins::).

   Many of the builtins have been extended by POSIX or Bash.

