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