1 \input texinfo.tex @c -*- texinfo -*-
3 @setfilename bashref.info
4 @settitle Bash Reference Manual
8 last change: Mon May 19 12:55:22 EDT 1997
13 @set UPDATED 19 May 1997
14 @set UPDATE-MONTH May 1997
20 @setchapternewpage odd
27 This text is a brief description of the features that are present in
30 This is Edition @value{EDITION}, last updated @value{UPDATED},
31 of @cite{The GNU Bash Reference Manual},
32 for @code{Bash}, Version @value{VERSION}.
34 Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
36 Permission is granted to make and distribute verbatim copies of
37 this manual provided the copyright notice and this permission notice
38 are preserved on all copies.
41 Permission is granted to process this file through TeX and print the
42 results, provided the printed document carries copying permission
43 notice identical to this one except for the removal of this paragraph
44 (this paragraph not being relevant to the printed manual).
47 Permission is granted to copy and distribute modified versions of this
48 manual under the conditions for verbatim copying, provided that the entire
49 resulting derived work is distributed under the terms of a permission
50 notice identical to this one.
52 Permission is granted to copy and distribute translations of this manual
53 into another language, under the above conditions for modified versions,
54 except that this permission notice may be stated in a translation approved
60 @title Bash Reference Manual
61 @subtitle Reference Documentation for Bash
62 @subtitle Edition @value{EDITION}, for @code{bash} Version @value{VERSION}.
63 @subtitle @value{UPDATED}
64 @author Chet Ramey, Case Western Reserve University
65 @author Brian Fox, Free Software Foundation
67 @vskip 0pt plus 1filll
68 Copyright @copyright{} 1991, 1993, 1996 Free Software Foundation, Inc.
70 Permission is granted to make and distribute verbatim copies of
71 this manual provided the copyright notice and this permission notice
72 are preserved on all copies.
74 Permission is granted to copy and distribute modified versions of this
75 manual under the conditions for verbatim copying, provided that the entire
76 resulting derived work is distributed under the terms of a permission
77 notice identical to this one.
79 Permission is granted to copy and distribute translations of this manual
80 into another language, under the above conditions for modified versions,
81 except that this permission notice may be stated in a translation approved
82 by the Free Software Foundation.
86 @node Top, Introduction, (dir), (dir)
91 This text is a brief description of the features that are present in
94 This is Edition @value{EDITION}, last updated @value{UPDATED},
95 of @cite{The GNU Bash Reference Manual},
96 for @code{Bash}, Version @value{VERSION}.
98 Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
100 Bash contains features that appear in other popular shells, and some
101 features that only appear in Bash. Some of the shells that Bash has
102 borrowed concepts from are the Bourne Shell (@file{sh}), the Korn Shell
103 (@file{ksh}), and the C-shell (@file{csh} and its successor,
104 @file{tcsh}). The following menu breaks the features up into
105 categories based upon which one of these other shells inspired the
108 This manual is meant as a brief introduction to features found in
109 Bash. The Bash manual page should be used as the definitive
110 reference on shell behavior.
113 * Introduction:: An introduction to the shell.
115 * Definitions:: Some definitions used in the rest of this
118 * Basic Shell Features:: The shell "building blocks".
120 * Bourne Shell Features:: Features similar to those found in the
123 * Csh Features:: Features originally found in the
126 * Korn Shell Features:: Features originally found in the Korn
129 * Bash Features:: Features found only in Bash.
131 * Job Control:: A chapter describing what job control is
132 and how Bash allows you to use it.
134 * Using History Interactively:: Chapter dealing with history expansion
137 * Command Line Editing:: Chapter describing the command line
140 * Installing Bash:: How to build and install Bash on your system.
142 * Reporting Bugs:: How to report bugs in Bash.
144 * Builtin Index:: Index of Bash builtin commands.
146 * Reserved Word Index:: Index of Bash reserved words.
148 * Variable Index:: Quick reference helps you find the
151 * Function Index:: Index of bindable Readline functions.
153 * Concept Index:: General index for concepts described in
159 @chapter Introduction
161 * What is Bash?:: A short description of Bash.
163 * What is a shell?:: A brief introduction to shells.
167 @section What is Bash?
169 Bash is the shell, or command language interpreter,
170 that will appear in the @sc{GNU} operating system.
171 The name is an acronym for the @samp{Bourne-Again SHell},
172 a pun on Steve Bourne, the author of the direct ancestor of the current
173 Unix shell @code{/bin/sh},
174 which appeared in the Seventh Edition Bell Labs Research version
177 Bash is an @code{sh}-compatible shell that incorporates useful
178 features from the Korn shell @code{ksh} and the C shell @code{csh}.
179 It is ultimately intended to be a
180 conformant implementation of the @sc{IEEE} @sc{POSIX} Shell and Tools
181 specification (@sc{IEEE} Working Group 1003.2). It offers functional
182 improvements over @code{sh} for both interactive and programming use.
184 While the @sc{GNU} operating system will include a version
185 of @code{csh}, Bash will be the default shell.
186 Like other @sc{GNU} software, Bash is quite portable. It currently runs
187 on nearly every version of Unix and a few other operating systems @minus{}
188 independently-supported ports exist for @sc{OS/2} and Windows @sc{NT}.
190 @node What is a shell?
191 @section What is a shell?
193 At its base, a shell is simply a macro processor that executes
194 commands. A Unix shell is both a command interpreter, which
195 provides the user interface to the rich set of Unix utilities,
196 and a programming language, allowing these utilitites to be
197 combined. The shell reads commands either from a terminal or a
198 file. Files containing commands can be created, and become
199 commands themselves. These new commands have the same status as
200 system commands in directories like @file{/bin}, allowing users
201 or groups to establish custom environments.
203 A shell allows execution of Unix commands, both synchronously and
204 asynchronously. The @dfn{redirection} constructs permit
205 fine-grained control of the input and output of those commands,
206 and the shell allows control over the contents of their
207 environment. Unix shells also provide a small set of built-in
208 commands (@dfn{builtins}) implementing functionality impossible
209 (e.g., @code{cd}, @code{break}, @code{continue}, and
210 @code{exec}), or inconvenient (@code{history}, @code{getopts},
211 @code{kill}, or @code{pwd}, for example) to obtain via separate
212 utilities. Shells may be used interactively or
213 non-interactively: they accept input typed from the keyboard or
214 from a file. All of the shell builtins are described in
217 While executing commands is essential, most of the power (and
218 complexity) of shells is due to their embedded programming
219 languages. Like any high-level language, the shell provides
220 variables, flow control constructs, quoting, and functions.
222 Shells have begun offering features geared specifically for
223 interactive use rather than to augment the programming language.
224 These interactive features include job control, command line
225 editing, history and aliases. Each of these features is
226 described in this manual.
230 These definitions are used throughout the remainder of this manual.
236 A family of open system standards based on Unix. Bash
237 is concerned with @sc{POSIX} 1003.2, the Shell and Tools Standard.
240 A space or tab character.
244 A command that is implemented internally by the shell itself, rather
245 than by an executable program somewhere in the file system.
247 @item control operator
248 @cindex control operator
249 A @code{word} that performs a control function. It is a @code{newline}
250 or one of the following:
251 @samp{||}, @samp{&&}, @samp{&}, @samp{;}, @samp{;;},
252 @samp{|}, @samp{(}, or @samp{)}.
256 The value returned by a command to its caller.
260 A unit of text that is the result of one of the shell expansions. After
261 expansion, when executing a command, the resulting fields are used as
262 the command name and arguments.
266 A string of characters used to identify a file.
270 A set of processes comprising a pipeline, and any processes descended
271 from it, that are all in the same process group.
275 A mechanism by which users can selectively stop (suspend) and restart
276 (resume) execution of processes.
279 @cindex metacharacter
280 A character that, when unquoted, separates words. A metacharacter is
281 a @code{blank} or one of the following characters:
282 @samp{|}, @samp{&}, @samp{;}, @samp{(}, @samp{)}, @samp{<}, or
288 A @code{word} consisting solely of letters, numbers, and underscores,
289 and beginning with a letter or underscore. @code{Name}s are used as
290 shell variable and function names.
291 Also referred to as an @code{identifier}.
294 @cindex operator, shell
295 A @code{control operator} or a @code{redirection operator}.
296 @xref{Redirections}, for a list of redirection operators.
299 @cindex process group
300 A collection of related processes each having the same process
303 @item process group ID
304 @cindex process group ID
305 A unique identifer that represents a @code{process group}
309 @cindex reserved word
310 A @code{word} that has a special meaning to the shell. Most reserved
311 words introduce shell flow control constructs, such as @code{for} and
315 @cindex return status
316 A synonym for @code{exit status}.
320 A mechanism by which a process may be notified by the kernal
321 of an event occurring in the system.
323 @item special builtin
324 @cindex special builtin
325 A shell builtin command that has been classified as special by the
326 @sc{POSIX.2} standard.
330 A sequence of characters considered a single unit by the shell. It is
331 either a @code{word} or an @code{operator}.
335 A @code{token} that is not an @code{operator}.
338 @node Basic Shell Features
339 @chapter Basic Shell Features
342 Bash is an acronym for @samp{Bourne-Again SHell}.
344 the traditional Unix shell originally written by Stephen Bourne.
345 All of the Bourne shell builtin commands are available in Bash,
346 and the rules for evaluation and quoting are taken from the @sc{POSIX}
347 1003.2 specification for the `standard' Unix shell.
349 This chapter briefly summarizes the shell's "building blocks":
350 commands, control structures, shell functions, shell @i{parameters},
352 @i{redirections}, which are a way to direct input and output from
353 and to named files, and how the shell executes commands.
356 * Shell Syntax:: What your input means to the shell.
357 * Simple Commands:: The most common type of command.
358 * Pipelines:: Connecting the input and output of several
360 * Lists:: How to execute commands sequentially.
361 * Looping Constructs:: Shell commands for iterative action.
362 * Conditional Constructs:: Shell commands for conditional execution.
363 * Command Grouping:: Ways to group commands.
364 * Shell Functions:: Grouping commands by name.
365 * Shell Parameters:: Special shell variables.
366 * Shell Expansions:: How Bash expands variables and the various
367 expansions available.
368 * Redirections:: A way to control where input and output go.
369 * Executing Commands:: What happens when you run a command.
370 * Shell Scripts:: Executing files of shell commands.
374 @section Shell Syntax
376 * Shell Operation:: The basic operation of the shell.
378 * Quoting:: How to remove the special meaning from characters.
380 * Comments:: How to specify comments.
383 @node Shell Operation
384 @subsection Shell Operation
386 The following is a brief description of the shell's operation when it
387 reads and executes a command. Basically, the shell does the
392 Reads its input from a file (@pxref{Shell Scripts}), from a string
393 supplied as an argument to the @samp{-c} invocation option
394 (@pxref{Invoking Bash}), or from the user's terminal.
397 Breaks the input into words and operators, obeying the quoting rules
398 described in @ref{Quoting}. Tokens are separated by
399 @code{metacharacters}. Alias expansion is performed by this step
403 Parses the tokens into simple and compound commands.
406 Performs the various shell expansions (@pxref{Shell Expansions}), breaking
407 the expanded tokens into lists of filenames (@pxref{Filename Expansion})
408 and commands and arguments.
411 Performs any necessary redirections (@pxref{Redirections}) and removes
412 the redirection operators and their operands from the argument list.
415 Executes the command (@pxref{Executing Commands}).
418 Optionally waits for the command to complete and collects its exit
427 * Escape Character:: How to remove the special meaning from a single
429 * Single Quotes:: How to inhibit all interpretation of a sequence
431 * Double Quotes:: How to suppress most of the interpretation of a
432 sequence of characters.
433 * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
435 * Locale Translation:: How to translate strings into different languages.
438 Quoting is used to remove the special meaning of certain
439 characters or words to the shell. Quoting can be used to
440 disable special treatment for special characters, to prevent
441 reserved words from being recognized as such, and to prevent
444 Each of the shell @code{metacharacters} (@pxref{Definitions})
445 has special meaning to the shell and must be quoted if they are to
446 represent themselves. There are three quoting mechanisms: the
447 @var{escape character}, single quotes, and double quotes.
449 @node Escape Character
450 @subsubsection Escape Character
451 A non-quoted backslash @samp{\} is the Bash escape character.
452 It preserves the literal value of the next character that follows,
453 with the exception of @code{newline}. If a @code{\newline} pair
454 appears, and the backslash is not quoted, the @code{\newline}
455 is treated as a line continuation (that is, it is effectively ignored).
458 @subsubsection Single Quotes
460 Enclosing characters in single quotes preserves the literal value
461 of each character within the quotes. A single quote may not occur
462 between single quotes, even when preceded by a backslash.
465 @subsubsection Double Quotes
467 Enclosing characters in double quotes preserves the literal value
468 of all characters within the quotes, with the exception of
469 @samp{$}, @samp{`}, and @samp{\}.
470 The characters @samp{$} and @samp{`}
471 retain their special meaning within double quotes. The backslash
472 retains its special meaning only when followed by one of the following
474 @samp{$}, @samp{`}, @samp{"}, @samp{\}, or @code{newline}.
475 A double quote may be quoted within double quotes by preceding it with
478 The special parameters @samp{*} and @samp{@@} have special meaning
479 when in double quotes (@pxref{Shell Parameter Expansion}).
482 @subsubsection ANSI-C Quoting
483 @cindex quoting, ANSI
485 Words of the form @code{$'@var{string}'} are treated specially. The
486 word expands to @var{string}, with backslash-escaped characters replaced
487 as specifed by the ANSI C standard. Backslash escape sequences, if
488 present, are decoded as follows:
496 an escape character (not ANSI C)
510 the character whose @code{ASCII} code is @var{nnn} in octal
514 The result is single-quoted, as if the dollar sign had not been present.
516 @node Locale Translation
517 @subsubsection Locale-Specific Translation
520 A double-quoted string preceded by a dollar sign (@samp{$}) will cause
521 the string to be translated according to the current locale.
522 If the current locale is @code{C} or @code{POSIX}, the dollar sign
524 If the string is translated and replaced, the replacement is
529 @cindex comments, shell
531 In a non-interactive shell, or an interactive shell in which the
532 @code{interactive_comments} option to the @code{shopt}
533 builtin is enabled (@pxref{Bash Builtins}),
534 a word beginning with @samp{#}
535 causes that word and all remaining characters on that line to
536 be ignored. An interactive shell without the @code{interactive_comments}
537 option enabled does not allow comments. The @code{interactive_comments}
538 option is on by default in interactive shells.
540 @node Simple Commands
541 @section Simple Commands
542 @cindex commands, simple
544 A simple command is the kind of command you'll encounter most often.
545 It's just a sequence of words separated by @code{blank}s, terminated
546 by one of the shell control operators (@pxref{Definitions}). The
547 first word generally specifies a command to be executed.
549 The return status (@pxref{Exit Status}) of a simple command is
550 its exit status as provided
551 by the @sc{POSIX.1} @code{waitpid} function, or 128+@var{n} if the command
552 was terminated by signal @var{n}.
557 @cindex commands, pipelines
559 A @code{pipeline} is a sequence of simple commands separated by
564 @cindex command timing
565 The format for a pipeline is
567 [@code{time} [@code{-p}]] [@code{!}] @var{command1} [@code{|} @var{command2} @dots{}]
571 The output of each command in the pipeline is connected to the input of
572 the next command. That is, each command reads the previous command's
575 The reserved word @code{time} causes timing statistics
576 to be printed for the pipeline once it finishes.
577 The @samp{-p} option changes the output format to that specified
579 The @code{TIMEFORMAT} variable may be set to a format string that
580 specifies how the timing information should be displayed.
581 @xref{Bash Variables}, for a description of the available formats.
583 Each command in a pipeline is executed in its own subshell. The exit
584 status of a pipeline is the exit status of the last command in the
585 pipeline. If the reserved word @samp{!} precedes the pipeline, the
586 exit status is the logical @sc{NOT} of the exit status of the last command.
589 @section Lists of Commands
590 @cindex commands, lists
592 A @code{list} is a sequence of one or more pipelines separated by one
593 of the operators @samp{;}, @samp{&}, @samp{&&}, or @samp{||},
594 and optionally terminated by one of @samp{;}, @samp{&}, or a
597 Of these list operators, @samp{&&} and @samp{||}
598 have equal precedence, followed by @samp{;} and @samp{&},
599 which have equal precedence.
601 If a command is terminated by the control operator @samp{&},
602 the shell executes the command in the @var{background}
603 in a subshell. The shell does not wait for the command to
604 finish, and the return status is 0 (true). Commands separated by a
605 @samp{;} are executed sequentially; the shell waits for each
606 command to terminate in turn. The return status is the
607 exit status of the last command executed.
609 The control operators @samp{&&} and @samp{||}
610 denote @sc{AND} lists and @sc{OR} lists, respectively.
611 An @sc{AND} list has the form
613 @var{command} && @var{command2}
617 @var{command2} is executed if, and only if, @var{command}
618 returns an exit status of zero.
620 An @sc{OR} list has the form
622 @var{command} || @var{command2}
626 @var{command2} is executed if and only if @var{command}
627 returns a non-zero exit status.
630 @sc{AND} and @sc{OR} lists is the exit status of the last command
631 executed in the list.
633 @node Looping Constructs
634 @section Looping Constructs
635 @cindex commands, looping
637 Note that wherever you see a @samp{;} in the description of a
638 command's syntax, it may be replaced indiscriminately with
639 one or more newlines.
641 Bash supports the following looping constructs.
648 The syntax of the @code{until} command is:
650 until @var{test-commands}; do @var{consequent-commands}; done
652 Execute @var{consequent-commands} as long as the final command in
653 @var{test-commands} has an exit status which is not zero.
657 The syntax of the @code{while} command is:
659 while @var{test-commands}; do @var{consequent-commands}; done
662 Execute @var{consequent-commands} as long as the final command in
663 @var{test-commands} has an exit status of zero.
667 The syntax of the @code{for} command is:
670 for @var{name} [in @var{words} @dots{}]; do @var{commands}; done
672 Execute @var{commands} for each member in @var{words}, with @var{name}
673 bound to the current member. If @samp{in @var{words}} is not
674 present, @samp{in "$@@"} is assumed.
678 The @code{break} and @code{continue} builtins (@pxref{Bourne Shell Builtins})
679 may be used to control loop execution.
681 @node Conditional Constructs
682 @section Conditional Constructs
683 @cindex commands, conditional
692 The syntax of the @code{if} command is:
695 if @var{test-commands}; then
696 @var{consequent-commands};
697 [elif @var{more-test-commands}; then
698 @var{more-consequents};]
699 [else @var{alternate-consequents};]
703 Execute @var{consequent-commands} only if the final command in
704 @var{test-commands} has an exit status of zero.
705 Otherwise, each @code{elif} list is executed in turn,
706 and if its exit status is zero,
707 the corresponding @var{more-consequents} is executed and the
709 If @samp{else @var{alternate-consequents}} is present, and
710 the final command in the final @code{if} or @code{elif} clause
711 has a non-zero exit status, then execute @var{alternate-consequents}.
717 The syntax of the @code{case} command is:
720 @code{case @var{word} in [ ( @var{pattern} [| @var{pattern}]@dots{}) @var{commands} ;;]@dots{} esac}
723 Selectively execute @var{commands} based upon @var{word} matching
724 @var{pattern}. The @samp{|} is used to separate multiple patterns.
726 Here is an example using @code{case} in a script that could be used to
727 describe one interesting feature of an animal:
730 echo -n "Enter the name of an animal: "
732 echo -n "The $ANIMAL has "
734 horse | dog | cat) echo -n "four";;
735 man | kangaroo ) echo -n "two";;
736 *) echo -n "an unknown number of";;
743 (( @var{expression} ))
746 The @var{expression} is evaluated according to the rules described
747 below (@pxref{Arithmetic Evaluation}).
748 If the value of the expression is non-zero, the return status is 0;
749 otherwise the return status is 1. This is exactly equivalent to
751 let "@var{expression}"
756 The @code{select} construct, which allows users to choose from a list
757 of items presented as a menu, is also available.
758 @xref{Korn Shell Constructs}, for a full description of @code{select}.
760 @node Command Grouping
761 @section Grouping Commands
762 @cindex commands, grouping
764 Bash provides two ways to group a list of commands to be executed
765 as a unit. When commands are grouped, redirections may be applied
766 to the entire command list. For example, the output of all the
767 commands in the list may be redirected to a single stream.
775 Placing a list of commands between parentheses causes a subshell
776 to be created, and each of the commands to be executed in that
777 subshell. Since the @var{list} is executed in a subshell, variable
778 assignments do not remain in effect after the subshell completes.
787 Placing a list of commands between curly braces causes the list to
788 be executed in the current shell context. No subshell is created.
789 The semicolon following @var{list} is required.
792 In addition to the creation of a subshell, there is a subtle difference
793 between these two constructs due to historical reasons. The braces
794 are @code{reserved words}, so they must be separated from the @var{list}
795 by @code{blank}s. The parentheses are @code{operators}, and are
796 recognized as separate tokens by the shell even if they are not separated
797 from the @var{list} by whitespace.
799 The exit status of both of these constructs is the exit status of
802 @node Shell Functions
803 @section Shell Functions
804 @cindex shell function
805 @cindex functions, shell
807 Shell functions are a way to group commands for later execution
808 using a single name for the group. They are executed just like
809 a "regular" command. Shell functions are executed in the current
810 shell context; no new process is created to interpret them.
812 Functions are declared using this syntax:
815 [ @code{function} ] @var{name} () @{ @var{command-list}; @}
818 This defines a shell function named @var{name}. The reserved
819 word @code{function} is optional. The @var{body} of the
820 function is the @var{command-list} between @{ and @}. This list
821 is executed whenever @var{name} is specified as the
822 name of a command. The exit status of a function is
823 the exit status of the last command executed in the body.
825 When a function is executed, the arguments to the
826 function become the positional parameters
827 during its execution (@pxref{Positional Parameters}).
828 The special parameter @samp{#} that expands to the number of
829 positional parameters is updated to reflect the change.
830 Positional parameter @code{0} is unchanged.
832 If the builtin command @code{return}
833 is executed in a function, the function completes and
834 execution resumes with the next command after the function
835 call. When a function completes, the values of the
836 positional parameters and the special parameter @samp{#}
837 are restored to the values they had prior to function
838 execution. If a numeric argument is given to @code{return},
839 that is the function return status.
841 Variables local to the function may be declared with the
842 @code{local} builtin. These variables are visible only to
843 the function and the commands it invokes.
845 Functions may be recursive. No limit is placed on the number of
848 @node Shell Parameters
849 @section Shell Parameters
851 @cindex variable, shell
852 @cindex shell variable
855 * Positional Parameters:: The shell's command-line arguments.
856 * Special Parameters:: Parameters with special meanings.
859 A @var{parameter} is an entity that stores values.
860 It can be a @code{name}, a number, or one of the special characters
862 For the shell's purposes, a @var{variable} is a parameter denoted by a
865 A parameter is set if it has been assigned a value. The null string is
866 a valid value. Once a variable is set, it may be unset only by using
867 the @code{unset} builtin command.
869 A variable may be assigned to by a statement of the form
871 @var{name}=[@var{value}]
875 is not given, the variable is assigned the null string. All
876 @var{value}s undergo tilde expansion, parameter and variable expansion,
877 command substitution, arithmetic expansion, and quote
878 removal (detailed below). If the variable has its @samp{-i} attribute
879 set (see the description of the @code{declare} builtin in
880 @ref{Bash Builtins}), then @var{value}
881 is subject to arithmetic expansion even if the @code{$((@dots{}))}
882 syntax does not appear (@pxref{Arithmetic Expansion}).
883 Word splitting is not performed, with the exception
884 of @code{"$@@"} as explained below.
885 Filename expansion is not performed.
887 @node Positional Parameters
888 @subsection Positional Parameters
889 @cindex parameters, positional
891 A @var{positional parameter}
892 is a parameter denoted by one or more
893 digits, other than the single digit @code{0}. Positional parameters are
894 assigned from the shell's arguments when it is invoked,
895 and may be reassigned using the @code{set}
896 builtin command. Positional parameters may not be assigned to
897 with assignment statements. The positional parameters are
898 temporarily replaced when a shell function is executed
899 (@pxref{Shell Functions}).
901 When a positional parameter consisting of more than a single
902 digit is expanded, it must be enclosed in braces.
904 @node Special Parameters
905 @subsection Special Parameters
906 @cindex parameters, special
908 The shell treats several parameters specially. These parameters may
909 only be referenced; assignment to them is not allowed.
914 Expands to the positional parameters, starting from one. When the
915 expansion occurs within double quotes, it expands to a single word
916 with the value of each parameter separated by the first character
918 special variable. That is, @code{"$*"} is equivalent
919 to @code{"$1@var{c}$2@var{c}@dots{}"}, where @var{c}
920 is the first character of the value of the @code{IFS}
922 If @code{IFS} is unset, the parameters are separated by spaces.
923 If @code{IFS} is null, the parameters are joined without intervening
928 Expands to the positional parameters, starting from one. When the
929 expansion occurs within double quotes, each parameter expands as a
930 separate word. That is, @code{"$@@"} is equivalent to
931 @code{"$1" "$2" @dots{}}.
932 When there are no positional parameters, @code{"$@@"} and
934 expand to nothing (i.e., they are removed).
937 Expands to the number of positional parameters in decimal.
940 Expands to the exit status of the most recently executed foreground
944 Expands to the current option flags as specified upon invocation,
946 builtin command, or those set by the shell itself
947 (such as the @samp{-i} option).
950 Expands to the process @sc{ID} of the shell. In a @code{()} subshell, it
951 expands to the process @sc{ID} of the current shell, not the
955 Expands to the process @sc{ID} of the most recently executed background
956 (asynchronous) command.
959 Expands to the name of the shell or shell script. This is set at
960 shell initialization. If Bash is invoked with a file of commands,
961 @code{$0} is set to the name of that file. If Bash
962 is started with the @samp{-c} option, then @code{$0}
963 is set to the first argument after the string to be
964 executed, if one is present. Otherwise, it is set
965 to the filename used to invoke Bash, as given by argument zero.
968 At shell startup, set to the absolute filename of the shell or shell
969 script being executed as passed in the argument list.
970 Subsequently, expands to the last argument to the previous command,
972 Also set to the full filename of each command executed and placed in
973 the environment exported to that command.
974 When checking mail, this parameter holds the name of the mail file.
977 @node Shell Expansions
978 @section Shell Expansions
981 Expansion is performed on the command line after it has been split into
982 @code{token}s. There are seven kinds of expansion performed:
984 @item brace expansion
985 @item tilde expansion
986 @item parameter and variable expansion
987 @item command substitution
988 @item arithmetic expansion
990 @item filename expansion
994 * Shell Parameter Expansion:: How Bash expands variables to their values.
995 * Command Substitution:: Using the output of a command as an argument.
996 * Process Substitution:: A way to write and read to and from a
998 * Word Splitting:: How the results of expansion are split into separate
1000 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
1001 * Quote Removal:: How and when quote characters are removed from
1005 Brace expansion, tilde expansion, and arithmetic expansion are described
1006 in other sections. For brace expansion, see @ref{Brace Expansion}; for
1007 tilde expansion, see @ref{Tilde Expansion}; and for arithmetic expansion,
1008 see @ref{Arithmetic Expansion}.
1010 The order of expansions is: brace expansion, tilde expansion,
1011 parameter, variable, and arithmetic expansion and
1012 command substitution
1013 (done in a left-to-right fashion), word splitting, and filename
1016 On systems that can support it, there is an additional expansion
1017 available: @var{process substitution}. This is performed at the
1018 same time as parameter, variable, and arithemtic expansion and
1019 command substitution.
1021 Only brace expansion, word splitting, and filename expansion
1022 can change the number of words of the expansion; other expansions
1023 expand a single word to a single word.
1024 The only exceptions to this are the expansions of
1025 @code{"$@@"} (@pxref{Special Parameters}) and @code{"$@{@var{name}[@@]@}"}
1028 After all expansions, @code{quote removal} (@pxref{Quote Removal})
1031 @node Shell Parameter Expansion
1032 @subsection Shell Parameter Expansion
1033 @cindex parameter expansion
1034 @cindex expansion, parameter
1036 The @samp{$} character introduces parameter expansion,
1037 command substitution, or arithmetic expansion. The parameter name
1038 or symbol to be expanded may be enclosed in braces, which
1039 are optional but serve to protect the variable to be expanded from
1040 characters immediately following it which could be
1041 interpreted as part of the name.
1043 The basic form of parameter expansion is $@{@var{parameter}@}.
1044 The value of @var{parameter} is substituted. The braces are required
1045 when @var{parameter}
1046 is a positional parameter with more than one digit,
1047 or when @var{parameter}
1048 is followed by a character that is not to be
1049 interpreted as part of its name.
1051 If the first character of @var{parameter} is an exclamation point,
1052 a level of variable indirection is introduced.
1053 Bash uses the value of the variable formed from the rest of
1054 @var{parameter} as the name of the variable; this variable is then
1055 expanded and that value is used in the rest of the substitution, rather
1056 than the value of @var{parameter} itself.
1057 This is known as @code{indirect expansion}.
1059 In each of the cases below, @var{word} is subject to tilde expansion,
1060 parameter expansion, command substitution, and arithmetic expansion.
1061 When not performing substring expansion, Bash tests for a parameter
1062 that is unset or null; omitting the colon results in a test only for a
1063 parameter that is unset.
1067 @item $@{@var{parameter}:@minus{}@var{word}@}
1068 If @var{parameter} is unset or null, the expansion of
1069 @var{word} is substituted. Otherwise, the value of
1070 @var{parameter} is substituted.
1072 @item $@{@var{parameter}:=@var{word}@}
1074 is unset or null, the expansion of @var{word}
1075 is assigned to @var{parameter}.
1076 The value of @var{parameter}
1077 is then substituted. Positional parameters and special parameters may
1078 not be assigned to in this way.
1080 @item $@{@var{parameter}:?@var{word}@}
1082 is null or unset, the expansion of @var{word} (or a message
1083 to that effect if @var{word}
1084 is not present) is written to the standard error and the shell, if it
1085 is not interactive, exits. Otherwise, the value of @var{parameter} is
1088 @item $@{@var{parameter}:+@var{word}@}
1090 is null or unset, nothing is substituted, otherwise the expansion of
1091 @var{word} is substituted.
1093 @item $@{@var{parameter}:@var{offset}@}
1094 @itemx $@{@var{parameter}:@var{offset}:@var{length}@}
1095 Expands to up to @var{length} characters of @var{parameter},
1096 starting at @var{offset}.
1097 If @var{length} is omitted, expands to the substring of
1098 @var{parameter}, starting at the character specified by @var{offset}.
1099 @var{length} and @var{offset} are arithmetic expressions
1100 (@pxref{Arithmetic Evaluation}).
1101 This is referred to as Substring Expansion.
1103 @var{length} must evaluate to a number greater than or equal to zero.
1104 If @var{offset} evaluates to a number less than zero, the value
1105 is used as an offset from the end of the value of @var{parameter}.
1106 If @var{parameter} is @samp{@@}, the result is @var{length} positional
1107 parameters beginning at @var{offset}.
1108 If @var{parameter} is an array name indexed by @samp{@@} or @samp{*},
1109 the result is the @var{length}
1110 members of the array beginning with $@{@var{parameter}[@var{offset}]@}.
1111 Substring indexing is zero-based unless the positional parameters are
1112 used, in which case the indexing starts at 1.
1114 @item $@{#@var{parameter}@}
1115 The length in characters of the value of @var{parameter} is substituted.
1117 is @samp{*} or @samp{@@},
1118 the length substituted is the number of positional parameters.
1120 is an array name subscripted
1121 by @samp{*} or @samp{@@},
1122 the length substituted is the number of elements in the array.
1124 @item $@{@var{parameter}#@var{word}@}
1125 @itemx $@{@var{parameter}##@var{word}@}
1127 is expanded to produce a pattern just as in filename
1128 expansion (@pxref{Filename Expansion}). If the pattern matches
1129 the beginning of the value of @var{parameter},
1130 then the expansion is the value of @var{parameter}
1131 with the shortest matching pattern (the @samp{#} case) or the
1132 longest matching pattern (the @samp{##} case) deleted.
1133 If @var{parameter} is @samp{@@} or @samp{*},
1134 the pattern removal operation is applied to each positional
1135 parameter in turn, and the expansion is the resultant list.
1136 If @var{parameter} is an array variable subscripted with
1137 @samp{@@} or @samp{*},
1138 the pattern removal operation is applied to each member of the
1139 array in turn, and the expansion is the resultant list.
1141 @item $@{@var{parameter}%@var{word}@}
1142 @itemx $@{@var{parameter}%%@var{word}@}
1143 The @var{word} is expanded to produce a pattern just as in
1145 If the pattern matches a trailing portion of the value of
1146 @var{parameter}, then the expansion is the value of @var{parameter}
1147 with the shortest matching pattern (the @samp{%} case) or the
1148 longest matching pattern (the @samp{%%} case) deleted.
1149 If @var{parameter} is @samp{@@} or @samp{*},
1150 the pattern removal operation is applied to each positional
1151 parameter in turn, and the expansion is the resultant list.
1153 is an array variable subscripted with @samp{@@} or @samp{*},
1154 the pattern removal operation is applied to each member of the
1155 array in turn, and the expansion is the resultant list.
1157 @item $@{@var{parameter}/@var{pattern}/@var{string}@}
1158 @itemx $@{@var{parameter}//@var{pattern}/@var{string}@}
1160 The @var{pattern} is expanded to produce a pattern just as in
1162 @var{Parameter} is expanded and the longest match of @var{pattern}
1163 against its value is replaced with @var{string}.
1164 In the first form, only the first match is replaced.
1165 The second form causes all matches of @var{pattern} to be
1166 replaced with @var{string}.
1167 If @var{pattern} begins with @samp{#}, it must match at the beginning
1169 If @var{pattern} begins with @samp{%}, it must match at the end
1171 If @var{string} is null, matches of @var{pattern} are deleted
1172 and the @code{/} following @var{pattern} may be omitted.
1173 If @var{parameter} is @samp{@@} or @samp{*},
1174 the substitution operation is applied to each positional
1175 parameter in turn, and the expansion is the resultant list.
1177 is an array variable subscripted with @samp{@@} or @samp{*},
1178 the substitution operation is applied to each member of the
1179 array in turn, and the expansion is the resultant list.
1183 @node Command Substitution
1184 @subsection Command Substitution
1185 @cindex command substitution
1187 Command substitution allows the output of a command to replace
1188 the command name. There are two forms:
1199 Bash performs the expansion by executing @var{command} and
1200 replacing the command substitution with the standard output of the
1201 command, with any trailing newlines deleted.
1203 When the old-style backquote form of substitution is used,
1204 backslash retains its literal meaning except when followed by
1205 @samp{$}, @samp{`}, or @samp{\}.
1206 When using the @code{$(@var{command})} form, all characters between
1207 the parentheses make up the command; none are treated specially.
1209 Command substitutions may be nested. To nest when using the old form,
1210 escape the inner backquotes with backslashes.
1212 If the substitution appears within double quotes, word splitting and
1213 filename expansion are not performed on the results.
1215 @node Process Substitution
1216 @subsection Process Substitution
1217 @cindex process substitution
1219 Process substitution is supported on systems that support named
1220 pipes (@sc{FIFO}s) or the @file{/dev/fd} method of naming open files.
1221 It takes the form of
1231 The process @var{list} is run with its input or output connected to a
1232 @sc{FIFO} or some file in @file{/dev/fd}. The name of this file is
1233 passed as an argument to the current command as the result of the
1234 expansion. If the @code{>(@var{list})} form is used, writing to
1235 the file will provide input for @var{list}. If the
1236 @code{<(@var{list})} form is used, the file passed as an
1237 argument should be read to obtain the output of @var{list}.
1239 On systems that support it, process substitution is performed
1240 simultaneously with parameter and variable expansion,
1241 command substitution, and arithmetic expansion.
1243 @node Word Splitting
1244 @subsection Word Splitting
1245 @cindex word splitting
1247 The shell scans the results of parameter expansion, command substitution,
1248 and arithmetic expansion that did not occur within double quotes for
1251 The shell treats each character of @code{$IFS}
1252 as a delimiter, and splits the results of the other
1253 expansions into words on these characters. If
1254 @code{IFS} is unset, or its value is exactly @code{<space><tab><newline>},
1255 the default, then any sequence of @code{IFS}
1256 characters serves to delimit words. If @code{IFS}
1257 has a value other than the default, then sequences of
1258 the whitespace characters @code{space} and @code{tab}
1259 are ignored at the beginning and end of the
1260 word, as long as the whitespace character is in the
1261 value of @code{IFS} (an @code{IFS} whitespace character).
1262 Any character in @code{IFS} that is not @code{IFS}
1263 whitespace, along with any adjacent @code{IFS}
1264 whitespace characters, delimits a field. A sequence of @code{IFS}
1265 whitespace characters is also treated as a delimiter.
1266 If the value of @code{IFS} is null, no word splitting occurs.
1268 Explicit null arguments (@code{""} or @code{''}) are retained.
1269 Unquoted implicit null arguments, resulting from the expansion of
1271 that have no values, are removed.
1272 If a parameter with no value is expanded within double quotes, a
1273 null argument results and is retained.
1275 Note that if no expansion occurs, no splitting
1278 @node Filename Expansion
1279 @subsection Filename Expansion
1280 @cindex expansion, filename
1281 @cindex expansion, pathname
1282 @cindex filename expansion
1283 @cindex pathname expansion
1285 After word splitting,
1286 unless the @samp{-f}
1287 option has been set (@pxref{The Set Builtin}),
1288 Bash scans each word for the characters
1289 @samp{*}, @samp{?}, and @samp{[}.
1290 If one of these characters appears, then the word is
1291 regarded as a @var{pattern},
1292 and replaced with an alphabetically sorted list of
1293 file names matching the pattern. If no matching file names are found,
1294 and the shell option @code{nullglob} is disabled, the word is left
1295 unchanged. If the option is set, and no matches are found, the word
1296 is removed. When a pattern is used for filename generation,
1297 the character @samp{.}
1298 at the start of a filename or immediately following a slash
1299 must be matched explicitly, unless the shell option @code{dotglob}
1300 is set. The slash character must always be matched explicitly.
1301 In other cases, the @samp{.} character is not treated specially.
1302 See the description of @code{shopt} in @ref{Bash Builtins},
1303 for a description of the @code{nullglob} and @code{dotglob} options.
1305 The @code{GLOBIGNORE}
1306 shell variable may be used to restrict the set of filenames matching a
1307 @var{pattern}. If @code{GLOBIGNORE}
1308 is set, each matching filename that also matches one of the patterns in
1309 @code{GLOBIGNORE} is removed from the list of matches. The filenames
1310 @file{.} and @file{..}
1311 are always ignored, even when @code{GLOBIGNORE}.
1312 is set. However, setting @code{GLOBIGNORE} has the effect of
1313 enabling the @code{dotglob}
1314 shell option, so all other filenames beginning with a
1315 @samp{.} will match.
1316 To get the old behavior of ignoring filenames beginning with a
1317 @samp{.}, make @samp{.*} one of the patterns in @code{GLOBIGNORE}.
1318 The @code{dotglob} option is disabled when @code{GLOBIGNORE}
1321 The special pattern characters have the following meanings:
1324 Matches any string, including the null string.
1326 Matches any single character.
1328 Matches any one of the enclosed characters. A pair of characters
1329 separated by a minus sign denotes a @var{range};
1330 any character lexically between those two characters, inclusive,
1331 is matched. If the first character following the
1332 @samp{[} is a @samp{!} or a @samp{^}
1333 then any character not enclosed is matched. A @samp{@minus{}}
1334 may be matched by including it as the first or last character
1335 in the set. A @samp{]} may be matched by including it as the first
1336 character in the set.
1340 @subsection Quote Removal
1342 After the preceding expansions, all unquoted occurrences of the
1343 characters @samp{\}, @samp{'}, and @samp{"} that did not
1344 result from one of the above expansions are removed.
1347 @section Redirections
1350 Before a command is executed, its input and output
1351 may be @var{redirected}
1352 using a special notation interpreted by the shell.
1353 Redirection may also be used to open and close files for the
1354 current shell execution environment. The following redirection
1355 operators may precede or appear anywhere within a
1356 simple command or may follow a command.
1357 Redirections are processed in the order they appear, from
1360 In the following descriptions, if the file descriptor number is
1361 omitted, and the first character of the redirection operator is
1362 @samp{<}, the redirection refers to the standard input (file
1363 descriptor 0). If the first character of the redirection operator
1364 is @samp{>}, the redirection refers to the standard output (file
1367 The word that follows the redirection operator in the following
1368 descriptions is subjected to brace expansion, tilde expansion,
1369 parameter expansion, command substitution, arithmetic expansion,
1370 quote removal, and filename expansion. If it expands to more
1371 than one word, Bash reports an error.
1373 Note that the order of redirections is significant. For example,
1376 ls > @var{dirlist} 2>&1
1379 directs both standard output and standard error to the file
1380 @var{dirlist}, while the command
1382 ls 2>&1 > @var{dirlist}
1385 directs only the standard output to file @var{dirlist},
1386 because the standard error was duplicated as standard output
1387 before the standard output was redirected to @var{dirlist}.
1389 @subsection Redirecting Input
1390 Redirection of input causes the file whose name results from
1391 the expansion of @var{word}
1392 to be opened for reading on file descriptor @code{n},
1393 or the standard input (file descriptor 0) if @code{n}
1396 The general format for redirecting input is:
1401 @subsection Redirecting Output
1402 Redirection of output causes the file whose name results from
1403 the expansion of @var{word}
1404 to be opened for writing on file descriptor @code{n},
1405 or the standard output (file descriptor 1) if @code{n}
1406 is not specified. If the file does not exist it is created;
1407 if it does exist it is truncated to zero size.
1409 The general format for redirecting output is:
1414 If the redirection operator is @samp{>}, and the @samp{-C} option to the
1415 @code{set} builtin has been enabled, the redirection will fail if the
1416 filename whose name results from the expansion of @var{word} exists.
1417 If the redirection operator is @samp{>|},
1418 then the value of the @samp{-C} option to the @code{set}
1419 builtin command is not tested, and the redirection is attempted even
1420 if the file named by @var{word} exists.
1422 @subsection Appending Redirected Output
1423 Redirection of output in this fashion
1424 causes the file whose name results from
1425 the expansion of @var{word}
1426 to be opened for appending on file descriptor @code{n},
1427 or the standard output (file descriptor 1) if @code{n}
1428 is not specified. If the file does not exist it is created.
1430 The general format for appending output is:
1435 @subsection Redirecting Standard Output and Standard Error
1436 Bash allows both the
1437 standard output (file descriptor 1) and
1438 the standard error output (file descriptor 2)
1439 to be redirected to the file whose name is the
1440 expansion of @var{word} with this construct.
1442 There are two formats for redirecting standard output and
1453 Of the two forms, the first is preferred.
1454 This is semantically equivalent to
1459 @subsection Here Documents
1460 This type of redirection instructs the shell to read input from the
1461 current source until a line containing only @var{word}
1462 (with no trailing blanks) is seen. All of
1463 the lines read up to that point are then used as the standard
1464 input for a command.
1466 The format of here-documents is as follows:
1468 <<[@minus{}]@var{word}
1473 No parameter expansion, command substitution, filename
1474 expansion, or arithmetic expansion is performed on
1475 @var{word}. If any characters in @var{word} are quoted, the
1476 @var{delimiter} is the result of quote removal on @var{word},
1477 and the lines in the here-document are not expanded. Otherwise,
1478 all lines of the here-document are subjected to parameter expansion,
1479 command substitution, and arithmetic expansion. In the latter
1480 case, the pair @code{\newline} is ignored, and @samp{\}
1481 must be used to quote the characters
1482 @samp{\}, @samp{$}, and @samp{`}.
1484 If the redirection operator is @samp{<<-},
1485 then all leading tab characters are stripped from input lines and the
1486 line containing @var{delimiter}.
1487 This allows here-documents within shell scripts to be indented in a
1490 @subsection Duplicating File Descriptors
1491 The redirection operator
1496 is used to duplicate input file descriptors.
1498 expands to one or more digits, the file descriptor denoted by @code{n}
1499 is made to be a copy of that file descriptor. If @var{word}
1500 evaluates to @samp{-}, file descriptor @code{n} is closed. If
1501 @code{n} is not specified, the standard input (file descriptor 0) is used.
1508 is used similarly to duplicate output file descriptors. If
1510 is not specified, the standard output (file descriptor 1) is used.
1511 As a special case, if @code{n} is omitted, and @var{word} does not
1512 expand to one or more digits, the standard output and standard
1513 error are redirected as described previously.
1515 @subsection Opening File Descriptors for Reading and Writing
1516 The redirection operator
1521 causes the file whose name is the expansion of @var{word}
1522 to be opened for both reading and writing on file descriptor
1523 @code{n}, or on file descriptor 0 if @code{n}
1524 is not specified. If the file does not exist, it is created.
1526 @node Executing Commands
1527 @section Executing Commands
1530 * Command Search and Execution:: How Bash finds commands and runs them.
1532 * Environment:: The environment given to a command.
1534 * Exit Status:: The status returned by commands and how Bash
1537 * Signals:: What happens when Bash or a command it runs
1541 @node Command Search and Execution
1542 @subsection Command Search and Execution
1543 @cindex command execution
1544 @cindex command search
1546 After a command has been split into words, if it results in a
1547 simple command and an optional list of arguments, the following
1552 If the command name contains no slashes, the shell attempts to
1553 locate it. If there exists a shell function by that name, that
1554 function is invoked as described above in @ref{Shell Functions}.
1557 If the name does not match a function, the shell searches for
1558 it in the list of shell builtins. If a match is found, that
1562 If the name is neither a shell function nor a builtin,
1563 and contains no slashes, Bash searches each element of
1564 @code{$PATH} for a directory containing an executable file
1565 by that name. Bash uses a hash table to remember the full
1566 filenames of executable files (see the description of
1567 @code{hash} in @ref{Bourne Shell Builtins}) to avoid multiple
1568 @code{PATH} searches.
1569 A full search of the directories in @code{$PATH}
1570 is performed only if the command is not found in the hash table.
1571 If the search is unsuccessful, the shell prints an error
1572 message and returns a nonzero exit status.
1575 If the search is successful, or if the command name contains
1576 one or more slashes, the shell executes the named program.
1577 Argument 0 is set to the name given, and the remaining arguments
1578 to the command are set to the arguments supplied, if any.
1581 If this execution fails because the file is not in executable
1582 format, and the file is not a directory, it is assumed to be
1583 @var{shell script} (@pxref{Shell Scripts}).
1587 @subsection Environment
1590 When a program is invoked it is given an array of strings
1591 called the @var{environment}.
1592 This is a list of name-value pairs, of the form @code{name=value}.
1594 Bash allows you to manipulate the environment in several
1595 ways. On invocation, the shell scans its own environment and
1596 creates a parameter for each name found, automatically marking
1598 to child processes. Executed commands inherit the environment.
1599 The @code{export} and @samp{declare -x}
1600 commands allow parameters and functions to be added to and
1601 deleted from the environment. If the value of a parameter
1602 in the environment is modified, the new value becomes part
1603 of the environment, replacing the old. The environment
1604 inherited by any executed command consists of the shell's
1605 initial environment, whose values may be modified in the shell,
1606 less any pairs removed by the @code{unset} command, plus any
1607 additions via the @code{export} and @samp{declare -x} commands.
1609 The environment for any simple command
1610 or function may be augmented temporarily by prefixing it with
1611 parameter assignments, as described in @ref{Shell Parameters}.
1612 These assignment statements affect only the environment seen
1615 If the @samp{-k} flag is set (@pxref{The Set Builtin}, then all
1616 parameter assignments are placed in the environment for a command,
1617 not just those that precede the command name.
1619 When Bash invokes an external command, the variable @samp{$_}
1620 is set to the full path name of the command and passed to that
1621 command in its environment.
1624 @subsection Exit Status
1627 For the purposes of the shell, a command which exits with a
1628 zero exit status has succeeded.
1629 A non-zero exit status indicates failure.
1630 This seemingly counter-intuitive scheme is used so there
1631 is one well-defined way to indicate success and a variety of
1632 ways to indicate various failure modes.
1633 When a command terminates on a fatal signal whose number is @var{n},
1634 Bash uses the value 128+@var{n} as the exit status.
1636 If a command is not found, the child process created to
1637 execute it returns a status of 127. If a command is found
1638 but is not executable, the return status is 126.
1640 The exit status is used by the Bash conditional commands
1641 (@pxref{Conditional Constructs}) and some of the list
1642 constructs (@pxref{Lists}).
1644 All of the Bash builtins return an exit status of zero if they succeed
1645 and a non-zero status on failure, so they may be used by the
1646 conditional and list constructs.
1650 @cindex signal handling
1652 When Bash is interactive, it ignores
1653 @code{SIGTERM} (so that @samp{kill 0} does not kill an interactive shell),
1655 is caught and handled (so that the @code{wait} builtin is interruptible).
1656 When Bash receives a @code{SIGINT}, it breaks out of any executing loops.
1657 In all cases, Bash ignores @code{SIGQUIT}.
1658 If job control is in effect (@pxref{Job Control}), Bash
1659 ignores @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
1661 Synchronous jobs started by Bash have signals set to the
1662 values inherited by the shell from its parent. When job control
1663 is not in effect, background jobs (commands terminated with @samp{&})
1664 ignore @code{SIGINT} and @code{SIGQUIT}.
1665 Commands run as a result of command substitution ignore the
1666 keyboard-generated job control signals
1667 @code{SIGTTIN}, @code{SIGTTOU}, and @code{SIGTSTP}.
1669 The shell exits by default upon receipt of a @code{SIGHUP}.
1670 Before exiting, it resends the @code{SIGHUP}
1671 to all jobs, running or stopped. To prevent the shell from
1672 sending the @code{SIGHUP} signal to a particular job, remove it
1673 from the jobs table with the @code{disown} builtin
1674 (@pxref{Job Control Builtins})
1675 or use @code{disown -h} to mark it to not receive @code{SIGHUP}.
1678 @section Shell Scripts
1679 @cindex shell script
1681 A shell script is a text file containing shell commands. When such
1682 a file is used as the first non-option argument when invoking Bash,
1683 and neither the @samp{-c} nor @samp{-s} option is supplied
1684 (@pxref{Invoking Bash}),
1685 Bash reads and executes commands from the file, then exits. This
1686 mode of operation creates a non-interactive shell. When Bash runs
1687 a shell script, it sets the special parameter @code{0} to the name
1688 of the file, rather than the name of the shell, and the positional
1689 parameters are set to the remaining arguments, if any are given.
1690 If no additional arguments are supplied, the positional parameters
1693 A shell script may be made executable by using the @code{chmod} command
1694 to turn on the execute bit. When Bash finds such a file while
1695 searching the @code{$PATH} for a command, it spawns a subshell to
1696 execute it. In other words, executing
1698 filename @var{arguments}
1701 is equivalent to executing
1703 bash filename @var{arguments}
1707 if @code{filename} is an executable shell script.
1708 This subshell reinitializes itself, so that the effect is as if a
1709 new shell had been invoked to interpret the script.
1711 Most versions of Unix make this a part of the kernel's command
1712 execution mechanism. If the first line of a script begins with
1713 the two characters @samp{#!}, the remainder of the line specifies
1714 an interpreter for the program. The arguments to the interpreter
1715 consist of a single optional argument following the interpreter
1716 name on the first line of the script file, followed by the name of
1717 the script file, followed by the rest of the arguments. Bash
1718 will perform this action on operating systems that do not handle it
1719 themselves. Note that some older versions of Unix limit the interpreter
1720 name and argument to a maximum of 32 characters.
1722 @node Bourne Shell Features
1723 @chapter Bourne Shell Style Features
1726 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
1728 * Bourne Shell Variables:: Variables which Bash uses in the same way
1729 as the Bourne Shell.
1730 * Other Bourne Shell Features:: Addtional aspects of Bash which behave in
1731 the same way as the Bourne Shell.
1734 This section briefly summarizes things which Bash inherits from
1735 the Bourne Shell: builtins, variables,
1736 and other features. It also lists the significant differences
1737 between Bash and the Bourne Shell.
1739 @node Bourne Shell Builtins
1740 @section Bourne Shell Builtins
1742 The following shell builtin commands are inherited from the Bourne
1743 Shell. These commands are implemented as specified by the @sc{POSIX}
1752 Do nothing beyond expanding @var{arguments} and performing redirections.
1759 Read and execute commands from the @var{filename} argument in the
1760 current shell context.
1767 Exit from a @code{for}, @code{while}, @code{until}, or @code{select} loop.
1768 If @var{n} is supplied, the @var{n}th enclosing loop is exited.
1773 cd [-LP] [@var{directory}]
1775 Change the current working directory to @var{directory}. If @var{directory}
1776 is not given, the value of the @code{HOME} shell variable is used. If the
1777 shell variable @code{CDPATH} exists, it is used as a search path. If
1778 @var{directory} begins with a slash, @code{CDPATH} is not used.
1779 The @samp{-P} option means
1780 to not follow symbolic links; symlinks are followed by default or with the
1788 Resume the next iteration of an enclosing @code{for}, @code{while},
1789 @code{until}, or @code{select} loop.
1790 If @var{n} is supplied, the execution of the
1791 @var{n}th enclosing loop is resumed.
1796 eval [@var{arguments}]
1798 The arguments are concatenated together into a single
1799 command, which is then read and executed.
1804 exec [-cl] [-a @var{name}] [@var{command}] [@var{arguments}]
1807 is supplied, it replaces the shell.
1808 If the @samp{-l} option is supplied,
1809 the shell places a dash in the zeroth arg passed to @var{command}.
1810 This is what the @code{login} program does.
1811 The @samp{-c} option causes @var{command}
1812 to be executed with an empty environment.
1813 If @samp{-a} is supplied, the shell passes @var{name}
1814 as the zeroth argument to @var{command}.
1815 If no @var{command} is specified, redirections may be used to affect
1816 the current shell environment.
1823 Exit the shell, returning a status of @var{n} to the shell's parent.
1828 export [-fn] [-p] [@var{name}[=@var{value}]]
1830 Mark each @var{name} to be passed to child processes
1831 in the environment. If the @samp{-f} option is supplied, the @var{name}s
1832 refer to shell functions. The @samp{-n} option means to no longer mark
1833 each @var{name} for export.
1834 If no @var{names} are supplied, or if the @samp{-p} option is given, a
1835 list of exported names is displayed.
1840 getopts @var{optstring} @var{name} [@var{args}]
1842 @code{getopts} is used by shell scripts to parse positional parameters.
1843 @var{optstring} contains the option letters to be recognized; if a letter
1844 is followed by a colon, the option is expected to have an
1845 argument, which should be separated from it by white space.
1846 Each time it is invoked, @code{getopts}
1847 places the next option in the shell variable @var{name}, initializing
1848 @var{name} if it does not exist,
1849 and the index of the next argument to be processed into the
1850 variable @code{OPTIND}. @code{OPTIND}
1851 is initialized to 1 each time the shell or a shell script
1852 is invoked. When an option requires an argument,
1853 @code{getopts} places that argument into the variable @code{OPTARG}.
1854 The shell does not reset @code{OPTIND}
1855 automatically; it must be manually reset between multiple
1856 calls to @code{getopts}
1857 within the same shell invocation if a new set of parameters
1860 @code{getopts} can report errors in two ways. If the first character of
1861 @var{optstring} is a colon, @var{silent}
1862 error reporting is used. In normal operation diagnostic messages
1863 are printed when illegal options or missing option arguments are
1865 If the variable @code{OPTERR}
1866 is set to 0, no error message will be displayed, even if the first
1867 character of @code{optstring} is not a colon.
1869 If an illegal option is seen,
1870 @code{getopts} places @samp{?} into @var{name} and, if not silent,
1871 prints an error message and unsets @code{OPTARG}.
1872 If @code{getopts} is silent, the option character found is placed in
1873 @code{OPTARG} and no diagnostic message is printed.
1875 If a required argument is not found, and @code{getopts}
1876 is not silent, a question mark (@samp{?}) is placed in @var{name},
1877 @code{OPTARG} is unset, and a diagnostic message is printed.
1878 If @code{getopts} is silent, then a colon (@samp{:}) is placed in
1879 @var{name} and @code{OPTARG} is set to the option character found.
1882 normally parses the positional parameters, but if more arguments are
1883 given in @var{args}, @code{getopts} parses those instead.
1888 hash [-r] [-p @var{filename}] [@var{name}]
1890 Remember the full filenames of commands specified as arguments,
1891 so they need not be searched for on subsequent invocations. The
1892 commands are found by searching through the directories listed in
1893 @code{$PATH}. The @samp{-p} option inhibits the path search, and
1894 @var{filename} is used as the location of @var{name}.
1895 The @samp{-r} option causes the shell to forget
1896 all remembered locations. If no arguments are given, information
1897 about remembered commands is printed.
1904 Print the current working directory. If the @samp{-P} option is supplied,
1905 the path printed will not contain symbolic links. If the @samp{-L} option
1906 is supplied, the path printed may contain symbolic links.
1911 readonly [-apf] [@var{name}] @dots{}
1913 Mark each @var{name} as unchangable. The values of these names may not
1914 be changed by subsequent assignment. If the @samp{-f} option is supplied,
1915 each @var{name} refers to a shell function. The @samp{-a} option means
1916 each @var{name} refers to an array variable.
1917 If no @var{name} arguments are given, or if the @samp{-p}
1918 option is supplied, a list of all readonly names is printed.
1925 Cause a shell function to exit with value @var{n}. This may also be used
1926 to terminate execution of a script being executed with the @code{.}
1934 Shift positional parameters to the left by @var{n}.
1935 The positional parameters from @var{n}+1 @dots{}
1938 Parameters represented by the numbers
1939 @code{$#} to @var{n}+1 are unset. @var{n}
1940 must be a non-negative number less than or equal to @code{$#}.
1946 Evaluate a conditional expression (@pxref{Bash Conditional Expressions}).
1953 Print out the user and system times used by the shell and its children.
1958 trap [-lp] [@var{arg}] [@var{sigspec} @dots{}]
1960 The commands in @var{arg} are to be read and executed when the
1961 shell receives signal @var{sigspec}. If @var{arg} is absent or
1962 equal to @samp{-}, all specified signals are reset to the values
1963 they had when the shell was started.
1964 If @var{arg} is the null string, then the signal specified by
1965 each @var{sigspec} is ignored by the shell and commands it invokes.
1966 If @var{arg} is @samp{-p}, the shell displays the trap commands
1967 associated with each @var{sigspec}. If no arguments are supplied, or
1968 only @samp{-p} is given, @code{trap} prints the list of commands
1969 associated with each signal number.
1970 Each @var{sigspec} is either a signal name such as @code{SIGINT} (with
1971 or without the @code{SIG} prefix) or a signal number.
1973 is @code{0} or @code{EXIT}, @var{arg} is executed when the shell exits.
1974 If a @var{sigspec} is @code{DEBUG}, the command @var{arg} is executed
1975 after every simple command.
1976 The @samp{-l} option causes the shell to print a list of signal names
1977 and their corresponding numbers.
1979 Signals ignored upon entry to the shell cannot be trapped or reset.
1980 Trapped signals are reset to their original values in a child
1981 process when it is created.
1986 umask [-S] [@var{mode}]
1988 Set the shell process's file creation mask to @var{mode}. If
1989 @var{mode} begins with a digit, it is interpreted as an octal number;
1990 if not, it is interpreted as a symbolic mode mask similar
1991 to that accepted by the @code{chmod} command. If @var{mode} is
1992 omitted, the current value of the mask is printed. If the @samp{-S}
1993 option is supplied without a @var{mode} argument, the mask is printed
1994 in a symbolic format.
1999 unset [-fv] [@var{name}]
2001 Each variable or function @var{name} is removed.
2002 If no options are supplied, or the @samp{-v} option is given, each
2003 @var{name} refers to a shell variable.
2004 If the @samp{-f} option is given, the @var{name}s refer to shell
2005 functions, and the function definition is removed.
2006 Read-only variables and functions may not be unset.
2010 @node Bourne Shell Variables
2011 @section Bourne Shell Variables
2013 Bash uses certain shell variables in the same way as the Bourne shell.
2014 In some cases, Bash assigns a default value to the variable.
2019 A list of characters that separate fields; used when the shell splits
2020 words as part of expansion.
2023 A colon-separated list of directories in which the shell looks for
2027 The current user's home directory; the default for the @code{cd} builtin
2031 A colon-separated list of directories used as a search path for
2032 the @code{cd} command.
2035 A colon-separated list of files which the shell periodically checks
2036 for new mail. You can
2037 also specify what message is printed by separating the file name from
2038 the message with a @samp{?}. When used in the text of the message,
2039 @code{$_} stands for the name of the current mailfile.
2042 If this parameter is set to a filename and the @code{MAILPATH} variable
2043 is not set, Bash informs the user of the arrival of mail in
2047 The primary prompt string. The default value is @samp{\s-\v\$ }.
2050 The secondary prompt string. The default value is @samp{> }.
2053 The index of the last option processed by the
2054 @code{getopts} builtin.
2057 The value of the last option argument processed by the
2058 @code{getopts} builtin.
2062 @node Other Bourne Shell Features
2063 @section Other Bourne Shell Features
2066 * Major Differences From The Bourne Shell:: Major differences between
2067 Bash and the Bourne shell.
2070 Bash implements essentially the same grammar, parameter and variable
2071 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
2072 @sc{POSIX} 1003.2 standard as the specification of how these features are to be
2073 implemented. There are some differences between the traditional Bourne
2074 shell and the @sc{POSIX} standard; this section quickly details the differences
2075 of significance. A number of these differences are explained in greater
2076 depth in subsequent sections.
2078 @node Major Differences From The Bourne Shell
2079 @subsection Major Differences From The SVR4.2 Bourne Shell
2081 Bash is @sc{POSIX}-conformant, even where the @sc{POSIX} specification
2082 differs from traditional @code{sh} behavior.
2084 Bash has multi-character invocation options (@pxref{Invoking Bash}).
2086 Bash has command-line editing (@pxref{Command Line Editing}) and
2087 the @code{bind} builtin.
2089 Bash has command history (@pxref{Bash History Facilities}) and the
2090 @code{history} and @code{fc} builtins to manipulate it.
2092 Bash implements @code{csh}-like history expansion (@pxref{History Interaction}).
2094 Bash has one-dimensional array variables (@pxref{Arrays}), and the
2095 appropriate variable expansions and assignment syntax to use them.
2096 Some of the Bash builtins take options to act on arrays. Bash provides
2097 some built-in array variables.
2099 Bash implements the @code{!} keyword to negate the return value of
2100 a pipeline (@pxref{Pipelines}).
2101 Very useful when an @code{if} statement needs to act only if a test fails.
2103 Bash includes the @code{select} compound command, which allows the
2104 generation of simple menus (@pxref{Korn Shell Constructs}).
2106 Bash includes brace expansion (@pxref{Brace Expansion}) and tilde
2107 expansion (@pxref{Tilde Expansion}).
2109 Bash implements command aliases and the @code{alias} and @code{unalias}
2110 builtins (@pxref{Aliases}).
2112 Bash provides shell arithmetic and arithmetic expansion
2113 (@pxref{Shell Arithmetic}).
2115 The @sc{POSIX} and @code{ksh}-style @code{$()} form of command substitution
2116 is implemented (@pxref{Command Substitution}),
2117 and preferred to the Bourne shell's @code{``} (which
2118 is also implemented for backwards compatibility).
2120 Variables present in the shell's initial environment are automatically
2121 exported to child processes. The Bourne shell does not normally do
2122 this unless the variables are explicitly marked using the @code{export}
2125 Bash includes the @sc{POSIX} and @code{ksh}-style pattern removal
2126 @samp{%}, @samp{#}, @samp{%%} and @samp{##} constructs to remove
2127 leading or trailing substrings from variable values
2128 (@pxref{Shell Parameter Expansion}).
2130 The expansion @code{$@{#xx@}}, which returns the length of @code{$xx},
2131 is supported (@pxref{Shell Parameter Expansion}).
2133 The @code{$'@dots{}'} quoting syntax, which expands ANSI-C
2134 backslash-escaped characters in the text between the single quotes,
2135 is supported (@pxref{ANSI-C Quoting}).
2137 Bash supports the @code{$"@dots{}"} quoting syntax to do
2138 locale-specific translation of the characters between the double
2139 quotes. The @samp{-D} and @samp{--dump-strings} invocation options
2140 list the translatable strings found in a script
2141 (@pxref{Locale Translation}).
2143 The expansion @code{$@{var:}@var{offset}@code{[:}@var{length}@code{]@}},
2144 which expands to the substring of @code{var}'s value of length
2145 @var{length}, optionally beginning at @var{offset}, is present
2146 (@pxref{Shell Parameter Expansion}).
2149 @code{$@{var/[/]}@var{pattern}@code{[/}@var{replacement}@code{]@}},
2150 which matches @var{pattern} and replaces it with @var{replacement} in
2151 the value of @code{var}, is available (@pxref{Shell Parameter Expansion}).
2153 Bash has @var{indirect} variable expansion using @code{$@{!word@}}
2154 (@pxref{Shell Parameter Expansion}).
2156 Bash can expand positional parameters beyond @code{$9} using
2157 @code{$@{@var{num}@}}.
2159 Bash has process substitution (@pxref{Process Substitution}).
2161 Bash automatically assigns variables that provide information about the
2162 current user (@code{UID}, @code{EUID}, and @code{GROUPS}), the current host
2163 (@code{HOSTTYPE}, @code{OSTYPE}, @code{MACHTYPE}, and @code{HOSTNAME}),
2164 and the instance of Bash that is running (@code{BASH},
2165 @code{BASH_VERSION}, and @code{BASH_VERSINFO}. @xref{Bash Variables},
2168 The @code{IFS} variable is used to split only the results of expansion,
2169 not all words (@pxref{Word Splitting}).
2170 This closes a longstanding shell security hole.
2172 It is possible to have a variable and a function with the same name;
2173 @code{sh} does not separate the two name spaces.
2175 Bash functions are permitted to have local variables using the
2176 @code{local} builtin, and thus useful recursive functions may be written.
2178 Variable assignments preceding commands affect only that command, even
2179 builtins and functions (@pxref{Environment}).
2180 In @code{sh}, all variable assignments
2181 preceding commands are global unless the command is executed from the
2184 Bash performs filename expansion on filenames specified as operands
2185 to output redirection operators.
2187 Bash contains the @samp{<>} redirection operator, allowing a file to be
2188 opened for both reading and writing, and the @samp{&>} redirection
2189 operator, for directing standard output and standard error to the same
2190 file (@pxref{Redirections}).
2192 The @code{noclobber} option is available to avoid overwriting existing
2193 files with output redirection (@pxref{The Set Builtin}).
2194 The @samp{>|} redirection operator may be used to override @code{noclobber}.
2196 Bash interprets special backslash-escaped characters in the prompt
2197 strings when interactive (@pxref{Printing a Prompt}).
2199 Bash allows you to write a function to override a builtin, and provides
2200 access to that builtin's functionality within the function via the
2201 @code{builtin} and @code{command} builtins (@pxref{Bash Builtins}).
2203 The @code{command} builtin allows selective disabling of functions
2204 when command lookup is performed (@pxref{Bash Builtins}).
2206 Individual builtins may be enabled or disabled using the @code{enable}
2207 builtin (@pxref{Bash Builtins}).
2209 The Bash @code{hash} builtin allows a name to be associated with
2210 an arbitrary filename, even when that filename cannot be found by
2211 searching the @code{$PATH}, using @samp{hash -p}.
2213 Shell functions may be exported to children via the environment
2214 (@pxref{Shell Functions}).
2216 Bash includes a @code{help} builtin for quick reference to shell
2217 facilities (@pxref{Bash Builtins}).
2219 The Bash @code{read} builtin (@pxref{Bash Builtins})
2220 will read a line ending in @samp{\} with
2221 the @samp{-r} option, and will use the @code{REPLY} variable as a
2222 default if no arguments are supplied. The Bash @code{read} builtin
2223 also accepts a prompt string with the @samp{-p} option and will use
2224 Readline to obtain the line when given the @samp{-e} option.
2226 Bash includes the @code{shopt} builtin, for finer control of shell
2227 optional capabilities (@pxref{Bash Builtins}).
2229 Bash has much more optional behavior controllable with the @code{set}
2230 builtin (@pxref{The Set Builtin}).
2232 The @code{disown} builtin can remove a job from the internal shell
2233 job table (@pxref{Job Control Builtins}).
2235 The @code{return} builtin may be used to abort execution of scripts
2236 executed with the @code{.} or @code{source} builtins
2237 (@pxref{Bourne Shell Builtins}).
2239 The @code{test} builtin (@pxref{Bourne Shell Builtins})
2240 is slightly different, as it implements the
2241 @sc{POSIX} 1003.2 algorithm, which specifies the behavior based on the
2242 number of arguments.
2244 The @code{trap} builtin (@pxref{Bourne Shell Builtins})
2245 allows a @code{DEBUG} pseudo-signal specification,
2246 similar to @code{EXIT}. Commands specified with a @code{DEBUG} trap are
2247 executed after every simple command. The @code{DEBUG} trap is not
2248 inherited by shell functions.
2250 The Bash @code{export}, @code{readonly}, and @code{declare} builtins can
2251 take a @samp{-f} option to act on shell functions, a @samp{-p} option to
2252 display variables with various attributes set in a format that can be
2253 used as shell input, a @samp{-n} option to remove various variable
2254 attributes, and @samp{name=value} arguments to set variable attributes
2255 and values simultaneously.
2257 The Bash @code{cd} and @code{pwd} builtins (@pxref{Bourne Shell Builtins})
2258 each take @samp{-L} and @samp{-P} builtins to switch between logical and
2261 The Bash @code{type} builtin is more extensive and gives more information
2262 about the names it finds (@pxref{Bash Builtins}).
2264 Bash implements a @code{csh}-like directory stack, and provides the
2265 @code{pushd}, @code{popd}, and @code{dirs} builtins to manipulate it
2266 (@pxref{C Shell Builtins}).
2267 Bash also makes the directory stack visible as the value of the
2268 @code{DIRSTACK} shell variable.
2270 The Bash restricted mode is more useful (@pxref{The Restricted Shell});
2271 the @sc{SVR4.2} shell restricted mode is too limited.
2273 Bash has the @code{time} reserved word and command timing (@pxref{Pipelines}).
2274 The display of the timing statistics may be controlled with the
2275 @code{TIMEFORMAT} variable.
2277 The @sc{SVR4.2} shell has two privilege-related builtins
2278 (@code{mldmode} and @code{priv}) not present in Bash.
2280 Bash does not have the @code{stop} or @code{newgrp} builtins.
2282 Bash does not use the @code{SHACCT} variable or perform shell accounting.
2284 The @sc{SVR4.2} @code{sh} uses a @code{TIMEOUT} variable like Bash uses
2287 More features unique to Bash may be found in
2288 @ref{Bash Features}.
2290 @subsection Implementation Differences From The SVR4.2 Shell
2292 Since Bash is a completely new implementation, it does not suffer from
2293 many of the limitations of the @sc{SVR4.2} shell. For instance:
2298 Bash does not fork a subshell when redirecting into or out of
2299 a shell control structure such as an @code{if} or @code{while}
2303 Bash does not allow unbalanced quotes. The @sc{SVR4.2} shell will silently
2304 insert a needed closing quote at @code{EOF} under certain circumstances.
2305 This can be the cause of some hard-to-find errors.
2308 The @sc{SVR4.2} shell uses a baroque memory management scheme based on
2309 trapping @code{SIGSEGV}. If the shell is started from a process with
2310 @code{SIGSEGV} blocked (e.g., by using the @code{system()} C library
2311 function call), the shell misbehaves badly.
2314 In a questionable attempt at security, the @sc{SVR4.2} shell,
2315 when invoked without the @samp{-p} option, will alter its real
2316 and effective @sc{UID} and @sc{GID} if they are less than some
2317 magic threshold value, commonly 100.
2318 This can lead to unexpected results.
2321 The @sc{SVR4.2} shell does not allow users to trap @code{SIGALRM} or
2325 For some reason, the @sc{SVR4.2} shell does not allow the @code{MAILCHECK}
2326 variable to be unset.
2329 The @sc{SVR4.2} shell treats @samp{^} as the undocumented equivalent of
2333 Bash allows multiple option arguments when it is invoked (@code{-x -v});
2334 the @sc{SVR4.2} shell allows only one option argument (@code{-xv}). In
2335 fact, some versions of the shell dump core if the second argument begins
2339 The @sc{SVR4.2} shell exits a script if any builtin fails; Bash exits
2340 a script only if one of the @sc{POSIX.2} special builtins fails, and
2341 only for certain failures, as enumerated in the @sc{POSIX.2} standard.
2344 The @sc{SVR4.2} shell behaves differently when invoked as @code{jsh}
2345 (it turns on job control).
2349 @chapter C-Shell Style Features
2351 The C-Shell (@dfn{@code{csh}}) was created by Bill Joy at The
2352 University of California at Berkeley. It
2353 is generally considered to have better features for interactive use than
2354 the original Bourne shell. Some of the @code{csh} features present in
2355 Bash include job control, history expansion, `protected' redirection, and
2356 several variables to control the interactive behaviour of the shell
2357 (e.g., @code{IGNOREEOF}).
2359 @xref{Using History Interactively}, for details on history expansion.
2362 * Brace Expansion:: Expansion of expressions within braces.
2363 * Tilde Expansion:: Expansion of the ~ character.
2364 * C Shell Builtins:: Builtin commands adopted from the C Shell.
2365 * C Shell Variables:: Variables which Bash uses in essentially
2366 the same way as the C Shell.
2369 @node Brace Expansion
2370 @section Brace Expansion
2371 @cindex brace expansion
2372 @cindex expansion, brace
2375 is a mechanism by which arbitrary strings
2376 may be generated. This mechanism is similar to
2377 @var{filename expansion} (@pxref{Filename Expansion}),
2378 but the file names generated
2379 need not exist. Patterns to be brace expanded take
2380 the form of an optional @var{preamble},
2381 followed by a series of comma-separated strings
2382 between a pair of braces, followed by an optional @var{postamble}.
2383 The preamble is prepended to each string contained
2384 within the braces, and the postamble is then appended
2385 to each resulting string, expanding left to right.
2387 Brace expansions may be nested. The results of each expanded
2388 string are not sorted; left to right order is preserved.
2391 bash$ echo a@{d,c,b@}e
2395 Brace expansion is performed before any other expansions,
2396 and any characters special to other expansions are preserved
2397 in the result. It is strictly textual. Bash
2398 does not apply any syntactic interpretation to the context of the
2399 expansion or the text between the braces.
2401 A correctly-formed brace expansion must contain unquoted opening
2402 and closing braces, and at least one unquoted comma.
2403 Any incorrectly formed brace expansion is left unchanged.
2405 This construct is typically used as shorthand when the common
2406 prefix of the strings to be generated is longer than in the
2409 mkdir /usr/local/src/bash/@{old,new,dist,bugs@}
2413 chown root /usr/@{ucb/@{ex,edit@},lib/@{ex?.?*,how_ex@}@}
2416 @node Tilde Expansion
2417 @section Tilde Expansion
2418 @cindex tilde expansion
2419 @cindex expansion, tilde
2421 Bash has tilde (~) expansion, similar, but not identical, to that of
2422 @code{csh}. The following table shows what unquoted words beginning
2423 with a tilde expand to.
2427 The current value of @code{$HOME}.
2432 The subdirectory @code{foo} of the home directory of the user
2442 Bash will also tilde expand words following redirection operators
2443 and words following @samp{=} in assignment statements.
2445 @node C Shell Builtins
2446 @section C Shell Builtins
2448 Bash has several builtin commands whose definition is very similar
2455 pushd [@var{dir} | @var{+N} | @var{-N}] [-n]
2458 Save the current directory on a list and then @code{cd} to
2460 arguments, exchanges the top two directories.
2464 Brings the @var{N}th directory (counting from the left of the
2465 list printed by @code{dirs}, starting with zero) to the top of
2466 the list by rotating the stack.
2468 Brings the @var{N}th directory (counting from the right of the
2469 list printed by @code{dirs}, starting with zero) to the top of
2470 the list by rotating the stack.
2472 Suppresses the normal change of directory when adding directories
2473 to the stack, so that only the stack is manipulated.
2475 Makes the current working directory be the top of the stack, and then
2476 @code{cd}s to @var{dir}. You can see the saved directory list
2477 with the @code{dirs} command.
2483 popd [+@var{N} | -@var{N}] [-n]
2486 Pop the directory stack, and @code{cd} to the new top directory. When
2487 no arguments are given, @code{popd}
2488 removes the top directory from the stack and
2489 performs a @code{cd} to the new top directory. The
2490 elements are numbered from 0 starting at the first directory listed with
2491 @code{dirs}; i.e., @code{popd} is equivalent to @code{popd +0}.
2494 Removes the @var{N}th directory (counting from the left of the
2495 list printed by @code{dirs}), starting with zero.
2497 Removes the @var{N}th directory (counting from the right of the
2498 list printed by @code{dirs}), starting with zero.
2500 Suppresses the normal change of directory when removing directories
2501 from the stack, so that only the stack is manipulated.
2507 dirs [+@var{N} | -@var{N}] [-clvp]
2509 Display the list of currently remembered directories. Directories
2510 find their way onto the list with the @code{pushd} command; you can get
2511 back up through the list with the @code{popd} command.
2514 Displays the @var{N}th directory (counting from the left of the
2515 list printed by @code{dirs} when invoked without options), starting
2518 Displays the @var{N}th directory (counting from the right of the
2519 list printed by @code{dirs} when invoked without options), starting
2522 Clears the directory stack by deleting all of the elements.
2524 Produces a longer listing; the default listing format uses a
2525 tilde to denote the home directory.
2527 Causes @code{dirs} to print the directory stack with one entry per
2530 Causes @code{dirs} to print the directory stack with one entry per
2531 line, prepending each entry with its index in the stack.
2537 history [-c] [@var{n}]
2538 history [-anrw] [@var{filename}]
2539 history -ps @var{arg}
2542 Display the history list with line numbers. Lines prefixed with
2543 with a @samp{*} have been modified. An argument of @var{n} says
2544 to list only the last @var{n} lines. Options, if supplied, have
2545 the following meanings:
2549 Write out the current history to the history file.
2552 Read the current history file and append its contents to
2557 history lines (history lines entered since the beginning of the
2558 current Bash session) to the history file.
2561 Append the history lines not already read from the history file
2562 to the current history list. These are lines appended to the history
2563 file since the beginning of the current Bash session.
2566 Clear the history list. This may be combined
2567 with the other options to replace the history list completely.
2570 The @var{arg}s are added to the end of
2571 the history list as a single entry.
2574 Perform history substitution on the @var{arg}s and display the result
2575 on the standard output, without storing the results in the history list.
2578 When the @samp{-w}, @samp{-r}, @samp{-a}, or @samp{-n} option is
2579 used, if @var{filename}
2580 is given, then it is used as the history file. If not, then
2581 the value of the @code{HISTFILE} variable is used.
2589 A synonym for @code{.} (@pxref{Bourne Shell Builtins}).
2593 @node C Shell Variables
2594 @section C Shell Variables
2599 If this variable is set, its value is used the number of consecutive
2600 @code{EOF}s Bash will read before exiting. By default, Bash will exit
2601 upon reading a single @code{EOF}. If @code{IGNOREEOF} is not set to
2602 a numeric value, Bash acts as if its value were 10.
2606 @node Korn Shell Features
2607 @chapter Korn Shell Style Features
2609 This section describes features primarily inspired by the
2610 Korn Shell (@code{ksh}). In some cases, the @sc{POSIX} 1003.2
2611 standard has adopted these commands and variables from the
2612 Korn Shell; Bash implements those features using the @sc{POSIX}
2613 standard as a guide.
2616 * Korn Shell Constructs:: Shell grammar constructs adopted from the
2618 * Korn Shell Builtins:: Builtin commands adopted from the Korn Shell.
2619 * Korn Shell Variables:: Variables which Bash uses in essentially
2620 the same way as the Korn Shell.
2621 * Aliases:: Substituting one command for another.
2624 @node Korn Shell Constructs
2625 @section Korn Shell Constructs
2627 Bash includes the Korn Shell @code{select} construct. This construct
2628 allows the easy generation of menus. It has almost the same syntax as
2629 the @code{for} command.
2631 The syntax of the @code{select} command is:
2634 select @var{name} [in @var{words} @dots{}]; do @var{commands}; done
2637 The list of words following @code{in} is expanded, generating a list
2638 of items. The set of expanded words is printed on the standard
2639 error, each preceded by a number. If the @samp{in @var{words}}
2640 is omitted, the positional parameters are printed. The
2641 @code{PS3} prompt is then displayed and a line is read from the standard
2642 input. If the line consists of a number corresponding to one of
2643 the displayed words, then the value of @var{name}
2644 is set to that word. If the line is empty, the words and prompt
2645 are displayed again. If @code{EOF} is read, the @code{select}
2646 command completes. Any other value read causes @var{name}
2647 to be set to null. The line read is saved in the variable
2650 The @var{commands} are executed after each selection until a
2651 @code{break} or @code{return} command is executed, at which
2652 point the @code{select} command completes.
2654 Bash also has adopted command timing from the Korn shell. If the
2655 @code{time} reserved word precedes a pipeline, which may consist
2656 of a single command, timing statistics for the pipeline are displayed
2658 The statistics currently consist of elapsed (wall-clock) time and
2659 user and system time consumed by the command's execution.
2661 The use of @code{time} as a reserved word permits the timing of
2662 shell builtins, shell functions, and pipelines. An external
2663 @code{time} command cannot time these easily.
2665 @node Korn Shell Builtins
2666 @section Korn Shell Builtins
2668 This section describes Bash builtin commands taken from @code{ksh}.
2675 @code{fc [-e @var{ename}] [-nlr] [@var{first}] [@var{last}]}
2676 @code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
2679 Fix Command. In the first form, a range of commands from @var{first} to
2680 @var{last} is selected from the history list. Both @var{first} and
2681 @var{last} may be specified as a string (to locate the most recent
2682 command beginning with that string) or as a number (an index into the
2683 history list, where a negative number is used as an offset from the
2684 current command number). If @var{last} is not specified it is set to
2685 @var{first}. If @var{first} is not specified it is set to the previous
2686 command for editing and @minus{}16 for listing. If the @samp{-l} flag is
2687 given, the commands are listed on standard output. The @samp{-n} flag
2688 suppresses the command numbers when listing. The @samp{-r} flag
2689 reverses the order of the listing. Otherwise, the editor given by
2690 @var{ename} is invoked on a file containing those commands. If
2691 @var{ename} is not given, the value of the following variable expansion
2692 is used: @code{$@{FCEDIT:-$@{EDITOR:-vi@}@}}. This says to use the
2693 value of the @code{FCEDIT} variable if set, or the value of the
2694 @code{EDITOR} variable if that is set, or @code{vi} if neither is set.
2695 When editing is complete, the edited commands are echoed and executed.
2697 In the second form, @var{command} is re-executed after each instance
2698 of @var{pat} in the selected command is replaced by @var{rep}.
2700 A useful alias to use with the @code{fc} command is @code{r='fc -s'}, so
2701 that typing @samp{r cc} runs the last command beginning with @code{cc}
2702 and typing @samp{r} re-executes the last command (@pxref{Aliases}).
2706 The @code{let} builtin allows arithmetic to be performed on shell variables.
2707 For details, refer to @ref{Arithmetic Builtins}.
2711 The @code{typeset} command is supplied for compatibility with the Korn
2712 shell; however, it has been deprecated in favor of the
2713 @code{declare} command (@pxref{Bash Builtins}).
2717 @node Korn Shell Variables
2718 @section Korn Shell Variables
2723 The default variable for the @code{read} builtin.
2726 Each time this parameter is referenced, a random integer
2727 between 0 and 32767 is generated. Assigning a value to this
2728 variable seeds the random number generator.
2731 This variable expands to the number of seconds since the
2732 shell was started. Assignment to this variable resets
2733 the count to the value assigned, and the expanded value
2734 becomes the value assigned plus the number of seconds
2735 since the assignment.
2738 The value of this variable is used as the prompt for the
2739 @code{select} command. If this variable is not set, the
2740 @code{select} command prompts with @samp{#? }
2743 This is the prompt printed before the command line is echoed
2744 when the @samp{-x} option is set (@pxref{The Set Builtin}).
2745 The default is @samp{+ }.
2748 The current working directory as set by the @code{cd} builtin.
2751 The previous working directory as set by the @code{cd} builtin.
2754 If set to a value greater than zero, the value is interpreted as
2755 the number of seconds to wait for input after issuing the primary
2757 Bash terminates after that number of seconds if input does
2761 The line number in the script or shell function currently executing.
2764 The editor used as a default by the @code{fc} builtin command.
2770 @cindex alias expansion
2773 * Alias Builtins:: Builtins commands to maniuplate aliases.
2776 The shell maintains a list of @var{aliases}
2777 that may be set and unset with the @code{alias} and
2778 @code{unalias} builtin commands.
2780 The first word of each command, if unquoted,
2781 is checked to see if it has an
2782 alias. If so, that word is replaced by the text of the alias.
2783 The alias name and the replacement text may contain any valid
2784 shell input, including shell metacharacters, with the exception
2785 that the alias name may not contain @key{=}.
2786 The first word of the replacement text is tested for
2787 aliases, but a word that is identical to an alias being expanded
2788 is not expanded a second time. This means that one may alias
2789 @code{ls} to @code{"ls -F"},
2790 for instance, and Bash does not try to recursively expand the
2791 replacement text. If the last character of the alias value is a
2792 space or tab character, then the next command word following the
2793 alias is also checked for alias expansion.
2795 Aliases are created and listed with the @code{alias}
2796 command, and removed with the @code{unalias} command.
2798 There is no mechanism for using arguments in the replacement text,
2800 If arguments are needed, a shell function should be used
2801 (@pxref{Shell Functions}).
2803 Aliases are not expanded when the shell is not interactive,
2804 unless the @code{expand_aliases} shell option is set using
2805 @code{shopt} (@pxref{Bash Builtins}).
2807 The rules concerning the definition and use of aliases are
2808 somewhat confusing. Bash
2809 always reads at least one complete line
2810 of input before executing any
2811 of the commands on that line. Aliases are expanded when a
2812 command is read, not when it is executed. Therefore, an
2813 alias definition appearing on the same line as another
2814 command does not take effect until the next line of input is read.
2815 The commands following the alias definition
2816 on that line are not affected by the new alias.
2817 This behavior is also an issue when functions are executed.
2818 Aliases are expanded when the function definition is read,
2819 not when the function is executed, because a function definition
2820 is itself a compound command. As a consequence, aliases
2821 defined in a function are not available until after that
2822 function is executed. To be safe, always put
2823 alias definitions on a separate line, and do not use @code{alias}
2824 in compound commands.
2826 Note that for almost every purpose, aliases are superseded by
2829 @node Alias Builtins
2830 @subsection Alias Builtins
2837 alias [@code{-p}] [@var{name}[=@var{value}] @dots{}]
2840 Without arguments or with the @samp{-p} option, @code{alias} prints
2841 the list of aliases on the standard output in a form that allows
2842 them to be reused as input.
2843 If arguments are supplied, an alias is defined for each @var{name}
2844 whose @var{value} is given. If no @var{value} is given, the name
2845 and value of the alias is printed.
2850 unalias [-a] [@var{name} @dots{} ]
2853 Remove each @var{name} from the list of aliases. If @samp{-a} is
2854 supplied, all aliases are removed.
2858 @chapter Bash Features
2860 This section describes features unique to Bash.
2863 * Invoking Bash:: Command line options that you can give
2865 * Bash Startup Files:: When and how Bash executes scripts.
2866 * Is This Shell Interactive?:: Determining the state of a running Bash.
2867 * Bash Builtins:: Table of builtins specific to Bash.
2868 * The Set Builtin:: This builtin is so overloaded it
2869 deserves its own section.
2870 * Bash Conditional Expressions:: Primitives used in composing expressions for
2871 the @code{test} builtin.
2872 * Bash Variables:: List of variables that exist in Bash.
2873 * Shell Arithmetic:: Arithmetic on shell variables.
2874 * Arrays:: Array Variables
2875 * Printing a Prompt:: Controlling the PS1 string.
2876 * The Restricted Shell:: A more controlled mode of shell execution.
2877 * Bash POSIX Mode:: Making Bash behave more closely to what
2878 the POSIX standard specifies.
2882 @section Invoking Bash
2885 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o @var{option}] [@var{argument} @dots{}]
2886 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o @var{option}] -c @var{string} [@var{argument} @dots{}]
2887 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o @var{option}] [@var{argument} @dots{}]
2890 In addition to the single-character shell command-line options
2891 (@pxref{The Set Builtin}), there are several multi-character
2892 options that you can use. These options must appear on the command
2893 line before the single-character options in order for them
2897 @item --dump-strings
2898 Equivalent to @samp{-D}.
2901 Display a usage message on standard output and exit sucessfully.
2904 Make this shell act as if it were directly invoked by login.
2905 This is equivalent to @samp{exec -l bash} but can be issued from
2906 another shell, such as @code{csh}. If you wanted to replace your
2907 current login shell with a Bash login shell, you would say
2908 @samp{exec bash --login}.
2911 Do not use the @sc{GNU} Readline library (@pxref{Command Line Editing})
2912 to read interactive command lines.
2915 Don't load the system-wide startup file @file{/etc/profile}
2916 or any of the personal initialization files
2917 @file{~/.bash_profile}, @file{~/.bash_login}, or @file{~/.profile}
2918 when Bash is invoked as a login shell.
2921 Don't read the @file{~/.bashrc} initialization file in an
2922 interactive shell. This is on by default if the shell is
2923 invoked as @code{sh}.
2926 Change the behavior of Bash where the default operation differs
2927 from the @sc{POSIX} 1003.2 standard to match the standard. This
2928 is intended to make Bash behave as a strict superset of that
2929 standard. @xref{Bash POSIX Mode}, for a description of the Bash
2932 @item --rcfile @var{filename}
2933 Execute commands from @var{filename} (instead of @file{~/.bashrc})
2934 in an interactive shell.
2937 Make the shell a restricted shell (@pxref{The Restricted Shell}).
2940 Equivalent to @samp{-v}.
2943 Show version information for this instance of
2944 Bash on the standard output and exit successfully.
2948 There are several single-character options you can give which are
2949 not available with the @code{set} builtin.
2952 @item -c @var{string}
2953 Read and execute commands from @var{string} after processing the
2954 options, then exit. Any remaining arguments are assigned to the
2955 positional parameters, starting with @code{$0}.
2958 Force the shell to run interactively.
2961 Make the shell restricted.
2964 If this flag is present, or if no arguments remain after option
2965 processing, then commands are read from the standard input.
2966 This option allows the positional parameters to be set
2967 when invoking an interactive shell.
2970 A list of all double-quoted strings preceded by @samp{$}
2971 is printed on the standard ouput.
2972 These are the strings that
2973 are subject to language translation when the current locale
2974 is not @code{C} or @code{POSIX} (@pxref{Locale Translation}).
2975 This implies the @samp{-n} option; no commands will be executed.
2979 @cindex interactive shell
2980 An @emph{interactive} shell is one whose input and output are both
2981 connected to terminals (as determined by @code{isatty()}), or one
2982 started with the @samp{-i} option.
2984 If arguments remain after option processing, and neither the
2985 @samp{-c} nor the @samp{-s}
2986 option has been supplied, the first argument is assumed to
2987 be the name of a file containing shell commands (@pxref{Shell Scripts}).
2988 When Bash is invoked in this fashion, @code{$0}
2989 is set to the name of the file, and the positional parameters
2990 are set to the remaining arguments.
2991 Bash reads and executes commands from this file, then exits.
2992 Bash's exit status is the exit status of the last command executed
2993 in the script. If no commands are executed, the exit status is 0.
2995 @node Bash Startup Files
2996 @section Bash Startup Files
2997 @cindex startup files
2999 This section describs how Bash executes its startup files.
3000 If any of the files exist but cannot be read, Bash reports an error.
3001 Tildes are expanded in file names as described above under
3002 Tilde Expansion (@pxref{Tilde Expansion}).
3004 When Bash is invoked as an interactive login shell, it first reads and
3005 executes commands from the file @file{/etc/profile}, if that file exists.
3006 After reading that file, it looks for @file{~/.bash_profile},
3007 @file{~/.bash_login}, and @file{~/.profile}, in that order, and reads
3008 and executes commands from the first one that exists and is readable.
3009 The @samp{--noprofile} option may be used when the shell is started to
3010 inhibit this behavior.
3012 When a login shell exits, Bash reads and executes commands from
3013 the file @file{~/.bash_logout}, if it exists.
3015 When an interactive shell that is not a login shell is started, Bash
3016 reads and executes commands from @file{~/.bashrc}, if that file exists.
3017 This may be inhibited by using the @samp{--norc} option.
3018 The @samp{--rcfile @var{file}} option will force Bash to read and
3019 execute commands from @var{file} instead of @file{~/.bashrc}.
3021 So, typically, your @file{~/.bash_profile} contains the line
3023 @code{if [ -f @file{~/.bashrc} ]; then . @file{~/.bashrc}; fi}
3026 after (or before) any login-specific initializations.
3028 When Bash is started non-interactively, to run a shell script,
3029 for example, it looks for the variable @code{BASH_ENV} in the environment,
3030 expands its value if it appears there, and uses the expanded value as
3031 the name of a file to read and execute. Bash behaves as if the
3032 following command were executed:
3034 @code{if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi}
3037 but the value of the @code{PATH} variable is not used to search for the
3040 If Bash is invoked with the name @code{sh}, it tries to mimic the
3041 startup behavior of historical versions of @code{sh} as closely as
3042 possible, while conforming to the @sc{POSIX} standard as well.
3044 When invoked as a login shell, it first attempts to read and execute
3045 commands from @file{/etc/profile} and @file{~/.profile}, in that order.
3046 The @samp{--noprofile} option may be used to inhibit this behavior.
3047 When invoked as an interactive shell with the name @code{sh},
3048 @code{bash} looks for the variable @code{ENV},
3049 expands its value if it is defined, and uses the
3050 expanded value as the name of a file to read and execute.
3051 Since a shell invoked as @code{sh} does not attempt to read and execute
3052 commands from any other startup files, the @samp{--rcfile} option has
3054 A non-interactive shell invoked with the name @code{sh} does not attempt
3055 to read any startup files.
3057 When invoked as @code{sh}, Bash enters @sc{POSIX} mode after
3058 the startup files are read.
3060 When Bash is started in @sc{POSIX} mode, as with the
3061 @samp{--posix} command line option, it follows the @sc{POSIX} standard
3063 In this mode, the @code{ENV} variable is expanded and commands are read
3064 and executed from the file whose name is the expanded value.
3065 No other startup files are read.
3066 This is done by interactive shells only.
3068 Bash attempts to determine when it is being run by the remote shell
3069 daemon, usually @code{rshd}. If Bash determines it is being run by
3070 rshd, it reads and executes commands from @file{~/.bashrc}, if that
3071 file exists and is readable.
3072 It will not do this if invoked as @code{sh}.
3073 The @samp{--norc} option may be used to inhibit this behavior, and the
3074 @samp{--rcfile} option may be used to force another file to be read, but
3075 rshd does not generally invoke the shell with those options or allow
3076 them to be specified.
3078 @node Is This Shell Interactive?
3079 @section Is This Shell Interactive?
3080 @cindex interactive shell
3082 As defined in @ref{Invoking Bash}, an interactive shell
3083 is one whose input and output are both
3084 connected to terminals (as determined by @code{isatty(3)}),
3085 or one started with the @samp{-i} option.
3087 You may wish to determine within a startup script whether Bash is
3088 running interactively or not. To do this, examine the variable
3089 @code{$PS1}; it is unset in non-interactive shells, and set in
3090 interactive shells. Thus:
3093 if [ -z "$PS1" ]; then
3094 echo This shell is not interactive
3096 echo This shell is interactive
3100 Alternatively, you may test the value of the @samp{-} special parameter.
3101 It contains @code{i} when the shell is interactive. For example:
3105 *i*) echo This shell is interactive ;;
3106 *) echo This shell is not interactive ;;
3111 @section Bash Builtin Commands
3113 This section describes builtin commands which are unique to
3114 or have been extended in Bash.
3121 bind [-m @var{keymap}] [-lpsvPSV] [-q @var{name}] [-r @var{keyseq}]
3122 bind [-m @var{keymap}] -f @var{filename}
3123 bind [-m @var{keymap}] @var{keyseq:function-name}
3126 Display current Readline (@pxref{Command Line Editing})
3127 key and function bindings, or
3128 bind a key sequence to a Readline function or macro. The
3129 binding syntax accepted is identical to that of
3130 @file{.inputrc} (@pxref{Readline Init File}),
3131 but each binding must be passed as a separate argument: e.g.,
3132 @samp{"\C-x\C-r":re-read-init-file}.
3133 Options, if supplied, have the following meanings:
3136 @item -m @var{keymap}
3137 Use @var{keymap} as the keymap to be affected by
3138 the subsequent bindings. Acceptable @var{keymap}
3141 @code{emacs-standard},
3145 @code{vi-command}, and
3147 @code{vi} is equivalent to @code{vi-command};
3148 @code{emacs} is equivalent to @code{emacs-standard}.
3151 List the names of all Readline functions
3154 Display Readline function names and bindings in such a way that they
3158 List current Readline function names and bindings
3161 Display Readline variable names and values in such a way that they
3165 List current Readline variable names and values
3168 Display Readline key sequences bound to macros and the strings they output
3169 in such a way that they can be re-read
3172 Display Readline key sequences bound to macros and the strings they output
3174 @item -f @var{filename}
3175 Read key bindings from @var{filename}
3178 Query about which keys invoke the named @var{function}
3180 @item -r @var{keyseq}
3181 Remove any current binding for @var{keyseq}
3188 builtin [@var{shell-builtin} [@var{args}]]
3190 Run a shell builtin. This is useful when you wish to define a
3191 shell function with the same name as a shell builtin, but need the
3192 functionality of the builtin within the function itself.
3197 command [-pVv] @var{command} [@var{args} @dots{}]
3199 Runs @var{command} with @var{arg} ignoring shell functions. If
3200 you have a shell function called @code{ls}, and you wish to call
3201 the command @code{ls}, you can say @samp{command ls}. The
3202 @samp{-p} option means to use a default value for @code{$PATH}
3203 that is guaranteed to find all of the standard utilities.
3205 If either the @samp{-V} or @samp{-v} option is supplied, a
3206 description of @var{command} is printed. The @samp{-v} option
3207 causes a single word indicating the command or file name used to
3208 invoke @var{command} to be printed; the @samp{-V} option produces
3209 a more verbose description.
3214 declare [-afFrxi] [-p] [@var{name}[=@var{value}]]
3217 Declare variables and give them attributes. If no @var{name}s
3218 are given, then display the values of variables instead.
3220 The @samp{-p} option will display the attributes and values of each
3221 @var{name}. When @samp{-p} is used, additional options are ignored.
3222 The @samp{-F} option inhibits the display of function definitions;
3223 only the function name and attributes are printed. @samp{-F} implies
3224 @samp{-f}. The following options can be used to restrict output
3225 to variables with the specified attributes or to give variables
3230 Each @var{name} is an array variable (@pxref{Arrays}).
3233 Use function names only.
3236 The variable is to be treated as
3237 an integer; arithmetic evaluation (@pxref{Shell Arithmetic}) is
3238 performed when the variable is assigned a value.
3241 Make @var{name}s readonly. These names cannot then be assigned values
3242 by subsequent assignment statements.
3245 Mark each @var{name} for export to subsequent commands via
3250 instead of @samp{-} turns off the attribute instead. When used in
3251 a function, @code{declare} makes each @var{name} local, as with the
3252 @code{local} command.
3257 echo [-neE] [arg @dots{}]
3259 Output the @code{arg}s, separated by spaces, terminated with a
3260 newline. The return status is always 0. If @samp{-n} is
3261 specified, the trailing newline is suppressed. If the @samp{-e}
3262 option is given, interpretation of the following backslash-escaped
3263 characters is enabled. The @samp{-E} option disables the interpretation
3264 of these escape characters, even on systems where they are interpreted
3266 @code{echo} interprets the following escape sequences:
3273 suppress trailing newline
3289 the character whose ASCII code is @code{nnn} (octal)
3295 enable [-n] [-p] [-f @var{filename}] [-ads] [@var{name} @dots{}]
3297 Enable and disable builtin shell commands. This allows you to
3298 use a disk command which has the same name as a shell builtin.
3299 If @samp{-n} is used, the @var{name}s become disabled. Otherwise
3300 @var{name}s are enabled. For example, to use the @code{test} binary
3301 found via @code{$PATH} instead of the shell builtin version, type
3302 @samp{enable -n test}.
3304 If the @samp{-p} option is supplied, or no @var{name} arguments appear,
3305 a list of shell builtins is printed. With no other arguments, the list
3306 consists of all enabled shell builtins.
3307 The @samp{-a} option means to list
3308 each builtin with an indication of whether or not it is enabled.
3310 The @samp{-f} option means to load the new builtin command @var{name}
3311 from shared object @var{filename}, on systems that support dynamic loading.
3312 The @samp{-d} option will delete a builtin loaded with @samp{-f}.
3313 If there are no options, a list of the shell builtins is displayed.
3314 The @samp{-s} option restricts @code{enable} to the @sc{POSIX.2} special
3315 builtins. If @samp{-s} is used with @samp{-f}, the new builtin becomes
3321 help [@var{pattern}]
3323 Display helpful information about builtin commands. If
3324 @var{pattern} is specified, @code{help} gives detailed help
3325 on all commands matching @var{pattern}, otherwise a list of
3326 the builtins is printed.
3331 local @var{name}[=@var{value}]
3333 For each argument, create a local variable called @var{name}, and
3334 give it @var{value}.
3335 @code{local} can only be used within a function; it makes the variable
3336 @var{name} have a visible scope restricted to that function and its
3344 Exit a login shell, returning a status of @var{n} to the shell's
3350 read [-a @var{aname}] [-p @var{prompt}] [-er] [@var{name} @dots{}]
3352 One line is read from the standard input, and the first word
3353 is assigned to the first
3354 @var{name}, the second word to the second @var{name},
3355 and so on, with leftover words assigned to the last @var{name}.
3356 Only the characters in the value of the @code{IFS} variable
3357 are recognized as word delimiters. If no names
3358 are supplied, the line read is assigned to the variable @code{REPLY}.
3359 The return code is zero, unless end-of-file is encountered. Options,
3360 if supplied, have the following meanings:
3364 If this option is given, a backslash-newline pair is not ignored, and
3365 the backslash is considered to be part of the line.
3367 @item -p @var{prompt}
3368 Display @code{prompt}, without a
3369 trailing newline, before attempting to read any input. The prompt
3370 is displayed only if input is coming from a terminal.
3372 @item -a @var{aname}
3373 The words are assigned to
3374 sequential indices of the array variable @var{aname}, starting at 0.
3377 Readline (@pxref{Command Line Editing})
3378 is used to obtain the line.
3384 shopt [-pqsu] [-o] [@var{optname} @dots{}]
3386 Toggle the values of variables controlling optional shell behavior.
3387 With no options, or with the @samp{-p}
3388 option, a list of all settable options is displayed, with
3389 an indication of whether or not each is set. Other options have
3390 the following meanings:
3394 Enable (set) each @var{optname}
3397 Disable (unset) each @var{optname}.
3400 Suppresses normal output; the return status
3401 indicates whether the @var{optname} is set or unset.
3402 If multiple @var{optname} arguments are given with @samp{-q},
3403 the return status is zero if all @var{optnames} are enabled;
3407 Restricts the values of
3408 @var{optname} to be those defined for the @samp{-o} option to the
3409 @code{set} builtin (@pxref{The Set Builtin}).
3413 @samp{-s} or @samp{-u}
3414 is used with no @var{optname} arguments, the display is limited to
3415 those options which are set or unset, respectively.
3417 Unless otherwise noted, the @code{shopt} options are disabled (off)
3420 The return status when listing options is zero if all @var{optnames}
3421 are enabled, non-zero otherwise. When setting or unsetting options,
3422 the return status is zero unless an @var{optname} is not a legal shell
3425 The list of @code{shopt} options is:
3428 If this is set, an argument to the @code{cd}
3429 builtin command that
3430 is not a directory is assumed to be the name of a variable whose
3431 value is the directory to change to.
3434 If set, minor errors in the spelling of a directory component in a
3435 @code{cd} command will be corrected.
3436 The errors checked for are transposed characters,
3437 a missing character, and a character too many.
3438 If a correction is found, the corrected path is printed,
3439 and the command proceeds.
3440 This option is only used by interactive shells.
3443 If this is set, Bash checks that a command found in the hash
3444 table exists before trying to execute it. If a hashed command no
3445 longer exists, a normal path search is performed.
3448 If set, Bash checks the window size after each command
3449 and, if necessary, updates the values of
3450 @code{LINES} and @code{COLUMNS}.
3454 attempts to save all lines of a multiple-line
3455 command in the same history entry. This allows
3456 easy re-editing of multi-line commands.
3459 If set, Bash includes filenames beginning with a `.' in
3460 the results of filename expansion.
3463 If this is set, a non-interactive shell will not exit if
3464 it cannot execute the file specified as an argument to the @code{exec}
3465 builtin command. An interactive shell does not exit if @code{exec}
3469 If set, the history list is appended to the file named by the value
3470 of the @code{HISTFILE}
3471 variable when the shell exits, rather than overwriting the file.
3474 If set, and Readline
3475 is being used, a user is given the opportunity to re-edit a
3476 failed history substitution.
3479 If set, and Readline
3480 is being used, the results of history substitution are not immediately
3481 passed to the shell parser. Instead, the resulting line is loaded into
3482 the Readline editing buffer, allowing further modification.
3485 If set, and Readline is being used, Bash will attempt to perform
3486 hostname completion when a word beginning with @samp{@@} is being
3487 completed (@pxref{Commands For Completion}). This option is enabled
3490 @item interactive_comments
3491 Allow a word beginning with @samp{#}
3492 to cause that word and all remaining characters on that
3493 line to be ignored in an interactive shell.
3494 This option is enabled by default.
3497 If enabled, and the @code{cmdhist}
3498 option is enabled, multi-line commands are saved to the history with
3499 embedded newlines rather than using semicolon separators where possible.
3502 If set, and a file that Bash is checking for mail has been
3503 accessed since the last time it was checked, the message
3504 @code{"The mail in @var{mailfile} has been read"} is displayed.
3507 If set, Bash allows filename patterns which match no
3508 files to expand to a null string, rather than themselves.
3511 If set, prompt strings undergo variable and parameter expansion after
3512 being expanded (@pxref{Printing a Prompt}).
3513 This option is enabled by default.
3516 If this is set, the @code{shift}
3517 builtin prints an error message when the shift count exceeds the
3518 number of positional parameters.
3521 If set, the @code{source} builtin uses the value of @code{PATH}
3522 to find the directory containing the file supplied as an argument.
3523 This is enabled by default.
3529 type [-all] [-type | -path] [@var{name} @dots{}]
3531 For each @var{name}, indicate how it would be interpreted if used as a
3534 If the @samp{-type} flag is used, @code{type} returns a single word
3535 which is one of @samp{alias}, @samp{function}, @samp{builtin},
3536 @samp{file} or @samp{keyword},
3537 if @var{name} is an alias, shell function, shell builtin,
3538 disk file, or shell reserved word, respectively.
3539 If the @var{name} is not found, then nothing is printed, and
3540 @code{type} returns a failure status.
3542 If the @samp{-path} flag is used, @code{type} either returns the name
3543 of the disk file that would be executed, or nothing if @samp{-type}
3544 would not return @samp{file}.
3546 If the @samp{-all} flag is used, returns all of the places that contain
3547 an executable named @var{file}. This includes aliases and functions,
3548 if and only if the @samp{-path} flag is not also used.
3550 @code{type} accepts @samp{-a}, @samp{-t}, and @samp{-p} as equivalent to
3551 @samp{-all}, @samp{-type}, and @samp{-path}, respectively.
3556 ulimit [-acdflmnpstuvSH] [@var{limit}]
3558 @code{ulimit} provides control over the resources available to processes
3559 started by the shell, on systems that allow such control. If an
3560 option is given, it is interpreted as follows:
3563 change and report the soft limit associated with a resource.
3566 change and report the hard limit associated with a resource.
3569 all current limits are reported.
3572 the maximum size of core files created.
3575 the maximum size of a process's data segment.
3578 the maximum size of files created by the shell.
3581 The maximum size that may be locked into memory.
3584 the maximum resident set size.
3587 the maximum number of open file descriptors.
3590 the pipe buffer size.
3593 the maximum stack size.
3596 the maximum amount of cpu time in seconds.
3599 the maximum number of processes available to a single user.
3602 the maximum amount of virtual memory available to the process.
3606 If @var{limit} is given, it is the new value of the specified resource.
3607 Otherwise, the current value of the soft limit for the specified resource
3608 is printed, unless the @samp{-H} option is supplied.
3609 When setting new limits, if neither @samp{-H} nor @samp{-S} is supplied,
3610 both the hard and soft limits are set.
3611 If no option is given, then @samp{-f} is assumed. Values are in 1024-byte
3612 increments, except for @samp{-t}, which is in seconds, @samp{-p},
3613 which is in units of 512-byte blocks, and @samp{-n} and @samp{-u}, which
3614 are unscaled values.
3618 @node The Set Builtin
3619 @section The Set Builtin
3621 This builtin is so overloaded that it deserves its own section.
3627 set [-abefhkmnptuvxdBCHP] [-o @var{option}] [@var{argument} @dots{}]
3632 Mark variables which are modified or created for export.
3635 Cause the status of terminated background jobs to be reported
3636 immediately, rather than before printing the next primary prompt.
3639 Exit immediately if a simple command exits with a non-zero status.
3642 Disable file name generation (globbing).
3645 Locate and remember (hash) commands as they are looked up for execution.
3648 All arguments in the form of assignment statements are placed
3649 in the environment for a command, not just those that precede
3653 Job control is enabled (@pxref{Job Control}).
3656 Read commands but do not execute them.
3658 @item -o @var{option-name}
3660 Set the flag corresponding to @var{option-name}:
3670 use an @code{emacs}-style line editing interface (@pxref{Command Line Editing}).
3682 Enable command history, as described in @ref{Bash History Facilities}.
3683 This option is on by default in interactive shells.
3686 the shell will not exit upon reading EOF.
3716 change the behavior of Bash where the default operation differs
3717 from the @sc{POSIX} 1003.2 standard to match the standard. This
3718 is intended to make Bash behave as a strict superset of that
3728 use a @code{vi}-style line editing interface.
3735 Turn on privileged mode.
3736 In this mode, the @code{$BASH_ENV}
3737 file is not processed, and shell functions
3738 are not inherited from the environment. This is enabled automatically
3739 on startup if the effective user (group) id is not equal to the real
3740 user (group) id. Turning this option off causes the effective user
3741 and group ids to be set to the real user and group ids.
3744 Exit after reading and executing one command.
3747 Treat unset variables as an error when substituting.
3750 Print shell input lines as they are read.
3753 Print commands and their arguments as they are executed.
3756 The shell will perform brace expansion (@pxref{Brace Expansion}).
3757 This option is on by default.
3760 Disallow output redirection to existing files.
3763 Enable @samp{!} style history substitution (@pxref{History Interaction}).
3764 This flag is on by default for interactive shells.
3767 If set, do not follow symbolic links when performing commands such as
3768 @code{cd} which change the current directory. The physical directory
3769 is used instead. By default, Bash follows
3770 the logical chain of directories when performing commands
3771 which change the current directory.
3773 For example, if @file{/usr/sys} is a link to @file{/usr/local/sys} then:
3775 $ cd /usr/sys; echo $PWD
3782 If @code{set -P} is on, then:
3784 $ cd /usr/sys; echo $PWD
3791 If no arguments follow this flag, then the positional parameters are
3792 unset. Otherwise, the positional parameters are set to the
3793 @var{arguments}, even if some of them begin with a @samp{-}.
3796 Signal the end of options, cause all remaining @var{arguments}
3797 to be assigned to the positional parameters. The @samp{-x}
3798 and @samp{-v} options are turned off.
3799 If there are no arguments, the positional parameters remain unchanged.
3802 Using @samp{+} rather than @samp{-} causes these flags to be
3803 turned off. The flags can also be used upon invocation of the
3804 shell. The current set of flags may be found in @code{$-}.
3806 The remaining N @var{arguments} are positional parameters and are
3807 assigned, in order, to @code{$1}, @code{$2}, @dots{} @code{$N}. If
3808 no arguments are given, all shell variables are printed.
3811 @node Bash Conditional Expressions
3812 @section Bash Conditional Expressions
3813 @cindex expressions, conditional
3815 Conditional expressions are used by the @code{test} and @code{[} builtins.
3817 Expressions may be unary or binary. Unary
3818 expressions are often used to examine the status of a file. There
3819 are string operators and numeric comparison operators as well. Each
3820 operator and operand must be a separate argument. If @var{file}
3821 is of the form @file{/dev/fd/@var{N}}, then file descriptor @var{N} is
3822 checked. Expressions are composed of the following primaries:
3826 True if @var{file} exists and is a block special file.
3829 True if @var{file} exists and is a character special file.
3832 True if @var{file} exists and is a directory.
3835 True if @var{file} exists.
3838 True if @var{file} exists and is a regular file.
3841 True if @var{file} exists and is set-group-id.
3844 True if @var{file} has its "sticky" bit set.
3847 True if @var{file} exists and is a symbolic link.
3850 True if @var{file} exists and is a named pipe.
3853 True if @var{file} exists and is readable.
3856 True if @var{file} exists and has a size greater than zero.
3859 True if @var{file} exists and is a socket.
3862 True if @var{fd} is opened on a terminal.
3865 True if @var{file} exists and its set-user-id bit is set.
3868 True if @var{file} exists and is writable.
3871 True if @var{file} exists and is executable.
3874 True if @var{file} exists and is owned by the effective user id.
3877 True if @var{file} exists and is owned by the effective group id.
3879 @item @var{file1} -nt @var{file2}
3880 True if @var{file1} is newer (according to
3881 modification date) than @var{file2}.
3883 @item @var{file1} -ot @var{file2}
3884 True if @var{file1} is older than @var{file2}.
3886 @item @var{file1} -ef @var{file2}
3887 True if @var{file1} and @var{file2} have the same device and
3890 @item -o @var{optname}
3891 True if shell option @var{optname} is enabled.
3892 The list of options appears in the description of the @samp{-o}
3893 option to the @code{set} builtin (@pxref{The Set Builtin}).
3895 @item -z @var{string}
3896 True if the length of @var{string} is zero.
3898 @item -n @var{string}
3900 True if the length of @var{string} is non-zero.
3902 @item @var{string1} = @var{string2}
3903 True if the strings are equal. @samp{==} may be used in place of
3906 @item @var{string1} != @var{string2}
3907 True if the strings are not equal.
3909 @item @var{string1} < @var{string2}
3910 True if @var{string1} sorts before @var{string2} lexicographically.
3912 @item @var{string1} > @var{string2}
3913 True if @var{string1} sorts after @var{string2} lexicographically.
3916 True if @var{expr} is false.
3918 @item @var{expr1} -a @var{expr2}
3919 True if both @var{expr1} and @var{expr2} are true.
3921 @item @var{expr1} -o @var{expr2}
3922 True if either @var{expr1} and @var{expr2} is true.
3924 @item @var{arg1} OP @var{arg2}
3926 @samp{-eq}, @samp{-ne}, @samp{-lt}, @samp{-le}, @samp{-gt}, or @samp{-ge}.
3927 These arithmetic binary operators return true if @var{arg1}
3928 is equal to, not equal to, less than, less than or equal to,
3929 greater than, or greater than or equal to @var{arg2},
3930 respectively. @var{Arg1} and @var{arg2}
3931 may be positive or negative integers.
3935 The Bash @code{test} and @code{[} builtins evaluate conditional
3936 expressions using a set of rules based on the number of arguments.
3937 These are the rules:
3941 The expression is false.
3943 The expression is true if and only if the argument is not null.
3945 If the first argument is @samp{!}, the expression is true if and
3946 only if the second argument is null. If the first argument is
3947 one of the listed unary operators, the expression is true if the
3948 unary test is true. If the first argument is not a legal unary
3949 operator, the expression is false.
3951 If the first argument is @samp{!}, the value is the negation of
3952 the two-argument test using the second and third arguments.
3953 If the second argument is one of the binary operators, the result
3954 of the expression is the result of the binary test using the first
3955 and third arguments as operands.
3956 If the first argument is exactly @samp{(} and the third argument is
3957 exactly @samp{)}, the result is the one-argument test of the second
3959 Otherwise, the expression is false.
3960 The @samp{-a} and @samp{-o} operators are considered binary operators
3963 If the first argument is @samp{!}, the result is the negation of
3964 the three-argument expression composed of the remaining arguments.
3965 Otherwise, the expression is parsed and evaluated according to
3966 precedence. @samp{-a} has a higher precedence than @samp{-o}.
3967 @item 5 or more arguments
3968 The expression is parsed and evaluated according to precedence,
3969 with @samp{-a} having a higher precedence than @samp{-o}.
3972 @node Bash Variables
3973 @section Bash Variables
3975 These variables are set or used by Bash, but other shells
3976 do not normally treat them specially.
3981 If this variable is set when Bash is invoked to execute a shell
3982 script, its value is expanded and used as the name of a startup file
3983 to read before executing the script. @xref{Bash Startup Files}.
3986 The value of this parameter is used as a format string specifying
3987 how the timing information for pipelines prefixed with the @code{time}
3988 reserved word should be displayed.
3989 The @samp{%} character introduces an
3990 escape sequence that is expanded to a time value or other
3992 The escape sequences and their meanings are as
3993 follows; the braces denote optional portions.
4000 @item %[@var{p}][l]R
4001 The elapsed time in seconds.
4003 @item %[@var{p}][l]U
4004 The number of CPU seconds spent in user mode.
4006 @item %[@var{p}][l]S
4007 The number of CPU seconds spent in system mode.
4010 The CPU percentage, computed as (%U + %S) / %R.
4013 The optional @var{p} is a digit specifying the precision, the number of
4014 fractional digits after a decimal point.
4015 A value of 0 causes no decimal point or fraction to be output.
4016 At most three places after the decimal point may be specified; values
4017 of @var{p} greater than 3 are changed to 3.
4018 If @var{p} is not specified, the value 3 is used.
4020 The optional @code{l} specifies a longer format, including minutes, of
4021 the form @var{MM}m@var{SS}.@var{FF}s.
4022 The value of @var{p} determines whether or not the fraction is included.
4024 If this variable is not set, bash acts as if it had the value
4026 @code{$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'}.
4028 If the value is null, no timing information is displayed.
4029 A trailing newline is added when the format string is displayed.
4032 Set to a value of @samp{ignorespace}, it means don't enter lines which
4033 begin with a space or tab into the history list. Set to a value
4034 of @samp{ignoredups}, it means don't enter lines which match the last
4035 entered line. A value of @samp{ignoreboth} combines the two options.
4036 Unset, or set to any other value than those above, means to save
4037 all lines on the history list.
4040 A colon-separated list of patterns used to decide which command
4041 lines should be saved on the history list. Each pattern is
4042 anchored at the beginning of the line and must fully specify the
4043 line (no implicit @samp{*} is appended). Each pattern is tested
4044 against the line after the checks specified by @code{HISTCONTROL}
4045 are applied. In addition to the normal shell pattern matching
4046 characters, @samp{&} matches the previous history line. @samp{&}
4047 may be escaped using a backslash. The backslash is removed
4048 before attempting a match.
4050 @code{HISTIGNORE} subsumes the function of @code{HISTCONTROL}. A
4051 pattern of @samp{&} is identical to @code{ignoredups}, and a
4052 pattern of @samp{[ ]*} is identical to @code{ignorespace}.
4053 Combining these two patterns, separating them with a colon,
4054 provides the functionality of @code{ignoreboth}.
4057 The name of the file to which the command history is saved. The
4058 default is @file{~/.bash_history}.
4061 If set, this is the maximum number of commands to remember in the
4065 The maximum number of lines contained in the history file. When this
4066 variable is assigned a value, the history file is truncated, if
4067 necessary, to contain no more than that number of lines. The default
4068 value is 500. The history file is also truncated to this size after
4069 writing it when an interactive shell exits.
4072 Up to three characters which control history expansion, quick
4073 substitution, and tokenization (@pxref{History Interaction}).
4074 The first character is the
4075 @dfn{history-expansion-char}, that is, the character which signifies the
4076 start of a history expansion, normally @samp{!}. The second character is the
4077 character which signifies `quick substitution' when seen as the first
4078 character on a line, normally @samp{^}. The optional third character is the
4079 character which signifies the remainder of the line is a comment, when
4080 found as the first character of a word, usually @samp{#}. The history
4081 comment character causes history substitution to be skipped for the
4082 remaining words on the line. It does not necessarily cause the shell
4083 parser to treat the rest of the line as a comment.
4086 The history number, or index in the history list, of the current
4087 command. If @code{HISTCMD} is unset, it loses its special properties,
4088 even if it is subsequently reset.
4091 Contains the name of a file in the same format as @file{/etc/hosts} that
4092 should be read when the shell needs to complete a hostname. You can
4093 change the file interactively; the next time you attempt to complete a
4094 hostname, Bash will add the contents of the new file to the already
4098 How often (in seconds) that the shell should check for mail
4099 in the files specified in @code{MAILPATH}.
4101 @item PROMPT_COMMAND
4102 If present, this contains a string which is a command to execute
4103 before the printing of each primary prompt (@code{$PS1}).
4106 The numeric real user id of the current user.
4109 The numeric effective user id of the current user.
4112 An array variable containing the list of groups of which the current
4116 The process id of the shell's parent process.
4119 The name of the current host.
4122 A string describing the machine Bash is running on.
4125 A string describing the operating system Bash is running on.
4128 A string that fully describes the system type on which Bash
4129 is executing, in the standard GNU @var{cpu-company-system} format.
4132 A colon-separated list of enabled shell options. Each word in
4133 the list is a valid argument for the @samp{-o} option to the
4134 @code{set} builtin command (@pxref{The Set Builtin}).
4135 The options appearing in @code{SHELLOPTS} are those reported
4136 as @samp{on} by @samp{set -o}.
4137 If this variable is in the environment when Bash
4138 starts up, each shell option in the list will be enabled before
4139 reading any startup files. This variable is readonly.
4142 A colon-separated list of suffixes to ignore when performing
4143 filename completion.
4144 A file name whose suffix matches one of the entries in
4146 is excluded from the list of matched file names. A sample
4147 value is @samp{.o:~}
4150 A colon-separated list of patterns defining the set of filenames to
4151 be ignored by filename expansion.
4152 If a filename matched by a filename expansion pattern also matches one
4153 of the patterns in @code{GLOBIGNORE}, it is removed from the list
4157 An array variable (@pxref{Arrays})
4158 containing the current contents of the directory stack.
4159 Directories appear in the stack in the order they are displayed by the
4160 @code{dirs} builtin.
4161 Assigning to members of this array variable may be used to modify
4162 directories already in the stack, but the @code{pushd} and @code{popd}
4163 builtins must be used to add and remove directories.
4164 Assignment to this variable will not change the current directory.
4165 If @code{DIRSTACK} is unset, it loses its special properties, even if
4166 it is subsequently reset.
4169 An array variable (@pxref{Arrays})
4170 containing a list of exit status values from the processes
4171 in the most-recently-executed foreground pipeline (which may
4172 contain only a single command).
4175 The name of the Readline startup file, overriding the default
4176 of @file{~/.inputrc}.
4179 The full filename used to execute the current instance of Bash.
4182 The version number of the current instance of Bash.
4185 An array variable whose members hold version information for this
4187 The values assigned to the array members are as follows:
4191 @item BASH_VERSINFO[0]
4192 The major version number (the @var{release}).
4194 @item BASH_VERSINFO[1]
4195 The minor version number (the @var{version}).
4197 @item BASH_VERSINFO[2]
4200 @item BASH_VERSINFO[3]
4203 @item BASH_VERSINFO[4]
4204 The release status (e.g., @var{beta1}).
4206 @item BASH_VERSINFO[5]
4207 The value of @code{MACHTYPE}.
4212 Incremented by one each time a new instance of Bash is started. This is
4213 intended to be a count of how deeply your Bash shells are nested.
4216 If set to the value 1, Bash displays error messages
4217 generated by the @code{getopts} builtin command.
4220 Used to determine the locale category for any category not specifically
4221 selected with a variable starting with @code{LC_}.
4224 This variable overrides the value of @code{LANG} and any other
4225 @code{LC_} variable specifying a locale category.
4228 This variable determines the collation order used when sorting the
4229 results of filename expansion (@pxref{Filename Expansion}).
4232 This variable determines the locale used to translate double-quoted
4233 strings preceded by a @samp{$} (@pxref{Locale Translation}).
4236 Controls the action of the shell on receipt of an @code{EOF} character
4237 as the sole input. If set, then the value of it is the number
4238 of consecutive @code{EOF} characters that can be read as the
4239 first character on an input line
4240 before the shell will exit. If the variable exists but does not
4241 have a numeric value (or has no value) then the default is 10.
4242 If the variable does not exist, then @code{EOF} signifies the end of
4243 input to the shell. This is only in effect for interactive shells.
4247 @node Shell Arithmetic
4248 @section Shell Arithmetic
4249 @cindex arithmetic, shell
4252 * Arithmetic Evaluation:: How shell arithmetic works.
4253 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
4254 * Arithmetic Builtins:: Builtin commands that use shell arithmetic.
4257 Bash includes several mechanisms to evaluate arithmetic expressions
4258 and display the result or use it as part of a command.
4260 @node Arithmetic Evaluation
4261 @subsection Arithmetic Evaluation
4262 @cindex expressions, arithmetic
4263 @cindex evaluation, arithmetic
4264 @cindex arithmetic evaluation
4266 The shell allows arithmetic expressions to be evaluated, as one of
4267 the shell expansions or by the @code{let} builtin.
4269 Evaluation is done in long integers with no check for overflow,
4270 though division by 0 is trapped and flagged as an error. The
4271 following list of operators is grouped into levels of
4272 equal-precedence operators. The levels are listed in order of
4273 decreasing precedence.
4277 unary minus and plus
4280 logical and bitwise negation
4283 multiplication, division, remainder
4286 addition, subtraction
4289 left and right bitwise shifts
4295 equality and inequality
4301 bitwise exclusive OR
4312 @item expr ? expr : expr
4313 conditional evaluation
4315 @item = *= /= %= += -= <<= >>= &= ^= |=
4319 Shell variables are allowed as operands; parameter expansion is
4320 performed before the expression is evaluated.
4321 The value of a parameter is coerced to a long integer within
4322 an expression. A shell variable need not have its integer attribute
4323 turned on to be used in an expression.
4325 Constants with a leading 0 are interpreted as octal numbers.
4326 A leading @samp{0x} or @samp{0X} denotes hexadecimal. Otherwise,
4327 numbers take the form [@var{base}@code{#}]@var{n}, where @var{base}
4328 is a decimal number between 2 and 64 representing the arithmetic
4329 base, and @var{n} is a number in that base. If @var{base} is
4330 omitted, then base 10 is used.
4331 The digits greater than 9 are represented by the lowercase letters,
4332 the uppercase letters, @samp{_}, and @samp{@@}, in that order.
4333 If @var{base} is less than or equal to 36, lowercase and uppercase
4334 letters may be used interchangably to represent numbers between 10
4337 Operators are evaluated in order of precedence. Sub-expressions in
4338 parentheses are evaluated first and may override the precedence
4341 @node Arithmetic Expansion
4342 @subsection Arithmetic Expansion
4343 @cindex expansion, arithmetic
4344 @cindex arithmetic expansion
4346 Arithmetic expansion allows the evaluation of an arithmetic expression
4347 and the substitution of the result. The format for arithmetic expansion is:
4350 $(( @var{expression} ))
4353 The expression is treated as if it were within double quotes, but
4354 a double quote inside the braces or parentheses is not treated
4355 specially. All tokens in the expression undergo parameter
4356 expansion, command substitution, and quote removal. Arithmetic
4357 substitutions may be nested.
4359 The evaluation is performed according to the rules listed above.
4360 If the expression is invalid, Bash
4361 prints a message indicating failure and no substitution occurs.
4363 @node Arithmetic Builtins
4364 @subsection Arithmetic Builtins
4371 let @var{expression} [@var{expression}]
4373 The @code{let} builtin allows arithmetic to be performed on shell
4374 variables. Each @var{expression} is evaluated according to the
4375 rules given previously (@pxref{Arithmetic Evaluation}). If the
4376 last @var{expression} evaluates to 0, @code{let} returns 1;
4377 otherwise 0 is returned.
4384 Bash provides one-dimensional array variables. Any variable may be used as
4385 an array; the @code{declare} builtin will explicitly declare an array.
4387 limit on the size of an array, nor any requirement that members
4388 be indexed or assigned contiguously. Arrays are zero-based.
4390 An array is created automatically if any variable is assigned to using
4393 name[@var{subscript}]=@var{value}
4398 is treated as an arithmetic expression that must evaluate to a number
4399 greater than or equal to zero. To explicitly declare an array, use
4401 declare -a @var{name}
4406 declare -a @var{name}[@var{subscript}]
4409 is also accepted; the @var{subscript} is ignored. Attributes may be
4410 specified for an array variable using the @code{declare} and
4411 @code{readonly} builtins. Each attribute applies to all members of
4414 Arrays are assigned to using compound assignments of the form
4416 name=(value@var{1} @dots{} value@var{n})
4420 @var{value} is of the form @code{[[@var{subscript}]=]}@var{string}. If
4421 the optional subscript is supplied, that index is assigned to;
4422 otherwise the index of the element assigned is the last index assigned
4423 to by the statement plus one. Indexing starts at zero.
4424 This syntax is also accepted by the @code{declare}
4425 builtin. Individual array elements may be assigned to using the
4426 @code{name[}@var{subscript}@code{]=}@var{value} syntax introduced above.
4428 Any element of an array may be referenced using
4429 @code{$@{name[}@var{subscript}@code{]@}}.
4430 The braces are required to avoid
4431 conflicts with the shell's filename expansion operators. If the
4432 @var{subscript} is @samp{@@} or @samp{*}, the word expands to all members
4433 of the array @var{name}. These subscripts differ only when the word
4434 appears within double quotes. If the word is double-quoted,
4435 @code{$@{name[*]@}} expands to a single word with
4436 the value of each array member separated by the first character of the
4437 @code{IFS} variable, and @code{$@{name[@@]@}} expands each element of
4438 @var{name} to a separate word. When there are no array members,
4439 @code{$@{name[@@]@}} expands to nothing. This is analogous to the
4440 expansion of the special parameters @samp{@@} and @samp{*}.
4441 @code{$@{#name[}@var{subscript}@code{]@}} expands to the length of
4442 @code{$@{name[}@var{subscript}@code{]@}}.
4443 If @var{subscript} is @samp{@@} or
4444 @samp{*}, the expansion is the number of elements in the array.
4445 Referencing an array variable without a subscript is equivalent to
4446 referencing element zero.
4448 The @code{unset} builtin is used to destroy arrays.
4449 @code{unset} @var{name[subscript]}
4450 destroys the array element at index @var{subscript}.
4451 @code{unset} @var{name}, where @var{name} is an array, removes the
4452 entire array. A subscript of @samp{*} or @samp{@@} also removes the
4455 The @code{declare}, @code{local}, and @code{readonly}
4456 builtins each accept a @samp{-a}
4457 option to specify an array. The @code{read}
4458 builtin accepts a @samp{-a}
4459 option to assign a list of words read from the standard input
4460 to an array, and can read values from the standard input into
4461 individual array elements. The @code{set} and @code{declare}
4462 builtins display array values in a way that allows them to be
4465 @node Printing a Prompt
4466 @section Controlling the Prompt
4469 The value of the variable @code{PROMPT_COMMAND} is examined just before
4470 Bash prints each primary prompt. If it is set and non-null, then the
4471 value is executed just as if you had typed it on the command line.
4473 In addition, the following table describes the special characters which
4474 can appear in the prompt variables:
4480 the date, in "Weekday Month Date" format (e.g., "Tue May 26").
4482 an escape character.
4484 the hostname, up to the first `.'.
4490 the name of the shell, the basename of @code{$0} (the portion
4491 following the final slash).
4493 the time, in 24-hour HH:MM:SS format.
4495 the time, in 12-hour HH:MM:SS format.
4497 the time, in 12-hour am/pm format.
4499 the version of Bash (e.g., 2.00)
4501 the release of Bash, version + patchlevel (e.g., 2.00.0)
4503 the current working directory.
4505 the basename of @code{$PWD}.
4509 the history number of this command.
4511 the command number of this command.
4513 if the effective uid is 0, @code{#}, otherwise @code{$}.
4515 the character corresponding to the octal number @code{nnn}.
4519 begin a sequence of non-printing characters. This could be used to
4520 embed a terminal control sequence into the prompt.
4522 end a sequence of non-printing characters.
4525 @node The Restricted Shell
4526 @section The Restricted Shell
4527 @cindex restricted shell
4529 If Bash is started with the name @code{rbash}, or the
4531 option is supplied at invocation, the shell becomes restricted.
4532 A restricted shell is used to
4533 set up an environment more controlled than the standard shell.
4534 A restricted shell behaves identically to @code{bash}
4535 with the exception that the following are disallowed:
4538 Changing directories with the @code{cd} builtin.
4540 Setting or unsetting the values of the @code{SHELL} or @code{PATH}
4543 Specifying command names containing slashes.
4545 Specifying a filename containing a slash as an argument to the @code{.}
4548 Importing function definitions from the shell environment at startup.
4550 Redirecting output using the @samp{>}, @samp{>|}, @samp{<>}, @samp{>&},
4551 @samp{&>}, and @samp{>>} redirection operators.
4553 Using the @code{exec} builtin to replace the shell with another command.
4555 Adding or deleting builtin commands with the
4556 @samp{-f} and @samp{-d} options to the @code{enable} builtin.
4558 Specifying the @samp{-p} option to the @code{command} builtin.
4560 Turning off restricted mode with @samp{set +r}.
4563 @node Bash POSIX Mode
4564 @section Bash POSIX Mode
4567 Starting Bash with the @samp{--posix} command-line option or executing
4568 @samp{set -o posix} while Bash is running will cause Bash to conform more
4569 closely to the @sc{POSIX.2} standard by changing the behavior to match that
4570 specified by @sc{POSIX.2} in areas where the Bash default differs.
4572 The following list is what's changed when `@sc{POSIX} mode' is in effect:
4576 When a command in the hash table no longer exists, Bash will re-search
4577 @code{$PATH} to find the new location. This is also available with
4578 @samp{shopt -s checkhash}.
4581 The @samp{>&} redirection does not redirect stdout and stderr.
4584 The message printed by the job control code and builtins when a job
4585 exits with a non-zero status is `Done(status)'.
4588 Reserved words may not be aliased.
4591 The @sc{POSIX.2} @code{PS1} and @code{PS2} expansions of @samp{!} to
4592 the history number and @samp{!!} to @samp{!} are enabled,
4593 and parameter expansion is performed on
4594 the value regardless of the setting of the @code{promptvars} option.
4597 Interactive comments are enabled by default. (Note that Bash has
4598 them on by default anyway.)
4601 The @sc{POSIX.2} startup files are executed (@code{$ENV}) rather than
4602 the normal Bash files.
4605 Tilde expansion is only performed on assignments preceding a command
4606 name, rather than on all assignment statements on the line.
4609 The default history file is @file{~/.sh_history} (this is the
4610 default value of @code{$HISTFILE}).
4613 The output of @samp{kill -l} prints all the signal names on a single line,
4614 separated by spaces.
4617 Non-interactive shells exit if @var{filename} in @code{.} @var{filename}
4621 Redirection operators do not perform filename expansion on the word
4622 in the redirection unless the shell is interactive.
4625 Function names must be valid shell @code{name}s. That is, they may not
4626 contain characters other than letters, digits, and underscores, and
4627 may not start with a digit. Declaring a function with an illegal name
4628 causes a fatal syntax error in non-interactive shells.
4631 @sc{POSIX.2} `special' builtins are found before shell functions
4632 during command lookup.
4635 If a @sc{POSIX.2} special builtin returns an error status, a
4636 non-interactive shell exits. The fatal errors are those listed in
4637 the POSIX.2 standard, and include things like passing incorrect options,
4638 redirection errors, variable assignment errors for assignments preceding
4639 the command name, and so on.
4642 If the @code{cd} builtin finds a directory to change to
4643 using @code{$CDPATH}, the
4644 value it assigns to the @code{PWD} variable does not contain any
4645 symbolic links, as if @samp{cd -P} had been executed.
4648 A non-interactive shell exits with an error status if a variable
4649 assignment error occurs when no command name follows the assignment
4651 A variable assignment error occurs, for example, when trying to assign
4652 a value to a read-only variable.
4655 A non-interactive shell exits with an error status if the iteration
4656 variable in a @code{for} statement or the selection variable in a
4657 @code{select} statement is a read-only variable.
4660 Process substitution is not available.
4663 Assignment statements preceding @sc{POSIX.2} @code{special} builtins
4664 persist in the shell environment after the builtin completes.
4667 The @code{export} and @code{readonly} builtin commands display their
4668 output in the format required by @sc{POSIX.2}.
4672 There is other @sc{POSIX.2} behavior that Bash does not implement.
4677 Assignment statements affect the execution environment of all
4678 builtins, not just special ones.
4682 @chapter Job Control
4684 This chapter disusses what job control is, how it works, and how
4685 Bash allows you to access its facilities.
4688 * Job Control Basics:: How job control works.
4689 * Job Control Builtins:: Bash builtin commands used to interact
4691 * Job Control Variables:: Variables Bash uses to customize job
4695 @node Job Control Basics
4696 @section Job Control Basics
4700 @cindex suspending jobs
4703 refers to the ability to selectively stop (suspend)
4704 the execution of processes and continue (resume)
4705 their execution at a later point. A user typically employs
4706 this facility via an interactive interface supplied jointly
4707 by the system's terminal driver and Bash.
4709 The shell associates a @var{job} with each pipeline. It keeps a
4710 table of currently executing jobs, which may be listed with the
4711 @code{jobs} command. When Bash starts a job
4712 asynchronously (in the background), it prints a line that looks
4718 indicating that this job is job number 1 and that the process @sc{ID}
4719 of the last process in the pipeline associated with this job is
4720 25647. All of the processes in a single pipeline are members of
4721 the same job. Bash uses the @var{job} abstraction as the
4722 basis for job control.
4724 To facilitate the implementation of the user interface to job
4725 control, the system maintains the notion of a current terminal
4726 process group @sc{ID}. Members of this process group (processes whose
4727 process group @sc{ID} is equal to the current terminal process group
4728 @sc{ID}) receive keyboard-generated signals such as @code{SIGINT}.
4729 These processes are said to be in the foreground. Background
4730 processes are those whose process group @sc{ID} differs from the
4731 terminal's; such processes are immune to keyboard-generated
4732 signals. Only foreground processes are allowed to read from or
4733 write to the terminal. Background processes which attempt to
4734 read from (write to) the terminal are sent a @code{SIGTTIN}
4735 (@code{SIGTTOU}) signal by the terminal driver, which, unless
4736 caught, suspends the process.
4738 If the operating system on which Bash is running supports
4739 job control, Bash allows you to use it. Typing the
4740 @var{suspend} character (typically @samp{^Z}, Control-Z) while a
4741 process is running causes that process to be stopped and returns
4742 you to Bash. Typing the @var{delayed suspend} character
4743 (typically @samp{^Y}, Control-Y) causes the process to be stopped
4744 when it attempts to read input from the terminal, and control to
4745 be returned to Bash. You may then manipulate the state of
4746 this job, using the @code{bg} command to continue it in the
4747 background, the @code{fg} command to continue it in the
4748 foreground, or the @code{kill} command to kill it. A @samp{^Z}
4749 takes effect immediately, and has the additional side effect of
4750 causing pending output and typeahead to be discarded.
4752 There are a number of ways to refer to a job in the shell. The
4753 character @samp{%} introduces a job name. Job number @code{n}
4754 may be referred to as @samp{%n}. A job may also be referred to
4755 using a prefix of the name used to start it, or using a substring
4756 that appears in its command line. For example, @samp{%ce} refers
4757 to a stopped @code{ce} job. Using @samp{%?ce}, on the
4758 other hand, refers to any job containing the string @samp{ce} in
4759 its command line. If the prefix or substring matches more than one job,
4760 Bash reports an error. The symbols @samp{%%} and
4761 @samp{%+} refer to the shell's notion of the current job, which
4762 is the last job stopped while it was in the foreground. The
4763 previous job may be referenced using @samp{%-}. In output
4764 pertaining to jobs (e.g., the output of the @code{jobs} command),
4765 the current job is always flagged with a @samp{+}, and the
4766 previous job with a @samp{-}.
4768 Simply naming a job can be used to bring it into the foreground:
4769 @samp{%1} is a synonym for @samp{fg %1}, bringing job 1 from the
4770 background into the foreground. Similarly, @samp{%1 &} resumes
4771 job 1 in the background, equivalent to @samp{bg %1}
4773 The shell learns immediately whenever a job changes state.
4774 Normally, Bash waits until it is about to print a prompt
4775 before reporting changes in a job's status so as to not interrupt
4776 any other output. If the
4777 the @samp{-b} option to the @code{set} builtin is set,
4778 Bash reports such changes immediately (@pxref{The Set Builtin}).
4780 If you attempt to exit Bash while jobs are stopped, the
4781 shell prints a message warning you that you have stopped jobs.
4782 You may then use the
4783 @code{jobs} command to inspect their status. If you do this, or
4784 try to exit again immediately, you are not warned again, and the
4785 stopped jobs are terminated.
4787 @node Job Control Builtins
4788 @section Job Control Builtins
4797 Place @var{jobspec} into the background, as if it had been started
4798 with @samp{&}. If @var{jobspec} is not supplied, the current job
4806 Bring @var{jobspec} into the foreground and make it the current job.
4807 If @var{jobspec} is not supplied, the current job is used.
4812 jobs [-lpnrs] [@var{jobspec}]
4813 jobs -x @var{command} [@var{jobspec}]
4816 The first form lists the active jobs. The options have the
4821 List process @sc{ID}s in addition to the normal information
4824 Display information only about jobs that have changed status since
4825 you were last notified of their status.
4828 List only the process @sc{ID} of the job's process group
4832 Restrict output to running jobs.
4835 Restrict output to stopped jobs.
4838 If @var{jobspec} is given,
4839 output is restricted to information about that job.
4840 If @var{jobspec} is not supplied, the status of all jobs is
4843 If the @samp{-x} option is supplied, @code{jobs} replaces any
4844 @var{jobspec} found in @var{command} or @var{arguments} with the
4845 corresponding process group @sc{ID}, and executes @var{command},
4846 passing it @var{argument}s, returning its exit status.
4851 kill [-s @var{sigspec}] [-n @var{signum}] [-@var{sigspec}] @var{jobspec}
4852 kill -l [@var{sigspec}]
4854 Send a signal specified by @var{sigspec} or @var{signum} to the process
4855 named by @var{jobspec}.
4856 @var{sigspec} is either a signal name such as @code{SIGINT} (with or without
4857 the @code{SIG} prefix) or a signal number; @var{signum} is a signal number.
4858 If @var{sigspec} and @var{signum} are not present, @code{SIGTERM} is used.
4859 The @samp{-l} option lists the signal names, or the signal name
4860 corresponding to @var{sigspec}.
4865 wait [@var{jobspec}|@var{pid}]
4867 Wait until the child process specified by process @sc{ID} @var{pid} or job
4868 specification @var{jobspec} exits and report its exit status. If a job
4869 spec is given, all processes in the job are waited for. If no arguments
4870 are given, all currently active child processes are waited for.
4875 disown [-h] [@var{jobspec} @dots{}]
4877 Without options, each @var{jobspec} is removed from the table of
4879 If the @samp{-h} option is given, the job is not removed from the table,
4880 but is marked so that @code{SIGHUP} is not sent to the job if the shell
4881 receives a @code{SIGHUP}.
4882 If @var{jobspec} is not present, the current job is used.
4889 Suspend the execution of this shell until it receives a
4890 @code{SIGCONT} signal. The @samp{-f} option means to suspend
4891 even if the shell is a login shell.
4895 When job control is not active, the @code{kill} and @code{wait}
4896 builtins do not accept @var{jobspec} arguments. They must be
4897 supplied process @sc{ID}s.
4899 @node Job Control Variables
4900 @section Job Control Variables
4905 This variable controls how the shell interacts with the user and
4906 job control. If this variable exists then single word simple
4907 commands without redirects are treated as candidates for resumption
4908 of an existing job. There is no ambiguity allowed; if there is
4909 more than one job beginning with the string typed, then
4910 the most recently accessed job will be selected.
4911 The name of a stopped job, in this context, is the command line
4912 used to start it. If this variable is set to the value @samp{exact},
4913 the string supplied must match the name of a stopped job exactly;
4914 if set to @samp{substring},
4915 the string supplied needs to match a substring of the name of a
4916 stopped job. The @samp{substring} value provides functionality
4917 analogous to the @samp{%?} job @sc{ID} (@pxref{Job Control Basics}).
4918 If set to any other value, the supplied string must
4919 be a prefix of a stopped job's name; this provides functionality
4920 analogous to the @samp{%} job @sc{ID}.
4924 @set readline-appendix
4925 @set history-appendix
4926 @cindex History, how to use
4927 @include hsuser.texinfo
4928 @cindex Readline, how to use
4929 @include rluser.texinfo
4930 @clear readline-appendix
4931 @clear history-appendix
4933 @node Installing Bash
4934 @chapter Installing Bash
4936 This chapter provides basic instructions for installing Bash on
4937 the various supported platforms. The distribution supports nearly every
4938 version of Unix (and, someday, @sc{GNU}). Other independent ports exist for
4939 @sc{OS/2}, Windows 95, and Windows @sc{NT}.
4942 * Basic Installation:: Installation instructions.
4944 * Compilers and Options:: How to set special options for various
4947 * Compiling For Multiple Architectures:: How to compile Bash for more
4948 than one kind of system from
4949 the same source tree.
4951 * Installation Names:: How to set the various paths used by the installation.
4953 * Specifying the System Type:: How to configure Bash for a particular system.
4955 * Sharing Defaults:: How to share default configuration values among GNU
4958 * Operation Controls:: Options recognized by the configuration program.
4960 * Optional Features:: How to enable and disable optional features when
4964 @node Basic Installation
4965 @section Basic Installation
4966 @cindex installation
4967 @cindex configuration
4968 @cindex Bash installation
4969 @cindex Bash configuration
4971 These are installation instructions for Bash.
4973 The @code{configure} shell script attempts to guess correct
4974 values for various system-dependent variables used during
4975 compilation. It uses those values to create a @file{Makefile} in
4976 each directory of the package (the top directory, the
4977 @file{builtins} and @file{doc} directories, and the
4978 each directory under @file{lib}). It also creates a
4979 @file{config.h} file containing system-dependent definitions.
4980 Finally, it creates a shell script named @code{config.status} that you
4981 can run in the future to recreate the current configuration, a
4982 file @file{config.cache} that saves the results of its tests to
4983 speed up reconfiguring, and a file @file{config.log} containing
4984 compiler output (useful mainly for debugging @code{configure}).
4986 @file{config.cache} contains results you don't want to keep, you
4987 may remove or edit it.
4989 If you need to do unusual things to compile the package, please
4990 try to figure out how @code{configure} could check whether or not
4991 to do them, and mail diffs or instructions to
4992 @code{bash-maintainers@@prep.ai.mit.edu} so they can be
4993 considered for the next release.
4995 The file @file{configure.in} is used to create @code{configure}
4996 by a program called Autoconf. You only need
4997 @file{configure.in} if you want to change it or regenerate
4998 @code{configure} using a newer version of Autoconf. If
4999 you do this, make sure you are using Autoconf version 2.10 or
5002 If you need to change @file{configure.in} or regenerate
5003 @code{configure}, you will need to create two files:
5004 @file{_distribution} and @file{_patchlevel}. @file{_distribution}
5005 should contain the major and minor version numbers of the Bash
5006 distribution, for example @samp{2.01}. @file{_patchlevel} should
5007 contain the patch level of the Bash distribution, @samp{0} for
5008 example. The script @file{support/mkconffiles} has been provided
5009 to automate the creation of these files.
5011 The simplest way to compile Bash is:
5015 @code{cd} to the directory containing the source code and type
5016 @samp{./configure} to configure Bash for your system. If you're
5017 using @code{csh} on an old version of System V, you might need to
5018 type @samp{sh ./configure} instead to prevent @code{csh} from trying
5019 to execute @code{configure} itself.
5021 Running @code{configure} takes awhile. While running, it prints some
5022 messages telling which features it is checking for.
5025 Type @samp{make} to compile Bash and build the @code{bashbug} bug
5029 Optionally, type @samp{make tests} to run the Bash test suite.
5032 Type @samp{make install} to install @code{bash} and @code{bashbug}.
5033 This will also install the manual pages and Info file.
5037 You can remove the program binaries and object files from the
5038 source code directory by typing @samp{make clean}. To also remove the
5039 files that @code{configure} created (so you can compile Bash for
5040 a different kind of computer), type @samp{make distclean}.
5042 @node Compilers and Options
5043 @section Compilers and Options
5045 Some systems require unusual options for compilation or linking
5046 that the @code{configure} script does not know about. You can
5047 give @code{configure} initial values for variables by setting
5048 them in the environment. Using a Bourne-compatible shell, you
5049 can do that on the command line like this:
5052 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
5055 On systems that have the @code{env} program, you can do it like this:
5058 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
5061 The configuration process uses GCC to build Bash if it
5064 @node Compiling For Multiple Architectures
5065 @section Compiling For Multiple Architectures
5067 You can compile Bash for more than one kind of computer at the
5068 same time, by placing the object files for each architecture in their
5069 own directory. To do this, you must use a version of @code{make} that
5070 supports the @code{VPATH} variable, such as GNU @code{make}.
5072 directory where you want the object files and executables to go and run
5073 the @code{configure} script from the source directory. You may need to
5074 supply the @samp{--srcdir=PATH} argument to tell @code{configure} where the
5075 source files are. @code{configure} automatically checks for the
5076 source code in the directory that @code{configure} is in and in `..'.
5078 If you have to use a @code{make} that does not supports the @code{VPATH}
5079 variable, you can compile Bash for one architecture at a
5080 time in the source code directory. After you have installed
5081 Bash for one architecture, use @samp{make distclean} before
5082 reconfiguring for another architecture.
5084 Alternatively, if your system supports symbolic links, you can use the
5085 @file{support/mkclone} script to create a build tree which has
5086 symbolic links back to each file in the source directory. Here's an
5087 example that creates a build directory in the current directory from a
5088 source directory @file{/usr/gnu/src/bash-2.0}:
5091 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
5095 The @code{mkclone} script requires Bash, so you must have already built
5096 Bash for at least one architecture before you can create build
5097 directories for other architectures.
5099 @node Installation Names
5100 @section Installation Names
5102 By default, @samp{make install} will install into
5103 @file{/usr/local/bin}, @file{/usr/local/man}, etc. You can
5104 specify an installation prefix other than @file{/usr/local} by
5105 giving @code{configure} the option @samp{--prefix=PATH}.
5107 You can specify separate installation prefixes for
5108 architecture-specific files and architecture-independent files.
5109 If you give @code{configure} the option
5110 @samp{--exec-prefix=PATH}, the package will use @samp{PATH} as the
5111 prefix for installing programs and libraries. Documentation and
5112 other data files will still use the regular prefix.
5114 @node Specifying the System Type
5115 @section Specifying the System Type
5117 There may be some features @code{configure} can not figure out
5118 automatically, but needs to determine by the type of host the
5119 package will run on. Usually @code{configure} can figure that
5120 out, but if it prints a message saying it can not guess the host
5121 type, give it the @samp{--host=TYPE} option. @samp{TYPE} can
5122 either be a short name for the system type, such as @samp{sun4},
5123 or a canonical name with three fields: @samp{CPU-COMPANY-SYSTEM}
5124 (e.g., @samp{sparc-sun-sunos4.1.2}).
5126 @noindent See the file @file{support/config.sub} for the possible
5127 values of each field.
5129 @node Sharing Defaults
5130 @section Sharing Defaults
5132 If you want to set default values for @code{configure} scripts to
5133 share, you can create a site shell script called
5134 @code{config.site} that gives default values for variables like
5135 @code{CC}, @code{cache_file}, and @code{prefix}. @code{configure}
5136 looks for @file{PREFIX/share/config.site} if it exists, then
5137 @file{PREFIX/etc/config.site} if it exists. Or, you can set the
5138 @code{CONFIG_SITE} environment variable to the location of the site
5139 script. A warning: the Bash @code{configure} looks for a site script,
5140 but not all @code{configure} scripts do.
5142 @node Operation Controls
5143 @section Operation Controls
5145 @code{configure} recognizes the following options to control how it
5150 @item --cache-file=@var{FILE}
5151 Use and save the results of the tests in
5152 @var{FILE} instead of @file{./config.cache}. Set @var{FILE} to
5153 @file{/dev/null} to disable caching, for debugging
5157 Print a summary of the options to @code{configure}, and exit.
5162 Do not print messages saying which checks are being made.
5164 @item --srcdir=@var{DIR}
5165 Look for the Bash source code in directory @var{DIR}. Usually
5166 @code{configure} can determine that directory automatically.
5169 Print the version of Autoconf used to generate the @code{configure}
5173 @code{configure} also accepts some other, not widely used, boilerplate
5176 @node Optional Features
5177 @section Optional Features
5179 The Bash @code{configure} has a number of @samp{--enable-@var{FEATURE}}
5180 options, where @var{FEATURE} indicates an optional part of the
5181 package. There are also several @samp{--with-@var{PACKAGE}} options,
5182 where @var{PACKAGE} is something like @samp{gnu-malloc} or
5183 @samp{purify} (for the Purify memory allocation checker). To
5184 turn off the default use of a package, use
5185 @samp{--without-@var{PACKAGE}}. To configure Bash without a feature
5186 that is enabled by default, use @samp{--disable-@var{FEATURE}}.
5188 Here is a complete list of the @samp{--enable-} and
5189 @samp{--with-} options that the Bash @code{configure} recognizes.
5193 Define if you are using the Andrew File System from Transarc.
5196 Use the curses library instead of the termcap library. This should
5197 be supplied if your system has an inadequate or incomplete termcap
5200 @item --with-glibc-malloc
5201 Use the @sc{GNU} libc version of @code{malloc} in
5202 @file{lib/malloc/gmalloc.c}. This is somewhat slower than the
5203 default @code{malloc}, but wastes considerably less space.
5205 @item --with-gnu-malloc
5206 Use the @sc{GNU} version of
5207 @code{malloc} in @file{lib/malloc/malloc.c}. This is not the same
5208 @code{malloc} that appears in @sc{GNU} libc, but an older version
5209 derived from the 4.2 @sc{BSD} @code{malloc}. This @code{malloc} is
5210 very fast, but wastes a lot of space. This option is enabled by
5211 default. The @file{NOTES} file contains a list of systems for
5212 which this should be turned off, and @code{configure} disables this
5213 option automatically for a number of systems.
5216 Define this to use the Purify memory allocation checker from Pure
5219 @item --enable-minimal-config
5220 This produces a shell with minimal features, close to the historical
5225 The @samp{minimal-config} option can be used to disable all of
5226 the following options, but it is processed first, so individual
5227 options may be enabled using @samp{enable-@var{FEATURE}}.
5229 All of the following options except for @samp{disabled-builtins} and
5230 @samp{usg-echo-default} are
5231 enabled by default, unless the operating system does not provide the
5235 @item --enable-alias
5236 Allow alias expansion and include the @code{alias} and @code{unalias}
5239 @item --enable-array-variables
5240 Include support for one-dimensional array shell variables.
5242 @item --enable-bang-history
5243 Include support for @code{csh}-like history substitution.
5245 @item --enable-brace-expansion
5246 Include @code{csh}-like brace expansion
5247 ( @code{b@{a,b@}c} @expansion{} @code{bac bbc} ).
5249 @item --enable-command-timing
5250 Include support for recognizing @code{time} as a reserved word and for
5251 displaying timing statistics for the pipeline following @code{time}. This
5252 allows pipelines as well as shell builtins and functions to be timed.
5254 @item --enable-directory-stack
5255 Include support for a @code{csh}-like directory stack and the
5256 @code{pushd}, @code{popd}, and @code{dirs} builtins.
5258 @item --enable-disabled-builtins
5259 Allow builtin commands to be invoked via @samp{builtin xxx}
5260 even after @code{xxx} has been disabled using @samp{enable -n xxx}.
5261 See @ref{Bash Builtins}, for details of the @code{builtin} and
5262 @code{enable} builtin commands.
5264 @item --enable-dparen-arithmetic
5265 Include support for the @code{ksh} @code{((@dots{}))} command.
5267 @item --enable-help-builtin
5268 Include the @code{help} builtin, which displays help on shell builtins and
5271 @item --enable-history
5272 Include command history and the @code{fc} and @code{history}
5275 @item --enable-job-control
5276 This enables job control features, if the @sc{OS} supports them.
5278 @item --enable-process-substitution
5279 This enables process substitution (@pxref{Process Substitution}) if
5280 the @sc{OS} provides the necessary support.
5282 @item --enable-prompt-string-decoding
5283 Turn on the interpretation of a number of backslash-escaped characters
5284 in the @code{$PS1}, @code{$PS2}, @code{$PS3}, and @code{$PS4} prompt
5287 @item --enable-readline
5288 Include support for command-line editing and history with the Bash
5289 version of the Readline library.
5291 @item --enable-restricted
5292 Include support for a @dfn{restricted shell}. If this is enabled, Bash,
5293 when called as @code{rbash}, enters a restricted mode. See
5294 @ref{The Restricted Shell}, for a description of restricted mode.
5296 @item --enable-select
5297 Include the @code{ksh} @code{select} builtin, which allows the
5298 generation of simple menus.
5300 @item --enable-usg-echo-default
5301 Make the @code{echo} builtin expand backslash-escaped characters by default,
5302 without requiring the @samp{-e} option. This makes the Bash @code{echo}
5303 behave more like the System V version.
5307 The file @file{config.h.top} contains C Preprocessor
5308 @samp{#define} statements for options which are not settable from
5310 Some of these are not meant to be changed; beware of the consequences if
5312 Read the comments associated with each definition for more
5313 information about its effect.
5315 @node Reporting Bugs
5316 @appendix Reporting Bugs
5318 Please report all bugs you find in Bash.
5319 But first, you should
5320 make sure that it really is a bug, and that it appears in the latest
5321 version of Bash that you have.
5323 Once you have determined that a bug actually exists, use the
5324 @code{bashbug} command to submit a bug report.
5325 If you have a fix, you are encouraged to mail that as well!
5326 Suggestions and `philosophical' bug reports may be mailed
5327 to @code{bug-bash@@prep.ai.MIT.Edu} or posted to the Usenet
5328 newsgroup @code{gnu.bash.bug}.
5330 All bug reports should include:
5333 The version number of Bash.
5335 The hardware and operating system.
5337 The compiler used to compile Bash.
5339 A description of the bug behaviour.
5341 A short script or `recipe' which exercises the bug and may be used
5346 @code{bashbug} inserts the first three items automatically into
5347 the template it provides for filing a bug report.
5349 Please send all reports concerning this manual to
5350 @code{chet@@ins.CWRU.Edu}.
5353 @appendix Index of Shell Builtin Commands
5356 @node Reserved Word Index
5357 @appendix Shell Reserved Words
5360 @node Variable Index
5361 @appendix Parameter and Variable Index
5364 @node Function Index
5365 @appendix Function Index
5369 @appendix Concept Index