of @cite{The GNU Bash Reference Manual},
for @code{Bash}, Version @value{VERSION}.
-Copyright @copyright{} 1988--2010 Free Software Foundation, Inc.
+Copyright @copyright{} 1988--2011 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
features that only appear in Bash. Some of the shells that Bash has
borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell
(@file{ksh}), and the C-shell (@file{csh} and its successor,
-@file{tcsh}). The following menu breaks the features up into
+@file{tcsh}). The following menu breaks the features up into
categories based upon which one of these other shells inspired the
feature.
commands (@dfn{builtins}) implementing functionality impossible
or inconvenient to obtain via separate utilities.
For example, @code{cd}, @code{break}, @code{continue}, and
-@code{exec}) cannot be implemented outside of the shell because
+@code{exec} cannot be implemented outside of the shell because
they directly manipulate the shell itself.
The @code{history}, @code{getopts}, @code{kill}, or @code{pwd}
builtins, among others, could be implemented in separate utilities,
@cindex command timing
The format for a pipeline is
@example
-[@code{time} [@code{-p}]] [@code{!}] @var{command1} [ [@code{|} or @code{|&}] @var{command2} @dots{}]
+[time [-p]] [!] @var{command1} [ | or |& @var{command2} ] @dots{}
@end example
@noindent
connection is performed before any redirections specified by the
command.
-If @samp{|&} is used, the standard error of @var{command1} is connected to
-@var{command2}'s standard input through the pipe; it is shorthand for
-@code{2>&1 |}. This implicit redirection of the standard error is
+If @samp{|&} is used, @var{command1}'s standard output and standard error
+are connected to
+@var{command2}'s standard input through the pipe;
+it is shorthand for @code{2>&1 |}.
+This implicit redirection of the standard error is
performed after any redirections specified by the command.
The reserved word @code{time} causes timing statistics
Any redirections (@pxref{Redirections}) associated with a compound command
apply to all commands within that compound command unless explicitly overridden.
+In most cases a list of commands in a compound command's description may be
+separated from the rest of the command by one or more newlines, and may be
+followed by a newline in place of a semicolon.
+
Bash provides looping constructs, conditional commands, and mechanisms
to group commands and execute them as a unit.
@rwindex do
@rwindex done
The syntax of the @code{until} command is:
+
@example
until @var{test-commands}; do @var{consequent-commands}; done
@end example
+
Execute @var{consequent-commands} as long as
@var{test-commands} has an exit status which is not zero.
The return status is the exit status of the last command executed
@item while
@rwindex while
The syntax of the @code{while} command is:
+
@example
while @var{test-commands}; do @var{consequent-commands}; done
@end example
@example
for @var{name} [ [in [@var{words} @dots{}] ] ; ] do @var{commands}; done
@end example
+
Expand @var{words}, and execute @var{commands} once for each member
in the resultant list, with @var{name} bound to the current member.
If @samp{in @var{words}} is not present, the @code{for} command
@example
for (( @var{expr1} ; @var{expr2} ; @var{expr3} )) ; do @var{commands} ; done
@end example
+
First, the arithmetic expression @var{expr1} is evaluated according
to the rules described below (@pxref{Shell Arithmetic}).
The arithmetic expression @var{expr2} is then evaluated repeatedly
If any expression is omitted, it behaves as if it evaluates to 1.
The return value is the exit status of the last command in @var{commands}
that is executed, or false if any of the expressions is invalid.
-
@end table
The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins})
The syntax of the @code{case} command is:
@example
-@code{case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac}
+case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac
@end example
@code{case} will selectively execute the @var{command-list} corresponding to
Conditional operators such as @samp{-f} must be unquoted to be recognized
as primaries.
-When used with @samp{[[}, The @samp{<} and @samp{>} operators sort
+When used with @samp{[[}, the @samp{<} and @samp{>} operators sort
lexicographically using the current locale.
When the @samp{==} and @samp{!=} operators are used, the string to the
of alphabetic characters.
The return value is 0 if the string matches (@samp{==}) or does not
match (@samp{!=})the pattern, and 1 otherwise.
-Any part of the pattern may be quoted to force it to be matched as a
-string.
+Any part of the pattern may be quoted to force the quoted portion
+to be matched as a string.
An additional binary operator, @samp{=~}, is available, with the same
precedence as @samp{==} and @samp{!=}.
(see the description of @code{shopt} in @ref{The Shopt Builtin})
is enabled, the match is performed without regard to the case
of alphabetic characters.
-Any part of the pattern may be quoted to force it to be matched as a
-string.
+Any part of the pattern may be quoted to force the quoted portion
+to be matched as a string.
+Bracket expressions in regular expressions must be treated carefully,
+since normal quoting characters lose their meanings between brackets.
+If the pattern is stored in a shell variable, quoting the variable
+expansion forces the entire pattern to be matched as a string.
Substrings matched by parenthesized subexpressions within the regular
expression are saved in the array variable @code{BASH_REMATCH}.
The element of @code{BASH_REMATCH} with index 0 is the portion of the string
The element of @code{BASH_REMATCH} with index @var{n} is the portion of the
string matching the @var{n}th parenthesized subexpression.
+For example, the following will match a line
+(stored in the shell variable @var{line})
+if there is a sequence of characters in the value consisting of
+any number, including zero, of
+space characters, zero or one instances of @samp{a}, then a @samp{b}:
+@example
+[[ $line =~ [[:space:]]*(a)?b ]]
+@end example
+
+@noindent
+That means values like @samp{aab} and @samp{ aaaaaab} will match, as
+will a line containing a @samp{b} anywhere in its value.
+
+Storing the regular expression in a shell variable is often a useful
+way to avoid problems with quoting characters that are special to the
+shell. For example, the following is equivalent to the above:
+@example
+pattern='[[:space:]]*(a)?b'
+[[ $line =~ $pattern ]]
+@end example
+
+@noindent
+If you want to match a character that's special to the regular expression
+grammar, it has to be quoted to remove its special meaning.
+Shell programmers should take special care with backslashes, since backslashes
+are used both by the shell and regular expressions to remove the special
+meaning from the following character.
+The following two sets of commands are @emph{not} equivalent:
+@example
+pattern='\.'
+
+[[ . =~ $pattern ]]
+[[ . =~ \. ]]
+
+[[ . =~ "$pattern" ]]
+[[ . =~ '\.' ]]
+@end example
+
+@noindent
+The first two matches will succeed, but the second two will not, because
+in the second two the backslash will be part of the pattern to be matched.
+In the first two examples, the backslash removes the special meaning from
+@samp{.}, so the literal @samp{.} matches.
+If the string in the first examples were anything other than @samp{.}, say
+@samp{a}, the pattern would not match, because the quoted @samp{.} in the
+pattern loses its special meaning of matching any single character.
+
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
@item @var{expression1} || @var{expression2}
True if either @var{expression1} or @var{expression2} is true.
@end table
+
@noindent
-The @code{&&} and @code{||} operators do not evaluate @var{expression2} if the
+The @code{&&} and @code{||} operators do not evaluate @var{[Bexpression2} if the
value of @var{expression1} is sufficient to determine the return
value of the entire conditional expression.
-
@end table
@node Command Grouping
The format for a coprocess is:
@example
-@code{coproc} [@var{NAME}] @var{command} [@var{redirections}]
+coproc [@var{NAME}] @var{command} [@var{redirections}]
@end example
@noindent
command (@pxref{Simple Commands}); otherwise, it is interpreted as
the first word of the simple command.
-When the coproc is executed, the shell creates an array variable
+When the coprocess is executed, the shell creates an array variable
(@pxref{Arrays})
-named @var{NAME} in the context of the executing shell.
+named @env{NAME} in the context of the executing shell.
The standard output of @var{command}
is connected via a pipe to a file descriptor in the executing shell,
-and that file descriptor is assigned to @var{NAME}[0].
+and that file descriptor is assigned to @env{NAME}[0].
The standard input of @var{command}
is connected via a pipe to a file descriptor in the executing shell,
-and that file descriptor is assigned to @var{NAME}[1].
+and that file descriptor is assigned to @env{NAME}[1].
This pipe is established before any redirections specified by the
command (@pxref{Redirections}).
The file descriptors can be utilized as arguments to shell commands
and redirections using standard word expansions.
-The process id of the shell spawned to execute the coprocess is
-available as the value of the variable @var{NAME}_PID.
+The process ID of the shell spawned to execute the coprocess is
+available as the value of the variable @env{NAME}_PID.
The @code{wait}
builtin command may be used to wait for the coprocess to terminate.
Functions are declared using this syntax:
@rwindex function
@example
-@var{name} () @var{compound-command} [ @var{redirections} ]@*or@*
-@code{function} @var{name} [()] @var{compound-command} [ @var{redirections} ]
+@var{name} () @var{compound-command} [ @var{redirections} ]
+@end example
+
+or
+
+@example
+function @var{name} [()] @var{compound-command} [ @var{redirections} ]
@end example
This defines a shell function named @var{name}. The reserved
may be any compound command listed above.
@var{compound-command} is executed whenever @var{name} is specified as the
name of a command.
+When the shell is in @sc{posix} mode (@pxref{Bash POSIX Mode}),
+@var{name} may not be the same as one of the special builtins
+(@pxref{Special Builtins}).
Any redirections (@pxref{Redirections}) associated with the shell function
are performed when the function is executed.
the function and the commands it invokes.
Function names and definitions may be listed with the
-@option{-f} option to the @code{declare} or @code{typeset}
-builtin commands (@pxref{Bash Builtins}).
+@option{-f} option to the @code{declare} (@code{typeset})
+builtin command (@pxref{Bash Builtins}).
The @option{-F} option to @code{declare} or @code{typeset}
will list the function names only
(and optionally the source file and line number, if the @code{extdebug}
@code{alias},
@code{declare}, @code{typeset}, @code{export}, @code{readonly},
and @code{local} builtin commands.
+When in @sc{posix} mode (@pxref{Bash POSIX Mode}), these builtins may appear
+in a command after one or more instances of the @code{command} builtin
+and retain these assignment statement properties.
In the context where an assignment statement is assigning a value
to a shell variable or array index (@pxref{Arrays}), the @samp{+=}
operator can be used to
append to or add to the variable's previous value.
-When @samp{+=} is applied to a variable for which the integer attribute
+When @samp{+=} is applied to a variable for which the @var{integer} attribute
has been set, @var{value} is evaluated as an arithmetic expression and
added to the variable's current value, which is also evaluated.
When @samp{+=} is applied to an array variable using compound assignment
Expansion is performed on the command line after it has been split into
@code{token}s. There are seven kinds of expansion performed:
+
@itemize @bullet
@item brace expansion
@item tilde expansion
Brace expansion is a mechanism by which arbitrary strings may be generated.
This mechanism is similar to
@var{filename expansion} (@pxref{Filename Expansion}),
-but the file names generated need not exist.
+but the filenames generated need not exist.
Patterns to be brace expanded take the form of an optional @var{preamble},
-followed by either a series of comma-separated strings or a seqeunce expression
+followed by either a series of comma-separated strings or a sequence expression
between a pair of braces,
followed by an optional @var{postscript}.
The preamble is prefixed to each string contained within the braces, and
Each variable assignment is checked for unquoted tilde-prefixes immediately
following a @samp{:} or the first @samp{=}.
In these cases, tilde expansion is also performed.
-Consequently, one may use file names with tildes in assignments to
+Consequently, one may use filenames with tildes in assignments to
@env{PATH}, @env{MAILPATH}, and @env{CDPATH},
and the shell assigns the expanded value.
@item ~-@var{N}
The string that would be displayed by @samp{dirs -@var{N}}
-
@end table
@node Shell Parameter Expansion
expanded and that value is used in the rest of the substitution, rather
than the value of @var{parameter} itself.
This is known as @code{indirect expansion}.
-The exceptions to this are the expansions of $@{!@var{prefix*}@}
+The exceptions to this are the expansions of $@{!@var{prefix}@*@}
and $@{!@var{name}[@@]@}
described below.
The exclamation point must immediately follow the left brace in order to
is an array variable subscripted with @samp{@@} or @samp{*},
the case modification operation is applied to each member of the
array in turn, and the expansion is the resultant list.
-
@end table
@node Command Substitution
If one of these characters appears, then the word is
regarded as a @var{pattern},
and replaced with an alphabetically sorted list of
-file names matching the pattern. If no matching file names are found,
+filenames matching the pattern (@pxref{Pattern Matching}).
+If no matching filenames are found,
and the shell option @code{nullglob} is disabled, the word is left
unchanged.
If the @code{nullglob} option is set, and no matches are found, the word
When a pattern is used for filename expansion, the character @samp{.}
at the start of a filename or immediately following a slash
must be matched explicitly, unless the shell option @code{dotglob} is set.
-When matching a file name, the slash character must always be
+When matching a filename, the slash character must always be
matched explicitly.
In other cases, the @samp{.} character is not treated specially.
in the set. A @samp{]} 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 @env{LC_COLLATE} shell variable,
-if set.
+the current locale and the values of the
+@env{LC_COLLATE} and @env{LC_ALL} shell variables, if set.
For example, in the default C locale, @samp{[a-dx-z]} is equivalent to
@samp{[abcdxyz]}. Many locales sort characters in dictionary order, and in
it might be equivalent to @samp{[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 @env{LC_COLLATE} or
-@env{LC_ALL} environment variable to the value @samp{C}.
+@env{LC_ALL} environment variable to the value @samp{C}, or enable the
+@code{globasciiranges} shell option.
Within @samp{[} and @samp{]}, @var{character classes} can be specified
using the syntax
If @var{host} is a valid hostname or Internet address, and @var{port}
is an integer port number or service name, Bash attempts to open a UDP
connection to the corresponding socket.
-
@end table
A failure to open or create a file causes the redirection to fail.
@example
>@var{word} 2>&1
@end example
+When using the second form, @var{word} may not expand to a number or
+@samp{-}. If it does, other redirection operators apply
+(see Duplicating File Descriptors below) for compatibility reasons.
@subsection Appending Standard Output and Standard Error
This construct allows both the
@example
>>@var{word} 2>&1
@end example
+(see Duplicating File Descriptors below).
@subsection Here Documents
This type of redirection instructs the shell to read input from the
@var{delimiter}
@end example
-No parameter expansion, command substitution, arithmetic expansion,
-or filename expansion is performed on
+No parameter and variable expansion, command substitution,
+arithmetic expansion, or filename expansion is performed on
@var{word}. If any characters in @var{word} are quoted, the
@var{delimiter} is the result of quote removal on @var{word},
and the lines in the here-document are not expanded.
<<< @var{word}
@end example
-The @var{word} is expanded and supplied to the command on its standard
-input.
+The @var{word} undergoes
+brace expansion, tilde expansion, parameter and variable expansion,
+command substitution, arithmetic expansion, and quote removal.
+Pathname expansion word splitting are not performed.
+The result is supplied as a single string to the command on its
+standard input.
@subsection Duplicating File Descriptors
The redirection operator
If the digits in @var{word} do not specify a file descriptor open for
input, a redirection error occurs.
If @var{word}
-evaluates to @samp{-}, file descriptor @var{n} is closed. If
-@var{n} is not specified, the standard input (file descriptor 0) is used.
+evaluates to @samp{-}, file descriptor @var{n} is closed.
+If @var{n} is not specified, the standard input (file descriptor 0) is used.
The operator
@example
@var{n} is not specified, the standard output (file descriptor 1) is used.
If the digits in @var{word} do not specify a file descriptor open for
output, a redirection error occurs.
+If @var{word}
+evaluates to @samp{-}, file descriptor @var{n} is closed.
As a special case, if @var{n} is omitted, and @var{word} does not
-expand to one or more digits, the standard output and standard
+expand to one or more digits or @samp{-}, the standard output and standard
error are redirected as described previously.
@subsection Moving File Descriptors
not just those that precede the command name.
When Bash invokes an external command, the variable @samp{$_}
-is set to the full path name of the command and passed to that
+is set to the full pathname of the command and passed to that
command in its environment.
@node Exit Status
@var{waitpid} system call or equivalent function. Exit statuses
fall between 0 and 255, though, as explained below, the shell may
use values above 125 specially. Exit statuses from shell builtins and
-compound commands are also limited to this range. Under certain
+compound commands are also limited to this range. Under certain
circumstances, the shell will use special values to indicate specific
failure modes.
@example
: [@var{arguments}]
@end example
+
Do nothing beyond expanding @var{arguments} and performing redirections.
The return status is zero.
@example
. @var{filename} [@var{arguments}]
@end example
+
Read and execute commands from the @var{filename} argument in the
current shell context. If @var{filename} does not contain a slash,
the @env{PATH} variable is used to find @var{filename}.
@example
break [@var{n}]
@end example
+
Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop.
If @var{n} is supplied, the @var{n}th enclosing loop is exited.
@var{n} must be greater than or equal to 1.
@example
cd [-L|[-P [-e]]] [@var{directory}]
@end example
+
Change the current working directory to @var{directory}.
If @var{directory} is not given, the value of the @env{HOME} shell
variable is used.
and the current working directory cannot be successfully determined
after a successful directory change, @code{cd} will return an unsuccessful
status.
-If @var{directory} is @samp{-}, it is equivalent to @env{$OLDPWD}.
+If @var{directory} is @samp{-}, it is converted to @env{$OLDPWD}
+before the directory change is attempted.
If a non-empty directory name from @env{CDPATH} is used, or if
@samp{-} is the first argument, and the directory change is
@example
continue [@var{n}]
@end example
+
Resume the next iteration of an enclosing @code{for}, @code{while},
@code{until}, or @code{select} loop.
If @var{n} is supplied, the execution of the @var{n}th enclosing loop
@example
eval [@var{arguments}]
@end example
+
The arguments are concatenated together into a single command, which is
then read and executed, and its exit status returned as the exit status
of @code{eval}.
@example
exec [-cl] [-a @var{name}] [@var{command} [@var{arguments}]]
@end example
+
If @var{command}
is supplied, it replaces the shell without creating a new process.
If the @option{-l} option is supplied, the shell places a dash at the
environment.
If @option{-a} is supplied, the shell passes @var{name} as the zeroth
argument to @var{command}.
+If @var{command}
+cannot be executed for some reason, a non-interactive shell exits,
+unless the @code{execfail} shell option
+is enabled. In that case, it returns failure.
+An interactive shell returns failure if the file cannot be executed.
If no @var{command} is specified, redirections may be used to affect
the current shell environment. If there are no redirection errors, the
return status is zero; otherwise the return status is non-zero.
@example
exit [@var{n}]
@end example
+
Exit the shell, returning a status of @var{n} to the shell's parent.
If @var{n} is omitted, the exit status is that of the last command executed.
Any trap on @code{EXIT} is executed before the shell terminates.
@example
export [-fn] [-p] [@var{name}[=@var{value}]]
@end example
+
Mark each @var{name} to be passed to child processes
in the environment. If the @option{-f} option is supplied, the @var{name}s
refer to shell functions; otherwise the names refer to shell variables.
The @option{-n} option means to no longer mark each @var{name} for export.
If no @var{names} are supplied, or if the @option{-p} option is given, a
-list of exported names is displayed.
+list of names of all exported variables is displayed.
The @option{-p} option displays output in a form that may be reused as input.
If a variable name is followed by =@var{value}, the value of
the variable is set to @var{value}.
@example
getopts @var{optstring} @var{name} [@var{args}]
@end example
+
@code{getopts} is used by shell scripts to parse positional parameters.
@var{optstring} contains the option characters to be recognized; if a
character is followed by a colon, the option is expected to have an
-argument, which should be separated from it by white space.
+argument, which should be separated from it by whitespace.
The colon (@samp{:}) and question mark (@samp{?}) may not be
used as option characters.
Each time it is invoked, @code{getopts}
When the end of options is encountered, @code{getopts} exits with a
return value greater than zero.
@env{OPTIND} is set to the index of the first non-option argument,
-and @code{name} is set to @samp{?}.
+and @var{name} is set to @samp{?}.
@code{getopts}
normally parses the positional parameters, but if more arguments are
@code{getopts} can report errors in two ways. If the first character of
@var{optstring} is a colon, @var{silent}
-error reporting is used. In normal operation diagnostic messages
+error reporting is used. In normal operation, diagnostic messages
are printed when invalid options or missing option arguments are
encountered.
If the variable @env{OPTERR}
@example
hash [-r] [-p @var{filename}] [-dt] [@var{name}]
@end example
+
Each time @code{hash} is invoked, it remembers the full pathnames of the
commands specified as @var{name} arguments,
so they need not be searched for on subsequent invocations.
@example
pwd [-LP]
@end example
+
Print the absolute pathname of the current working directory.
If the @option{-P} option is supplied, the pathname printed will not
contain symbolic links.
@item readonly
@btindex readonly
@example
-readonly [-aApf] [@var{name}[=@var{value}]] @dots{}
+readonly [-aAf] [-p] [@var{name}[=@var{value}]] @dots{}
@end example
+
Mark each @var{name} as readonly.
The values of these names may not be changed by subsequent assignment.
If the @option{-f} option is supplied, each @var{name} refers to a shell
The @option{-a} option means each @var{name} refers to an indexed
array variable; the @option{-A} option means each @var{name} refers
to an associative array variable.
+If both options are supplied, @option{-A} takes precedence.
If no @var{name} arguments are given, or if the @option{-p}
option is supplied, a list of all readonly names is printed.
+The other options may be used to restrict the output to a subset of
+the set of readonly names.
The @option{-p} option causes output to be displayed in a format that
may be reused as input.
If a variable name is followed by =@var{value}, the value of
@example
return [@var{n}]
@end example
-Cause a shell function to exit with the return value @var{n}.
+
+Cause a shell function to stop executing and return the value @var{n}
+to its caller.
If @var{n} is not supplied, the return value is the exit status of the
last command executed in the function.
-This may also be used to terminate execution of a script being executed
-with the @code{.} (or @code{source}) builtin, returning either @var{n} or
+@code{return} may also be used to terminate execution of a script
+being executed with the @code{.} (@code{source}) builtin,
+returning either @var{n} or
the exit status of the last command executed within the script as the exit
status of the script.
+If @var{n} is supplied, the return value is its least significant
+8 bits.
Any command associated with the @code{RETURN} trap is executed
before execution resumes after the function or script.
-The return status is non-zero if @code{return} is used outside a function
+The return status is non-zero if @code{return} is supplied a non-numeric
+argument or is used outside a function
and not during the execution of a script by @code{.} or @code{source}.
@item shift
@example
shift [@var{n}]
@end example
+
Shift the positional parameters to the left by @var{n}.
The positional parameters from @var{n}+1 @dots{} @code{$#} are
renamed to @code{$1} @dots{} @code{$#}-@var{n}.
The return status is zero unless @var{n} is greater than @code{$#} or
less than zero, non-zero otherwise.
-@item test
+@item test[B
@itemx [
@btindex test
@btindex [
-Evaluate a conditional expression @var{expr}.
+@example
+test @var{expr}
+@end example
+
+Evaluate a conditional expression @var{expr} and return a status of 0
+(true) or 1 (false).
Each operator and operand must be a separate argument.
Expressions are composed of the primaries described below in
@ref{Bash Conditional Expressions}.
Expressions may be combined using the following operators, listed in
decreasing order of precedence.
The evaluation depends on the number of arguments; see below.
+Operator precedence is used when there are five or more arguments.
@table @code
@item ! @var{expr}
false.
@item 3 arguments
+The following conditions are applied in the order listed.
If the second argument is one of the binary conditional
operators (@pxref{Bash Conditional Expressions}), the
result of the expression is the result of the binary test using the
using the rules listed above.
@end table
+When used with @code{test} or @samp{[}, the @samp{<} and @samp{>}
+operators sort lexicographically using ASCII ordering.
+
@item times
@btindex times
@example
times
@end example
+
Print out the user and system times used by the shell and its children.
The return status is zero.
@example
trap [-lp] [@var{arg}] [@var{sigspec} @dots{}]
@end example
+
The commands in @var{arg} are to be read and executed when the
shell receives signal @var{sigspec}. If @var{arg} is absent (and
there is a single @var{sigspec}) or
@example
umask [-p] [-S] [@var{mode}]
@end example
+
Set the shell process's file creation mask to @var{mode}. If
@var{mode} begins with a digit, it is interpreted as an octal number;
if not, it is interpreted as a symbolic mode mask similar
@example
unset [-fv] [@var{name}]
@end example
-Each variable or function @var{name} is removed.
-If no options are supplied, or the @option{-v} option is given, each
-@var{name} refers to a shell variable.
+
+Remove each variable or function @var{name}.
+If the @option{-v} option is given, each
+@var{name} refers to a shell variable and that variable is remvoved.
If the @option{-f} option is given, the @var{name}s refer to shell
functions, and the function definition is removed.
+If no options are supplied, each @var{name} refers to a variable; if
+there is no variable by that name, any function with that name is
+unset.
Readonly variables and functions may not be unset.
The return status is zero unless a @var{name} is readonly.
@end table
@item alias
@btindex alias
@example
-alias [@code{-p}] [@var{name}[=@var{value}] @dots{}]
+alias [-p] [@var{name}[=@var{value}] @dots{}]
@end example
Without arguments or with the @option{-p} option, @code{alias} prints
@example
builtin [@var{shell-builtin} [@var{args}]]
@end example
+
Run a shell builtin, passing it @var{args}, and return its exit status.
This is useful when defining a shell function with the same
name as a shell builtin, retaining the functionality of the builtin within
@example
caller [@var{expr}]
@end example
+
Returns the context of any active subroutine call (a shell function or
a script executed with the @code{.} or @code{source} builtins).
@example
command [-pVv] @var{command} [@var{arguments} @dots{}]
@end example
+
Runs @var{command} with @var{arguments} ignoring any shell function
named @var{command}.
Only shell builtin commands or commands found by searching the
@item declare
@btindex declare
@example
-declare [-aAfFilrtux] [-p] [@var{name}[=@var{value}] @dots{}]
+declare [-aAfFgilrtux] [-p] [@var{name}[=@var{value}] @dots{}]
@end example
Declare variables and give them attributes. If no @var{name}s
@option{-F} implies @option{-f}.
The @option{-g} option forces variables to be created or modified at
-the global scope, even when \fBdeclare\fP is executed in a shell function.
+the global scope, even when @code{declare} is executed in a shell function.
It is ignored in all other cases.
The following options can be used to restrict output to variables with
may not be used to destroy an array variable and @samp{+r} will not
remove the readonly attribute.
When used in a function, @code{declare} makes each @var{name} local,
-as with the @code{local} command, unless the @samp{-g} option is used.
+as with the @code{local} command, unless the @option{-g} option is used.
If a variable name is followed by =@var{value}, the value of the variable
is set to @var{value}.
@example
echo [-neE] [@var{arg} @dots{}]
@end example
+
Output the @var{arg}s, separated by spaces, terminated with a
newline.
-The return status is always 0.
+The return status is 0 unless a write error occurs.
If @option{-n} is specified, the trailing newline is suppressed.
If the @option{-e} option is given, interpretation of the following
backslash-escaped characters is enabled.
@example
enable [-a] [-dnps] [-f @var{filename}] [@var{name} @dots{}]
@end example
+
Enable and disable builtin shell commands.
Disabling a builtin allows a disk command which has the same name
as a shell builtin to be executed without specifying a full pathname,
@example
help [-dms] [@var{pattern}]
@end example
+
Display helpful information about builtin commands.
If @var{pattern} is specified, @code{help} gives detailed help
on all commands matching @var{pattern}, otherwise a list of
@item let
@btindex let
@example
-let @var{expression} [@var{expression}]
+let @var{expression} [@var{expression} @dots{}]
@end example
+
The @code{let} builtin allows arithmetic to be performed on shell
variables. Each @var{expression} is evaluated according to the
rules given below in @ref{Shell Arithmetic}. If the
@example
local [@var{option}] @var{name}[=@var{value}] @dots{}
@end example
+
For each argument, a local variable named @var{name} is created,
and assigned @var{value}.
The @var{option} can be any of the options accepted by @code{declare}.
@example
logout [@var{n}]
@end example
+
Exit a login shell, returning a status of @var{n} to the shell's
parent.
@item mapfile
@btindex mapfile
@example
-mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [
--C @var{callback}] [-c @var{quantum}] [@var{array}]
+mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}]
+ [-C @var{callback}] [-c @var{quantum}] [@var{array}]
@end example
+
Read lines from the standard input into the indexed array variable @var{array},
or from file descriptor @var{fd}
if the @option{-u} option is supplied.
The variable @code{MAPFILE} is the default @var{array}.
Options, if supplied, have the following meanings:
+
@table @code
@item -n
@example
printf [-v @var{var}] @var{format} [@var{arguments}]
@end example
+
Write the formatted @var{arguments} to the standard output under the
control of the @var{format}.
The @option{-v} option causes the output to be assigned to the variable
@table @code
@item %b
-causes @code{printf} to expand backslash escape sequences in the
+Causes @code{printf} to expand backslash escape sequences in the
corresponding @var{argument},
-(except that @samp{\c} terminates output, backslashes in
+except that @samp{\c} terminates output, backslashes in
@samp{\'}, @samp{\"}, and @samp{\?} are not removed, and octal escapes
-beginning with @samp{\0} may contain up to four digits).
+beginning with @samp{\0} may contain up to four digits.
@item %q
-causes @code{printf} to output the
+Causes @code{printf} to output the
corresponding @var{argument} in a format that can be reused as shell input.
@item %(@var{datefmt})T
-causes @code{printf} to output the date-time string resulting from using
+Causes @code{printf} to output the date-time string resulting from using
@var{datefmt} as a format string for @code{strftime}(3). The corresponding
@var{argument} is an integer representing the number of seconds since the
epoch. Two special argument values may be used: -1 represents the current
@item read
@btindex read
@example
-read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}]
+read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}]
+ [-N @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}]
@end example
+
One line is read from the standard input, or from the file descriptor
@var{fd} supplied as an argument to the @option{-u} option, and the first word
is assigned to the first @var{name}, the second word to the second @var{name},
This option is only effective if @code{read} is reading input from a
terminal, pipe, or other special file; it has no effect when reading
from regular files.
-If @var{timeout} is 0, @code{read} returns success if input is available on
-the specified file descriptor, failure otherwise.
+If @var{timeout} is 0, @code{read} returns immediately, without trying to
+read and data. The exit status is 0 if input is available on
+the specified file descriptor, non-zero otherwise.
The exit status is greater than 128 if the timeout is exceeded.
@item -u @var{fd}
Read input from file descriptor @var{fd}.
-
@end table
@item readarray
@btindex readarray
@example
-readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [
--C @var{callback}] [-c @var{quantum}] [@var{array}]
+readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}]
+ [-C @var{callback}] [-c @var{quantum}] [@var{array}]
@end example
+
Read lines from the standard input into the indexed array variable @var{array},
or from file descriptor @var{fd}
if the @option{-u} option is supplied.
@example
source @var{filename}
@end example
+
A synonym for @code{.} (@pxref{Bourne Shell Builtins}).
@item type
@example
type [-afptP] [@var{name} @dots{}]
@end example
+
For each @var{name}, indicate how it would be interpreted if used as a
command name.
@option{-t} would not return @samp{file}.
If a command is hashed, @option{-p} and @option{-P} print the hashed value,
-not necessarily the file that appears first in @code{$PATH}.
+which is not necessarily the file that appears first in @code{$PATH}.
If the @option{-a} option is used, @code{type} returns all of the places
that contain an executable named @var{file}.
@item typeset
@btindex typeset
@example
-typeset [-afFrxi] [-p] [@var{name}[=@var{value}] @dots{}]
+typeset [-afFgrxilrtux] [-p] [@var{name}[=@var{value}] @dots{}]
@end example
+
The @code{typeset} command is supplied for compatibility with the Korn
-shell; however, it has been deprecated in favor of the @code{declare}
-builtin command.
+shell.
+It is a synonym for the @code{declare} builtin command.
@item ulimit
@btindex ulimit
@example
ulimit [-abcdefilmnpqrstuvxHST] [@var{limit}]
@end example
+
@code{ulimit} provides control over the resources available to processes
started by the shell, on systems that allow such control. If an
option is given, it is interpreted as follows:
+
@table @code
@item -S
Change and report the soft limit associated with a resource.
@item -T
The maximum number of threads.
-
@end table
-If @var{limit} is given, it is the new value of the specified resource;
-the special @var{limit} values @code{hard}, @code{soft}, and
+If @var{limit} is given, and the @option{-a} option is not used,
+@var{limit} is the new value of the specified resource.
+The special @var{limit} values @code{hard}, @code{soft}, and
@code{unlimited} stand for the current hard limit, the current soft limit,
and no limit, respectively.
A hard limit cannot be increased by a non-root user once it is set;
When setting new limits, if neither @option{-H} nor @option{-S} is supplied,
both the hard and soft limits are set.
If no option is given, then @option{-f} is assumed. Values are in 1024-byte
-increments, except for @option{-t}, which is in seconds, @option{-p},
-which is in units of 512-byte blocks, and @option{-n} and @option{-u}, which
-are unscaled values.
+increments, except for @option{-t}, which is in seconds; @option{-p},
+which is in units of 512-byte blocks; and @option{-T}, @option{-b},
+@option{-n} and @option{-u}, which are unscaled values.
The return status is zero unless an invalid option or argument is supplied,
or an error occurs while setting a new limit.
Remove each @var{name} from the list of aliases. If @option{-a} is
supplied, all aliases are removed.
Aliases are described in @ref{Aliases}.
-
@end table
@node Modifying Shell Behavior
@item set
@btindex set
@example
-set [--abefhkmnptuvxBCEHPT] [-o @var{option}] [@var{argument} @dots{}]
-set [+abefhkmnptuvxBCEHPT] [+o @var{option}] [@var{argument} @dots{}]
+set [--abefhkmnptuvxBCEHPT] [-o @var{option-name}] [@var{argument} @dots{}]
+set [+abefhkmnptuvxBCEHPT] [+o @var{option-name}] [@var{argument} @dots{}]
@end example
If no options or arguments are supplied, @code{set} displays the names
immediately, rather than before printing the next primary prompt.
@item -e
-Exit immediately if a pipeline (@pxref{Pipelines}), which may consist
-of a single simple command (@pxref{Simple Commands}),
-a subshell command enclosed in parentheses (@pxref{Command Grouping}),
-or one of the commands executed as part of a command list enclosed
-by braces (@pxref{Command Grouping})
+Exit immediately if
+a pipeline (@pxref{Pipelines}), which may consist of a single simple command
+(@pxref{Simple Commands}),
+a list (@pxref{Lists}),
+or a compound command (@pxref{Compound Commands})
returns a non-zero status.
The shell does not exit if the command that fails is part of the
command list immediately following a @code{while} or @code{until} keyword,
the command following the final @code{&&} or @code{||},
any command in a pipeline but the last,
or if the command's return status is being inverted with @code{!}.
+If a compound command other than a subshell
+returns a non-zero status because a command failed
+while @option{-e} was being ignored, the shell does not exit.
A trap on @code{ERR}, if set, is executed before the shell exits.
This option applies to the shell environment and each subshell environment
@item -m
Job control is enabled (@pxref{Job Control}).
+All processes run in a separate process group.
+When a background job completes, the shell prints a line
+containing its exit status.
@item -n
Read commands but do not execute them; this may be used to check a
and the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH} and @env{GLOBIGNORE}
variables, if they appear in the environment, are ignored.
If the shell is started with the effective user (group) id not equal to the
-real user (group) id, and the @code{-p} option is not supplied, these actions
+real user (group) id, and the @option{-p} option is not supplied, these actions
are taken and the effective user id is set to the real user id.
-If the @code{-p} option is supplied at startup, the effective user id is
+If the @option{-p} option is supplied at startup, the effective user id is
not reset.
Turning this option off causes the effective user
and group ids to be set to the real user and group ids.
@example
shopt [-pqsu] [-o] [@var{optname} @dots{}]
@end example
+
Toggle the values of variables controlling optional shell behavior.
With no options, or with the @option{-p} option, a list of all settable
options is displayed, with an indication of whether or not each is set.
@end table
If either @option{-s} or @option{-u}
-is used with no @var{optname} arguments, the display is limited to
+is used with no @var{optname} arguments, @code{shopt} shows only
those options which are set or unset, respectively.
Unless otherwise noted, the @code{shopt} options are disabled (off)
@item checkwinsize
If set, Bash checks the window size after each command
-and, if necessary, updates the values of
+ and, if necessary, updates the values of
@env{LINES} and @env{COLUMNS}.
@item cmdhist
@item compat31
If set, Bash
changes its behavior to that of version 3.1 with respect to quoted
-arguments to the conditional command's =~ operator.
+arguments to the conditional command's @samp{=~} operator.
@item compat32
If set, Bash
changes its behavior to that of version 3.2 with respect to locale-specific
-string comparison when using the conditional command's < and > operators.
+string comparison when using the @samp{[[}
+conditional command's @samp{<} and @samp{>} operators.
+Bash versions prior to bash-4.0 use ASCII collation and strcmp(3);
+bash-4.1 and later use the current locale's collation sequence and strcoll(3).
@item compat40
If set, Bash
changes its behavior to that of version 4.0 with respect to locale-specific
-string comparison when using the conditional command's < and > operators
+string comparison when using the @samp{[[}
+conditional command's @samp{<} and @samp{>} operators (see previous item)
and the effect of interrupting a command list.
@item compat41
quoted. This is the behavior of @sc{posix} mode through version 4.1.
The default Bash behavior remains as in previous versions.
+@item complete_fullquote
+If set, Bash
+quotes all shell metacharacters in filenames and directory names when
+performing completion.
+If not set, Bash
+removes metacharacters such as the dollar sign from the set of
+characters that will be quoted in completed filenames
+when these metacharacters appear in shell variable references in words to be
+completed.
+This means that dollar signs in variable names that expand to directories
+will not be quoted;
+however, any dollar signs appearing in filenames will not be quoted, either.
+This is active only when bash is using backslashes to quote completed
+filenames.
+This variable is set by default, which is the default Bash behavior in
+versions through 4.2.
+
+@item direxpand
+If set, Bash
+replaces directory names with the results of word expansion when performing
+filename completion. This changes the contents of the readline editing
+buffer.
+If not set, Bash attempts to preserve what the user typed.
+
@item dirspell
If set, Bash
attempts spelling correction on directory names during word completion
@xref{Bash Variables}, for a description of @env{FIGNORE}.
This option is enabled by default.
+@item globasciiranges
+If set, range expressions used in pattern matching (@pxref{Pattern Matching})
+behave as if in the traditional C locale when performing
+comparisons. That is, the current locale's collating sequence
+is not taken into account, so
+@samp{b} will not collate between @samp{A} and @samp{B},
+and upper-case and lower-case ASCII characters will collate together.
+
@item globstar
If set, the pattern @samp{**} used in a filename expansion context will
-match a files and zero or more directories and subdirectories.
+match all files and zero or more directories and subdirectories.
If the pattern is followed by a @samp{/}, only directories and
subdirectories match.
If set, prompt strings undergo
parameter expansion, command substitution, arithmetic
expansion, and quote removal after being expanded
-as described below (@pxref{Printing a Prompt}).
+as described below (@pxref{Controlling the Prompt}).
This option is enabled by default.
@item restricted_shell
are enabled, non-zero otherwise.
When setting or unsetting options, the return status is zero unless an
@var{optname} is not a valid shell option.
-
@end table
@node Special Builtins
A colon-separated list of filenames which the shell periodically checks
for new mail.
Each list entry can specify the message that is printed when new mail
-arrives in the mail file by separating the file name from the message with
+arrives in the mail file by separating the filename from the message with
a @samp{?}.
When used in the text of the message, @code{$_} expands to the name of
the current mail file.
@item PS1
The primary prompt string. The default value is @samp{\s-\v\$ }.
-@xref{Printing a Prompt}, for the complete list of escape
+@xref{Controlling the Prompt}, for the complete list of escape
sequences that are expanded before @env{PS1} is displayed.
@item PS2
reading any startup files. This variable is readonly.
@item BASHPID
-Expands to the process id of the current Bash process.
+Expands to the process ID of the current Bash process.
This differs from @code{$$} under certain circumstances, such as subshells
that do not require Bash to be re-initialized.
@item BASH_ALIASES
An associative array variable whose members correspond to the internal
-list of aliases as maintained by the @code{alias} builtin
+list of aliases as maintained by the @code{alias} builtin.
(@pxref{Bourne Shell Builtins}).
Elements added to this array appear in the alias list; unsetting array
elements cause aliases to be removed from the alias list.
@code{$@{BASH_SOURCE[$i]@}} and called from @code{$@{BASH_SOURCE[$i+1]@}}
@item BASH_SUBSHELL
-Incremented by one each time a subshell or subshell environment is spawned.
+Incremented by one within each subshell or subshell environment when
+the shell begins executing in that environment.
The initial value is 0.
@item BASH_VERSINFO
@item BASH_VERSINFO[5]
The value of @env{MACHTYPE}.
-
@end table
@item BASH_VERSION
being closed.
@item COLUMNS
-Used by the @code{select} builtin command to determine the terminal width
-when printing selection lists. Automatically set upon receipt of a
+Used by the @code{select} command to determine the terminal width
+when printing selection lists. Automatically set by an interactive shell
+upon receipt of a
@code{SIGWINCH}.
@item COMP_CWORD
@item FIGNORE
A colon-separated list of suffixes to ignore when performing
filename completion.
-A file name whose suffix matches one of the entries in
+A filename whose suffix matches one of the entries in
@env{FIGNORE}
-is excluded from the list of matched file names. A sample
+is excluded from the list of matched filenames. A sample
value is @samp{.o:~}
@item FUNCNAME
default value is @file{~/.bash_history}.
@item HISTFILESIZE
-The maximum number of lines contained in the history file. When this
-variable is assigned a value, the history file is truncated, if
-necessary, by removing the oldest entries,
-to contain no more than that number of lines.
+The maximum number of lines contained in the history file.
+When this variable is assigned a value, the history file is truncated,
+if necessary, to contain no more than that number of lines
+by removing the oldest entries.
The history file is also truncated to this size after
writing it when an interactive shell exits.
-The default value is 500.
+If the value is 0, the history file is truncated to zero size.
+Non-numeric values and numeric values less than zero inhibit truncation.
+The shell sets the default value to the value of @env{HISTSIZE}
+after reading any startup files.
@item HISTIGNORE
A colon-separated list of patterns used to decide which command
@item HISTSIZE
The maximum number of commands to remember on the history list.
-The default value is 500.
+If the value is 0, commands are not saved in the history list.
+Numeric values less than zero result in every command being saved
+on the history list (there is no limit).
+The shell sets the default value to 500 after reading any startup files.
@item HISTTIMEFORMAT
If this variable is set and not null, its value is used as a format string
The line number in the script or shell function currently executing.
@item LINES
-Used by the @code{select} builtin command to determine the column length
-for printing selection lists. Automatically set upon receipt of a
+Used by the @code{select} command to determine the column length
+for printing selection lists. Automatically set by an interactive shell
+upon receipt of a
@code{SIGWINCH}.
@item MACHTYPE
contain only a single command).
@item POSIXLY_CORRECT
-If this variable is in the environment when @code{bash} starts, the shell
+If this variable is in the environment when Bash starts, the shell
enters @sc{posix} mode (@pxref{Bash POSIX Mode}) before reading the
startup files, as if the @option{--posix} invocation option had been supplied.
-If it is set while the shell is running, @code{bash} enables @sc{posix} mode,
+If it is set while the shell is running, Bash enables @sc{posix} mode,
as if the command
@example
@code{set -o posix}
@item PROMPT_DIRTRIM
If set to a number greater than zero, the value is used as the number of
trailing directory components to retain when expanding the @code{\w} and
-@code{\W} prompt string escapes (@pxref{Printing a Prompt}).
+@code{\W} prompt string escapes (@pxref{Controlling the Prompt}).
Characters removed are replaced with an ellipsis.
@item PS3
@node Bash Features
@chapter Bash Features
-This section describes features unique to Bash.
+This chapter describes features unique to Bash.
@menu
* Invoking Bash:: Command line options that you can give
* Aliases:: Substituting one command for another.
* Arrays:: Array Variables.
* The Directory Stack:: History of visited directories.
-* Printing a Prompt:: Controlling the PS1 string.
+* Controlling the Prompt:: Customizing the various prompt strings.
* The Restricted Shell:: A more controlled mode of shell execution.
* Bash POSIX Mode:: Making Bash behave more closely to what
the POSIX standard specifies.
@item --version
Show version information for this instance of
Bash on the standard output and exit successfully.
-
@end table
There are several single-character options that may be supplied at
invocation which are not available with the @code{set} builtin.
@table @code
-@item -c @var{string}
-Read and execute commands from @var{string} after processing the
-options, then exit. Any remaining arguments are assigned to the
+@item -c
+Read and execute commands from the first non-option @var{argument}
+after processing the options, then exit.
+Any remaining arguments are assigned to the
positional parameters, starting with @code{$0}.
@item -i
A @code{--} signals the end of options and disables further option
processing.
Any arguments after the @code{--} are treated as filenames and arguments.
-
@end table
@cindex login shell
This section describes how Bash executes its startup files.
If any of the files exist but cannot be read, Bash reports an error.
-Tildes are expanded in file names as described above under
+Tildes are expanded in filenames as described above under
Tilde Expansion (@pxref{Tilde Expansion}).
Interactive shells are described in @ref{Interactive Shells}.
@end example
@noindent
but the value of the @env{PATH} variable is not used to search for the
-file name.
+filename.
As noted above, if a non-interactive shell is invoked with the
@option{--login} option, Bash attempts to read and execute commands from the
@subsubheading Invoked by remote shell daemon
Bash attempts to determine when it is being run with its standard input
-connected to a network connection, as if by the remote shell
+connected to a network connection, as when executed by the remote shell
daemon, usually @code{rshd}, or the secure shell daemon @code{sshd}.
If Bash determines it is being run in
this fashion, it reads and executes commands from @file{~/.bashrc}, if that
@subsubheading Invoked with unequal effective and real @sc{uid/gid}s
If Bash is started with the effective user (group) id not equal to the
-real user (group) id, and the @code{-p} option is not supplied, no startup
+real user (group) id, and the @option{-p} option is not supplied, no startup
files are read, shell functions are not inherited from the environment,
the @env{SHELLOPTS}, @env{BASHOPTS}, @env{CDPATH}, and @env{GLOBIGNORE}
variables, if they appear in the environment, are ignored, and the effective
user id is set to the real user id.
-If the @code{-p} option is supplied at invocation, the startup behavior is
+If the @option{-p} option is supplied at invocation, the startup behavior is
the same, but the effective user id is not reset.
@node Interactive Shells
@file{/dev/stdin}, @file{/dev/stdout}, or @file{/dev/stderr}, file
descriptor 0, 1, or 2, respectively, is checked.
-When used with @samp{[[}, The @samp{<} and @samp{>} operators sort
+When used with @samp{[[}, the @samp{<} and @samp{>} operators sort
lexicographically using the current locale.
+The @code{test} command uses ASCII ordering.
Unless otherwise specified, primaries that operate on files follow symbolic
links and operate on the target of the link, rather than the link itself.
greater than, or greater than or equal to @var{arg2},
respectively. @var{Arg1} and @var{arg2}
may be positive or negative integers.
-
@end table
@node Shell Arithmetic
when it is referenced, or when a variable which has been given the
@var{integer} attribute using @samp{declare -i} is assigned a value.
A null value evaluates to 0.
-A shell variable need not have its integer attribute turned on
+A shell variable need not have its @var{integer} attribute turned on
to be used in an expression.
Constants with a leading 0 are interpreted as octal numbers.
is not expanded a second time.
This means that one may alias @code{ls} to @code{"ls -F"},
for instance, and Bash does not try to recursively expand the
-replacement text. If the last character of the alias value is a
-space or tab character, then the next command word following the
+replacement text.
+If the last character of the alias value is a
+@var{blank}, then the next command word following the
alias is also checked for alias expansion.
Aliases are created and listed with the @code{alias}
limit on the size of an array, nor any requirement that members
be indexed or assigned contiguously.
Indexed arrays are referenced using integers (including arithmetic
-expressions (@pxref{Shell Arithmetic}) and are zero-based;
+expressions (@pxref{Shell Arithmetic})) and are zero-based;
associative arrays use arbitrary strings.
An indexed array is created automatically if any variable is assigned to
using the syntax
@example
-name[@var{subscript}]=@var{value}
+@var{name}[@var{subscript}]=@var{value}
@end example
@noindent
The @var{subscript}
is treated as an arithmetic expression that must evaluate to a number.
-If @var{subscript} evaluates to a number less than zero, it is used as
-an offset from one greater than the array's maximum index (so a subcript
-of -1 refers to the last element of the array).
To explicitly declare an array, use
@example
declare -a @var{name}
@noindent
is also accepted; the @var{subscript} is ignored.
+@noindent
Associative arrays are created using
@example
declare -A @var{name}.
Arrays are assigned to using compound assignments of the form
@example
-name=(value@var{1} @dots{} value@var{n})
+@var{name}=(@var{value1} @var{value2} @dots{} )
@end example
@noindent
where each
@var{value} is of the form @code{[@var{subscript}]=}@var{string}.
-Indexed array assignments do not require the bracket and subscript.
+Indexed array assignments do not require anything but @var{string}.
When assigning to indexed arrays, if
the optional subscript is supplied, that index is assigned to;
otherwise the index of the element assigned is the last index assigned
This syntax is also accepted by the @code{declare}
builtin. Individual array elements may be assigned to using the
-@code{name[}@var{subscript}@code{]=}@var{value} syntax introduced above.
+@code{@var{name}[@var{subscript}]=@var{value}} syntax introduced above.
Any element of an array may be referenced using
-@code{$@{name[}@var{subscript}@code{]@}}.
+@code{$@{@var{name}[@var{subscript}]@}}.
The braces are required to avoid
conflicts with the shell's filename expansion operators. If the
@var{subscript} is @samp{@@} or @samp{*}, the word expands to all members
of the array @var{name}. These subscripts differ only when the word
appears within double quotes.
If the word is double-quoted,
-@code{$@{name[*]@}} expands to a single word with
+@code{$@{@var{name}[*]@}} expands to a single word with
the value of each array member separated by the first character of the
-@env{IFS} variable, and @code{$@{name[@@]@}} expands each element of
+@env{IFS} variable, and @code{$@{@var{name}[@@]@}} expands each element of
@var{name} to a separate word. When there are no array members,
-@code{$@{name[@@]@}} expands to nothing.
+@code{$@{@var{name}[@@]@}} expands to nothing.
If the double-quoted expansion occurs within a word, the expansion of
the first parameter is joined with the beginning part of the original
word, and the expansion of the last parameter is joined with the last
part of the original word.
This is analogous to the
expansion of the special parameters @samp{@@} and @samp{*}.
-@code{$@{#name[}@var{subscript}@code{]@}} expands to the length of
-@code{$@{name[}@var{subscript}@code{]@}}.
+@code{$@{#@var{name}[@var{subscript}]@}} expands to the length of
+@code{$@{@var{name}[@var{subscript}]@}}.
If @var{subscript} is @samp{@@} or
@samp{*}, the expansion is the number of elements in the array.
Referencing an array variable without a subscript is equivalent to
referencing with a subscript of 0.
+If the @var{subscript}
+used to reference an element of an indexed array
+evaluates to a number less than zero, it is used as
+an offset from one greater than the array's maximum index (so a subcript
+of -1 refers to the last element of the array).
An array variable is considered set if a subscript has been assigned a
value. The null string is a valid value.
The @code{unset} builtin is used to destroy arrays.
-@code{unset} @var{name}[@var{subscript}]
+@code{unset @var{name}[@var{subscript}]}
destroys the array element at index @var{subscript}.
Care must be taken to avoid unwanted side effects caused by filename
expansion.
-@code{unset} @var{name}, where @var{name} is an array, removes the
-entire array. A subscript of @samp{*} or @samp{@@} also removes the
+@code{unset @var{name}}, where @var{name} is an array, removes the
+entire array. A subscript of @samp{*} or @samp{@@} also removes the
entire array.
The @code{declare}, @code{local}, and @code{readonly}
builtins each accept a @option{-a} option to specify an indexed
array and a @option{-A} option to specify an associative array.
+If both options are supplied, @option{-A} takes precedence.
The @code{read} builtin accepts a @option{-a}
option to assign a list of words read from the standard input
to an array, and can read values from the standard input into
@item dirs
@btindex dirs
@example
-dirs [+@var{N} | -@var{N}] [-clpv]
+dirs [-clpv] [+@var{N} | -@var{N}]
@end example
+
Display the list of currently remembered directories. Directories
are added to the list with the @code{pushd} command; the
@code{popd} command removes directories from the list.
+
@table @code
-@item +@var{N}
-Displays the @var{N}th directory (counting from the left of the
-list printed by @code{dirs} when invoked without options), starting
-with zero.
-@item -@var{N}
-Displays the @var{N}th directory (counting from the right of the
-list printed by @code{dirs} when invoked without options), starting
-with zero.
@item -c
Clears the directory stack by deleting all of the elements.
@item -l
-Produces a longer listing; the default listing format uses a
-tilde to denote the home directory.
+Produces a listing using full pathnames;
+the default listing format uses a tilde to denote the home directory.
@item -p
Causes @code{dirs} to print the directory stack with one entry per
line.
@item -v
Causes @code{dirs} to print the directory stack with one entry per
line, prefixing each entry with its index in the stack.
+@item +@var{N}
+Displays the @var{N}th directory (counting from the left of the
+list printed by @code{dirs} when invoked without options), starting
+with zero.
+@item -@var{N}
+Displays the @var{N}th directory (counting from the right of the
+list printed by @code{dirs} when invoked without options), starting
+with zero.
@end table
@item popd
@btindex popd
@example
-popd [+@var{N} | -@var{N}] [-n]
+popd [-n] [+@var{N} | -@var{N}]
@end example
Remove the top entry from the directory stack, and @code{cd}
removes the top directory from the stack and
performs a @code{cd} to the new top directory. The
elements are numbered from 0 starting at the first directory listed with
-@code{dirs}; i.e., @code{popd} is equivalent to @code{popd +0}.
+@code{dirs}; that is, @code{popd} is equivalent to @code{popd +0}.
+
@table @code
+@item -n
+Suppresses the normal change of directory when removing directories
+from the stack, so that only the stack is manipulated.
@item +@var{N}
Removes the @var{N}th directory (counting from the left of the
list printed by @code{dirs}), starting with zero.
@item -@var{N}
Removes the @var{N}th directory (counting from the right of the
list printed by @code{dirs}), starting with zero.
-@item -n
-Suppresses the normal change of directory when removing directories
-from the stack, so that only the stack is manipulated.
@end table
@btindex pushd
@item pushd
@example
-pushd [-n] [@var{+N} | @var{-N} | @var{dir} ]
+pushd [-n] [@var{+N} | @var{-N} | @var{dir}]
@end example
Save the current directory on the top of the directory stack
list printed by @code{dirs}, starting with zero) to the top of
the list by rotating the stack.
@item @var{dir}
-Makes the current working directory be the top of the stack, and then
-executes the equivalent of `@code{cd} @var{dir}'.
-@code{cd}s to @var{dir}.
+Makes the current working directory be the top of the stack, making
+it the new current directory as if it had been supplied as an argument
+to the @code{cd} builtin.
@end table
-
@end table
-@node Printing a Prompt
+@node Controlling the Prompt
@section Controlling the Prompt
@cindex prompting
value is executed just as if it had been typed on the command line.
In addition, the following table describes the special characters which
-can appear in the prompt variables:
+can appear in the prompt variables @env{PS1} to @env{PS4}:
@table @code
@item \a
Tilde expansion is only performed on assignments preceding a command
name, rather than on all assignment statements on the line.
+@item
+The @code{command} builtin does not prevent builtins that take assignment
+statements as arguments from expanding them as assignment statements;
+when not in POSIX mode, assignment builtins lose their assignment
+statement expansion properties when preceded by @code{command}.
+
@item
The default history file is @file{~/.sh_history} (this is the
default value of @env{$HISTFILE}).
may not start with a digit. Declaring a function with an invalid name
causes a fatal syntax error in non-interactive shells.
+@item
+Function names may not be the same as one of the @sc{posix} special
+builtins.
+
@item
@sc{posix} special builtins are found before shell functions
during command lookup.
redirection errors, variable assignment errors for assignments preceding
the command name, and so on.
-@item
-If @env{CDPATH} is set, the @code{cd} builtin will not implicitly
-append the current directory to it. This means that @code{cd} will
-fail if no valid directory name can be constructed from
-any of the entries in @env{$CDPATH}, even if the a directory with
-the same name as the name given as an argument to @code{cd} exists
-in the current directory.
-
@item
A non-interactive shell exits with an error status if a variable
assignment error occurs when no command name follows the assignment
A variable assignment error occurs, for example, when trying to assign
a value to a readonly variable.
+@item
+A non-interactive shell exists with an error status if a variable
+assignment error occurs in an assignment statement preceding a special
+builtin, but not with any other simple command.
+
@item
A non-interactive shell exits with an error status if the iteration
variable in a @code{for} statement or the selection variable in a
@item
Process substitution is not available.
+@item
+While variable indirection is available, it may not be applied to the
+@samp{#} and @samp{?} special parameters.
+
@item
Assignment statements preceding @sc{posix} special builtins
persist in the shell environment after the builtin completes.
does not refer to an existing directory, @code{cd} will fail instead of
falling back to @var{physical} mode.
-@item
-When the @code{pwd} builtin is supplied the @option{-P} option, it resets
-@code{$PWD} to a pathname containing no symlinks.
-
@item
The @code{pwd} builtin verifies that the value it prints is the same as the
current directory, even if it is not asked to check the file system with the
A job may also be referred to
using a prefix of the name used to start it, or using a substring
that appears in its command line. For example, @samp{%ce} refers
-to a stopped @code{ce} job. Using @samp{%?ce}, on the
+to a stopped @code{ce} job. Using @samp{%?ce}, on the
other hand, refers to any job containing the string @samp{ce} in
its command line. If the prefix or substring matches more than one job,
Bash reports an error.
@example
bg [@var{jobspec} @dots{}]
@end example
+
Resume each suspended job @var{jobspec} in the background, as if it
had been started with @samp{&}.
If @var{jobspec} is not supplied, the current job is used.
@example
fg [@var{jobspec}]
@end example
+
Resume the job @var{jobspec} in the foreground and make it the current job.
If @var{jobspec} is not supplied, the current job is used.
The return status is that of the command placed into the foreground,
List only the process @sc{id} of the job's process group leader.
@item -r
-Restrict output to running jobs.
+Display only running jobs.
@item -s
-Restrict output to stopped jobs.
+Display only stopped jobs.
@end table
If @var{jobspec} is given,
kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec} or @var{pid}
kill -l [@var{exit_status}]
@end example
+
Send a signal specified by @var{sigspec} or @var{signum} to the process
named by job specification @var{jobspec} or process @sc{id} @var{pid}.
@var{sigspec} is either a case-insensitive signal name such as
@item wait
@btindex wait
@example
-wait [@var{jobspec} or @var{pid} ...]
+wait [@var{jobspec} or @var{pid} @dots{}]
@end example
+
Wait until the child process specified by each process @sc{id} @var{pid}
or job specification @var{jobspec} exits and return the exit status of the
last command waited for.
@example
disown [-ar] [-h] [@var{jobspec} @dots{}]
@end example
-Without options, each @var{jobspec} is removed from the table of
+
+Without options, remove each @var{jobspec} from the table of
active jobs.
If the @option{-h} option is given, the job is not removed from the table,
but is marked so that @code{SIGHUP} is not sent to the job if the shell
@example
suspend [-f]
@end example
+
Suspend the execution of this shell until it receives a
@code{SIGCONT} signal.
A login shell cannot be suspended; the @option{-f}
option can be used to override this and force the suspension.
-
@end table
When job control is not active, the @code{kill} and @code{wait}
@item --enable-prompt-string-decoding
Turn on the interpretation of a number of backslash-escaped characters
in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt
-strings. See @ref{Printing a Prompt}, for a complete list of prompt
+strings. See @ref{Controlling the Prompt}, for a complete list of prompt
string escape sequences.
@item --enable-readline
@ref{The Restricted Shell}, for a description of restricted mode.
@item --enable-select
-Include the @code{select} builtin, which allows the generation of simple
-menus (@pxref{Conditional Constructs}).
+Include the @code{select} compound command, which allows the generation of
+simple menus (@pxref{Conditional Constructs}).
@item --enable-separate-helpfiles
Use external files for the documentation displayed by the @code{help} builtin
the Single Unix Specification, version 3.
@xref{Bash Builtins}, for a description of the escape sequences that
@code{echo} recognizes.
-
@end table
The file @file{config-top.h} contains C Preprocessor
builtin (@pxref{The Set Builtin}).
@item
-The @samp{-x} (@code{xtrace}) option displays commands other than
+The @samp{-x} (@option{xtrace}) option displays commands other than
simple commands when performing an execution trace
(@pxref{The Set Builtin}).
@item
Bash interprets special backslash-escaped characters in the prompt
-strings when interactive (@pxref{Printing a Prompt}).
+strings when interactive (@pxref{Controlling the Prompt}).
@item
The Bash restricted mode is more useful (@pxref{The Restricted Shell});