This is bashref.info, produced by makeinfo version 4.13 from
-/Users/chet/src/bash/src/doc/bashref.texi.
+/usr/homes/chet/src/bash/src/doc/bashref.texi.
This text is a brief description of the features that are present in
-the Bash shell (version 4.2, 28 December 2010).
+the Bash shell (version 4.3, 2 February 2014).
- This is Edition 4.2, last updated 28 December 2010, of `The GNU Bash
-Reference Manual', for `Bash', Version 4.2.
+ This is Edition 4.3, last updated 2 February 2014, of `The GNU Bash
+Reference Manual', for `Bash', Version 4.3.
- Copyright (C) 1988-2010 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.
+ Copyright (C) 1988-2014 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
- Foundation; with no Invariant Sections, with the Front-Cover texts
- being "A GNU Manual", and with the Back-Cover Texts as in (a)
- below. A copy of the license is included in the section entitled
- "GNU Free Documentation License".
-
- (a) The FSF's Back-Cover Text is: You are free to copy and modify
- this GNU manual. Buying copies from GNU Press supports the FSF in
- developing GNU and promoting software freedom."
-
+ Foundation; with no Invariant Sections, no Front-Cover Texts, and
+ no Back-Cover Texts. A copy of the license is included in the
+ section entitled "GNU Free Documentation License".
INFO-DIR-SECTION Basics
START-INFO-DIR-ENTRY
*************
This text is a brief description of the features that are present in
-the Bash shell (version 4.2, 28 December 2010).
+the Bash shell (version 4.3, 2 February 2014). The Bash home page is
+`http://www.gnu.org/software/bash/'.
- This is Edition 4.2, last updated 28 December 2010, of `The GNU Bash
-Reference Manual', for `Bash', Version 4.2.
+ This is Edition 4.3, last updated 2 February 2014, of `The GNU Bash
+Reference Manual', for `Bash', Version 4.3.
Bash contains features that appear in other popular shells, and some
features that only appear in Bash. Some of the shells that Bash has
borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell
-(`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The
-following menu breaks the features up into categories based upon which
-one of these other shells inspired the feature.
+(`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The
+following menu breaks the features up into categories, noting which
+features were inspired by other shells and which are specific to Bash.
This manual is meant as a brief introduction to features found in
Bash. The Bash manual page should be used as the definitive reference
Shells also provide a small set of built-in commands ("builtins")
implementing functionality impossible or inconvenient to obtain via
-separate utilities. For example, `cd', `break', `continue', and
-`exec') cannot be implemented outside of the shell because they
-directly manipulate the shell itself. The `history', `getopts',
-`kill', or `pwd' builtins, among others, could be implemented in
-separate utilities, but they are more convenient to use as builtin
-commands. All of the shell builtins are described in subsequent
-sections.
+separate utilities. For example, `cd', `break', `continue', and `exec'
+cannot be implemented outside of the shell because they directly
+manipulate the shell itself. The `history', `getopts', `kill', or `pwd'
+builtins, among others, could be implemented in separate utilities, but
+they are more convenient to use as builtin commands. All of the shell
+builtins are described in subsequent sections.
While executing commands is essential, most of the power (and
complexity) of shells is due to their embedded programming languages.
control operators `|' or `|&'.
The format for a pipeline is
- [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...]
+ [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
The output of each command in the pipeline is connected via a pipe to
the input of the next command. That is, each command reads the
previous command's output. This connection is performed before any
redirections specified by the command.
- If `|&' is used, the standard error of COMMAND1 is connected to
-COMMAND2's standard input through the pipe; it is shorthand for `2>&1
-|'. This implicit redirection of the standard error is performed after
-any redirections specified by the command.
+ If `|&' is used, COMMAND1's standard error, in addition to its
+standard output, is connected to COMMAND2's standard input through the
+pipe; it is shorthand for `2>&1 |'. This implicit redirection of the
+standard error to the standard output is performed after any
+redirections specified by the command.
The reserved word `time' causes timing statistics to be printed for
the pipeline once it finishes. The statistics currently consist of
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.
`until'
The syntax of the `until' command is:
+
until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
+
Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
status which is not zero. The return status is the exit status of
the last command executed in CONSEQUENT-COMMANDS, or zero if none
`while'
The syntax of the `while' command is:
+
while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
The syntax of the `for' command is:
for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
+
Expand WORDS, and execute COMMANDS once for each member in the
resultant list, with NAME bound to the current member. If `in
WORDS' is not present, the `for' command executes the COMMANDS
An alternate form of the `for' command is also supported:
for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
+
First, the arithmetic expression EXPR1 is evaluated according to
the rules described below (*note Shell Arithmetic::). The
arithmetic expression EXPR2 is then evaluated repeatedly until it
command in COMMANDS that is executed, or false if any of the
expressions is invalid.
-
The `break' and `continue' builtins (*note Bourne Shell Builtins::)
may be used to control loop execution.
`case'
The syntax of the `case' command is:
- `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
+ case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac
`case' will selectively execute the COMMAND-LIST corresponding to
the first PATTERN that matches WORD. If the shell option
There may be an arbitrary number of `case' clauses, each terminated
by a `;;', `;&', or `;;&'. The first pattern that matches
- determines the command-list that is executed.
+ determines the command-list that is executed. It's a common idiom
+ to use `*' as the final pattern to define the default case, since
+ that pattern will always match.
Here is an example using `case' in a script that could be used to
describe one interesting feature of an animal:
When the `==' and `!=' operators are used, the string to the right
of the operator is considered a pattern and matched according to
- the rules described below in *note Pattern Matching::. If the
- shell option `nocasematch' (see the description of `shopt' in
- *note The Shopt Builtin::) is enabled, the match is performed
- without regard to the case of alphabetic characters. The return
- value is 0 if the string matches (`==') or does not match
- (`!=')the pattern, and 1 otherwise. Any part of the pattern may
- be quoted to force it to be matched as a string.
+ the rules described below in *note Pattern Matching::, as if the
+ `extglob' shell option were enabled. The `=' operator is
+ identical to `=='. If the shell option `nocasematch' (see the
+ description of `shopt' in *note The Shopt Builtin::) is enabled,
+ the match is performed without regard to the case of alphabetic
+ characters. The return value is 0 if the string matches (`==') or
+ does not match (`!=')the pattern, and 1 otherwise. Any part of
+ the pattern may be quoted to force the quoted portion to be
+ matched as a string.
An additional binary operator, `=~', is available, with the same
precedence as `==' and `!='. When it is used, the string to the
(see the description of `shopt' in *note 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. Substrings matched by
- parenthesized subexpressions within the regular expression are
- saved in the array variable `BASH_REMATCH'. The element of
- `BASH_REMATCH' with index 0 is the portion of the string matching
- the entire regular expression. The element of `BASH_REMATCH' with
- index N is the portion of the string matching the Nth
- parenthesized subexpression.
+ 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
+ `BASH_REMATCH'. The element of `BASH_REMATCH' with index 0 is the
+ portion of the string matching the entire regular expression. The
+ element of `BASH_REMATCH' with index N is the portion of the
+ string matching the Nth parenthesized subexpression.
+
+ For example, the following will match a line (stored in the shell
+ variable 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 `a', then a `b':
+ [[ $line =~ [[:space:]]*(a)?b ]]
+
+ That means values like `aab' and ` aaaaaab' will match, as will a
+ line containing a `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. It is sometimes difficult to specify a
+ regular expression literally without using quotes, or to keep
+ track of the quoting used by regular expressions while paying
+ attention to the shell's quote removal. Using a shell variable to
+ store the pattern decreases these problems. For example, the
+ following is equivalent to the above:
+ pattern='[[:space:]]*(a)?b'
+ [[ $line =~ $pattern ]]
+
+ 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. This means that in the pattern `xxx.txt', the `.'
+ matches any character in the string (its usual regular expression
+ meaning), but in the pattern `"xxx.txt"' it can only match a
+ literal `.'. 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 _not_
+ equivalent:
+ pattern='\.'
+
+ [[ . =~ $pattern ]]
+ [[ . =~ \. ]]
+
+ [[ . =~ "$pattern" ]]
+ [[ . =~ '\.' ]]
+
+ 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 `.', so the literal `.' matches.
+ If the string in the first examples were anything other than `.',
+ say `a', the pattern would not match, because the quoted `.' 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:
`EXPRESSION1 || EXPRESSION2'
True if either EXPRESSION1 or EXPRESSION2 is true.
+
The `&&' and `||' operators do not evaluate EXPRESSION2 if the
value of EXPRESSION1 is sufficient to determine the return value
of the entire conditional expression.
-
\1f
File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
established between the executing shell and the coprocess.
The format for a coprocess is:
- `coproc' [NAME] COMMAND [REDIRECTIONS]
+ coproc [NAME] COMMAND [REDIRECTIONS]
This creates a coprocess named NAME. If NAME is not supplied, the
default name is COPROC. NAME must not be supplied if COMMAND is a
simple command (*note 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
-(*note Arrays::) named NAME in the context of the executing shell. The
-standard output of COMMAND is connected via a pipe to a file descriptor
-in the executing shell, and that file descriptor is assigned to NAME[0].
-The standard input of COMMAND is connected via a pipe to a file
+ When the coprocess is executed, the shell creates an array variable
+(*note Arrays::) named `NAME' in the context of the executing shell.
+The standard output of COMMAND is connected via a pipe to a file
descriptor in the executing shell, and that file descriptor is assigned
-to NAME[1]. This pipe is established before any redirections specified
-by the command (*note Redirections::). The file descriptors can be
-utilized as arguments to shell commands and redirections using standard
-word expansions.
+to `NAME'[0]. The standard input of COMMAND is connected via a pipe to
+a file descriptor in the executing shell, and that file descriptor is
+assigned to `NAME'[1]. This pipe is established before any
+redirections specified by the command (*note Redirections::). The file
+descriptors can be utilized as arguments to shell commands and
+redirections using standard word expansions. The file descriptors are
+not available in subshells.
The process ID of the shell spawned to execute the coprocess is
-available as the value of the variable NAME_PID. The `wait' builtin
+available as the value of the variable `NAME'_PID. The `wait' builtin
command may be used to wait for the coprocess to terminate.
- The return status of a coprocess is the exit status of COMMAND.
+ Since the coprocess is created as an asynchronous command, the
+`coproc' command always returns success. The return status of a
+coprocess is the exit status of COMMAND.
\1f
File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
3.2.6 GNU Parallel
------------------
-GNU Parallel, as its name suggests, can be used to build and run
+There are ways to run commands in parallel that are not built into Bash.
+GNU Parallel is a tool to do just that.
+
+ GNU Parallel, as its name suggests, can be used to build and run
commands in parallel. You may run the same command with different
arguments, whether they are filenames, usernames, hostnames, or lines
-read from files.
+read from files. GNU Parallel provides shorthand references to many of
+the most common operations (input lines, various portions of the input
+line, different ways to specify the input source, and so on). Parallel
+can replace `xargs' or feed commands from its input sources to several
+different instances of Bash.
For a complete description, refer to the GNU Parallel documentation.
A few examples should provide a brief introduction to its use.
- For example, it is easy to prefix each line in a text file with a
-specified string:
- cat file | parallel -k echo prefix_string
- The `-k' option is required to preserve the lines' order.
-
- Similarly, you can append a specified string to each line in a text
-file:
- cat file | parallel -k echo {} append_string
+ For example, it is easy to replace `xargs' to gzip all html files in
+the current directory and its subdirectories:
+ find . -type f -name '*.html' -print | parallel gzip
+ If you need to protect special characters such as newlines in file
+names, use find's `-print0' option and parallel's `-0' option.
You can use Parallel to move files from the current directory when
the number of files is too large to process with one `mv' invocation:
ls | parallel mv {} destdir
As you can see, the {} is replaced with each line read from standard
-input. This will run as many `mv' commands as there are files in the
-current directory. You can emulate a parallel `xargs' by adding the
-`-X' option:
- ls | parallel -X mv {} destdir
+input. While using `ls' will work in most instances, it is not
+sufficient to deal with all filenames. If you need to accommodate
+special characters in filenames, you can use
+
+ find . -depth 1 \! -name '.*' -print0 | parallel -0 mv {} destdir
+
+as alluded to above.
+
+ This will run as many `mv' commands as there are files in the current
+directory. You can emulate a parallel `xargs' by adding the `-X'
+option:
+ find . -depth 1 \! -name '.*' -print0 | parallel -0 -X mv {} destdir
GNU Parallel can replace certain common idioms that operate on lines
-read from a file (in this case, filenames):
- for x in $(cat list); do
- do-something1 $x config-$x
- do-something2 < $x
- done | process-output
+read from a file (in this case, filenames listed one per line):
+ while IFS= read -r x; do
+ do-something1 "$x" "config-$x"
+ do-something2 < "$x"
+ done < file | process-output
with a more compact syntax reminiscent of lambdas:
cat list | parallel "do-something1 {} config-{} ; do-something2 < {}" | process-output
renaming:
ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
This will recompress all files in the current directory with names
-ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
+ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
+(We use `ls' for brevity here; using `find' as above is more robust in
+the face of filenames containing unexpected characters.) Parallel can
+take arguments from the command line; the above can also be written as
+
+ parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
If a command generates output, you may want to preserve the input
order in the output. For instance, the following command
{ echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel traceroute
- will display as output the traceroute invocation that finishes
-first. Using the `-k' option, as we saw above
+ will display as output the traceroute invocation that finishes first.
+Adding the `-k' option
{ echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel -k traceroute
will ensure that the output of `traceroute foss.org.my' is displayed
first.
+ Finally, Parallel can be used to run a sequence of shell commands in
+parallel, similar to `cat file | bash'. It is not uncommon to take a
+list of filenames, create a series of shell commands to operate on
+them, and feed that list of commnds to a shell. Parallel can speed
+this up. Assuming that `file' contains a list of shell commands, one
+per line,
+
+ parallel -j 10 < file
+
+will evaluate the commands using the shell (since no explicit command is
+supplied as an argument), in blocks of ten shell jobs at a time.
+
\1f
File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
Functions are declared using this syntax:
NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
- or
- `function' NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
+ or
+
+ function NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
This defines a shell function named NAME. The reserved word
`function' is optional. If the `function' reserved word is supplied,
command COMPOUND-COMMAND (*note Compound Commands::). That command is
usually a LIST enclosed between { and }, but may be any compound
command listed above. COMPOUND-COMMAND is executed whenever NAME is
-specified as the name of a command. Any redirections (*note
+specified as the name of a command. When the shell is in POSIX mode
+(*note Bash POSIX Mode::), NAME may not be the same as one of the
+special builtins (*note Special Builtins::). Any redirections (*note
Redirections::) associated with the shell function are performed when
the function is executed.
commands it invokes.
Function names and definitions may be listed with the `-f' option to
-the `declare' or `typeset' builtin commands (*note Bash Builtins::).
-The `-F' option to `declare' or `typeset' will list the function names
-only (and optionally the source file and line number, if the `extdebug'
+the `declare' (`typeset') builtin command (*note Bash Builtins::). The
+`-F' option to `declare' or `typeset' will list the function names only
+(and optionally the source file and line number, if the `extdebug'
shell option is enabled). Functions may be exported so that subshells
automatically have them defined with the `-f' option to the `export'
builtin (*note Bourne Shell Builtins::). Note that shell functions and
performed, with the exception of `"$@"' as explained below. Filename
expansion is not performed. Assignment statements may also appear as
arguments to the `alias', `declare', `typeset', `export', `readonly',
-and `local' builtin commands.
+and `local' builtin commands. When in POSIX mode (*note Bash POSIX
+Mode::), these builtins may appear in a command after one or more
+instances of the `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 (*note Arrays::), the `+=' operator can
string-valued variable, VALUE is expanded and appended to the
variable's value.
+ A variable can be assigned the NAMEREF attribute using the `-n'
+option to the \fBdeclare\fP or \fBlocal\fP builtin commands (*note Bash
+Builtins::) to create a NAMEREF, or a reference to another variable.
+This allows variables to be manipulated indirectly. Whenever the
+nameref variable is referenced or assigned to, the operation is
+actually performed on the variable specified by the nameref variable's
+value. A nameref is commonly used within shell functions to refer to a
+variable whose name is passed as an argument to the function. For
+instance, if a variable name is passed to a shell function as its first
+argument, running
+ declare -n ref=$1
+ inside the function creates a nameref variable REF whose value is
+the variable name passed as the first argument. References and
+assignments to REF are treated as references and assignments to the
+variable whose name was passed as `$1'.
+
+ If the control variable in a `for' loop has the nameref attribute,
+the list of words can be a list of shell variables, and a name reference
+will be established for each word in the list, in turn, when the loop is
+executed. Array variables cannot be given the `-n' attribute.
+However, nameref variables can reference array variables and subscripted
+array variables. Namerefs can be unset using the `-n' option to the
+`unset' builtin (*note Bourne Shell Builtins::). Otherwise, if `unset'
+is executed with the name of a nameref variable as an argument, the
+variable referenced by the nameref variable will be unset.
+
\1f
File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
only be referenced; assignment to them is not allowed.
`*'
- Expands to the positional parameters, starting from one. When the
- expansion occurs within double quotes, it expands to a single word
- with the value of each parameter separated by the first character
- of the `IFS' special variable. That is, `"$*"' is equivalent to
- `"$1C$2C..."', where C is the first character of the value of the
- `IFS' variable. If `IFS' is unset, the parameters are separated
- by spaces. If `IFS' is null, the parameters are joined without
- intervening separators.
+ ($*) Expands to the positional parameters, starting from one.
+ When the expansion is not within double quotes, each positional
+ parameter expands to a separate word. In contexts where it is
+ performed, those words are subject to further word splitting and
+ pathname expansion. When the expansion occurs within double
+ quotes, it expands to a single word with the value of each
+ parameter separated by the first character of the `IFS' special
+ variable. That is, `"$*"' is equivalent to `"$1C$2C..."', where C
+ is the first character of the value of the `IFS' variable. If
+ `IFS' is unset, the parameters are separated by spaces. If `IFS'
+ is null, the parameters are joined without intervening separators.
`@'
- Expands to the positional parameters, starting from one. When the
- expansion occurs within double quotes, each parameter expands to a
- separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
- 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. When there are no
- positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
- they are removed).
+ ($@) Expands to the positional parameters, starting from one.
+ When the expansion occurs within double quotes, each parameter
+ expands to a separate word. That is, `"$@"' is equivalent to
+ `"$1" "$2" ...'. 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. When
+ there are no positional parameters, `"$@"' and `$@' expand to
+ nothing (i.e., they are removed).
`#'
- Expands to the number of positional parameters in decimal.
+ ($#) Expands to the number of positional parameters in decimal.
`?'
- Expands to the exit status of the most recently executed foreground
- pipeline.
+ ($?) Expands to the exit status of the most recently executed
+ foreground pipeline.
`-'
- (A hyphen.) Expands to the current option flags as specified upon
- invocation, by the `set' builtin command, or those set by the
+ ($-, a hyphen.) Expands to the current option flags as specified
+ upon invocation, by the `set' builtin command, or those set by the
shell itself (such as the `-i' option).
`$'
- Expands to the process ID of the shell. In a `()' subshell, it
- expands to the process ID of the invoking shell, not the subshell.
+ ($$) Expands to the process ID of the shell. In a `()' subshell,
+ it expands to the process ID of the invoking shell, not the
+ subshell.
`!'
- Expands to the process ID of the most recently executed background
- (asynchronous) command.
+ ($!) Expands to the process ID of the job most recently placed
+ into the background, whether executed as an asynchronous command
+ or using the `bg' builtin (*note Job Control Builtins::).
`0'
- Expands to the name of the shell or shell script. This is set at
- shell initialization. If Bash is invoked with a file of commands
- (*note Shell Scripts::), `$0' is set to the name of that file. If
- Bash is started with the `-c' option (*note Invoking Bash::), then
- `$0' is set to the first argument after the string to be executed,
- if one is present. Otherwise, it is set to the filename used to
- invoke Bash, as given by argument zero.
+ ($0) Expands to the name of the shell or shell script. This is
+ set at shell initialization. If Bash is invoked with a file of
+ commands (*note Shell Scripts::), `$0' is set to the name of that
+ file. If Bash is started with the `-c' option (*note Invoking
+ Bash::), then `$0' is set to the first argument after the string
+ to be executed, if one is present. Otherwise, it is set to the
+ filename used to invoke Bash, as given by argument zero.
`_'
- (An underscore.) At shell startup, set to the absolute pathname
- used to invoke the shell or shell script being executed as passed
- in the environment or argument list. Subsequently, expands to the
- last argument to the previous command, after expansion. Also set
- to the full pathname used to invoke each command executed and
- placed in the environment exported to that command. When checking
- mail, this parameter holds the name of the mail file.
+ ($_, an underscore.) At shell startup, set to the absolute
+ pathname used to invoke the shell or shell script being executed
+ as passed in the environment or argument list. Subsequently,
+ expands to the last argument to the previous command, after
+ expansion. Also set to the full pathname used to invoke each
+ command executed and placed in the environment exported to that
+ command. When checking mail, this parameter holds the name of the
+ mail file.
\1f
File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
Expansion is performed on the command line after it has been split into
`token's. There are seven kinds of expansion performed:
+
* brace expansion
* tilde expansion
* Quote Removal:: How and when quote characters are removed from
words.
- The order of expansions is: brace expansion, tilde expansion,
-parameter, variable, and arithmetic expansion and command substitution
-(done in a left-to-right fashion), word splitting, and filename
-expansion.
+ The order of expansions is: brace expansion; tilde expansion,
+parameter and variable expansion, arithmetic expansion, and command
+substitution (done in a left-to-right fashion); word splitting; and
+filename expansion.
On systems that can support it, there is an additional expansion
available: PROCESS SUBSTITUTION. This is performed at the same time as
-parameter, variable, and arithmetic expansion and command substitution.
+tilde, parameter, variable, and arithmetic expansion and command
+substitution.
Only brace expansion, word splitting, and filename expansion can
change the number of words of the expansion; other expansions expand a
Brace expansion is a mechanism by which arbitrary strings may be
generated. This mechanism is similar to FILENAME EXPANSION (*note
-Filename Expansion::), but the file names generated need not exist.
+Filename Expansion::), but the filenames generated need not exist.
Patterns to be brace expanded take the form of an optional PREAMBLE,
-followed by either a series of comma-separated strings or a seqeunce
+followed by either a series of comma-separated strings or a sequence
expression between a pair of braces, followed by an optional POSTSCRIPT.
The preamble is prefixed to each string contained within the braces, and
the postscript is then appended to each resulting string, expanding left
When either X or Y begins with a zero, the shell attempts to force all
generated terms to contain the same number of digits, zero-padding
where necessary. When characters are supplied, the expression expands
-to each character lexicographically between X and Y, inclusive. Note
-that both X and Y must be of the same type. When the increment is
-supplied, it is used as the difference between each term. The default
-increment is 1 or -1 as appropriate.
+to each character lexicographically between X and Y, inclusive, using
+the default C locale. Note that both X and Y must be of the same type.
+When the increment is supplied, it is used as the difference between
+each term. The default increment is 1 or -1 as appropriate.
Brace expansion is performed before any other expansions, and any
characters special to other expansions are preserved in the result. It
Each variable assignment is checked for unquoted tilde-prefixes
immediately following a `:' or the first `='. In these cases, tilde
-expansion is also performed. Consequently, one may use file names with
+expansion is also performed. Consequently, one may use filenames with
tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
shell assigns the expanded value.
`~-N'
The string that would be displayed by `dirs -N'
-
\1f
File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
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 exceptions to this are the
-expansions of ${!PREFIX
-} and ${!NAME[@]} described below. The exclamation point must
-immediately follow the left brace in order to introduce indirection.
+PARAMETER is substituted. The PARAMETER is a shell parameter as
+described above (*note Shell Parameters::) or an array reference (*note
+Arrays::). 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 (!), it
+introduces a level of variable indirection. 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 exceptions to this are the
+expansions of ${!PREFIX*} and ${!NAME[@]} described below. The
+exclamation point must immediately follow the left brace in order to
+introduce indirection.
In each of the cases below, WORD is subject to tilde expansion,
parameter expansion, command substitution, and arithmetic expansion.
When not performing substring expansion, using the form described
-below, 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
+below (e.g., `:-'), 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
PARAMETER's existence and that its value is not null; if the colon is
omitted, the operator tests only for existence.
`${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.
+ This is referred to as Substring Expansion. It expands to up to
+ LENGTH characters of the value of PARAMETER starting at the
+ character specified by OFFSET. If PARAMETER is `@', an indexed
+ array subscripted by `@' or `*', or an associative array name, the
+ results differ as described below. If LENGTH is omitted, it
+ expands to the substring of the value of PARAMETER starting at the
+ character specified by OFFSET and extending to the end of the
+ value. LENGTH and OFFSET are arithmetic expressions (*note Shell
+ Arithmetic::).
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 LENGTH
- evaluates to a number less than zero, and PARAMETER is not `@' and
- not an indexed or associative array, it is interpreted as an
- offset from the end of the value of PARAMETER rather than a number
- of characters, and the expansion is the characters between the two
- offsets. If PARAMETER is `@', the result is LENGTH positional
- parameters beginning at OFFSET. If PARAMETER is an indexed array
- name subscripted by `@' or `*', the result is the LENGTH members
- of the array beginning with `${PARAMETER[OFFSET]}'. A negative
- OFFSET is taken relative to one greater than the maximum index of
- the specified array. Substring expansion applied to an
- associative array produces undefined results.
-
- Note that a negative offset must be separated from the colon by at
- least one space to avoid being confused with the `:-' expansion.
+ as an offset in characters from the end of the value of PARAMETER.
+ If LENGTH evaluates to a number less than zero, it is interpreted
+ as an offset in characters from the end of the value of PARAMETER
+ rather than a number of characters, and the expansion is the
+ characters between OFFSET and that result. Note that a negative
+ offset must be separated from the colon by at least one space to
+ avoid being confused with the `:-' expansion.
+
+ Here are some examples illustrating substring expansion on
+ parameters and subscripted arrays:
+
+ $ string=01234567890abcdefgh
+ $ echo ${string:7}
+ 7890abcdefgh
+ $ echo ${string:7:0}
+
+ $ echo ${string:7:2}
+ 78
+ $ echo ${string:7:-2}
+ 7890abcdef
+ $ echo ${string: -7}
+ bcdefgh
+ $ echo ${string: -7:0}
+
+ $ echo ${string: -7:2}
+ bc
+ $ echo ${string: -7:-2}
+ bcdef
+ $ set -- 01234567890abcdefgh
+ $ echo ${1:7}
+ 7890abcdefgh
+ $ echo ${1:7:0}
+
+ $ echo ${1:7:2}
+ 78
+ $ echo ${1:7:-2}
+ 7890abcdef
+ $ echo ${1: -7}
+ bcdefgh
+ $ echo ${1: -7:0}
+
+ $ echo ${1: -7:2}
+ bc
+ $ echo ${1: -7:-2}
+ bcdef
+ $ array[0]=01234567890abcdefgh
+ $ echo ${array[0]:7}
+ 7890abcdefgh
+ $ echo ${array[0]:7:0}
+
+ $ echo ${array[0]:7:2}
+ 78
+ $ echo ${array[0]:7:-2}
+ 7890abcdef
+ $ echo ${array[0]: -7}
+ bcdefgh
+ $ echo ${array[0]: -7:0}
+
+ $ echo ${array[0]: -7:2}
+ bc
+ $ echo ${array[0]: -7:-2}
+ bcdef
+
+ If PARAMETER is `@', the result is LENGTH positional parameters
+ beginning at OFFSET. A negative OFFSET is taken relative to one
+ greater than the greatest positional parameter, so an offset of -1
+ evaluates to the last positional parameter. It is an expansion
+ error if LENGTH evaluates to a number less than zero.
+
+ The following examples illustrate substring expansion using
+ positional parameters:
+
+ $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
+ $ echo ${@:7}
+ 7 8 9 0 a b c d e f g h
+ $ echo ${@:7:0}
+
+ $ echo ${@:7:2}
+ 7 8
+ $ echo ${@:7:-2}
+ bash: -2: substring expression < 0
+ $ echo ${@: -7:2}
+ b c
+ $ echo ${@:0}
+ ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
+ $ echo ${@:0:2}
+ ./bash 1
+ $ echo ${@: -7:0}
+
+ If PARAMETER is an indexed array name subscripted by `@' or `*',
+ the result is the LENGTH members of the array beginning with
+ `${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to
+ one greater than the maximum index of the specified array. It is
+ an expansion error if LENGTH evaluates to a number less than zero.
+
+ These examples show how you can use substring expansion with
+ indexed arrays:
+
+ $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
+ $ echo ${array[@]:7}
+ 7 8 9 0 a b c d e f g h
+ $ echo ${array[@]:7:2}
+ 7 8
+ $ echo ${array[@]: -7:2}
+ b c
+ $ echo ${array[@]: -7:-2}
+ bash: -2: substring expression < 0
+ $ echo ${array[@]:0}
+ 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
+ $ echo ${array[@]:0:2}
+ 0 1
+ $ echo ${array[@]: -7:0}
+
+ Substring expansion applied to an associative array produces
+ undefined results.
+
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1 by default. If
OFFSET is 0, and the positional parameters are used, `$@' 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.
+ number of elements in the array. If PARAMETER is an indexed array
+ name subscripted by a negative number, that number is interpreted
+ as relative to one greater than the maximum index of PARAMETER, so
+ negative indices count back from the end of the array, and an
+ index of -1 references the last element.
`${PARAMETER#WORD}'
`${PARAMETER##WORD}'
`${PARAMETER,,PATTERN}'
This expansion modifies the case of alphabetic characters in
PARAMETER. The PATTERN is expanded to produce a pattern just as in
- filename expansion. The `^' operator converts lowercase letters
- matching PATTERN to uppercase; the `,' operator converts matching
- uppercase letters to lowercase. The `^^' and `,,' expansions
- convert each matched character in the expanded value; the `^' and
- `,' expansions match and convert only the first character in the
- expanded value. If PATTERN is omitted, it is treated like a `?',
- which matches every character. If PARAMETER is `@' or `*', the
- case modification 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
- case modification operation is applied to each member of the array
- in turn, and the expansion is the resultant list.
-
+ filename expansion. Each character in the expanded value of
+ PARAMETER is tested against PATTERN, and, if it matches the
+ pattern, its case is converted. The pattern should not attempt to
+ match more than one character. The `^' operator converts
+ lowercase letters matching PATTERN to uppercase; the `,' operator
+ converts matching uppercase letters to lowercase. The `^^' and
+ `,,' expansions convert each matched character in the expanded
+ value; the `^' and `,' expansions match and convert only the first
+ character in the expanded value. If PATTERN is omitted, it is
+ treated like a `?', which matches every character. If PARAMETER
+ is `@' or `*', the case modification 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 case modification operation is applied to each member of
+ the array in turn, and the expansion is the resultant list.
\1f
File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
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 expansions may be nested.
+tokens in the expression undergo parameter and variable expansion,
+command substitution, and quote removal. The result is treated as the
+arithmetic expression to be evaluated. Arithmetic expansions may be
+nested.
The evaluation is performed according to the rules listed below
(*note Shell Arithmetic::). If the expression is invalid, Bash prints
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 sequences of ` <space>', `<tab>', and `<newline>' at the
-beginning and end of the results of the previous expansions are
-ignored, and any sequence of `IFS' characters not at the beginning or
-end 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.
+the results of the other expansions into words using these characters
+as field terminators. If `IFS' is unset, or its value is exactly
+`<space><tab><newline>', the default, then sequences of ` <space>',
+`<tab>', and `<newline>' at the beginning and end of the results of the
+previous expansions are ignored, and any sequence of `IFS' characters
+not at the beginning or end 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
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 `failglob' shell option is set, and no matches are
-found, an error message is printed and the command is not executed. If
-the shell option `nocaseglob' is enabled, the match is performed
-without regard to the case of alphabetic characters.
+a PATTERN, and replaced with an alphabetically sorted list of filenames
+matching the pattern (*note Pattern Matching::). If no matching
+filenames 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 `failglob' shell option
+is set, and no matches are found, an error message is printed and the
+command is not executed. 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 expansion, 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
+matching a filename, the slash character must always be matched
explicitly. In other cases, the `.' character is not treated specially.
See the description of `shopt' in *note The Shopt Builtin::, for a
`[...]'
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
+ that falls 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.
+ the current locale and the values of the `LC_COLLATE' and `LC_ALL'
+ shell variables, if set.
For example, in the default C locale, `[a-dx-z]' is equivalent to
`[abcdxyz]'. Many locales sort characters in dictionary order,
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'.
+ value `C', or enable the `globasciiranges' shell option.
Within `[' and `]', CHARACTER CLASSES can be specified using the
syntax `[:'CLASS`:]', where CLASS is one of the following classes
================
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.
+using a special notation interpreted by the shell. Redirection allows
+commands' file handles to be duplicated, opened, closed, made to refer
+to different files, and can change the files the command reads from and
+writes to. Redirection may also be used to modify file handles in 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.
Each redirection that may be preceded by a file descriptor number
may instead be preceded by a word of the form {VARNAME}. In this case,
`/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.
+ integer port number or service name, Bash attempts to open the
+ corresponding TCP 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.
-
+ integer port number or service name, Bash attempts to open the
+ corresponding UDP socket.
A failure to open or create a file causes the redirection to fail.
Of the two forms, the first is preferred. This is semantically
equivalent to
>WORD 2>&1
+ When using the second form, WORD may not expand to a number or `-'.
+If it does, other redirection operators apply (see Duplicating File
+Descriptors below) for compatibility reasons.
3.6.5 Appending Standard Output and Standard Error
--------------------------------------------------
&>>WORD
This is semantically equivalent to
>>WORD 2>&1
+ (see Duplicating File Descriptors below).
3.6.6 Here Documents
--------------------
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,
+ No parameter and variable 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,
the character sequence `\newline' is ignored, and `\' must be used to
quote the characters `\', `$', and ``'.
A variant of here documents, the format is:
<<< WORD
- The WORD is expanded and supplied to the command on its standard
-input.
+ The WORD undergoes brace expansion, tilde expansion, parameter and
+variable expansion, command substitution, arithmetic expansion, and
+quote removal. Pathname expansion and word splitting are not performed.
+The result is supplied as a single string to the command on its
+standard input.
3.6.8 Duplicating File Descriptors
----------------------------------
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
+redirection error occurs. If WORD evaluates to `-', file descriptor N
+is closed. As a special case, if N is omitted, and WORD does not
+expand to one or more digits or `-', the standard output and standard
error are redirected as described previously.
3.6.9 Moving File Descriptors
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
+the full pathname of the command and passed to that command in its
environment.
\1f
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 circumstances, the shell
+are also limited to this range. Under certain circumstances, the shell
will use special values to indicate specific failure modes.
For the shell's purposes, a command which exits with a zero exit
`: (a colon)'
: [ARGUMENTS]
+
Do nothing beyond expanding ARGUMENTS and performing redirections.
The return status is zero.
`. (a period)'
. FILENAME [ARGUMENTS]
+
Read and execute commands from the FILENAME argument in the
current shell context. If FILENAME does not contain a slash, the
`PATH' variable is used to find FILENAME. When Bash is not in
`break'
break [N]
+
Exit from a `for', `while', `until', or `select' loop. If N is
supplied, the Nth enclosing loop is exited. N must be greater
than or equal to 1. The return status is zero unless N is not
greater than or equal to 1.
`cd'
- cd [-L|[-P [-e]]] [DIRECTORY]
+ cd [-L|[-P [-e]] [-@] [DIRECTORY]
+
Change the current working directory to DIRECTORY. If DIRECTORY
- is not given, the value of the `HOME' shell variable is used. If
- the shell variable `CDPATH' exists, it is used as a search path.
+ is not supplied, the value of the `HOME' shell variable is used.
+ Any additional arguments following DIRECTORY are ignored. If the
+ shell variable `CDPATH' exists, it is used as a search path: each
+ directory name in `CDPATH' is searched for DIRECTORY, with
+ alternative directory names in `CDPATH' separated by a colon (`:').
If DIRECTORY begins with a slash, `CDPATH' is not used.
- The `-P' option means to not follow symbolic links; symbolic links
- are followed by default or with the `-L' option. If the `-e'
- option is supplied with `-P' and the current working directory
- cannot be successfully determined after a successful directory
- change, `cd' will return an unsuccessful status. If DIRECTORY is
- `-', it is equivalent to `$OLDPWD'.
+ The `-P' option means to not follow symbolic links: symbolic links
+ are resolved while `cd' is traversing DIRECTORY and before
+ processing an instance of `..' in DIRECTORY.
+
+ By default, or when the `-L' option is supplied, symbolic links in
+ DIRECTORY are resolved after `cd' processes an instance of `..' in
+ DIRECTORY.
+
+ If `..' appears in DIRECTORY, it is processed by removing the
+ immediately preceding pathname component, back to a slash or the
+ beginning of DIRECTORY.
+
+ If the `-e' option is supplied with `-P' and the current working
+ directory cannot be successfully determined after a successful
+ directory change, `cd' will return an unsuccessful status.
+
+ On systems that support it, the `-@' option presents the extended
+ attributes associated with a file as a directory.
+
+ If DIRECTORY is `-', it is converted to `$OLDPWD' before the
+ directory change is attempted.
If a non-empty directory name from `CDPATH' is used, or if `-' is
the first argument, and the directory change is successful, the
`continue'
continue [N]
+
Resume the next iteration of an enclosing `for', `while', `until',
or `select' loop. If N is supplied, the execution of the Nth
enclosing loop is resumed. N must be greater than or equal to 1.
`eval'
eval [ARGUMENTS]
+
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 `eval'. If there are no arguments or only
`exec'
exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
+
If COMMAND is supplied, it replaces the shell without creating a
new process. If the `-l' option is supplied, the shell places a
dash at the beginning of the zeroth argument passed to COMMAND.
This is what the `login' program does. The `-c' option causes
COMMAND to be executed with an empty environment. If `-a' is
supplied, the shell passes NAME as the zeroth argument to COMMAND.
- If no COMMAND is specified, redirections may be used to affect the
- current shell environment. If there are no redirection errors, the
- return status is zero; otherwise the return status is non-zero.
+ If COMMAND cannot be executed for some reason, a non-interactive
+ shell exits, unless the `execfail' shell option is enabled. In
+ that case, it returns failure. An interactive shell returns
+ failure if the file cannot be executed. If no 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.
`exit'
exit [N]
+
Exit the shell, returning a status of N to the shell's parent. If
N is omitted, the exit status is that of the last command executed.
Any trap on `EXIT' is executed before the shell terminates.
`export'
export [-fn] [-p] [NAME[=VALUE]]
+
Mark each NAME to be passed to child processes in the environment.
If the `-f' option is supplied, the NAMEs refer to shell
functions; otherwise the names refer to shell variables. The `-n'
option means to no longer mark each NAME for export. If no NAMES
- are supplied, or if the `-p' option is given, a list of exported
- names is displayed. The `-p' option displays output in a form
- that may be reused as input. If a variable name is followed by
- =VALUE, the value of the variable is set to VALUE.
+ are supplied, or if the `-p' option is given, a list of names of
+ all exported variables is displayed. The `-p' option displays
+ output in a form that may be reused as input. If a variable name
+ is followed by =VALUE, the value of the variable is set to VALUE.
The return status is zero unless an invalid option is supplied,
one of the names is not a valid shell variable name, or `-f' is
`getopts'
getopts OPTSTRING NAME [ARGS]
+
`getopts' is used by shell scripts to parse positional parameters.
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. The
+ argument, which should be separated from it by whitespace. The
colon (`:') and question mark (`?') may not be used as option
characters. Each time it is invoked, `getopts' places the next
option in the shell variable NAME, initializing NAME if it does
`getopts' can report errors in two ways. If the first character of
OPTSTRING is a colon, SILENT error reporting is used. In normal
- operation diagnostic messages are printed when invalid options or
+ operation, diagnostic messages are printed when invalid options or
missing option arguments are encountered. If the variable `OPTERR'
is set to 0, no error messages will be displayed, even if the first
character of `optstring' is not a colon.
`hash'
hash [-r] [-p FILENAME] [-dt] [NAME]
+
Each time `hash' is invoked, it remembers the full pathnames of the
commands specified as NAME arguments, so they need not be searched
for on subsequent invocations. The commands are found by
`pwd'
pwd [-LP]
+
Print the absolute pathname of the current working directory. If
the `-P' option is supplied, the pathname printed will not contain
symbolic links. If the `-L' option is supplied, the pathname
current directory or an invalid option is supplied.
`readonly'
- readonly [-aApf] [NAME[=VALUE]] ...
+ readonly [-aAf] [-p] [NAME[=VALUE]] ...
+
Mark each NAME as readonly. The values of these names may not be
changed by subsequent assignment. If the `-f' option is supplied,
each NAME refers to a shell function. The `-a' option means each
NAME refers to an indexed array variable; the `-A' option means
- each NAME refers to an associative array variable. If no NAME
- arguments are given, or if the `-p' option is supplied, a list of
- all readonly names is printed. The `-p' option causes output to
- be displayed in a format that may be reused as input. If a
- variable name is followed by =VALUE, the value of the variable is
- set to VALUE. The return status is zero unless an invalid option
- is supplied, one of the NAME arguments is not a valid shell
- variable or function name, or the `-f' option is supplied with a
- name that is not a shell function.
+ each NAME refers to an associative array variable. If both
+ options are supplied, `-A' takes precedence. If no NAME arguments
+ are given, or if the `-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
+ `-p' option causes output to be displayed in a format that may be
+ reused as input. If a variable name is followed by =VALUE, the
+ value of the variable is set to VALUE. The return status is zero
+ unless an invalid option is supplied, one of the NAME arguments is
+ not a valid shell variable or function name, or the `-f' option is
+ supplied with a name that is not a shell function.
`return'
return [N]
- Cause a shell function to exit with the return value N. If 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 `.' (or
- `source') builtin, returning either N or the exit status of the
- last command executed within the script as the exit status of the
- script. Any command associated with the `RETURN' trap is executed
- before execution resumes after the function or script. The return
- status is non-zero if `return' is used outside a function and not
- during the execution of a script by `.' or `source'.
+
+ Cause a shell function to stop executing and return the value N to
+ its caller. If N is not supplied, the return value is the exit
+ status of the last command executed in the function. `return' may
+ also be used to terminate execution of a script being executed
+ with the `.' (`source') builtin, returning either N or the exit
+ status of the last command executed within the script as the exit
+ status of the script. If N is supplied, the return value is its
+ least significant 8 bits. Any command associated with the
+ `RETURN' trap is executed before execution resumes after the
+ function or script. The return status is non-zero if `return' is
+ supplied a non-numeric argument or is used outside a function and
+ not during the execution of a script by `.' or `source'.
`shift'
shift [N]
+
Shift the positional parameters to the left by N. The positional
parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
`test'
`['
- Evaluate a conditional expression EXPR. Each operator and operand
- must be a separate argument. Expressions are composed of the
- primaries described below in *note Bash Conditional Expressions::.
- `test' does not accept any options, nor does it accept and ignore
- an argument of `--' as signifying the end of options.
+ test EXPR
+
+ Evaluate a conditional express ion 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 *note Bash Conditional Expressions::. `test' does not
+ accept any options, nor does it accept and ignore an argument of
+ `--' as signifying the end of options.
When the `[' form is used, the last argument to the command must
be a `]'.
`times'
times
+
Print out the user and system times used by the shell and its
children. The return status is zero.
`trap'
trap [-lp] [ARG] [SIGSPEC ...]
+
The commands in ARG are to be read and executed when the shell
receives signal SIGSPEC. If ARG is absent (and there is a single
SIGSPEC) or equal to `-', each specified signal's disposition is
builtins finishes executing.
If a SIGSPEC is `ERR', the command ARG is executed whenever a
- simple command has a non-zero exit status, subject to the
- following conditions. The `ERR' trap is not executed if the
+ pipeline (which may consist of a single simple command), a list,
+ or a compound command returns a non-zero exit status, subject to
+ the following conditions. The `ERR' trap is not executed if the
failed command is part of the command list immediately following
an `until' or `while' keyword, part of the test following the `if'
or `elif' reserved words, part of a command executed in a `&&' or
- `||' list, or if the command's return status is being inverted
- using `!'. These are the same conditions obeyed by the `errexit'
- option.
+ `||' list except the command following the final `&&' or `||', any
+ command in a pipeline but the last, or if the command's return
+ status is being inverted using `!'. These are the same conditions
+ obeyed by the `errexit' (`-e') option.
Signals ignored upon entry to the shell cannot be trapped or reset.
Trapped signals that are not being ignored are reset to their
`umask'
umask [-p] [-S] [MODE]
+
Set the shell process's file creation mask to MODE. If MODE
begins with a digit, it is interpreted as an octal number; if not,
it is interpreted as a symbolic mode mask similar to that accepted
results in permissions of `755'.
`unset'
- unset [-fv] [NAME]
- Each variable or function NAME is removed. If no options are
- supplied, or the `-v' option is given, each NAME refers to a shell
- variable. If the `-f' option is given, the NAMEs refer to shell
- functions, and the function definition is removed. Readonly
- variables and functions may not be unset. The return status is
- zero unless a NAME is readonly.
+ unset [-fnv] [NAME]
+
+ Remove each variable or function NAME. If the `-v' option is
+ given, each NAME refers to a shell variable and that variable is
+ remvoved. If the `-f' option is given, the NAMEs refer to shell
+ functions, and the function definition is removed. If the `-n'
+ option is supplied, and NAME is a variable with the NAMEREF
+ attribute, NAME will be unset rather than the variable it
+ references. `-n' has no effect if the `-f' option is supplied.
+ If no options are supplied, each 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 NAME is readonly.
\1f
File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
POSIX standard.
`alias'
- alias [`-p'] [NAME[=VALUE] ...]
+ alias [-p] [NAME[=VALUE] ...]
Without arguments or with the `-p' option, `alias' prints the list
of aliases on the standard output in a form that allows them to be
Aliases::.
`bind'
- bind [-m KEYMAP] [-lpsvPSV]
+ bind [-m KEYMAP] [-lpsvPSVX]
bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
bind [-m KEYMAP] -f FILENAME
bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
changes the value of `READLINE_LINE' or `READLINE_POINT',
those new values will be reflected in the editing state.
+ `-X'
+ List all key sequences bound to shell commands and the
+ associated commands in a format that can be reused as input.
+
The return status is zero unless an invalid option is supplied or
an error occurs.
`builtin'
builtin [SHELL-BUILTIN [ARGS]]
+
Run a shell builtin, passing it 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
`caller'
caller [EXPR]
+
Returns the context of any active subroutine call (a shell
function or a script executed with the `.' or `source' builtins).
`command'
command [-pVv] COMMAND [ARGUMENTS ...]
+
Runs COMMAND with ARGUMENTS ignoring any shell function named
COMMAND. Only shell builtin commands or commands found by
searching the `PATH' are executed. If there is a shell function
non-zero if not.
`declare'
- declare [-aAfFilrtux] [-p] [NAME[=VALUE] ...]
+ declare [-aAfFgilnrtux] [-p] [NAME[=VALUE] ...]
Declare variables and give them attributes. If no NAMEs are
given, then display the values of variables instead.
The `-p' option will display the attributes and values of each
- NAME. When `-p' is used with NAME arguments, additional options
- are ignored.
+ NAME. When `-p' is used with NAME arguments, additional options,
+ other than `-f' and `-F', are ignored.
When `-p' is supplied without NAME arguments, `declare' will
display the attributes and values of all variables having the
are displayed as well. `-F' implies `-f'.
The `-g' option forces variables to be created or modified at the
- global scope, even when \fBdeclare\fP is executed in a shell
- function. It is ignored in all other cases.
+ global scope, even when `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 the specified attributes or to give variables attributes:
characters are converted to lower-case. The upper-case
attribute is disabled.
+ `-n'
+ Give each NAME the NAMEREF attribute, making it a name
+ reference to another variable. That other variable is
+ defined by the value of NAME. All references and assignments
+ to NAME, except for changing the `-n' attribute itself, are
+ performed on the variable referenced by NAME's value. The
+ `-n' attribute cannot be applied to array variables.
+
`-r'
Make NAMEs readonly. These names cannot then be assigned
values by subsequent assignment statements or unset.
command, unless the `-g' option is used. If a variable name is
followed by =VALUE, the value of the variable is set to VALUE.
+ When using `-a' or `-A' and the compound assignment syntax to
+ create array variables, additional attributes do not take effect
+ until subsequent assignments.
+
The return status is zero unless an invalid option is encountered,
an attempt is made to define a function using `-f foo=bar', an
attempt is made to assign a value to a readonly variable, an
`echo'
echo [-neE] [ARG ...]
+
Output the ARGs, separated by spaces, terminated with a newline.
- The return status is always 0. If `-n' is specified, the trailing
- newline is suppressed. If the `-e' option is given,
- interpretation of the following backslash-escaped characters is
- enabled. The `-E' option disables the interpretation of these
- escape characters, even on systems where they are interpreted by
- default. The `xpg_echo' shell option may be used to dynamically
- determine whether or not `echo' expands these escape characters by
- default. `echo' does not interpret `--' to mean the end of
- options.
+ The return status is 0 unless a write error occurs. If `-n' is
+ specified, the trailing newline is suppressed. If the `-e' option
+ is given, interpretation of the following backslash-escaped
+ characters is enabled. The `-E' option disables the
+ interpretation of these escape characters, even on systems where
+ they are interpreted by default. The `xpg_echo' shell option may
+ be used to dynamically determine whether or not `echo' expands
+ these escape characters by default. `echo' does not interpret
+ `--' to mean the end of options.
`echo' interprets the following escape sequences:
`\a'
`enable'
enable [-a] [-dnps] [-f FILENAME] [NAME ...]
+
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, even though the
`help'
help [-dms] [PATTERN]
+
Display helpful information about builtin commands. If PATTERN is
specified, `help' gives detailed help on all commands matching
PATTERN, otherwise a list of the builtins is printed.
The return status is zero unless no command matches PATTERN.
`let'
- let EXPRESSION [EXPRESSION]
+ let EXPRESSION [EXPRESSION ...]
+
The `let' builtin allows arithmetic to be performed on shell
variables. Each EXPRESSION is evaluated according to the rules
given below in *note Shell Arithmetic::. If the last EXPRESSION
`local'
local [OPTION] NAME[=VALUE] ...
+
For each argument, a local variable named NAME is created, and
assigned VALUE. The OPTION can be any of the options accepted by
`declare'. `local' can only be used within a function; it makes
`logout'
logout [N]
+
Exit a login shell, returning a status of N to the shell's parent.
`mapfile'
- mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
- -C CALLBACK] [-c QUANTUM] [ARRAY]
+ mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
+ [-C CALLBACK] [-c QUANTUM] [ARRAY]
+
Read lines from the standard input into the indexed array variable
ARRAY, or from file descriptor FD if the `-u' option is supplied.
The variable `MAPFILE' is the default ARRAY. Options, if
supplied, have the following meanings:
+
`-n'
Copy at most COUNT lines. If COUNT is 0, all lines are
copied.
`printf'
printf [-v VAR] FORMAT [ARGUMENTS]
+
Write the formatted ARGUMENTS to the standard output under the
control of the FORMAT. The `-v' option causes the output to be
assigned to the variable VAR rather than being printed to the
following extensions:
`%b'
- causes `printf' to expand backslash escape sequences in the
- corresponding ARGUMENT, (except that `\c' terminates output,
+ Causes `printf' to expand backslash escape sequences in the
+ corresponding ARGUMENT, except that `\c' terminates output,
backslashes in `\'', `\"', and `\?' are not removed, and
octal escapes beginning with `\0' may contain up to four
- digits).
+ digits.
`%q'
- causes `printf' to output the corresponding ARGUMENT in a
+ Causes `printf' to output the corresponding ARGUMENT in a
format that can be reused as shell input.
`%(DATEFMT)T'
- causes `printf' to output the date-time string resulting from
+ Causes `printf' to output the date-time string resulting from
using DATEFMT as a format string for `strftime'(3). The
corresponding ARGUMENT is an integer representing the number
of seconds since the epoch. Two special argument values may
be used: -1 represents the current time, and -2 represents
- the time the shell was invoked.
+ the time the shell was invoked. If no argument is specified,
+ conversion behaves as if -1 had been given. This is an
+ exception to the usual `printf' behavior.
Arguments to non-string format specifiers are treated as C
language constants, except that a leading plus or minus sign is
success, non-zero on failure.
`read'
- read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
+ read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
+ [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
+
One line is read from the standard input, or from the file
descriptor FD supplied as an argument to the `-u' option, and the
first word is assigned to the first NAME, the second word to the
separators assigned to the last NAME. If there are fewer words
read from the input stream than names, the remaining names are
assigned empty values. The characters in the value of the `IFS'
- variable are used to split the line into words. The backslash
- character `\' may be used to remove any special meaning for the
- next character read and for line continuation. If no names are
- supplied, the line read is assigned to the variable `REPLY'. The
- return code is zero, unless end-of-file is encountered, `read'
- times out (in which case the return code is greater than 128), or
- an invalid file descriptor is supplied as the argument to `-u'.
+ variable are used to split the line into words using the same
+ rules the shell uses for expansion (described above in *note Word
+ Splitting::). The backslash character `\' may be used to remove
+ any special meaning for the next character read and for line
+ continuation. If no names are supplied, the line read is assigned
+ to the variable `REPLY'. The return code is zero, unless
+ end-of-file is encountered, `read' times out (in which case the
+ return code is greater than 128), a variable assignment error
+ (such as assigning to a readonly variable) occurs, or an invalid
+ file descriptor is supplied as the argument to `-u'.
Options, if supplied, have the following meanings:
`-t TIMEOUT'
Cause `read' to time out and return failure if a complete
- line of input is not read within TIMEOUT seconds. TIMEOUT
- may be a decimal number with a fractional portion following
- the decimal point. This option is only effective if `read'
- is reading input from a terminal, pipe, or other special
- file; it has no effect when reading from regular files. If
- TIMEOUT is 0, `read' returns success if input is available on
- the specified file descriptor, failure otherwise. The exit
+ line of input (or a specified number of characters) is not
+ read within TIMEOUT seconds. TIMEOUT may be a decimal
+ number with a fractional portion following the decimal point.
+ This option is only effective if `read' is reading input from
+ a terminal, pipe, or other special file; it has no effect
+ when reading from regular files. If `read' times out, `read'
+ saves any partial input read into the specified variable NAME.
+ If TIMEOUT is 0, `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.
`-u FD'
Read input from file descriptor FD.
-
`readarray'
- readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
- -C CALLBACK] [-c QUANTUM] [ARRAY]
+ readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
+ [-C CALLBACK] [-c QUANTUM] [ARRAY]
+
Read lines from the standard input into the indexed array variable
ARRAY, or from file descriptor FD if the `-u' option is supplied.
`source'
source FILENAME
+
A synonym for `.' (*note Bourne Shell Builtins::).
`type'
type [-afptP] [NAME ...]
+
For each NAME, indicate how it would be interpreted if used as a
command name.
The `-P' option forces a path search for each NAME, even if `-t'
would not return `file'.
- If a command is hashed, `-p' and `-P' print the hashed value, not
- necessarily the file that appears first in `$PATH'.
+ If a command is hashed, `-p' and `-P' print the hashed value,
+ which is not necessarily the file that appears first in `$PATH'.
If the `-a' option is used, `type' returns all of the places that
contain an executable named FILE. This includes aliases and
if any are not found.
`typeset'
- typeset [-afFrxi] [-p] [NAME[=VALUE] ...]
+ typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...]
+
The `typeset' command is supplied for compatibility with the Korn
- shell; however, it has been deprecated in favor of the `declare'
- builtin command.
+ shell. It is a synonym for the `declare' builtin command.
`ulimit'
ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
+
`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:
+
`-S'
Change and report the soft limit associated with a resource.
`-T'
The maximum number of threads.
-
- If LIMIT is given, it is the new value of the specified resource;
- the special LIMIT values `hard', `soft', and `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; a soft limit may be increased up to the value of
- the hard limit. Otherwise, the current value of the soft limit
- for the specified resource is printed, unless the `-H' option is
- supplied. When setting new limits, if neither `-H' nor `-S' is
- supplied, both the hard and soft limits are set. If no option is
- given, then `-f' is assumed. Values are in 1024-byte increments,
- except for `-t', which is in seconds, `-p', which is in units of
- 512-byte blocks, and `-n' and `-u', which are unscaled values.
+ If LIMIT is given, and the `-a' option is not used, LIMIT is the
+ new value of the specified resource. The special LIMIT values
+ `hard', `soft', and `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; a soft
+ limit may be increased up to the value of the hard limit.
+ Otherwise, the current value of the soft limit for the specified
+ resource is printed, unless the `-H' option is supplied. When
+ setting new limits, if neither `-H' nor `-S' is supplied, both the
+ hard and soft limits are set. If no option is given, then `-f' is
+ assumed. Values are in 1024-byte increments, except for `-t',
+ which is in seconds; `-p', which is in units of 512-byte blocks;
+ and `-T', `-b', `-n' and `-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 NAME from the list of aliases. If `-a' is supplied,
all aliases are removed. Aliases are described in *note Aliases::.
-
\1f
File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
`-e'
Exit immediately if a pipeline (*note Pipelines::), which may
consist of a single simple command (*note Simple Commands::),
- a subshell command enclosed in parentheses (*note Command
- Grouping::), or one of the commands executed as part of a
- command list enclosed by braces (*note Command Grouping::)
- returns a non-zero status. The shell does not exit if the
- command that fails is part of the command list immediately
- following a `while' or `until' keyword, part of the test in
- an `if' statement, part of any command executed in a `&&' or
- `||' list except the command following the final `&&' or `||',
- any command in a pipeline but the last, or if the command's
- return status is being inverted with `!'. A trap on `ERR',
- if set, is executed before the shell exits.
+ a list (*note Lists::), or a compound command (*note 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 `while' or `until' keyword, part of
+ the test in an `if' statement, part of any command executed
+ in a `&&' or `||' list except the command following the final
+ `&&' or `||', any command in a pipeline but the last, or if
+ the command's return status is being inverted with `!'. If a
+ compound command other than a subshell returns a non-zero
+ status because a command failed while `-e' was being ignored,
+ the shell does not exit. A trap on `ERR', if set, is
+ executed before the shell exits.
This option applies to the shell environment and each
subshell environment separately (*note Command Execution
Environment::), and may cause subshells to exit before
executing all the commands in the subshell.
+ If a compound command or shell function executes in a context
+ where `-e' is being ignored, none of the commands executed
+ within the compound command or function body will be affected
+ by the `-e' setting, even if `-e' is set and a command
+ returns a failure status. If a compound command or shell
+ function sets `-e' while executing in a context where `-e' is
+ ignored, that setting will not have any effect until the
+ compound command or the command containing the function call
+ completes.
+
`-f'
Disable filename expansion (globbing).
the command name.
`-m'
- Job control is enabled (*note Job Control::).
+ Job control is enabled (*note Job Control::). All processes
+ run in a separate process group. When a background job
+ completes, the shell prints a line containing its exit status.
`-n'
Read commands but do not execute them; this may be used to
shells.
`-P'
- If set, do not follow symbolic links when performing commands
- such as `cd' which change the current directory. The
- physical directory is used instead. By default, Bash follows
- the logical chain of directories when performing commands
- which change the current directory.
+ If set, do not resolve symbolic links when performing
+ commands such as `cd' which change the current directory.
+ The physical directory is used instead. By default, Bash
+ follows the logical chain of directories when performing
+ commands which change the current directory.
For example, if `/usr/sys' is a symbolic link to
`/usr/local/sys' then:
`shopt'
shopt [-pqsu] [-o] [OPTNAME ...]
- Toggle the values of variables controlling optional shell behavior.
- With no options, or with the `-p' option, a list of all settable
- options is displayed, with an indication of whether or not each is
- set. The `-p' option causes output to be displayed in a form that
- may be reused as input. Other options have the following meanings:
+
+ Toggle the values of settings controlling optional shell behavior.
+ The settings can be either those listed below, or, if the `-o'
+ option is used, those available with the `-o' option to the `set'
+ builtin command (*note The Set Builtin::). With no options, or
+ with the `-p' option, a list of all settable options is displayed,
+ with an indication of whether or not each is set. The `-p' option
+ causes output to be displayed in a form that may be reused as
+ input. Other options have the following meanings:
`-s'
Enable (set) each OPTNAME.
Restricts the values of OPTNAME to be those defined for the
`-o' option to the `set' builtin (*note The Set Builtin::).
- If either `-s' or `-u' is used with no OPTNAME arguments, the
- display is limited to those options which are set or unset,
- respectively.
+ If either `-s' or `-u' is used with no OPTNAME arguments, `shopt'
+ shows only those options which are set or unset, respectively.
Unless otherwise noted, the `shopt' options are disabled (off) by
default.
are stopped.
`checkwinsize'
- If set, Bash checks the window size after each command and,
+ If set, Bash checks the window size after each command and,
if necessary, updates the values of `LINES' and `COLUMNS'.
`cmdhist'
`compat31'
If set, Bash changes its behavior to that of version 3.1 with
respect to quoted arguments to the conditional command's `=~'
- operator.
+ operator and with respect to locale-specific string
+ comparison when using the `[[' conditional command's `<' and
+ `>' operators. Bash versions prior to bash-4.1 use ASCII
+ collation and strcmp(3); bash-4.1 and later use the current
+ locale's collation sequence and strcoll(3).
`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. 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).
+ `[[' conditional command's `<' and `>' operators (see
+ previous 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 (see
- previous item) and the effect of interrupting a command list.
+ description of `compat31') and the effect of interrupting a
+ command list. Bash versions 4.0 and later interrupt the list
+ as if the shell received the interrupt; previous versions
+ continue with the next command in the list.
`compat41'
- If set, Bash, when in posix mode, treats a single quote in a
+ If set, Bash, when in POSIX mode, treats a single quote in a
double-quoted parameter expansion as a special character.
The single quotes must match (an even number) and the
characters between the single quotes are considered quoted.
This is the behavior of POSIX mode through version 4.1. The
default Bash behavior remains as in previous versions.
+ `compat42'
+ If set, Bash does not process the replacement string in the
+ pattern substitution word expansion using quote removal.
+
+ `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.
+
+ `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.
+
`dirspell'
If set, Bash attempts spelling correction on directory names
during word completion if the directory name initially
*Note Bash Variables::, for a description of `FIGNORE'. This
option is enabled by default.
+ `globasciiranges'
+ If set, range expressions used in pattern matching bracket
+ expressions (*note 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 `b' will not collate between `A' and `B', and
+ upper-case and lower-case ASCII characters will collate
+ together.
+
`globstar'
If set, the pattern `**' used in a filename expansion context
- will match a files and zero or more directories and
+ will match all files and zero or more directories and
subdirectories. If the pattern is followed by a `/', only
directories and subdirectories match.
`promptvars'
If set, prompt strings undergo parameter expansion, command
substitution, arithmetic expansion, and quote removal after
- being expanded as described below (*note Printing a Prompt::).
- This option is enabled by default.
+ being expanded as described below (*note Controlling the
+ Prompt::). This option is enabled by default.
`restricted_shell'
The shell sets this option if it is started in restricted mode
the return status is zero unless an OPTNAME is not a valid shell
option.
-
\1f
File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
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 a `?'. When used in the text
+ the filename from the message with a `?'. When used in the text
of the message, `$_' expands to the name of the current mail file.
`OPTARG'
`PS1'
The primary prompt string. The default value is `\s-\v\$ '.
- *Note Printing a Prompt::, for the complete list of escape
+ *Note Controlling the Prompt::, for the complete list of escape
sequences that are expanded before `PS1' is displayed.
`PS2'
unless the shell is executing a command as the result of a trap,
in which case it is the command executing at the time of the trap.
+`BASH_COMPAT'
+ The value is used to set the shell's compatibility level. *Note
+ The Shopt Builtin::, for a description of the various compatibility
+ levels and their effects. The value may be a decimal number
+ (e.g., 4.2) or an integer (e.g., 42) corresponding to the desired
+ compatibility level. If `BASH_COMPAT' is unset or set to the
+ empty string, the compatibility level is set to the default for
+ the current version. If `BASH_COMPAT' is set to a value that is
+ not one of the valid compatibility levels, the shell prints an
+ error message and sets the compatibility level to the default for
+ the current version. The valid compatibility levels correspond to
+ the compatibility options accepted by the `shopt' builtin
+ described above (for example, COMPAT42 means that 4.2 and 42 are
+ valid values). The current version is also a valid value.
+
`BASH_ENV'
If this variable is set when Bash is invoked to execute a shell
script, its value is expanded and used as the name of a startup
`${BASH_SOURCE[$i+1]}'
`BASH_SUBSHELL'
- Incremented by one each time a subshell or subshell environment is
- spawned. The initial value is 0.
+ Incremented by one within each subshell or subshell environment
+ when the shell begins executing in that environment. The initial
+ value is 0.
`BASH_VERSINFO'
A readonly array variable (*note Arrays::) whose members hold
`BASH_VERSINFO[5]'
The value of `MACHTYPE'.
-
`BASH_VERSION'
The version number of the current instance of Bash.
`BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
unsetting it will result in the standard error being closed.
+`CHILD_MAX'
+ Set the number of exited child status values for the shell to
+ remember. Bash will not allow this value to be decreased below a
+ POSIX-mandated minimum, and there is a maximum value (currently
+ 8192) that this may not exceed. The minimum value is
+ system-dependent.
+
`COLUMNS'
Used by the `select' command to determine the terminal width when
- printing selection lists. Automatically set upon receipt of a
- `SIGWINCH'.
+ printing selection lists. Automatically set if the `checkwinsize'
+ option is enabled (*note The Shopt Builtin::), or in an
+ interactive shell upon receipt of a `SIGWINCH'.
`COMP_CWORD'
An index into `${COMP_WORDS}' of the word containing the current
`COMPREPLY'
An array variable from which Bash reads the possible completions
generated by a shell function invoked by the programmable
- completion facility (*note Programmable Completion::).
+ completion facility (*note Programmable Completion::). Each array
+ element contains one possible completion.
`COPROC'
An array variable created to hold the file descriptors for output
`FIGNORE'
A colon-separated list of suffixes to ignore when performing
- filename completion. A file name whose suffix matches one of the
- entries in `FIGNORE' is excluded from the list of matched file
- names. A sample value is `.o:~'
+ filename completion. A filename whose suffix matches one of the
+ entries in `FIGNORE' is excluded from the list of matched
+ filenames. A sample value is `.o:~'
`FUNCNAME'
An array variable containing the names of all shell functions
`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 history file is also truncated to
- this size after writing it when an interactive shell exits. The
- default value is 500.
+ 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 a shell exits. 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 `HISTSIZE' after reading
+ any startup files.
`HISTIGNORE'
A colon-separated list of patterns used to decide which command
`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.
`HISTTIMEFORMAT'
If this variable is set and not null, its value is used as a
`LINES'
Used by the `select' command to determine the column length for
- printing selection lists. Automatically set upon receipt of a
- `SIGWINCH'.
+ printing selection lists. Automatically set if the `checkwinsize'
+ option is enabled (*note The Shopt Builtin::), or in an
+ interactive shell upon receipt of a `SIGWINCH'.
`MACHTYPE'
A string that fully describes the system type on which Bash is
foreground pipeline (which may contain only a single command).
`POSIXLY_CORRECT'
- If this variable is in the environment when `bash' starts, the
- shell enters POSIX mode (*note Bash POSIX Mode::) before reading
- the startup files, as if the `--posix' invocation option had been
- supplied. If it is set while the shell is running, `bash' enables
+ If this variable is in the environment when Bash starts, the shell
+ enters POSIX mode (*note Bash POSIX Mode::) before reading the
+ startup files, as if the `--posix' invocation option had been
+ supplied. If it is set while the shell is running, Bash enables
POSIX mode, as if the command
`set -o posix'
had been executed.
`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 `\w' and `\W' prompt string escapes (*note Printing a
+ the `\w' and `\W' prompt string escapes (*note Controlling the
Prompt::). Characters removed are replaced with an ellipsis.
`PS3'
from a terminal.
In an interactive shell, the value is interpreted as the number of
- seconds to wait for input after issuing the primary prompt when
- the shell is interactive. Bash terminates after that number of
- seconds if input does not arrive.
+ seconds to wait for a line of input after issuing the primary
+ prompt. Bash terminates after waiting for that number of seconds
+ if a complete line of input does not arrive.
`TMPDIR'
If set, Bash uses its value as the name of a directory in which
6 Bash Features
***************
-This section describes features unique to Bash.
+This chapter describes features unique to Bash.
* Menu:
* 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.
Show version information for this instance of Bash on the standard
output and exit successfully.
-
There are several single-character options that may be supplied at
invocation which are not available with the `set' builtin.
-`-c STRING'
- Read and execute commands from STRING after processing the
- options, then exit. Any remaining arguments are assigned to the
- positional parameters, starting with `$0'.
+`-c'
+ Read and execute commands from the first non-option ARGUMENT after
+ processing the options, then exit. Any remaining arguments are
+ assigned to the positional parameters, starting with `$0'.
`-i'
Force the shell to run interactively. Interactive shells are
processing. Any arguments after the `--' are treated as filenames
and arguments.
-
A _login_ shell is one whose first character of argument zero is
`-', or one invoked with the `--login' option.
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 Tilde Expansion (*note
+expanded in filenames as described above under Tilde Expansion (*note
Tilde Expansion::).
Interactive shells are described in *note Interactive Shells::.
following command were executed:
`if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
but the value of the `PATH' variable is not used to search for the
-file name.
+filename.
As noted above, if a non-interactive shell is invoked with the
`--login' option, Bash attempts to read and execute commands from the
commands from `~/.bashrc', if that file exists and is readable. It
will not do this if invoked as `sh'. The `--norc' option may be used
to inhibit this behavior, and the `--rcfile' option may be used to
-force another file to be read, but `rshd' does not generally invoke the
-shell with those options or allow them to be specified.
+force another file to be read, but neither `rshd' nor `sshd' generally
+invoke the shell with those options or allow them to be specified.
Invoked with unequal effective and real UID/GIDs
................................................
7. Command history (*note Bash History Facilities::) and history
expansion (*note History Interaction::) are enabled by default.
Bash will save the command history to the file named by `$HISTFILE'
- when an interactive shell exits.
+ when a shell with history enabled exits.
8. Alias expansion (*note Aliases::) is performed by default.
True if the shell variable VARNAME is set (has been assigned a
value).
+`-R VARNAME'
+ True if the shell variable VARNAME is set and is a name reference.
+
`-z STRING'
True if the length of STRING is zero.
`STRING1 == STRING2'
`STRING1 = STRING2'
- True if the strings are equal. `=' should be used with the `test'
- command for POSIX conformance.
+ True if the strings are equal. When used with the `[[' command,
+ this performs pattern matching as described above (*note
+ Conditional Constructs::).
+
+ `=' should be used with the `test' command for POSIX conformance.
`STRING1 != STRING2'
True if the strings are not equal.
greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
positive or negative integers.
-
\1f
File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
Constants with a leading 0 are interpreted as octal numbers. A
leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
form [BASE`#']N, where the optional BASE is a decimal number between 2
-and 64 representing the arithmetic base, and N is a number in that
-base. If BASE`#' is omitted, then base 10 is used. The digits greater
-than 9 are represented by the lowercase letters, the uppercase letters,
-`@', and `_', in that order. If BASE is less than or equal to 36,
-lowercase and uppercase letters may be used interchangeably to
-represent numbers between 10 and 35.
+and 64 representing the arithmetic base, and N is a number in that base.
+If BASE`#' is omitted, then base 10 is used. When specifying N, he
+digits greater than 9 are represented by the lowercase letters, the
+uppercase letters, `@', and `_', in that order. If BASE is less than
+or equal to 36, lowercase and uppercase letters may be used
+interchangeably to represent numbers between 10 and 35.
Operators are evaluated in order of precedence. Sub-expressions in
parentheses are evaluated first and may override the precedence rules
is tested for aliases, but a word that is identical to an alias being
expanded is not expanded a second time. This means that one may alias
`ls' to `"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
-alias is also checked for alias expansion.
+expand the replacement text. If the last character of the alias value
+is a BLANK, then the next command word following the alias is also
+checked for alias expansion.
Aliases are created and listed with the `alias' command, and removed
with the `unalias' command.
will explicitly declare an array. There is no maximum 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 (*note Shell Arithmetic::) and are
-zero-based; associative arrays use arbitrary strings.
+(including arithmetic expressions (*note Shell Arithmetic::)) and are
+zero-based; associative arrays use arbitrary strings. Unless otherwise
+noted, indexed array indices must be non-negative integers.
An indexed array is created automatically if any variable is
assigned to using the syntax
- name[SUBSCRIPT]=VALUE
+ NAME[SUBSCRIPT]=VALUE
The SUBSCRIPT is treated as an arithmetic expression that must evaluate
-to a number. If 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
+to a number. To explicitly declare an array, use
declare -a NAME
The syntax
declare -a NAME[SUBSCRIPT]
is also accepted; the SUBSCRIPT is ignored.
- Associative arrays are created using
+Associative arrays are created using
declare -A NAME.
Attributes may be specified for an array variable using the
members of an array.
Arrays are assigned to using compound assignments of the form
- name=(value1 ... valueN)
+ NAME=(VALUE1 VALUE2 ... )
where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array
-assignments do not require the bracket and subscript. When assigning
-to indexed arrays, if the optional subscript is supplied, that index is
+assignments do not require anything but 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 to by the statement plus one. Indexing starts at zero.
When assigning to an associative array, the subscript is required.
This syntax is also accepted by the `declare' builtin. Individual
-array elements may be assigned to using the `name['SUBSCRIPT`]='VALUE
+array elements may be assigned to using the `NAME[SUBSCRIPT]=VALUE'
syntax introduced above.
- Any element of an array may be referenced using
-`${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
-with the shell's filename expansion operators. If the SUBSCRIPT is `@'
-or `*', the word expands to all members of the array NAME. These
-subscripts differ only when the word appears within double quotes. If
-the word is double-quoted, `${name[*]}' expands to a single word with
-the value of each array member separated by the first character of the
-`IFS' variable, and `${name[@]}' expands each element of NAME to a
-separate word. When there are no array members, `${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 `@' and `*'.
-`${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'.
-If SUBSCRIPT is `@' or `*', 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.
+ When assigning to an indexed array, if NAME is subscripted by a
+negative number, that number is interpreted as relative to one greater
+than the maximum index of NAME, so negative indices count back from the
+end of the array, and an index of -1 references the last element.
+
+ Any element of an array may be referenced using `${NAME[SUBSCRIPT]}'.
+The braces are required to avoid conflicts with the shell's filename
+expansion operators. If the SUBSCRIPT is `@' or `*', the word expands
+to all members of the array NAME. These subscripts differ only when
+the word appears within double quotes. If the word is double-quoted,
+`${NAME[*]}' expands to a single word with the value of each array
+member separated by the first character of the `IFS' variable, and
+`${NAME[@]}' expands each element of NAME to a separate word. When
+there are no array members, `${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 `@' and `*'. `${#NAME[SUBSCRIPT]}' expands to the length of
+`${NAME[SUBSCRIPT]}'. If SUBSCRIPT is `@' or `*', 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
+SUBSCRIPT used to reference an element of an indexed array evaluates to
+a number less than zero, it is interpreted as relative to one greater
+than the maximum index of the array, so negative indices count back
+from the end of the array, and an index of -1 refers to the last
+element.
An array variable is considered set if a subscript has been assigned
a value. The null string is a valid value.
- The `unset' builtin is used to destroy arrays. `unset'
-NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care
-must be taken to avoid unwanted side effects caused by filename
-expansion. `unset' NAME, where NAME is an array, removes the entire
-array. A subscript of `*' or `@' also removes the entire array.
+ It is possible to obtain the keys (indices) of an array as well as
+the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned
+in array variable NAME. The treatment when in double quotes is similar
+to the expansion of the special parameters `@' and `*' within double
+quotes.
+
+ The `unset' builtin is used to destroy arrays. `unset
+NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
+Negative subscripts to indexed arrays are interpreted as described
+above. Care must be taken to avoid unwanted side effects caused by
+filename expansion. `unset NAME', where NAME is an array, removes the
+entire array. A subscript of `*' or `@' also removes the entire array.
The `declare', `local', and `readonly' builtins each accept a `-a'
option to specify an indexed array and a `-A' option to specify an
-associative array. The `read' builtin accepts a `-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 individual array elements. The
-`set' and `declare' builtins display array values in a way that allows
-them to be reused as input.
+associative array. If both options are supplied, `-A' takes precedence.
+The `read' builtin accepts a `-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 individual array elements. The `set' and `declare'
+builtins display array values in a way that allows them to be reused as
+input.
\1f
-File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
+File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
6.8 The Directory Stack
=======================
------------------------------
`dirs'
- dirs [+N | -N] [-clpv]
+ dirs [-clpv] [+N | -N]
+
Display the list of currently remembered directories. Directories
are added to the list with the `pushd' command; the `popd' command
removes directories from the list.
- `+N'
- Displays the Nth directory (counting from the left of the
- list printed by `dirs' when invoked without options), starting
- with zero.
-
- `-N'
- Displays the Nth directory (counting from the right of the
- list printed by `dirs' when invoked without options), starting
- with zero.
`-c'
Clears the directory stack by deleting all of the elements.
`-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.
`-p'
Causes `dirs' to print the directory stack with one entry per
Causes `dirs' to print the directory stack with one entry per
line, prefixing each entry with its index in the stack.
+ `+N'
+ Displays the Nth directory (counting from the left of the
+ list printed by `dirs' when invoked without options), starting
+ with zero.
+
+ `-N'
+ Displays the Nth directory (counting from the right of the
+ list printed by `dirs' when invoked without options), starting
+ with zero.
+
`popd'
- popd [+N | -N] [-n]
+ popd [-n] [+N | -N]
Remove the top entry from the directory stack, and `cd' to the new
top directory. When no arguments are given, `popd' removes the
top directory from the stack and performs a `cd' to the new top
directory. The elements are numbered from 0 starting at the first
- directory listed with `dirs'; i.e., `popd' is equivalent to `popd
- +0'.
+ directory listed with `dirs'; that is, `popd' is equivalent to
+ `popd +0'.
+
+ `-n'
+ Suppresses the normal change of directory when removing
+ directories from the stack, so that only the stack is
+ manipulated.
+
`+N'
Removes the Nth directory (counting from the left of the list
printed by `dirs'), starting with zero.
Removes the Nth directory (counting from the right of the
list printed by `dirs'), starting with zero.
- `-n'
- Suppresses the normal change of directory when removing
- directories from the stack, so that only the stack is
- manipulated.
-
`pushd'
- pushd [-n] [+N | -N | DIR ]
+ pushd [-n] [+N | -N | DIR]
Save the current directory on the top of the directory stack and
then `cd' to DIR. With no arguments, `pushd' exchanges the top
`DIR'
Makes the current working directory be the top of the stack,
- and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
-
+ making it the new current directory as if it had been
+ supplied as an argument to the `cd' builtin.
\1f
-File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
+File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
6.9 Controlling the Prompt
==========================
on the command line.
In addition, the following table describes the special characters
-which can appear in the prompt variables:
+which can appear in the prompt variables `PS1' to `PS4':
`\a'
A bell character.
to the value of the `promptvars' shell option (*note Bash Builtins::).
\1f
-File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
+File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
6.10 The Restricted Shell
=========================
8. Tilde expansion is only performed on assignments preceding a
command name, rather than on all assignment statements on the line.
- 9. The default history file is `~/.sh_history' (this is the default
+ 9. The `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 `command'.
+
+ 10. The default history file is `~/.sh_history' (this is the default
value of `$HISTFILE').
- 10. The output of `kill -l' prints all the signal names on a single
+ 11. The output of `kill -l' prints all the signal names on a single
line, separated by spaces, without the `SIG' prefix.
- 11. The `kill' builtin does not accept signal names with a `SIG'
+ 12. The `kill' builtin does not accept signal names with a `SIG'
prefix.
- 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
+ 13. Non-interactive shells exit if FILENAME in `.' FILENAME is not
found.
- 13. Non-interactive shells exit if a syntax error in an arithmetic
+ 14. Non-interactive shells exit if a syntax error in an arithmetic
expansion results in an invalid expression.
- 14. Non-interactive shells exit if there is a syntax error in a script
+ 15. Non-interactive shells exit if there is a syntax error in a script
read with the `.' or `source' builtins, or in a string processed by
the `eval' builtin.
- 15. Redirection operators do not perform filename expansion on the word
+ 16. Redirection operators do not perform filename expansion on the word
in the redirection unless the shell is interactive.
- 16. Redirection operators do not perform word splitting on the word in
+ 17. Redirection operators do not perform word splitting on the word in
the redirection.
- 17. Function names must be valid shell `name's. That is, they may not
+ 18. Function names must be valid shell `name's. That is, they may not
contain characters other than letters, digits, and underscores, and
may not start with a digit. Declaring a function with an invalid
name causes a fatal syntax error in non-interactive shells.
- 18. POSIX special builtins are found before shell functions during
+ 19. Function names may not be the same as one of the POSIX special
+ builtins.
+
+ 20. POSIX special builtins are found before shell functions during
command lookup.
- 19. The `time' reserved word may be used by itself as a command. When
+ 21. The `time' reserved word may be used by itself as a command. When
used in this way, it displays timing statistics for the shell and
its completed children. The `TIMEFORMAT' variable controls the
format of the timing information.
- 20. When parsing and expanding a ${...} expansion that appears within
+ 22. When parsing and expanding a ${...} expansion that appears within
double quotes, single quotes are no longer special and cannot be
used to quote a closing brace or other special character, unless
the operator is one of those defined to perform pattern removal.
In this case, they do not have to appear as matched pairs.
- 21. The parser does not recognize `time' as a reserved word if the next
+ 23. The parser does not recognize `time' as a reserved word if the next
token begins with a `-'.
- 22. If a POSIX special builtin returns an error status, a
+ 24. If a POSIX special builtin returns an error status, a
non-interactive shell exits. The fatal errors are those listed in
the POSIX standard, and include things like passing incorrect
options, redirection errors, variable assignment errors for
assignments preceding the command name, and so on.
- 23. A non-interactive shell exits with an error status if a variable
+ 25. A non-interactive shell exits with an error status if a variable
assignment error occurs when no command name follows the assignment
statements. A variable assignment error occurs, for example, when
trying to assign a value to a readonly variable.
- 24. A non-interactive shell exists with an error status if a variable
+ 26. A non-interactive shell exits 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.
- 25. A non-interactive shell exits with an error status if the iteration
+ 27. A non-interactive shell exits with an error status if the iteration
variable in a `for' statement or the selection variable in a
`select' statement is a readonly variable.
- 26. Process substitution is not available.
+ 28. Process substitution is not available.
- 27. Assignment statements preceding POSIX special builtins persist in
+ 29. While variable indirection is available, it may not be applied to
+ the `#' and `?' special parameters.
+
+ 30. Assignment statements preceding POSIX special builtins persist in
the shell environment after the builtin completes.
- 28. Assignment statements preceding shell function calls persist in the
+ 31. Assignment statements preceding shell function calls persist in the
shell environment after the function returns, as if a POSIX
special builtin command had been executed.
- 29. The `export' and `readonly' builtin commands display their output
+ 32. The `export' and `readonly' builtin commands display their output
in the format required by POSIX.
- 30. The `trap' builtin displays signal names without the leading `SIG'.
+ 33. The `trap' builtin displays signal names without the leading `SIG'.
- 31. The `trap' builtin doesn't check the first argument for a possible
+ 34. The `trap' builtin doesn't check the first argument for a possible
signal specification and revert the signal handling to the original
disposition if it is, unless that argument consists solely of
digits and is a valid signal number. If users want to reset the
handler for a given signal to the original disposition, they
should use `-' as the first argument.
- 32. The `.' and `source' builtins do not search the current directory
+ 35. The `.' and `source' builtins do not search the current directory
for the filename argument if it is not found by searching `PATH'.
- 33. Subshells spawned to execute command substitutions inherit the
+ 36. Subshells spawned to execute command substitutions inherit the
value of the `-e' option from the parent shell. When not in POSIX
mode, Bash clears the `-e' option in such subshells.
- 34. Alias expansion is always enabled, even in non-interactive shells.
+ 37. Alias expansion is always enabled, even in non-interactive shells.
- 35. When the `alias' builtin displays alias definitions, it does not
+ 38. When the `alias' builtin displays alias definitions, it does not
display them with a leading `alias ' unless the `-p' option is
supplied.
- 36. When the `set' builtin is invoked without options, it does not
+ 39. When the `set' builtin is invoked without options, it does not
display shell function names and definitions.
- 37. When the `set' builtin is invoked without options, it displays
+ 40. When the `set' builtin is invoked without options, it displays
variable values without quotes, unless they contain shell
metacharacters, even if the result contains nonprinting characters.
- 38. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
+ 41. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
constructed from `$PWD' and the directory name supplied as an
argument does not refer to an existing directory, `cd' will fail
instead of falling back to PHYSICAL mode.
- 39. The `pwd' builtin verifies that the value it prints is the same as
+ 42. The `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 `-P' option.
- 40. When listing the history, the `fc' builtin does not include an
+ 43. When listing the history, the `fc' builtin does not include an
indication of whether or not a history entry has been modified.
- 41. The default editor used by `fc' is `ed'.
+ 44. The default editor used by `fc' is `ed'.
- 42. The `type' and `command' builtins will not report a non-executable
+ 45. The `type' and `command' builtins will not report a non-executable
file as having been found, though the shell will attempt to
execute such a file if it is the only so-named file found in
`$PATH'.
- 43. The `vi' editing mode will invoke the `vi' editor directly when
+ 46. The `vi' editing mode will invoke the `vi' editor directly when
the `v' command is run, instead of checking `$VISUAL' and
`$EDITOR'.
- 44. When the `xpg_echo' option is enabled, Bash does not attempt to
+ 47. When the `xpg_echo' option is enabled, Bash does not attempt to
interpret any arguments to `echo' as options. Each argument is
displayed, after escape characters are converted.
- 45. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
+ 48. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
and `-f' options.
- 46. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
+ 49. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
interrupt the `wait' builtin and cause it to return immediately.
The trap command is run once for each child that exits.
+ 50. The `read' builtin may be interrupted by a signal for which a trap
+ has been set. If Bash receives a trapped signal while executing
+ `read', the trap handler executes and `read' returns an exit
+ status greater than 128.
+
There is other POSIX behavior that Bash does not implement by
default even when in POSIX mode. Specifically:
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, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other
-hand, refers to any job containing the string `ce' in its command line.
-If the prefix or substring matches more than one job, Bash reports an
-error.
+example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the
+other hand, refers to any job containing the string `ce' in its command
+line. If the prefix or substring matches more than one job, Bash
+reports an error.
Simply naming a job can be used to bring it into the foreground:
`%1' is a synonym for `fg %1', bringing job 1 from the background into
`bg'
bg [JOBSPEC ...]
+
Resume each suspended job JOBSPEC in the background, as if it had
been started with `&'. If JOBSPEC is not supplied, the current
job is used. The return status is zero unless it is run when job
`fg'
fg [JOBSPEC]
+
Resume the job JOBSPEC in the foreground and make it the current
job. If 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 ID of the job's process group leader.
`-r'
- Restrict output to running jobs.
+ Display only running jobs.
`-s'
- Restrict output to stopped jobs.
+ Display only stopped jobs.
If JOBSPEC is given, output is restricted to information about
that job. If JOBSPEC is not supplied, the status of all jobs is
`kill'
kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
kill -l [EXIT_STATUS]
+
Send a signal specified by SIGSPEC or SIGNUM to the process named
by job specification JOBSPEC or process ID PID. SIGSPEC is either
a case-insensitive signal name such as `SIGINT' (with or without
occurs or an invalid option is encountered.
`wait'
- wait [JOBSPEC or PID ...]
+ wait [-n] [JOBSPEC or PID ...]
+
Wait until the child process specified by each process ID PID or
job specification JOBSPEC exits and return the exit status of the
last command waited for. If a job spec is given, all processes in
the job are waited for. If no arguments are given, all currently
active child processes are waited for, and the return status is
- zero. If neither JOBSPEC nor PID specifies an active child process
- of the shell, the return status is 127.
+ zero. If the `-n' option is supplied, `wait' waits for any job to
+ terminate and returns its exit status. If neither JOBSPEC nor PID
+ specifies an active child process of the shell, the return status
+ is 127.
`disown'
disown [-ar] [-h] [JOBSPEC ...]
- Without options, each JOBSPEC is removed from the table of active
- jobs. If the `-h' option is given, the job is not removed from
- the table, but is marked so that `SIGHUP' is not sent to the job
- if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
- neither the `-a' nor `-r' option is supplied, the current job is
- used. If no JOBSPEC is supplied, the `-a' option means to remove
- or mark all jobs; the `-r' option without a JOBSPEC argument
- restricts operation to running jobs.
+
+ Without options, remove each JOBSPEC from the table of active jobs.
+ If the `-h' option is given, the job is not removed from the table,
+ but is marked so that `SIGHUP' is not sent to the job if the shell
+ receives a `SIGHUP'. If JOBSPEC is not present, and neither the
+ `-a' nor the `-r' option is supplied, the current job is used. If
+ no JOBSPEC is supplied, the `-a' option means to remove or mark
+ all jobs; the `-r' option without a JOBSPEC argument restricts
+ operation to running jobs.
`suspend'
suspend [-f]
+
Suspend the execution of this shell until it receives a `SIGCONT'
signal. A login shell cannot be suspended; the `-f' option can be
used to override this and force the suspension.
-
When job control is not active, the `kill' and `wait' builtins do
not accept JOBSPEC arguments. They must be supplied process IDs.
a specific command.
* Programmable Completion Builtins:: Builtin commands to specify how to
complete arguments for a particular command.
+* A Programmable Completion Example:: An example shell function for
+ generating possible completions.
\1f
File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
characters treated specially by the kernel's terminal driver
to their Readline equivalents.
+ `colored-stats'
+ If set to `on', Readline displays possible completions using
+ different colors to indicate their file type. The color
+ definitions are taken from the value of the `LS_COLORS'
+ environment variable. The default is `off'.
+
`comment-begin'
The string to insert at the beginning of the line when the
`insert-comment' command is executed. The default value is
`history-size'
Set the maximum number of history entries saved in the
- history list. If set to zero, the number of entries in the
- history list is not limited.
+ history list. If set to zero, any existing history entries
+ are deleted and no new entries are saved. If set to a value
+ less than zero, the number of history entries is not limited.
+ By default, the number of history entries is not limited.
`horizontal-scroll-mode'
This variable can be set to either `on' or `off'. Setting it
default value is `emacs'. The value of the `editing-mode'
variable also affects the default keymap.
+ `keyseq-timeout'
+ Specifies the duration Readline will wait for a character
+ when reading an ambiguous key sequence (one that can form a
+ complete key sequence using the input read so far, or can
+ take additional input to complete a longer key sequence). If
+ no input is received within the timeout, Readline will use
+ the shorter but complete key sequence. Readline uses this
+ value to determine whether or not input is available on the
+ current input source (`rl_instream' by default). The value
+ is specified in milliseconds, so a value of 1000 means that
+ Readline will wait one second for additional input. If this
+ variable is set to a value less than or equal to zero, or to a
+ non-numeric value, Readline will wait until another key is
+ pressed to decide which key sequence to complete. The
+ default value is `500'.
+
`mark-directories'
If set to `on', completed directory names have a slash
appended. The default is `on'.
be listed immediately instead of ringing the bell. The
default value is `off'.
+ `show-mode-in-prompt'
+ If set to `on', add a character to the beginning of the prompt
+ indicating the editing mode: emacs (`@'), vi command (`:'),
+ or vi insertion (`+'). The default value is `off'.
+
`skip-completed-text'
If set to `on', this alters the default completion behavior
when inserting a single match into the line. It's only
# You can re-read the inputrc file with C-x C-r.
# Lines beginning with '#' are comments.
#
- # First, include any systemwide bindings and variable
+ # First, include any system-wide bindings and variable
# assignments from /etc/Inputrc
$include /etc/Inputrc
`history-search-forward ()'
Search forward through the history for the string of characters
- between the start of the current line and the point. This is a
+ between the start of the current line and the point. The search
+ string must match at the beginning of a history line. This is a
non-incremental search. By default, this command is unbound.
`history-search-backward ()'
Search backward through the history for the string of characters
- between the start of the current line and the point. This is a
+ between the start of the current line and the point. The search
+ string must match at the beginning of a history line. This is a
+ non-incremental search. By default, this command is unbound.
+
+`history-substr-search-forward ()'
+ Search forward through the history for the string of characters
+ between the start of the current line and the point. The search
+ string may match anywhere in a history line. This is a
+ non-incremental search. By default, this command is unbound.
+
+`history-substr-search-backward ()'
+ Search backward through the history for the string of characters
+ between the start of the current line and the point. The search
+ string may match anywhere in a history line. This is a
non-incremental search. By default, this command is unbound.
`yank-nth-arg (M-C-y)'
8.4.3 Commands For Changing Text
--------------------------------
+`end-of-file (usually C-d)'
+ The character indicating end-of-file as set, for example, by
+ `stty'. If this character is read when there are no characters on
+ the line, and point is at the beginning of the line, Readline
+ interprets it as the end of input and returns EOF.
+
`delete-char (C-d)'
- Delete the character at point. If point is at the beginning of
- the line, there are no characters in the line, and the last
- character typed was not bound to `delete-char', then return EOF.
+ Delete the character at point. If this function is bound to the
+ same character as the tty EOF character, as `C-d' commonly is, see
+ above for the effects.
`backward-delete-char (Rubout)'
Delete the character behind the cursor. A numeric argument means
Re-execute the last keyboard macro defined, by making the
characters in the macro appear as if typed at the keyboard.
+`print-last-kbd-macro ()'
+ Print the last keboard macro defined in a format suitable for the
+ INPUTRC file.
+
\1f
File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
`COMP_KEY', and `COMP_TYPE' variables are assigned values as described
above (*note Bash Variables::). If a shell function is being invoked,
the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
-function or command is invoked, the first argument is the name of the
-command whose arguments are being completed, the second argument is the
-word being completed, and the third argument is the word preceding the
-word being completed on the current command line. No filtering of the
-generated completions against the word being completed is performed;
-the function or command has complete freedom in generating the matches.
+function or command is invoked, the first argument ($1) is the name of
+the command whose arguments are being completed, the second argument
+($2) is the word being completed, and the third argument ($3) is the
+word preceding the word being completed on the current command line.
+No filtering of the generated completions against the word being
+completed is performed; the function or command has complete freedom in
+generating the matches.
Any function specified with `-F' is invoked first. The function may
use any of the shell facilities, including the `compgen' and `compopt'
builtins described below (*note Programmable Completion Builtins::), to
generate the matches. It must put the possible completions in the
-`COMPREPLY' array variable.
+`COMPREPLY' array variable, one per array element.
Next, any command specified with the `-C' option is invoked in an
environment equivalent to command substitution. It should print a list
_completion_loader()
{
- . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
+ . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
}
- complete -D -F _completion_loader
+ complete -D -F _completion_loader -o bashdefault -o default
\1f
-File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
+File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing
8.7 Programmable Completion Builtins
====================================
-Two builtin commands are available to manipulate the programmable
-completion facilities.
+Three builtin commands are available to manipulate the programmable
+completion facilities: one to specify how the arguments to a particular
+command are to be completed, and two to modify the completion as it is
+happening.
`compgen'
`compgen [OPTION] [WORD]'
option is intended to be used with shell functions
specified with `-F'.
+ `noquote'
+ Tell Readline not to quote the completed words if they
+ are filenames (quoting filenames is the default).
+
`nospace'
Tell Readline not to append a space (the default) to
words completed at the end of the line.
`-F FUNCTION'
The shell function FUNCTION is executed in the current shell
- environment. When it finishes, the possible completions are
- retrieved from the value of the `COMPREPLY' array variable.
+ environment. When it is executed, $1 is the name of the
+ command whose arguments are being completed, $2 is the word
+ being completed, and $3 is the word preceding the word being
+ completed, as described above (*note Programmable
+ Completion::). When it finishes, the possible completions
+ are retrieved from the value of the `COMPREPLY' array
+ variable.
`-G GLOBPAT'
The filename expansion pattern GLOBPAT is expanded to generate
\1f
+File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing
+
+8.8 A Programmable Completion Example
+=====================================
+
+The most common way to obtain additional completion functionality beyond
+the default actions `complete' and `compgen' provide is to use a shell
+function and bind it to a particular command using `complete -F'.
+
+ The following function provides completions for the `cd' builtin.
+It is a reasonably good example of what shell functions must do when
+used for completion. This function uses the word passsed as `$2' to
+determine the directory name to complete. You can also use the
+`COMP_WORDS' array variable; the current word is indexed by the
+`COMP_CWORD' variable.
+
+ The function relies on the `complete' and `compgen' builtins to do
+much of the work, adding only the things that the Bash `cd' does beyond
+accepting basic directory names: tilde expansion (*note Tilde
+Expansion::), searching directories in $CDPATH, which is described above
+(*note Bourne Shell Builtins::), and basic support for the
+`cdable_vars' shell option (*note The Shopt Builtin::). `_comp_cd'
+modifies the value of IFS so that it contains only a newline to
+accommodate file names containing spaces and tabs - `compgen' prints
+the possible completions it generates one per line.
+
+ Possible completions go into the COMPREPLY array variable, one
+completion per array element. The programmable completion system
+retrieves the completions from there when the function returns.
+
+ # A completion function for the cd builtin
+ # based on the cd completion function from the bash_completion package
+ _comp_cd()
+ {
+ local IFS=$' \t\n' # normalize IFS
+ local cur _skipdot _cdpath
+ local i j k
+
+ # Tilde expansion, with side effect of expanding tilde to full pathname
+ case "$2" in
+ \~*) eval cur="$2" ;;
+ *) cur=$2 ;;
+ esac
+
+ # no cdpath or absolute pathname -- straight directory completion
+ if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
+ # compgen prints paths one per line; could also use while loop
+ IFS=$'\n'
+ COMPREPLY=( $(compgen -d -- "$cur") )
+ IFS=$' \t\n'
+ # CDPATH+directories in the current directory if not in CDPATH
+ else
+ IFS=$'\n'
+ _skipdot=false
+ # preprocess CDPATH to convert null directory names to .
+ _cdpath=${CDPATH/#:/.:}
+ _cdpath=${_cdpath//::/:.:}
+ _cdpath=${_cdpath/%:/:.}
+ for i in ${_cdpath//:/$'\n'}; do
+ if [[ $i -ef . ]]; then _skipdot=true; fi
+ k="${#COMPREPLY[@]}"
+ for j in $( compgen -d -- "$i/$cur" ); do
+ COMPREPLY[k++]=${j#$i/} # cut off directory
+ done
+ done
+ $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
+ IFS=$' \t\n'
+ fi
+
+ # variable names if appropriate shell option set and no completions
+ if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
+ COMPREPLY=( $(compgen -v -- "$cur") )
+ fi
+
+ return 0
+ }
+
+ We install the completion function using the `-F' option to
+`complete':
+
+ # Tell readline to quote appropriate and append slashes to directories;
+ # use the bash default completion for other arguments
+ complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
+
+Since we'd like Bash and Readline to take care of some of the other
+details for us, we use several other options to tell Bash and Readline
+what to do. The `-o filenames' option tells Readline that the possible
+completions should be treated as filenames, and quoted appropriately.
+That option will also cause Readline to append a slash to filenames it
+can determine are directories (which is why we might want to extend
+`_comp_cd' to append a slash if we're using directories found via
+CDPATH: Readline can't tell those completions are directories). The
+`-o nospace' option tells Readline to not append a space character to
+the directory name, in case we want to append to it. The `-o
+bashdefault' option brings in the rest of the "Bash default"
+completions - possible completion that Bash adds to the default Readline
+set. These include things like command name completion, variable
+completion for words beginning with `{', completions containing pathname
+expansion patterns (*note Filename Expansion::), and so on.
+
+ Once installed using `complete', `_comp_cd' will be called every
+time we attempt word completion for a `cd' command.
+
+ Many more examples - an extensive collection of completions for most
+of the common GNU, Unix, and Linux commands - are available as part of
+the bash_completion project. This is installed by default on many
+GNU/Linux distributions. Originally written by Ian Macdonald, the
+project now lives at `http://bash-completion.alioth.debian.org/'.
+There are ports for other systems such as Solaris and Mac OS X.
+
+ An older version of the bash_completion package is distributed with
+bash in the `examples/complete' subdirectory.
+
+\1f
File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
9 Using History Interactively
named by the `HISTFILE' variable (default `~/.bash_history'). The file
named by the value of `HISTFILE' is truncated, if necessary, to contain
no more than the number of lines specified by the value of the
-`HISTFILESIZE' variable. When an interactive shell exits, the last
-`$HISTSIZE' lines are copied from the history list to the file named by
-`$HISTFILE'. If the `histappend' shell option is set (*note Bash
-Builtins::), the lines are appended to the history file, otherwise the
-history file is overwritten. If `HISTFILE' is unset, or if the history
-file is unwritable, the history is not saved. After saving the
+`HISTFILESIZE' variable. When a shell with history enabled exits, the
+last `$HISTSIZE' lines are copied from the history list to the file
+named by `$HISTFILE'. If the `histappend' shell option is set (*note
+Bash Builtins::), the lines are appended to the history file, otherwise
+the history file is overwritten. If `HISTFILE' is unset, or if the
+history file is unwritable, the history is not saved. After saving the
history, the history file is truncated to contain no more than
-`$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
-performed.
+`$HISTFILESIZE' lines. If `HISTFILESIZE' is unset, or set to null, a
+non-numeric value, or a numeric value less than zero, the history file
+is not truncated.
If the `HISTTIMEFORMAT' is set, the time stamp information
associated with each history entry is written to the history file,
`fc [-e ENAME] [-lnr] [FIRST] [LAST]'
`fc -s [PAT=REP] [COMMAND]'
- Fix Command. In the first form, a range of commands from FIRST to
- LAST is selected from the history list. Both FIRST and LAST may
- be specified as a string (to locate the most recent command
- beginning with that string) or as a number (an index into the
- history list, where a negative number is used as an offset from the
- current command number). If LAST is not specified it is set to
- FIRST. If FIRST is not specified it is set to the previous
- command for editing and -16 for listing. If the `-l' flag is
- given, the commands are listed on standard output. The `-n' flag
- suppresses the command numbers when listing. The `-r' flag
- reverses the order of the listing. Otherwise, the editor given by
- ENAME is invoked on a file containing those commands. If ENAME is
- not given, the value of the following variable expansion is used:
- `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
- `FCEDIT' variable if set, or the value of the `EDITOR' variable if
- that is set, or `vi' if neither is set. When editing is complete,
- the edited commands are echoed and executed.
+ The first form selects a range of commands from FIRST to LAST from
+ the history list and displays or edits and re-executes them. Both
+ FIRST and LAST may be specified as a string (to locate the most
+ recent command beginning with that string) or as a number (an
+ index into the history list, where a negative number is used as an
+ offset from the current command number). If LAST is not specified
+ it is set to FIRST. If FIRST is not specified it is set to the
+ previous command for editing and -16 for listing. If the `-l'
+ flag is given, the commands are listed on standard output. The
+ `-n' flag suppresses the command numbers when listing. The `-r'
+ flag reverses the order of the listing. Otherwise, the editor
+ given by ENAME is invoked on a file containing those commands. If
+ ENAME is not given, the value of the following variable expansion
+ is used: `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value
+ of the `FCEDIT' variable if set, or the value of the `EDITOR'
+ variable if that is set, or `vi' if neither is set. When editing
+ is complete, the edited commands are echoed and executed.
In the second form, COMMAND is re-executed after each instance of
- PAT in the selected command is replaced by REP.
+ PAT in the selected command is replaced by REP. COMMAND is
+ intepreted the same as FIRST above.
A useful alias to use with the `fc' command is `r='fc -s'', so
that typing `r cc' runs the last command beginning with `cc' and
session.
`-r'
- Read the current history file and append its contents to the
- history list.
+ Read the history file and append its contents to the history
+ list.
`-w'
- Write out the current history to the history file.
+ Write out the current history list to the history file.
`-p'
Perform history substitution on the ARGs and display the
mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
considered for the next release.
- The file `configure.in' is used to create `configure' by a program
-called Autoconf. You only need `configure.in' if you want to change it
+ The file `configure.ac' is used to create `configure' by a program
+called Autoconf. You only need `configure.ac' if you want to change it
or regenerate `configure' using a newer version of Autoconf. If you do
this, make sure you are using Autoconf version 2.50 or newer.
following options, but it is processed first, so individual options may
be enabled using `enable-FEATURE'.
- All of the following options except for `disabled-builtins' and
-`xpg-echo-default' are enabled by default, unless the operating system
-does not provide the necessary support.
+ All of the following options except for `disabled-builtins',
+`directpand-default', and `xpg-echo-default' are enabled by default,
+unless the operating system does not provide the necessary support.
`--enable-alias'
Allow alias expansion and include the `alias' and `unalias'
`--enable-debugger'
Include support for the bash debugger (distributed separately).
+`--enable-direxpand-default'
+ Cause the `direxpand' shell option (*note The Shopt Builtin::) to
+ be enabled by default when the shell starts. It is normally
+ disabled by default.
+
`--enable-directory-stack'
Include support for a `csh'-like directory stack and the `pushd',
`popd', and `dirs' builtins (*note The Directory Stack::).
Set the default value of the EXTGLOB shell option described above
under *note The Shopt Builtin:: to be enabled.
+`--enable-glob-asciirange-default'
+ Set the default value of the GLOBASCIIRANGES shell option described
+ above under *note The Shopt Builtin:: to be enabled. This
+ controls the behavior of character ranges when used in pattern
+ matching bracket expressions.
+
`--enable-help-builtin'
Include the `help' builtin, which displays help on shell builtins
and variables (*note Bash Builtins::).
`--enable-prompt-string-decoding'
Turn on the interpretation of a number of backslash-escaped
characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
- strings. See *note Printing a Prompt::, for a complete list of
- prompt string escape sequences.
+ strings. See *note Controlling the Prompt::, for a complete list
+ of prompt string escape sequences.
`--enable-readline'
Include support for command-line editing and history with the Bash
Specification, version 3. *Note Bash Builtins::, for a
description of the escape sequences that `echo' recognizes.
-
The file `config-top.h' contains C Preprocessor `#define' statements
for options which are not settable from `configure'. Some of these are
not meant to be changed; beware of the consequences if you do. Read
`bashbug' inserts the first three items automatically into the template
it provides for filing a bug report.
- Please send all reports concerning this manual to
-<chet.ramey@case.edu>.
+ Please send all reports concerning this manual to <bug-bash@gnu.org>.
\1f
File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
PATTERN and replaces it with REPLACEMENT in the value of `var', is
available (*note Shell Parameter Expansion::).
- * The expansion `${!PREFIX}*' expansion, which expands to the names
+ * The expansion `${!PREFIX*}' expansion, which expands to the names
of all shell variables whose names begin with PREFIX, is available
(*note Shell Parameter Expansion::).
not all words (*note Word Splitting::). This closes a
longstanding shell security hole.
+ * The filename expansion bracket expression code uses `!' and `^' to
+ negate the set of characters between the brackets. The Bourne
+ shell uses only `!'.
+
* Bash implements the full set of POSIX filename expansion operators,
including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
SYMBOLS (*note Filename Expansion::).
as the value of the `DIRSTACK' shell variable.
* Bash interprets special backslash-escaped characters in the prompt
- strings when interactive (*note Printing a Prompt::).
+ strings when interactive (*note Controlling the Prompt::).
* The Bash restricted mode is more useful (*note The Restricted
Shell::); the SVR4.2 shell restricted mode is too limited.
* Menu:
* .: Bourne Shell Builtins.
- (line 16)
+ (line 17)
* :: Bourne Shell Builtins.
(line 11)
* [: Bourne Shell Builtins.
- (line 217)
+ (line 258)
* alias: Bash Builtins. (line 11)
* bg: Job Control Builtins.
(line 7)
* bind: Bash Builtins. (line 21)
* break: Bourne Shell Builtins.
- (line 29)
-* builtin: Bash Builtins. (line 98)
-* caller: Bash Builtins. (line 106)
+ (line 31)
+* builtin: Bash Builtins. (line 102)
+* caller: Bash Builtins. (line 111)
* cd: Bourne Shell Builtins.
- (line 36)
-* command: Bash Builtins. (line 123)
+ (line 39)
+* command: Bash Builtins. (line 129)
* compgen: Programmable Completion Builtins.
- (line 10)
+ (line 12)
* complete: Programmable Completion Builtins.
- (line 28)
+ (line 30)
* compopt: Programmable Completion Builtins.
- (line 217)
+ (line 228)
* continue: Bourne Shell Builtins.
- (line 58)
-* declare: Bash Builtins. (line 142)
+ (line 80)
+* declare: Bash Builtins. (line 149)
* dirs: Directory Stack Builtins.
(line 7)
* disown: Job Control Builtins.
- (line 83)
-* echo: Bash Builtins. (line 226)
-* enable: Bash Builtins. (line 287)
+ (line 89)
+* echo: Bash Builtins. (line 245)
+* enable: Bash Builtins. (line 307)
* eval: Bourne Shell Builtins.
- (line 66)
+ (line 89)
* exec: Bourne Shell Builtins.
- (line 73)
+ (line 97)
* exit: Bourne Shell Builtins.
- (line 85)
+ (line 114)
* export: Bourne Shell Builtins.
- (line 91)
+ (line 121)
* fc: Bash History Builtins.
(line 10)
* fg: Job Control Builtins.
- (line 16)
+ (line 17)
* getopts: Bourne Shell Builtins.
- (line 106)
+ (line 137)
* hash: Bourne Shell Builtins.
- (line 148)
-* help: Bash Builtins. (line 315)
+ (line 180)
+* help: Bash Builtins. (line 336)
* history: Bash History Builtins.
- (line 39)
+ (line 40)
* jobs: Job Control Builtins.
- (line 25)
+ (line 27)
* kill: Job Control Builtins.
- (line 57)
-* let: Bash Builtins. (line 335)
-* local: Bash Builtins. (line 342)
-* logout: Bash Builtins. (line 352)
-* mapfile: Bash Builtins. (line 356)
+ (line 59)
+* let: Bash Builtins. (line 357)
+* local: Bash Builtins. (line 365)
+* logout: Bash Builtins. (line 376)
+* mapfile: Bash Builtins. (line 381)
* popd: Directory Stack Builtins.
- (line 37)
-* printf: Bash Builtins. (line 402)
+ (line 39)
+* printf: Bash Builtins. (line 429)
* pushd: Directory Stack Builtins.
- (line 58)
+ (line 61)
* pwd: Bourne Shell Builtins.
- (line 167)
-* read: Bash Builtins. (line 447)
-* readarray: Bash Builtins. (line 527)
+ (line 200)
+* read: Bash Builtins. (line 477)
+* readarray: Bash Builtins. (line 564)
* readonly: Bourne Shell Builtins.
- (line 176)
+ (line 210)
* return: Bourne Shell Builtins.
- (line 192)
+ (line 229)
* set: The Set Builtin. (line 11)
* shift: Bourne Shell Builtins.
- (line 205)
+ (line 245)
* shopt: The Shopt Builtin. (line 9)
-* source: Bash Builtins. (line 535)
+* source: Bash Builtins. (line 573)
* suspend: Job Control Builtins.
- (line 94)
+ (line 101)
* test: Bourne Shell Builtins.
- (line 217)
+ (line 258)
* times: Bourne Shell Builtins.
- (line 290)
+ (line 334)
* trap: Bourne Shell Builtins.
- (line 295)
-* type: Bash Builtins. (line 539)
-* typeset: Bash Builtins. (line 570)
-* ulimit: Bash Builtins. (line 576)
+ (line 340)
+* type: Bash Builtins. (line 578)
+* typeset: Bash Builtins. (line 610)
+* ulimit: Bash Builtins. (line 616)
* umask: Bourne Shell Builtins.
- (line 341)
-* unalias: Bash Builtins. (line 665)
+ (line 389)
+* unalias: Bash Builtins. (line 707)
* unset: Bourne Shell Builtins.
- (line 358)
+ (line 407)
* wait: Job Control Builtins.
- (line 73)
+ (line 76)
\1f
File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
* !: Pipelines. (line 9)
* [[: Conditional Constructs.
- (line 117)
+ (line 119)
* ]]: Conditional Constructs.
- (line 117)
+ (line 119)
* case: Conditional Constructs.
(line 28)
* do: Looping Constructs. (line 12)
(line 28)
* fi: Conditional Constructs.
(line 7)
-* for: Looping Constructs. (line 29)
+* for: Looping Constructs. (line 32)
* function: Shell Functions. (line 13)
* if: Conditional Constructs.
(line 7)
* in: Conditional Constructs.
(line 28)
* select: Conditional Constructs.
- (line 76)
+ (line 78)
* then: Conditional Constructs.
(line 7)
* time: Pipelines. (line 9)
* until: Looping Constructs. (line 12)
-* while: Looping Constructs. (line 20)
+* while: Looping Constructs. (line 22)
* {: Command Grouping. (line 21)
* }: Command Grouping. (line 21)
\0\b[index\0\b]
* Menu:
-* !: Special Parameters. (line 46)
-* #: Special Parameters. (line 30)
-* $: Special Parameters. (line 42)
+* !: Special Parameters. (line 50)
+* #: Special Parameters. (line 33)
+* $: Special Parameters. (line 45)
+* $!: Special Parameters. (line 51)
+* $#: Special Parameters. (line 34)
+* $$: Special Parameters. (line 46)
+* $*: Special Parameters. (line 10)
+* $-: Special Parameters. (line 41)
+* $0: Special Parameters. (line 56)
+* $?: Special Parameters. (line 37)
+* $@: Special Parameters. (line 23)
+* $_: Special Parameters. (line 65)
* *: Special Parameters. (line 9)
-* -: Special Parameters. (line 37)
-* 0: Special Parameters. (line 50)
-* ?: Special Parameters. (line 33)
-* @: Special Parameters. (line 19)
-* _: Special Parameters. (line 59)
+* -: Special Parameters. (line 40)
+* 0: Special Parameters. (line 55)
+* ?: Special Parameters. (line 36)
+* @: Special Parameters. (line 22)
+* _: Special Parameters. (line 64)
* auto_resume: Job Control Variables.
(line 6)
* BASH: Bash Variables. (line 13)
* BASH_ARGV: Bash Variables. (line 47)
* BASH_CMDS: Bash Variables. (line 57)
* BASH_COMMAND: Bash Variables. (line 64)
-* BASH_ENV: Bash Variables. (line 69)
-* BASH_EXECUTION_STRING: Bash Variables. (line 75)
-* BASH_LINENO: Bash Variables. (line 78)
-* BASH_REMATCH: Bash Variables. (line 86)
-* BASH_SOURCE: Bash Variables. (line 94)
-* BASH_SUBSHELL: Bash Variables. (line 101)
-* BASH_VERSINFO: Bash Variables. (line 105)
-* BASH_VERSION: Bash Variables. (line 129)
-* BASH_XTRACEFD: Bash Variables. (line 132)
+* BASH_COMPAT: Bash Variables. (line 69)
+* BASH_ENV: Bash Variables. (line 84)
+* BASH_EXECUTION_STRING: Bash Variables. (line 90)
+* BASH_LINENO: Bash Variables. (line 93)
+* BASH_REMATCH: Bash Variables. (line 101)
+* BASH_SOURCE: Bash Variables. (line 109)
+* BASH_SUBSHELL: Bash Variables. (line 116)
+* BASH_VERSINFO: Bash Variables. (line 121)
+* BASH_VERSION: Bash Variables. (line 144)
+* BASH_XTRACEFD: Bash Variables. (line 147)
* BASHOPTS: Bash Variables. (line 16)
* BASHPID: Bash Variables. (line 25)
* bell-style: Readline Init File Syntax.
(line 45)
* CDPATH: Bourne Shell Variables.
(line 9)
-* COLUMNS: Bash Variables. (line 143)
-* comment-begin: Readline Init File Syntax.
+* CHILD_MAX: Bash Variables. (line 158)
+* colored-stats: Readline Init File Syntax.
(line 50)
-* COMP_CWORD: Bash Variables. (line 148)
-* COMP_KEY: Bash Variables. (line 177)
-* COMP_LINE: Bash Variables. (line 154)
-* COMP_POINT: Bash Variables. (line 159)
-* COMP_TYPE: Bash Variables. (line 167)
-* COMP_WORDBREAKS: Bash Variables. (line 181)
-* COMP_WORDS: Bash Variables. (line 187)
+* COLUMNS: Bash Variables. (line 165)
+* comment-begin: Readline Init File Syntax.
+ (line 56)
+* COMP_CWORD: Bash Variables. (line 171)
+* COMP_KEY: Bash Variables. (line 200)
+* COMP_LINE: Bash Variables. (line 177)
+* COMP_POINT: Bash Variables. (line 182)
+* COMP_TYPE: Bash Variables. (line 190)
+* COMP_WORDBREAKS: Bash Variables. (line 204)
+* COMP_WORDS: Bash Variables. (line 210)
* completion-display-width: Readline Init File Syntax.
- (line 55)
+ (line 61)
* completion-ignore-case: Readline Init File Syntax.
- (line 62)
+ (line 68)
* completion-map-case: Readline Init File Syntax.
- (line 67)
-* completion-prefix-display-length: Readline Init File Syntax.
(line 73)
+* completion-prefix-display-length: Readline Init File Syntax.
+ (line 79)
* completion-query-items: Readline Init File Syntax.
- (line 80)
-* COMPREPLY: Bash Variables. (line 195)
+ (line 86)
+* COMPREPLY: Bash Variables. (line 218)
* convert-meta: Readline Init File Syntax.
- (line 90)
-* COPROC: Bash Variables. (line 200)
-* DIRSTACK: Bash Variables. (line 204)
-* disable-completion: Readline Init File Syntax.
(line 96)
+* COPROC: Bash Variables. (line 224)
+* DIRSTACK: Bash Variables. (line 228)
+* disable-completion: Readline Init File Syntax.
+ (line 102)
* editing-mode: Readline Init File Syntax.
- (line 101)
-* EMACS: Bash Variables. (line 214)
+ (line 107)
+* EMACS: Bash Variables. (line 238)
* enable-keypad: Readline Init File Syntax.
- (line 112)
-* ENV: Bash Variables. (line 219)
-* EUID: Bash Variables. (line 223)
+ (line 118)
+* ENV: Bash Variables. (line 243)
+* EUID: Bash Variables. (line 247)
* expand-tilde: Readline Init File Syntax.
- (line 123)
-* FCEDIT: Bash Variables. (line 227)
-* FIGNORE: Bash Variables. (line 231)
-* FUNCNAME: Bash Variables. (line 237)
-* FUNCNEST: Bash Variables. (line 255)
-* GLOBIGNORE: Bash Variables. (line 260)
-* GROUPS: Bash Variables. (line 266)
-* histchars: Bash Variables. (line 272)
-* HISTCMD: Bash Variables. (line 287)
-* HISTCONTROL: Bash Variables. (line 292)
-* HISTFILE: Bash Variables. (line 308)
-* HISTFILESIZE: Bash Variables. (line 312)
-* HISTIGNORE: Bash Variables. (line 320)
+ (line 129)
+* FCEDIT: Bash Variables. (line 251)
+* FIGNORE: Bash Variables. (line 255)
+* FUNCNAME: Bash Variables. (line 261)
+* FUNCNEST: Bash Variables. (line 279)
+* GLOBIGNORE: Bash Variables. (line 284)
+* GROUPS: Bash Variables. (line 290)
+* histchars: Bash Variables. (line 296)
+* HISTCMD: Bash Variables. (line 311)
+* HISTCONTROL: Bash Variables. (line 316)
+* HISTFILE: Bash Variables. (line 332)
+* HISTFILESIZE: Bash Variables. (line 336)
+* HISTIGNORE: Bash Variables. (line 347)
* history-preserve-point: Readline Init File Syntax.
- (line 127)
-* history-size: Readline Init File Syntax.
(line 133)
-* HISTSIZE: Bash Variables. (line 339)
-* HISTTIMEFORMAT: Bash Variables. (line 343)
+* history-size: Readline Init File Syntax.
+ (line 139)
+* HISTSIZE: Bash Variables. (line 366)
+* HISTTIMEFORMAT: Bash Variables. (line 373)
* HOME: Bourne Shell Variables.
(line 13)
* horizontal-scroll-mode: Readline Init File Syntax.
- (line 138)
-* HOSTFILE: Bash Variables. (line 352)
-* HOSTNAME: Bash Variables. (line 363)
-* HOSTTYPE: Bash Variables. (line 366)
+ (line 146)
+* HOSTFILE: Bash Variables. (line 382)
+* HOSTNAME: Bash Variables. (line 393)
+* HOSTTYPE: Bash Variables. (line 396)
* IFS: Bourne Shell Variables.
(line 18)
-* IGNOREEOF: Bash Variables. (line 369)
+* IGNOREEOF: Bash Variables. (line 399)
* input-meta: Readline Init File Syntax.
- (line 145)
-* INPUTRC: Bash Variables. (line 379)
+ (line 153)
+* INPUTRC: Bash Variables. (line 409)
* isearch-terminators: Readline Init File Syntax.
- (line 152)
+ (line 160)
* keymap: Readline Init File Syntax.
- (line 159)
-* LANG: Bash Variables. (line 383)
-* LC_ALL: Bash Variables. (line 387)
-* LC_COLLATE: Bash Variables. (line 391)
-* LC_CTYPE: Bash Variables. (line 398)
+ (line 167)
+* LANG: Bash Variables. (line 413)
+* LC_ALL: Bash Variables. (line 417)
+* LC_COLLATE: Bash Variables. (line 421)
+* LC_CTYPE: Bash Variables. (line 428)
* LC_MESSAGES <1>: Locale Translation. (line 11)
-* LC_MESSAGES: Bash Variables. (line 403)
-* LC_NUMERIC: Bash Variables. (line 407)
-* LINENO: Bash Variables. (line 411)
-* LINES: Bash Variables. (line 415)
-* MACHTYPE: Bash Variables. (line 420)
+* LC_MESSAGES: Bash Variables. (line 433)
+* LC_NUMERIC: Bash Variables. (line 437)
+* LINENO: Bash Variables. (line 441)
+* LINES: Bash Variables. (line 445)
+* MACHTYPE: Bash Variables. (line 451)
* MAIL: Bourne Shell Variables.
(line 22)
-* MAILCHECK: Bash Variables. (line 424)
+* MAILCHECK: Bash Variables. (line 455)
* MAILPATH: Bourne Shell Variables.
(line 27)
-* MAPFILE: Bash Variables. (line 432)
+* MAPFILE: Bash Variables. (line 463)
* mark-modified-lines: Readline Init File Syntax.
- (line 172)
+ (line 196)
* mark-symlinked-directories: Readline Init File Syntax.
- (line 177)
+ (line 201)
* match-hidden-files: Readline Init File Syntax.
- (line 182)
+ (line 206)
* menu-complete-display-prefix: Readline Init File Syntax.
- (line 189)
+ (line 213)
* meta-flag: Readline Init File Syntax.
- (line 145)
-* OLDPWD: Bash Variables. (line 436)
+ (line 153)
+* OLDPWD: Bash Variables. (line 467)
* OPTARG: Bourne Shell Variables.
(line 34)
-* OPTERR: Bash Variables. (line 439)
+* OPTERR: Bash Variables. (line 470)
* OPTIND: Bourne Shell Variables.
(line 38)
-* OSTYPE: Bash Variables. (line 443)
+* OSTYPE: Bash Variables. (line 474)
* output-meta: Readline Init File Syntax.
- (line 194)
+ (line 218)
* page-completions: Readline Init File Syntax.
- (line 199)
+ (line 223)
* PATH: Bourne Shell Variables.
(line 42)
-* PIPESTATUS: Bash Variables. (line 446)
-* POSIXLY_CORRECT: Bash Variables. (line 451)
-* PPID: Bash Variables. (line 460)
-* PROMPT_COMMAND: Bash Variables. (line 464)
-* PROMPT_DIRTRIM: Bash Variables. (line 468)
+* PIPESTATUS: Bash Variables. (line 477)
+* POSIXLY_CORRECT: Bash Variables. (line 482)
+* PPID: Bash Variables. (line 491)
+* PROMPT_COMMAND: Bash Variables. (line 495)
+* PROMPT_DIRTRIM: Bash Variables. (line 499)
* PS1: Bourne Shell Variables.
(line 48)
* PS2: Bourne Shell Variables.
(line 53)
-* PS3: Bash Variables. (line 474)
-* PS4: Bash Variables. (line 479)
-* PWD: Bash Variables. (line 485)
-* RANDOM: Bash Variables. (line 488)
-* READLINE_LINE: Bash Variables. (line 493)
-* READLINE_POINT: Bash Variables. (line 497)
-* REPLY: Bash Variables. (line 501)
+* PS3: Bash Variables. (line 505)
+* PS4: Bash Variables. (line 510)
+* PWD: Bash Variables. (line 516)
+* RANDOM: Bash Variables. (line 519)
+* READLINE_LINE: Bash Variables. (line 524)
+* READLINE_POINT: Bash Variables. (line 528)
+* REPLY: Bash Variables. (line 532)
* revert-all-at-newline: Readline Init File Syntax.
- (line 209)
-* SECONDS: Bash Variables. (line 504)
-* SHELL: Bash Variables. (line 510)
-* SHELLOPTS: Bash Variables. (line 515)
-* SHLVL: Bash Variables. (line 524)
+ (line 233)
+* SECONDS: Bash Variables. (line 535)
+* SHELL: Bash Variables. (line 541)
+* SHELLOPTS: Bash Variables. (line 546)
+* SHLVL: Bash Variables. (line 555)
* show-all-if-ambiguous: Readline Init File Syntax.
- (line 215)
+ (line 239)
* show-all-if-unmodified: Readline Init File Syntax.
- (line 221)
+ (line 245)
+* show-mode-in-prompt: Readline Init File Syntax.
+ (line 254)
* skip-completed-text: Readline Init File Syntax.
- (line 230)
+ (line 259)
* TEXTDOMAIN: Locale Translation. (line 11)
* TEXTDOMAINDIR: Locale Translation. (line 11)
-* TIMEFORMAT: Bash Variables. (line 529)
-* TMOUT: Bash Variables. (line 567)
-* TMPDIR: Bash Variables. (line 579)
-* UID: Bash Variables. (line 583)
+* TIMEFORMAT: Bash Variables. (line 560)
+* TMOUT: Bash Variables. (line 598)
+* TMPDIR: Bash Variables. (line 610)
+* UID: Bash Variables. (line 614)
* visible-stats: Readline Init File Syntax.
- (line 243)
+ (line 272)
\1f
File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
(line 10)
* accept-line (Newline or Return): Commands For History. (line 6)
* backward-char (C-b): Commands For Moving. (line 15)
-* backward-delete-char (Rubout): Commands For Text. (line 11)
+* backward-delete-char (Rubout): Commands For Text. (line 17)
* backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
* backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
* backward-word (M-b): Commands For Moving. (line 22)
* beginning-of-history (M-<): Commands For History. (line 20)
* beginning-of-line (C-a): Commands For Moving. (line 6)
* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
-* capitalize-word (M-c): Commands For Text. (line 46)
+* capitalize-word (M-c): Commands For Text. (line 52)
* character-search (C-]): Miscellaneous Commands.
(line 41)
* character-search-backward (M-C-]): Miscellaneous Commands.
* copy-backward-word (): Commands For Killing. (line 58)
* copy-forward-word (): Commands For Killing. (line 63)
* copy-region-as-kill (): Commands For Killing. (line 54)
-* delete-char (C-d): Commands For Text. (line 6)
+* delete-char (C-d): Commands For Text. (line 12)
* delete-char-or-list (): Commands For Completion.
(line 43)
* delete-horizontal-space (): Commands For Killing. (line 46)
* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
* do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
(line 14)
-* downcase-word (M-l): Commands For Text. (line 42)
+* downcase-word (M-l): Commands For Text. (line 48)
* dump-functions (): Miscellaneous Commands.
(line 73)
* dump-macros (): Miscellaneous Commands.
* dump-variables (): Miscellaneous Commands.
(line 79)
* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
+* end-of-file (usually C-d): Commands For Text. (line 6)
* end-of-history (M->): Commands For History. (line 23)
* end-of-line (C-e): Commands For Moving. (line 9)
* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
(line 36)
-* forward-backward-delete-char (): Commands For Text. (line 15)
+* forward-backward-delete-char (): Commands For Text. (line 21)
* forward-char (C-f): Commands For Moving. (line 12)
* forward-search-history (C-s): Commands For History. (line 31)
* forward-word (M-f): Commands For Moving. (line 18)
-* history-search-backward (): Commands For History. (line 51)
+* history-search-backward (): Commands For History. (line 52)
* history-search-forward (): Commands For History. (line 46)
+* history-substr-search-backward (): Commands For History. (line 64)
+* history-substr-search-forward (): Commands For History. (line 58)
* insert-comment (M-#): Miscellaneous Commands.
(line 60)
* insert-completions (M-*): Commands For Completion.
(line 41)
* non-incremental-reverse-search-history (M-p): Commands For History.
(line 36)
-* overwrite-mode (): Commands For Text. (line 50)
+* overwrite-mode (): Commands For Text. (line 56)
* possible-completions (M-?): Commands For Completion.
(line 15)
* prefix-meta (<ESC>): Miscellaneous Commands.
(line 18)
* previous-history (C-p): Commands For History. (line 13)
-* quoted-insert (C-q or C-v): Commands For Text. (line 20)
+* print-last-kbd-macro (): Keyboard Macros. (line 17)
+* quoted-insert (C-q or C-v): Commands For Text. (line 26)
* re-read-init-file (C-x C-r): Miscellaneous Commands.
(line 6)
* redraw-current-line (): Commands For Moving. (line 38)
* reverse-search-history (C-r): Commands For History. (line 27)
* revert-line (M-r): Miscellaneous Commands.
(line 25)
-* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
+* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 30)
* set-mark (C-@): Miscellaneous Commands.
(line 32)
* skip-csi-sequence (): Miscellaneous Commands.
(line 51)
* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
-* transpose-chars (C-t): Commands For Text. (line 27)
-* transpose-words (M-t): Commands For Text. (line 33)
+* transpose-chars (C-t): Commands For Text. (line 33)
+* transpose-words (M-t): Commands For Text. (line 39)
* undo (C-_ or C-x C-u): Miscellaneous Commands.
(line 22)
* universal-argument (): Numeric Arguments. (line 10)
* unix-filename-rubout (): Commands For Killing. (line 41)
* unix-line-discard (C-u): Commands For Killing. (line 12)
* unix-word-rubout (C-w): Commands For Killing. (line 37)
-* upcase-word (M-u): Commands For Text. (line 38)
+* upcase-word (M-u): Commands For Text. (line 44)
* yank (C-y): Commands For Killing. (line 68)
-* yank-last-arg (M-. or M-_): Commands For History. (line 65)
-* yank-nth-arg (M-C-y): Commands For History. (line 56)
+* yank-last-arg (M-. or M-_): Commands For History. (line 79)
+* yank-nth-arg (M-C-y): Commands For History. (line 70)
* yank-pop (M-y): Commands For Killing. (line 71)
\1f
* history expansion: History Interaction. (line 6)
* history list: Bash History Facilities.
(line 6)
-* History, how to use: Programmable Completion Builtins.
- (line 237)
+* History, how to use: A Programmable Completion Example.
+ (line 114)
* identifier: Definitions. (line 51)
* initialization file, readline: Readline Init File. (line 6)
* installation: Basic Installation. (line 6)
* interaction, readline: Readline Interaction.
(line 6)
* interactive shell <1>: Interactive Shells. (line 6)
-* interactive shell: Invoking Bash. (line 127)
+* interactive shell: Invoking Bash. (line 125)
* internationalization: Locale Translation. (line 6)
* job: Definitions. (line 38)
* job control <1>: Job Control Basics. (line 6)
* killing text: Readline Killing Commands.
(line 6)
* localization: Locale Translation. (line 6)
-* login shell: Invoking Bash. (line 124)
+* login shell: Invoking Bash. (line 122)
* matching, pattern: Pattern Matching. (line 6)
* metacharacter: Definitions. (line 46)
* name: Definitions. (line 51)
(line 6)
* programmable completion: Programmable Completion.
(line 6)
-* prompting: Printing a Prompt. (line 6)
+* prompting: Controlling the Prompt.
+ (line 6)
* quoting: Quoting. (line 6)
* quoting, ANSI: ANSI-C Quoting. (line 6)
* Readline, how to use: Job Control Variables.
\1f
Tag Table:
-Node: Top\7f1346
-Node: Introduction\7f3185
-Node: What is Bash?\7f3413
-Node: What is a shell?\7f4526
-Node: Definitions\7f7066
-Node: Basic Shell Features\7f9984
-Node: Shell Syntax\7f11203
-Node: Shell Operation\7f12233
-Node: Quoting\7f13527
-Node: Escape Character\7f14830
-Node: Single Quotes\7f15315
-Node: Double Quotes\7f15663
-Node: ANSI-C Quoting\7f16788
-Node: Locale Translation\7f18032
-Node: Comments\7f18928
-Node: Shell Commands\7f19546
-Node: Simple Commands\7f20418
-Node: Pipelines\7f21049
-Node: Lists\7f23743
-Node: Compound Commands\7f25472
-Node: Looping Constructs\7f26276
-Node: Conditional Constructs\7f28735
-Node: Command Grouping\7f36848
-Node: Coprocesses\7f38327
-Node: GNU Parallel\7f39992
-Node: Shell Functions\7f42460
-Node: Shell Parameters\7f47404
-Node: Positional Parameters\7f49820
-Node: Special Parameters\7f50720
-Node: Shell Expansions\7f53684
-Node: Brace Expansion\7f55609
-Node: Tilde Expansion\7f58364
-Node: Shell Parameter Expansion\7f60715
-Node: Command Substitution\7f69850
-Node: Arithmetic Expansion\7f71183
-Node: Process Substitution\7f72033
-Node: Word Splitting\7f73083
-Node: Filename Expansion\7f74706
-Node: Pattern Matching\7f76845
-Node: Quote Removal\7f80484
-Node: Redirections\7f80779
-Node: Executing Commands\7f89304
-Node: Simple Command Expansion\7f89974
-Node: Command Search and Execution\7f91904
-Node: Command Execution Environment\7f94241
-Node: Environment\7f97227
-Node: Exit Status\7f98887
-Node: Signals\7f100508
-Node: Shell Scripts\7f102476
-Node: Shell Builtin Commands\7f104994
-Node: Bourne Shell Builtins\7f107022
-Node: Bash Builtins\7f124952
-Node: Modifying Shell Behavior\7f151166
-Node: The Set Builtin\7f151511
-Node: The Shopt Builtin\7f161045
-Node: Special Builtins\7f173217
-Node: Shell Variables\7f174196
-Node: Bourne Shell Variables\7f174636
-Node: Bash Variables\7f176663
-Node: Bash Features\7f201572
-Node: Invoking Bash\7f202455
-Node: Bash Startup Files\7f208219
-Node: Interactive Shells\7f213240
-Node: What is an Interactive Shell?\7f213650
-Node: Is this Shell Interactive?\7f214299
-Node: Interactive Shell Behavior\7f215114
-Node: Bash Conditional Expressions\7f218394
-Node: Shell Arithmetic\7f222183
-Node: Aliases\7f224942
-Node: Arrays\7f227514
-Node: The Directory Stack\7f231629
-Node: Directory Stack Builtins\7f232343
-Node: Printing a Prompt\7f235235
-Node: The Restricted Shell\7f237987
-Node: Bash POSIX Mode\7f239819
-Node: Job Control\7f248480
-Node: Job Control Basics\7f248940
-Node: Job Control Builtins\7f253657
-Node: Job Control Variables\7f258021
-Node: Command Line Editing\7f259179
-Node: Introduction and Notation\7f260746
-Node: Readline Interaction\7f262368
-Node: Readline Bare Essentials\7f263559
-Node: Readline Movement Commands\7f265348
-Node: Readline Killing Commands\7f266313
-Node: Readline Arguments\7f268233
-Node: Searching\7f269277
-Node: Readline Init File\7f271463
-Node: Readline Init File Syntax\7f272610
-Node: Conditional Init Constructs\7f287952
-Node: Sample Init File\7f290485
-Node: Bindable Readline Commands\7f293602
-Node: Commands For Moving\7f294809
-Node: Commands For History\7f295953
-Node: Commands For Text\7f299388
-Node: Commands For Killing\7f302061
-Node: Numeric Arguments\7f304518
-Node: Commands For Completion\7f305657
-Node: Keyboard Macros\7f309849
-Node: Miscellaneous Commands\7f310420
-Node: Readline vi Mode\7f316226
-Node: Programmable Completion\7f317133
-Node: Programmable Completion Builtins\7f324343
-Node: Using History Interactively\7f333479
-Node: Bash History Facilities\7f334163
-Node: Bash History Builtins\7f337077
-Node: History Interaction\7f340934
-Node: Event Designators\7f343639
-Node: Word Designators\7f344861
-Node: Modifiers\7f346500
-Node: Installing Bash\7f347904
-Node: Basic Installation\7f349041
-Node: Compilers and Options\7f351733
-Node: Compiling For Multiple Architectures\7f352474
-Node: Installation Names\7f354138
-Node: Specifying the System Type\7f354956
-Node: Sharing Defaults\7f355672
-Node: Operation Controls\7f356345
-Node: Optional Features\7f357303
-Node: Reporting Bugs\7f366871
-Node: Major Differences From The Bourne Shell\7f368072
-Node: GNU Free Documentation License\7f384759
-Node: Indexes\7f409955
-Node: Builtin Index\7f410409
-Node: Reserved Word Index\7f417236
-Node: Variable Index\7f419684
-Node: Function Index\7f432779
-Node: Concept Index\7f439788
+Node: Top\7f930
+Node: Introduction\7f2848
+Node: What is Bash?\7f3076
+Node: What is a shell?\7f4189
+Node: Definitions\7f6728
+Node: Basic Shell Features\7f9646
+Node: Shell Syntax\7f10865
+Node: Shell Operation\7f11895
+Node: Quoting\7f13189
+Node: Escape Character\7f14492
+Node: Single Quotes\7f14977
+Node: Double Quotes\7f15325
+Node: ANSI-C Quoting\7f16450
+Node: Locale Translation\7f17694
+Node: Comments\7f18590
+Node: Shell Commands\7f19208
+Node: Simple Commands\7f20080
+Node: Pipelines\7f20711
+Node: Lists\7f23449
+Node: Compound Commands\7f25178
+Node: Looping Constructs\7f26184
+Node: Conditional Constructs\7f28647
+Node: Command Grouping\7f39577
+Node: Coprocesses\7f41056
+Node: GNU Parallel\7f42889
+Node: Shell Functions\7f46875
+Node: Shell Parameters\7f51959
+Node: Positional Parameters\7f56088
+Node: Special Parameters\7f56988
+Node: Shell Expansions\7f60327
+Node: Brace Expansion\7f62270
+Node: Tilde Expansion\7f65051
+Node: Shell Parameter Expansion\7f67400
+Node: Command Substitution\7f79694
+Node: Arithmetic Expansion\7f81027
+Node: Process Substitution\7f81959
+Node: Word Splitting\7f83009
+Node: Filename Expansion\7f84657
+Node: Pattern Matching\7f86822
+Node: Quote Removal\7f90522
+Node: Redirections\7f90817
+Node: Executing Commands\7f99981
+Node: Simple Command Expansion\7f100651
+Node: Command Search and Execution\7f102581
+Node: Command Execution Environment\7f104918
+Node: Environment\7f107904
+Node: Exit Status\7f109563
+Node: Signals\7f111185
+Node: Shell Scripts\7f113153
+Node: Shell Builtin Commands\7f115671
+Node: Bourne Shell Builtins\7f117699
+Node: Bash Builtins\7f137606
+Node: Modifying Shell Behavior\7f165232
+Node: The Set Builtin\7f165577
+Node: The Shopt Builtin\7f175903
+Node: Special Builtins\7f190324
+Node: Shell Variables\7f191303
+Node: Bourne Shell Variables\7f191743
+Node: Bash Variables\7f193774
+Node: Bash Features\7f220649
+Node: Invoking Bash\7f221548
+Node: Bash Startup Files\7f227326
+Node: Interactive Shells\7f232355
+Node: What is an Interactive Shell?\7f232765
+Node: Is this Shell Interactive?\7f233414
+Node: Interactive Shell Behavior\7f234229
+Node: Bash Conditional Expressions\7f237517
+Node: Shell Arithmetic\7f241519
+Node: Aliases\7f244295
+Node: Arrays\7f246851
+Node: The Directory Stack\7f251832
+Node: Directory Stack Builtins\7f252551
+Node: Controlling the Prompt\7f255507
+Node: The Restricted Shell\7f258279
+Node: Bash POSIX Mode\7f260116
+Node: Job Control\7f269502
+Node: Job Control Basics\7f269962
+Node: Job Control Builtins\7f274681
+Node: Job Control Variables\7f279152
+Node: Command Line Editing\7f280310
+Node: Introduction and Notation\7f281982
+Node: Readline Interaction\7f283604
+Node: Readline Bare Essentials\7f284795
+Node: Readline Movement Commands\7f286584
+Node: Readline Killing Commands\7f287549
+Node: Readline Arguments\7f289469
+Node: Searching\7f290513
+Node: Readline Init File\7f292699
+Node: Readline Init File Syntax\7f293846
+Node: Conditional Init Constructs\7f310832
+Node: Sample Init File\7f313365
+Node: Bindable Readline Commands\7f316483
+Node: Commands For Moving\7f317690
+Node: Commands For History\7f318834
+Node: Commands For Text\7f323019
+Node: Commands For Killing\7f325948
+Node: Numeric Arguments\7f328405
+Node: Commands For Completion\7f329544
+Node: Keyboard Macros\7f333736
+Node: Miscellaneous Commands\7f334424
+Node: Readline vi Mode\7f340230
+Node: Programmable Completion\7f341137
+Node: Programmable Completion Builtins\7f348413
+Node: A Programmable Completion Example\7f358159
+Node: Using History Interactively\7f363409
+Node: Bash History Facilities\7f364093
+Node: Bash History Builtins\7f367092
+Node: History Interaction\7f371020
+Node: Event Designators\7f373725
+Node: Word Designators\7f374947
+Node: Modifiers\7f376586
+Node: Installing Bash\7f377990
+Node: Basic Installation\7f379127
+Node: Compilers and Options\7f381819
+Node: Compiling For Multiple Architectures\7f382560
+Node: Installation Names\7f384224
+Node: Specifying the System Type\7f385042
+Node: Sharing Defaults\7f385758
+Node: Operation Controls\7f386431
+Node: Optional Features\7f387389
+Node: Reporting Bugs\7f397453
+Node: Major Differences From The Bourne Shell\7f398651
+Node: GNU Free Documentation License\7f415510
+Node: Indexes\7f440706
+Node: Builtin Index\7f441160
+Node: Reserved Word Index\7f447987
+Node: Variable Index\7f450435
+Node: Function Index\7f464615
+Node: Concept Index\7f471916
\1f
End Tag Table