1 This is bashref.info, produced by makeinfo version 4.13 from
2 /Users/chet/src/bash/src/doc/bashref.texi.
4 This text is a brief description of the features that are present in
5 the Bash shell (version 4.0, 29 December 2008).
7 This is Edition 4.0, last updated 29 December 2008, of `The GNU Bash
8 Reference Manual', for `Bash', Version 4.0.
10 Copyright (C) 1988-2009 Free Software Foundation, Inc.
12 Permission is granted to make and distribute verbatim copies of this
13 manual provided the copyright notice and this permission notice are
14 preserved on all copies.
16 Permission is granted to copy, distribute and/or modify this
17 document under the terms of the GNU Free Documentation License,
18 Version 1.2 or any later version published by the Free Software
19 Foundation; with no Invariant Sections, with the Front-Cover texts
20 being "A GNU Manual", and with the Back-Cover Texts as in (a)
21 below. A copy of the license is included in the section entitled
22 "GNU Free Documentation License".
24 (a) The FSF's Back-Cover Text is: You are free to copy and modify
25 this GNU manual. Buying copies from GNU Press supports the FSF in
26 developing GNU and promoting software freedom."
29 INFO-DIR-SECTION Basics
31 * Bash: (bash). The GNU Bourne-Again SHell.
35 File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
40 This text is a brief description of the features that are present in
41 the Bash shell (version 4.0, 29 December 2008).
43 This is Edition 4.0, last updated 29 December 2008, of `The GNU Bash
44 Reference Manual', for `Bash', Version 4.0.
46 Bash contains features that appear in other popular shells, and some
47 features that only appear in Bash. Some of the shells that Bash has
48 borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell
49 (`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The
50 following menu breaks the features up into categories based upon which
51 one of these other shells inspired the feature.
53 This manual is meant as a brief introduction to features found in
54 Bash. The Bash manual page should be used as the definitive reference
59 * Introduction:: An introduction to the shell.
60 * Definitions:: Some definitions used in the rest of this
62 * Basic Shell Features:: The shell "building blocks".
63 * Shell Builtin Commands:: Commands that are a part of the shell.
64 * Shell Variables:: Variables used or set by Bash.
65 * Bash Features:: Features found only in Bash.
66 * Job Control:: What job control is and how Bash allows you
68 * Command Line Editing:: Chapter describing the command line
70 * Using History Interactively:: Command History Expansion
71 * Installing Bash:: How to build and install Bash on your system.
72 * Reporting Bugs:: How to report bugs in Bash.
73 * Major Differences From The Bourne Shell:: A terse list of the differences
74 between Bash and historical
76 * GNU Free Documentation License:: Copying and sharing this documentation.
77 * Indexes:: Various indexes for this manual.
80 File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top
87 * What is Bash?:: A short description of Bash.
88 * What is a shell?:: A brief introduction to shells.
91 File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
96 Bash is the shell, or command language interpreter, for the GNU
97 operating system. The name is an acronym for the `Bourne-Again SHell',
98 a pun on Stephen Bourne, the author of the direct ancestor of the
99 current Unix shell `sh', which appeared in the Seventh Edition Bell
100 Labs Research version of Unix.
102 Bash is largely compatible with `sh' and incorporates useful
103 features from the Korn shell `ksh' and the C shell `csh'. It is
104 intended to be a conformant implementation of the IEEE POSIX Shell and
105 Tools portion of the IEEE POSIX specification (IEEE Standard 1003.1).
106 It offers functional improvements over `sh' for both interactive and
109 While the GNU operating system provides other shells, including a
110 version of `csh', Bash is the default shell. Like other GNU software,
111 Bash is quite portable. It currently runs on nearly every version of
112 Unix and a few other operating systems - independently-supported ports
113 exist for MS-DOS, OS/2, and Windows platforms.
116 File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
121 At its base, a shell is simply a macro processor that executes
122 commands. The term macro processor means functionality where text and
123 symbols are expanded to create larger expressions.
125 A Unix shell is both a command interpreter and a programming
126 language. As a command interpreter, the shell provides the user
127 interface to the rich set of GNU utilities. The programming language
128 features allow these utilities to be combined. Files containing
129 commands can be created, and become commands themselves. These new
130 commands have the same status as system commands in directories such as
131 `/bin', allowing users or groups to establish custom environments to
132 automate their common tasks.
134 Shells may be used interactively or non-interactively. In
135 interactive mode, they accept input typed from the keyboard. When
136 executing non-interactively, shells execute commands read from a file.
138 A shell allows execution of GNU commands, both synchronously and
139 asynchronously. The shell waits for synchronous commands to complete
140 before accepting more input; asynchronous commands continue to execute
141 in parallel with the shell while it reads and executes additional
142 commands. The "redirection" constructs permit fine-grained control of
143 the input and output of those commands. Moreover, the shell allows
144 control over the contents of commands' environments.
146 Shells also provide a small set of built-in commands ("builtins")
147 implementing functionality impossible or inconvenient to obtain via
148 separate utilities. For example, `cd', `break', `continue', and
149 `exec') cannot be implemented outside of the shell because they
150 directly manipulate the shell itself. The `history', `getopts',
151 `kill', or `pwd' builtins, among others, could be implemented in
152 separate utilities, but they are more convenient to use as builtin
153 commands. All of the shell builtins are described in subsequent
156 While executing commands is essential, most of the power (and
157 complexity) of shells is due to their embedded programming languages.
158 Like any high-level language, the shell provides variables, flow
159 control constructs, quoting, and functions.
161 Shells offer features geared specifically for interactive use rather
162 than to augment the programming language. These interactive features
163 include job control, command line editing, command history and aliases.
164 Each of these features is described in this manual.
167 File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
172 These definitions are used throughout the remainder of this manual.
175 A family of open system standards based on Unix. Bash is
176 primarily concerned with the Shell and Utilities portion of the
177 POSIX 1003.1 standard.
180 A space or tab character.
183 A command that is implemented internally by the shell itself,
184 rather than by an executable program somewhere in the file system.
187 A `token' that performs a control function. It is a `newline' or
188 one of the following: `||', `&&', `&', `;', `;;', `|', `|&', `(',
192 The value returned by a command to its caller. The value is
193 restricted to eight bits, so the maximum value is 255.
196 A unit of text that is the result of one of the shell expansions.
197 After expansion, when executing a command, the resulting fields
198 are used as the command name and arguments.
201 A string of characters used to identify a file.
204 A set of processes comprising a pipeline, and any processes
205 descended from it, that are all in the same process group.
208 A mechanism by which users can selectively stop (suspend) and
209 restart (resume) execution of processes.
212 A character that, when unquoted, separates words. A metacharacter
213 is a `blank' or one of the following characters: `|', `&', `;',
214 `(', `)', `<', or `>'.
217 A `word' consisting solely of letters, numbers, and underscores,
218 and beginning with a letter or underscore. `Name's are used as
219 shell variable and function names. Also referred to as an
223 A `control operator' or a `redirection operator'. *Note
224 Redirections::, for a list of redirection operators. Operators
225 contain at least one unquoted `metacharacter'.
228 A collection of related processes each having the same process
232 A unique identifier that represents a `process group' during its
236 A `word' that has a special meaning to the shell. Most reserved
237 words introduce shell flow control constructs, such as `for' and
241 A synonym for `exit status'.
244 A mechanism by which a process may be notified by the kernel of an
245 event occurring in the system.
248 A shell builtin command that has been classified as special by the
252 A sequence of characters considered a single unit by the shell.
253 It is either a `word' or an `operator'.
256 A sequence of characters treated as a unit by the shell. Words
257 may not include unquoted `metacharacters'.
260 File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
262 3 Basic Shell Features
263 **********************
265 Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is the
266 traditional Unix shell originally written by Stephen Bourne. All of
267 the Bourne shell builtin commands are available in Bash, The rules for
268 evaluation and quoting are taken from the POSIX specification for the
269 `standard' Unix shell.
271 This chapter briefly summarizes the shell's `building blocks':
272 commands, control structures, shell functions, shell parameters, shell
273 expansions, redirections, which are a way to direct input and output
274 from and to named files, and how the shell executes commands.
278 * Shell Syntax:: What your input means to the shell.
279 * Shell Commands:: The types of commands you can use.
280 * Shell Functions:: Grouping commands by name.
281 * Shell Parameters:: How the shell stores values.
282 * Shell Expansions:: How Bash expands parameters and the various
283 expansions available.
284 * Redirections:: A way to control where input and output go.
285 * Executing Commands:: What happens when you run a command.
286 * Shell Scripts:: Executing files of shell commands.
289 File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
296 * Shell Operation:: The basic operation of the shell.
297 * Quoting:: How to remove the special meaning from characters.
298 * Comments:: How to specify comments.
300 When the shell reads input, it proceeds through a sequence of
301 operations. If the input indicates the beginning of a comment, the
302 shell ignores the comment symbol (`#'), and the rest of that line.
304 Otherwise, roughly speaking, the shell reads its input and divides
305 the input into words and operators, employing the quoting rules to
306 select which meanings to assign various words and characters.
308 The shell then parses these tokens into commands and other
309 constructs, removes the special meaning of certain words or characters,
310 expands others, redirects input and output as needed, executes the
311 specified command, waits for the command's exit status, and makes that
312 exit status available for further inspection or processing.
315 File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
317 3.1.1 Shell Operation
318 ---------------------
320 The following is a brief description of the shell's operation when it
321 reads and executes a command. Basically, the shell does the following:
323 1. Reads its input from a file (*note Shell Scripts::), from a string
324 supplied as an argument to the `-c' invocation option (*note
325 Invoking Bash::), or from the user's terminal.
327 2. Breaks the input into words and operators, obeying the quoting
328 rules described in *note Quoting::. These tokens are separated by
329 `metacharacters'. Alias expansion is performed by this step
332 3. Parses the tokens into simple and compound commands (*note Shell
335 4. Performs the various shell expansions (*note Shell Expansions::),
336 breaking the expanded tokens into lists of filenames (*note
337 Filename Expansion::) and commands and arguments.
339 5. Performs any necessary redirections (*note Redirections::) and
340 removes the redirection operators and their operands from the
343 6. Executes the command (*note Executing Commands::).
345 7. Optionally waits for the command to complete and collects its exit
346 status (*note Exit Status::).
350 File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
357 * Escape Character:: How to remove the special meaning from a single
359 * Single Quotes:: How to inhibit all interpretation of a sequence
361 * Double Quotes:: How to suppress most of the interpretation of a
362 sequence of characters.
363 * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
364 * Locale Translation:: How to translate strings into different languages.
366 Quoting is used to remove the special meaning of certain characters
367 or words to the shell. Quoting can be used to disable special
368 treatment for special characters, to prevent reserved words from being
369 recognized as such, and to prevent parameter expansion.
371 Each of the shell metacharacters (*note Definitions::) has special
372 meaning to the shell and must be quoted if it is to represent itself.
373 When the command history expansion facilities are being used (*note
374 History Interaction::), the HISTORY EXPANSION character, usually `!',
375 must be quoted to prevent history expansion. *Note Bash History
376 Facilities::, for more details concerning history expansion.
378 There are three quoting mechanisms: the ESCAPE CHARACTER, single
379 quotes, and double quotes.
382 File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
384 3.1.2.1 Escape Character
385 ........................
387 A non-quoted backslash `\' is the Bash escape character. It preserves
388 the literal value of the next character that follows, with the
389 exception of `newline'. If a `\newline' pair appears, and the
390 backslash itself is not quoted, the `\newline' is treated as a line
391 continuation (that is, it is removed from the input stream and
392 effectively ignored).
395 File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
397 3.1.2.2 Single Quotes
398 .....................
400 Enclosing characters in single quotes (`'') preserves the literal value
401 of each character within the quotes. A single quote may not occur
402 between single quotes, even when preceded by a backslash.
405 File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
407 3.1.2.3 Double Quotes
408 .....................
410 Enclosing characters in double quotes (`"') preserves the literal value
411 of all characters within the quotes, with the exception of `$', ``',
412 `\', and, when history expansion is enabled, `!'. The characters `$'
413 and ``' retain their special meaning within double quotes (*note Shell
414 Expansions::). The backslash retains its special meaning only when
415 followed by one of the following characters: `$', ``', `"', `\', or
416 `newline'. Within double quotes, backslashes that are followed by one
417 of these characters are removed. Backslashes preceding characters
418 without a special meaning are left unmodified. A double quote may be
419 quoted within double quotes by preceding it with a backslash. If
420 enabled, history expansion will be performed unless an `!' appearing in
421 double quotes is escaped using a backslash. The backslash preceding
422 the `!' is not removed.
424 The special parameters `*' and `@' have special meaning when in
425 double quotes (*note Shell Parameter Expansion::).
428 File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
430 3.1.2.4 ANSI-C Quoting
431 ......................
433 Words of the form `$'STRING'' are treated specially. The word expands
434 to STRING, with backslash-escaped characters replaced as specified by
435 the ANSI C standard. Backslash escape sequences, if present, are
445 an escape character (not ANSI C)
469 the eight-bit character whose value is the octal value NNN (one to
473 the eight-bit character whose value is the hexadecimal value HH
474 (one or two hex digits)
477 a control-X character
479 The expanded result is single-quoted, as if the dollar sign had not
483 File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
485 3.1.2.5 Locale-Specific Translation
486 ...................................
488 A double-quoted string preceded by a dollar sign (`$') will cause the
489 string to be translated according to the current locale. If the
490 current locale is `C' or `POSIX', the dollar sign is ignored. If the
491 string is translated and replaced, the replacement is double-quoted.
493 Some systems use the message catalog selected by the `LC_MESSAGES'
494 shell variable. Others create the name of the message catalog from the
495 value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
496 `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the
497 `TEXTDOMAINDIR' variable to the location of the message catalog files.
498 Still others use both variables in this fashion:
499 `TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.
502 File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
507 In a non-interactive shell, or an interactive shell in which the
508 `interactive_comments' option to the `shopt' builtin is enabled (*note
509 The Shopt Builtin::), a word beginning with `#' causes that word and
510 all remaining characters on that line to be ignored. An interactive
511 shell without the `interactive_comments' option enabled does not allow
512 comments. The `interactive_comments' option is on by default in
513 interactive shells. *Note Interactive Shells::, for a description of
514 what makes a shell interactive.
517 File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
522 A simple shell command such as `echo a b c' consists of the command
523 itself followed by arguments, separated by spaces.
525 More complex shell commands are composed of simple commands arranged
526 together in a variety of ways: in a pipeline in which the output of one
527 command becomes the input of a second, in a loop or conditional
528 construct, or in some other grouping.
532 * Simple Commands:: The most common type of command.
533 * Pipelines:: Connecting the input and output of several
535 * Lists:: How to execute commands sequentially.
536 * Compound Commands:: Shell commands for control flow.
537 * Coprocesses:: Two-way communication between commands.
540 File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
542 3.2.1 Simple Commands
543 ---------------------
545 A simple command is the kind of command encountered most often. It's
546 just a sequence of words separated by `blank's, terminated by one of
547 the shell's control operators (*note Definitions::). The first word
548 generally specifies a command to be executed, with the rest of the
549 words being that command's arguments.
551 The return status (*note Exit Status::) of a simple command is its
552 exit status as provided by the POSIX 1003.1 `waitpid' function, or
553 128+N if the command was terminated by signal N.
556 File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
561 A `pipeline' is a sequence of simple commands separated by one of the
562 control operators `|' or `|&'.
564 The format for a pipeline is
565 [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...]
567 The output of each command in the pipeline is connected via a pipe to
568 the input of the next command. That is, each command reads the
569 previous command's output. This connection is performed before any
570 redirections specified by the command.
572 If `|&' is used, the standard error of COMMAND1 is connected to
573 COMMAND2's standard input through the pipe; it is shorthand for `2>&1
574 |'. This implicit redirection of the standard error is performed after
575 any redirections specified by the command.
577 The reserved word `time' causes timing statistics to be printed for
578 the pipeline once it finishes. The statistics currently consist of
579 elapsed (wall-clock) time and user and system time consumed by the
580 command's execution. The `-p' option changes the output format to that
581 specified by POSIX. The `TIMEFORMAT' variable may be set to a format
582 string that specifies how the timing information should be displayed.
583 *Note Bash Variables::, for a description of the available formats.
584 The use of `time' as a reserved word permits the timing of shell
585 builtins, shell functions, and pipelines. An external `time' command
586 cannot time these easily.
588 If the pipeline is not executed asynchronously (*note Lists::), the
589 shell waits for all commands in the pipeline to complete.
591 Each command in a pipeline is executed in its own subshell (*note
592 Command Execution Environment::). The exit status of a pipeline is the
593 exit status of the last command in the pipeline, unless the `pipefail'
594 option is enabled (*note The Set Builtin::). If `pipefail' is enabled,
595 the pipeline's return status is the value of the last (rightmost)
596 command to exit with a non-zero status, or zero if all commands exit
597 successfully. If the reserved word `!' precedes the pipeline, the exit
598 status is the logical negation of the exit status as described above.
599 The shell waits for all commands in the pipeline to terminate before
603 File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
605 3.2.3 Lists of Commands
606 -----------------------
608 A `list' is a sequence of one or more pipelines separated by one of the
609 operators `;', `&', `&&', or `||', and optionally terminated by one of
610 `;', `&', or a `newline'.
612 Of these list operators, `&&' and `||' have equal precedence,
613 followed by `;' and `&', which have equal precedence.
615 A sequence of one or more newlines may appear in a `list' to delimit
616 commands, equivalent to a semicolon.
618 If a command is terminated by the control operator `&', the shell
619 executes the command asynchronously in a subshell. This is known as
620 executing the command in the BACKGROUND. The shell does not wait for
621 the command to finish, and the return status is 0 (true). When job
622 control is not active (*note Job Control::), the standard input for
623 asynchronous commands, in the absence of any explicit redirections, is
624 redirected from `/dev/null'.
626 Commands separated by a `;' are executed sequentially; the shell
627 waits for each command to terminate in turn. The return status is the
628 exit status of the last command executed.
630 AND and OR lists are sequences of one or more pipelines separated by
631 the control operators `&&' and `||', respectively. AND and OR lists
632 are executed with left associativity.
634 An AND list has the form
637 COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
640 An OR list has the form
643 COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
646 The return status of AND and OR lists is the exit status of the last
647 command executed in the list.
650 File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
652 3.2.4 Compound Commands
653 -----------------------
657 * Looping Constructs:: Shell commands for iterative action.
658 * Conditional Constructs:: Shell commands for conditional execution.
659 * Command Grouping:: Ways to group commands.
661 Compound commands are the shell programming constructs. Each
662 construct begins with a reserved word or control operator and is
663 terminated by a corresponding reserved word or operator. Any
664 redirections (*note Redirections::) associated with a compound command
665 apply to all commands within that compound command unless explicitly
668 Bash provides looping constructs, conditional commands, and
669 mechanisms to group commands and execute them as a unit.
672 File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
674 3.2.4.1 Looping Constructs
675 ..........................
677 Bash supports the following looping constructs.
679 Note that wherever a `;' appears in the description of a command's
680 syntax, it may be replaced with one or more newlines.
683 The syntax of the `until' command is:
684 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
685 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
686 status which is not zero. The return status is the exit status of
687 the last command executed in CONSEQUENT-COMMANDS, or zero if none
691 The syntax of the `while' command is:
692 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
694 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
695 status of zero. The return status is the exit status of the last
696 command executed in CONSEQUENT-COMMANDS, or zero if none was
700 The syntax of the `for' command is:
702 for NAME [in WORDS ...]; do COMMANDS; done
703 Expand WORDS, and execute COMMANDS once for each member in the
704 resultant list, with NAME bound to the current member. If `in
705 WORDS' is not present, the `for' command executes the COMMANDS
706 once for each positional parameter that is set, as if `in "$@"'
707 had been specified (*note Special Parameters::). The return
708 status is the exit status of the last command that executes. If
709 there are no items in the expansion of WORDS, no commands are
710 executed, and the return status is zero.
712 An alternate form of the `for' command is also supported:
714 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
715 First, the arithmetic expression EXPR1 is evaluated according to
716 the rules described below (*note Shell Arithmetic::). The
717 arithmetic expression EXPR2 is then evaluated repeatedly until it
718 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
719 COMMANDS are executed and the arithmetic expression EXPR3 is
720 evaluated. If any expression is omitted, it behaves as if it
721 evaluates to 1. The return value is the exit status of the last
722 command in LIST that is executed, or false if any of the
723 expressions is invalid.
726 The `break' and `continue' builtins (*note Bourne Shell Builtins::)
727 may be used to control loop execution.
730 File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
732 3.2.4.2 Conditional Constructs
733 ..............................
736 The syntax of the `if' command is:
738 if TEST-COMMANDS; then
740 [elif MORE-TEST-COMMANDS; then
742 [else ALTERNATE-CONSEQUENTS;]
745 The TEST-COMMANDS list is executed, and if its return status is
746 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
747 returns a non-zero status, each `elif' list is executed in turn,
748 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
749 is executed and the command completes. If `else
750 ALTERNATE-CONSEQUENTS' is present, and the final command in the
751 final `if' or `elif' clause has a non-zero exit status, then
752 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
753 status of the last command executed, or zero if no condition
757 The syntax of the `case' command is:
759 `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
761 `case' will selectively execute the COMMAND-LIST corresponding to
762 the first PATTERN that matches WORD. If the shell option
763 `nocasematch' (see the description of `shopt' in *note The Shopt
764 Builtin::) is enabled, the match is performed without regard to
765 the case of alphabetic characters. The `|' is used to separate
766 multiple patterns, and the `)' operator terminates a pattern list.
767 A list of patterns and an associated command-list is known as a
770 Each clause must be terminated with `;;', `,&', or `;;&'. The
771 WORD undergoes tilde expansion, parameter expansion, command
772 substitution, arithmetic expansion, and quote removal before
773 matching is attempted. Each PATTERN undergoes tilde expansion,
774 parameter expansion, command substitution, and arithmetic
777 There may be an arbitrary number of `case' clauses, each terminated
778 by a `;;', `;&', or `;;&'. The first pattern that matches
779 determines the command-list that is executed.
781 Here is an example using `case' in a script that could be used to
782 describe one interesting feature of an animal:
784 echo -n "Enter the name of an animal: "
786 echo -n "The $ANIMAL has "
788 horse | dog | cat) echo -n "four";;
789 man | kangaroo ) echo -n "two";;
790 *) echo -n "an unknown number of";;
794 If the `;;' operator is used, no subsequent matches are attempted
795 after the first pattern match. Using `;&' in place of `;;'
796 causes execution to continue with the COMMAND-LIST associated with
797 the next clause, if any. Using `;;&' in place of `;;' causes the
798 shell to test the patterns in the next clause, if any, and execute
799 any associated COMMAND-LIST on a successful match.
801 The return status is zero if no PATTERN is matched. Otherwise, the
802 return status is the exit status of the COMMAND-LIST executed.
805 The `select' construct allows the easy generation of menus. It
806 has almost the same syntax as the `for' command:
808 select NAME [in WORDS ...]; do COMMANDS; done
810 The list of words following `in' is expanded, generating a list of
811 items. The set of expanded words is printed on the standard error
812 output stream, each preceded by a number. If the `in WORDS' is
813 omitted, the positional parameters are printed, as if `in "$@"'
814 had been specified. The `PS3' prompt is then displayed and a line
815 is read from the standard input. If the line consists of a number
816 corresponding to one of the displayed words, then the value of
817 NAME is set to that word. If the line is empty, the words and
818 prompt are displayed again. If `EOF' is read, the `select'
819 command completes. Any other value read causes NAME to be set to
820 null. The line read is saved in the variable `REPLY'.
822 The COMMANDS are executed after each selection until a `break'
823 command is executed, at which point the `select' command completes.
825 Here is an example that allows the user to pick a filename from the
826 current directory, and displays the name and index of the file
831 echo you picked $fname \($REPLY\)
838 The arithmetic EXPRESSION is evaluated according to the rules
839 described below (*note Shell Arithmetic::). If the value of the
840 expression is non-zero, the return status is 0; otherwise the
841 return status is 1. This is exactly equivalent to
843 *Note Bash Builtins::, for a full description of the `let' builtin.
848 Return a status of 0 or 1 depending on the evaluation of the
849 conditional expression EXPRESSION. Expressions are composed of
850 the primaries described below in *note Bash Conditional
851 Expressions::. Word splitting and filename expansion are not
852 performed on the words between the `[[' and `]]'; tilde expansion,
853 parameter and variable expansion, arithmetic expansion, command
854 substitution, process substitution, and quote removal are
855 performed. Conditional operators such as `-f' must be unquoted to
856 be recognized as primaries.
858 When the `==' and `!=' operators are used, the string to the right
859 of the operator is considered a pattern and matched according to
860 the rules described below in *note Pattern Matching::. If the
861 shell option `nocasematch' (see the description of `shopt' in
862 *note The Shopt Builtin::) is enabled, the match is performed
863 without regard to the case of alphabetic characters. The return
864 value is 0 if the string matches (`==') or does not match
865 (`!=')the pattern, and 1 otherwise. Any part of the pattern may
866 be quoted to force it to be matched as a string.
868 An additional binary operator, `=~', is available, with the same
869 precedence as `==' and `!='. When it is used, the string to the
870 right of the operator is considered an extended regular expression
871 and matched accordingly (as in regex3)). The return value is 0 if
872 the string matches the pattern, and 1 otherwise. If the regular
873 expression is syntactically incorrect, the conditional
874 expression's return value is 2. If the shell option `nocasematch'
875 (see the description of `shopt' in *note The Shopt Builtin::) is
876 enabled, the match is performed without regard to the case of
877 alphabetic characters. Any part of the pattern may be quoted to
878 force it to be matched as a string. Substrings matched by
879 parenthesized subexpressions within the regular expression are
880 saved in the array variable `BASH_REMATCH'. The element of
881 `BASH_REMATCH' with index 0 is the portion of the string matching
882 the entire regular expression. The element of `BASH_REMATCH' with
883 index N is the portion of the string matching the Nth
884 parenthesized subexpression.
886 Expressions may be combined using the following operators, listed
887 in decreasing order of precedence:
890 Returns the value of EXPRESSION. This may be used to
891 override the normal precedence of operators.
894 True if EXPRESSION is false.
896 `EXPRESSION1 && EXPRESSION2'
897 True if both EXPRESSION1 and EXPRESSION2 are true.
899 `EXPRESSION1 || EXPRESSION2'
900 True if either EXPRESSION1 or EXPRESSION2 is true.
901 The `&&' and `||' operators do not evaluate EXPRESSION2 if the
902 value of EXPRESSION1 is sufficient to determine the return value
903 of the entire conditional expression.
907 File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
909 3.2.4.3 Grouping Commands
910 .........................
912 Bash provides two ways to group a list of commands to be executed as a
913 unit. When commands are grouped, redirections may be applied to the
914 entire command list. For example, the output of all the commands in
915 the list may be redirected to a single stream.
920 Placing a list of commands between parentheses causes a subshell
921 environment to be created (*note Command Execution Environment::),
922 and each of the commands in LIST to be executed in that subshell.
923 Since the LIST is executed in a subshell, variable assignments do
924 not remain in effect after the subshell completes.
929 Placing a list of commands between curly braces causes the list to
930 be executed in the current shell context. No subshell is created.
931 The semicolon (or newline) following LIST is required.
933 In addition to the creation of a subshell, there is a subtle
934 difference between these two constructs due to historical reasons. The
935 braces are `reserved words', so they must be separated from the LIST by
936 `blank's or other shell metacharacters. The parentheses are
937 `operators', and are recognized as separate tokens by the shell even if
938 they are not separated from the LIST by whitespace.
940 The exit status of both of these constructs is the exit status of
944 File: bashref.info, Node: Coprocesses, Prev: Compound Commands, Up: Shell Commands
949 A `coprocess' is a shell command preceded by the `coproc' reserved word.
950 A coprocess is executed asynchronously in a subshell, as if the command
951 had been terminated with the `&' control operator, with a two-way pipe
952 established between the executing shell and the coprocess.
954 The format for a coprocess is:
955 `coproc' [NAME] COMMAND [REDIRECTIONS]
957 This creates a coprocess named NAME. If NAME is not supplied, the
958 default name is COPROC. NAME must not be supplied if COMMAND is a
959 simple command (*note Simple Commands::); otherwise, it is interpreted
960 as the first word of the simple command.
962 When the coproc is executed, the shell creates an array variable
963 (*note Arrays::) named NAME in the context of the executing shell. The
964 standard output of COMMAND is connected via a pipe to a file descriptor
965 in the executing shell, and that file descriptor is assigned to NAME[0].
966 The standard input of COMMAND is connected via a pipe to a file
967 descriptor in the executing shell, and that file descriptor is assigned
968 to NAME[1]. This pipe is established before any redirections specified
969 by the command (*note Redirections::). The file descriptors can be
970 utilized as arguments to shell commands and redirections using standard
973 The process id of the shell spawned to execute the coprocess is
974 available as the value of the variable NAME_PID. The `wait' builtin
975 command may be used to wait for the coprocess to terminate.
977 The return status of a coprocess is the exit status of COMMAND.
980 File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
985 Shell functions are a way to group commands for later execution using a
986 single name for the group. They are executed just like a "regular"
987 command. When the name of a shell function is used as a simple command
988 name, the list of commands associated with that function name is
989 executed. Shell functions are executed in the current shell context;
990 no new process is created to interpret them.
992 Functions are declared using this syntax:
993 [ `function' ] NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
995 This defines a shell function named NAME. The reserved word
996 `function' is optional. If the `function' reserved word is supplied,
997 the parentheses are optional. The BODY of the function is the compound
998 command COMPOUND-COMMAND (*note Compound Commands::). That command is
999 usually a LIST enclosed between { and }, but may be any compound
1000 command listed above. COMPOUND-COMMAND is executed whenever NAME is
1001 specified as the name of a command. Any redirections (*note
1002 Redirections::) associated with the shell function are performed when
1003 the function is executed.
1005 A function definition may be deleted using the `-f' option to the
1006 `unset' builtin (*note Bourne Shell Builtins::).
1008 The exit status of a function definition is zero unless a syntax
1009 error occurs or a readonly function with the same name already exists.
1010 When executed, the exit status of a function is the exit status of the
1011 last command executed in the body.
1013 Note that for historical reasons, in the most common usage the curly
1014 braces that surround the body of the function must be separated from
1015 the body by `blank's or newlines. This is because the braces are
1016 reserved words and are only recognized as such when they are separated
1017 from the command list by whitespace or another shell metacharacter.
1018 Also, when using the braces, the LIST must be terminated by a semicolon,
1019 a `&', or a newline.
1021 When a function is executed, the arguments to the function become
1022 the positional parameters during its execution (*note Positional
1023 Parameters::). The special parameter `#' that expands to the number of
1024 positional parameters is updated to reflect the change. Special
1025 parameter `0' is unchanged. The first element of the `FUNCNAME'
1026 variable is set to the name of the function while the function is
1027 executing. All other aspects of the shell execution environment are
1028 identical between a function and its caller with the exception that the
1029 `DEBUG' and `RETURN' traps are not inherited unless the function has
1030 been given the `trace' attribute using the `declare' builtin or the `-o
1031 functrace' option has been enabled with the `set' builtin, (in which
1032 case all functions inherit the `DEBUG' and `RETURN' traps). *Note
1033 Bourne Shell Builtins::, for the description of the `trap' builtin.
1035 If the builtin command `return' is executed in a function, the
1036 function completes and execution resumes with the next command after
1037 the function call. Any command associated with the `RETURN' trap is
1038 executed before execution resumes. When a function completes, the
1039 values of the positional parameters and the special parameter `#' are
1040 restored to the values they had prior to the function's execution. If
1041 a numeric argument is given to `return', that is the function's return
1042 status; otherwise the function's return status is the exit status of
1043 the last command executed before the `return'.
1045 Variables local to the function may be declared with the `local'
1046 builtin. These variables are visible only to the function and the
1047 commands it invokes.
1049 Function names and definitions may be listed with the `-f' option to
1050 the `declare' or `typeset' builtin commands (*note Bash Builtins::).
1051 The `-F' option to `declare' or `typeset' will list the function names
1052 only (and optionally the source file and line number, if the `extdebug'
1053 shell option is enabled). Functions may be exported so that subshells
1054 automatically have them defined with the `-f' option to the `export'
1055 builtin (*note Bourne Shell Builtins::). Note that shell functions and
1056 variables with the same name may result in multiple identically-named
1057 entries in the environment passed to the shell's children. Care should
1058 be taken in cases where this may cause a problem.
1060 Functions may be recursive. No limit is placed on the number of
1064 File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1066 3.4 Shell Parameters
1067 ====================
1071 * Positional Parameters:: The shell's command-line arguments.
1072 * Special Parameters:: Parameters denoted by special characters.
1074 A PARAMETER is an entity that stores values. It can be a `name', a
1075 number, or one of the special characters listed below. A VARIABLE is a
1076 parameter denoted by a `name'. A variable has a VALUE and zero or more
1077 ATTRIBUTES. Attributes are assigned using the `declare' builtin command
1078 (see the description of the `declare' builtin in *note Bash Builtins::).
1080 A parameter is set if it has been assigned a value. The null string
1081 is a valid value. Once a variable is set, it may be unset only by using
1082 the `unset' builtin command.
1084 A variable may be assigned to by a statement of the form
1086 If VALUE is not given, the variable is assigned the null string. All
1087 VALUEs undergo tilde expansion, parameter and variable expansion,
1088 command substitution, arithmetic expansion, and quote removal (detailed
1089 below). If the variable has its `integer' attribute set, then VALUE is
1090 evaluated as an arithmetic expression even if the `$((...))' expansion
1091 is not used (*note Arithmetic Expansion::). Word splitting is not
1092 performed, with the exception of `"$@"' as explained below. Filename
1093 expansion is not performed. Assignment statements may also appear as
1094 arguments to the `alias', `declare', `typeset', `export', `readonly',
1095 and `local' builtin commands.
1097 In the context where an assignment statement is assigning a value to
1098 a shell variable or array index (*note Arrays::), the `+=' operator can
1099 be used to append to or add to the variable's previous value. When
1100 `+=' is applied to a variable for which the integer attribute has been
1101 set, VALUE is evaluated as an arithmetic expression and added to the
1102 variable's current value, which is also evaluated. When `+=' is
1103 applied to an array variable using compound assignment (*note
1104 Arrays::), the variable's value is not unset (as it is when using `='),
1105 and new values are appended to the array beginning at one greater than
1106 the array's maximum index (for indexed arrays), or added as additional
1107 key-value pairs in an associative array. When applied to a
1108 string-valued variable, VALUE is expanded and appended to the
1112 File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1114 3.4.1 Positional Parameters
1115 ---------------------------
1117 A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
1118 other than the single digit `0'. Positional parameters are assigned
1119 from the shell's arguments when it is invoked, and may be reassigned
1120 using the `set' builtin command. Positional parameter `N' may be
1121 referenced as `${N}', or as `$N' when `N' consists of a single digit.
1122 Positional parameters may not be assigned to with assignment statements.
1123 The `set' and `shift' builtins are used to set and unset them (*note
1124 Shell Builtin Commands::). The positional parameters are temporarily
1125 replaced when a shell function is executed (*note Shell Functions::).
1127 When a positional parameter consisting of more than a single digit
1128 is expanded, it must be enclosed in braces.
1131 File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1133 3.4.2 Special Parameters
1134 ------------------------
1136 The shell treats several parameters specially. These parameters may
1137 only be referenced; assignment to them is not allowed.
1140 Expands to the positional parameters, starting from one. When the
1141 expansion occurs within double quotes, it expands to a single word
1142 with the value of each parameter separated by the first character
1143 of the `IFS' special variable. That is, `"$*"' is equivalent to
1144 `"$1C$2C..."', where C is the first character of the value of the
1145 `IFS' variable. If `IFS' is unset, the parameters are separated
1146 by spaces. If `IFS' is null, the parameters are joined without
1147 intervening separators.
1150 Expands to the positional parameters, starting from one. When the
1151 expansion occurs within double quotes, each parameter expands to a
1152 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
1153 If the double-quoted expansion occurs within a word, the expansion
1154 of the first parameter is joined with the beginning part of the
1155 original word, and the expansion of the last parameter is joined
1156 with the last part of the original word. When there are no
1157 positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
1161 Expands to the number of positional parameters in decimal.
1164 Expands to the exit status of the most recently executed foreground
1168 (A hyphen.) Expands to the current option flags as specified upon
1169 invocation, by the `set' builtin command, or those set by the
1170 shell itself (such as the `-i' option).
1173 Expands to the process ID of the shell. In a `()' subshell, it
1174 expands to the process ID of the invoking shell, not the subshell.
1177 Expands to the process ID of the most recently executed background
1178 (asynchronous) command.
1181 Expands to the name of the shell or shell script. This is set at
1182 shell initialization. If Bash is invoked with a file of commands
1183 (*note Shell Scripts::), `$0' is set to the name of that file. If
1184 Bash is started with the `-c' option (*note Invoking Bash::), then
1185 `$0' is set to the first argument after the string to be executed,
1186 if one is present. Otherwise, it is set to the filename used to
1187 invoke Bash, as given by argument zero.
1190 (An underscore.) At shell startup, set to the absolute pathname
1191 used to invoke the shell or shell script being executed as passed
1192 in the environment or argument list. Subsequently, expands to the
1193 last argument to the previous command, after expansion. Also set
1194 to the full pathname used to invoke each command executed and
1195 placed in the environment exported to that command. When checking
1196 mail, this parameter holds the name of the mail file.
1199 File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1201 3.5 Shell Expansions
1202 ====================
1204 Expansion is performed on the command line after it has been split into
1205 `token's. There are seven kinds of expansion performed:
1210 * parameter and variable expansion
1212 * command substitution
1214 * arithmetic expansion
1218 * filename expansion
1222 * Brace Expansion:: Expansion of expressions within braces.
1223 * Tilde Expansion:: Expansion of the ~ character.
1224 * Shell Parameter Expansion:: How Bash expands variables to their values.
1225 * Command Substitution:: Using the output of a command as an argument.
1226 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
1227 * Process Substitution:: A way to write and read to and from a
1229 * Word Splitting:: How the results of expansion are split into separate
1231 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
1232 * Quote Removal:: How and when quote characters are removed from
1235 The order of expansions is: brace expansion, tilde expansion,
1236 parameter, variable, and arithmetic expansion and command substitution
1237 (done in a left-to-right fashion), word splitting, and filename
1240 On systems that can support it, there is an additional expansion
1241 available: PROCESS SUBSTITUTION. This is performed at the same time as
1242 parameter, variable, and arithmetic expansion and command substitution.
1244 Only brace expansion, word splitting, and filename expansion can
1245 change the number of words of the expansion; other expansions expand a
1246 single word to a single word. The only exceptions to this are the
1247 expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
1250 After all expansions, `quote removal' (*note Quote Removal::) is
1254 File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1256 3.5.1 Brace Expansion
1257 ---------------------
1259 Brace expansion is a mechanism by which arbitrary strings may be
1260 generated. This mechanism is similar to FILENAME EXPANSION (*note
1261 Filename Expansion::), but the file names generated need not exist.
1262 Patterns to be brace expanded take the form of an optional PREAMBLE,
1263 followed by either a series of comma-separated strings or a seqeunce
1264 expression between a pair of braces, followed by an optional POSTSCRIPT.
1265 The preamble is prefixed to each string contained within the braces, and
1266 the postscript is then appended to each resulting string, expanding left
1269 Brace expansions may be nested. The results of each expanded string
1270 are not sorted; left to right order is preserved. For example,
1271 bash$ echo a{d,c,b}e
1274 A sequence expression takes the form `{X..Y[INCR]}', where X and Y
1275 are either integers or single characters, and INCR, an optional
1276 increment, is an integer. When integers are supplied, the expression
1277 expands to each number between X and Y, inclusive. Supplied integers
1278 may be prefixed with `0' to force each term to have the same width.
1279 When either X or Y begins with a zero, the shell attempts to force all
1280 generated terms to contain the same number of digits, zero-padding
1281 where necessary. When characters are supplied, the expression expands
1282 to each character lexicographically between X and Y, inclusive. Note
1283 that both X and Y must be of the same type. When the increment is
1284 supplied, it is used as the difference between each term. The default
1285 increment is 1 or -1 as appropriate.
1287 Brace expansion is performed before any other expansions, and any
1288 characters special to other expansions are preserved in the result. It
1289 is strictly textual. Bash does not apply any syntactic interpretation
1290 to the context of the expansion or the text between the braces. To
1291 avoid conflicts with parameter expansion, the string `${' is not
1292 considered eligible for brace expansion.
1294 A correctly-formed brace expansion must contain unquoted opening and
1295 closing braces, and at least one unquoted comma or a valid sequence
1296 expression. Any incorrectly formed brace expansion is left unchanged.
1298 A { or `,' may be quoted with a backslash to prevent its being
1299 considered part of a brace expression. To avoid conflicts with
1300 parameter expansion, the string `${' is not considered eligible for
1303 This construct is typically used as shorthand when the common prefix
1304 of the strings to be generated is longer than in the above example:
1305 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1307 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1310 File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1312 3.5.2 Tilde Expansion
1313 ---------------------
1315 If a word begins with an unquoted tilde character (`~'), all of the
1316 characters up to the first unquoted slash (or all characters, if there
1317 is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1318 characters in the tilde-prefix are quoted, the characters in the
1319 tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1320 If this login name is the null string, the tilde is replaced with the
1321 value of the `HOME' shell variable. If `HOME' is unset, the home
1322 directory of the user executing the shell is substituted instead.
1323 Otherwise, the tilde-prefix is replaced with the home directory
1324 associated with the specified login name.
1326 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1327 replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1328 the shell variable `OLDPWD', if it is set, is substituted.
1330 If the characters following the tilde in the tilde-prefix consist of
1331 a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1332 replaced with the corresponding element from the directory stack, as it
1333 would be displayed by the `dirs' builtin invoked with the characters
1334 following tilde in the tilde-prefix as an argument (*note The Directory
1335 Stack::). If the tilde-prefix, sans the tilde, consists of a number
1336 without a leading `+' or `-', `+' is assumed.
1338 If the login name is invalid, or the tilde expansion fails, the word
1341 Each variable assignment is checked for unquoted tilde-prefixes
1342 immediately following a `:' or the first `='. In these cases, tilde
1343 expansion is also performed. Consequently, one may use file names with
1344 tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
1345 shell assigns the expanded value.
1347 The following table shows how Bash treats unquoted tilde-prefixes:
1350 The value of `$HOME'
1356 The subdirectory `foo' of the home directory of the user `fred'
1362 `${OLDPWD-'~-'}/foo'
1365 The string that would be displayed by `dirs +N'
1368 The string that would be displayed by `dirs +N'
1371 The string that would be displayed by `dirs -N'
1375 File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1377 3.5.3 Shell Parameter Expansion
1378 -------------------------------
1380 The `$' character introduces parameter expansion, command substitution,
1381 or arithmetic expansion. The parameter name or symbol to be expanded
1382 may be enclosed in braces, which are optional but serve to protect the
1383 variable to be expanded from characters immediately following it which
1384 could be interpreted as part of the name.
1386 When braces are used, the matching ending brace is the first `}' not
1387 escaped by a backslash or within a quoted string, and not within an
1388 embedded arithmetic expansion, command substitution, or parameter
1391 The basic form of parameter expansion is ${PARAMETER}. The value of
1392 PARAMETER is substituted. The braces are required when PARAMETER is a
1393 positional parameter with more than one digit, or when PARAMETER is
1394 followed by a character that is not to be interpreted as part of its
1397 If the first character of PARAMETER is an exclamation point, a level
1398 of variable indirection is introduced. Bash uses the value of the
1399 variable formed from the rest of PARAMETER as the name of the variable;
1400 this variable is then expanded and that value is used in the rest of
1401 the substitution, rather than the value of PARAMETER itself. This is
1402 known as `indirect expansion'. The exceptions to this are the
1403 expansions of ${!PREFIX*} and ${!NAME[@]} described below. The
1404 exclamation point must immediately follow the left brace in order to
1405 introduce indirection.
1407 In each of the cases below, WORD is subject to tilde expansion,
1408 parameter expansion, command substitution, and arithmetic expansion.
1410 When not performing substring expansion, using the form described
1411 below, Bash tests for a parameter that is unset or null. Omitting the
1412 colon results in a test only for a parameter that is unset. Put
1413 another way, if the colon is included, the operator tests for both
1414 PARAMETER's existence and that its value is not null; if the colon is
1415 omitted, the operator tests only for existence.
1417 `${PARAMETER:-WORD}'
1418 If PARAMETER is unset or null, the expansion of WORD is
1419 substituted. Otherwise, the value of PARAMETER is substituted.
1421 `${PARAMETER:=WORD}'
1422 If PARAMETER is unset or null, the expansion of WORD is assigned
1423 to PARAMETER. The value of PARAMETER is then substituted.
1424 Positional parameters and special parameters may not be assigned to
1427 `${PARAMETER:?WORD}'
1428 If PARAMETER is null or unset, the expansion of WORD (or a message
1429 to that effect if WORD is not present) is written to the standard
1430 error and the shell, if it is not interactive, exits. Otherwise,
1431 the value of PARAMETER is substituted.
1433 `${PARAMETER:+WORD}'
1434 If PARAMETER is null or unset, nothing is substituted, otherwise
1435 the expansion of WORD is substituted.
1437 `${PARAMETER:OFFSET}'
1438 `${PARAMETER:OFFSET:LENGTH}'
1439 Expands to up to LENGTH characters of PARAMETER starting at the
1440 character specified by OFFSET. If LENGTH is omitted, expands to
1441 the substring of PARAMETER starting at the character specified by
1442 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
1443 Arithmetic::). This is referred to as Substring Expansion.
1445 LENGTH must evaluate to a number greater than or equal to zero.
1446 If OFFSET evaluates to a number less than zero, the value is used
1447 as an offset from the end of the value of PARAMETER. If PARAMETER
1448 is `@', the result is LENGTH positional parameters beginning at
1449 OFFSET. If PARAMETER is an indexed array name subscripted by `@'
1450 or `*', the result is the LENGTH members of the array beginning
1451 with `${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative
1452 to one greater than the maximum index of the specified array.
1453 Substring expansion applied to an associative array produces
1456 Note that a negative offset must be separated from the colon by at
1457 least one space to avoid being confused with the `:-' expansion.
1458 Substring indexing is zero-based unless the positional parameters
1459 are used, in which case the indexing starts at 1 by default. If
1460 OFFSET is 0, and the positional parameters are used, `$@' is
1461 prefixed to the list.
1465 Expands to the names of variables whose names begin with PREFIX,
1466 separated by the first character of the `IFS' special variable.
1467 When `@' is used and the expansion appears within double quotes,
1468 each variable name expands to a separate word.
1472 If NAME is an array variable, expands to the list of array indices
1473 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1474 NAME is set and null otherwise. When `@' is used and the
1475 expansion appears within double quotes, each key expands to a
1479 The length in characters of the expanded value of PARAMETER is
1480 substituted. If PARAMETER is `*' or `@', the value substituted is
1481 the number of positional parameters. If PARAMETER is an array
1482 name subscripted by `*' or `@', the value substituted is the
1483 number of elements in the array.
1486 `${PARAMETER##WORD}'
1487 The WORD is expanded to produce a pattern just as in filename
1488 expansion (*note Filename Expansion::). If the pattern matches
1489 the beginning of the expanded value of PARAMETER, then the result
1490 of the expansion is the expanded value of PARAMETER with the
1491 shortest matching pattern (the `#' case) or the longest matching
1492 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1493 pattern removal operation is applied to each positional parameter
1494 in turn, and the expansion is the resultant list. If PARAMETER is
1495 an array variable subscripted with `@' or `*', the pattern removal
1496 operation is applied to each member of the array in turn, and the
1497 expansion is the resultant list.
1500 `${PARAMETER%%WORD}'
1501 The WORD is expanded to produce a pattern just as in filename
1502 expansion. If the pattern matches a trailing portion of the
1503 expanded value of PARAMETER, then the result of the expansion is
1504 the value of PARAMETER with the shortest matching pattern (the `%'
1505 case) or the longest matching pattern (the `%%' case) deleted. If
1506 PARAMETER is `@' or `*', the pattern removal operation is applied
1507 to each positional parameter in turn, and the expansion is the
1508 resultant list. If PARAMETER is an array variable subscripted
1509 with `@' or `*', the pattern removal operation is applied to each
1510 member of the array in turn, and the expansion is the resultant
1513 `${PARAMETER/PATTERN/STRING}'
1514 The PATTERN is expanded to produce a pattern just as in filename
1515 expansion. PARAMETER is expanded and the longest match of PATTERN
1516 against its value is replaced with STRING. If PATTERN begins with
1517 `/', all matches of PATTERN are replaced with STRING. Normally
1518 only the first match is replaced. If PATTERN begins with `#', it
1519 must match at the beginning of the expanded value of PARAMETER.
1520 If PATTERN begins with `%', it must match at the end of the
1521 expanded value of PARAMETER. If STRING is null, matches of
1522 PATTERN are deleted and the `/' following PATTERN may be omitted.
1523 If PARAMETER is `@' or `*', the substitution operation is applied
1524 to each positional parameter in turn, and the expansion is the
1525 resultant list. If PARAMETER is an array variable subscripted
1526 with `@' or `*', the substitution operation is applied to each
1527 member of the array in turn, and the expansion is the resultant
1530 `${PARAMETER^PATTERN}'
1531 `${PARAMETER^^PATTERN}'
1532 `${PARAMETER,PATTERN}'
1533 `${PARAMETER,,PATTERN}'
1534 This expansion modifies the case of alphabetic characters in
1535 PARAMETER. The PATTERN is expanded to produce a pattern just as in
1536 pathname expansion. The `^' operator converts lowercase letters
1537 matching PATTERN to uppercase; the `,' operator converts matching
1538 uppercase letters to lowercase. The `^^' and `,,' expansions
1539 convert each matched character in the expanded value; the `^' and
1540 `,' expansions match and convert only the first character in the
1541 expanded value. If PATTERN is omitted, it is treated like a `?',
1542 which matches every character. If PARAMETER is `@' or `*', the
1543 case modification operation is applied to each positional
1544 parameter in turn, and the expansion is the resultant list. If
1545 PARAMETER is an array variable subscripted with `@' or `*', the
1546 case modification operation is applied to each member of the array
1547 in turn, and the expansion is the resultant list.
1551 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1553 3.5.4 Command Substitution
1554 --------------------------
1556 Command substitution allows the output of a command to replace the
1557 command itself. Command substitution occurs when a command is enclosed
1563 Bash performs the expansion by executing COMMAND and replacing the
1564 command substitution with the standard output of the command, with any
1565 trailing newlines deleted. Embedded newlines are not deleted, but they
1566 may be removed during word splitting. The command substitution `$(cat
1567 FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
1569 When the old-style backquote form of substitution is used, backslash
1570 retains its literal meaning except when followed by `$', ``', or `\'.
1571 The first backquote not preceded by a backslash terminates the command
1572 substitution. When using the `$(COMMAND)' form, all characters between
1573 the parentheses make up the command; none are treated specially.
1575 Command substitutions may be nested. To nest when using the
1576 backquoted form, escape the inner backquotes with backslashes.
1578 If the substitution appears within double quotes, word splitting and
1579 filename expansion are not performed on the results.
1582 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1584 3.5.5 Arithmetic Expansion
1585 --------------------------
1587 Arithmetic expansion allows the evaluation of an arithmetic expression
1588 and the substitution of the result. The format for arithmetic
1593 The expression is treated as if it were within double quotes, but a
1594 double quote inside the parentheses is not treated specially. All
1595 tokens in the expression undergo parameter expansion, command
1596 substitution, and quote removal. Arithmetic expansions may be nested.
1598 The evaluation is performed according to the rules listed below
1599 (*note Shell Arithmetic::). If the expression is invalid, Bash prints
1600 a message indicating failure to the standard error and no substitution
1604 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1606 3.5.6 Process Substitution
1607 --------------------------
1609 Process substitution is supported on systems that support named pipes
1610 (FIFOs) or the `/dev/fd' method of naming open files. It takes the
1615 The process LIST is run with its input or output connected to a FIFO
1616 or some file in `/dev/fd'. The name of this file is passed as an
1617 argument to the current command as the result of the expansion. If the
1618 `>(LIST)' form is used, writing to the file will provide input for
1619 LIST. If the `<(LIST)' form is used, the file passed as an argument
1620 should be read to obtain the output of LIST. Note that no space may
1621 appear between the `<' or `>' and the left parenthesis, otherwise the
1622 construct would be interpreted as a redirection.
1624 When available, process substitution is performed simultaneously with
1625 parameter and variable expansion, command substitution, and arithmetic
1629 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1631 3.5.7 Word Splitting
1632 --------------------
1634 The shell scans the results of parameter expansion, command
1635 substitution, and arithmetic expansion that did not occur within double
1636 quotes for word splitting.
1638 The shell treats each character of `$IFS' as a delimiter, and splits
1639 the results of the other expansions into words on these characters. If
1640 `IFS' is unset, or its value is exactly `<space><tab><newline>', the
1641 default, then sequences of ` <space>', `<tab>', and `<newline>' at the
1642 beginning and end of the results of the previous expansions are
1643 ignored, and any sequence of `IFS' characters not at the beginning or
1644 end serves to delimit words. If `IFS' has a value other than the
1645 default, then sequences of the whitespace characters `space' and `tab'
1646 are ignored at the beginning and end of the word, as long as the
1647 whitespace character is in the value of `IFS' (an `IFS' whitespace
1648 character). Any character in `IFS' that is not `IFS' whitespace, along
1649 with any adjacent `IFS' whitespace characters, delimits a field. A
1650 sequence of `IFS' whitespace characters is also treated as a delimiter.
1651 If the value of `IFS' is null, no word splitting occurs.
1653 Explicit null arguments (`""' or `''') are retained. Unquoted
1654 implicit null arguments, resulting from the expansion of parameters
1655 that have no values, are removed. If a parameter with no value is
1656 expanded within double quotes, a null argument results and is retained.
1658 Note that if no expansion occurs, no splitting is performed.
1661 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1663 3.5.8 Filename Expansion
1664 ------------------------
1668 * Pattern Matching:: How the shell matches patterns.
1670 After word splitting, unless the `-f' option has been set (*note The
1671 Set Builtin::), Bash scans each word for the characters `*', `?', and
1672 `['. If one of these characters appears, then the word is regarded as
1673 a PATTERN, and replaced with an alphabetically sorted list of file
1674 names matching the pattern. If no matching file names are found, and
1675 the shell option `nullglob' is disabled, the word is left unchanged.
1676 If the `nullglob' option is set, and no matches are found, the word is
1677 removed. If the `failglob' shell option is set, and no matches are
1678 found, an error message is printed and the command is not executed. If
1679 the shell option `nocaseglob' is enabled, the match is performed
1680 without regard to the case of alphabetic characters.
1682 When a pattern is used for filename generation, the character `.' at
1683 the start of a filename or immediately following a slash must be
1684 matched explicitly, unless the shell option `dotglob' is set. When
1685 matching a file name, the slash character must always be matched
1686 explicitly. In other cases, the `.' character is not treated specially.
1688 See the description of `shopt' in *note The Shopt Builtin::, for a
1689 description of the `nocaseglob', `nullglob', `failglob', and `dotglob'
1692 The `GLOBIGNORE' shell variable may be used to restrict the set of
1693 filenames matching a pattern. If `GLOBIGNORE' is set, each matching
1694 filename that also matches one of the patterns in `GLOBIGNORE' is
1695 removed from the list of matches. The filenames `.' and `..' are
1696 always ignored when `GLOBIGNORE' is set and not null. However, setting
1697 `GLOBIGNORE' to a non-null value has the effect of enabling the
1698 `dotglob' shell option, so all other filenames beginning with a `.'
1699 will match. To get the old behavior of ignoring filenames beginning
1700 with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The
1701 `dotglob' option is disabled when `GLOBIGNORE' is unset.
1704 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1706 3.5.8.1 Pattern Matching
1707 ........................
1709 Any character that appears in a pattern, other than the special pattern
1710 characters described below, matches itself. The NUL character may not
1711 occur in a pattern. A backslash escapes the following character; the
1712 escaping backslash is discarded when matching. The special pattern
1713 characters must be quoted if they are to be matched literally.
1715 The special pattern characters have the following meanings:
1717 Matches any string, including the null string. When the
1718 `globstar' shell option is enabled, and `*' is used in a filename
1719 expansion context, two adjacent `*'s used as a single pattern will
1720 match all files and zero or more directories and subdirectories.
1721 If followed by a `/', two adjacent `*'s will match only
1722 directories and subdirectories.
1725 Matches any single character.
1728 Matches any one of the enclosed characters. A pair of characters
1729 separated by a hyphen denotes a RANGE EXPRESSION; any character
1730 that sorts between those two characters, inclusive, using the
1731 current locale's collating sequence and character set, is matched.
1732 If the first character following the `[' is a `!' or a `^' then
1733 any character not enclosed is matched. A `-' may be matched by
1734 including it as the first or last character in the set. A `]' may
1735 be matched by including it as the first character in the set. The
1736 sorting order of characters in range expressions is determined by
1737 the current locale and the value of the `LC_COLLATE' shell
1740 For example, in the default C locale, `[a-dx-z]' is equivalent to
1741 `[abcdxyz]'. Many locales sort characters in dictionary order,
1742 and in these locales `[a-dx-z]' is typically not equivalent to
1743 `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
1744 example. To obtain the traditional interpretation of ranges in
1745 bracket expressions, you can force the use of the C locale by
1746 setting the `LC_COLLATE' or `LC_ALL' environment variable to the
1749 Within `[' and `]', CHARACTER CLASSES can be specified using the
1750 syntax `[:'CLASS`:]', where CLASS is one of the following classes
1751 defined in the POSIX standard:
1752 alnum alpha ascii blank cntrl digit graph lower
1753 print punct space upper word xdigit
1754 A character class matches any character belonging to that class.
1755 The `word' character class matches letters, digits, and the
1758 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1759 the syntax `[='C`=]', which matches all characters with the same
1760 collation weight (as defined by the current locale) as the
1763 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
1764 collating symbol SYMBOL.
1766 If the `extglob' shell option is enabled using the `shopt' builtin,
1767 several extended pattern matching operators are recognized. In the
1768 following description, a PATTERN-LIST is a list of one or more patterns
1769 separated by a `|'. Composite patterns may be formed using one or more
1770 of the following sub-patterns:
1773 Matches zero or one occurrence of the given patterns.
1776 Matches zero or more occurrences of the given patterns.
1779 Matches one or more occurrences of the given patterns.
1782 Matches one of the given patterns.
1785 Matches anything except one of the given patterns.
1788 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1793 After the preceding expansions, all unquoted occurrences of the
1794 characters `\', `'', and `"' that did not result from one of the above
1795 expansions are removed.
1798 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1803 Before a command is executed, its input and output may be REDIRECTED
1804 using a special notation interpreted by the shell. Redirection may
1805 also be used to open and close files for the current shell execution
1806 environment. The following redirection operators may precede or appear
1807 anywhere within a simple command or may follow a command. Redirections
1808 are processed in the order they appear, from left to right.
1810 In the following descriptions, if the file descriptor number is
1811 omitted, and the first character of the redirection operator is `<',
1812 the redirection refers to the standard input (file descriptor 0). If
1813 the first character of the redirection operator is `>', the redirection
1814 refers to the standard output (file descriptor 1).
1816 The word following the redirection operator in the following
1817 descriptions, unless otherwise noted, is subjected to brace expansion,
1818 tilde expansion, parameter expansion, command substitution, arithmetic
1819 expansion, quote removal, filename expansion, and word splitting. If
1820 it expands to more than one word, Bash reports an error.
1822 Note that the order of redirections is significant. For example,
1825 directs both standard output (file descriptor 1) and standard error
1826 (file descriptor 2) to the file DIRLIST, while the command
1828 directs only the standard output to file DIRLIST, because the
1829 standard error was duplicated as standard output before the standard
1830 output was redirected to DIRLIST.
1832 Bash handles several filenames specially when they are used in
1833 redirections, as described in the following table:
1836 If FD is a valid integer, file descriptor FD is duplicated.
1839 File descriptor 0 is duplicated.
1842 File descriptor 1 is duplicated.
1845 File descriptor 2 is duplicated.
1847 `/dev/tcp/HOST/PORT'
1848 If HOST is a valid hostname or Internet address, and PORT is an
1849 integer port number or service name, Bash attempts to open a TCP
1850 connection to the corresponding socket.
1852 `/dev/udp/HOST/PORT'
1853 If HOST is a valid hostname or Internet address, and PORT is an
1854 integer port number or service name, Bash attempts to open a UDP
1855 connection to the corresponding socket.
1858 A failure to open or create a file causes the redirection to fail.
1860 Redirections using file descriptors greater than 9 should be used
1861 with care, as they may conflict with file descriptors the shell uses
1864 3.6.1 Redirecting Input
1865 -----------------------
1867 Redirection of input causes the file whose name results from the
1868 expansion of WORD to be opened for reading on file descriptor `n', or
1869 the standard input (file descriptor 0) if `n' is not specified.
1871 The general format for redirecting input is:
1874 3.6.2 Redirecting Output
1875 ------------------------
1877 Redirection of output causes the file whose name results from the
1878 expansion of WORD to be opened for writing on file descriptor N, or the
1879 standard output (file descriptor 1) if N is not specified. If the file
1880 does not exist it is created; if it does exist it is truncated to zero
1883 The general format for redirecting output is:
1886 If the redirection operator is `>', and the `noclobber' option to
1887 the `set' builtin has been enabled, the redirection will fail if the
1888 file whose name results from the expansion of WORD exists and is a
1889 regular file. If the redirection operator is `>|', or the redirection
1890 operator is `>' and the `noclobber' option is not enabled, the
1891 redirection is attempted even if the file named by WORD exists.
1893 3.6.3 Appending Redirected Output
1894 ---------------------------------
1896 Redirection of output in this fashion causes the file whose name
1897 results from the expansion of WORD to be opened for appending on file
1898 descriptor N, or the standard output (file descriptor 1) if N is not
1899 specified. If the file does not exist it is created.
1901 The general format for appending output is:
1904 3.6.4 Redirecting Standard Output and Standard Error
1905 ----------------------------------------------------
1907 This construct allows both the standard output (file descriptor 1) and
1908 the standard error output (file descriptor 2) to be redirected to the
1909 file whose name is the expansion of WORD.
1911 There are two formats for redirecting standard output and standard
1916 Of the two forms, the first is preferred. This is semantically
1920 3.6.5 Appending Standard Output and Standard Error
1921 --------------------------------------------------
1923 This construct allows both the standard output (file descriptor 1) and
1924 the standard error output (file descriptor 2) to be appended to the
1925 file whose name is the expansion of WORD.
1927 The format for appending standard output and standard error is:
1929 This is semantically equivalent to
1932 3.6.6 Here Documents
1933 --------------------
1935 This type of redirection instructs the shell to read input from the
1936 current source until a line containing only WORD (with no trailing
1937 blanks) is seen. All of the lines read up to that point are then used
1938 as the standard input for a command.
1940 The format of here-documents is:
1945 No parameter expansion, command substitution, arithmetic expansion,
1946 or filename expansion is performed on WORD. If any characters in WORD
1947 are quoted, the DELIMITER is the result of quote removal on WORD, and
1948 the lines in the here-document are not expanded. If WORD is unquoted,
1949 all lines of the here-document are subjected to parameter expansion,
1950 command substitution, and arithmetic expansion. In the latter case,
1951 the character sequence `\newline' is ignored, and `\' must be used to
1952 quote the characters `\', `$', and ``'.
1954 If the redirection operator is `<<-', then all leading tab
1955 characters are stripped from input lines and the line containing
1956 DELIMITER. This allows here-documents within shell scripts to be
1957 indented in a natural fashion.
1962 A variant of here documents, the format is:
1965 The WORD is expanded and supplied to the command on its standard
1968 3.6.8 Duplicating File Descriptors
1969 ----------------------------------
1971 The redirection operator
1973 is used to duplicate input file descriptors. If WORD expands to one
1974 or more digits, the file descriptor denoted by N is made to be a copy
1975 of that file descriptor. If the digits in WORD do not specify a file
1976 descriptor open for input, a redirection error occurs. If WORD
1977 evaluates to `-', file descriptor N is closed. If N is not specified,
1978 the standard input (file descriptor 0) is used.
1982 is used similarly to duplicate output file descriptors. If N is not
1983 specified, the standard output (file descriptor 1) is used. If the
1984 digits in WORD do not specify a file descriptor open for output, a
1985 redirection error occurs. As a special case, if N is omitted, and WORD
1986 does not expand to one or more digits, the standard output and standard
1987 error are redirected as described previously.
1989 3.6.9 Moving File Descriptors
1990 -----------------------------
1992 The redirection operator
1994 moves the file descriptor DIGIT to file descriptor N, or the
1995 standard input (file descriptor 0) if N is not specified. DIGIT is
1996 closed after being duplicated to N.
1998 Similarly, the redirection operator
2000 moves the file descriptor DIGIT to file descriptor N, or the
2001 standard output (file descriptor 1) if N is not specified.
2003 3.6.10 Opening File Descriptors for Reading and Writing
2004 -------------------------------------------------------
2006 The redirection operator
2008 causes the file whose name is the expansion of WORD to be opened for
2009 both reading and writing on file descriptor N, or on file descriptor 0
2010 if N is not specified. If the file does not exist, it is created.
2013 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2015 3.7 Executing Commands
2016 ======================
2020 * Simple Command Expansion:: How Bash expands simple commands before
2022 * Command Search and Execution:: How Bash finds commands and runs them.
2023 * Command Execution Environment:: The environment in which Bash
2024 executes commands that are not
2026 * Environment:: The environment given to a command.
2027 * Exit Status:: The status returned by commands and how Bash
2029 * Signals:: What happens when Bash or a command it runs
2033 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2035 3.7.1 Simple Command Expansion
2036 ------------------------------
2038 When a simple command is executed, the shell performs the following
2039 expansions, assignments, and redirections, from left to right.
2041 1. The words that the parser has marked as variable assignments (those
2042 preceding the command name) and redirections are saved for later
2045 2. The words that are not variable assignments or redirections are
2046 expanded (*note Shell Expansions::). If any words remain after
2047 expansion, the first word is taken to be the name of the command
2048 and the remaining words are the arguments.
2050 3. Redirections are performed as described above (*note
2053 4. The text after the `=' in each variable assignment undergoes tilde
2054 expansion, parameter expansion, command substitution, arithmetic
2055 expansion, and quote removal before being assigned to the variable.
2057 If no command name results, the variable assignments affect the
2058 current shell environment. Otherwise, the variables are added to the
2059 environment of the executed command and do not affect the current shell
2060 environment. If any of the assignments attempts to assign a value to a
2061 readonly variable, an error occurs, and the command exits with a
2064 If no command name results, redirections are performed, but do not
2065 affect the current shell environment. A redirection error causes the
2066 command to exit with a non-zero status.
2068 If there is a command name left after expansion, execution proceeds
2069 as described below. Otherwise, the command exits. If one of the
2070 expansions contained a command substitution, the exit status of the
2071 command is the exit status of the last command substitution performed.
2072 If there were no command substitutions, the command exits with a status
2076 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2078 3.7.2 Command Search and Execution
2079 ----------------------------------
2081 After a command has been split into words, if it results in a simple
2082 command and an optional list of arguments, the following actions are
2085 1. If the command name contains no slashes, the shell attempts to
2086 locate it. If there exists a shell function by that name, that
2087 function is invoked as described in *note Shell Functions::.
2089 2. If the name does not match a function, the shell searches for it
2090 in the list of shell builtins. If a match is found, that builtin
2093 3. If the name is neither a shell function nor a builtin, and
2094 contains no slashes, Bash searches each element of `$PATH' for a
2095 directory containing an executable file by that name. Bash uses a
2096 hash table to remember the full pathnames of executable files to
2097 avoid multiple `PATH' searches (see the description of `hash' in
2098 *note Bourne Shell Builtins::). A full search of the directories
2099 in `$PATH' is performed only if the command is not found in the
2100 hash table. If the search is unsuccessful, the shell searches for
2101 a defined shell function named `command_not_found_handle'. If
2102 that function exists, it is invoked with the original command and
2103 the original command's arguments as its arguments, and the
2104 function's exit status becomes the exit status of the shell. If
2105 that function is not defined, the shell prints an error message
2106 and returns an exit status of 127.
2108 4. If the search is successful, or if the command name contains one
2109 or more slashes, the shell executes the named program in a
2110 separate execution environment. Argument 0 is set to the name
2111 given, and the remaining arguments to the command are set to the
2112 arguments supplied, if any.
2114 5. If this execution fails because the file is not in executable
2115 format, and the file is not a directory, it is assumed to be a
2116 SHELL SCRIPT and the shell executes it as described in *note Shell
2119 6. If the command was not begun asynchronously, the shell waits for
2120 the command to complete and collects its exit status.
2124 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2126 3.7.3 Command Execution Environment
2127 -----------------------------------
2129 The shell has an EXECUTION ENVIRONMENT, which consists of the following:
2131 * open files inherited by the shell at invocation, as modified by
2132 redirections supplied to the `exec' builtin
2134 * the current working directory as set by `cd', `pushd', or `popd',
2135 or inherited by the shell at invocation
2137 * the file creation mode mask as set by `umask' or inherited from
2140 * current traps set by `trap'
2142 * shell parameters that are set by variable assignment or with `set'
2143 or inherited from the shell's parent in the environment
2145 * shell functions defined during execution or inherited from the
2146 shell's parent in the environment
2148 * options enabled at invocation (either by default or with
2149 command-line arguments) or by `set'
2151 * options enabled by `shopt' (*note The Shopt Builtin::)
2153 * shell aliases defined with `alias' (*note Aliases::)
2155 * various process IDs, including those of background jobs (*note
2156 Lists::), the value of `$$', and the value of `$PPID'
2159 When a simple command other than a builtin or shell function is to
2160 be executed, it is invoked in a separate execution environment that
2161 consists of the following. Unless otherwise noted, the values are
2162 inherited from the shell.
2164 * the shell's open files, plus any modifications and additions
2165 specified by redirections to the command
2167 * the current working directory
2169 * the file creation mode mask
2171 * shell variables and functions marked for export, along with
2172 variables exported for the command, passed in the environment
2173 (*note Environment::)
2175 * traps caught by the shell are reset to the values inherited from
2176 the shell's parent, and traps ignored by the shell are ignored
2179 A command invoked in this separate environment cannot affect the
2180 shell's execution environment.
2182 Command substitution, commands grouped with parentheses, and
2183 asynchronous commands are invoked in a subshell environment that is a
2184 duplicate of the shell environment, except that traps caught by the
2185 shell are reset to the values that the shell inherited from its parent
2186 at invocation. Builtin commands that are invoked as part of a pipeline
2187 are also executed in a subshell environment. Changes made to the
2188 subshell environment cannot affect the shell's execution environment.
2190 Subshells spawned to execute command substitutions inherit the value
2191 of the `-e' option from the parent shell. When not in POSIX mode, Bash
2192 clears the `-e' option in such subshells.
2194 If a command is followed by a `&' and job control is not active, the
2195 default standard input for the command is the empty file `/dev/null'.
2196 Otherwise, the invoked command inherits the file descriptors of the
2197 calling shell as modified by redirections.
2200 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2205 When a program is invoked it is given an array of strings called the
2206 ENVIRONMENT. This is a list of name-value pairs, of the form
2209 Bash provides several ways to manipulate the environment. On
2210 invocation, the shell scans its own environment and creates a parameter
2211 for each name found, automatically marking it for EXPORT to child
2212 processes. Executed commands inherit the environment. The `export'
2213 and `declare -x' commands allow parameters and functions to be added to
2214 and deleted from the environment. If the value of a parameter in the
2215 environment is modified, the new value becomes part of the environment,
2216 replacing the old. The environment inherited by any executed command
2217 consists of the shell's initial environment, whose values may be
2218 modified in the shell, less any pairs removed by the `unset' and
2219 `export -n' commands, plus any additions via the `export' and `declare
2222 The environment for any simple command or function may be augmented
2223 temporarily by prefixing it with parameter assignments, as described in
2224 *note Shell Parameters::. These assignment statements affect only the
2225 environment seen by that command.
2227 If the `-k' option is set (*note The Set Builtin::), then all
2228 parameter assignments are placed in the environment for a command, not
2229 just those that precede the command name.
2231 When Bash invokes an external command, the variable `$_' is set to
2232 the full path name of the command and passed to that command in its
2236 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2241 The exit status of an executed command is the value returned by the
2242 WAITPID system call or equivalent function. Exit statuses fall between
2243 0 and 255, though, as explained below, the shell may use values above
2244 125 specially. Exit statuses from shell builtins and compound commands
2245 are also limited to this range. Under certain circumstances, the shell
2246 will use special values to indicate specific failure modes.
2248 For the shell's purposes, a command which exits with a zero exit
2249 status has succeeded. A non-zero exit status indicates failure. This
2250 seemingly counter-intuitive scheme is used so there is one well-defined
2251 way to indicate success and a variety of ways to indicate various
2252 failure modes. When a command terminates on a fatal signal whose
2253 number is N, Bash uses the value 128+N as the exit status.
2255 If a command is not found, the child process created to execute it
2256 returns a status of 127. If a command is found but is not executable,
2257 the return status is 126.
2259 If a command fails because of an error during expansion or
2260 redirection, the exit status is greater than zero.
2262 The exit status is used by the Bash conditional commands (*note
2263 Conditional Constructs::) and some of the list constructs (*note
2266 All of the Bash builtins return an exit status of zero if they
2267 succeed and a non-zero status on failure, so they may be used by the
2268 conditional and list constructs. All builtins return an exit status of
2269 2 to indicate incorrect usage.
2272 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2277 When Bash is interactive, in the absence of any traps, it ignores
2278 `SIGTERM' (so that `kill 0' does not kill an interactive shell), and
2279 `SIGINT' is caught and handled (so that the `wait' builtin is
2280 interruptible). When Bash receives a `SIGINT', it breaks out of any
2281 executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
2282 is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
2285 Non-builtin commands started by Bash have signal handlers set to the
2286 values inherited by the shell from its parent. When job control is not
2287 in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in
2288 addition to these inherited handlers. Commands run as a result of
2289 command substitution ignore the keyboard-generated job control signals
2290 `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
2292 The shell exits by default upon receipt of a `SIGHUP'. Before
2293 exiting, an interactive shell resends the `SIGHUP' to all jobs, running
2294 or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive
2295 the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to
2296 a particular job, it should be removed from the jobs table with the
2297 `disown' builtin (*note Job Control Builtins::) or marked to not
2298 receive `SIGHUP' using `disown -h'.
2300 If the `huponexit' shell option has been set with `shopt' (*note
2301 The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an
2302 interactive login shell exits.
2304 If Bash is waiting for a command to complete and receives a signal
2305 for which a trap has been set, the trap will not be executed until the
2306 command completes. When Bash is waiting for an asynchronous command
2307 via the `wait' builtin, the reception of a signal for which a trap has
2308 been set will cause the `wait' builtin to return immediately with an
2309 exit status greater than 128, immediately after which the trap is
2313 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2318 A shell script is a text file containing shell commands. When such a
2319 file is used as the first non-option argument when invoking Bash, and
2320 neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
2321 Bash reads and executes commands from the file, then exits. This mode
2322 of operation creates a non-interactive shell. The shell first searches
2323 for the file in the current directory, and looks in the directories in
2324 `$PATH' if not found there.
2326 When Bash runs a shell script, it sets the special parameter `0' to
2327 the name of the file, rather than the name of the shell, and the
2328 positional parameters are set to the remaining arguments, if any are
2329 given. If no additional arguments are supplied, the positional
2330 parameters are unset.
2332 A shell script may be made executable by using the `chmod' command
2333 to turn on the execute bit. When Bash finds such a file while
2334 searching the `$PATH' for a command, it spawns a subshell to execute
2335 it. In other words, executing
2337 is equivalent to executing
2338 bash filename ARGUMENTS
2340 if `filename' is an executable shell script. This subshell
2341 reinitializes itself, so that the effect is as if a new shell had been
2342 invoked to interpret the script, with the exception that the locations
2343 of commands remembered by the parent (see the description of `hash' in
2344 *note Bourne Shell Builtins::) are retained by the child.
2346 Most versions of Unix make this a part of the operating system's
2347 command execution mechanism. If the first line of a script begins with
2348 the two characters `#!', the remainder of the line specifies an
2349 interpreter for the program. Thus, you can specify Bash, `awk', Perl,
2350 or some other interpreter and write the rest of the script file in that
2353 The arguments to the interpreter consist of a single optional
2354 argument following the interpreter name on the first line of the script
2355 file, followed by the name of the script file, followed by the rest of
2356 the arguments. Bash will perform this action on operating systems that
2357 do not handle it themselves. Note that some older versions of Unix
2358 limit the interpreter name and argument to a maximum of 32 characters.
2360 Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
2361 been installed in `/bin'), since this ensures that Bash will be used to
2362 interpret the script, even if it is executed under another shell.
2365 File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
2367 4 Shell Builtin Commands
2368 ************************
2372 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2374 * Bash Builtins:: Table of builtins specific to Bash.
2375 * Modifying Shell Behavior:: Builtins to modify shell attributes and
2377 * Special Builtins:: Builtin commands classified specially by
2380 Builtin commands are contained within the shell itself. When the
2381 name of a builtin command is used as the first word of a simple command
2382 (*note Simple Commands::), the shell executes the command directly,
2383 without invoking another program. Builtin commands are necessary to
2384 implement functionality impossible or inconvenient to obtain with
2387 This section briefly describes the builtins which Bash inherits from
2388 the Bourne Shell, as well as the builtin commands which are unique to
2389 or have been extended in Bash.
2391 Several builtin commands are described in other chapters: builtin
2392 commands which provide the Bash interface to the job control facilities
2393 (*note Job Control Builtins::), the directory stack (*note Directory
2394 Stack Builtins::), the command history (*note Bash History Builtins::),
2395 and the programmable completion facilities (*note Programmable
2396 Completion Builtins::).
2398 Many of the builtins have been extended by POSIX or Bash.
2400 Unless otherwise noted, each builtin command documented as accepting
2401 options preceded by `-' accepts `--' to signify the end of the options.
2402 For example, the `:', `true', `false', and `test' builtins do not
2406 File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
2408 4.1 Bourne Shell Builtins
2409 =========================
2411 The following shell builtin commands are inherited from the Bourne
2412 Shell. These commands are implemented as specified by the POSIX
2417 Do nothing beyond expanding ARGUMENTS and performing redirections.
2418 The return status is zero.
2421 . FILENAME [ARGUMENTS]
2422 Read and execute commands from the FILENAME argument in the
2423 current shell context. If FILENAME does not contain a slash, the
2424 `PATH' variable is used to find FILENAME. When Bash is not in
2425 POSIX mode, the current directory is searched if FILENAME is not
2426 found in `$PATH'. If any ARGUMENTS are supplied, they become the
2427 positional parameters when FILENAME is executed. Otherwise the
2428 positional parameters are unchanged. The return status is the
2429 exit status of the last command executed, or zero if no commands
2430 are executed. If FILENAME is not found, or cannot be read, the
2431 return status is non-zero. This builtin is equivalent to `source'.
2435 Exit from a `for', `while', `until', or `select' loop. If N is
2436 supplied, the Nth enclosing loop is exited. N must be greater
2437 than or equal to 1. The return status is zero unless N is not
2438 greater than or equal to 1.
2441 cd [-L|-P] [DIRECTORY]
2442 Change the current working directory to DIRECTORY. If DIRECTORY
2443 is not given, the value of the `HOME' shell variable is used. If
2444 the shell variable `CDPATH' exists, it is used as a search path.
2445 If DIRECTORY begins with a slash, `CDPATH' is not used.
2447 The `-P' option means to not follow symbolic links; symbolic links
2448 are followed by default or with the `-L' option. If DIRECTORY is
2449 `-', it is equivalent to `$OLDPWD'.
2451 If a non-empty directory name from `CDPATH' is used, or if `-' is
2452 the first argument, and the directory change is successful, the
2453 absolute pathname of the new working directory is written to the
2456 The return status is zero if the directory is successfully changed,
2461 Resume the next iteration of an enclosing `for', `while', `until',
2462 or `select' loop. If N is supplied, the execution of the Nth
2463 enclosing loop is resumed. N must be greater than or equal to 1.
2464 The return status is zero unless N is not greater than or equal to
2469 The arguments are concatenated together into a single command,
2470 which is then read and executed, and its exit status returned as
2471 the exit status of `eval'. If there are no arguments or only
2472 empty arguments, the return status is zero.
2475 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2476 If COMMAND is supplied, it replaces the shell without creating a
2477 new process. If the `-l' option is supplied, the shell places a
2478 dash at the beginning of the zeroth argument passed to COMMAND.
2479 This is what the `login' program does. The `-c' option causes
2480 COMMAND to be executed with an empty environment. If `-a' is
2481 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2482 If no COMMAND is specified, redirections may be used to affect the
2483 current shell environment. If there are no redirection errors, the
2484 return status is zero; otherwise the return status is non-zero.
2488 Exit the shell, returning a status of N to the shell's parent. If
2489 N is omitted, the exit status is that of the last command executed.
2490 Any trap on `EXIT' is executed before the shell terminates.
2493 export [-fn] [-p] [NAME[=VALUE]]
2494 Mark each NAME to be passed to child processes in the environment.
2495 If the `-f' option is supplied, the NAMEs refer to shell
2496 functions; otherwise the names refer to shell variables. The `-n'
2497 option means to no longer mark each NAME for export. If no NAMES
2498 are supplied, or if the `-p' option is given, a list of exported
2499 names is displayed. The `-p' option displays output in a form
2500 that may be reused as input. If a variable name is followed by
2501 =VALUE, the value of the variable is set to VALUE.
2503 The return status is zero unless an invalid option is supplied,
2504 one of the names is not a valid shell variable name, or `-f' is
2505 supplied with a name that is not a shell function.
2508 getopts OPTSTRING NAME [ARGS]
2509 `getopts' is used by shell scripts to parse positional parameters.
2510 OPTSTRING contains the option characters to be recognized; if a
2511 character is followed by a colon, the option is expected to have an
2512 argument, which should be separated from it by white space. The
2513 colon (`:') and question mark (`?') may not be used as option
2514 characters. Each time it is invoked, `getopts' places the next
2515 option in the shell variable NAME, initializing NAME if it does
2516 not exist, and the index of the next argument to be processed into
2517 the variable `OPTIND'. `OPTIND' is initialized to 1 each time the
2518 shell or a shell script is invoked. When an option requires an
2519 argument, `getopts' places that argument into the variable
2520 `OPTARG'. The shell does not reset `OPTIND' automatically; it
2521 must be manually reset between multiple calls to `getopts' within
2522 the same shell invocation if a new set of parameters is to be used.
2524 When the end of options is encountered, `getopts' exits with a
2525 return value greater than zero. `OPTIND' is set to the index of
2526 the first non-option argument, and `name' is set to `?'.
2528 `getopts' normally parses the positional parameters, but if more
2529 arguments are given in ARGS, `getopts' parses those instead.
2531 `getopts' can report errors in two ways. If the first character of
2532 OPTSTRING is a colon, SILENT error reporting is used. In normal
2533 operation diagnostic messages are printed when invalid options or
2534 missing option arguments are encountered. If the variable `OPTERR'
2535 is set to 0, no error messages will be displayed, even if the first
2536 character of `optstring' is not a colon.
2538 If an invalid option is seen, `getopts' places `?' into NAME and,
2539 if not silent, prints an error message and unsets `OPTARG'. If
2540 `getopts' is silent, the option character found is placed in
2541 `OPTARG' and no diagnostic message is printed.
2543 If a required argument is not found, and `getopts' is not silent,
2544 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2545 diagnostic message is printed. If `getopts' is silent, then a
2546 colon (`:') is placed in NAME and `OPTARG' is set to the option
2550 hash [-r] [-p FILENAME] [-dt] [NAME]
2551 Remember the full pathnames of commands specified as NAME
2552 arguments, so they need not be searched for on subsequent
2553 invocations. The commands are found by searching through the
2554 directories listed in `$PATH'. The `-p' option inhibits the path
2555 search, and FILENAME is used as the location of NAME. The `-r'
2556 option causes the shell to forget all remembered locations. The
2557 `-d' option causes the shell to forget the remembered location of
2558 each NAME. If the `-t' option is supplied, the full pathname to
2559 which each NAME corresponds is printed. If multiple NAME
2560 arguments are supplied with `-t' the NAME is printed before the
2561 hashed full pathname. The `-l' option causes output to be
2562 displayed in a format that may be reused as input. If no
2563 arguments are given, or if only `-l' is supplied, information
2564 about remembered commands is printed. The return status is zero
2565 unless a NAME is not found or an invalid option is supplied.
2569 Print the absolute pathname of the current working directory. If
2570 the `-P' option is supplied, the pathname printed will not contain
2571 symbolic links. If the `-L' option is supplied, the pathname
2572 printed may contain symbolic links. The return status is zero
2573 unless an error is encountered while determining the name of the
2574 current directory or an invalid option is supplied.
2577 readonly [-aApf] [NAME[=VALUE]] ...
2578 Mark each NAME as readonly. The values of these names may not be
2579 changed by subsequent assignment. If the `-f' option is supplied,
2580 each NAME refers to a shell function. The `-a' option means each
2581 NAME refers to an indexed array variable; the `-A' option means
2582 each NAME refers to an associative array variable. If no NAME
2583 arguments are given, or if the `-p' option is supplied, a list of
2584 all readonly names is printed. The `-p' option causes output to
2585 be displayed in a format that may be reused as input. If a
2586 variable name is followed by =VALUE, the value of the variable is
2587 set to VALUE. The return status is zero unless an invalid option
2588 is supplied, one of the NAME arguments is not a valid shell
2589 variable or function name, or the `-f' option is supplied with a
2590 name that is not a shell function.
2594 Cause a shell function to exit with the return value N. If N is
2595 not supplied, the return value is the exit status of the last
2596 command executed in the function. This may also be used to
2597 terminate execution of a script being executed with the `.' (or
2598 `source') builtin, returning either N or the exit status of the
2599 last command executed within the script as the exit status of the
2600 script. Any command associated with the `RETURN' trap is executed
2601 before execution resumes after the function or script. The return
2602 status is non-zero if `return' is used outside a function and not
2603 during the execution of a script by `.' or `source'.
2607 Shift the positional parameters to the left by N. The positional
2608 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
2609 Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
2610 N must be a non-negative number less than or equal to `$#'. If N
2611 is zero or greater than `$#', the positional parameters are not
2612 changed. If N is not supplied, it is assumed to be 1. The return
2613 status is zero unless N is greater than `$#' or less than zero,
2618 Evaluate a conditional expression EXPR. Each operator and operand
2619 must be a separate argument. Expressions are composed of the
2620 primaries described below in *note Bash Conditional Expressions::.
2621 `test' does not accept any options, nor does it accept and ignore
2622 an argument of `--' as signifying the end of options.
2624 When the `[' form is used, the last argument to the command must
2627 Expressions may be combined using the following operators, listed
2628 in decreasing order of precedence. The evaluation depends on the
2629 number of arguments; see below.
2632 True if EXPR is false.
2635 Returns the value of EXPR. This may be used to override the
2636 normal precedence of operators.
2639 True if both EXPR1 and EXPR2 are true.
2642 True if either EXPR1 or EXPR2 is true.
2644 The `test' and `[' builtins evaluate conditional expressions using
2645 a set of rules based on the number of arguments.
2648 The expression is false.
2651 The expression is true if and only if the argument is not
2655 If the first argument is `!', the expression is true if and
2656 only if the second argument is null. If the first argument
2657 is one of the unary conditional operators (*note Bash
2658 Conditional Expressions::), the expression is true if the
2659 unary test is true. If the first argument is not a valid
2660 unary operator, the expression is false.
2663 If the second argument is one of the binary conditional
2664 operators (*note Bash Conditional Expressions::), the result
2665 of the expression is the result of the binary test using the
2666 first and third arguments as operands. The `-a' and `-o'
2667 operators are considered binary operators when there are
2668 three arguments. If the first argument is `!', the value is
2669 the negation of the two-argument test using the second and
2670 third arguments. If the first argument is exactly `(' and
2671 the third argument is exactly `)', the result is the
2672 one-argument test of the second argument. Otherwise, the
2673 expression is false.
2676 If the first argument is `!', the result is the negation of
2677 the three-argument expression composed of the remaining
2678 arguments. Otherwise, the expression is parsed and evaluated
2679 according to precedence using the rules listed above.
2682 The expression is parsed and evaluated according to precedence
2683 using the rules listed above.
2687 Print out the user and system times used by the shell and its
2688 children. The return status is zero.
2691 trap [-lp] [ARG] [SIGSPEC ...]
2692 The commands in ARG are to be read and executed when the shell
2693 receives signal SIGSPEC. If ARG is absent (and there is a single
2694 SIGSPEC) or equal to `-', each specified signal's disposition is
2695 reset to the value it had when the shell was started. If ARG is
2696 the null string, then the signal specified by each SIGSPEC is
2697 ignored by the shell and commands it invokes. If ARG is not
2698 present and `-p' has been supplied, the shell displays the trap
2699 commands associated with each SIGSPEC. If no arguments are
2700 supplied, or only `-p' is given, `trap' prints the list of commands
2701 associated with each signal number in a form that may be reused as
2702 shell input. The `-l' option causes the shell to print a list of
2703 signal names and their corresponding numbers. Each SIGSPEC is
2704 either a signal name or a signal number. Signal names are case
2705 insensitive and the `SIG' prefix is optional. If a SIGSPEC is `0'
2706 or `EXIT', ARG is executed when the shell exits. If a SIGSPEC is
2707 `DEBUG', the command ARG is executed before every simple command,
2708 `for' command, `case' command, `select' command, every arithmetic
2709 `for' command, and before the first command executes in a shell
2710 function. Refer to the description of the `extglob' option to the
2711 `shopt' builtin (*note The Shopt Builtin::) for details of its
2712 effect on the `DEBUG' trap. If a SIGSPEC is `ERR', the command ARG
2713 is executed whenever a simple command has a non-zero exit status,
2714 subject to the following conditions. The `ERR' trap is not
2715 executed if the failed command is part of the command list
2716 immediately following an `until' or `while' keyword, part of the
2717 test in an `if' statement, part of a command executed in a `&&' or
2718 `||' list, or if the command's return status is being inverted
2719 using `!'. These are the same conditions obeyed by the `errexit'
2720 option. If a SIGSPEC is `RETURN', the command ARG is executed
2721 each time a shell function or a script executed with the `.' or
2722 `source' builtins finishes executing.
2724 Signals ignored upon entry to the shell cannot be trapped or reset.
2725 Trapped signals that are not being ignored are reset to their
2726 original values in a child process when it is created.
2728 The return status is zero unless a SIGSPEC does not specify a
2732 umask [-p] [-S] [MODE]
2733 Set the shell process's file creation mask to MODE. If MODE
2734 begins with a digit, it is interpreted as an octal number; if not,
2735 it is interpreted as a symbolic mode mask similar to that accepted
2736 by the `chmod' command. If MODE is omitted, the current value of
2737 the mask is printed. If the `-S' option is supplied without a
2738 MODE argument, the mask is printed in a symbolic format. If the
2739 `-p' option is supplied, and MODE is omitted, the output is in a
2740 form that may be reused as input. The return status is zero if
2741 the mode is successfully changed or if no MODE argument is
2742 supplied, and non-zero otherwise.
2744 Note that when the mode is interpreted as an octal number, each
2745 number of the umask is subtracted from `7'. Thus, a umask of `022'
2746 results in permissions of `755'.
2750 Each variable or function NAME is removed. If no options are
2751 supplied, or the `-v' option is given, each NAME refers to a shell
2752 variable. If the `-f' option is given, the NAMEs refer to shell
2753 functions, and the function definition is removed. Readonly
2754 variables and functions may not be unset. The return status is
2755 zero unless a NAME is readonly.
2758 File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
2760 4.2 Bash Builtin Commands
2761 =========================
2763 This section describes builtin commands which are unique to or have
2764 been extended in Bash. Some of these commands are specified in the
2768 alias [`-p'] [NAME[=VALUE] ...]
2770 Without arguments or with the `-p' option, `alias' prints the list
2771 of aliases on the standard output in a form that allows them to be
2772 reused as input. If arguments are supplied, an alias is defined
2773 for each NAME whose VALUE is given. If no VALUE is given, the name
2774 and value of the alias is printed. Aliases are described in *note
2778 bind [-m KEYMAP] [-lpsvPSV]
2779 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2780 bind [-m KEYMAP] -f FILENAME
2781 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
2782 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
2783 bind READLINE-COMMAND
2785 Display current Readline (*note Command Line Editing::) key and
2786 function bindings, bind a key sequence to a Readline function or
2787 macro, or set a Readline variable. Each non-option argument is a
2788 command as it would appear in a Readline initialization file
2789 (*note Readline Init File::), but each binding or command must be
2790 passed as a separate argument; e.g.,
2791 `"\C-x\C-r":re-read-init-file'.
2793 Options, if supplied, have the following meanings:
2796 Use KEYMAP as the keymap to be affected by the subsequent
2797 bindings. Acceptable KEYMAP names are `emacs',
2798 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
2799 `vi-command', and `vi-insert'. `vi' is equivalent to
2800 `vi-command'; `emacs' is equivalent to `emacs-standard'.
2803 List the names of all Readline functions.
2806 Display Readline function names and bindings in such a way
2807 that they can be used as input or in a Readline
2808 initialization file.
2811 List current Readline function names and bindings.
2814 Display Readline variable names and values in such a way that
2815 they can be used as input or in a Readline initialization
2819 List current Readline variable names and values.
2822 Display Readline key sequences bound to macros and the
2823 strings they output in such a way that they can be used as
2824 input or in a Readline initialization file.
2827 Display Readline key sequences bound to macros and the
2828 strings they output.
2831 Read key bindings from FILENAME.
2834 Query about which keys invoke the named FUNCTION.
2837 Unbind all keys bound to the named FUNCTION.
2840 Remove any current binding for KEYSEQ.
2842 `-x KEYSEQ:SHELL-COMMAND'
2843 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
2844 When SHELL-COMMAND is executed, the shell sets the
2845 `READLINE_LINE' variable to the contents of the Readline line
2846 buffer and the `READLINE_POINT' variable to the current
2847 location of the insertion point. If the executed command
2848 changes the value of `READLINE_LINE' or `READLINE_POINT',
2849 those new values will be reflected in the editing state.
2851 The return status is zero unless an invalid option is supplied or
2855 builtin [SHELL-BUILTIN [ARGS]]
2856 Run a shell builtin, passing it ARGS, and return its exit status.
2857 This is useful when defining a shell function with the same name
2858 as a shell builtin, retaining the functionality of the builtin
2859 within the function. The return status is non-zero if
2860 SHELL-BUILTIN is not a shell builtin command.
2864 Returns the context of any active subroutine call (a shell
2865 function or a script executed with the `.' or `source' builtins).
2867 Without EXPR, `caller' displays the line number and source
2868 filename of the current subroutine call. If a non-negative
2869 integer is supplied as EXPR, `caller' displays the line number,
2870 subroutine name, and source file corresponding to that position in
2871 the current execution call stack. This extra information may be
2872 used, for example, to print a stack trace. The current frame is
2875 The return value is 0 unless the shell is not executing a
2876 subroutine call or EXPR does not correspond to a valid position in
2880 command [-pVv] COMMAND [ARGUMENTS ...]
2881 Runs COMMAND with ARGUMENTS ignoring any shell function named
2882 COMMAND. Only shell builtin commands or commands found by
2883 searching the `PATH' are executed. If there is a shell function
2884 named `ls', running `command ls' within the function will execute
2885 the external command `ls' instead of calling the function
2886 recursively. The `-p' option means to use a default value for
2887 `PATH' that is guaranteed to find all of the standard utilities.
2888 The return status in this case is 127 if COMMAND cannot be found
2889 or an error occurred, and the exit status of COMMAND otherwise.
2891 If either the `-V' or `-v' option is supplied, a description of
2892 COMMAND is printed. The `-v' option causes a single word
2893 indicating the command or file name used to invoke COMMAND to be
2894 displayed; the `-V' option produces a more verbose description.
2895 In this case, the return status is zero if COMMAND is found, and
2899 declare [-aAfFilrtux] [-p] [NAME[=VALUE] ...]
2901 Declare variables and give them attributes. If no NAMEs are
2902 given, then display the values of variables instead.
2904 The `-p' option will display the attributes and values of each
2905 NAME. When `-p' is used with NAME arguments, additional options
2908 When `-p' is supplied without NAME arguments, `declare' will
2909 display the attributes and values of all variables having the
2910 attributes specified by the additional options. If no other
2911 options are supplied with `-p', `declare' will display the
2912 attributes and values of all shell variables. The `-f' option
2913 will restrict the display to shell functions.
2915 The `-F' option inhibits the display of function definitions; only
2916 the function name and attributes are printed. If the `extdebug'
2917 shell option is enabled using `shopt' (*note The Shopt Builtin::),
2918 the source file name and line number where the function is defined
2919 are displayed as well. `-F' implies `-f'. The following options
2920 can be used to restrict output to variables with the specified
2921 attributes or to give variables attributes:
2924 Each NAME is an indexed array variable (*note Arrays::).
2927 Each NAME is an associative array variable (*note Arrays::).
2930 Use function names only.
2933 The variable is to be treated as an integer; arithmetic
2934 evaluation (*note Shell Arithmetic::) is performed when the
2935 variable is assigned a value.
2938 When the variable is assigned a value, all upper-case
2939 characters are converted to lower-case. The upper-case
2940 attribute is disabled.
2943 Make NAMEs readonly. These names cannot then be assigned
2944 values by subsequent assignment statements or unset.
2947 Give each NAME the `trace' attribute. Traced functions
2948 inherit the `DEBUG' and `RETURN' traps from the calling shell.
2949 The trace attribute has no special meaning for variables.
2952 When the variable is assigned a value, all lower-case
2953 characters are converted to upper-case. The lower-case
2954 attribute is disabled.
2957 Mark each NAME for export to subsequent commands via the
2960 Using `+' instead of `-' turns off the attribute instead, with the
2961 exceptions that `+a' may not be used to destroy an array variable
2962 and `+r' will not remove the readonly attribute. When used in a
2963 function, `declare' makes each NAME local, as with the `local'
2964 command. If a variable name is followed by =VALUE, the value of
2965 the variable is set to VALUE.
2967 The return status is zero unless an invalid option is encountered,
2968 an attempt is made to define a function using `-f foo=bar', an
2969 attempt is made to assign a value to a readonly variable, an
2970 attempt is made to assign a value to an array variable without
2971 using the compound assignment syntax (*note Arrays::), one of the
2972 NAMES is not a valid shell variable name, an attempt is made to
2973 turn off readonly status for a readonly variable, an attempt is
2974 made to turn off array status for an array variable, or an attempt
2975 is made to display a non-existent function with `-f'.
2978 echo [-neE] [ARG ...]
2979 Output the ARGs, separated by spaces, terminated with a newline.
2980 The return status is always 0. If `-n' is specified, the trailing
2981 newline is suppressed. If the `-e' option is given,
2982 interpretation of the following backslash-escaped characters is
2983 enabled. The `-E' option disables the interpretation of these
2984 escape characters, even on systems where they are interpreted by
2985 default. The `xpg_echo' shell option may be used to dynamically
2986 determine whether or not `echo' expands these escape characters by
2987 default. `echo' does not interpret `--' to mean the end of
2990 `echo' interprets the following escape sequences:
2998 suppress further output
3022 the eight-bit character whose value is the octal value NNN
3023 (zero to three octal digits)
3026 the eight-bit character whose value is the hexadecimal value
3027 HH (one or two hex digits)
3030 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3031 Enable and disable builtin shell commands. Disabling a builtin
3032 allows a disk command which has the same name as a shell builtin
3033 to be executed without specifying a full pathname, even though the
3034 shell normally searches for builtins before disk commands. If
3035 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3036 enabled. For example, to use the `test' binary found via `$PATH'
3037 instead of the shell builtin version, type `enable -n test'.
3039 If the `-p' option is supplied, or no NAME arguments appear, a
3040 list of shell builtins is printed. With no other arguments, the
3041 list consists of all enabled shell builtins. The `-a' option
3042 means to list each builtin with an indication of whether or not it
3045 The `-f' option means to load the new builtin command NAME from
3046 shared object FILENAME, on systems that support dynamic loading.
3047 The `-d' option will delete a builtin loaded with `-f'.
3049 If there are no options, a list of the shell builtins is displayed.
3050 The `-s' option restricts `enable' to the POSIX special builtins.
3051 If `-s' is used with `-f', the new builtin becomes a special
3052 builtin (*note Special Builtins::).
3054 The return status is zero unless a NAME is not a shell builtin or
3055 there is an error loading a new builtin from a shared object.
3058 help [-dms] [PATTERN]
3059 Display helpful information about builtin commands. If PATTERN is
3060 specified, `help' gives detailed help on all commands matching
3061 PATTERN, otherwise a list of the builtins is printed.
3063 Options, if supplied, have the following meanings:
3066 Display a short description of each PATTERN
3069 Display the description of each PATTERN in a manpage-like
3073 Display only a short usage synopsis for each PATTERN
3075 The return status is zero unless no command matches PATTERN.
3078 let EXPRESSION [EXPRESSION]
3079 The `let' builtin allows arithmetic to be performed on shell
3080 variables. Each EXPRESSION is evaluated according to the rules
3081 given below in *note Shell Arithmetic::. If the last EXPRESSION
3082 evaluates to 0, `let' returns 1; otherwise 0 is returned.
3085 local [OPTION] NAME[=VALUE] ...
3086 For each argument, a local variable named NAME is created, and
3087 assigned VALUE. The OPTION can be any of the options accepted by
3088 `declare'. `local' can only be used within a function; it makes
3089 the variable NAME have a visible scope restricted to that function
3090 and its children. The return status is zero unless `local' is
3091 used outside a function, an invalid NAME is supplied, or NAME is a
3096 Exit a login shell, returning a status of N to the shell's parent.
3099 mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3100 -C CALLBACK] [-c QUANTUM] [ARRAY]
3101 Read lines from the standard input into array variable ARRAY, or
3102 from file descriptor FD if the `-u' option is supplied. The
3103 variable `MAPFILE' is the default ARRAY. Options, if supplied,
3104 have the following meanings:
3106 Copy at most COUNT lines. If COUNT is 0, all lines are
3110 Begin assigning to ARRAY at index ORIGIN. The default index
3114 Discard the first COUNT lines read.
3117 Remove a trailing line from each line read.
3120 Read lines from file descriptor FD instead of the standard
3124 Evaluate CALLBACK each time QUANTUMP lines are read. The
3125 `-c' option specifies QUANTUM.
3128 Specify the number of lines read between each call to
3131 If `-C' is specified without `-c', the default quantum is 5000.
3132 When CALLBACK is evaluated, it is supplied the index of the next
3133 array element to be assigned as an additional argument. CALLBACK
3134 is evaluated after the line is read but before the array element
3137 If not supplied with an explicit origin, `mapfile' will clear ARRAY
3138 before assigning to it.
3140 `mapfile' returns successfully unless an invalid option or option
3141 argument is supplied, or ARRAY is invalid or unassignable.
3144 printf [-v VAR] FORMAT [ARGUMENTS]
3145 Write the formatted ARGUMENTS to the standard output under the
3146 control of the FORMAT. The FORMAT is a character string which
3147 contains three types of objects: plain characters, which are
3148 simply copied to standard output, character escape sequences,
3149 which are converted and copied to the standard output, and format
3150 specifications, each of which causes printing of the next
3151 successive ARGUMENT. In addition to the standard `printf(1)'
3152 formats, `%b' causes `printf' to expand backslash escape sequences
3153 in the corresponding ARGUMENT, (except that `\c' terminates
3154 output, backslashes in `\'', `\"', and `\?' are not removed, and
3155 octal escapes beginning with `\0' may contain up to four digits),
3156 and `%q' causes `printf' to output the corresponding ARGUMENT in a
3157 format that can be reused as shell input.
3159 The `-v' option causes the output to be assigned to the variable
3160 VAR rather than being printed to the standard output.
3162 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3163 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3164 format specifications behave as if a zero value or null string, as
3165 appropriate, had been supplied. The return value is zero on
3166 success, non-zero on failure.
3169 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3170 One line is read from the standard input, or from the file
3171 descriptor FD supplied as an argument to the `-u' option, and the
3172 first word is assigned to the first NAME, the second word to the
3173 second NAME, and so on, with leftover words and their intervening
3174 separators assigned to the last NAME. If there are fewer words
3175 read from the input stream than names, the remaining names are
3176 assigned empty values. The characters in the value of the `IFS'
3177 variable are used to split the line into words. The backslash
3178 character `\' may be used to remove any special meaning for the
3179 next character read and for line continuation. If no names are
3180 supplied, the line read is assigned to the variable `REPLY'. The
3181 return code is zero, unless end-of-file is encountered, `read'
3182 times out (in which case the return code is greater than 128), or
3183 an invalid file descriptor is supplied as the argument to `-u'.
3185 Options, if supplied, have the following meanings:
3188 The words are assigned to sequential indices of the array
3189 variable ANAME, starting at 0. All elements are removed from
3190 ANAME before the assignment. Other NAME arguments are
3194 The first character of DELIM is used to terminate the input
3195 line, rather than newline.
3198 Readline (*note Command Line Editing::) is used to obtain the
3199 line. Readline uses the current (or default, if line editing
3200 was not previously active) editing settings.
3203 If Readline is being used to read the line, TEXT is placed
3204 into the editing buffer before editing begins.
3207 `read' returns after reading NCHARS characters rather than
3208 waiting for a complete line of input.
3211 Display PROMPT, without a trailing newline, before attempting
3212 to read any input. The prompt is displayed only if input is
3213 coming from a terminal.
3216 If this option is given, backslash does not act as an escape
3217 character. The backslash is considered to be part of the
3218 line. In particular, a backslash-newline pair may not be
3219 used as a line continuation.
3222 Silent mode. If input is coming from a terminal, characters
3226 Cause `read' to time out and return failure if a complete
3227 line of input is not read within TIMEOUT seconds. TIMEOUT
3228 may be a decimal number with a fractional portion following
3229 the decimal point. This option is only effective if `read'
3230 is reading input from a terminal, pipe, or other special
3231 file; it has no effect when reading from regular files. If
3232 TIMEOUT is 0, `read' returns success if input is available on
3233 the specified file descriptor, failure otherwise. The exit
3234 status is greater than 128 if the timeout is exceeded.
3237 Read input from file descriptor FD.
3241 readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3242 -C CALLBACK] [-c QUANTUM] [ARRAY]
3243 Read lines from the standard input into array variable ARRAY, or
3244 from file descriptor FD if the `-u' option is supplied.
3246 A synonym for `mapfile'.
3250 A synonym for `.' (*note Bourne Shell Builtins::).
3253 type [-afptP] [NAME ...]
3254 For each NAME, indicate how it would be interpreted if used as a
3257 If the `-t' option is used, `type' prints a single word which is
3258 one of `alias', `function', `builtin', `file' or `keyword', if
3259 NAME is an alias, shell function, shell builtin, disk file, or
3260 shell reserved word, respectively. If the NAME is not found, then
3261 nothing is printed, and `type' returns a failure status.
3263 If the `-p' option is used, `type' either returns the name of the
3264 disk file that would be executed, or nothing if `-t' would not
3267 The `-P' option forces a path search for each NAME, even if `-t'
3268 would not return `file'.
3270 If a command is hashed, `-p' and `-P' print the hashed value, not
3271 necessarily the file that appears first in `$PATH'.
3273 If the `-a' option is used, `type' returns all of the places that
3274 contain an executable named FILE. This includes aliases and
3275 functions, if and only if the `-p' option is not also used.
3277 If the `-f' option is used, `type' does not attempt to find shell
3278 functions, as with the `command' builtin.
3280 The return status is zero if all of the NAMES are found, non-zero
3281 if any are not found.
3284 typeset [-afFrxi] [-p] [NAME[=VALUE] ...]
3285 The `typeset' command is supplied for compatibility with the Korn
3286 shell; however, it has been deprecated in favor of the `declare'
3290 ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
3291 `ulimit' provides control over the resources available to processes
3292 started by the shell, on systems that allow such control. If an
3293 option is given, it is interpreted as follows:
3295 Change and report the soft limit associated with a resource.
3298 Change and report the hard limit associated with a resource.
3301 All current limits are reported.
3304 The maximum socket buffer size.
3307 The maximum size of core files created.
3310 The maximum size of a process's data segment.
3313 The maximum scheduling priority ("nice").
3316 The maximum size of files written by the shell and its
3320 The maximum number of pending signals.
3323 The maximum size that may be locked into memory.
3326 The maximum resident set size.
3329 The maximum number of open file descriptors.
3332 The pipe buffer size.
3335 The maximum number of bytes in POSIX message queues.
3338 The maximum real-time scheduling priority.
3341 The maximum stack size.
3344 The maximum amount of cpu time in seconds.
3347 The maximum number of processes available to a single user.
3350 The maximum amount of virtual memory available to the process.
3353 The maximum number of file locks.
3356 The maximum number of threads.
3359 If LIMIT is given, it is the new value of the specified resource;
3360 the special LIMIT values `hard', `soft', and `unlimited' stand for
3361 the current hard limit, the current soft limit, and no limit,
3362 respectively. A hard limit cannot be increased by a non-root user
3363 once it is set; a soft limit may be increased up to the value of
3364 the hard limit. Otherwise, the current value of the soft limit
3365 for the specified resource is printed, unless the `-H' option is
3366 supplied. When setting new limits, if neither `-H' nor `-S' is
3367 supplied, both the hard and soft limits are set. If no option is
3368 given, then `-f' is assumed. Values are in 1024-byte increments,
3369 except for `-t', which is in seconds, `-p', which is in units of
3370 512-byte blocks, and `-n' and `-u', which are unscaled values.
3372 The return status is zero unless an invalid option or argument is
3373 supplied, or an error occurs while setting a new limit.
3376 unalias [-a] [NAME ... ]
3378 Remove each NAME from the list of aliases. If `-a' is supplied,
3379 all aliases are removed. Aliases are described in *note Aliases::.
3383 File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
3385 4.3 Modifying Shell Behavior
3386 ============================
3390 * The Set Builtin:: Change the values of shell attributes and
3391 positional parameters.
3392 * The Shopt Builtin:: Modify shell optional behavior.
3395 File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3397 4.3.1 The Set Builtin
3398 ---------------------
3400 This builtin is so complicated that it deserves its own section. `set'
3401 allows you to change the values of shell options and set the positional
3402 parameters, or to display the names and values of shell variables.
3405 set [--abefhkmnptuvxBCEHPT] [-o OPTION] [ARGUMENT ...]
3406 set [+abefhkmnptuvxBCEHPT] [+o OPTION] [ARGUMENT ...]
3408 If no options or arguments are supplied, `set' displays the names
3409 and values of all shell variables and functions, sorted according
3410 to the current locale, in a format that may be reused as input for
3411 setting or resetting the currently-set variables. Read-only
3412 variables cannot be reset. In POSIX mode, only shell variables
3415 When options are supplied, they set or unset shell attributes.
3416 Options, if specified, have the following meanings:
3419 Mark variables and function which are modified or created for
3420 export to the environment of subsequent commands.
3423 Cause the status of terminated background jobs to be reported
3424 immediately, rather than before printing the next primary
3428 Exit immediately if a simple command (*note Simple
3429 Commands::) exits with a non-zero status, unless the command
3430 that fails is part of the command list immediately following
3431 a `while' or `until' keyword, part of the test in an `if'
3432 statement, part of a command executed in a `&&' or `||b' list,
3433 any command in a pipeline but the last, or if the command's
3434 return status is being inverted using `!'. Failing simple
3435 commands that are part of shell functions or command lists
3436 enclosed in braces or parentheses satisfying the above
3437 conditions do not cause the shell to exit. A trap on `ERR',
3438 if set, is executed before the shell exits.
3441 Disable file name generation (globbing).
3444 Locate and remember (hash) commands as they are looked up for
3445 execution. This option is enabled by default.
3448 All arguments in the form of assignment statements are placed
3449 in the environment for a command, not just those that precede
3453 Job control is enabled (*note Job Control::).
3456 Read commands but do not execute them; this may be used to
3457 check a script for syntax errors. This option is ignored by
3461 Set the option corresponding to OPTION-NAME:
3470 Use an `emacs'-style line editing interface (*note
3471 Command Line Editing::). This also affects the editing
3472 interface used for `read -e'.
3490 Enable command history, as described in *note Bash
3491 History Facilities::. This option is on by default in
3495 An interactive shell will not exit upon reading EOF.
3528 If set, the return value of a pipeline is the value of
3529 the last (rightmost) command to exit with a non-zero
3530 status, or zero if all commands in the pipeline exit
3531 successfully. This option is disabled by default.
3534 Change the behavior of Bash where the default operation
3535 differs from the POSIX standard to match the standard
3536 (*note Bash POSIX Mode::). This is intended to make
3537 Bash behave as a strict superset of that standard.
3546 Use a `vi'-style line editing interface. This also
3547 affects the editing interface used for `read -e'.
3553 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3554 `$ENV' files are not processed, shell functions are not
3555 inherited from the environment, and the `SHELLOPTS', `CDPATH'
3556 and `GLOBIGNORE' variables, if they appear in the
3557 environment, are ignored. If the shell is started with the
3558 effective user (group) id not equal to the real user (group)
3559 id, and the `-p' option is not supplied, these actions are
3560 taken and the effective user id is set to the real user id.
3561 If the `-p' option is supplied at startup, the effective user
3562 id is not reset. Turning this option off causes the
3563 effective user and group ids to be set to the real user and
3567 Exit after reading and executing one command.
3570 Treat unset variables as an error when performing parameter
3571 expansion. An error message will be written to the standard
3572 error, and a non-interactive shell will exit.
3575 Print shell input lines as they are read.
3578 Print a trace of simple commands, `for' commands, `case'
3579 commands, `select' commands, and arithmetic `for' commands
3580 and their arguments or associated word lists after they are
3581 expanded and before they are executed. The value of the `PS4'
3582 variable is expanded and the resultant value is printed before
3583 the command and its expanded arguments.
3586 The shell will perform brace expansion (*note Brace
3587 Expansion::). This option is on by default.
3590 Prevent output redirection using `>', `>&', and `<>' from
3591 overwriting existing files.
3594 If set, any trap on `ERR' is inherited by shell functions,
3595 command substitutions, and commands executed in a subshell
3596 environment. The `ERR' trap is normally not inherited in
3600 Enable `!' style history substitution (*note History
3601 Interaction::). This option is on by default for interactive
3605 If set, do not follow symbolic links when performing commands
3606 such as `cd' which change the current directory. The
3607 physical directory is used instead. By default, Bash follows
3608 the logical chain of directories when performing commands
3609 which change the current directory.
3611 For example, if `/usr/sys' is a symbolic link to
3612 `/usr/local/sys' then:
3613 $ cd /usr/sys; echo $PWD
3618 If `set -P' is on, then:
3619 $ cd /usr/sys; echo $PWD
3625 If set, any trap on `DEBUG' and `RETURN' are inherited by
3626 shell functions, command substitutions, and commands executed
3627 in a subshell environment. The `DEBUG' and `RETURN' traps
3628 are normally not inherited in such cases.
3631 If no arguments follow this option, then the positional
3632 parameters are unset. Otherwise, the positional parameters
3633 are set to the ARGUMENTS, even if some of them begin with a
3637 Signal the end of options, cause all remaining ARGUMENTS to
3638 be assigned to the positional parameters. The `-x' and `-v'
3639 options are turned off. If there are no arguments, the
3640 positional parameters remain unchanged.
3642 Using `+' rather than `-' causes these options to be turned off.
3643 The options can also be used upon invocation of the shell. The
3644 current set of options may be found in `$-'.
3646 The remaining N ARGUMENTS are positional parameters and are
3647 assigned, in order, to `$1', `$2', ... `$N'. The special
3648 parameter `#' is set to N.
3650 The return status is always zero unless an invalid option is
3654 File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
3656 4.3.2 The Shopt Builtin
3657 -----------------------
3659 This builtin allows you to change additional shell optional behavior.
3662 shopt [-pqsu] [-o] [OPTNAME ...]
3663 Toggle the values of variables controlling optional shell behavior.
3664 With no options, or with the `-p' option, a list of all settable
3665 options is displayed, with an indication of whether or not each is
3666 set. The `-p' option causes output to be displayed in a form that
3667 may be reused as input. Other options have the following meanings:
3670 Enable (set) each OPTNAME.
3673 Disable (unset) each OPTNAME.
3676 Suppresses normal output; the return status indicates whether
3677 the OPTNAME is set or unset. If multiple OPTNAME arguments
3678 are given with `-q', the return status is zero if all
3679 OPTNAMES are enabled; non-zero otherwise.
3682 Restricts the values of OPTNAME to be those defined for the
3683 `-o' option to the `set' builtin (*note The Set Builtin::).
3685 If either `-s' or `-u' is used with no OPTNAME arguments, the
3686 display is limited to those options which are set or unset,
3689 Unless otherwise noted, the `shopt' options are disabled (off) by
3692 The return status when listing options is zero if all OPTNAMES are
3693 enabled, non-zero otherwise. When setting or unsetting options,
3694 the return status is zero unless an OPTNAME is not a valid shell
3697 The list of `shopt' options is:
3699 If set, a command name that is the name of a directory is
3700 executed as if it were the argument to the `cd' command.
3701 This option is only used by interactive shells.
3704 If this is set, an argument to the `cd' builtin command that
3705 is not a directory is assumed to be the name of a variable
3706 whose value is the directory to change to.
3709 If set, minor errors in the spelling of a directory component
3710 in a `cd' command will be corrected. The errors checked for
3711 are transposed characters, a missing character, and a
3712 character too many. If a correction is found, the corrected
3713 path is printed, and the command proceeds. This option is
3714 only used by interactive shells.
3717 If this is set, Bash checks that a command found in the hash
3718 table exists before trying to execute it. If a hashed
3719 command no longer exists, a normal path search is performed.
3722 If set, Bash lists the status of any stopped and running jobs
3723 before exiting an interactive shell. If any jobs are
3724 running, this causes the exit to be deferred until a second
3725 exit is attempted without an intervening command (*note Job
3726 Control::). The shell always postpones exiting if any jobs
3730 If set, Bash checks the window size after each command and,
3731 if necessary, updates the values of `LINES' and `COLUMNS'.
3734 If set, Bash attempts to save all lines of a multiple-line
3735 command in the same history entry. This allows easy
3736 re-editing of multi-line commands.
3739 If set, Bash changes its behavior to that of version 3.1 with
3740 respect to quoted arguments to the conditional command's =~
3744 If set, Bash attempts spelling correction on directory names
3745 during word completion if the directory name initially
3746 supplied does not exist.
3749 If set, Bash includes filenames beginning with a `.' in the
3750 results of filename expansion.
3753 If this is set, a non-interactive shell will not exit if it
3754 cannot execute the file specified as an argument to the `exec'
3755 builtin command. An interactive shell does not exit if `exec'
3759 If set, aliases are expanded as described below under Aliases,
3760 *note Aliases::. This option is enabled by default for
3764 If set, behavior intended for use by debuggers is enabled:
3766 1. The `-F' option to the `declare' builtin (*note Bash
3767 Builtins::) displays the source file name and line
3768 number corresponding to each function name supplied as
3771 2. If the command run by the `DEBUG' trap returns a
3772 non-zero value, the next command is skipped and not
3775 3. If the command run by the `DEBUG' trap returns a value
3776 of 2, and the shell is executing in a subroutine (a
3777 shell function or a shell script executed by the `.' or
3778 `source' builtins), a call to `return' is simulated.
3780 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in
3781 their descriptions (*note Bash Variables::).
3783 5. Function tracing is enabled: command substitution,
3784 shell functions, and subshells invoked with `( COMMAND
3785 )' inherit the `DEBUG' and `RETURN' traps.
3787 6. Error tracing is enabled: command substitution, shell
3788 functions, and subshells invoked with `( COMMAND )'
3789 inherit the `ERROR' trap.
3792 If set, the extended pattern matching features described above
3793 (*note Pattern Matching::) are enabled.
3796 If set, `$'STRING'' and `$"STRING"' quoting is performed
3797 within `${PARAMETER}' expansions enclosed in double quotes.
3798 This option is enabled by default.
3801 If set, patterns which fail to match filenames during
3802 pathname expansion result in an expansion error.
3805 If set, the suffixes specified by the `FIGNORE' shell variable
3806 cause words to be ignored when performing word completion
3807 even if the ignored words are the only possible completions.
3808 *Note Bash Variables::, for a description of `FIGNORE'. This
3809 option is enabled by default.
3812 If set, the pattern `**' used in a filename expansion context
3813 will match a files and zero or more directories and
3814 subdirectories. If the pattern is followed by a `/', only
3815 directories and subdirectories match.
3818 If set, shell error messages are written in the standard GNU
3819 error message format.
3822 If set, the history list is appended to the file named by the
3823 value of the `HISTFILE' variable when the shell exits, rather
3824 than overwriting the file.
3827 If set, and Readline is being used, a user is given the
3828 opportunity to re-edit a failed history substitution.
3831 If set, and Readline is being used, the results of history
3832 substitution are not immediately passed to the shell parser.
3833 Instead, the resulting line is loaded into the Readline
3834 editing buffer, allowing further modification.
3837 If set, and Readline is being used, Bash will attempt to
3838 perform hostname completion when a word containing a `@' is
3839 being completed (*note Commands For Completion::). This
3840 option is enabled by default.
3843 If set, Bash will send `SIGHUP' to all jobs when an
3844 interactive login shell exits (*note Signals::).
3846 `interactive_comments'
3847 Allow a word beginning with `#' to cause that word and all
3848 remaining characters on that line to be ignored in an
3849 interactive shell. This option is enabled by default.
3852 If enabled, and the `cmdhist' option is enabled, multi-line
3853 commands are saved to the history with embedded newlines
3854 rather than using semicolon separators where possible.
3857 The shell sets this option if it is started as a login shell
3858 (*note Invoking Bash::). The value may not be changed.
3861 If set, and a file that Bash is checking for mail has been
3862 accessed since the last time it was checked, the message
3863 `"The mail in MAILFILE has been read"' is displayed.
3865 `no_empty_cmd_completion'
3866 If set, and Readline is being used, Bash will not attempt to
3867 search the `PATH' for possible completions when completion is
3868 attempted on an empty line.
3871 If set, Bash matches filenames in a case-insensitive fashion
3872 when performing filename expansion.
3875 If set, Bash matches patterns in a case-insensitive fashion
3876 when performing matching while executing `case' or `[['
3877 conditional commands.
3880 If set, Bash allows filename patterns which match no files to
3881 expand to a null string, rather than themselves.
3884 If set, the programmable completion facilities (*note
3885 Programmable Completion::) are enabled. This option is
3889 If set, prompt strings undergo parameter expansion, command
3890 substitution, arithmetic expansion, and quote removal after
3891 being expanded as described below (*note Printing a Prompt::).
3892 This option is enabled by default.
3895 The shell sets this option if it is started in restricted mode
3896 (*note The Restricted Shell::). The value may not be changed.
3897 This is not reset when the startup files are executed,
3898 allowing the startup files to discover whether or not a shell
3902 If this is set, the `shift' builtin prints an error message
3903 when the shift count exceeds the number of positional
3907 If set, the `source' builtin uses the value of `PATH' to find
3908 the directory containing the file supplied as an argument.
3909 This option is enabled by default.
3912 If set, the `echo' builtin expands backslash-escape sequences
3916 The return status when listing options is zero if all OPTNAMES are
3917 enabled, non-zero otherwise. When setting or unsetting options,
3918 the return status is zero unless an OPTNAME is not a valid shell
3923 File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
3925 4.4 Special Builtins
3926 ====================
3928 For historical reasons, the POSIX standard has classified several
3929 builtin commands as _special_. When Bash is executing in POSIX mode,
3930 the special builtins differ from other builtin commands in three
3933 1. Special builtins are found before shell functions during command
3936 2. If a special builtin returns an error status, a non-interactive
3939 3. Assignment statements preceding the command stay in effect in the
3940 shell environment after the command completes.
3942 When Bash is not executing in POSIX mode, these builtins behave no
3943 differently than the rest of the Bash builtin commands. The Bash POSIX
3944 mode is described in *note Bash POSIX Mode::.
3946 These are the POSIX special builtins:
3947 break : . continue eval exec exit export readonly return set
3951 File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
3958 * Bourne Shell Variables:: Variables which Bash uses in the same way
3959 as the Bourne Shell.
3960 * Bash Variables:: List of variables that exist in Bash.
3962 This chapter describes the shell variables that Bash uses. Bash
3963 automatically assigns default values to a number of variables.
3966 File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
3968 5.1 Bourne Shell Variables
3969 ==========================
3971 Bash uses certain shell variables in the same way as the Bourne shell.
3972 In some cases, Bash assigns a default value to the variable.
3975 A colon-separated list of directories used as a search path for
3976 the `cd' builtin command.
3979 The current user's home directory; the default for the `cd' builtin
3980 command. The value of this variable is also used by tilde
3981 expansion (*note Tilde Expansion::).
3984 A list of characters that separate fields; used when the shell
3985 splits words as part of expansion.
3988 If this parameter is set to a filename and the `MAILPATH' variable
3989 is not set, Bash informs the user of the arrival of mail in the
3993 A colon-separated list of filenames which the shell periodically
3994 checks for new mail. Each list entry can specify the message that
3995 is printed when new mail arrives in the mail file by separating
3996 the file name from the message with a `?'. When used in the text
3997 of the message, `$_' expands to the name of the current mail file.
4000 The value of the last option argument processed by the `getopts'
4004 The index of the last option argument processed by the `getopts'
4008 A colon-separated list of directories in which the shell looks for
4009 commands. A zero-length (null) directory name in the value of
4010 `PATH' indicates the current directory. A null directory name may
4011 appear as two adjacent colons, or as an initial or trailing colon.
4014 The primary prompt string. The default value is `\s-\v\$ '.
4015 *Note Printing a Prompt::, for the complete list of escape
4016 sequences that are expanded before `PS1' is displayed.
4019 The secondary prompt string. The default value is `> '.
4023 File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
4028 These variables are set or used by Bash, but other shells do not
4029 normally treat them specially.
4031 A few variables used by Bash are described in different chapters:
4032 variables for controlling the job control facilities (*note Job Control
4036 The full pathname used to execute the current instance of Bash.
4039 Expands to the process id of the current Bash process. This
4040 differs from `$$' under certain circumstances, such as subshells
4041 that do not require Bash to be re-initialized.
4044 An associative array variable whose members correspond to the
4045 internal list of aliases as maintained by the `alias' builtin
4046 (*note Bourne Shell Builtins::). Elements added to this array
4047 appear in the alias list; unsetting array elements cause aliases
4048 to be removed from the alias list.
4051 An array variable whose values are the number of parameters in each
4052 frame of the current bash execution call stack. The number of
4053 parameters to the current subroutine (shell function or script
4054 executed with `.' or `source') is at the top of the stack. When a
4055 subroutine is executed, the number of parameters passed is pushed
4056 onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in
4057 extended debugging mode (see *note The Shopt Builtin:: for a
4058 description of the `extdebug' option to the `shopt' builtin).
4061 An array variable containing all of the parameters in the current
4062 bash execution call stack. The final parameter of the last
4063 subroutine call is at the top of the stack; the first parameter of
4064 the initial call is at the bottom. When a subroutine is executed,
4065 the parameters supplied are pushed onto `BASH_ARGV'. The shell
4066 sets `BASH_ARGV' only when in extended debugging mode (see *note
4067 The Shopt Builtin:: for a description of the `extdebug' option to
4068 the `shopt' builtin).
4071 An associative array variable whose members correspond to the
4072 internal hash table of commands as maintained by the `hash' builtin
4073 (*note Bourne Shell Builtins::). Elements added to this array
4074 appear in the hash table; unsetting array elements cause commands
4075 to be removed from the hash table.
4078 The command currently being executed or about to be executed,
4079 unless the shell is executing a command as the result of a trap,
4080 in which case it is the command executing at the time of the trap.
4083 If this variable is set when Bash is invoked to execute a shell
4084 script, its value is expanded and used as the name of a startup
4085 file to read before executing the script. *Note Bash Startup
4088 `BASH_EXECUTION_STRING'
4089 The command argument to the `-c' invocation option.
4092 An array variable whose members are the line numbers in source
4093 files corresponding to each member of FUNCNAME.
4094 `${BASH_LINENO[$i]}' is the line number in the source file where
4095 `${FUNCNAME[$i]}' was called (or `${BASH_LINENO[$i-1]}' if
4096 referenced within another shell function). The corresponding
4097 source file name is `${BASH_SOURCE[$i]}'. Use `LINENO' to obtain
4098 the current line number.
4101 An array variable whose members are assigned by the `=~' binary
4102 operator to the `[[' conditional command (*note Conditional
4103 Constructs::). The element with index 0 is the portion of the
4104 string matching the entire regular expression. The element with
4105 index N is the portion of the string matching the Nth
4106 parenthesized subexpression. This variable is read-only.
4109 An array variable whose members are the source filenames
4110 corresponding to the elements in the `FUNCNAME' array variable.
4113 Incremented by one each time a subshell or subshell environment is
4114 spawned. The initial value is 0.
4117 A readonly array variable (*note Arrays::) whose members hold
4118 version information for this instance of Bash. The values
4119 assigned to the array members are as follows:
4122 The major version number (the RELEASE).
4125 The minor version number (the VERSION).
4134 The release status (e.g., BETA1).
4137 The value of `MACHTYPE'.
4141 The version number of the current instance of Bash.
4144 Used by the `select' builtin command to determine the terminal
4145 width when printing selection lists. Automatically set upon
4146 receipt of a `SIGWINCH'.
4149 An index into `${COMP_WORDS}' of the word containing the current
4150 cursor position. This variable is available only in shell
4151 functions invoked by the programmable completion facilities (*note
4152 Programmable Completion::).
4155 The current command line. This variable is available only in
4156 shell functions and external commands invoked by the programmable
4157 completion facilities (*note Programmable Completion::).
4160 The index of the current cursor position relative to the beginning
4161 of the current command. If the current cursor position is at the
4162 end of the current command, the value of this variable is equal to
4163 `${#COMP_LINE}'. This variable is available only in shell
4164 functions and external commands invoked by the programmable
4165 completion facilities (*note Programmable Completion::).
4168 Set to an integer value corresponding to the type of completion
4169 attempted that caused a completion function to be called: TAB, for
4170 normal completion, `?', for listing completions after successive
4171 tabs, `!', for listing alternatives on partial word completion,
4172 `@', to list completions if the word is not unmodified, or `%',
4173 for menu completion. This variable is available only in shell
4174 functions and external commands invoked by the programmable
4175 completion facilities (*note Programmable Completion::).
4178 The key (or final key of a key sequence) used to invoke the current
4179 completion function.
4182 The set of characters that the Readline library treats as word
4183 separators when performing word completion. If `COMP_WORDBREAKS'
4184 is unset, it loses its special properties, even if it is
4188 An array variable consisting of the individual words in the
4189 current command line. The words are split on shell metacharacters
4190 as the shell parser would separate them. This variable is
4191 available only in shell functions invoked by the programmable
4192 completion facilities (*note Programmable Completion::).
4195 An array variable from which Bash reads the possible completions
4196 generated by a shell function invoked by the programmable
4197 completion facility (*note Programmable Completion::).
4200 An array variable containing the current contents of the directory
4201 stack. Directories appear in the stack in the order they are
4202 displayed by the `dirs' builtin. Assigning to members of this
4203 array variable may be used to modify directories already in the
4204 stack, but the `pushd' and `popd' builtins must be used to add and
4205 remove directories. Assignment to this variable will not change
4206 the current directory. If `DIRSTACK' is unset, it loses its
4207 special properties, even if it is subsequently reset.
4210 If Bash finds this variable in the environment when the shell
4211 starts with value `t', it assumes that the shell is running in an
4212 emacs shell buffer and disables line editing.
4215 The numeric effective user id of the current user. This variable
4219 The editor used as a default by the `-e' option to the `fc'
4223 A colon-separated list of suffixes to ignore when performing
4224 filename completion. A file name whose suffix matches one of the
4225 entries in `FIGNORE' is excluded from the list of matched file
4226 names. A sample value is `.o:~'
4229 An array variable containing the names of all shell functions
4230 currently in the execution call stack. The element with index 0
4231 is the name of any currently-executing shell function. The
4232 bottom-most element is `"main"'. This variable exists only when a
4233 shell function is executing. Assignments to `FUNCNAME' have no
4234 effect and return an error status. If `FUNCNAME' is unset, it
4235 loses its special properties, even if it is subsequently reset.
4238 A colon-separated list of patterns defining the set of filenames to
4239 be ignored by filename expansion. If a filename matched by a
4240 filename expansion pattern also matches one of the patterns in
4241 `GLOBIGNORE', it is removed from the list of matches.
4244 An array variable containing the list of groups of which the
4245 current user is a member. Assignments to `GROUPS' have no effect
4246 and return an error status. If `GROUPS' is unset, it loses its
4247 special properties, even if it is subsequently reset.
4250 Up to three characters which control history expansion, quick
4251 substitution, and tokenization (*note History Interaction::). The
4252 first character is the HISTORY EXPANSION character, that is, the
4253 character which signifies the start of a history expansion,
4254 normally `!'. The second character is the character which
4255 signifies `quick substitution' when seen as the first character on
4256 a line, normally `^'. The optional third character is the
4257 character which indicates that the remainder of the line is a
4258 comment when found as the first character of a word, usually `#'.
4259 The history comment character causes history substitution to be
4260 skipped for the remaining words on the line. It does not
4261 necessarily cause the shell parser to treat the rest of the line
4265 The history number, or index in the history list, of the current
4266 command. If `HISTCMD' is unset, it loses its special properties,
4267 even if it is subsequently reset.
4270 A colon-separated list of values controlling how commands are
4271 saved on the history list. If the list of values includes
4272 `ignorespace', lines which begin with a space character are not
4273 saved in the history list. A value of `ignoredups' causes lines
4274 which match the previous history entry to not be saved. A value
4275 of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'.
4276 A value of `erasedups' causes all previous lines matching the
4277 current line to be removed from the history list before that line
4278 is saved. Any value not in the above list is ignored. If
4279 `HISTCONTROL' is unset, or does not include a valid value, all
4280 lines read by the shell parser are saved on the history list,
4281 subject to the value of `HISTIGNORE'. The second and subsequent
4282 lines of a multi-line compound command are not tested, and are
4283 added to the history regardless of the value of `HISTCONTROL'.
4286 The name of the file to which the command history is saved. The
4287 default value is `~/.bash_history'.
4290 The maximum number of lines contained in the history file. When
4291 this variable is assigned a value, the history file is truncated,
4292 if necessary, by removing the oldest entries, to contain no more
4293 than that number of lines. The history file is also truncated to
4294 this size after writing it when an interactive shell exits. The
4295 default value is 500.
4298 A colon-separated list of patterns used to decide which command
4299 lines should be saved on the history list. Each pattern is
4300 anchored at the beginning of the line and must match the complete
4301 line (no implicit `*' is appended). Each pattern is tested
4302 against the line after the checks specified by `HISTCONTROL' are
4303 applied. In addition to the normal shell pattern matching
4304 characters, `&' matches the previous history line. `&' may be
4305 escaped using a backslash; the backslash is removed before
4306 attempting a match. The second and subsequent lines of a
4307 multi-line compound command are not tested, and are added to the
4308 history regardless of the value of `HISTIGNORE'.
4310 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
4311 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
4312 identical to `ignorespace'. Combining these two patterns,
4313 separating them with a colon, provides the functionality of
4317 The maximum number of commands to remember on the history list.
4318 The default value is 500.
4321 If this variable is set and not null, its value is used as a
4322 format string for STRFTIME to print the time stamp associated with
4323 each history entry displayed by the `history' builtin. If this
4324 variable is set, time stamps are written to the history file so
4325 they may be preserved across shell sessions. This uses the
4326 history comment character to distinguish timestamps from other
4330 Contains the name of a file in the same format as `/etc/hosts' that
4331 should be read when the shell needs to complete a hostname. The
4332 list of possible hostname completions may be changed while the
4333 shell is running; the next time hostname completion is attempted
4334 after the value is changed, Bash adds the contents of the new file
4335 to the existing list. If `HOSTFILE' is set, but has no value,
4336 Bash attempts to read `/etc/hosts' to obtain the list of possible
4337 hostname completions. When `HOSTFILE' is unset, the hostname list
4341 The name of the current host.
4344 A string describing the machine Bash is running on.
4347 Controls the action of the shell on receipt of an `EOF' character
4348 as the sole input. If set, the value denotes the number of
4349 consecutive `EOF' characters that can be read as the first
4350 character on an input line before the shell will exit. If the
4351 variable exists but does not have a numeric value (or has no
4352 value) then the default is 10. If the variable does not exist,
4353 then `EOF' signifies the end of input to the shell. This is only
4354 in effect for interactive shells.
4357 The name of the Readline initialization file, overriding the
4358 default of `~/.inputrc'.
4361 Used to determine the locale category for any category not
4362 specifically selected with a variable starting with `LC_'.
4365 This variable overrides the value of `LANG' and any other `LC_'
4366 variable specifying a locale category.
4369 This variable determines the collation order used when sorting the
4370 results of filename expansion, and determines the behavior of
4371 range expressions, equivalence classes, and collating sequences
4372 within filename expansion and pattern matching (*note Filename
4376 This variable determines the interpretation of characters and the
4377 behavior of character classes within filename expansion and pattern
4378 matching (*note Filename Expansion::).
4381 This variable determines the locale used to translate double-quoted
4382 strings preceded by a `$' (*note Locale Translation::).
4385 This variable determines the locale category used for number
4389 The line number in the script or shell function currently
4393 Used by the `select' builtin command to determine the column length
4394 for printing selection lists. Automatically set upon receipt of a
4398 A string that fully describes the system type on which Bash is
4399 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
4402 How often (in seconds) that the shell should check for mail in the
4403 files specified in the `MAILPATH' or `MAIL' variables. The
4404 default is 60 seconds. When it is time to check for mail, the
4405 shell does so before displaying the primary prompt. If this
4406 variable is unset, or set to a value that is not a number greater
4407 than or equal to zero, the shell disables mail checking.
4410 The previous working directory as set by the `cd' builtin.
4413 If set to the value 1, Bash displays error messages generated by
4414 the `getopts' builtin command.
4417 A string describing the operating system Bash is running on.
4420 An array variable (*note Arrays::) containing a list of exit
4421 status values from the processes in the most-recently-executed
4422 foreground pipeline (which may contain only a single command).
4425 If this variable is in the environment when `bash' starts, the
4426 shell enters POSIX mode (*note Bash POSIX Mode::) before reading
4427 the startup files, as if the `--posix' invocation option had been
4428 supplied. If it is set while the shell is running, `bash' enables
4429 POSIX mode, as if the command
4434 The process ID of the shell's parent process. This variable is
4438 If set, the value is interpreted as a command to execute before
4439 the printing of each primary prompt (`$PS1').
4442 If set to a number greater than zero, the value is used as the
4443 number of trailing directory components to retain when expanding
4444 the `\w' and `\W' prompt string escapes (*note Printing a
4445 Prompt::). Characters removed are replaced with an ellipsis.
4448 The value of this variable is used as the prompt for the `select'
4449 command. If this variable is not set, the `select' command
4453 The value is the prompt printed before the command line is echoed
4454 when the `-x' option is set (*note The Set Builtin::). The first
4455 character of `PS4' is replicated multiple times, as necessary, to
4456 indicate multiple levels of indirection. The default is `+ '.
4459 The current working directory as set by the `cd' builtin.
4462 Each time this parameter is referenced, a random integer between 0
4463 and 32767 is generated. Assigning a value to this variable seeds
4464 the random number generator.
4467 The default variable for the `read' builtin.
4470 This variable expands to the number of seconds since the shell was
4471 started. Assignment to this variable resets the count to the
4472 value assigned, and the expanded value becomes the value assigned
4473 plus the number of seconds since the assignment.
4476 The full pathname to the shell is kept in this environment
4477 variable. If it is not set when the shell starts, Bash assigns to
4478 it the full pathname of the current user's login shell.
4481 A colon-separated list of enabled shell options. Each word in the
4482 list is a valid argument for the `-o' option to the `set' builtin
4483 command (*note The Set Builtin::). The options appearing in
4484 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4485 variable is in the environment when Bash starts up, each shell
4486 option in the list will be enabled before reading any startup
4487 files. This variable is readonly.
4490 Incremented by one each time a new instance of Bash is started.
4491 This is intended to be a count of how deeply your Bash shells are
4495 The value of this parameter is used as a format string specifying
4496 how the timing information for pipelines prefixed with the `time'
4497 reserved word should be displayed. The `%' character introduces an
4498 escape sequence that is expanded to a time value or other
4499 information. The escape sequences and their meanings are as
4500 follows; the braces denote optional portions.
4506 The elapsed time in seconds.
4509 The number of CPU seconds spent in user mode.
4512 The number of CPU seconds spent in system mode.
4515 The CPU percentage, computed as (%U + %S) / %R.
4517 The optional P is a digit specifying the precision, the number of
4518 fractional digits after a decimal point. A value of 0 causes no
4519 decimal point or fraction to be output. At most three places
4520 after the decimal point may be specified; values of P greater than
4521 3 are changed to 3. If P is not specified, the value 3 is used.
4523 The optional `l' specifies a longer format, including minutes, of
4524 the form MMmSS.FFs. The value of P determines whether or not the
4525 fraction is included.
4527 If this variable is not set, Bash acts as if it had the value
4528 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4529 If the value is null, no timing information is displayed. A
4530 trailing newline is added when the format string is displayed.
4533 If set to a value greater than zero, `TMOUT' is treated as the
4534 default timeout for the `read' builtin (*note Bash Builtins::).
4535 The `select' command (*note Conditional Constructs::) terminates
4536 if input does not arrive after `TMOUT' seconds when input is coming
4539 In an interactive shell, the value is interpreted as the number of
4540 seconds to wait for input after issuing the primary prompt when
4541 the shell is interactive. Bash terminates after that number of
4542 seconds if input does not arrive.
4545 If set, Bash uses its value as the name of a directory in which
4546 Bash creates temporary files for the shell's use.
4549 The numeric real user id of the current user. This variable is
4554 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
4559 This section describes features unique to Bash.
4563 * Invoking Bash:: Command line options that you can give
4565 * Bash Startup Files:: When and how Bash executes scripts.
4566 * Interactive Shells:: What an interactive shell is.
4567 * Bash Conditional Expressions:: Primitives used in composing expressions for
4569 * Shell Arithmetic:: Arithmetic on shell variables.
4570 * Aliases:: Substituting one command for another.
4571 * Arrays:: Array Variables.
4572 * The Directory Stack:: History of visited directories.
4573 * Printing a Prompt:: Controlling the PS1 string.
4574 * The Restricted Shell:: A more controlled mode of shell execution.
4575 * Bash POSIX Mode:: Making Bash behave more closely to what
4576 the POSIX standard specifies.
4579 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
4584 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4585 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
4586 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4588 In addition to the single-character shell command-line options
4589 (*note The Set Builtin::), there are several multi-character options
4590 that you can use. These options must appear on the command line before
4591 the single-character options to be recognized.
4594 Arrange for the debugger profile to be executed before the shell
4595 starts. Turns on extended debugging mode (see *note The Shopt
4596 Builtin:: for a description of the `extdebug' option to the `shopt'
4597 builtin) and shell function tracing (see *note The Set Builtin::
4598 for a description of the `-o functrace' option).
4601 A list of all double-quoted strings preceded by `$' is printed on
4602 the standard output in the GNU `gettext' PO (portable object) file
4603 format. Equivalent to `-D' except for the output format.
4609 Display a usage message on standard output and exit successfully.
4611 `--init-file FILENAME'
4613 Execute commands from FILENAME (instead of `~/.bashrc') in an
4620 Do not use the GNU Readline library (*note Command Line Editing::)
4621 to read command lines when the shell is interactive.
4624 Don't load the system-wide startup file `/etc/profile' or any of
4625 the personal initialization files `~/.bash_profile',
4626 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
4630 Don't read the `~/.bashrc' initialization file in an interactive
4631 shell. This is on by default if the shell is invoked as `sh'.
4634 Change the behavior of Bash where the default operation differs
4635 from the POSIX standard to match the standard. This is intended
4636 to make Bash behave as a strict superset of that standard. *Note
4637 Bash POSIX Mode::, for a description of the Bash POSIX mode.
4640 Make the shell a restricted shell (*note The Restricted Shell::).
4643 Equivalent to `-v'. Print shell input lines as they're read.
4646 Show version information for this instance of Bash on the standard
4647 output and exit successfully.
4650 There are several single-character options that may be supplied at
4651 invocation which are not available with the `set' builtin.
4654 Read and execute commands from STRING after processing the
4655 options, then exit. Any remaining arguments are assigned to the
4656 positional parameters, starting with `$0'.
4659 Force the shell to run interactively. Interactive shells are
4660 described in *note Interactive Shells::.
4663 Make this shell act as if it had been directly invoked by login.
4664 When the shell is interactive, this is equivalent to starting a
4665 login shell with `exec -l bash'. When the shell is not
4666 interactive, the login shell startup files will be executed.
4667 `exec bash -l' or `exec bash --login' will replace the current
4668 shell with a Bash login shell. *Note Bash Startup Files::, for a
4669 description of the special behavior of a login shell.
4672 Make the shell a restricted shell (*note The Restricted Shell::).
4675 If this option is present, or if no arguments remain after option
4676 processing, then commands are read from the standard input. This
4677 option allows the positional parameters to be set when invoking an
4681 A list of all double-quoted strings preceded by `$' is printed on
4682 the standard output. These are the strings that are subject to
4683 language translation when the current locale is not `C' or `POSIX'
4684 (*note Locale Translation::). This implies the `-n' option; no
4685 commands will be executed.
4687 `[-+]O [SHOPT_OPTION]'
4688 SHOPT_OPTION is one of the shell options accepted by the `shopt'
4689 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
4690 `-O' sets the value of that option; `+O' unsets it. If
4691 SHOPT_OPTION is not supplied, the names and values of the shell
4692 options accepted by `shopt' are printed on the standard output.
4693 If the invocation option is `+O', the output is displayed in a
4694 format that may be reused as input.
4697 A `--' signals the end of options and disables further option
4698 processing. Any arguments after the `--' are treated as filenames
4702 A _login_ shell is one whose first character of argument zero is
4703 `-', or one invoked with the `--login' option.
4705 An _interactive_ shell is one started without non-option arguments,
4706 unless `-s' is specified, without specifying the `-c' option, and whose
4707 input and output are both connected to terminals (as determined by
4708 `isatty(3)'), or one started with the `-i' option. *Note Interactive
4709 Shells::, for more information.
4711 If arguments remain after option processing, and neither the `-c'
4712 nor the `-s' option has been supplied, the first argument is assumed to
4713 be the name of a file containing shell commands (*note Shell Scripts::).
4714 When Bash is invoked in this fashion, `$0' is set to the name of the
4715 file, and the positional parameters are set to the remaining arguments.
4716 Bash reads and executes commands from this file, then exits. Bash's
4717 exit status is the exit status of the last command executed in the
4718 script. If no commands are executed, the exit status is 0.
4721 File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
4723 6.2 Bash Startup Files
4724 ======================
4726 This section describes how Bash executes its startup files. If any of
4727 the files exist but cannot be read, Bash reports an error. Tildes are
4728 expanded in file names as described above under Tilde Expansion (*note
4731 Interactive shells are described in *note Interactive Shells::.
4733 Invoked as an interactive login shell, or with `--login'
4734 ........................................................
4736 When Bash is invoked as an interactive login shell, or as a
4737 non-interactive shell with the `--login' option, it first reads and
4738 executes commands from the file `/etc/profile', if that file exists.
4739 After reading that file, it looks for `~/.bash_profile',
4740 `~/.bash_login', and `~/.profile', in that order, and reads and
4741 executes commands from the first one that exists and is readable. The
4742 `--noprofile' option may be used when the shell is started to inhibit
4745 When a login shell exits, Bash reads and executes commands from the
4746 file `~/.bash_logout', if it exists.
4748 Invoked as an interactive non-login shell
4749 .........................................
4751 When an interactive shell that is not a login shell is started, Bash
4752 reads and executes commands from `~/.bashrc', if that file exists.
4753 This may be inhibited by using the `--norc' option. The `--rcfile
4754 FILE' option will force Bash to read and execute commands from FILE
4755 instead of `~/.bashrc'.
4757 So, typically, your `~/.bash_profile' contains the line
4758 `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'
4759 after (or before) any login-specific initializations.
4761 Invoked non-interactively
4762 .........................
4764 When Bash is started non-interactively, to run a shell script, for
4765 example, it looks for the variable `BASH_ENV' in the environment,
4766 expands its value if it appears there, and uses the expanded value as
4767 the name of a file to read and execute. Bash behaves as if the
4768 following command were executed:
4769 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
4770 but the value of the `PATH' variable is not used to search for the
4773 As noted above, if a non-interactive shell is invoked with the
4774 `--login' option, Bash attempts to read and execute commands from the
4775 login shell startup files.
4777 Invoked with name `sh'
4778 ......................
4780 If Bash is invoked with the name `sh', it tries to mimic the startup
4781 behavior of historical versions of `sh' as closely as possible, while
4782 conforming to the POSIX standard as well.
4784 When invoked as an interactive login shell, or as a non-interactive
4785 shell with the `--login' option, it first attempts to read and execute
4786 commands from `/etc/profile' and `~/.profile', in that order. The
4787 `--noprofile' option may be used to inhibit this behavior. When
4788 invoked as an interactive shell with the name `sh', Bash looks for the
4789 variable `ENV', expands its value if it is defined, and uses the
4790 expanded value as the name of a file to read and execute. Since a
4791 shell invoked as `sh' does not attempt to read and execute commands
4792 from any other startup files, the `--rcfile' option has no effect. A
4793 non-interactive shell invoked with the name `sh' does not attempt to
4794 read any other startup files.
4796 When invoked as `sh', Bash enters POSIX mode after the startup files
4799 Invoked in POSIX mode
4800 .....................
4802 When Bash is started in POSIX mode, as with the `--posix' command line
4803 option, it follows the POSIX standard for startup files. In this mode,
4804 interactive shells expand the `ENV' variable and commands are read and
4805 executed from the file whose name is the expanded value. No other
4806 startup files are read.
4808 Invoked by remote shell daemon
4809 ..............................
4811 Bash attempts to determine when it is being run with its standard input
4812 connected to a a network connection, as if by the remote shell daemon,
4813 usually `rshd', or the secure shell daemon `sshd'. If Bash determines
4814 it is being run in this fashion, it reads and executes commands from
4815 `~/.bashrc', if that file exists and is readable. It will not do this
4816 if invoked as `sh'. The `--norc' option may be used to inhibit this
4817 behavior, and the `--rcfile' option may be used to force another file
4818 to be read, but `rshd' does not generally invoke the shell with those
4819 options or allow them to be specified.
4821 Invoked with unequal effective and real UID/GIDs
4822 ................................................
4824 If Bash is started with the effective user (group) id not equal to the
4825 real user (group) id, and the `-p' option is not supplied, no startup
4826 files are read, shell functions are not inherited from the environment,
4827 the `SHELLOPTS' variable, if it appears in the environment, is ignored,
4828 and the effective user id is set to the real user id. If the `-p'
4829 option is supplied at invocation, the startup behavior is the same, but
4830 the effective user id is not reset.
4833 File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
4835 6.3 Interactive Shells
4836 ======================
4840 * What is an Interactive Shell?:: What determines whether a shell is Interactive.
4841 * Is this Shell Interactive?:: How to tell if a shell is interactive.
4842 * Interactive Shell Behavior:: What changes in a interactive shell?
4845 File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
4847 6.3.1 What is an Interactive Shell?
4848 -----------------------------------
4850 An interactive shell is one started without non-option arguments,
4851 unless `-s' is specified, without specifying the `-c' option, and whose
4852 input and error output are both connected to terminals (as determined
4853 by `isatty(3)'), or one started with the `-i' option.
4855 An interactive shell generally reads from and writes to a user's
4858 The `-s' invocation option may be used to set the positional
4859 parameters when an interactive shell is started.
4862 File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
4864 6.3.2 Is this Shell Interactive?
4865 --------------------------------
4867 To determine within a startup script whether or not Bash is running
4868 interactively, test the value of the `-' special parameter. It
4869 contains `i' when the shell is interactive. For example:
4872 *i*) echo This shell is interactive ;;
4873 *) echo This shell is not interactive ;;
4876 Alternatively, startup scripts may examine the variable `PS1'; it is
4877 unset in non-interactive shells, and set in interactive shells. Thus:
4879 if [ -z "$PS1" ]; then
4880 echo This shell is not interactive
4882 echo This shell is interactive
4886 File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
4888 6.3.3 Interactive Shell Behavior
4889 --------------------------------
4891 When the shell is running interactively, it changes its behavior in
4894 1. Startup files are read and executed as described in *note Bash
4897 2. Job Control (*note Job Control::) is enabled by default. When job
4898 control is in effect, Bash ignores the keyboard-generated job
4899 control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
4901 3. Bash expands and displays `PS1' before reading the first line of a
4902 command, and expands and displays `PS2' before reading the second
4903 and subsequent lines of a multi-line command.
4905 4. Bash executes the value of the `PROMPT_COMMAND' variable as a
4906 command before printing the primary prompt, `$PS1' (*note Bash
4909 5. Readline (*note Command Line Editing::) is used to read commands
4910 from the user's terminal.
4912 6. Bash inspects the value of the `ignoreeof' option to `set -o'
4913 instead of exiting immediately when it receives an `EOF' on its
4914 standard input when reading a command (*note The Set Builtin::).
4916 7. Command history (*note Bash History Facilities::) and history
4917 expansion (*note History Interaction::) are enabled by default.
4918 Bash will save the command history to the file named by `$HISTFILE'
4919 when an interactive shell exits.
4921 8. Alias expansion (*note Aliases::) is performed by default.
4923 9. In the absence of any traps, Bash ignores `SIGTERM' (*note
4926 10. In the absence of any traps, `SIGINT' is caught and handled
4927 ((*note Signals::). `SIGINT' will interrupt some shell builtins.
4929 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
4930 the `huponexit' shell option has been enabled (*note Signals::).
4932 12. The `-n' invocation option is ignored, and `set -n' has no effect
4933 (*note The Set Builtin::).
4935 13. Bash will check for mail periodically, depending on the values of
4936 the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
4939 14. Expansion errors due to references to unbound shell variables after
4940 `set -u' has been enabled will not cause the shell to exit (*note
4943 15. The shell will not exit on expansion errors caused by VAR being
4944 unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
4947 16. Redirection errors encountered by shell builtins will not cause the
4950 17. When running in POSIX mode, a special builtin returning an error
4951 status will not cause the shell to exit (*note Bash POSIX Mode::).
4953 18. A failed `exec' will not cause the shell to exit (*note Bourne
4956 19. Parser syntax errors will not cause the shell to exit.
4958 20. Simple spelling correction for directory arguments to the `cd'
4959 builtin is enabled by default (see the description of the `cdspell'
4960 option to the `shopt' builtin in *note The Shopt Builtin::).
4962 21. The shell will check the value of the `TMOUT' variable and exit if
4963 a command is not read within the specified number of seconds after
4964 printing `$PS1' (*note Bash Variables::).
4968 File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
4970 6.4 Bash Conditional Expressions
4971 ================================
4973 Conditional expressions are used by the `[[' compound command and the
4974 `test' and `[' builtin commands.
4976 Expressions may be unary or binary. Unary expressions are often
4977 used to examine the status of a file. There are string operators and
4978 numeric comparison operators as well. If the FILE argument to one of
4979 the primaries is of the form `/dev/fd/N', then file descriptor N is
4980 checked. If the FILE argument to one of the primaries is one of
4981 `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
4982 2, respectively, is checked.
4984 Unless otherwise specified, primaries that operate on files follow
4985 symbolic links and operate on the target of the link, rather than the
4989 True if FILE exists.
4992 True if FILE exists and is a block special file.
4995 True if FILE exists and is a character special file.
4998 True if FILE exists and is a directory.
5001 True if FILE exists.
5004 True if FILE exists and is a regular file.
5007 True if FILE exists and its set-group-id bit is set.
5010 True if FILE exists and is a symbolic link.
5013 True if FILE exists and its "sticky" bit is set.
5016 True if FILE exists and is a named pipe (FIFO).
5019 True if FILE exists and is readable.
5022 True if FILE exists and has a size greater than zero.
5025 True if file descriptor FD is open and refers to a terminal.
5028 True if FILE exists and its set-user-id bit is set.
5031 True if FILE exists and is writable.
5034 True if FILE exists and is executable.
5037 True if FILE exists and is owned by the effective user id.
5040 True if FILE exists and is owned by the effective group id.
5043 True if FILE exists and is a symbolic link.
5046 True if FILE exists and is a socket.
5049 True if FILE exists and has been modified since it was last read.
5052 True if FILE1 is newer (according to modification date) than
5053 FILE2, or if FILE1 exists and FILE2 does not.
5056 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
5060 True if FILE1 and FILE2 refer to the same device and inode numbers.
5063 True if shell option OPTNAME is enabled. The list of options
5064 appears in the description of the `-o' option to the `set' builtin
5065 (*note The Set Builtin::).
5068 True if the length of STRING is zero.
5072 True if the length of STRING is non-zero.
5074 `STRING1 == STRING2'
5075 True if the strings are equal. `=' may be used in place of `=='
5076 for strict POSIX compliance.
5078 `STRING1 != STRING2'
5079 True if the strings are not equal.
5082 True if STRING1 sorts before STRING2 lexicographically in the
5086 True if STRING1 sorts after STRING2 lexicographically in the
5090 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
5091 arithmetic binary operators return true if ARG1 is equal to, not
5092 equal to, less than, less than or equal to, greater than, or
5093 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
5094 positive or negative integers.
5098 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
5100 6.5 Shell Arithmetic
5101 ====================
5103 The shell allows arithmetic expressions to be evaluated, as one of the
5104 shell expansions or by the `let' and the `-i' option to the `declare'
5107 Evaluation is done in fixed-width integers with no check for
5108 overflow, though division by 0 is trapped and flagged as an error. The
5109 operators and their precedence, associativity, and values are the same
5110 as in the C language. The following list of operators is grouped into
5111 levels of equal-precedence operators. The levels are listed in order
5112 of decreasing precedence.
5115 variable post-increment and post-decrement
5118 variable pre-increment and pre-decrement
5121 unary minus and plus
5124 logical and bitwise negation
5130 multiplication, division, remainder
5133 addition, subtraction
5136 left and right bitwise shifts
5142 equality and inequality
5148 bitwise exclusive OR
5159 `expr ? expr : expr'
5160 conditional operator
5162 `= *= /= %= += -= <<= >>= &= ^= |='
5168 Shell variables are allowed as operands; parameter expansion is
5169 performed before the expression is evaluated. Within an expression,
5170 shell variables may also be referenced by name without using the
5171 parameter expansion syntax. A shell variable that is null or unset
5172 evaluates to 0 when referenced by name without using the parameter
5173 expansion syntax. The value of a variable is evaluated as an
5174 arithmetic expression when it is referenced, or when a variable which
5175 has been given the INTEGER attribute using `declare -i' is assigned a
5176 value. A null value evaluates to 0. A shell variable need not have
5177 its integer attribute turned on to be used in an expression.
5179 Constants with a leading 0 are interpreted as octal numbers. A
5180 leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
5181 form [BASE`#']N, where BASE is a decimal number between 2 and 64
5182 representing the arithmetic base, and N is a number in that base. If
5183 BASE`#' is omitted, then base 10 is used. The digits greater than 9
5184 are represented by the lowercase letters, the uppercase letters, `@',
5185 and `_', in that order. If BASE is less than or equal to 36, lowercase
5186 and uppercase letters may be used interchangeably to represent numbers
5189 Operators are evaluated in order of precedence. Sub-expressions in
5190 parentheses are evaluated first and may override the precedence rules
5194 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
5199 ALIASES allow a string to be substituted for a word when it is used as
5200 the first word of a simple command. The shell maintains a list of
5201 aliases that may be set and unset with the `alias' and `unalias'
5204 The first word of each simple command, if unquoted, is checked to see
5205 if it has an alias. If so, that word is replaced by the text of the
5206 alias. The characters `/', `$', ``', `=' and any of the shell
5207 metacharacters or quoting characters listed above may not appear in an
5208 alias name. The replacement text may contain any valid shell input,
5209 including shell metacharacters. The first word of the replacement text
5210 is tested for aliases, but a word that is identical to an alias being
5211 expanded is not expanded a second time. This means that one may alias
5212 `ls' to `"ls -F"', for instance, and Bash does not try to recursively
5213 expand the replacement text. If the last character of the alias value
5214 is a space or tab character, then the next command word following the
5215 alias is also checked for alias expansion.
5217 Aliases are created and listed with the `alias' command, and removed
5218 with the `unalias' command.
5220 There is no mechanism for using arguments in the replacement text,
5221 as in `csh'. If arguments are needed, a shell function should be used
5222 (*note Shell Functions::).
5224 Aliases are not expanded when the shell is not interactive, unless
5225 the `expand_aliases' shell option is set using `shopt' (*note The Shopt
5228 The rules concerning the definition and use of aliases are somewhat
5229 confusing. Bash always reads at least one complete line of input
5230 before executing any of the commands on that line. Aliases are
5231 expanded when a command is read, not when it is executed. Therefore, an
5232 alias definition appearing on the same line as another command does not
5233 take effect until the next line of input is read. The commands
5234 following the alias definition on that line are not affected by the new
5235 alias. This behavior is also an issue when functions are executed.
5236 Aliases are expanded when a function definition is read, not when the
5237 function is executed, because a function definition is itself a
5238 compound command. As a consequence, aliases defined in a function are
5239 not available until after that function is executed. To be safe,
5240 always put alias definitions on a separate line, and do not use `alias'
5241 in compound commands.
5243 For almost every purpose, shell functions are preferred over aliases.
5246 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
5251 Bash provides one-dimensional indexed and associative array variables.
5252 Any variable may be used as an indexed array; the `declare' builtin
5253 will explicitly declare an array. There is no maximum limit on the
5254 size of an array, nor any requirement that members be indexed or
5255 assigned contiguously. Indexed arrays are referenced using integers
5256 (including arithmetic expressions (*note Shell Arithmetic::) and are
5257 zero-based; associative arrays use arbitrary strings.
5259 An indexed array is created automatically if any variable is
5260 assigned to using the syntax
5261 name[SUBSCRIPT]=VALUE
5263 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
5264 to a number greater than or equal to zero. To explicitly declare an
5268 declare -a NAME[SUBSCRIPT]
5269 is also accepted; the SUBSCRIPT is ignored.
5271 Associative arrays are created using
5274 Attributes may be specified for an array variable using the
5275 `declare' and `readonly' builtins. Each attribute applies to all
5276 members of an array.
5278 Arrays are assigned to using compound assignments of the form
5279 name=(value1 ... valueN)
5280 where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array
5281 assignments do not require the bracket and subscript. When assigning
5282 to indexed arrays, if the optional subscript is supplied, that index is
5283 assigned to; otherwise the index of the element assigned is the last
5284 index assigned to by the statement plus one. Indexing starts at zero.
5286 When assigning to an associative array, the subscript is required.
5288 This syntax is also accepted by the `declare' builtin. Individual
5289 array elements may be assigned to using the `name['SUBSCRIPT`]='VALUE
5290 syntax introduced above.
5292 Any element of an array may be referenced using
5293 `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
5294 with the shell's filename expansion operators. If the SUBSCRIPT is `@'
5295 or `*', the word expands to all members of the array NAME. These
5296 subscripts differ only when the word appears within double quotes. If
5297 the word is double-quoted, `${name[*]}' expands to a single word with
5298 the value of each array member separated by the first character of the
5299 `IFS' variable, and `${name[@]}' expands each element of NAME to a
5300 separate word. When there are no array members, `${name[@]}' expands
5301 to nothing. If the double-quoted expansion occurs within a word, the
5302 expansion of the first parameter is joined with the beginning part of
5303 the original word, and the expansion of the last parameter is joined
5304 with the last part of the original word. This is analogous to the
5305 expansion of the special parameters `@' and `*'.
5306 `${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'.
5307 If SUBSCRIPT is `@' or `*', the expansion is the number of elements in
5308 the array. Referencing an array variable without a subscript is
5309 equivalent to referencing with a subscript of 0.
5311 The `unset' builtin is used to destroy arrays. `unset'
5312 NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care
5313 must be taken to avoid unwanted side effects caused by filename
5314 generation. `unset' NAME, where NAME is an array, removes the entire
5315 array. A subscript of `*' or `@' also removes the entire array.
5317 The `declare', `local', and `readonly' builtins each accept a `-a'
5318 option to specify an indexed array and a `-A' option to specify an
5319 associative array. The `read' builtin accepts a `-a' option to assign
5320 a list of words read from the standard input to an array, and can read
5321 values from the standard input into individual array elements. The
5322 `set' and `declare' builtins display array values in a way that allows
5323 them to be reused as input.
5326 File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
5328 6.8 The Directory Stack
5329 =======================
5333 * Directory Stack Builtins:: Bash builtin commands to manipulate
5334 the directory stack.
5336 The directory stack is a list of recently-visited directories. The
5337 `pushd' builtin adds directories to the stack as it changes the current
5338 directory, and the `popd' builtin removes specified directories from
5339 the stack and changes the current directory to the directory removed.
5340 The `dirs' builtin displays the contents of the directory stack.
5342 The contents of the directory stack are also visible as the value of
5343 the `DIRSTACK' shell variable.
5346 File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
5348 6.8.1 Directory Stack Builtins
5349 ------------------------------
5352 dirs [+N | -N] [-clpv]
5353 Display the list of currently remembered directories. Directories
5354 are added to the list with the `pushd' command; the `popd' command
5355 removes directories from the list.
5357 Displays the Nth directory (counting from the left of the
5358 list printed by `dirs' when invoked without options), starting
5362 Displays the Nth directory (counting from the right of the
5363 list printed by `dirs' when invoked without options), starting
5367 Clears the directory stack by deleting all of the elements.
5370 Produces a longer listing; the default listing format uses a
5371 tilde to denote the home directory.
5374 Causes `dirs' to print the directory stack with one entry per
5378 Causes `dirs' to print the directory stack with one entry per
5379 line, prefixing each entry with its index in the stack.
5384 Remove the top entry from the directory stack, and `cd' to the new
5385 top directory. When no arguments are given, `popd' removes the
5386 top directory from the stack and performs a `cd' to the new top
5387 directory. The elements are numbered from 0 starting at the first
5388 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
5391 Removes the Nth directory (counting from the left of the list
5392 printed by `dirs'), starting with zero.
5395 Removes the Nth directory (counting from the right of the
5396 list printed by `dirs'), starting with zero.
5399 Suppresses the normal change of directory when removing
5400 directories from the stack, so that only the stack is
5404 pushd [-n] [+N | -N | DIR ]
5406 Save the current directory on the top of the directory stack and
5407 then `cd' to DIR. With no arguments, `pushd' exchanges the top
5411 Suppresses the normal change of directory when adding
5412 directories to the stack, so that only the stack is
5416 Brings the Nth directory (counting from the left of the list
5417 printed by `dirs', starting with zero) to the top of the list
5418 by rotating the stack.
5421 Brings the Nth directory (counting from the right of the list
5422 printed by `dirs', starting with zero) to the top of the list
5423 by rotating the stack.
5426 Makes the current working directory be the top of the stack,
5427 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
5431 File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
5433 6.9 Controlling the Prompt
5434 ==========================
5436 The value of the variable `PROMPT_COMMAND' is examined just before Bash
5437 prints each primary prompt. If `PROMPT_COMMAND' is set and has a
5438 non-null value, then the value is executed just as if it had been typed
5439 on the command line.
5441 In addition, the following table describes the special characters
5442 which can appear in the prompt variables:
5448 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
5451 The FORMAT is passed to `strftime'(3) and the result is inserted
5452 into the prompt string; an empty FORMAT results in a
5453 locale-specific time representation. The braces are required.
5456 An escape character.
5459 The hostname, up to the first `.'.
5465 The number of jobs currently managed by the shell.
5468 The basename of the shell's terminal device name.
5477 The name of the shell, the basename of `$0' (the portion following
5481 The time, in 24-hour HH:MM:SS format.
5484 The time, in 12-hour HH:MM:SS format.
5487 The time, in 12-hour am/pm format.
5490 The time, in 24-hour HH:MM format.
5493 The username of the current user.
5496 The version of Bash (e.g., 2.00)
5499 The release of Bash, version + patchlevel (e.g., 2.00.0)
5502 The current working directory, with `$HOME' abbreviated with a
5503 tilde (uses the `$PROMPT_DIRTRIM' variable).
5506 The basename of `$PWD', with `$HOME' abbreviated with a tilde.
5509 The history number of this command.
5512 The command number of this command.
5515 If the effective uid is 0, `#', otherwise `$'.
5518 The character whose ASCII code is the octal value NNN.
5524 Begin a sequence of non-printing characters. This could be used to
5525 embed a terminal control sequence into the prompt.
5528 End a sequence of non-printing characters.
5530 The command number and the history number are usually different: the
5531 history number of a command is its position in the history list, which
5532 may include commands restored from the history file (*note Bash History
5533 Facilities::), while the command number is the position in the sequence
5534 of commands executed during the current shell session.
5536 After the string is decoded, it is expanded via parameter expansion,
5537 command substitution, arithmetic expansion, and quote removal, subject
5538 to the value of the `promptvars' shell option (*note Bash Builtins::).
5541 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
5543 6.10 The Restricted Shell
5544 =========================
5546 If Bash is started with the name `rbash', or the `--restricted' or `-r'
5547 option is supplied at invocation, the shell becomes restricted. A
5548 restricted shell is used to set up an environment more controlled than
5549 the standard shell. A restricted shell behaves identically to `bash'
5550 with the exception that the following are disallowed or not performed:
5552 * Changing directories with the `cd' builtin.
5554 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
5555 `BASH_ENV' variables.
5557 * Specifying command names containing slashes.
5559 * Specifying a filename containing a slash as an argument to the `.'
5562 * Specifying a filename containing a slash as an argument to the `-p'
5563 option to the `hash' builtin command.
5565 * Importing function definitions from the shell environment at
5568 * Parsing the value of `SHELLOPTS' from the shell environment at
5571 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
5572 redirection operators.
5574 * Using the `exec' builtin to replace the shell with another command.
5576 * Adding or deleting builtin commands with the `-f' and `-d' options
5577 to the `enable' builtin.
5579 * Using the `enable' builtin command to enable disabled shell
5582 * Specifying the `-p' option to the `command' builtin.
5584 * Turning off restricted mode with `set +r' or `set +o restricted'.
5586 These restrictions are enforced after any startup files are read.
5588 When a command that is found to be a shell script is executed (*note
5589 Shell Scripts::), `rbash' turns off any restrictions in the shell
5590 spawned to execute the script.
5593 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
5595 6.11 Bash POSIX Mode
5596 ====================
5598 Starting Bash with the `--posix' command-line option or executing `set
5599 -o posix' while Bash is running will cause Bash to conform more closely
5600 to the POSIX standard by changing the behavior to match that specified
5601 by POSIX in areas where the Bash default differs.
5603 When invoked as `sh', Bash enters POSIX mode after reading the
5606 The following list is what's changed when `POSIX mode' is in effect:
5608 1. When a command in the hash table no longer exists, Bash will
5609 re-search `$PATH' to find the new location. This is also
5610 available with `shopt -s checkhash'.
5612 2. The message printed by the job control code and builtins when a job
5613 exits with a non-zero status is `Done(status)'.
5615 3. The message printed by the job control code and builtins when a job
5616 is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
5619 4. The `bg' builtin uses the required format to describe each job
5620 placed in the background, which does not include an indication of
5621 whether the job is the current or previous job.
5623 5. Reserved words appearing in a context where reserved words are
5624 recognized do not undergo alias expansion.
5626 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number
5627 and `!!' to `!' are enabled, and parameter expansion is performed
5628 on the values of `PS1' and `PS2' regardless of the setting of the
5629 `promptvars' option.
5631 7. The POSIX startup files are executed (`$ENV') rather than the
5634 8. Tilde expansion is only performed on assignments preceding a
5635 command name, rather than on all assignment statements on the line.
5637 9. The default history file is `~/.sh_history' (this is the default
5638 value of `$HISTFILE').
5640 10. The output of `kill -l' prints all the signal names on a single
5641 line, separated by spaces, without the `SIG' prefix.
5643 11. The `kill' builtin does not accept signal names with a `SIG'
5646 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
5649 13. Non-interactive shells exit if a syntax error in an arithmetic
5650 expansion results in an invalid expression.
5652 14. Redirection operators do not perform filename expansion on the word
5653 in the redirection unless the shell is interactive.
5655 15. Redirection operators do not perform word splitting on the word in
5658 16. Function names must be valid shell `name's. That is, they may not
5659 contain characters other than letters, digits, and underscores, and
5660 may not start with a digit. Declaring a function with an invalid
5661 name causes a fatal syntax error in non-interactive shells.
5663 17. POSIX special builtins are found before shell functions during
5666 18. If a POSIX special builtin returns an error status, a
5667 non-interactive shell exits. The fatal errors are those listed in
5668 the POSIX standard, and include things like passing incorrect
5669 options, redirection errors, variable assignment errors for
5670 assignments preceding the command name, and so on.
5672 19. If `CDPATH' is set, the `cd' builtin will not implicitly append
5673 the current directory to it. This means that `cd' will fail if no
5674 valid directory name can be constructed from any of the entries in
5675 `$CDPATH', even if the a directory with the same name as the name
5676 given as an argument to `cd' exists in the current directory.
5678 20. A non-interactive shell exits with an error status if a variable
5679 assignment error occurs when no command name follows the assignment
5680 statements. A variable assignment error occurs, for example, when
5681 trying to assign a value to a readonly variable.
5683 21. A non-interactive shell exits with an error status if the iteration
5684 variable in a `for' statement or the selection variable in a
5685 `select' statement is a readonly variable.
5687 22. Process substitution is not available.
5689 23. Assignment statements preceding POSIX special builtins persist in
5690 the shell environment after the builtin completes.
5692 24. Assignment statements preceding shell function calls persist in the
5693 shell environment after the function returns, as if a POSIX
5694 special builtin command had been executed.
5696 25. The `export' and `readonly' builtin commands display their output
5697 in the format required by POSIX.
5699 26. The `trap' builtin displays signal names without the leading `SIG'.
5701 27. The `trap' builtin doesn't check the first argument for a possible
5702 signal specification and revert the signal handling to the original
5703 disposition if it is, unless that argument consists solely of
5704 digits and is a valid signal number. If users want to reset the
5705 handler for a given signal to the original disposition, they
5706 should use `-' as the first argument.
5708 28. The `.' and `source' builtins do not search the current directory
5709 for the filename argument if it is not found by searching `PATH'.
5711 29. Subshells spawned to execute command substitutions inherit the
5712 value of the `-e' option from the parent shell. When not in POSIX
5713 mode, Bash clears the `-e' option in such subshells.
5715 30. Alias expansion is always enabled, even in non-interactive shells.
5717 31. When the `alias' builtin displays alias definitions, it does not
5718 display them with a leading `alias ' unless the `-p' option is
5721 32. When the `set' builtin is invoked without options, it does not
5722 display shell function names and definitions.
5724 33. When the `set' builtin is invoked without options, it displays
5725 variable values without quotes, unless they contain shell
5726 metacharacters, even if the result contains nonprinting characters.
5728 34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
5729 constructed from `$PWD' and the directory name supplied as an
5730 argument does not refer to an existing directory, `cd' will fail
5731 instead of falling back to PHYSICAL mode.
5733 35. When the `pwd' builtin is supplied the `-P' option, it resets
5734 `$PWD' to a pathname containing no symlinks.
5736 36. The `pwd' builtin verifies that the value it prints is the same as
5737 the current directory, even if it is not asked to check the file
5738 system with the `-P' option.
5740 37. When listing the history, the `fc' builtin does not include an
5741 indication of whether or not a history entry has been modified.
5743 38. The default editor used by `fc' is `ed'.
5745 39. The `type' and `command' builtins will not report a non-executable
5746 file as having been found, though the shell will attempt to
5747 execute such a file if it is the only so-named file found in
5750 40. The `vi' editing mode will invoke the `vi' editor directly when
5751 the `v' command is run, instead of checking `$VISUAL' and
5754 41. When the `xpg_echo' option is enabled, Bash does not attempt to
5755 interpret any arguments to `echo' as options. Each argument is
5756 displayed, after escape characters are converted.
5758 42. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
5762 There is other POSIX behavior that Bash does not implement by
5763 default even when in POSIX mode. Specifically:
5765 1. The `fc' builtin checks `$EDITOR' as a program to edit history
5766 entries if `FCEDIT' is unset, rather than defaulting directly to
5767 `ed'. `fc' uses `ed' if `EDITOR' is unset.
5769 2. As noted above, Bash requires the `xpg_echo' option to be enabled
5770 for the `echo' builtin to be fully conformant.
5773 Bash can be configured to be POSIX-conformant by default, by
5774 specifying the `--enable-strict-posix-default' to `configure' when
5775 building (*note Optional Features::).
5778 File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
5783 This chapter discusses what job control is, how it works, and how Bash
5784 allows you to access its facilities.
5788 * Job Control Basics:: How job control works.
5789 * Job Control Builtins:: Bash builtin commands used to interact
5791 * Job Control Variables:: Variables Bash uses to customize job
5795 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
5797 7.1 Job Control Basics
5798 ======================
5800 Job control refers to the ability to selectively stop (suspend) the
5801 execution of processes and continue (resume) their execution at a later
5802 point. A user typically employs this facility via an interactive
5803 interface supplied jointly by the system's terminal driver and Bash.
5805 The shell associates a JOB with each pipeline. It keeps a table of
5806 currently executing jobs, which may be listed with the `jobs' command.
5807 When Bash starts a job asynchronously, it prints a line that looks like:
5809 indicating that this job is job number 1 and that the process ID of
5810 the last process in the pipeline associated with this job is 25647.
5811 All of the processes in a single pipeline are members of the same job.
5812 Bash uses the JOB abstraction as the basis for job control.
5814 To facilitate the implementation of the user interface to job
5815 control, the operating system maintains the notion of a current terminal
5816 process group ID. Members of this process group (processes whose
5817 process group ID is equal to the current terminal process group ID)
5818 receive keyboard-generated signals such as `SIGINT'. These processes
5819 are said to be in the foreground. Background processes are those whose
5820 process group ID differs from the terminal's; such processes are immune
5821 to keyboard-generated signals. Only foreground processes are allowed
5822 to read from or write to the terminal. Background processes which
5823 attempt to read from (write to) the terminal are sent a `SIGTTIN'
5824 (`SIGTTOU') signal by the terminal driver, which, unless caught,
5825 suspends the process.
5827 If the operating system on which Bash is running supports job
5828 control, Bash contains facilities to use it. Typing the SUSPEND
5829 character (typically `^Z', Control-Z) while a process is running causes
5830 that process to be stopped and returns control to Bash. Typing the
5831 DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
5832 process to be stopped when it attempts to read input from the terminal,
5833 and control to be returned to Bash. The user then manipulates the
5834 state of this job, using the `bg' command to continue it in the
5835 background, the `fg' command to continue it in the foreground, or the
5836 `kill' command to kill it. A `^Z' takes effect immediately, and has
5837 the additional side effect of causing pending output and typeahead to
5840 There are a number of ways to refer to a job in the shell. The
5841 character `%' introduces a job specification (JOBSPEC).
5843 Job number `n' may be referred to as `%n'. The symbols `%%' and
5844 `%+' refer to the shell's notion of the current job, which is the last
5845 job stopped while it was in the foreground or started in the background.
5846 A single `%' (with no accompanying job specification) also refers to
5847 the current job. The previous job may be referenced using `%-'. If
5848 there is only a single job, `%+' and `%-' can both be used to refer to
5849 that job. In output pertaining to jobs (e.g., the output of the `jobs'
5850 command), the current job is always flagged with a `+', and the
5851 previous job with a `-'.
5853 A job may also be referred to using a prefix of the name used to
5854 start it, or using a substring that appears in its command line. For
5855 example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other
5856 hand, refers to any job containing the string `ce' in its command line.
5857 If the prefix or substring matches more than one job, Bash reports an
5860 Simply naming a job can be used to bring it into the foreground:
5861 `%1' is a synonym for `fg %1', bringing job 1 from the background into
5862 the foreground. Similarly, `%1 &' resumes job 1 in the background,
5863 equivalent to `bg %1'
5865 The shell learns immediately whenever a job changes state.
5866 Normally, Bash waits until it is about to print a prompt before
5867 reporting changes in a job's status so as to not interrupt any other
5868 output. If the `-b' option to the `set' builtin is enabled, Bash
5869 reports such changes immediately (*note The Set Builtin::). Any trap
5870 on `SIGCHLD' is executed for each child process that exits.
5872 If an attempt to exit Bash is made while jobs are stopped, (or
5873 running, if the `checkjobs' option is enabled - see *note The Shopt
5874 Builtin::), the shell prints a warning message, and if the `checkjobs'
5875 option is enabled, lists the jobs and their statuses. The `jobs'
5876 command may then be used to inspect their status. If a second attempt
5877 to exit is made without an intervening command, Bash does not print
5878 another warning, and any stopped jobs are terminated.
5881 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
5883 7.2 Job Control Builtins
5884 ========================
5888 Resume each suspended job JOBSPEC in the background, as if it had
5889 been started with `&'. If JOBSPEC is not supplied, the current
5890 job is used. The return status is zero unless it is run when job
5891 control is not enabled, or, when run with job control enabled, any
5892 JOBSPEC was not found or specifies a job that was started without
5897 Resume the job JOBSPEC in the foreground and make it the current
5898 job. If JOBSPEC is not supplied, the current job is used. The
5899 return status is that of the command placed into the foreground,
5900 or non-zero if run when job control is disabled or, when run with
5901 job control enabled, JOBSPEC does not specify a valid job or
5902 JOBSPEC specifies a job that was started without job control.
5905 jobs [-lnprs] [JOBSPEC]
5906 jobs -x COMMAND [ARGUMENTS]
5908 The first form lists the active jobs. The options have the
5912 List process IDs in addition to the normal information.
5915 Display information only about jobs that have changed status
5916 since the user was last notified of their status.
5919 List only the process ID of the job's process group leader.
5922 Restrict output to running jobs.
5925 Restrict output to stopped jobs.
5927 If JOBSPEC is given, output is restricted to information about
5928 that job. If JOBSPEC is not supplied, the status of all jobs is
5931 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
5932 in COMMAND or ARGUMENTS with the corresponding process group ID,
5933 and executes COMMAND, passing it ARGUMENTs, returning its exit
5937 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
5938 kill -l [EXIT_STATUS]
5939 Send a signal specified by SIGSPEC or SIGNUM to the process named
5940 by job specification JOBSPEC or process ID PID. SIGSPEC is either
5941 a case-insensitive signal name such as `SIGINT' (with or without
5942 the `SIG' prefix) or a signal number; SIGNUM is a signal number.
5943 If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The
5944 `-l' option lists the signal names. If any arguments are supplied
5945 when `-l' is given, the names of the signals corresponding to the
5946 arguments are listed, and the return status is zero. EXIT_STATUS
5947 is a number specifying a signal number or the exit status of a
5948 process terminated by a signal. The return status is zero if at
5949 least one signal was successfully sent, or non-zero if an error
5950 occurs or an invalid option is encountered.
5953 wait [JOBSPEC or PID ...]
5954 Wait until the child process specified by each process ID PID or
5955 job specification JOBSPEC exits and return the exit status of the
5956 last command waited for. If a job spec is given, all processes in
5957 the job are waited for. If no arguments are given, all currently
5958 active child processes are waited for, and the return status is
5959 zero. If neither JOBSPEC nor PID specifies an active child process
5960 of the shell, the return status is 127.
5963 disown [-ar] [-h] [JOBSPEC ...]
5964 Without options, each JOBSPEC is removed from the table of active
5965 jobs. If the `-h' option is given, the job is not removed from
5966 the table, but is marked so that `SIGHUP' is not sent to the job
5967 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
5968 neither the `-a' nor `-r' option is supplied, the current job is
5969 used. If no JOBSPEC is supplied, the `-a' option means to remove
5970 or mark all jobs; the `-r' option without a JOBSPEC argument
5971 restricts operation to running jobs.
5975 Suspend the execution of this shell until it receives a `SIGCONT'
5976 signal. A login shell cannot be suspended; the `-f' option can be
5977 used to override this and force the suspension.
5980 When job control is not active, the `kill' and `wait' builtins do
5981 not accept JOBSPEC arguments. They must be supplied process IDs.
5984 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
5986 7.3 Job Control Variables
5987 =========================
5990 This variable controls how the shell interacts with the user and
5991 job control. If this variable exists then single word simple
5992 commands without redirections are treated as candidates for
5993 resumption of an existing job. There is no ambiguity allowed; if
5994 there is more than one job beginning with the string typed, then
5995 the most recently accessed job will be selected. The name of a
5996 stopped job, in this context, is the command line used to start
5997 it. If this variable is set to the value `exact', the string
5998 supplied must match the name of a stopped job exactly; if set to
5999 `substring', the string supplied needs to match a substring of the
6000 name of a stopped job. The `substring' value provides
6001 functionality analogous to the `%?' job ID (*note Job Control
6002 Basics::). If set to any other value, the supplied string must be
6003 a prefix of a stopped job's name; this provides functionality
6004 analogous to the `%' job ID.
6008 File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
6010 8 Command Line Editing
6011 **********************
6013 This chapter describes the basic features of the GNU command line
6014 editing interface. Command line editing is provided by the Readline
6015 library, which is used by several different programs, including Bash.
6016 Command line editing is enabled by default when using an interactive
6017 shell, unless the `--noediting' option is supplied at shell invocation.
6018 Line editing is also used when using the `-e' option to the `read'
6019 builtin command (*note Bash Builtins::). By default, the line editing
6020 commands are similar to those of emacs. A vi-style line editing
6021 interface is also available. Line editing can be enabled at any time
6022 using the `-o emacs' or `-o vi' options to the `set' builtin command
6023 (*note The Set Builtin::), or disabled using the `+o emacs' or `+o vi'
6028 * Introduction and Notation:: Notation used in this text.
6029 * Readline Interaction:: The minimum set of commands for editing a line.
6030 * Readline Init File:: Customizing Readline from a user's view.
6031 * Bindable Readline Commands:: A description of most of the Readline commands
6032 available for binding
6033 * Readline vi Mode:: A short description of how to make Readline
6034 behave like the vi editor.
6036 * Programmable Completion:: How to specify the possible completions for
6038 * Programmable Completion Builtins:: Builtin commands to specify how to
6039 complete arguments for a particular command.
6042 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
6044 8.1 Introduction to Line Editing
6045 ================================
6047 The following paragraphs describe the notation used to represent
6050 The text `C-k' is read as `Control-K' and describes the character
6051 produced when the <k> key is pressed while the Control key is depressed.
6053 The text `M-k' is read as `Meta-K' and describes the character
6054 produced when the Meta key (if you have one) is depressed, and the <k>
6055 key is pressed. The Meta key is labeled <ALT> on many keyboards. On
6056 keyboards with two keys labeled <ALT> (usually to either side of the
6057 space bar), the <ALT> on the left side is generally set to work as a
6058 Meta key. The <ALT> key on the right may also be configured to work as
6059 a Meta key or may be configured as some other modifier, such as a
6060 Compose key for typing accented characters.
6062 If you do not have a Meta or <ALT> key, or another key working as a
6063 Meta key, the identical keystroke can be generated by typing <ESC>
6064 _first_, and then typing <k>. Either process is known as "metafying"
6067 The text `M-C-k' is read as `Meta-Control-k' and describes the
6068 character produced by "metafying" `C-k'.
6070 In addition, several keys have their own names. Specifically,
6071 <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
6072 when seen in this text, or in an init file (*note Readline Init File::).
6073 If your keyboard lacks a <LFD> key, typing <C-j> will produce the
6074 desired character. The <RET> key may be labeled <Return> or <Enter> on
6078 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
6080 8.2 Readline Interaction
6081 ========================
6083 Often during an interactive session you type in a long line of text,
6084 only to notice that the first word on the line is misspelled. The
6085 Readline library gives you a set of commands for manipulating the text
6086 as you type it in, allowing you to just fix your typo, and not forcing
6087 you to retype the majority of the line. Using these editing commands,
6088 you move the cursor to the place that needs correction, and delete or
6089 insert the text of the corrections. Then, when you are satisfied with
6090 the line, you simply press <RET>. You do not have to be at the end of
6091 the line to press <RET>; the entire line is accepted regardless of the
6092 location of the cursor within the line.
6096 * Readline Bare Essentials:: The least you need to know about Readline.
6097 * Readline Movement Commands:: Moving about the input line.
6098 * Readline Killing Commands:: How to delete text, and how to get it back!
6099 * Readline Arguments:: Giving numeric arguments to commands.
6100 * Searching:: Searching through previous lines.
6103 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
6105 8.2.1 Readline Bare Essentials
6106 ------------------------------
6108 In order to enter characters into the line, simply type them. The typed
6109 character appears where the cursor was, and then the cursor moves one
6110 space to the right. If you mistype a character, you can use your erase
6111 character to back up and delete the mistyped character.
6113 Sometimes you may mistype a character, and not notice the error
6114 until you have typed several other characters. In that case, you can
6115 type `C-b' to move the cursor to the left, and then correct your
6116 mistake. Afterwards, you can move the cursor to the right with `C-f'.
6118 When you add text in the middle of a line, you will notice that
6119 characters to the right of the cursor are `pushed over' to make room
6120 for the text that you have inserted. Likewise, when you delete text
6121 behind the cursor, characters to the right of the cursor are `pulled
6122 back' to fill in the blank space created by the removal of the text. A
6123 list of the bare essentials for editing the text of an input line
6127 Move back one character.
6130 Move forward one character.
6132 <DEL> or <Backspace>
6133 Delete the character to the left of the cursor.
6136 Delete the character underneath the cursor.
6139 Insert the character into the line at the cursor.
6142 Undo the last editing command. You can undo all the way back to an
6145 (Depending on your configuration, the <Backspace> key be set to delete
6146 the character to the left of the cursor and the <DEL> key set to delete
6147 the character underneath the cursor, like `C-d', rather than the
6148 character to the left of the cursor.)
6151 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
6153 8.2.2 Readline Movement Commands
6154 --------------------------------
6156 The above table describes the most basic keystrokes that you need in
6157 order to do editing of the input line. For your convenience, many
6158 other commands have been added in addition to `C-b', `C-f', `C-d', and
6159 <DEL>. Here are some commands for moving more rapidly about the line.
6162 Move to the start of the line.
6165 Move to the end of the line.
6168 Move forward a word, where a word is composed of letters and
6172 Move backward a word.
6175 Clear the screen, reprinting the current line at the top.
6177 Notice how `C-f' moves forward a character, while `M-f' moves
6178 forward a word. It is a loose convention that control keystrokes
6179 operate on characters while meta keystrokes operate on words.
6182 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
6184 8.2.3 Readline Killing Commands
6185 -------------------------------
6187 "Killing" text means to delete the text from the line, but to save it
6188 away for later use, usually by "yanking" (re-inserting) it back into
6189 the line. (`Cut' and `paste' are more recent jargon for `kill' and
6192 If the description for a command says that it `kills' text, then you
6193 can be sure that you can get the text back in a different (or the same)
6196 When you use a kill command, the text is saved in a "kill-ring".
6197 Any number of consecutive kills save all of the killed text together, so
6198 that when you yank it back, you get it all. The kill ring is not line
6199 specific; the text that you killed on a previously typed line is
6200 available to be yanked back later, when you are typing another line.
6202 Here is the list of commands for killing text.
6205 Kill the text from the current cursor position to the end of the
6209 Kill from the cursor to the end of the current word, or, if between
6210 words, to the end of the next word. Word boundaries are the same
6211 as those used by `M-f'.
6214 Kill from the cursor the start of the current word, or, if between
6215 words, to the start of the previous word. Word boundaries are the
6216 same as those used by `M-b'.
6219 Kill from the cursor to the previous whitespace. This is
6220 different than `M-<DEL>' because the word boundaries differ.
6223 Here is how to "yank" the text back into the line. Yanking means to
6224 copy the most-recently-killed text from the kill buffer.
6227 Yank the most recently killed text back into the buffer at the
6231 Rotate the kill-ring, and yank the new top. You can only do this
6232 if the prior command is `C-y' or `M-y'.
6235 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
6237 8.2.4 Readline Arguments
6238 ------------------------
6240 You can pass numeric arguments to Readline commands. Sometimes the
6241 argument acts as a repeat count, other times it is the sign of the
6242 argument that is significant. If you pass a negative argument to a
6243 command which normally acts in a forward direction, that command will
6244 act in a backward direction. For example, to kill text back to the
6245 start of the line, you might type `M-- C-k'.
6247 The general way to pass numeric arguments to a command is to type
6248 meta digits before the command. If the first `digit' typed is a minus
6249 sign (`-'), then the sign of the argument will be negative. Once you
6250 have typed one meta digit to get the argument started, you can type the
6251 remainder of the digits, and then the command. For example, to give
6252 the `C-d' command an argument of 10, you could type `M-1 0 C-d', which
6253 will delete the next ten characters on the input line.
6256 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
6258 8.2.5 Searching for Commands in the History
6259 -------------------------------------------
6261 Readline provides commands for searching through the command history
6262 (*note Bash History Facilities::) for lines containing a specified
6263 string. There are two search modes: "incremental" and
6266 Incremental searches begin before the user has finished typing the
6267 search string. As each character of the search string is typed,
6268 Readline displays the next entry from the history matching the string
6269 typed so far. An incremental search requires only as many characters
6270 as needed to find the desired history entry. To search backward in the
6271 history for a particular string, type `C-r'. Typing `C-s' searches
6272 forward through the history. The characters present in the value of
6273 the `isearch-terminators' variable are used to terminate an incremental
6274 search. If that variable has not been assigned a value, the <ESC> and
6275 `C-J' characters will terminate an incremental search. `C-g' will
6276 abort an incremental search and restore the original line. When the
6277 search is terminated, the history entry containing the search string
6278 becomes the current line.
6280 To find other matching entries in the history list, type `C-r' or
6281 `C-s' as appropriate. This will search backward or forward in the
6282 history for the next entry matching the search string typed so far.
6283 Any other key sequence bound to a Readline command will terminate the
6284 search and execute that command. For instance, a <RET> will terminate
6285 the search and accept the line, thereby executing the command from the
6286 history list. A movement command will terminate the search, make the
6287 last line found the current line, and begin editing.
6289 Readline remembers the last incremental search string. If two
6290 `C-r's are typed without any intervening characters defining a new
6291 search string, any remembered search string is used.
6293 Non-incremental searches read the entire search string before
6294 starting to search for matching history lines. The search string may be
6295 typed by the user or be part of the contents of the current line.
6298 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
6300 8.3 Readline Init File
6301 ======================
6303 Although the Readline library comes with a set of Emacs-like
6304 keybindings installed by default, it is possible to use a different set
6305 of keybindings. Any user can customize programs that use Readline by
6306 putting commands in an "inputrc" file, conventionally in his home
6307 directory. The name of this file is taken from the value of the shell
6308 variable `INPUTRC'. If that variable is unset, the default is
6309 `~/.inputrc'. If that file does not exist or cannot be read, the
6310 ultimate default is `/etc/inputrc'.
6312 When a program which uses the Readline library starts up, the init
6313 file is read, and the key bindings are set.
6315 In addition, the `C-x C-r' command re-reads this init file, thus
6316 incorporating any changes that you might have made to it.
6320 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
6322 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
6324 * Sample Init File:: An example inputrc file.
6327 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
6329 8.3.1 Readline Init File Syntax
6330 -------------------------------
6332 There are only a few basic constructs allowed in the Readline init
6333 file. Blank lines are ignored. Lines beginning with a `#' are
6334 comments. Lines beginning with a `$' indicate conditional constructs
6335 (*note Conditional Init Constructs::). Other lines denote variable
6336 settings and key bindings.
6339 You can modify the run-time behavior of Readline by altering the
6340 values of variables in Readline using the `set' command within the
6341 init file. The syntax is simple:
6345 Here, for example, is how to change from the default Emacs-like
6346 key binding to use `vi' line editing commands:
6350 Variable names and values, where appropriate, are recognized
6351 without regard to case. Unrecognized variable names are ignored.
6353 Boolean variables (those that can be set to on or off) are set to
6354 on if the value is null or empty, ON (case-insensitive), or 1.
6355 Any other value results in the variable being set to off.
6357 The `bind -V' command lists the current Readline variable names
6358 and values. *Note Bash Builtins::.
6360 A great deal of run-time behavior is changeable with the following
6364 Controls what happens when Readline wants to ring the
6365 terminal bell. If set to `none', Readline never rings the
6366 bell. If set to `visible', Readline uses a visible bell if
6367 one is available. If set to `audible' (the default),
6368 Readline attempts to ring the terminal's bell.
6370 `bind-tty-special-chars'
6371 If set to `on', Readline attempts to bind the control
6372 characters treated specially by the kernel's terminal driver
6373 to their Readline equivalents.
6376 The string to insert at the beginning of the line when the
6377 `insert-comment' command is executed. The default value is
6380 `completion-ignore-case'
6381 If set to `on', Readline performs filename matching and
6382 completion in a case-insensitive fashion. The default value
6385 `completion-prefix-display-length'
6386 The length in characters of the common prefix of a list of
6387 possible completions that is displayed without modification.
6388 When set to a value greater than zero, common prefixes longer
6389 than this value are replaced with an ellipsis when displaying
6390 possible completions.
6392 `completion-query-items'
6393 The number of possible completions that determines when the
6394 user is asked whether the list of possibilities should be
6395 displayed. If the number of possible completions is greater
6396 than this value, Readline will ask the user whether or not he
6397 wishes to view them; otherwise, they are simply listed. This
6398 variable must be set to an integer value greater than or
6399 equal to 0. A negative value means Readline should never ask.
6400 The default limit is `100'.
6403 If set to `on', Readline will convert characters with the
6404 eighth bit set to an ASCII key sequence by stripping the
6405 eighth bit and prefixing an <ESC> character, converting them
6406 to a meta-prefixed key sequence. The default value is `on'.
6408 `disable-completion'
6409 If set to `On', Readline will inhibit word completion.
6410 Completion characters will be inserted into the line as if
6411 they had been mapped to `self-insert'. The default is `off'.
6414 The `editing-mode' variable controls which default set of key
6415 bindings is used. By default, Readline starts up in Emacs
6416 editing mode, where the keystrokes are most similar to Emacs.
6417 This variable can be set to either `emacs' or `vi'.
6420 When set to `on', Readline will try to enable the application
6421 keypad when it is called. Some systems need this to enable
6422 the arrow keys. The default is `off'.
6425 If set to `on', tilde expansion is performed when Readline
6426 attempts word completion. The default is `off'.
6428 `history-preserve-point'
6429 If set to `on', the history code attempts to place the point
6430 (the current cursor position) at the same location on each
6431 history line retrieved with `previous-history' or
6432 `next-history'. The default is `off'.
6435 Set the maximum number of history entries saved in the
6436 history list. If set to zero, the number of entries in the
6437 history list is not limited.
6439 `horizontal-scroll-mode'
6440 This variable can be set to either `on' or `off'. Setting it
6441 to `on' means that the text of the lines being edited will
6442 scroll horizontally on a single screen line when they are
6443 longer than the width of the screen, instead of wrapping onto
6444 a new screen line. By default, this variable is set to `off'.
6447 If set to `on', Readline will enable eight-bit input (it will
6448 not clear the eighth bit in the characters it reads),
6449 regardless of what the terminal claims it can support. The
6450 default value is `off'. The name `meta-flag' is a synonym
6453 `isearch-terminators'
6454 The string of characters that should terminate an incremental
6455 search without subsequently executing the character as a
6456 command (*note Searching::). If this variable has not been
6457 given a value, the characters <ESC> and `C-J' will terminate
6458 an incremental search.
6461 Sets Readline's idea of the current keymap for key binding
6462 commands. Acceptable `keymap' names are `emacs',
6463 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
6464 `vi-command', and `vi-insert'. `vi' is equivalent to
6465 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
6466 default value is `emacs'. The value of the `editing-mode'
6467 variable also affects the default keymap.
6470 If set to `on', completed directory names have a slash
6471 appended. The default is `on'.
6473 `mark-modified-lines'
6474 This variable, when set to `on', causes Readline to display an
6475 asterisk (`*') at the start of history lines which have been
6476 modified. This variable is `off' by default.
6478 `mark-symlinked-directories'
6479 If set to `on', completed names which are symbolic links to
6480 directories have a slash appended (subject to the value of
6481 `mark-directories'). The default is `off'.
6483 `match-hidden-files'
6484 This variable, when set to `on', causes Readline to match
6485 files whose names begin with a `.' (hidden files) when
6486 performing filename completion, unless the leading `.' is
6487 supplied by the user in the filename to be completed. This
6488 variable is `on' by default.
6491 If set to `on', Readline will display characters with the
6492 eighth bit set directly rather than as a meta-prefixed escape
6493 sequence. The default is `off'.
6496 If set to `on', Readline uses an internal `more'-like pager
6497 to display a screenful of possible completions at a time.
6498 This variable is `on' by default.
6500 `print-completions-horizontally'
6501 If set to `on', Readline will display completions with matches
6502 sorted horizontally in alphabetical order, rather than down
6503 the screen. The default is `off'.
6505 `revert-all-at-newline'
6506 If set to `on', Readline will undo all changes to history
6507 lines before returning when `accept-line' is executed. By
6508 default, history lines may be modified and retain individual
6509 undo lists across calls to `readline'. The default is `off'.
6511 `show-all-if-ambiguous'
6512 This alters the default behavior of the completion functions.
6513 If set to `on', words which have more than one possible
6514 completion cause the matches to be listed immediately instead
6515 of ringing the bell. The default value is `off'.
6517 `show-all-if-unmodified'
6518 This alters the default behavior of the completion functions
6519 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
6520 `on', words which have more than one possible completion
6521 without any possible partial completion (the possible
6522 completions don't share a common prefix) cause the matches to
6523 be listed immediately instead of ringing the bell. The
6524 default value is `off'.
6527 If set to `on', a character denoting a file's type is
6528 appended to the filename when listing possible completions.
6529 The default is `off'.
6533 The syntax for controlling key bindings in the init file is
6534 simple. First you need to find the name of the command that you
6535 want to change. The following sections contain tables of the
6536 command name, the default keybinding, if any, and a short
6537 description of what the command does.
6539 Once you know the name of the command, simply place on a line in
6540 the init file the name of the key you wish to bind the command to,
6541 a colon, and then the name of the command. There can be no space
6542 between the key name and the colon - that will be interpreted as
6543 part of the key name. The name of the key can be expressed in
6544 different ways, depending on what you find most comfortable.
6546 In addition to command names, readline allows keys to be bound to
6547 a string that is inserted when the key is pressed (a MACRO).
6549 The `bind -p' command displays Readline function names and
6550 bindings in a format that can put directly into an initialization
6551 file. *Note Bash Builtins::.
6553 KEYNAME: FUNCTION-NAME or MACRO
6554 KEYNAME is the name of a key spelled out in English. For
6556 Control-u: universal-argument
6557 Meta-Rubout: backward-kill-word
6558 Control-o: "> output"
6560 In the above example, `C-u' is bound to the function
6561 `universal-argument', `M-DEL' is bound to the function
6562 `backward-kill-word', and `C-o' is bound to run the macro
6563 expressed on the right hand side (that is, to insert the text
6564 `> output' into the line).
6566 A number of symbolic character names are recognized while
6567 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
6568 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
6570 "KEYSEQ": FUNCTION-NAME or MACRO
6571 KEYSEQ differs from KEYNAME above in that strings denoting an
6572 entire key sequence can be specified, by placing the key
6573 sequence in double quotes. Some GNU Emacs style key escapes
6574 can be used, as in the following example, but the special
6575 character names are not recognized.
6577 "\C-u": universal-argument
6578 "\C-x\C-r": re-read-init-file
6579 "\e[11~": "Function Key 1"
6581 In the above example, `C-u' is again bound to the function
6582 `universal-argument' (just as it was in the first example),
6583 `C-x C-r' is bound to the function `re-read-init-file', and
6584 `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function
6588 The following GNU Emacs style escape sequences are available when
6589 specifying key sequences:
6604 <">, a double quotation mark
6607 <'>, a single quote or apostrophe
6609 In addition to the GNU Emacs style escape sequences, a second set
6610 of backslash escapes is available:
6637 the eight-bit character whose value is the octal value NNN
6638 (one to three digits)
6641 the eight-bit character whose value is the hexadecimal value
6642 HH (one or two hex digits)
6644 When entering the text of a macro, single or double quotes must be
6645 used to indicate a macro definition. Unquoted text is assumed to
6646 be a function name. In the macro body, the backslash escapes
6647 described above are expanded. Backslash will quote any other
6648 character in the macro text, including `"' and `''. For example,
6649 the following binding will make `C-x \' insert a single `\' into
6655 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
6657 8.3.2 Conditional Init Constructs
6658 ---------------------------------
6660 Readline implements a facility similar in spirit to the conditional
6661 compilation features of the C preprocessor which allows key bindings
6662 and variable settings to be performed as the result of tests. There
6663 are four parser directives used.
6666 The `$if' construct allows bindings to be made based on the
6667 editing mode, the terminal being used, or the application using
6668 Readline. The text of the test extends to the end of the line; no
6669 characters are required to isolate it.
6672 The `mode=' form of the `$if' directive is used to test
6673 whether Readline is in `emacs' or `vi' mode. This may be
6674 used in conjunction with the `set keymap' command, for
6675 instance, to set bindings in the `emacs-standard' and
6676 `emacs-ctlx' keymaps only if Readline is starting out in
6680 The `term=' form may be used to include terminal-specific key
6681 bindings, perhaps to bind the key sequences output by the
6682 terminal's function keys. The word on the right side of the
6683 `=' is tested against both the full name of the terminal and
6684 the portion of the terminal name before the first `-'. This
6685 allows `sun' to match both `sun' and `sun-cmd', for instance.
6688 The APPLICATION construct is used to include
6689 application-specific settings. Each program using the
6690 Readline library sets the APPLICATION NAME, and you can test
6691 for a particular value. This could be used to bind key
6692 sequences to functions useful for a specific program. For
6693 instance, the following command adds a key sequence that
6694 quotes the current or previous word in Bash:
6696 # Quote the current or previous word
6697 "\C-xq": "\eb\"\ef\""
6701 This command, as seen in the previous example, terminates an `$if'
6705 Commands in this branch of the `$if' directive are executed if the
6709 This directive takes a single filename as an argument and reads
6710 commands and bindings from that file. For example, the following
6711 directive reads from `/etc/inputrc':
6712 $include /etc/inputrc
6715 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
6717 8.3.3 Sample Init File
6718 ----------------------
6720 Here is an example of an INPUTRC file. This illustrates key binding,
6721 variable assignment, and conditional syntax.
6724 # This file controls the behaviour of line input editing for
6725 # programs that use the GNU Readline library. Existing
6726 # programs include FTP, Bash, and GDB.
6728 # You can re-read the inputrc file with C-x C-r.
6729 # Lines beginning with '#' are comments.
6731 # First, include any systemwide bindings and variable
6732 # assignments from /etc/Inputrc
6733 $include /etc/Inputrc
6736 # Set various bindings for emacs mode.
6738 set editing-mode emacs
6742 Meta-Control-h: backward-kill-word Text after the function name is ignored
6745 # Arrow keys in keypad mode
6747 #"\M-OD": backward-char
6748 #"\M-OC": forward-char
6749 #"\M-OA": previous-history
6750 #"\M-OB": next-history
6752 # Arrow keys in ANSI mode
6754 "\M-[D": backward-char
6755 "\M-[C": forward-char
6756 "\M-[A": previous-history
6757 "\M-[B": next-history
6759 # Arrow keys in 8 bit keypad mode
6761 #"\M-\C-OD": backward-char
6762 #"\M-\C-OC": forward-char
6763 #"\M-\C-OA": previous-history
6764 #"\M-\C-OB": next-history
6766 # Arrow keys in 8 bit ANSI mode
6768 #"\M-\C-[D": backward-char
6769 #"\M-\C-[C": forward-char
6770 #"\M-\C-[A": previous-history
6771 #"\M-\C-[B": next-history
6777 # An old-style binding. This happens to be the default.
6780 # Macros that are convenient for shell interaction
6783 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
6784 # prepare to type a quoted word --
6785 # insert open and close double quotes
6786 # and move to just after the open quote
6787 "\C-x\"": "\"\"\C-b"
6788 # insert a backslash (testing backslash escapes
6789 # in sequences and macros)
6791 # Quote the current or previous word
6792 "\C-xq": "\eb\"\ef\""
6793 # Add a binding to refresh the line, which is unbound
6794 "\C-xr": redraw-current-line
6795 # Edit variable on current line.
6796 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
6799 # use a visible bell if one is available
6800 set bell-style visible
6802 # don't strip characters to 7 bits when reading
6805 # allow iso-latin1 characters to be inserted rather
6806 # than converted to prefix-meta sequences
6807 set convert-meta off
6809 # display characters with the eighth bit set directly
6810 # rather than as meta-prefixed characters
6813 # if there are more than 150 possible completions for
6814 # a word, ask the user if he wants to see all of them
6815 set completion-query-items 150
6821 "\M-.": yank-last-arg
6825 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
6827 8.4 Bindable Readline Commands
6828 ==============================
6832 * Commands For Moving:: Moving about the line.
6833 * Commands For History:: Getting at previous lines.
6834 * Commands For Text:: Commands for changing text.
6835 * Commands For Killing:: Commands for killing and yanking.
6836 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
6837 * Commands For Completion:: Getting Readline to do the typing for you.
6838 * Keyboard Macros:: Saving and re-executing typed characters
6839 * Miscellaneous Commands:: Other miscellaneous commands.
6841 This section describes Readline commands that may be bound to key
6842 sequences. You can list your key bindings by executing `bind -P' or,
6843 for a more terse format, suitable for an INPUTRC file, `bind -p'.
6844 (*Note Bash Builtins::.) Command names without an accompanying key
6845 sequence are unbound by default.
6847 In the following descriptions, "point" refers to the current cursor
6848 position, and "mark" refers to a cursor position saved by the
6849 `set-mark' command. The text between the point and mark is referred to
6853 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
6855 8.4.1 Commands For Moving
6856 -------------------------
6858 `beginning-of-line (C-a)'
6859 Move to the start of the current line.
6862 Move to the end of the line.
6864 `forward-char (C-f)'
6865 Move forward a character.
6867 `backward-char (C-b)'
6868 Move back a character.
6870 `forward-word (M-f)'
6871 Move forward to the end of the next word. Words are composed of
6874 `backward-word (M-b)'
6875 Move back to the start of the current or previous word. Words are
6876 composed of letters and digits.
6878 `shell-forward-word ()'
6879 Move forward to the end of the next word. Words are delimited by
6880 non-quoted shell metacharacters.
6882 `shell-backward-word ()'
6883 Move back to the start of the current or previous word. Words are
6884 delimited by non-quoted shell metacharacters.
6886 `clear-screen (C-l)'
6887 Clear the screen and redraw the current line, leaving the current
6888 line at the top of the screen.
6890 `redraw-current-line ()'
6891 Refresh the current line. By default, this is unbound.
6895 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
6897 8.4.2 Commands For Manipulating The History
6898 -------------------------------------------
6900 `accept-line (Newline or Return)'
6901 Accept the line regardless of where the cursor is. If this line is
6902 non-empty, add it to the history list according to the setting of
6903 the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a
6904 modified history line, then restore the history line to its
6907 `previous-history (C-p)'
6908 Move `back' through the history list, fetching the previous
6911 `next-history (C-n)'
6912 Move `forward' through the history list, fetching the next command.
6914 `beginning-of-history (M-<)'
6915 Move to the first line in the history.
6917 `end-of-history (M->)'
6918 Move to the end of the input history, i.e., the line currently
6921 `reverse-search-history (C-r)'
6922 Search backward starting at the current line and moving `up'
6923 through the history as necessary. This is an incremental search.
6925 `forward-search-history (C-s)'
6926 Search forward starting at the current line and moving `down'
6927 through the the history as necessary. This is an incremental
6930 `non-incremental-reverse-search-history (M-p)'
6931 Search backward starting at the current line and moving `up'
6932 through the history as necessary using a non-incremental search
6933 for a string supplied by the user.
6935 `non-incremental-forward-search-history (M-n)'
6936 Search forward starting at the current line and moving `down'
6937 through the the history as necessary using a non-incremental search
6938 for a string supplied by the user.
6940 `history-search-forward ()'
6941 Search forward through the history for the string of characters
6942 between the start of the current line and the point. This is a
6943 non-incremental search. By default, this command is unbound.
6945 `history-search-backward ()'
6946 Search backward through the history for the string of characters
6947 between the start of the current line and the point. This is a
6948 non-incremental search. By default, this command is unbound.
6950 `yank-nth-arg (M-C-y)'
6951 Insert the first argument to the previous command (usually the
6952 second word on the previous line) at point. With an argument N,
6953 insert the Nth word from the previous command (the words in the
6954 previous command begin with word 0). A negative argument inserts
6955 the Nth word from the end of the previous command. Once the
6956 argument N is computed, the argument is extracted as if the `!N'
6957 history expansion had been specified.
6959 `yank-last-arg (M-. or M-_)'
6960 Insert last argument to the previous command (the last word of the
6961 previous history entry). With an argument, behave exactly like
6962 `yank-nth-arg'. Successive calls to `yank-last-arg' move back
6963 through the history list, inserting the last argument of each line
6964 in turn. The history expansion facilities are used to extract the
6965 last argument, as if the `!$' history expansion had been specified.
6969 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
6971 8.4.3 Commands For Changing Text
6972 --------------------------------
6975 Delete the character at point. If point is at the beginning of
6976 the line, there are no characters in the line, and the last
6977 character typed was not bound to `delete-char', then return EOF.
6979 `backward-delete-char (Rubout)'
6980 Delete the character behind the cursor. A numeric argument means
6981 to kill the characters instead of deleting them.
6983 `forward-backward-delete-char ()'
6984 Delete the character under the cursor, unless the cursor is at the
6985 end of the line, in which case the character behind the cursor is
6986 deleted. By default, this is not bound to a key.
6988 `quoted-insert (C-q or C-v)'
6989 Add the next character typed to the line verbatim. This is how to
6990 insert key sequences like `C-q', for example.
6992 `self-insert (a, b, A, 1, !, ...)'
6995 `transpose-chars (C-t)'
6996 Drag the character before the cursor forward over the character at
6997 the cursor, moving the cursor forward as well. If the insertion
6998 point is at the end of the line, then this transposes the last two
6999 characters of the line. Negative arguments have no effect.
7001 `transpose-words (M-t)'
7002 Drag the word before point past the word after point, moving point
7003 past that word as well. If the insertion point is at the end of
7004 the line, this transposes the last two words on the line.
7007 Uppercase the current (or following) word. With a negative
7008 argument, uppercase the previous word, but do not move the cursor.
7010 `downcase-word (M-l)'
7011 Lowercase the current (or following) word. With a negative
7012 argument, lowercase the previous word, but do not move the cursor.
7014 `capitalize-word (M-c)'
7015 Capitalize the current (or following) word. With a negative
7016 argument, capitalize the previous word, but do not move the cursor.
7019 Toggle overwrite mode. With an explicit positive numeric argument,
7020 switches to overwrite mode. With an explicit non-positive numeric
7021 argument, switches to insert mode. This command affects only
7022 `emacs' mode; `vi' mode does overwrite differently. Each call to
7023 `readline()' starts in insert mode.
7025 In overwrite mode, characters bound to `self-insert' replace the
7026 text at point rather than pushing the text to the right.
7027 Characters bound to `backward-delete-char' replace the character
7028 before point with a space.
7030 By default, this command is unbound.
7034 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
7036 8.4.4 Killing And Yanking
7037 -------------------------
7040 Kill the text from point to the end of the line.
7042 `backward-kill-line (C-x Rubout)'
7043 Kill backward to the beginning of the line.
7045 `unix-line-discard (C-u)'
7046 Kill backward from the cursor to the beginning of the current line.
7048 `kill-whole-line ()'
7049 Kill all characters on the current line, no matter where point is.
7050 By default, this is unbound.
7053 Kill from point to the end of the current word, or if between
7054 words, to the end of the next word. Word boundaries are the same
7057 `backward-kill-word (M-<DEL>)'
7058 Kill the word behind point. Word boundaries are the same as
7061 `shell-kill-word ()'
7062 Kill from point to the end of the current word, or if between
7063 words, to the end of the next word. Word boundaries are the same
7064 as `shell-forward-word'.
7066 `backward-kill-word ()'
7067 Kill the word behind point. Word boundaries are the same as
7068 `shell-backward-word'.
7070 `unix-word-rubout (C-w)'
7071 Kill the word behind point, using white space as a word boundary.
7072 The killed text is saved on the kill-ring.
7074 `unix-filename-rubout ()'
7075 Kill the word behind point, using white space and the slash
7076 character as the word boundaries. The killed text is saved on the
7079 `delete-horizontal-space ()'
7080 Delete all spaces and tabs around point. By default, this is
7084 Kill the text in the current region. By default, this command is
7087 `copy-region-as-kill ()'
7088 Copy the text in the region to the kill buffer, so it can be yanked
7089 right away. By default, this command is unbound.
7091 `copy-backward-word ()'
7092 Copy the word before point to the kill buffer. The word
7093 boundaries are the same as `backward-word'. By default, this
7096 `copy-forward-word ()'
7097 Copy the word following point to the kill buffer. The word
7098 boundaries are the same as `forward-word'. By default, this
7102 Yank the top of the kill ring into the buffer at point.
7105 Rotate the kill-ring, and yank the new top. You can only do this
7106 if the prior command is `yank' or `yank-pop'.
7109 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
7111 8.4.5 Specifying Numeric Arguments
7112 ----------------------------------
7114 `digit-argument (M-0, M-1, ... M--)'
7115 Add this digit to the argument already accumulating, or start a new
7116 argument. `M--' starts a negative argument.
7118 `universal-argument ()'
7119 This is another way to specify an argument. If this command is
7120 followed by one or more digits, optionally with a leading minus
7121 sign, those digits define the argument. If the command is
7122 followed by digits, executing `universal-argument' again ends the
7123 numeric argument, but is otherwise ignored. As a special case, if
7124 this command is immediately followed by a character that is
7125 neither a digit or minus sign, the argument count for the next
7126 command is multiplied by four. The argument count is initially
7127 one, so executing this function the first time makes the argument
7128 count four, a second time makes the argument count sixteen, and so
7129 on. By default, this is not bound to a key.
7132 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
7134 8.4.6 Letting Readline Type For You
7135 -----------------------------------
7138 Attempt to perform completion on the text before point. The
7139 actual completion performed is application-specific. Bash
7140 attempts completion treating the text as a variable (if the text
7141 begins with `$'), username (if the text begins with `~'), hostname
7142 (if the text begins with `@'), or command (including aliases and
7143 functions) in turn. If none of these produces a match, filename
7144 completion is attempted.
7146 `possible-completions (M-?)'
7147 List the possible completions of the text before point.
7149 `insert-completions (M-*)'
7150 Insert all completions of the text before point that would have
7151 been generated by `possible-completions'.
7154 Similar to `complete', but replaces the word to be completed with
7155 a single match from the list of possible completions. Repeated
7156 execution of `menu-complete' steps through the list of possible
7157 completions, inserting each match in turn. At the end of the list
7158 of completions, the bell is rung (subject to the setting of
7159 `bell-style') and the original text is restored. An argument of N
7160 moves N positions forward in the list of matches; a negative
7161 argument may be used to move backward through the list. This
7162 command is intended to be bound to <TAB>, but is unbound by
7165 `delete-char-or-list ()'
7166 Deletes the character under the cursor if not at the beginning or
7167 end of the line (like `delete-char'). If at the end of the line,
7168 behaves identically to `possible-completions'. This command is
7171 `complete-filename (M-/)'
7172 Attempt filename completion on the text before point.
7174 `possible-filename-completions (C-x /)'
7175 List the possible completions of the text before point, treating
7178 `complete-username (M-~)'
7179 Attempt completion on the text before point, treating it as a
7182 `possible-username-completions (C-x ~)'
7183 List the possible completions of the text before point, treating
7186 `complete-variable (M-$)'
7187 Attempt completion on the text before point, treating it as a
7190 `possible-variable-completions (C-x $)'
7191 List the possible completions of the text before point, treating
7192 it as a shell variable.
7194 `complete-hostname (M-@)'
7195 Attempt completion on the text before point, treating it as a
7198 `possible-hostname-completions (C-x @)'
7199 List the possible completions of the text before point, treating
7202 `complete-command (M-!)'
7203 Attempt completion on the text before point, treating it as a
7204 command name. Command completion attempts to match the text
7205 against aliases, reserved words, shell functions, shell builtins,
7206 and finally executable filenames, in that order.
7208 `possible-command-completions (C-x !)'
7209 List the possible completions of the text before point, treating
7210 it as a command name.
7212 `dynamic-complete-history (M-<TAB>)'
7213 Attempt completion on the text before point, comparing the text
7214 against lines from the history list for possible completion
7218 Attempt menu completion on the text before point, comparing the
7219 text against lines from the history list for possible completion
7222 `complete-into-braces (M-{)'
7223 Perform filename completion and insert the list of possible
7224 completions enclosed within braces so the list is available to the
7225 shell (*note Brace Expansion::).
7229 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
7231 8.4.7 Keyboard Macros
7232 ---------------------
7234 `start-kbd-macro (C-x ()'
7235 Begin saving the characters typed into the current keyboard macro.
7237 `end-kbd-macro (C-x ))'
7238 Stop saving the characters typed into the current keyboard macro
7239 and save the definition.
7241 `call-last-kbd-macro (C-x e)'
7242 Re-execute the last keyboard macro defined, by making the
7243 characters in the macro appear as if typed at the keyboard.
7247 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
7249 8.4.8 Some Miscellaneous Commands
7250 ---------------------------------
7252 `re-read-init-file (C-x C-r)'
7253 Read in the contents of the INPUTRC file, and incorporate any
7254 bindings or variable assignments found there.
7257 Abort the current editing command and ring the terminal's bell
7258 (subject to the setting of `bell-style').
7260 `do-uppercase-version (M-a, M-b, M-X, ...)'
7261 If the metafied character X is lowercase, run the command that is
7262 bound to the corresponding uppercase character.
7264 `prefix-meta (<ESC>)'
7265 Metafy the next character typed. This is for keyboards without a
7266 meta key. Typing `<ESC> f' is equivalent to typing `M-f'.
7268 `undo (C-_ or C-x C-u)'
7269 Incremental undo, separately remembered for each line.
7272 Undo all changes made to this line. This is like executing the
7273 `undo' command enough times to get back to the beginning.
7275 `tilde-expand (M-&)'
7276 Perform tilde expansion on the current word.
7279 Set the mark to the point. If a numeric argument is supplied, the
7280 mark is set to that position.
7282 `exchange-point-and-mark (C-x C-x)'
7283 Swap the point with the mark. The current cursor position is set
7284 to the saved position, and the old cursor position is saved as the
7287 `character-search (C-])'
7288 A character is read and point is moved to the next occurrence of
7289 that character. A negative count searches for previous
7292 `character-search-backward (M-C-])'
7293 A character is read and point is moved to the previous occurrence
7294 of that character. A negative count searches for subsequent
7297 `insert-comment (M-#)'
7298 Without a numeric argument, the value of the `comment-begin'
7299 variable is inserted at the beginning of the current line. If a
7300 numeric argument is supplied, this command acts as a toggle: if
7301 the characters at the beginning of the line do not match the value
7302 of `comment-begin', the value is inserted, otherwise the
7303 characters in `comment-begin' are deleted from the beginning of
7304 the line. In either case, the line is accepted as if a newline
7305 had been typed. The default value of `comment-begin' causes this
7306 command to make the current line a shell comment. If a numeric
7307 argument causes the comment character to be removed, the line will
7308 be executed by the shell.
7311 Print all of the functions and their key bindings to the Readline
7312 output stream. If a numeric argument is supplied, the output is
7313 formatted in such a way that it can be made part of an INPUTRC
7314 file. This command is unbound by default.
7317 Print all of the settable variables and their values to the
7318 Readline output stream. If a numeric argument is supplied, the
7319 output is formatted in such a way that it can be made part of an
7320 INPUTRC file. This command is unbound by default.
7323 Print all of the Readline key sequences bound to macros and the
7324 strings they output. If a numeric argument is supplied, the
7325 output is formatted in such a way that it can be made part of an
7326 INPUTRC file. This command is unbound by default.
7328 `glob-complete-word (M-g)'
7329 The word before point is treated as a pattern for pathname
7330 expansion, with an asterisk implicitly appended. This pattern is
7331 used to generate a list of matching file names for possible
7334 `glob-expand-word (C-x *)'
7335 The word before point is treated as a pattern for pathname
7336 expansion, and the list of matching file names is inserted,
7337 replacing the word. If a numeric argument is supplied, a `*' is
7338 appended before pathname expansion.
7340 `glob-list-expansions (C-x g)'
7341 The list of expansions that would have been generated by
7342 `glob-expand-word' is displayed, and the line is redrawn. If a
7343 numeric argument is supplied, a `*' is appended before pathname
7346 `display-shell-version (C-x C-v)'
7347 Display version information about the current instance of Bash.
7349 `shell-expand-line (M-C-e)'
7350 Expand the line as the shell does. This performs alias and
7351 history expansion as well as all of the shell word expansions
7352 (*note Shell Expansions::).
7354 `history-expand-line (M-^)'
7355 Perform history expansion on the current line.
7358 Perform history expansion on the current line and insert a space
7359 (*note History Interaction::).
7361 `alias-expand-line ()'
7362 Perform alias expansion on the current line (*note Aliases::).
7364 `history-and-alias-expand-line ()'
7365 Perform history and alias expansion on the current line.
7367 `insert-last-argument (M-. or M-_)'
7368 A synonym for `yank-last-arg'.
7370 `operate-and-get-next (C-o)'
7371 Accept the current line for execution and fetch the next line
7372 relative to the current line from the history for editing. Any
7373 argument is ignored.
7375 `edit-and-execute-command (C-xC-e)'
7376 Invoke an editor on the current command line, and execute the
7377 result as shell commands. Bash attempts to invoke `$VISUAL',
7378 `$EDITOR', and `emacs' as the editor, in that order.
7382 File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
7384 8.5 Readline vi Mode
7385 ====================
7387 While the Readline library does not have a full set of `vi' editing
7388 functions, it does contain enough to allow simple editing of the line.
7389 The Readline `vi' mode behaves as specified in the POSIX 1003.2
7392 In order to switch interactively between `emacs' and `vi' editing
7393 modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
7394 Builtin::). The Readline default is `emacs' mode.
7396 When you enter a line in `vi' mode, you are already placed in
7397 `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
7398 you into `command' mode, where you can edit the text of the line with
7399 the standard `vi' movement keys, move to previous history lines with
7400 `k' and subsequent lines with `j', and so forth.
7403 File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
7405 8.6 Programmable Completion
7406 ===========================
7408 When word completion is attempted for an argument to a command for
7409 which a completion specification (a COMPSPEC) has been defined using
7410 the `complete' builtin (*note Programmable Completion Builtins::), the
7411 programmable completion facilities are invoked.
7413 First, the command name is identified. If a compspec has been
7414 defined for that command, the compspec is used to generate the list of
7415 possible completions for the word. If the command word is a full
7416 pathname, a compspec for the full pathname is searched for first. If
7417 no compspec is found for the full pathname, an attempt is made to find
7418 a compspec for the portion following the final slash.
7420 Once a compspec has been found, it is used to generate the list of
7421 matching words. If a compspec is not found, the default Bash completion
7422 described above (*note Commands For Completion::) is performed.
7424 First, the actions specified by the compspec are used. Only matches
7425 which are prefixed by the word being completed are returned. When the
7426 `-f' or `-d' option is used for filename or directory name completion,
7427 the shell variable `FIGNORE' is used to filter the matches. *Note Bash
7428 Variables::, for a description of `FIGNORE'.
7430 Any completions specified by a filename expansion pattern to the
7431 `-G' option are generated next. The words generated by the pattern
7432 need not match the word being completed. The `GLOBIGNORE' shell
7433 variable is not used to filter the matches, but the `FIGNORE' shell
7436 Next, the string specified as the argument to the `-W' option is
7437 considered. The string is first split using the characters in the `IFS'
7438 special variable as delimiters. Shell quoting is honored. Each word
7439 is then expanded using brace expansion, tilde expansion, parameter and
7440 variable expansion, command substitution, and arithmetic expansion, as
7441 described above (*note Shell Expansions::). The results are split
7442 using the rules described above (*note Word Splitting::). The results
7443 of the expansion are prefix-matched against the word being completed,
7444 and the matching words become the possible completions.
7446 After these matches have been generated, any shell function or
7447 command specified with the `-F' and `-C' options is invoked. When the
7448 command or function is invoked, the `COMP_LINE', `COMP_POINT',
7449 `COMP_KEY', and `COMP_TYPE' variables are assigned values as described
7450 above (*note Bash Variables::). If a shell function is being invoked,
7451 the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
7452 function or command is invoked, the first argument is the name of the
7453 command whose arguments are being completed, the second argument is the
7454 word being completed, and the third argument is the word preceding the
7455 word being completed on the current command line. No filtering of the
7456 generated completions against the word being completed is performed;
7457 the function or command has complete freedom in generating the matches.
7459 Any function specified with `-F' is invoked first. The function may
7460 use any of the shell facilities, including the `compgen' and `compopt'
7461 builtins described below (*note Programmable Completion Builtins::), to
7462 generate the matches. It must put the possible completions in the
7463 `COMPREPLY' array variable.
7465 Next, any command specified with the `-C' option is invoked in an
7466 environment equivalent to command substitution. It should print a list
7467 of completions, one per line, to the standard output. Backslash may be
7468 used to escape a newline, if necessary.
7470 After all of the possible completions are generated, any filter
7471 specified with the `-X' option is applied to the list. The filter is a
7472 pattern as used for pathname expansion; a `&' in the pattern is
7473 replaced with the text of the word being completed. A literal `&' may
7474 be escaped with a backslash; the backslash is removed before attempting
7475 a match. Any completion that matches the pattern will be removed from
7476 the list. A leading `!' negates the pattern; in this case any
7477 completion not matching the pattern will be removed.
7479 Finally, any prefix and suffix specified with the `-P' and `-S'
7480 options are added to each member of the completion list, and the result
7481 is returned to the Readline completion code as the list of possible
7484 If the previously-applied actions do not generate any matches, and
7485 the `-o dirnames' option was supplied to `complete' when the compspec
7486 was defined, directory name completion is attempted.
7488 If the `-o plusdirs' option was supplied to `complete' when the
7489 compspec was defined, directory name completion is attempted and any
7490 matches are added to the results of the other actions.
7492 By default, if a compspec is found, whatever it generates is
7493 returned to the completion code as the full set of possible completions.
7494 The default Bash completions are not attempted, and the Readline default
7495 of filename completion is disabled. If the `-o bashdefault' option was
7496 supplied to `complete' when the compspec was defined, the default Bash
7497 completions are attempted if the compspec generates no matches. If the
7498 `-o default' option was supplied to `complete' when the compspec was
7499 defined, Readline's default completion will be performed if the
7500 compspec (and, if attempted, the default Bash completions) generate no
7503 When a compspec indicates that directory name completion is desired,
7504 the programmable completion functions force Readline to append a slash
7505 to completed names which are symbolic links to directories, subject to
7506 the value of the MARK-DIRECTORIES Readline variable, regardless of the
7507 setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
7510 File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
7512 8.7 Programmable Completion Builtins
7513 ====================================
7515 Two builtin commands are available to manipulate the programmable
7516 completion facilities.
7519 `compgen [OPTION] [WORD]'
7521 Generate possible completion matches for WORD according to the
7522 OPTIONs, which may be any option accepted by the `complete'
7523 builtin with the exception of `-p' and `-r', and write the matches
7524 to the standard output. When using the `-F' or `-C' options, the
7525 various shell variables set by the programmable completion
7526 facilities, while available, will not have useful values.
7528 The matches will be generated in the same way as if the
7529 programmable completion code had generated them directly from a
7530 completion specification with the same flags. If WORD is
7531 specified, only those completions matching WORD will be displayed.
7533 The return value is true unless an invalid option is supplied, or
7534 no matches were generated.
7537 `complete [-abcdefgjksuv] [-o COMP-OPTION] [-E] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
7538 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
7539 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]'
7540 `complete -pr [-E] [NAME ...]'
7542 Specify how arguments to each NAME should be completed. If the
7543 `-p' option is supplied, or if no options are supplied, existing
7544 completion specifications are printed in a way that allows them to
7545 be reused as input. The `-r' option removes a completion
7546 specification for each NAME, or, if no NAMEs are supplied, all
7547 completion specifications. The `-E' option indicates that the
7548 remaining options and actions should apply to "empty" command
7549 completion; that is, completion attempted on a blank line.
7551 The process of applying these completion specifications when word
7552 completion is attempted is described above (*note Programmable
7555 Other options, if specified, have the following meanings. The
7556 arguments to the `-G', `-W', and `-X' options (and, if necessary,
7557 the `-P' and `-S' options) should be quoted to protect them from
7558 expansion before the `complete' builtin is invoked.
7561 The COMP-OPTION controls several aspects of the compspec's
7562 behavior beyond the simple generation of completions.
7563 COMP-OPTION may be one of:
7566 Perform the rest of the default Bash completions if the
7567 compspec generates no matches.
7570 Use Readline's default filename completion if the
7571 compspec generates no matches.
7574 Perform directory name completion if the compspec
7575 generates no matches.
7578 Tell Readline that the compspec generates filenames, so
7579 it can perform any filename-specific processing (like
7580 adding a slash to directory names quoting special
7581 characters, or suppressing trailing spaces). This
7582 option is intended to be used with shell functions
7583 specified with `-F'.
7586 Tell Readline not to append a space (the default) to
7587 words completed at the end of the line.
7590 After any matches defined by the compspec are generated,
7591 directory name completion is attempted and any matches
7592 are added to the results of the other actions.
7596 The ACTION may be one of the following to generate a list of
7597 possible completions:
7600 Alias names. May also be specified as `-a'.
7603 Array variable names.
7606 Readline key binding names (*note Bindable Readline
7610 Names of shell builtin commands. May also be specified
7614 Command names. May also be specified as `-c'.
7617 Directory names. May also be specified as `-d'.
7620 Names of disabled shell builtins.
7623 Names of enabled shell builtins.
7626 Names of exported shell variables. May also be
7630 File names. May also be specified as `-f'.
7633 Names of shell functions.
7636 Group names. May also be specified as `-g'.
7639 Help topics as accepted by the `help' builtin (*note
7643 Hostnames, as taken from the file specified by the
7644 `HOSTFILE' shell variable (*note Bash Variables::).
7647 Job names, if job control is active. May also be
7651 Shell reserved words. May also be specified as `-k'.
7654 Names of running jobs, if job control is active.
7657 Service names. May also be specified as `-s'.
7660 Valid arguments for the `-o' option to the `set' builtin
7661 (*note The Set Builtin::).
7664 Shell option names as accepted by the `shopt' builtin
7665 (*note Bash Builtins::).
7671 Names of stopped jobs, if job control is active.
7674 User names. May also be specified as `-u'.
7677 Names of all shell variables. May also be specified as
7681 The filename expansion pattern GLOBPAT is expanded to generate
7682 the possible completions.
7685 The WORDLIST is split using the characters in the `IFS'
7686 special variable as delimiters, and each resultant word is
7687 expanded. The possible completions are the members of the
7688 resultant list which match the word being completed.
7691 COMMAND is executed in a subshell environment, and its output
7692 is used as the possible completions.
7695 The shell function FUNCTION is executed in the current shell
7696 environment. When it finishes, the possible completions are
7697 retrieved from the value of the `COMPREPLY' array variable.
7700 FILTERPAT is a pattern as used for filename expansion. It is
7701 applied to the list of possible completions generated by the
7702 preceding options and arguments, and each completion matching
7703 FILTERPAT is removed from the list. A leading `!' in
7704 FILTERPAT negates the pattern; in this case, any completion
7705 not matching FILTERPAT is removed.
7708 PREFIX is added at the beginning of each possible completion
7709 after all other options have been applied.
7712 SUFFIX is appended to each possible completion after all
7713 other options have been applied.
7715 The return value is true unless an invalid option is supplied, an
7716 option other than `-p' or `-r' is supplied without a NAME
7717 argument, an attempt is made to remove a completion specification
7718 for a NAME for which no specification exists, or an error occurs
7719 adding a completion specification.
7722 `compopt' [-o OPTION] [+o OPTION] [NAME]
7723 Modify completion options for each NAME according to the OPTIONs,
7724 or for the currently-execution completion if no NAMEs are supplied.
7725 If no OPTIONs are given, display the completion options for each
7726 NAME or the current completion. The possible values of OPTION are
7727 those valid for the `complete' builtin described above.
7729 The return value is true unless an invalid option is supplied, an
7730 attempt is made to modify the options for a NAME for which no
7731 completion specification exists, or an output error occurs.
7735 File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
7737 9 Using History Interactively
7738 *****************************
7740 This chapter describes how to use the GNU History Library
7741 interactively, from a user's standpoint. It should be considered a
7742 user's guide. For information on using the GNU History Library in
7743 other programs, see the GNU Readline Library Manual.
7747 * Bash History Facilities:: How Bash lets you manipulate your command
7749 * Bash History Builtins:: The Bash builtin commands that manipulate
7750 the command history.
7751 * History Interaction:: What it feels like using History as a user.
7754 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
7756 9.1 Bash History Facilities
7757 ===========================
7759 When the `-o history' option to the `set' builtin is enabled (*note The
7760 Set Builtin::), the shell provides access to the "command history", the
7761 list of commands previously typed. The value of the `HISTSIZE' shell
7762 variable is used as the number of commands to save in a history list.
7763 The text of the last `$HISTSIZE' commands (default 500) is saved. The
7764 shell stores each command in the history list prior to parameter and
7765 variable expansion but after history expansion is performed, subject to
7766 the values of the shell variables `HISTIGNORE' and `HISTCONTROL'.
7768 When the shell starts up, the history is initialized from the file
7769 named by the `HISTFILE' variable (default `~/.bash_history'). The file
7770 named by the value of `HISTFILE' is truncated, if necessary, to contain
7771 no more than the number of lines specified by the value of the
7772 `HISTFILESIZE' variable. When an interactive shell exits, the last
7773 `$HISTSIZE' lines are copied from the history list to the file named by
7774 `$HISTFILE'. If the `histappend' shell option is set (*note Bash
7775 Builtins::), the lines are appended to the history file, otherwise the
7776 history file is overwritten. If `HISTFILE' is unset, or if the history
7777 file is unwritable, the history is not saved. After saving the
7778 history, the history file is truncated to contain no more than
7779 `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
7782 If the `HISTTIMEFORMAT' is set, the time stamp information
7783 associated with each history entry is written to the history file,
7784 marked with the history comment character. When the history file is
7785 read, lines beginning with the history comment character followed
7786 immediately by a digit are interpreted as timestamps for the previous
7789 The builtin command `fc' may be used to list or edit and re-execute
7790 a portion of the history list. The `history' builtin may be used to
7791 display or modify the history list and manipulate the history file.
7792 When using command-line editing, search commands are available in each
7793 editing mode that provide access to the history list (*note Commands
7796 The shell allows control over which commands are saved on the history
7797 list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
7798 the shell to save only a subset of the commands entered. The `cmdhist'
7799 shell option, if enabled, causes the shell to attempt to save each line
7800 of a multi-line command in the same history entry, adding semicolons
7801 where necessary to preserve syntactic correctness. The `lithist' shell
7802 option causes the shell to save the command with embedded newlines
7803 instead of semicolons. The `shopt' builtin is used to set these
7804 options. *Note Bash Builtins::, for a description of `shopt'.
7807 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
7809 9.2 Bash History Builtins
7810 =========================
7812 Bash provides two builtin commands which manipulate the history list
7816 `fc [-e ENAME] [-lnr] [FIRST] [LAST]'
7817 `fc -s [PAT=REP] [COMMAND]'
7819 Fix Command. In the first form, a range of commands from FIRST to
7820 LAST is selected from the history list. Both FIRST and LAST may
7821 be specified as a string (to locate the most recent command
7822 beginning with that string) or as a number (an index into the
7823 history list, where a negative number is used as an offset from the
7824 current command number). If LAST is not specified it is set to
7825 FIRST. If FIRST is not specified it is set to the previous
7826 command for editing and -16 for listing. If the `-l' flag is
7827 given, the commands are listed on standard output. The `-n' flag
7828 suppresses the command numbers when listing. The `-r' flag
7829 reverses the order of the listing. Otherwise, the editor given by
7830 ENAME is invoked on a file containing those commands. If ENAME is
7831 not given, the value of the following variable expansion is used:
7832 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
7833 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
7834 that is set, or `vi' if neither is set. When editing is complete,
7835 the edited commands are echoed and executed.
7837 In the second form, COMMAND is re-executed after each instance of
7838 PAT in the selected command is replaced by REP.
7840 A useful alias to use with the `fc' command is `r='fc -s'', so
7841 that typing `r cc' runs the last command beginning with `cc' and
7842 typing `r' re-executes the last command (*note Aliases::).
7848 history [-anrw] [FILENAME]
7851 With no options, display the history list with line numbers.
7852 Lines prefixed with a `*' have been modified. An argument of N
7853 lists only the last N lines. If the shell variable
7854 `HISTTIMEFORMAT' is set and not null, it is used as a format
7855 string for STRFTIME to display the time stamp associated with each
7856 displayed history entry. No intervening blank is printed between
7857 the formatted time stamp and the history line.
7859 Options, if supplied, have the following meanings:
7862 Clear the history list. This may be combined with the other
7863 options to replace the history list completely.
7866 Delete the history entry at position OFFSET. OFFSET should
7867 be specified as it appears when the history is displayed.
7870 Append the new history lines (history lines entered since the
7871 beginning of the current Bash session) to the history file.
7874 Append the history lines not already read from the history
7875 file to the current history list. These are lines appended
7876 to the history file since the beginning of the current Bash
7880 Read the current history file and append its contents to the
7884 Write out the current history to the history file.
7887 Perform history substitution on the ARGs and display the
7888 result on the standard output, without storing the results in
7892 The ARGs are added to the end of the history list as a single
7896 When any of the `-w', `-r', `-a', or `-n' options is used, if
7897 FILENAME is given, then it is used as the history file. If not,
7898 then the value of the `HISTFILE' variable is used.
7902 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
7904 9.3 History Expansion
7905 =====================
7907 The History library provides a history expansion feature that is similar
7908 to the history expansion provided by `csh'. This section describes the
7909 syntax used to manipulate the history information.
7911 History expansions introduce words from the history list into the
7912 input stream, making it easy to repeat commands, insert the arguments
7913 to a previous command into the current input line, or fix errors in
7914 previous commands quickly.
7916 History expansion takes place in two parts. The first is to
7917 determine which line from the history list should be used during
7918 substitution. The second is to select portions of that line for
7919 inclusion into the current one. The line selected from the history is
7920 called the "event", and the portions of that line that are acted upon
7921 are called "words". Various "modifiers" are available to manipulate
7922 the selected words. The line is broken into words in the same fashion
7923 that Bash does, so that several words surrounded by quotes are
7924 considered one word. History expansions are introduced by the
7925 appearance of the history expansion character, which is `!' by default.
7926 Only `\' and `'' may be used to escape the history expansion character.
7928 Several shell options settable with the `shopt' builtin (*note Bash
7929 Builtins::) may be used to tailor the behavior of history expansion.
7930 If the `histverify' shell option is enabled, and Readline is being
7931 used, history substitutions are not immediately passed to the shell
7932 parser. Instead, the expanded line is reloaded into the Readline
7933 editing buffer for further modification. If Readline is being used,
7934 and the `histreedit' shell option is enabled, a failed history
7935 expansion will be reloaded into the Readline editing buffer for
7936 correction. The `-p' option to the `history' builtin command may be
7937 used to see what a history expansion will do before using it. The `-s'
7938 option to the `history' builtin may be used to add commands to the end
7939 of the history list without actually executing them, so that they are
7940 available for subsequent recall. This is most useful in conjunction
7943 The shell allows control of the various characters used by the
7944 history expansion mechanism with the `histchars' variable, as explained
7945 above (*note Bash Variables::). The shell uses the history comment
7946 character to mark history timestamps when writing the history file.
7950 * Event Designators:: How to specify which history line to use.
7951 * Word Designators:: Specifying which words are of interest.
7952 * Modifiers:: Modifying the results of substitution.
7955 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
7957 9.3.1 Event Designators
7958 -----------------------
7960 An event designator is a reference to a command line entry in the
7964 Start a history substitution, except when followed by a space, tab,
7965 the end of the line, `=' or `(' (when the `extglob' shell option
7966 is enabled using the `shopt' builtin).
7969 Refer to command line N.
7972 Refer to the command N lines back.
7975 Refer to the previous command. This is a synonym for `!-1'.
7978 Refer to the most recent command starting with STRING.
7981 Refer to the most recent command containing STRING. The trailing
7982 `?' may be omitted if the STRING is followed immediately by a
7986 Quick Substitution. Repeat the last command, replacing STRING1
7987 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
7990 The entire command line typed so far.
7994 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
7996 9.3.2 Word Designators
7997 ----------------------
7999 Word designators are used to select desired words from the event. A
8000 `:' separates the event specification from the word designator. It may
8001 be omitted if the word designator begins with a `^', `$', `*', `-', or
8002 `%'. Words are numbered from the beginning of the line, with the first
8003 word being denoted by 0 (zero). Words are inserted into the current
8004 line separated by single spaces.
8009 designates the preceding command. When you type this, the
8010 preceding command is repeated in toto.
8013 designates the last argument of the preceding command. This may be
8017 designates the second argument of the most recent command starting
8018 with the letters `fi'.
8020 Here are the word designators:
8023 The `0'th word. For many applications, this is the command word.
8029 The first argument; that is, word 1.
8035 The word matched by the most recent `?STRING?' search.
8038 A range of words; `-Y' abbreviates `0-Y'.
8041 All of the words, except the `0'th. This is a synonym for `1-$'.
8042 It is not an error to use `*' if there is just one word in the
8043 event; the empty string is returned in that case.
8049 Abbreviates `X-$' like `X*', but omits the last word.
8052 If a word designator is supplied without an event specification, the
8053 previous command is used as the event.
8056 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
8061 After the optional word designator, you can add a sequence of one or
8062 more of the following modifiers, each preceded by a `:'.
8065 Remove a trailing pathname component, leaving only the head.
8068 Remove all leading pathname components, leaving the tail.
8071 Remove a trailing suffix of the form `.SUFFIX', leaving the
8075 Remove all but the trailing suffix.
8078 Print the new command but do not execute it.
8081 Quote the substituted words, escaping further substitutions.
8084 Quote the substituted words as with `q', but break into words at
8085 spaces, tabs, and newlines.
8088 Substitute NEW for the first occurrence of OLD in the event line.
8089 Any delimiter may be used in place of `/'. The delimiter may be
8090 quoted in OLD and NEW with a single backslash. If `&' appears in
8091 NEW, it is replaced by OLD. A single backslash will quote the
8092 `&'. The final delimiter is optional if it is the last character
8096 Repeat the previous substitution.
8100 Cause changes to be applied over the entire event line. Used in
8101 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
8104 Apply the following `s' modifier once to each word in the event.
8108 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
8113 This chapter provides basic instructions for installing Bash on the
8114 various supported platforms. The distribution supports the GNU
8115 operating systems, nearly every version of Unix, and several non-Unix
8116 systems such as BeOS and Interix. Other independent ports exist for
8117 MS-DOS, OS/2, and Windows platforms.
8121 * Basic Installation:: Installation instructions.
8122 * Compilers and Options:: How to set special options for various
8124 * Compiling For Multiple Architectures:: How to compile Bash for more
8125 than one kind of system from
8126 the same source tree.
8127 * Installation Names:: How to set the various paths used by the installation.
8128 * Specifying the System Type:: How to configure Bash for a particular system.
8129 * Sharing Defaults:: How to share default configuration values among GNU
8131 * Operation Controls:: Options recognized by the configuration program.
8132 * Optional Features:: How to enable and disable optional features when
8136 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
8138 10.1 Basic Installation
8139 =======================
8141 These are installation instructions for Bash.
8143 The simplest way to compile Bash is:
8145 1. `cd' to the directory containing the source code and type
8146 `./configure' to configure Bash for your system. If you're using
8147 `csh' on an old version of System V, you might need to type `sh
8148 ./configure' instead to prevent `csh' from trying to execute
8151 Running `configure' takes some time. While running, it prints
8152 messages telling which features it is checking for.
8154 2. Type `make' to compile Bash and build the `bashbug' bug reporting
8157 3. Optionally, type `make tests' to run the Bash test suite.
8159 4. Type `make install' to install `bash' and `bashbug'. This will
8160 also install the manual pages and Info file.
8163 The `configure' shell script attempts to guess correct values for
8164 various system-dependent variables used during compilation. It uses
8165 those values to create a `Makefile' in each directory of the package
8166 (the top directory, the `builtins', `doc', and `support' directories,
8167 each directory under `lib', and several others). It also creates a
8168 `config.h' file containing system-dependent definitions. Finally, it
8169 creates a shell script named `config.status' that you can run in the
8170 future to recreate the current configuration, a file `config.cache'
8171 that saves the results of its tests to speed up reconfiguring, and a
8172 file `config.log' containing compiler output (useful mainly for
8173 debugging `configure'). If at some point `config.cache' contains
8174 results you don't want to keep, you may remove or edit it.
8176 To find out more about the options and arguments that the
8177 `configure' script understands, type
8179 bash-2.04$ ./configure --help
8181 at the Bash prompt in your Bash source directory.
8183 If you need to do unusual things to compile Bash, please try to
8184 figure out how `configure' could check whether or not to do them, and
8185 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
8186 considered for the next release.
8188 The file `configure.in' is used to create `configure' by a program
8189 called Autoconf. You only need `configure.in' if you want to change it
8190 or regenerate `configure' using a newer version of Autoconf. If you do
8191 this, make sure you are using Autoconf version 2.50 or newer.
8193 You can remove the program binaries and object files from the source
8194 code directory by typing `make clean'. To also remove the files that
8195 `configure' created (so you can compile Bash for a different kind of
8196 computer), type `make distclean'.
8199 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
8201 10.2 Compilers and Options
8202 ==========================
8204 Some systems require unusual options for compilation or linking that
8205 the `configure' script does not know about. You can give `configure'
8206 initial values for variables by setting them in the environment. Using
8207 a Bourne-compatible shell, you can do that on the command line like
8210 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
8212 On systems that have the `env' program, you can do it like this:
8214 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
8216 The configuration process uses GCC to build Bash if it is available.
8219 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
8221 10.3 Compiling For Multiple Architectures
8222 =========================================
8224 You can compile Bash for more than one kind of computer at the same
8225 time, by placing the object files for each architecture in their own
8226 directory. To do this, you must use a version of `make' that supports
8227 the `VPATH' variable, such as GNU `make'. `cd' to the directory where
8228 you want the object files and executables to go and run the `configure'
8229 script from the source directory. You may need to supply the
8230 `--srcdir=PATH' argument to tell `configure' where the source files
8231 are. `configure' automatically checks for the source code in the
8232 directory that `configure' is in and in `..'.
8234 If you have to use a `make' that does not supports the `VPATH'
8235 variable, you can compile Bash for one architecture at a time in the
8236 source code directory. After you have installed Bash for one
8237 architecture, use `make distclean' before reconfiguring for another
8240 Alternatively, if your system supports symbolic links, you can use
8241 the `support/mkclone' script to create a build tree which has symbolic
8242 links back to each file in the source directory. Here's an example
8243 that creates a build directory in the current directory from a source
8244 directory `/usr/gnu/src/bash-2.0':
8246 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
8248 The `mkclone' script requires Bash, so you must have already built Bash
8249 for at least one architecture before you can create build directories
8250 for other architectures.
8253 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
8255 10.4 Installation Names
8256 =======================
8258 By default, `make install' will install into `/usr/local/bin',
8259 `/usr/local/man', etc. You can specify an installation prefix other
8260 than `/usr/local' by giving `configure' the option `--prefix=PATH', or
8261 by specifying a value for the `DESTDIR' `make' variable when running
8264 You can specify separate installation prefixes for
8265 architecture-specific files and architecture-independent files. If you
8266 give `configure' the option `--exec-prefix=PATH', `make install' will
8267 use PATH as the prefix for installing programs and libraries.
8268 Documentation and other data files will still use the regular prefix.
8271 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
8273 10.5 Specifying the System Type
8274 ===============================
8276 There may be some features `configure' can not figure out
8277 automatically, but need to determine by the type of host Bash will run
8278 on. Usually `configure' can figure that out, but if it prints a
8279 message saying it can not guess the host type, give it the
8280 `--host=TYPE' option. `TYPE' can either be a short name for the system
8281 type, such as `sun4', or a canonical name with three fields:
8282 `CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
8284 See the file `support/config.sub' for the possible values of each
8288 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
8290 10.6 Sharing Defaults
8291 =====================
8293 If you want to set default values for `configure' scripts to share, you
8294 can create a site shell script called `config.site' that gives default
8295 values for variables like `CC', `cache_file', and `prefix'. `configure'
8296 looks for `PREFIX/share/config.site' if it exists, then
8297 `PREFIX/etc/config.site' if it exists. Or, you can set the
8298 `CONFIG_SITE' environment variable to the location of the site script.
8299 A warning: the Bash `configure' looks for a site script, but not all
8300 `configure' scripts do.
8303 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
8305 10.7 Operation Controls
8306 =======================
8308 `configure' recognizes the following options to control how it operates.
8311 Use and save the results of the tests in FILE instead of
8312 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
8313 debugging `configure'.
8316 Print a summary of the options to `configure', and exit.
8321 Do not print messages saying which checks are being made.
8324 Look for the Bash source code in directory DIR. Usually
8325 `configure' can determine that directory automatically.
8328 Print the version of Autoconf used to generate the `configure'
8331 `configure' also accepts some other, not widely used, boilerplate
8332 options. `configure --help' prints the complete list.
8335 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
8337 10.8 Optional Features
8338 ======================
8340 The Bash `configure' has a number of `--enable-FEATURE' options, where
8341 FEATURE indicates an optional part of Bash. There are also several
8342 `--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
8343 or `purify'. To turn off the default use of a package, use
8344 `--without-PACKAGE'. To configure Bash without a feature that is
8345 enabled by default, use `--disable-FEATURE'.
8347 Here is a complete list of the `--enable-' and `--with-' options
8348 that the Bash `configure' recognizes.
8351 Define if you are using the Andrew File System from Transarc.
8353 `--with-bash-malloc'
8354 Use the Bash version of `malloc' in the directory `lib/malloc'.
8355 This is not the same `malloc' that appears in GNU libc, but an
8356 older version originally derived from the 4.2 BSD `malloc'. This
8357 `malloc' is very fast, but wastes some space on each allocation.
8358 This option is enabled by default. The `NOTES' file contains a
8359 list of systems for which this should be turned off, and
8360 `configure' disables this option automatically for a number of
8364 Use the curses library instead of the termcap library. This should
8365 be supplied if your system has an inadequate or incomplete termcap
8369 A synonym for `--with-bash-malloc'.
8371 `--with-installed-readline[=PREFIX]'
8372 Define this to make Bash link with a locally-installed version of
8373 Readline rather than the version in `lib/readline'. This works
8374 only with Readline 5.0 and later versions. If PREFIX is `yes' or
8375 not supplied, `configure' uses the values of the make variables
8376 `includedir' and `libdir', which are subdirectories of `prefix' by
8377 default, to find the installed version of Readline if it is not in
8378 the standard system include and library directories. If PREFIX is
8379 `no', Bash links with the version in `lib/readline'. If PREFIX is
8380 set to any other value, `configure' treats it as a directory
8381 pathname and looks for the installed version of Readline in
8382 subdirectories of that directory (include files in
8383 PREFIX/`include' and the library in PREFIX/`lib').
8386 Define this to use the Purify memory allocation checker from
8389 `--enable-minimal-config'
8390 This produces a shell with minimal features, close to the
8391 historical Bourne shell.
8393 There are several `--enable-' options that alter how Bash is
8394 compiled and linked, rather than changing run-time features.
8396 `--enable-largefile'
8397 Enable support for large files
8398 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
8399 the operating system requires special compiler options to build
8400 programs which can access large files. This is enabled by
8401 default, if the operating system provides large file support.
8403 `--enable-profiling'
8404 This builds a Bash binary that produces profiling information to be
8405 processed by `gprof' each time it is executed.
8407 `--enable-static-link'
8408 This causes Bash to be linked statically, if `gcc' is being used.
8409 This could be used to build a version to use as root's shell.
8411 The `minimal-config' option can be used to disable all of the
8412 following options, but it is processed first, so individual options may
8413 be enabled using `enable-FEATURE'.
8415 All of the following options except for `disabled-builtins' and
8416 `xpg-echo-default' are enabled by default, unless the operating system
8417 does not provide the necessary support.
8420 Allow alias expansion and include the `alias' and `unalias'
8421 builtins (*note Aliases::).
8423 `--enable-arith-for-command'
8424 Include support for the alternate form of the `for' command that
8425 behaves like the C language `for' statement (*note Looping
8428 `--enable-array-variables'
8429 Include support for one-dimensional array shell variables (*note
8432 `--enable-bang-history'
8433 Include support for `csh'-like history substitution (*note History
8436 `--enable-brace-expansion'
8437 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
8438 See *note Brace Expansion::, for a complete description.
8440 `--enable-casemod-attributes'
8441 Include support for case-modifying attributes in the `declare'
8442 builtin and assignment statements. Variables with the UPPERCASE
8443 attribute, for example, will have their values converted to
8444 uppercase upon assignment.
8446 `--enable-casemod-expansion'
8447 Include support for case-modifying word expansions.
8449 `--enable-command-timing'
8450 Include support for recognizing `time' as a reserved word and for
8451 displaying timing statistics for the pipeline following `time'
8452 (*note Pipelines::). This allows pipelines as well as shell
8453 builtins and functions to be timed.
8455 `--enable-cond-command'
8456 Include support for the `[[' conditional command. (*note
8457 Conditional Constructs::).
8459 `--enable-cond-regexp'
8460 Include support for matching POSIX regular expressions using the
8461 `=~' binary operator in the `[[' conditional command. (*note
8462 Conditional Constructs::).
8464 `--enable-coprocesses'
8465 Include support for coprocesses and the `coproc' reserved word
8466 (*note Pipelines::).
8469 Include support for the bash debugger (distributed separately).
8471 `--enable-directory-stack'
8472 Include support for a `csh'-like directory stack and the `pushd',
8473 `popd', and `dirs' builtins (*note The Directory Stack::).
8475 `--enable-disabled-builtins'
8476 Allow builtin commands to be invoked via `builtin xxx' even after
8477 `xxx' has been disabled using `enable -n xxx'. See *note Bash
8478 Builtins::, for details of the `builtin' and `enable' builtin
8481 `--enable-dparen-arithmetic'
8482 Include support for the `((...))' command (*note Conditional
8485 `--enable-extended-glob'
8486 Include support for the extended pattern matching features
8487 described above under *note Pattern Matching::.
8489 `--enable-help-builtin'
8490 Include the `help' builtin, which displays help on shell builtins
8491 and variables (*note Bash Builtins::).
8494 Include command history and the `fc' and `history' builtin
8495 commands (*note Bash History Facilities::).
8497 `--enable-job-control'
8498 This enables the job control features (*note Job Control::), if
8499 the operating system supports them.
8501 `--enable-multibyte'
8502 This enables support for multibyte characters if the operating
8503 system provides the necessary support.
8505 `--enable-net-redirections'
8506 This enables the special handling of filenames of the form
8507 `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
8508 redirections (*note Redirections::).
8510 `--enable-process-substitution'
8511 This enables process substitution (*note Process Substitution::) if
8512 the operating system provides the necessary support.
8515 Enable the programmable completion facilities (*note Programmable
8516 Completion::). If Readline is not enabled, this option has no
8519 `--enable-prompt-string-decoding'
8520 Turn on the interpretation of a number of backslash-escaped
8521 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
8522 strings. See *note Printing a Prompt::, for a complete list of
8523 prompt string escape sequences.
8526 Include support for command-line editing and history with the Bash
8527 version of the Readline library (*note Command Line Editing::).
8529 `--enable-restricted'
8530 Include support for a "restricted shell". If this is enabled,
8531 Bash, when called as `rbash', enters a restricted mode. See *note
8532 The Restricted Shell::, for a description of restricted mode.
8535 Include the `select' builtin, which allows the generation of simple
8536 menus (*note Conditional Constructs::).
8538 `--enable-separate-helpfiles'
8539 Use external files for the documentation displayed by the `help'
8540 builtin instead of storing the text internally.
8542 `--enable-single-help-strings'
8543 Store the text displayed by the `help' builtin as a single string
8544 for each help topic. This aids in translating the text to
8545 different languages. You may need to disable this if your
8546 compiler cannot handle very long string literals.
8548 `--enable-strict-posix-default'
8549 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
8551 `--enable-usg-echo-default'
8552 A synonym for `--enable-xpg-echo-default'.
8554 `--enable-xpg-echo-default'
8555 Make the `echo' builtin expand backslash-escaped characters by
8556 default, without requiring the `-e' option. This sets the default
8557 value of the `xpg_echo' shell option to `on', which makes the Bash
8558 `echo' behave more like the version specified in the Single Unix
8559 Specification, version 3. *Note Bash Builtins::, for a
8560 description of the escape sequences that `echo' recognizes.
8563 The file `config-top.h' contains C Preprocessor `#define' statements
8564 for options which are not settable from `configure'. Some of these are
8565 not meant to be changed; beware of the consequences if you do. Read
8566 the comments associated with each definition for more information about
8570 File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
8572 Appendix A Reporting Bugs
8573 *************************
8575 Please report all bugs you find in Bash. But first, you should make
8576 sure that it really is a bug, and that it appears in the latest version
8577 of Bash. The latest version of Bash is always available for FTP from
8578 `ftp://ftp.gnu.org/pub/bash/'.
8580 Once you have determined that a bug actually exists, use the
8581 `bashbug' command to submit a bug report. If you have a fix, you are
8582 encouraged to mail that as well! Suggestions and `philosophical' bug
8583 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
8584 newsgroup `gnu.bash.bug'.
8586 All bug reports should include:
8587 * The version number of Bash.
8589 * The hardware and operating system.
8591 * The compiler used to compile Bash.
8593 * A description of the bug behaviour.
8595 * A short script or `recipe' which exercises the bug and may be used
8598 `bashbug' inserts the first three items automatically into the template
8599 it provides for filing a bug report.
8601 Please send all reports concerning this manual to <chet@po.CWRU.Edu>.
8604 File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
8606 Appendix B Major Differences From The Bourne Shell
8607 **************************************************
8609 Bash implements essentially the same grammar, parameter and variable
8610 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
8611 POSIX standard as the specification of how these features are to be
8612 implemented. There are some differences between the traditional Bourne
8613 shell and Bash; this section quickly details the differences of
8614 significance. A number of these differences are explained in greater
8615 depth in previous sections. This section uses the version of `sh'
8616 included in SVR4.2 (the last version of the historical Bourne shell) as
8617 the baseline reference.
8619 * Bash is POSIX-conformant, even where the POSIX specification
8620 differs from traditional `sh' behavior (*note Bash POSIX Mode::).
8622 * Bash has multi-character invocation options (*note Invoking
8625 * Bash has command-line editing (*note Command Line Editing::) and
8628 * Bash provides a programmable word completion mechanism (*note
8629 Programmable Completion::), and builtin commands `complete',
8630 `compgen', and `compopt', to manipulate it.
8632 * Bash has command history (*note Bash History Facilities::) and the
8633 `history' and `fc' builtins to manipulate it. The Bash history
8634 list maintains timestamp information and uses the value of the
8635 `HISTTIMEFORMAT' variable to display it.
8637 * Bash implements `csh'-like history expansion (*note History
8640 * Bash has one-dimensional array variables (*note Arrays::), and the
8641 appropriate variable expansions and assignment syntax to use them.
8642 Several of the Bash builtins take options to act on arrays. Bash
8643 provides a number of built-in array variables.
8645 * The `$'...'' quoting syntax, which expands ANSI-C
8646 backslash-escaped characters in the text between the single quotes,
8647 is supported (*note ANSI-C Quoting::).
8649 * Bash supports the `$"..."' quoting syntax to do locale-specific
8650 translation of the characters between the double quotes. The
8651 `-D', `--dump-strings', and `--dump-po-strings' invocation options
8652 list the translatable strings found in a script (*note Locale
8655 * Bash implements the `!' keyword to negate the return value of a
8656 pipeline (*note Pipelines::). Very useful when an `if' statement
8657 needs to act only if a test fails. The Bash `-o pipefail' option
8658 to `set' will cause a pipeline to return a failure status if any
8661 * Bash has the `time' reserved word and command timing (*note
8662 Pipelines::). The display of the timing statistics may be
8663 controlled with the `TIMEFORMAT' variable.
8665 * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
8666 for command, similar to the C language (*note Looping
8669 * Bash includes the `select' compound command, which allows the
8670 generation of simple menus (*note Conditional Constructs::).
8672 * Bash includes the `[[' compound command, which makes conditional
8673 testing part of the shell grammar (*note Conditional
8674 Constructs::), including optional regular expression matching.
8676 * Bash provides optional case-insensitive matching for the `case' and
8679 * Bash includes brace expansion (*note Brace Expansion::) and tilde
8680 expansion (*note Tilde Expansion::).
8682 * Bash implements command aliases and the `alias' and `unalias'
8683 builtins (*note Aliases::).
8685 * Bash provides shell arithmetic, the `((' compound command (*note
8686 Conditional Constructs::), and arithmetic expansion (*note Shell
8689 * Variables present in the shell's initial environment are
8690 automatically exported to child processes. The Bourne shell does
8691 not normally do this unless the variables are explicitly marked
8692 using the `export' command.
8694 * Bash supports the `+=' assignment operator, which appends to the
8695 value of the variable named on the left hand side.
8697 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
8698 expansions to remove leading or trailing substrings from variable
8699 values (*note Shell Parameter Expansion::).
8701 * The expansion `${#xx}', which returns the length of `${xx}', is
8702 supported (*note Shell Parameter Expansion::).
8704 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
8705 substring of `var''s value of length LENGTH, beginning at OFFSET,
8706 is present (*note Shell Parameter Expansion::).
8708 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
8709 PATTERN and replaces it with REPLACEMENT in the value of `var', is
8710 available (*note Shell Parameter Expansion::).
8712 * The expansion `${!PREFIX}*' expansion, which expands to the names
8713 of all shell variables whose names begin with PREFIX, is available
8714 (*note Shell Parameter Expansion::).
8716 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
8717 Parameter Expansion::).
8719 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
8721 * The POSIX `$()' form of command substitution is implemented (*note
8722 Command Substitution::), and preferred to the Bourne shell's ```'
8723 (which is also implemented for backwards compatibility).
8725 * Bash has process substitution (*note Process Substitution::).
8727 * Bash automatically assigns variables that provide information
8728 about the current user (`UID', `EUID', and `GROUPS'), the current
8729 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
8730 instance of Bash that is running (`BASH', `BASH_VERSION', and
8731 `BASH_VERSINFO'). *Note Bash Variables::, for details.
8733 * The `IFS' variable is used to split only the results of expansion,
8734 not all words (*note Word Splitting::). This closes a
8735 longstanding shell security hole.
8737 * Bash implements the full set of POSIX filename expansion operators,
8738 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
8739 SYMBOLS (*note Filename Expansion::).
8741 * Bash implements extended pattern matching features when the
8742 `extglob' shell option is enabled (*note Pattern Matching::).
8744 * It is possible to have a variable and a function with the same
8745 name; `sh' does not separate the two name spaces.
8747 * Bash functions are permitted to have local variables using the
8748 `local' builtin, and thus useful recursive functions may be written
8749 (*note Bash Builtins::).
8751 * Variable assignments preceding commands affect only that command,
8752 even builtins and functions (*note Environment::). In `sh', all
8753 variable assignments preceding commands are global unless the
8754 command is executed from the file system.
8756 * Bash performs filename expansion on filenames specified as operands
8757 to input and output redirection operators (*note Redirections::).
8759 * Bash contains the `<>' redirection operator, allowing a file to be
8760 opened for both reading and writing, and the `&>' redirection
8761 operator, for directing standard output and standard error to the
8762 same file (*note Redirections::).
8764 * Bash includes the `<<<' redirection operator, allowing a string to
8765 be used as the standard input to a command.
8767 * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection
8768 operators, which move one file descriptor to another.
8770 * Bash treats a number of filenames specially when they are used in
8771 redirection operators (*note Redirections::).
8773 * Bash can open network connections to arbitrary machines and
8774 services with the redirection operators (*note Redirections::).
8776 * The `noclobber' option is available to avoid overwriting existing
8777 files with output redirection (*note The Set Builtin::). The `>|'
8778 redirection operator may be used to override `noclobber'.
8780 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::)
8781 each take `-L' and `-P' options to switch between logical and
8784 * Bash allows a function to override a builtin with the same name,
8785 and provides access to that builtin's functionality within the
8786 function via the `builtin' and `command' builtins (*note Bash
8789 * The `command' builtin allows selective disabling of functions when
8790 command lookup is performed (*note Bash Builtins::).
8792 * Individual builtins may be enabled or disabled using the `enable'
8793 builtin (*note Bash Builtins::).
8795 * The Bash `exec' builtin takes additional options that allow users
8796 to control the contents of the environment passed to the executed
8797 command, and what the zeroth argument to the command is to be
8798 (*note Bourne Shell Builtins::).
8800 * Shell functions may be exported to children via the environment
8801 using `export -f' (*note Shell Functions::).
8803 * The Bash `export', `readonly', and `declare' builtins can take a
8804 `-f' option to act on shell functions, a `-p' option to display
8805 variables with various attributes set in a format that can be used
8806 as shell input, a `-n' option to remove various variable
8807 attributes, and `name=value' arguments to set variable attributes
8808 and values simultaneously.
8810 * The Bash `hash' builtin allows a name to be associated with an
8811 arbitrary filename, even when that filename cannot be found by
8812 searching the `$PATH', using `hash -p' (*note Bourne Shell
8815 * Bash includes a `help' builtin for quick reference to shell
8816 facilities (*note Bash Builtins::).
8818 * The `printf' builtin is available to display formatted output
8819 (*note Bash Builtins::).
8821 * The Bash `read' builtin (*note Bash Builtins::) will read a line
8822 ending in `\' with the `-r' option, and will use the `REPLY'
8823 variable as a default if no non-option arguments are supplied.
8824 The Bash `read' builtin also accepts a prompt string with the `-p'
8825 option and will use Readline to obtain the line when given the
8826 `-e' option. The `read' builtin also has additional options to
8827 control input: the `-s' option will turn off echoing of input
8828 characters as they are read, the `-t' option will allow `read' to
8829 time out if input does not arrive within a specified number of
8830 seconds, the `-n' option will allow reading only a specified
8831 number of characters rather than a full line, and the `-d' option
8832 will read until a particular character rather than newline.
8834 * The `return' builtin may be used to abort execution of scripts
8835 executed with the `.' or `source' builtins (*note Bourne Shell
8838 * Bash includes the `shopt' builtin, for finer control of shell
8839 optional capabilities (*note The Shopt Builtin::), and allows
8840 these options to be set and unset at shell invocation (*note
8843 * Bash has much more optional behavior controllable with the `set'
8844 builtin (*note The Set Builtin::).
8846 * The `-x' (`xtrace') option displays commands other than simple
8847 commands when performing an execution trace (*note The Set
8850 * The `test' builtin (*note Bourne Shell Builtins::) is slightly
8851 different, as it implements the POSIX algorithm, which specifies
8852 the behavior based on the number of arguments.
8854 * Bash includes the `caller' builtin, which displays the context of
8855 any active subroutine call (a shell function or a script executed
8856 with the `.' or `source' builtins). This supports the bash
8859 * The `trap' builtin (*note Bourne Shell Builtins::) allows a
8860 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
8861 specified with a `DEBUG' trap are executed before every simple
8862 command, `for' command, `case' command, `select' command, every
8863 arithmetic `for' command, and before the first command executes in
8864 a shell function. The `DEBUG' trap is not inherited by shell
8865 functions unless the function has been given the `trace' attribute
8866 or the `functrace' option has been enabled using the `shopt'
8867 builtin. The `extdebug' shell option has additional effects on the
8870 The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR'
8871 pseudo-signal specification, similar to `EXIT' and `DEBUG'.
8872 Commands specified with an `ERR' trap are executed after a simple
8873 command fails, with a few exceptions. The `ERR' trap is not
8874 inherited by shell functions unless the `-o errtrace' option to
8875 the `set' builtin is enabled.
8877 The `trap' builtin (*note Bourne Shell Builtins::) allows a
8878 `RETURN' pseudo-signal specification, similar to `EXIT' and
8879 `DEBUG'. Commands specified with an `RETURN' trap are executed
8880 before execution resumes after a shell function or a shell script
8881 executed with `.' or `source' returns. The `RETURN' trap is not
8882 inherited by shell functions unless the function has been given
8883 the `trace' attribute or the `functrace' option has been enabled
8884 using the `shopt' builtin.
8886 * The Bash `type' builtin is more extensive and gives more
8887 information about the names it finds (*note Bash Builtins::).
8889 * The Bash `umask' builtin permits a `-p' option to cause the output
8890 to be displayed in the form of a `umask' command that may be
8891 reused as input (*note Bourne Shell Builtins::).
8893 * Bash implements a `csh'-like directory stack, and provides the
8894 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
8895 Directory Stack::). Bash also makes the directory stack visible
8896 as the value of the `DIRSTACK' shell variable.
8898 * Bash interprets special backslash-escaped characters in the prompt
8899 strings when interactive (*note Printing a Prompt::).
8901 * The Bash restricted mode is more useful (*note The Restricted
8902 Shell::); the SVR4.2 shell restricted mode is too limited.
8904 * The `disown' builtin can remove a job from the internal shell job
8905 table (*note Job Control Builtins::) or suppress the sending of
8906 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
8908 * Bash includes a number of features to support a separate debugger
8911 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
8912 `priv') not present in Bash.
8914 * Bash does not have the `stop' or `newgrp' builtins.
8916 * Bash does not use the `SHACCT' variable or perform shell
8919 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
8922 More features unique to Bash may be found in *note Bash Features::.
8924 B.1 Implementation Differences From The SVR4.2 Shell
8925 ====================================================
8927 Since Bash is a completely new implementation, it does not suffer from
8928 many of the limitations of the SVR4.2 shell. For instance:
8930 * Bash does not fork a subshell when redirecting into or out of a
8931 shell control structure such as an `if' or `while' statement.
8933 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
8934 silently insert a needed closing quote at `EOF' under certain
8935 circumstances. This can be the cause of some hard-to-find errors.
8937 * The SVR4.2 shell uses a baroque memory management scheme based on
8938 trapping `SIGSEGV'. If the shell is started from a process with
8939 `SIGSEGV' blocked (e.g., by using the `system()' C library
8940 function call), it misbehaves badly.
8942 * In a questionable attempt at security, the SVR4.2 shell, when
8943 invoked without the `-p' option, will alter its real and effective
8944 UID and GID if they are less than some magic threshold value,
8945 commonly 100. This can lead to unexpected results.
8947 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
8948 `SIGALRM', or `SIGCHLD'.
8950 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
8951 `PS1', or `PS2' variables to be unset.
8953 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
8955 * Bash allows multiple option arguments when it is invoked (`-x -v');
8956 the SVR4.2 shell allows only one option argument (`-xv'). In
8957 fact, some versions of the shell dump core if the second argument
8960 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
8961 script only if one of the POSIX special builtins fails, and only
8962 for certain failures, as enumerated in the POSIX standard.
8964 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
8965 turns on job control).
8968 File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
8970 Appendix C GNU Free Documentation License
8971 *****************************************
8973 Version 1.2, November 2002
8975 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc.
8976 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
8978 Everyone is permitted to copy and distribute verbatim copies
8979 of this license document, but changing it is not allowed.
8983 The purpose of this License is to make a manual, textbook, or other
8984 functional and useful document "free" in the sense of freedom: to
8985 assure everyone the effective freedom to copy and redistribute it,
8986 with or without modifying it, either commercially or
8987 noncommercially. Secondarily, this License preserves for the
8988 author and publisher a way to get credit for their work, while not
8989 being considered responsible for modifications made by others.
8991 This License is a kind of "copyleft", which means that derivative
8992 works of the document must themselves be free in the same sense.
8993 It complements the GNU General Public License, which is a copyleft
8994 license designed for free software.
8996 We have designed this License in order to use it for manuals for
8997 free software, because free software needs free documentation: a
8998 free program should come with manuals providing the same freedoms
8999 that the software does. But this License is not limited to
9000 software manuals; it can be used for any textual work, regardless
9001 of subject matter or whether it is published as a printed book.
9002 We recommend this License principally for works whose purpose is
9003 instruction or reference.
9005 1. APPLICABILITY AND DEFINITIONS
9007 This License applies to any manual or other work, in any medium,
9008 that contains a notice placed by the copyright holder saying it
9009 can be distributed under the terms of this License. Such a notice
9010 grants a world-wide, royalty-free license, unlimited in duration,
9011 to use that work under the conditions stated herein. The
9012 "Document", below, refers to any such manual or work. Any member
9013 of the public is a licensee, and is addressed as "you". You
9014 accept the license if you copy, modify or distribute the work in a
9015 way requiring permission under copyright law.
9017 A "Modified Version" of the Document means any work containing the
9018 Document or a portion of it, either copied verbatim, or with
9019 modifications and/or translated into another language.
9021 A "Secondary Section" is a named appendix or a front-matter section
9022 of the Document that deals exclusively with the relationship of the
9023 publishers or authors of the Document to the Document's overall
9024 subject (or to related matters) and contains nothing that could
9025 fall directly within that overall subject. (Thus, if the Document
9026 is in part a textbook of mathematics, a Secondary Section may not
9027 explain any mathematics.) The relationship could be a matter of
9028 historical connection with the subject or with related matters, or
9029 of legal, commercial, philosophical, ethical or political position
9032 The "Invariant Sections" are certain Secondary Sections whose
9033 titles are designated, as being those of Invariant Sections, in
9034 the notice that says that the Document is released under this
9035 License. If a section does not fit the above definition of
9036 Secondary then it is not allowed to be designated as Invariant.
9037 The Document may contain zero Invariant Sections. If the Document
9038 does not identify any Invariant Sections then there are none.
9040 The "Cover Texts" are certain short passages of text that are
9041 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
9042 that says that the Document is released under this License. A
9043 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
9044 be at most 25 words.
9046 A "Transparent" copy of the Document means a machine-readable copy,
9047 represented in a format whose specification is available to the
9048 general public, that is suitable for revising the document
9049 straightforwardly with generic text editors or (for images
9050 composed of pixels) generic paint programs or (for drawings) some
9051 widely available drawing editor, and that is suitable for input to
9052 text formatters or for automatic translation to a variety of
9053 formats suitable for input to text formatters. A copy made in an
9054 otherwise Transparent file format whose markup, or absence of
9055 markup, has been arranged to thwart or discourage subsequent
9056 modification by readers is not Transparent. An image format is
9057 not Transparent if used for any substantial amount of text. A
9058 copy that is not "Transparent" is called "Opaque".
9060 Examples of suitable formats for Transparent copies include plain
9061 ASCII without markup, Texinfo input format, LaTeX input format,
9062 SGML or XML using a publicly available DTD, and
9063 standard-conforming simple HTML, PostScript or PDF designed for
9064 human modification. Examples of transparent image formats include
9065 PNG, XCF and JPG. Opaque formats include proprietary formats that
9066 can be read and edited only by proprietary word processors, SGML or
9067 XML for which the DTD and/or processing tools are not generally
9068 available, and the machine-generated HTML, PostScript or PDF
9069 produced by some word processors for output purposes only.
9071 The "Title Page" means, for a printed book, the title page itself,
9072 plus such following pages as are needed to hold, legibly, the
9073 material this License requires to appear in the title page. For
9074 works in formats which do not have any title page as such, "Title
9075 Page" means the text near the most prominent appearance of the
9076 work's title, preceding the beginning of the body of the text.
9078 A section "Entitled XYZ" means a named subunit of the Document
9079 whose title either is precisely XYZ or contains XYZ in parentheses
9080 following text that translates XYZ in another language. (Here XYZ
9081 stands for a specific section name mentioned below, such as
9082 "Acknowledgements", "Dedications", "Endorsements", or "History".)
9083 To "Preserve the Title" of such a section when you modify the
9084 Document means that it remains a section "Entitled XYZ" according
9087 The Document may include Warranty Disclaimers next to the notice
9088 which states that this License applies to the Document. These
9089 Warranty Disclaimers are considered to be included by reference in
9090 this License, but only as regards disclaiming warranties: any other
9091 implication that these Warranty Disclaimers may have is void and
9092 has no effect on the meaning of this License.
9096 You may copy and distribute the Document in any medium, either
9097 commercially or noncommercially, provided that this License, the
9098 copyright notices, and the license notice saying this License
9099 applies to the Document are reproduced in all copies, and that you
9100 add no other conditions whatsoever to those of this License. You
9101 may not use technical measures to obstruct or control the reading
9102 or further copying of the copies you make or distribute. However,
9103 you may accept compensation in exchange for copies. If you
9104 distribute a large enough number of copies you must also follow
9105 the conditions in section 3.
9107 You may also lend copies, under the same conditions stated above,
9108 and you may publicly display copies.
9110 3. COPYING IN QUANTITY
9112 If you publish printed copies (or copies in media that commonly
9113 have printed covers) of the Document, numbering more than 100, and
9114 the Document's license notice requires Cover Texts, you must
9115 enclose the copies in covers that carry, clearly and legibly, all
9116 these Cover Texts: Front-Cover Texts on the front cover, and
9117 Back-Cover Texts on the back cover. Both covers must also clearly
9118 and legibly identify you as the publisher of these copies. The
9119 front cover must present the full title with all words of the
9120 title equally prominent and visible. You may add other material
9121 on the covers in addition. Copying with changes limited to the
9122 covers, as long as they preserve the title of the Document and
9123 satisfy these conditions, can be treated as verbatim copying in
9126 If the required texts for either cover are too voluminous to fit
9127 legibly, you should put the first ones listed (as many as fit
9128 reasonably) on the actual cover, and continue the rest onto
9131 If you publish or distribute Opaque copies of the Document
9132 numbering more than 100, you must either include a
9133 machine-readable Transparent copy along with each Opaque copy, or
9134 state in or with each Opaque copy a computer-network location from
9135 which the general network-using public has access to download
9136 using public-standard network protocols a complete Transparent
9137 copy of the Document, free of added material. If you use the
9138 latter option, you must take reasonably prudent steps, when you
9139 begin distribution of Opaque copies in quantity, to ensure that
9140 this Transparent copy will remain thus accessible at the stated
9141 location until at least one year after the last time you
9142 distribute an Opaque copy (directly or through your agents or
9143 retailers) of that edition to the public.
9145 It is requested, but not required, that you contact the authors of
9146 the Document well before redistributing any large number of
9147 copies, to give them a chance to provide you with an updated
9148 version of the Document.
9152 You may copy and distribute a Modified Version of the Document
9153 under the conditions of sections 2 and 3 above, provided that you
9154 release the Modified Version under precisely this License, with
9155 the Modified Version filling the role of the Document, thus
9156 licensing distribution and modification of the Modified Version to
9157 whoever possesses a copy of it. In addition, you must do these
9158 things in the Modified Version:
9160 A. Use in the Title Page (and on the covers, if any) a title
9161 distinct from that of the Document, and from those of
9162 previous versions (which should, if there were any, be listed
9163 in the History section of the Document). You may use the
9164 same title as a previous version if the original publisher of
9165 that version gives permission.
9167 B. List on the Title Page, as authors, one or more persons or
9168 entities responsible for authorship of the modifications in
9169 the Modified Version, together with at least five of the
9170 principal authors of the Document (all of its principal
9171 authors, if it has fewer than five), unless they release you
9172 from this requirement.
9174 C. State on the Title page the name of the publisher of the
9175 Modified Version, as the publisher.
9177 D. Preserve all the copyright notices of the Document.
9179 E. Add an appropriate copyright notice for your modifications
9180 adjacent to the other copyright notices.
9182 F. Include, immediately after the copyright notices, a license
9183 notice giving the public permission to use the Modified
9184 Version under the terms of this License, in the form shown in
9187 G. Preserve in that license notice the full lists of Invariant
9188 Sections and required Cover Texts given in the Document's
9191 H. Include an unaltered copy of this License.
9193 I. Preserve the section Entitled "History", Preserve its Title,
9194 and add to it an item stating at least the title, year, new
9195 authors, and publisher of the Modified Version as given on
9196 the Title Page. If there is no section Entitled "History" in
9197 the Document, create one stating the title, year, authors,
9198 and publisher of the Document as given on its Title Page,
9199 then add an item describing the Modified Version as stated in
9200 the previous sentence.
9202 J. Preserve the network location, if any, given in the Document
9203 for public access to a Transparent copy of the Document, and
9204 likewise the network locations given in the Document for
9205 previous versions it was based on. These may be placed in
9206 the "History" section. You may omit a network location for a
9207 work that was published at least four years before the
9208 Document itself, or if the original publisher of the version
9209 it refers to gives permission.
9211 K. For any section Entitled "Acknowledgements" or "Dedications",
9212 Preserve the Title of the section, and preserve in the
9213 section all the substance and tone of each of the contributor
9214 acknowledgements and/or dedications given therein.
9216 L. Preserve all the Invariant Sections of the Document,
9217 unaltered in their text and in their titles. Section numbers
9218 or the equivalent are not considered part of the section
9221 M. Delete any section Entitled "Endorsements". Such a section
9222 may not be included in the Modified Version.
9224 N. Do not retitle any existing section to be Entitled
9225 "Endorsements" or to conflict in title with any Invariant
9228 O. Preserve any Warranty Disclaimers.
9230 If the Modified Version includes new front-matter sections or
9231 appendices that qualify as Secondary Sections and contain no
9232 material copied from the Document, you may at your option
9233 designate some or all of these sections as invariant. To do this,
9234 add their titles to the list of Invariant Sections in the Modified
9235 Version's license notice. These titles must be distinct from any
9236 other section titles.
9238 You may add a section Entitled "Endorsements", provided it contains
9239 nothing but endorsements of your Modified Version by various
9240 parties--for example, statements of peer review or that the text
9241 has been approved by an organization as the authoritative
9242 definition of a standard.
9244 You may add a passage of up to five words as a Front-Cover Text,
9245 and a passage of up to 25 words as a Back-Cover Text, to the end
9246 of the list of Cover Texts in the Modified Version. Only one
9247 passage of Front-Cover Text and one of Back-Cover Text may be
9248 added by (or through arrangements made by) any one entity. If the
9249 Document already includes a cover text for the same cover,
9250 previously added by you or by arrangement made by the same entity
9251 you are acting on behalf of, you may not add another; but you may
9252 replace the old one, on explicit permission from the previous
9253 publisher that added the old one.
9255 The author(s) and publisher(s) of the Document do not by this
9256 License give permission to use their names for publicity for or to
9257 assert or imply endorsement of any Modified Version.
9259 5. COMBINING DOCUMENTS
9261 You may combine the Document with other documents released under
9262 this License, under the terms defined in section 4 above for
9263 modified versions, provided that you include in the combination
9264 all of the Invariant Sections of all of the original documents,
9265 unmodified, and list them all as Invariant Sections of your
9266 combined work in its license notice, and that you preserve all
9267 their Warranty Disclaimers.
9269 The combined work need only contain one copy of this License, and
9270 multiple identical Invariant Sections may be replaced with a single
9271 copy. If there are multiple Invariant Sections with the same name
9272 but different contents, make the title of each such section unique
9273 by adding at the end of it, in parentheses, the name of the
9274 original author or publisher of that section if known, or else a
9275 unique number. Make the same adjustment to the section titles in
9276 the list of Invariant Sections in the license notice of the
9279 In the combination, you must combine any sections Entitled
9280 "History" in the various original documents, forming one section
9281 Entitled "History"; likewise combine any sections Entitled
9282 "Acknowledgements", and any sections Entitled "Dedications". You
9283 must delete all sections Entitled "Endorsements."
9285 6. COLLECTIONS OF DOCUMENTS
9287 You may make a collection consisting of the Document and other
9288 documents released under this License, and replace the individual
9289 copies of this License in the various documents with a single copy
9290 that is included in the collection, provided that you follow the
9291 rules of this License for verbatim copying of each of the
9292 documents in all other respects.
9294 You may extract a single document from such a collection, and
9295 distribute it individually under this License, provided you insert
9296 a copy of this License into the extracted document, and follow
9297 this License in all other respects regarding verbatim copying of
9300 7. AGGREGATION WITH INDEPENDENT WORKS
9302 A compilation of the Document or its derivatives with other
9303 separate and independent documents or works, in or on a volume of
9304 a storage or distribution medium, is called an "aggregate" if the
9305 copyright resulting from the compilation is not used to limit the
9306 legal rights of the compilation's users beyond what the individual
9307 works permit. When the Document is included in an aggregate, this
9308 License does not apply to the other works in the aggregate which
9309 are not themselves derivative works of the Document.
9311 If the Cover Text requirement of section 3 is applicable to these
9312 copies of the Document, then if the Document is less than one half
9313 of the entire aggregate, the Document's Cover Texts may be placed
9314 on covers that bracket the Document within the aggregate, or the
9315 electronic equivalent of covers if the Document is in electronic
9316 form. Otherwise they must appear on printed covers that bracket
9317 the whole aggregate.
9321 Translation is considered a kind of modification, so you may
9322 distribute translations of the Document under the terms of section
9323 4. Replacing Invariant Sections with translations requires special
9324 permission from their copyright holders, but you may include
9325 translations of some or all Invariant Sections in addition to the
9326 original versions of these Invariant Sections. You may include a
9327 translation of this License, and all the license notices in the
9328 Document, and any Warranty Disclaimers, provided that you also
9329 include the original English version of this License and the
9330 original versions of those notices and disclaimers. In case of a
9331 disagreement between the translation and the original version of
9332 this License or a notice or disclaimer, the original version will
9335 If a section in the Document is Entitled "Acknowledgements",
9336 "Dedications", or "History", the requirement (section 4) to
9337 Preserve its Title (section 1) will typically require changing the
9342 You may not copy, modify, sublicense, or distribute the Document
9343 except as expressly provided for under this License. Any other
9344 attempt to copy, modify, sublicense or distribute the Document is
9345 void, and will automatically terminate your rights under this
9346 License. However, parties who have received copies, or rights,
9347 from you under this License will not have their licenses
9348 terminated so long as such parties remain in full compliance.
9350 10. FUTURE REVISIONS OF THIS LICENSE
9352 The Free Software Foundation may publish new, revised versions of
9353 the GNU Free Documentation License from time to time. Such new
9354 versions will be similar in spirit to the present version, but may
9355 differ in detail to address new problems or concerns. See
9356 `http://www.gnu.org/copyleft/'.
9358 Each version of the License is given a distinguishing version
9359 number. If the Document specifies that a particular numbered
9360 version of this License "or any later version" applies to it, you
9361 have the option of following the terms and conditions either of
9362 that specified version or of any later version that has been
9363 published (not as a draft) by the Free Software Foundation. If
9364 the Document does not specify a version number of this License,
9365 you may choose any version ever published (not as a draft) by the
9366 Free Software Foundation.
9368 ADDENDUM: How to use this License for your documents
9369 ====================================================
9371 To use this License in a document you have written, include a copy of
9372 the License in the document and put the following copyright and license
9373 notices just after the title page:
9375 Copyright (C) YEAR YOUR NAME.
9376 Permission is granted to copy, distribute and/or modify this document
9377 under the terms of the GNU Free Documentation License, Version 1.2
9378 or any later version published by the Free Software Foundation;
9379 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9380 Texts. A copy of the license is included in the section entitled ``GNU
9381 Free Documentation License''.
9383 If you have Invariant Sections, Front-Cover Texts and Back-Cover
9384 Texts, replace the "with...Texts." line with this:
9386 with the Invariant Sections being LIST THEIR TITLES, with
9387 the Front-Cover Texts being LIST, and with the Back-Cover Texts
9390 If you have Invariant Sections without Cover Texts, or some other
9391 combination of the three, merge those two alternatives to suit the
9394 If your document contains nontrivial examples of program code, we
9395 recommend releasing these examples in parallel under your choice of
9396 free software license, such as the GNU General Public License, to
9397 permit their use in free software.
9400 File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
9407 * Builtin Index:: Index of Bash builtin commands.
9408 * Reserved Word Index:: Index of Bash reserved words.
9409 * Variable Index:: Quick reference helps you find the
9411 * Function Index:: Index of bindable Readline functions.
9412 * Concept Index:: General index for concepts described in
9416 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
9418 D.1 Index of Shell Builtin Commands
9419 ===================================
9424 * .: Bourne Shell Builtins.
9426 * :: Bourne Shell Builtins.
9428 * [: Bourne Shell Builtins.
9430 * alias: Bash Builtins. (line 11)
9431 * bg: Job Control Builtins.
9433 * bind: Bash Builtins. (line 21)
9434 * break: Bourne Shell Builtins.
9436 * builtin: Bash Builtins. (line 98)
9437 * caller: Bash Builtins. (line 106)
9438 * cd: Bourne Shell Builtins.
9440 * command: Bash Builtins. (line 123)
9441 * compgen: Programmable Completion Builtins.
9443 * complete: Programmable Completion Builtins.
9445 * compopt: Programmable Completion Builtins.
9447 * continue: Bourne Shell Builtins.
9449 * declare: Bash Builtins. (line 142)
9450 * dirs: Directory Stack Builtins.
9452 * disown: Job Control Builtins.
9454 * echo: Bash Builtins. (line 221)
9455 * enable: Bash Builtins. (line 273)
9456 * eval: Bourne Shell Builtins.
9458 * exec: Bourne Shell Builtins.
9460 * exit: Bourne Shell Builtins.
9462 * export: Bourne Shell Builtins.
9464 * fc: Bash History Builtins.
9466 * fg: Job Control Builtins.
9468 * getopts: Bourne Shell Builtins.
9470 * hash: Bourne Shell Builtins.
9472 * help: Bash Builtins. (line 301)
9473 * history: Bash History Builtins.
9475 * jobs: Job Control Builtins.
9477 * kill: Job Control Builtins.
9479 * let: Bash Builtins. (line 321)
9480 * local: Bash Builtins. (line 328)
9481 * logout: Bash Builtins. (line 338)
9482 * mapfile: Bash Builtins. (line 342)
9483 * popd: Directory Stack Builtins.
9485 * printf: Bash Builtins. (line 387)
9486 * pushd: Directory Stack Builtins.
9488 * pwd: Bourne Shell Builtins.
9490 * read: Bash Builtins. (line 412)
9491 * readarray: Bash Builtins. (line 484)
9492 * readonly: Bourne Shell Builtins.
9494 * return: Bourne Shell Builtins.
9496 * set: The Set Builtin. (line 11)
9497 * shift: Bourne Shell Builtins.
9499 * shopt: The Shopt Builtin. (line 9)
9500 * source: Bash Builtins. (line 492)
9501 * suspend: Job Control Builtins.
9503 * test: Bourne Shell Builtins.
9505 * times: Bourne Shell Builtins.
9507 * trap: Bourne Shell Builtins.
9509 * type: Bash Builtins. (line 496)
9510 * typeset: Bash Builtins. (line 527)
9511 * ulimit: Bash Builtins. (line 533)
9512 * umask: Bourne Shell Builtins.
9514 * unalias: Bash Builtins. (line 619)
9515 * unset: Bourne Shell Builtins.
9517 * wait: Job Control Builtins.
9521 File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
9523 D.2 Index of Shell Reserved Words
9524 =================================
9529 * !: Pipelines. (line 9)
9530 * [[: Conditional Constructs.
9532 * ]]: Conditional Constructs.
9534 * case: Conditional Constructs.
9536 * do: Looping Constructs. (line 12)
9537 * done: Looping Constructs. (line 12)
9538 * elif: Conditional Constructs.
9540 * else: Conditional Constructs.
9542 * esac: Conditional Constructs.
9544 * fi: Conditional Constructs.
9546 * for: Looping Constructs. (line 29)
9547 * function: Shell Functions. (line 13)
9548 * if: Conditional Constructs.
9550 * in: Conditional Constructs.
9552 * select: Conditional Constructs.
9554 * then: Conditional Constructs.
9556 * time: Pipelines. (line 9)
9557 * until: Looping Constructs. (line 12)
9558 * while: Looping Constructs. (line 20)
9559 * {: Command Grouping. (line 21)
9560 * }: Command Grouping. (line 21)
9563 File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
9565 D.3 Parameter and Variable Index
9566 ================================
9571 * !: Special Parameters. (line 46)
9572 * #: Special Parameters. (line 30)
9573 * $: Special Parameters. (line 42)
9574 * *: Special Parameters. (line 9)
9575 * -: Special Parameters. (line 37)
9576 * 0: Special Parameters. (line 50)
9577 * ?: Special Parameters. (line 33)
9578 * @: Special Parameters. (line 19)
9579 * _: Special Parameters. (line 59)
9580 * auto_resume: Job Control Variables.
9582 * BASH: Bash Variables. (line 13)
9583 * BASH_ALIASES: Bash Variables. (line 21)
9584 * BASH_ARGC: Bash Variables. (line 28)
9585 * BASH_ARGV: Bash Variables. (line 38)
9586 * BASH_CMDS: Bash Variables. (line 48)
9587 * BASH_COMMAND: Bash Variables. (line 55)
9588 * BASH_ENV: Bash Variables. (line 60)
9589 * BASH_EXECUTION_STRING: Bash Variables. (line 66)
9590 * BASH_LINENO: Bash Variables. (line 69)
9591 * BASH_REMATCH: Bash Variables. (line 78)
9592 * BASH_SOURCE: Bash Variables. (line 86)
9593 * BASH_SUBSHELL: Bash Variables. (line 90)
9594 * BASH_VERSINFO: Bash Variables. (line 94)
9595 * BASH_VERSION: Bash Variables. (line 118)
9596 * BASHPID: Bash Variables. (line 16)
9597 * bell-style: Readline Init File Syntax.
9599 * bind-tty-special-chars: Readline Init File Syntax.
9601 * CDPATH: Bourne Shell Variables.
9603 * COLUMNS: Bash Variables. (line 121)
9604 * comment-begin: Readline Init File Syntax.
9606 * COMP_CWORD: Bash Variables. (line 126)
9607 * COMP_KEY: Bash Variables. (line 155)
9608 * COMP_LINE: Bash Variables. (line 132)
9609 * COMP_POINT: Bash Variables. (line 137)
9610 * COMP_TYPE: Bash Variables. (line 145)
9611 * COMP_WORDBREAKS: Bash Variables. (line 159)
9612 * COMP_WORDS: Bash Variables. (line 165)
9613 * completion-prefix-display-length: Readline Init File Syntax.
9615 * completion-query-items: Readline Init File Syntax.
9617 * COMPREPLY: Bash Variables. (line 172)
9618 * convert-meta: Readline Init File Syntax.
9620 * DIRSTACK: Bash Variables. (line 177)
9621 * disable-completion: Readline Init File Syntax.
9623 * editing-mode: Readline Init File Syntax.
9625 * EMACS: Bash Variables. (line 187)
9626 * enable-keypad: Readline Init File Syntax.
9628 * EUID: Bash Variables. (line 192)
9629 * expand-tilde: Readline Init File Syntax.
9631 * FCEDIT: Bash Variables. (line 196)
9632 * FIGNORE: Bash Variables. (line 200)
9633 * FUNCNAME: Bash Variables. (line 206)
9634 * GLOBIGNORE: Bash Variables. (line 215)
9635 * GROUPS: Bash Variables. (line 221)
9636 * histchars: Bash Variables. (line 227)
9637 * HISTCMD: Bash Variables. (line 242)
9638 * HISTCONTROL: Bash Variables. (line 247)
9639 * HISTFILE: Bash Variables. (line 263)
9640 * HISTFILESIZE: Bash Variables. (line 267)
9641 * HISTIGNORE: Bash Variables. (line 275)
9642 * history-preserve-point: Readline Init File Syntax.
9644 * history-size: Readline Init File Syntax.
9646 * HISTSIZE: Bash Variables. (line 294)
9647 * HISTTIMEFORMAT: Bash Variables. (line 298)
9648 * HOME: Bourne Shell Variables.
9650 * horizontal-scroll-mode: Readline Init File Syntax.
9652 * HOSTFILE: Bash Variables. (line 307)
9653 * HOSTNAME: Bash Variables. (line 318)
9654 * HOSTTYPE: Bash Variables. (line 321)
9655 * IFS: Bourne Shell Variables.
9657 * IGNOREEOF: Bash Variables. (line 324)
9658 * input-meta: Readline Init File Syntax.
9660 * INPUTRC: Bash Variables. (line 334)
9661 * isearch-terminators: Readline Init File Syntax.
9663 * keymap: Readline Init File Syntax.
9665 * LANG: Bash Variables. (line 338)
9666 * LC_ALL: Bash Variables. (line 342)
9667 * LC_COLLATE: Bash Variables. (line 346)
9668 * LC_CTYPE: Bash Variables. (line 353)
9669 * LC_MESSAGES <1>: Locale Translation. (line 11)
9670 * LC_MESSAGES: Bash Variables. (line 358)
9671 * LC_NUMERIC: Bash Variables. (line 362)
9672 * LINENO: Bash Variables. (line 366)
9673 * LINES: Bash Variables. (line 370)
9674 * MACHTYPE: Bash Variables. (line 375)
9675 * MAIL: Bourne Shell Variables.
9677 * MAILCHECK: Bash Variables. (line 379)
9678 * MAILPATH: Bourne Shell Variables.
9680 * mark-modified-lines: Readline Init File Syntax.
9682 * mark-symlinked-directories: Readline Init File Syntax.
9684 * match-hidden-files: Readline Init File Syntax.
9686 * meta-flag: Readline Init File Syntax.
9688 * OLDPWD: Bash Variables. (line 387)
9689 * OPTARG: Bourne Shell Variables.
9691 * OPTERR: Bash Variables. (line 390)
9692 * OPTIND: Bourne Shell Variables.
9694 * OSTYPE: Bash Variables. (line 394)
9695 * output-meta: Readline Init File Syntax.
9697 * page-completions: Readline Init File Syntax.
9699 * PATH: Bourne Shell Variables.
9701 * PIPESTATUS: Bash Variables. (line 397)
9702 * POSIXLY_CORRECT: Bash Variables. (line 402)
9703 * PPID: Bash Variables. (line 411)
9704 * PROMPT_COMMAND: Bash Variables. (line 415)
9705 * PROMPT_DIRTRIM: Bash Variables. (line 419)
9706 * PS1: Bourne Shell Variables.
9708 * PS2: Bourne Shell Variables.
9710 * PS3: Bash Variables. (line 425)
9711 * PS4: Bash Variables. (line 430)
9712 * PWD: Bash Variables. (line 436)
9713 * RANDOM: Bash Variables. (line 439)
9714 * REPLY: Bash Variables. (line 444)
9715 * revert-all-at-newline: Readline Init File Syntax.
9717 * SECONDS: Bash Variables. (line 447)
9718 * SHELL: Bash Variables. (line 453)
9719 * SHELLOPTS: Bash Variables. (line 458)
9720 * SHLVL: Bash Variables. (line 467)
9721 * show-all-if-ambiguous: Readline Init File Syntax.
9723 * show-all-if-unmodified: Readline Init File Syntax.
9725 * TEXTDOMAIN: Locale Translation. (line 11)
9726 * TEXTDOMAINDIR: Locale Translation. (line 11)
9727 * TIMEFORMAT: Bash Variables. (line 472)
9728 * TMOUT: Bash Variables. (line 510)
9729 * TMPDIR: Bash Variables. (line 522)
9730 * UID: Bash Variables. (line 526)
9731 * visible-stats: Readline Init File Syntax.
9735 File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
9743 * abort (C-g): Miscellaneous Commands.
9745 * accept-line (Newline or Return): Commands For History. (line 6)
9746 * backward-char (C-b): Commands For Moving. (line 15)
9747 * backward-delete-char (Rubout): Commands For Text. (line 11)
9748 * backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
9749 * backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
9750 * backward-word (M-b): Commands For Moving. (line 22)
9751 * beginning-of-history (M-<): Commands For History. (line 20)
9752 * beginning-of-line (C-a): Commands For Moving. (line 6)
9753 * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
9754 * capitalize-word (M-c): Commands For Text. (line 46)
9755 * character-search (C-]): Miscellaneous Commands.
9757 * character-search-backward (M-C-]): Miscellaneous Commands.
9759 * clear-screen (C-l): Commands For Moving. (line 34)
9760 * complete (<TAB>): Commands For Completion.
9762 * copy-backward-word (): Commands For Killing. (line 58)
9763 * copy-forward-word (): Commands For Killing. (line 63)
9764 * copy-region-as-kill (): Commands For Killing. (line 54)
9765 * delete-char (C-d): Commands For Text. (line 6)
9766 * delete-char-or-list (): Commands For Completion.
9768 * delete-horizontal-space (): Commands For Killing. (line 46)
9769 * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
9770 * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
9772 * downcase-word (M-l): Commands For Text. (line 42)
9773 * dump-functions (): Miscellaneous Commands.
9775 * dump-macros (): Miscellaneous Commands.
9777 * dump-variables (): Miscellaneous Commands.
9779 * end-kbd-macro (C-x )): Keyboard Macros. (line 9)
9780 * end-of-history (M->): Commands For History. (line 23)
9781 * end-of-line (C-e): Commands For Moving. (line 9)
9782 * exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
9784 * forward-backward-delete-char (): Commands For Text. (line 15)
9785 * forward-char (C-f): Commands For Moving. (line 12)
9786 * forward-search-history (C-s): Commands For History. (line 31)
9787 * forward-word (M-f): Commands For Moving. (line 18)
9788 * history-search-backward (): Commands For History. (line 51)
9789 * history-search-forward (): Commands For History. (line 46)
9790 * insert-comment (M-#): Miscellaneous Commands.
9792 * insert-completions (M-*): Commands For Completion.
9794 * kill-line (C-k): Commands For Killing. (line 6)
9795 * kill-region (): Commands For Killing. (line 50)
9796 * kill-whole-line (): Commands For Killing. (line 15)
9797 * kill-word (M-d): Commands For Killing. (line 19)
9798 * menu-complete (): Commands For Completion.
9800 * next-history (C-n): Commands For History. (line 17)
9801 * non-incremental-forward-search-history (M-n): Commands For History.
9803 * non-incremental-reverse-search-history (M-p): Commands For History.
9805 * overwrite-mode (): Commands For Text. (line 50)
9806 * possible-completions (M-?): Commands For Completion.
9808 * prefix-meta (<ESC>): Miscellaneous Commands.
9810 * previous-history (C-p): Commands For History. (line 13)
9811 * quoted-insert (C-q or C-v): Commands For Text. (line 20)
9812 * re-read-init-file (C-x C-r): Miscellaneous Commands.
9814 * redraw-current-line (): Commands For Moving. (line 38)
9815 * reverse-search-history (C-r): Commands For History. (line 27)
9816 * revert-line (M-r): Miscellaneous Commands.
9818 * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
9819 * set-mark (C-@): Miscellaneous Commands.
9821 * start-kbd-macro (C-x (): Keyboard Macros. (line 6)
9822 * transpose-chars (C-t): Commands For Text. (line 27)
9823 * transpose-words (M-t): Commands For Text. (line 33)
9824 * undo (C-_ or C-x C-u): Miscellaneous Commands.
9826 * universal-argument (): Numeric Arguments. (line 10)
9827 * unix-filename-rubout (): Commands For Killing. (line 41)
9828 * unix-line-discard (C-u): Commands For Killing. (line 12)
9829 * unix-word-rubout (C-w): Commands For Killing. (line 37)
9830 * upcase-word (M-u): Commands For Text. (line 38)
9831 * yank (C-y): Commands For Killing. (line 68)
9832 * yank-last-arg (M-. or M-_): Commands For History. (line 65)
9833 * yank-nth-arg (M-C-y): Commands For History. (line 56)
9834 * yank-pop (M-y): Commands For Killing. (line 71)
9837 File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
9845 * alias expansion: Aliases. (line 6)
9846 * arithmetic evaluation: Shell Arithmetic. (line 6)
9847 * arithmetic expansion: Arithmetic Expansion.
9849 * arithmetic, shell: Shell Arithmetic. (line 6)
9850 * arrays: Arrays. (line 6)
9851 * background: Job Control Basics. (line 6)
9852 * Bash configuration: Basic Installation. (line 6)
9853 * Bash installation: Basic Installation. (line 6)
9854 * Bourne shell: Basic Shell Features.
9856 * brace expansion: Brace Expansion. (line 6)
9857 * builtin: Definitions. (line 17)
9858 * command editing: Readline Bare Essentials.
9860 * command execution: Command Search and Execution.
9862 * command expansion: Simple Command Expansion.
9864 * command history: Bash History Facilities.
9866 * command search: Command Search and Execution.
9868 * command substitution: Command Substitution.
9870 * command timing: Pipelines. (line 9)
9871 * commands, compound: Compound Commands. (line 6)
9872 * commands, conditional: Conditional Constructs.
9874 * commands, grouping: Command Grouping. (line 6)
9875 * commands, lists: Lists. (line 6)
9876 * commands, looping: Looping Constructs. (line 6)
9877 * commands, pipelines: Pipelines. (line 6)
9878 * commands, shell: Shell Commands. (line 6)
9879 * commands, simple: Simple Commands. (line 6)
9880 * comments, shell: Comments. (line 6)
9881 * completion builtins: Programmable Completion Builtins.
9883 * configuration: Basic Installation. (line 6)
9884 * control operator: Definitions. (line 21)
9885 * coprocess: Coprocesses. (line 6)
9886 * directory stack: The Directory Stack. (line 6)
9887 * editing command lines: Readline Bare Essentials.
9889 * environment: Environment. (line 6)
9890 * evaluation, arithmetic: Shell Arithmetic. (line 6)
9891 * event designators: Event Designators. (line 6)
9892 * execution environment: Command Execution Environment.
9894 * exit status <1>: Exit Status. (line 6)
9895 * exit status: Definitions. (line 26)
9896 * expansion: Shell Expansions. (line 6)
9897 * expansion, arithmetic: Arithmetic Expansion.
9899 * expansion, brace: Brace Expansion. (line 6)
9900 * expansion, filename: Filename Expansion. (line 9)
9901 * expansion, parameter: Shell Parameter Expansion.
9903 * expansion, pathname: Filename Expansion. (line 9)
9904 * expansion, tilde: Tilde Expansion. (line 6)
9905 * expressions, arithmetic: Shell Arithmetic. (line 6)
9906 * expressions, conditional: Bash Conditional Expressions.
9908 * field: Definitions. (line 30)
9909 * filename: Definitions. (line 35)
9910 * filename expansion: Filename Expansion. (line 9)
9911 * foreground: Job Control Basics. (line 6)
9912 * functions, shell: Shell Functions. (line 6)
9913 * history builtins: Bash History Builtins.
9915 * history events: Event Designators. (line 7)
9916 * history expansion: History Interaction. (line 6)
9917 * history list: Bash History Facilities.
9919 * History, how to use: Programmable Completion Builtins.
9921 * identifier: Definitions. (line 51)
9922 * initialization file, readline: Readline Init File. (line 6)
9923 * installation: Basic Installation. (line 6)
9924 * interaction, readline: Readline Interaction.
9926 * interactive shell <1>: Interactive Shells. (line 6)
9927 * interactive shell: Invoking Bash. (line 127)
9928 * internationalization: Locale Translation. (line 6)
9929 * job: Definitions. (line 38)
9930 * job control <1>: Job Control Basics. (line 6)
9931 * job control: Definitions. (line 42)
9932 * kill ring: Readline Killing Commands.
9934 * killing text: Readline Killing Commands.
9936 * localization: Locale Translation. (line 6)
9937 * login shell: Invoking Bash. (line 124)
9938 * matching, pattern: Pattern Matching. (line 6)
9939 * metacharacter: Definitions. (line 46)
9940 * name: Definitions. (line 51)
9941 * native languages: Locale Translation. (line 6)
9942 * notation, readline: Readline Bare Essentials.
9944 * operator, shell: Definitions. (line 57)
9945 * parameter expansion: Shell Parameter Expansion.
9947 * parameters: Shell Parameters. (line 6)
9948 * parameters, positional: Positional Parameters.
9950 * parameters, special: Special Parameters. (line 6)
9951 * pathname expansion: Filename Expansion. (line 9)
9952 * pattern matching: Pattern Matching. (line 6)
9953 * pipeline: Pipelines. (line 6)
9954 * POSIX: Definitions. (line 9)
9955 * POSIX Mode: Bash POSIX Mode. (line 6)
9956 * process group: Definitions. (line 62)
9957 * process group ID: Definitions. (line 66)
9958 * process substitution: Process Substitution.
9960 * programmable completion: Programmable Completion.
9962 * prompting: Printing a Prompt. (line 6)
9963 * quoting: Quoting. (line 6)
9964 * quoting, ANSI: ANSI-C Quoting. (line 6)
9965 * Readline, how to use: Job Control Variables.
9967 * redirection: Redirections. (line 6)
9968 * reserved word: Definitions. (line 70)
9969 * restricted shell: The Restricted Shell.
9971 * return status: Definitions. (line 75)
9972 * shell arithmetic: Shell Arithmetic. (line 6)
9973 * shell function: Shell Functions. (line 6)
9974 * shell script: Shell Scripts. (line 6)
9975 * shell variable: Shell Parameters. (line 6)
9976 * shell, interactive: Interactive Shells. (line 6)
9977 * signal: Definitions. (line 78)
9978 * signal handling: Signals. (line 6)
9979 * special builtin <1>: Special Builtins. (line 6)
9980 * special builtin: Definitions. (line 82)
9981 * startup files: Bash Startup Files. (line 6)
9982 * suspending jobs: Job Control Basics. (line 6)
9983 * tilde expansion: Tilde Expansion. (line 6)
9984 * token: Definitions. (line 86)
9985 * translation, native languages: Locale Translation. (line 6)
9986 * variable, shell: Shell Parameters. (line 6)
9987 * variables, readline: Readline Init File Syntax.
9989 * word: Definitions. (line 90)
9990 * word splitting: Word Splitting. (line 6)
9991 * yanking text: Readline Killing Commands.
9998 Node: Introduction
\7f3185
9999 Node: What is Bash?
\7f3413
10000 Node: What is a shell?
\7f4526
10001 Node: Definitions
\7f7066
10002 Node: Basic Shell Features
\7f9984
10003 Node: Shell Syntax
\7f11203
10004 Node: Shell Operation
\7f12233
10005 Node: Quoting
\7f13527
10006 Node: Escape Character
\7f14830
10007 Node: Single Quotes
\7f15315
10008 Node: Double Quotes
\7f15663
10009 Node: ANSI-C Quoting
\7f16788
10010 Node: Locale Translation
\7f17744
10011 Node: Comments
\7f18640
10012 Node: Shell Commands
\7f19258
10013 Node: Simple Commands
\7f20082
10014 Node: Pipelines
\7f20713
10015 Node: Lists
\7f22969
10016 Node: Compound Commands
\7f24698
10017 Node: Looping Constructs
\7f25502
10018 Node: Conditional Constructs
\7f27949
10019 Node: Command Grouping
\7f35955
10020 Node: Coprocesses
\7f37434
10021 Node: Shell Functions
\7f39078
10022 Node: Shell Parameters
\7f43539
10023 Node: Positional Parameters
\7f45955
10024 Node: Special Parameters
\7f46855
10025 Node: Shell Expansions
\7f49819
10026 Node: Brace Expansion
\7f51744
10027 Node: Tilde Expansion
\7f54497
10028 Node: Shell Parameter Expansion
\7f56848
10029 Node: Command Substitution
\7f65746
10030 Node: Arithmetic Expansion
\7f67079
10031 Node: Process Substitution
\7f67929
10032 Node: Word Splitting
\7f68979
10033 Node: Filename Expansion
\7f70602
10034 Node: Pattern Matching
\7f72742
10035 Node: Quote Removal
\7f76381
10036 Node: Redirections
\7f76676
10037 Node: Executing Commands
\7f84819
10038 Node: Simple Command Expansion
\7f85489
10039 Node: Command Search and Execution
\7f87419
10040 Node: Command Execution Environment
\7f89756
10041 Node: Environment
\7f92742
10042 Node: Exit Status
\7f94402
10043 Node: Signals
\7f96023
10044 Node: Shell Scripts
\7f97991
10045 Node: Shell Builtin Commands
\7f100509
10046 Node: Bourne Shell Builtins
\7f102186
10047 Node: Bash Builtins
\7f119504
10048 Node: Modifying Shell Behavior
\7f143695
10049 Node: The Set Builtin
\7f144040
10050 Node: The Shopt Builtin
\7f153080
10051 Node: Special Builtins
\7f163942
10052 Node: Shell Variables
\7f164921
10053 Node: Bourne Shell Variables
\7f165361
10054 Node: Bash Variables
\7f167342
10055 Node: Bash Features
\7f189660
10056 Node: Invoking Bash
\7f190543
10057 Node: Bash Startup Files
\7f196352
10058 Node: Interactive Shells
\7f201321
10059 Node: What is an Interactive Shell?
\7f201731
10060 Node: Is this Shell Interactive?
\7f202380
10061 Node: Interactive Shell Behavior
\7f203195
10062 Node: Bash Conditional Expressions
\7f206475
10063 Node: Shell Arithmetic
\7f210054
10064 Node: Aliases
\7f212800
10065 Node: Arrays
\7f215372
10066 Node: The Directory Stack
\7f219214
10067 Node: Directory Stack Builtins
\7f219928
10068 Node: Printing a Prompt
\7f222820
10069 Node: The Restricted Shell
\7f225572
10070 Node: Bash POSIX Mode
\7f227404
10071 Node: Job Control
\7f235257
10072 Node: Job Control Basics
\7f235717
10073 Node: Job Control Builtins
\7f240330
10074 Node: Job Control Variables
\7f244694
10075 Node: Command Line Editing
\7f245852
10076 Node: Introduction and Notation
\7f247419
10077 Node: Readline Interaction
\7f249041
10078 Node: Readline Bare Essentials
\7f250232
10079 Node: Readline Movement Commands
\7f252021
10080 Node: Readline Killing Commands
\7f252986
10081 Node: Readline Arguments
\7f254906
10082 Node: Searching
\7f255950
10083 Node: Readline Init File
\7f258136
10084 Node: Readline Init File Syntax
\7f259283
10085 Node: Conditional Init Constructs
\7f272517
10086 Node: Sample Init File
\7f275050
10087 Node: Bindable Readline Commands
\7f278167
10088 Node: Commands For Moving
\7f279374
10089 Node: Commands For History
\7f280518
10090 Node: Commands For Text
\7f283673
10091 Node: Commands For Killing
\7f286346
10092 Node: Numeric Arguments
\7f288797
10093 Node: Commands For Completion
\7f289936
10094 Node: Keyboard Macros
\7f293703
10095 Node: Miscellaneous Commands
\7f294274
10096 Node: Readline vi Mode
\7f299585
10097 Node: Programmable Completion
\7f300499
10098 Node: Programmable Completion Builtins
\7f306332
10099 Node: Using History Interactively
\7f314758
10100 Node: Bash History Facilities
\7f315442
10101 Node: Bash History Builtins
\7f318356
10102 Node: History Interaction
\7f322213
10103 Node: Event Designators
\7f324918
10104 Node: Word Designators
\7f325933
10105 Node: Modifiers
\7f327572
10106 Node: Installing Bash
\7f328976
10107 Node: Basic Installation
\7f330113
10108 Node: Compilers and Options
\7f332805
10109 Node: Compiling For Multiple Architectures
\7f333546
10110 Node: Installation Names
\7f335210
10111 Node: Specifying the System Type
\7f336028
10112 Node: Sharing Defaults
\7f336744
10113 Node: Operation Controls
\7f337417
10114 Node: Optional Features
\7f338375
10115 Node: Reporting Bugs
\7f347777
10116 Node: Major Differences From The Bourne Shell
\7f348971
10117 Node: GNU Free Documentation License
\7f365658
10118 Node: Indexes
\7f388119
10119 Node: Builtin Index
\7f388573
10120 Node: Reserved Word Index
\7f395400
10121 Node: Variable Index
\7f397848
10122 Node: Function Index
\7f409654
10123 Node: Concept Index
\7f416386