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

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

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

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

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

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

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

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


File: bashref.info,  Node: Top,  Next: Introduction,  Prev: (dir),  Up: (dir)

Bash Features
*************

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

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

   Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.

   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.

   This manual is meant as a brief introduction to features found in
Bash.  The Bash manual page should be used as the definitive reference
on shell behavior.

* Menu:

* Introduction::		An introduction to the shell.

* Definitions::			Some definitions used in the rest of this
				manual.

* Basic Shell Features::	The shell "building blocks".

* Shell Builtin Commands::	Commands that are a part of the shell.

* Shell Variables::		Variables used or set by Bash.

* Bash Features::		Features found only in Bash.

* Job Control::			A chapter describing what job control is
				and how Bash allows you to use it.

* Using History Interactively::	Chapter dealing with history expansion
				rules.

* Command Line Editing::	Chapter describing the command line
				editing features.

* Installing Bash::		How to build and install Bash on your system.

* Reporting Bugs::		How to report bugs in Bash.

* Major Differences From The Bourne Shell::	A terse list of the differences
						between Bash and historical
						versions of /bin/sh.

* Builtin Index::		Index of Bash builtin commands.

* Reserved Word Index::		Index of Bash reserved words.

* Variable Index::		Quick reference helps you find the
				variable you want.

* Function Index::		Index of bindable Readline functions.

* Concept Index::		General index for concepts described in
				this manual.


File: bashref.info,  Node: Introduction,  Next: Definitions,  Prev: Top,  Up: Top

Introduction
************

* Menu:

* What is Bash?::		A short description of Bash.

* What is a shell?::		A brief introduction to shells.


File: bashref.info,  Node: What is Bash?,  Next: What is a shell?,  Up: Introduction

What is Bash?
=============

   Bash is the shell, or command language interpreter, for the GNU
operating system.  The name is an acronym for the `Bourne-Again SHell',
a pun on Stephen Bourne, the author of the direct ancestor of the
current Unix shell `/bin/sh', which appeared in the Seventh Edition
Bell Labs Research version of Unix.

   Bash is largely compatible with `sh' and incorporates useful
features from the Korn shell `ksh' and the C shell `csh'.  It is
intended to be a conformant implementation of the IEEE POSIX Shell and
Tools specification (IEEE Working Group 1003.2).  It offers functional
improvements over `sh' for both interactive and programming use.

   While the GNU operating system provides other shells, including a
version of `csh', Bash is the default shell.  Like other GNU software,
Bash is quite portable.  It currently runs on nearly every version of
Unix and a few other operating systems - independently-supported ports
exist for MS-DOS, OS/2, Windows 95/98, and Windows NT.


File: bashref.info,  Node: What is a shell?,  Prev: What is Bash?,  Up: Introduction

What is a shell?
================

   At its base, a shell is simply a macro processor that executes
commands.  A Unix shell is both a command interpreter, which provides
the user interface to the rich set of GNU utilities, and a programming
language, allowing these utilitites to be combined.  Files containing
commands can be created, and become commands themselves.  These new
commands have the same status as system commands in directories such as
`/bin', allowing users or groups to establish custom environments.

   A shell allows execution of GNU commands, both synchronously and
asynchronously.  The shell waits for synchronous commands to complete
before accepting more input; asynchronous commands continue to execute
in parallel with the shell while it reads and executes additional
commands.  The "redirection" constructs permit fine-grained control of
the input and output of those commands.  Moreover, the shell allows
control over the contents of commands' environments.  Shells may be
used interactively or non-interactively: they accept input typed from
the keyboard or from a file.

   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.

   While executing commands is essential, most of the power (and
complexity) of shells is due to their embedded programming languages.
Like any high-level language, the shell provides variables, flow
control constructs, quoting, and functions.

   Shells offer features geared specifically for interactive use rather
than to augment the programming language.  These interactive features
include job control, command line editing, history and aliases.  Each
of these features is described in this manual.


File: bashref.info,  Node: Definitions,  Next: Basic Shell Features,  Prev: Introduction,  Up: Top

Definitions
***********

   These definitions are used throughout the remainder of this manual.

`POSIX'
     A family of open system standards based on Unix.  Bash is
     concerned with POSIX 1003.2, the Shell and Tools Standard.

`blank'
     A space or tab character.

`builtin'
     A command that is implemented internally by the shell itself,
     rather than by an executable program somewhere in the file system.

`control operator'
     A `word' that performs a control function.  It is a `newline' or
     one of the following: `||', `&&', `&', `;', `;;', `|', `(', or `)'.

`exit status'
     The value returned by a command to its caller.  The value is
     restricted to eight bits, so the maximum value is 255.

`field'
     A unit of text that is the result of one of the shell expansions.
     After expansion, when executing a command, the resulting fields
     are used as the command name and arguments.

`filename'
     A string of characters used to identify a file.

`job'
     A set of processes comprising a pipeline, and any processes
     descended from it, that are all in the same process group.

`job control'
     A mechanism by which users can selectively stop (suspend) and
     restart (resume) execution of processes.

`metacharacter'
     A character that, when unquoted, separates words.  A metacharacter
     is a `blank' or one of the following characters: `|', `&', `;',
     `(', `)', `<', or `>'.

`name'
     A `word' consisting solely of letters, numbers, and underscores,
     and beginning with a letter or underscore.  `Name's are used as
     shell variable and function names.  Also referred to as an
     `identifier'.

`operator'
     A `control operator' or a `redirection operator'.  *Note
     Redirections::, for a list of redirection operators.

`process group'
     A collection of related processes each having the same process
     group ID.

`process group ID'
     A unique identifer that represents a `process group' during its
     lifetime.

`reserved word'
     A `word' that has a special meaning to the shell.  Most reserved
     words introduce shell flow control constructs, such as `for' and
     `while'.

`return status'
     A synonym for `exit status'.

`signal'
     A mechanism by which a process may be notified by the kernel of an
     event occurring in the system.

`special builtin'
     A shell builtin command that has been classified as special by the
     POSIX 1003.2 standard.

`token'
     A sequence of characters considered a single unit by the shell.
     It is either a `word' or an `operator'.

`word'
     A `token' that is not an `operator'.


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

Basic Shell Features
********************

   Bash is an acronym for `Bourne-Again SHell'.  The Bourne shell is
the traditional Unix shell originally written by Stephen Bourne.  All
of the Bourne shell builtin commands are available in Bash, and the
rules for evaluation and quoting are taken from the POSIX 1003.2
specification for the `standard' Unix shell.

   This chapter briefly summarizes the shell's `building blocks':
commands, control structures, shell functions, shell parameters, shell
expansions, redirections, which are a way to direct input and output
from and to named files, and how the shell executes commands.

* Menu:

* Shell Syntax::		What your input means to the shell.
* Shell Commands::		The types of commands you can use.
* Shell Functions::		Grouping commands by name.
* Shell Parameters::		Special shell variables.
* Shell Expansions::		How Bash expands variables and the various
				expansions available.
* Redirections::		A way to control where input and output go.
* Executing Commands::		What happens when you run a command.
* Shell Scripts::		Executing files of shell commands.


File: bashref.info,  Node: Shell Syntax,  Next: Shell Commands,  Up: Basic Shell Features

Shell Syntax
============

* Menu:

* Shell Operation::	The basic operation of the shell.

* Quoting::		How to remove the special meaning from characters.

* Comments::		How to specify comments.

   When the shell reads input, it proceeds through a sequence of
operations.  If the input indicates the beginning of a comment, the
shell ignores the comment symbol (`#'), and the rest of that line.

   Otherwise, roughly speaking,  the shell reads its input and divides
the input into words and operators, employing the quoting rules to
select which meanings to assign various words and characters.

   The shell then parses these tokens into commands and other
constructs, removes the special meaning of certain words or characters,
expands others, redirects input and output as needed, executes the
specified command, waits for the command's exit status, and makes that
exit status available for further inspection or processing.


File: bashref.info,  Node: Shell Operation,  Next: Quoting,  Up: Shell Syntax

Shell Operation
---------------

   The following is a brief description of the shell's operation when it
reads and executes a command.  Basically, the shell does the following:

  1. Reads its input from a file (*note Shell Scripts::), from a string
     supplied as an argument to the `-c' invocation option (*note
     Invoking Bash::), or from the user's terminal.

  2. Breaks the input into words and operators, obeying the quoting
     rules described in *Note Quoting::.  These tokens are separated by
     `metacharacters'.  Alias expansion is performed by this step
     (*note Aliases::).

  3. Parses the tokens into simple and compound commands (*note Shell
     Commands::).

  4. Performs the various shell expansions (*note Shell Expansions::),
     breaking the expanded tokens into lists of filenames (*note
     Filename Expansion::) and commands and arguments.

  5. Performs any necessary redirections (*note Redirections::) and
     removes the redirection operators and their operands from the
     argument list.

  6. Executes the command (*note Executing Commands::).

  7. Optionally waits for the command to complete and collects its exit
     status (*note Exit Status::).



File: bashref.info,  Node: Quoting,  Next: Comments,  Prev: Shell Operation,  Up: Shell Syntax

Quoting
-------

* Menu:

* Escape Character::	How to remove the special meaning from a single
			character.
* Single Quotes::	How to inhibit all interpretation of a sequence
			of characters.
* Double Quotes::	How to suppress most of the interpretation of a
			sequence of characters.
* ANSI-C Quoting::	How to expand ANSI-C sequences in quoted strings.

* Locale Translation::	How to translate strings into different languages.

   Quoting is used to remove the special meaning of certain characters
or words to the shell.  Quoting can be used to disable special
treatment for special characters, to prevent reserved words from being
recognized as such, and to prevent parameter expansion.

   Each of the shell metacharacters (*note Definitions::) has special
meaning to the shell and must be quoted if it is to represent itself.
When the command history expansion facilities are being used, the
HISTORY EXPANSION character, usually `!', must be quoted to prevent
history expansion.  *Note Bash History Facilities::, for more details
concerning history expansion.  There are three quoting mechanisms: the
ESCAPE CHARACTER, single quotes, and double quotes.


File: bashref.info,  Node: Escape Character,  Next: Single Quotes,  Up: Quoting

Escape Character
................

   A non-quoted backslash `\' is the Bash escape character.  It
preserves the literal value of the next character that follows, with
the exception of `newline'.  If a `\newline' pair appears, and the
backslash itself is not quoted, the `\newline' is treated as a line
continuation (that is, it is removed from the input stream and
effectively ignored).


File: bashref.info,  Node: Single Quotes,  Next: Double Quotes,  Prev: Escape Character,  Up: Quoting

Single Quotes
.............

   Enclosing characters in single quotes (`'') preserves the literal
value of each character within the quotes.  A single quote may not occur
between single quotes, even when preceded by a backslash.


File: bashref.info,  Node: Double Quotes,  Next: ANSI-C Quoting,  Prev: Single Quotes,  Up: Quoting

Double Quotes
.............

   Enclosing characters in double quotes (`"') preserves the literal
value of all characters within the quotes, with the exception of `$',
``', and `\'.  The characters `$' and ``' retain their special meaning
within double quotes (*note Shell Expansions::).  The backslash retains
its special meaning only when followed by one of the following
characters: `$', ``', `"', `\', or `newline'.  Within double quotes,
backslashes that are followed by one of these characters are removed.
Backslashes preceding characters without a special meaning are left
unmodified.  A double quote may be quoted within double quotes by
preceding it with a backslash.

   The special parameters `*' and `@' have special meaning when in
double quotes (*note Shell Parameter Expansion::).


File: bashref.info,  Node: ANSI-C Quoting,  Next: Locale Translation,  Prev: Double Quotes,  Up: Quoting

ANSI-C Quoting
..............

   Words of the form `$'STRING'' are treated specially.  The word
expands to STRING, with backslash-escaped characters replaced as
specified by the ANSI C standard.  Backslash escape sequences, if
present, are decoded as follows:

`\a'
     alert (bell)

`\b'
     backspace

`\e'
     an escape character (not ANSI C)

`\f'
     form feed

`\n'
     newline

`\r'
     carriage return

`\t'
     horizontal tab

`\v'
     vertical tab

`\\'
     backslash

`\''
     single quote

`\NNN'
     the eight-bit character whose value is the octal value NNN (one to
     three digits)

`\xHH'
     the eight-bit character whose value is the hexadecimal value HH
     (one or two hex digits)

The expanded result is single-quoted, as if the dollar sign had not
been present.


File: bashref.info,  Node: Locale Translation,  Prev: ANSI-C Quoting,  Up: Quoting

Locale-Specific Translation
...........................

   A double-quoted string preceded by a dollar sign (`$') will cause
the string to be translated according to the current locale.  If the
current locale is `C' or `POSIX', the dollar sign is ignored.  If the
string is translated and replaced, the replacement is double-quoted.

   Some systems use the message catalog selected by the `LC_MESSAGES'
shell variable.  Others create the name of the message catalog from the
value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
`.mo'.  If you use the `TEXTDOMAIN' variable, you may need to set the
`TEXTDOMAINDIR' variable to the location of the message catalog files.
Still others use both variables in this fashion:
`TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.


File: bashref.info,  Node: Comments,  Prev: Quoting,  Up: Shell Syntax

Comments
--------

   In a non-interactive shell, or an interactive shell in which the
`interactive_comments' option to the `shopt' builtin is enabled (*note
Bash Builtins::), a word beginning with `#' causes that word and all
remaining characters on that line to be ignored.  An interactive shell
without the `interactive_comments' option enabled does not allow
comments.  The `interactive_comments' option is on by default in
interactive shells.  *Note Interactive Shells::, for a description of
what makes a shell interactive.


File: bashref.info,  Node: Shell Commands,  Next: Shell Functions,  Prev: Shell Syntax,  Up: Basic Shell Features

Shell Commands
==============

   A simple shell command such as `echo a b c' consists of the command
itself followed by arguments, separated by spaces.

   More complex shell commands are composed of simple commands arranged
together in a variety of ways: in a pipeline in which the output of one
command becomes the input of a second, in a loop or conditional
construct, or in some other grouping.

* Menu:

* Simple Commands::		The most common type of command.
* Pipelines::			Connecting the input and output of several
				commands.
* Lists::			How to execute commands sequentially.
* Looping Constructs::		Shell commands for iterative action.
* Conditional Constructs::	Shell commands for conditional execution.
* Command Grouping::		Ways to group commands.


File: bashref.info,  Node: Simple Commands,  Next: Pipelines,  Up: Shell Commands

Simple Commands
---------------

   A simple command is the kind of command encountered most often.
It's just a sequence of words separated by `blank's, terminated by one
of the shell's control operators (*note Definitions::).  The first word
generally specifies a command to be executed, with the rest of the
words being that command's arguments.

   The return status (*note Exit Status::) of a simple command is its
exit status as provided by the POSIX 1003.1 `waitpid' function, or
128+N if the command was terminated by signal N.


File: bashref.info,  Node: Pipelines,  Next: Lists,  Prev: Simple Commands,  Up: Shell Commands

Pipelines
---------

   A `pipeline' is a sequence of simple commands separated by `|'.

   The format for a pipeline is
     [`time' [`-p']] [`!'] COMMAND1 [`|' 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.

   The reserved word `time' causes timing statistics to be printed for
the pipeline once it finishes.  The statistics currently consist of
elapsed (wall-clock) time and user and system time consumed by the
command's execution.  The `-p' option changes the output format to that
specified by POSIX.  The `TIMEFORMAT' variable may be set to a format
string that specifies how the timing information should be displayed.
*Note Bash Variables::, for a description of the available formats.
The use of `time' as a reserved word permits the timing of shell
builtins, shell functions, and pipelines.  An external `time' command
cannot time these easily.

   If the pipeline is not executed asynchronously (*note Lists::), the
shell waits for all commands in the pipeline to complete.

   Each command in a pipeline is executed in its own subshell (*note
Command Execution Environment::).  The exit status of a pipeline is the
exit status of the last command in the pipeline.  If the reserved word
`!' precedes the pipeline, the exit status is the logical negation of
the exit status of the last command.


File: bashref.info,  Node: Lists,  Next: Looping Constructs,  Prev: Pipelines,  Up: Shell Commands

Lists of Commands
-----------------

   A `list' is a sequence of one or more pipelines separated by one of
the operators `;', `&', `&&', or `||', and optionally terminated by one
of `;', `&', or a `newline'.

   Of these list operators, `&&' and `||' have equal precedence,
followed by `;' and `&', which have equal precedence.

   If a command is terminated by the control operator `&', the shell
executes the command asynchronously in a subshell.  This is known as
executing the command in the BACKGROUND.  The shell does not wait for
the command to finish, and the return status is 0 (true).  When job
control is not active (*note Job Control::), the standard input for
asynchronous commands, in the absence of any explicit redirections, is
redirected from `/dev/null'.

   Commands separated by a `;' are executed sequentially; the shell
waits for each command to terminate in turn.  The return status is the
exit status of the last command executed.

   The control operators `&&' and `||' denote AND lists and OR lists,
respectively.  An AND list has the form
     COMMAND1 && COMMAND2

COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
of zero.

   An OR list has the form
     COMMAND1 || COMMAND2

COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
status.

   The return status of AND and OR lists is the exit status of the last
command executed in the list.


File: bashref.info,  Node: Looping Constructs,  Next: Conditional Constructs,  Prev: Lists,  Up: Shell Commands

Looping Constructs
------------------

   Bash supports the following looping constructs.

   Note that wherever a `;' appears in the description of a command's
syntax, it may be replaced with one or more newlines.

`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
     was executed.

`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
     status of zero.  The return status is the exit status of the last
     command executed in CONSEQUENT-COMMANDS, or zero if none was
     executed.

`for'
     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
     once for each positional parameter that is set, as if `in "$@"'
     had been specified (*note Special Parameters::).  The return
     status is the exit status of the last command that executes.  If
     there are no items in the expansion of WORDS, no commands are
     executed, and the return status is zero.

     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
     evaluates to zero.  Each time EXPR2 evaluates to a non-zero value,
     COMMANDS are executed and the arithmetic expression EXPR3 is
     evaluated.  If any expression is omitted, it behaves as if it
     evaluates to 1.  The return value is the exit status of the last
     command in LIST 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.


File: bashref.info,  Node: Conditional Constructs,  Next: Command Grouping,  Prev: Looping Constructs,  Up: Shell Commands

Conditional Constructs
----------------------

`if'
     The syntax of the `if' command is:

          if TEST-COMMANDS; then
            CONSEQUENT-COMMANDS;
          [elif MORE-TEST-COMMANDS; then
            MORE-CONSEQUENTS;]
          [else ALTERNATE-CONSEQUENTS;]
          fi

     The TEST-COMMANDS list is executed, and if its return status is
     zero, the CONSEQUENT-COMMANDS list is executed.  If TEST-COMMANDS
     returns a non-zero status, each `elif' list is executed in turn,
     and if its exit status is zero, the corresponding MORE-CONSEQUENTS
     is executed and the command completes.  If `else
     ALTERNATE-CONSEQUENTS' is present, and the final command in the
     final `if' or `elif' clause has a non-zero exit status, then
     ALTERNATE-CONSEQUENTS is executed.  The return status is the exit
     status of the last command executed, or zero if no condition
     tested true.

`case'
     The syntax of the `case' command is:

          `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'

     `case' will selectively execute the COMMAND-LIST corresponding to
     the first PATTERN that matches WORD.  The `|' is used to separate
     multiple patterns, and the `)' operator terminates a pattern list.
     A list of patterns and an associated command-list is known as a
     CLAUSE.  Each clause must be terminated with `;;'.  The WORD
     undergoes tilde expansion, parameter expansion, command
     substitution, arithmetic expansion, and quote removal before
     matching is attempted.  Each PATTERN undergoes tilde expansion,
     parameter expansion, command substitution, and arithmetic
     expansion.

     There may be an arbitrary number of `case' clauses, each terminated
     by a `;;'.  The first pattern that matches determines the
     command-list that is executed.

     Here is an example using `case' in a script that could be used to
     describe one interesting feature of an animal:

          echo -n "Enter the name of an animal: "
          read ANIMAL
          echo -n "The $ANIMAL has "
          case $ANIMAL in
            horse | dog | cat) echo -n "four";;
            man | kangaroo ) echo -n "two";;
            *) echo -n "an unknown number of";;
          esac
          echo " legs."

     The return status is zero if no PATTERN is matched.  Otherwise, the
     return status is the exit status of the COMMAND-LIST executed.

`select'
     The `select' construct allows the easy generation of menus.  It
     has almost the same syntax as the `for' command:

          select NAME [in WORDS ...]; do COMMANDS; done

     The list of words following `in' is expanded, generating a list of
     items.  The set of expanded words is printed on the standard error
     output stream, each preceded by a number.  If the `in WORDS' is
     omitted, the positional parameters are printed, as if `in "$@"'
     had been specifed.  The `PS3' prompt is then displayed and a line
     is read from the standard input.  If the line consists of a number
     corresponding to one of the displayed words, then the value of
     NAME is set to that word.  If the line is empty, the words and
     prompt are displayed again.  If `EOF' is read, the `select'
     command completes.  Any other value read causes NAME to be set to
     null.  The line read is saved in the variable `REPLY'.

     The COMMANDS are executed after each selection until a `break'
     command is executed, at which point the `select' command completes.

     Here is an example that allows the user to pick a filename from the
     current directory, and displays the name and index of the file
     selected.

          select fname in *;
          do
          	echo you picked $fname \($REPLY\)
          	break;
          done

`((...))'
          (( EXPRESSION ))

     The arithmetic EXPRESSION is evaluated according to the rules
     described below (*note Shell Arithmetic::).  If the value of the
     expression is non-zero, the return status is 0; otherwise the
     return status is 1.  This is exactly equivalent to
          let "EXPRESSION"

     *Note Bash Builtins::, for a full description of the `let' builtin.

`[[...]]'
          [[ EXPRESSION ]]

     Return a status of 0 or 1 depending on the evaluation of the
     conditional expression EXPRESSION.  Expressions are composed of
     the primaries described below in *Note Bash Conditional
     Expressions::.  Word splitting and filename expansion are not
     performed on the words between the `[[' and `]]'; tilde expansion,
     parameter and variable expansion, arithmetic expansion, command
     substitution, process substitution, and quote removal are
     performed.

     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::.  The return
     value is 0 if the string matches or does not match the pattern,
     respectively, and 1 otherwise.  Any part of the pattern may be
     quoted to force it to be matched as a string.

     Expressions may be combined using the following operators, listed
     in decreasing order of precedence:

    `( EXPRESSION )'
          Returns the value of EXPRESSION.  This may be used to
          override the normal precedence of operators.

    `! EXPRESSION'
          True if EXPRESSION is false.

    `EXPRESSION1 && EXPRESSION2'
          True if both EXPRESSION1 and EXPRESSION2 are true.

    `EXPRESSION1 || EXPRESSION2'
          True if either EXPRESSION1 or EXPRESSION2 is true.

     The `&&' and `||' commands do not execute EXPRESSION2 if the value
     of EXPRESSION1 is sufficient to determine the return value of the
     entire conditional expression.


File: bashref.info,  Node: Command Grouping,  Prev: Conditional Constructs,  Up: Shell Commands

Grouping Commands
-----------------

   Bash provides two ways to group a list of commands to be executed as
a unit.  When commands are grouped, redirections may be applied to the
entire command list.  For example, the output of all the commands in
the list may be redirected to a single stream.

`()'
          ( LIST )

     Placing a list of commands between parentheses causes a subshell
     to be created, and each of the commands in LIST to be executed in
     that subshell.  Since the LIST is executed in a subshell, variable
     assignments do not remain in effect after the subshell completes.

`{}'
          { LIST; }

     Placing a list of commands between curly braces causes the list to
     be executed in the current shell context.  No subshell is created.
     The semicolon (or newline) following LIST is required.

   In addition to the creation of a subshell, there is a subtle
difference between these two constructs due to historical reasons.  The
braces are `reserved words', so they must be separated from the LIST by
`blank's.  The parentheses are `operators', and are recognized as
separate tokens by the shell even if they are not separated from the
LIST by whitespace.

   The exit status of both of these constructs is the exit status of
LIST.


File: bashref.info,  Node: Shell Functions,  Next: Shell Parameters,  Prev: Shell Commands,  Up: Basic Shell Features

Shell Functions
===============

   Shell functions are a way to group commands for later execution
using a single name for the group.  They are executed just like a
"regular" command.  When the name of a shell function is used as a
simple command name, the list of commands associated with that function
name is executed.  Shell functions are executed in the current shell
context; no new process is created to interpret them.

   Functions are declared using this syntax:
     [ `function' ] NAME () { COMMAND-LIST; }

   This defines a shell function named NAME.  The reserved word
`function' is optional.  If the `function' reserved word is supplied,
the parentheses are optional.  The BODY of the function is the
COMMAND-LIST between { and }.  This list is executed whenever NAME is
specified as the name of a command.  The exit status of a function is
the exit status of the last command executed in the body.

   Note that for historical reasons, the curly braces that surround the
body of the function must be separated from the body by `blank's or
newlines.  This is because the braces are reserved words and are only
recognized as such when they are separated by whitespace.  Also, the
COMMAND-LIST must be terminated with a semicolon or a newline.

   When a function is executed, the arguments to the function become
the positional parameters during its execution (*note Positional
Parameters::).  The special parameter `#' that expands to the number of
positional parameters is updated to reflect the change.  Positional
parameter `0' is unchanged.  The `FUNCNAME' variable is set to the name
of the function while the function is executing.

   If the builtin command `return' is executed in a function, the
function completes and execution resumes with the next command after
the function call.  When a function completes, the values of the
positional parameters and the special parameter `#' are restored to the
values they had prior to the function's execution.  If a numeric
argument is given to `return', that is the function's return status;
otherwise the function's return status is the exit status of the last
command executed before the `return'.

   Variables local to the function may be declared with the `local'
builtin.  These variables are visible only to the function and the
commands it invokes.

   Functions may be recursive.  No limit is placed on the number of
recursive  calls.


File: bashref.info,  Node: Shell Parameters,  Next: Shell Expansions,  Prev: Shell Functions,  Up: Basic Shell Features

Shell Parameters
================

* Menu:

* Positional Parameters::	The shell's command-line arguments.
* Special Parameters::		Parameters with special meanings.

   A PARAMETER is an entity that stores values.  It can be a `name', a
number, or one of the special characters listed below.  For the shell's
purposes, a VARIABLE is a parameter denoted by a `name'.  A variable
has a VALUE and zero or more ATTRIBUTES.  Attributes are assigned using
the `declare' builtin command (see the description of the `declare'
builtin in *Note Bash Builtins::).

   A parameter is set if it has been assigned a value.  The null string
is a valid value.  Once a variable is set, it may be unset only by using
the `unset' builtin command.

   A variable may be assigned to by a statement of the form
     NAME=[VALUE]

If VALUE is not given, the variable is assigned the null string.  All
VALUEs undergo tilde expansion, parameter and variable expansion,
command substitution, arithmetic expansion, and quote removal (detailed
below).  If the variable has its `integer' attribute set, then VALUE is
subject to arithmetic expansion even if the `$((...))' expansion is not
used (*note Arithmetic Expansion::).  Word splitting is not performed,
with the exception of `"$@"' as explained below.  Filename expansion is
not performed.  Assignment statements may also appear as arguments to
the `declare', `typeset', `export', `readonly', and `local' builtin
commands.


File: bashref.info,  Node: Positional Parameters,  Next: Special Parameters,  Up: Shell Parameters

Positional Parameters
---------------------

   A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
other than the single digit `0'.  Positional parameters are assigned
from the shell's arguments when it is invoked, and may be reassigned
using the `set' builtin command.  Positional parameter `N' may be
referenced as `${N}', or as `$N' when `N' consists of a single digit.
Positional parameters may not be assigned to with assignment statements.
The `set' and `shift' builtins are used to set and unset them (*note
Shell Builtin Commands::).  The positional parameters are temporarily
replaced when a shell function is executed (*note Shell Functions::).

   When a positional parameter consisting of more than a single digit
is expanded, it must be enclosed in braces.


File: bashref.info,  Node: Special Parameters,  Prev: Positional Parameters,  Up: Shell Parameters

Special Parameters
------------------

   The shell treats several parameters specially.  These parameters may
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 occurs within double quotes, each parameter expands to a
     separate word.  That is, `"$@"' is equivalent to `"$1" "$2" ...'.
     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 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
     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 most recently executed background
     (asynchronous) command.

`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 filename
     of the shell or shell script being executed as passed in the
     argument list.  Subsequently, expands to the last argument to the
     previous command, after expansion.  Also set to the full pathname
     of each command executed and placed in the environment exported to
     that command.  When checking mail, this parameter holds the name
     of the mail file.


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

Shell Expansions
================

   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

   * parameter and variable expansion

   * command substitution

   * arithmetic expansion

   * word splitting

   * filename expansion

* Menu:

* Brace Expansion::		Expansion of expressions within braces.
* Tilde Expansion::		Expansion of the ~ character.
* Shell Parameter Expansion::	How Bash expands variables to their values.
* Command Substitution::	Using the output of a command as an argument.
* Arithmetic Expansion::	How to use arithmetic in shell expansions.
* Process Substitution::	A way to write and read to and from a
				command.
* Word Splitting::	How the results of expansion are split into separate
			arguments.
* Filename Expansion::	A shorthand for specifying filenames matching patterns.
* 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.

   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.

   Only brace expansion, word splitting, and filename expansion can
change the number of words of the expansion; other expansions expand a
single word to a single word.  The only exceptions to this are the
expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
(*note Arrays::).

   After all expansions, `quote removal' (*note Quote Removal::) is
performed.


File: bashref.info,  Node: Brace Expansion,  Next: Tilde Expansion,  Up: Shell Expansions

Brace Expansion
---------------

   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.
Patterns to be brace expanded take the form of an optional PREAMBLE,
followed by a series of comma-separated strings 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 to right.

   Brace expansions may be nested.  The results of each expanded string
are not sorted; left to right order is preserved.  For example,
     bash$ echo a{d,c,b}e
     ade ace abe

   Brace expansion is performed before any other expansions, and any
characters special to other expansions are preserved in the result.  It
is strictly textual.  Bash does not apply any syntactic interpretation
to the context of the expansion or the text between the braces.  To
avoid conflicts with parameter expansion, the string `${' is not
considered eligible for brace expansion.

   A correctly-formed brace expansion must contain unquoted opening and
closing braces, and at least one unquoted comma.  Any incorrectly
formed brace expansion is left unchanged.

   This construct is typically used as shorthand when the common prefix
of the strings to be generated is longer than in the above example:
     mkdir /usr/local/src/bash/{old,new,dist,bugs}
   or
     chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}


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

Tilde Expansion
---------------

   If a word begins with an unquoted tilde character (`~'), all of the
characters up to the first unquoted slash (or all characters, if there
is no unquoted slash) are considered a TILDE-PREFIX.  If none of the
characters in the tilde-prefix are quoted, the characters in the
tilde-prefix following the tilde are treated as a possible LOGIN NAME.
If this login name is the null string, the tilde is replaced with the
value of the `HOME' shell variable.  If `HOME' is unset, the home
directory of the user executing the shell is substituted instead.
Otherwise, the tilde-prefix is replaced with the home directory
associated with the specified login name.

   If the tilde-prefix is `~+', the value of the shell variable `PWD'
replaces the tilde-prefix.  If the tilde-prefix is `~-', the value of
the shell variable `OLDPWD', if it is set, is substituted.

   If the characters following the tilde in the tilde-prefix consist of
a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
replaced with the corresponding element from the directory stack, as it
would be displayed by the `dirs' builtin invoked with the characters
following tilde in the tilde-prefix as an argument (*note The Directory
Stack::).  If the tilde-prefix, sans the tilde, consists of a number
without a leading `+' or `-', `+' is assumed.

   If the login name is invalid, or the tilde expansion fails, the word
is left unchanged.

   Each variable assignment is checked for unquoted tilde-prefixes
immediately following a `:' or `='.  In these cases, tilde expansion is
also performed.  Consequently, one may use file names with tildes in
assignments to `PATH', `MAILPATH', and `CDPATH', and the shell assigns
the expanded value.

   The following table shows how Bash treats unquoted tilde-prefixes:

`~'
     The value of `$HOME'

`~/foo'
     `$HOME/foo'

`~fred/foo'
     The subdirectory `foo' of the home directory of the user `fred'

`~+/foo'
     `$PWD/foo'

`~-/foo'
     `${OLDPWD-'~-'}/foo'

`~N'
     The string that would be displayed by `dirs +N'

`~+N'
     The string that would be displayed by `dirs +N'

`~-N'
     The string that would be displayed by `dirs -N'

