UNPKG

esy-bash

Version:

Cross-platform bash utilities - primed for Reason/OCaml

1,984 lines (1,503 loc) 342 kB
<HTML><HEAD> <TITLE>BASH(1) Manual Page</TITLE> </HEAD> <BODY><TABLE WIDTH=100%> <TR> <TH ALIGN=LEFT width=33%>BASH(1)<TH ALIGN=CENTER width=33%>2016 August 26<TH ALIGN=RIGHT width=33%>BASH(1) </TR> </TABLE> <BR><A HREF="#index">Index</A> <HR> <A NAME="lbAB">&nbsp;</A> <H3>NAME</H3> bash - GNU Bourne-Again SHell <A NAME="lbAC">&nbsp;</A> <H3>SYNOPSIS</H3> <B>bash</B> [options] [command_string | file] <A NAME="lbAD">&nbsp;</A> <H3>COPYRIGHT</H3> Bash is Copyright &#169; 1989-2016 by the Free Software Foundation, Inc. <A NAME="lbAE">&nbsp;</A> <H3>DESCRIPTION</H3> <B>Bash</B> is an <B>sh</B>-compatible command language interpreter that executes commands read from the standard input or from a file. <B>Bash</B> also incorporates useful features from the <I>Korn</I> and <I>C</I> shells (<B>ksh</B> and <B>csh</B>). <P> <B>Bash</B> is intended to be a conformant implementation of the Shell and Utilities portion of the IEEE POSIX specification (IEEE Standard 1003.1). <B>Bash</B> can be configured to be POSIX-conformant by default. <A NAME="lbAF">&nbsp;</A> <H3>OPTIONS</H3> All of the single-character shell options documented in the description of the <B>set</B> builtin command can be used as options when the shell is invoked. In addition, <B>bash</B> interprets the following options when it is invoked: <P> <DL COMPACT> <DT><B>-c</B> <DD> If the <B>-c</B> option is present, then commands are read from the first non-option argument <I>command_string</I>. If there are arguments after the <I>command_string</I>, the first argument is assigned to <B>$0</B> and any remaining arguments are assigned to the positional parameters. The assignment to <B>$0</B> sets the name of the shell, which is used in warning and error messages. <DT><B>-i</B> <DD> If the <B>-i</B> option is present, the shell is <I>interactive</I>. <DT><B>-l</B> <DD> Make <B>bash</B> act as if it had been invoked as a login shell (see <FONT SIZE=-1><B>INVOCATION</B> </FONT> below). <DT><B>-r</B> <DD> If the <B>-r</B> option is present, the shell becomes <I>restricted</I> (see <FONT SIZE=-1><B>RESTRICTED SHELL</B> </FONT> below). <DT><B>-s</B> <DD> If the <B>-s</B> option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell. <DT><B>-D</B> <DD> A list of all double-quoted strings preceded by <B>$</B> is printed on the standard output. These are the strings that are subject to language translation when the current locale is not <B>C</B> or <B>POSIX</B>. This implies the <B>-n</B> option; no commands will be executed. <DT><B>[-+]O [</B><I>shopt_option</I>] <DD> <I>shopt_option</I> is one of the shell options accepted by the <B>shopt</B> builtin (see <FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B> </FONT> below). If <I>shopt_option</I> is present, <B>-O</B> sets the value of that option; <B>+O</B> unsets it. If <I>shopt_option</I> is not supplied, the names and values of the shell options accepted by <B>shopt</B> are printed on the standard output. If the invocation option is <B>+O</B>, the output is displayed in a format that may be reused as input. <DT><B>--</B> <DD> A <B>--</B> signals the end of options and disables further option processing. Any arguments after the <B>--</B> are treated as filenames and arguments. An argument of <B>-</B> is equivalent to <B>--</B>. </DL> <P> <B>Bash</B> also interprets a number of multi-character options. These options must appear on the command line before the single-character options to be recognized. <P> <DL COMPACT> <DT><B>--debugger</B> <DD> Arrange for the debugger profile to be executed before the shell starts. Turns on extended debugging mode (see the description of the <B>extdebug</B> option to the <B>shopt</B> builtin below). <DT><B>--dump-po-strings</B> <DD> Equivalent to <B>-D</B>, but the output is in the GNU <I>gettext</I> <B>po</B> (portable object) file format. <DT><B>--dump-strings</B> <DD> Equivalent to <B>-D</B>. <DT><B>--help</B> <DD> Display a usage message on standard output and exit successfully. <DT><B>--init-file</B> <I>file</I><DD> <DT><B>--rcfile</B> <I>file</I><DD> Execute commands from <I>file</I> instead of the standard personal initialization file <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A> if the shell is interactive (see <FONT SIZE=-1><B>INVOCATION</B> </FONT> below). <DT><B>--login</B> <DD> Equivalent to <B>-l</B>. <DT><B>--noediting</B> <DD> Do not use the GNU <B>readline</B> library to read command lines when the shell is interactive. <DT><B>--noprofile</B> <DD> Do not read either the system-wide startup file <A HREF="file:/etc/profile"><I>/etc/profile</I></A> or any of the personal initialization files <A HREF="file:~/.bash_profile"><I>~/.bash_profile</I></A>, <A HREF="file:~/.bash_login"><I>~/.bash_login</I></A>, or <A HREF="file:~/.profile"><I>~/.profile</I></A>. By default, <B>bash</B> reads these files when it is invoked as a login shell (see <FONT SIZE=-1><B>INVOCATION</B> </FONT> below). <DT><B>--norc</B> <DD> Do not read and execute the personal initialization file <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A> if the shell is interactive. This option is on by default if the shell is invoked as <B>sh</B>. <DT><B>--posix</B> <DD> Change the behavior of <B>bash</B> where the default operation differs from the POSIX standard to match the standard (<I>posix mode</I>). See <FONT SIZE=-1><B>SEE ALSO</B> </FONT> below for a reference to a document that details how posix mode affects bash's behavior. <DT><B>--restricted</B> <DD> The shell becomes restricted (see <FONT SIZE=-1><B>RESTRICTED SHELL</B> </FONT> below). <DT><B>--verbose</B> <DD> Equivalent to <B>-v</B>. <DT><B>--version</B> <DD> Show version information for this instance of <B>bash</B> on the standard output and exit successfully. </DL> <A NAME="lbAG">&nbsp;</A> <H3>ARGUMENTS</H3> If arguments remain after option processing, and neither the <B>-c</B> nor the <B>-s</B> option has been supplied, the first argument is assumed to be the name of a file containing shell commands. If <B>bash</B> is invoked in this fashion, <B>$0</B> is set to the name of the file, and the positional parameters are set to the remaining arguments. <B>Bash</B> reads and executes commands from this file, then exits. <B>Bash</B>'s exit status is the exit status of the last command executed in the script. If no commands are executed, the exit status is 0. An attempt is first made to open the file in the current directory, and, if no file is found, then the shell searches the directories in <FONT SIZE=-1><B>PATH</B> </FONT> for the script. <A NAME="lbAH">&nbsp;</A> <H3>INVOCATION</H3> A <I>login shell</I> is one whose first character of argument zero is a <B>-</B>, or one started with the <B>--login</B> option. <P> An <I>interactive</I> shell is one started without non-option arguments (unless <B>-s</B> is specified) and without the <B>-c</B> option whose standard input and error are both connected to terminals (as determined by <I>isatty</I>(3)), or one started with the <B>-i</B> option. <FONT SIZE=-1><B>PS1</B> </FONT> is set and <B>$-</B> includes <B>i</B> if <B>bash</B> is interactive, allowing a shell script or a startup file to test this state. <P> The following paragraphs describe how <B>bash</B> executes its startup files. If any of the files exist but cannot be read, <B>bash</B> reports an error. Tildes are expanded in filenames as described below under <B>Tilde Expansion</B> in the <FONT SIZE=-1><B>EXPANSION</B> </FONT> section. <P> When <B>bash</B> is invoked as an interactive login shell, or as a non-interactive shell with the <B>--login</B> option, it first reads and executes commands from the file <A HREF="file:/etc/profile"><I>/etc/profile</I></A>, if that file exists. After reading that file, it looks for <A HREF="file:~/.bash_profile"><I>~/.bash_profile</I></A>, <A HREF="file:~/.bash_login"><I>~/.bash_login</I></A>, and <A HREF="file:~/.profile"><I>~/.profile</I></A>, in that order, and reads and executes commands from the first one that exists and is readable. The <B>--noprofile</B> option may be used when the shell is started to inhibit this behavior. <P> When an interactive login shell exits, or a non-interactive login shell executes the <B>exit</B> builtin command, <B>bash</B> reads and executes commands from the file <A HREF="file:~/.bash_logout"><I>~/.bash_logout</I></A>, if it exists. <P> When an interactive shell that is not a login shell is started, <B>bash</B> reads and executes commands from <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>, if that file exists. This may be inhibited by using the <B>--norc</B> option. The <B>--rcfile</B> <I>file</I> option will force <B>bash</B> to read and execute commands from <I>file</I> instead of <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>. <P> When <B>bash</B> is started non-interactively, to run a shell script, for example, it looks for the variable <FONT SIZE=-1><B>BASH_ENV</B> </FONT> in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. <B>Bash</B> behaves as if the following command were executed: <P> <DL COMPACT><DT><DD> <TT>if [ -n &quot;$BASH_ENV&quot; ]; then . &quot;$BASH_ENV&quot;; fi</TT> </DL> <P> but the value of the <FONT SIZE=-1><B>PATH</B> </FONT> variable is not used to search for the filename. <P> If <B>bash</B> is invoked with the name <B>sh</B>, it tries to mimic the startup behavior of historical versions of <B>sh</B> as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the <B>--login</B> option, it first attempts to read and execute commands from <A HREF="file:/etc/profile"><I>/etc/profile</I></A> and <A HREF="file:~/.profile"><I>~/.profile</I></A>, in that order. The <B>--noprofile</B> option may be used to inhibit this behavior. When invoked as an interactive shell with the name <B>sh</B>, <B>bash</B> looks for the variable <FONT SIZE=-1><B>ENV</B>, </FONT> expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as <B>sh</B> does not attempt to read and execute commands from any other startup files, the <B>--rcfile</B> option has no effect. A non-interactive shell invoked with the name <B>sh</B> does not attempt to read any other startup files. When invoked as <B>sh</B>, <B>bash</B> enters <I>posix</I> mode after the startup files are read. <P> When <B>bash</B> is started in <I>posix</I> mode, as with the <B>--posix</B> command line option, it follows the POSIX standard for startup files. In this mode, interactive shells expand the <FONT SIZE=-1><B>ENV</B> </FONT> variable and commands are read and executed from the file whose name is the expanded value. No other startup files are read. <P> <B>Bash</B> attempts to determine when it is being run with its standard input connected to a network connection, as when executed by the remote shell daemon, usually <I>rshd</I>, or the secure shell daemon <I>sshd</I>. If <B>bash</B> determines it is being run in this fashion, it reads and executes commands from <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>, if that file exists and is readable. It will not do this if invoked as <B>sh</B>. The <B>--norc</B> option may be used to inhibit this behavior, and the <B>--rcfile</B> option may be used to force another file to be read, but neither <I>rshd</I> nor <I>sshd</I> generally invoke the shell with those options or allow them to be specified. <P> If the shell is started with the effective user (group) id not equal to the real user (group) id, and the <B>-p</B> option is not supplied, no startup files are read, shell functions are not inherited from the environment, the <FONT SIZE=-1><B>SHELLOPTS</B>, </FONT> <FONT SIZE=-1><B>BASHOPTS</B>, </FONT> <FONT SIZE=-1><B>CDPATH</B>, </FONT> and <FONT SIZE=-1><B>GLOBIGNORE</B> </FONT> variables, if they appear in the environment, are ignored, and the effective user id is set to the real user id. If the <B>-p</B> option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset. <A NAME="lbAI">&nbsp;</A> <H3>DEFINITIONS</H3> <P> The following definitions are used throughout the rest of this document. <DL COMPACT> <DT><B>blank</B> <DD> A space or tab. <DT><B>word</B> <DD> A sequence of characters considered as a single unit by the shell. Also known as a <B>token</B>. <DT><B>name</B> <DD> A <I>word</I> consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an <B>identifier</B>. <DT><B>metacharacter</B> <DD> A character that, when unquoted, separates words. One of the following: <BR> <DL COMPACT><DT><DD> <P> <B>| &amp; ; ( ) &lt; &gt; space tab newline</B> </DL> </DL> <P> <DL COMPACT> <DT><B>control operator</B> <DD> A <I>token</I> that performs a control function. It is one of the following symbols: <DL COMPACT><DT><DD> <P> <B>|| &amp; &amp;&amp; ; ;; ;&amp; ;;&amp; ( ) | |&amp; &lt;newline&gt;</B> </DL> </DL> <A NAME="lbAJ">&nbsp;</A> <H3>RESERVED WORDS</H3> <I>Reserved words</I> are words that have a special meaning to the shell. The following words are recognized as reserved when unquoted and either the first word of a simple command (see <FONT SIZE=-1><B>SHELL GRAMMAR</B> </FONT> below) or the third word of a <B>case</B> or <B>for</B> command: <DL COMPACT><DT><DD> <P> <B> </B> ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]] </DL> <A NAME="lbAK">&nbsp;</A> <H3>SHELL GRAMMAR</H3> <A NAME="lbAL">&nbsp;</A> <H4>Simple Commands</H4> <P> A <I>simple command</I> is a sequence of optional variable assignments followed by <B>blank</B>-separated words and redirections, and terminated by a <I>control operator</I>. The first word specifies the command to be executed, and is passed as argument zero. The remaining words are passed as arguments to the invoked command. <P> The return value of a <I>simple command</I> is its exit status, or 128+<I>n</I> if the command is terminated by signal <I>n</I>. <A NAME="lbAM">&nbsp;</A> <H4>Pipelines</H4> <P> A <I>pipeline</I> is a sequence of one or more commands separated by one of the control operators <B>|</B> or <B>|&amp;</B>. The format for a pipeline is: <DL COMPACT><DT><DD> <P> [<B>time</B> [<B>-p</B>]] [ ! ] <I>command</I> [ [<B>|</B>|<B>|&amp;</B>] <I>command2</I> ... ] </DL> <P> The standard output of <I>command</I> is connected via a pipe to the standard input of <I>command2</I>. This connection is performed before any redirections specified by the command (see <FONT SIZE=-1><B>REDIRECTION</B> </FONT> below). If <B>|&amp;</B> is used, <I>command</I>'s standard error, in addition to its standard output, is connected to <I>command2</I>'s standard input through the pipe; it is shorthand for <B>2&gt;&amp;1 |</B>. This implicit redirection of the standard error to the standard output is performed after any redirections specified by the command. <P> The return status of a pipeline is the exit status of the last command, unless the <B>pipefail</B> option is enabled. If <B>pipefail</B> is enabled, the pipeline's return status is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands exit successfully. If the reserved word <B>!</B> precedes a pipeline, the exit status of that pipeline is the logical negation of the exit status as described above. The shell waits for all commands in the pipeline to terminate before returning a value. <P> If the <B>time</B> reserved word precedes a pipeline, the elapsed as well as user and system time consumed by its execution are reported when the pipeline terminates. The <B>-p</B> option changes the output format to that specified by POSIX. When the shell is in <I>posix mode</I>, it does not recognize <B>time</B> as a reserved word if the next token begins with a `-'. The <FONT SIZE=-1><B>TIMEFORMAT</B> </FONT> variable may be set to a format string that specifies how the timing information should be displayed; see the description of <FONT SIZE=-1><B>TIMEFORMAT</B> </FONT> under <B>Shell Variables</B> below. <P> When the shell is in <I>posix mode</I>, <B>time</B> may be followed by a newline. In this case, the shell displays the total user and system time consumed by the shell and its children. The <FONT SIZE=-1><B>TIMEFORMAT</B> </FONT> variable may be used to specify the format of the time information. <P> Each command in a pipeline is executed as a separate process (i.e., in a subshell). <A NAME="lbAN">&nbsp;</A> <H4>Lists</H4> <P> A <I>list</I> is a sequence of one or more pipelines separated by one of the operators <B>;</B>, <B>&amp;</B>, <B>&amp;&amp;</B>, or <B>||</B>, and optionally terminated by one of <B>;</B>, <B>&amp;</B>, or <B>&lt;newline&gt;</B>. <P> Of these list operators, <B>&amp;&amp;</B> and <B>||</B> have equal precedence, followed by <B>;</B> and <B>&amp;</B>, which have equal precedence. <P> A sequence of one or more newlines may appear in a <I>list</I> instead of a semicolon to delimit commands. <P> If a command is terminated by the control operator <B>&amp;</B>, the shell executes the command in the <I>background</I> in a subshell. The shell does not wait for the command to finish, and the return status is 0. Commands separated by a <B>;</B> 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. <P> AND and OR lists are sequences of one or more pipelines separated by the <B>&amp;&amp;</B> and <B>||</B> control operators, respectively. AND and OR lists are executed with left associativity. An AND list has the form <DL COMPACT><DT><DD> <P> <I>command1</I> <B>&amp;&amp;</B> <I>command2</I> </DL> <P> <I>command2</I> is executed if, and only if, <I>command1</I> returns an exit status of zero. <P> An OR list has the form <DL COMPACT><DT><DD> <P> <I>command1</I> <B>||</B> <I>command2</I> <P> </DL> <P> <I>command2</I> is executed if and only if <I>command1</I> 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. <A NAME="lbAO">&nbsp;</A> <H4>Compound Commands</H4> <P> A <I>compound command</I> is one of the following. In most cases a <I>list</I> in a 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. <DL COMPACT> <DT>(<I>list</I>)<DD> <I>list</I> is executed in a subshell environment (see <FONT SIZE=-1><B>COMMAND EXECUTION ENVIRONMENT</B></FONT> below). Variable assignments and builtin commands that affect the shell's environment do not remain in effect after the command completes. The return status is the exit status of <I>list</I>. <DT>{ <I>list</I>; }<DD> <I>list</I> is simply executed in the current shell environment. <I>list</I> must be terminated with a newline or semicolon. This is known as a <I>group command</I>. The return status is the exit status of <I>list</I>. Note that unlike the metacharacters <B>(</B> and <B>)</B>, <B>{</B> and <B>}</B> are <I>reserved words</I> and must occur where a reserved word is permitted to be recognized. Since they do not cause a word break, they must be separated from <I>list</I> by whitespace or another shell metacharacter. <DT>((<I>expression</I>))<DD> The <I>expression</I> is evaluated according to the rules described below under <FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>. </FONT> 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 <B>let &quot;</B><I>expression</I>&quot;. <DT><B>[[</B> <I>expression</I> <B>]]</B><DD> Return a status of 0 or 1 depending on the evaluation of the conditional expression <I>expression</I>. Expressions are composed of the primaries described below under <FONT SIZE=-1><B>CONDITIONAL EXPRESSIONS</B>. </FONT> Word splitting and pathname expansion are not performed on the words between the <B>[[</B> and <B>]]</B>; tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution, and quote removal are performed. Conditional operators such as <B>-f</B> must be unquoted to be recognized as primaries. <P> When used with <B>[[</B>, the <B>&lt;</B> and <B>&gt;</B> operators sort lexicographically using the current locale. <P> When the <B>==</B> and <B>!=</B> operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below under <B>Pattern Matching</B>, as if the <B>extglob</B> shell option were enabled. The <B>=</B> operator is equivalent to <B>==</B>. If the <B>nocasematch</B> shell option is enabled, the match is performed without regard to the case of alphabetic characters. The return value is 0 if the string matches (<B>==</B>) or does not match (<B>!=</B>) the pattern, and 1 otherwise. Any part of the pattern may be quoted to force the quoted portion to be matched as a string. <P> An additional binary operator, <B>=~</B>, is available, with the same precedence as <B>==</B> and <B>!=</B>. When it is used, the string to the right of the operator is considered an extended regular expression and matched accordingly (as in <I>regex</I>(3)). The return value is 0 if the string matches the pattern, and 1 otherwise. If the regular expression is syntactically incorrect, the conditional expression's return value is 2. If the <B>nocasematch</B> shell option is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force the quoted portion to be matched as a string. Bracket expressions in regular expressions must be treated carefully, since normal quoting characters lose their meanings between brackets. If the pattern is stored in a shell variable, quoting the variable expansion forces the entire pattern to be matched as a string. Substrings matched by parenthesized subexpressions within the regular expression are saved in the array variable <FONT SIZE=-1><B>BASH_REMATCH</B>. </FONT> The element of <FONT SIZE=-1><B>BASH_REMATCH</B> </FONT> with index 0 is the portion of the string matching the entire regular expression. The element of <FONT SIZE=-1><B>BASH_REMATCH</B> </FONT> with index <I>n</I> is the portion of the string matching the <I>n</I>th parenthesized subexpression. <P> Expressions may be combined using the following operators, listed in decreasing order of precedence: <P> <DL COMPACT><DT><DD> <DL COMPACT> <DT><B>( </B><I>expression</I> ) <DD> Returns the value of <I>expression</I>. This may be used to override the normal precedence of operators. <DT><B>! </B><I>expression</I> <DD> True if <I>expression</I> is false. <DT><I>expression1</I> <B>&amp;&amp;</B> <I>expression2</I><DD> True if both <I>expression1</I> and <I>expression2</I> are true. <DT><I>expression1</I> <B>||</B> <I>expression2</I><DD> True if either <I>expression1</I> or <I>expression2</I> is true. </DL> <P> The <B>&amp;&amp;</B> and <B>||</B> operators do not evaluate <I>expression2</I> if the value of <I>expression1</I> is sufficient to determine the return value of the entire conditional expression. </DL> <DT><B>for</B> <I>name</I> [ [ <B>in</B> [ <I>word ...</I> ] ] ; ] <B>do</B> <I>list</I> ; <B>done</B><DD> The list of words following <B>in</B> is expanded, generating a list of items. The variable <I>name</I> is set to each element of this list in turn, and <I>list</I> is executed each time. If the <B>in</B> <I>word</I> is omitted, the <B>for</B> command executes <I>list</I> once for each positional parameter that is set (see <FONT SIZE=-1><B>PARAMETERS</B> </FONT> below). The return status is the exit status of the last command that executes. If the expansion of the items following <B>in</B> results in an empty list, no commands are executed, and the return status is 0. <DT><B>for</B> (( <I>expr1</I> ; <I>expr2</I> ; <I>expr3</I> )) ; <B>do</B> <I>list</I> ; <B>done</B><DD> First, the arithmetic expression <I>expr1</I> is evaluated according to the rules described below under <FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>. </FONT> The arithmetic expression <I>expr2</I> is then evaluated repeatedly until it evaluates to zero. Each time <I>expr2</I> evaluates to a non-zero value, <I>list</I> is executed and the arithmetic expression <I>expr3</I> 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 <I>list</I> that is executed, or false if any of the expressions is invalid. <DT><B>select</B> <I>name</I> [ <B>in</B> <I>word</I> ] ; <B>do</B> <I>list</I> ; <B>done</B><DD> The list of words following <B>in</B> is expanded, generating a list of items. The set of expanded words is printed on the standard error, each preceded by a number. If the <B>in</B> <I>word</I> is omitted, the positional parameters are printed (see <FONT SIZE=-1><B>PARAMETERS</B> </FONT> below). The <FONT SIZE=-1><B>PS3</B> </FONT> prompt is then displayed and a line read from the standard input. If the line consists of a number corresponding to one of the displayed words, then the value of <I>name</I> is set to that word. If the line is empty, the words and prompt are displayed again. If EOF is read, the command completes. Any other value read causes <I>name</I> to be set to null. The line read is saved in the variable <FONT SIZE=-1><B>REPLY</B>. </FONT> The <I>list</I> is executed after each selection until a <B>break</B> command is executed. The exit status of <B>select</B> is the exit status of the last command executed in <I>list</I>, or zero if no commands were executed. <DT><B>case</B> <I>word</I> <B>in</B> [ [(] <I>pattern</I> [ <B>|</B> <I>pattern</I> ] <DD> A <B>case</B> command first expands <I>word</I>, and tries to match it against each <I>pattern</I> in turn, using the same matching rules as for pathname expansion (see <B>Pathname Expansion</B> below). The <I>word</I> is expanded using tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, process substitution and quote removal. Each <I>pattern</I> examined is expanded using tilde expansion, parameter and variable expansion, arithmetic expansion, command substitution, and process substitution. If the <B>nocasematch</B> shell option is enabled, the match is performed without regard to the case of alphabetic characters. When a match is found, the corresponding <I>list</I> is executed. If the <B>;;</B> operator is used, no subsequent matches are attempted after the first pattern match. Using <B>;&amp;</B> in place of <B>;;</B> causes execution to continue with the <I>list</I> associated with the next set of patterns. Using <B>;;&amp;</B> in place of <B>;;</B> causes the shell to test the next pattern list in the statement, if any, and execute any associated <I>list</I> on a successful match. The exit status is zero if no pattern matches. Otherwise, it is the exit status of the last command executed in <I>list</I>. <DT><B>if</B> <I>list</I>; <B>then</B> <I>list</I>; [ <B>elif</B> <I>list</I>; <B>then</B> <I>list</I>; ] ... [ <B>else</B> <I>list</I>; ] <B>fi</B><DD> The <B>if</B> <I>list</I> is executed. If its exit status is zero, the <B>then</B> <I>list</I> is executed. Otherwise, each <B>elif</B> <I>list</I> is executed in turn, and if its exit status is zero, the corresponding <B>then</B> <I>list</I> is executed and the command completes. Otherwise, the <B>else</B> <I>list</I> is executed, if present. The exit status is the exit status of the last command executed, or zero if no condition tested true. <DT><B>while</B> <I>list-1</I>; <B>do</B> <I>list-2</I>; <B>done</B><DD> <DT><B>until</B> <I>list-1</I>; <B>do</B> <I>list-2</I>; <B>done</B><DD> The <B>while</B> command continuously executes the list <I>list-2</I> as long as the last command in the list <I>list-1</I> returns an exit status of zero. The <B>until</B> command is identical to the <B>while</B> command, except that the test is negated: <I>list-2</I> is executed as long as the last command in <I>list-1</I> returns a non-zero exit status. The exit status of the <B>while</B> and <B>until</B> commands is the exit status of the last command executed in <I>list-2</I>, or zero if none was executed. </DL> <A NAME="lbAP">&nbsp;</A> <H4>Coprocesses</H4> <P> A <I>coprocess</I> is a shell command preceded by the <B>coproc</B> reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the <B>&amp;</B> control operator, with a two-way pipe established between the executing shell and the coprocess. <P> The format for a coprocess is: <DL COMPACT><DT><DD> <P> <B>coproc</B> [<I>NAME</I>] <I>command</I> [<I>redirections</I>] </DL> <P> This creates a coprocess named <I>NAME</I>. If <I>NAME</I> is not supplied, the default name is <B>COPROC</B>. <I>NAME</I> must not be supplied if <I>command</I> is a <I>simple command</I> (see above); otherwise, it is interpreted as the first word of the simple command. When the coprocess is executed, the shell creates an array variable (see <B>Arrays</B> below) named <I>NAME</I> in the context of the executing shell. The standard output of <I>command</I> is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to <I>NAME</I>[0]. The standard input of <I>command</I> is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to <I>NAME</I>[1]. This pipe is established before any redirections specified by the command (see <FONT SIZE=-1><B>REDIRECTION</B> </FONT> below). 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 <I>NAME</I>_PID. The <B>wait</B> builtin command may be used to wait for the coprocess to terminate. <P> Since the coprocess is created as an asynchronous command, the <B>coproc</B> command always returns success. The return status of a coprocess is the exit status of <I>command</I>. <A NAME="lbAQ">&nbsp;</A> <H4>Shell Function Definitions</H4> <P> A shell function is an object that is called like a simple command and executes a compound command with a new set of positional parameters. Shell functions are declared as follows: <DL COMPACT> <DT><I>name</I> () <I>compound-command</I> [<I>redirection</I>]<DD> <DT><B>function</B> <I>name</I> [()] <I>compound-command</I> [<I>redirection</I>]<DD> This defines a function named <I>name</I>. The reserved word <B>function</B> is optional. If the <B>function</B> reserved word is supplied, the parentheses are optional. The <I>body</I> of the function is the compound command <I>compound-command</I> (see <B>Compound Commands</B> above). That command is usually a <I>list</I> of commands between { and }, but may be any command listed under <B>Compound Commands</B> above, with one exception: If the <B>function</B> reserved word is used, but the parentheses are not supplied, the braces are required. <I>compound-command</I> is executed whenever <I>name</I> is specified as the name of a simple command. When in <I>posix mode</I>, <I>name</I> may not be the name of one of the POSIX <I>special builtins</I>. Any redirections (see <FONT SIZE=-1><B>REDIRECTION</B> </FONT> below) specified when a function is defined are performed when the function is executed. The exit status of a function definition is zero unless a syntax error occurs or a readonly function with the same name already exists. When executed, the exit status of a function is the exit status of the last command executed in the body. (See <FONT SIZE=-1><B>FUNCTIONS</B> </FONT> below.) </DL> <A NAME="lbAR">&nbsp;</A> <H3>COMMENTS</H3> In a non-interactive shell, or an interactive shell in which the <B>interactive_comments</B> option to the <B>shopt</B> builtin is enabled (see <FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B> </FONT> below), a word beginning with <B>#</B> causes that word and all remaining characters on that line to be ignored. An interactive shell without the <B>interactive_comments</B> option enabled does not allow comments. The <B>interactive_comments</B> option is on by default in interactive shells. <A NAME="lbAS">&nbsp;</A> <H3>QUOTING</H3> <I>Quoting</I> 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. <P> Each of the <I>metacharacters</I> listed above under <FONT SIZE=-1><B>DEFINITIONS</B> </FONT> has special meaning to the shell and must be quoted if it is to represent itself. <P> When the command history expansion facilities are being used (see <FONT SIZE=-1><B>HISTORY EXPANSION</B> </FONT> below), the <I>history expansion</I> character, usually <B>!</B>, must be quoted to prevent history expansion. <P> There are three quoting mechanisms: the <I>escape character</I>, single quotes, and double quotes. <P> A non-quoted backslash (<B>\</B>) is the <I>escape character</I>. It preserves the literal value of the next character that follows, with the exception of &lt;newline&gt;. If a <B>\</B>&lt;newline&gt; pair appears, and the backslash is not itself quoted, the <B>\</B>&lt;newline&gt; is treated as a line continuation (that is, it is removed from the input stream and effectively ignored). <P> 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. <P> Enclosing characters in double quotes preserves the literal value of all characters within the quotes, with the exception of <B>$</B>, <B>`</B>, <B>\</B>, and, when history expansion is enabled, <B>!</B>. When the shell is in <I>posix mode</I>, the <B>!</B> has no special meaning within double quotes, even when history expansion is enabled. The characters <B>$</B> and <B>`</B> retain their special meaning within double quotes. The backslash retains its special meaning only when followed by one of the following characters: <B>$</B>, <B>`</B>, <B>&quot;</B>, <B>\</B>, or <B>&lt;newline&gt;</B>. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an <B>!</B> appearing in double quotes is escaped using a backslash. The backslash preceding the <B>!</B> is not removed. <P> The special parameters <B>*</B> and <B>@</B> have special meaning when in double quotes (see <FONT SIZE=-1><B>PARAMETERS</B> </FONT> below). <P> Words of the form <B>$</B>aq<I>string</I>aq are treated specially. The word expands to <I>string</I>, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows: <DL COMPACT><DT><DD> <DL COMPACT> <DT><B>\a</B> <DD> alert (bell) <DT><B>\b</B> <DD> backspace <DT><B>\e</B> <DD> <DT><B>\E</B> <DD> an escape character <DT><B>\f</B> <DD> form feed <DT><B>\n</B> <DD> new line <DT><B>\r</B> <DD> carriage return <DT><B>\t</B> <DD> horizontal tab <DT><B>\v</B> <DD> vertical tab <DT><B>\\</B> <DD> backslash <DT><B>\aq</B> <DD> single quote <DT><B>\dq</B> <DD> double quote <DT><B>\?</B> <DD> question mark <DT><B>\</B><I>nnn</I> <DD> the eight-bit character whose value is the octal value <I>nnn</I> (one to three digits) <DT><B>\x</B><I>HH</I> <DD> the eight-bit character whose value is the hexadecimal value <I>HH</I> (one or two hex digits) <DT><B>\u</B><I>HHHH</I> <DD> the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value <I>HHHH</I> (one to four hex digits) <DT><B>\U</B><I>HHHHHHHH</I> <DD> the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value <I>HHHHHHHH</I> (one to eight hex digits) <DT><B>\c</B><I>x</I> <DD> a control-<I>x</I> character </DL></DL> <P> The expanded result is single-quoted, as if the dollar sign had not been present. <P> A double-quoted string preceded by a dollar sign (<B>$</B>dq<I>string</I>dq) will cause the string to be translated according to the current locale. If the current locale is <B>C</B> or <B>POSIX</B>, the dollar sign is ignored. If the string is translated and replaced, the replacement is double-quoted. <A NAME="lbAT">&nbsp;</A> <H3>PARAMETERS</H3> A <I>parameter</I> is an entity that stores values. It can be a <I>name</I>, a number, or one of the special characters listed below under <B>Special Parameters</B>. A <I>variable</I> is a parameter denoted by a <I>name</I>. A variable has a <I>value</I> and zero or more <I>attributes</I>. Attributes are assigned using the <B>declare</B> builtin command (see <B>declare</B> below in <FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>). </FONT> <P> 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 <B>unset</B> builtin command (see <FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B> </FONT> below). <P> A <I>variable</I> may be assigned to by a statement of the form <DL COMPACT><DT><DD> <P> <I>name</I>=[<I>value</I>] </DL> <P> If <I>value</I> is not given, the variable is assigned the null string. All <I>values</I> undergo tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, and quote removal (see <FONT SIZE=-1><B>EXPANSION</B> </FONT> below). If the variable has its <B>integer</B> attribute set, then <I>value</I> is evaluated as an arithmetic expression even if the $((...)) expansion is not used (see <B>Arithmetic Expansion</B> below). Word splitting is not performed, with the exception of <B>&quot;$@&quot;</B> as explained below under <B>Special Parameters</B>. Pathname expansion is not performed. Assignment statements may also appear as arguments to the <B>alias</B>, <B>declare</B>, <B>typeset</B>, <B>export</B>, <B>readonly</B>, and <B>local</B> builtin commands (<I>declaration</I> commands). When in <I>posix mode</I>, these builtins may appear in a command after one or more instances of the <B>command</B> builtin and retain these assignment statement properties. <P> In the context where an assignment statement is assigning a value to a shell variable or array index, the += operator can be used to append to or add to the variable's previous value. This includes arguments to builtin commands such as <B>declare</B> that accept assignment statements (<I>declaration</I> commands). When += is applied to a variable for which the <I>integer</I> attribute has been set, <I>value</I> is evaluated as an arithmetic expression and added to the variable's current value, which is also evaluated. When += is applied to an array variable using compound assignment (see <B>Arrays</B> below), the variable's value is not unset (as it is when using =), and new values are appended to the array beginning at one greater than the array's maximum index (for indexed arrays) or added as additional key-value pairs in an associative array. When applied to a string-valued variable, <I>value</I> is expanded and appended to the variable's value. <P> A variable can be assigned the <I>nameref</I> attribute using the <B>-n</B> option to the <B>declare</B> or <B>local</B> builtin commands (see the descriptions of <B>declare</B> and <B>local</B> below) to create a <I>nameref</I>, or a reference to another variable. This allows variables to be manipulated indirectly. Whenever the nameref variable is referenced, assigned to, unset, or has its attributes modified (other than using or changing the <I>nameref</I> attribute itself), 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 <P> <DL COMPACT><DT><DD> <TT>declare -n ref=$1</TT> </DL> <P> inside the function creates a nameref variable <B>ref</B> whose value is the variable name passed as the first argument. References and assignments to <B>ref</B>, and changes to its attributes, are treated as references, assignments, and attribute modifications to the variable whose name was passed as <B>$1</B>. If the control variable in a <B>for</B> 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 <B>nameref</B> attribute. However, nameref variables can reference array variables and subscripted array variables. Namerefs can be unset using the <B>-n</B> option to the <B>unset</B> builtin. Otherwise, if <B>unset</B> is executed with the name of a nameref variable as an argument, the variable referenced by the nameref variable will be unset. <A NAME="lbAU">&nbsp;</A> <H4>Positional Parameters</H4> <P> A <I>positional parameter</I> 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 <B>set</B> builtin command. Positional parameters may not be assigned to with assignment statements. The positional parameters are temporarily replaced when a shell function is executed (see <FONT SIZE=-1><B>FUNCTIONS</B> </FONT> below). <P> When a positional parameter consisting of more than a single digit is expanded, it must be enclosed in braces (see <FONT SIZE=-1><B>EXPANSION</B> </FONT> below). <A NAME="lbAV">&nbsp;</A> <H4>Special Parameters</H4> <P> The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. <DL COMPACT> <DT><B>*</B> <DD> 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 <FONT SIZE=-1><B>IFS</B> </FONT> special variable. That is, &quot;<B>$*</B>&quot; is equivalent to &quot;<B>$1</B><I>c</I><B>$2</B><I>c</I><B>...</B>&quot;, where <I>c</I> is the first character of the value of the <FONT SIZE=-1><B>IFS</B> </FONT> variable. If <FONT SIZE=-1><B>IFS</B> </FONT> is unset, the parameters are separated by spaces. If <FONT SIZE=-1><B>IFS</B> </FONT> is null, the parameters are joined without intervening separators. <DT><B>@</B> <DD> Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, &quot;<B>$@</B>&quot; is equivalent to &quot;<B>$1</B>&quot; &quot;<B>$2</B>&quot; ... 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, &quot;<B>$@</B>&quot; and <B>$@</B> expand to nothing (i.e., they are removed). <DT><B>#</B> <DD> Expands to the number of positional parameters in decimal. <DT><B>?</B> <DD> Expands to the exit status of the most recently executed foreground pipeline. <DT><B>-</B> <DD> Expands to the current option flags as specified upon invocation, by the <B>set</B> builtin command, or those set by the shell itself (such as the <B>-i</B> option). <DT><B>$</B> <DD> Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the current shell, not the subshell. <DT><B>!</B> <DD> Expands to the process ID of the job most recently placed into the background, whether executed as an asynchronous command or using the <B>bg</B> builtin (see <FONT SIZE=-1><B>JOB CONTROL</B> </FONT> below). <DT><B>0</B> <DD> Expands to the name of the shell or shell script. This is set at shell initialization. If <B>bash</B> is invoked with a file of commands, <B>$0</B> is set to the name of that file. If <B>bash</B> is started with the <B>-c</B> option, then <B>$0</B> 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 <B>bash</B>, as given by argument zero. <DT><B>_</B> <DD> 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 currently being checked. </DL> <A NAME="lbAW">&nbsp;</A> <H4>Shell Variables</H4> <P> The following variables are set by the shell: <P> <DL COMPACT> <DT><B>BASH</B> <DD> Expands to the full filename used to invoke this instance of <B>bash</B>. <DT><B>BASHOPTS</B> <DD> A colon-separated list of enabled shell options. Each word in the list is a valid argument for the <B>-s</B> option to the <B>shopt</B> builtin command (see <FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B> </FONT> below). The options appearing in <FONT SIZE=-1><B>BASHOPTS</B> </FONT> are those reported as <I>on</I> by <B>shopt</B>. If this variable is in the environment when <B>bash</B> starts up, each shell option in the list will be enabled before reading any startup files. This variable is read-only. <DT><B>BASHPID</B> <DD> Expands to the process ID of the current <B>bash</B> process. This differs from <B>$$</B> under certain circumstances, such as subshells that do not require <B>bash</B> to be re-initialized. <DT><B>BASH_ALIASES</B> <DD> An associative array variable whose members correspond to the internal list of aliases as maintained by the <B>alias</B> builtin. Elements added to this array appear in the alias list; however, unsetting array elements currently does not cause aliases to be removed from the alias list. If <B>BASH_ALIASES</B> is unset, it loses its special properties, even if it is subsequently reset. <DT><B>BASH_ARGC</B> <DD> An array variable whose values are the number of parameters in each frame of the current <B>bash</B> execution call stack. The number of parameters to the current subroutine (shell function or script executed with <B>.</B> or <B>source</B>) is at the top of the stack. When a subroutine is executed, the number of parameters passed is pushed onto <FONT SIZE=-1><B>BASH_ARGC</B>. </FONT> The shell sets <FONT SIZE=-1><B>BASH_ARGC</B> </FONT> only when in extended debugging mode (see the description of the <B>extdebug</B> option to the <B>shopt</B> builtin below) <DT><B>BASH_ARGV</B> <DD> An array variable containing all of the parameters in the current <B>bash</B> execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom. When a subroutine is executed, the parameters supplied are pushed onto <FONT SIZE=-1><B>BASH_ARGV</B>. </FONT> The shell sets <FONT SIZE=-1><B>BASH_ARGV</B> </FONT> only when in extended debugging mode (see the description of the <B>extdebug</B> option to the <B>shopt</B> builtin below) <DT><B>BASH_CMDS</B> <DD> An associative array variable whose members correspond to the internal hash table of commands as maintained by the <B>hash</B> builtin. Elements added to this array appear in the hash table; however, unsetting array elements currently does not cause command names to be removed from the hash table. If <B>BASH_CMDS</B> is unset, it loses its special properties, even if it is subsequently reset. <DT><B>BASH_COMMAND</B> <DD> The command currently being executed or about to be executed, 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. <DT><B>BASH_EXECUTION_STRING</B> <DD> The command argument to the <B>-c</B> invocation option. <DT><B>BASH_LINENO</B> <DD> An array variable whose members are the line numbers in source files where each corresponding member of <FONT SIZE=-1><B>FUNCNAME</B> </FONT> was invoked. <B>${BASH_LINENO[</B><I>$i</I><B>]}</B> is the line number in the source file (<B>${BASH_SOURCE[</B><I>$i+1</I><B>]}</B>) where <B>${FUNCNAME[</B><I>$i</I><B>]}</B> was called (or <B>${BASH_LINENO[</B><I>$i-1</I><B>]}</B> if referenced within another shell function). Use <FONT SIZE=-1><B>LINENO</B> </FONT> to obtain the current line number. <DT><B>BASH_LOADABLES_PATH</B> <DD> A colon-separated list of directories in which the shell looks for dynamically loadable builtins specified by the <B>enable</B> command. <DT><B>BASH_REMATCH</B> <DD> An array variable whose members are assigned by the <B>=~</B> binary opera