<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><!-- Created on October, 3 2005 by texi2html 1.64 --><!--
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
Karl Berry <karl@freefriends.org>
Olaf Bachmann <obachman@mathematik.uni-kl.de>
and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
-->
<HEAD><TITLE>Bash Reference Manual: </TITLE><META NAME="description" CONTENT="Bash Reference Manual: "><META NAME="keywords" CONTENT="Bash Reference Manual: "><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META NAME="Generator" CONTENT="texi2html 1.64"></HEAD><BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000"><A NAME="SEC_Top"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1>Bash Reference Manual</H1></P><P>
This text is a brief description of the features that are present in
the Bash shell (version 3.1-beta1, 5 September 2005)..
</P><P>
This is Edition 3.1-beta1, last updated 5 September 2005,
of <CITE>The GNU Bash Reference Manual</CITE>,
for <CODE>Bash</CODE>, Version 3.1-beta1.
</P><P>
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 (<TT>`sh'</TT>), the Korn Shell
(<TT>`ksh'</TT>), and the C-shell (<TT>`csh'</TT> and its successor,
<TT>`tcsh'</TT>). The following menu breaks the features up into
categories based upon which one of these other shells inspired the
feature.
</P><P>
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.
</P><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC1">1. Introduction</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">An introduction to the shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC4">2. Definitions</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Some definitions used in the rest of this
manual.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC5">3. Basic Shell Features</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The shell "building blocks".</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC56">4. Shell Builtin Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Commands that are a part of the shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC61">5. Shell Variables</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Variables used or set by Bash.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC64">6. Bash Features</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Features found only in Bash.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC87">7. Job Control</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">What job control is and how Bash allows you
to use it.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC115">9. Using History Interactively</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Command History Expansion</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC91">8. Command Line Editing</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Chapter describing the command line
editing features.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC122">10. Installing Bash</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to build and install Bash on your system.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC131">A. Reporting Bugs</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to report bugs in Bash.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC132">B. Major Differences From The Bourne Shell</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A terse list of the differences
between Bash and historical
versions of /bin/sh.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC134">C. Copying This Manual</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Copying this manual.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC137">Index of Shell Builtin Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Index of Bash builtin commands.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC138">Index of Shell Reserved Words</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Index of Bash reserved words.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC139">Parameter and Variable Index</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Quick reference helps you find the
variable you want.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC140">Function Index</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Index of bindable Readline functions.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC141">Concept Index</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">General index for concepts described in
this manual.</TD></TR></TABLE></BLOCKQUOTE><P><HR SIZE=1><A NAME="SEC1"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC2">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><A NAME="Introduction"></A><H1> 1. Introduction </H1><!--docid::SEC1::--><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC2">1.1 What is Bash?</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A short description of Bash.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC3">1.2 What is a shell?</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A brief introduction to shells.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="What is Bash?"></A><HR SIZE="6"><A NAME="SEC2"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC3">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 1.1 What is Bash? </H2><!--docid::SEC2::--><P>
Bash is the shell, or command language interpreter,
for the GNU operating system.
The name is an acronym for the <SAMP>`Bourne-Again SHell'</SAMP>,
a pun on Stephen Bourne, the author of the direct ancestor of
the current Unix shell <CODE>sh</CODE>,
which appeared in the Seventh Edition Bell Labs Research version
of Unix.
</P><P>
Bash is largely compatible with <CODE>sh</CODE> and incorporates useful
features from the Korn shell <CODE>ksh</CODE> and the C shell <CODE>csh</CODE>.
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 <CODE>sh</CODE> for both interactive and
programming use.
</P><P>
While the GNU operating system provides other shells, including
a version of <CODE>csh</CODE>, 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,
and Windows platforms.
</P><P><A NAME="What is a shell?"></A><HR SIZE="6"><A NAME="SEC3"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC2">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[ &lt;&lt; ]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC1"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 1.2 What is a shell? </H2><!--docid::SEC3::--><P>
At its base, a shell is simply a macro processor that executes
commands. The term macro processor means functionality where text
and symbols are expanded to create larger expressions.
</P><P>
A Unix shell is both a command interpreter and a programming
language. As a command interpreter, the shell provides the user
interface to the rich set of GNU utilities. The programming
language features allow 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 <TT>`/bin'</TT>, allowing users
or groups to establish custom environments to automate their common
tasks.
</P><P>
Shells may be used interactively or non-interactively. In
interactive mode, they accept input typed from the keyboard.
When executing non-interactively, shells execute commands read
from a file.
</P><P>
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 <EM>redirection</EM> constructs permit
fine-grained control of the input and output of those commands.
Moreover, the shell allows control over the contents of commands'
environments.
</P><P>
Shells also provide a small set of built-in
commands (<EM>builtins</EM>) implementing functionality impossible
or inconvenient to obtain via separate utilities.
For example, <CODE>cd</CODE>, <CODE>break</CODE>, <CODE>continue</CODE>, and
<CODE>exec</CODE>) cannot be implemented outside of the shell because
they directly manipulate the shell itself.
The <CODE>history</CODE>, <CODE>getopts</CODE>, <CODE>kill</CODE>, or <CODE>pwd</CODE>
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.
</P><P>
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.
</P><P>
Shells offer features geared specifically for
interactive use rather than to augment the programming language.
These interactive features include job control, command line
editing, command history and aliases. Each of these features is
described in this manual.
</P><P><A NAME="Definitions"></A><HR SIZE="6"><A NAME="SEC4"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC3">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1> 2. Definitions </H1><!--docid::SEC4::-->
These definitions are used throughout the remainder of this manual.
<P><DL COMPACT><DT><CODE>POSIX</CODE><DD><A NAME="IDX1"></A>
A family of open system standards based on Unix. Bash
is concerned with POSIX 1003.2, the Shell and Tools Standard.
<P><DT><CODE>blank</CODE><DD>A space or tab character.
<P><DT><CODE>builtin</CODE><DD><A NAME="IDX2"></A>
A command that is implemented internally by the shell itself, rather
than by an executable program somewhere in the file system.
<P><DT><CODE>control operator</CODE><DD><A NAME="IDX3"></A>
A <CODE>word</CODE> that performs a control function. It is a <CODE>newline</CODE>
or one of the following:
<SAMP>`||'</SAMP>, <SAMP>`&#38;&#38;'</SAMP>, <SAMP>`&#38;'</SAMP>, <SAMP>`;'</SAMP>, <SAMP>`;;'</SAMP>,
<SAMP>`|'</SAMP>, <SAMP>`('</SAMP>, or <SAMP>`)'</SAMP>.
<P><DT><CODE>exit status</CODE><DD><A NAME="IDX4"></A>
The value returned by a command to its caller. The value is restricted
to eight bits, so the maximum value is 255.
<P><DT><CODE>field</CODE><DD><A NAME="IDX5"></A>
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.
<P><DT><CODE>filename</CODE><DD><A NAME="IDX6"></A>
A string of characters used to identify a file.
<P><DT><CODE>job</CODE><DD><A NAME="IDX7"></A>
A set of processes comprising a pipeline, and any processes descended
from it, that are all in the same process group.
<P><DT><CODE>job control</CODE><DD><A NAME="IDX8"></A>
A mechanism by which users can selectively stop (suspend) and restart
(resume) execution of processes.
<P><DT><CODE>metacharacter</CODE><DD><A NAME="IDX9"></A>
A character that, when unquoted, separates words. A metacharacter is
a <CODE>blank</CODE> or one of the following characters:
<SAMP>`|'</SAMP>, <SAMP>`&#38;'</SAMP>, <SAMP>`;'</SAMP>, <SAMP>`('</SAMP>, <SAMP>`)'</SAMP>, <SAMP>`&#60;'</SAMP>, or
<SAMP>`&#62;'</SAMP>.
<P><DT><CODE>name</CODE><DD><A NAME="IDX10"></A><A NAME="IDX11"></A>
A <CODE>word</CODE> consisting solely of letters, numbers, and underscores,
and beginning with a letter or underscore. <CODE>Name</CODE>s are used as
shell variable and function names.
Also referred to as an <CODE>identifier</CODE>.
<P><DT><CODE>operator</CODE><DD><A NAME="IDX12"></A>
A <CODE>control operator</CODE> or a <CODE>redirection operator</CODE>.
See section <A HREF="bashref.html#SEC38">3.6 Redirections</A>, for a list of redirection operators.
<P><DT><CODE>process group</CODE><DD><A NAME="IDX13"></A>
A collection of related processes each having the same process
group ID.
<P><DT><CODE>process group ID</CODE><DD><A NAME="IDX14"></A>
A unique identifer that represents a <CODE>process group</CODE>
during its lifetime.
<P><DT><CODE>reserved word</CODE><DD><A NAME="IDX15"></A>
A <CODE>word</CODE> that has a special meaning to the shell. Most reserved
words introduce shell flow control constructs, such as <CODE>for</CODE> and
<CODE>while</CODE>.
<P><DT><CODE>return status</CODE><DD><A NAME="IDX16"></A>
A synonym for <CODE>exit status</CODE>.
<P><DT><CODE>signal</CODE><DD><A NAME="IDX17"></A>
A mechanism by which a process may be notified by the kernel
of an event occurring in the system.
<P><DT><CODE>special builtin</CODE><DD><A NAME="IDX18"></A>
A shell builtin command that has been classified as special by the
POSIX 1003.2 standard.
<P><DT><CODE>token</CODE><DD><A NAME="IDX19"></A>
A sequence of characters considered a single unit by the shell. It is
either a <CODE>word</CODE> or an <CODE>operator</CODE>.
<P><DT><CODE>word</CODE><DD><A NAME="IDX20"></A>
A <CODE>token</CODE> that is not an <CODE>operator</CODE>.
</DL><P><A NAME="Basic Shell Features"></A><HR SIZE="6"><A NAME="SEC5"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC4">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1> 3. Basic Shell Features </H1><!--docid::SEC5::--><P>
Bash is an acronym for <SAMP>`Bourne-Again SHell'</SAMP>.
The Bourne shell is
the traditional Unix shell originally written by Stephen Bourne.
All of the Bourne shell builtin commands are available in Bash,
The rules for evaluation and quoting are taken from the POSIX
specification for the `standard' Unix shell.
</P><P>
This chapter briefly summarizes the shell's `building blocks':
commands, control structures, shell functions, shell <I>parameters</I>,
shell expansions,
<I>redirections</I>, which are a way to direct input and output from
and to named files, and how the shell executes commands.
</P><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC6">3.1 Shell Syntax</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">What your input means to the shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC15">3.2 Shell Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The types of commands you can use.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC23">3.3 Shell Functions</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Grouping commands by name.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC24">3.4 Shell Parameters</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How the shell stores values.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC27">3.5 Shell Expansions</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How Bash expands parameters and the various
expansions available.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC38">3.6 Redirections</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A way to control where input and output go.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC48">3.7 Executing Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">What happens when you run a command.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC55">3.8 Shell Scripts</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Executing files of shell commands.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="Shell Syntax"></A><HR SIZE="6"><A NAME="SEC6"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC7">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.1 Shell Syntax </H2><!--docid::SEC6::--><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC7">3.1.1 Shell Operation</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The basic operation of the shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC8">3.1.2 Quoting</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to remove the special meaning from characters.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC14">3.1.3 Comments</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to specify comments.</TD></TR></TABLE></BLOCKQUOTE><P>
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 (<SAMP>`#'</SAMP>), 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.
</P><P>
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.
</P><P><A NAME="Shell Operation"></A><HR SIZE="6"><A NAME="SEC7"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.1.1 Shell Operation </H3><!--docid::SEC7::--><P>
The following is a brief description of the shell's operation when it
reads and executes a command. Basically, the shell does the
following:
</P><P><OL><LI>
Reads its input from a file (see section <A HREF="bashref.html#SEC55">3.8 Shell Scripts</A>), from a string
supplied as an argument to the <SAMP>`-c'</SAMP> invocation option
(see section <A HREF="bashref.html#SEC65">6.1 Invoking Bash</A>), or from the user's terminal.
<P><LI>
Breaks the input into words and operators, obeying the quoting rules
described in <A HREF="bashref.html#SEC8">3.1.2 Quoting</A>. These tokens are separated by
<CODE>metacharacters</CODE>. Alias expansion is performed by this step
(see section <A HREF="bashref.html#SEC80">6.6 Aliases</A>).
<P><LI>
Parses the tokens into simple and compound commands
(see section <A HREF="bashref.html#SEC15">3.2 Shell Commands</A>).
<P><LI>
Performs the various shell expansions (see section <A HREF="bashref.html#SEC27">3.5 Shell Expansions</A>), breaking
the expanded tokens into lists of filenames (see section <A HREF="bashref.html#SEC35">3.5.8 Filename Expansion</A>)
and commands and arguments.
<P><LI>
Performs any necessary redirections (see section <A HREF="bashref.html#SEC38">3.6 Redirections</A>) and removes
the redirection operators and their operands from the argument list.
<P><LI>
Executes the command (see section <A HREF="bashref.html#SEC48">3.7 Executing Commands</A>).
<P><LI>
Optionally waits for the command to complete and collects its exit
status (see section <A HREF="bashref.html#SEC53">3.7.5 Exit Status</A>).
<P></OL><P><A NAME="Quoting"></A><HR SIZE="6"><A NAME="SEC8"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC7">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC9">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.1.2 Quoting </H3><!--docid::SEC8::--><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC9">3.1.2.1 Escape Character</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to remove the special meaning from a single
character.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC10">3.1.2.2 Single Quotes</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to inhibit all interpretation of a sequence
of characters.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC11">3.1.2.3 Double Quotes</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to suppress most of the interpretation of a
sequence of characters.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC12">3.1.2.4 ANSI-C Quoting</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to expand ANSI-C sequences in quoted strings.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC13">3.1.2.5 Locale-Specific Translation</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to translate strings into different languages.</TD></TR></TABLE></BLOCKQUOTE><P>
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.
</P><P>
Each of the shell metacharacters (see section <A HREF="bashref.html#SEC4">2. Definitions</A>)
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
(see section <A HREF="bashref.html#SEC118">9.3 History Expansion</A>), the
<VAR>history expansion</VAR> character, usually <SAMP>`!'</SAMP>, must be quoted
to prevent history expansion. See section <A HREF="bashref.html#SEC116">9.1 Bash History Facilities</A>, for
more details concerning history expansion.
</P><P>
There are three quoting mechanisms: the
<VAR>escape character</VAR>, single quotes, and double quotes.
</P><P><A NAME="Escape Character"></A><HR SIZE="6"><A NAME="SEC9"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC10">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.1.2.1 Escape Character </H4><!--docid::SEC9::-->
A non-quoted backslash <SAMP>`\'</SAMP> is the Bash escape character.
It preserves the literal value of the next character that follows,
with the exception of <CODE>newline</CODE>. If a <CODE>\newline</CODE> pair
appears, and the backslash itself is not quoted, the <CODE>\newline</CODE>
is treated as a line continuation (that is, it is removed from
the input stream and effectively ignored).
<P><A NAME="Single Quotes"></A><HR SIZE="6"><A NAME="SEC10"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC9">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC11">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC11">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.1.2.2 Single Quotes </H4><!--docid::SEC10::--><P>
Enclosing characters in single quotes (<SAMP>`''</SAMP>) 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><P><A NAME="Double Quotes"></A><HR SIZE="6"><A NAME="SEC11"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC10">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC12">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC12">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.1.2.3 Double Quotes </H4><!--docid::SEC11::--><P>
Enclosing characters in double quotes (<SAMP>`"'</SAMP>) preserves the literal value
of all characters within the quotes, with the exception of
<SAMP>`$'</SAMP>, <SAMP>``'</SAMP>, <SAMP>`\'</SAMP>,
and, when history expansion is enabled, <SAMP>`!'</SAMP>.
The characters <SAMP>`$'</SAMP> and <SAMP>``'</SAMP>
retain their special meaning within double quotes (see section <A HREF="bashref.html#SEC27">3.5 Shell Expansions</A>).
The backslash retains its special meaning only when followed by one of
the following characters:
<SAMP>`$'</SAMP>, <SAMP>``'</SAMP>, <SAMP>`"'</SAMP>, <SAMP>`\'</SAMP>, or <CODE>newline</CODE>.
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.
If enabled, history expansion will be performed unless an <SAMP>`!'</SAMP>
appearing in double quotes is escaped using a backslash.
The backslash preceding the <SAMP>`!'</SAMP> is not removed.
</P><P>
The special parameters <SAMP>`*'</SAMP> and <SAMP>`@'</SAMP> have special meaning
when in double quotes (see section <A HREF="bashref.html#SEC30">3.5.3 Shell Parameter Expansion</A>).
</P><P><A NAME="ANSI-C Quoting"></A><HR SIZE="6"><A NAME="SEC12"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC11">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC13">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC13">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.1.2.4 ANSI-C Quoting </H4><!--docid::SEC12::--><P>
Words of the form <CODE>$'<VAR>string</VAR>'</CODE> are treated specially. The
word expands to <VAR>string</VAR>, with backslash-escaped characters replaced
as specified by the ANSI C standard. Backslash escape sequences, if
present, are decoded as follows:
</P><P><DL COMPACT><DT><CODE>\a</CODE><DD>alert (bell)
<DT><CODE>\b</CODE><DD>backspace
<DT><CODE>\e</CODE><DD>an escape character (not ANSI C)
<DT><CODE>\f</CODE><DD>form feed
<DT><CODE>\n</CODE><DD>newline
<DT><CODE>\r</CODE><DD>carriage return
<DT><CODE>\t</CODE><DD>horizontal tab
<DT><CODE>\v</CODE><DD>vertical tab
<DT><CODE>\\</CODE><DD>backslash
<DT><CODE>\'</CODE><DD>single quote
<DT><CODE>\<VAR>nnn</VAR></CODE><DD>the eight-bit character whose value is the octal value <VAR>nnn</VAR>
(one to three digits)
<DT><CODE>\x<VAR>HH</VAR></CODE><DD>the eight-bit character whose value is the hexadecimal value <VAR>HH</VAR>
(one or two hex digits)
<DT><CODE>\c<VAR>x</VAR></CODE><DD>a control-<VAR>x</VAR> character
</DL><P>
The expanded result is single-quoted, as if the dollar sign had not
been present.
</P><P><A NAME="Locale Translation"></A><HR SIZE="6"><A NAME="SEC13"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC12">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC8"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.1.2.5 Locale-Specific Translation </H4><!--docid::SEC13::--><P>
A double-quoted string preceded by a dollar sign (<SAMP>`$'</SAMP>) will cause
the string to be translated according to the current locale.
If the current locale is <CODE>C</CODE> or <CODE>POSIX</CODE>, the dollar sign
is ignored.
If the string is translated and replaced, the replacement is
double-quoted.
</P><P><A NAME="IDX21"></A><A NAME="IDX22"></A><A NAME="IDX23"></A>
Some systems use the message catalog selected by the <CODE>LC_MESSAGES</CODE>
shell variable. Others create the name of the message catalog from the
value of the <CODE>TEXTDOMAIN</CODE> shell variable, possibly adding a
suffix of <SAMP>`.mo'</SAMP>. If you use the <CODE>TEXTDOMAIN</CODE> variable, you
may need to set the <CODE>TEXTDOMAINDIR</CODE> variable to the location of
the message catalog files. Still others use both variables in this
fashion:
<CODE>TEXTDOMAINDIR</CODE>/<CODE>LC_MESSAGES</CODE>/LC_MESSAGES/<CODE>TEXTDOMAIN</CODE>.mo.
</P><P><A NAME="Comments"></A><HR SIZE="6"><A NAME="SEC14"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC13">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC6"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.1.3 Comments </H3><!--docid::SEC14::--><P>
In a non-interactive shell, or an interactive shell in which the
<CODE>interactive_comments</CODE> option to the <CODE>shopt</CODE>
builtin is enabled (see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>),
a word beginning with <SAMP>`#'</SAMP>
causes that word and all remaining characters on that line to
be ignored. An interactive shell without the <CODE>interactive_comments</CODE>
option enabled does not allow comments. The <CODE>interactive_comments</CODE>
option is on by default in interactive shells.
See section <A HREF="bashref.html#SEC74">6.3 Interactive Shells</A>, for a description of what makes
a shell interactive.
</P><P><A NAME="Shell Commands"></A><HR SIZE="6"><A NAME="SEC15"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC14">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC16">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.2 Shell Commands </H2><!--docid::SEC15::--><P>
A simple shell command such as <CODE>echo a b c</CODE> consists of the command
itself followed by arguments, separated by spaces.
</P><P>
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.
</P><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC16">3.2.1 Simple Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The most common type of command.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC17">3.2.2 Pipelines</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Connecting the input and output of several
commands.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to execute commands sequentially.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC19">3.2.4 Compound Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Shell commands for control flow.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="Simple Commands"></A><HR SIZE="6"><A NAME="SEC16"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC17">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.1 Simple Commands </H3><!--docid::SEC16::--><P>
A simple command is the kind of command encountered most often.
It's just a sequence of words separated by <CODE>blank</CODE>s, terminated
by one of the shell's control operators (see section <A HREF="bashref.html#SEC4">2. Definitions</A>). The
first word generally specifies a command to be executed, with the
rest of the words being that command's arguments.
</P><P>
The return status (see section <A HREF="bashref.html#SEC53">3.7.5 Exit Status</A>) of a simple command is
its exit status as provided
by the POSIX 1003.1 <CODE>waitpid</CODE> function, or 128+<VAR>n</VAR> if
the command was terminated by signal <VAR>n</VAR>.
</P><P><A NAME="Pipelines"></A><HR SIZE="6"><A NAME="SEC17"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC16">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.2 Pipelines </H3><!--docid::SEC17::--><P>
A <CODE>pipeline</CODE> is a sequence of simple commands separated by
<SAMP>`|'</SAMP>.
</P><P><A NAME="IDX24"></A><A NAME="IDX25"></A><A NAME="IDX26"></A>
The format for a pipeline is
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<CODE>time</CODE> [<CODE>-p</CODE>]] [<CODE>!</CODE>] <VAR>command1</VAR> [<CODE>|</CODE><VAR>command2</VAR><small>...</small>]
</pre></td></tr></table></P><P>
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.
</P><P>
The reserved word <CODE>time</CODE> 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 <SAMP>`-p'</SAMP> option changes the output format to that specified
by POSIX.
The <CODE>TIMEFORMAT</CODE> variable may be set to a format string that
specifies how the timing information should be displayed.
See section <A HREF="bashref.html#SEC63">5.2 Bash Variables</A>, for a description of the available formats.
The use of <CODE>time</CODE> as a reserved word permits the timing of
shell builtins, shell functions, and pipelines. An external
<CODE>time</CODE> command cannot time these easily.
</P><P>
If the pipeline is not executed asynchronously (see section <A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A>), the
shell waits for all commands in the pipeline to complete.
</P><P>
Each command in a pipeline is executed in its own subshell
(see section <A HREF="bashref.html#SEC51">3.7.3 Command Execution Environment</A>). The exit
status of a pipeline is the exit status of the last command in the
pipeline, unless the <CODE>pipefail</CODE> option is enabled
(see section <A HREF="bashref.html#SEC59">4.3 The Set Builtin</A>).
If <CODE>pipefail</CODE> 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 <SAMP>`!'</SAMP> precedes the pipeline, the
exit status 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><P><A NAME="Lists"></A><HR SIZE="6"><A NAME="SEC18"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC17">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.3 Lists of Commands </H3><!--docid::SEC18::--><P>
A <CODE>list</CODE> is a sequence of one or more pipelines separated by one
of the operators <SAMP>`;'</SAMP>, <SAMP>`&#38;'</SAMP>, <SAMP>`&#38;&#38;'</SAMP>, or <SAMP>`||'</SAMP>,
and optionally terminated by one of <SAMP>`;'</SAMP>, <SAMP>`&#38;'</SAMP>, or a
<CODE>newline</CODE>.
</P><P>
Of these list operators, <SAMP>`&#38;&#38;'</SAMP> and <SAMP>`||'</SAMP>
have equal precedence, followed by <SAMP>`;'</SAMP> and <SAMP>`&#38;'</SAMP>,
which have equal precedence.
</P><P>
A sequence of one or more newlines may appear in a <CODE>list</CODE>
to delimit commands, equivalent to a semicolon.
</P><P>
If a command is terminated by the control operator <SAMP>`&#38;'</SAMP>,
the shell executes the command asynchronously in a subshell.
This is known as executing the command in the <VAR>background</VAR>.
The shell does not wait for the command to finish, and the return
status is 0 (true).
When job control is not active (see section <A HREF="bashref.html#SEC87">7. Job Control</A>),
the standard input for asynchronous commands, in the absence of any
explicit redirections, is redirected from <CODE>/dev/null</CODE>.
</P><P>
Commands separated by a <SAMP>`;'</SAMP> 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><P>
The control operators <SAMP>`&#38;&#38;'</SAMP> and <SAMP>`||'</SAMP>
denote AND lists and OR lists, respectively.
An AND list has the form
<TABLE><tr><td>&nbsp;</td><td class=example><pre><VAR>command1</VAR>&#38;&#38;<VAR>command2</VAR></pre></td></tr></table></P><P><VAR>command2</VAR> is executed if, and only if, <VAR>command1</VAR>
returns an exit status of zero.
</P><P>
An OR list has the form
<TABLE><tr><td>&nbsp;</td><td class=example><pre><VAR>command1</VAR> || <VAR>command2</VAR></pre></td></tr></table></P><P><VAR>command2</VAR> is executed if, and only if, <VAR>command1</VAR>
returns a non-zero exit status.
</P><P>
The return status of
AND and OR lists is the exit status of the last command
executed in the list.
</P><P><A NAME="Compound Commands"></A><HR SIZE="6"><A NAME="SEC19"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC18">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC20">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC15"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.2.4 Compound Commands </H3><!--docid::SEC19::--><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC20">3.2.4.1 Looping Constructs</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Shell commands for iterative action.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC21">3.2.4.2 Conditional Constructs</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Shell commands for conditional execution.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC22">3.2.4.3 Grouping Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Ways to group commands.</TD></TR></TABLE></BLOCKQUOTE><P>
Compound commands are the shell programming constructs.
Each construct begins with a reserved word or control operator and is
terminated by a corresponding reserved word or operator.
Any redirections (see section <A HREF="bashref.html#SEC38">3.6 Redirections</A>) associated with a compound command
apply to all commands within that compound command unless explicitly overridden.
</P><P>
Bash provides looping constructs, conditional commands, and mechanisms
to group commands and execute them as a unit.
</P><P><A NAME="Looping Constructs"></A><HR SIZE="6"><A NAME="SEC20"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC21">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.2.4.1 Looping Constructs </H4><!--docid::SEC20::--><P>
Bash supports the following looping constructs.
</P><P>
Note that wherever a <SAMP>`;'</SAMP> appears in the description of a
command's syntax, it may be replaced with one or more newlines.
</P><P><DL COMPACT><DT><CODE>until</CODE><DD><A NAME="IDX27"></A><A NAME="IDX28"></A><A NAME="IDX29"></A>
The syntax of the <CODE>until</CODE> command is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>until <VAR>test-commands</VAR>; do <VAR>consequent-commands</VAR>; done
</pre></td></tr></table>Execute <VAR>consequent-commands</VAR> as long as
<VAR>test-commands</VAR> has an exit status which is not zero.
The return status is the exit status of the last command executed
in <VAR>consequent-commands</VAR>, or zero if none was executed.
<P><DT><CODE>while</CODE><DD><A NAME="IDX30"></A>
The syntax of the <CODE>while</CODE> command is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>while <VAR>test-commands</VAR>; do <VAR>consequent-commands</VAR>; done
</pre></td></tr></table><P>
Execute <VAR>consequent-commands</VAR> as long as
<VAR>test-commands</VAR> has an exit status of zero.
The return status is the exit status of the last command executed
in <VAR>consequent-commands</VAR>, or zero if none was executed.
</P><P><DT><CODE>for</CODE><DD><A NAME="IDX31"></A>
The syntax of the <CODE>for</CODE> command is:
<P><TABLE><tr><td>&nbsp;</td><td class=example><pre>for <VAR>name</VAR> [in <VAR>words</VAR><small>...</small>]; do <VAR>commands</VAR>; done
</pre></td></tr></table>Expand <VAR>words</VAR>, and execute <VAR>commands</VAR> once for each member
in the resultant list, with <VAR>name</VAR> bound to the current member.
If <SAMP>`in <VAR>words</VAR>'</SAMP> is not present, the <CODE>for</CODE> command
executes the <VAR>commands</VAR> once for each positional parameter that is
set, as if <SAMP>`in "$@"'</SAMP> had been specified
(see section <A HREF="bashref.html#SEC26">3.4.2 Special Parameters</A>).
The return status is the exit status of the last command that executes.
If there are no items in the expansion of <VAR>words</VAR>, no commands are
executed, and the return status is zero.
</P><P>
An alternate form of the <CODE>for</CODE> command is also supported:
</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>for (( <VAR>expr1</VAR> ; <VAR>expr2</VAR> ; <VAR>expr3</VAR> )) ; do <VAR>commands</VAR> ; done
</pre></td></tr></table>First, the arithmetic expression <VAR>expr1</VAR> is evaluated according
to the rules described below (see section <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>).
The arithmetic expression <VAR>expr2</VAR> is then evaluated repeatedly
until it evaluates to zero.
Each time <VAR>expr2</VAR> evaluates to a non-zero value, <VAR>commands</VAR> are
executed and the arithmetic expression <VAR>expr3</VAR> 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 <VAR>list</VAR>
that is executed, or false if any of the expressions is invalid.
</P><P></DL><P>
The <CODE>break</CODE> and <CODE>continue</CODE> builtins (see section <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>)
may be used to control loop execution.
</P><P><A NAME="Conditional Constructs"></A><HR SIZE="6"><A NAME="SEC21"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC20">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.2.4.2 Conditional Constructs </H4><!--docid::SEC21::--><P><DL COMPACT><DT><CODE>if</CODE><DD><A NAME="IDX32"></A><A NAME="IDX33"></A><A NAME="IDX34"></A><A NAME="IDX35"></A><A NAME="IDX36"></A>
The syntax of the <CODE>if</CODE> command is:
<P><TABLE><tr><td>&nbsp;</td><td class=example><pre>if <VAR>test-commands</VAR>; then
<VAR>consequent-commands</VAR>;
[elif <VAR>more-test-commands</VAR>; then
<VAR>more-consequents</VAR>;]
[else <VAR>alternate-consequents</VAR>;]
fi
</pre></td></tr></table></P><P>
The <VAR>test-commands</VAR> list is executed, and if its return status is zero,
the <VAR>consequent-commands</VAR> list is executed.
If <VAR>test-commands</VAR> returns a non-zero status, each <CODE>elif</CODE> list
is executed in turn, and if its exit status is zero,
the corresponding <VAR>more-consequents</VAR> is executed and the
command completes.
If <SAMP>`else <VAR>alternate-consequents</VAR>'</SAMP> is present, and
the final command in the final <CODE>if</CODE> or <CODE>elif</CODE> clause
has a non-zero exit status, then <VAR>alternate-consequents</VAR> is executed.
The return status is the exit status of the last command executed, or
zero if no condition tested true.
</P><P><DT><CODE>case</CODE><DD><A NAME="IDX37"></A><A NAME="IDX38"></A><A NAME="IDX39"></A>
The syntax of the <CODE>case</CODE> command is:
<P><TABLE><tr><td>&nbsp;</td><td class=example><pre><CODE>case <VAR>word</VAR> in [ [(] <VAR>pattern</VAR> [| <VAR>pattern</VAR>]<small>...</small>) <VAR>command-list</VAR> ;;]<small>...</small> esac</CODE></pre></td></tr></table></P><P><CODE>case</CODE> will selectively execute the <VAR>command-list</VAR> corresponding to
the first <VAR>pattern</VAR> that matches <VAR>word</VAR>.
If the shell option <CODE>nocasematch</CODE>
(see the description of <CODE>shopt</CODE> in <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>)
is enabled, the match is performed without regard to the case
of alphabetic characters.
The <SAMP>`|'</SAMP> is used to separate multiple patterns, and the <SAMP>`)'</SAMP>
operator terminates a pattern list.
A list of patterns and an associated command-list is known
as a <VAR>clause</VAR>. Each clause must be terminated with <SAMP>`;;'</SAMP>.
The <VAR>word</VAR> undergoes tilde expansion, parameter expansion, command
substitution, arithmetic expansion, and quote removal before matching is
attempted. Each <VAR>pattern</VAR> undergoes tilde expansion, parameter
expansion, command substitution, and arithmetic expansion.
</P><P>
There may be an arbitrary number of <CODE>case</CODE> clauses, each terminated
by a <SAMP>`;;'</SAMP>. The first pattern that matches determines the
command-list that is executed.
</P><P>
Here is an example using <CODE>case</CODE> in a script that could be used to
describe one interesting feature of an animal:
</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>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."
</pre></td></tr></table></P><P>
The return status is zero if no <VAR>pattern</VAR> is matched. Otherwise, the
return status is the exit status of the <VAR>command-list</VAR> executed.
</P><P><DT><CODE>select</CODE><DD><A NAME="IDX40"></A><P>
The <CODE>select</CODE> construct allows the easy generation of menus.
It has almost the same syntax as the <CODE>for</CODE> command:
</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>select <VAR>name</VAR> [in <VAR>words</VAR><small>...</small>]; do <VAR>commands</VAR>; done
</pre></td></tr></table></P><P>
The list of words following <CODE>in</CODE> 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
<SAMP>`in <VAR>words</VAR>'</SAMP> is omitted, the positional parameters are printed,
as if <SAMP>`in "$@"'</SAMP> had been specifed.
The <CODE>PS3</CODE> 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 <VAR>name</VAR> is set to that word.
If the line is empty, the words and prompt are displayed again.
If <CODE>EOF</CODE> is read, the <CODE>select</CODE> command completes.
Any other value read causes <VAR>name</VAR> to be set to null.
The line read is saved in the variable <CODE>REPLY</CODE>.
</P><P>
The <VAR>commands</VAR> are executed after each selection until a
<CODE>break</CODE> command is executed, at which
point the <CODE>select</CODE> command completes.
</P><P>
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.
</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>select fname in *;
do
echo you picked $fname \($REPLY\)
break;
done
</pre></td></tr></table></P><P><DT><CODE>((<small>...</small>))</CODE><DD><TABLE><tr><td>&nbsp;</td><td class=example><pre>(( <VAR>expression</VAR> ))
</pre></td></tr></table><P>
The arithmetic <VAR>expression</VAR> is evaluated according to the rules
described below (see section <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>).
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
<TABLE><tr><td>&nbsp;</td><td class=example><pre>let "<VAR>expression</VAR>"
</pre></td></tr></table>See section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>, for a full description of the <CODE>let</CODE> builtin.
</P><P><DT><CODE>[[<small>...</small>]]</CODE><DD><A NAME="IDX41"></A><A NAME="IDX42"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>[[ <VAR>expression</VAR> ]]
</pre></td></tr></table><P>
Return a status of 0 or 1 depending on the evaluation of
the conditional expression <VAR>expression</VAR>.
Expressions are composed of the primaries described below in
<A HREF="bashref.html#SEC78">6.4 Bash Conditional Expressions</A>.
Word splitting and filename expansion are not performed on the words
between the <SAMP>`[['</SAMP> and <SAMP>`]]'</SAMP>; tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution, process
substitution, and quote removal are performed.
Conditional operators such as <SAMP>`-f'</SAMP> must be unquoted to be recognized
as primaries.
</P><P>
When the <SAMP>`=='</SAMP> and <SAMP>`!='</SAMP> operators are used, the string to the
right of the operator is considered a pattern and matched according
to the rules described below in <A HREF="bashref.html#SEC36">3.5.8.1 Pattern Matching</A>.
If the shell option <CODE>nocasematch</CODE>
(see the description of <CODE>shopt</CODE> in <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>)
is enabled, the match is performed without regard to the case
of alphabetic characters.
The return value is 0 if the string matches or does not match
the pattern, respectively, and 1 otherwise.
Any part of the pattern may be quoted to force it to be matched as a
string.
</P><P>
An additional binary operator, <SAMP>`=~'</SAMP>, is available, with the same
precedence as <SAMP>`=='</SAMP> and <SAMP>`!='</SAMP>.
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 shell option <CODE>nocasematch</CODE>
(see the description of <CODE>shopt</CODE> in <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>)
is enabled, the match is performed without regard to the case
of alphabetic characters.
Substrings matched by parenthesized subexpressions within the regular
expression are saved in the array variable <CODE>BASH_REMATCH</CODE>.
The element of <CODE>BASH_REMATCH</CODE> with index 0 is the portion of the string
matching the entire regular expression.
The element of <CODE>BASH_REMATCH</CODE> with index <VAR>n</VAR> is the portion of the
string matching the <VAR>n</VAR>th parenthesized subexpression.
</P><P>
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
</P><P><DL COMPACT><DT><CODE>( <VAR>expression</VAR> )</CODE><DD>Returns the value of <VAR>expression</VAR>.
This may be used to override the normal precedence of operators.
<P><DT><CODE>! <VAR>expression</VAR></CODE><DD>True if <VAR>expression</VAR> is false.
<P><DT><CODE><VAR>expression1</VAR>&#38;&#38;<VAR>expression2</VAR></CODE><DD>True if both <VAR>expression1</VAR> and <VAR>expression2</VAR> are true.
<P><DT><CODE><VAR>expression1</VAR> || <VAR>expression2</VAR></CODE><DD>True if either <VAR>expression1</VAR> or <VAR>expression2</VAR> is true.
</DL>
The <CODE>&#38;&#38;</CODE> and <CODE>||</CODE> operators do not evaluate <VAR>expression2</VAR> if the
value of <VAR>expression1</VAR> is sufficient to determine the return
value of the entire conditional expression.
<P></DL><P><A NAME="Command Grouping"></A><HR SIZE="6"><A NAME="SEC22"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC21">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC19"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.2.4.3 Grouping Commands </H4><!--docid::SEC22::--><P>
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.
</P><P><DL COMPACT><DT><CODE>()</CODE><DD><TABLE><tr><td>&nbsp;</td><td class=example><pre>( <VAR>list</VAR> )
</pre></td></tr></table><P>
Placing a list of commands between parentheses causes a subshell
environment to be created (see section <A HREF="bashref.html#SEC51">3.7.3 Command Execution Environment</A>), and each
of the commands in <VAR>list</VAR> to be executed in that subshell. Since the
<VAR>list</VAR> is executed in a subshell, variable assignments do not remain in
effect after the subshell completes.
</P><P><DT><CODE>{}</CODE><DD><A NAME="IDX43"></A><A NAME="IDX44"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>{ <VAR>list</VAR>; }
</pre></td></tr></table><P>
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 <VAR>list</VAR> is required.
</DL><P>
In addition to the creation of a subshell, there is a subtle difference
between these two constructs due to historical reasons. The braces
are <CODE>reserved words</CODE>, so they must be separated from the <VAR>list</VAR>
by <CODE>blank</CODE>s. The parentheses are <CODE>operators</CODE>, and are
recognized as separate tokens by the shell even if they are not separated
from the <VAR>list</VAR> by whitespace.
</P><P>
The exit status of both of these constructs is the exit status of
<VAR>list</VAR>.
</P><P><A NAME="Shell Functions"></A><HR SIZE="6"><A NAME="SEC23"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC22">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC24">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC24">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.3 Shell Functions </H2><!--docid::SEC23::--><P>
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.
</P><P>
Functions are declared using this syntax:
<A NAME="IDX45"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>[ <CODE>function</CODE> ] <VAR>name</VAR> () <VAR>compound-command</VAR> [ <VAR>redirections</VAR> ]
</pre></td></tr></table></P><P>
This defines a shell function named <VAR>name</VAR>. The reserved
word <CODE>function</CODE> is optional.
If the <CODE>function</CODE> reserved
word is supplied, the parentheses are optional.
The <VAR>body</VAR> of the function is the compound command
<VAR>compound-command</VAR> (see section <A HREF="bashref.html#SEC19">3.2.4 Compound Commands</A>).
That command is usually a <VAR>list</VAR> enclosed between { and }, but
may be any compound command listed above.
<VAR>compound-command</VAR> is executed whenever <VAR>name</VAR> is specified as the
name of a command.
Any redirections (see section <A HREF="bashref.html#SEC38">3.6 Redirections</A>) associated with the shell function
are performed when the function is executed.
</P><P>
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.
</P><P>
Note that for historical reasons, in the most common usage the curly braces
that surround the body of the function must be separated from the body by
<CODE>blank</CODE>s or newlines.
This is because the braces are reserved words and are only recognized
as such when they are separated by whitespace.
Also, when using the braces, the <VAR>list</VAR> must be terminated by a semicolon,
a <SAMP>`&#38;'</SAMP>, or a newline.
</P><P>
When a function is executed, the arguments to the
function become the positional parameters
during its execution (see section <A HREF="bashref.html#SEC25">3.4.1 Positional Parameters</A>).
The special parameter <SAMP>`#'</SAMP> that expands to the number of
positional parameters is updated to reflect the change.
Special parameter <CODE>0</CODE> is unchanged.
The first element of the <CODE>FUNCNAME</CODE> variable is set to the
name of the function while the function is executing.
All other aspects of the shell execution
environment are identical between a function and its caller
with the exception that the <CODE>DEBUG</CODE> and <CODE>RETURN</CODE> traps
are not inherited unless the function has been given the
<CODE>trace</CODE> attribute using the <CODE>declare</CODE> builtin or
the <CODE>-o functrace</CODE> option has been enabled with
the <CODE>set</CODE> builtin,
(in which case all functions inherit the <CODE>DEBUG</CODE> and <CODE>RETURN</CODE> traps).
See section <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>, for the description of the
<CODE>trap</CODE> builtin.
</P><P>
If the builtin command <CODE>return</CODE>
is executed in a function, the function completes and
execution resumes with the next command after the function
call.
Any command associated with the <CODE>RETURN</CODE> trap is executed
before execution resumes.
When a function completes, the values of the
positional parameters and the special parameter <SAMP>`#'</SAMP>
are restored to the values they had prior to the function's
execution. If a numeric argument is given to <CODE>return</CODE>,
that is the function's return status; otherwise the function's
return status is the exit status of the last command executed
before the <CODE>return</CODE>.
</P><P>
Variables local to the function may be declared with the
<CODE>local</CODE> builtin. These variables are visible only to
the function and the commands it invokes.
</P><P>
Function names and definitions may be listed with the
<SAMP>`-f'</SAMP> option to the <CODE>declare</CODE> or <CODE>typeset</CODE>
builtin commands (see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>).
The <SAMP>`-F'</SAMP> option to <CODE>declare</CODE> or <CODE>typeset</CODE>
will list the function names only
(and optionally the source file and line number, if the <CODE>extdebug</CODE>
shell option is enabled).
Functions may be exported so that subshells
automatically have them defined with the
<SAMP>`-f'</SAMP> option to the <CODE>export</CODE> builtin
(see section <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>).
Note that shell functions and variables with the same name may result
in multiple identically-named entries in the environment passed to the
shell's children.
Care should be taken in cases where this may cause a problem.
</P><P>
Functions may be recursive. No limit is placed on the number of
recursive calls.
</P><P><A NAME="Shell Parameters"></A><HR SIZE="6"><A NAME="SEC24"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC23">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC25">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.4 Shell Parameters </H2><!--docid::SEC24::--><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC25">3.4.1 Positional Parameters</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The shell's command-line arguments.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC26">3.4.2 Special Parameters</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Parameters denoted by special characters.</TD></TR></TABLE></BLOCKQUOTE><P>
A <VAR>parameter</VAR> is an entity that stores values.
It can be a <CODE>name</CODE>, a number, or one of the special characters
listed below.
A <VAR>variable</VAR> is a parameter denoted by a <CODE>name</CODE>.
A variable has a <VAR>value</VAR> and zero or more <VAR>attributes</VAR>.
Attributes are assigned using the <CODE>declare</CODE> builtin command
(see the description of the <CODE>declare</CODE> builtin in <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>).
</P><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 <CODE>unset</CODE> builtin command.
</P><P>
A variable may be assigned to by a statement of the form
<TABLE><tr><td>&nbsp;</td><td class=example><pre><VAR>name</VAR>=[<VAR>value</VAR>]
</pre></td></tr></table>If <VAR>value</VAR>
is not given, the variable is assigned the null string. All
<VAR>value</VAR>s undergo tilde expansion, parameter and variable expansion,
command substitution, arithmetic expansion, and quote
removal (detailed below). If the variable has its <CODE>integer</CODE>
attribute set, then <VAR>value</VAR>
is evaluated as an arithmetic expression even if the <CODE>$((<small>...</small>))</CODE>
expansion is not used (see section <A HREF="bashref.html#SEC32">3.5.5 Arithmetic Expansion</A>).
Word splitting is not performed, with the exception
of <CODE>"$@"</CODE> as explained below.
Filename expansion is not performed.
Assignment statements may also appear as arguments to the
<CODE>alias</CODE>,
<CODE>declare</CODE>, <CODE>typeset</CODE>, <CODE>export</CODE>, <CODE>readonly</CODE>,
and <CODE>local</CODE> builtin commands.
</P><P>
In the context where an assignment statement is assigning a value
to a shell variable or array index (see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>), the <SAMP>`+='</SAMP>
operator can be used to
append to or add to the variable's previous value.
When <SAMP>`+='</SAMP> is applied to a variable for which the integer attribute
has been set, <VAR>value</VAR> is evaluated as an arithmetic expression and
added to the variable's current value, which is also evaluated.
When <SAMP>`+='</SAMP> is applied to an array variable using compound assignment
(see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>), the
variable's value is not unset (as it is when using <SAMP>`='</SAMP>), and new
values are appended to the array beginning at one greater than the array's
maximum index.
When applied to a string-valued variable, <VAR>value</VAR> is expanded and
appended to the variable's value.
</P><P><A NAME="Positional Parameters"></A><HR SIZE="6"><A NAME="SEC25"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC24">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC26">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC24"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.4.1 Positional Parameters </H3><!--docid::SEC25::--><P>
A <VAR>positional parameter</VAR> is a parameter denoted by one or more
digits, other than the single digit <CODE>0</CODE>. Positional parameters are
assigned from the shell's arguments when it is invoked,
and may be reassigned using the <CODE>set</CODE> builtin command.
Positional parameter <CODE>N</CODE> may be referenced as <CODE>${N}</CODE>, or
as <CODE>$N</CODE> when <CODE>N</CODE> consists of a single digit.
Positional parameters may not be assigned to with assignment statements.
The <CODE>set</CODE> and <CODE>shift</CODE> builtins are used to set and
unset them (see section <A HREF="bashref.html#SEC56">4. Shell Builtin Commands</A>).
The positional parameters are
temporarily replaced when a shell function is executed
(see section <A HREF="bashref.html#SEC23">3.3 Shell Functions</A>).
</P><P>
When a positional parameter consisting of more than a single
digit is expanded, it must be enclosed in braces.
</P><P><A NAME="Special Parameters"></A><HR SIZE="6"><A NAME="SEC26"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC25">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC24"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.4.2 Special Parameters </H3><!--docid::SEC26::--><P>
The shell treats several parameters specially. These parameters may
only be referenced; assignment to them is not allowed.
</P><P><DL COMPACT><A NAME="IDX46"></A><DT><CODE>*</CODE><DD><A NAME="IDX47"></A>
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 <CODE>IFS</CODE>
special variable. That is, <CODE>"$*"</CODE> is equivalent
to <CODE>"$1<VAR>c</VAR>$2<VAR>c</VAR><small>...</small>"</CODE>, where <VAR>c</VAR>
is the first character of the value of the <CODE>IFS</CODE>
variable.
If <CODE>IFS</CODE> is unset, the parameters are separated by spaces.
If <CODE>IFS</CODE> is null, the parameters are joined without intervening
separators.
<P><A NAME="IDX48"></A><DT><CODE>@</CODE><DD><A NAME="IDX49"></A>
Expands to the positional parameters, starting from one. When the
expansion occurs within double quotes, each parameter expands to a
separate word. That is, <CODE>"$@"</CODE> is equivalent to
<CODE>"$1" "$2" <small>...</small></CODE>.
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, <CODE>"$@"</CODE> and
<CODE>$@</CODE>
expand to nothing (i.e., they are removed).
<P><A NAME="IDX50"></A><DT><CODE>#</CODE><DD><A NAME="IDX51"></A>
Expands to the number of positional parameters in decimal.
<P><A NAME="IDX52"></A><DT><CODE>?</CODE><DD><A NAME="IDX53"></A>
Expands to the exit status of the most recently executed foreground
pipeline.
<P><A NAME="IDX54"></A><DT><CODE>-</CODE><DD><A NAME="IDX55"></A>
(A hyphen.) Expands to the current option flags as specified upon
invocation, by the <CODE>set</CODE>
builtin command, or those set by the shell itself
(such as the <SAMP>`-i'</SAMP> option).
<P><A NAME="IDX56"></A><DT><CODE>$</CODE><DD><A NAME="IDX57"></A>
Expands to the process ID of the shell. In a <CODE>()</CODE> subshell, it
expands to the process ID of the invoking shell, not the subshell.
<P><A NAME="IDX58"></A><DT><CODE>!</CODE><DD><A NAME="IDX59"></A>
Expands to the process ID of the most recently executed background
(asynchronous) command.
<P><A NAME="IDX60"></A><DT><CODE>0</CODE><DD><A NAME="IDX61"></A>
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
(see section <A HREF="bashref.html#SEC55">3.8 Shell Scripts</A>), <CODE>$0</CODE> is set to the name of that file.
If Bash is started with the <SAMP>`-c'</SAMP> option (see section <A HREF="bashref.html#SEC65">6.1 Invoking Bash</A>),
then <CODE>$0</CODE> 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.
<P><A NAME="IDX62"></A><DT><CODE>_</CODE><DD><A NAME="IDX63"></A>
(An underscore.)
At shell startup, set to the absolute pathname used to invoke the
shell or shell script being executed as passed in the environment
or argument list.
Subsequently, expands to the last argument to the previous command,
after expansion.
Also set to the full pathname used to invoke each command executed
and placed in the environment exported to that command.
When checking mail, this parameter holds the name of the mail file.
</DL><P><A NAME="Shell Expansions"></A><HR SIZE="6"><A NAME="SEC27"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC26">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC28">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.5 Shell Expansions </H2><!--docid::SEC27::--><P>
Expansion is performed on the command line after it has been split into
<CODE>token</CODE>s. There are seven kinds of expansion performed:
<UL><LI>brace expansion
<LI>tilde expansion
<LI>parameter and variable expansion
<LI>command substitution
<LI>arithmetic expansion
<LI>word splitting
<LI>filename expansion
</UL><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC28">3.5.1 Brace Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Expansion of expressions within braces.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC29">3.5.2 Tilde Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Expansion of the ~ character.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC30">3.5.3 Shell Parameter Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How Bash expands variables to their values.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC31">3.5.4 Command Substitution</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Using the output of a command as an argument.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC32">3.5.5 Arithmetic Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How to use arithmetic in shell expansions.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC33">3.5.6 Process Substitution</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A way to write and read to and from a
command.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC34">3.5.7 Word Splitting</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How the results of expansion are split into separate
arguments.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC35">3.5.8 Filename Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">A shorthand for specifying filenames matching patterns.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC37">3.5.9 Quote Removal</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How and when quote characters are removed from
words.</TD></TR></TABLE></BLOCKQUOTE><P>
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.
</P><P>
On systems that can support it, there is an additional expansion
available: <VAR>process substitution</VAR>. This is performed at the
same time as parameter, variable, and arithmetic expansion and
command substitution.
</P><P>
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
<CODE>"$@"</CODE> (see section <A HREF="bashref.html#SEC26">3.4.2 Special Parameters</A>) and <CODE>"${<VAR>name</VAR>[@]}"</CODE>
(see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>).
</P><P>
After all expansions, <CODE>quote removal</CODE> (see section <A HREF="bashref.html#SEC37">3.5.9 Quote Removal</A>)
is performed.
</P><P><A NAME="Brace Expansion"></A><HR SIZE="6"><A NAME="SEC28"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC29">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.1 Brace Expansion </H3><!--docid::SEC28::--><P>
Brace expansion is a mechanism by which arbitrary strings may be generated.
This mechanism is similar to
<VAR>filename expansion</VAR> (see section <A HREF="bashref.html#SEC35">3.5.8 Filename Expansion</A>),
but the file names generated need not exist.
Patterns to be brace expanded take the form of an optional <VAR>preamble</VAR>,
followed by either a series of comma-separated strings or a sequnce expression
between a pair of braces,
followed by an optional <VAR>postscript</VAR>.
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.
</P><P>
Brace expansions may be nested.
The results of each expanded string are not sorted; left to right order
is preserved.
For example,
<TABLE><tr><td>&nbsp;</td><td class=example><pre>bash$ echo a{d,c,b}e
ade ace abe
</pre></td></tr></table></P><P>
A sequence expression takes the form <CODE>{<VAR>x</VAR>..<VAR>y</VAR>}</CODE>,
where <VAR>x</VAR> and <VAR>y</VAR> are either integers or single characters.
When integers are supplied, the expression expands to each number between
<VAR>x</VAR> and <VAR>y</VAR>, inclusive.
When characters are supplied, the expression expands to each character
lexicographically between <VAR>x</VAR> and <VAR>y</VAR>, inclusive. Note that
both <VAR>x</VAR> and <VAR>y</VAR> must be of the same type.
</P><P>
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 <SAMP>`${'</SAMP>
is not considered eligible for brace expansion.
</P><P>
A correctly-formed brace expansion must contain unquoted opening
and closing braces, and at least one unquoted comma or a valid
sequence expression.
Any incorrectly formed brace expansion is left unchanged.
</P><P>
A { or <SAMP>`,'</SAMP> may be quoted with a backslash to prevent its
being considered part of a brace expression.
To avoid conflicts with parameter expansion, the string <SAMP>`${'</SAMP>
is not considered eligible for brace expansion.
</P><P>
This construct is typically used as shorthand when the common
prefix of the strings to be generated is longer than in the
above example:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>mkdir /usr/local/src/bash/{old,new,dist,bugs}
</pre></td></tr></table>or
<TABLE><tr><td>&nbsp;</td><td class=example><pre>chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
</pre></td></tr></table></P><P><A NAME="Tilde Expansion"></A><HR SIZE="6"><A NAME="SEC29"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC28">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC30">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC30">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.2 Tilde Expansion </H3><!--docid::SEC29::--><P>
If a word begins with an unquoted tilde character (<SAMP>`~'</SAMP>), all of the
characters up to the first unquoted slash (or all characters,
if there is no unquoted slash) are considered a <VAR>tilde-prefix</VAR>.
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 <VAR>login name</VAR>.
If this login name is the null string, the tilde is replaced with the
value of the <CODE>HOME</CODE> shell variable.
If <CODE>HOME</CODE> 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.
</P><P>
If the tilde-prefix is <SAMP>`~+'</SAMP>, the value of
the shell variable <CODE>PWD</CODE> replaces the tilde-prefix.
If the tilde-prefix is <SAMP>`~-'</SAMP>, the value of the shell variable
<CODE>OLDPWD</CODE>, if it is set, is substituted.
</P><P>
If the characters following the tilde in the tilde-prefix consist of a
number <VAR>N</VAR>, optionally prefixed by a <SAMP>`+'</SAMP> or a <SAMP>`-'</SAMP>,
the tilde-prefix is replaced with the
corresponding element from the directory stack, as it would be displayed
by the <CODE>dirs</CODE> builtin invoked with the characters following tilde
in the tilde-prefix as an argument (see section <A HREF="bashref.html#SEC82">6.8 The Directory Stack</A>).
If the tilde-prefix, sans the tilde, consists of a number without a
leading <SAMP>`+'</SAMP> or <SAMP>`-'</SAMP>, <SAMP>`+'</SAMP> is assumed.
</P><P>
If the login name is invalid, or the tilde expansion fails, the word is
left unchanged.
</P><P>
Each variable assignment is checked for unquoted tilde-prefixes immediately
following a <SAMP>`:'</SAMP> or the first <SAMP>`='</SAMP>.
In these cases, tilde expansion is also performed.
Consequently, one may use file names with tildes in assignments to
<CODE>PATH</CODE>, <CODE>MAILPATH</CODE>, and <CODE>CDPATH</CODE>,
and the shell assigns the expanded value.
</P><P>
The following table shows how Bash treats unquoted tilde-prefixes:
</P><P><DL COMPACT><DT><CODE>~</CODE><DD>The value of <CODE>$HOME</CODE><DT><CODE>~/foo</CODE><DD><TT>`$HOME/foo'</TT><P><DT><CODE>~fred/foo</CODE><DD>The subdirectory <CODE>foo</CODE> of the home directory of the user
<CODE>fred</CODE><P><DT><CODE>~+/foo</CODE><DD><TT>`$PWD/foo'</TT><P><DT><CODE>~-/foo</CODE><DD><TT>`${OLDPWD-'~-'}/foo'</TT><P><DT><CODE>~<VAR>N</VAR></CODE><DD>The string that would be displayed by <SAMP>`dirs +<VAR>N</VAR>'</SAMP><P><DT><CODE>~+<VAR>N</VAR></CODE><DD>The string that would be displayed by <SAMP>`dirs +<VAR>N</VAR>'</SAMP><P><DT><CODE>~-<VAR>N</VAR></CODE><DD>The string that would be displayed by <SAMP>`dirs -<VAR>N</VAR>'</SAMP><P></DL><P><A NAME="Shell Parameter Expansion"></A><HR SIZE="6"><A NAME="SEC30"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC29">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC31">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC31">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.3 Shell Parameter Expansion </H3><!--docid::SEC30::--><P>
The <SAMP>`$'</SAMP> character introduces parameter expansion,
command substitution, or arithmetic expansion. The parameter name
or symbol to be expanded may be enclosed in braces, which
are optional but serve to protect the variable to be expanded from
characters immediately following it which could be
interpreted as part of the name.
</P><P>
When braces are used, the matching ending brace is the first <SAMP>`}'</SAMP>
not escaped by a backslash or within a quoted string, and not within an
embedded arithmetic expansion, command substitution, or parameter
expansion.
</P><P>
The basic form of parameter expansion is ${<VAR>parameter</VAR>}.
The value of <VAR>parameter</VAR> is substituted. The braces are required
when <VAR>parameter</VAR>
is a positional parameter with more than one digit,
or when <VAR>parameter</VAR>
is followed by a character that is not to be
interpreted as part of its name.
</P><P>
If the first character of <VAR>parameter</VAR> is an exclamation point,
a level of variable indirection is introduced.
Bash uses the value of the variable formed from the rest of
<VAR>parameter</VAR> as the name of the variable; this variable is then
expanded and that value is used in the rest of the substitution, rather
than the value of <VAR>parameter</VAR> itself.
This is known as <CODE>indirect expansion</CODE>.
The exceptions to this are the expansions of ${!<VAR>prefix*</VAR>}
and ${!<VAR>name</VAR>[@]}
described below.
The exclamation point must immediately follow the left brace in order to
introduce indirection.
</P><P>
In each of the cases below, <VAR>word</VAR> is subject to tilde expansion,
parameter expansion, command substitution, and arithmetic expansion.
</P><P>
When not performing substring expansion, Bash tests for a parameter
that is unset or null; omitting the colon results in a test only for a
parameter that is unset. Put another way, if the colon is included,
the operator tests for both existence and that the value is not null;
if the colon is omitted, the operator tests only for existence.
</P><P><DL COMPACT><DT><CODE>${<VAR>parameter</VAR>:-<VAR>word</VAR>}</CODE><DD>If <VAR>parameter</VAR> is unset or null, the expansion of
<VAR>word</VAR> is substituted. Otherwise, the value of
<VAR>parameter</VAR> is substituted.
<P><DT><CODE>${<VAR>parameter</VAR>:=<VAR>word</VAR>}</CODE><DD>If <VAR>parameter</VAR>
is unset or null, the expansion of <VAR>word</VAR>
is assigned to <VAR>parameter</VAR>.
The value of <VAR>parameter</VAR> is then substituted.
Positional parameters and special parameters may not be assigned to
in this way.
<P><DT><CODE>${<VAR>parameter</VAR>:?<VAR>word</VAR>}</CODE><DD>If <VAR>parameter</VAR>
is null or unset, the expansion of <VAR>word</VAR> (or a message
to that effect if <VAR>word</VAR>
is not present) is written to the standard error and the shell, if it
is not interactive, exits. Otherwise, the value of <VAR>parameter</VAR> is
substituted.
<P><DT><CODE>${<VAR>parameter</VAR>:+<VAR>word</VAR>}</CODE><DD>If <VAR>parameter</VAR>
is null or unset, nothing is substituted, otherwise the expansion of
<VAR>word</VAR> is substituted.
<P><DT><CODE>${<VAR>parameter</VAR>:<VAR>offset</VAR>}</CODE><DD><DT><CODE>${<VAR>parameter</VAR>:<VAR>offset</VAR>:<VAR>length</VAR>}</CODE><DD>Expands to up to <VAR>length</VAR> characters of <VAR>parameter</VAR>
starting at the character specified by <VAR>offset</VAR>.
If <VAR>length</VAR> is omitted, expands to the substring of
<VAR>parameter</VAR> starting at the character specified by <VAR>offset</VAR>.
<VAR>length</VAR> and <VAR>offset</VAR> are arithmetic expressions
(see section <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>).
This is referred to as Substring Expansion.
<P><VAR>length</VAR> must evaluate to a number greater than or equal to zero.
If <VAR>offset</VAR> evaluates to a number less than zero, the value
is used as an offset from the end of the value of <VAR>parameter</VAR>.
If <VAR>parameter</VAR> is <SAMP>`@'</SAMP>, the result is <VAR>length</VAR> positional
parameters beginning at <VAR>offset</VAR>.
If <VAR>parameter</VAR> is an array name indexed by <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the result is the <VAR>length</VAR>
members of the array beginning with <CODE>${<VAR>parameter</VAR>[<VAR>offset</VAR>]}</CODE>.
A negative <VAR>offset</VAR> is taken relative to one greater than the maximum
index of the specified array.
Note that a negative offset must be separated from the colon by at least
one space to avoid being confused with the <SAMP>`:-'</SAMP> expansion.
Substring indexing is zero-based unless the positional parameters
are used, in which case the indexing starts at 1.
</P><P><DT><CODE>${!<VAR>prefix</VAR>*}</CODE><DD><DT><CODE>${!<VAR>prefix</VAR>@}</CODE><DD>Expands to the names of variables whose names begin with <VAR>prefix</VAR>,
separated by the first character of the <CODE>IFS</CODE> special variable.
<P><DT><CODE>${!<VAR>name</VAR>[@]}</CODE><DD><DT><CODE>${!<VAR>name</VAR>[*]}</CODE><DD>If <VAR>name</VAR> is an array variable, expands to the list of array indices
(keys) assigned in <VAR>name</VAR>.
If <VAR>name</VAR> is not an array, expands to 0 if <VAR>name</VAR> is set and null
otherwise.
When <SAMP>`@'</SAMP> is used and the expansion appears within double quotes, each
key expands to a separate word.
<P><DT><CODE>${#<VAR>parameter</VAR>}</CODE><DD>The length in characters of the expanded value of <VAR>parameter</VAR> is
substituted.
If <VAR>parameter</VAR> is <SAMP>`*'</SAMP> or <SAMP>`@'</SAMP>, the value substituted
is the number of positional parameters.
If <VAR>parameter</VAR> is an array name subscripted by <SAMP>`*'</SAMP> or <SAMP>`@'</SAMP>,
the value substituted is the number of elements in the array.
<P><DT><CODE>${<VAR>parameter</VAR>#<VAR>word</VAR>}</CODE><DD><DT><CODE>${<VAR>parameter</VAR>##<VAR>word</VAR>}</CODE><DD>The <VAR>word</VAR>
is expanded to produce a pattern just as in filename
expansion (see section <A HREF="bashref.html#SEC35">3.5.8 Filename Expansion</A>). If the pattern matches
the beginning of the expanded value of <VAR>parameter</VAR>,
then the result of the expansion is the expanded value of <VAR>parameter</VAR>
with the shortest matching pattern (the <SAMP>`#'</SAMP> case) or the
longest matching pattern (the <SAMP>`##'</SAMP> case) deleted.
If <VAR>parameter</VAR> is <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list.
If <VAR>parameter</VAR> is an array variable subscripted with
<SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the pattern removal operation is applied to each member of the
array in turn, and the expansion is the resultant list.
<P><DT><CODE>${<VAR>parameter</VAR>%<VAR>word</VAR>}</CODE><DD><DT><CODE>${<VAR>parameter</VAR>%%<VAR>word</VAR>}</CODE><DD>The <VAR>word</VAR> is expanded to produce a pattern just as in
filename expansion.
If the pattern matches a trailing portion of the expanded value of
<VAR>parameter</VAR>, then the result of the expansion is the value of
<VAR>parameter</VAR> with the shortest matching pattern (the <SAMP>`%'</SAMP> case)
or the longest matching pattern (the <SAMP>`%%'</SAMP> case) deleted.
If <VAR>parameter</VAR> is <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the pattern removal operation is applied to each positional
parameter in turn, and the expansion is the resultant list.
If <VAR>parameter</VAR>
is an array variable subscripted with <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the pattern removal operation is applied to each member of the
array in turn, and the expansion is the resultant list.
<P><DT><CODE>${<VAR>parameter</VAR>/<VAR>pattern</VAR>/<VAR>string</VAR>}</CODE><DD><DT><CODE>${<VAR>parameter</VAR>//<VAR>pattern</VAR>/<VAR>string</VAR>}</CODE><DD><P>
The <VAR>pattern</VAR> is expanded to produce a pattern just as in
filename expansion.
<VAR>Parameter</VAR> is expanded and the longest match of <VAR>pattern</VAR>
against its value is replaced with <VAR>string</VAR>.
In the first form, only the first match is replaced.
The second form causes all matches of <VAR>pattern</VAR> to be
replaced with <VAR>string</VAR>.
If <VAR>pattern</VAR> begins with <SAMP>`#'</SAMP>, it must match at the beginning
of the expanded value of <VAR>parameter</VAR>.
If <VAR>pattern</VAR> begins with <SAMP>`%'</SAMP>, it must match at the end
of the expanded value of <VAR>parameter</VAR>.
If <VAR>string</VAR> is null, matches of <VAR>pattern</VAR> are deleted
and the <CODE>/</CODE> following <VAR>pattern</VAR> may be omitted.
If <VAR>parameter</VAR> is <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the substitution operation is applied to each positional
parameter in turn, and the expansion is the resultant list.
If <VAR>parameter</VAR>
is an array variable subscripted with <SAMP>`@'</SAMP> or <SAMP>`*'</SAMP>,
the substitution operation is applied to each member of the
array in turn, and the expansion is the resultant list.
</P><P></DL><P><A NAME="Command Substitution"></A><HR SIZE="6"><A NAME="SEC31"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC30">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC32">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC32">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.4 Command Substitution </H3><!--docid::SEC31::--><P>
Command substitution allows the output of a command to replace
the command itself.
Command substitution occurs when a command is enclosed as follows:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>$(<VAR>command</VAR>)
</pre></td></tr></table>or
<TABLE><tr><td>&nbsp;</td><td class=example><pre>`<VAR>command</VAR>`
</pre></td></tr></table></P><P>
Bash performs the expansion by executing <VAR>command</VAR> and
replacing the command substitution with the standard output of the
command, with any trailing newlines deleted.
Embedded newlines are not deleted, but they may be removed during
word splitting.
The command substitution <CODE>$(cat <VAR>file</VAR>)</CODE> can be
replaced by the equivalent but faster <CODE>$(&#60;<VAR>file</VAR>)</CODE>.
</P><P>
When the old-style backquote form of substitution is used,
backslash retains its literal meaning except when followed by
<SAMP>`$'</SAMP>, <SAMP>``'</SAMP>, or <SAMP>`\'</SAMP>.
The first backquote not preceded by a backslash terminates the
command substitution.
When using the <CODE>$(<VAR>command</VAR>)</CODE> form, all characters between
the parentheses make up the command; none are treated specially.
</P><P>
Command substitutions may be nested. To nest when using the backquoted
form, escape the inner backquotes with backslashes.
</P><P>
If the substitution appears within double quotes, word splitting and
filename expansion are not performed on the results.
</P><P><A NAME="Arithmetic Expansion"></A><HR SIZE="6"><A NAME="SEC32"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC31">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC33">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC33">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.5 Arithmetic Expansion </H3><!--docid::SEC32::--><P>
Arithmetic expansion allows the evaluation of an arithmetic expression
and the substitution of the result. The format for arithmetic expansion is:
</P><P><TABLE><tr><td>&nbsp;</td><td class=example><pre>$(( <VAR>expression</VAR> ))
</pre></td></tr></table></P><P>
The expression is treated as if it were within double quotes, but
a double quote inside the parentheses is not treated specially.
All tokens in the expression undergo parameter expansion, command
substitution, and quote removal.
Arithmetic expansions may be nested.
</P><P>
The evaluation is performed according to the rules listed below
(see section <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>).
If the expression is invalid, Bash prints a message indicating
failure to the standard error and no substitution occurs.
</P><P><A NAME="Process Substitution"></A><HR SIZE="6"><A NAME="SEC33"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC32">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC34">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC34">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.6 Process Substitution </H3><!--docid::SEC33::--><P>
Process substitution is supported on systems that support named
pipes (FIFOs) or the <TT>`/dev/fd'</TT> method of naming open files.
It takes the form of
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#60;(<VAR>list</VAR>)
</pre></td></tr></table>or
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#62;(<VAR>list</VAR>)
</pre></td></tr></table>The process <VAR>list</VAR> is run with its input or output connected to a
FIFO or some file in <TT>`/dev/fd'</TT>. The name of this file is
passed as an argument to the current command as the result of the
expansion. If the <CODE>&#62;(<VAR>list</VAR>)</CODE> form is used, writing to
the file will provide input for <VAR>list</VAR>. If the
<CODE>&#60;(<VAR>list</VAR>)</CODE> form is used, the file passed as an
argument should be read to obtain the output of <VAR>list</VAR>.
Note that no space may appear between the <CODE>&#60;</CODE> or <CODE>&#62;</CODE>
and the left parenthesis, otherwise the construct would be interpreted
as a redirection.
</P><P>
When available, process substitution is performed simultaneously with
parameter and variable expansion, command substitution, and arithmetic
expansion.
</P><P><A NAME="Word Splitting"></A><HR SIZE="6"><A NAME="SEC34"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC33">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC35">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC35">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.7 Word Splitting </H3><!--docid::SEC34::--><P>
The shell scans the results of parameter expansion, command substitution,
and arithmetic expansion that did not occur within double quotes for
word splitting.
</P><P>
The shell treats each character of <CODE>$IFS</CODE>
as a delimiter, and splits the results of the other
expansions into words on these characters. If
<CODE>IFS</CODE> is unset, or its value is exactly <CODE>&#60;space&#62;&#60;tab&#62;&#60;newline&#62;</CODE>,
the default, then any sequence of <CODE>IFS</CODE>
characters serves to delimit words. If <CODE>IFS</CODE>
has a value other than the default, then sequences of
the whitespace characters <CODE>space</CODE> and <CODE>tab</CODE>
are ignored at the beginning and end of the
word, as long as the whitespace character is in the
value of <CODE>IFS</CODE> (an <CODE>IFS</CODE> whitespace character).
Any character in <CODE>IFS</CODE> that is not <CODE>IFS</CODE>
whitespace, along with any adjacent <CODE>IFS</CODE>
whitespace characters, delimits a field. A sequence of <CODE>IFS</CODE>
whitespace characters is also treated as a delimiter.
If the value of <CODE>IFS</CODE> is null, no word splitting occurs.
</P><P>
Explicit null arguments (<CODE>""</CODE> or <CODE>"</CODE>) are retained.
Unquoted implicit null arguments, resulting from the expansion of
parameters that have no values, are removed.
If a parameter with no value is expanded within double quotes, a
null argument results and is retained.
</P><P>
Note that if no expansion occurs, no splitting
is performed.
</P><P><A NAME="Filename Expansion"></A><HR SIZE="6"><A NAME="SEC35"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC34">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC36">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.8 Filename Expansion </H3><!--docid::SEC35::--><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC36">3.5.8.1 Pattern Matching</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How the shell matches patterns.</TD></TR></TABLE></BLOCKQUOTE><A NAME="IDX64"></A><A NAME="IDX65"></A><A NAME="IDX66"></A><A NAME="IDX67"></A><P>
After word splitting, unless the <SAMP>`-f'</SAMP> option has been set
(see section <A HREF="bashref.html#SEC59">4.3 The Set Builtin</A>), Bash scans each word for the characters
<SAMP>`*'</SAMP>, <SAMP>`?'</SAMP>, and <SAMP>`['</SAMP>.
If one of these characters appears, then the word is
regarded as a <VAR>pattern</VAR>,
and replaced with an alphabetically sorted list of
file names matching the pattern. If no matching file names are found,
and the shell option <CODE>nullglob</CODE> is disabled, the word is left
unchanged.
If the <CODE>nullglob</CODE> option is set, and no matches are found, the word
is removed.
If the <CODE>failglob</CODE> shell option is set, and no matches are found,
an error message is printed and the command is not executed.
If the shell option <CODE>nocaseglob</CODE> is enabled, the match is performed
without regard to the case of alphabetic characters.
</P><P>
When a pattern is used for filename generation, the character <SAMP>`.'</SAMP>
at the start of a filename or immediately following a slash
must be matched explicitly, unless the shell option <CODE>dotglob</CODE> is set.
When matching a file name, the slash character must always be
matched explicitly.
In other cases, the <SAMP>`.'</SAMP> character is not treated specially.
</P><P>
See the description of <CODE>shopt</CODE> in <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>,
for a description of the <CODE>nocaseglob</CODE>, <CODE>nullglob</CODE>,
<CODE>failglob</CODE>, and <CODE>dotglob</CODE> options.
</P><P>
The <CODE>GLOBIGNORE</CODE>
shell variable may be used to restrict the set of filenames matching a
pattern. If <CODE>GLOBIGNORE</CODE>
is set, each matching filename that also matches one of the patterns in
<CODE>GLOBIGNORE</CODE> is removed from the list of matches. The filenames
<TT>`.'</TT> and <TT>`..'</TT>
are always ignored when <CODE>GLOBIGNORE</CODE>
is set and not null.
However, setting <CODE>GLOBIGNORE</CODE> to a non-null value has the effect of
enabling the <CODE>dotglob</CODE>
shell option, so all other filenames beginning with a
<SAMP>`.'</SAMP> will match.
To get the old behavior of ignoring filenames beginning with a
<SAMP>`.'</SAMP>, make <SAMP>`.*'</SAMP> one of the patterns in <CODE>GLOBIGNORE</CODE>.
The <CODE>dotglob</CODE> option is disabled when <CODE>GLOBIGNORE</CODE>
is unset.
</P><P><A NAME="Pattern Matching"></A><HR SIZE="6"><A NAME="SEC36"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC35">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC35"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H4> 3.5.8.1 Pattern Matching </H4><!--docid::SEC36::--><P>
Any character that appears in a pattern, other than the special pattern
characters described below, matches itself.
The NUL character may not occur in a pattern.
A backslash escapes the following character; the
escaping backslash is discarded when matching.
The special pattern characters must be quoted if they are to be matched
literally.
</P><P>
The special pattern characters have the following meanings:
<DL COMPACT><DT><CODE>*</CODE><DD>Matches any string, including the null string.
<DT><CODE>?</CODE><DD>Matches any single character.
<DT><CODE>[<small>...</small>]</CODE><DD>Matches any one of the enclosed characters. A pair of characters
separated by a hyphen denotes a <VAR>range expression</VAR>;
any character that sorts between those two characters, inclusive,
using the current locale's collating sequence and character set,
is matched. If the first character following the
<SAMP>`['</SAMP> is a <SAMP>`!'</SAMP> or a <SAMP>`^'</SAMP>
then any character not enclosed is matched. A <SAMP>`-'</SAMP>
may be matched by including it as the first or last character
in the set. A <SAMP>`]'</SAMP> may be matched by including it as the first
character in the set.
The sorting order of characters in range expressions is determined by
the current locale and the value of the <CODE>LC_COLLATE</CODE> shell variable,
if set.
<P>
For example, in the default C locale, <SAMP>`[a-dx-z]'</SAMP> is equivalent to
<SAMP>`[abcdxyz]'</SAMP>. Many locales sort characters in dictionary order, and in
these locales <SAMP>`[a-dx-z]'</SAMP> is typically not equivalent to <SAMP>`[abcdxyz]'</SAMP>;
it might be equivalent to <SAMP>`[aBbCcDdxXyYz]'</SAMP>, for example. To obtain
the traditional interpretation of ranges in bracket expressions, you can
force the use of the C locale by setting the <CODE>LC_COLLATE</CODE> or
<CODE>LC_ALL</CODE> environment variable to the value <SAMP>`C'</SAMP>.
</P><P>
Within <SAMP>`['</SAMP> and <SAMP>`]'</SAMP>, <VAR>character classes</VAR> can be specified
using the syntax
<CODE>[:</CODE><VAR>class</VAR><CODE>:]</CODE>, where <VAR>class</VAR> is one of the
following classes defined in the POSIX 1003.2 standard:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>alnum alpha ascii blank cntrl digit graph lower
print punct space upper word xdigit
</pre></td></tr></table>A character class matches any character belonging to that class.
The <CODE>word</CODE> character class matches letters, digits, and the character
<SAMP>`_'</SAMP>.
</P><P>
Within <SAMP>`['</SAMP> and <SAMP>`]'</SAMP>, an <VAR>equivalence class</VAR> can be
specified using the syntax <CODE>[=</CODE><VAR>c</VAR><CODE>=]</CODE>, which
matches all characters with the same collation weight (as defined
by the current locale) as the character <VAR>c</VAR>.
</P><P>
Within <SAMP>`['</SAMP> and <SAMP>`]'</SAMP>, the syntax <CODE>[.</CODE><VAR>symbol</VAR><CODE>.]</CODE>
matches the collating symbol <VAR>symbol</VAR>.
</DL><P>
If the <CODE>extglob</CODE> shell option is enabled using the <CODE>shopt</CODE>
builtin, several extended pattern matching operators are recognized.
In the following description, a <VAR>pattern-list</VAR> is a list of one
or more patterns separated by a <SAMP>`|'</SAMP>.
Composite patterns may be formed using one or more of the following
sub-patterns:
</P><P><DL COMPACT><DT><CODE>?(<VAR>pattern-list</VAR>)</CODE><DD>Matches zero or one occurrence of the given patterns.
<P><DT><CODE>*(<VAR>pattern-list</VAR>)</CODE><DD>Matches zero or more occurrences of the given patterns.
<P><DT><CODE>+(<VAR>pattern-list</VAR>)</CODE><DD>Matches one or more occurrences of the given patterns.
<P><DT><CODE>@(<VAR>pattern-list</VAR>)</CODE><DD>Matches one of the given patterns.
<P><DT><CODE>!(<VAR>pattern-list</VAR>)</CODE><DD>Matches anything except one of the given patterns.
</DL><P><A NAME="Quote Removal"></A><HR SIZE="6"><A NAME="SEC37"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC36">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC27"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.5.9 Quote Removal </H3><!--docid::SEC37::--><P>
After the preceding expansions, all unquoted occurrences of the
characters <SAMP>`\'</SAMP>, <SAMP>`''</SAMP>, and <SAMP>`"'</SAMP> that did not
result from one of the above expansions are removed.
</P><P><A NAME="Redirections"></A><HR SIZE="6"><A NAME="SEC38"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC37">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC39">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.6 Redirections </H2><!--docid::SEC38::--><P>
Before a command is executed, its input and output
may be <VAR>redirected</VAR>
using a special notation interpreted by the shell.
Redirection may also be used to open and close files for the
current shell execution environment. The following redirection
operators may precede or appear anywhere within a
simple command or may follow a command.
Redirections are processed in the order they appear, from
left to right.
</P><P>
In the following descriptions, if the file descriptor number is
omitted, and the first character of the redirection operator is
<SAMP>`&#60;'</SAMP>, the redirection refers to the standard input (file
descriptor 0). If the first character of the redirection operator
is <SAMP>`&#62;'</SAMP>, the redirection refers to the standard output (file
descriptor 1).
</P><P>
The word following the redirection operator in the following
descriptions, unless otherwise noted, is subjected to brace expansion,
tilde expansion, parameter expansion, command substitution, arithmetic
expansion, quote removal, filename expansion, and word splitting.
If it expands to more than one word, Bash reports an error.
</P><P>
Note that the order of redirections is significant. For example,
the command
<TABLE><tr><td>&nbsp;</td><td class=example><pre>ls &#62;<VAR>dirlist</VAR> 2&#62;&#38;1
</pre></td></tr></table>directs both standard output (file descriptor 1) and standard error
(file descriptor 2) to the file <VAR>dirlist</VAR>, while the command
<TABLE><tr><td>&nbsp;</td><td class=example><pre>ls 2&#62;&#38;1 &#62;<VAR>dirlist</VAR></pre></td></tr></table>directs only the standard output to file <VAR>dirlist</VAR>,
because the standard error was duplicated as standard output
before the standard output was redirected to <VAR>dirlist</VAR>.
</P><P>
Bash handles several filenames specially when they are used in
redirections, as described in the following table:
</P><P><DL COMPACT><DT><CODE>/dev/fd/<VAR>fd</VAR></CODE><DD>If <VAR>fd</VAR> is a valid integer, file descriptor <VAR>fd</VAR> is duplicated.
<P><DT><CODE>/dev/stdin</CODE><DD>File descriptor 0 is duplicated.
<P><DT><CODE>/dev/stdout</CODE><DD>File descriptor 1 is duplicated.
<P><DT><CODE>/dev/stderr</CODE><DD>File descriptor 2 is duplicated.
<P><DT><CODE>/dev/tcp/<VAR>host</VAR>/<VAR>port</VAR></CODE><DD>If <VAR>host</VAR> is a valid hostname or Internet address, and <VAR>port</VAR>
is an integer port number or service name, Bash attempts to open a TCP
connection to the corresponding socket.
<P><DT><CODE>/dev/udp/<VAR>host</VAR>/<VAR>port</VAR></CODE><DD>If <VAR>host</VAR> is a valid hostname or Internet address, and <VAR>port</VAR>
is an integer port number or service name, Bash attempts to open a UDP
connection to the corresponding socket.
<P></DL><P>
A failure to open or create a file causes the redirection to fail.
</P><P>
Redirections using file descriptors greater than 9 should be used with
care, as they may conflict with file descriptors the shell uses
internally.
</P><P><HR SIZE="6"><A NAME="SEC39"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC40">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.1 Redirecting Input </H3><!--docid::SEC39::-->
Redirection of input causes the file whose name results from
the expansion of <VAR>word</VAR>
to be opened for reading on file descriptor <CODE>n</CODE>,
or the standard input (file descriptor 0) if <CODE>n</CODE>
is not specified.
<P>
The general format for redirecting input is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#60;<VAR>word</VAR></pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC40"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC39">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC41">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC41">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.2 Redirecting Output </H3><!--docid::SEC40::-->
Redirection of output causes the file whose name results from
the expansion of <VAR>word</VAR>
to be opened for writing on file descriptor <VAR>n</VAR>,
or the standard output (file descriptor 1) if <VAR>n</VAR>
is not specified. If the file does not exist it is created;
if it does exist it is truncated to zero size.
<P>
The general format for redirecting output is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#62;[|]<VAR>word</VAR></pre></td></tr></table></P><P>
If the redirection operator is <SAMP>`&#62;'</SAMP>, and the <CODE>noclobber</CODE>
option to the <CODE>set</CODE> builtin has been enabled, the redirection
will fail if the file whose name results from the expansion of
<VAR>word</VAR> exists and is a regular file.
If the redirection operator is <SAMP>`&#62;|'</SAMP>, or the redirection operator is
<SAMP>`&#62;'</SAMP> and the <CODE>noclobber</CODE> option is not enabled, the redirection
is attempted even if the file named by <VAR>word</VAR> exists.
</P><P><HR SIZE="6"><A NAME="SEC41"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC40">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC42">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC42">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.3 Appending Redirected Output </H3><!--docid::SEC41::-->
Redirection of output in this fashion
causes the file whose name results from
the expansion of <VAR>word</VAR>
to be opened for appending on file descriptor <VAR>n</VAR>,
or the standard output (file descriptor 1) if <VAR>n</VAR>
is not specified. If the file does not exist it is created.
<P>
The general format for appending output is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#62;&#62;<VAR>word</VAR></pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC42"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC41">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC43">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC43">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.4 Redirecting Standard Output and Standard Error </H3><!--docid::SEC42::-->
Bash allows both the
standard output (file descriptor 1) and
the standard error output (file descriptor 2)
to be redirected to the file whose name is the
expansion of <VAR>word</VAR> with this construct.
<P>
There are two formats for redirecting standard output and
standard error:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#38;&#62;<VAR>word</VAR></pre></td></tr></table>and
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#62;&#38;<VAR>word</VAR></pre></td></tr></table>Of the two forms, the first is preferred.
This is semantically equivalent to
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#62;<VAR>word</VAR> 2&#62;&#38;1
</pre></td></tr></table></P><P><HR SIZE="6"><A NAME="SEC43"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC42">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC44">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC44">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.5 Here Documents </H3><!--docid::SEC43::-->
This type of redirection instructs the shell to read input from the
current source until a line containing only <VAR>word</VAR>
(with no trailing blanks) is seen. All of
the lines read up to that point are then used as the standard
input for a command.
<P>
The format of here-documents is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#60;&#60;[-]<VAR>word</VAR><VAR>here-document</VAR><VAR>delimiter</VAR></pre></td></tr></table></P><P>
No parameter expansion, command substitution, arithmetic expansion,
or filename expansion is performed on
<VAR>word</VAR>. If any characters in <VAR>word</VAR> are quoted, the
<VAR>delimiter</VAR> is the result of quote removal on <VAR>word</VAR>,
and the lines in the here-document are not expanded.
If <VAR>word</VAR> is unquoted,
all lines of the here-document are subjected to parameter expansion,
command substitution, and arithmetic expansion. In the latter
case, the character sequence <CODE>\newline</CODE> is ignored, and <SAMP>`\'</SAMP>
must be used to quote the characters
<SAMP>`\'</SAMP>, <SAMP>`$'</SAMP>, and <SAMP>``'</SAMP>.
</P><P>
If the redirection operator is <SAMP>`&#60;&#60;-'</SAMP>,
then all leading tab characters are stripped from input lines and the
line containing <VAR>delimiter</VAR>.
This allows here-documents within shell scripts to be indented in a
natural fashion.
</P><P><HR SIZE="6"><A NAME="SEC44"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC43">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC45">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC45">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.6 Here Strings </H3><!--docid::SEC44::-->
A variant of here documents, the format is:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>&#60;&#60;&#60;<VAR>word</VAR></pre></td></tr></table><P>
The <VAR>word</VAR> is expanded and supplied to the command on its standard
input.
</P><P><HR SIZE="6"><A NAME="SEC45"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC44">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC46">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC46">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.7 Duplicating File Descriptors </H3><!--docid::SEC45::-->
The redirection operator
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#60;&#38;<VAR>word</VAR></pre></td></tr></table>is used to duplicate input file descriptors.
If <VAR>word</VAR>
expands to one or more digits, the file descriptor denoted by <VAR>n</VAR>
is made to be a copy of that file descriptor.
If the digits in <VAR>word</VAR> do not specify a file descriptor open for
input, a redirection error occurs.
If <VAR>word</VAR>
evaluates to <SAMP>`-'</SAMP>, file descriptor <VAR>n</VAR> is closed. If
<VAR>n</VAR> is not specified, the standard input (file descriptor 0) is used.
<P>
The operator
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#62;&#38;<VAR>word</VAR></pre></td></tr></table>is used similarly to duplicate output file descriptors. If
<VAR>n</VAR> is not specified, the standard output (file descriptor 1) is used.
If the digits in <VAR>word</VAR> do not specify a file descriptor open for
output, a redirection error occurs.
As a special case, if <VAR>n</VAR> is omitted, and <VAR>word</VAR> does not
expand to one or more digits, the standard output and standard
error are redirected as described previously.
</P><P><HR SIZE="6"><A NAME="SEC46"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC45">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC47">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC47">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.8 Moving File Descriptors </H3><!--docid::SEC46::-->
The redirection operator
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#60;&#38;<VAR>digit</VAR>-
</pre></td></tr></table>moves the file descriptor <VAR>digit</VAR> to file descriptor <VAR>n</VAR>,
or the standard input (file descriptor 0) if <VAR>n</VAR> is not specified.
<VAR>digit</VAR> is closed after being duplicated to <VAR>n</VAR>.
<P>
Similarly, the redirection operator
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#62;&#38;<VAR>digit</VAR>-
</pre></td></tr></table>moves the file descriptor <VAR>digit</VAR> to file descriptor <VAR>n</VAR>,
or the standard output (file descriptor 1) if <VAR>n</VAR> is not specified.
</P><P><HR SIZE="6"><A NAME="SEC47"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC46">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC38"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.6.9 Opening File Descriptors for Reading and Writing </H3><!--docid::SEC47::-->
The redirection operator
<TABLE><tr><td>&nbsp;</td><td class=example><pre>[<VAR>n</VAR>]&#60;&#62;<VAR>word</VAR></pre></td></tr></table>causes the file whose name is the expansion of <VAR>word</VAR>
to be opened for both reading and writing on file descriptor
<VAR>n</VAR>, or on file descriptor 0 if <VAR>n</VAR>
is not specified. If the file does not exist, it is created.
<P><A NAME="Executing Commands"></A><HR SIZE="6"><A NAME="SEC48"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC47">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC49">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.7 Executing Commands </H2><!--docid::SEC48::--><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC49">3.7.1 Simple Command Expansion</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How Bash expands simple commands before
executing them.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC50">3.7.2 Command Search and Execution</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">How Bash finds commands and runs them.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC51">3.7.3 Command Execution Environment</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The environment in which Bash
executes commands that are not
shell builtins.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC52">3.7.4 Environment</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The environment given to a command.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC53">3.7.5 Exit Status</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">The status returned by commands and how Bash
interprets it.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC54">3.7.6 Signals</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">What happens when Bash or a command it runs
receives a signal.</TD></TR></TABLE></BLOCKQUOTE><P><A NAME="Simple Command Expansion"></A><HR SIZE="6"><A NAME="SEC49"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC50">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.1 Simple Command Expansion </H3><!--docid::SEC49::--><P>
When a simple command is executed, the shell performs the following
expansions, assignments, and redirections, from left to right.
</P><P><OL><LI>
The words that the parser has marked as variable assignments (those
preceding the command name) and redirections are saved for later
processing.
<P><LI>
The words that are not variable assignments or redirections are
expanded (see section <A HREF="bashref.html#SEC27">3.5 Shell Expansions</A>).
If any words remain after expansion, the first word
is taken to be the name of the command and the remaining words are
the arguments.
<P><LI>
Redirections are performed as described above (see section <A HREF="bashref.html#SEC38">3.6 Redirections</A>).
<P><LI>
The text after the <SAMP>`='</SAMP> in each variable assignment undergoes tilde
expansion, parameter expansion, command substitution, arithmetic expansion,
and quote removal before being assigned to the variable.
</OL><P>
If no command name results, the variable assignments affect the current
shell environment. Otherwise, the variables are added to the environment
of the executed command and do not affect the current shell environment.
If any of the assignments attempts to assign a value to a readonly variable,
an error occurs, and the command exits with a non-zero status.
</P><P>
If no command name results, redirections are performed, but do not
affect the current shell environment. A redirection error causes the
command to exit with a non-zero status.
</P><P>
If there is a command name left after expansion, execution proceeds as
described below. Otherwise, the command exits. If one of the expansions
contained a command substitution, the exit status of the command is
the exit status of the last command substitution performed. If there
were no command substitutions, the command exits with a status of zero.
</P><P><A NAME="Command Search and Execution"></A><HR SIZE="6"><A NAME="SEC50"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC49">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC51">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC51">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.2 Command Search and Execution </H3><!--docid::SEC50::--><P>
After a command has been split into words, if it results in a
simple command and an optional list of arguments, the following
actions are taken.
</P><P><OL><LI>
If the command name contains no slashes, the shell attempts to
locate it. If there exists a shell function by that name, that
function is invoked as described in <A HREF="bashref.html#SEC23">3.3 Shell Functions</A>.
<P><LI>
If the name does not match a function, the shell searches for
it in the list of shell builtins. If a match is found, that
builtin is invoked.
<P><LI>
If the name is neither a shell function nor a builtin,
and contains no slashes, Bash searches each element of
<CODE>$PATH</CODE> for a directory containing an executable file
by that name. Bash uses a hash table to remember the full
pathnames of executable files to avoid multiple <CODE>PATH</CODE> searches
(see the description of <CODE>hash</CODE> in <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>).
A full search of the directories in <CODE>$PATH</CODE>
is performed only if the command is not found in the hash table.
If the search is unsuccessful, the shell prints an error
message and returns an exit status of 127.
<P><LI>
If the search is successful, or if the command name contains
one or more slashes, the shell executes the named program in
a separate execution environment.
Argument 0 is set to the name given, and the remaining arguments
to the command are set to the arguments supplied, if any.
<P><LI>
If this execution fails because the file is not in executable
format, and the file is not a directory, it is assumed to be a
<VAR>shell script</VAR> and the shell executes it as described in
<A HREF="bashref.html#SEC55">3.8 Shell Scripts</A>.
<P><LI>
If the command was not begun asynchronously, the shell waits for
the command to complete and collects its exit status.
<P></OL><P><A NAME="Command Execution Environment"></A><HR SIZE="6"><A NAME="SEC51"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC50">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC52">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC52">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.3 Command Execution Environment </H3><!--docid::SEC51::--><P>
The shell has an <VAR>execution environment</VAR>, which consists of the
following:
</P><P><UL><LI>
open files inherited by the shell at invocation, as modified by
redirections supplied to the <CODE>exec</CODE> builtin
<P><LI>
the current working directory as set by <CODE>cd</CODE>, <CODE>pushd</CODE>, or
<CODE>popd</CODE>, or inherited by the shell at invocation
<P><LI>
the file creation mode mask as set by <CODE>umask</CODE> or inherited from
the shell's parent
<P><LI>
current traps set by <CODE>trap</CODE><P><LI>
shell parameters that are set by variable assignment or with <CODE>set</CODE>
or inherited from the shell's parent in the environment
<P><LI>
shell functions defined during execution or inherited from the shell's
parent in the environment
<P><LI>
options enabled at invocation (either by default or with command-line
arguments) or by <CODE>set</CODE><P><LI>
options enabled by <CODE>shopt</CODE><P><LI>
shell aliases defined with <CODE>alias</CODE> (see section <A HREF="bashref.html#SEC80">6.6 Aliases</A>)
<P><LI>
various process IDs, including those of background jobs
(see section <A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A>), the value of <CODE>$$</CODE>, and the value of
<CODE>$PPID</CODE><P></UL><P>
When a simple command other than a builtin or shell function
is to be executed, it
is invoked in a separate execution environment that consists of
the following. Unless otherwise noted, the values are inherited
from the shell.
</P><P><UL><LI>
the shell's open files, plus any modifications and additions specified
by redirections to the command
<P><LI>
the current working directory
<P><LI>
the file creation mode mask
<P><LI>
shell variables and functions marked for export, along with variables
exported for the command, passed in the environment (see section <A HREF="bashref.html#SEC52">3.7.4 Environment</A>)
<P><LI>
traps caught by the shell are reset to the values inherited from the
shell's parent, and traps ignored by the shell are ignored
<P></UL><P>
A command invoked in this separate environment cannot affect the
shell's execution environment.
</P><P>
Command substitution, commands grouped with parentheses,
and asynchronous commands are invoked in a
subshell environment that is a duplicate of the shell environment,
except that traps caught by the shell are reset to the values
that the shell inherited from its parent at invocation. Builtin
commands that are invoked as part of a pipeline are also executed
in a subshell environment. Changes made to the subshell environment
cannot affect the shell's execution environment.
</P><P>
If a command is followed by a <SAMP>`&#38;'</SAMP> and job control is not active, the
default standard input for the command is the empty file <TT>`/dev/null'</TT>.
Otherwise, the invoked command inherits the file descriptors of the calling
shell as modified by redirections.
</P><P><A NAME="Environment"></A><HR SIZE="6"><A NAME="SEC52"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC51">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC53">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC53">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.4 Environment </H3><!--docid::SEC52::--><P>
When a program is invoked it is given an array of strings
called the <VAR>environment</VAR>.
This is a list of name-value pairs, of the form <CODE>name=value</CODE>.
</P><P>
Bash provides several ways to manipulate the environment.
On invocation, the shell scans its own environment and
creates a parameter for each name found, automatically marking
it for <VAR>export</VAR>
to child processes. Executed commands inherit the environment.
The <CODE>export</CODE> and <SAMP>`declare -x'</SAMP>
commands allow parameters and functions to be added to and
deleted from the environment. If the value of a parameter
in the environment is modified, the new value becomes part
of the environment, replacing the old. The environment
inherited by any executed command consists of the shell's
initial environment, whose values may be modified in the shell,
less any pairs removed by the <CODE>unset</CODE> and <SAMP>`export -n'</SAMP>
commands, plus any additions via the <CODE>export</CODE> and
<SAMP>`declare -x'</SAMP> commands.
</P><P>
The environment for any simple command
or function may be augmented temporarily by prefixing it with
parameter assignments, as described in <A HREF="bashref.html#SEC24">3.4 Shell Parameters</A>.
These assignment statements affect only the environment seen
by that command.
</P><P>
If the <SAMP>`-k'</SAMP> option is set (see section <A HREF="bashref.html#SEC59">4.3 The Set Builtin</A>), then all
parameter assignments are placed in the environment for a command,
not just those that precede the command name.
</P><P>
When Bash invokes an external command, the variable <SAMP>`$_'</SAMP>
is set to the full path name of the command and passed to that
command in its environment.
</P><P><A NAME="Exit Status"></A><HR SIZE="6"><A NAME="SEC53"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC52">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC54">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC54">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.5 Exit Status </H3><!--docid::SEC53::--><P>
For the shell's purposes, a command which exits with a
zero exit status has succeeded.
A non-zero exit status indicates failure.
This seemingly counter-intuitive scheme is used so there
is one well-defined way to indicate success and a variety of
ways to indicate various failure modes.
When a command terminates on a fatal signal whose number is <VAR>N</VAR>,
Bash uses the value 128+<VAR>N</VAR> as the exit status.
</P><P>
If a command is not found, the child process created to
execute it returns a status of 127. If a command is found
but is not executable, the return status is 126.
</P><P>
If a command fails because of an error during expansion or redirection,
the exit status is greater than zero.
</P><P>
The exit status is used by the Bash conditional commands
(see section <A HREF="bashref.html#SEC21">3.2.4.2 Conditional Constructs</A>) and some of the list
constructs (see section <A HREF="bashref.html#SEC18">3.2.3 Lists of Commands</A>).
</P><P>
All of the Bash builtins return an exit status of zero if they succeed
and a non-zero status on failure, so they may be used by the
conditional and list constructs.
All builtins return an exit status of 2 to indicate incorrect usage.
</P><P><A NAME="Signals"></A><HR SIZE="6"><A NAME="SEC54"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC53">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC48"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H3> 3.7.6 Signals </H3><!--docid::SEC54::--><P>
When Bash is interactive, in the absence of any traps, it ignores
<CODE>SIGTERM</CODE> (so that <SAMP>`kill 0'</SAMP> does not kill an interactive shell),
and <CODE>SIGINT</CODE>
is caught and handled (so that the <CODE>wait</CODE> builtin is interruptible).
When Bash receives a <CODE>SIGINT</CODE>, it breaks out of any executing loops.
In all cases, Bash ignores <CODE>SIGQUIT</CODE>.
If job control is in effect (see section <A HREF="bashref.html#SEC87">7. Job Control</A>), Bash
ignores <CODE>SIGTTIN</CODE>, <CODE>SIGTTOU</CODE>, and <CODE>SIGTSTP</CODE>.
</P><P>
Non-builtin commands started by Bash have signal handlers set to the
values inherited by the shell from its parent.
When job control is not in effect, asynchronous commands
ignore <CODE>SIGINT</CODE> and <CODE>SIGQUIT</CODE> in addition to these inherited
handlers.
Commands run as a result of
command substitution ignore the keyboard-generated job control signals
<CODE>SIGTTIN</CODE>, <CODE>SIGTTOU</CODE>, and <CODE>SIGTSTP</CODE>.
</P><P>
The shell exits by default upon receipt of a <CODE>SIGHUP</CODE>.
Before exiting, an interactive shell resends the <CODE>SIGHUP</CODE> to
all jobs, running or stopped.
Stopped jobs are sent <CODE>SIGCONT</CODE> to ensure that they receive
the <CODE>SIGHUP</CODE>.
To prevent the shell from sending the <CODE>SIGHUP</CODE> signal to a
particular job, it should be removed
from the jobs table with the <CODE>disown</CODE>
builtin (see section <A HREF="bashref.html#SEC89">7.2 Job Control Builtins</A>) or marked
to not receive <CODE>SIGHUP</CODE> using <CODE>disown -h</CODE>.
</P><P>
If the <CODE>huponexit</CODE> shell option has been set with <CODE>shopt</CODE>
(see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>), Bash sends a <CODE>SIGHUP</CODE> to all jobs when
an interactive login shell exits.
</P><P>
If Bash is waiting for a command to complete and receives a signal
for which a trap has been set, the trap will not be executed until
the command completes.
When Bash is waiting for an asynchronous
command via the <CODE>wait</CODE> builtin, the reception of a signal for
which a trap has been set will cause the <CODE>wait</CODE> builtin to return
immediately with an exit status greater than 128, immediately after
which the trap is executed.
</P><P><A NAME="Shell Scripts"></A><HR SIZE="6"><A NAME="SEC55"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC54">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC5"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 3.8 Shell Scripts </H2><!--docid::SEC55::--><P>
A shell script is a text file containing shell commands. When such
a file is used as the first non-option argument when invoking Bash,
and neither the <SAMP>`-c'</SAMP> nor <SAMP>`-s'</SAMP> option is supplied
(see section <A HREF="bashref.html#SEC65">6.1 Invoking Bash</A>),
Bash reads and executes commands from the file, then exits. This
mode of operation creates a non-interactive shell. The shell first
searches for the file in the current directory, and looks in the
directories in <CODE>$PATH</CODE> if not found there.
</P><P>
When Bash runs
a shell script, it sets the special parameter <CODE>0</CODE> to the name
of the file, rather than the name of the shell, and the positional
parameters are set to the remaining arguments, if any are given.
If no additional arguments are supplied, the positional parameters
are unset.
</P><P>
A shell script may be made executable by using the <CODE>chmod</CODE> command
to turn on the execute bit. When Bash finds such a file while
searching the <CODE>$PATH</CODE> for a command, it spawns a subshell to
execute it. In other words, executing
<TABLE><tr><td>&nbsp;</td><td class=example><pre>filename <VAR>arguments</VAR></pre></td></tr></table>is equivalent to executing
<TABLE><tr><td>&nbsp;</td><td class=example><pre>bash filename <VAR>arguments</VAR></pre></td></tr></table></P><P>
if <CODE>filename</CODE> is an executable shell script.
This subshell reinitializes itself, so that the effect is as if a
new shell had been invoked to interpret the script, with the
exception that the locations of commands remembered by the parent
(see the description of <CODE>hash</CODE> in <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>)
are retained by the child.
</P><P>
Most versions of Unix make this a part of the operating system's command
execution mechanism. If the first line of a script begins with
the two characters <SAMP>`#!'</SAMP>, the remainder of the line specifies
an interpreter for the program.
Thus, you can specify Bash, <CODE>awk</CODE>, Perl, or some other
interpreter and write the rest of the script file in that language.
</P><P>
The arguments to the interpreter
consist of a single optional argument following the interpreter
name on the first line of the script file, followed by the name of
the script file, followed by the rest of the arguments. Bash
will perform this action on operating systems that do not handle it
themselves. Note that some older versions of Unix limit the interpreter
name and argument to a maximum of 32 characters.
</P><P>
Bash scripts often begin with <CODE>#! /bin/bash</CODE> (assuming that
Bash has been installed in <TT>`/bin'</TT>), since this ensures that
Bash will be used to interpret the script, even if it is executed
under another shell.
</P><P><A NAME="Shell Builtin Commands"></A><HR SIZE="6"><A NAME="SEC56"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC55">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC57">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1> 4. Shell Builtin Commands </H1><!--docid::SEC56::--><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Builtin commands inherited from the Bourne
Shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Table of builtins specific to Bash.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC59">4.3 The Set Builtin</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">This builtin is so overloaded it
deserves its own section.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC60">4.4 Special Builtins</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Builtin commands classified specially by
POSIX.2.</TD></TR></TABLE></BLOCKQUOTE><P>
Builtin commands are contained within the shell itself.
When the name of a builtin command is used as the first word of
a simple command (see section <A HREF="bashref.html#SEC16">3.2.1 Simple Commands</A>), the shell executes
the command directly, without invoking another program.
Builtin commands are necessary to implement functionality impossible
or inconvenient to obtain with separate utilities.
</P><P>
This section briefly the builtins which Bash inherits from
the Bourne Shell, as well as the builtin commands which are unique
to or have been extended in Bash.
</P><P>
Several builtin commands are described in other chapters: builtin
commands which provide the Bash interface to the job control
facilities (see section <A HREF="bashref.html#SEC89">7.2 Job Control Builtins</A>), the directory stack
(see section <A HREF="bashref.html#SEC83">6.8.1 Directory Stack Builtins</A>), the command history
(see section <A HREF="bashref.html#SEC117">9.2 Bash History Builtins</A>), and the programmable completion
facilities (see section <A HREF="bashref.html#SEC114">8.7 Programmable Completion Builtins</A>).
</P><P>
Many of the builtins have been extended by POSIX or Bash.
</P><P>
Unless otherwise noted, each builtin command documented as accepting
options preceded by <SAMP>`-'</SAMP> accepts <SAMP>`--'</SAMP>
to signify the end of the options.
For example, the <CODE>:</CODE>, <CODE>true</CODE>, <CODE>false</CODE>, and <CODE>test</CODE>
builtins do not accept options.
</P><P><A NAME="Bourne Shell Builtins"></A><HR SIZE="6"><A NAME="SEC57"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC58">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 4.1 Bourne Shell Builtins </H2><!--docid::SEC57::--><P>
The following shell builtin commands are inherited from the Bourne Shell.
These commands are implemented as specified by the POSIX 1003.2 standard.
</P><P><DL COMPACT><DT><CODE>: (a colon)</CODE><DD><A NAME="IDX68"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>: [<VAR>arguments</VAR>]
</pre></td></tr></table>Do nothing beyond expanding <VAR>arguments</VAR> and performing redirections.
The return status is zero.
<P><DT><CODE>. (a period)</CODE><DD><A NAME="IDX69"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>. <VAR>filename</VAR> [<VAR>arguments</VAR>]
</pre></td></tr></table>Read and execute commands from the <VAR>filename</VAR> argument in the
current shell context. If <VAR>filename</VAR> does not contain a slash,
the <CODE>PATH</CODE> variable is used to find <VAR>filename</VAR>.
When Bash is not in POSIX mode, the current directory is searched
if <VAR>filename</VAR> is not found in <CODE>$PATH</CODE>.
If any <VAR>arguments</VAR> are supplied, they become the positional
parameters when <VAR>filename</VAR> is executed. Otherwise the positional
parameters are unchanged.
The return status is the exit status of the last command executed, or
zero if no commands are executed. If <VAR>filename</VAR> is not found, or
cannot be read, the return status is non-zero.
This builtin is equivalent to <CODE>source</CODE>.
<P><DT><CODE>break</CODE><DD><A NAME="IDX70"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>break [<VAR>n</VAR>]
</pre></td></tr></table>Exit from a <CODE>for</CODE>, <CODE>while</CODE>, <CODE>until</CODE>, or <CODE>select</CODE> loop.
If <VAR>n</VAR> is supplied, the <VAR>n</VAR>th enclosing loop is exited.
<VAR>n</VAR> must be greater than or equal to 1.
The return status is zero unless <VAR>n</VAR> is not greater than or equal to 1.
<P><DT><CODE>cd</CODE><DD><A NAME="IDX71"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>cd [-L|-P] [<VAR>directory</VAR>]
</pre></td></tr></table>Change the current working directory to <VAR>directory</VAR>.
If <VAR>directory</VAR> is not given, the value of the <CODE>HOME</CODE> shell
variable is used.
If the shell variable <CODE>CDPATH</CODE> exists, it is used as a search path.
If <VAR>directory</VAR> begins with a slash, <CODE>CDPATH</CODE> is not used.
<P>
The <SAMP>`-P'</SAMP> option means to not follow symbolic links; symbolic
links are followed by default or with the <SAMP>`-L'</SAMP> option.
If <VAR>directory</VAR> is <SAMP>`-'</SAMP>, it is equivalent to <CODE>$OLDPWD</CODE>.
</P><P>
If a non-empty directory name from <CODE>CDPATH</CODE> is used, or if
<SAMP>`-'</SAMP> is the first argument, and the directory change is
successful, the absolute pathname of the new working directory is
written to the standard output.
</P><P>
The return status is zero if the directory is successfully changed,
non-zero otherwise.
</P><P><DT><CODE>continue</CODE><DD><A NAME="IDX72"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>continue [<VAR>n</VAR>]
</pre></td></tr></table>Resume the next iteration of an enclosing <CODE>for</CODE>, <CODE>while</CODE>,
<CODE>until</CODE>, or <CODE>select</CODE> loop.
If <VAR>n</VAR> is supplied, the execution of the <VAR>n</VAR>th enclosing loop
is resumed.
<VAR>n</VAR> must be greater than or equal to 1.
The return status is zero unless <VAR>n</VAR> is not greater than or equal to 1.
<P><DT><CODE>eval</CODE><DD><A NAME="IDX73"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>eval [<VAR>arguments</VAR>]
</pre></td></tr></table>The arguments are concatenated together into a single command, which is
then read and executed, and its exit status returned as the exit status
of <CODE>eval</CODE>.
If there are no arguments or only empty arguments, the return status is
zero.
<P><DT><CODE>exec</CODE><DD><A NAME="IDX74"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>exec [-cl] [-a <VAR>name</VAR>] [<VAR>command</VAR> [<VAR>arguments</VAR>]]
</pre></td></tr></table>If <VAR>command</VAR>
is supplied, it replaces the shell without creating a new process.
If the <SAMP>`-l'</SAMP> option is supplied, the shell places a dash at the
beginning of the zeroth arg passed to <VAR>command</VAR>.
This is what the <CODE>login</CODE> program does.
The <SAMP>`-c'</SAMP> option causes <VAR>command</VAR> to be executed with an empty
environment.
If <SAMP>`-a'</SAMP> is supplied, the shell passes <VAR>name</VAR> as the zeroth
argument to <VAR>command</VAR>.
If no <VAR>command</VAR> is specified, redirections may be used to affect
the current shell environment. If there are no redirection errors, the
return status is zero; otherwise the return status is non-zero.
<P><DT><CODE>exit</CODE><DD><A NAME="IDX75"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>exit [<VAR>n</VAR>]
</pre></td></tr></table>Exit the shell, returning a status of <VAR>n</VAR> to the shell's parent.
If <VAR>n</VAR> is omitted, the exit status is that of the last command executed.
Any trap on <CODE>EXIT</CODE> is executed before the shell terminates.
<P><DT><CODE>export</CODE><DD><A NAME="IDX76"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>export [-fn] [-p] [<VAR>name</VAR>[=<VAR>value</VAR>]]
</pre></td></tr></table>Mark each <VAR>name</VAR> to be passed to child processes
in the environment. If the <SAMP>`-f'</SAMP> option is supplied, the <VAR>name</VAR>s
refer to shell functions; otherwise the names refer to shell variables.
The <SAMP>`-n'</SAMP> option means to no longer mark each <VAR>name</VAR> for export.
If no <VAR>names</VAR> are supplied, or if the <SAMP>`-p'</SAMP> option is given, a
list of exported names is displayed.
The <SAMP>`-p'</SAMP> option displays output in a form that may be reused as input.
If a variable name is followed by =<VAR>value</VAR>, the value of
the variable is set to <VAR>value</VAR>.
<P>
The return status is zero unless an invalid option is supplied, one of
the names is not a valid shell variable name, or <SAMP>`-f'</SAMP> is supplied
with a name that is not a shell function.
</P><P><DT><CODE>getopts</CODE><DD><A NAME="IDX77"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>getopts <VAR>optstring</VAR><VAR>name</VAR> [<VAR>args</VAR>]
</pre></td></tr></table><CODE>getopts</CODE> is used by shell scripts to parse positional parameters.
<VAR>optstring</VAR> contains the option characters to be recognized; if a
character is followed by a colon, the option is expected to have an
argument, which should be separated from it by white space.
The colon (<SAMP>`:'</SAMP>) and question mark (<SAMP>`?'</SAMP>) may not be
used as option characters.
Each time it is invoked, <CODE>getopts</CODE>
places the next option in the shell variable <VAR>name</VAR>, initializing
<VAR>name</VAR> if it does not exist,
and the index of the next argument to be processed into the
variable <CODE>OPTIND</CODE>.
<CODE>OPTIND</CODE> is initialized to 1 each time the shell or a shell script
is invoked.
When an option requires an argument,
<CODE>getopts</CODE> places that argument into the variable <CODE>OPTARG</CODE>.
The shell does not reset <CODE>OPTIND</CODE> automatically; it must be manually
reset between multiple calls to <CODE>getopts</CODE> within the same shell
invocation if a new set of parameters is to be used.
<P>
When the end of options is encountered, <CODE>getopts</CODE> exits with a
return value greater than zero.
<CODE>OPTIND</CODE> is set to the index of the first non-option argument,
and <CODE>name</CODE> is set to <SAMP>`?'</SAMP>.
</P><P><CODE>getopts</CODE>
normally parses the positional parameters, but if more arguments are
given in <VAR>args</VAR>, <CODE>getopts</CODE> parses those instead.
</P><P><CODE>getopts</CODE> can report errors in two ways. If the first character of
<VAR>optstring</VAR> is a colon, <VAR>silent</VAR>
error reporting is used. In normal operation diagnostic messages
are printed when invalid options or missing option arguments are
encountered.
If the variable <CODE>OPTERR</CODE>
is set to 0, no error messages will be displayed, even if the first
character of <CODE>optstring</CODE> is not a colon.
</P><P>
If an invalid option is seen,
<CODE>getopts</CODE> places <SAMP>`?'</SAMP> into <VAR>name</VAR> and, if not silent,
prints an error message and unsets <CODE>OPTARG</CODE>.
If <CODE>getopts</CODE> is silent, the option character found is placed in
<CODE>OPTARG</CODE> and no diagnostic message is printed.
</P><P>
If a required argument is not found, and <CODE>getopts</CODE>
is not silent, a question mark (<SAMP>`?'</SAMP>) is placed in <VAR>name</VAR>,
<CODE>OPTARG</CODE> is unset, and a diagnostic message is printed.
If <CODE>getopts</CODE> is silent, then a colon (<SAMP>`:'</SAMP>) is placed in
<VAR>name</VAR> and <CODE>OPTARG</CODE> is set to the option character found.
</P><P><DT><CODE>hash</CODE><DD><A NAME="IDX78"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>hash [-'r] [-p <VAR>filename</VAR>] [-dt] [<VAR>name</VAR>]
</pre></td></tr></table>Remember the full pathnames of commands specified as <VAR>name</VAR> arguments,
so they need not be searched for on subsequent invocations.
The commands are found by searching through the directories listed in
<CODE>$PATH</CODE>.
The <SAMP>`-p'</SAMP> option inhibits the path search, and <VAR>filename</VAR> is
used as the location of <VAR>name</VAR>.
The <SAMP>`-r'</SAMP> option causes the shell to forget all remembered locations.
The <SAMP>`-d'</SAMP> option causes the shell to forget the remembered location
of each <VAR>name</VAR>.
If the <SAMP>`-t'</SAMP> option is supplied, the full pathname to which each
<VAR>name</VAR> corresponds is printed. If multiple <VAR>name</VAR> arguments are
supplied with <SAMP>`-t'</SAMP> the <VAR>name</VAR> is printed before the hashed
full pathname.
The <SAMP>`-l'</SAMP> option causes output to be displayed in a format
that may be reused as input.
If no arguments are given, or if only <SAMP>`-l'</SAMP> is supplied,
information about remembered commands is printed.
The return status is zero unless a <VAR>name</VAR> is not found or an invalid
option is supplied.
<P><DT><CODE>pwd</CODE><DD><A NAME="IDX79"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>pwd [-LP]
</pre></td></tr></table>Print the absolute pathname of the current working directory.
If the <SAMP>`-P'</SAMP> option is supplied, the pathname printed will not
contain symbolic links.
If the <SAMP>`-L'</SAMP> option is supplied, the pathname printed may contain
symbolic links.
The return status is zero unless an error is encountered while
determining the name of the current directory or an invalid option
is supplied.
<P><DT><CODE>readonly</CODE><DD><A NAME="IDX80"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>readonly [-apf] [<VAR>name</VAR>[=<VAR>value</VAR>]] <small>...</small></pre></td></tr></table>Mark each <VAR>name</VAR> as readonly.
The values of these names may not be changed by subsequent assignment.
If the <SAMP>`-f'</SAMP> option is supplied, each <VAR>name</VAR> refers to a shell
function.
The <SAMP>`-a'</SAMP> option means each <VAR>name</VAR> refers to an array variable.
If no <VAR>name</VAR> arguments are given, or if the <SAMP>`-p'</SAMP>
option is supplied, a list of all readonly names is printed.
The <SAMP>`-p'</SAMP> option causes output to be displayed in a format that
may be reused as input.
If a variable name is followed by =<VAR>value</VAR>, the value of
the variable is set to <VAR>value</VAR>.
The return status is zero unless an invalid option is supplied, one of
the <VAR>name</VAR> arguments is not a valid shell variable or function name,
or the <SAMP>`-f'</SAMP> option is supplied with a name that is not a shell function.
<P><DT><CODE>return</CODE><DD><A NAME="IDX81"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>return [<VAR>n</VAR>]
</pre></td></tr></table>Cause a shell function to exit with the return value <VAR>n</VAR>.
If <VAR>n</VAR> is not supplied, the return value is the exit status of the
last command executed in the function.
This may also be used to terminate execution of a script being executed
with the <CODE>.</CODE> (or <CODE>source</CODE>) builtin, returning either <VAR>n</VAR> or
the exit status of the last command executed within the script as the exit
status of the script.
Any command associated with the <CODE>RETURN</CODE> trap is executed
before execution resumes after the function or script.
The return status is non-zero if <CODE>return</CODE> is used outside a function
and not during the execution of a script by <CODE>.</CODE> or <CODE>source</CODE>.
<P><DT><CODE>shift</CODE><DD><A NAME="IDX82"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>shift [<VAR>n</VAR>]
</pre></td></tr></table>Shift the positional parameters to the left by <VAR>n</VAR>.
The positional parameters from <VAR>n</VAR>+1 <small>...</small><CODE>$#</CODE> are
renamed to <CODE>$1</CODE><small>...</small><CODE>$#</CODE>-<VAR>n</VAR>+1.
Parameters represented by the numbers <CODE>$#</CODE> to <VAR>n</VAR>+1 are unset.
<VAR>n</VAR> must be a non-negative number less than or equal to <CODE>$#</CODE>.
If <VAR>n</VAR> is zero or greater than <CODE>$#</CODE>, the positional parameters
are not changed.
If <VAR>n</VAR> is not supplied, it is assumed to be 1.
The return status is zero unless <VAR>n</VAR> is greater than <CODE>$#</CODE> or
less than zero, non-zero otherwise.
<P><DT><CODE>test</CODE><DD><DT><CODE>[</CODE><DD><A NAME="IDX83"></A><A NAME="IDX84"></A>
Evaluate a conditional expression <VAR>expr</VAR>.
Each operator and operand must be a separate argument.
Expressions are composed of the primaries described below in
<A HREF="bashref.html#SEC78">6.4 Bash Conditional Expressions</A>.
<CODE>test</CODE> does not accept any options, nor does it accept and ignore
an argument of <SAMP>`--'</SAMP> as signifying the end of options.
<P>
When the <CODE>[</CODE> form is used, the last argument to the command must
be a <CODE>]</CODE>.
</P><P>
Expressions may be combined using the following operators, listed in
decreasing order of precedence.
</P><P><DL COMPACT><DT><CODE>! <VAR>expr</VAR></CODE><DD>True if <VAR>expr</VAR> is false.
<P><DT><CODE>( <VAR>expr</VAR> )</CODE><DD>Returns the value of <VAR>expr</VAR>.
This may be used to override the normal precedence of operators.
<P><DT><CODE><VAR>expr1</VAR> -a <VAR>expr2</VAR></CODE><DD>True if both <VAR>expr1</VAR> and <VAR>expr2</VAR> are true.
<P><DT><CODE><VAR>expr1</VAR> -o <VAR>expr2</VAR></CODE><DD>True if either <VAR>expr1</VAR> or <VAR>expr2</VAR> is true.
</DL><P>
The <CODE>test</CODE> and <CODE>[</CODE> builtins evaluate conditional
expressions using a set of rules based on the number of arguments.
</P><P><DL COMPACT><DT>0 arguments
<DD>The expression is false.
<P><DT>1 argument
<DD>The expression is true if and only if the argument is not null.
<P><DT>2 arguments
<DD>If the first argument is <SAMP>`!'</SAMP>, the expression is true if and
only if the second argument is null.
If the first argument is one of the unary conditional operators
(see section <A HREF="bashref.html#SEC78">6.4 Bash Conditional Expressions</A>), the expression
is true if the unary test is true.
If the first argument is not a valid unary operator, the expression is
false.
<P><DT>3 arguments
<DD>If the second argument is one of the binary conditional
operators (see section <A HREF="bashref.html#SEC78">6.4 Bash Conditional Expressions</A>), the
result of the expression is the result of the binary test using the
first and third arguments as operands.
If the first argument is <SAMP>`!'</SAMP>, the value is the negation of
the two-argument test using the second and third arguments.
If the first argument is exactly <SAMP>`('</SAMP> and the third argument is
exactly <SAMP>`)'</SAMP>, the result is the one-argument test of the second
argument.
Otherwise, the expression is false.
The <SAMP>`-a'</SAMP> and <SAMP>`-o'</SAMP> operators are considered binary operators
in this case.
<P><DT>4 arguments
<DD>If the first argument is <SAMP>`!'</SAMP>, the result is the negation of
the three-argument expression composed of the remaining arguments.
Otherwise, the expression is parsed and evaluated according to
precedence using the rules listed above.
<P><DT>5 or more arguments
<DD>The expression is parsed and evaluated according to precedence
using the rules listed above.
</DL><P><DT><CODE>times</CODE><DD><A NAME="IDX85"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>times
</pre></td></tr></table>Print out the user and system times used by the shell and its children.
The return status is zero.
<P><DT><CODE>trap</CODE><DD><A NAME="IDX86"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>trap [-lp] [<VAR>arg</VAR>] [<VAR>sigspec</VAR><small>...</small>]
</pre></td></tr></table>The commands in <VAR>arg</VAR> are to be read and executed when the
shell receives signal <VAR>sigspec</VAR>. If <VAR>arg</VAR> is absent (and
there is a single <VAR>sigspec</VAR>) or
equal to <SAMP>`-'</SAMP>, each specified signal's disposition is reset
to the value it had when the shell was started.
If <VAR>arg</VAR> is the null string, then the signal specified by
each <VAR>sigspec</VAR> is ignored by the shell and commands it invokes.
If <VAR>arg</VAR> is not present and <SAMP>`-p'</SAMP> has been supplied,
the shell displays the trap commands associated with each <VAR>sigspec</VAR>.
If no arguments are supplied, or
only <SAMP>`-p'</SAMP> is given, <CODE>trap</CODE> prints the list of commands
associated with each signal number in a form that may be reused as
shell input.
The <SAMP>`-l'</SAMP> option causes the shell to print a list of signal names
and their corresponding numbers.
Each <VAR>sigspec</VAR> is either a signal name or a signal number.
Signal names are case insensitive and the <CODE>SIG</CODE> prefix is optional.
If a <VAR>sigspec</VAR>
is <CODE>0</CODE> or <CODE>EXIT</CODE>, <VAR>arg</VAR> is executed when the shell exits.
If a <VAR>sigspec</VAR> is <CODE>DEBUG</CODE>, the command <VAR>arg</VAR> is executed
before every simple command, <CODE>for</CODE> command, <CODE>case</CODE> command,
<CODE>select</CODE> command, every arithmetic <CODE>for</CODE> command, and before
the first command executes in a shell function.
Refer to the description of the <CODE>extglob</CODE> option to the
<CODE>shopt</CODE> builtin (see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>) for details of its
effect on the <CODE>DEBUG</CODE> trap.
If a <VAR>sigspec</VAR> is <CODE>ERR</CODE>, the command <VAR>arg</VAR>
is executed whenever a simple command has a non-zero exit status,
subject to the following conditions.
The <CODE>ERR</CODE> trap is not executed if the failed command is part of the
command list immediately following an <CODE>until</CODE> or <CODE>while</CODE> keyword,
part of the test in an <CODE>if</CODE> statement,
part of a <CODE>&#38;&#38;</CODE> or <CODE>||</CODE> list, or if the command's return
status is being inverted using <CODE>!</CODE>.
These are the same conditions obeyed by the <CODE>errexit</CODE> option.
If a <VAR>sigspec</VAR> is <CODE>RETURN</CODE>, the command <VAR>arg</VAR> is executed
each time a shell function or a script executed with the <CODE>.</CODE> or
<CODE>source</CODE> builtins finishes executing.
<P>
Signals ignored upon entry to the shell cannot be trapped or reset.
Trapped signals are reset to their original values in a child
process when it is created.
</P><P>
The return status is zero unless a <VAR>sigspec</VAR> does not specify a
valid signal.
</P><P><DT><CODE>umask</CODE><DD><A NAME="IDX87"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>umask [-p] [-S] [<VAR>mode</VAR>]
</pre></td></tr></table>Set the shell process's file creation mask to <VAR>mode</VAR>. If
<VAR>mode</VAR> begins with a digit, it is interpreted as an octal number;
if not, it is interpreted as a symbolic mode mask similar
to that accepted by the <CODE>chmod</CODE> command. If <VAR>mode</VAR> is
omitted, the current value of the mask is printed. If the <SAMP>`-S'</SAMP>
option is supplied without a <VAR>mode</VAR> argument, the mask is printed
in a symbolic format.
If the <SAMP>`-p'</SAMP> option is supplied, and <VAR>mode</VAR>
is omitted, the output is in a form that may be reused as input.
The return status is zero if the mode is successfully changed or if
no <VAR>mode</VAR> argument is supplied, and non-zero otherwise.
<P>
Note that when the mode is interpreted as an octal number, each number
of the umask is subtracted from <CODE>7</CODE>. Thus, a umask of <CODE>022</CODE>
results in permissions of <CODE>755</CODE>.
</P><P><DT><CODE>unset</CODE><DD><A NAME="IDX88"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>unset [-fv] [<VAR>name</VAR>]
</pre></td></tr></table>Each variable or function <VAR>name</VAR> is removed.
If no options are supplied, or the <SAMP>`-v'</SAMP> option is given, each
<VAR>name</VAR> refers to a shell variable.
If the <SAMP>`-f'</SAMP> option is given, the <VAR>name</VAR>s refer to shell
functions, and the function definition is removed.
Readonly variables and functions may not be unset.
The return status is zero unless a <VAR>name</VAR> is readonly.
</DL><P><A NAME="Bash Builtins"></A><HR SIZE="6"><A NAME="SEC58"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC57">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC59">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC59">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 4.2 Bash Builtin Commands </H2><!--docid::SEC58::--><P>
This section describes builtin commands which are unique to
or have been extended in Bash.
Some of these commands are specified in the POSIX 1003.2 standard.
</P><P><DL COMPACT><DT><CODE>alias</CODE><DD><A NAME="IDX89"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>alias [<CODE>-p</CODE>] [<VAR>name</VAR>[=<VAR>value</VAR>] <small>...</small>]
</pre></td></tr></table><P>
Without arguments or with the <SAMP>`-p'</SAMP> option, <CODE>alias</CODE> prints
the list of aliases on the standard output in a form that allows
them to be reused as input.
If arguments are supplied, an alias is defined for each <VAR>name</VAR>
whose <VAR>value</VAR> is given. If no <VAR>value</VAR> is given, the name
and value of the alias is printed.
Aliases are described in <A HREF="bashref.html#SEC80">6.6 Aliases</A>.
</P><P><DT><CODE>bind</CODE><DD><A NAME="IDX90"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>bind [-m <VAR>keymap</VAR>] [-lpsvPSV]
bind [-m <VAR>keymap</VAR>] [-q <VAR>function</VAR>] [-u <VAR>function</VAR>] [-r <VAR>keyseq</VAR>]
bind [-m <VAR>keymap</VAR>] -f <VAR>filename</VAR>
bind [-m <VAR>keymap</VAR>] -x <VAR>keyseq:shell-command</VAR>
bind [-m <VAR>keymap</VAR>] <VAR>keyseq:function-name</VAR>
bind <VAR>readline-command</VAR></pre></td></tr></table><P>
Display current Readline (see section <A HREF="bashref.html#SEC91">8. Command Line Editing</A>)
key and function bindings,
bind a key sequence to a Readline function or macro,
or set a Readline variable.
Each non-option argument is a command as it would appear in a
a Readline initialization file (see section <A HREF="bashref.html#SEC99">8.3 Readline Init File</A>),
but each binding or command must be passed as a separate argument; e.g.,
<SAMP>`"\C-x\C-r":re-read-init-file'</SAMP>.
Options, if supplied, have the following meanings:
</P><P><DL COMPACT><DT><CODE>-m <VAR>keymap</VAR></CODE><DD>Use <VAR>keymap</VAR> as the keymap to be affected by
the subsequent bindings. Acceptable <VAR>keymap</VAR>
names are
<CODE>emacs</CODE>,
<CODE>emacs-standard</CODE>,
<CODE>emacs-meta</CODE>,
<CODE>emacs-ctlx</CODE>,
<CODE>vi</CODE>,
<CODE>vi-move</CODE>,
<CODE>vi-command</CODE>, and
<CODE>vi-insert</CODE>.
<CODE>vi</CODE> is equivalent to <CODE>vi-command</CODE>;
<CODE>emacs</CODE> is equivalent to <CODE>emacs-standard</CODE>.
<P><DT><CODE>-l</CODE><DD>List the names of all Readline functions.
<P><DT><CODE>-p</CODE><DD>Display Readline function names and bindings in such a way that they
can be used as input or in a Readline initialization file.
<P><DT><CODE>-P</CODE><DD>List current Readline function names and bindings.
<P><DT><CODE>-v</CODE><DD>Display Readline variable names and values in such a way that they
can be used as input or in a Readline initialization file.
<P><DT><CODE>-V</CODE><DD>List current Readline variable names and values.
<P><DT><CODE>-s</CODE><DD>Display Readline key sequences bound to macros and the strings they output
in such a way that they can be used as input or in a Readline
initialization file.
<P><DT><CODE>-S</CODE><DD>Display Readline key sequences bound to macros and the strings they output.
<P><DT><CODE>-f <VAR>filename</VAR></CODE><DD>Read key bindings from <VAR>filename</VAR>.
<P><DT><CODE>-q <VAR>function</VAR></CODE><DD>Query about which keys invoke the named <VAR>function</VAR>.
<P><DT><CODE>-u <VAR>function</VAR></CODE><DD>Unbind all keys bound to the named <VAR>function</VAR>.
<P><DT><CODE>-r <VAR>keyseq</VAR></CODE><DD>Remove any current binding for <VAR>keyseq</VAR>.
<P><DT><CODE>-x <VAR>keyseq:shell-command</VAR></CODE><DD>Cause <VAR>shell-command</VAR> to be executed whenever <VAR>keyseq</VAR> is
entered.
<P></DL><P>
The return status is zero unless an invalid option is supplied or an
error occurs.
</P><P><DT><CODE>builtin</CODE><DD><A NAME="IDX91"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>builtin [<VAR>shell-builtin</VAR> [<VAR>args</VAR>]]
</pre></td></tr></table>Run a shell builtin, passing it <VAR>args</VAR>, and return its exit status.
This is useful when defining a shell function with the same
name as a shell builtin, retaining the functionality of the builtin within
the function.
The return status is non-zero if <VAR>shell-builtin</VAR> is not a shell
builtin command.
<P><DT><CODE>caller</CODE><DD><A NAME="IDX92"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>caller [<VAR>expr</VAR>]
</pre></td></tr></table>Returns the context of any active subroutine call (a shell function or
a script executed with the <CODE>.</CODE> or <CODE>source</CODE> builtins).
<P>
Without <VAR>expr</VAR>, <CODE>caller</CODE> displays the line number and source
filename of the current subroutine call.
If a non-negative integer is supplied as <VAR>expr</VAR>, <CODE>caller</CODE>
displays the line number, subroutine name, and source file corresponding
to that position in the current execution call stack. This extra
information may be used, for example, to print a stack trace. The
current frame is frame 0.
</P><P>
The return value is 0 unless the shell is not executing a subroutine
call or <VAR>expr</VAR> does not correspond to a valid position in the
call stack.
</P><P><DT><CODE>command</CODE><DD><A NAME="IDX93"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>command [-pVv] <VAR>command</VAR> [<VAR>arguments</VAR><small>...</small>]
</pre></td></tr></table>Runs <VAR>command</VAR> with <VAR>arguments</VAR> ignoring any shell function
named <VAR>command</VAR>.
Only shell builtin commands or commands found by searching the
<CODE>PATH</CODE> are executed.
If there is a shell function named <CODE>ls</CODE>, running <SAMP>`command ls'</SAMP>
within the function will execute the external command <CODE>ls</CODE>
instead of calling the function recursively.
The <SAMP>`-p'</SAMP> option means to use a default value for <CODE>PATH</CODE>
that is guaranteed to find all of the standard utilities.
The return status in this case is 127 if <VAR>command</VAR> cannot be
found or an error occurred, and the exit status of <VAR>command</VAR>
otherwise.
<P>
If either the <SAMP>`-V'</SAMP> or <SAMP>`-v'</SAMP> option is supplied, a
description of <VAR>command</VAR> is printed. The <SAMP>`-v'</SAMP> option
causes a single word indicating the command or file name used to
invoke <VAR>command</VAR> to be displayed; the <SAMP>`-V'</SAMP> option produces
a more verbose description. In this case, the return status is
zero if <VAR>command</VAR> is found, and non-zero if not.
</P><P><DT><CODE>declare</CODE><DD><A NAME="IDX94"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>declare [-afFirtx] [-p] [<VAR>name</VAR>[=<VAR>value</VAR>] <small>...</small>]
</pre></td></tr></table><P>
Declare variables and give them attributes. If no <VAR>name</VAR>s
are given, then display the values of variables instead.
</P><P>
The <SAMP>`-p'</SAMP> option will display the attributes and values of each
<VAR>name</VAR>.
When <SAMP>`-p'</SAMP> is used, additional options are ignored.
The <SAMP>`-F'</SAMP> option inhibits the display of function definitions;
only the function name and attributes are printed.
If the <CODE>extdebug</CODE> shell option is enabled using <CODE>shopt</CODE>
(see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>), the source file name and line number where
the function is defined are displayed as well.
<SAMP>`-F'</SAMP> implies <SAMP>`-f'</SAMP>.
The following options can be used to restrict output to variables with
the specified attributes or to give variables attributes:
</P><P><DL COMPACT><DT><CODE>-a</CODE><DD>Each <VAR>name</VAR> is an array variable (see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>).
<P><DT><CODE>-f</CODE><DD>Use function names only.
<P><DT><CODE>-i</CODE><DD>The variable is to be treated as
an integer; arithmetic evaluation (see section <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>) is
performed when the variable is assigned a value.
<P><DT><CODE>-r</CODE><DD>Make <VAR>name</VAR>s readonly. These names cannot then be assigned values
by subsequent assignment statements or unset.
<P><DT><CODE>-t</CODE><DD>Give each <VAR>name</VAR> the <CODE>trace</CODE> attribute.
Traced functions inherit the <CODE>DEBUG</CODE> and <CODE>RETURN</CODE> traps from
the calling shell.
The trace attribute has no special meaning for variables.
<P><DT><CODE>-x</CODE><DD>Mark each <VAR>name</VAR> for export to subsequent commands via
the environment.
</DL><P>
Using <SAMP>`+'</SAMP> instead of <SAMP>`-'</SAMP> turns off the attribute instead.
When used in a function, <CODE>declare</CODE> makes each <VAR>name</VAR> local,
as with the <CODE>local</CODE> command. If a variable name is followed by
=<VAR>value</VAR>, the value of the variable is set to <VAR>value</VAR>.
</P><P>
The return status is zero unless an invalid option is encountered,
an attempt is made to define a function using <SAMP>`-f foo=bar'</SAMP>,
an attempt is made to assign a value to a readonly variable,
an attempt is made to assign a value to an array variable without
using the compound assignment syntax (see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>),
one of the <VAR>names</VAR> is not a valid shell variable name,
an attempt is made to turn off readonly status for a readonly variable,
an attempt is made to turn off array status for an array variable,
or an attempt is made to display a non-existent function with <SAMP>`-f'</SAMP>.
</P><P><DT><CODE>echo</CODE><DD><A NAME="IDX95"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>echo [-neE] [<VAR>arg</VAR><small>...</small>]
</pre></td></tr></table>Output the <VAR>arg</VAR>s, separated by spaces, terminated with a
newline.
The return status is always 0.
If <SAMP>`-n'</SAMP> is specified, the trailing newline is suppressed.
If the <SAMP>`-e'</SAMP> option is given, interpretation of the following
backslash-escaped characters is enabled.
The <SAMP>`-E'</SAMP> option disables the interpretation of these escape characters,
even on systems where they are interpreted by default.
The <CODE>xpg_echo</CODE> shell option may be used to
dynamically determine whether or not <CODE>echo</CODE> expands these
escape characters by default.
<CODE>echo</CODE> does not interpret <SAMP>`--'</SAMP> to mean the end of options.
<P><CODE>echo</CODE> interprets the following escape sequences:
<DL COMPACT><DT><CODE>\a</CODE><DD>alert (bell)
<DT><CODE>\b</CODE><DD>backspace
<DT><CODE>\c</CODE><DD>suppress trailing newline
<DT><CODE>\e</CODE><DD>escape
<DT><CODE>\f</CODE><DD>form feed
<DT><CODE>\n</CODE><DD>new line
<DT><CODE>\r</CODE><DD>carriage return
<DT><CODE>\t</CODE><DD>horizontal tab
<DT><CODE>\v</CODE><DD>vertical tab
<DT><CODE>\\</CODE><DD>backslash
<DT><CODE>\0<VAR>nnn</VAR></CODE><DD>the eight-bit character whose value is the octal value <VAR>nnn</VAR>
(zero to three octal digits)
<DT><CODE>\<VAR>nnn</VAR></CODE><DD>the eight-bit character whose value is the octal value <VAR>nnn</VAR>
(one to three octal digits)
<DT><CODE>\x<VAR>HH</VAR></CODE><DD>the eight-bit character whose value is the hexadecimal value <VAR>HH</VAR>
(one or two hex digits)
</DL><P><DT><CODE>enable</CODE><DD><A NAME="IDX96"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>enable [-n] [-p] [-f <VAR>filename</VAR>] [-ads] [<VAR>name</VAR><small>...</small>]
</pre></td></tr></table>Enable and disable builtin shell commands.
Disabling a builtin allows a disk command which has the same name
as a shell builtin to be executed without specifying a full pathname,
even though the shell normally searches for builtins before disk commands.
If <SAMP>`-n'</SAMP> is used, the <VAR>name</VAR>s become disabled. Otherwise
<VAR>name</VAR>s are enabled. For example, to use the <CODE>test</CODE> binary
found via <CODE>$PATH</CODE> instead of the shell builtin version, type
<SAMP>`enable -n test'</SAMP>.
<P>
If the <SAMP>`-p'</SAMP> option is supplied, or no <VAR>name</VAR> arguments appear,
a list of shell builtins is printed. With no other arguments, the list
consists of all enabled shell builtins.
The <SAMP>`-a'</SAMP> option means to list
each builtin with an indication of whether or not it is enabled.
</P><P>
The <SAMP>`-f'</SAMP> option means to load the new builtin command <VAR>name</VAR>
from shared object <VAR>filename</VAR>, on systems that support dynamic loading.
The <SAMP>`-d'</SAMP> option will delete a builtin loaded with <SAMP>`-f'</SAMP>.
</P><P>
If there are no options, a list of the shell builtins is displayed.
The <SAMP>`-s'</SAMP> option restricts <CODE>enable</CODE> to the POSIX special
builtins. If <SAMP>`-s'</SAMP> is used with <SAMP>`-f'</SAMP>, the new builtin becomes
a special builtin (see section <A HREF="bashref.html#SEC60">4.4 Special Builtins</A>).
</P><P>
The return status is zero unless a <VAR>name</VAR> is not a shell builtin
or there is an error loading a new builtin from a shared object.
</P><P><DT><CODE>help</CODE><DD><A NAME="IDX97"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>help [-s] [<VAR>pattern</VAR>]
</pre></td></tr></table>Display helpful information about builtin commands.
If <VAR>pattern</VAR> is specified, <CODE>help</CODE> gives detailed help
on all commands matching <VAR>pattern</VAR>, otherwise a list of
the builtins is printed.
The <SAMP>`-s'</SAMP> option restricts the information displayed to a short
usage synopsis.
The return status is zero unless no command matches <VAR>pattern</VAR>.
<P><DT><CODE>let</CODE><DD><A NAME="IDX98"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>let <VAR>expression</VAR> [<VAR>expression</VAR>]
</pre></td></tr></table>The <CODE>let</CODE> builtin allows arithmetic to be performed on shell
variables. Each <VAR>expression</VAR> is evaluated according to the
rules given below in <A HREF="bashref.html#SEC79">6.5 Shell Arithmetic</A>. If the
last <VAR>expression</VAR> evaluates to 0, <CODE>let</CODE> returns 1;
otherwise 0 is returned.
<P><DT><CODE>local</CODE><DD><A NAME="IDX99"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>local [<VAR>option</VAR>] <VAR>name</VAR>[=<VAR>value</VAR>] <small>...</small></pre></td></tr></table>For each argument, a local variable named <VAR>name</VAR> is created,
and assigned <VAR>value</VAR>.
The <VAR>option</VAR> can be any of the options accepted by <CODE>declare</CODE>.
<CODE>local</CODE> can only be used within a function; it makes the variable
<VAR>name</VAR> have a visible scope restricted to that function and its
children. The return status is zero unless <CODE>local</CODE> is used outside
a function, an invalid <VAR>name</VAR> is supplied, or <VAR>name</VAR> is a
readonly variable.
<P><DT><CODE>logout</CODE><DD><A NAME="IDX100"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>logout [<VAR>n</VAR>]
</pre></td></tr></table>Exit a login shell, returning a status of <VAR>n</VAR> to the shell's
parent.
<P><DT><CODE>printf</CODE><DD><A NAME="IDX101"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre><CODE>printf</CODE> [-v <VAR>var</VAR>] <VAR>format</VAR> [<VAR>arguments</VAR>]
</pre></td></tr></table>Write the formatted <VAR>arguments</VAR> to the standard output under the
control of the <VAR>format</VAR>.
The <VAR>format</VAR> is a character string which contains three types of objects:
plain characters, which are simply copied to standard output, character
escape sequences, which are converted and copied to the standard output, and
format specifications, each of which causes printing of the next successive
<VAR>argument</VAR>.
In addition to the standard <CODE>printf(1)</CODE> formats, <SAMP>`%b'</SAMP> causes
<CODE>printf</CODE> to expand backslash escape sequences in the corresponding
<VAR>argument</VAR>,
(except that <SAMP>`\c'</SAMP> terminates output, backslashes in
<SAMP>`\''</SAMP>, <SAMP>`\"'</SAMP>, and <SAMP>`\?'</SAMP> are not removed, and octal escapes
beginning with <SAMP>`\0'</SAMP> may contain up to four digits),
and <SAMP>`%q'</SAMP> causes <CODE>printf</CODE> to output the
corresponding <VAR>argument</VAR> in a format that can be reused as shell input.
<P>
The <SAMP>`-v'</SAMP> option causes the output to be assigned to the variable
<VAR>var</VAR> rather than being printed to the standard output.
</P><P>
The <VAR>format</VAR> is reused as necessary to consume all of the <VAR>arguments</VAR>.
If the <VAR>format</VAR> requires more <VAR>arguments</VAR> than are supplied, the
extra format specifications behave as if a zero value or null string, as
appropriate, had been supplied. The return value is zero on success,
non-zero on failure.
</P><P><DT><CODE>read</CODE><DD><A NAME="IDX102"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>read [-ers] [-a <VAR>aname</VAR>] [-d <VAR>delim</VAR>] [-n <VAR>nchars</VAR>] [-p <VAR>prompt</VAR>] [-t <VAR>timeout</VAR>] [-u <VAR>fd</VAR>] [<VAR>name</VAR><small>...</small>]
</pre></td></tr></table>One line is read from the standard input, or from the file descriptor
<VAR>fd</VAR> supplied as an argument to the <SAMP>`-u'</SAMP> option, and the first word
is assigned to the first <VAR>name</VAR>, the second word to the second <VAR>name</VAR>,
and so on, with leftover words and their intervening separators assigned
to the last <VAR>name</VAR>.
If there are fewer words read from the input stream than names,
the remaining names are assigned empty values.
The characters in the value of the <CODE>IFS</CODE> variable
are used to split the line into words.
The backslash character <SAMP>`\'</SAMP> may be used to remove any special
meaning for the next character read and for line continuation.
If no names are supplied, the line read is assigned to the
variable <CODE>REPLY</CODE>.
The return code is zero, unless end-of-file is encountered, <CODE>read</CODE>
times out, or an invalid file descriptor is supplied as the argument to
<SAMP>`-u'</SAMP>.
Options, if supplied, have the following meanings:
<P><DL COMPACT><DT><CODE>-a <VAR>aname</VAR></CODE><DD>The words are assigned to sequential indices of the array variable
<VAR>aname</VAR>, starting at 0.
All elements are removed from <VAR>aname</VAR> before the assignment.
Other <VAR>name</VAR> arguments are ignored.
<P><DT><CODE>-d <VAR>delim</VAR></CODE><DD>The first character of <VAR>delim</VAR> is used to terminate the input line,
rather than newline.
<P><DT><CODE>-e</CODE><DD>Readline (see section <A HREF="bashref.html#SEC91">8. Command Line Editing</A>) is used to obtain the line.
<P><DT><CODE>-n <VAR>nchars</VAR></CODE><DD><CODE>read</CODE> returns after reading <VAR>nchars</VAR> characters rather than
waiting for a complete line of input.
<P><DT><CODE>-p <VAR>prompt</VAR></CODE><DD>Display <VAR>prompt</VAR>, without a trailing newline, before attempting
to read any input.
The prompt is displayed only if input is coming from a terminal.
<P><DT><CODE>-r</CODE><DD>If this option is given, backslash does not act as an escape character.
The backslash is considered to be part of the line.
In particular, a backslash-newline pair may not be used as a line
continuation.
<P><DT><CODE>-s</CODE><DD>Silent mode. If input is coming from a terminal, characters are
not echoed.
<P><DT><CODE>-t <VAR>timeout</VAR></CODE><DD>Cause <CODE>read</CODE> to time out and return failure if a complete line of
input is not read within <VAR>timeout</VAR> seconds.
This option has no effect if <CODE>read</CODE> is not reading input from the
terminal or a pipe.
<P><DT><CODE>-u <VAR>fd</VAR></CODE><DD>Read input from file descriptor <VAR>fd</VAR>.
<P></DL><P><DT><CODE>shopt</CODE><DD><A NAME="IDX103"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>shopt [-pqsu] [-o] [<VAR>optname</VAR><small>...</small>]
</pre></td></tr></table>Toggle the values of variables controlling optional shell behavior.
With no options, or with the <SAMP>`-p'</SAMP> option, a list of all settable
options is displayed, with an indication of whether or not each is set.
The <SAMP>`-p'</SAMP> option causes output to be displayed in a form that
may be reused as input.
Other options have the following meanings:
<P><DL COMPACT><DT><CODE>-s</CODE><DD>Enable (set) each <VAR>optname</VAR>.
<P><DT><CODE>-u</CODE><DD>Disable (unset) each <VAR>optname</VAR>.
<P><DT><CODE>-q</CODE><DD>Suppresses normal output; the return status
indicates whether the <VAR>optname</VAR> is set or unset.
If multiple <VAR>optname</VAR> arguments are given with <SAMP>`-q'</SAMP>,
the return status is zero if all <VAR>optnames</VAR> are enabled;
non-zero otherwise.
<P><DT><CODE>-o</CODE><DD>Restricts the values of
<VAR>optname</VAR> to be those defined for the <SAMP>`-o'</SAMP> option to the
<CODE>set</CODE> builtin (see section <A HREF="bashref.html#SEC59">4.3 The Set Builtin</A>).
</DL><P>
If either <SAMP>`-s'</SAMP> or <SAMP>`-u'</SAMP>
is used with no <VAR>optname</VAR> arguments, the display is limited to
those options which are set or unset, respectively.
</P><P>
Unless otherwise noted, the <CODE>shopt</CODE> options are disabled (off)
by default.
</P><P>
The return status when listing options is zero if all <VAR>optnames</VAR>
are enabled, non-zero otherwise. When setting or unsetting options,
the return status is zero unless an <VAR>optname</VAR> is not a valid shell
option.
</P><P>
The list of <CODE>shopt</CODE> options is:
<DL COMPACT><DT><CODE>cdable_vars</CODE><DD>If this is set, an argument to the <CODE>cd</CODE>
builtin command that
is not a directory is assumed to be the name of a variable whose
value is the directory to change to.
<P><DT><CODE>cdspell</CODE><DD>If set, minor errors in the spelling of a directory component in a
<CODE>cd</CODE> command will be corrected.
The errors checked for are transposed characters,
a missing character, and a character too many.
If a correction is found, the corrected path is printed,
and the command proceeds.
This option is only used by interactive shells.
<P><DT><CODE>checkhash</CODE><DD>If this is set, Bash checks that a command found in the hash
table exists before trying to execute it. If a hashed command no
longer exists, a normal path search is performed.
<P><DT><CODE>checkwinsize</CODE><DD>If set, Bash checks the window size after each command
and, if necessary, updates the values of
<CODE>LINES</CODE> and <CODE>COLUMNS</CODE>.
<P><DT><CODE>cmdhist</CODE><DD>If set, Bash
attempts to save all lines of a multiple-line
command in the same history entry. This allows
easy re-editing of multi-line commands.
<P><DT><CODE>dotglob</CODE><DD>If set, Bash includes filenames beginning with a `.' in
the results of filename expansion.
<P><DT><CODE>execfail</CODE><DD>If this is set, a non-interactive shell will not exit if
it cannot execute the file specified as an argument to the <CODE>exec</CODE>
builtin command. An interactive shell does not exit if <CODE>exec</CODE>
fails.
<P><DT><CODE>expand_aliases</CODE><DD>If set, aliases are expanded as described below under Aliases,
<A HREF="bashref.html#SEC80">6.6 Aliases</A>.
This option is enabled by default for interactive shells.
<P><DT><CODE>extdebug</CODE><DD>If set, behavior intended for use by debuggers is enabled:
<P><OL><LI>
The <SAMP>`-F'</SAMP> option to the <CODE>declare</CODE> builtin (see section <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>)
displays the source file name and line number corresponding to each function
name supplied as an argument.
<P><LI>
If the command run by the <CODE>DEBUG</CODE> trap returns a non-zero value, the
next command is skipped and not executed.
<P><LI>
If the command run by the <CODE>DEBUG</CODE> trap returns a value of 2, and the
shell is executing in a subroutine (a shell function or a shell script
executed by the <CODE>.</CODE> or <CODE>source</CODE> builtins), a call to
<CODE>return</CODE> is simulated.
<P><LI><CODE>BASH_ARGC</CODE> and <CODE>BASH_ARGV</CODE> are updated as described in their
descriptions (see section <A HREF="bashref.html#SEC63">5.2 Bash Variables</A>).
<P><LI>
Function tracing is enabled: command substitution, shell functions, and
subshells invoked with <CODE>( <VAR>command</VAR> )</CODE> inherit the
<CODE>DEBUG</CODE> and <CODE>RETURN</CODE> traps.
<P><LI>
Error tracing is enabled: command substitution, shell functions, and
subshells invoked with <CODE>( <VAR>command</VAR> )</CODE> inherit the
<CODE>ERROR</CODE> trap.
</OL><P><DT><CODE>extglob</CODE><DD>If set, the extended pattern matching features described above
(see section <A HREF="bashref.html#SEC36">3.5.8.1 Pattern Matching</A>) are enabled.
<P><DT><CODE>extquote</CODE><DD>If set, <CODE>$'<VAR>string</VAR>'</CODE> and <CODE>$"<VAR>string</VAR>"</CODE> quoting is
performed within <CODE>${<VAR>parameter</VAR>}</CODE> expansions
enclosed in double quotes. This option is enabled by default.
<P><DT><CODE>failglob</CODE><DD>If set, patterns which fail to match filenames during pathname expansion
result in an expansion error.
<P><DT><CODE>force_fignore</CODE><DD>If set, the suffixes specified by the <CODE>FIGNORE</CODE> shell variable
cause words to be ignored when performing word completion even if
the ignored words are the only possible completions.
See section <A HREF="bashref.html#SEC63">5.2 Bash Variables</A>, for a description of <CODE>FIGNORE</CODE>.
This option is enabled by default.
<P><DT><CODE>gnu_errfmt</CODE><DD>If set, shell error messages are written in the standard GNU error
message format.
<P><DT><CODE>histappend</CODE><DD>If set, the history list is appended to the file named by the value
of the <CODE>HISTFILE</CODE>
variable when the shell exits, rather than overwriting the file.
<P><DT><CODE>histreedit</CODE><DD>If set, and Readline
is being used, a user is given the opportunity to re-edit a
failed history substitution.
<P><DT><CODE>histverify</CODE><DD>If set, and Readline
is being used, the results of history substitution are not immediately
passed to the shell parser. Instead, the resulting line is loaded into
the Readline editing buffer, allowing further modification.
<P><DT><CODE>hostcomplete</CODE><DD>If set, and Readline is being used, Bash will attempt to perform
hostname completion when a word containing a <SAMP>`@'</SAMP> is being
completed (see section <A HREF="bashref.html#SEC109">8.4.6 Letting Readline Type For You</A>). This option is enabled
by default.
<P><DT><CODE>huponexit</CODE><DD>If set, Bash will send <CODE>SIGHUP</CODE> to all jobs when an interactive
login shell exits (see section <A HREF="bashref.html#SEC54">3.7.6 Signals</A>).
<P><DT><CODE>interactive_comments</CODE><DD>Allow a word beginning with <SAMP>`#'</SAMP>
to cause that word and all remaining characters on that
line to be ignored in an interactive shell.
This option is enabled by default.
<P><DT><CODE>lithist</CODE><DD>If enabled, and the <CODE>cmdhist</CODE>
option is enabled, multi-line commands are saved to the history with
embedded newlines rather than using semicolon separators where possible.
<P><DT><CODE>login_shell</CODE><DD>The shell sets this option if it is started as a login shell
(see section <A HREF="bashref.html#SEC65">6.1 Invoking Bash</A>).
The value may not be changed.
<P><DT><CODE>mailwarn</CODE><DD>If set, and a file that Bash is checking for mail has been
accessed since the last time it was checked, the message
<CODE>"The mail in <VAR>mailfile</VAR> has been read"</CODE> is displayed.
<P><DT><CODE>no_empty_cmd_completion</CODE><DD>If set, and Readline is being used, Bash will not attempt to search
the <CODE>PATH</CODE> for possible completions when completion is attempted
on an empty line.
<P><DT><CODE>nocaseglob</CODE><DD>If set, Bash matches filenames in a case-insensitive fashion when
performing filename expansion.
<P><DT><CODE>nocasematch</CODE><DD>If set, Bash matches patterns in a case-insensitive fashion when
performing matching while executing <CODE>case</CODE> or <CODE>[[</CODE>
conditional commands.
<P><DT><CODE>nullglob</CODE><DD>If set, Bash allows filename patterns which match no
files to expand to a null string, rather than themselves.
<P><DT><CODE>progcomp</CODE><DD>If set, the programmable completion facilities
(see section <A HREF="bashref.html#SEC113">8.6 Programmable Completion</A>) are enabled.
This option is enabled by default.
<P><DT><CODE>promptvars</CODE><DD>If set, prompt strings undergo
parameter expansion, command substitution, arithmetic
expansion, and quote removal after being expanded
as described below (see section <A HREF="bashref.html#SEC84">6.9 Controlling the Prompt</A>).
This option is enabled by default.
<P><DT><CODE>restricted_shell</CODE><DD>The shell sets this option if it is started in restricted mode
(see section <A HREF="bashref.html#SEC85">6.10 The Restricted Shell</A>).
The value may not be changed.
This is not reset when the startup files are executed, allowing
the startup files to discover whether or not a shell is restricted.
<P><DT><CODE>shift_verbose</CODE><DD>If this is set, the <CODE>shift</CODE>
builtin prints an error message when the shift count exceeds the
number of positional parameters.
<P><DT><CODE>sourcepath</CODE><DD>If set, the <CODE>source</CODE> builtin uses the value of <CODE>PATH</CODE>
to find the directory containing the file supplied as an argument.
This option is enabled by default.
<P><DT><CODE>xpg_echo</CODE><DD>If set, the <CODE>echo</CODE> builtin expands backslash-escape sequences
by default.
<P></DL><P>
The return status when listing options is zero if all <VAR>optnames</VAR>
are enabled, non-zero otherwise.
When setting or unsetting options, the return status is zero unless an
<VAR>optname</VAR> is not a valid shell option.
</P><P><DT><CODE>source</CODE><DD><A NAME="IDX104"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>source <VAR>filename</VAR></pre></td></tr></table>A synonym for <CODE>.</CODE> (see section <A HREF="bashref.html#SEC57">4.1 Bourne Shell Builtins</A>).
<P><DT><CODE>type</CODE><DD><A NAME="IDX105"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>type [-afptP] [<VAR>name</VAR><small>...</small>]
</pre></td></tr></table>For each <VAR>name</VAR>, indicate how it would be interpreted if used as a
command name.
<P>
If the <SAMP>`-t'</SAMP> option is used, <CODE>type</CODE> prints a single word
which is one of <SAMP>`alias'</SAMP>, <SAMP>`function'</SAMP>, <SAMP>`builtin'</SAMP>,
<SAMP>`file'</SAMP> or <SAMP>`keyword'</SAMP>,
if <VAR>name</VAR> is an alias, shell function, shell builtin,
disk file, or shell reserved word, respectively.
If the <VAR>name</VAR> is not found, then nothing is printed, and
<CODE>type</CODE> returns a failure status.
</P><P>
If the <SAMP>`-p'</SAMP> option is used, <CODE>type</CODE> either returns the name
of the disk file that would be executed, or nothing if <SAMP>`-t'</SAMP>
would not return <SAMP>`file'</SAMP>.
</P><P>
The <SAMP>`-P'</SAMP> option forces a path search for each <VAR>name</VAR>, even if
<SAMP>`-t'</SAMP> would not return <SAMP>`file'</SAMP>.
</P><P>
If a command is hashed, <SAMP>`-p'</SAMP> and <SAMP>`-P'</SAMP> print the hashed value,
not necessarily the file that appears first in <CODE>$PATH</CODE>.
</P><P>
If the <SAMP>`-a'</SAMP> option is used, <CODE>type</CODE> returns all of the places
that contain an executable named <VAR>file</VAR>.
This includes aliases and functions, if and only if the <SAMP>`-p'</SAMP> option
is not also used.
</P><P>
If the <SAMP>`-f'</SAMP> option is used, <CODE>type</CODE> does not attempt to find
shell functions, as with the <CODE>command</CODE> builtin.
</P><P>
The return status is zero if any of the <VAR>names</VAR> are found, non-zero
if none are found.
</P><P><DT><CODE>typeset</CODE><DD><A NAME="IDX106"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>typeset [-afFrxi] [-p] [<VAR>name</VAR>[=<VAR>value</VAR>] <small>...</small>]
</pre></td></tr></table>The <CODE>typeset</CODE> command is supplied for compatibility with the Korn
shell; however, it has been deprecated in favor of the <CODE>declare</CODE>
builtin command.
<P><DT><CODE>ulimit</CODE><DD><A NAME="IDX107"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>ulimit [-acdflmnpstuvSH] [<VAR>limit</VAR>]
</pre></td></tr></table><CODE>ulimit</CODE> provides control over the resources available to processes
started by the shell, on systems that allow such control. If an
option is given, it is interpreted as follows:
<DL COMPACT><DT><CODE>-S</CODE><DD>Change and report the soft limit associated with a resource.
<P><DT><CODE>-H</CODE><DD>Change and report the hard limit associated with a resource.
<P><DT><CODE>-a</CODE><DD>All current limits are reported.
<P><DT><CODE>-c</CODE><DD>The maximum size of core files created.
<P><DT><CODE>-d</CODE><DD>The maximum size of a process's data segment.
<P><DT><CODE>-f</CODE><DD>The maximum size of files created by the shell.
<P><DT><CODE>-l</CODE><DD>The maximum size that may be locked into memory.
<P><DT><CODE>-m</CODE><DD>The maximum resident set size.
<P><DT><CODE>-n</CODE><DD>The maximum number of open file descriptors.
<P><DT><CODE>-p</CODE><DD>The pipe buffer size.
<P><DT><CODE>-s</CODE><DD>The maximum stack size.
<P><DT><CODE>-t</CODE><DD>The maximum amount of cpu time in seconds.
<P><DT><CODE>-u</CODE><DD>The maximum number of processes available to a single user.
<P><DT><CODE>-v</CODE><DD>The maximum amount of virtual memory available to the process.
<P></DL><P>
If <VAR>limit</VAR> is given, it is the new value of the specified resource;
the special <VAR>limit</VAR> values <CODE>hard</CODE>, <CODE>soft</CODE>, and
<CODE>unlimited</CODE> stand for the current hard limit, the current soft limit,
and no limit, respectively.
Otherwise, the current value of the soft limit for the specified resource
is printed, unless the <SAMP>`-H'</SAMP> option is supplied.
When setting new limits, if neither <SAMP>`-H'</SAMP> nor <SAMP>`-S'</SAMP> is supplied,
both the hard and soft limits are set.
If no option is given, then <SAMP>`-f'</SAMP> is assumed. Values are in 1024-byte
increments, except for <SAMP>`-t'</SAMP>, which is in seconds, <SAMP>`-p'</SAMP>,
which is in units of 512-byte blocks, and <SAMP>`-n'</SAMP> and <SAMP>`-u'</SAMP>, which
are unscaled values.
</P><P>
The return status is zero unless an invalid option or argument is supplied,
or an error occurs while setting a new limit.
</P><P><DT><CODE>unalias</CODE><DD><A NAME="IDX108"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>unalias [-a] [<VAR>name</VAR><small>...</small> ]
</pre></td></tr></table><P>
Remove each <VAR>name</VAR> from the list of aliases. If <SAMP>`-a'</SAMP> is
supplied, all aliases are removed.
Aliases are described in <A HREF="bashref.html#SEC80">6.6 Aliases</A>.
</P><P></DL><P><A NAME="The Set Builtin"></A><HR SIZE="6"><A NAME="SEC59"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC58">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC60">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC60">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 4.3 The Set Builtin </H2><!--docid::SEC59::--><P>
This builtin is so complicated that it deserves its own section.
</P><P><DL COMPACT><DT><CODE>set</CODE><DD><A NAME="IDX109"></A><TABLE><tr><td>&nbsp;</td><td class=example><pre>set [--abefhkmnptuvxBCHP] [-o <VAR>option</VAR>] [<VAR>argument</VAR><small>...</small>]
</pre></td></tr></table><P>
If no options or arguments are supplied, <CODE>set</CODE> displays the names
and values of all shell variables and functions, sorted according to the
current locale, in a format that may be reused as input
for setting or resetting the currently-set variables.
Read-only variables cannot be reset.
In POSIX mode, only shell variables are listed.
</P><P>
When options are supplied, they set or unset shell attributes.
Options, if specified, have the following meanings:
</P><P><DL COMPACT><DT><CODE>-a</CODE><DD>Mark variables and function which are modified or created for export
to the environment of subsequent commands.
<P><DT><CODE>-b</CODE><DD>Cause the status of terminated background jobs to be reported
immediately, rather than before printing the next primary prompt.
<P><DT><CODE>-e</CODE><DD>Exit immediately if a simple command (see section <A HREF="bashref.html#SEC16">3.2.1 Simple Commands</A>) exits
with a non-zero status, unless the command that fails is part of the
command list immediately following a <CODE>while</CODE> or <CODE>until</CODE>
keyword, part of the test in an <CODE>if</CODE> statement,
part of a <CODE>&#38;&#38;</CODE> or <CODE>||</CODE> list, or if the command's return
status is being inverted using <CODE>!</CODE>.
A trap on <CODE>ERR</CODE>, if set, is executed before the shell exits.
<P><DT><CODE>-f</CODE><DD>Disable file name generation (globbing).
<P><DT><CODE>-h</CODE><DD>Locate and remember (hash) commands as they are looked up for execution.
This option is enabled by default.
<P><DT><CODE>-k</CODE><DD>All arguments in the form of assignment statements are placed
in the environment for a command, not just those that precede
the command name.
<P><DT><CODE>-m</CODE><DD>Job control is enabled (see section <A HREF="bashref.html#SEC87">7. Job Control</A>).
<P><DT><CODE>-n</CODE><DD>Read commands but do not execute them; this may be used to check a
script for syntax errors.
This option is ignored by interactive shells.
<P><DT><CODE>-o <VAR>option-name</VAR></CODE><DD><P>
Set the option corresponding to <VAR>option-name</VAR>:
</P><P><DL COMPACT><DT><CODE>allexport</CODE><DD>Same as <CODE>-a</CODE>.
<P><DT><CODE>braceexpand</CODE><DD>Same as <CODE>-B</CODE>.
<P><DT><CODE>emacs</CODE><DD>Use an <CODE>emacs</CODE>-style line editing interface (see section <A HREF="bashref.html#SEC91">8. Command Line Editing</A>).
<P><DT><CODE>errexit</CODE><DD>Same as <CODE>-e</CODE>.
<P><DT><CODE>errtrace</CODE><DD>Same as <CODE>-E</CODE>.
<P><DT><CODE>functrace</CODE><DD>Same as <CODE>-T</CODE>.
<P><DT><CODE>hashall</CODE><DD>Same as <CODE>-h</CODE>.
<P><DT><CODE>histexpand</CODE><DD>Same as <CODE>-H</CODE>.
<P><DT><CODE>history</CODE><DD>Enable command history, as described in <A HREF="bashref.html#SEC116">9.1 Bash History Facilities</A>.
This option is on by default in interactive shells.
<P><DT><CODE>ignoreeof</CODE><DD>An interactive shell will not exit upon reading EOF.
<P><DT><CODE>keyword</CODE><DD>Same as <CODE>-k</CODE>.
<P><DT><CODE>monitor</CODE><DD>Same as <CODE>-m</CODE>.
<P><DT><CODE>noclobber</CODE><DD>Same as <CODE>-C</CODE>.
<P><DT><CODE>noexec</CODE><DD>Same as <CODE>-n</CODE>.
<P><DT><CODE>noglob</CODE><DD>Same as <CODE>-f</CODE>.
<P><DT><CODE>nolog</CODE><DD>Currently ignored.
<P><DT><CODE>notify</CODE><DD>Same as <CODE>-b</CODE>.
<P><DT><CODE>nounset</CODE><DD>Same as <CODE>-u</CODE>.
<P><DT><CODE>onecmd</CODE><DD>Same as <CODE>-t</CODE>.
<P><DT><CODE>physical</CODE><DD>Same as <CODE>-P</CODE>.
<P><DT><CODE>pipefail</CODE><DD>If set, the return value of a pipeline is the value of the last
(rightmost) command to exit with a non-zero status, or zero if all
commands in the pipeline exit successfully.
This option is disabled by default.
<P><DT><CODE>posix</CODE><DD>Change the behavior of Bash where the default operation differs
from the POSIX 1003.2 standard to match the standard
(see section <A HREF="bashref.html#SEC86">6.11 Bash POSIX Mode</A>).
This is intended to make Bash behave as a strict superset of that
standard.
<P><DT><CODE>privileged</CODE><DD>Same as <CODE>-p</CODE>.
<P><DT><CODE>verbose</CODE><DD>Same as <CODE>-v</CODE>.
<P><DT><CODE>vi</CODE><DD>Use a <CODE>vi</CODE>-style line editing interface.
<P><DT><CODE>xtrace</CODE><DD>Same as <CODE>-x</CODE>.
</DL><P><DT><CODE>-p</CODE><DD>Turn on privileged mode.
In this mode, the <CODE>$BASH_ENV</CODE> and <CODE>$ENV</CODE> files are not
processed, shell functions are not inherited from the environment,
and the <CODE>SHELLOPTS</CODE> variable, if it appears in the environment,
is ignored.
If the shell is started with the effective user (group) id not equal to the
real user (group) id, and the <CODE>-p</CODE> option is not supplied, these actions
are taken and the effective user id is set to the real user id.
If the <CODE>-p</CODE> option is supplied at startup, the effective user id is
not reset.
Turning this option off causes the effective user
and group ids to be set to the real user and group ids.
<P><DT><CODE>-t</CODE><DD>Exit after reading and executing one command.
<P><DT><CODE>-u</CODE><DD>Treat unset variables as an error when performing parameter expansion.
An error message will be written to the standard error, and a non-interactive
shell will exit.
<P><DT><CODE>-v</CODE><DD>Print shell input lines as they are read.
<P><DT><CODE>-x</CODE><DD>Print a trace of simple commands, \fBfor\fP commands, \fBcase\fP
commands, \fBselect\fP commands, and arithmetic \fBfor\fP commands
and their arguments or associated word lists after they are
expanded and before they are executed. The value of the <CODE>PS4</CODE>
variable is expanded and the resultant value is printed before
the command and its expanded arguments.
<P><DT><CODE>-B</CODE><DD>The shell will perform brace expansion (see section <A HREF="bashref.html#SEC28">3.5.1 Brace Expansion</A>).
This option is on by default.
<P><DT><CODE>-C</CODE><DD>Prevent output redirection using <SAMP>`&#62;'</SAMP>, <SAMP>`&#62;&#38;'</SAMP>, and <SAMP>`&#60;&#62;'</SAMP>
from overwriting existing files.
<P><DT><CODE>-E</CODE><DD>If set, any trap on <CODE>ERR</CODE> is inherited by shell functions, command
substitutions, and commands executed in a subshell environment.
The <CODE>ERR</CODE> trap is normally not inherited in such cases.
<P><DT><CODE>-H</CODE><DD>Enable <SAMP>`!'</SAMP> style history substitution (see section <A HREF="bashref.html#SEC118">9.3 History Expansion</A>).
This option is on by default for interactive shells.
<P><DT><CODE>-P</CODE><DD>If set, do not follow symbolic links when performing commands such as
<CODE>cd</CODE> which change the current directory. The physical directory
is used instead. By default, Bash follows
the logical chain of directories when performing commands
which change the current directory.
<P>
For example, if <TT>`/usr/sys'</TT> is a symbolic link to <TT>`/usr/local/sys'</TT>
then:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>$ cd /usr/sys; echo $PWD
/usr/sys
$ cd ..; pwd
/usr
</pre></td></tr></table></P><P>
If <CODE>set -P</CODE> is on, then:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>$ cd /usr/sys; echo $PWD
/usr/local/sys
$ cd ..; pwd
/usr/local
</pre></td></tr></table></P><P><DT><CODE>-T</CODE><DD>If set, any trap on <CODE>DEBUG</CODE> and <CODE>RETURN</CODE> are inherited by
shell functions, command substitutions, and commands executed
in a subshell environment.
The <CODE>DEBUG</CODE> and <CODE>RETURN</CODE> traps are normally not inherited
in such cases.
<P><DT><CODE>--</CODE><DD>If no arguments follow this option, then the positional parameters are
unset. Otherwise, the positional parameters are set to the
<VAR>arguments</VAR>, even if some of them begin with a <SAMP>`-'</SAMP>.
<P><DT><CODE>-</CODE><DD>Signal the end of options, cause all remaining <VAR>arguments</VAR>
to be assigned to the positional parameters. The <SAMP>`-x'</SAMP>
and <SAMP>`-v'</SAMP> options are turned off.
If there are no arguments, the positional parameters remain unchanged.
</DL><P>
Using <SAMP>`+'</SAMP> rather than <SAMP>`-'</SAMP> causes these options to be
turned off. The options can also be used upon invocation of the
shell. The current set of options may be found in <CODE>$-</CODE>.
</P><P>
The remaining N <VAR>arguments</VAR> are positional parameters and are
assigned, in order, to <CODE>$1</CODE>, <CODE>$2</CODE>, <small>...</small><CODE>$N</CODE>.
The special parameter <CODE>#</CODE> is set to N.
</P><P>
The return status is always zero unless an invalid option is supplied.
</DL><P><A NAME="Special Builtins"></A><HR SIZE="6"><A NAME="SEC60"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC59">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC56"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 4.4 Special Builtins </H2><!--docid::SEC60::--><P>
For historical reasons, the POSIX 1003.2 standard has classified
several builtin commands as <EM>special</EM>.
When Bash is executing in POSIX mode, the special builtins
differ from other builtin commands in three respects:
</P><P><OL><LI>
Special builtins are found before shell functions during command lookup.
<P><LI>
If a special builtin returns an error status, a non-interactive shell exits.
<P><LI>
Assignment statements preceding the command stay in effect in the shell
environment after the command completes.
</OL><P>
When Bash is not executing in POSIX mode, these builtins behave no
differently than the rest of the Bash builtin commands.
The Bash POSIX mode is described in <A HREF="bashref.html#SEC86">6.11 Bash POSIX Mode</A>.
</P><P>
These are the POSIX special builtins:
<TABLE><tr><td>&nbsp;</td><td class=example><pre>break : . continue eval exec exit export readonly return set
shift trap unset
</pre></td></tr></table></P><P><A NAME="Shell Variables"></A><HR SIZE="6"><A NAME="SEC61"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC60">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC62">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC64">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC64">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H1> 5. Shell Variables </H1><!--docid::SEC61::--><P><BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC62">5.1 Bourne Shell Variables</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">Variables which Bash uses in the same way
as the Bourne Shell.</TD></TR><TR><TD ALIGN="left" VALIGN="TOP"><A HREF="bashref.html#SEC63">5.2 Bash Variables</A></TD><TD>&nbsp;&nbsp;</TD><TD ALIGN="left" VALIGN="TOP">List of variables that exist in Bash.</TD></TR></TABLE></BLOCKQUOTE><P>
This chapter describes the shell variables that Bash uses.
Bash automatically assigns default values to a number of variables.
</P><P><A NAME="Bourne Shell Variables"></A><HR SIZE="6"><A NAME="SEC62"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC63">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC64">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 5.1 Bourne Shell Variables </H2><!--docid::SEC62::--><P>
Bash uses certain shell variables in the same way as the Bourne shell.
In some cases, Bash assigns a default value to the variable.
</P><P><DL COMPACT><A NAME="IDX110"></A><DT><CODE>CDPATH</CODE><DD><A NAME="IDX111"></A>
A colon-separated list of directories used as a search path for
the <CODE>cd</CODE> builtin command.
<P><A NAME="IDX112"></A><DT><CODE>HOME</CODE><DD><A NAME="IDX113"></A>
The current user's home directory; the default for the <CODE>cd</CODE> builtin
command.
The value of this variable is also used by tilde expansion
(see section <A HREF="bashref.html#SEC29">3.5.2 Tilde Expansion</A>).
<P><A NAME="IDX114"></A><DT><CODE>IFS</CODE><DD><A NAME="IDX115"></A>
A list of characters that separate fields; used when the shell splits
words as part of expansion.
<P><A NAME="IDX116"></A><DT><CODE>MAIL</CODE><DD><A NAME="IDX117"></A>
If this parameter is set to a filename and the <CODE>MAILPATH</CODE> variable
is not set, Bash informs the user of the arrival of mail in
the specified file.
<P><A NAME="IDX118"></A><DT><CODE>MAILPATH</CODE><DD><A NAME="IDX119"></A>
A colon-separated list of filenames which the shell periodically checks
for new mail.
Each list entry can specify the message that is printed when new mail
arrives in the mail file by separating the file name from the message with
a <SAMP>`?'</SAMP>.
When used in the text of the message, <CODE>$_</CODE> expands to the name of
the current mail file.
<P><A NAME="IDX120"></A><DT><CODE>OPTARG</CODE><DD><A NAME="IDX121"></A>
The value of the last option argument processed by the <CODE>getopts</CODE> builtin.
<P><A NAME="IDX122"></A><DT><CODE>OPTIND</CODE><DD><A NAME="IDX123"></A>
The index of the last option argument processed by the <CODE>getopts</CODE> builtin.
<P><A NAME="IDX124"></A><DT><CODE>PATH</CODE><DD><A NAME="IDX125"></A>
A colon-separated list of directories in which the shell looks for
commands.
A zero-length (null) directory name in the value of <CODE>PATH</CODE> indicates the
current directory.
A null directory name may appear as two adjacent colons, or as an initial
or trailing colon.
<P><A NAME="IDX126"></A><DT><CODE>PS1</CODE><DD><A NAME="IDX127"></A>
The primary prompt string. The default value is <SAMP>`\s-\v\$ '</SAMP>.
See section <A HREF="bashref.html#SEC84">6.9 Controlling the Prompt</A>, for the complete list of escape
sequences that are expanded before <CODE>PS1</CODE> is displayed.
<P><A NAME="IDX128"></A><DT><CODE>PS2</CODE><DD><A NAME="IDX129"></A>
The secondary prompt string. The default value is <SAMP>`&#62; '</SAMP>.
<P></DL><P><A NAME="Bash Variables"></A><HR SIZE="6"><A NAME="SEC63"></A><TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0><TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC62">&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC64">&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61">&lt;&lt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC61"> Up </A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC64">&gt;&gt;</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">&nbsp;<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Top">Top</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_Contents">Contents</A>]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="bashref.html#SEC_About"> ? </A>]</TD></TR></TABLE><H2> 5.2 Bash Variables </H2><!--docid::SEC63::--><P>
These variables are set or used by Bash, but other shells
do not normally treat them specially.
</P><P>
A few variables used by Bash are described in different chapters:
variables for controlling the job control facilities
(see section <A HREF="bashref.html#SEC90">7.3 Job Control Variables</A>).
</P><P><DL COMPACT><A NAME="IDX130"></A><DT><CODE>BASH</CODE><DD><A NAME="IDX131"></A>
The full pathname used to execute the current instance of Bash.
<P><A NAME="IDX132"></A><DT><CODE>BASH_ARGC</CODE><DD><A NAME="IDX133"></A>
An array variable whose values are the number of parameters in each
frame of the current bash execution call stack. The number of
parameters to the current subroutine (shell function or script executed
with <CODE>.</CODE> or <CODE>source</CODE>) is at the top of the stack. When a
subroutine is executed, the number of parameters passed is pushed onto
<CODE>BASH_ARGC</CODE>.
The shell sets <CODE>BASH_ARGC</CODE> only when in extended debugging mode
(see <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>
for a description of the <CODE>extdebug</CODE> option to the <CODE>shopt</CODE>
builtin).
<P><A NAME="IDX134"></A><DT><CODE>BASH_ARGV</CODE><DD><A NAME="IDX135"></A>
An array variable containing all of the parameters in the current bash
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 <CODE>BASH_ARGV</CODE>.
The shell sets <CODE>BASH_ARGV</CODE> only when in extended debugging mode
(see <A HREF="bashref.html#SEC58">4.2 Bash Builtin Commands</A>
for a description of the <CODE>extdebug</CODE> option to the <CODE>shopt</CODE>
builtin).
<P><A NAME="IDX136"></A><DT><CODE>BASH_COMMAND</CODE><DD><A NAME="IDX137"></A>
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.
<P><A NAME="IDX138"></A><DT><CODE>BASH_ENV</CODE><DD><A NAME="IDX139"></A>
If this variable is set when Bash is invoked to execute a shell
script, its value is expanded and used as the name of a startup file
to read before executing the script. See section <A HREF="bashref.html#SEC66">6.2 Bash Startup Files</A>.
<P><A NAME="IDX140"></A><DT><CODE>BASH_EXECUTION_STRING</CODE><DD><A NAME="IDX141"></A>
The command argument to the <SAMP>`-c'</SAMP> invocation option.
<P><A NAME="IDX142"></A><DT><CODE>BASH_LINENO</CODE><DD><A NAME="IDX143"></A>
An array variable whose members are the line numbers in source files
corresponding to each member of <VAR>FUNCNAME</VAR>.
<CODE>${BASH_LINENO[$i]}</CODE> is the line number in the source file where
<CODE>${FUNCNAME[$i]}</CODE> was called.
The corresponding source file name is <CODE>${BASH_SOURCE[$i]}</CODE>.
Use <CODE>LINENO</CODE> to obtain the current line number.
<P><A NAME="IDX144"></A><DT><CODE>BASH_REMATCH</CODE><DD><A NAME="IDX145"></A>
An array variable whose members are assigned by the <SAMP>`=~'</SAMP> binary
operator to the <CODE>[[</CODE> conditional command
(see section <A HREF="bashref.html#SEC21">3.2.4.2 Conditional Constructs</A>).
The element with index 0 is the portion of the string
matching the entire regular expression.
The element with index <VAR>n</VAR> is the portion of the
string matching the <VAR>n</VAR>th parenthesized subexpression.
This variable is read-only.
<P><A NAME="IDX146"></A><DT><CODE>BASH_SOURCE</CODE><DD><A NAME="IDX147"></A>
An array variable whose members are the source filenames corresponding
to the elements in the <CODE>FUNCNAME</CODE> array variable.
<P><A NAME="IDX148"></A><DT><CODE>BASH_SUBSHELL</CODE><DD><A NAME="IDX149"></A>
Incremented by one each time a subshell or subshell environment is spawned.
The initial value is 0.
<P><A NAME="IDX150"></A><DT><CODE>BASH_VERSINFO</CODE><DD><A NAME="IDX151"></A>
A readonly array variable (see section <A HREF="bashref.html#SEC81">6.7 Arrays</A>)
whose members hold version information for this instance of Bash.
The values assigned to the array members are as