04178bc9f8015ee8dc91617bee807794417b0659
[platform/upstream/bash.git] / doc / bashref.texi
1 \input texinfo.tex @c -*- texinfo -*-
2 @c %**start of header
3 @setfilename bashref.info
4 @settitle Bash Reference Manual
5 @c %**end of header
6
7 @setchapternewpage odd
8
9 @include version.texi
10
11 @copying
12 This text is a brief description of the features that are present in
13 the Bash shell (version @value{VERSION}, @value{UPDATED}).
14
15 This is Edition @value{EDITION}, last updated @value{UPDATED},
16 of @cite{The GNU Bash Reference Manual},
17 for @code{Bash}, Version @value{VERSION}.
18
19 Copyright @copyright{} 1988--2009 Free Software Foundation, Inc.
20
21 Permission is granted to make and distribute verbatim copies of
22 this manual provided the copyright notice and this permission notice
23 are preserved on all copies.
24
25 @quotation
26 Permission is granted to copy, distribute and/or modify this document
27 under the terms of the GNU Free Documentation License, Version 1.2 or
28 any later version published by the Free Software Foundation; with no
29 Invariant Sections, with the Front-Cover texts being ``A GNU Manual'',
30 and with the Back-Cover Texts as in (a) below.  A copy of the license is
31 included in the section entitled ``GNU Free Documentation License''.
32
33 (a) The FSF's Back-Cover Text is: You are free to copy and modify
34 this GNU manual.  Buying copies from GNU Press supports the FSF in
35 developing GNU and promoting software freedom.''
36
37 @end quotation
38 @end copying
39
40 @defcodeindex bt
41 @defcodeindex rw
42 @set BashFeatures
43
44 @dircategory Basics
45 @direntry
46 * Bash: (bash).                     The GNU Bourne-Again SHell.
47 @end direntry
48
49 @finalout
50
51 @titlepage
52 @title Bash Reference Manual
53 @subtitle Reference Documentation for Bash
54 @subtitle Edition @value{EDITION}, for @code{Bash} Version @value{VERSION}.
55 @subtitle @value{UPDATED-MONTH}
56 @author Chet Ramey, Case Western Reserve University
57 @author Brian Fox, Free Software Foundation
58
59 @page
60 @vskip 0pt plus 1filll
61 @insertcopying
62
63 @sp 1
64 Published by the Free Software Foundation @*
65 59 Temple Place, Suite 330, @*
66 Boston, MA 02111-1307 @*
67 USA @*
68
69 @end titlepage
70
71 @contents
72
73 @ifnottex
74 @node Top, Introduction, (dir), (dir)
75 @top Bash Features
76
77 This text is a brief description of the features that are present in
78 the Bash shell (version @value{VERSION}, @value{UPDATED}).
79
80 This is Edition @value{EDITION}, last updated @value{UPDATED},
81 of @cite{The GNU Bash Reference Manual},
82 for @code{Bash}, Version @value{VERSION}.
83
84 Bash contains features that appear in other popular shells, and some
85 features that only appear in Bash.  Some of the shells that Bash has
86 borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell
87 (@file{ksh}), and the C-shell (@file{csh} and its successor,
88 @file{tcsh}). The following menu breaks the features up into
89 categories based upon which one of these other shells inspired the
90 feature.
91
92 This manual is meant as a brief introduction to features found in
93 Bash.  The Bash manual page should be used as the definitive
94 reference on shell behavior.
95
96 @menu
97 * Introduction::                An introduction to the shell.
98 * Definitions::                 Some definitions used in the rest of this
99                                 manual.
100 * Basic Shell Features::        The shell "building blocks".
101 * Shell Builtin Commands::      Commands that are a part of the shell.
102 * Shell Variables::             Variables used or set by Bash.
103 * Bash Features::               Features found only in Bash.
104 * Job Control::                 What job control is and how Bash allows you
105                                 to use it.
106 * Command Line Editing::        Chapter describing the command line
107                                 editing features.
108 * Using History Interactively:: Command History Expansion
109 * Installing Bash::             How to build and install Bash on your system.
110 * Reporting Bugs::              How to report bugs in Bash.
111 * Major Differences From The Bourne Shell::     A terse list of the differences
112                                                 between Bash and historical
113                                                 versions of /bin/sh.
114 * GNU Free Documentation License::      Copying and sharing this documentation.
115 * Indexes::                     Various indexes for this manual.
116 @end menu
117 @end ifnottex
118
119 @node Introduction
120 @chapter Introduction
121 @menu
122 * What is Bash?::               A short description of Bash.
123 * What is a shell?::            A brief introduction to shells.
124 @end menu
125
126 @node What is Bash?
127 @section What is Bash?
128
129 Bash is the shell, or command language interpreter,
130 for the @sc{gnu} operating system.
131 The name is an acronym for the @samp{Bourne-Again SHell},
132 a pun on Stephen Bourne, the author of the direct ancestor of
133 the current Unix shell @code{sh}, 
134 which appeared in the Seventh Edition Bell Labs Research version
135 of Unix.
136
137 Bash is largely compatible with @code{sh} and incorporates useful
138 features from the Korn shell @code{ksh} and the C shell @code{csh}.
139 It is intended to be a conformant implementation of the @sc{ieee}
140 @sc{posix} Shell and Tools portion of the @sc{ieee} @sc{posix}
141 specification (@sc{ieee} Standard 1003.1).
142 It offers functional improvements over @code{sh} for both interactive and
143 programming use.
144
145 While the @sc{gnu} operating system provides other shells, including
146 a version of @code{csh}, Bash is the default shell.
147 Like other @sc{gnu} software, Bash is quite portable.  It currently runs
148 on nearly every version of Unix and a few other operating systems @minus{}
149 independently-supported ports exist for @sc{ms-dos}, @sc{os/2},
150 and Windows platforms.
151
152 @node What is a shell?
153 @section What is a shell?
154
155 At its base, a shell is simply a macro processor that executes
156 commands.  The term macro processor means functionality where text
157 and symbols are expanded to create larger expressions.
158
159 A Unix shell is both a command interpreter and a programming
160 language.  As a command interpreter, the shell provides the user
161 interface to the rich set of @sc{gnu} utilities.  The programming
162 language features allow these utilities to be combined.
163 Files containing commands can be created, and become
164 commands themselves.  These new commands have the same status as
165 system commands in directories such as @file{/bin}, allowing users
166 or groups to establish custom environments to automate their common
167 tasks.
168
169 Shells may be used interactively or non-interactively.  In
170 interactive mode, they accept input typed from the keyboard.
171 When executing non-interactively, shells execute commands read
172 from a file.
173
174 A shell allows execution of @sc{gnu} commands, both synchronously and
175 asynchronously.
176 The shell waits for synchronous commands to complete before accepting
177 more input; asynchronous commands continue to execute in parallel
178 with the shell while it reads and executes additional commands.
179 The @dfn{redirection} constructs permit
180 fine-grained control of the input and output of those commands.
181 Moreover, the shell allows control over the contents of commands'
182 environments.
183
184 Shells also provide a small set of built-in
185 commands (@dfn{builtins}) implementing functionality impossible
186 or inconvenient to obtain via separate utilities.
187 For example, @code{cd}, @code{break}, @code{continue}, and
188 @code{exec}) cannot be implemented outside of the shell because
189 they directly manipulate the shell itself.
190 The @code{history}, @code{getopts}, @code{kill}, or @code{pwd}
191 builtins, among others, could be implemented in separate utilities,
192 but they are more convenient to use as builtin commands.
193 All of the shell builtins are described in
194 subsequent sections.
195
196 While executing commands is essential, most of the power (and
197 complexity) of shells is due to their embedded programming
198 languages.  Like any high-level language, the shell provides
199 variables, flow control constructs, quoting, and functions. 
200
201 Shells offer features geared specifically for
202 interactive use rather than to augment the programming language. 
203 These interactive features include job control, command line
204 editing, command history and aliases.  Each of these features is
205 described in this manual.
206
207 @node Definitions
208 @chapter Definitions
209 These definitions are used throughout the remainder of this manual.
210
211 @table @code
212
213 @item POSIX
214 @cindex POSIX
215 A family of open system standards based on Unix.  Bash
216 is primarily concerned with the Shell and Utilities portion of the
217 @sc{posix} 1003.1 standard. 
218
219 @item blank
220 A space or tab character.
221
222 @item builtin
223 @cindex builtin
224 A command that is implemented internally by the shell itself, rather
225 than by an executable program somewhere in the file system.
226
227 @item control operator
228 @cindex control operator
229 A @code{token} that performs a control function.  It is a @code{newline}
230 or one of the following:
231 @samp{||}, @samp{&&}, @samp{&}, @samp{;}, @samp{;;},
232 @samp{|}, @samp{|&}, @samp{(}, or @samp{)}.
233
234 @item exit status
235 @cindex exit status
236 The value returned by a command to its caller.  The value is restricted
237 to eight bits, so the maximum value is 255.
238
239 @item field
240 @cindex field
241 A unit of text that is the result of one of the shell expansions.  After
242 expansion, when executing a command, the resulting fields are used as
243 the command name and arguments.
244
245 @item filename
246 @cindex filename
247 A string of characters used to identify a file.
248
249 @item job
250 @cindex job
251 A set of processes comprising a pipeline, and any processes descended
252 from it, that are all in the same process group.
253
254 @item job control
255 @cindex job control
256 A mechanism by which users can selectively stop (suspend) and restart
257 (resume) execution of processes.
258
259 @item metacharacter
260 @cindex metacharacter
261 A character that, when unquoted, separates words.  A metacharacter is
262 a @code{blank} or one of the following characters:
263 @samp{|}, @samp{&}, @samp{;}, @samp{(}, @samp{)}, @samp{<}, or
264 @samp{>}.
265
266 @item name
267 @cindex name
268 @cindex identifier
269 A @code{word} consisting solely of letters, numbers, and underscores,
270 and beginning with a letter or underscore.  @code{Name}s are used as
271 shell variable and function names.
272 Also referred to as an @code{identifier}.
273
274 @item operator
275 @cindex operator, shell
276 A @code{control operator} or a @code{redirection operator}.
277 @xref{Redirections}, for a list of redirection operators.
278 Operators contain at least one unquoted @code{metacharacter}.
279
280 @item process group
281 @cindex process group
282 A collection of related processes each having the same process
283 group @sc{id}.
284
285 @item process group ID
286 @cindex process group ID
287 A unique identifier that represents a @code{process group}
288 during its lifetime.
289
290 @item reserved word
291 @cindex reserved word
292 A @code{word} that has a special meaning to the shell.  Most reserved
293 words introduce shell flow control constructs, such as @code{for} and
294 @code{while}.
295
296 @item return status
297 @cindex return status
298 A synonym for @code{exit status}.
299
300 @item signal
301 @cindex signal
302 A mechanism by which a process may be notified by the kernel
303 of an event occurring in the system.
304
305 @item special builtin
306 @cindex special builtin
307 A shell builtin command that has been classified as special by the
308 @sc{posix} standard.
309
310 @item token
311 @cindex token
312 A sequence of characters considered a single unit by the shell.
313 It is either a @code{word} or an @code{operator}.
314
315 @item word
316 @cindex word
317 A sequence of characters treated as a unit by the shell.
318 Words may not include unquoted @code{metacharacters}.
319 @end table
320
321 @node Basic Shell Features
322 @chapter Basic Shell Features
323 @cindex Bourne shell
324
325 Bash is an acronym for @samp{Bourne-Again SHell}.
326 The Bourne shell is
327 the traditional Unix shell originally written by Stephen Bourne.
328 All of the Bourne shell builtin commands are available in Bash,
329 The rules for evaluation and quoting are taken from the @sc{posix}
330 specification for the `standard' Unix shell.
331
332 This chapter briefly summarizes the shell's `building blocks':
333 commands, control structures, shell functions, shell @i{parameters},
334 shell expansions,
335 @i{redirections}, which are a way to direct input and output from
336 and to named files, and how the shell executes commands.
337
338 @menu
339 * Shell Syntax::                What your input means to the shell.
340 * Shell Commands::              The types of commands you can use.
341 * Shell Functions::             Grouping commands by name.
342 * Shell Parameters::            How the shell stores values.
343 * Shell Expansions::            How Bash expands parameters and the various
344                                 expansions available.
345 * Redirections::                A way to control where input and output go.
346 * Executing Commands::          What happens when you run a command.
347 * Shell Scripts::               Executing files of shell commands.
348 @end menu
349
350 @node Shell Syntax
351 @section Shell Syntax
352 @menu
353 * Shell Operation::     The basic operation of the shell.
354 * Quoting::             How to remove the special meaning from characters.
355 * Comments::            How to specify comments.
356 @end menu
357
358 When the shell reads input, it proceeds through a
359 sequence of operations.  If the input indicates the beginning of a
360 comment, the shell ignores the comment symbol (@samp{#}), and the rest
361 of that line.
362                                 
363 Otherwise, roughly speaking,  the shell reads its input and
364 divides the input into words and operators, employing the quoting rules
365 to select which meanings to assign various words and characters.
366
367 The shell then parses these tokens into commands and other constructs,
368 removes the special meaning of certain words or characters, expands
369 others, redirects input and output as needed, executes the specified
370 command, waits for the command's exit status, and makes that exit status
371 available for further inspection or processing.
372
373 @node Shell Operation
374 @subsection Shell Operation
375
376 The following is a brief description of the shell's operation when it
377 reads and executes a command.  Basically, the shell does the
378 following:
379
380 @enumerate
381 @item
382 Reads its input from a file (@pxref{Shell Scripts}), from a string
383 supplied as an argument to the @option{-c} invocation option
384 (@pxref{Invoking Bash}), or from the user's terminal.
385
386 @item
387 Breaks the input into words and operators, obeying the quoting rules
388 described in @ref{Quoting}.  These tokens are separated by
389 @code{metacharacters}.  Alias expansion is performed by this step
390 (@pxref{Aliases}).
391
392 @item
393 Parses the tokens into simple and compound commands
394 (@pxref{Shell Commands}).
395
396 @item
397 Performs the various shell expansions (@pxref{Shell Expansions}), breaking
398 the expanded tokens into lists of filenames (@pxref{Filename Expansion})
399 and commands and arguments.
400
401 @item
402 Performs any necessary redirections (@pxref{Redirections}) and removes
403 the redirection operators and their operands from the argument list.
404
405 @item
406 Executes the command (@pxref{Executing Commands}).
407
408 @item
409 Optionally waits for the command to complete and collects its exit
410 status (@pxref{Exit Status}).
411
412 @end enumerate
413
414 @node Quoting
415 @subsection Quoting
416 @cindex quoting
417 @menu
418 * Escape Character::    How to remove the special meaning from a single
419                         character.
420 * Single Quotes::       How to inhibit all interpretation of a sequence
421                         of characters.
422 * Double Quotes::       How to suppress most of the interpretation of a
423                         sequence of characters.
424 * ANSI-C Quoting::      How to expand ANSI-C sequences in quoted strings.
425 * Locale Translation::  How to translate strings into different languages.
426 @end menu
427
428 Quoting is used to remove the special meaning of certain
429 characters or words to the shell.  Quoting can be used to
430 disable special treatment for special characters, to prevent
431 reserved words from being recognized as such, and to prevent
432 parameter expansion.
433
434 Each of the shell metacharacters (@pxref{Definitions})
435 has special meaning to the shell and must be quoted if it is to
436 represent itself.
437 When the command history expansion facilities are being used
438 (@pxref{History Interaction}), the
439 @var{history expansion} character, usually @samp{!}, must be quoted
440 to prevent history expansion.  @xref{Bash History Facilities}, for
441 more details concerning history expansion.
442
443 There are three quoting mechanisms: the
444 @var{escape character}, single quotes, and double quotes.
445
446 @node Escape Character
447 @subsubsection Escape Character
448 A non-quoted backslash @samp{\} is the Bash escape character.
449 It preserves the literal value of the next character that follows,
450 with the exception of @code{newline}.  If a @code{\newline} pair
451 appears, and the backslash itself is not quoted, the @code{\newline}
452 is treated as a line continuation (that is, it is removed from
453 the input stream and effectively ignored).
454
455 @node Single Quotes
456 @subsubsection Single Quotes
457
458 Enclosing characters in single quotes (@samp{'}) preserves the literal value
459 of each character within the quotes.  A single quote may not occur
460 between single quotes, even when preceded by a backslash.
461
462 @node Double Quotes
463 @subsubsection Double Quotes
464
465 Enclosing characters in double quotes (@samp{"}) preserves the literal value
466 of all characters within the quotes, with the exception of
467 @samp{$}, @samp{`}, @samp{\},
468 and, when history expansion is enabled, @samp{!}.
469 The characters @samp{$} and @samp{`}
470 retain their special meaning within double quotes (@pxref{Shell Expansions}).
471 The backslash retains its special meaning only when followed by one of
472 the following characters:
473 @samp{$}, @samp{`}, @samp{"}, @samp{\}, or @code{newline}.
474 Within double quotes, backslashes that are followed by one of these
475 characters are removed.  Backslashes preceding characters without a
476 special meaning are left unmodified.
477 A double quote may be quoted within double quotes by preceding it with
478 a backslash.
479 If enabled, history expansion will be performed unless an @samp{!}
480 appearing in double quotes is escaped using a backslash.
481 The backslash preceding the @samp{!} is not removed.
482
483 The special parameters @samp{*} and @samp{@@} have special meaning
484 when in double quotes (@pxref{Shell Parameter Expansion}).
485
486 @node ANSI-C Quoting
487 @subsubsection ANSI-C Quoting
488 @cindex quoting, ANSI
489
490 Words of the form @code{$'@var{string}'} are treated specially.  The
491 word expands to @var{string}, with backslash-escaped characters replaced
492 as specified by the ANSI C standard.  Backslash escape sequences, if
493 present, are decoded as follows:
494
495 @table @code
496 @item \a
497 alert (bell)
498 @item \b
499 backspace
500 @item \e
501 an escape character (not ANSI C)
502 @item \f
503 form feed
504 @item \n
505 newline
506 @item \r
507 carriage return
508 @item \t
509 horizontal tab
510 @item \v
511 vertical tab
512 @item \\
513 backslash
514 @item \'
515 single quote
516 @item \@var{nnn}
517 the eight-bit character whose value is the octal value @var{nnn}
518 (one to three digits)
519 @item \x@var{HH}
520 the eight-bit character whose value is the hexadecimal value @var{HH}
521 (one or two hex digits)
522 @item \c@var{x}
523 a control-@var{x} character
524 @end table
525
526 @noindent
527 The expanded result is single-quoted, as if the dollar sign had not
528 been present.
529
530 @node Locale Translation
531 @subsubsection Locale-Specific Translation
532 @cindex localization
533 @cindex internationalization
534 @cindex native languages
535 @cindex translation, native languages
536
537 A double-quoted string preceded by a dollar sign (@samp{$}) will cause
538 the string to be translated according to the current locale.
539 If the current locale is @code{C} or @code{POSIX}, the dollar sign
540 is ignored.
541 If the string is translated and replaced, the replacement is
542 double-quoted.
543
544 @vindex LC_MESSAGES
545 @vindex TEXTDOMAIN
546 @vindex TEXTDOMAINDIR
547 Some systems use the message catalog selected by the @env{LC_MESSAGES}
548 shell variable.  Others create the name of the message catalog from the
549 value of the @env{TEXTDOMAIN} shell variable, possibly adding a
550 suffix of @samp{.mo}.  If you use the @env{TEXTDOMAIN} variable, you
551 may need to set the @env{TEXTDOMAINDIR} variable to the location of
552 the message catalog files.  Still others use both variables in this
553 fashion:
554 @env{TEXTDOMAINDIR}/@env{LC_MESSAGES}/LC_MESSAGES/@env{TEXTDOMAIN}.mo.
555
556 @node Comments
557 @subsection Comments
558 @cindex comments, shell
559
560 In a non-interactive shell, or an interactive shell in which the
561 @code{interactive_comments} option to the @code{shopt}
562 builtin is enabled (@pxref{The Shopt Builtin}),
563 a word beginning with @samp{#}
564 causes that word and all remaining characters on that line to
565 be ignored.  An interactive shell without the @code{interactive_comments}
566 option enabled does not allow comments.  The @code{interactive_comments}
567 option is on by default in interactive shells.
568 @xref{Interactive Shells}, for a description of what makes
569 a shell interactive.
570
571 @node Shell Commands
572 @section Shell Commands
573 @cindex commands, shell
574
575 A simple shell command such as @code{echo a b c} consists of the command
576 itself followed by arguments, separated by spaces.
577
578 More complex shell commands are composed of simple commands arranged together
579 in a variety of ways: in a pipeline in which the output of one command
580 becomes the input of a second, in a loop or conditional construct, or in
581 some other grouping.
582
583 @menu
584 * Simple Commands::             The most common type of command.
585 * Pipelines::                   Connecting the input and output of several
586                                 commands.
587 * Lists::                       How to execute commands sequentially.
588 * Compound Commands::           Shell commands for control flow.
589 * Coprocesses::                 Two-way communication between commands.
590 @end menu
591
592 @node Simple Commands
593 @subsection Simple Commands
594 @cindex commands, simple
595
596 A simple command is the kind of command encountered most often.
597 It's just a sequence of words separated by @code{blank}s, terminated
598 by one of the shell's control operators (@pxref{Definitions}).  The
599 first word generally specifies a command to be executed, with the
600 rest of the words being that command's arguments.
601
602 The return status (@pxref{Exit Status}) of a simple command is
603 its exit status as provided
604 by the @sc{posix} 1003.1 @code{waitpid} function, or 128+@var{n} if
605 the command was terminated by signal @var{n}.
606
607 @node Pipelines
608 @subsection Pipelines
609 @cindex pipeline
610 @cindex commands, pipelines
611
612 A @code{pipeline} is a sequence of simple commands separated by one of
613 the control operators @samp{|} or @samp{|&}.
614
615 @rwindex time
616 @rwindex !
617 @cindex command timing
618 The format for a pipeline is
619 @example
620 [@code{time} [@code{-p}]] [@code{!}] @var{command1} [ [@code{|} or @code{|&}] @var{command2} @dots{}]
621 @end example
622
623 @noindent
624 The output of each command in the pipeline is connected via a pipe
625 to the input of the next command.
626 That is, each command reads the previous command's output.  This
627 connection is performed before any redirections specified by the
628 command.
629
630 If @samp{|&} is used, the standard error of @var{command1} is connected to
631 @var{command2}'s standard input through the pipe; it is shorthand for
632 @code{2>&1 |}.  This implicit redirection of the standard error is
633 performed after any redirections specified by the command.
634
635 The reserved word @code{time} causes timing statistics
636 to be printed for the pipeline once it finishes.
637 The statistics currently consist of elapsed (wall-clock) time and
638 user and system time consumed by the command's execution.
639 The @option{-p} option changes the output format to that specified
640 by @sc{posix}.
641 The @env{TIMEFORMAT} variable may be set to a format string that
642 specifies how the timing information should be displayed.
643 @xref{Bash Variables}, for a description of the available formats.
644 The use of @code{time} as a reserved word permits the timing of
645 shell builtins, shell functions, and pipelines.  An external
646 @code{time} command cannot time these easily.
647
648 If the pipeline is not executed asynchronously (@pxref{Lists}), the
649 shell waits for all commands in the pipeline to complete.
650
651 Each command in a pipeline is executed in its own subshell
652 (@pxref{Command Execution Environment}).  The exit
653 status of a pipeline is the exit status of the last command in the
654 pipeline, unless the @code{pipefail} option is enabled
655 (@pxref{The Set Builtin}).
656 If @code{pipefail} is enabled, the pipeline's return status is the
657 value of the last (rightmost) command to exit with a non-zero status,
658 or zero if all commands exit successfully.
659 If the reserved word @samp{!} precedes the pipeline, the
660 exit status is the logical negation of the exit status as described
661 above.
662 The shell waits for all commands in the pipeline to terminate before
663 returning a value.
664
665 @node Lists
666 @subsection Lists of Commands
667 @cindex commands, lists
668
669 A @code{list} is a sequence of one or more pipelines separated by one
670 of the operators @samp{;}, @samp{&}, @samp{&&}, or @samp{||},
671 and optionally terminated by one of @samp{;}, @samp{&}, or a
672 @code{newline}.
673
674 Of these list operators, @samp{&&} and @samp{||}
675 have equal precedence, followed by @samp{;} and @samp{&},
676 which have equal precedence.
677
678 A sequence of one or more newlines may appear in a @code{list}
679 to delimit commands, equivalent to a semicolon.
680
681 If a command is terminated by the control operator @samp{&},
682 the shell executes the command asynchronously in a subshell.
683 This is known as executing the command in the @var{background}.
684 The shell does not wait for the command to finish, and the return
685 status is 0 (true).
686 When job control is not active (@pxref{Job Control}),
687 the standard input for asynchronous commands, in the absence of any
688 explicit redirections, is redirected from @code{/dev/null}.
689
690 Commands separated by a @samp{;} are executed sequentially; the shell
691 waits for each command to terminate in turn.  The return status is the
692 exit status of the last command executed.
693
694 @sc{and} and @sc{or} lists are sequences of one or more pipelines
695 separated by the control operators @samp{&&} and @samp{||},
696 respectively.  @sc{and} and @sc{or} lists are executed with left
697 associativity.
698
699 An @sc{and} list has the form
700 @example
701 @var{command1} && @var{command2}
702 @end example
703
704 @noindent
705 @var{command2} is executed if, and only if, @var{command1}
706 returns an exit status of zero.
707
708 An @sc{or} list has the form
709 @example
710 @var{command1} || @var{command2}
711 @end example
712
713 @noindent
714 @var{command2} is executed if, and only if, @var{command1}
715 returns a non-zero exit status.
716
717 The return status of
718 @sc{and} and @sc{or} lists is the exit status of the last command
719 executed in the list.
720
721 @node Compound Commands
722 @subsection Compound Commands
723 @cindex commands, compound
724
725 @menu
726 * Looping Constructs::          Shell commands for iterative action.
727 * Conditional Constructs::      Shell commands for conditional execution.
728 * Command Grouping::            Ways to group commands.
729 @end menu
730
731 Compound commands are the shell programming constructs.
732 Each construct begins with a reserved word or control operator and is
733 terminated by a corresponding reserved word or operator.
734 Any redirections (@pxref{Redirections}) associated with a compound command
735 apply to all commands within that compound command unless explicitly overridden.
736
737 Bash provides looping constructs, conditional commands, and mechanisms
738 to group commands and execute them as a unit.
739
740 @node Looping Constructs
741 @subsubsection Looping Constructs
742 @cindex commands, looping
743
744 Bash supports the following looping constructs.
745
746 Note that wherever a @samp{;} appears in the description of a
747 command's syntax, it may be replaced with one or more newlines.
748
749 @table @code
750 @item until
751 @rwindex until
752 @rwindex do
753 @rwindex done
754 The syntax of the @code{until} command is:
755 @example
756 until @var{test-commands}; do @var{consequent-commands}; done
757 @end example
758 Execute @var{consequent-commands} as long as
759 @var{test-commands} has an exit status which is not zero.
760 The return status is the exit status of the last command executed
761 in @var{consequent-commands}, or zero if none was executed.
762
763 @item while
764 @rwindex while
765 The syntax of the @code{while} command is:
766 @example
767 while @var{test-commands}; do @var{consequent-commands}; done
768 @end example
769
770 Execute @var{consequent-commands} as long as
771 @var{test-commands} has an exit status of zero.
772 The return status is the exit status of the last command executed
773 in @var{consequent-commands}, or zero if none was executed.
774
775 @item for
776 @rwindex for
777 The syntax of the @code{for} command is:
778
779 @example
780 for @var{name} [in @var{words} @dots{}]; do @var{commands}; done
781 @end example
782 Expand @var{words}, and execute @var{commands} once for each member
783 in the resultant list, with @var{name} bound to the current member.
784 If @samp{in @var{words}} is not present, the @code{for} command
785 executes the @var{commands} once for each positional parameter that is
786 set, as if @samp{in "$@@"} had been specified
787 (@pxref{Special Parameters}).
788 The return status is the exit status of the last command that executes.
789 If there are no items in the expansion of @var{words}, no commands are
790 executed, and the return status is zero.
791
792 An alternate form of the @code{for} command is also supported:
793
794 @example
795 for (( @var{expr1} ; @var{expr2} ; @var{expr3} )) ; do @var{commands} ; done
796 @end example
797 First, the arithmetic expression @var{expr1} is evaluated according
798 to the rules described below (@pxref{Shell Arithmetic}).
799 The arithmetic expression @var{expr2} is then evaluated repeatedly
800 until it evaluates to zero.   
801 Each time @var{expr2} evaluates to a non-zero value, @var{commands} are
802 executed and the arithmetic expression @var{expr3} is evaluated.       
803 If any expression is omitted, it behaves as if it evaluates to 1.
804 The return value is the exit status of the last command in @var{list}
805 that is executed, or false if any of the expressions is invalid.
806
807 @end table
808
809 The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins})
810 may be used to control loop execution.
811
812 @node Conditional Constructs
813 @subsubsection Conditional Constructs
814 @cindex commands, conditional
815
816 @table @code
817 @item if
818 @rwindex if
819 @rwindex then
820 @rwindex else
821 @rwindex elif
822 @rwindex fi
823 The syntax of the @code{if} command is:
824
825 @example
826 if @var{test-commands}; then
827   @var{consequent-commands};
828 [elif @var{more-test-commands}; then
829   @var{more-consequents};]
830 [else @var{alternate-consequents};]
831 fi
832 @end example
833
834 The @var{test-commands} list is executed, and if its return status is zero,
835 the @var{consequent-commands} list is executed.
836 If @var{test-commands} returns a non-zero status, each @code{elif} list
837 is executed in turn, and if its exit status is zero,
838 the corresponding @var{more-consequents} is executed and the   
839 command completes.
840 If @samp{else @var{alternate-consequents}} is present, and
841 the final command in the final @code{if} or @code{elif} clause
842 has a non-zero exit status, then @var{alternate-consequents} is executed.
843 The return status is the exit status of the last command executed, or
844 zero if no condition tested true.
845
846 @item case
847 @rwindex case
848 @rwindex in
849 @rwindex esac
850 The syntax of the @code{case} command is:
851
852 @example
853 @code{case @var{word} in [ [(] @var{pattern} [| @var{pattern}]@dots{}) @var{command-list} ;;]@dots{} esac}
854 @end example
855
856 @code{case} will selectively execute the @var{command-list} corresponding to
857 the first @var{pattern} that matches @var{word}.
858 If the shell option @code{nocasematch}
859 (see the description of @code{shopt} in @ref{The Shopt Builtin})
860 is enabled, the match is performed without regard to the case
861 of alphabetic characters.
862 The @samp{|} is used to separate multiple patterns, and the @samp{)}
863 operator terminates a pattern list.
864 A list of patterns and an associated command-list is known
865 as a @var{clause}.
866
867 Each clause must be terminated with @samp{;;}, @samp{,&}, or @samp{;;&}.
868 The @var{word} undergoes tilde expansion, parameter expansion, command
869 substitution, arithmetic expansion, and quote removal before matching is
870 attempted.  Each @var{pattern} undergoes tilde expansion, parameter
871 expansion, command substitution, and arithmetic expansion.
872
873 There may be an arbitrary number of @code{case} clauses, each terminated
874 by a @samp{;;}, @samp{;&}, or @samp{;;&}.
875 The first pattern that matches determines the
876 command-list that is executed.
877
878 Here is an example using @code{case} in a script that could be used to
879 describe one interesting feature of an animal:
880
881 @example
882 echo -n "Enter the name of an animal: "
883 read ANIMAL
884 echo -n "The $ANIMAL has "
885 case $ANIMAL in
886   horse | dog | cat) echo -n "four";;
887   man | kangaroo ) echo -n "two";;
888   *) echo -n "an unknown number of";;
889 esac
890 echo " legs."
891 @end example
892
893 @noindent
894
895 If the @samp{;;} operator is used, no subsequent matches are attempted after
896 the first pattern match.
897 Using @samp{;&}  in place of @samp{;;} causes execution to continue with
898 the @var{command-list} associated with the next clause, if any.
899 Using @samp{;;&} in place of @samp{;;} causes the shell to test the patterns
900 in the next clause, if any, and execute any associated @var{command-list}
901 on a successful match.
902
903 The return status is zero if no @var{pattern} is matched.  Otherwise, the
904 return status is the exit status of the @var{command-list} executed.
905
906 @item select
907 @rwindex select
908
909 The @code{select} construct allows the easy generation of menus.
910 It has almost the same syntax as the @code{for} command:
911
912 @example
913 select @var{name} [in @var{words} @dots{}]; do @var{commands}; done
914 @end example
915
916 The list of words following @code{in} is expanded, generating a list
917 of items.  The set of expanded words is printed on the standard
918 error output stream, each preceded by a number.  If the
919 @samp{in @var{words}} is omitted, the positional parameters are printed,
920 as if @samp{in "$@@"} had been specified.
921 The @env{PS3} prompt is then displayed and a line is read from the
922 standard input.
923 If the line consists of a number corresponding to one of the displayed
924 words, then the value of @var{name} is set to that word.
925 If the line is empty, the words and prompt are displayed again.
926 If @code{EOF} is read, the @code{select} command completes.
927 Any other value read causes @var{name} to be set to null.
928 The line read is saved in the variable @env{REPLY}.
929
930 The @var{commands} are executed after each selection until a
931 @code{break} command is executed, at which
932 point the @code{select} command completes.
933
934 Here is an example that allows the user to pick a filename from the
935 current directory, and displays the name and index of the file
936 selected.
937
938 @example
939 select fname in *;
940 do
941         echo you picked $fname \($REPLY\)
942         break;
943 done
944 @end example
945
946 @item ((@dots{}))
947 @example
948 (( @var{expression} ))
949 @end example
950
951 The arithmetic @var{expression} is evaluated according to the rules
952 described below (@pxref{Shell Arithmetic}).
953 If the value of the expression is non-zero, the return status is 0;
954 otherwise the return status is 1.  This is exactly equivalent to
955 @example
956 let "@var{expression}"
957 @end example
958 @noindent
959 @xref{Bash Builtins}, for a full description of the @code{let} builtin.
960
961 @item [[@dots{}]]
962 @rwindex [[
963 @rwindex ]]
964 @example
965 [[ @var{expression} ]]
966 @end example
967
968 Return a status of 0 or 1 depending on the evaluation of
969 the conditional expression @var{expression}.
970 Expressions are composed of the primaries described below in
971 @ref{Bash Conditional Expressions}.
972 Word splitting and filename expansion are not performed on the words
973 between the @samp{[[} and @samp{]]}; tilde expansion, parameter and
974 variable expansion, arithmetic expansion, command substitution, process
975 substitution, and quote removal are performed.
976 Conditional operators such as @samp{-f} must be unquoted to be recognized
977 as primaries.
978
979 When the @samp{==} and @samp{!=} operators are used, the string to the
980 right of the operator is considered a pattern and matched according
981 to the rules described below in @ref{Pattern Matching}.
982 If the shell option @code{nocasematch}
983 (see the description of @code{shopt} in @ref{The Shopt Builtin})
984 is enabled, the match is performed without regard to the case
985 of alphabetic characters.
986 The return value is 0 if the string matches (@samp{==}) or does not
987 match (@samp{!=})the pattern, and 1 otherwise.
988 Any part of the pattern may be quoted to force it to be matched as a
989 string.
990
991 An additional binary operator, @samp{=~}, is available, with the same
992 precedence as @samp{==} and @samp{!=}.
993 When it is used, the string to the right of the operator is considered
994 an extended regular expression and matched accordingly (as in @i{regex}3)).  
995 The return value is 0 if the string matches
996 the pattern, and 1 otherwise.
997 If the regular expression is syntactically incorrect, the conditional
998 expression's return value is 2.
999 If the shell option @code{nocasematch}
1000 (see the description of @code{shopt} in @ref{The Shopt Builtin})
1001 is enabled, the match is performed without regard to the case
1002 of alphabetic characters.
1003 Any part of the pattern may be quoted to force it to be matched as a
1004 string.
1005 Substrings matched by parenthesized subexpressions within the regular
1006 expression are saved in the array variable @code{BASH_REMATCH}.
1007 The element of @code{BASH_REMATCH} with index 0 is the portion of the string
1008 matching the entire regular expression.
1009 The element of @code{BASH_REMATCH} with index @var{n} is the portion of the
1010 string matching the @var{n}th parenthesized subexpression.
1011
1012 Expressions may be combined using the following operators, listed
1013 in decreasing order of precedence:
1014
1015 @table @code
1016 @item ( @var{expression} )
1017 Returns the value of @var{expression}.
1018 This may be used to override the normal precedence of operators.
1019
1020 @item ! @var{expression}
1021 True if @var{expression} is false.
1022
1023 @item @var{expression1} && @var{expression2}
1024 True if both @var{expression1} and @var{expression2} are true.
1025
1026 @item @var{expression1} || @var{expression2}
1027 True if either @var{expression1} or @var{expression2} is true.
1028 @end table
1029 @noindent
1030 The @code{&&} and @code{||} operators do not evaluate @var{expression2} if the
1031 value of @var{expression1} is sufficient to determine the return
1032 value of the entire conditional expression.
1033
1034 @end table
1035
1036 @node Command Grouping
1037 @subsubsection Grouping Commands
1038 @cindex commands, grouping
1039
1040 Bash provides two ways to group a list of commands to be executed
1041 as a unit.  When commands are grouped, redirections may be applied
1042 to the entire command list.  For example, the output of all the
1043 commands in the list may be redirected to a single stream.
1044
1045 @table @code
1046 @item ()
1047 @example
1048 ( @var{list} )
1049 @end example
1050
1051 Placing a list of commands between parentheses causes a subshell
1052 environment to be created (@pxref{Command Execution Environment}), and each
1053 of the commands in @var{list} to be executed in that subshell.  Since the
1054 @var{list} is executed in a subshell, variable assignments do not remain in
1055 effect after the subshell completes. 
1056
1057 @item @{@}
1058 @rwindex @{
1059 @rwindex @}
1060 @example
1061 @{ @var{list}; @}
1062 @end example
1063
1064 Placing a list of commands between curly braces causes the list to
1065 be executed in the current shell context.  No subshell is created.
1066 The semicolon (or newline) following @var{list} is required.
1067 @end table
1068
1069 In addition to the creation of a subshell, there is a subtle difference
1070 between these two constructs due to historical reasons.  The braces
1071 are @code{reserved words}, so they must be separated from the @var{list}
1072 by @code{blank}s or other shell metacharacters.
1073 The parentheses are @code{operators}, and are
1074 recognized as separate tokens by the shell even if they are not separated
1075 from the @var{list} by whitespace.
1076
1077 The exit status of both of these constructs is the exit status of
1078 @var{list}.
1079
1080 @node Coprocesses
1081 @subsection Coprocesses
1082 @cindex coprocess
1083
1084 A @code{coprocess} is a shell command preceded by the @code{coproc}
1085 reserved word.
1086 A coprocess is executed asynchronously in a subshell, as if the command
1087 had been terminated with the @samp{&} control operator, with a two-way pipe
1088 established between the executing shell and the coprocess.
1089
1090 The format for a coprocess is:
1091 @example
1092 @code{coproc} [@var{NAME}] @var{command} [@var{redirections}]
1093 @end example
1094
1095 @noindent
1096 This creates a coprocess named @var{NAME}.
1097 If @var{NAME} is not supplied, the default name is @var{COPROC}.
1098 @var{NAME} must not be supplied if @var{command} is a simple
1099 command (@pxref{Simple Commands}); otherwise, it is interpreted as
1100 the first word of the simple command.
1101
1102 When the coproc is executed, the shell creates an array variable
1103 (@pxref{Arrays})
1104 named @var{NAME} in the context of the executing shell.
1105 The standard output of @var{command}
1106 is connected via a pipe to a file descriptor in the executing shell,
1107 and that file descriptor is assigned to @var{NAME}[0].
1108 The standard input of @var{command}
1109 is connected via a pipe to a file descriptor in the executing shell,
1110 and that file descriptor is assigned to @var{NAME}[1].
1111 This pipe is established before any redirections specified by the
1112 command (@pxref{Redirections}).
1113 The file descriptors can be utilized as arguments to shell commands
1114 and redirections using standard word expansions.
1115
1116 The process id of the shell spawned to execute the coprocess is
1117 available as the value of the variable @var{NAME}_PID.
1118 The @code{wait}
1119 builtin command may be used to wait for the coprocess to terminate.
1120
1121 The return status of a coprocess is the exit status of @var{command}.
1122
1123 @node Shell Functions
1124 @section Shell Functions
1125 @cindex shell function
1126 @cindex functions, shell
1127
1128 Shell functions are a way to group commands for later execution
1129 using a single name for the group.  They are executed just like
1130 a "regular" command.
1131 When the name of a shell function is used as a simple command name,
1132 the list of commands associated with that function name is executed.
1133 Shell functions are executed in the current
1134 shell context; no new process is created to interpret them.
1135
1136 Functions are declared using this syntax:
1137 @rwindex function
1138 @example
1139 [ @code{function} ] @var{name} () @var{compound-command} [ @var{redirections} ]
1140 @end example
1141
1142 This defines a shell function named @var{name}.  The reserved
1143 word @code{function} is optional.
1144 If the @code{function} reserved
1145 word is supplied, the parentheses are optional.
1146 The @var{body} of the function is the compound command
1147 @var{compound-command} (@pxref{Compound Commands}).
1148 That command is usually a @var{list} enclosed between @{ and @}, but
1149 may be any compound command listed above.
1150 @var{compound-command} is executed whenever @var{name} is specified as the
1151 name of a command.
1152 Any redirections (@pxref{Redirections}) associated with the shell function
1153 are performed when the function is executed.
1154
1155 A function definition may be deleted using the @option{-f} option to the
1156 @code{unset} builtin (@pxref{Bourne Shell Builtins}).
1157
1158 The exit status of a function definition is zero unless a syntax error
1159 occurs or a readonly function with the same name already exists.
1160 When executed, the exit status of a function is the exit status of the
1161 last command executed in the body.
1162
1163 Note that for historical reasons, in the most common usage the curly braces
1164 that surround the body of the function must be separated from the body by
1165 @code{blank}s or newlines.
1166 This is because the braces are reserved words and are only recognized
1167 as such when they are separated from the command list
1168 by whitespace or another shell metacharacter.
1169 Also, when using the braces, the @var{list} must be terminated by a semicolon,
1170 a @samp{&}, or a newline.
1171
1172 When a function is executed, the arguments to the
1173 function become the positional parameters
1174 during its execution (@pxref{Positional Parameters}).
1175 The special parameter @samp{#} that expands to the number of
1176 positional parameters is updated to reflect the change.
1177 Special parameter @code{0} is unchanged.
1178 The first element of the @env{FUNCNAME} variable is set to the
1179 name of the function while the function is executing.
1180 All other aspects of the shell execution
1181 environment are identical between a function and its caller
1182 with the exception that the @env{DEBUG} and @env{RETURN} traps
1183 are not inherited unless the function has been given the
1184 @code{trace} attribute using the @code{declare} builtin or
1185 the @code{-o functrace} option has been enabled with
1186 the @code{set} builtin,
1187 (in which case all functions inherit the @env{DEBUG} and @env{RETURN} traps).
1188 @xref{Bourne Shell Builtins}, for the description of the
1189 @code{trap} builtin.
1190
1191 If the builtin command @code{return}
1192 is executed in a function, the function completes and
1193 execution resumes with the next command after the function
1194 call.
1195 Any command associated with the @code{RETURN} trap is executed
1196 before execution resumes.
1197 When a function completes, the values of the
1198 positional parameters and the special parameter @samp{#}
1199 are restored to the values they had prior to the function's
1200 execution.  If a numeric argument is given to @code{return},
1201 that is the function's return status; otherwise the function's
1202 return status is the exit status of the last command executed
1203 before the @code{return}.
1204
1205 Variables local to the function may be declared with the
1206 @code{local} builtin.  These variables are visible only to
1207 the function and the commands it invokes.
1208
1209 Function names and definitions may be listed with the
1210 @option{-f} option to the @code{declare} or @code{typeset}
1211 builtin commands (@pxref{Bash Builtins}).
1212 The @option{-F} option to @code{declare} or @code{typeset}
1213 will list the function names only
1214 (and optionally the source file and line number, if the @code{extdebug}
1215 shell option is enabled).
1216 Functions may be exported so that subshells
1217 automatically have them defined with the
1218 @option{-f} option to the @code{export} builtin
1219 (@pxref{Bourne Shell Builtins}).
1220 Note that shell functions and variables with the same name may result
1221 in multiple identically-named entries in the environment passed to the
1222 shell's children.
1223 Care should be taken in cases where this may cause a problem.
1224
1225 Functions may be recursive.  No limit is placed on the number of
1226 recursive  calls.
1227
1228 @node Shell Parameters
1229 @section Shell Parameters
1230 @cindex parameters
1231 @cindex variable, shell
1232 @cindex shell variable
1233
1234 @menu
1235 * Positional Parameters::       The shell's command-line arguments.
1236 * Special Parameters::          Parameters denoted by special characters.
1237 @end menu
1238
1239 A @var{parameter} is an entity that stores values.
1240 It can be a @code{name}, a number, or one of the special characters
1241 listed below.
1242 A @var{variable} is a parameter denoted by a @code{name}.
1243 A variable has a @var{value} and zero or more @var{attributes}.
1244 Attributes are assigned using the @code{declare} builtin command
1245 (see the description of the @code{declare} builtin in @ref{Bash Builtins}).
1246
1247 A parameter is set if it has been assigned a value.  The null string is
1248 a valid value.  Once a variable is set, it may be unset only by using
1249 the @code{unset} builtin command.
1250
1251 A variable may be assigned to by a statement of the form
1252 @example
1253 @var{name}=[@var{value}]
1254 @end example
1255 @noindent
1256 If @var{value}
1257 is not given, the variable is assigned the null string.  All
1258 @var{value}s undergo tilde expansion, parameter and variable expansion,
1259 command substitution, arithmetic expansion, and quote
1260 removal (detailed below).  If the variable has its @code{integer}
1261 attribute set, then @var{value} 
1262 is evaluated as an arithmetic expression even if the @code{$((@dots{}))}
1263 expansion is not used (@pxref{Arithmetic Expansion}).
1264 Word splitting is not performed, with the exception
1265 of @code{"$@@"} as explained below.
1266 Filename expansion is not performed.
1267 Assignment statements may also appear as arguments to the
1268 @code{alias}, 
1269 @code{declare}, @code{typeset}, @code{export}, @code{readonly},
1270 and @code{local} builtin commands.
1271
1272 In the context where an assignment statement is assigning a value  
1273 to a shell variable or array index (@pxref{Arrays}), the @samp{+=}
1274 operator can be used to   
1275 append to or add to the variable's previous value.
1276 When @samp{+=} is applied to a variable for which the integer attribute
1277 has been set, @var{value} is evaluated as an arithmetic expression and
1278 added to the variable's current value, which is also evaluated.
1279 When @samp{+=} is applied to an array variable using compound assignment
1280 (@pxref{Arrays}), the
1281 variable's value is not unset (as it is when using @samp{=}), and new
1282 values are appended to the array beginning at one greater than the array's
1283 maximum index (for indexed arrays),  or added as additional key-value pairs
1284 in an associative array.
1285 When applied to a string-valued variable, @var{value} is expanded and
1286 appended to the variable's value.
1287
1288 @node Positional Parameters
1289 @subsection Positional Parameters
1290 @cindex parameters, positional
1291
1292 A @var{positional parameter} is a parameter denoted by one or more
1293 digits, other than the single digit @code{0}.  Positional parameters are
1294 assigned from the shell's arguments when it is invoked,
1295 and may be reassigned using the @code{set} builtin command.
1296 Positional parameter @code{N} may be referenced as @code{$@{N@}}, or
1297 as @code{$N} when @code{N} consists of a single digit.
1298 Positional parameters may not be assigned to with assignment statements.
1299 The @code{set} and @code{shift} builtins are used to set and
1300 unset them (@pxref{Shell Builtin Commands}).
1301 The positional parameters are
1302 temporarily replaced when a shell function is executed
1303 (@pxref{Shell Functions}).
1304
1305 When a positional parameter consisting of more than a single
1306 digit is expanded, it must be enclosed in braces.
1307
1308 @node Special Parameters
1309 @subsection Special Parameters
1310 @cindex parameters, special
1311
1312 The shell treats several parameters specially.  These parameters may
1313 only be referenced; assignment to them is not allowed.
1314
1315 @vtable @code
1316
1317 @item *
1318 Expands to the positional parameters, starting from one.  When the
1319 expansion occurs within double quotes, it expands to a single word
1320 with the value of each parameter separated by the first character
1321 of the @env{IFS}
1322 special variable.  That is, @code{"$*"} is equivalent
1323 to @code{"$1@var{c}$2@var{c}@dots{}"}, where @var{c}
1324 is the first character of the value of the @code{IFS}
1325 variable.
1326 If @env{IFS} is unset, the parameters are separated by spaces.
1327 If @env{IFS} is null, the parameters are joined without intervening
1328 separators.
1329
1330
1331 @item @@
1332 Expands to the positional parameters, starting from one.  When the
1333 expansion occurs within double quotes, each parameter expands to a
1334 separate word.  That is, @code{"$@@"} is equivalent to
1335 @code{"$1" "$2" @dots{}}.
1336 If the double-quoted expansion occurs within a word, the expansion of
1337 the first parameter is joined with the beginning part of the original
1338 word, and the expansion of the last parameter is joined with the last
1339 part of the original word.
1340 When there are no positional parameters, @code{"$@@"} and
1341 @code{$@@}
1342 expand to nothing (i.e., they are removed).
1343
1344 @item #
1345 Expands to the number of positional parameters in decimal.
1346
1347 @item ?
1348 Expands to the exit status of the most recently executed foreground
1349 pipeline.
1350
1351 @item -
1352 (A hyphen.)  Expands to the current option flags as specified upon
1353 invocation, by the @code{set}
1354 builtin command, or those set by the shell itself
1355 (such as the @option{-i} option).
1356
1357 @item $
1358 Expands to the process @sc{id} of the shell.  In a @code{()} subshell, it
1359 expands to the process @sc{id} of the invoking shell, not the subshell.
1360
1361 @item !
1362 Expands to the process @sc{id} of the most recently executed background
1363 (asynchronous) command.
1364
1365 @item 0
1366 Expands to the name of the shell or shell script.  This is set at
1367 shell initialization.  If Bash is invoked with a file of commands
1368 (@pxref{Shell Scripts}), @code{$0} is set to the name of that file.
1369 If Bash is started with the @option{-c} option (@pxref{Invoking Bash}),
1370 then @code{$0} is set to the first argument after the string to be
1371 executed, if one is present.  Otherwise, it is set
1372 to the filename used to invoke Bash, as given by argument zero.
1373
1374 @item _
1375 (An underscore.)
1376 At shell startup, set to the absolute pathname used to invoke the
1377 shell or shell script being executed as passed in the environment
1378 or argument list.
1379 Subsequently, expands to the last argument to the previous command,
1380 after expansion.   
1381 Also set to the full pathname used to invoke each command executed
1382 and placed in the environment exported to that command.
1383 When checking mail, this parameter holds the name of the mail file.
1384 @end vtable
1385
1386 @node Shell Expansions
1387 @section Shell Expansions
1388 @cindex expansion
1389
1390 Expansion is performed on the command line after it has been split into
1391 @code{token}s.  There are seven kinds of expansion performed:
1392 @itemize @bullet
1393 @item brace expansion
1394 @item tilde expansion
1395 @item parameter and variable expansion
1396 @item command substitution
1397 @item arithmetic expansion
1398 @item word splitting
1399 @item filename expansion
1400 @end itemize
1401
1402 @menu
1403 * Brace Expansion::             Expansion of expressions within braces.
1404 * Tilde Expansion::             Expansion of the ~ character.
1405 * Shell Parameter Expansion::   How Bash expands variables to their values.
1406 * Command Substitution::        Using the output of a command as an argument.
1407 * Arithmetic Expansion::        How to use arithmetic in shell expansions.
1408 * Process Substitution::        A way to write and read to and from a
1409                                 command.
1410 * Word Splitting::      How the results of expansion are split into separate
1411                         arguments.
1412 * Filename Expansion::  A shorthand for specifying filenames matching patterns.
1413 * Quote Removal::       How and when quote characters are removed from
1414                         words.
1415 @end menu
1416
1417 The order of expansions is: brace expansion, tilde expansion,
1418 parameter, variable, and arithmetic expansion and
1419 command substitution
1420 (done in a left-to-right fashion), word splitting, and filename
1421 expansion.
1422
1423 On systems that can support it, there is an additional expansion
1424 available: @var{process substitution}.  This is performed at the
1425 same time as parameter, variable, and arithmetic expansion and
1426 command substitution.
1427
1428 Only brace expansion, word splitting, and filename expansion
1429 can change the number of words of the expansion; other expansions
1430 expand a single word to a single word.
1431 The only exceptions to this are the expansions of
1432 @code{"$@@"} (@pxref{Special Parameters}) and @code{"$@{@var{name}[@@]@}"}
1433 (@pxref{Arrays}).
1434
1435 After all expansions, @code{quote removal} (@pxref{Quote Removal})
1436 is performed.
1437
1438 @node Brace Expansion
1439 @subsection Brace Expansion
1440 @cindex brace expansion
1441 @cindex expansion, brace
1442
1443 Brace expansion is a mechanism by which arbitrary strings may be generated.
1444 This mechanism is similar to
1445 @var{filename expansion} (@pxref{Filename Expansion}),
1446 but the file names generated need not exist.
1447 Patterns to be brace expanded take the form of an optional @var{preamble},
1448 followed by either a series of comma-separated strings or a seqeunce expression
1449 between a pair of braces,
1450 followed by an optional @var{postscript}.
1451 The preamble is prefixed to each string contained within the braces, and
1452 the postscript is then appended to each resulting string, expanding left
1453 to right.
1454
1455 Brace expansions may be nested.
1456 The results of each expanded string are not sorted; left to right order
1457 is preserved.
1458 For example,
1459 @example
1460 bash$ echo a@{d,c,b@}e
1461 ade ace abe
1462 @end example
1463
1464 A sequence expression takes the form @code{@{@var{x}..@var{y}[@var{incr}]@}},
1465 where @var{x} and @var{y} are either integers or single characters,
1466 and @var{incr}, an optional increment, is an integer.
1467 When integers are supplied, the expression expands to each number between
1468 @var{x} and @var{y}, inclusive.
1469 Supplied integers may be prefixed with @samp{0} to force each term to have the
1470 same width.  When either @var{x} or @var{y} begins with a zero, the shell
1471 attempts to force all generated terms to contain the same number of digits,
1472 zero-padding where necessary.
1473 When characters are supplied, the expression expands to each character
1474 lexicographically between @var{x} and @var{y}, inclusive.  Note that
1475 both @var{x} and @var{y} must be of the same type.
1476 When the increment is supplied, it is used as the difference between
1477 each term.  The default increment is 1 or -1 as appropriate.
1478
1479 Brace expansion is performed before any other expansions,
1480 and any characters special to other expansions are preserved
1481 in the result.  It is strictly textual.  Bash
1482 does not apply any syntactic interpretation to the context of the
1483 expansion or the text between the braces.
1484 To avoid conflicts with parameter expansion, the string @samp{$@{}
1485 is not considered eligible for brace expansion.
1486
1487 A correctly-formed brace expansion must contain unquoted opening
1488 and closing braces, and at least one unquoted comma or a valid
1489 sequence expression.
1490 Any incorrectly formed brace expansion is left unchanged.
1491
1492 A @{ or @samp{,} may be quoted with a backslash to prevent its
1493 being considered part of a brace expression.
1494 To avoid conflicts with parameter expansion, the string @samp{$@{}
1495 is not considered eligible for brace expansion.
1496
1497 This construct is typically used as shorthand when the common
1498 prefix of the strings to be generated is longer than in the
1499 above example:
1500 @example
1501 mkdir /usr/local/src/bash/@{old,new,dist,bugs@}
1502 @end example
1503 or
1504 @example
1505 chown root /usr/@{ucb/@{ex,edit@},lib/@{ex?.?*,how_ex@}@}
1506 @end example
1507
1508 @node Tilde Expansion
1509 @subsection Tilde Expansion
1510 @cindex tilde expansion
1511 @cindex expansion, tilde
1512
1513 If a word begins with an unquoted tilde character (@samp{~}), all of the
1514 characters up to the first unquoted slash (or all characters,
1515 if there is no unquoted slash) are considered a @var{tilde-prefix}.
1516 If none of the characters in the tilde-prefix are quoted, the
1517 characters in the tilde-prefix following the tilde are treated as a
1518 possible @var{login name}.
1519 If this login name is the null string, the tilde is replaced with the
1520 value of the @env{HOME} shell variable.
1521 If @env{HOME} is unset, the home directory of the user executing the
1522 shell is substituted instead.
1523 Otherwise, the tilde-prefix is replaced with the home directory
1524 associated with the specified login name.
1525
1526 If the tilde-prefix is @samp{~+}, the value of
1527 the shell variable @env{PWD} replaces the tilde-prefix.
1528 If the tilde-prefix is @samp{~-}, the value of the shell variable
1529 @env{OLDPWD}, if it is set, is substituted.
1530
1531 If the characters following the tilde in the tilde-prefix consist of a
1532 number @var{N}, optionally prefixed by a @samp{+} or a @samp{-},
1533 the tilde-prefix is replaced with the
1534 corresponding element from the directory stack, as it would be displayed
1535 by the @code{dirs} builtin invoked with the characters following tilde
1536 in the tilde-prefix as an argument (@pxref{The Directory Stack}).
1537 If the tilde-prefix, sans the tilde, consists of a number without a
1538 leading @samp{+} or @samp{-}, @samp{+} is assumed.
1539
1540 If the login name is invalid, or the tilde expansion fails, the word is
1541 left unchanged.
1542
1543 Each variable assignment is checked for unquoted tilde-prefixes immediately
1544 following a @samp{:} or the first @samp{=}.
1545 In these cases, tilde expansion is also performed.
1546 Consequently, one may use file names with tildes in assignments to
1547 @env{PATH}, @env{MAILPATH}, and @env{CDPATH},
1548 and the shell assigns the expanded value.
1549
1550 The following table shows how Bash treats unquoted tilde-prefixes:
1551
1552 @table @code
1553 @item ~
1554 The value of @code{$HOME}
1555 @item ~/foo
1556 @file{$HOME/foo}
1557
1558 @item ~fred/foo
1559 The subdirectory @code{foo} of the home directory of the user
1560 @code{fred}
1561
1562 @item ~+/foo
1563 @file{$PWD/foo}
1564
1565 @item ~-/foo
1566 @file{$@{OLDPWD-'~-'@}/foo}
1567
1568 @item ~@var{N}
1569 The string that would be displayed by @samp{dirs +@var{N}}
1570
1571 @item ~+@var{N}
1572 The string that would be displayed by @samp{dirs +@var{N}}
1573
1574 @item ~-@var{N}
1575 The string that would be displayed by @samp{dirs -@var{N}}
1576
1577 @end table
1578
1579 @node Shell Parameter Expansion
1580 @subsection Shell Parameter Expansion
1581 @cindex parameter expansion
1582 @cindex expansion, parameter
1583
1584 The @samp{$} character introduces parameter expansion,
1585 command substitution, or arithmetic expansion.  The parameter name
1586 or symbol to be expanded may be enclosed in braces, which
1587 are optional but serve to protect the variable to be expanded from
1588 characters immediately following it which could be
1589 interpreted as part of the name.
1590
1591 When braces are used, the matching ending brace is the first @samp{@}}
1592 not escaped by a backslash or within a quoted string, and not within an
1593 embedded arithmetic expansion, command substitution, or parameter
1594 expansion.
1595
1596 The basic form of parameter expansion is $@{@var{parameter}@}.
1597 The value of @var{parameter} is substituted.  The braces are required
1598 when @var{parameter}
1599 is a positional parameter with more than one digit,
1600 or when @var{parameter}
1601 is followed by a character that is not to be
1602 interpreted as part of its name.
1603
1604 If the first character of @var{parameter} is an exclamation point,
1605 a level of variable indirection is introduced.
1606 Bash uses the value of the variable formed from the rest of
1607 @var{parameter} as the name of the variable; this variable is then
1608 expanded and that value is used in the rest of the substitution, rather
1609 than the value of @var{parameter} itself.
1610 This is known as @code{indirect expansion}.
1611 The exceptions to this are the expansions of $@{!@var{prefix*}@}
1612 and $@{!@var{name}[@@]@}
1613 described below.
1614 The exclamation point must immediately follow the left brace in order to
1615 introduce indirection.
1616
1617 In each of the cases below, @var{word} is subject to tilde expansion,
1618 parameter expansion, command substitution, and arithmetic expansion.
1619
1620 When not performing substring expansion, using the form described
1621 below, Bash tests for a parameter that is unset or null.
1622 Omitting the colon results in a test only for a parameter that is unset.
1623 Put another way, if the colon is included,
1624 the operator tests for both @var{parameter}'s existence and that its value
1625 is not null; if the colon is omitted, the operator tests only for existence.
1626
1627 @table @code
1628
1629 @item $@{@var{parameter}:@minus{}@var{word}@}
1630 If @var{parameter} is unset or null, the expansion of
1631 @var{word} is substituted.  Otherwise, the value of
1632 @var{parameter} is substituted.
1633
1634 @item $@{@var{parameter}:=@var{word}@}
1635 If @var{parameter}
1636 is unset or null, the expansion of @var{word}
1637 is assigned to @var{parameter}.
1638 The value of @var{parameter} is then substituted. 
1639 Positional parameters and special parameters may not be assigned to
1640 in this way.
1641
1642 @item $@{@var{parameter}:?@var{word}@}
1643 If @var{parameter}
1644 is null or unset, the expansion of @var{word} (or a message
1645 to that effect if @var{word}
1646 is not present) is written to the standard error and the shell, if it
1647 is not interactive, exits.  Otherwise, the value of @var{parameter} is
1648 substituted.
1649
1650 @item $@{@var{parameter}:+@var{word}@}
1651 If @var{parameter}
1652 is null or unset, nothing is substituted, otherwise the expansion of
1653 @var{word} is substituted.
1654
1655 @item $@{@var{parameter}:@var{offset}@}
1656 @itemx $@{@var{parameter}:@var{offset}:@var{length}@}
1657 Expands to up to @var{length} characters of @var{parameter}
1658 starting at the character specified by @var{offset}.
1659 If @var{length} is omitted, expands to the substring of
1660 @var{parameter} starting at the character specified by @var{offset}.
1661 @var{length} and @var{offset} are arithmetic expressions
1662 (@pxref{Shell Arithmetic}).
1663 This is referred to as Substring Expansion.
1664
1665 @var{length} must evaluate to a number greater than or equal to zero.
1666 If @var{offset} evaluates to a number less than zero, the value
1667 is used as an offset from the end of the value of @var{parameter}.
1668 If @var{parameter} is @samp{@@}, the result is @var{length} positional
1669 parameters beginning at @var{offset}.
1670 If @var{parameter} is an indexed array name subscripted
1671 by @samp{@@} or @samp{*}, the result is the @var{length}
1672 members of the array beginning with @code{$@{@var{parameter}[@var{offset}]@}}.
1673 A negative @var{offset} is taken relative to one greater than the maximum
1674 index of the specified array.
1675 Substring expansion applied to an associative array produces undefined
1676 results.
1677
1678 Note that a negative offset must be separated from the colon by at least
1679 one space to avoid being confused with the @samp{:-} expansion.
1680 Substring indexing is zero-based unless the positional parameters
1681 are used, in which case the indexing starts at 1 by default.
1682 If @var{offset} is 0, and the positional parameters are used, @code{$@@} is
1683 prefixed to the list.
1684
1685 @item $@{!@var{prefix}*@}
1686 @itemx $@{!@var{prefix}@@@}
1687 Expands to the names of variables whose names begin with @var{prefix},
1688 separated by the first character of the @env{IFS} special variable.
1689 When @samp{@@} is used and the expansion appears within double quotes, each
1690 variable name expands to a separate word.
1691
1692 @item $@{!@var{name}[@@]@}
1693 @itemx $@{!@var{name}[*]@}
1694 If @var{name} is an array variable, expands to the list of array indices
1695 (keys) assigned in @var{name}.
1696 If @var{name} is not an array, expands to 0 if @var{name} is set and null
1697 otherwise.
1698 When @samp{@@} is used and the expansion appears within double quotes, each
1699 key expands to a separate word.
1700
1701 @item $@{#@var{parameter}@}
1702 The length in characters of the expanded value of @var{parameter} is
1703 substituted.
1704 If @var{parameter} is @samp{*} or @samp{@@}, the value substituted
1705 is the number of positional parameters.
1706 If @var{parameter} is an array name subscripted by @samp{*} or @samp{@@}, 
1707 the value substituted is the number of elements in the array.
1708
1709 @item $@{@var{parameter}#@var{word}@}
1710 @itemx $@{@var{parameter}##@var{word}@}
1711 The @var{word}
1712 is expanded to produce a pattern just as in filename
1713 expansion (@pxref{Filename Expansion}).  If the pattern matches
1714 the beginning of the expanded value of @var{parameter},
1715 then the result of the expansion is the expanded value of @var{parameter}
1716 with the shortest matching pattern (the @samp{#} case) or the
1717 longest matching pattern (the @samp{##} case) deleted.
1718 If @var{parameter} is @samp{@@} or @samp{*},
1719 the pattern removal operation is applied to each positional
1720 parameter in turn, and the expansion is the resultant list.
1721 If @var{parameter} is an array variable subscripted with
1722 @samp{@@} or @samp{*},
1723 the pattern removal operation is applied to each member of the
1724 array in turn, and the expansion is the resultant list.
1725
1726 @item $@{@var{parameter}%@var{word}@}
1727 @itemx $@{@var{parameter}%%@var{word}@}
1728 The @var{word} is expanded to produce a pattern just as in
1729 filename expansion.
1730 If the pattern matches a trailing portion of the expanded value of
1731 @var{parameter}, then the result of the expansion is the value of
1732 @var{parameter} with the shortest matching pattern (the @samp{%} case)
1733 or the longest matching pattern (the @samp{%%} case) deleted.
1734 If @var{parameter} is @samp{@@} or @samp{*},
1735 the pattern removal operation is applied to each positional
1736 parameter in turn, and the expansion is the resultant list.
1737 If @var{parameter}
1738 is an array variable subscripted with @samp{@@} or @samp{*},
1739 the pattern removal operation is applied to each member of the
1740 array in turn, and the expansion is the resultant list.
1741
1742 @item $@{@var{parameter}/@var{pattern}/@var{string}@} 
1743
1744 The @var{pattern} is expanded to produce a pattern just as in
1745 filename expansion.
1746 @var{Parameter} is expanded and the longest match of @var{pattern}
1747 against its value is replaced with @var{string}.
1748 If @var{pattern} begins with @samp{/}, all matches of @var{pattern} are
1749 replaced with @var{string}.  Normally only the first match is replaced.
1750 If @var{pattern} begins with @samp{#}, it must match at the beginning
1751 of the expanded value of @var{parameter}.
1752 If @var{pattern} begins with @samp{%}, it must match at the end
1753 of the expanded value of @var{parameter}.
1754 If @var{string} is null, matches of @var{pattern} are deleted
1755 and the @code{/} following @var{pattern} may be omitted.
1756 If @var{parameter} is @samp{@@} or @samp{*},
1757 the substitution operation is applied to each positional
1758 parameter in turn, and the expansion is the resultant list.
1759 If @var{parameter}
1760 is an array variable subscripted with @samp{@@} or @samp{*},
1761 the substitution operation is applied to each member of the
1762 array in turn, and the expansion is the resultant list.
1763
1764 @item $@{@var{parameter}^@var{pattern}@}
1765 @itemx $@{@var{parameter}^^@var{pattern}@}
1766 @itemx $@{@var{parameter},@var{pattern}@}
1767 @itemx $@{@var{parameter},,@var{pattern}@}
1768 This expansion modifies the case of alphabetic characters in @var{parameter}.
1769 The @var{pattern} is expanded to produce a pattern just as in
1770 pathname expansion.
1771 The @samp{^} operator converts lowercase letters matching @var{pattern}
1772 to uppercase; the @samp{,} operator converts matching uppercase letters
1773 to lowercase.
1774 The @samp{^^} and @samp{,,} expansions convert each matched character in the
1775 expanded value; the @samp{^} and @samp{,} expansions match and convert only
1776 the first character in the expanded value.
1777 If @var{pattern} is omitted, it is treated like a @samp{?}, which matches
1778 every character.
1779 If @var{parameter} is @samp{@@} or @samp{*},
1780 the case modification operation is applied to each positional
1781 parameter in turn, and the expansion is the resultant list.
1782 If @var{parameter}
1783 is an array variable subscripted with @samp{@@} or @samp{*},
1784 the case modification operation is applied to each member of the
1785 array in turn, and the expansion is the resultant list.
1786
1787 @end table
1788
1789 @node Command Substitution
1790 @subsection Command Substitution
1791 @cindex command substitution
1792
1793 Command substitution allows the output of a command to replace
1794 the command itself.
1795 Command substitution occurs when a command is enclosed as follows:
1796 @example
1797 $(@var{command})
1798 @end example
1799 @noindent
1800 or
1801 @example
1802 `@var{command}`
1803 @end example
1804
1805 @noindent
1806 Bash performs the expansion by executing @var{command} and
1807 replacing the command substitution with the standard output of the
1808 command, with any trailing newlines deleted.
1809 Embedded newlines are not deleted, but they may be removed during
1810 word splitting.
1811 The command substitution @code{$(cat @var{file})} can be
1812 replaced by the equivalent but faster @code{$(< @var{file})}.
1813
1814 When the old-style backquote form of substitution is used,
1815 backslash retains its literal meaning except when followed by
1816 @samp{$}, @samp{`}, or @samp{\}. 
1817 The first backquote not preceded by a backslash terminates the
1818 command substitution.
1819 When using the @code{$(@var{command})} form, all characters between
1820 the parentheses make up the command; none are treated specially.
1821
1822 Command substitutions may be nested.  To nest when using the backquoted
1823 form, escape the inner backquotes with backslashes.
1824
1825 If the substitution appears within double quotes, word splitting and
1826 filename expansion are not performed on the results.
1827
1828 @node Arithmetic Expansion
1829 @subsection Arithmetic Expansion
1830 @cindex expansion, arithmetic
1831 @cindex arithmetic expansion
1832
1833 Arithmetic expansion allows the evaluation of an arithmetic expression
1834 and the substitution of the result.  The format for arithmetic expansion is:
1835
1836 @example
1837 $(( @var{expression} ))
1838 @end example
1839
1840 The expression is treated as if it were within double quotes, but
1841 a double quote inside the parentheses is not treated specially.
1842 All tokens in the expression undergo parameter expansion, command
1843 substitution, and quote removal.
1844 Arithmetic expansions may be nested. 
1845
1846 The evaluation is performed according to the rules listed below
1847 (@pxref{Shell Arithmetic}).
1848 If the expression is invalid, Bash prints a message indicating
1849 failure to the standard error and no substitution occurs.
1850
1851 @node Process Substitution
1852 @subsection Process Substitution
1853 @cindex process substitution
1854
1855 Process substitution is supported on systems that support named
1856 pipes (@sc{fifo}s) or the @file{/dev/fd} method of naming open files.
1857 It takes the form of 
1858 @example
1859 <(@var{list})
1860 @end example
1861 @noindent
1862 or
1863 @example
1864 >(@var{list})
1865 @end example
1866 @noindent
1867 The process @var{list} is run with its input or output connected to a
1868 @sc{fifo} or some file in @file{/dev/fd}.  The name of this file is
1869 passed as an argument to the current command as the result of the
1870 expansion.  If the @code{>(@var{list})} form is used, writing to
1871 the file will provide input for @var{list}.  If the
1872 @code{<(@var{list})} form is used, the file passed as an
1873 argument should be read to obtain the output of @var{list}.
1874 Note that no space may appear between the @code{<} or @code{>}
1875 and the left parenthesis, otherwise the construct would be interpreted
1876 as a redirection.
1877
1878 When available, process substitution is performed simultaneously with
1879 parameter and variable expansion, command substitution, and arithmetic
1880 expansion.
1881
1882 @node Word Splitting
1883 @subsection Word Splitting
1884 @cindex word splitting
1885
1886 The shell scans the results of parameter expansion, command substitution,
1887 and arithmetic expansion that did not occur within double quotes for
1888 word splitting.
1889
1890 The shell treats each character of @env{$IFS} as a delimiter, and splits
1891 the results of the other expansions into words on these characters.
1892 If @env{IFS} is unset, or its value is exactly @code{<space><tab><newline>},
1893 the default, then sequences of
1894 @code{ <space>}, @code{<tab>}, and @code{<newline>}
1895 at the beginning and end of the results of the previous
1896 expansions are ignored, and any sequence of @env{IFS}
1897 characters not at the beginning or end serves to delimit words.
1898 If @env{IFS} has a value other than the default, then sequences of
1899 the whitespace characters @code{space} and @code{tab}
1900 are ignored at the beginning and end of the
1901 word, as long as the whitespace character is in the
1902 value of @env{IFS} (an @env{IFS} whitespace character).
1903 Any character in @env{IFS} that is not @env{IFS}
1904 whitespace, along with any adjacent @env{IFS}
1905 whitespace characters, delimits a field.  A sequence of @env{IFS}
1906 whitespace characters is also treated as a delimiter.
1907 If the value of @env{IFS} is null, no word splitting occurs.
1908
1909 Explicit null arguments (@code{""} or @code{''}) are retained.
1910 Unquoted implicit null arguments, resulting from the expansion of
1911 parameters that have no values, are removed.
1912 If a parameter with no value is expanded within double quotes, a
1913 null argument results and is retained.
1914
1915 Note that if no expansion occurs, no splitting
1916 is performed.
1917
1918 @node Filename Expansion
1919 @subsection Filename Expansion
1920 @menu
1921 * Pattern Matching::    How the shell matches patterns.
1922 @end menu
1923 @cindex expansion, filename
1924 @cindex expansion, pathname
1925 @cindex filename expansion
1926 @cindex pathname expansion
1927
1928 After word splitting, unless the @option{-f} option has been set
1929 (@pxref{The Set Builtin}), Bash scans each word for the characters
1930 @samp{*}, @samp{?}, and @samp{[}.
1931 If one of these characters appears, then the word is
1932 regarded as a @var{pattern},
1933 and replaced with an alphabetically sorted list of
1934 file names matching the pattern. If no matching file names are found,
1935 and the shell option @code{nullglob} is disabled, the word is left
1936 unchanged.
1937 If the @code{nullglob} option is set, and no matches are found, the word
1938 is removed.
1939 If the @code{failglob} shell option is set, and no matches are found,
1940 an error message is printed and the command is not executed.
1941 If the shell option @code{nocaseglob} is enabled, the match is performed
1942 without regard to the case of alphabetic characters.
1943
1944 When a pattern is used for filename generation, the character @samp{.}
1945 at the start of a filename or immediately following a slash
1946 must be matched explicitly, unless the shell option @code{dotglob} is set.
1947 When matching a file name, the slash character must always be
1948 matched explicitly.
1949 In other cases, the @samp{.} character is not treated specially.
1950
1951 See the description of @code{shopt} in @ref{The Shopt Builtin},
1952 for a description of the @code{nocaseglob}, @code{nullglob},
1953 @code{failglob}, and @code{dotglob} options.
1954
1955 The @env{GLOBIGNORE}
1956 shell variable may be used to restrict the set of filenames matching a
1957 pattern.  If @env{GLOBIGNORE}
1958 is set, each matching filename that also matches one of the patterns in
1959 @env{GLOBIGNORE} is removed from the list of matches.  The filenames
1960 @file{.} and @file{..}
1961 are always ignored when @env{GLOBIGNORE}
1962 is set and not null.
1963 However, setting @env{GLOBIGNORE} to a non-null value has the effect of
1964 enabling the @code{dotglob}
1965 shell option, so all other filenames beginning with a
1966 @samp{.} will match.
1967 To get the old behavior of ignoring filenames beginning with a
1968 @samp{.}, make @samp{.*} one of the patterns in @env{GLOBIGNORE}.
1969 The @code{dotglob} option is disabled when @env{GLOBIGNORE}
1970 is unset.
1971
1972 @node Pattern Matching
1973 @subsubsection Pattern Matching
1974 @cindex pattern matching
1975 @cindex matching, pattern
1976
1977 Any character that appears in a pattern, other than the special pattern
1978 characters described below, matches itself.
1979 The @sc{nul} character may not occur in a pattern.
1980 A backslash escapes the following character; the
1981 escaping backslash is discarded when matching.
1982 The special pattern characters must be quoted if they are to be matched
1983 literally.
1984
1985 The special pattern characters have the following meanings:
1986 @table @code
1987 @item *
1988 Matches any string, including the null string.
1989 When the @code{globstar} shell option is enabled, and @samp{*} is used in
1990 a filename expansion context, two adjacent @samp{*}s used as a single
1991 pattern will match all files and zero or more directories and
1992 subdirectories.
1993 If followed by a @samp{/}, two adjacent @samp{*}s will match only
1994 directories and subdirectories.
1995 @item ?
1996 Matches any single character.
1997 @item [@dots{}]
1998 Matches any one of the enclosed characters.  A pair of characters
1999 separated by a hyphen denotes a @var{range expression};
2000 any character that sorts between those two characters, inclusive,
2001 using the current locale's collating sequence and character set,
2002 is matched.  If the first character following the
2003 @samp{[} is a @samp{!}  or a @samp{^}
2004 then any character not enclosed is matched.  A @samp{@minus{}}
2005 may be matched by including it as the first or last character
2006 in the set.  A @samp{]} may be matched by including it as the first
2007 character in the set.
2008 The sorting order of characters in range expressions is determined by
2009 the current locale and the value of the @env{LC_COLLATE} shell variable,
2010 if set.
2011
2012 For example, in the default C locale, @samp{[a-dx-z]} is equivalent to
2013 @samp{[abcdxyz]}.  Many locales sort characters in dictionary order, and in
2014 these locales @samp{[a-dx-z]} is typically not equivalent to @samp{[abcdxyz]};
2015 it might be equivalent to @samp{[aBbCcDdxXyYz]}, for example.  To obtain
2016 the traditional interpretation of ranges in bracket expressions, you can
2017 force the use of the C locale by setting the @env{LC_COLLATE} or
2018 @env{LC_ALL} environment variable to the value @samp{C}.
2019
2020 Within @samp{[} and @samp{]}, @var{character classes} can be specified
2021 using the syntax
2022 @code{[:}@var{class}@code{:]}, where @var{class} is one of the
2023 following classes defined in the @sc{posix} standard:
2024 @example
2025 alnum   alpha   ascii   blank   cntrl   digit   graph   lower
2026 print   punct   space   upper   word    xdigit
2027 @end example
2028 @noindent
2029 A character class matches any character belonging to that class.
2030 The @code{word} character class matches letters, digits, and the character
2031 @samp{_}.
2032
2033 Within @samp{[} and @samp{]}, an @var{equivalence class} can be
2034 specified using the syntax @code{[=}@var{c}@code{=]}, which
2035 matches all characters with the same collation weight (as defined
2036 by the current locale) as the character @var{c}.
2037
2038 Within @samp{[} and @samp{]}, the syntax @code{[.}@var{symbol}@code{.]}
2039 matches the collating symbol @var{symbol}.
2040 @end table
2041
2042 If the @code{extglob} shell option is enabled using the @code{shopt}
2043 builtin, several extended pattern matching operators are recognized.
2044 In the following description, a @var{pattern-list} is a list of one
2045 or more patterns separated by a @samp{|}.
2046 Composite patterns may be formed using one or more of the following
2047 sub-patterns:
2048
2049 @table @code
2050 @item ?(@var{pattern-list})
2051 Matches zero or one occurrence of the given patterns.
2052
2053 @item *(@var{pattern-list})
2054 Matches zero or more occurrences of the given patterns.
2055
2056 @item +(@var{pattern-list})
2057 Matches one or more occurrences of the given patterns.
2058
2059 @item @@(@var{pattern-list})
2060 Matches one of the given patterns.
2061
2062 @item !(@var{pattern-list})
2063 Matches anything except one of the given patterns.
2064 @end table
2065
2066 @node Quote Removal
2067 @subsection Quote Removal
2068
2069 After the preceding expansions, all unquoted occurrences of the
2070 characters @samp{\}, @samp{'}, and @samp{"} that did not
2071 result from one of the above expansions are removed.
2072
2073 @node Redirections
2074 @section Redirections
2075 @cindex redirection
2076
2077 Before a command is executed, its input and output
2078 may be @var{redirected}
2079 using a special notation interpreted by the shell.
2080 Redirection may also be used to open and close files for the
2081 current shell execution environment.  The following redirection
2082 operators may precede or appear anywhere within a
2083 simple command or may follow a command.
2084 Redirections are processed in the order they appear, from
2085 left to right.
2086
2087 In the following descriptions, if the file descriptor number is
2088 omitted, and the first character of the redirection operator is
2089 @samp{<}, the redirection refers to the standard input (file
2090 descriptor 0).  If the first character of the redirection operator
2091 is @samp{>}, the redirection refers to the standard output (file
2092 descriptor 1).
2093
2094 The word following the redirection operator in the following
2095 descriptions, unless otherwise noted, is subjected to brace expansion,
2096 tilde expansion, parameter expansion, command substitution, arithmetic
2097 expansion, quote removal, filename expansion, and word splitting.
2098 If it expands to more than one word, Bash reports an error.
2099
2100 Note that the order of redirections is significant.  For example,
2101 the command
2102 @example
2103 ls > @var{dirlist} 2>&1
2104 @end example
2105 @noindent
2106 directs both standard output (file descriptor 1) and standard error
2107 (file descriptor 2) to the file @var{dirlist}, while the command
2108 @example
2109 ls 2>&1 > @var{dirlist}
2110 @end example
2111 @noindent
2112 directs only the standard output to file @var{dirlist},
2113 because the standard error was made a copy of the standard output
2114 before the standard output was redirected to @var{dirlist}.
2115
2116 Bash handles several filenames specially when they are used in
2117 redirections, as described in the following table:
2118
2119 @table @code
2120 @item /dev/fd/@var{fd}
2121 If @var{fd} is a valid integer, file descriptor @var{fd} is duplicated.
2122
2123 @item /dev/stdin
2124 File descriptor 0 is duplicated.
2125
2126 @item /dev/stdout
2127 File descriptor 1 is duplicated.
2128
2129 @item /dev/stderr
2130 File descriptor 2 is duplicated.
2131
2132 @item /dev/tcp/@var{host}/@var{port}
2133 If @var{host} is a valid hostname or Internet address, and @var{port}
2134 is an integer port number or service name, Bash attempts to open a TCP
2135 connection to the corresponding socket.
2136
2137 @item /dev/udp/@var{host}/@var{port}
2138 If @var{host} is a valid hostname or Internet address, and @var{port}
2139 is an integer port number or service name, Bash attempts to open a UDP
2140 connection to the corresponding socket.
2141
2142 @end table
2143
2144 A failure to open or create a file causes the redirection to fail.
2145
2146 Redirections using file descriptors greater than 9 should be used with
2147 care, as they may conflict with file descriptors the shell uses
2148 internally.
2149
2150 @subsection Redirecting Input
2151 Redirection of input causes the file whose name results from
2152 the expansion of @var{word}
2153 to be opened for reading on file descriptor @code{n},
2154 or the standard input (file descriptor 0) if @code{n}
2155 is not specified.
2156
2157 The general format for redirecting input is:
2158 @example
2159 [@var{n}]<@var{word}
2160 @end example
2161
2162 @subsection Redirecting Output
2163 Redirection of output causes the file whose name results from
2164 the expansion of @var{word}
2165 to be opened for writing on file descriptor @var{n},
2166 or the standard output (file descriptor 1) if @var{n}
2167 is not specified.  If the file does not exist it is created;
2168 if it does exist it is truncated to zero size.
2169
2170 The general format for redirecting output is:
2171 @example
2172 [@var{n}]>[|]@var{word}
2173 @end example
2174
2175 If the redirection operator is @samp{>}, and the @code{noclobber}
2176 option to the @code{set} builtin has been enabled, the redirection
2177 will fail if the file whose name results from the expansion of
2178 @var{word} exists and is a regular file.
2179 If the redirection operator is @samp{>|}, or the redirection operator is
2180 @samp{>} and the @code{noclobber} option is not enabled, the redirection
2181 is attempted even if the file named by @var{word} exists.
2182
2183 @subsection Appending Redirected Output
2184 Redirection of output in this fashion
2185 causes the file whose name results from
2186 the expansion of @var{word}
2187 to be opened for appending on file descriptor @var{n},
2188 or the standard output (file descriptor 1) if @var{n}
2189 is not specified.  If the file does not exist it is created.
2190
2191 The general format for appending output is:
2192 @example
2193 [@var{n}]>>@var{word}
2194 @end example
2195
2196 @subsection Redirecting Standard Output and Standard Error
2197 This construct allows both the
2198 standard output (file descriptor 1) and
2199 the standard error output (file descriptor 2)
2200 to be redirected to the file whose name is the
2201 expansion of @var{word}.
2202
2203 There are two formats for redirecting standard output and
2204 standard error:
2205 @example
2206 &>@var{word}
2207 @end example
2208 @noindent
2209 and
2210 @example
2211 >&@var{word}
2212 @end example
2213 @noindent
2214 Of the two forms, the first is preferred.
2215 This is semantically equivalent to
2216 @example
2217 >@var{word} 2>&1
2218 @end example
2219
2220 @subsection Appending Standard Output and Standard Error
2221 This construct allows both the
2222 standard output (file descriptor 1) and
2223 the standard error output (file descriptor 2)
2224 to be appended to the file whose name is the
2225 expansion of @var{word}.
2226
2227 The format for appending standard output and standard error is:
2228 @example
2229 &>>@var{word}
2230 @end example
2231 @noindent
2232 This is semantically equivalent to
2233 @example
2234 >>@var{word} 2>&1
2235 @end example
2236
2237 @subsection Here Documents
2238 This type of redirection instructs the shell to read input from the
2239 current source until a line containing only @var{word}
2240 (with no trailing blanks) is seen.  All of
2241 the lines read up to that point are then used as the standard
2242 input for a command.
2243
2244 The format of here-documents is:
2245 @example
2246 <<[@minus{}]@var{word}
2247         @var{here-document}
2248 @var{delimiter}
2249 @end example
2250
2251 No parameter expansion, command substitution, arithmetic expansion,
2252 or filename expansion is performed on
2253 @var{word}.  If any characters in @var{word} are quoted, the
2254 @var{delimiter} is the result of quote removal on @var{word},
2255 and the lines in the here-document are not expanded.
2256 If @var{word} is unquoted,
2257 all lines of the here-document are subjected to parameter expansion,
2258 command substitution, and arithmetic expansion.  In the latter
2259 case, the character sequence @code{\newline} is ignored, and @samp{\}
2260 must be used to quote the characters
2261 @samp{\}, @samp{$}, and @samp{`}.
2262
2263 If the redirection operator is @samp{<<-},
2264 then all leading tab characters are stripped from input lines and the
2265 line containing @var{delimiter}.
2266 This allows here-documents within shell scripts to be indented in a
2267 natural fashion.
2268
2269 @subsection Here Strings
2270 A variant of here documents, the format is:
2271 @example
2272 <<< @var{word}
2273 @end example
2274
2275 The @var{word} is expanded and supplied to the command on its standard
2276 input.
2277
2278 @subsection Duplicating File Descriptors
2279 The redirection operator
2280 @example
2281 [@var{n}]<&@var{word}
2282 @end example
2283 @noindent
2284 is used to duplicate input file descriptors.
2285 If @var{word}
2286 expands to one or more digits, the file descriptor denoted by @var{n}
2287 is made to be a copy of that file descriptor.
2288 If the digits in @var{word} do not specify a file descriptor open for
2289 input, a redirection error occurs.
2290 If @var{word}
2291 evaluates to @samp{-}, file descriptor @var{n} is closed.  If
2292 @var{n} is not specified, the standard input (file descriptor 0) is used.
2293
2294 The operator
2295 @example
2296 [@var{n}]>&@var{word}
2297 @end example
2298 @noindent
2299 is used similarly to duplicate output file descriptors.  If
2300 @var{n} is not specified, the standard output (file descriptor 1) is used.
2301 If the digits in @var{word} do not specify a file descriptor open for
2302 output, a redirection error occurs.
2303 As a special case, if @var{n} is omitted, and @var{word} does not
2304 expand to one or more digits, the standard output and standard
2305 error are redirected as described previously.
2306
2307 @subsection Moving File Descriptors
2308 The redirection operator
2309 @example
2310 [@var{n}]<&@var{digit}-
2311 @end example
2312 @noindent
2313 moves the file descriptor @var{digit} to file descriptor @var{n},
2314 or the standard input (file descriptor 0) if @var{n} is not specified.
2315 @var{digit} is closed after being duplicated to @var{n}.
2316
2317 Similarly, the redirection operator
2318 @example
2319 [@var{n}]>&@var{digit}-
2320 @end example
2321 @noindent
2322 moves the file descriptor @var{digit} to file descriptor @var{n},
2323 or the standard output (file descriptor 1) if @var{n} is not specified.
2324
2325 @subsection Opening File Descriptors for Reading and Writing
2326 The redirection operator
2327 @example
2328 [@var{n}]<>@var{word}
2329 @end example
2330 @noindent
2331 causes the file whose name is the expansion of @var{word}
2332 to be opened for both reading and writing on file descriptor
2333 @var{n}, or on file descriptor 0 if @var{n}
2334 is not specified.  If the file does not exist, it is created.
2335
2336 @node Executing Commands
2337 @section Executing Commands
2338
2339 @menu
2340 * Simple Command Expansion::    How Bash expands simple commands before
2341                                 executing them.
2342 * Command Search and Execution::        How Bash finds commands and runs them.
2343 * Command Execution Environment::       The environment in which Bash
2344                                         executes commands that are not
2345                                         shell builtins.
2346 * Environment::         The environment given to a command.
2347 * Exit Status::         The status returned by commands and how Bash
2348                         interprets it.
2349 * Signals::             What happens when Bash or a command it runs
2350                         receives a signal.
2351 @end menu
2352
2353 @node Simple Command Expansion
2354 @subsection Simple Command Expansion
2355 @cindex command expansion
2356
2357 When a simple command is executed, the shell performs the following
2358 expansions, assignments, and redirections, from left to right.
2359
2360 @enumerate
2361 @item
2362 The words that the parser has marked as variable assignments (those
2363 preceding the command name) and redirections are saved for later
2364 processing.
2365
2366 @item
2367 The words that are not variable assignments or redirections are
2368 expanded (@pxref{Shell Expansions}).
2369 If any words remain after expansion, the first word
2370 is taken to be the name of the command and the remaining words are
2371 the arguments.
2372
2373 @item
2374 Redirections are performed as described above (@pxref{Redirections}).
2375
2376 @item
2377 The text after the @samp{=} in each variable assignment undergoes tilde
2378 expansion, parameter expansion, command substitution, arithmetic expansion,
2379 and quote removal before being assigned to the variable.
2380 @end enumerate
2381
2382 If no command name results, the variable assignments affect the current
2383 shell environment.  Otherwise, the variables are added to the environment
2384 of the executed command and do not affect the current shell environment.
2385 If any of the assignments attempts to assign a value to a readonly variable,
2386 an error occurs, and the command exits with a non-zero status.
2387
2388 If no command name results, redirections are performed, but do not
2389 affect the current shell environment.  A redirection error causes the
2390 command to exit with a non-zero status.
2391
2392 If there is a command name left after expansion, execution proceeds as
2393 described below.  Otherwise, the command exits.  If one of the expansions
2394 contained a command substitution, the exit status of the command is
2395 the exit status of the last command substitution performed.  If there
2396 were no command substitutions, the command exits with a status of zero.
2397
2398 @node Command Search and Execution
2399 @subsection Command Search and Execution
2400 @cindex command execution
2401 @cindex command search
2402
2403 After a command has been split into words, if it results in a
2404 simple command and an optional list of arguments, the following
2405 actions are taken.
2406
2407 @enumerate
2408 @item
2409 If the command name contains no slashes, the shell attempts to
2410 locate it.  If there exists a shell function by that name, that
2411 function is invoked as described in @ref{Shell Functions}.
2412
2413 @item
2414 If the name does not match a function, the shell searches for
2415 it in the list of shell builtins.  If a match is found, that
2416 builtin is invoked.
2417
2418 @item
2419 If the name is neither a shell function nor a builtin,
2420 and contains no slashes, Bash searches each element of
2421 @env{$PATH} for a directory containing an executable file
2422 by that name.  Bash uses a hash table to remember the full
2423 pathnames of executable files to avoid multiple @env{PATH} searches
2424 (see the description of @code{hash} in @ref{Bourne Shell Builtins}).
2425 A full search of the directories in @env{$PATH}
2426 is performed only if the command is not found in the hash table.
2427 If the search is unsuccessful, the shell searches for a defined shell
2428 function named @code{command_not_found_handle}.
2429 If that function exists, it is invoked with the original command and
2430 the original command's arguments as its arguments, and the function's
2431 exit status becomes the exit status of the shell.
2432 If that function is not defined, the shell prints an error
2433 message and returns an exit status of 127.
2434
2435 @item
2436 If the search is successful, or if the command name contains
2437 one or more slashes, the shell executes the named program in
2438 a separate execution environment.
2439 Argument 0 is set to the name given, and the remaining arguments
2440 to the command are set to the arguments supplied, if any.
2441
2442 @item
2443 If this execution fails because the file is not in executable
2444 format, and the file is not a directory, it is assumed to be a
2445 @var{shell script} and the shell executes it as described in
2446 @ref{Shell Scripts}.
2447
2448 @item
2449 If the command was not begun asynchronously, the shell waits for
2450 the command to complete and collects its exit status.
2451
2452 @end enumerate
2453
2454 @node Command Execution Environment
2455 @subsection Command Execution Environment
2456 @cindex execution environment
2457
2458 The shell has an @var{execution environment}, which consists of the
2459 following:
2460
2461 @itemize @bullet
2462 @item
2463 open files inherited by the shell at invocation, as modified by
2464 redirections supplied to the @code{exec} builtin
2465
2466 @item
2467 the current working directory as set by @code{cd}, @code{pushd}, or
2468 @code{popd}, or inherited by the shell at invocation
2469
2470 @item
2471 the file creation mode mask as set by @code{umask} or inherited from
2472 the shell's parent
2473
2474 @item
2475 current traps set by @code{trap}
2476
2477 @item
2478 shell parameters that are set by variable assignment or with @code{set}
2479 or inherited from the shell's parent in the environment
2480
2481 @item
2482 shell functions defined during execution or inherited from the shell's
2483 parent in the environment
2484
2485 @item
2486 options enabled at invocation (either by default or with command-line
2487 arguments) or by @code{set}
2488
2489 @item
2490 options enabled by @code{shopt} (@pxref{The Shopt Builtin})
2491
2492 @item
2493 shell aliases defined with @code{alias} (@pxref{Aliases})
2494
2495 @item
2496 various process @sc{id}s, including those of background jobs
2497 (@pxref{Lists}), the value of @code{$$}, and the value of
2498 @env{$PPID}
2499
2500 @end itemize
2501
2502 When a simple command other than a builtin or shell function
2503 is to be executed, it
2504 is invoked in a separate execution environment that consists of
2505 the following.  Unless otherwise noted, the values are inherited
2506 from the shell.
2507
2508 @itemize @bullet
2509 @item
2510 the shell's open files, plus any modifications and additions specified
2511 by redirections to the command
2512
2513 @item
2514 the current working directory
2515
2516 @item
2517 the file creation mode mask
2518
2519 @item
2520 shell variables and functions marked for export, along with variables
2521 exported for the command, passed in the environment (@pxref{Environment})
2522
2523 @item
2524 traps caught by the shell are reset to the values inherited from the
2525 shell's parent, and traps ignored by the shell are ignored
2526
2527 @end itemize
2528
2529 A command invoked in this separate environment cannot affect the
2530 shell's execution environment. 
2531
2532 Command substitution, commands grouped with parentheses,
2533 and asynchronous commands are invoked in a
2534 subshell environment that is a duplicate of the shell environment,
2535 except that traps caught by the shell are reset to the values
2536 that the shell inherited from its parent at invocation.  Builtin
2537 commands that are invoked as part of a pipeline are also executed
2538 in a subshell environment.  Changes made to the subshell environment
2539 cannot affect the shell's execution environment.
2540
2541 Subshells spawned to execute command substitutions inherit the value of
2542 the @option{-e} option from the parent shell.  When not in @sc{posix} mode,
2543 Bash clears the @option{-e} option in such subshells.
2544
2545 If a command is followed by a @samp{&} and job control is not active, the
2546 default standard input for the command is the empty file @file{/dev/null}.
2547 Otherwise, the invoked command inherits the file descriptors of the calling
2548 shell as modified by redirections.
2549
2550 @node Environment
2551 @subsection Environment
2552 @cindex environment
2553
2554 When a program is invoked it is given an array of strings
2555 called the @var{environment}.
2556 This is a list of name-value pairs, of the form @code{name=value}.
2557
2558 Bash provides several ways to manipulate the environment.
2559 On invocation, the shell scans its own environment and
2560 creates a parameter for each name found, automatically marking
2561 it for @var{export}
2562 to child processes.  Executed commands inherit the environment.
2563 The @code{export} and @samp{declare -x}
2564 commands allow parameters and functions to be added to and
2565 deleted from the environment.  If the value of a parameter
2566 in the environment is modified, the new value becomes part
2567 of the environment, replacing the old.  The environment
2568 inherited by any executed command consists of the shell's
2569 initial environment, whose values may be modified in the shell,
2570 less any pairs removed by the @code{unset} and @samp{export -n}
2571 commands, plus any additions via the @code{export} and
2572 @samp{declare -x} commands.
2573
2574 The environment for any simple command
2575 or function may be augmented temporarily by prefixing it with
2576 parameter assignments, as described in @ref{Shell Parameters}.
2577 These assignment statements affect only the environment seen
2578 by that command.
2579
2580 If the @option{-k} option is set (@pxref{The Set Builtin}), then all
2581 parameter assignments are placed in the environment for a command,
2582 not just those that precede the command name.
2583
2584 When Bash invokes an external command, the variable @samp{$_}
2585 is set to the full path name of the command and passed to that
2586 command in its environment.
2587
2588 @node Exit Status
2589 @subsection Exit Status
2590 @cindex exit status
2591
2592 The exit status of an executed command is the value returned by the
2593 @var{waitpid} system call or equivalent function.  Exit statuses    
2594 fall between 0 and 255, though, as explained below, the shell may
2595 use values above 125 specially.  Exit statuses from shell builtins and
2596 compound commands are also limited to this range. Under certain
2597 circumstances, the shell will use special values to indicate specific
2598 failure modes.
2599
2600 For the shell's purposes, a command which exits with a
2601 zero exit status has succeeded.
2602 A non-zero exit status indicates failure.
2603 This seemingly counter-intuitive scheme is used so there
2604 is one well-defined way to indicate success and a variety of
2605 ways to indicate various failure modes.
2606 When a command terminates on a fatal signal whose number is @var{N},
2607 Bash uses the value 128+@var{N} as the exit status.
2608
2609 If a command is not found, the child process created to
2610 execute it returns a status of 127.  If a command is found  
2611 but is not executable, the return status is 126.
2612
2613 If a command fails because of an error during expansion or redirection,
2614 the exit status is greater than zero.
2615
2616 The exit status is used by the Bash conditional commands
2617 (@pxref{Conditional Constructs}) and some of the list
2618 constructs (@pxref{Lists}).
2619
2620 All of the Bash builtins return an exit status of zero if they succeed
2621 and a non-zero status on failure, so they may be used by the
2622 conditional and list constructs.
2623 All builtins return an exit status of 2 to indicate incorrect usage.
2624
2625 @node Signals
2626 @subsection Signals
2627 @cindex signal handling
2628
2629 When Bash is interactive, in the absence of any traps, it ignores
2630 @code{SIGTERM} (so that @samp{kill 0} does not kill an interactive shell),
2631 and @code{SIGINT}
2632 is caught and handled (so that the @code{wait} builtin is interruptible).
2633 When Bash receives a @code{SIGINT}, it breaks out of any executing loops.
2634 In all cases, Bash ignores @code{SIGQUIT}.
2635 If job control is in effect (@pxref{Job Control}), Bash
2636 ignores @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
2637
2638 Non-builtin commands started by Bash have signal handlers set to the
2639 values inherited by the shell from its parent.
2640 When job control is not in effect, asynchronous commands
2641 ignore @code{SIGINT} and @code{SIGQUIT} in addition to these inherited
2642 handlers.
2643 Commands run as a result of
2644 command substitution ignore the keyboard-generated job control signals
2645 @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
2646
2647 The shell exits by default upon receipt of a @code{SIGHUP}.
2648 Before exiting, an interactive shell resends the @code{SIGHUP} to
2649 all jobs, running or stopped.
2650 Stopped jobs are sent @code{SIGCONT} to ensure that they receive
2651 the @code{SIGHUP}.
2652 To prevent the shell from sending the @code{SIGHUP} signal to a
2653 particular job, it should be removed
2654 from the jobs table with the @code{disown}
2655 builtin (@pxref{Job Control Builtins}) or marked
2656 to not receive @code{SIGHUP} using @code{disown -h}.
2657
2658 If the  @code{huponexit} shell option has been set with @code{shopt}
2659 (@pxref{The Shopt Builtin}), Bash sends a @code{SIGHUP} to all jobs when
2660 an interactive login shell exits.
2661
2662 If Bash is waiting for a command to complete and receives a signal
2663 for which a trap has been set, the trap will not be executed until
2664 the command completes. 
2665 When Bash is waiting for an asynchronous
2666 command via the @code{wait} builtin, the reception of a signal for
2667 which a trap has been set will cause the @code{wait} builtin to return
2668 immediately with an exit status greater than 128, immediately after
2669 which the trap is executed.
2670
2671 @node Shell Scripts
2672 @section Shell Scripts
2673 @cindex shell script
2674
2675 A shell script is a text file containing shell commands.  When such
2676 a file is used as the first non-option argument when invoking Bash,
2677 and neither the @option{-c} nor @option{-s} option is supplied
2678 (@pxref{Invoking Bash}), 
2679 Bash reads and executes commands from the file, then exits.  This
2680 mode of operation creates a non-interactive shell.  The shell first
2681 searches for the file in the current directory, and looks in the
2682 directories in @env{$PATH} if not found there.
2683
2684 When Bash runs
2685 a shell script, it sets the special parameter @code{0} to the name
2686 of the file, rather than the name of the shell, and the positional
2687 parameters are set to the remaining arguments, if any are given.
2688 If no additional arguments are supplied, the positional parameters
2689 are unset.
2690
2691 A shell script may be made executable by using the @code{chmod} command
2692 to turn on the execute bit.  When Bash finds such a file while
2693 searching the @env{$PATH} for a command, it spawns a subshell to
2694 execute it.  In other words, executing
2695 @example
2696 filename @var{arguments}
2697 @end example
2698 @noindent
2699 is equivalent to executing
2700 @example
2701 bash filename @var{arguments}
2702 @end example
2703
2704 @noindent
2705 if @code{filename} is an executable shell script.
2706 This subshell reinitializes itself, so that the effect is as if a
2707 new shell had been invoked to interpret the script, with the
2708 exception that the locations of commands remembered by the parent
2709 (see the description of @code{hash} in @ref{Bourne Shell Builtins})
2710 are retained by the child.
2711
2712 Most versions of Unix make this a part of the operating system's command
2713 execution mechanism.  If the first line of a script begins with
2714 the two characters @samp{#!}, the remainder of the line specifies
2715 an interpreter for the program.
2716 Thus, you can specify Bash, @code{awk}, Perl, or some other
2717 interpreter and write the rest of the script file in that language.
2718
2719 The arguments to the interpreter
2720 consist of a single optional argument following the interpreter
2721 name on the first line of the script file, followed by the name of
2722 the script file, followed by the rest of the arguments.  Bash
2723 will perform this action on operating systems that do not handle it
2724 themselves.  Note that some older versions of Unix limit the interpreter
2725 name and argument to a maximum of 32 characters.
2726
2727 Bash scripts often begin with @code{#! /bin/bash} (assuming that
2728 Bash has been installed in @file{/bin}), since this ensures that
2729 Bash will be used to interpret the script, even if it is executed
2730 under another shell.
2731
2732 @node Shell Builtin Commands
2733 @chapter Shell Builtin Commands
2734
2735 @menu
2736 * Bourne Shell Builtins::       Builtin commands inherited from the Bourne
2737                                 Shell.
2738 * Bash Builtins::               Table of builtins specific to Bash.
2739 * Modifying Shell Behavior::    Builtins to modify shell attributes and
2740                                 optional behavior.
2741 * Special Builtins::            Builtin commands classified specially by
2742                                 POSIX.
2743 @end menu
2744
2745 Builtin commands are contained within the shell itself.
2746 When the name of a builtin command is used as the first word of
2747 a simple command (@pxref{Simple Commands}), the shell executes
2748 the command directly, without invoking another program.
2749 Builtin commands are necessary to implement functionality impossible
2750 or inconvenient to obtain with separate utilities.
2751
2752 This section briefly describes the builtins which Bash inherits from
2753 the Bourne Shell, as well as the builtin commands which are unique
2754 to or have been extended in Bash.
2755
2756 Several builtin commands are described in other chapters:  builtin
2757 commands which provide the Bash interface to the job control
2758 facilities (@pxref{Job Control Builtins}), the directory stack
2759 (@pxref{Directory Stack Builtins}), the command history
2760 (@pxref{Bash History Builtins}), and the programmable completion
2761 facilities (@pxref{Programmable Completion Builtins}).
2762
2763 Many of the builtins have been extended by @sc{posix} or Bash.
2764
2765 Unless otherwise noted, each builtin command documented as accepting
2766 options preceded by @samp{-} accepts @samp{--}
2767 to signify the end of the options.
2768 For example, the @code{:}, @code{true}, @code{false}, and @code{test}
2769 builtins do not accept options.
2770
2771 @node Bourne Shell Builtins
2772 @section Bourne Shell Builtins
2773
2774 The following shell builtin commands are inherited from the Bourne Shell.
2775 These commands are implemented as specified by the @sc{posix} standard.
2776
2777 @table @code
2778 @item :    @r{(a colon)}
2779 @btindex :
2780 @example
2781 : [@var{arguments}]
2782 @end example
2783 Do nothing beyond expanding @var{arguments} and performing redirections.
2784 The return status is zero.
2785
2786 @item .    @r{(a period)}
2787 @btindex .
2788 @example
2789 . @var{filename} [@var{arguments}]
2790 @end example
2791 Read and execute commands from the @var{filename} argument in the
2792 current shell context.  If @var{filename} does not contain a slash,
2793 the @env{PATH} variable is used to find @var{filename}.
2794 When Bash is not in @sc{posix} mode, the current directory is searched
2795 if @var{filename} is not found in @env{$PATH}.
2796 If any @var{arguments} are supplied, they become the positional
2797 parameters when @var{filename} is executed.  Otherwise the positional
2798 parameters are unchanged.
2799 The return status is the exit status of the last command executed, or
2800 zero if no commands are executed.  If @var{filename} is not found, or
2801 cannot be read, the return status is non-zero.
2802 This builtin is equivalent to @code{source}.
2803
2804 @item break
2805 @btindex break
2806 @example
2807 break [@var{n}]
2808 @end example
2809 Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop.
2810 If @var{n} is supplied, the @var{n}th enclosing loop is exited.
2811 @var{n} must be greater than or equal to 1.
2812 The return status is zero unless @var{n} is not greater than or equal to 1.
2813
2814 @item cd
2815 @btindex cd
2816 @example
2817 cd [-L|-P] [@var{directory}]
2818 @end example
2819 Change the current working directory to @var{directory}.
2820 If @var{directory} is not given, the value of the @env{HOME} shell
2821 variable is used.
2822 If the shell variable @env{CDPATH} exists, it is used as a search path.
2823 If @var{directory} begins with a slash, @env{CDPATH} is not used.
2824
2825 The @option{-P} option means to not follow symbolic links; symbolic
2826 links are followed by default or with the @option{-L} option.
2827 If @var{directory} is @samp{-}, it is equivalent to @env{$OLDPWD}.
2828
2829 If a non-empty directory name from @env{CDPATH} is used, or if
2830 @samp{-} is the first argument, and the directory change is
2831 successful, the absolute pathname of the new working directory is
2832 written to the standard output.
2833
2834 The return status is zero if the directory is successfully changed,
2835 non-zero otherwise.
2836
2837 @item continue
2838 @btindex continue
2839 @example
2840 continue [@var{n}]
2841 @end example
2842 Resume the next iteration of an enclosing @code{for}, @code{while},
2843 @code{until}, or @code{select} loop.
2844 If @var{n} is supplied, the execution of the @var{n}th enclosing loop
2845 is resumed.
2846 @var{n} must be greater than or equal to 1.
2847 The return status is zero unless @var{n} is not greater than or equal to 1.
2848
2849 @item eval
2850 @btindex eval
2851 @example
2852 eval [@var{arguments}]
2853 @end example
2854 The arguments are concatenated together into a single command, which is
2855 then read and executed, and its exit status returned as the exit status
2856 of @code{eval}.
2857 If there are no arguments or only empty arguments, the return status is
2858 zero.
2859
2860 @item exec
2861 @btindex exec
2862 @example
2863 exec [-cl] [-a @var{name}] [@var{command} [@var{arguments}]]
2864 @end example
2865 If @var{command}
2866 is supplied, it replaces the shell without creating a new process.
2867 If the @option{-l} option is supplied, the shell places a dash at the
2868 beginning of the zeroth argument passed to @var{command}.
2869 This is what the @code{login} program does.
2870 The @option{-c} option causes @var{command} to be executed with an empty
2871 environment.
2872 If @option{-a} is supplied, the shell passes @var{name} as the zeroth
2873 argument to @var{command}.
2874 If no @var{command} is specified, redirections may be used to affect
2875 the current shell environment.  If there are no redirection errors, the
2876 return status is zero; otherwise the return status is non-zero.
2877
2878 @item exit
2879 @btindex exit
2880 @example
2881 exit [@var{n}]
2882 @end example
2883 Exit the shell, returning a status of @var{n} to the shell's parent.
2884 If @var{n} is omitted, the exit status is that of the last command executed.
2885 Any trap on @code{EXIT} is executed before the shell terminates.
2886
2887 @item export
2888 @btindex export
2889 @example
2890 export [-fn] [-p] [@var{name}[=@var{value}]]
2891 @end example
2892 Mark each @var{name} to be passed to child processes
2893 in the environment.  If the @option{-f} option is supplied, the @var{name}s
2894 refer to shell functions; otherwise the names refer to shell variables.
2895 The @option{-n} option means to no longer mark each @var{name} for export.
2896 If no @var{names} are supplied, or if the @option{-p} option is given, a
2897 list of exported names is displayed.
2898 The @option{-p} option displays output in a form that may be reused as input.
2899 If a variable name is followed by =@var{value}, the value of
2900 the variable is set to @var{value}.
2901
2902 The return status is zero unless an invalid option is supplied, one of
2903 the names is not a valid shell variable name, or @option{-f} is supplied
2904 with a name that is not a shell function.
2905
2906 @item getopts
2907 @btindex getopts
2908 @example
2909 getopts @var{optstring} @var{name} [@var{args}]
2910 @end example
2911 @code{getopts} is used by shell scripts to parse positional parameters.
2912 @var{optstring} contains the option characters to be recognized; if a
2913 character is followed by a colon, the option is expected to have an
2914 argument, which should be separated from it by white space.
2915 The colon (@samp{:}) and question mark (@samp{?}) may not be
2916 used as option characters.
2917 Each time it is invoked, @code{getopts}
2918 places the next option in the shell variable @var{name}, initializing
2919 @var{name} if it does not exist,
2920 and the index of the next argument to be processed into the
2921 variable @env{OPTIND}.
2922 @env{OPTIND} is initialized to 1 each time the shell or a shell script
2923 is invoked.
2924 When an option requires an argument,
2925 @code{getopts} places that argument into the variable @env{OPTARG}.
2926 The shell does not reset @env{OPTIND} automatically; it must be manually
2927 reset between multiple calls to @code{getopts} within the same shell
2928 invocation if a new set of parameters is to be used.
2929
2930 When the end of options is encountered, @code{getopts} exits with a
2931 return value greater than zero.
2932 @env{OPTIND} is set to the index of the first non-option argument,
2933 and @code{name} is set to @samp{?}.
2934
2935 @code{getopts}
2936 normally parses the positional parameters, but if more arguments are
2937 given in @var{args}, @code{getopts} parses those instead.
2938
2939 @code{getopts} can report errors in two ways.  If the first character of
2940 @var{optstring} is a colon, @var{silent}
2941 error reporting is used.  In normal operation diagnostic messages
2942 are printed when invalid options or missing option arguments are
2943 encountered.
2944 If the variable @env{OPTERR}
2945 is set to 0, no error messages will be displayed, even if the first
2946 character of @code{optstring} is not a colon.
2947
2948 If an invalid option is seen,
2949 @code{getopts} places @samp{?} into @var{name} and, if not silent,
2950 prints an error message and unsets @env{OPTARG}.
2951 If @code{getopts} is silent, the option character found is placed in
2952 @env{OPTARG} and no diagnostic message is printed.
2953
2954 If a required argument is not found, and @code{getopts}
2955 is not silent, a question mark (@samp{?}) is placed in @var{name},
2956 @code{OPTARG} is unset, and a diagnostic message is printed.
2957 If @code{getopts} is silent, then a colon (@samp{:}) is placed in
2958 @var{name} and @env{OPTARG} is set to the option character found.
2959
2960 @item hash
2961 @btindex hash
2962 @example
2963 hash [-r] [-p @var{filename}] [-dt] [@var{name}]
2964 @end example
2965 Remember the full pathnames of commands specified as @var{name} arguments,
2966 so they need not be searched for on subsequent invocations.
2967 The commands are found by searching through the directories listed in
2968 @env{$PATH}.
2969 The @option{-p} option inhibits the path search, and @var{filename} is
2970 used as the location of @var{name}.
2971 The @option{-r} option causes the shell to forget all remembered locations.
2972 The @option{-d} option causes the shell to forget the remembered location
2973 of each @var{name}.
2974 If the @option{-t} option is supplied, the full pathname to which each
2975 @var{name} corresponds is printed.  If multiple @var{name} arguments are
2976 supplied with @option{-t} the @var{name} is printed before the hashed
2977 full pathname.
2978 The @option{-l} option causes output to be displayed in a format
2979 that may be reused as input.
2980 If no arguments are given, or if only @option{-l} is supplied,
2981 information about remembered commands is printed.
2982 The return status is zero unless a @var{name} is not found or an invalid
2983 option is supplied.
2984
2985 @item pwd
2986 @btindex pwd
2987 @example
2988 pwd [-LP]
2989 @end example
2990 Print the absolute pathname of the current working directory.
2991 If the @option{-P} option is supplied, the pathname printed will not
2992 contain symbolic links.
2993 If the @option{-L} option is supplied, the pathname printed may contain
2994 symbolic links.
2995 The return status is zero unless an error is encountered while
2996 determining the name of the current directory or an invalid option
2997 is supplied.
2998
2999 @item readonly
3000 @btindex readonly
3001 @example
3002 readonly [-aApf] [@var{name}[=@var{value}]] @dots{}
3003 @end example
3004 Mark each @var{name} as readonly.
3005 The values of these names may not be changed by subsequent assignment.
3006 If the @option{-f} option is supplied, each @var{name} refers to a shell
3007 function.
3008 The @option{-a} option means each @var{name} refers to an indexed
3009 array variable; the @option{-A} option means each @var{name} refers
3010 to an associative array variable.
3011 If no @var{name} arguments are given, or if the @option{-p}
3012 option is supplied, a list of all readonly names is printed.
3013 The @option{-p} option causes output to be displayed in a format that
3014 may be reused as input.
3015 If a variable name is followed by =@var{value}, the value of
3016 the variable is set to @var{value}.
3017 The return status is zero unless an invalid option is supplied, one of
3018 the @var{name} arguments is not a valid shell variable or function name,
3019 or the @option{-f} option is supplied with a name that is not a shell function.
3020
3021 @item return
3022 @btindex return
3023 @example
3024 return [@var{n}]
3025 @end example
3026 Cause a shell function to exit with the return value @var{n}.
3027 If @var{n} is not supplied, the return value is the exit status of the
3028 last command executed in the function.
3029 This may also be used to terminate execution of a script being executed
3030 with the @code{.} (or @code{source}) builtin, returning either @var{n} or
3031 the exit status of the last command executed within the script as the exit
3032 status of the script.
3033 Any command associated with the @code{RETURN} trap is executed
3034 before execution resumes after the function or script.
3035 The return status is non-zero if @code{return} is used outside a function
3036 and not during the execution of a script by @code{.} or @code{source}.
3037
3038 @item shift
3039 @btindex shift
3040 @example
3041 shift [@var{n}]
3042 @end example
3043 Shift the positional parameters to the left by @var{n}.
3044 The positional parameters from @var{n}+1 @dots{} @code{$#} are
3045 renamed to @code{$1} @dots{} @code{$#}-@var{n}.
3046 Parameters represented by the numbers @code{$#} to @code{$#}-@var{n}+1
3047 are unset.
3048 @var{n} must be a non-negative number less than or equal to @code{$#}.
3049 If @var{n} is zero or greater than @code{$#}, the positional parameters
3050 are not changed.
3051 If @var{n} is not supplied, it is assumed to be 1.
3052 The return status is zero unless @var{n} is greater than @code{$#} or
3053 less than zero, non-zero otherwise.
3054
3055 @item test
3056 @itemx [
3057 @btindex test
3058 @btindex [
3059 Evaluate a conditional expression @var{expr}.
3060 Each operator and operand must be a separate argument.
3061 Expressions are composed of the primaries described below in
3062 @ref{Bash Conditional Expressions}.
3063 @code{test} does not accept any options, nor does it accept and ignore
3064 an argument of @option{--} as signifying the end of options.
3065
3066 When the @code{[} form is used, the last argument to the command must
3067 be a @code{]}.
3068
3069 Expressions may be combined using the following operators, listed in
3070 decreasing order of precedence.
3071 The evaluation depends on the number of arguments; see below.
3072
3073 @table @code
3074 @item ! @var{expr}
3075 True if @var{expr} is false.
3076
3077 @item ( @var{expr} )
3078 Returns the value of @var{expr}.
3079 This may be used to override the normal precedence of operators.
3080
3081 @item @var{expr1} -a @var{expr2}
3082 True if both @var{expr1} and @var{expr2} are true.
3083
3084 @item @var{expr1} -o @var{expr2}
3085 True if either @var{expr1} or @var{expr2} is true.
3086 @end table
3087
3088 The @code{test} and @code{[} builtins evaluate conditional
3089 expressions using a set of rules based on the number of arguments.
3090
3091 @table @asis
3092 @item 0 arguments
3093 The expression is false.
3094
3095 @item 1 argument
3096 The expression is true if and only if the argument is not null.
3097
3098 @item 2 arguments
3099 If the first argument is @samp{!}, the expression is true if and
3100 only if the second argument is null.
3101 If the first argument is one of the unary conditional operators
3102 (@pxref{Bash Conditional Expressions}), the expression
3103 is true if the unary test is true.
3104 If the first argument is not a valid unary operator, the expression is
3105 false.
3106
3107 @item 3 arguments
3108 If the second argument is one of the binary conditional
3109 operators (@pxref{Bash Conditional Expressions}), the
3110 result of the expression is the result of the binary test using the
3111 first and third arguments as operands.
3112 The @samp{-a} and @samp{-o} operators are considered binary operators
3113 when there are three arguments.
3114 If the first argument is @samp{!}, the value is the negation of
3115 the two-argument test using the second and third arguments.
3116 If the first argument is exactly @samp{(} and the third argument is
3117 exactly @samp{)}, the result is the one-argument test of the second
3118 argument.
3119 Otherwise, the expression is false.
3120
3121 @item 4 arguments
3122 If the first argument is @samp{!}, the result is the negation of
3123 the three-argument expression composed of the remaining arguments.
3124 Otherwise, the expression is parsed and evaluated according to 
3125 precedence using the rules listed above.
3126
3127 @item 5 or more arguments
3128 The expression is parsed and evaluated according to precedence
3129 using the rules listed above.
3130 @end table
3131
3132 @item times
3133 @btindex times
3134 @example
3135 times
3136 @end example
3137 Print out the user and system times used by the shell and its children.
3138 The return status is zero.
3139
3140 @item trap
3141 @btindex trap
3142 @example
3143 trap [-lp] [@var{arg}] [@var{sigspec} @dots{}]
3144 @end example
3145 The commands in @var{arg} are to be read and executed when the
3146 shell receives signal @var{sigspec}.  If @var{arg} is absent (and
3147 there is a single @var{sigspec}) or
3148 equal to @samp{-}, each specified signal's disposition is reset
3149 to the value it had when the shell was started.
3150 If @var{arg} is the null string, then the signal specified by
3151 each @var{sigspec} is ignored by the shell and commands it invokes.
3152 If @var{arg} is not present and @option{-p} has been supplied,
3153 the shell displays the trap commands associated with each @var{sigspec}.
3154 If no arguments are supplied, or
3155 only @option{-p} is given, @code{trap} prints the list of commands
3156 associated with each signal number in a form that may be reused as
3157 shell input.
3158 The @option{-l} option causes the shell to print a list of signal names
3159 and their corresponding numbers.
3160 Each @var{sigspec} is either a signal name or a signal number.
3161 Signal names are case insensitive and the @code{SIG} prefix is optional.
3162 If a @var{sigspec}
3163 is @code{0} or @code{EXIT}, @var{arg} is executed when the shell exits.
3164 If a @var{sigspec} is @code{DEBUG}, the command @var{arg} is executed
3165 before every simple command, @code{for} command, @code{case} command,
3166 @code{select} command, every arithmetic @code{for} command, and before
3167 the first command executes in a shell function.
3168 Refer to the description of the @code{extglob} option to the
3169 @code{shopt} builtin (@pxref{The Shopt Builtin}) for details of its
3170 effect on the @code{DEBUG} trap.
3171 If a @var{sigspec} is @code{ERR}, the command @var{arg} 
3172 is executed whenever a simple command has a non-zero exit status,
3173 subject to the following conditions.
3174 The @code{ERR} trap is not executed if the failed command is part of the
3175 command list immediately following an @code{until} or @code{while} keyword,
3176 part of the test following the @code{if} or @code{elif} reserved words,
3177 part of a command executed in a @code{&&} or @code{||} list,
3178 or if the command's return
3179 status is being inverted using @code{!}.
3180 These are the same conditions obeyed by the @code{errexit} option.
3181 If a @var{sigspec} is @code{RETURN}, the command @var{arg} is executed
3182 each time a shell function or a script executed with the @code{.} or
3183 @code{source} builtins finishes executing.
3184
3185 Signals ignored upon entry to the shell cannot be trapped or reset.
3186 Trapped signals that are not being ignored are reset to their original
3187 values in a child process when it is created.
3188
3189 The return status is zero unless a @var{sigspec} does not specify a
3190 valid signal.
3191
3192 @item umask
3193 @btindex umask
3194 @example
3195 umask [-p] [-S] [@var{mode}]
3196 @end example
3197 Set the shell process's file creation mask to @var{mode}.  If
3198 @var{mode} begins with a digit, it is interpreted as an octal number;
3199 if not, it is interpreted as a symbolic mode mask similar
3200 to that accepted by the @code{chmod} command.  If @var{mode} is
3201 omitted, the current value of the mask is printed.  If the @option{-S}
3202 option is supplied without a @var{mode} argument, the mask is printed
3203 in a symbolic format.
3204 If the  @option{-p} option is supplied, and @var{mode}
3205 is omitted, the output is in a form that may be reused as input.
3206 The return status is zero if the mode is successfully changed or if
3207 no @var{mode} argument is supplied, and non-zero otherwise.
3208
3209 Note that when the mode is interpreted as an octal number, each number
3210 of the umask is subtracted from @code{7}.  Thus, a umask of @code{022}
3211 results in permissions of @code{755}.
3212
3213 @item unset
3214 @btindex unset
3215 @example
3216 unset [-fv] [@var{name}]
3217 @end example
3218 Each variable or function @var{name} is removed.
3219 If no options are supplied, or the @option{-v} option is given, each
3220 @var{name} refers to a shell variable. 
3221 If the @option{-f} option is given, the @var{name}s refer to shell
3222 functions, and the function definition is removed.
3223 Readonly variables and functions may not be unset.
3224 The return status is zero unless a @var{name} is readonly.
3225 @end table
3226
3227 @node Bash Builtins
3228 @section Bash Builtin Commands
3229
3230 This section describes builtin commands which are unique to
3231 or have been extended in Bash.
3232 Some of these commands are specified in the @sc{posix} standard.
3233
3234 @table @code
3235
3236 @item alias
3237 @btindex alias
3238 @example
3239 alias [@code{-p}] [@var{name}[=@var{value}] @dots{}]
3240 @end example
3241
3242 Without arguments or with the @option{-p} option, @code{alias} prints
3243 the list of aliases on the standard output in a form that allows
3244 them to be reused as input.
3245 If arguments are supplied, an alias is defined for each @var{name}
3246 whose @var{value} is given.  If no @var{value} is given, the name
3247 and value of the alias is printed.
3248 Aliases are described in @ref{Aliases}.
3249
3250 @item bind
3251 @btindex bind
3252 @example
3253 bind [-m @var{keymap}] [-lpsvPSV]
3254 bind [-m @var{keymap}] [-q @var{function}] [-u @var{function}] [-r @var{keyseq}]
3255 bind [-m @var{keymap}] -f @var{filename}
3256 bind [-m @var{keymap}] -x @var{keyseq:shell-command}
3257 bind [-m @var{keymap}] @var{keyseq:function-name}
3258 bind @var{readline-command}
3259 @end example
3260
3261 Display current Readline (@pxref{Command Line Editing})
3262 key and function bindings,
3263 bind a key sequence to a Readline function or macro,
3264 or set a Readline variable.
3265 Each non-option argument is a command as it would appear in a
3266 Readline initialization file (@pxref{Readline Init File}),
3267 but each binding or command must be passed as a separate argument;  e.g.,
3268 @samp{"\C-x\C-r":re-read-init-file}.
3269
3270 Options, if supplied, have the following meanings:
3271
3272 @table @code
3273 @item -m @var{keymap}
3274 Use @var{keymap} as the keymap to be affected by
3275 the subsequent bindings.  Acceptable @var{keymap}
3276 names are
3277 @code{emacs},
3278 @code{emacs-standard},
3279 @code{emacs-meta},
3280 @code{emacs-ctlx},
3281 @code{vi},
3282 @code{vi-move},
3283 @code{vi-command}, and
3284 @code{vi-insert}.
3285 @code{vi} is equivalent to @code{vi-command};
3286 @code{emacs} is equivalent to @code{emacs-standard}.
3287
3288 @item -l
3289 List the names of all Readline functions.
3290
3291 @item -p
3292 Display Readline function names and bindings in such a way that they
3293 can be used as input or in a Readline initialization file.
3294
3295 @item -P
3296 List current Readline function names and bindings.
3297
3298 @item -v
3299 Display Readline variable names and values in such a way that they
3300 can be used as input or in a Readline initialization file.
3301
3302 @item -V
3303 List current Readline variable names and values.
3304
3305 @item -s
3306 Display Readline key sequences bound to macros and the strings they output
3307 in such a way that they can be used as input or in a Readline
3308 initialization file.
3309
3310 @item -S
3311 Display Readline key sequences bound to macros and the strings they output.
3312
3313 @item -f @var{filename}
3314 Read key bindings from @var{filename}.
3315
3316 @item -q @var{function}
3317 Query about which keys invoke the named @var{function}.
3318
3319 @item -u @var{function}
3320 Unbind all keys bound to the named @var{function}.
3321
3322 @item -r @var{keyseq}
3323 Remove any current binding for @var{keyseq}.
3324
3325 @item -x @var{keyseq:shell-command}
3326 Cause @var{shell-command} to be executed whenever @var{keyseq} is
3327 entered.
3328 When @var{shell-command} is executed, the shell sets the
3329 @code{READLINE_LINE} variable to the contents of the Readline line
3330 buffer and the @code{READLINE_POINT} variable to the current location
3331 of the insertion point.
3332 If the executed command changes the value of @code{READLINE_LINE} or
3333 @code{READLINE_POINT}, those new values will be reflected in the
3334 editing state.
3335 @end table
3336
3337 @noindent
3338 The return status is zero unless an invalid option is supplied or an
3339 error occurs.
3340
3341 @item builtin
3342 @btindex builtin
3343 @example
3344 builtin [@var{shell-builtin} [@var{args}]]
3345 @end example
3346 Run a shell builtin, passing it @var{args}, and return its exit status.
3347 This is useful when defining a shell function with the same
3348 name as a shell builtin, retaining the functionality of the builtin within
3349 the function.
3350 The return status is non-zero if @var{shell-builtin} is not a shell
3351 builtin command.
3352
3353 @item caller
3354 @btindex caller
3355 @example
3356 caller [@var{expr}]
3357 @end example
3358 Returns the context of any active subroutine call (a shell function or
3359 a script executed with the @code{.} or @code{source} builtins).
3360
3361 Without @var{expr}, @code{caller} displays the line number and source
3362 filename of the current subroutine call.
3363 If a non-negative integer is supplied as @var{expr}, @code{caller} 
3364 displays the line number, subroutine name, and source file corresponding
3365 to that position in the current execution call stack.  This extra
3366 information may be used, for example, to print a stack trace.  The
3367 current frame is frame 0.
3368
3369 The return value is 0 unless the shell is not executing a subroutine
3370 call or @var{expr} does not correspond to a valid position in the
3371 call stack.
3372
3373 @item command
3374 @btindex command
3375 @example
3376 command [-pVv] @var{command} [@var{arguments} @dots{}]
3377 @end example
3378 Runs @var{command} with @var{arguments} ignoring any shell function
3379 named @var{command}.
3380 Only shell builtin commands or commands found by searching the
3381 @env{PATH} are executed.
3382 If there is a shell function named @code{ls}, running @samp{command ls}
3383 within the function will execute the external command @code{ls}
3384 instead of calling the function recursively.
3385 The @option{-p} option means to use a default value for @env{PATH}
3386 that is guaranteed to find all of the standard utilities.
3387 The return status in this case is 127 if @var{command} cannot be
3388 found or an error occurred, and the exit status of @var{command}
3389 otherwise.
3390
3391 If either the @option{-V} or @option{-v} option is supplied, a
3392 description of @var{command} is printed.  The @option{-v} option
3393 causes a single word indicating the command or file name used to
3394 invoke @var{command} to be displayed; the @option{-V} option produces
3395 a more verbose description.  In this case, the return status is
3396 zero if @var{command} is found, and non-zero if not.
3397
3398 @item declare
3399 @btindex declare
3400 @example
3401 declare [-aAfFilrtux] [-p] [@var{name}[=@var{value}] @dots{}]
3402 @end example
3403
3404 Declare variables and give them attributes.  If no @var{name}s
3405 are given, then display the values of variables instead. 
3406
3407 The @option{-p} option will display the attributes and values of each
3408 @var{name}.
3409 When @option{-p} is used with @var{name} arguments, additional options
3410 are ignored.
3411
3412 When @option{-p} is supplied without @var{name} arguments, @code{declare}
3413 will display the attributes and values of all variables having the
3414 attributes specified by the additional options.
3415 If no other options are supplied with @option{-p}, @code{declare} will
3416 display the attributes and values of all shell variables.  The @option{-f}
3417 option will restrict the display to shell functions.
3418
3419 The @option{-F} option inhibits the display of function definitions;
3420 only the function name and attributes are printed.
3421 If the @code{extdebug} shell option is enabled using @code{shopt}
3422 (@pxref{The Shopt Builtin}), the source file name and line number where
3423 the function is defined are displayed as well.
3424 @option{-F} implies @option{-f}.
3425 The following options can be used to restrict output to variables with
3426 the specified attributes or to give variables attributes:
3427
3428 @table @code
3429 @item -a
3430 Each @var{name} is an indexed array variable (@pxref{Arrays}).
3431
3432 @item -A
3433 Each @var{name} is an associative array variable (@pxref{Arrays}).
3434
3435 @item -f
3436 Use function names only.
3437
3438 @item -i
3439 The variable is to be treated as
3440 an integer; arithmetic evaluation (@pxref{Shell Arithmetic}) is
3441 performed when the variable is assigned a value.
3442
3443 @item -l
3444 When the variable is assigned a value, all upper-case characters are
3445 converted to lower-case.
3446 The upper-case attribute is disabled.
3447
3448 @item -r
3449 Make @var{name}s readonly.  These names cannot then be assigned values
3450 by subsequent assignment statements or unset.
3451
3452 @item -t
3453 Give each @var{name} the @code{trace} attribute.
3454 Traced functions inherit the @code{DEBUG} and @code{RETURN} traps from
3455 the calling shell.
3456 The trace attribute has no special meaning for variables.
3457
3458 @item -u
3459 When the variable is assigned a value, all lower-case characters are
3460 converted to upper-case.
3461 The lower-case attribute is disabled.
3462
3463 @item -x
3464 Mark each @var{name} for export to subsequent commands via
3465 the environment.
3466 @end table
3467
3468 Using @samp{+} instead of @samp{-} turns off the attribute instead,
3469 with the exceptions that @samp{+a}
3470 may not be used to destroy an array variable and @samp{+r} will not
3471 remove the readonly attribute.
3472 When used in a function, @code{declare} makes each @var{name} local,
3473 as with the @code{local} command.  If a variable name is followed by
3474 =@var{value}, the value of the variable is set to @var{value}.
3475
3476 The return status is zero unless an invalid option is encountered,
3477 an attempt is made to define a function using @samp{-f foo=bar},
3478 an attempt is made to assign a value to a readonly variable,
3479 an attempt is made to assign a value to an array variable without
3480 using the compound assignment syntax (@pxref{Arrays}),
3481 one of the @var{names} is not a valid shell variable name,
3482 an attempt is made to turn off readonly status for a readonly variable,
3483 an attempt is made to turn off array status for an array variable,
3484 or an attempt is made to display a non-existent function with @option{-f}.
3485
3486 @item echo
3487 @btindex echo
3488 @example
3489 echo [-neE] [@var{arg} @dots{}]
3490 @end example
3491 Output the @var{arg}s, separated by spaces, terminated with a
3492 newline.
3493 The return status is always 0.
3494 If @option{-n} is specified, the trailing newline is suppressed.
3495 If the @option{-e} option is given, interpretation of the following
3496 backslash-escaped characters is enabled.
3497 The @option{-E} option disables the interpretation of these escape characters,
3498 even on systems where they are interpreted by default.
3499 The @code{xpg_echo} shell option may be used to
3500 dynamically determine whether or not @code{echo} expands these
3501 escape characters by default.
3502 @code{echo} does not interpret @option{--} to mean the end of options.
3503
3504 @code{echo} interprets the following escape sequences:
3505 @table @code
3506 @item \a
3507 alert (bell)
3508 @item \b
3509 backspace
3510 @item \c
3511 suppress further output
3512 @item \e
3513 escape
3514 @item \f
3515 form feed
3516 @item \n
3517 new line
3518 @item \r
3519 carriage return
3520 @item \t 
3521 horizontal tab
3522 @item \v
3523 vertical tab
3524 @item \\
3525 backslash
3526 @item \0@var{nnn}
3527 the eight-bit character whose value is the octal value @var{nnn}
3528 (zero to three octal digits)
3529 @item \x@var{HH}
3530 the eight-bit character whose value is the hexadecimal value @var{HH}
3531 (one or two hex digits)
3532 @end table
3533
3534 @item enable
3535 @btindex enable
3536 @example
3537 enable [-a] [-dnps] [-f @var{filename}] [@var{name} @dots{}]
3538 @end example
3539 Enable and disable builtin shell commands.
3540 Disabling a builtin allows a disk command which has the same name
3541 as a shell builtin to be executed without specifying a full pathname,
3542 even though the shell normally searches for builtins before disk commands.
3543 If @option{-n} is used, the @var{name}s become disabled.  Otherwise
3544 @var{name}s are enabled.  For example, to use the @code{test} binary
3545 found via @env{$PATH} instead of the shell builtin version, type
3546 @samp{enable -n test}.
3547
3548 If the @option{-p} option is supplied, or no @var{name} arguments appear,
3549 a list of shell builtins is printed.  With no other arguments, the list
3550 consists of all enabled shell builtins.
3551 The @option{-a} option means to list
3552 each builtin with an indication of whether or not it is enabled. 
3553
3554 The @option{-f} option means to load the new builtin command @var{name}
3555 from shared object @var{filename}, on systems that support dynamic loading.
3556 The @option{-d} option will delete a builtin loaded with @option{-f}.
3557
3558 If there are no options, a list of the shell builtins is displayed.
3559 The @option{-s} option restricts @code{enable} to the @sc{posix} special
3560 builtins.  If @option{-s} is used with @option{-f}, the new builtin becomes
3561 a special builtin (@pxref{Special Builtins}).
3562
3563 The return status is zero unless a @var{name} is not a shell builtin
3564 or there is an error loading a new builtin from a shared object.
3565
3566 @item help
3567 @btindex help
3568 @example
3569 help [-dms] [@var{pattern}]
3570 @end example
3571 Display helpful information about builtin commands.
3572 If @var{pattern} is specified, @code{help} gives detailed help
3573 on all commands matching @var{pattern}, otherwise a list of
3574 the builtins is printed.
3575
3576 Options, if supplied, have the following meanings:
3577
3578 @table @code
3579 @item -d
3580 Display a short description of each @var{pattern}
3581 @item -m
3582 Display the description of each @var{pattern} in a manpage-like format
3583 @item -s
3584 Display only a short usage synopsis for each @var{pattern}
3585 @end table
3586
3587 The return status is zero unless no command matches @var{pattern}.
3588
3589 @item let
3590 @btindex let
3591 @example
3592 let @var{expression} [@var{expression}]
3593 @end example
3594 The @code{let} builtin allows arithmetic to be performed on shell
3595 variables.  Each @var{expression} is evaluated according to the
3596 rules given below in @ref{Shell Arithmetic}.  If the
3597 last @var{expression} evaluates to 0, @code{let} returns 1;
3598 otherwise 0 is returned.
3599
3600 @item local
3601 @btindex local
3602 @example
3603 local [@var{option}] @var{name}[=@var{value}] @dots{}
3604 @end example
3605 For each argument, a local variable named @var{name} is created,
3606 and assigned @var{value}.
3607 The @var{option} can be any of the options accepted by @code{declare}.
3608 @code{local} can only be used within a function; it makes the variable
3609 @var{name} have a visible scope restricted to that function and its
3610 children.  The return status is zero unless @code{local} is used outside
3611 a function, an invalid @var{name} is supplied, or @var{name} is a
3612 readonly variable.
3613
3614 @item logout
3615 @btindex logout
3616 @example
3617 logout [@var{n}]
3618 @end example
3619 Exit a login shell, returning a status of @var{n} to the shell's
3620 parent.
3621
3622 @item mapfile
3623 @btindex mapfile
3624 @example
3625 mapfile [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [
3626 -C @var{callback}] [-c @var{quantum}] [@var{array}]
3627 @end example
3628 Read lines from the standard input into array variable @var{array},
3629 or from file descriptor @var{fd}
3630 if the @option{-u} option is supplied.
3631 The variable @code{MAPFILE} is the default @var{array}.
3632 Options, if supplied, have the following meanings:
3633 @table @code
3634
3635 @item -n
3636 Copy at most @var{count} lines.  If @var{count} is 0, all lines are copied.
3637 @item -O
3638 Begin assigning to @var{array} at index @var{origin}.
3639 The default index is 0.
3640 @item -s
3641 Discard the first @var{count} lines read.
3642 @item -t
3643 Remove a trailing line from each line read.
3644 @item -u
3645 Read lines from file descriptor @var{fd} instead of the standard input.
3646 @item -C
3647 Evaluate @var{callback} each time @var{quantum}P lines are read.
3648 The @option{-c} option specifies @var{quantum}.
3649 @item -c
3650 Specify the number of lines read between each call to @var{callback}.
3651 @end table
3652
3653 If @option{-C} is specified without @option{-c}, 
3654 the default quantum is 5000.
3655 When @var{callback}  is evaluated, it is supplied the index of the next
3656 array element to be assigned as an additional argument.
3657 @var{callback} is evaluated after the line is read but before the 
3658 array element is assigned.
3659
3660 If not supplied with an explicit origin, @code{mapfile} will clear @var{array}
3661 before assigning to it.
3662
3663 @code{mapfile} returns successfully unless an invalid option or option
3664 argument is supplied, or @var{array} is invalid or unassignable.
3665
3666 @item printf
3667 @btindex printf
3668 @example
3669 printf [-v @var{var}] @var{format} [@var{arguments}]
3670 @end example
3671 Write the formatted @var{arguments} to the standard output under the
3672 control of the @var{format}.
3673 The @var{format} is a character string which contains three types of objects:
3674 plain characters, which are simply copied to standard output, character
3675 escape sequences, which are converted and copied to the standard output, and
3676 format specifications, each of which causes printing of the next successive
3677 @var{argument}.
3678 In addition to the standard @code{printf(1)} formats, @samp{%b} causes
3679 @code{printf} to expand backslash escape sequences in the corresponding
3680 @var{argument},
3681 (except that @samp{\c} terminates output, backslashes in
3682 @samp{\'}, @samp{\"}, and @samp{\?} are not removed, and octal escapes
3683 beginning with @samp{\0} may contain up to four digits),
3684 and @samp{%q} causes @code{printf} to output the
3685 corresponding @var{argument} in a format that can be reused as shell input.
3686
3687 The @option{-v} option causes the output to be assigned to the variable
3688 @var{var} rather than being printed to the standard output.
3689
3690 The @var{format} is reused as necessary to consume all of the @var{arguments}.
3691 If the @var{format} requires more @var{arguments} than are supplied, the
3692 extra format specifications behave as if a zero value or null string, as
3693 appropriate, had been supplied.  The return value is zero on success,
3694 non-zero on failure.
3695
3696 @item read
3697 @btindex read
3698 @example
3699 read [-ers] [-a @var{aname}] [-d @var{delim}] [-i @var{text}] [-n @var{nchars}] [-p @var{prompt}] [-t @var{timeout}] [-u @var{fd}] [@var{name} @dots{}]
3700 @end example
3701 One line is read from the standard input, or from the file descriptor
3702 @var{fd} supplied as an argument to the @option{-u} option, and the first word
3703 is assigned to the first @var{name}, the second word to the second @var{name},
3704 and so on, with leftover words and their intervening separators assigned
3705 to the last @var{name}.
3706 If there are fewer words read from the input stream than names,
3707 the remaining names are assigned empty values.
3708 The characters in the value of the @env{IFS} variable
3709 are used to split the line into words.
3710 The backslash character @samp{\} may be used to remove any special
3711 meaning for the next character read and for line continuation.
3712 If no names are supplied, the line read is assigned to the
3713 variable @env{REPLY}.
3714 The return code is zero, unless end-of-file is encountered, @code{read}
3715 times out (in which case the return code is greater than 128), or an
3716 invalid file descriptor is supplied as the argument to @option{-u}.
3717
3718 Options, if supplied, have the following meanings:
3719
3720 @table @code
3721 @item -a @var{aname}
3722 The words are assigned to sequential indices of the array variable
3723 @var{aname}, starting at 0.
3724 All elements are removed from @var{aname} before the assignment.
3725 Other @var{name} arguments are ignored.
3726
3727 @item -d @var{delim}
3728 The first character of @var{delim} is used to terminate the input line,
3729 rather than newline.
3730
3731 @item -e
3732 Readline (@pxref{Command Line Editing}) is used to obtain the line.
3733 Readline uses the current (or default, if line editing was not previously
3734 active) editing settings.
3735
3736 @item -i @var{text}
3737 If Readline is being used to read the line, @var{text} is placed into
3738 the editing buffer before editing begins.
3739
3740 @item -n @var{nchars}
3741 @code{read} returns after reading @var{nchars} characters rather than
3742 waiting for a complete line of input.
3743
3744 @item -p @var{prompt}
3745 Display @var{prompt}, without a trailing newline, before attempting
3746 to read any input.
3747 The prompt is displayed only if input is coming from a terminal.
3748
3749 @item -r
3750 If this option is given, backslash does not act as an escape character.
3751 The backslash is considered to be part of the line.
3752 In particular, a backslash-newline pair may not be used as a line
3753 continuation.
3754
3755 @item -s
3756 Silent mode.  If input is coming from a terminal, characters are
3757 not echoed.
3758
3759 @item -t @var{timeout}
3760 Cause @code{read} to time out and return failure if a complete line of
3761 input is not read within @var{timeout} seconds.
3762 @var{timeout}  may be a decimal number with a fractional portion following
3763 the decimal point.
3764 This option is only effective if @code{read} is reading input from a
3765 terminal, pipe, or other special file; it has no effect when reading
3766 from regular files.
3767 If @var{timeout} is 0, @code{read} returns success if input is available on
3768 the specified file descriptor, failure otherwise.
3769 The exit status is greater than 128 if the timeout is exceeded.
3770
3771 @item -u @var{fd}
3772 Read input from file descriptor @var{fd}.
3773
3774 @end table
3775
3776 @item readarray
3777 @btindex readarray
3778 @example
3779 readarray [-n @var{count}] [-O @var{origin}] [-s @var{count}] [-t] [-u @var{fd}] [
3780 -C @var{callback}] [-c @var{quantum}] [@var{array}]
3781 @end example
3782 Read lines from the standard input into array variable @var{array},
3783 or from file descriptor @var{fd}
3784 if the @option{-u} option is supplied.
3785
3786 A synonym for @code{mapfile}.
3787
3788 @item source
3789 @btindex source
3790 @example
3791 source @var{filename}
3792 @end example
3793 A synonym for @code{.} (@pxref{Bourne Shell Builtins}).
3794
3795 @item type
3796 @btindex type
3797 @example
3798 type [-afptP] [@var{name} @dots{}]
3799 @end example
3800 For each @var{name}, indicate how it would be interpreted if used as a
3801 command name.
3802
3803 If the @option{-t} option is used, @code{type} prints a single word
3804 which is one of @samp{alias}, @samp{function}, @samp{builtin},
3805 @samp{file} or @samp{keyword},
3806 if @var{name} is an alias, shell function, shell builtin,
3807 disk file, or shell reserved word, respectively.
3808 If the @var{name} is not found, then nothing is printed, and
3809 @code{type} returns a failure status.
3810
3811 If the @option{-p} option is used, @code{type} either returns the name
3812 of the disk file that would be executed, or nothing if @option{-t}
3813 would not return @samp{file}.
3814
3815 The @option{-P} option forces a path search for each @var{name}, even if
3816 @option{-t} would not return @samp{file}.
3817
3818 If a command is hashed, @option{-p} and @option{-P} print the hashed value,
3819 not necessarily the file that appears first in @code{$PATH}.
3820
3821 If the @option{-a} option is used, @code{type} returns all of the places
3822 that contain an executable named @var{file}.
3823 This includes aliases and functions, if and only if the @option{-p} option
3824 is not also used.
3825
3826 If the @option{-f} option is used, @code{type} does not attempt to find
3827 shell functions, as with the @code{command} builtin.
3828
3829 The return status is zero if all of the @var{names} are found, non-zero
3830 if any are not found.
3831
3832 @item typeset
3833 @btindex typeset
3834 @example
3835 typeset [-afFrxi] [-p] [@var{name}[=@var{value}] @dots{}]
3836 @end example
3837 The @code{typeset} command is supplied for compatibility with the Korn
3838 shell; however, it has been deprecated in favor of the @code{declare}
3839 builtin command.
3840
3841 @item ulimit
3842 @btindex ulimit
3843 @example
3844 ulimit [-abcdefilmnpqrstuvxHST] [@var{limit}]
3845 @end example
3846 @code{ulimit} provides control over the resources available to processes
3847 started by the shell, on systems that allow such control.  If an
3848 option is given, it is interpreted as follows:
3849 @table @code
3850 @item -S
3851 Change and report the soft limit associated with a resource.
3852
3853 @item -H
3854 Change and report the hard limit associated with a resource.
3855
3856 @item -a
3857 All current limits are reported.
3858
3859 @item -b
3860 The maximum socket buffer size.
3861
3862 @item -c
3863 The maximum size of core files created.
3864
3865 @item -d
3866 The maximum size of a process's data segment.
3867
3868 @item -e
3869 The maximum scheduling priority ("nice").
3870
3871 @item -f
3872 The maximum size of files written by the shell and its children.
3873
3874 @item -i
3875 The maximum number of pending signals.
3876
3877 @item -l
3878 The maximum size that may be locked into memory.
3879
3880 @item -m
3881 The maximum resident set size (many systems do not honor this limit).
3882
3883 @item -n
3884 The maximum number of open file descriptors (most systems do not
3885 allow this value to be set).
3886
3887 @item -p
3888 The pipe buffer size.
3889
3890 @item -q
3891 The maximum number of bytes in POSIX message queues.
3892
3893 @item -r
3894 The maximum real-time scheduling priority.
3895
3896 @item -s
3897 The maximum stack size.
3898
3899 @item -t
3900 The maximum amount of cpu time in seconds.
3901
3902 @item -u
3903 The maximum number of processes available to a single user.
3904
3905 @item -v
3906 The maximum amount of virtual memory available to the process.
3907
3908 @item -x
3909 The maximum number of file locks.
3910
3911 @item -T
3912 The maximum number of threads.
3913
3914 @end table
3915
3916 If @var{limit} is given, it is the new value of the specified resource;
3917 the special @var{limit} values @code{hard}, @code{soft}, and
3918 @code{unlimited} stand for the current hard limit, the current soft limit,
3919 and no limit, respectively.
3920 A hard limit cannot be increased by a non-root user once it is set;
3921 a soft limit may be increased up to the value of the hard limit.
3922 Otherwise, the current value of the soft limit for the specified resource
3923 is printed, unless the @option{-H} option is supplied.
3924 When setting new limits, if neither @option{-H} nor @option{-S} is supplied,
3925 both the hard and soft limits are set.
3926 If no option is given, then @option{-f} is assumed.  Values are in 1024-byte
3927 increments, except for @option{-t}, which is in seconds, @option{-p},
3928 which is in units of 512-byte blocks, and @option{-n} and @option{-u}, which
3929 are unscaled values.
3930
3931 The return status is zero unless an invalid option or argument is supplied,
3932 or an error occurs while setting a new limit.
3933
3934 @item unalias
3935 @btindex unalias
3936 @example
3937 unalias [-a] [@var{name} @dots{} ]
3938 @end example
3939
3940 Remove each @var{name} from the list of aliases.  If @option{-a} is
3941 supplied, all aliases are removed.
3942 Aliases are described in @ref{Aliases}.
3943
3944 @end table
3945
3946 @node Modifying Shell Behavior
3947 @section Modifying Shell Behavior
3948  
3949 @menu
3950 * The Set Builtin::             Change the values of shell attributes and
3951                                 positional parameters.
3952 * The Shopt Builtin::           Modify shell optional behavior.
3953 @end menu
3954
3955 @node The Set Builtin
3956 @subsection The Set Builtin
3957
3958 This builtin is so complicated that it deserves its own section.  @code{set}
3959 allows you to change the values of shell options and set the positional
3960 parameters, or to display the names and values of shell variables.
3961
3962 @table @code
3963 @item set
3964 @btindex set
3965 @example
3966 set [--abefhkmnptuvxBCEHPT] [-o @var{option}] [@var{argument} @dots{}]
3967 set [+abefhkmnptuvxBCEHPT] [+o @var{option}] [@var{argument} @dots{}]
3968 @end example
3969
3970 If no options or arguments are supplied, @code{set} displays the names
3971 and values of all shell variables and functions, sorted according to the
3972 current locale, in a format that may be reused as input
3973 for setting or resetting the currently-set variables.
3974 Read-only variables cannot be reset.
3975 In @sc{posix} mode, only shell variables are listed.
3976
3977 When options are supplied, they set or unset shell attributes.
3978 Options, if specified, have the following meanings:
3979
3980 @table @code
3981 @item -a
3982 Mark variables and function which are modified or created for export
3983 to the environment of subsequent commands.
3984
3985 @item -b
3986 Cause the status of terminated background jobs to be reported
3987 immediately, rather than before printing the next primary prompt.
3988
3989 @item -e
3990 Exit immediately if a pipeline (@pxref{Pipelines}), which may consist
3991 of a single simple command (@pxref{Simple Commands}),
3992 a subshell command enclosed in parentheses (@pxref{Command Grouping}),
3993 or one of the commands executed as part of a command list enclosed
3994 by braces (@pxref{Command Grouping})
3995 returns a non-zero status.
3996 The shell does not exit if the command that fails is part of the
3997 command list immediately following a @code{while} or @code{until} keyword,
3998 part of the test in an @code{if} statement,
3999 part of any command executed in a @code{&&} or @code{||} list except
4000 the command following the final @code{&&} or @code{||},
4001 any command in a pipeline but the last,
4002 or if the command's return status is being inverted with @code{!}.
4003 A trap on @code{ERR}, if set, is executed before the shell exits.
4004
4005 This option applies to the shell environment and each subshell environment
4006 separately (@pxref{Command Execution Environment}), and may cause
4007 subshells to exit before executing all the commands in the subshell.
4008
4009 @item -f
4010 Disable file name generation (globbing).
4011
4012 @item -h
4013 Locate and remember (hash) commands as they are looked up for execution.
4014 This option is enabled by default.
4015
4016 @item -k
4017 All arguments in the form of assignment statements are placed
4018 in the environment for a command, not just those that precede
4019 the command name.
4020
4021 @item -m
4022 Job control is enabled (@pxref{Job Control}).
4023
4024 @item -n
4025 Read commands but do not execute them; this may be used to check a
4026 script for syntax errors.
4027 This option is ignored by interactive shells.
4028
4029 @item -o @var{option-name}
4030
4031 Set the option corresponding to @var{option-name}:
4032
4033 @table @code
4034 @item allexport
4035 Same as @code{-a}.
4036
4037 @item braceexpand
4038 Same as @code{-B}.
4039
4040 @item emacs
4041 Use an @code{emacs}-style line editing interface (@pxref{Command Line Editing}).
4042 This also affects the editing interface used for @code{read -e}.
4043
4044 @item errexit
4045 Same as @code{-e}.
4046
4047 @item errtrace
4048 Same as @code{-E}.
4049
4050 @item functrace
4051 Same as @code{-T}.
4052
4053 @item hashall
4054 Same as @code{-h}.
4055
4056 @item histexpand
4057 Same as @code{-H}.
4058
4059 @item history
4060 Enable command history, as described in @ref{Bash History Facilities}.
4061 This option is on by default in interactive shells.
4062
4063 @item ignoreeof
4064 An interactive shell will not exit upon reading EOF.
4065
4066 @item keyword
4067 Same as @code{-k}.
4068
4069 @item monitor
4070 Same as @code{-m}.
4071
4072 @item noclobber
4073 Same as @code{-C}.
4074
4075 @item noexec
4076 Same as @code{-n}.
4077
4078 @item noglob
4079 Same as @code{-f}.
4080
4081 @item nolog
4082 Currently ignored.
4083
4084 @item notify
4085 Same as @code{-b}.
4086
4087 @item nounset
4088 Same as @code{-u}.
4089
4090 @item onecmd
4091 Same as @code{-t}.
4092
4093 @item physical
4094 Same as @code{-P}.
4095
4096 @item pipefail
4097 If set, the return value of a pipeline is the value of the last
4098 (rightmost) command to exit with a non-zero status, or zero if all
4099 commands in the pipeline exit successfully.
4100 This option is disabled by default.
4101
4102 @item posix
4103 Change the behavior of Bash where the default operation differs
4104 from the @sc{posix} standard to match the standard
4105 (@pxref{Bash POSIX Mode}).
4106 This is intended to make Bash behave as a strict superset of that
4107 standard.
4108
4109 @item privileged
4110 Same as @code{-p}.
4111
4112 @item verbose
4113 Same as @code{-v}.
4114
4115 @item vi
4116 Use a @code{vi}-style line editing interface.
4117 This also affects the editing interface used for @code{read -e}.
4118
4119 @item xtrace
4120 Same as @code{-x}.
4121 @end table
4122
4123 @item -p
4124 Turn on privileged mode.
4125 In this mode, the @env{$BASH_ENV} and @env{$ENV} files are not
4126 processed, shell functions are not inherited from the environment,
4127 and the @env{SHELLOPTS}, @env{CDPATH} and @env{GLOBIGNORE}  variables,
4128 if they appear in the environment, are ignored.
4129 If the shell is started with the effective user (group) id not equal to the
4130 real user (group) id, and the @code{-p} option is not supplied, these actions
4131 are taken and the effective user id is set to the real user id.
4132 If the @code{-p} option is supplied at startup, the effective user id is
4133 not reset.
4134 Turning this option off causes the effective user
4135 and group ids to be set to the real user and group ids.
4136
4137 @item -t
4138 Exit after reading and executing one command.
4139
4140 @item -u
4141 Treat unset variables as an error when performing parameter expansion.
4142 An error message will be written to the standard error, and a non-interactive
4143 shell will exit.
4144
4145 @item -v
4146 Print shell input lines as they are read.
4147
4148 @item -x
4149 Print a trace of simple commands, @code{for} commands, @code{case}
4150 commands, @code{select} commands, and arithmetic @code{for} commands
4151 and their arguments or associated word lists after they are
4152 expanded and before they are executed.  The value of the @env{PS4}
4153 variable is expanded and the resultant value is printed before
4154 the command and its expanded arguments.
4155
4156 @item -B
4157 The shell will perform brace expansion (@pxref{Brace Expansion}).
4158 This option is on by default.
4159
4160 @item -C
4161 Prevent output redirection using @samp{>}, @samp{>&}, and @samp{<>}
4162 from overwriting existing files.
4163
4164 @item -E
4165 If set, any trap on @code{ERR} is inherited by shell functions, command
4166 substitutions, and commands executed in a subshell environment.
4167 The @code{ERR} trap is normally not inherited in such cases.
4168
4169 @item -H
4170 Enable @samp{!} style history substitution (@pxref{History Interaction}).
4171 This option is on by default for interactive shells.
4172
4173 @item -P
4174 If set, do not follow symbolic links when performing commands such as
4175 @code{cd} which change the current directory.  The physical directory
4176 is used instead.  By default, Bash follows
4177 the logical chain of directories when performing commands
4178 which change the current directory.
4179
4180 For example, if @file{/usr/sys} is a symbolic link to @file{/usr/local/sys}
4181 then:
4182 @example
4183 $ cd /usr/sys; echo $PWD
4184 /usr/sys
4185 $ cd ..; pwd
4186 /usr
4187 @end example
4188
4189 @noindent
4190 If @code{set -P} is on, then:
4191 @example
4192 $ cd /usr/sys; echo $PWD
4193 /usr/local/sys
4194 $ cd ..; pwd
4195 /usr/local
4196 @end example
4197
4198 @item -T
4199 If set, any trap on @code{DEBUG} and @code{RETURN} are inherited by
4200 shell functions, command substitutions, and commands executed
4201 in a subshell environment.
4202 The @code{DEBUG} and @code{RETURN} traps are normally not inherited
4203 in such cases.
4204
4205 @item --
4206 If no arguments follow this option, then the positional parameters are
4207 unset.  Otherwise, the positional parameters are set to the
4208 @var{arguments}, even if some of them begin with a @samp{-}.
4209
4210 @item -
4211 Signal the end of options, cause all remaining @var{arguments}
4212 to be assigned to the positional parameters.  The @option{-x}
4213 and @option{-v}  options are turned off.
4214 If there are no arguments, the positional parameters remain unchanged.
4215 @end table
4216
4217 Using @samp{+} rather than @samp{-} causes these options to be
4218 turned off.  The options can also be used upon invocation of the
4219 shell.  The current set of options may be found in @code{$-}.
4220
4221 The remaining N @var{arguments} are positional parameters and are
4222 assigned, in order, to @code{$1}, @code{$2}, @dots{}  @code{$N}.
4223 The special parameter @code{#} is set to N.
4224
4225 The return status is always zero unless an invalid option is supplied.
4226 @end table
4227
4228 @node The Shopt Builtin
4229 @subsection The Shopt Builtin
4230
4231 This builtin allows you to change additional shell optional behavior.
4232
4233 @table @code
4234
4235 @item shopt
4236 @btindex shopt
4237 @example
4238 shopt [-pqsu] [-o] [@var{optname} @dots{}]
4239 @end example
4240 Toggle the values of variables controlling optional shell behavior.
4241 With no options, or with the @option{-p} option, a list of all settable
4242 options is displayed, with an indication of whether or not each is set.
4243 The @option{-p} option causes output to be displayed in a form that
4244 may be reused as input.
4245 Other options have the following meanings:
4246
4247 @table @code
4248 @item -s
4249 Enable (set) each @var{optname}.
4250
4251 @item -u
4252 Disable (unset) each @var{optname}.
4253
4254 @item -q
4255 Suppresses normal output; the return status
4256 indicates whether the @var{optname} is set or unset.
4257 If multiple @var{optname} arguments are given with @option{-q},
4258 the return status is zero if all @var{optnames} are enabled;
4259 non-zero otherwise.
4260
4261 @item -o
4262 Restricts the values of
4263 @var{optname} to be those defined for the @option{-o} option to the
4264 @code{set} builtin (@pxref{The Set Builtin}).
4265 @end table
4266
4267 If either @option{-s} or @option{-u}
4268 is used with no @var{optname} arguments, the display is limited to
4269 those options which are set or unset, respectively.
4270
4271 Unless otherwise noted, the @code{shopt} options are disabled (off)
4272 by default.
4273
4274 The return status when listing options is zero if all @var{optnames}
4275 are enabled, non-zero otherwise.  When setting or unsetting options,
4276 the return status is zero unless an @var{optname} is not a valid shell
4277 option.
4278
4279 The list of @code{shopt} options is:
4280 @table @code
4281
4282 @item autocd
4283 If set, a command name that is the name of a directory is executed as if
4284 it were the argument to the @code{cd} command.
4285 This option is only used by interactive shells.
4286
4287 @item cdable_vars
4288 If this is set, an argument to the @code{cd} builtin command that
4289 is not a directory is assumed to be the name of a variable whose
4290 value is the directory to change to.
4291
4292 @item cdspell
4293 If set, minor errors in the spelling of a directory component in a
4294 @code{cd} command will be corrected.
4295 The errors checked for are transposed characters,
4296 a missing character, and a character too many.
4297 If a correction is found, the corrected path is printed,
4298 and the command proceeds.
4299 This option is only used by interactive shells.
4300
4301 @item checkhash
4302 If this is set, Bash checks that a command found in the hash
4303 table exists before trying to execute it.  If a hashed command no
4304 longer exists, a normal path search is performed.
4305
4306 @item checkjobs
4307 If set, Bash lists the status of any stopped and running jobs before
4308 exiting an interactive shell.  If any jobs are running, this causes
4309 the exit to be deferred until a second exit is attempted without an
4310 intervening command (@pxref{Job Control}).
4311 The shell always postpones exiting if any jobs are stopped.
4312
4313 @item checkwinsize
4314 If set, Bash checks the window size after each command
4315 and, if necessary, updates the values of    
4316 @env{LINES} and @env{COLUMNS}.
4317
4318 @item cmdhist
4319 If set, Bash
4320 attempts to save all lines of a multiple-line
4321 command in the same history entry.  This allows
4322 easy re-editing of multi-line commands.
4323
4324 @item compat31
4325 If set, Bash
4326 changes its behavior to that of version 3.1 with respect to quoted
4327 arguments to the conditional command's =~ operator.
4328
4329 @item dirspell
4330 If set, Bash
4331 attempts spelling correction on directory names during word completion 
4332 if the directory name initially supplied does not exist.
4333
4334 @item dotglob
4335 If set, Bash includes filenames beginning with a `.' in
4336 the results of filename expansion.
4337
4338 @item execfail
4339 If this is set, a non-interactive shell will not exit if
4340 it cannot execute the file specified as an argument to the @code{exec}
4341 builtin command.  An interactive shell does not exit if @code{exec}
4342 fails.
4343
4344 @item expand_aliases
4345 If set, aliases are expanded as described below under Aliases,
4346 @ref{Aliases}.
4347 This option is enabled by default for interactive shells.
4348
4349 @item extdebug
4350 If set, behavior intended for use by debuggers is enabled:
4351
4352 @enumerate
4353 @item
4354 The @option{-F} option to the @code{declare} builtin (@pxref{Bash Builtins})
4355 displays the source file name and line number corresponding to each function
4356 name supplied as an argument.
4357
4358 @item
4359 If the command run by the @code{DEBUG} trap returns a non-zero value, the
4360 next command is skipped and not executed.
4361
4362 @item
4363 If the command run by the @code{DEBUG} trap returns a value of 2, and the
4364 shell is executing in a subroutine (a shell function or a shell script
4365 executed by the @code{.} or @code{source} builtins), a call to
4366 @code{return} is simulated.
4367
4368 @item
4369 @code{BASH_ARGC} and @code{BASH_ARGV} are updated as described in their
4370 descriptions (@pxref{Bash Variables}).
4371
4372 @item
4373 Function tracing is enabled:  command substitution, shell functions, and
4374 subshells invoked with @code{( @var{command} )} inherit the
4375 @code{DEBUG} and @code{RETURN} traps.
4376
4377 @item
4378 Error tracing is enabled:  command substitution, shell functions, and
4379 subshells invoked with @code{( @var{command} )} inherit the
4380 @code{ERROR} trap.
4381 @end enumerate
4382
4383 @item extglob
4384 If set, the extended pattern matching features described above
4385 (@pxref{Pattern Matching}) are enabled.
4386
4387 @item extquote
4388 If set, @code{$'@var{string}'} and @code{$"@var{string}"} quoting is  
4389 performed within @code{$@{@var{parameter}@}} expansions                     
4390 enclosed in double quotes.  This option is enabled by default. 
4391
4392 @item failglob
4393 If set, patterns which fail to match filenames during pathname expansion
4394 result in an expansion error.
4395
4396 @item force_fignore
4397 If set, the suffixes specified by the @env{FIGNORE} shell variable
4398 cause words to be ignored when performing word completion even if
4399 the ignored words are the only possible completions.
4400 @xref{Bash Variables}, for a description of @env{FIGNORE}.
4401 This option is enabled by default.
4402
4403 @item globstar
4404 If set, the pattern @samp{**} used in a filename expansion context will
4405 match a files and zero or more directories and subdirectories.
4406 If the pattern is followed by a @samp{/}, only directories and
4407 subdirectories match.
4408
4409 @item gnu_errfmt
4410 If set, shell error messages are written in the standard @sc{gnu} error
4411 message format.
4412
4413 @item histappend
4414 If set, the history list is appended to the file named by the value
4415 of the @env{HISTFILE}
4416 variable when the shell exits, rather than overwriting the file.
4417
4418 @item histreedit
4419 If set, and Readline
4420 is being used, a user is given the opportunity to re-edit a
4421 failed history substitution.
4422
4423 @item histverify
4424 If set, and Readline
4425 is being used, the results of history substitution are not immediately
4426 passed to the shell parser.  Instead, the resulting line is loaded into
4427 the Readline editing buffer, allowing further modification.
4428
4429 @item hostcomplete
4430 If set, and Readline is being used, Bash will attempt to perform
4431 hostname completion when a word containing a @samp{@@} is being
4432 completed (@pxref{Commands For Completion}).  This option is enabled
4433 by default.
4434
4435 @item huponexit
4436 If set, Bash will send @code{SIGHUP} to all jobs when an interactive
4437 login shell exits (@pxref{Signals}).
4438
4439 @item interactive_comments
4440 Allow a word beginning with @samp{#}
4441 to cause that word and all remaining characters on that
4442 line to be ignored in an interactive shell.
4443 This option is enabled by default.
4444
4445 @item lithist
4446 If enabled, and the @code{cmdhist}
4447 option is enabled, multi-line commands are saved to the history with
4448 embedded newlines rather than using semicolon separators where possible.
4449
4450 @item login_shell
4451 The shell sets this option if it is started as a login shell
4452 (@pxref{Invoking Bash}).
4453 The value may not be changed.
4454
4455 @item mailwarn
4456 If set, and a file that Bash is checking for mail has been  
4457 accessed since the last time it was checked, the message
4458 @code{"The mail in @var{mailfile} has been read"} is displayed.
4459
4460 @item no_empty_cmd_completion
4461 If set, and Readline is being used, Bash will not attempt to search
4462 the @env{PATH} for possible completions when completion is attempted
4463 on an empty line.
4464
4465 @item nocaseglob
4466 If set, Bash matches filenames in a case-insensitive fashion when
4467 performing filename expansion.
4468
4469 @item nocasematch
4470 If set, Bash matches patterns in a case-insensitive fashion when
4471 performing matching while executing @code{case} or @code{[[}
4472 conditional commands.
4473
4474 @item nullglob
4475 If set, Bash allows filename patterns which match no
4476 files to expand to a null string, rather than themselves.
4477
4478 @item progcomp
4479 If set, the programmable completion facilities
4480 (@pxref{Programmable Completion}) are enabled.
4481 This option is enabled by default.
4482
4483 @item promptvars
4484 If set, prompt strings undergo
4485 parameter expansion, command substitution, arithmetic
4486 expansion, and quote removal after being expanded
4487 as described below (@pxref{Printing a Prompt}).
4488 This option is enabled by default.
4489
4490 @item restricted_shell
4491 The shell sets this option if it is started in restricted mode
4492 (@pxref{The Restricted Shell}).
4493 The value may not be changed.
4494 This is not reset when the startup files are executed, allowing
4495 the startup files to discover whether or not a shell is restricted.
4496
4497 @item shift_verbose
4498 If this is set, the @code{shift}
4499 builtin prints an error message when the shift count exceeds the
4500 number of positional parameters.
4501
4502 @item sourcepath
4503 If set, the @code{source} builtin uses the value of @env{PATH}
4504 to find the directory containing the file supplied as an argument.
4505 This option is enabled by default.
4506
4507 @item xpg_echo
4508 If set, the @code{echo} builtin expands backslash-escape sequences
4509 by default.
4510
4511 @end table
4512
4513 @noindent
4514 The return status when listing options is zero if all @var{optnames}
4515 are enabled, non-zero otherwise.
4516 When setting or unsetting options, the return status is zero unless an
4517 @var{optname} is not a valid shell option.
4518
4519 @end table
4520
4521 @node Special Builtins
4522 @section Special Builtins
4523 @cindex special builtin
4524
4525 For historical reasons, the @sc{posix} standard has classified
4526 several builtin commands as @emph{special}.
4527 When Bash is executing in @sc{posix} mode, the special builtins
4528 differ from other builtin commands in three respects:
4529
4530 @enumerate
4531 @item
4532 Special builtins are found before shell functions during command lookup.
4533
4534 @item
4535 If a special builtin returns an error status, a non-interactive shell exits.
4536
4537 @item
4538 Assignment statements preceding the command stay in effect in the shell
4539 environment after the command completes.
4540 @end enumerate
4541
4542 When Bash is not executing in @sc{posix} mode, these builtins behave no
4543 differently than the rest of the Bash builtin commands.
4544 The Bash @sc{posix} mode is described in @ref{Bash POSIX Mode}. 
4545
4546 These are the @sc{posix} special builtins:
4547 @example
4548 @w{break : . continue eval exec exit export readonly return set}
4549 @w{shift trap unset}
4550 @end example
4551
4552 @node Shell Variables
4553 @chapter Shell Variables
4554
4555 @menu
4556 * Bourne Shell Variables::      Variables which Bash uses in the same way
4557                                 as the Bourne Shell.
4558 * Bash Variables::              List of variables that exist in Bash.
4559 @end menu
4560
4561 This chapter describes the shell variables that Bash uses.
4562 Bash automatically assigns default values to a number of variables.
4563
4564 @node Bourne Shell Variables
4565 @section Bourne Shell Variables
4566
4567 Bash uses certain shell variables in the same way as the Bourne shell.
4568 In some cases, Bash assigns a default value to the variable.
4569
4570 @vtable @code
4571
4572 @item CDPATH
4573 A colon-separated list of directories used as a search path for
4574 the @code{cd} builtin command.
4575
4576 @item HOME
4577 The current user's home directory; the default for the @code{cd} builtin
4578 command.
4579 The value of this variable is also used by tilde expansion
4580 (@pxref{Tilde Expansion}).
4581
4582 @item IFS
4583 A list of characters that separate fields; used when the shell splits
4584 words as part of expansion.
4585
4586 @item MAIL
4587 If this parameter is set to a filename and the @env{MAILPATH} variable
4588 is not set, Bash informs the user of the arrival of mail in
4589 the specified file.
4590
4591 @item MAILPATH
4592 A colon-separated list of filenames which the shell periodically checks
4593 for new mail.
4594 Each list entry can specify the message that is printed when new mail
4595 arrives in the mail file by separating the file name from the message with
4596 a @samp{?}.
4597 When used in the text of the message, @code{$_} expands to the name of
4598 the current mail file.
4599
4600 @item OPTARG
4601 The value of the last option argument processed by the @code{getopts} builtin.
4602
4603 @item OPTIND
4604 The index of the last option argument processed by the @code{getopts} builtin.
4605
4606 @item PATH
4607 A colon-separated list of directories in which the shell looks for
4608 commands.
4609 A zero-length (null) directory name in the value of @code{PATH} indicates the
4610 current directory.
4611 A null directory name may appear as two adjacent colons, or as an initial
4612 or trailing colon.
4613
4614
4615 @item PS1
4616 The primary prompt string.  The default value is @samp{\s-\v\$ }.
4617 @xref{Printing a Prompt}, for the complete list of escape
4618 sequences that are expanded before @env{PS1} is displayed.
4619
4620 @item PS2
4621 The secondary prompt string.  The default value is @samp{> }.
4622
4623 @end vtable
4624
4625 @node Bash Variables
4626 @section Bash Variables
4627
4628 These variables are set or used by Bash, but other shells
4629 do not normally treat them specially.
4630
4631 A few variables used by Bash are described in different chapters:
4632 variables for controlling the job control facilities
4633 (@pxref{Job Control Variables}).
4634
4635 @vtable @code
4636
4637 @item BASH
4638 The full pathname used to execute the current instance of Bash.
4639
4640 @item BASHPID
4641 Expands to the process id of the current Bash process.
4642 This differs from @code{$$} under certain circumstances, such as subshells
4643 that do not require Bash to be re-initialized.
4644
4645 @item BASH_ALIASES
4646 An associative array variable whose members correspond to the internal
4647 list of aliases as maintained by the @code{alias} builtin
4648 (@pxref{Bourne Shell Builtins}).
4649 Elements added to this array appear in the alias list; unsetting array
4650 elements cause aliases to be removed from the alias list.
4651
4652 @item BASH_ARGC
4653 An array variable whose values are the number of parameters in each
4654 frame of the current bash execution call stack.  The number of
4655 parameters to the current subroutine (shell function or script executed
4656 with @code{.} or @code{source}) is at the top of the stack.  When a
4657 subroutine is executed, the number of parameters passed is pushed onto
4658 @code{BASH_ARGC}.
4659 The shell sets @code{BASH_ARGC} only when in extended debugging mode
4660 (see @ref{The Shopt Builtin}
4661 for a description of the @code{extdebug} option to the @code{shopt}
4662 builtin).
4663
4664 @item BASH_ARGV
4665 An array variable containing all of the parameters in the current bash
4666 execution call stack.  The final parameter of the last subroutine call
4667 is at the top of the stack; the first parameter of the initial call is
4668 at the bottom.  When a subroutine is executed, the parameters supplied
4669 are pushed onto @code{BASH_ARGV}.
4670 The shell sets @code{BASH_ARGV} only when in extended debugging mode
4671 (see @ref{The Shopt Builtin}
4672 for a description of the @code{extdebug} option to the @code{shopt}
4673 builtin).
4674
4675 @item BASH_CMDS
4676 An associative array variable whose members correspond to the internal
4677 hash table of commands as maintained by the @code{hash} builtin
4678 (@pxref{Bourne Shell Builtins}).
4679 Elements added to this array appear in the hash table; unsetting array
4680 elements cause commands to be removed from the hash table.
4681
4682 @item BASH_COMMAND
4683 The command currently being executed or about to be executed, unless the
4684 shell is executing a command as the result of a trap,
4685 in which case it is the command executing at the time of the trap.
4686
4687 @item BASH_ENV
4688 If this variable is set when Bash is invoked to execute a shell
4689 script, its value is expanded and used as the name of a startup file
4690 to read before executing the script.  @xref{Bash Startup Files}.
4691
4692 @item BASH_EXECUTION_STRING
4693 The command argument to the @option{-c} invocation option.
4694
4695 @item BASH_LINENO
4696 An array variable whose members are the line numbers in source files
4697 corresponding to each member of @var{FUNCNAME}.
4698 @code{$@{BASH_LINENO[$i]@}} is the line number in the source file where
4699 @code{$@{FUNCNAME[$i]@}} was called (or @code{$@{BASH_LINENO[$i-1]@}} if
4700 referenced within another shell function).
4701 The corresponding source file name is @code{$@{BASH_SOURCE[$i]@}}.
4702 Use @code{LINENO} to obtain the current line number.
4703
4704 @item BASH_REMATCH
4705 An array variable whose members are assigned by the @samp{=~} binary
4706 operator to the @code{[[} conditional command
4707 (@pxref{Conditional Constructs}).
4708 The element with index 0 is the portion of the string
4709 matching the entire regular expression.
4710 The element with index @var{n} is the portion of the
4711 string matching the @var{n}th parenthesized subexpression.
4712 This variable is read-only.
4713
4714 @item BASH_SOURCE
4715 An array variable whose members are the source filenames corresponding
4716 to the elements in the @code{FUNCNAME} array variable.
4717
4718 @item BASH_SUBSHELL
4719 Incremented by one each time a subshell or subshell environment is spawned.
4720 The initial value is 0.
4721
4722 @item BASH_VERSINFO
4723 A readonly array variable (@pxref{Arrays})
4724 whose members hold version information for this instance of Bash.
4725 The values assigned to the array members are as follows:
4726
4727 @table @code
4728
4729 @item BASH_VERSINFO[0]
4730 The major version number (the @var{release}).
4731
4732 @item BASH_VERSINFO[1]
4733 The minor version number (the @var{version}).
4734
4735 @item BASH_VERSINFO[2]
4736 The patch level.
4737
4738 @item BASH_VERSINFO[3]
4739 The build version.
4740
4741 @item BASH_VERSINFO[4]
4742 The release status (e.g., @var{beta1}).
4743
4744 @item BASH_VERSINFO[5]
4745 The value of @env{MACHTYPE}.
4746
4747 @end table
4748
4749 @item BASH_VERSION
4750 The version number of the current instance of Bash.
4751
4752 @item COLUMNS
4753 Used by the @code{select} builtin command to determine the terminal width
4754 when printing selection lists.  Automatically set upon receipt of a
4755 @code{SIGWINCH}.
4756
4757 @item COMP_CWORD
4758 An index into @env{$@{COMP_WORDS@}} of the word containing the current
4759 cursor position.
4760 This variable is available only in shell functions invoked by the
4761 programmable completion facilities (@pxref{Programmable Completion}).
4762
4763 @item COMP_LINE
4764 The current command line.
4765 This variable is available only in shell functions and external
4766 commands invoked by the
4767 programmable completion facilities (@pxref{Programmable Completion}).
4768
4769 @item COMP_POINT
4770 The index of the current cursor position relative to the beginning of
4771 the current command.
4772 If the current cursor position is at the end of the current command,
4773 the value of this variable is equal to @code{$@{#COMP_LINE@}}.
4774 This variable is available only in shell functions and external
4775 commands invoked by the
4776 programmable completion facilities (@pxref{Programmable Completion}).
4777
4778 @item COMP_TYPE
4779 Set to an integer value corresponding to the type of completion attempted
4780 that caused a completion function to be called:
4781 @var{TAB}, for normal completion,
4782 @samp{?}, for listing completions after successive tabs,
4783 @samp{!}, for listing alternatives on partial word completion,
4784 @samp{@@}, to list completions if the word is not unmodified,
4785 or
4786 @samp{%}, for menu completion.
4787 This variable is available only in shell functions and external
4788 commands invoked by the
4789 programmable completion facilities (@pxref{Programmable Completion}).
4790
4791 @item COMP_KEY
4792 The key (or final key of a key sequence) used to invoke the current
4793 completion function.
4794
4795 @item COMP_WORDBREAKS
4796 The set of characters that the Readline library treats as word
4797 separators when performing word completion.
4798 If @code{COMP_WORDBREAKS} is unset, it loses its special properties,
4799 even if it is subsequently reset.
4800
4801 @item COMP_WORDS
4802 An array variable consisting of the individual
4803 words in the current command line.
4804 The line is split into words as Readline would split it, using
4805 @code{COMP_WORDBREAKS} as described above.
4806 This variable is available only in shell functions invoked by the
4807 programmable completion facilities (@pxref{Programmable Completion}).
4808
4809 @item COMPREPLY
4810 An array variable from which Bash reads the possible completions
4811 generated by a shell function invoked by the programmable completion
4812 facility (@pxref{Programmable Completion}).
4813
4814 @item DIRSTACK
4815 An array variable containing the current contents of the directory stack.
4816 Directories appear in the stack in the order they are displayed by the
4817 @code{dirs} builtin.
4818 Assigning to members of this array variable may be used to modify
4819 directories already in the stack, but the @code{pushd} and @code{popd}
4820 builtins must be used to add and remove directories.
4821 Assignment to this variable will not change the current directory.
4822 If @env{DIRSTACK} is unset, it loses its special properties, even if
4823 it is subsequently reset.
4824
4825 @item EMACS
4826 If Bash finds this variable in the environment when the shell
4827 starts with value @samp{t}, it assumes that the shell is running in an
4828 emacs shell buffer and disables line editing.
4829
4830 @item EUID
4831 The numeric effective user id of the current user.  This variable
4832 is readonly.
4833
4834 @item FCEDIT
4835 The editor used as a default by the @option{-e} option to the @code{fc}
4836 builtin command.
4837
4838 @item FIGNORE
4839 A colon-separated list of suffixes to ignore when performing
4840 filename completion.
4841 A file name whose suffix matches one of the entries in 
4842 @env{FIGNORE}
4843 is excluded from the list of matched file names.  A sample
4844 value is @samp{.o:~}
4845
4846 @item FUNCNAME
4847 An array variable containing the names of all shell functions
4848 currently in the execution call stack.
4849 The element with index 0 is the name of any currently-executing
4850 shell function.
4851 The bottom-most element is @code{"main"}.
4852 This variable exists only when a shell function is executing.
4853 Assignments to @env{FUNCNAME} have no effect and return an error status.
4854 If @env{FUNCNAME} is unset, it loses its special properties, even if
4855 it is subsequently reset.
4856
4857 @item GLOBIGNORE
4858 A colon-separated list of patterns defining the set of filenames to
4859 be ignored by filename expansion.
4860 If a filename matched by a filename expansion pattern also matches one
4861 of the patterns in @env{GLOBIGNORE}, it is removed from the list
4862 of matches.
4863
4864 @item GROUPS
4865 An array variable containing the list of groups of which the current    
4866 user is a member.
4867 Assignments to @env{GROUPS} have no effect and return an error status.
4868 If @env{GROUPS} is unset, it loses its special properties, even if it is
4869 subsequently reset.
4870
4871 @item histchars
4872 Up to three characters which control history expansion, quick
4873 substitution, and tokenization (@pxref{History Interaction}).
4874 The first character is the
4875 @var{history expansion} character, that is, the character which signifies the
4876 start of a history expansion, normally @samp{!}.  The second character is the
4877 character which signifies `quick substitution' when seen as the first
4878 character on a line, normally @samp{^}.  The optional third character is the
4879 character which indicates that the remainder of the line is a comment when
4880 found as the first character of a word, usually @samp{#}.  The history
4881 comment character causes history substitution to be skipped for the
4882 remaining words on the line.  It does not necessarily cause the shell
4883 parser to treat the rest of the line as a comment.
4884
4885 @item HISTCMD
4886 The history number, or index in the history list, of the current
4887 command.  If @env{HISTCMD} is unset, it loses its special properties,
4888 even if it is subsequently reset.
4889
4890 @item HISTCONTROL
4891 A colon-separated list of values controlling how commands are saved on
4892 the history list.
4893 If the list of values includes @samp{ignorespace}, lines which begin
4894 with a space character are not saved in the history list.
4895 A value of @samp{ignoredups} causes lines which match the previous
4896 history entry to not be saved.
4897 A value of @samp{ignoreboth} is shorthand for
4898 @samp{ignorespace} and @samp{ignoredups}.
4899 A value of @samp{erasedups} causes all previous lines matching the
4900 current line to be removed from the history list before that line
4901 is saved.
4902 Any value not in the above list is ignored.
4903 If @env{HISTCONTROL} is unset, or does not include a valid value, 
4904 all lines read by the shell parser are saved on the history list, 
4905 subject to the value of @env{HISTIGNORE}.
4906 The second and subsequent lines of a multi-line compound command are
4907 not tested, and are added to the history regardless of the value of
4908 @env{HISTCONTROL}.
4909
4910 @item HISTFILE
4911 The name of the file to which the command history is saved.  The
4912 default value is @file{~/.bash_history}.
4913
4914 @item HISTFILESIZE
4915 The maximum number of lines contained in the history file.  When this
4916 variable is assigned a value, the history file is truncated, if
4917 necessary, by removing the oldest entries,
4918 to contain no more than that number of lines.
4919 The history file is also truncated to this size after
4920 writing it when an interactive shell exits.
4921 The default value is 500.
4922
4923 @item HISTIGNORE
4924 A colon-separated list of patterns used to decide which command
4925 lines should be saved on the history list.  Each pattern is
4926 anchored at the beginning of the line and must match the complete
4927 line (no implicit @samp{*} is appended).  Each pattern is tested
4928 against the line after the checks specified by @env{HISTCONTROL}
4929 are applied.  In addition to the normal shell pattern matching
4930 characters, @samp{&} matches the previous history line.  @samp{&}
4931 may be escaped using a backslash; the backslash is removed
4932 before attempting a match. 
4933 The second and subsequent lines of a multi-line compound command are
4934 not tested, and are added to the history regardless of the value of
4935 @env{HISTIGNORE}.
4936
4937 @env{HISTIGNORE} subsumes the function of @env{HISTCONTROL}.  A
4938 pattern of @samp{&} is identical to @code{ignoredups}, and a
4939 pattern of @samp{[ ]*} is identical to @code{ignorespace}. 
4940 Combining these two patterns, separating them with a colon,
4941 provides the functionality of @code{ignoreboth}. 
4942
4943 @item HISTSIZE
4944 The maximum number of commands to remember on the history list.
4945 The default value is 500.
4946
4947 @item HISTTIMEFORMAT
4948 If this variable is set and not null, its value is used as a format string
4949 for @var{strftime} to print the time stamp associated with each history
4950 entry displayed by the @code{history} builtin.
4951 If this variable is set, time stamps are written to the history file so
4952 they may be preserved across shell sessions.
4953 This uses the history comment character to distinguish timestamps from
4954 other history lines.
4955
4956 @item HOSTFILE
4957 Contains the name of a file in the same format as @file{/etc/hosts} that
4958 should be read when the shell needs to complete a hostname.
4959 The list of possible hostname completions may be changed while the shell
4960 is running;
4961 the next time hostname completion is attempted after the
4962 value is changed, Bash adds the contents of the new file to the
4963 existing list.
4964 If @env{HOSTFILE} is set, but has no value, Bash attempts to read 
4965 @file{/etc/hosts} to obtain the list of possible hostname completions.
4966 When @env{HOSTFILE} is unset, the hostname list is cleared.
4967
4968 @item HOSTNAME
4969 The name of the current host.
4970
4971 @item HOSTTYPE
4972 A string describing the machine Bash is running on.
4973
4974 @item IGNOREEOF
4975 Controls the action of the shell on receipt of an @code{EOF} character
4976 as the sole input.  If set, the value denotes the number
4977 of consecutive @code{EOF} characters that can be read as the
4978 first character on an input line
4979 before the shell will exit.  If the variable exists but does not
4980 have a numeric value (or has no value) then the default is 10.
4981 If the variable does not exist, then @code{EOF} signifies the end of 
4982 input to the shell.  This is only in effect for interactive shells.
4983
4984 @item INPUTRC
4985 The name of the Readline initialization file, overriding the default
4986 of @file{~/.inputrc}.
4987
4988 @item LANG  
4989 Used to determine the locale category for any category not specifically
4990 selected with a variable starting with @code{LC_}.
4991
4992 @item LC_ALL
4993 This variable overrides the value of @env{LANG} and any other
4994 @code{LC_} variable specifying a locale category.
4995
4996 @item LC_COLLATE
4997 This variable determines the collation order used when sorting the
4998 results of filename expansion, and
4999 determines the behavior of range expressions, equivalence classes,
5000 and collating sequences within filename expansion and pattern matching
5001 (@pxref{Filename Expansion}).
5002
5003 @item LC_CTYPE
5004 This variable determines the interpretation of characters and the
5005 behavior of character classes within filename expansion and pattern
5006 matching (@pxref{Filename Expansion}).
5007
5008 @item LC_MESSAGES
5009 This variable determines the locale used to translate double-quoted
5010 strings preceded by a @samp{$} (@pxref{Locale Translation}).
5011
5012 @item LC_NUMERIC
5013 This variable determines the locale category used for number formatting.
5014
5015 @item LINENO
5016 The line number in the script or shell function currently executing.
5017
5018 @item LINES
5019 Used by the @code{select} builtin command to determine the column length
5020 for printing selection lists.  Automatically set upon receipt of a
5021 @code{SIGWINCH}.
5022
5023 @item MACHTYPE
5024 A string that fully describes the system type on which Bash
5025 is executing, in the standard @sc{gnu} @var{cpu-company-system} format.
5026
5027 @item MAILCHECK
5028 How often (in seconds) that the shell should check for mail in the
5029 files specified in the @env{MAILPATH} or @env{MAIL} variables.
5030 The default is 60 seconds.  When it is time to check
5031 for mail, the shell does so before displaying the primary prompt.
5032 If this variable is unset, or set to a value that is not a number
5033 greater than or equal to zero, the shell disables mail checking.
5034
5035 @item OLDPWD
5036 The previous working directory as set by the @code{cd} builtin.
5037
5038 @item OPTERR
5039 If set to the value 1, Bash displays error messages
5040 generated by the @code{getopts} builtin command.
5041
5042 @item OSTYPE
5043 A string describing the operating system Bash is running on.
5044
5045 @item PIPESTATUS
5046 An array variable (@pxref{Arrays})
5047 containing a list of exit status values from the processes
5048 in the most-recently-executed foreground pipeline (which may
5049 contain only a single command).
5050
5051 @item POSIXLY_CORRECT
5052 If this variable is in the environment when @code{bash} starts, the shell
5053 enters @sc{posix} mode (@pxref{Bash POSIX Mode}) before reading the
5054 startup files, as if the @option{--posix} invocation option had been supplied.
5055 If it is set while the shell is running, @code{bash} enables @sc{posix} mode,
5056 as if the command
5057 @example
5058 @code{set -o posix}
5059 @end example
5060 @noindent
5061 had been executed.  
5062
5063 @item PPID
5064 The process @sc{id} of the shell's parent process.  This variable
5065 is readonly.
5066
5067 @item PROMPT_COMMAND
5068 If set, the value is interpreted as a command to execute
5069 before the printing of each primary prompt (@env{$PS1}).
5070
5071 @item PROMPT_DIRTRIM
5072 If set to a number greater than zero, the value is used as the number of
5073 trailing directory components to retain when expanding the @code{\w} and
5074 @code{\W} prompt string escapes (@pxref{Printing a Prompt}).
5075 Characters removed are replaced with an ellipsis.
5076
5077 @item PS3
5078 The value of this variable is used as the prompt for the
5079 @code{select} command.  If this variable is not set, the
5080 @code{select} command prompts with @samp{#? }
5081
5082 @item PS4
5083 The value is the prompt printed before the command line is echoed
5084 when the @option{-x} option is set (@pxref{The Set Builtin}).
5085 The first character of @env{PS4} is replicated multiple times, as
5086 necessary, to indicate multiple levels of indirection.
5087 The default is @samp{+ }.
5088
5089 @item PWD
5090 The current working directory as set by the @code{cd} builtin.
5091
5092 @item RANDOM
5093 Each time this parameter is referenced, a random integer
5094 between 0 and 32767 is generated.  Assigning a value to this
5095 variable seeds the random number generator.
5096
5097 @item REPLY
5098 The default variable for the @code{read} builtin.
5099
5100 @item SECONDS
5101 This variable expands to the number of seconds since the
5102 shell was started.  Assignment to this variable resets
5103 the count to the value assigned, and the expanded value
5104 becomes the value assigned plus the number of seconds
5105 since the assignment.
5106
5107 @item SHELL
5108 The full pathname to the shell is kept in this environment variable.
5109 If it is not set when the shell starts,
5110 Bash assigns to it the full pathname of the current user's login shell.
5111
5112 @item SHELLOPTS
5113 A colon-separated list of enabled shell options.  Each word in
5114 the list is a valid argument for the @option{-o} option to the
5115 @code{set} builtin command (@pxref{The Set Builtin}).
5116 The options appearing in @env{SHELLOPTS} are those reported
5117 as @samp{on} by @samp{set -o}.
5118 If this variable is in the environment when Bash
5119 starts up, each shell option in the list will be enabled before
5120 reading any startup files.  This variable is readonly.
5121
5122 @item SHLVL
5123 Incremented by one each time a new instance of Bash is started.  This is
5124 intended to be a count of how deeply your Bash shells are nested.
5125
5126 @item TIMEFORMAT
5127 The value of this parameter is used as a format string specifying
5128 how the timing information for pipelines prefixed with the @code{time}
5129 reserved word should be displayed.
5130 The @samp{%} character introduces an
5131 escape sequence that is expanded to a time value or other
5132 information.
5133 The escape sequences and their meanings are as
5134 follows; the braces denote optional portions. 
5135
5136 @table @code
5137
5138 @item %%
5139 A literal @samp{%}.
5140
5141 @item %[@var{p}][l]R
5142 The elapsed time in seconds. 
5143
5144 @item %[@var{p}][l]U
5145 The number of CPU seconds spent in user mode. 
5146
5147 @item %[@var{p}][l]S
5148 The number of CPU seconds spent in system mode. 
5149
5150 @item %P
5151 The CPU percentage, computed as (%U + %S) / %R. 
5152 @end table
5153
5154 The optional @var{p} is a digit specifying the precision, the number of
5155 fractional digits after a decimal point.
5156 A value of 0 causes no decimal point or fraction to be output.
5157 At most three places after the decimal point may be specified; values
5158 of @var{p} greater than 3 are changed to 3.
5159 If @var{p} is not specified, the value 3 is used. 
5160
5161 The optional @code{l} specifies a longer format, including minutes, of
5162 the form @var{MM}m@var{SS}.@var{FF}s.
5163 The value of @var{p} determines whether or not the fraction is included. 
5164
5165 If this variable is not set, Bash acts as if it had the value
5166 @example
5167 @code{$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'}
5168 @end example
5169 If the value is null, no timing information is displayed.
5170 A trailing newline is added when the format string is displayed.
5171
5172 @item TMOUT
5173 If set to a value greater than zero, @code{TMOUT} is treated as the
5174 default timeout for the @code{read} builtin (@pxref{Bash Builtins}).
5175 The @code{select} command (@pxref{Conditional Constructs}) terminates
5176 if input does not arrive after @code{TMOUT} seconds when input is coming
5177 from a terminal.
5178
5179 In an interactive shell, the value is interpreted as
5180 the number of seconds to wait for input after issuing the primary
5181 prompt when the shell is interactive.
5182 Bash terminates after that number of seconds if input does
5183 not arrive.
5184
5185 @item TMPDIR
5186 If set, Bash uses its value as the name of a directory in which
5187 Bash creates temporary files for the shell's use.
5188
5189 @item UID
5190 The numeric real user id of the current user.  This variable is readonly.
5191
5192 @end vtable
5193
5194 @node Bash Features
5195 @chapter Bash Features
5196
5197 This section describes features unique to Bash.
5198
5199 @menu
5200 * Invoking Bash::               Command line options that you can give
5201                                 to Bash.
5202 * Bash Startup Files::          When and how Bash executes scripts.
5203 * Interactive Shells::          What an interactive shell is.
5204 * Bash Conditional Expressions::        Primitives used in composing expressions for
5205                                 the @code{test} builtin.
5206 * Shell Arithmetic::            Arithmetic on shell variables.
5207 * Aliases::                     Substituting one command for another.
5208 * Arrays::                      Array Variables.
5209 * The Directory Stack::         History of visited directories.
5210 * Printing a Prompt::           Controlling the PS1 string.
5211 * The Restricted Shell::        A more controlled mode of shell execution.
5212 * Bash POSIX Mode::             Making Bash behave more closely to what
5213                                 the POSIX standard specifies.
5214 @end menu
5215
5216 @node Invoking Bash
5217 @section Invoking Bash
5218
5219 @example
5220 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] [@var{argument} @dots{}]
5221 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] -c @var{string} [@var{argument} @dots{}]
5222 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o @var{option}] [-O @var{shopt_option}] [@var{argument} @dots{}]
5223 @end example
5224
5225 In addition to the single-character shell command-line options
5226 (@pxref{The Set Builtin}), there are several multi-character
5227 options that you can use.  These options must appear on the command
5228 line before the single-character options to be recognized. 
5229
5230 @table @code
5231 @item --debugger
5232 Arrange for the debugger profile to be executed before the shell
5233 starts.  Turns on extended debugging mode (see @ref{The Shopt Builtin}
5234 for a description of the @code{extdebug} option to the @code{shopt}
5235 builtin) and shell function tracing
5236 (see @ref{The Set Builtin} for a description of the @code{-o functrace}
5237 option).
5238
5239 @item --dump-po-strings
5240 A list of all double-quoted strings preceded by @samp{$}
5241 is printed on the standard output
5242 in the @sc{gnu} @code{gettext} PO (portable object) file format.
5243 Equivalent to @option{-D} except for the output format.
5244
5245 @item --dump-strings
5246 Equivalent to @option{-D}.
5247
5248 @item --help
5249 Display a usage message on standard output and exit successfully.
5250
5251 @item --init-file @var{filename}
5252 @itemx --rcfile @var{filename}
5253 Execute commands from @var{filename} (instead of @file{~/.bashrc})
5254 in an interactive shell.
5255
5256 @item --login
5257 Equivalent to @option{-l}.
5258
5259 @item --noediting
5260 Do not use the @sc{gnu} Readline library (@pxref{Command Line Editing})
5261 to read  command lines when the shell is interactive.
5262
5263 @item --noprofile
5264 Don't load the system-wide startup file @file{/etc/profile}
5265 or any of the personal initialization files
5266 @file{~/.bash_profile}, @file{~/.bash_login}, or @file{~/.profile}
5267 when Bash is invoked as a login shell.
5268
5269 @item --norc
5270 Don't read the @file{~/.bashrc} initialization file in an
5271 interactive shell.  This is on by default if the shell is
5272 invoked as @code{sh}.
5273
5274 @item --posix
5275 Change the behavior of Bash where the default operation differs
5276 from the @sc{posix} standard to match the standard.  This
5277 is intended to make Bash behave as a strict superset of that
5278 standard.  @xref{Bash POSIX Mode}, for a description of the Bash
5279 @sc{posix} mode.
5280
5281 @item --restricted
5282 Make the shell a restricted shell (@pxref{The Restricted Shell}).
5283
5284 @item --verbose
5285 Equivalent to @option{-v}.  Print shell input lines as they're read.
5286
5287 @item --version
5288 Show version information for this instance of
5289 Bash on the standard output and exit successfully.
5290
5291 @end table
5292
5293 There are several single-character options that may be supplied at
5294 invocation which are not available with the @code{set} builtin.
5295
5296 @table @code
5297 @item -c @var{string}
5298 Read and execute commands from @var{string} after processing the
5299 options, then exit.  Any remaining arguments are assigned to the
5300 positional parameters, starting with @code{$0}.
5301
5302 @item -i
5303 Force the shell to run interactively.  Interactive shells are
5304 described in @ref{Interactive Shells}.
5305
5306 @item -l
5307 Make this shell act as if it had been directly invoked by login.
5308 When the shell is interactive, this is equivalent to starting a
5309 login shell with @samp{exec -l bash}.
5310 When the shell is not interactive, the login shell startup files will
5311 be executed.
5312 @samp{exec bash -l} or @samp{exec bash --login}
5313 will replace the current shell with a Bash login shell.
5314 @xref{Bash Startup Files}, for a description of the special behavior
5315 of a login shell.
5316
5317 @item -r
5318 Make the shell a restricted shell (@pxref{The Restricted Shell}).
5319
5320 @item -s
5321 If this option is present, or if no arguments remain after option
5322 processing, then commands are read from the standard input.
5323 This option allows the positional parameters to be set
5324 when invoking an interactive shell.
5325
5326 @item -D
5327 A list of all double-quoted strings preceded by @samp{$}
5328 is printed on the standard output.
5329 These are the strings that
5330 are subject to language translation when the current locale
5331 is not @code{C} or @code{POSIX} (@pxref{Locale Translation}).
5332 This implies the @option{-n} option; no commands will be executed.
5333
5334 @item [-+]O [@var{shopt_option}]
5335 @var{shopt_option} is one of the shell options accepted by the
5336 @code{shopt} builtin (@pxref{The Shopt Builtin}).
5337 If @var{shopt_option} is present, @option{-O} sets the value of that option;
5338 @option{+O} unsets it.  
5339 If @var{shopt_option} is not supplied, the names and values of the shell
5340 options accepted by @code{shopt} are printed on the standard output.
5341 If the invocation option is @option{+O}, the output is displayed in a format
5342 that may be reused as input.
5343
5344 @item --
5345 A @code{--} signals the end of options and disables further option
5346 processing.
5347 Any arguments after the @code{--} are treated as filenames and arguments.
5348
5349 @end table
5350
5351 @cindex login shell
5352 A @emph{login} shell is one whose first character of argument zero is
5353 @samp{-}, or one invoked with the @option{--login} option.
5354
5355 @cindex interactive shell
5356 An @emph{interactive} shell is one started without non-option arguments,
5357 unless @option{-s} is specified,
5358 without specifying the @option{-c} option, and whose input and output are both
5359 connected to terminals (as determined by @code{isatty(3)}), or one
5360 started with the @option{-i} option.  @xref{Interactive Shells}, for more
5361 information.
5362
5363 If arguments remain after option processing, and neither the
5364 @option{-c} nor the @option{-s}
5365 option has been supplied, the first argument is assumed to
5366 be the name of a file containing shell commands (@pxref{Shell Scripts}).
5367 When Bash is invoked in this fashion, @code{$0}
5368 is set to the name of the file, and the positional parameters
5369 are set to the remaining arguments.
5370 Bash reads and executes commands from this file, then exits.   
5371 Bash's exit status is the exit status of the last command executed
5372 in the script.  If no commands are executed, the exit status is 0.
5373
5374 @node Bash Startup Files
5375 @section Bash Startup Files
5376 @cindex startup files
5377
5378 This section describes how Bash executes its startup files.
5379 If any of the files exist but cannot be read, Bash reports an error.
5380 Tildes are expanded in file names as described above under
5381 Tilde Expansion (@pxref{Tilde Expansion}).
5382
5383 Interactive shells are described in @ref{Interactive Shells}.
5384
5385 @subsubheading Invoked as an interactive login shell, or with @option{--login}
5386
5387 When Bash is invoked as an interactive login shell, or as a
5388 non-interactive shell with the @option{--login} option, it first reads and
5389 executes commands from the file @file{/etc/profile}, if that file exists.
5390 After reading that file, it looks for @file{~/.bash_profile},
5391 @file{~/.bash_login}, and @file{~/.profile}, in that order, and reads
5392 and executes commands from the first one that exists and is readable.
5393 The @option{--noprofile} option may be used when the shell is started to
5394 inhibit this behavior.
5395
5396 When a login shell exits, Bash reads and executes commands from
5397 the file @file{~/.bash_logout}, if it exists.
5398
5399 @subsubheading Invoked as an interactive non-login shell
5400
5401 When an interactive shell that is not a login shell is started, Bash
5402 reads and executes commands from @file{~/.bashrc}, if that file exists.
5403 This may be inhibited by using the @option{--norc} option.
5404 The @option{--rcfile @var{file}} option will force Bash to read and
5405 execute commands from @var{file} instead of @file{~/.bashrc}.
5406
5407 So, typically, your @file{~/.bash_profile} contains the line
5408 @example
5409 @code{if [ -f ~/.bashrc ]; then . ~/.bashrc; fi}
5410 @end example
5411 @noindent
5412 after (or before) any login-specific initializations.
5413
5414 @subsubheading Invoked non-interactively
5415
5416 When Bash is started non-interactively, to run a shell script,
5417 for example, it looks for the variable @env{BASH_ENV} in the environment,
5418 expands its value if it appears there, and uses the expanded value as
5419 the name of a file to read and execute.  Bash behaves as if the
5420 following command were executed:
5421 @example
5422 @code{if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi}
5423 @end example
5424 @noindent
5425 but the value of the @env{PATH} variable is not used to search for the
5426 file name.
5427
5428 As noted above, if a non-interactive shell is invoked with the
5429 @option{--login} option, Bash attempts to read and execute commands from the
5430 login shell startup files. 
5431
5432 @subsubheading Invoked with name @code{sh}
5433
5434 If Bash is invoked with the name @code{sh}, it tries to mimic the
5435 startup behavior of historical versions of @code{sh} as closely as
5436 possible, while conforming to the @sc{posix} standard as well.
5437
5438 When invoked as an interactive login shell, or as a non-interactive
5439 shell with the @option{--login} option, it first attempts to read
5440 and execute commands from @file{/etc/profile} and @file{~/.profile}, in
5441 that order.
5442 The @option{--noprofile} option may be used to inhibit this behavior.
5443 When invoked as an interactive shell with the name @code{sh}, Bash
5444 looks for the variable @env{ENV}, expands its value if it is defined,
5445 and uses the expanded value as the name of a file to read and execute.
5446 Since a shell invoked as @code{sh} does not attempt to read and execute
5447 commands from any other startup files, the @option{--rcfile} option has
5448 no effect.
5449 A non-interactive shell invoked with the name @code{sh} does not attempt
5450 to read any other startup files.
5451
5452 When invoked as @code{sh}, Bash enters @sc{posix} mode after
5453 the startup files are read.
5454
5455 @subsubheading Invoked in @sc{posix} mode
5456
5457 When Bash is started in @sc{posix} mode, as with the
5458 @option{--posix} command line option, it follows the @sc{posix} standard
5459 for startup files.
5460 In this mode, interactive shells expand the @env{ENV} variable
5461 and commands are read and executed from the file whose name is the
5462 expanded value.
5463 No other startup files are read.
5464
5465 @subsubheading Invoked by remote shell daemon
5466
5467 Bash attempts to determine when it is being run with its standard input
5468 connected to a a network connection, as if by the remote shell
5469 daemon, usually @code{rshd}, or the secure shell daemon @code{sshd}.
5470 If Bash determines it is being run in
5471 this fashion, it reads and executes commands from @file{~/.bashrc}, if that
5472 file exists and is readable.
5473 It will not do this if invoked as @code{sh}.
5474 The @option{--norc} option may be used to inhibit this behavior, and the
5475 @option{--rcfile} option may be used to force another file to be read, but
5476 @code{rshd} does not generally invoke the shell with those options or
5477 allow them to be specified.
5478
5479 @subsubheading Invoked with unequal effective and real @sc{uid/gid}s
5480
5481 If Bash is started with the effective user (group) id not equal to the
5482 real user (group) id, and the @code{-p} option is not supplied, no startup
5483 files are read, shell functions are not inherited from the environment,
5484 the @env{SHELLOPTS} variable, if it appears in the environment, is ignored,
5485 and the effective user id is set to the real user id.
5486 If the @code{-p} option is supplied at invocation, the startup behavior is
5487 the same, but the effective user id is not reset.
5488
5489 @node Interactive Shells
5490 @section Interactive Shells
5491 @cindex interactive shell
5492 @cindex shell, interactive
5493
5494 @menu
5495 * What is an Interactive Shell?::       What determines whether a shell is Interactive.
5496 * Is this Shell Interactive?::  How to tell if a shell is interactive.
5497 * Interactive Shell Behavior::  What changes in a interactive shell?
5498 @end menu
5499
5500 @node What is an Interactive Shell?
5501 @subsection What is an Interactive Shell?
5502
5503 An interactive shell
5504 is one started without non-option arguments, unless @option{-s} is
5505 specified, without specifying the @option{-c} option, and
5506 whose input and error output are both
5507 connected to terminals (as determined by @code{isatty(3)}),
5508 or one started with the @option{-i} option.
5509
5510 An interactive shell generally reads from and writes to a user's
5511 terminal.
5512
5513 The @option{-s} invocation option may be used to set the positional parameters
5514 when an interactive shell is started.
5515
5516 @node Is this Shell Interactive?
5517 @subsection Is this Shell Interactive?
5518
5519 To determine within a startup script whether or not Bash is
5520 running interactively,
5521 test the value of the @samp{-} special parameter.
5522 It contains @code{i} when the shell is interactive.  For example:
5523
5524 @example
5525 case "$-" in
5526 *i*)    echo This shell is interactive ;;
5527 *)      echo This shell is not interactive ;;
5528 esac
5529 @end example
5530
5531 Alternatively, startup scripts may examine the variable
5532 @env{PS1}; it is unset in non-interactive shells, and set in
5533 interactive shells.  Thus:
5534
5535 @example
5536 if [ -z "$PS1" ]; then
5537         echo This shell is not interactive
5538 else
5539         echo This shell is interactive
5540 fi
5541 @end example
5542
5543 @node Interactive Shell Behavior
5544 @subsection Interactive Shell Behavior
5545
5546 When the shell is running interactively, it changes its behavior in
5547 several ways.
5548
5549 @enumerate
5550 @item
5551 Startup files are read and executed as described in @ref{Bash Startup Files}.
5552
5553 @item
5554 Job Control (@pxref{Job Control}) is enabled by default.  When job
5555 control is in effect, Bash ignores the keyboard-generated job control
5556 signals @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
5557
5558 @item
5559 Bash expands and displays @env{PS1} before reading the first line
5560 of a command, and expands and displays @env{PS2} before reading the
5561 second and subsequent lines of a multi-line command.
5562
5563 @item
5564 Bash executes the value of the @env{PROMPT_COMMAND} variable as a command
5565 before printing the primary prompt, @env{$PS1}
5566 (@pxref{Bash Variables}).
5567
5568 @item
5569 Readline (@pxref{Command Line Editing}) is used to read commands from
5570 the user's terminal.
5571
5572 @item
5573 Bash inspects the value of the @code{ignoreeof} option to @code{set -o}
5574 instead of exiting immediately when it receives an @code{EOF} on its
5575 standard input when reading a command (@pxref{The Set Builtin}).
5576
5577 @item
5578 Command history (@pxref{Bash History Facilities})
5579 and history expansion (@pxref{History Interaction})
5580 are enabled by default.
5581 Bash will save the command history to the file named by @env{$HISTFILE}
5582 when an interactive shell exits.
5583
5584 @item
5585 Alias expansion (@pxref{Aliases}) is performed by default.
5586
5587 @item
5588 In the absence of any traps, Bash ignores @code{SIGTERM}
5589 (@pxref{Signals}).
5590
5591 @item
5592 In the absence of any traps, @code{SIGINT} is caught and handled
5593 ((@pxref{Signals}).
5594 @code{SIGINT} will interrupt some shell builtins.
5595
5596 @item
5597 An interactive login shell sends a @code{SIGHUP} to all jobs on exit
5598 if the @code{huponexit} shell option has been enabled (@pxref{Signals}).
5599
5600 @item
5601 The @option{-n} invocation option is ignored, and @samp{set -n} has
5602 no effect (@pxref{The Set Builtin}).
5603
5604 @item
5605 Bash will check for mail periodically, depending on the values of the
5606 @env{MAIL}, @env{MAILPATH}, and @env{MAILCHECK} shell variables
5607 (@pxref{Bash Variables}).
5608
5609 @item
5610 Expansion errors due to references to unbound shell variables after
5611 @samp{set -u} has been enabled will not cause the shell to exit
5612 (@pxref{The Set Builtin}).
5613
5614 @item
5615 The shell will not exit on expansion errors caused by @var{var} being unset
5616 or null in @code{$@{@var{var}:?@var{word}@}} expansions
5617 (@pxref{Shell Parameter Expansion}).
5618
5619 @item
5620 Redirection errors encountered by shell builtins will not cause the
5621 shell to exit.
5622
5623 @item
5624 When running in @sc{posix} mode, a special builtin returning an error
5625 status will not cause the shell to exit (@pxref{Bash POSIX Mode}).
5626
5627 @item
5628 A failed @code{exec} will not cause the shell to exit
5629 (@pxref{Bourne Shell Builtins}).
5630
5631 @item
5632 Parser syntax errors will not cause the shell to exit.
5633
5634 @item
5635 Simple spelling correction for directory arguments to the @code{cd}
5636 builtin is enabled by default (see the description of the @code{cdspell}
5637 option to the @code{shopt} builtin in @ref{The Shopt Builtin}).
5638
5639 @item
5640 The shell will check the value of the @env{TMOUT} variable and exit
5641 if a command is not read within the specified number of seconds after
5642 printing @env{$PS1} (@pxref{Bash Variables}).
5643
5644 @end enumerate
5645
5646 @node Bash Conditional Expressions
5647 @section Bash Conditional Expressions
5648 @cindex expressions, conditional
5649
5650 Conditional expressions are used by the @code{[[} compound command
5651 and the @code{test} and @code{[} builtin commands.
5652
5653 Expressions may be unary or binary.
5654 Unary expressions are often used to examine the status of a file.
5655 There are string operators and numeric comparison operators as well.
5656 If the @var{file} argument to one of the primaries is of the form
5657 @file{/dev/fd/@var{N}}, then file descriptor @var{N} is checked.
5658 If the @var{file} argument to one of the primaries is one of
5659 @file{/dev/stdin}, @file{/dev/stdout}, or @file{/dev/stderr}, file
5660 descriptor 0, 1, or 2, respectively, is checked.
5661
5662 Unless otherwise specified, primaries that operate on files follow symbolic
5663 links and operate on the target of the link, rather than the link itself.
5664
5665 @table @code
5666 @item -a @var{file}
5667 True if @var{file} exists.
5668
5669 @item -b @var{file}
5670 True if @var{file} exists and is a block special file.
5671
5672 @item -c @var{file}
5673 True if @var{file} exists and is a character special file.
5674
5675 @item -d @var{file}
5676 True if @var{file} exists and is a directory.
5677
5678 @item -e @var{file}
5679 True if @var{file} exists.
5680
5681 @item -f @var{file}
5682 True if @var{file} exists and is a regular file.
5683
5684 @item -g @var{file}
5685 True if @var{file} exists and its set-group-id bit is set.
5686
5687 @item -h @var{file}
5688 True if @var{file} exists and is a symbolic link.
5689
5690 @item -k @var{file}
5691 True if @var{file} exists and its "sticky" bit is set.
5692
5693 @item -p @var{file}
5694 True if @var{file} exists and is a named pipe (FIFO).
5695
5696 @item -r @var{file}
5697 True if @var{file} exists and is readable.
5698
5699 @item -s @var{file}
5700 True if @var{file} exists and has a size greater than zero.
5701
5702 @item -t @var{fd}
5703 True if file descriptor @var{fd} is open and refers to a terminal.
5704
5705 @item -u @var{file}
5706 True if @var{file} exists and its set-user-id bit is set.
5707
5708 @item -w @var{file}
5709 True if @var{file} exists and is writable.
5710
5711 @item -x @var{file}
5712 True if @var{file} exists and is executable.
5713
5714 @item -O @var{file}
5715 True if @var{file} exists and is owned by the effective user id.
5716
5717 @item -G @var{file}
5718 True if @var{file} exists and is owned by the effective group id.
5719
5720 @item -L @var{file}
5721 True if @var{file} exists and is a symbolic link.
5722
5723 @item -S @var{file}
5724 True if @var{file} exists and is a socket.
5725
5726 @item -N @var{file}
5727 True if @var{file} exists and has been modified since it was last read.
5728
5729 @item @var{file1} -nt @var{file2}
5730 True if @var{file1} is newer (according to modification date)
5731 than @var{file2}, or if @var{file1} exists and @var{file2} does not.
5732
5733 @item @var{file1} -ot @var{file2}
5734 True if @var{file1} is older than @var{file2},
5735 or if @var{file2} exists and @var{file1} does not.
5736
5737 @item @var{file1} -ef @var{file2}
5738 True if @var{file1} and @var{file2} refer to the same device and
5739 inode numbers.
5740
5741 @item -o @var{optname}
5742 True if shell option @var{optname} is enabled.
5743 The list of options appears in the description of the @option{-o}
5744 option to the @code{set} builtin (@pxref{The Set Builtin}).
5745
5746 @item -z @var{string}
5747 True if the length of @var{string} is zero.
5748
5749 @item -n @var{string}
5750 @itemx @var{string}
5751 True if the length of @var{string} is non-zero.
5752
5753 @item @var{string1} == @var{string2}
5754 True if the strings are equal.
5755 @samp{=} may be used in place of @samp{==} for strict @sc{posix} compliance.
5756
5757 @item @var{string1} != @var{string2}
5758 True if the strings are not equal.
5759
5760 @item @var{string1} < @var{string2}
5761 True if @var{string1} sorts before @var{string2} lexicographically
5762 in the current locale.
5763
5764 @item @var{string1} > @var{string2}
5765 True if @var{string1} sorts after @var{string2} lexicographically
5766 in the current locale.
5767
5768 @item @var{arg1} OP @var{arg2}
5769 @code{OP} is one of 
5770 @samp{-eq}, @samp{-ne}, @samp{-lt}, @samp{-le}, @samp{-gt}, or @samp{-ge}.
5771 These arithmetic binary operators return true if @var{arg1}
5772 is equal to, not equal to, less than, less than or equal to,
5773 greater than, or greater than or equal to @var{arg2},
5774 respectively.  @var{Arg1} and @var{arg2}
5775 may be positive or negative integers.
5776
5777 @end table
5778
5779 @node Shell Arithmetic
5780 @section Shell Arithmetic
5781 @cindex arithmetic, shell
5782 @cindex shell arithmetic
5783 @cindex expressions, arithmetic
5784 @cindex evaluation, arithmetic
5785 @cindex arithmetic evaluation
5786
5787 The shell allows arithmetic expressions to be evaluated, as one of
5788 the shell expansions or by the @code{let} and the @option{-i} option
5789 to the @code{declare} builtins.
5790
5791 Evaluation is done in fixed-width integers with no check for overflow,
5792 though division by 0 is trapped and flagged as an error.
5793 The operators and their precedence, associativity, and values
5794 are the same as in the C language.
5795 The following list of operators is grouped into levels of
5796 equal-precedence operators.
5797 The levels are listed in order of decreasing precedence. 
5798
5799 @table @code
5800
5801 @item @var{id}++ @var{id}--
5802 variable post-increment and post-decrement 
5803
5804 @item ++@var{id} --@var{id}
5805 variable pre-increment and pre-decrement
5806
5807 @item - +
5808 unary minus and plus
5809
5810 @item ! ~
5811 logical and bitwise negation
5812
5813 @item **
5814 exponentiation
5815
5816 @item * / %
5817 multiplication, division, remainder
5818
5819 @item + -
5820 addition, subtraction
5821
5822 @item << >>
5823 left and right bitwise shifts
5824
5825 @item <= >= < >
5826 comparison
5827
5828 @item == !=
5829 equality and inequality
5830
5831 @item &
5832 bitwise AND
5833
5834 @item ^
5835 bitwise exclusive OR
5836
5837 @item |
5838 bitwise OR
5839
5840 @item &&
5841 logical AND
5842
5843 @item ||
5844 logical OR
5845
5846 @item expr ? expr : expr
5847 conditional operator
5848
5849 @item = *= /= %= += -= <<= >>= &= ^= |=
5850 assignment
5851
5852 @item expr1 , expr2
5853 comma
5854 @end table
5855
5856 Shell variables are allowed as operands; parameter expansion is
5857 performed before the expression is evaluated. 
5858 Within an expression, shell variables may also be referenced by name
5859 without using the parameter expansion syntax.
5860 A shell variable that is null or unset evaluates to 0 when referenced
5861 by name without using the parameter expansion syntax.
5862 The value of a variable is evaluated as an arithmetic expression
5863 when it is referenced, or when a variable which has been given the  
5864 @var{integer} attribute using @samp{declare -i} is assigned a value.
5865 A null value evaluates to 0.
5866 A shell variable need not have its integer attribute turned on
5867 to be used in an expression.
5868
5869 Constants with a leading 0 are interpreted as octal numbers.
5870 A leading @samp{0x} or @samp{0X} denotes hexadecimal.  Otherwise,
5871 numbers take the form [@var{base}@code{#}]@var{n}, where @var{base}
5872 is a decimal number between 2 and 64 representing the arithmetic
5873 base, and @var{n} is a number in that base.  If @var{base}@code{#} is
5874 omitted, then base 10 is used.
5875 The digits greater than 9 are represented by the lowercase letters,
5876 the uppercase letters, @samp{@@}, and @samp{_}, in that order.
5877 If @var{base} is less than or equal to 36, lowercase and uppercase
5878 letters may be used interchangeably to represent numbers between 10
5879 and 35.
5880
5881 Operators are evaluated in order of precedence.  Sub-expressions in
5882 parentheses are evaluated first and may override the precedence
5883 rules above.
5884
5885 @node Aliases
5886 @section Aliases
5887 @cindex alias expansion
5888
5889 @var{Aliases} allow a string to be substituted for a word when it is used
5890 as the first word of a simple command.
5891 The shell maintains a list of aliases that may be set and unset with
5892 the @code{alias} and @code{unalias} builtin commands.
5893
5894 The first word of each simple command, if unquoted, is checked to see
5895 if it has an alias.
5896 If so, that word is replaced by the text of the alias.
5897 The characters @samp{/}, @samp{$}, @samp{`}, @samp{=} and any of the
5898 shell metacharacters or quoting characters listed above may not appear
5899 in an alias name.
5900 The replacement text may contain any valid
5901 shell input, including shell metacharacters.
5902 The first word of the replacement text is tested for
5903 aliases, but a word that is identical to an alias being expanded
5904 is not expanded a second time.
5905 This means that one may alias @code{ls} to @code{"ls -F"},
5906 for instance, and Bash does not try to recursively expand the
5907 replacement text. If the last character of the alias value is a
5908 space or tab character, then the next command word following the
5909 alias is also checked for alias expansion.
5910
5911 Aliases are created and listed with the @code{alias}
5912 command, and removed with the @code{unalias} command.
5913
5914 There is no mechanism for using arguments in the replacement text,
5915 as in @code{csh}.
5916 If arguments are needed, a shell function should be used
5917 (@pxref{Shell Functions}).
5918
5919 Aliases are not expanded when the shell is not interactive,
5920 unless the @code{expand_aliases} shell option is set using
5921 @code{shopt} (@pxref{The Shopt Builtin}).
5922
5923 The rules concerning the definition and use of aliases are
5924 somewhat confusing.  Bash
5925 always reads at least one complete line
5926 of input before executing any
5927 of the commands on that line.  Aliases are expanded when a
5928 command is read, not when it is executed.  Therefore, an
5929 alias definition appearing on the same line as another
5930 command does not take effect until the next line of input is read.
5931 The commands following the alias definition
5932 on that line are not affected by the new alias.
5933 This behavior is also an issue when functions are executed.
5934 Aliases are expanded when a function definition is read,
5935 not when the function is executed, because a function definition
5936 is itself a compound command.  As a consequence, aliases
5937 defined in a function are not available until after that
5938 function is executed.  To be safe, always put
5939 alias definitions on a separate line, and do not use @code{alias}
5940 in compound commands.
5941
5942 For almost every purpose, shell functions are preferred over aliases.
5943
5944 @node Arrays
5945 @section Arrays
5946 @cindex arrays
5947
5948 Bash provides one-dimensional indexed and associative array variables.
5949 Any variable may be used as an indexed array;
5950 the @code{declare} builtin will explicitly declare an array.
5951 There is no maximum
5952 limit on the size of an array, nor any requirement that members
5953 be indexed or assigned contiguously.
5954 Indexed arrays are referenced using integers (including arithmetic
5955 expressions (@pxref{Shell Arithmetic}) and are zero-based;
5956 associative arrays use arbitrary strings.
5957
5958 An indexed array is created automatically if any variable is assigned to
5959 using the syntax
5960 @example
5961 name[@var{subscript}]=@var{value}
5962 @end example
5963
5964 @noindent
5965 The @var{subscript}
5966 is treated as an arithmetic expression that must evaluate to a number
5967 greater than or equal to zero.  To explicitly declare an array, use
5968 @example
5969 declare -a @var{name}
5970 @end example
5971 @noindent
5972 The syntax
5973 @example
5974 declare -a @var{name}[@var{subscript}]
5975 @end example
5976 @noindent
5977 is also accepted; the @var{subscript} is ignored.
5978
5979 Associative arrays are created using
5980 @example
5981 declare -A @var{name}.
5982 @end example
5983
5984 Attributes may be
5985 specified for an array variable using the @code{declare} and
5986 @code{readonly} builtins.  Each attribute applies to all members of
5987 an array.
5988
5989 Arrays are assigned to using compound assignments of the form
5990 @example
5991 name=(value@var{1} @dots{} value@var{n})
5992 @end example
5993 @noindent
5994 where each
5995 @var{value} is of the form @code{[@var{subscript}]=}@var{string}.
5996 Indexed array assignments do not require the bracket and subscript.
5997 When assigning to indexed arrays, if
5998 the optional subscript is supplied, that index is assigned to;
5999 otherwise the index of the element assigned is the last index assigned
6000 to by the statement plus one.  Indexing starts at zero.
6001
6002 When assigning to an associative array, the subscript is required.
6003
6004 This syntax is also accepted by the @code{declare}
6005 builtin.  Individual array elements may be assigned to using the
6006 @code{name[}@var{subscript}@code{]=}@var{value} syntax introduced above.
6007
6008 Any element of an array may be referenced using
6009 @code{$@{name[}@var{subscript}@code{]@}}.
6010 The braces are required to avoid
6011 conflicts with the shell's filename expansion operators.  If the
6012 @var{subscript} is @samp{@@} or @samp{*}, the word expands to all members
6013 of the array @var{name}.  These subscripts differ only when the word
6014 appears within double quotes.
6015 If the word is double-quoted,
6016 @code{$@{name[*]@}} expands to a single word with
6017 the value of each array member separated by the first character of the
6018 @env{IFS} variable, and @code{$@{name[@@]@}} expands each element of
6019 @var{name} to a separate word.  When there are no array members,
6020 @code{$@{name[@@]@}} expands to nothing.
6021 If the double-quoted expansion occurs within a word, the expansion of
6022 the first parameter is joined with the beginning part of the original
6023 word, and the expansion of the last parameter is joined with the last
6024 part of the original word.
6025 This is analogous to the
6026 expansion of the special parameters @samp{@@} and @samp{*}. 
6027 @code{$@{#name[}@var{subscript}@code{]@}} expands to the length of
6028 @code{$@{name[}@var{subscript}@code{]@}}.
6029 If @var{subscript} is @samp{@@} or
6030 @samp{*}, the expansion is the number of elements in the array. 
6031 Referencing an array variable without a subscript is equivalent to
6032 referencing with a subscript of 0. 
6033
6034 The @code{unset} builtin is used to destroy arrays.
6035 @code{unset} @var{name}[@var{subscript}]
6036 destroys the array element at index @var{subscript}.
6037 Care must be taken to avoid unwanted side effects caused by filename
6038 generation.
6039 @code{unset} @var{name}, where @var{name} is an array, removes the
6040 entire array. A subscript of @samp{*} or @samp{@@} also removes the
6041 entire array.
6042
6043 The @code{declare}, @code{local}, and @code{readonly}
6044 builtins each accept a @option{-a} option to specify an indexed
6045 array and a @option{-A} option to specify an associative array.
6046 The @code{read} builtin accepts a @option{-a}
6047 option to assign a list of words read from the standard input
6048 to an array, and can read values from the standard input into
6049 individual array elements.  The @code{set} and @code{declare}
6050 builtins display array values in a way that allows them to be
6051 reused as input.
6052
6053 @node The Directory Stack
6054 @section The Directory Stack
6055 @cindex directory stack
6056
6057 @menu
6058 * Directory Stack Builtins::            Bash builtin commands to manipulate
6059                                         the directory stack.
6060 @end menu
6061
6062 The directory stack is a list of recently-visited directories.  The
6063 @code{pushd} builtin adds directories to the stack as it changes
6064 the current directory, and the @code{popd} builtin removes specified
6065 directories from the stack and changes the current directory to
6066 the directory removed.  The @code{dirs} builtin displays the contents
6067 of the directory stack.
6068
6069 The contents of the directory stack are also visible
6070 as the value of the @env{DIRSTACK} shell variable.
6071
6072 @node Directory Stack Builtins
6073 @subsection Directory Stack Builtins
6074
6075 @table @code
6076
6077 @item dirs
6078 @btindex dirs
6079 @example
6080 dirs [+@var{N} | -@var{N}] [-clpv]
6081 @end example
6082 Display the list of currently remembered directories.  Directories
6083 are added to the list with the @code{pushd} command; the
6084 @code{popd} command removes directories from the list.
6085 @table @code
6086 @item +@var{N}
6087 Displays the @var{N}th directory (counting from the left of the
6088 list printed by @code{dirs} when invoked without options), starting
6089 with zero.
6090 @item -@var{N}
6091 Displays the @var{N}th directory (counting from the right of the
6092 list printed by @code{dirs} when invoked without options), starting
6093 with zero.
6094 @item -c
6095 Clears the directory stack by deleting all of the elements.
6096 @item -l
6097 Produces a longer listing; the default listing format uses a 
6098 tilde to denote the home directory.
6099 @item -p
6100 Causes @code{dirs} to print the directory stack with one entry per
6101 line.
6102 @item -v
6103 Causes @code{dirs} to print the directory stack with one entry per
6104 line, prefixing each entry with its index in the stack.
6105 @end table
6106
6107 @item popd
6108 @btindex popd
6109 @example
6110 popd [+@var{N} | -@var{N}] [-n]
6111 @end example
6112
6113 Remove the top entry from the directory stack, and @code{cd}
6114 to the new top directory.
6115 When no arguments are given, @code{popd}
6116 removes the top directory from the stack and
6117 performs a @code{cd} to the new top directory.  The
6118 elements are numbered from 0 starting at the first directory listed with
6119 @code{dirs}; i.e., @code{popd} is equivalent to @code{popd +0}.
6120 @table @code
6121 @item +@var{N}
6122 Removes the @var{N}th directory (counting from the left of the
6123 list printed by @code{dirs}), starting with zero.
6124 @item -@var{N}
6125 Removes the @var{N}th directory (counting from the right of the
6126 list printed by @code{dirs}), starting with zero.
6127 @item -n
6128 Suppresses the normal change of directory when removing directories
6129 from the stack, so that only the stack is manipulated.
6130 @end table
6131
6132 @btindex pushd
6133 @item pushd
6134 @example
6135 pushd [-n] [@var{+N} | @var{-N} | @var{dir} ]
6136 @end example
6137
6138 Save the current directory on the top of the directory stack
6139 and then @code{cd} to @var{dir}.
6140 With no arguments, @code{pushd} exchanges the top two directories.
6141
6142 @table @code
6143 @item -n
6144 Suppresses the normal change of directory when adding directories
6145 to the stack, so that only the stack is manipulated.
6146 @item +@var{N}
6147 Brings the @var{N}th directory (counting from the left of the
6148 list printed by @code{dirs}, starting with zero) to the top of
6149 the list by rotating the stack.
6150 @item -@var{N}
6151 Brings the @var{N}th directory (counting from the right of the
6152 list printed by @code{dirs}, starting with zero) to the top of
6153 the list by rotating the stack.
6154 @item @var{dir}
6155 Makes the current working directory be the top of the stack, and then
6156 executes the equivalent of `@code{cd} @var{dir}'.
6157 @code{cd}s to @var{dir}.
6158 @end table
6159
6160 @end table
6161
6162 @node Printing a Prompt
6163 @section Controlling the Prompt
6164 @cindex prompting
6165
6166 The value of the variable @env{PROMPT_COMMAND} is examined just before
6167 Bash prints each primary prompt.  If @env{PROMPT_COMMAND} is set and
6168 has a non-null value, then the
6169 value is executed just as if it had been typed on the command line.
6170
6171 In addition, the following table describes the special characters which
6172 can appear in the prompt variables:
6173
6174 @table @code
6175 @item \a
6176 A bell character.
6177 @item \d
6178 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
6179 @item \D@{@var{format}@}
6180 The @var{format} is passed to @code{strftime}(3) and the result is inserted
6181 into the prompt string; an empty @var{format} results in a locale-specific
6182 time representation.  The braces are required.
6183 @item \e
6184 An escape character.
6185 @item \h
6186 The hostname, up to the first `.'.
6187 @item \H
6188 The hostname.
6189 @item \j
6190 The number of jobs currently managed by the shell.
6191 @item \l
6192 The basename of the shell's terminal device name.
6193 @item \n
6194 A newline.
6195 @item \r
6196 A carriage return.
6197 @item \s
6198 The name of the shell, the basename of @code{$0} (the portion
6199 following the final slash).
6200 @item \t
6201 The time, in 24-hour HH:MM:SS format.
6202 @item \T
6203 The time, in 12-hour HH:MM:SS format.
6204 @item \@@
6205 The time, in 12-hour am/pm format.
6206 @item \A
6207 The time, in 24-hour HH:MM format.
6208 @item \u
6209 The username of the current user.
6210 @item \v
6211 The version of Bash (e.g., 2.00)          
6212 @item \V
6213 The release of Bash, version + patchlevel (e.g., 2.00.0)
6214 @item \w
6215 The current working directory, with @env{$HOME} abbreviated with a tilde
6216 (uses the @env{$PROMPT_DIRTRIM} variable).
6217 @item \W
6218 The basename of @env{$PWD}, with @env{$HOME} abbreviated with a tilde.
6219 @item \!
6220 The history number of this command.
6221 @item \#
6222 The command number of this command.
6223 @item \$
6224 If the effective uid is 0, @code{#}, otherwise @code{$}.
6225 @item \@var{nnn}
6226 The character whose ASCII code is the octal value @var{nnn}.
6227 @item \\
6228 A backslash.
6229 @item \[
6230 Begin a sequence of non-printing characters.  This could be used to
6231 embed a terminal control sequence into the prompt.
6232 @item \]
6233 End a sequence of non-printing characters.
6234 @end table
6235
6236 The command number and the history number are usually different:
6237 the history number of a command is its position in the history
6238 list, which may include commands restored from the history file
6239 (@pxref{Bash History Facilities}), while the command number is
6240 the position in the sequence of commands executed during the current
6241 shell session.
6242
6243 After the string is decoded, it is expanded via
6244 parameter expansion, command substitution, arithmetic
6245 expansion, and quote removal, subject to the value of the
6246 @code{promptvars} shell option (@pxref{Bash Builtins}).
6247
6248 @node The Restricted Shell
6249 @section The Restricted Shell
6250 @cindex restricted shell
6251
6252 If Bash is started with the name @code{rbash}, or the
6253 @option{--restricted}
6254 or
6255 @option{-r}
6256 option is supplied at invocation, the shell becomes restricted.
6257 A restricted shell is used to
6258 set up an environment more controlled than the standard shell.
6259 A restricted shell behaves identically to @code{bash}
6260 with the exception that the following are disallowed or not performed:
6261
6262 @itemize @bullet
6263 @item
6264 Changing directories with the @code{cd} builtin.
6265 @item
6266 Setting or unsetting the values of the @env{SHELL}, @env{PATH},
6267 @env{ENV}, or @env{BASH_ENV} variables.
6268 @item
6269 Specifying command names containing slashes.
6270 @item
6271 Specifying a filename containing a slash as an argument to the @code{.}
6272 builtin command.
6273 @item
6274 Specifying a filename containing a slash as an argument to the @option{-p}
6275 option to the @code{hash} builtin command.
6276 @item
6277 Importing function definitions from the shell environment at startup.
6278 @item
6279 Parsing the value of @env{SHELLOPTS} from the shell environment at startup.
6280 @item
6281 Redirecting output using the @samp{>}, @samp{>|}, @samp{<>}, @samp{>&},
6282 @samp{&>}, and @samp{>>} redirection operators.
6283 @item
6284 Using the @code{exec} builtin to replace the shell with another command.
6285 @item
6286 Adding or deleting builtin commands with the
6287 @option{-f} and @option{-d} options to the @code{enable} builtin.
6288 @item
6289 Using the @code{enable} builtin command to enable disabled shell builtins.
6290 @item
6291 Specifying the @option{-p} option to the @code{command} builtin.
6292 @item
6293 Turning off restricted mode with @samp{set +r} or @samp{set +o restricted}.
6294 @end itemize
6295
6296 These restrictions are enforced after any startup files are read.
6297
6298 When a command that is found to be a shell script is executed
6299 (@pxref{Shell Scripts}), @code{rbash} turns off any restrictions in
6300 the shell spawned to execute the script.
6301
6302 @node Bash POSIX Mode
6303 @section Bash POSIX Mode
6304 @cindex POSIX Mode
6305
6306 Starting Bash with the @option{--posix} command-line option or executing
6307 @samp{set -o posix} while Bash is running will cause Bash to conform more
6308 closely to the @sc{posix} standard by changing the behavior to
6309 match that specified by @sc{posix} in areas where the Bash default differs.
6310
6311 When invoked as @code{sh}, Bash enters @sc{posix} mode after reading the
6312 startup files.
6313
6314 The following list is what's changed when `@sc{posix} mode' is in effect:
6315
6316 @enumerate
6317 @item
6318 When a command in the hash table no longer exists, Bash will re-search
6319 @env{$PATH} to find the new location.  This is also available with
6320 @samp{shopt -s checkhash}.
6321
6322 @item
6323 The message printed by the job control code and builtins when a job
6324 exits with a non-zero status is `Done(status)'.
6325
6326 @item
6327 The message printed by the job control code and builtins when a job
6328 is stopped is `Stopped(@var{signame})', where @var{signame} is, for
6329 example, @code{SIGTSTP}.
6330
6331 @item
6332 The @code{bg} builtin uses the required format to describe each job placed
6333 in the background, which does not include an indication of whether the job
6334 is the current or previous job.
6335
6336 @item
6337 Reserved words appearing in a context where reserved words are recognized
6338 do not undergo alias expansion.
6339
6340 @item
6341 The @sc{posix} @env{PS1} and @env{PS2} expansions of @samp{!} to
6342 the history number and @samp{!!} to @samp{!} are enabled,
6343 and parameter expansion is performed on the values of @env{PS1} and
6344 @env{PS2} regardless of the setting of the @code{promptvars} option.
6345
6346 @item
6347 The @sc{posix} startup files are executed (@env{$ENV}) rather than
6348 the normal Bash files.
6349
6350 @item
6351 Tilde expansion is only performed on assignments preceding a command
6352 name, rather than on all assignment statements on the line.
6353
6354 @item
6355 The default history file is @file{~/.sh_history} (this is the
6356 default value of @env{$HISTFILE}).
6357
6358 @item
6359 The output of @samp{kill -l} prints all the signal names on a single line,
6360 separated by spaces, without the @samp{SIG} prefix.
6361
6362 @item
6363 The @code{kill} builtin does not accept signal names with a @samp{SIG}
6364 prefix.
6365
6366 @item
6367 Non-interactive shells exit if @var{filename} in @code{.} @var{filename}
6368 is not found.
6369
6370 @item
6371 Non-interactive shells exit if a syntax error in an arithmetic expansion
6372 results in an invalid expression.
6373
6374 @item
6375 Redirection operators do not perform filename expansion on the word
6376 in the redirection unless the shell is interactive.
6377
6378 @item
6379 Redirection operators do not perform word splitting on the word in the
6380 redirection.
6381
6382 @item
6383 Function names must be valid shell @code{name}s.  That is, they may not
6384 contain characters other than letters, digits, and underscores, and
6385 may not start with a digit.  Declaring a function with an invalid name
6386 causes a fatal syntax error in non-interactive shells.
6387
6388 @item
6389 @sc{posix} special builtins are found before shell functions
6390 during command lookup.
6391
6392 @item
6393 If a @sc{posix} special builtin returns an error status, a
6394 non-interactive shell exits.  The fatal errors are those listed in
6395 the POSIX standard, and include things like passing incorrect options,
6396 redirection errors, variable assignment errors for assignments preceding
6397 the command name, and so on.
6398
6399 @item
6400 If @env{CDPATH} is set, the @code{cd} builtin will not implicitly
6401 append the current directory to it.  This means that @code{cd} will
6402 fail if no valid directory name can be constructed from
6403 any of the entries in @env{$CDPATH}, even if the a directory with
6404 the same name as the name given as an argument to @code{cd} exists
6405 in the current directory.
6406
6407 @item
6408 A non-interactive shell exits with an error status if a variable
6409 assignment error occurs when no command name follows the assignment
6410 statements.
6411 A variable assignment error occurs, for example, when trying to assign
6412 a value to a readonly variable.
6413
6414 @item
6415 A non-interactive shell exits with an error status if the iteration
6416 variable in a @code{for} statement or the selection variable in a
6417 @code{select} statement is a readonly variable.
6418
6419 @item
6420 Process substitution is not available.
6421
6422 @item
6423 Assignment statements preceding @sc{posix} special builtins
6424 persist in the shell environment after the builtin completes.
6425
6426 @item
6427 Assignment statements preceding shell function calls persist in the
6428 shell environment after the function returns, as if a @sc{posix}
6429 special builtin command had been executed.
6430
6431 @item
6432 The @code{export} and @code{readonly} builtin commands display their
6433 output in the format required by @sc{posix}.
6434
6435 @item
6436 The @code{trap} builtin displays signal names without the leading
6437 @code{SIG}.
6438
6439 @item
6440 The @code{trap} builtin doesn't check the first argument for a possible
6441 signal specification and revert the signal handling to the original
6442 disposition if it is, unless that argument consists solely of digits and
6443 is a valid signal number.  If users want to reset the handler for a given
6444 signal to the original disposition, they should use @samp{-} as the
6445 first argument.
6446
6447 @item
6448 The @code{.} and @code{source} builtins do not search the current directory
6449 for the filename argument if it is not found by searching @env{PATH}.
6450
6451 @item
6452 Subshells spawned to execute command substitutions inherit the value of
6453 the @option{-e} option from the parent shell.  When not in @sc{posix} mode,
6454 Bash clears the @option{-e} option in such subshells.
6455
6456 @item
6457 Alias expansion is always enabled, even in non-interactive shells.
6458
6459 @item
6460 When the @code{alias} builtin displays alias definitions, it does not
6461 display them with a leading @samp{alias } unless the @option{-p} option
6462 is supplied.
6463
6464 @item
6465 When the @code{set} builtin is invoked without options, it does not display
6466 shell function names and definitions.
6467
6468 @item
6469 When the @code{set} builtin is invoked without options, it displays
6470 variable values without quotes, unless they contain shell metacharacters,
6471 even if the result contains nonprinting characters.
6472
6473 @item
6474 When the @code{cd} builtin is invoked in @var{logical} mode, and the pathname
6475 constructed from @code{$PWD} and the directory name supplied as an argument
6476 does not refer to an existing directory, @code{cd} will fail instead of
6477 falling back to @var{physical} mode.
6478
6479 @item
6480 When the @code{pwd} builtin is supplied the @option{-P} option, it resets
6481 @code{$PWD} to a pathname containing no symlinks.
6482
6483 @item
6484 The @code{pwd} builtin verifies that the value it prints is the same as the
6485 current directory, even if it is not asked to check the file system with the
6486 @option{-P} option.
6487
6488 @item
6489 When listing the history, the @code{fc} builtin does not include an
6490 indication of whether or not a history entry has been modified.
6491
6492 @item
6493 The default editor used by @code{fc} is @code{ed}.
6494
6495 @item
6496 The @code{type} and @code{command} builtins will not report a non-executable
6497 file as having been found, though the shell will attempt to execute such a
6498 file if it is the only so-named file found in @code{$PATH}.
6499
6500 @item
6501 The @code{vi} editing mode will invoke the @code{vi} editor directly when
6502 the @samp{v} command is run, instead of checking @code{$VISUAL} and
6503 @code{$EDITOR}.
6504
6505 @item
6506 When the @code{xpg_echo} option is enabled, Bash does not attempt to interpret
6507 any arguments to @code{echo} as options.  Each argument is displayed, after
6508 escape characters are converted.
6509
6510 @item
6511 The @code{ulimit} builtin uses a block size of 512 bytes for the @option{-c}
6512 and @option{-f} options.
6513
6514 @end enumerate
6515
6516 There is other @sc{posix} behavior that Bash does not implement by
6517 default even when in @sc{posix} mode.
6518 Specifically:
6519
6520 @enumerate
6521
6522 @item
6523 The @code{fc} builtin checks @code{$EDITOR} as a program to edit history
6524 entries if @code{FCEDIT} is unset, rather than defaulting directly to
6525 @code{ed}.  @code{fc} uses @code{ed} if @code{EDITOR} is unset.
6526
6527 @item
6528 As noted above, Bash requires the @code{xpg_echo} option to be enabled for
6529 the @code{echo} builtin to be fully conformant.
6530
6531 @end enumerate
6532
6533 Bash can be configured to be @sc{posix}-conformant by default, by specifying
6534 the @option{--enable-strict-posix-default} to @code{configure} when building
6535 (@pxref{Optional Features}).
6536
6537 @node Job Control
6538 @chapter Job Control
6539
6540 This chapter discusses what job control is, how it works, and how
6541 Bash allows you to access its facilities.
6542
6543 @menu
6544 * Job Control Basics::          How job control works.
6545 * Job Control Builtins::        Bash builtin commands used to interact
6546                                 with job control.
6547 * Job Control Variables::       Variables Bash uses to customize job
6548                                 control.
6549 @end menu
6550
6551 @node Job Control Basics
6552 @section Job Control Basics
6553 @cindex job control
6554 @cindex foreground
6555 @cindex background
6556 @cindex suspending jobs
6557
6558 Job control
6559 refers to the ability to selectively stop (suspend)
6560 the execution of processes and continue (resume)
6561 their execution at a later point.  A user typically employs
6562 this facility via an interactive interface supplied jointly
6563 by the system's terminal driver and Bash.
6564
6565 The shell associates a @var{job} with each pipeline.  It keeps a
6566 table of currently executing jobs, which may be listed with the
6567 @code{jobs} command.  When Bash starts a job
6568 asynchronously, it prints a line that looks
6569 like:
6570 @example
6571 [1] 25647
6572 @end example
6573 @noindent
6574 indicating that this job is job number 1 and that the process @sc{id}
6575 of the last process in the pipeline associated with this job is
6576 25647.  All of the processes in a single pipeline are members of
6577 the same job.  Bash uses the @var{job} abstraction as the
6578 basis for job control. 
6579
6580 To facilitate the implementation of the user interface to job
6581 control, the operating system maintains the notion of a current terminal
6582 process group @sc{id}.  Members of this process group (processes whose
6583 process group @sc{id} is equal to the current terminal process group
6584 @sc{id}) receive keyboard-generated signals such as @code{SIGINT}. 
6585 These processes are said to be in the foreground.  Background
6586 processes are those whose process group @sc{id} differs from the
6587 terminal's; such processes are immune to keyboard-generated
6588 signals.  Only foreground processes are allowed to read from or
6589 write to the terminal.  Background processes which attempt to
6590 read from (write to) the terminal are sent a @code{SIGTTIN}
6591 (@code{SIGTTOU}) signal by the terminal driver, which, unless
6592 caught, suspends the process. 
6593
6594 If the operating system on which Bash is running supports
6595 job control, Bash contains facilities to use it.  Typing the
6596 @var{suspend} character (typically @samp{^Z}, Control-Z) while a
6597 process is running causes that process to be stopped and returns
6598 control to Bash.  Typing the @var{delayed suspend} character
6599 (typically @samp{^Y}, Control-Y) causes the process to be stopped
6600 when it attempts to read input from the terminal, and control to
6601 be returned to Bash.  The user then manipulates the state of
6602 this job, using the @code{bg} command to continue it in the
6603 background, the @code{fg} command to continue it in the
6604 foreground, or the @code{kill} command to kill it.  A @samp{^Z}
6605 takes effect immediately, and has the additional side effect of
6606 causing pending output and typeahead to be discarded. 
6607
6608 There are a number of ways to refer to a job in the shell.  The
6609 character @samp{%} introduces a job specification (@var{jobspec}).
6610
6611 Job number @code{n} may be referred to as @samp{%n}.
6612 The symbols @samp{%%} and  @samp{%+} refer to the shell's notion of the
6613 current job, which is the last job stopped while it was in the foreground
6614 or started in the background.
6615 A single @samp{%} (with no accompanying job specification) also refers
6616 to the current job.
6617 The previous job may be referenced using @samp{%-}.
6618 If there is only a single job, @samp{%+} and @samp{%-} can both be used
6619 to refer to that job.
6620 In output pertaining to jobs (e.g., the output of the @code{jobs}
6621 command), the current job is always flagged with a @samp{+}, and the
6622 previous job with a @samp{-}. 
6623
6624 A job may also be referred to
6625 using a prefix of the name used to start it, or using a substring
6626 that appears in its command line.  For example, @samp{%ce} refers
6627 to a stopped @code{ce} job. Using @samp{%?ce}, on the
6628 other hand, refers to any job containing the string @samp{ce} in
6629 its command line.  If the prefix or substring matches more than one job,
6630 Bash reports an error.
6631
6632 Simply naming a job can be used to bring it into the foreground:
6633 @samp{%1} is a synonym for @samp{fg %1}, bringing job 1 from the
6634 background into the foreground.  Similarly, @samp{%1 &} resumes
6635 job 1 in the background, equivalent to @samp{bg %1}
6636
6637 The shell learns immediately whenever a job changes state. 
6638 Normally, Bash waits until it is about to print a prompt
6639 before reporting changes in a job's status so as to not interrupt
6640 any other output.
6641 If the @option{-b} option to the @code{set} builtin is enabled,
6642 Bash reports such changes immediately (@pxref{The Set Builtin}).
6643 Any trap on @code{SIGCHLD} is executed for each child process
6644 that exits.
6645
6646 If an attempt to exit Bash is made while jobs are stopped, (or running, if
6647 the @code{checkjobs} option is enabled -- see @ref{The Shopt Builtin}), the
6648 shell prints a warning message, and if the @code{checkjobs} option is
6649 enabled, lists the jobs and their statuses.
6650 The @code{jobs} command may then be used to inspect their status.
6651 If a second attempt to exit is made without an intervening command,
6652 Bash does not print another warning, and any stopped jobs are terminated.
6653
6654 @node Job Control Builtins
6655 @section Job Control Builtins
6656
6657 @table @code
6658
6659 @item bg
6660 @btindex bg
6661 @example
6662 bg [@var{jobspec} @dots{}]
6663 @end example
6664 Resume each suspended job @var{jobspec} in the background, as if it
6665 had been started with @samp{&}.
6666 If @var{jobspec} is not supplied, the current job is used.
6667 The return status is zero unless it is run when job control is not
6668 enabled, or, when run with job control enabled, any
6669 @var{jobspec} was not found or specifies a job
6670 that was started without job control.
6671
6672 @item fg
6673 @btindex fg
6674 @example
6675 fg [@var{jobspec}]
6676 @end example
6677 Resume the job @var{jobspec} in the foreground and make it the current job.
6678 If @var{jobspec} is not supplied, the current job is used.
6679 The return status is that of the command placed into the foreground,
6680 or non-zero if run when job control is disabled or, when run with
6681 job control enabled, @var{jobspec} does not specify a valid job or
6682 @var{jobspec} specifies a job that was started without job control.
6683
6684 @item jobs
6685 @btindex jobs
6686 @example
6687 jobs [-lnprs] [@var{jobspec}]
6688 jobs -x @var{command} [@var{arguments}]
6689 @end example
6690
6691 The first form lists the active jobs.  The options have the
6692 following meanings:
6693
6694 @table @code
6695 @item -l
6696 List process @sc{id}s in addition to the normal information.
6697
6698 @item -n
6699 Display information only about jobs that have changed status since
6700 the user was last notified of their status.
6701
6702 @item -p
6703 List only the process @sc{id} of the job's process group leader.
6704
6705 @item -r
6706 Restrict output to running jobs.
6707
6708 @item -s
6709 Restrict output to stopped jobs.
6710 @end table
6711
6712 If @var{jobspec} is given,
6713 output is restricted to information about that job. 
6714 If @var{jobspec} is not supplied, the status of all jobs is
6715 listed.
6716
6717 If the @option{-x} option is supplied, @code{jobs} replaces any
6718 @var{jobspec} found in @var{command} or @var{arguments} with the
6719 corresponding process group @sc{id}, and executes @var{command},
6720 passing it @var{argument}s, returning its exit status. 
6721
6722 @item kill
6723 @btindex kill
6724 @example
6725 kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec} or @var{pid}
6726 kill -l [@var{exit_status}]
6727 @end example
6728 Send a signal specified by @var{sigspec} or @var{signum} to the process
6729 named by job specification @var{jobspec} or process @sc{id} @var{pid}.
6730 @var{sigspec} is either a case-insensitive signal name such as
6731 @code{SIGINT} (with or without the @code{SIG} prefix)
6732 or a signal number; @var{signum} is a signal number.
6733 If @var{sigspec} and @var{signum} are not present, @code{SIGTERM} is used.
6734 The @option{-l} option lists the signal names.
6735 If any arguments are supplied when @option{-l} is given, the names of the
6736 signals corresponding to the arguments are listed, and the return status
6737 is zero.
6738 @var{exit_status} is a number specifying a signal number or the exit
6739 status of a process terminated by a signal.
6740 The return status is zero if at least one signal was successfully sent,
6741 or non-zero if an error occurs or an invalid option is encountered.
6742
6743 @item wait
6744 @btindex wait
6745 @example
6746 wait [@var{jobspec} or @var{pid} ...]
6747 @end example
6748 Wait until the child process specified by each process @sc{id} @var{pid}
6749 or job specification @var{jobspec} exits and return the exit status of the
6750 last command waited for.
6751 If a job spec is given, all processes in the job are waited for.
6752 If no arguments are given, all currently active child processes are
6753 waited for, and the return status is zero.
6754 If neither @var{jobspec} nor @var{pid} specifies an active child process
6755 of the shell, the return status is 127.
6756
6757 @item disown
6758 @btindex disown
6759 @example
6760 disown [-ar] [-h] [@var{jobspec} @dots{}]
6761 @end example
6762 Without options, each @var{jobspec} is removed from the table of
6763 active jobs.
6764 If the @option{-h} option is given, the job is not removed from the table,
6765 but is marked so that @code{SIGHUP} is not sent to the job if the shell
6766 receives a @code{SIGHUP}.
6767 If @var{jobspec} is not present, and neither the @option{-a} nor @option{-r}
6768 option is supplied, the current job is used.
6769 If no @var{jobspec} is supplied, the @option{-a} option means to remove or
6770 mark all jobs; the @option{-r} option without a @var{jobspec}
6771 argument restricts operation to running jobs.
6772
6773 @item suspend
6774 @btindex suspend
6775 @example
6776 suspend [-f]
6777 @end example
6778 Suspend the execution of this shell until it receives a
6779 @code{SIGCONT} signal.
6780 A login shell cannot be suspended; the @option{-f}
6781 option can be used to override this and force the suspension.
6782
6783 @end table
6784
6785 When job control is not active, the @code{kill} and @code{wait}
6786 builtins do not accept @var{jobspec} arguments.  They must be
6787 supplied process @sc{id}s.
6788
6789 @node Job Control Variables
6790 @section Job Control Variables
6791
6792 @vtable @code
6793
6794 @item auto_resume
6795 This variable controls how the shell interacts with the user and
6796 job control.  If this variable exists then single word simple
6797 commands without redirections are treated as candidates for resumption
6798 of an existing job.  There is no ambiguity allowed; if there is
6799 more than one job beginning with the string typed, then
6800 the most recently accessed job will be selected.
6801 The name of a stopped job, in this context, is the command line
6802 used to start it.  If this variable is set to the value @samp{exact},
6803 the string supplied must match the name of a stopped job exactly;
6804 if set to @samp{substring},
6805 the string supplied needs to match a substring of the name of a
6806 stopped job.  The @samp{substring} value provides functionality
6807 analogous to the @samp{%?} job @sc{id} (@pxref{Job Control Basics}).
6808 If set to any other value, the supplied string must
6809 be a prefix of a stopped job's name; this provides functionality
6810 analogous to the @samp{%} job @sc{id}.
6811
6812 @end vtable
6813
6814 @set readline-appendix
6815 @set history-appendix
6816 @cindex Readline, how to use
6817 @include rluser.texi
6818 @cindex History, how to use
6819 @include hsuser.texi
6820 @clear readline-appendix
6821 @clear history-appendix
6822
6823 @node Installing Bash
6824 @chapter Installing Bash
6825
6826 This chapter provides basic instructions for installing Bash on
6827 the various supported platforms.  The distribution supports the
6828 @sc{gnu} operating systems, nearly every version of Unix, and several
6829 non-Unix systems such as BeOS and Interix.
6830 Other independent ports exist for
6831 @sc{ms-dos}, @sc{os/2}, and Windows platforms.
6832
6833 @menu
6834 * Basic Installation::  Installation instructions.
6835 * Compilers and Options::       How to set special options for various
6836                                 systems.
6837 * Compiling For Multiple Architectures::        How to compile Bash for more
6838                                                 than one kind of system from
6839                                                 the same source tree.
6840 * Installation Names::  How to set the various paths used by the installation.
6841 * Specifying the System Type::  How to configure Bash for a particular system.
6842 * Sharing Defaults::    How to share default configuration values among GNU
6843                         programs.
6844 * Operation Controls::  Options recognized by the configuration program.
6845 * Optional Features::   How to enable and disable optional features when
6846                         building Bash.
6847 @end menu
6848
6849 @node Basic Installation
6850 @section Basic Installation
6851 @cindex installation
6852 @cindex configuration
6853 @cindex Bash installation
6854 @cindex Bash configuration
6855
6856 These are installation instructions for Bash.
6857
6858 The simplest way to compile Bash is:
6859
6860 @enumerate
6861 @item
6862 @code{cd} to the directory containing the source code and type
6863 @samp{./configure} to configure Bash for your system.  If you're
6864 using @code{csh} on an old version of System V, you might need to
6865 type @samp{sh ./configure} instead to prevent @code{csh} from trying
6866 to execute @code{configure} itself.
6867
6868 Running @code{configure} takes some time.
6869 While running, it prints messages telling which features it is
6870 checking for.
6871
6872 @item
6873 Type @samp{make} to compile Bash and build the @code{bashbug} bug
6874 reporting script.
6875
6876 @item
6877 Optionally, type @samp{make tests} to run the Bash test suite.
6878
6879 @item
6880 Type @samp{make install} to install @code{bash} and @code{bashbug}.
6881 This will also install the manual pages and Info file.
6882
6883 @end enumerate
6884
6885 The @code{configure} shell script attempts to guess correct
6886 values for various system-dependent variables used during
6887 compilation.  It uses those values to create a @file{Makefile} in
6888 each directory of the package (the top directory, the
6889 @file{builtins}, @file{doc}, and @file{support} directories,
6890 each directory under @file{lib}, and several others).  It also creates a
6891 @file{config.h} file containing system-dependent definitions. 
6892 Finally, it creates a shell script named @code{config.status} that you
6893 can run in the future to recreate the current configuration, a
6894 file @file{config.cache} that saves the results of its tests to
6895 speed up reconfiguring, and a file @file{config.log} containing
6896 compiler output (useful mainly for debugging @code{configure}). 
6897 If at some point
6898 @file{config.cache} contains results you don't want to keep, you
6899 may remove or edit it. 
6900
6901 To find out more about the options and arguments that the
6902 @code{configure} script understands, type 
6903
6904 @example
6905 bash-2.04$ ./configure --help
6906 @end example
6907
6908 @noindent
6909 at the Bash prompt in your Bash source directory.
6910
6911 If you need to do unusual things to compile Bash, please
6912 try to figure out how @code{configure} could check whether or not
6913 to do them, and mail diffs or instructions to
6914 @email{bash-maintainers@@gnu.org} so they can be
6915 considered for the next release.
6916
6917 The file @file{configure.in} is used to create @code{configure}
6918 by a program called Autoconf.  You only need
6919 @file{configure.in} if you want to change it or regenerate
6920 @code{configure} using a newer version of Autoconf.  If
6921 you do this, make sure you are using Autoconf version 2.50 or
6922 newer.
6923
6924 You can remove the program binaries and object files from the
6925 source code directory by typing @samp{make clean}.  To also remove the
6926 files that @code{configure} created (so you can compile Bash for
6927 a different kind of computer), type @samp{make distclean}.
6928
6929 @node Compilers and Options
6930 @section Compilers and Options
6931
6932 Some systems require unusual options for compilation or linking
6933 that the @code{configure} script does not know about.  You can
6934 give @code{configure} initial values for variables by setting
6935 them in the environment.  Using a Bourne-compatible shell, you
6936 can do that on the command line like this:
6937
6938 @example
6939 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
6940 @end example
6941
6942 On systems that have the @code{env} program, you can do it like this:
6943
6944 @example
6945 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
6946 @end example
6947
6948 The configuration process uses GCC to build Bash if it
6949 is available.
6950
6951 @node Compiling For Multiple Architectures
6952 @section Compiling For Multiple Architectures
6953
6954 You can compile Bash for more than one kind of computer at the
6955 same time, by placing the object files for each architecture in their
6956 own directory.  To do this, you must use a version of @code{make} that
6957 supports the @code{VPATH} variable, such as GNU @code{make}.
6958 @code{cd} to the
6959 directory where you want the object files and executables to go and run
6960 the @code{configure} script from the source directory.  You may need to
6961 supply the @option{--srcdir=PATH} argument to tell @code{configure} where the
6962 source files are.  @code{configure} automatically checks for the
6963 source code in the directory that @code{configure} is in and in `..'.
6964
6965 If you have to use a @code{make} that does not supports the @code{VPATH}
6966 variable, you can compile Bash for one architecture at a
6967 time in the source code directory.  After you have installed
6968 Bash for one architecture, use @samp{make distclean} before
6969 reconfiguring for another architecture.
6970
6971 Alternatively, if your system supports symbolic links, you can use the
6972 @file{support/mkclone} script to create a build tree which has
6973 symbolic links back to each file in the source directory.  Here's an
6974 example that creates a build directory in the current directory from a
6975 source directory @file{/usr/gnu/src/bash-2.0}:
6976
6977 @example
6978 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
6979 @end example
6980
6981 @noindent
6982 The @code{mkclone} script requires Bash, so you must have already built
6983 Bash for at least one architecture before you can create build
6984 directories for other architectures.
6985
6986 @node Installation Names
6987 @section Installation Names
6988
6989 By default, @samp{make install} will install into
6990 @file{/usr/local/bin}, @file{/usr/local/man}, etc.  You can
6991 specify an installation prefix other than @file{/usr/local} by
6992 giving @code{configure} the option @option{--prefix=@var{PATH}},
6993 or by specifying a value for the @code{DESTDIR} @samp{make}
6994 variable when running @samp{make install}.
6995
6996 You can specify separate installation prefixes for
6997 architecture-specific files and architecture-independent files. 
6998 If you give @code{configure} the option
6999 @option{--exec-prefix=@var{PATH}}, @samp{make install} will use
7000 @var{PATH} as the prefix for installing programs and libraries.
7001 Documentation and other data files will still use the regular prefix. 
7002
7003 @node Specifying the System Type
7004 @section Specifying the System Type
7005
7006 There may be some features @code{configure} can not figure out
7007 automatically, but need to determine by the type of host Bash
7008 will run on.  Usually @code{configure} can figure that
7009 out, but if it prints a message saying it can not guess the host
7010 type, give it the @option{--host=TYPE} option.  @samp{TYPE} can
7011 either be a short name for the system type, such as @samp{sun4},
7012 or a canonical name with three fields: @samp{CPU-COMPANY-SYSTEM}
7013 (e.g., @samp{i386-unknown-freebsd4.2}).
7014
7015 See the file @file{support/config.sub} for the possible
7016 values of each field. 
7017
7018 @node Sharing Defaults
7019 @section Sharing Defaults
7020
7021 If you want to set default values for @code{configure} scripts to
7022 share, you can create a site shell script called
7023 @code{config.site} that gives default values for variables like
7024 @code{CC}, @code{cache_file}, and @code{prefix}.  @code{configure}
7025 looks for @file{PREFIX/share/config.site} if it exists, then
7026 @file{PREFIX/etc/config.site} if it exists.  Or, you can set the
7027 @code{CONFIG_SITE} environment variable to the location of the site
7028 script.  A warning: the Bash @code{configure} looks for a site script,
7029 but not all @code{configure} scripts do.
7030
7031 @node Operation Controls
7032 @section Operation Controls
7033
7034 @code{configure} recognizes the following options to control how it
7035 operates.
7036
7037 @table @code
7038
7039 @item --cache-file=@var{file}
7040 Use and save the results of the tests in
7041 @var{file} instead of @file{./config.cache}.  Set @var{file} to
7042 @file{/dev/null} to disable caching, for debugging
7043 @code{configure}. 
7044
7045 @item --help
7046 Print a summary of the options to @code{configure}, and exit.
7047
7048 @item --quiet
7049 @itemx --silent
7050 @itemx -q
7051 Do not print messages saying which checks are being made.
7052
7053 @item --srcdir=@var{dir}
7054 Look for the Bash source code in directory @var{dir}.  Usually
7055 @code{configure} can determine that directory automatically.
7056
7057 @item --version
7058 Print the version of Autoconf used to generate the @code{configure}
7059 script, and exit.
7060 @end table
7061
7062 @code{configure} also accepts some other, not widely used, boilerplate
7063 options.  @samp{configure --help} prints the complete list.
7064
7065 @node Optional Features
7066 @section Optional Features
7067
7068 The Bash @code{configure} has a number of @option{--enable-@var{feature}}
7069 options, where @var{feature} indicates an optional part of Bash.
7070 There are also several @option{--with-@var{package}} options,
7071 where @var{package} is something like @samp{bash-malloc} or @samp{purify}.
7072 To turn off the default use of a package, use
7073 @option{--without-@var{package}}.  To configure Bash without a feature
7074 that is enabled by default, use @option{--disable-@var{feature}}.
7075
7076 Here is a complete list of the @option{--enable-} and
7077 @option{--with-} options that the Bash @code{configure} recognizes. 
7078
7079 @table @code
7080 @item --with-afs
7081 Define if you are using the Andrew File System from Transarc.
7082
7083 @item --with-bash-malloc
7084 Use the Bash version of
7085 @code{malloc} in the directory @file{lib/malloc}.  This is not the same
7086 @code{malloc} that appears in @sc{gnu} libc, but an older version
7087 originally derived from the 4.2 @sc{bsd} @code{malloc}.  This @code{malloc}
7088 is very fast, but wastes some space on each allocation.
7089 This option is enabled by default.
7090 The @file{NOTES} file contains a list of systems for
7091 which this should be turned off, and @code{configure} disables this
7092 option automatically for a number of systems.
7093
7094 @item --with-curses
7095 Use the curses library instead of the termcap library.  This should
7096 be supplied if your system has an inadequate or incomplete termcap
7097 database.
7098
7099 @item --with-gnu-malloc
7100 A synonym for @code{--with-bash-malloc}.
7101
7102 @item --with-installed-readline[=@var{PREFIX}]
7103 Define this to make Bash link with a locally-installed version of Readline
7104 rather than the version in @file{lib/readline}.  This works only with
7105 Readline 5.0 and later versions.  If @var{PREFIX} is @code{yes} or not
7106 supplied, @code{configure} uses the values of the make variables
7107 @code{includedir} and @code{libdir}, which are subdirectories of @code{prefix}
7108 by default, to find the installed version of Readline if it is not in
7109 the standard system include and library directories.
7110 If @var{PREFIX} is @code{no}, Bash links with the version in
7111 @file{lib/readline}.
7112 If @var{PREFIX} is set to any other value, @code{configure} treats it as
7113 a directory pathname and looks for
7114 the installed version of Readline in subdirectories of that directory
7115 (include files in @var{PREFIX}/@code{include} and the library in
7116 @var{PREFIX}/@code{lib}).
7117
7118 @item --with-purify
7119 Define this to use the Purify memory allocation checker from Rational
7120 Software.
7121
7122 @item --enable-minimal-config
7123 This produces a shell with minimal features, close to the historical
7124 Bourne shell.
7125 @end table
7126
7127 There are several @option{--enable-} options that alter how Bash is
7128 compiled and linked, rather than changing run-time features.
7129
7130 @table @code
7131 @item --enable-largefile
7132 Enable support for @uref{http://www.sas.com/standards/large_file/x_open.20Mar96.html,
7133 large files} if the operating system requires special compiler options
7134 to build programs which can access large files.  This is enabled by
7135 default, if the operating system provides large file support.
7136
7137 @item --enable-profiling
7138 This builds a Bash binary that produces profiling information to be
7139 processed by @code{gprof} each time it is executed.
7140
7141 @item --enable-static-link
7142 This causes Bash to be linked statically, if @code{gcc} is being used.
7143 This could be used to build a version to use as root's shell.
7144 @end table
7145
7146 The @samp{minimal-config} option can be used to disable all of
7147 the following options, but it is processed first, so individual
7148 options may be enabled using @samp{enable-@var{feature}}. 
7149
7150 All of the following options except for @samp{disabled-builtins} and
7151 @samp{xpg-echo-default} are
7152 enabled by default, unless the operating system does not provide the
7153 necessary support.
7154
7155 @table @code
7156 @item --enable-alias
7157 Allow alias expansion and include the @code{alias} and @code{unalias}
7158 builtins (@pxref{Aliases}).
7159
7160 @item --enable-arith-for-command
7161 Include support for the alternate form of the @code{for} command
7162 that behaves like the C language @code{for} statement
7163 (@pxref{Looping Constructs}).
7164
7165 @item --enable-array-variables
7166 Include support for one-dimensional array shell variables
7167 (@pxref{Arrays}).
7168
7169 @item --enable-bang-history
7170 Include support for @code{csh}-like history substitution
7171 (@pxref{History Interaction}).
7172
7173 @item --enable-brace-expansion
7174 Include @code{csh}-like brace expansion
7175 ( @code{b@{a,b@}c} @expansion{} @code{bac bbc} ).
7176 See @ref{Brace Expansion}, for a complete description.
7177
7178 @item --enable-casemod-attributes
7179 Include support for case-modifying attributes in the @code{declare} builtin
7180 and assignment statements.  Variables with the @var{uppercase} attribute,
7181 for example, will have their values converted to uppercase upon assignment.
7182
7183 @item --enable-casemod-expansion
7184 Include support for case-modifying word expansions.
7185
7186 @item --enable-command-timing
7187 Include support for recognizing @code{time} as a reserved word and for
7188 displaying timing statistics for the pipeline following @code{time}
7189 (@pxref{Pipelines}).
7190 This allows pipelines as well as shell builtins and functions to be timed.
7191
7192 @item --enable-cond-command
7193 Include support for the @code{[[} conditional command.
7194 (@pxref{Conditional Constructs}).
7195
7196 @item --enable-cond-regexp
7197 Include support for matching POSIX regular expressions using the
7198 @samp{=~} binary operator in the @code{[[} conditional command.
7199 (@pxref{Conditional Constructs}).
7200
7201 @item --enable-coprocesses
7202 Include support for coprocesses and the @code{coproc} reserved word
7203 (@pxref{Pipelines}).
7204
7205 @item --enable-debugger
7206 Include support for the bash debugger (distributed separately).
7207
7208 @item --enable-directory-stack
7209 Include support for a @code{csh}-like directory stack and the
7210 @code{pushd}, @code{popd}, and @code{dirs} builtins
7211 (@pxref{The Directory Stack}).
7212
7213 @item --enable-disabled-builtins
7214 Allow builtin commands to be invoked via @samp{builtin xxx}
7215 even after @code{xxx} has been disabled using @samp{enable -n xxx}.
7216 See @ref{Bash Builtins}, for details of the @code{builtin} and
7217 @code{enable} builtin commands.
7218
7219 @item --enable-dparen-arithmetic
7220 Include support for the @code{((@dots{}))} command
7221 (@pxref{Conditional Constructs}).
7222
7223 @item --enable-extended-glob
7224 Include support for the extended pattern matching features described
7225 above under @ref{Pattern Matching}.
7226
7227 @item --enable-help-builtin
7228 Include the @code{help} builtin, which displays help on shell builtins and
7229 variables (@pxref{Bash Builtins}).
7230
7231 @item --enable-history
7232 Include command history and the @code{fc} and @code{history}
7233 builtin commands (@pxref{Bash History Facilities}).
7234
7235 @item --enable-job-control
7236 This enables the job control features (@pxref{Job Control}),
7237 if the operating system supports them.
7238
7239 @item --enable-multibyte
7240 This enables support for multibyte characters if the operating
7241 system provides the necessary support.
7242
7243 @item --enable-net-redirections
7244 This enables the special handling of filenames of the form
7245 @code{/dev/tcp/@var{host}/@var{port}} and
7246 @code{/dev/udp/@var{host}/@var{port}}
7247 when used in redirections (@pxref{Redirections}).
7248
7249 @item --enable-process-substitution
7250 This enables process substitution (@pxref{Process Substitution}) if
7251 the operating system provides the necessary support.
7252
7253 @item --enable-progcomp
7254 Enable the programmable completion facilities
7255 (@pxref{Programmable Completion}).
7256 If Readline is not enabled, this option has no effect.
7257
7258 @item --enable-prompt-string-decoding
7259 Turn on the interpretation of a number of backslash-escaped characters
7260 in the @env{$PS1}, @env{$PS2}, @env{$PS3}, and @env{$PS4} prompt
7261 strings.  See @ref{Printing a Prompt}, for a complete list of prompt
7262 string escape sequences.
7263
7264 @item --enable-readline
7265 Include support for command-line editing and history with the Bash
7266 version of the Readline library (@pxref{Command Line Editing}).
7267
7268 @item --enable-restricted
7269 Include support for a @dfn{restricted shell}.  If this is enabled, Bash,
7270 when called as @code{rbash}, enters a restricted mode.  See
7271 @ref{The Restricted Shell}, for a description of restricted mode.
7272
7273 @item --enable-select
7274 Include the @code{select} builtin, which allows the generation of simple
7275 menus (@pxref{Conditional Constructs}).
7276
7277 @item --enable-separate-helpfiles
7278 Use external files for the documentation displayed by the @code{help} builtin
7279 instead of storing the text internally.
7280
7281 @item --enable-single-help-strings
7282 Store the text displayed by the @code{help} builtin as a single string for
7283 each help topic.  This aids in translating the text to different languages.
7284 You may need to disable this if your compiler cannot handle very long string
7285 literals.
7286
7287 @item --enable-strict-posix-default
7288 Make Bash @sc{posix}-conformant by default (@pxref{Bash POSIX Mode}).
7289
7290 @item --enable-usg-echo-default
7291 A synonym for @code{--enable-xpg-echo-default}.
7292
7293 @item --enable-xpg-echo-default
7294 Make the @code{echo} builtin expand backslash-escaped characters by default,
7295 without requiring the @option{-e} option.
7296 This sets the default value of the @code{xpg_echo} shell option to @code{on},
7297 which makes the Bash @code{echo} behave more like the version specified in
7298 the Single Unix Specification, version 3.
7299 @xref{Bash Builtins}, for a description of the escape sequences that
7300 @code{echo} recognizes.
7301
7302 @end table
7303
7304 The file @file{config-top.h} contains C Preprocessor
7305 @samp{#define} statements for options which are not settable from
7306 @code{configure}.
7307 Some of these are not meant to be changed; beware of the consequences if
7308 you do.
7309 Read the comments associated with each definition for more
7310 information about its effect.
7311
7312 @node Reporting Bugs
7313 @appendix Reporting Bugs
7314
7315 Please report all bugs you find in Bash.
7316 But first, you should
7317 make sure that it really is a bug, and that it appears in the latest
7318 version of Bash.
7319 The latest version of Bash is always available for FTP from
7320 @uref{ftp://ftp.gnu.org/pub/bash/}.
7321
7322 Once you have determined that a bug actually exists, use the
7323 @code{bashbug} command to submit a bug report.
7324 If you have a fix, you are encouraged to mail that as well!
7325 Suggestions and `philosophical' bug reports may be mailed
7326 to @email{bug-bash@@gnu.org} or posted to the Usenet
7327 newsgroup @code{gnu.bash.bug}.
7328
7329 All bug reports should include:
7330 @itemize @bullet
7331 @item
7332 The version number of Bash.
7333 @item
7334 The hardware and operating system.
7335 @item
7336 The compiler used to compile Bash.
7337 @item
7338 A description of the bug behaviour.
7339 @item
7340 A short script or `recipe' which exercises the bug and may be used
7341 to reproduce it.
7342 @end itemize
7343
7344 @noindent
7345 @code{bashbug} inserts the first three items automatically into
7346 the template it provides for filing a bug report.
7347
7348 Please send all reports concerning this manual to
7349 @email{chet.ramey@@case.edu}.
7350
7351 @node Major Differences From The Bourne Shell
7352 @appendix Major Differences From The Bourne Shell
7353
7354 Bash implements essentially the same grammar, parameter and
7355 variable expansion, redirection, and quoting as the Bourne Shell. 
7356 Bash uses the @sc{posix} standard as the specification of
7357 how these features are to be implemented.  There are some
7358 differences between the traditional Bourne shell and Bash; this
7359 section quickly details the differences of significance.  A
7360 number of these differences are explained in greater depth in
7361 previous sections.
7362 This section uses the version of @code{sh} included in SVR4.2 (the
7363 last version of the historical Bourne shell) as the baseline reference.
7364
7365 @itemize @bullet
7366
7367 @item
7368 Bash is @sc{posix}-conformant, even where the @sc{posix} specification
7369 differs from traditional @code{sh} behavior (@pxref{Bash POSIX Mode}).
7370
7371 @item
7372 Bash has multi-character invocation options (@pxref{Invoking Bash}).
7373
7374 @item
7375 Bash has command-line editing (@pxref{Command Line Editing}) and
7376 the @code{bind} builtin.
7377
7378 @item
7379 Bash provides a programmable word completion mechanism
7380 (@pxref{Programmable Completion}), and builtin commands
7381 @code{complete}, @code{compgen}, and @code{compopt}, to
7382 manipulate it.
7383
7384 @item
7385 Bash has command history (@pxref{Bash History Facilities}) and the
7386 @code{history} and @code{fc} builtins to manipulate it.
7387 The Bash history list maintains timestamp information and uses the
7388 value of the @code{HISTTIMEFORMAT} variable to display it.
7389
7390 @item
7391 Bash implements @code{csh}-like history expansion
7392 (@pxref{History Interaction}).
7393
7394 @item
7395 Bash has one-dimensional array variables (@pxref{Arrays}), and the
7396 appropriate variable expansions and assignment syntax to use them.
7397 Several of the Bash builtins take options to act on arrays.
7398 Bash provides a number of built-in array variables.
7399
7400 @item
7401 The @code{$'@dots{}'} quoting syntax, which expands ANSI-C
7402 backslash-escaped characters in the text between the single quotes,
7403 is supported (@pxref{ANSI-C Quoting}).
7404
7405 @item
7406 Bash supports the @code{$"@dots{}"} quoting syntax to do
7407 locale-specific translation of the characters between the double
7408 quotes.  The @option{-D}, @option{--dump-strings}, and @option{--dump-po-strings}
7409 invocation options list the translatable strings found in a script
7410 (@pxref{Locale Translation}).
7411
7412 @item
7413 Bash implements the @code{!} keyword to negate the return value of
7414 a pipeline (@pxref{Pipelines}).
7415 Very useful when an @code{if} statement needs to act only if a test fails.
7416 The Bash @samp{-o pipefail} option to @code{set} will cause a pipeline to
7417 return a failure status if any command fails.
7418
7419 @item
7420 Bash has the @code{time} reserved word and command timing (@pxref{Pipelines}).
7421 The display of the timing statistics may be controlled with the
7422 @env{TIMEFORMAT} variable.
7423
7424 @item
7425 Bash implements the @code{for (( @var{expr1} ; @var{expr2} ; @var{expr3} ))}
7426 arithmetic for command, similar to the C language (@pxref{Looping Constructs}).
7427
7428 @item
7429 Bash includes the @code{select} compound command, which allows the
7430 generation of simple menus (@pxref{Conditional Constructs}).
7431
7432 @item
7433 Bash includes the @code{[[} compound command, which makes conditional
7434 testing part of the shell grammar (@pxref{Conditional Constructs}), including
7435 optional regular expression matching.
7436
7437 @item
7438 Bash provides optional case-insensitive matching for the @code{case} and
7439 @code{[[} constructs.
7440
7441 @item
7442 Bash includes brace expansion (@pxref{Brace Expansion}) and tilde
7443 expansion (@pxref{Tilde Expansion}).
7444
7445 @item
7446 Bash implements command aliases and the @code{alias} and @code{unalias}
7447 builtins (@pxref{Aliases}).
7448
7449 @item
7450 Bash provides shell arithmetic, the @code{((} compound command
7451 (@pxref{Conditional Constructs}),
7452 and arithmetic expansion (@pxref{Shell Arithmetic}).
7453
7454 @item
7455 Variables present in the shell's initial environment are automatically
7456 exported to child processes.  The Bourne shell does not normally do
7457 this unless the variables are explicitly marked using the @code{export}
7458 command.
7459
7460 @item
7461 Bash supports the @samp{+=} assignment operator, which appends to the value
7462 of the variable named on the left hand side.
7463
7464 @item
7465 Bash includes the @sc{posix} pattern removal @samp{%}, @samp{#}, @samp{%%}
7466 and @samp{##} expansions to remove leading or trailing substrings from
7467 variable values (@pxref{Shell Parameter Expansion}).
7468
7469 @item
7470 The expansion @code{$@{#xx@}}, which returns the length of @code{$@{xx@}},
7471 is supported (@pxref{Shell Parameter Expansion}).
7472
7473 @item
7474 The expansion @code{$@{var:}@var{offset}@code{[:}@var{length}@code{]@}},
7475 which expands to the substring of @code{var}'s value of length
7476 @var{length}, beginning at @var{offset}, is present
7477 (@pxref{Shell Parameter Expansion}).
7478
7479 @item
7480 The expansion
7481 @code{$@{var/[/]}@var{pattern}@code{[/}@var{replacement}@code{]@}},
7482 which matches @var{pattern} and replaces it with @var{replacement} in
7483 the value of @code{var}, is available (@pxref{Shell Parameter Expansion}).
7484
7485 @item
7486 The expansion @code{$@{!@var{prefix@}*}} expansion, which expands to
7487 the names of all shell variables whose names begin with @var{prefix},
7488 is available (@pxref{Shell Parameter Expansion}).
7489
7490 @item
7491 Bash has @var{indirect} variable expansion using @code{$@{!word@}}
7492 (@pxref{Shell Parameter Expansion}).
7493
7494 @item
7495 Bash can expand positional parameters beyond @code{$9} using
7496 @code{$@{@var{num}@}}.
7497
7498 @item
7499 The @sc{posix} @code{$()} form of command substitution
7500 is implemented (@pxref{Command Substitution}),
7501 and preferred to the Bourne shell's @code{``} (which
7502 is also implemented for backwards compatibility).
7503
7504 @item
7505 Bash has process substitution (@pxref{Process Substitution}).
7506
7507 @item
7508 Bash automatically assigns variables that provide information about the
7509 current user (@env{UID}, @env{EUID}, and @env{GROUPS}), the current host
7510 (@env{HOSTTYPE}, @env{OSTYPE}, @env{MACHTYPE}, and @env{HOSTNAME}),
7511 and the instance of Bash that is running (@env{BASH},
7512 @env{BASH_VERSION}, and @env{BASH_VERSINFO}).  @xref{Bash Variables},
7513 for details.
7514
7515 @item
7516 The @env{IFS} variable is used to split only the results of expansion,
7517 not all words (@pxref{Word Splitting}).
7518 This closes a longstanding shell security hole.
7519
7520 @item
7521 Bash implements the full set of @sc{posix} filename expansion operators,
7522 including @var{character classes}, @var{equivalence classes}, and
7523 @var{collating symbols} (@pxref{Filename Expansion}).
7524
7525 @item
7526 Bash implements extended pattern matching features when the @code{extglob}
7527 shell option is enabled (@pxref{Pattern Matching}).
7528
7529 @item
7530 It is possible to have a variable and a function with the same name;
7531 @code{sh} does not separate the two name spaces.
7532
7533 @item
7534 Bash functions are permitted to have local variables using the
7535 @code{local} builtin, and thus useful recursive functions may be written
7536 (@pxref{Bash Builtins}).
7537
7538 @item
7539 Variable assignments preceding commands affect only that command, even
7540 builtins and functions (@pxref{Environment}).
7541 In @code{sh}, all variable assignments 
7542 preceding commands are global unless the command is executed from the
7543 file system.
7544
7545 @item
7546 Bash performs filename expansion on filenames specified as operands
7547 to input and output redirection operators (@pxref{Redirections}).
7548
7549 @item
7550 Bash contains the @samp{<>} redirection operator, allowing a file to be
7551 opened for both reading and writing, and the @samp{&>} redirection
7552 operator, for directing standard output and standard error to the same
7553 file (@pxref{Redirections}).
7554
7555 @item
7556 Bash includes the @samp{<<<} redirection operator, allowing a string to
7557 be used as the standard input to a command.
7558
7559 @item
7560 Bash implements the @samp{[n]<&@var{word}} and @samp{[n]>&@var{word}}
7561 redirection operators, which move one file descriptor to another.
7562
7563 @item
7564 Bash treats a number of filenames specially when they are
7565 used in redirection operators (@pxref{Redirections}).
7566
7567 @item
7568 Bash can open network connections to arbitrary machines and services
7569 with the redirection operators (@pxref{Redirections}).
7570
7571 @item
7572 The @code{noclobber} option is available to avoid overwriting existing
7573 files with output redirection (@pxref{The Set Builtin}).
7574 The @samp{>|} redirection operator may be used to override @code{noclobber}.
7575
7576 @item
7577 The Bash @code{cd} and @code{pwd} builtins (@pxref{Bourne Shell Builtins})
7578 each take @option{-L} and @option{-P} options to switch between logical and
7579 physical modes.
7580
7581 @item
7582 Bash allows a function to override a builtin with the same name, and provides
7583 access to that builtin's functionality within the function via the
7584 @code{builtin} and @code{command} builtins (@pxref{Bash Builtins}).
7585
7586 @item
7587 The @code{command} builtin allows selective disabling of functions
7588 when command lookup is performed (@pxref{Bash Builtins}).
7589
7590 @item
7591 Individual builtins may be enabled or disabled using the @code{enable}
7592 builtin (@pxref{Bash Builtins}).
7593
7594 @item
7595 The Bash @code{exec} builtin takes additional options that allow users
7596 to control the contents of the environment passed to the executed
7597 command, and what the zeroth argument to the command is to be
7598 (@pxref{Bourne Shell Builtins}).
7599
7600 @item
7601 Shell functions may be exported to children via the environment
7602 using @code{export -f} (@pxref{Shell Functions}).
7603
7604 @item
7605 The Bash @code{export}, @code{readonly}, and @code{declare} builtins can
7606 take a @option{-f} option to act on shell functions, a @option{-p} option to
7607 display variables with various attributes set in a format that can be
7608 used as shell input, a @option{-n} option to remove various variable
7609 attributes, and @samp{name=value} arguments to set variable attributes
7610 and values simultaneously.
7611
7612 @item
7613 The Bash @code{hash} builtin allows a name to be associated with
7614 an arbitrary filename, even when that filename cannot be found by
7615 searching the @env{$PATH}, using @samp{hash -p}
7616 (@pxref{Bourne Shell Builtins}).
7617
7618 @item
7619 Bash includes a @code{help} builtin for quick reference to shell
7620 facilities (@pxref{Bash Builtins}).
7621
7622 @item
7623 The @code{printf} builtin is available to display formatted output
7624 (@pxref{Bash Builtins}).
7625
7626 @item
7627 The Bash @code{read} builtin (@pxref{Bash Builtins})
7628 will read a line ending in @samp{\} with
7629 the @option{-r} option, and will use the @env{REPLY} variable as a
7630 default if no non-option arguments are supplied.
7631 The Bash @code{read} builtin
7632 also accepts a prompt string with the @option{-p} option and will use
7633 Readline to obtain the line when given the @option{-e} option.
7634 The @code{read} builtin also has additional options to control input:
7635 the @option{-s} option will turn off echoing of input characters as
7636 they are read, the @option{-t} option will allow @code{read} to time out
7637 if input does not arrive within a specified number of seconds, the
7638 @option{-n} option will allow reading only a specified number of
7639 characters rather than a full line, and the @option{-d} option will read
7640 until a particular character rather than newline.
7641
7642 @item
7643 The @code{return} builtin may be used to abort execution of scripts
7644 executed with the @code{.} or @code{source} builtins
7645 (@pxref{Bourne Shell Builtins}).
7646
7647 @item
7648 Bash includes the @code{shopt} builtin, for finer control of shell
7649 optional capabilities (@pxref{The Shopt Builtin}), and allows these options
7650 to be set and unset at shell invocation (@pxref{Invoking Bash}).
7651
7652 @item
7653 Bash has much more optional behavior controllable with the @code{set}
7654 builtin (@pxref{The Set Builtin}).
7655
7656 @item
7657 The @samp{-x} (@code{xtrace}) option displays commands other than
7658 simple commands when performing an execution trace
7659 (@pxref{The Set Builtin}).
7660
7661 @item
7662 The @code{test} builtin (@pxref{Bourne Shell Builtins})
7663 is slightly different, as it implements the @sc{posix} algorithm,
7664 which specifies the behavior based on the number of arguments.
7665
7666 @item
7667 Bash includes the @code{caller} builtin, which displays the context of
7668 any active subroutine call (a shell function or a script executed with
7669 the @code{.} or @code{source} builtins).  This supports the bash
7670 debugger.
7671
7672 @item
7673 The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a
7674 @code{DEBUG} pseudo-signal specification, similar to @code{EXIT}.
7675 Commands specified with a @code{DEBUG} trap are executed before every
7676 simple command, @code{for} command, @code{case} command,
7677 @code{select} command, every arithmetic @code{for} command, and before
7678 the first command executes in a shell function.
7679 The @code{DEBUG} trap is not inherited by shell functions unless the
7680 function has been given the @code{trace} attribute or the
7681 @code{functrace} option has been enabled using the @code{shopt} builtin.
7682 The @code{extdebug} shell option has additional effects on the
7683 @code{DEBUG} trap.
7684
7685 The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows an
7686 @code{ERR} pseudo-signal specification, similar to @code{EXIT} and @code{DEBUG}.
7687 Commands specified with an @code{ERR} trap are executed after a simple
7688 command fails, with a few exceptions.
7689 The @code{ERR} trap is not inherited by shell functions unless the
7690 @code{-o errtrace} option to the @code{set} builtin is enabled.
7691
7692 The @code{trap} builtin (@pxref{Bourne Shell Builtins}) allows a
7693 @code{RETURN} pseudo-signal specification, similar to
7694 @code{EXIT} and @code{DEBUG}.
7695 Commands specified with an @code{RETURN} trap are executed before
7696 execution resumes after a shell function or a shell script executed with
7697 @code{.} or @code{source} returns.
7698 The @code{RETURN} trap is not inherited by shell functions unless the
7699 function has been given the @code{trace} attribute or the
7700 @code{functrace} option has been enabled using the @code{shopt} builtin.
7701
7702 @item
7703 The Bash @code{type} builtin is more extensive and gives more information
7704 about the names it finds (@pxref{Bash Builtins}).
7705
7706 @item
7707 The Bash @code{umask} builtin permits a @option{-p} option to cause
7708 the output to be displayed in the form of a @code{umask} command
7709 that may be reused as input (@pxref{Bourne Shell Builtins}).
7710
7711 @item
7712 Bash implements a @code{csh}-like directory stack, and provides the
7713 @code{pushd}, @code{popd}, and @code{dirs} builtins to manipulate it
7714 (@pxref{The Directory Stack}).
7715 Bash also makes the directory stack visible as the value of the
7716 @env{DIRSTACK} shell variable.
7717
7718 @item
7719 Bash interprets special backslash-escaped characters in the prompt
7720 strings when interactive (@pxref{Printing a Prompt}).
7721
7722 @item
7723 The Bash restricted mode is more useful (@pxref{The Restricted Shell});
7724 the SVR4.2 shell restricted mode is too limited.
7725
7726 @item
7727 The @code{disown} builtin can remove a job from the internal shell
7728 job table (@pxref{Job Control Builtins}) or suppress the sending
7729 of @code{SIGHUP} to a job when the shell exits as the result of a
7730 @code{SIGHUP}.
7731
7732 @item
7733 Bash includes a number of features to support a separate debugger for
7734 shell scripts.
7735
7736 @item
7737 The SVR4.2 shell has two privilege-related builtins
7738 (@code{mldmode} and @code{priv}) not present in Bash.
7739
7740 @item
7741 Bash does not have the @code{stop} or @code{newgrp} builtins.
7742
7743 @item
7744 Bash does not use the @env{SHACCT} variable or perform shell accounting.
7745
7746 @item
7747 The SVR4.2 @code{sh} uses a @env{TIMEOUT} variable like Bash uses
7748 @env{TMOUT}.
7749
7750 @end itemize
7751
7752 @noindent
7753 More features unique to Bash may be found in @ref{Bash Features}.
7754
7755
7756 @appendixsec Implementation Differences From The SVR4.2 Shell
7757
7758 Since Bash is a completely new implementation, it does not suffer from
7759 many of the limitations of the SVR4.2 shell.  For instance:
7760
7761 @itemize @bullet
7762
7763 @item
7764 Bash does not fork a subshell when redirecting into or out of
7765 a shell control structure such as  an @code{if} or @code{while}
7766 statement.
7767
7768 @item
7769 Bash does not allow unbalanced quotes.  The SVR4.2 shell will silently
7770 insert a needed closing quote at @code{EOF} under certain circumstances.
7771 This can be the cause of some hard-to-find errors.
7772
7773 @item
7774 The SVR4.2 shell uses a baroque memory management scheme based on
7775 trapping @code{SIGSEGV}.  If the shell is started from a process with
7776 @code{SIGSEGV} blocked (e.g., by using the @code{system()} C library
7777 function call), it misbehaves badly.
7778
7779 @item
7780 In a questionable attempt at security, the SVR4.2 shell,
7781 when invoked without the @option{-p} option, will alter its real
7782 and effective @sc{uid} and @sc{gid} if they are less than some
7783 magic threshold value, commonly 100.
7784 This can lead to unexpected results.
7785
7786 @item
7787 The SVR4.2 shell does not allow users to trap @code{SIGSEGV},
7788 @code{SIGALRM}, or @code{SIGCHLD}.
7789
7790 @item
7791 The SVR4.2 shell does not allow the @env{IFS}, @env{MAILCHECK},
7792 @env{PATH}, @env{PS1}, or @env{PS2} variables to be unset.
7793
7794 @item
7795 The SVR4.2 shell treats @samp{^} as the undocumented equivalent of
7796 @samp{|}.
7797
7798 @item
7799 Bash allows multiple option arguments when it is invoked (@code{-x -v});
7800 the SVR4.2 shell allows only one option argument (@code{-xv}).  In
7801 fact, some versions of the shell dump core if the second argument begins
7802 with a @samp{-}.
7803
7804 @item
7805 The SVR4.2 shell exits a script if any builtin fails; Bash exits
7806 a script only if one of the @sc{posix} special builtins fails, and
7807 only for certain failures, as enumerated in the @sc{posix} standard.
7808
7809 @item 
7810 The SVR4.2 shell behaves differently when invoked as @code{jsh}
7811 (it turns on job control).
7812 @end itemize
7813
7814 @node GNU Free Documentation License
7815 @appendix GNU Free Documentation License
7816
7817 @include fdl.texi
7818
7819 @node Indexes
7820 @appendix Indexes
7821
7822 @menu
7823 * Builtin Index::               Index of Bash builtin commands.
7824 * Reserved Word Index::         Index of Bash reserved words.
7825 * Variable Index::              Quick reference helps you find the
7826                                 variable you want.
7827 * Function Index::              Index of bindable Readline functions.
7828 * Concept Index::               General index for concepts described in
7829                                 this manual.
7830 @end menu
7831
7832 @node Builtin Index
7833 @appendixsec Index of Shell Builtin Commands
7834 @printindex bt
7835
7836 @node Reserved Word Index
7837 @appendixsec Index of Shell Reserved Words
7838 @printindex rw
7839
7840 @node Variable Index
7841 @appendixsec Parameter and Variable Index
7842 @printindex vr
7843
7844 @node Function Index
7845 @appendixsec Function Index
7846 @printindex fn
7847
7848 @node Concept Index
7849 @appendixsec Concept Index
7850 @printindex cp
7851
7852 @bye