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