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