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.1, 23 December 2009).
7 This is Edition 4.1, last updated 23 December 2009, of `The GNU Bash
8 Reference Manual', for `Bash', Version 4.1.
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.3 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.1, 23 December 2009).
43 This is Edition 4.1, last updated 23 December 2009, of `The GNU Bash
44 Reference Manual', for `Bash', Version 4.1.
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
446 an escape character (not ANSI C)
473 the eight-bit character whose value is the octal value NNN (one to
477 the eight-bit character whose value is the hexadecimal value HH
478 (one or two hex digits)
481 a control-X character
483 The expanded result is single-quoted, as if the dollar sign had not
487 File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
489 3.1.2.5 Locale-Specific Translation
490 ...................................
492 A double-quoted string preceded by a dollar sign (`$') will cause the
493 string to be translated according to the current locale. If the
494 current locale is `C' or `POSIX', the dollar sign is ignored. If the
495 string is translated and replaced, the replacement is double-quoted.
497 Some systems use the message catalog selected by the `LC_MESSAGES'
498 shell variable. Others create the name of the message catalog from the
499 value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
500 `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the
501 `TEXTDOMAINDIR' variable to the location of the message catalog files.
502 Still others use both variables in this fashion:
503 `TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.
506 File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
511 In a non-interactive shell, or an interactive shell in which the
512 `interactive_comments' option to the `shopt' builtin is enabled (*note
513 The Shopt Builtin::), a word beginning with `#' causes that word and
514 all remaining characters on that line to be ignored. An interactive
515 shell without the `interactive_comments' option enabled does not allow
516 comments. The `interactive_comments' option is on by default in
517 interactive shells. *Note Interactive Shells::, for a description of
518 what makes a shell interactive.
521 File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
526 A simple shell command such as `echo a b c' consists of the command
527 itself followed by arguments, separated by spaces.
529 More complex shell commands are composed of simple commands arranged
530 together in a variety of ways: in a pipeline in which the output of one
531 command becomes the input of a second, in a loop or conditional
532 construct, or in some other grouping.
536 * Simple Commands:: The most common type of command.
537 * Pipelines:: Connecting the input and output of several
539 * Lists:: How to execute commands sequentially.
540 * Compound Commands:: Shell commands for control flow.
541 * Coprocesses:: Two-way communication between commands.
544 File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
546 3.2.1 Simple Commands
547 ---------------------
549 A simple command is the kind of command encountered most often. It's
550 just a sequence of words separated by `blank's, terminated by one of
551 the shell's control operators (*note Definitions::). The first word
552 generally specifies a command to be executed, with the rest of the
553 words being that command's arguments.
555 The return status (*note Exit Status::) of a simple command is its
556 exit status as provided by the POSIX 1003.1 `waitpid' function, or
557 128+N if the command was terminated by signal N.
560 File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
565 A `pipeline' is a sequence of simple commands separated by one of the
566 control operators `|' or `|&'.
568 The format for a pipeline is
569 [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...]
571 The output of each command in the pipeline is connected via a pipe to
572 the input of the next command. That is, each command reads the
573 previous command's output. This connection is performed before any
574 redirections specified by the command.
576 If `|&' is used, the standard error of COMMAND1 is connected to
577 COMMAND2's standard input through the pipe; it is shorthand for `2>&1
578 |'. This implicit redirection of the standard error is performed after
579 any redirections specified by the command.
581 The reserved word `time' causes timing statistics to be printed for
582 the pipeline once it finishes. The statistics currently consist of
583 elapsed (wall-clock) time and user and system time consumed by the
584 command's execution. The `-p' option changes the output format to that
585 specified by POSIX. The `TIMEFORMAT' variable may be set to a format
586 string that specifies how the timing information should be displayed.
587 *Note Bash Variables::, for a description of the available formats.
588 The use of `time' as a reserved word permits the timing of shell
589 builtins, shell functions, and pipelines. An external `time' command
590 cannot time these easily.
592 If the pipeline is not executed asynchronously (*note Lists::), the
593 shell waits for all commands in the pipeline to complete.
595 Each command in a pipeline is executed in its own subshell (*note
596 Command Execution Environment::). The exit status of a pipeline is the
597 exit status of the last command in the pipeline, unless the `pipefail'
598 option is enabled (*note The Set Builtin::). If `pipefail' is enabled,
599 the pipeline's return status is the value of the last (rightmost)
600 command to exit with a non-zero status, or zero if all commands exit
601 successfully. If the reserved word `!' precedes the pipeline, the exit
602 status is the logical negation of the exit status as described above.
603 The shell waits for all commands in the pipeline to terminate before
607 File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
609 3.2.3 Lists of Commands
610 -----------------------
612 A `list' is a sequence of one or more pipelines separated by one of the
613 operators `;', `&', `&&', or `||', and optionally terminated by one of
614 `;', `&', or a `newline'.
616 Of these list operators, `&&' and `||' have equal precedence,
617 followed by `;' and `&', which have equal precedence.
619 A sequence of one or more newlines may appear in a `list' to delimit
620 commands, equivalent to a semicolon.
622 If a command is terminated by the control operator `&', the shell
623 executes the command asynchronously in a subshell. This is known as
624 executing the command in the BACKGROUND. The shell does not wait for
625 the command to finish, and the return status is 0 (true). When job
626 control is not active (*note Job Control::), the standard input for
627 asynchronous commands, in the absence of any explicit redirections, is
628 redirected from `/dev/null'.
630 Commands separated by a `;' are executed sequentially; the shell
631 waits for each command to terminate in turn. The return status is the
632 exit status of the last command executed.
634 AND and OR lists are sequences of one or more pipelines separated by
635 the control operators `&&' and `||', respectively. AND and OR lists
636 are executed with left associativity.
638 An AND list has the form
641 COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
644 An OR list has the form
647 COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
650 The return status of AND and OR lists is the exit status of the last
651 command executed in the list.
654 File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
656 3.2.4 Compound Commands
657 -----------------------
661 * Looping Constructs:: Shell commands for iterative action.
662 * Conditional Constructs:: Shell commands for conditional execution.
663 * Command Grouping:: Ways to group commands.
665 Compound commands are the shell programming constructs. Each
666 construct begins with a reserved word or control operator and is
667 terminated by a corresponding reserved word or operator. Any
668 redirections (*note Redirections::) associated with a compound command
669 apply to all commands within that compound command unless explicitly
672 Bash provides looping constructs, conditional commands, and
673 mechanisms to group commands and execute them as a unit.
676 File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
678 3.2.4.1 Looping Constructs
679 ..........................
681 Bash supports the following looping constructs.
683 Note that wherever a `;' appears in the description of a command's
684 syntax, it may be replaced with one or more newlines.
687 The syntax of the `until' command is:
688 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
689 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
690 status which is not zero. The return status is the exit status of
691 the last command executed in CONSEQUENT-COMMANDS, or zero if none
695 The syntax of the `while' command is:
696 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
698 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
699 status of zero. The return status is the exit status of the last
700 command executed in CONSEQUENT-COMMANDS, or zero if none was
704 The syntax of the `for' command is:
706 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
707 Expand WORDS, and execute COMMANDS once for each member in the
708 resultant list, with NAME bound to the current member. If `in
709 WORDS' is not present, the `for' command executes the COMMANDS
710 once for each positional parameter that is set, as if `in "$@"'
711 had been specified (*note Special Parameters::). The return
712 status is the exit status of the last command that executes. If
713 there are no items in the expansion of WORDS, no commands are
714 executed, and the return status is zero.
716 An alternate form of the `for' command is also supported:
718 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
719 First, the arithmetic expression EXPR1 is evaluated according to
720 the rules described below (*note Shell Arithmetic::). The
721 arithmetic expression EXPR2 is then evaluated repeatedly until it
722 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
723 COMMANDS are executed and the arithmetic expression EXPR3 is
724 evaluated. If any expression is omitted, it behaves as if it
725 evaluates to 1. The return value is the exit status of the last
726 command in LIST that is executed, or false if any of the
727 expressions is invalid.
730 The `break' and `continue' builtins (*note Bourne Shell Builtins::)
731 may be used to control loop execution.
734 File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
736 3.2.4.2 Conditional Constructs
737 ..............................
740 The syntax of the `if' command is:
742 if TEST-COMMANDS; then
744 [elif MORE-TEST-COMMANDS; then
746 [else ALTERNATE-CONSEQUENTS;]
749 The TEST-COMMANDS list is executed, and if its return status is
750 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
751 returns a non-zero status, each `elif' list is executed in turn,
752 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
753 is executed and the command completes. If `else
754 ALTERNATE-CONSEQUENTS' is present, and the final command in the
755 final `if' or `elif' clause has a non-zero exit status, then
756 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
757 status of the last command executed, or zero if no condition
761 The syntax of the `case' command is:
763 `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
765 `case' will selectively execute the COMMAND-LIST corresponding to
766 the first PATTERN that matches WORD. If the shell option
767 `nocasematch' (see the description of `shopt' in *note The Shopt
768 Builtin::) is enabled, the match is performed without regard to
769 the case of alphabetic characters. The `|' is used to separate
770 multiple patterns, and the `)' operator terminates a pattern list.
771 A list of patterns and an associated command-list is known as a
774 Each clause must be terminated with `;;', `;&', or `;;&'. The
775 WORD undergoes tilde expansion, parameter expansion, command
776 substitution, arithmetic expansion, and quote removal before
777 matching is attempted. Each PATTERN undergoes tilde expansion,
778 parameter expansion, command substitution, and arithmetic
781 There may be an arbitrary number of `case' clauses, each terminated
782 by a `;;', `;&', or `;;&'. The first pattern that matches
783 determines the command-list that is executed.
785 Here is an example using `case' in a script that could be used to
786 describe one interesting feature of an animal:
788 echo -n "Enter the name of an animal: "
790 echo -n "The $ANIMAL has "
792 horse | dog | cat) echo -n "four";;
793 man | kangaroo ) echo -n "two";;
794 *) echo -n "an unknown number of";;
798 If the `;;' operator is used, no subsequent matches are attempted
799 after the first pattern match. Using `;&' in place of `;;'
800 causes execution to continue with the COMMAND-LIST associated with
801 the next clause, if any. Using `;;&' in place of `;;' causes the
802 shell to test the patterns in the next clause, if any, and execute
803 any associated COMMAND-LIST on a successful match.
805 The return status is zero if no PATTERN is matched. Otherwise, the
806 return status is the exit status of the COMMAND-LIST executed.
809 The `select' construct allows the easy generation of menus. It
810 has almost the same syntax as the `for' command:
812 select NAME [in WORDS ...]; do COMMANDS; done
814 The list of words following `in' is expanded, generating a list of
815 items. The set of expanded words is printed on the standard error
816 output stream, each preceded by a number. If the `in WORDS' is
817 omitted, the positional parameters are printed, as if `in "$@"'
818 had been specified. The `PS3' prompt is then displayed and a line
819 is read from the standard input. If the line consists of a number
820 corresponding to one of the displayed words, then the value of
821 NAME is set to that word. If the line is empty, the words and
822 prompt are displayed again. If `EOF' is read, the `select'
823 command completes. Any other value read causes NAME to be set to
824 null. The line read is saved in the variable `REPLY'.
826 The COMMANDS are executed after each selection until a `break'
827 command is executed, at which point the `select' command completes.
829 Here is an example that allows the user to pick a filename from the
830 current directory, and displays the name and index of the file
835 echo you picked $fname \($REPLY\)
842 The arithmetic EXPRESSION is evaluated according to the rules
843 described below (*note Shell Arithmetic::). If the value of the
844 expression is non-zero, the return status is 0; otherwise the
845 return status is 1. This is exactly equivalent to
847 *Note Bash Builtins::, for a full description of the `let' builtin.
852 Return a status of 0 or 1 depending on the evaluation of the
853 conditional expression EXPRESSION. Expressions are composed of
854 the primaries described below in *note Bash Conditional
855 Expressions::. Word splitting and filename expansion are not
856 performed on the words between the `[[' and `]]'; tilde expansion,
857 parameter and variable expansion, arithmetic expansion, command
858 substitution, process substitution, and quote removal are
859 performed. Conditional operators such as `-f' must be unquoted to
860 be recognized as primaries.
862 When used with `[[', The `<' and `>' operators sort
863 lexicographically using the current locale.
865 When the `==' and `!=' operators are used, the string to the right
866 of the operator is considered a pattern and matched according to
867 the rules described below in *note Pattern Matching::. If the
868 shell option `nocasematch' (see the description of `shopt' in
869 *note The Shopt Builtin::) is enabled, the match is performed
870 without regard to the case of alphabetic characters. The return
871 value is 0 if the string matches (`==') or does not match
872 (`!=')the pattern, and 1 otherwise. Any part of the pattern may
873 be quoted to force it to be matched as a string.
875 An additional binary operator, `=~', is available, with the same
876 precedence as `==' and `!='. When it is used, the string to the
877 right of the operator is considered an extended regular expression
878 and matched accordingly (as in regex3)). The return value is 0 if
879 the string matches the pattern, and 1 otherwise. If the regular
880 expression is syntactically incorrect, the conditional
881 expression's return value is 2. If the shell option `nocasematch'
882 (see the description of `shopt' in *note The Shopt Builtin::) is
883 enabled, the match is performed without regard to the case of
884 alphabetic characters. Any part of the pattern may be quoted to
885 force it to be matched as a string. Substrings matched by
886 parenthesized subexpressions within the regular expression are
887 saved in the array variable `BASH_REMATCH'. The element of
888 `BASH_REMATCH' with index 0 is the portion of the string matching
889 the entire regular expression. The element of `BASH_REMATCH' with
890 index N is the portion of the string matching the Nth
891 parenthesized subexpression.
893 Expressions may be combined using the following operators, listed
894 in decreasing order of precedence:
897 Returns the value of EXPRESSION. This may be used to
898 override the normal precedence of operators.
901 True if EXPRESSION is false.
903 `EXPRESSION1 && EXPRESSION2'
904 True if both EXPRESSION1 and EXPRESSION2 are true.
906 `EXPRESSION1 || EXPRESSION2'
907 True if either EXPRESSION1 or EXPRESSION2 is true.
908 The `&&' and `||' operators do not evaluate EXPRESSION2 if the
909 value of EXPRESSION1 is sufficient to determine the return value
910 of the entire conditional expression.
914 File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
916 3.2.4.3 Grouping Commands
917 .........................
919 Bash provides two ways to group a list of commands to be executed as a
920 unit. When commands are grouped, redirections may be applied to the
921 entire command list. For example, the output of all the commands in
922 the list may be redirected to a single stream.
927 Placing a list of commands between parentheses causes a subshell
928 environment to be created (*note Command Execution Environment::),
929 and each of the commands in LIST to be executed in that subshell.
930 Since the LIST is executed in a subshell, variable assignments do
931 not remain in effect after the subshell completes.
936 Placing a list of commands between curly braces causes the list to
937 be executed in the current shell context. No subshell is created.
938 The semicolon (or newline) following LIST is required.
940 In addition to the creation of a subshell, there is a subtle
941 difference between these two constructs due to historical reasons. The
942 braces are `reserved words', so they must be separated from the LIST by
943 `blank's or other shell metacharacters. The parentheses are
944 `operators', and are recognized as separate tokens by the shell even if
945 they are not separated from the LIST by whitespace.
947 The exit status of both of these constructs is the exit status of
951 File: bashref.info, Node: Coprocesses, Prev: Compound Commands, Up: Shell Commands
956 A `coprocess' is a shell command preceded by the `coproc' reserved word.
957 A coprocess is executed asynchronously in a subshell, as if the command
958 had been terminated with the `&' control operator, with a two-way pipe
959 established between the executing shell and the coprocess.
961 The format for a coprocess is:
962 `coproc' [NAME] COMMAND [REDIRECTIONS]
964 This creates a coprocess named NAME. If NAME is not supplied, the
965 default name is COPROC. NAME must not be supplied if COMMAND is a
966 simple command (*note Simple Commands::); otherwise, it is interpreted
967 as the first word of the simple command.
969 When the coproc is executed, the shell creates an array variable
970 (*note Arrays::) named NAME in the context of the executing shell. The
971 standard output of COMMAND is connected via a pipe to a file descriptor
972 in the executing shell, and that file descriptor is assigned to NAME[0].
973 The standard input of COMMAND is connected via a pipe to a file
974 descriptor in the executing shell, and that file descriptor is assigned
975 to NAME[1]. This pipe is established before any redirections specified
976 by the command (*note Redirections::). The file descriptors can be
977 utilized as arguments to shell commands and redirections using standard
980 The process id of the shell spawned to execute the coprocess is
981 available as the value of the variable NAME_PID. The `wait' builtin
982 command may be used to wait for the coprocess to terminate.
984 The return status of a coprocess is the exit status of COMMAND.
987 File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
992 Shell functions are a way to group commands for later execution using a
993 single name for the group. They are executed just like a "regular"
994 command. When the name of a shell function is used as a simple command
995 name, the list of commands associated with that function name is
996 executed. Shell functions are executed in the current shell context;
997 no new process is created to interpret them.
999 Functions are declared using this syntax:
1000 [ `function' ] NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
1002 This defines a shell function named NAME. The reserved word
1003 `function' is optional. If the `function' reserved word is supplied,
1004 the parentheses are optional. The BODY of the function is the compound
1005 command COMPOUND-COMMAND (*note Compound Commands::). That command is
1006 usually a LIST enclosed between { and }, but may be any compound
1007 command listed above. COMPOUND-COMMAND is executed whenever NAME is
1008 specified as the name of a command. Any redirections (*note
1009 Redirections::) associated with the shell function are performed when
1010 the function is executed.
1012 A function definition may be deleted using the `-f' option to the
1013 `unset' builtin (*note Bourne Shell Builtins::).
1015 The exit status of a function definition is zero unless a syntax
1016 error occurs or a readonly function with the same name already exists.
1017 When executed, the exit status of a function is the exit status of the
1018 last command executed in the body.
1020 Note that for historical reasons, in the most common usage the curly
1021 braces that surround the body of the function must be separated from
1022 the body by `blank's or newlines. This is because the braces are
1023 reserved words and are only recognized as such when they are separated
1024 from the command list by whitespace or another shell metacharacter.
1025 Also, when using the braces, the LIST must be terminated by a semicolon,
1026 a `&', or a newline.
1028 When a function is executed, the arguments to the function become
1029 the positional parameters during its execution (*note Positional
1030 Parameters::). The special parameter `#' that expands to the number of
1031 positional parameters is updated to reflect the change. Special
1032 parameter `0' is unchanged. The first element of the `FUNCNAME'
1033 variable is set to the name of the function while the function is
1036 All other aspects of the shell execution environment are identical
1037 between a function and its caller with these exceptions: the `DEBUG'
1038 and `RETURN' traps are not inherited unless the function has been given
1039 the `trace' attribute using the `declare' builtin or the `-o functrace'
1040 option has been enabled with the `set' builtin, (in which case all
1041 functions inherit the `DEBUG' and `RETURN' traps), and the `ERR' trap
1042 is not inherited unless the `-o errtrace' shell option has been enabled.
1043 *Note Bourne Shell Builtins::, for the description of the `trap'
1046 If the builtin command `return' is executed in a function, the
1047 function completes and execution resumes with the next command after
1048 the function call. Any command associated with the `RETURN' trap is
1049 executed before execution resumes. When a function completes, the
1050 values of the positional parameters and the special parameter `#' are
1051 restored to the values they had prior to the function's execution. If
1052 a numeric argument is given to `return', that is the function's return
1053 status; otherwise the function's return status is the exit status of
1054 the last command executed before the `return'.
1056 Variables local to the function may be declared with the `local'
1057 builtin. These variables are visible only to the function and the
1058 commands it invokes.
1060 Function names and definitions may be listed with the `-f' option to
1061 the `declare' or `typeset' builtin commands (*note Bash Builtins::).
1062 The `-F' option to `declare' or `typeset' will list the function names
1063 only (and optionally the source file and line number, if the `extdebug'
1064 shell option is enabled). Functions may be exported so that subshells
1065 automatically have them defined with the `-f' option to the `export'
1066 builtin (*note Bourne Shell Builtins::). Note that shell functions and
1067 variables with the same name may result in multiple identically-named
1068 entries in the environment passed to the shell's children. Care should
1069 be taken in cases where this may cause a problem.
1071 Functions may be recursive. No limit is placed on the number of
1075 File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1077 3.4 Shell Parameters
1078 ====================
1082 * Positional Parameters:: The shell's command-line arguments.
1083 * Special Parameters:: Parameters denoted by special characters.
1085 A PARAMETER is an entity that stores values. It can be a `name', a
1086 number, or one of the special characters listed below. A VARIABLE is a
1087 parameter denoted by a `name'. A variable has a VALUE and zero or more
1088 ATTRIBUTES. Attributes are assigned using the `declare' builtin command
1089 (see the description of the `declare' builtin in *note Bash Builtins::).
1091 A parameter is set if it has been assigned a value. The null string
1092 is a valid value. Once a variable is set, it may be unset only by using
1093 the `unset' builtin command.
1095 A variable may be assigned to by a statement of the form
1097 If VALUE is not given, the variable is assigned the null string. All
1098 VALUEs undergo tilde expansion, parameter and variable expansion,
1099 command substitution, arithmetic expansion, and quote removal (detailed
1100 below). If the variable has its `integer' attribute set, then VALUE is
1101 evaluated as an arithmetic expression even if the `$((...))' expansion
1102 is not used (*note Arithmetic Expansion::). Word splitting is not
1103 performed, with the exception of `"$@"' as explained below. Filename
1104 expansion is not performed. Assignment statements may also appear as
1105 arguments to the `alias', `declare', `typeset', `export', `readonly',
1106 and `local' builtin commands.
1108 In the context where an assignment statement is assigning a value to
1109 a shell variable or array index (*note Arrays::), the `+=' operator can
1110 be used to append to or add to the variable's previous value. When
1111 `+=' is applied to a variable for which the integer attribute has been
1112 set, VALUE is evaluated as an arithmetic expression and added to the
1113 variable's current value, which is also evaluated. When `+=' is
1114 applied to an array variable using compound assignment (*note
1115 Arrays::), the variable's value is not unset (as it is when using `='),
1116 and new values are appended to the array beginning at one greater than
1117 the array's maximum index (for indexed arrays), or added as additional
1118 key-value pairs in an associative array. When applied to a
1119 string-valued variable, VALUE is expanded and appended to the
1123 File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1125 3.4.1 Positional Parameters
1126 ---------------------------
1128 A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
1129 other than the single digit `0'. Positional parameters are assigned
1130 from the shell's arguments when it is invoked, and may be reassigned
1131 using the `set' builtin command. Positional parameter `N' may be
1132 referenced as `${N}', or as `$N' when `N' consists of a single digit.
1133 Positional parameters may not be assigned to with assignment statements.
1134 The `set' and `shift' builtins are used to set and unset them (*note
1135 Shell Builtin Commands::). The positional parameters are temporarily
1136 replaced when a shell function is executed (*note Shell Functions::).
1138 When a positional parameter consisting of more than a single digit
1139 is expanded, it must be enclosed in braces.
1142 File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1144 3.4.2 Special Parameters
1145 ------------------------
1147 The shell treats several parameters specially. These parameters may
1148 only be referenced; assignment to them is not allowed.
1151 Expands to the positional parameters, starting from one. When the
1152 expansion occurs within double quotes, it expands to a single word
1153 with the value of each parameter separated by the first character
1154 of the `IFS' special variable. That is, `"$*"' is equivalent to
1155 `"$1C$2C..."', where C is the first character of the value of the
1156 `IFS' variable. If `IFS' is unset, the parameters are separated
1157 by spaces. If `IFS' is null, the parameters are joined without
1158 intervening separators.
1161 Expands to the positional parameters, starting from one. When the
1162 expansion occurs within double quotes, each parameter expands to a
1163 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
1164 If the double-quoted expansion occurs within a word, the expansion
1165 of the first parameter is joined with the beginning part of the
1166 original word, and the expansion of the last parameter is joined
1167 with the last part of the original word. When there are no
1168 positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
1172 Expands to the number of positional parameters in decimal.
1175 Expands to the exit status of the most recently executed foreground
1179 (A hyphen.) Expands to the current option flags as specified upon
1180 invocation, by the `set' builtin command, or those set by the
1181 shell itself (such as the `-i' option).
1184 Expands to the process ID of the shell. In a `()' subshell, it
1185 expands to the process ID of the invoking shell, not the subshell.
1188 Expands to the process ID of the most recently executed background
1189 (asynchronous) command.
1192 Expands to the name of the shell or shell script. This is set at
1193 shell initialization. If Bash is invoked with a file of commands
1194 (*note Shell Scripts::), `$0' is set to the name of that file. If
1195 Bash is started with the `-c' option (*note Invoking Bash::), then
1196 `$0' is set to the first argument after the string to be executed,
1197 if one is present. Otherwise, it is set to the filename used to
1198 invoke Bash, as given by argument zero.
1201 (An underscore.) At shell startup, set to the absolute pathname
1202 used to invoke the shell or shell script being executed as passed
1203 in the environment or argument list. Subsequently, expands to the
1204 last argument to the previous command, after expansion. Also set
1205 to the full pathname used to invoke each command executed and
1206 placed in the environment exported to that command. When checking
1207 mail, this parameter holds the name of the mail file.
1210 File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1212 3.5 Shell Expansions
1213 ====================
1215 Expansion is performed on the command line after it has been split into
1216 `token's. There are seven kinds of expansion performed:
1221 * parameter and variable expansion
1223 * command substitution
1225 * arithmetic expansion
1229 * filename expansion
1233 * Brace Expansion:: Expansion of expressions within braces.
1234 * Tilde Expansion:: Expansion of the ~ character.
1235 * Shell Parameter Expansion:: How Bash expands variables to their values.
1236 * Command Substitution:: Using the output of a command as an argument.
1237 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
1238 * Process Substitution:: A way to write and read to and from a
1240 * Word Splitting:: How the results of expansion are split into separate
1242 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
1243 * Quote Removal:: How and when quote characters are removed from
1246 The order of expansions is: brace expansion, tilde expansion,
1247 parameter, variable, and arithmetic expansion and command substitution
1248 (done in a left-to-right fashion), word splitting, and filename
1251 On systems that can support it, there is an additional expansion
1252 available: PROCESS SUBSTITUTION. This is performed at the same time as
1253 parameter, variable, and arithmetic expansion and command substitution.
1255 Only brace expansion, word splitting, and filename expansion can
1256 change the number of words of the expansion; other expansions expand a
1257 single word to a single word. The only exceptions to this are the
1258 expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
1261 After all expansions, `quote removal' (*note Quote Removal::) is
1265 File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1267 3.5.1 Brace Expansion
1268 ---------------------
1270 Brace expansion is a mechanism by which arbitrary strings may be
1271 generated. This mechanism is similar to FILENAME EXPANSION (*note
1272 Filename Expansion::), but the file names generated need not exist.
1273 Patterns to be brace expanded take the form of an optional PREAMBLE,
1274 followed by either a series of comma-separated strings or a seqeunce
1275 expression between a pair of braces, followed by an optional POSTSCRIPT.
1276 The preamble is prefixed to each string contained within the braces, and
1277 the postscript is then appended to each resulting string, expanding left
1280 Brace expansions may be nested. The results of each expanded string
1281 are not sorted; left to right order is preserved. For example,
1282 bash$ echo a{d,c,b}e
1285 A sequence expression takes the form `{X..Y[..INCR]}', where X and Y
1286 are either integers or single characters, and INCR, an optional
1287 increment, is an integer. When integers are supplied, the expression
1288 expands to each number between X and Y, inclusive. Supplied integers
1289 may be prefixed with `0' to force each term to have the same width.
1290 When either X or Y begins with a zero, the shell attempts to force all
1291 generated terms to contain the same number of digits, zero-padding
1292 where necessary. When characters are supplied, the expression expands
1293 to each character lexicographically between X and Y, inclusive. Note
1294 that both X and Y must be of the same type. When the increment is
1295 supplied, it is used as the difference between each term. The default
1296 increment is 1 or -1 as appropriate.
1298 Brace expansion is performed before any other expansions, and any
1299 characters special to other expansions are preserved in the result. It
1300 is strictly textual. Bash does not apply any syntactic interpretation
1301 to the context of the expansion or the text between the braces. To
1302 avoid conflicts with parameter expansion, the string `${' is not
1303 considered eligible for brace expansion.
1305 A correctly-formed brace expansion must contain unquoted opening and
1306 closing braces, and at least one unquoted comma or a valid sequence
1307 expression. Any incorrectly formed brace expansion is left unchanged.
1309 A { or `,' may be quoted with a backslash to prevent its being
1310 considered part of a brace expression. To avoid conflicts with
1311 parameter expansion, the string `${' is not considered eligible for
1314 This construct is typically used as shorthand when the common prefix
1315 of the strings to be generated is longer than in the above example:
1316 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1318 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1321 File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1323 3.5.2 Tilde Expansion
1324 ---------------------
1326 If a word begins with an unquoted tilde character (`~'), all of the
1327 characters up to the first unquoted slash (or all characters, if there
1328 is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1329 characters in the tilde-prefix are quoted, the characters in the
1330 tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1331 If this login name is the null string, the tilde is replaced with the
1332 value of the `HOME' shell variable. If `HOME' is unset, the home
1333 directory of the user executing the shell is substituted instead.
1334 Otherwise, the tilde-prefix is replaced with the home directory
1335 associated with the specified login name.
1337 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1338 replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1339 the shell variable `OLDPWD', if it is set, is substituted.
1341 If the characters following the tilde in the tilde-prefix consist of
1342 a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1343 replaced with the corresponding element from the directory stack, as it
1344 would be displayed by the `dirs' builtin invoked with the characters
1345 following tilde in the tilde-prefix as an argument (*note The Directory
1346 Stack::). If the tilde-prefix, sans the tilde, consists of a number
1347 without a leading `+' or `-', `+' is assumed.
1349 If the login name is invalid, or the tilde expansion fails, the word
1352 Each variable assignment is checked for unquoted tilde-prefixes
1353 immediately following a `:' or the first `='. In these cases, tilde
1354 expansion is also performed. Consequently, one may use file names with
1355 tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
1356 shell assigns the expanded value.
1358 The following table shows how Bash treats unquoted tilde-prefixes:
1361 The value of `$HOME'
1367 The subdirectory `foo' of the home directory of the user `fred'
1373 `${OLDPWD-'~-'}/foo'
1376 The string that would be displayed by `dirs +N'
1379 The string that would be displayed by `dirs +N'
1382 The string that would be displayed by `dirs -N'
1386 File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1388 3.5.3 Shell Parameter Expansion
1389 -------------------------------
1391 The `$' character introduces parameter expansion, command substitution,
1392 or arithmetic expansion. The parameter name or symbol to be expanded
1393 may be enclosed in braces, which are optional but serve to protect the
1394 variable to be expanded from characters immediately following it which
1395 could be interpreted as part of the name.
1397 When braces are used, the matching ending brace is the first `}' not
1398 escaped by a backslash or within a quoted string, and not within an
1399 embedded arithmetic expansion, command substitution, or parameter
1402 The basic form of parameter expansion is ${PARAMETER}. The value of
1403 PARAMETER is substituted. The braces are required when PARAMETER is a
1404 positional parameter with more than one digit, or when PARAMETER is
1405 followed by a character that is not to be interpreted as part of its
1408 If the first character of PARAMETER is an exclamation point (!), a
1409 level of variable indirection is introduced. Bash uses the value of
1410 the variable formed from the rest of PARAMETER as the name of the
1411 variable; this variable is then expanded and that value is used in the
1412 rest of the substitution, rather than the value of PARAMETER itself.
1413 This is known as `indirect expansion'. The exceptions to this are the
1414 expansions of ${!PREFIX*} and ${!NAME[@]} described below. The
1415 exclamation point must immediately follow the left brace in order to
1416 introduce indirection.
1418 In each of the cases below, WORD is subject to tilde expansion,
1419 parameter expansion, command substitution, and arithmetic expansion.
1421 When not performing substring expansion, using the form described
1422 below, Bash tests for a parameter that is unset or null. Omitting the
1423 colon results in a test only for a parameter that is unset. Put
1424 another way, if the colon is included, the operator tests for both
1425 PARAMETER's existence and that its value is not null; if the colon is
1426 omitted, the operator tests only for existence.
1428 `${PARAMETER:-WORD}'
1429 If PARAMETER is unset or null, the expansion of WORD is
1430 substituted. Otherwise, the value of PARAMETER is substituted.
1432 `${PARAMETER:=WORD}'
1433 If PARAMETER is unset or null, the expansion of WORD is assigned
1434 to PARAMETER. The value of PARAMETER is then substituted.
1435 Positional parameters and special parameters may not be assigned to
1438 `${PARAMETER:?WORD}'
1439 If PARAMETER is null or unset, the expansion of WORD (or a message
1440 to that effect if WORD is not present) is written to the standard
1441 error and the shell, if it is not interactive, exits. Otherwise,
1442 the value of PARAMETER is substituted.
1444 `${PARAMETER:+WORD}'
1445 If PARAMETER is null or unset, nothing is substituted, otherwise
1446 the expansion of WORD is substituted.
1448 `${PARAMETER:OFFSET}'
1449 `${PARAMETER:OFFSET:LENGTH}'
1450 Expands to up to LENGTH characters of PARAMETER starting at the
1451 character specified by OFFSET. If LENGTH is omitted, expands to
1452 the substring of PARAMETER starting at the character specified by
1453 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
1454 Arithmetic::). This is referred to as Substring Expansion.
1456 LENGTH must evaluate to a number greater than or equal to zero.
1457 If OFFSET evaluates to a number less than zero, the value is used
1458 as an offset from the end of the value of PARAMETER. If PARAMETER
1459 is `@', the result is LENGTH positional parameters beginning at
1460 OFFSET. If PARAMETER is an indexed array name subscripted by `@'
1461 or `*', the result is the LENGTH members of the array beginning
1462 with `${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative
1463 to one greater than the maximum index of the specified array.
1464 Substring expansion applied to an associative array produces
1467 Note that a negative offset must be separated from the colon by at
1468 least one space to avoid being confused with the `:-' expansion.
1469 Substring indexing is zero-based unless the positional parameters
1470 are used, in which case the indexing starts at 1 by default. If
1471 OFFSET is 0, and the positional parameters are used, `$@' is
1472 prefixed to the list.
1476 Expands to the names of variables whose names begin with PREFIX,
1477 separated by the first character of the `IFS' special variable.
1478 When `@' is used and the expansion appears within double quotes,
1479 each variable name expands to a separate word.
1483 If NAME is an array variable, expands to the list of array indices
1484 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1485 NAME is set and null otherwise. When `@' is used and the
1486 expansion appears within double quotes, each key expands to a
1490 The length in characters of the expanded value of PARAMETER is
1491 substituted. If PARAMETER is `*' or `@', the value substituted is
1492 the number of positional parameters. If PARAMETER is an array
1493 name subscripted by `*' or `@', the value substituted is the
1494 number of elements in the array.
1497 `${PARAMETER##WORD}'
1498 The WORD is expanded to produce a pattern just as in filename
1499 expansion (*note Filename Expansion::). If the pattern matches
1500 the beginning of the expanded value of PARAMETER, then the result
1501 of the expansion is the expanded value of PARAMETER with the
1502 shortest matching pattern (the `#' case) or the longest matching
1503 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1504 pattern removal operation is applied to each positional parameter
1505 in turn, and the expansion is the resultant list. If PARAMETER is
1506 an array variable subscripted with `@' or `*', the pattern removal
1507 operation is applied to each member of the array in turn, and the
1508 expansion is the resultant list.
1511 `${PARAMETER%%WORD}'
1512 The WORD is expanded to produce a pattern just as in filename
1513 expansion. If the pattern matches a trailing portion of the
1514 expanded value of PARAMETER, then the result of the expansion is
1515 the value of PARAMETER with the shortest matching pattern (the `%'
1516 case) or the longest matching pattern (the `%%' case) deleted. If
1517 PARAMETER is `@' or `*', the pattern removal operation is applied
1518 to each positional parameter in turn, and the expansion is the
1519 resultant list. If PARAMETER is an array variable subscripted
1520 with `@' or `*', the pattern removal operation is applied to each
1521 member of the array in turn, and the expansion is the resultant
1524 `${PARAMETER/PATTERN/STRING}'
1525 The PATTERN is expanded to produce a pattern just as in filename
1526 expansion. PARAMETER is expanded and the longest match of PATTERN
1527 against its value is replaced with STRING. If PATTERN begins with
1528 `/', all matches of PATTERN are replaced with STRING. Normally
1529 only the first match is replaced. If PATTERN begins with `#', it
1530 must match at the beginning of the expanded value of PARAMETER.
1531 If PATTERN begins with `%', it must match at the end of the
1532 expanded value of PARAMETER. If STRING is null, matches of
1533 PATTERN are deleted and the `/' following PATTERN may be omitted.
1534 If PARAMETER is `@' or `*', the substitution operation is applied
1535 to each positional parameter in turn, and the expansion is the
1536 resultant list. If PARAMETER is an array variable subscripted
1537 with `@' or `*', the substitution operation is applied to each
1538 member of the array in turn, and the expansion is the resultant
1541 `${PARAMETER^PATTERN}'
1542 `${PARAMETER^^PATTERN}'
1543 `${PARAMETER,PATTERN}'
1544 `${PARAMETER,,PATTERN}'
1545 This expansion modifies the case of alphabetic characters in
1546 PARAMETER. The PATTERN is expanded to produce a pattern just as in
1547 filename expansion. The `^' operator converts lowercase letters
1548 matching PATTERN to uppercase; the `,' operator converts matching
1549 uppercase letters to lowercase. The `^^' and `,,' expansions
1550 convert each matched character in the expanded value; the `^' and
1551 `,' expansions match and convert only the first character in the
1552 expanded value. If PATTERN is omitted, it is treated like a `?',
1553 which matches every character. If PARAMETER is `@' or `*', the
1554 case modification operation is applied to each positional
1555 parameter in turn, and the expansion is the resultant list. If
1556 PARAMETER is an array variable subscripted with `@' or `*', the
1557 case modification operation is applied to each member of the array
1558 in turn, and the expansion is the resultant list.
1562 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1564 3.5.4 Command Substitution
1565 --------------------------
1567 Command substitution allows the output of a command to replace the
1568 command itself. Command substitution occurs when a command is enclosed
1574 Bash performs the expansion by executing COMMAND and replacing the
1575 command substitution with the standard output of the command, with any
1576 trailing newlines deleted. Embedded newlines are not deleted, but they
1577 may be removed during word splitting. The command substitution `$(cat
1578 FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
1580 When the old-style backquote form of substitution is used, backslash
1581 retains its literal meaning except when followed by `$', ``', or `\'.
1582 The first backquote not preceded by a backslash terminates the command
1583 substitution. When using the `$(COMMAND)' form, all characters between
1584 the parentheses make up the command; none are treated specially.
1586 Command substitutions may be nested. To nest when using the
1587 backquoted form, escape the inner backquotes with backslashes.
1589 If the substitution appears within double quotes, word splitting and
1590 filename expansion are not performed on the results.
1593 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1595 3.5.5 Arithmetic Expansion
1596 --------------------------
1598 Arithmetic expansion allows the evaluation of an arithmetic expression
1599 and the substitution of the result. The format for arithmetic
1604 The expression is treated as if it were within double quotes, but a
1605 double quote inside the parentheses is not treated specially. All
1606 tokens in the expression undergo parameter expansion, command
1607 substitution, and quote removal. Arithmetic expansions may be nested.
1609 The evaluation is performed according to the rules listed below
1610 (*note Shell Arithmetic::). If the expression is invalid, Bash prints
1611 a message indicating failure to the standard error and no substitution
1615 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1617 3.5.6 Process Substitution
1618 --------------------------
1620 Process substitution is supported on systems that support named pipes
1621 (FIFOs) or the `/dev/fd' method of naming open files. It takes the
1626 The process LIST is run with its input or output connected to a FIFO
1627 or some file in `/dev/fd'. The name of this file is passed as an
1628 argument to the current command as the result of the expansion. If the
1629 `>(LIST)' form is used, writing to the file will provide input for
1630 LIST. If the `<(LIST)' form is used, the file passed as an argument
1631 should be read to obtain the output of LIST. Note that no space may
1632 appear between the `<' or `>' and the left parenthesis, otherwise the
1633 construct would be interpreted as a redirection.
1635 When available, process substitution is performed simultaneously with
1636 parameter and variable expansion, command substitution, and arithmetic
1640 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1642 3.5.7 Word Splitting
1643 --------------------
1645 The shell scans the results of parameter expansion, command
1646 substitution, and arithmetic expansion that did not occur within double
1647 quotes for word splitting.
1649 The shell treats each character of `$IFS' as a delimiter, and splits
1650 the results of the other expansions into words on these characters. If
1651 `IFS' is unset, or its value is exactly `<space><tab><newline>', the
1652 default, then sequences of ` <space>', `<tab>', and `<newline>' at the
1653 beginning and end of the results of the previous expansions are
1654 ignored, and any sequence of `IFS' characters not at the beginning or
1655 end serves to delimit words. If `IFS' has a value other than the
1656 default, then sequences of the whitespace characters `space' and `tab'
1657 are ignored at the beginning and end of the word, as long as the
1658 whitespace character is in the value of `IFS' (an `IFS' whitespace
1659 character). Any character in `IFS' that is not `IFS' whitespace, along
1660 with any adjacent `IFS' whitespace characters, delimits a field. A
1661 sequence of `IFS' whitespace characters is also treated as a delimiter.
1662 If the value of `IFS' is null, no word splitting occurs.
1664 Explicit null arguments (`""' or `''') are retained. Unquoted
1665 implicit null arguments, resulting from the expansion of parameters
1666 that have no values, are removed. If a parameter with no value is
1667 expanded within double quotes, a null argument results and is retained.
1669 Note that if no expansion occurs, no splitting is performed.
1672 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1674 3.5.8 Filename Expansion
1675 ------------------------
1679 * Pattern Matching:: How the shell matches patterns.
1681 After word splitting, unless the `-f' option has been set (*note The
1682 Set Builtin::), Bash scans each word for the characters `*', `?', and
1683 `['. If one of these characters appears, then the word is regarded as
1684 a PATTERN, and replaced with an alphabetically sorted list of file
1685 names matching the pattern. If no matching file names are found, and
1686 the shell option `nullglob' is disabled, the word is left unchanged.
1687 If the `nullglob' option is set, and no matches are found, the word is
1688 removed. If the `failglob' shell option is set, and no matches are
1689 found, an error message is printed and the command is not executed. If
1690 the shell option `nocaseglob' is enabled, the match is performed
1691 without regard to the case of alphabetic characters.
1693 When a pattern is used for filename expansion, the character `.' at
1694 the start of a filename or immediately following a slash must be
1695 matched explicitly, unless the shell option `dotglob' is set. When
1696 matching a file name, the slash character must always be matched
1697 explicitly. In other cases, the `.' character is not treated specially.
1699 See the description of `shopt' in *note The Shopt Builtin::, for a
1700 description of the `nocaseglob', `nullglob', `failglob', and `dotglob'
1703 The `GLOBIGNORE' shell variable may be used to restrict the set of
1704 filenames matching a pattern. If `GLOBIGNORE' is set, each matching
1705 filename that also matches one of the patterns in `GLOBIGNORE' is
1706 removed from the list of matches. The filenames `.' and `..' are
1707 always ignored when `GLOBIGNORE' is set and not null. However, setting
1708 `GLOBIGNORE' to a non-null value has the effect of enabling the
1709 `dotglob' shell option, so all other filenames beginning with a `.'
1710 will match. To get the old behavior of ignoring filenames beginning
1711 with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The
1712 `dotglob' option is disabled when `GLOBIGNORE' is unset.
1715 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1717 3.5.8.1 Pattern Matching
1718 ........................
1720 Any character that appears in a pattern, other than the special pattern
1721 characters described below, matches itself. The NUL character may not
1722 occur in a pattern. A backslash escapes the following character; the
1723 escaping backslash is discarded when matching. The special pattern
1724 characters must be quoted if they are to be matched literally.
1726 The special pattern characters have the following meanings:
1728 Matches any string, including the null string. When the
1729 `globstar' shell option is enabled, and `*' is used in a filename
1730 expansion context, two adjacent `*'s used as a single pattern will
1731 match all files and zero or more directories and subdirectories.
1732 If followed by a `/', two adjacent `*'s will match only
1733 directories and subdirectories.
1736 Matches any single character.
1739 Matches any one of the enclosed characters. A pair of characters
1740 separated by a hyphen denotes a RANGE EXPRESSION; any character
1741 that sorts between those two characters, inclusive, using the
1742 current locale's collating sequence and character set, is matched.
1743 If the first character following the `[' is a `!' or a `^' then
1744 any character not enclosed is matched. A `-' may be matched by
1745 including it as the first or last character in the set. A `]' may
1746 be matched by including it as the first character in the set. The
1747 sorting order of characters in range expressions is determined by
1748 the current locale and the value of the `LC_COLLATE' shell
1751 For example, in the default C locale, `[a-dx-z]' is equivalent to
1752 `[abcdxyz]'. Many locales sort characters in dictionary order,
1753 and in these locales `[a-dx-z]' is typically not equivalent to
1754 `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
1755 example. To obtain the traditional interpretation of ranges in
1756 bracket expressions, you can force the use of the C locale by
1757 setting the `LC_COLLATE' or `LC_ALL' environment variable to the
1760 Within `[' and `]', CHARACTER CLASSES can be specified using the
1761 syntax `[:'CLASS`:]', where CLASS is one of the following classes
1762 defined in the POSIX standard:
1763 alnum alpha ascii blank cntrl digit graph lower
1764 print punct space upper word xdigit
1765 A character class matches any character belonging to that class.
1766 The `word' character class matches letters, digits, and the
1769 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1770 the syntax `[='C`=]', which matches all characters with the same
1771 collation weight (as defined by the current locale) as the
1774 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
1775 collating symbol SYMBOL.
1777 If the `extglob' shell option is enabled using the `shopt' builtin,
1778 several extended pattern matching operators are recognized. In the
1779 following description, a PATTERN-LIST is a list of one or more patterns
1780 separated by a `|'. Composite patterns may be formed using one or more
1781 of the following sub-patterns:
1784 Matches zero or one occurrence of the given patterns.
1787 Matches zero or more occurrences of the given patterns.
1790 Matches one or more occurrences of the given patterns.
1793 Matches one of the given patterns.
1796 Matches anything except one of the given patterns.
1799 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1804 After the preceding expansions, all unquoted occurrences of the
1805 characters `\', `'', and `"' that did not result from one of the above
1806 expansions are removed.
1809 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1814 Before a command is executed, its input and output may be REDIRECTED
1815 using a special notation interpreted by the shell. Redirection may
1816 also be used to open and close files for the current shell execution
1817 environment. The following redirection operators may precede or appear
1818 anywhere within a simple command or may follow a command. Redirections
1819 are processed in the order they appear, from left to right.
1821 Each redirection that may be preceded by a file descriptor number
1822 may instead be preceded by a word of the form {VARNAME}. In this case,
1823 for each redirection operator except >&- and <&-, the shell will
1824 allocate a file descriptor greater than 10 and assign it to {VARNAME}.
1825 If >&- or <&- is preceded by {VARNAME}, the value of VARNAME defines
1826 the file descriptor to close.
1828 In the following descriptions, if the file descriptor number is
1829 omitted, and the first character of the redirection operator is `<',
1830 the redirection refers to the standard input (file descriptor 0). If
1831 the first character of the redirection operator is `>', the redirection
1832 refers to the standard output (file descriptor 1).
1834 The word following the redirection operator in the following
1835 descriptions, unless otherwise noted, is subjected to brace expansion,
1836 tilde expansion, parameter expansion, command substitution, arithmetic
1837 expansion, quote removal, filename expansion, and word splitting. If
1838 it expands to more than one word, Bash reports an error.
1840 Note that the order of redirections is significant. For example,
1843 directs both standard output (file descriptor 1) and standard error
1844 (file descriptor 2) to the file DIRLIST, while the command
1846 directs only the standard output to file DIRLIST, because the
1847 standard error was made a copy of the standard output before the
1848 standard output was redirected to DIRLIST.
1850 Bash handles several filenames specially when they are used in
1851 redirections, as described in the following table:
1854 If FD is a valid integer, file descriptor FD is duplicated.
1857 File descriptor 0 is duplicated.
1860 File descriptor 1 is duplicated.
1863 File descriptor 2 is duplicated.
1865 `/dev/tcp/HOST/PORT'
1866 If HOST is a valid hostname or Internet address, and PORT is an
1867 integer port number or service name, Bash attempts to open a TCP
1868 connection to the corresponding socket.
1870 `/dev/udp/HOST/PORT'
1871 If HOST is a valid hostname or Internet address, and PORT is an
1872 integer port number or service name, Bash attempts to open a UDP
1873 connection to the corresponding socket.
1876 A failure to open or create a file causes the redirection to fail.
1878 Redirections using file descriptors greater than 9 should be used
1879 with care, as they may conflict with file descriptors the shell uses
1882 3.6.1 Redirecting Input
1883 -----------------------
1885 Redirection of input causes the file whose name results from the
1886 expansion of WORD to be opened for reading on file descriptor `n', or
1887 the standard input (file descriptor 0) if `n' is not specified.
1889 The general format for redirecting input is:
1892 3.6.2 Redirecting Output
1893 ------------------------
1895 Redirection of output causes the file whose name results from the
1896 expansion of WORD to be opened for writing on file descriptor N, or the
1897 standard output (file descriptor 1) if N is not specified. If the file
1898 does not exist it is created; if it does exist it is truncated to zero
1901 The general format for redirecting output is:
1904 If the redirection operator is `>', and the `noclobber' option to
1905 the `set' builtin has been enabled, the redirection will fail if the
1906 file whose name results from the expansion of WORD exists and is a
1907 regular file. If the redirection operator is `>|', or the redirection
1908 operator is `>' and the `noclobber' option is not enabled, the
1909 redirection is attempted even if the file named by WORD exists.
1911 3.6.3 Appending Redirected Output
1912 ---------------------------------
1914 Redirection of output in this fashion causes the file whose name
1915 results from the expansion of WORD to be opened for appending on file
1916 descriptor N, or the standard output (file descriptor 1) if N is not
1917 specified. If the file does not exist it is created.
1919 The general format for appending output is:
1922 3.6.4 Redirecting Standard Output and Standard Error
1923 ----------------------------------------------------
1925 This construct allows both the standard output (file descriptor 1) and
1926 the standard error output (file descriptor 2) to be redirected to the
1927 file whose name is the expansion of WORD.
1929 There are two formats for redirecting standard output and standard
1934 Of the two forms, the first is preferred. This is semantically
1938 3.6.5 Appending Standard Output and Standard Error
1939 --------------------------------------------------
1941 This construct allows both the standard output (file descriptor 1) and
1942 the standard error output (file descriptor 2) to be appended to the
1943 file whose name is the expansion of WORD.
1945 The format for appending standard output and standard error is:
1947 This is semantically equivalent to
1950 3.6.6 Here Documents
1951 --------------------
1953 This type of redirection instructs the shell to read input from the
1954 current source until a line containing only WORD (with no trailing
1955 blanks) is seen. All of the lines read up to that point are then used
1956 as the standard input for a command.
1958 The format of here-documents is:
1963 No parameter expansion, command substitution, arithmetic expansion,
1964 or filename expansion is performed on WORD. If any characters in WORD
1965 are quoted, the DELIMITER is the result of quote removal on WORD, and
1966 the lines in the here-document are not expanded. If WORD is unquoted,
1967 all lines of the here-document are subjected to parameter expansion,
1968 command substitution, and arithmetic expansion. In the latter case,
1969 the character sequence `\newline' is ignored, and `\' must be used to
1970 quote the characters `\', `$', and ``'.
1972 If the redirection operator is `<<-', then all leading tab
1973 characters are stripped from input lines and the line containing
1974 DELIMITER. This allows here-documents within shell scripts to be
1975 indented in a natural fashion.
1980 A variant of here documents, the format is:
1983 The WORD is expanded and supplied to the command on its standard
1986 3.6.8 Duplicating File Descriptors
1987 ----------------------------------
1989 The redirection operator
1991 is used to duplicate input file descriptors. If WORD expands to one
1992 or more digits, the file descriptor denoted by N is made to be a copy
1993 of that file descriptor. If the digits in WORD do not specify a file
1994 descriptor open for input, a redirection error occurs. If WORD
1995 evaluates to `-', file descriptor N is closed. If N is not specified,
1996 the standard input (file descriptor 0) is used.
2000 is used similarly to duplicate output file descriptors. If N is not
2001 specified, the standard output (file descriptor 1) is used. If the
2002 digits in WORD do not specify a file descriptor open for output, a
2003 redirection error occurs. As a special case, if N is omitted, and WORD
2004 does not expand to one or more digits, the standard output and standard
2005 error are redirected as described previously.
2007 3.6.9 Moving File Descriptors
2008 -----------------------------
2010 The redirection operator
2012 moves the file descriptor DIGIT to file descriptor N, or the
2013 standard input (file descriptor 0) if N is not specified. DIGIT is
2014 closed after being duplicated to N.
2016 Similarly, the redirection operator
2018 moves the file descriptor DIGIT to file descriptor N, or the
2019 standard output (file descriptor 1) if N is not specified.
2021 3.6.10 Opening File Descriptors for Reading and Writing
2022 -------------------------------------------------------
2024 The redirection operator
2026 causes the file whose name is the expansion of WORD to be opened for
2027 both reading and writing on file descriptor N, or on file descriptor 0
2028 if N is not specified. If the file does not exist, it is created.
2031 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2033 3.7 Executing Commands
2034 ======================
2038 * Simple Command Expansion:: How Bash expands simple commands before
2040 * Command Search and Execution:: How Bash finds commands and runs them.
2041 * Command Execution Environment:: The environment in which Bash
2042 executes commands that are not
2044 * Environment:: The environment given to a command.
2045 * Exit Status:: The status returned by commands and how Bash
2047 * Signals:: What happens when Bash or a command it runs
2051 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2053 3.7.1 Simple Command Expansion
2054 ------------------------------
2056 When a simple command is executed, the shell performs the following
2057 expansions, assignments, and redirections, from left to right.
2059 1. The words that the parser has marked as variable assignments (those
2060 preceding the command name) and redirections are saved for later
2063 2. The words that are not variable assignments or redirections are
2064 expanded (*note Shell Expansions::). If any words remain after
2065 expansion, the first word is taken to be the name of the command
2066 and the remaining words are the arguments.
2068 3. Redirections are performed as described above (*note
2071 4. The text after the `=' in each variable assignment undergoes tilde
2072 expansion, parameter expansion, command substitution, arithmetic
2073 expansion, and quote removal before being assigned to the variable.
2075 If no command name results, the variable assignments affect the
2076 current shell environment. Otherwise, the variables are added to the
2077 environment of the executed command and do not affect the current shell
2078 environment. If any of the assignments attempts to assign a value to a
2079 readonly variable, an error occurs, and the command exits with a
2082 If no command name results, redirections are performed, but do not
2083 affect the current shell environment. A redirection error causes the
2084 command to exit with a non-zero status.
2086 If there is a command name left after expansion, execution proceeds
2087 as described below. Otherwise, the command exits. If one of the
2088 expansions contained a command substitution, the exit status of the
2089 command is the exit status of the last command substitution performed.
2090 If there were no command substitutions, the command exits with a status
2094 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2096 3.7.2 Command Search and Execution
2097 ----------------------------------
2099 After a command has been split into words, if it results in a simple
2100 command and an optional list of arguments, the following actions are
2103 1. If the command name contains no slashes, the shell attempts to
2104 locate it. If there exists a shell function by that name, that
2105 function is invoked as described in *note Shell Functions::.
2107 2. If the name does not match a function, the shell searches for it
2108 in the list of shell builtins. If a match is found, that builtin
2111 3. If the name is neither a shell function nor a builtin, and
2112 contains no slashes, Bash searches each element of `$PATH' for a
2113 directory containing an executable file by that name. Bash uses a
2114 hash table to remember the full pathnames of executable files to
2115 avoid multiple `PATH' searches (see the description of `hash' in
2116 *note Bourne Shell Builtins::). A full search of the directories
2117 in `$PATH' is performed only if the command is not found in the
2118 hash table. If the search is unsuccessful, the shell searches for
2119 a defined shell function named `command_not_found_handle'. If
2120 that function exists, it is invoked with the original command and
2121 the original command's arguments as its arguments, and the
2122 function's exit status becomes the exit status of the shell. If
2123 that function is not defined, the shell prints an error message
2124 and returns an exit status of 127.
2126 4. If the search is successful, or if the command name contains one
2127 or more slashes, the shell executes the named program in a
2128 separate execution environment. Argument 0 is set to the name
2129 given, and the remaining arguments to the command are set to the
2130 arguments supplied, if any.
2132 5. If this execution fails because the file is not in executable
2133 format, and the file is not a directory, it is assumed to be a
2134 SHELL SCRIPT and the shell executes it as described in *note Shell
2137 6. If the command was not begun asynchronously, the shell waits for
2138 the command to complete and collects its exit status.
2142 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2144 3.7.3 Command Execution Environment
2145 -----------------------------------
2147 The shell has an EXECUTION ENVIRONMENT, which consists of the following:
2149 * open files inherited by the shell at invocation, as modified by
2150 redirections supplied to the `exec' builtin
2152 * the current working directory as set by `cd', `pushd', or `popd',
2153 or inherited by the shell at invocation
2155 * the file creation mode mask as set by `umask' or inherited from
2158 * current traps set by `trap'
2160 * shell parameters that are set by variable assignment or with `set'
2161 or inherited from the shell's parent in the environment
2163 * shell functions defined during execution or inherited from the
2164 shell's parent in the environment
2166 * options enabled at invocation (either by default or with
2167 command-line arguments) or by `set'
2169 * options enabled by `shopt' (*note The Shopt Builtin::)
2171 * shell aliases defined with `alias' (*note Aliases::)
2173 * various process IDs, including those of background jobs (*note
2174 Lists::), the value of `$$', and the value of `$PPID'
2177 When a simple command other than a builtin or shell function is to
2178 be executed, it is invoked in a separate execution environment that
2179 consists of the following. Unless otherwise noted, the values are
2180 inherited from the shell.
2182 * the shell's open files, plus any modifications and additions
2183 specified by redirections to the command
2185 * the current working directory
2187 * the file creation mode mask
2189 * shell variables and functions marked for export, along with
2190 variables exported for the command, passed in the environment
2191 (*note Environment::)
2193 * traps caught by the shell are reset to the values inherited from
2194 the shell's parent, and traps ignored by the shell are ignored
2197 A command invoked in this separate environment cannot affect the
2198 shell's execution environment.
2200 Command substitution, commands grouped with parentheses, and
2201 asynchronous commands are invoked in a subshell environment that is a
2202 duplicate of the shell environment, except that traps caught by the
2203 shell are reset to the values that the shell inherited from its parent
2204 at invocation. Builtin commands that are invoked as part of a pipeline
2205 are also executed in a subshell environment. Changes made to the
2206 subshell environment cannot affect the shell's execution environment.
2208 Subshells spawned to execute command substitutions inherit the value
2209 of the `-e' option from the parent shell. When not in POSIX mode, Bash
2210 clears the `-e' option in such subshells.
2212 If a command is followed by a `&' and job control is not active, the
2213 default standard input for the command is the empty file `/dev/null'.
2214 Otherwise, the invoked command inherits the file descriptors of the
2215 calling shell as modified by redirections.
2218 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2223 When a program is invoked it is given an array of strings called the
2224 ENVIRONMENT. This is a list of name-value pairs, of the form
2227 Bash provides several ways to manipulate the environment. On
2228 invocation, the shell scans its own environment and creates a parameter
2229 for each name found, automatically marking it for EXPORT to child
2230 processes. Executed commands inherit the environment. The `export'
2231 and `declare -x' commands allow parameters and functions to be added to
2232 and deleted from the environment. If the value of a parameter in the
2233 environment is modified, the new value becomes part of the environment,
2234 replacing the old. The environment inherited by any executed command
2235 consists of the shell's initial environment, whose values may be
2236 modified in the shell, less any pairs removed by the `unset' and
2237 `export -n' commands, plus any additions via the `export' and `declare
2240 The environment for any simple command or function may be augmented
2241 temporarily by prefixing it with parameter assignments, as described in
2242 *note Shell Parameters::. These assignment statements affect only the
2243 environment seen by that command.
2245 If the `-k' option is set (*note The Set Builtin::), then all
2246 parameter assignments are placed in the environment for a command, not
2247 just those that precede the command name.
2249 When Bash invokes an external command, the variable `$_' is set to
2250 the full path name of the command and passed to that command in its
2254 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2259 The exit status of an executed command is the value returned by the
2260 WAITPID system call or equivalent function. Exit statuses fall between
2261 0 and 255, though, as explained below, the shell may use values above
2262 125 specially. Exit statuses from shell builtins and compound commands
2263 are also limited to this range. Under certain circumstances, the shell
2264 will use special values to indicate specific failure modes.
2266 For the shell's purposes, a command which exits with a zero exit
2267 status has succeeded. A non-zero exit status indicates failure. This
2268 seemingly counter-intuitive scheme is used so there is one well-defined
2269 way to indicate success and a variety of ways to indicate various
2270 failure modes. When a command terminates on a fatal signal whose
2271 number is N, Bash uses the value 128+N as the exit status.
2273 If a command is not found, the child process created to execute it
2274 returns a status of 127. If a command is found but is not executable,
2275 the return status is 126.
2277 If a command fails because of an error during expansion or
2278 redirection, the exit status is greater than zero.
2280 The exit status is used by the Bash conditional commands (*note
2281 Conditional Constructs::) and some of the list constructs (*note
2284 All of the Bash builtins return an exit status of zero if they
2285 succeed and a non-zero status on failure, so they may be used by the
2286 conditional and list constructs. All builtins return an exit status of
2287 2 to indicate incorrect usage.
2290 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2295 When Bash is interactive, in the absence of any traps, it ignores
2296 `SIGTERM' (so that `kill 0' does not kill an interactive shell), and
2297 `SIGINT' is caught and handled (so that the `wait' builtin is
2298 interruptible). When Bash receives a `SIGINT', it breaks out of any
2299 executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
2300 is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
2303 Non-builtin commands started by Bash have signal handlers set to the
2304 values inherited by the shell from its parent. When job control is not
2305 in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in
2306 addition to these inherited handlers. Commands run as a result of
2307 command substitution ignore the keyboard-generated job control signals
2308 `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
2310 The shell exits by default upon receipt of a `SIGHUP'. Before
2311 exiting, an interactive shell resends the `SIGHUP' to all jobs, running
2312 or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive
2313 the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to
2314 a particular job, it should be removed from the jobs table with the
2315 `disown' builtin (*note Job Control Builtins::) or marked to not
2316 receive `SIGHUP' using `disown -h'.
2318 If the `huponexit' shell option has been set with `shopt' (*note
2319 The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an
2320 interactive login shell exits.
2322 If Bash is waiting for a command to complete and receives a signal
2323 for which a trap has been set, the trap will not be executed until the
2324 command completes. When Bash is waiting for an asynchronous command
2325 via the `wait' builtin, the reception of a signal for which a trap has
2326 been set will cause the `wait' builtin to return immediately with an
2327 exit status greater than 128, immediately after which the trap is
2331 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2336 A shell script is a text file containing shell commands. When such a
2337 file is used as the first non-option argument when invoking Bash, and
2338 neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
2339 Bash reads and executes commands from the file, then exits. This mode
2340 of operation creates a non-interactive shell. The shell first searches
2341 for the file in the current directory, and looks in the directories in
2342 `$PATH' if not found there.
2344 When Bash runs a shell script, it sets the special parameter `0' to
2345 the name of the file, rather than the name of the shell, and the
2346 positional parameters are set to the remaining arguments, if any are
2347 given. If no additional arguments are supplied, the positional
2348 parameters are unset.
2350 A shell script may be made executable by using the `chmod' command
2351 to turn on the execute bit. When Bash finds such a file while
2352 searching the `$PATH' for a command, it spawns a subshell to execute
2353 it. In other words, executing
2355 is equivalent to executing
2356 bash filename ARGUMENTS
2358 if `filename' is an executable shell script. This subshell
2359 reinitializes itself, so that the effect is as if a new shell had been
2360 invoked to interpret the script, with the exception that the locations
2361 of commands remembered by the parent (see the description of `hash' in
2362 *note Bourne Shell Builtins::) are retained by the child.
2364 Most versions of Unix make this a part of the operating system's
2365 command execution mechanism. If the first line of a script begins with
2366 the two characters `#!', the remainder of the line specifies an
2367 interpreter for the program. Thus, you can specify Bash, `awk', Perl,
2368 or some other interpreter and write the rest of the script file in that
2371 The arguments to the interpreter consist of a single optional
2372 argument following the interpreter name on the first line of the script
2373 file, followed by the name of the script file, followed by the rest of
2374 the arguments. Bash will perform this action on operating systems that
2375 do not handle it themselves. Note that some older versions of Unix
2376 limit the interpreter name and argument to a maximum of 32 characters.
2378 Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
2379 been installed in `/bin'), since this ensures that Bash will be used to
2380 interpret the script, even if it is executed under another shell.
2383 File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
2385 4 Shell Builtin Commands
2386 ************************
2390 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2392 * Bash Builtins:: Table of builtins specific to Bash.
2393 * Modifying Shell Behavior:: Builtins to modify shell attributes and
2395 * Special Builtins:: Builtin commands classified specially by
2398 Builtin commands are contained within the shell itself. When the
2399 name of a builtin command is used as the first word of a simple command
2400 (*note Simple Commands::), the shell executes the command directly,
2401 without invoking another program. Builtin commands are necessary to
2402 implement functionality impossible or inconvenient to obtain with
2405 This section briefly describes the builtins which Bash inherits from
2406 the Bourne Shell, as well as the builtin commands which are unique to
2407 or have been extended in Bash.
2409 Several builtin commands are described in other chapters: builtin
2410 commands which provide the Bash interface to the job control facilities
2411 (*note Job Control Builtins::), the directory stack (*note Directory
2412 Stack Builtins::), the command history (*note Bash History Builtins::),
2413 and the programmable completion facilities (*note Programmable
2414 Completion Builtins::).
2416 Many of the builtins have been extended by POSIX or Bash.
2418 Unless otherwise noted, each builtin command documented as accepting
2419 options preceded by `-' accepts `--' to signify the end of the options.
2420 The `:', `true', `false', and `test' builtins do not accept options and
2421 do not treat `--' specially. The `exit', `logout', `break',
2422 `continue', `let', and `shift' builtins accept and process arguments
2423 beginning with `-' without requiring `--'. Other builtins that accept
2424 arguments but are not specified as accepting options interpret
2425 arguments beginning with `-' as invalid options and require `--' to
2426 prevent this interpretation.
2429 File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
2431 4.1 Bourne Shell Builtins
2432 =========================
2434 The following shell builtin commands are inherited from the Bourne
2435 Shell. These commands are implemented as specified by the POSIX
2440 Do nothing beyond expanding ARGUMENTS and performing redirections.
2441 The return status is zero.
2444 . FILENAME [ARGUMENTS]
2445 Read and execute commands from the FILENAME argument in the
2446 current shell context. If FILENAME does not contain a slash, the
2447 `PATH' variable is used to find FILENAME. When Bash is not in
2448 POSIX mode, the current directory is searched if FILENAME is not
2449 found in `$PATH'. If any ARGUMENTS are supplied, they become the
2450 positional parameters when FILENAME is executed. Otherwise the
2451 positional parameters are unchanged. The return status is the
2452 exit status of the last command executed, or zero if no commands
2453 are executed. If FILENAME is not found, or cannot be read, the
2454 return status is non-zero. This builtin is equivalent to `source'.
2458 Exit from a `for', `while', `until', or `select' loop. If N is
2459 supplied, the Nth enclosing loop is exited. N must be greater
2460 than or equal to 1. The return status is zero unless N is not
2461 greater than or equal to 1.
2464 cd [-L|-P] [DIRECTORY]
2465 Change the current working directory to DIRECTORY. If DIRECTORY
2466 is not given, the value of the `HOME' shell variable is used. If
2467 the shell variable `CDPATH' exists, it is used as a search path.
2468 If DIRECTORY begins with a slash, `CDPATH' is not used.
2470 The `-P' option means to not follow symbolic links; symbolic links
2471 are followed by default or with the `-L' option. If DIRECTORY is
2472 `-', it is equivalent to `$OLDPWD'.
2474 If a non-empty directory name from `CDPATH' is used, or if `-' is
2475 the first argument, and the directory change is successful, the
2476 absolute pathname of the new working directory is written to the
2479 The return status is zero if the directory is successfully changed,
2484 Resume the next iteration of an enclosing `for', `while', `until',
2485 or `select' loop. If N is supplied, the execution of the Nth
2486 enclosing loop is resumed. N must be greater than or equal to 1.
2487 The return status is zero unless N is not greater than or equal to
2492 The arguments are concatenated together into a single command,
2493 which is then read and executed, and its exit status returned as
2494 the exit status of `eval'. If there are no arguments or only
2495 empty arguments, the return status is zero.
2498 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2499 If COMMAND is supplied, it replaces the shell without creating a
2500 new process. If the `-l' option is supplied, the shell places a
2501 dash at the beginning of the zeroth argument passed to COMMAND.
2502 This is what the `login' program does. The `-c' option causes
2503 COMMAND to be executed with an empty environment. If `-a' is
2504 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2505 If no COMMAND is specified, redirections may be used to affect the
2506 current shell environment. If there are no redirection errors, the
2507 return status is zero; otherwise the return status is non-zero.
2511 Exit the shell, returning a status of N to the shell's parent. If
2512 N is omitted, the exit status is that of the last command executed.
2513 Any trap on `EXIT' is executed before the shell terminates.
2516 export [-fn] [-p] [NAME[=VALUE]]
2517 Mark each NAME to be passed to child processes in the environment.
2518 If the `-f' option is supplied, the NAMEs refer to shell
2519 functions; otherwise the names refer to shell variables. The `-n'
2520 option means to no longer mark each NAME for export. If no NAMES
2521 are supplied, or if the `-p' option is given, a list of exported
2522 names is displayed. The `-p' option displays output in a form
2523 that may be reused as input. If a variable name is followed by
2524 =VALUE, the value of the variable is set to VALUE.
2526 The return status is zero unless an invalid option is supplied,
2527 one of the names is not a valid shell variable name, or `-f' is
2528 supplied with a name that is not a shell function.
2531 getopts OPTSTRING NAME [ARGS]
2532 `getopts' is used by shell scripts to parse positional parameters.
2533 OPTSTRING contains the option characters to be recognized; if a
2534 character is followed by a colon, the option is expected to have an
2535 argument, which should be separated from it by white space. The
2536 colon (`:') and question mark (`?') may not be used as option
2537 characters. Each time it is invoked, `getopts' places the next
2538 option in the shell variable NAME, initializing NAME if it does
2539 not exist, and the index of the next argument to be processed into
2540 the variable `OPTIND'. `OPTIND' is initialized to 1 each time the
2541 shell or a shell script is invoked. When an option requires an
2542 argument, `getopts' places that argument into the variable
2543 `OPTARG'. The shell does not reset `OPTIND' automatically; it
2544 must be manually reset between multiple calls to `getopts' within
2545 the same shell invocation if a new set of parameters is to be used.
2547 When the end of options is encountered, `getopts' exits with a
2548 return value greater than zero. `OPTIND' is set to the index of
2549 the first non-option argument, and `name' is set to `?'.
2551 `getopts' normally parses the positional parameters, but if more
2552 arguments are given in ARGS, `getopts' parses those instead.
2554 `getopts' can report errors in two ways. If the first character of
2555 OPTSTRING is a colon, SILENT error reporting is used. In normal
2556 operation diagnostic messages are printed when invalid options or
2557 missing option arguments are encountered. If the variable `OPTERR'
2558 is set to 0, no error messages will be displayed, even if the first
2559 character of `optstring' is not a colon.
2561 If an invalid option is seen, `getopts' places `?' into NAME and,
2562 if not silent, prints an error message and unsets `OPTARG'. If
2563 `getopts' is silent, the option character found is placed in
2564 `OPTARG' and no diagnostic message is printed.
2566 If a required argument is not found, and `getopts' is not silent,
2567 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2568 diagnostic message is printed. If `getopts' is silent, then a
2569 colon (`:') is placed in NAME and `OPTARG' is set to the option
2573 hash [-r] [-p FILENAME] [-dt] [NAME]
2574 Remember the full pathnames of commands specified as NAME
2575 arguments, so they need not be searched for on subsequent
2576 invocations. The commands are found by searching through the
2577 directories listed in `$PATH'. The `-p' option inhibits the path
2578 search, and FILENAME is used as the location of NAME. The `-r'
2579 option causes the shell to forget all remembered locations. The
2580 `-d' option causes the shell to forget the remembered location of
2581 each NAME. If the `-t' option is supplied, the full pathname to
2582 which each NAME corresponds is printed. If multiple NAME
2583 arguments are supplied with `-t' the NAME is printed before the
2584 hashed full pathname. The `-l' option causes output to be
2585 displayed in a format that may be reused as input. If no
2586 arguments are given, or if only `-l' is supplied, information
2587 about remembered commands is printed. The return status is zero
2588 unless a NAME is not found or an invalid option is supplied.
2592 Print the absolute pathname of the current working directory. If
2593 the `-P' option is supplied, the pathname printed will not contain
2594 symbolic links. If the `-L' option is supplied, the pathname
2595 printed may contain symbolic links. The return status is zero
2596 unless an error is encountered while determining the name of the
2597 current directory or an invalid option is supplied.
2600 readonly [-aApf] [NAME[=VALUE]] ...
2601 Mark each NAME as readonly. The values of these names may not be
2602 changed by subsequent assignment. If the `-f' option is supplied,
2603 each NAME refers to a shell function. The `-a' option means each
2604 NAME refers to an indexed array variable; the `-A' option means
2605 each NAME refers to an associative array variable. If no NAME
2606 arguments are given, or if the `-p' option is supplied, a list of
2607 all readonly names is printed. The `-p' option causes output to
2608 be displayed in a format that may be reused as input. If a
2609 variable name is followed by =VALUE, the value of the variable is
2610 set to VALUE. The return status is zero unless an invalid option
2611 is supplied, one of the NAME arguments is not a valid shell
2612 variable or function name, or the `-f' option is supplied with a
2613 name that is not a shell function.
2617 Cause a shell function to exit with the return value N. If N is
2618 not supplied, the return value is the exit status of the last
2619 command executed in the function. This may also be used to
2620 terminate execution of a script being executed with the `.' (or
2621 `source') builtin, returning either N or the exit status of the
2622 last command executed within the script as the exit status of the
2623 script. Any command associated with the `RETURN' trap is executed
2624 before execution resumes after the function or script. The return
2625 status is non-zero if `return' is used outside a function and not
2626 during the execution of a script by `.' or `source'.
2630 Shift the positional parameters to the left by N. The positional
2631 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
2632 Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
2633 N must be a non-negative number less than or equal to `$#'. If N
2634 is zero or greater than `$#', the positional parameters are not
2635 changed. If N is not supplied, it is assumed to be 1. The return
2636 status is zero unless N is greater than `$#' or less than zero,
2641 Evaluate a conditional expression EXPR. Each operator and operand
2642 must be a separate argument. Expressions are composed of the
2643 primaries described below in *note Bash Conditional Expressions::.
2644 `test' does not accept any options, nor does it accept and ignore
2645 an argument of `--' as signifying the end of options.
2647 When the `[' form is used, the last argument to the command must
2650 Expressions may be combined using the following operators, listed
2651 in decreasing order of precedence. The evaluation depends on the
2652 number of arguments; see below.
2655 True if EXPR is false.
2658 Returns the value of EXPR. This may be used to override the
2659 normal precedence of operators.
2662 True if both EXPR1 and EXPR2 are true.
2665 True if either EXPR1 or EXPR2 is true.
2667 The `test' and `[' builtins evaluate conditional expressions using
2668 a set of rules based on the number of arguments.
2671 The expression is false.
2674 The expression is true if and only if the argument is not
2678 If the first argument is `!', the expression is true if and
2679 only if the second argument is null. If the first argument
2680 is one of the unary conditional operators (*note Bash
2681 Conditional Expressions::), the expression is true if the
2682 unary test is true. If the first argument is not a valid
2683 unary operator, the expression is false.
2686 If the second argument is one of the binary conditional
2687 operators (*note Bash Conditional Expressions::), the result
2688 of the expression is the result of the binary test using the
2689 first and third arguments as operands. The `-a' and `-o'
2690 operators are considered binary operators when there are
2691 three arguments. If the first argument is `!', the value is
2692 the negation of the two-argument test using the second and
2693 third arguments. If the first argument is exactly `(' and
2694 the third argument is exactly `)', the result is the
2695 one-argument test of the second argument. Otherwise, the
2696 expression is false.
2699 If the first argument is `!', the result is the negation of
2700 the three-argument expression composed of the remaining
2701 arguments. Otherwise, the expression is parsed and evaluated
2702 according to precedence using the rules listed above.
2705 The expression is parsed and evaluated according to precedence
2706 using the rules listed above.
2710 Print out the user and system times used by the shell and its
2711 children. The return status is zero.
2714 trap [-lp] [ARG] [SIGSPEC ...]
2715 The commands in ARG are to be read and executed when the shell
2716 receives signal SIGSPEC. If ARG is absent (and there is a single
2717 SIGSPEC) or equal to `-', each specified signal's disposition is
2718 reset to the value it had when the shell was started. If ARG is
2719 the null string, then the signal specified by each SIGSPEC is
2720 ignored by the shell and commands it invokes. If ARG is not
2721 present and `-p' has been supplied, the shell displays the trap
2722 commands associated with each SIGSPEC. If no arguments are
2723 supplied, or only `-p' is given, `trap' prints the list of commands
2724 associated with each signal number in a form that may be reused as
2725 shell input. The `-l' option causes the shell to print a list of
2726 signal names and their corresponding numbers. Each SIGSPEC is
2727 either a signal name or a signal number. Signal names are case
2728 insensitive and the `SIG' prefix is optional.
2730 If a SIGSPEC is `0' or `EXIT', ARG is executed when the shell
2731 exits. If a SIGSPEC is `DEBUG', the command ARG is executed
2732 before every simple command, `for' command, `case' command,
2733 `select' command, every arithmetic `for' command, and before the
2734 first command executes in a shell function. Refer to the
2735 description of the `extdebug' option to the `shopt' builtin (*note
2736 The Shopt Builtin::) for details of its effect on the `DEBUG' trap.
2737 If a SIGSPEC is `RETURN', the command ARG is executed each time a
2738 shell function or a script executed with the `.' or `source'
2739 builtins finishes executing.
2741 If a SIGSPEC is `ERR', the command ARG is executed whenever a
2742 simple command has a non-zero exit status, subject to the
2743 following conditions. The `ERR' trap is not executed if the
2744 failed command is part of the command list immediately following
2745 an `until' or `while' keyword, part of the test following the `if'
2746 or `elif' reserved words, part of a command executed in a `&&' or
2747 `||' list, or if the command's return status is being inverted
2748 using `!'. These are the same conditions obeyed by the `errexit'
2751 Signals ignored upon entry to the shell cannot be trapped or reset.
2752 Trapped signals that are not being ignored are reset to their
2753 original values in a subshell or subshell environment when one is
2756 The return status is zero unless a SIGSPEC does not specify a
2760 umask [-p] [-S] [MODE]
2761 Set the shell process's file creation mask to MODE. If MODE
2762 begins with a digit, it is interpreted as an octal number; if not,
2763 it is interpreted as a symbolic mode mask similar to that accepted
2764 by the `chmod' command. If MODE is omitted, the current value of
2765 the mask is printed. If the `-S' option is supplied without a
2766 MODE argument, the mask is printed in a symbolic format. If the
2767 `-p' option is supplied, and MODE is omitted, the output is in a
2768 form that may be reused as input. The return status is zero if
2769 the mode is successfully changed or if no MODE argument is
2770 supplied, and non-zero otherwise.
2772 Note that when the mode is interpreted as an octal number, each
2773 number of the umask is subtracted from `7'. Thus, a umask of `022'
2774 results in permissions of `755'.
2778 Each variable or function NAME is removed. If no options are
2779 supplied, or the `-v' option is given, each NAME refers to a shell
2780 variable. If the `-f' option is given, the NAMEs refer to shell
2781 functions, and the function definition is removed. Readonly
2782 variables and functions may not be unset. The return status is
2783 zero unless a NAME is readonly.
2786 File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
2788 4.2 Bash Builtin Commands
2789 =========================
2791 This section describes builtin commands which are unique to or have
2792 been extended in Bash. Some of these commands are specified in the
2796 alias [`-p'] [NAME[=VALUE] ...]
2798 Without arguments or with the `-p' option, `alias' prints the list
2799 of aliases on the standard output in a form that allows them to be
2800 reused as input. If arguments are supplied, an alias is defined
2801 for each NAME whose VALUE is given. If no VALUE is given, the name
2802 and value of the alias is printed. Aliases are described in *note
2806 bind [-m KEYMAP] [-lpsvPSV]
2807 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2808 bind [-m KEYMAP] -f FILENAME
2809 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
2810 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
2811 bind READLINE-COMMAND
2813 Display current Readline (*note Command Line Editing::) key and
2814 function bindings, bind a key sequence to a Readline function or
2815 macro, or set a Readline variable. Each non-option argument is a
2816 command as it would appear in a Readline initialization file
2817 (*note Readline Init File::), but each binding or command must be
2818 passed as a separate argument; e.g.,
2819 `"\C-x\C-r":re-read-init-file'.
2821 Options, if supplied, have the following meanings:
2824 Use KEYMAP as the keymap to be affected by the subsequent
2825 bindings. Acceptable KEYMAP names are `emacs',
2826 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
2827 `vi-command', and `vi-insert'. `vi' is equivalent to
2828 `vi-command'; `emacs' is equivalent to `emacs-standard'.
2831 List the names of all Readline functions.
2834 Display Readline function names and bindings in such a way
2835 that they can be used as input or in a Readline
2836 initialization file.
2839 List current Readline function names and bindings.
2842 Display Readline variable names and values in such a way that
2843 they can be used as input or in a Readline initialization
2847 List current Readline variable names and values.
2850 Display Readline key sequences bound to macros and the
2851 strings they output in such a way that they can be used as
2852 input or in a Readline initialization file.
2855 Display Readline key sequences bound to macros and the
2856 strings they output.
2859 Read key bindings from FILENAME.
2862 Query about which keys invoke the named FUNCTION.
2865 Unbind all keys bound to the named FUNCTION.
2868 Remove any current binding for KEYSEQ.
2870 `-x KEYSEQ:SHELL-COMMAND'
2871 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
2872 When SHELL-COMMAND is executed, the shell sets the
2873 `READLINE_LINE' variable to the contents of the Readline line
2874 buffer and the `READLINE_POINT' variable to the current
2875 location of the insertion point. If the executed command
2876 changes the value of `READLINE_LINE' or `READLINE_POINT',
2877 those new values will be reflected in the editing state.
2879 The return status is zero unless an invalid option is supplied or
2883 builtin [SHELL-BUILTIN [ARGS]]
2884 Run a shell builtin, passing it ARGS, and return its exit status.
2885 This is useful when defining a shell function with the same name
2886 as a shell builtin, retaining the functionality of the builtin
2887 within the function. The return status is non-zero if
2888 SHELL-BUILTIN is not a shell builtin command.
2892 Returns the context of any active subroutine call (a shell
2893 function or a script executed with the `.' or `source' builtins).
2895 Without EXPR, `caller' displays the line number and source
2896 filename of the current subroutine call. If a non-negative
2897 integer is supplied as EXPR, `caller' displays the line number,
2898 subroutine name, and source file corresponding to that position in
2899 the current execution call stack. This extra information may be
2900 used, for example, to print a stack trace. The current frame is
2903 The return value is 0 unless the shell is not executing a
2904 subroutine call or EXPR does not correspond to a valid position in
2908 command [-pVv] COMMAND [ARGUMENTS ...]
2909 Runs COMMAND with ARGUMENTS ignoring any shell function named
2910 COMMAND. Only shell builtin commands or commands found by
2911 searching the `PATH' are executed. If there is a shell function
2912 named `ls', running `command ls' within the function will execute
2913 the external command `ls' instead of calling the function
2914 recursively. The `-p' option means to use a default value for
2915 `PATH' that is guaranteed to find all of the standard utilities.
2916 The return status in this case is 127 if COMMAND cannot be found
2917 or an error occurred, and the exit status of COMMAND otherwise.
2919 If either the `-V' or `-v' option is supplied, a description of
2920 COMMAND is printed. The `-v' option causes a single word
2921 indicating the command or file name used to invoke COMMAND to be
2922 displayed; the `-V' option produces a more verbose description.
2923 In this case, the return status is zero if COMMAND is found, and
2927 declare [-aAfFilrtux] [-p] [NAME[=VALUE] ...]
2929 Declare variables and give them attributes. If no NAMEs are
2930 given, then display the values of variables instead.
2932 The `-p' option will display the attributes and values of each
2933 NAME. When `-p' is used with NAME arguments, additional options
2936 When `-p' is supplied without NAME arguments, `declare' will
2937 display the attributes and values of all variables having the
2938 attributes specified by the additional options. If no other
2939 options are supplied with `-p', `declare' will display the
2940 attributes and values of all shell variables. The `-f' option
2941 will restrict the display to shell functions.
2943 The `-F' option inhibits the display of function definitions; only
2944 the function name and attributes are printed. If the `extdebug'
2945 shell option is enabled using `shopt' (*note The Shopt Builtin::),
2946 the source file name and line number where the function is defined
2947 are displayed as well. `-F' implies `-f'. The following options
2948 can be used to restrict output to variables with the specified
2949 attributes or to give variables attributes:
2952 Each NAME is an indexed array variable (*note Arrays::).
2955 Each NAME is an associative array variable (*note Arrays::).
2958 Use function names only.
2961 The variable is to be treated as an integer; arithmetic
2962 evaluation (*note Shell Arithmetic::) is performed when the
2963 variable is assigned a value.
2966 When the variable is assigned a value, all upper-case
2967 characters are converted to lower-case. The upper-case
2968 attribute is disabled.
2971 Make NAMEs readonly. These names cannot then be assigned
2972 values by subsequent assignment statements or unset.
2975 Give each NAME the `trace' attribute. Traced functions
2976 inherit the `DEBUG' and `RETURN' traps from the calling shell.
2977 The trace attribute has no special meaning for variables.
2980 When the variable is assigned a value, all lower-case
2981 characters are converted to upper-case. The lower-case
2982 attribute is disabled.
2985 Mark each NAME for export to subsequent commands via the
2988 Using `+' instead of `-' turns off the attribute instead, with the
2989 exceptions that `+a' may not be used to destroy an array variable
2990 and `+r' will not remove the readonly attribute. When used in a
2991 function, `declare' makes each NAME local, as with the `local'
2992 command. If a variable name is followed by =VALUE, the value of
2993 the variable is set to VALUE.
2995 The return status is zero unless an invalid option is encountered,
2996 an attempt is made to define a function using `-f foo=bar', an
2997 attempt is made to assign a value to a readonly variable, an
2998 attempt is made to assign a value to an array variable without
2999 using the compound assignment syntax (*note Arrays::), one of the
3000 NAMES is not a valid shell variable name, an attempt is made to
3001 turn off readonly status for a readonly variable, an attempt is
3002 made to turn off array status for an array variable, or an attempt
3003 is made to display a non-existent function with `-f'.
3006 echo [-neE] [ARG ...]
3007 Output the ARGs, separated by spaces, terminated with a newline.
3008 The return status is always 0. If `-n' is specified, the trailing
3009 newline is suppressed. If the `-e' option is given,
3010 interpretation of the following backslash-escaped characters is
3011 enabled. The `-E' option disables the interpretation of these
3012 escape characters, even on systems where they are interpreted by
3013 default. The `xpg_echo' shell option may be used to dynamically
3014 determine whether or not `echo' expands these escape characters by
3015 default. `echo' does not interpret `--' to mean the end of
3018 `echo' interprets the following escape sequences:
3026 suppress further output
3050 the eight-bit character whose value is the octal value NNN
3051 (zero to three octal digits)
3054 the eight-bit character whose value is the hexadecimal value
3055 HH (one or two hex digits)
3058 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3059 Enable and disable builtin shell commands. Disabling a builtin
3060 allows a disk command which has the same name as a shell builtin
3061 to be executed without specifying a full pathname, even though the
3062 shell normally searches for builtins before disk commands. If
3063 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3064 enabled. For example, to use the `test' binary found via `$PATH'
3065 instead of the shell builtin version, type `enable -n test'.
3067 If the `-p' option is supplied, or no NAME arguments appear, a
3068 list of shell builtins is printed. With no other arguments, the
3069 list consists of all enabled shell builtins. The `-a' option
3070 means to list each builtin with an indication of whether or not it
3073 The `-f' option means to load the new builtin command NAME from
3074 shared object FILENAME, on systems that support dynamic loading.
3075 The `-d' option will delete a builtin loaded with `-f'.
3077 If there are no options, a list of the shell builtins is displayed.
3078 The `-s' option restricts `enable' to the POSIX special builtins.
3079 If `-s' is used with `-f', the new builtin becomes a special
3080 builtin (*note Special Builtins::).
3082 The return status is zero unless a NAME is not a shell builtin or
3083 there is an error loading a new builtin from a shared object.
3086 help [-dms] [PATTERN]
3087 Display helpful information about builtin commands. If PATTERN is
3088 specified, `help' gives detailed help on all commands matching
3089 PATTERN, otherwise a list of the builtins is printed.
3091 Options, if supplied, have the following meanings:
3094 Display a short description of each PATTERN
3097 Display the description of each PATTERN in a manpage-like
3101 Display only a short usage synopsis for each PATTERN
3103 The return status is zero unless no command matches PATTERN.
3106 let EXPRESSION [EXPRESSION]
3107 The `let' builtin allows arithmetic to be performed on shell
3108 variables. Each EXPRESSION is evaluated according to the rules
3109 given below in *note Shell Arithmetic::. If the last EXPRESSION
3110 evaluates to 0, `let' returns 1; otherwise 0 is returned.
3113 local [OPTION] NAME[=VALUE] ...
3114 For each argument, a local variable named NAME is created, and
3115 assigned VALUE. The OPTION can be any of the options accepted by
3116 `declare'. `local' can only be used within a function; it makes
3117 the variable NAME have a visible scope restricted to that function
3118 and its children. The return status is zero unless `local' is
3119 used outside a function, an invalid NAME is supplied, or NAME is a
3124 Exit a login shell, returning a status of N to the shell's parent.
3127 mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3128 -C CALLBACK] [-c QUANTUM] [ARRAY]
3129 Read lines from the standard input into the indexed array variable
3130 ARRAY, or from file descriptor FD if the `-u' option is supplied.
3131 The variable `MAPFILE' is the default ARRAY. Options, if
3132 supplied, have the following meanings:
3134 Copy at most COUNT lines. If COUNT is 0, all lines are
3138 Begin assigning to ARRAY at index ORIGIN. The default index
3142 Discard the first COUNT lines read.
3145 Remove a trailing newline from each line read.
3148 Read lines from file descriptor FD instead of the standard
3152 Evaluate CALLBACK each time QUANTUMP lines are read. The
3153 `-c' option specifies QUANTUM.
3156 Specify the number of lines read between each call to
3159 If `-C' is specified without `-c', the default quantum is 5000.
3160 When CALLBACK is evaluated, it is supplied the index of the next
3161 array element to be assigned as an additional argument. CALLBACK
3162 is evaluated after the line is read but before the array element
3165 If not supplied with an explicit origin, `mapfile' will clear ARRAY
3166 before assigning to it.
3168 `mapfile' returns successfully unless an invalid option or option
3169 argument is supplied, ARRAY is invalid or unassignable, or ARRAY
3170 is not an indexed array.
3173 printf [-v VAR] FORMAT [ARGUMENTS]
3174 Write the formatted ARGUMENTS to the standard output under the
3175 control of the FORMAT. The FORMAT is a character string which
3176 contains three types of objects: plain characters, which are
3177 simply copied to standard output, character escape sequences,
3178 which are converted and copied to the standard output, and format
3179 specifications, each of which causes printing of the next
3180 successive ARGUMENT. In addition to the standard `printf(1)'
3181 formats, `%b' causes `printf' to expand backslash escape sequences
3182 in the corresponding ARGUMENT, (except that `\c' terminates
3183 output, backslashes in `\'', `\"', and `\?' are not removed, and
3184 octal escapes beginning with `\0' may contain up to four digits),
3185 and `%q' causes `printf' to output the corresponding ARGUMENT in a
3186 format that can be reused as shell input.
3188 The `-v' option causes the output to be assigned to the variable
3189 VAR rather than being printed to the standard output.
3191 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3192 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3193 format specifications behave as if a zero value or null string, as
3194 appropriate, had been supplied. The return value is zero on
3195 success, non-zero on failure.
3198 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3199 One line is read from the standard input, or from the file
3200 descriptor FD supplied as an argument to the `-u' option, and the
3201 first word is assigned to the first NAME, the second word to the
3202 second NAME, and so on, with leftover words and their intervening
3203 separators assigned to the last NAME. If there are fewer words
3204 read from the input stream than names, the remaining names are
3205 assigned empty values. The characters in the value of the `IFS'
3206 variable are used to split the line into words. The backslash
3207 character `\' may be used to remove any special meaning for the
3208 next character read and for line continuation. If no names are
3209 supplied, the line read is assigned to the variable `REPLY'. The
3210 return code is zero, unless end-of-file is encountered, `read'
3211 times out (in which case the return code is greater than 128), or
3212 an invalid file descriptor is supplied as the argument to `-u'.
3214 Options, if supplied, have the following meanings:
3217 The words are assigned to sequential indices of the array
3218 variable ANAME, starting at 0. All elements are removed from
3219 ANAME before the assignment. Other NAME arguments are
3223 The first character of DELIM is used to terminate the input
3224 line, rather than newline.
3227 Readline (*note Command Line Editing::) is used to obtain the
3228 line. Readline uses the current (or default, if line editing
3229 was not previously active) editing settings.
3232 If Readline is being used to read the line, TEXT is placed
3233 into the editing buffer before editing begins.
3236 `read' returns after reading NCHARS characters rather than
3237 waiting for a complete line of input, but honor a delimiter
3238 if fewer than NCHARS characters are read before the delimiter.
3241 `read' returns after reading exactly NCHARS characters rather
3242 than waiting for a complete line of input, unless EOF is
3243 encountered or `read' times out. Delimiter characters
3244 encountered in the input are not treated specially and do not
3245 cause `read' to return until NCHARS characters are read.
3248 Display PROMPT, without a trailing newline, before attempting
3249 to read any input. The prompt is displayed only if input is
3250 coming from a terminal.
3253 If this option is given, backslash does not act as an escape
3254 character. The backslash is considered to be part of the
3255 line. In particular, a backslash-newline pair may not be
3256 used as a line continuation.
3259 Silent mode. If input is coming from a terminal, characters
3263 Cause `read' to time out and return failure if a complete
3264 line of input is not read within TIMEOUT seconds. TIMEOUT
3265 may be a decimal number with a fractional portion following
3266 the decimal point. This option is only effective if `read'
3267 is reading input from a terminal, pipe, or other special
3268 file; it has no effect when reading from regular files. If
3269 TIMEOUT is 0, `read' returns success if input is available on
3270 the specified file descriptor, failure otherwise. The exit
3271 status is greater than 128 if the timeout is exceeded.
3274 Read input from file descriptor FD.
3278 readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3279 -C CALLBACK] [-c QUANTUM] [ARRAY]
3280 Read lines from the standard input into the indexed array variable
3281 ARRAY, or from file descriptor FD if the `-u' option is supplied.
3283 A synonym for `mapfile'.
3287 A synonym for `.' (*note Bourne Shell Builtins::).
3290 type [-afptP] [NAME ...]
3291 For each NAME, indicate how it would be interpreted if used as a
3294 If the `-t' option is used, `type' prints a single word which is
3295 one of `alias', `function', `builtin', `file' or `keyword', if
3296 NAME is an alias, shell function, shell builtin, disk file, or
3297 shell reserved word, respectively. If the NAME is not found, then
3298 nothing is printed, and `type' returns a failure status.
3300 If the `-p' option is used, `type' either returns the name of the
3301 disk file that would be executed, or nothing if `-t' would not
3304 The `-P' option forces a path search for each NAME, even if `-t'
3305 would not return `file'.
3307 If a command is hashed, `-p' and `-P' print the hashed value, not
3308 necessarily the file that appears first in `$PATH'.
3310 If the `-a' option is used, `type' returns all of the places that
3311 contain an executable named FILE. This includes aliases and
3312 functions, if and only if the `-p' option is not also used.
3314 If the `-f' option is used, `type' does not attempt to find shell
3315 functions, as with the `command' builtin.
3317 The return status is zero if all of the NAMES are found, non-zero
3318 if any are not found.
3321 typeset [-afFrxi] [-p] [NAME[=VALUE] ...]
3322 The `typeset' command is supplied for compatibility with the Korn
3323 shell; however, it has been deprecated in favor of the `declare'
3327 ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
3328 `ulimit' provides control over the resources available to processes
3329 started by the shell, on systems that allow such control. If an
3330 option is given, it is interpreted as follows:
3332 Change and report the soft limit associated with a resource.
3335 Change and report the hard limit associated with a resource.
3338 All current limits are reported.
3341 The maximum socket buffer size.
3344 The maximum size of core files created.
3347 The maximum size of a process's data segment.
3350 The maximum scheduling priority ("nice").
3353 The maximum size of files written by the shell and its
3357 The maximum number of pending signals.
3360 The maximum size that may be locked into memory.
3363 The maximum resident set size (many systems do not honor this
3367 The maximum number of open file descriptors (most systems do
3368 not allow this value to be set).
3371 The pipe buffer size.
3374 The maximum number of bytes in POSIX message queues.
3377 The maximum real-time scheduling priority.
3380 The maximum stack size.
3383 The maximum amount of cpu time in seconds.
3386 The maximum number of processes available to a single user.
3389 The maximum amount of virtual memory available to the process.
3392 The maximum number of file locks.
3395 The maximum number of threads.
3398 If LIMIT is given, it is the new value of the specified resource;
3399 the special LIMIT values `hard', `soft', and `unlimited' stand for
3400 the current hard limit, the current soft limit, and no limit,
3401 respectively. A hard limit cannot be increased by a non-root user
3402 once it is set; a soft limit may be increased up to the value of
3403 the hard limit. Otherwise, the current value of the soft limit
3404 for the specified resource is printed, unless the `-H' option is
3405 supplied. When setting new limits, if neither `-H' nor `-S' is
3406 supplied, both the hard and soft limits are set. If no option is
3407 given, then `-f' is assumed. Values are in 1024-byte increments,
3408 except for `-t', which is in seconds, `-p', which is in units of
3409 512-byte blocks, and `-n' and `-u', which are unscaled values.
3411 The return status is zero unless an invalid option or argument is
3412 supplied, or an error occurs while setting a new limit.
3415 unalias [-a] [NAME ... ]
3417 Remove each NAME from the list of aliases. If `-a' is supplied,
3418 all aliases are removed. Aliases are described in *note Aliases::.
3422 File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
3424 4.3 Modifying Shell Behavior
3425 ============================
3429 * The Set Builtin:: Change the values of shell attributes and
3430 positional parameters.
3431 * The Shopt Builtin:: Modify shell optional behavior.
3434 File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3436 4.3.1 The Set Builtin
3437 ---------------------
3439 This builtin is so complicated that it deserves its own section. `set'
3440 allows you to change the values of shell options and set the positional
3441 parameters, or to display the names and values of shell variables.
3444 set [--abefhkmnptuvxBCEHPT] [-o OPTION] [ARGUMENT ...]
3445 set [+abefhkmnptuvxBCEHPT] [+o OPTION] [ARGUMENT ...]
3447 If no options or arguments are supplied, `set' displays the names
3448 and values of all shell variables and functions, sorted according
3449 to the current locale, in a format that may be reused as input for
3450 setting or resetting the currently-set variables. Read-only
3451 variables cannot be reset. In POSIX mode, only shell variables
3454 When options are supplied, they set or unset shell attributes.
3455 Options, if specified, have the following meanings:
3458 Mark variables and function which are modified or created for
3459 export to the environment of subsequent commands.
3462 Cause the status of terminated background jobs to be reported
3463 immediately, rather than before printing the next primary
3467 Exit immediately if a pipeline (*note Pipelines::), which may
3468 consist of a single simple command (*note Simple Commands::),
3469 a subshell command enclosed in parentheses (*note Command
3470 Grouping::), or one of the commands executed as part of a
3471 command list enclosed by braces (*note Command Grouping::)
3472 returns a non-zero status. The shell does not exit if the
3473 command that fails is part of the command list immediately
3474 following a `while' or `until' keyword, part of the test in
3475 an `if' statement, part of any command executed in a `&&' or
3476 `||' list except the command following the final `&&' or `||',
3477 any command in a pipeline but the last, or if the command's
3478 return status is being inverted with `!'. A trap on `ERR',
3479 if set, is executed before the shell exits.
3481 This option applies to the shell environment and each
3482 subshell environment separately (*note Command Execution
3483 Environment::), and may cause subshells to exit before
3484 executing all the commands in the subshell.
3487 Disable filename expansion (globbing).
3490 Locate and remember (hash) commands as they are looked up for
3491 execution. This option is enabled by default.
3494 All arguments in the form of assignment statements are placed
3495 in the environment for a command, not just those that precede
3499 Job control is enabled (*note Job Control::).
3502 Read commands but do not execute them; this may be used to
3503 check a script for syntax errors. This option is ignored by
3507 Set the option corresponding to OPTION-NAME:
3516 Use an `emacs'-style line editing interface (*note
3517 Command Line Editing::). This also affects the editing
3518 interface used for `read -e'.
3536 Enable command history, as described in *note Bash
3537 History Facilities::. This option is on by default in
3541 An interactive shell will not exit upon reading EOF.
3574 If set, the return value of a pipeline is the value of
3575 the last (rightmost) command to exit with a non-zero
3576 status, or zero if all commands in the pipeline exit
3577 successfully. This option is disabled by default.
3580 Change the behavior of Bash where the default operation
3581 differs from the POSIX standard to match the standard
3582 (*note Bash POSIX Mode::). This is intended to make
3583 Bash behave as a strict superset of that standard.
3592 Use a `vi'-style line editing interface. This also
3593 affects the editing interface used for `read -e'.
3599 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3600 `$ENV' files are not processed, shell functions are not
3601 inherited from the environment, and the `SHELLOPTS',
3602 `BASHOPTS', `CDPATH' and `GLOBIGNORE' variables, if they
3603 appear in the environment, are ignored. If the shell is
3604 started with the effective user (group) id not equal to the
3605 real user (group) id, and the `-p' option is not supplied,
3606 these actions are taken and the effective user id is set to
3607 the real user id. If the `-p' option is supplied at startup,
3608 the effective user id is not reset. Turning this option off
3609 causes the effective user and group ids to be set to the real
3613 Exit after reading and executing one command.
3616 Treat unset variables and parameters other than the special
3617 parameters `@' or `*' as an error when performing parameter
3618 expansion. An error message will be written to the standard
3619 error, and a non-interactive shell will exit.
3622 Print shell input lines as they are read.
3625 Print a trace of simple commands, `for' commands, `case'
3626 commands, `select' commands, and arithmetic `for' commands
3627 and their arguments or associated word lists after they are
3628 expanded and before they are executed. The value of the `PS4'
3629 variable is expanded and the resultant value is printed before
3630 the command and its expanded arguments.
3633 The shell will perform brace expansion (*note Brace
3634 Expansion::). This option is on by default.
3637 Prevent output redirection using `>', `>&', and `<>' from
3638 overwriting existing files.
3641 If set, any trap on `ERR' is inherited by shell functions,
3642 command substitutions, and commands executed in a subshell
3643 environment. The `ERR' trap is normally not inherited in
3647 Enable `!' style history substitution (*note History
3648 Interaction::). This option is on by default for interactive
3652 If set, do not follow symbolic links when performing commands
3653 such as `cd' which change the current directory. The
3654 physical directory is used instead. By default, Bash follows
3655 the logical chain of directories when performing commands
3656 which change the current directory.
3658 For example, if `/usr/sys' is a symbolic link to
3659 `/usr/local/sys' then:
3660 $ cd /usr/sys; echo $PWD
3665 If `set -P' is on, then:
3666 $ cd /usr/sys; echo $PWD
3672 If set, any trap on `DEBUG' and `RETURN' are inherited by
3673 shell functions, command substitutions, and commands executed
3674 in a subshell environment. The `DEBUG' and `RETURN' traps
3675 are normally not inherited in such cases.
3678 If no arguments follow this option, then the positional
3679 parameters are unset. Otherwise, the positional parameters
3680 are set to the ARGUMENTS, even if some of them begin with a
3684 Signal the end of options, cause all remaining ARGUMENTS to
3685 be assigned to the positional parameters. The `-x' and `-v'
3686 options are turned off. If there are no arguments, the
3687 positional parameters remain unchanged.
3689 Using `+' rather than `-' causes these options to be turned off.
3690 The options can also be used upon invocation of the shell. The
3691 current set of options may be found in `$-'.
3693 The remaining N ARGUMENTS are positional parameters and are
3694 assigned, in order, to `$1', `$2', ... `$N'. The special
3695 parameter `#' is set to N.
3697 The return status is always zero unless an invalid option is
3701 File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
3703 4.3.2 The Shopt Builtin
3704 -----------------------
3706 This builtin allows you to change additional shell optional behavior.
3709 shopt [-pqsu] [-o] [OPTNAME ...]
3710 Toggle the values of variables controlling optional shell behavior.
3711 With no options, or with the `-p' option, a list of all settable
3712 options is displayed, with an indication of whether or not each is
3713 set. The `-p' option causes output to be displayed in a form that
3714 may be reused as input. Other options have the following meanings:
3717 Enable (set) each OPTNAME.
3720 Disable (unset) each OPTNAME.
3723 Suppresses normal output; the return status indicates whether
3724 the OPTNAME is set or unset. If multiple OPTNAME arguments
3725 are given with `-q', the return status is zero if all
3726 OPTNAMES are enabled; non-zero otherwise.
3729 Restricts the values of OPTNAME to be those defined for the
3730 `-o' option to the `set' builtin (*note The Set Builtin::).
3732 If either `-s' or `-u' is used with no OPTNAME arguments, the
3733 display is limited to those options which are set or unset,
3736 Unless otherwise noted, the `shopt' options are disabled (off) by
3739 The return status when listing options is zero if all OPTNAMES are
3740 enabled, non-zero otherwise. When setting or unsetting options,
3741 the return status is zero unless an OPTNAME is not a valid shell
3744 The list of `shopt' options is:
3746 If set, a command name that is the name of a directory is
3747 executed as if it were the argument to the `cd' command.
3748 This option is only used by interactive shells.
3751 If this is set, an argument to the `cd' builtin command that
3752 is not a directory is assumed to be the name of a variable
3753 whose value is the directory to change to.
3756 If set, minor errors in the spelling of a directory component
3757 in a `cd' command will be corrected. The errors checked for
3758 are transposed characters, a missing character, and a
3759 character too many. If a correction is found, the corrected
3760 path is printed, and the command proceeds. This option is
3761 only used by interactive shells.
3764 If this is set, Bash checks that a command found in the hash
3765 table exists before trying to execute it. If a hashed
3766 command no longer exists, a normal path search is performed.
3769 If set, Bash lists the status of any stopped and running jobs
3770 before exiting an interactive shell. If any jobs are
3771 running, this causes the exit to be deferred until a second
3772 exit is attempted without an intervening command (*note Job
3773 Control::). The shell always postpones exiting if any jobs
3777 If set, Bash checks the window size after each command and,
3778 if necessary, updates the values of `LINES' and `COLUMNS'.
3781 If set, Bash attempts to save all lines of a multiple-line
3782 command in the same history entry. This allows easy
3783 re-editing of multi-line commands.
3786 If set, Bash changes its behavior to that of version 3.1 with
3787 respect to quoted arguments to the conditional command's =~
3791 If set, Bash attempts spelling correction on directory names
3792 during word completion if the directory name initially
3793 supplied does not exist.
3796 If set, Bash includes filenames beginning with a `.' in the
3797 results of filename expansion.
3800 If this is set, a non-interactive shell will not exit if it
3801 cannot execute the file specified as an argument to the `exec'
3802 builtin command. An interactive shell does not exit if `exec'
3806 If set, aliases are expanded as described below under Aliases,
3807 *note Aliases::. This option is enabled by default for
3811 If set, behavior intended for use by debuggers is enabled:
3813 1. The `-F' option to the `declare' builtin (*note Bash
3814 Builtins::) displays the source file name and line
3815 number corresponding to each function name supplied as
3818 2. If the command run by the `DEBUG' trap returns a
3819 non-zero value, the next command is skipped and not
3822 3. If the command run by the `DEBUG' trap returns a value
3823 of 2, and the shell is executing in a subroutine (a
3824 shell function or a shell script executed by the `.' or
3825 `source' builtins), a call to `return' is simulated.
3827 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in
3828 their descriptions (*note Bash Variables::).
3830 5. Function tracing is enabled: command substitution,
3831 shell functions, and subshells invoked with `( COMMAND
3832 )' inherit the `DEBUG' and `RETURN' traps.
3834 6. Error tracing is enabled: command substitution, shell
3835 functions, and subshells invoked with `( COMMAND )'
3836 inherit the `ERROR' trap.
3839 If set, the extended pattern matching features described above
3840 (*note Pattern Matching::) are enabled.
3843 If set, `$'STRING'' and `$"STRING"' quoting is performed
3844 within `${PARAMETER}' expansions enclosed in double quotes.
3845 This option is enabled by default.
3848 If set, patterns which fail to match filenames during
3849 filename expansion result in an expansion error.
3852 If set, the suffixes specified by the `FIGNORE' shell variable
3853 cause words to be ignored when performing word completion
3854 even if the ignored words are the only possible completions.
3855 *Note Bash Variables::, for a description of `FIGNORE'. This
3856 option is enabled by default.
3859 If set, the pattern `**' used in a filename expansion context
3860 will match a files and zero or more directories and
3861 subdirectories. If the pattern is followed by a `/', only
3862 directories and subdirectories match.
3865 If set, shell error messages are written in the standard GNU
3866 error message format.
3869 If set, the history list is appended to the file named by the
3870 value of the `HISTFILE' variable when the shell exits, rather
3871 than overwriting the file.
3874 If set, and Readline is being used, a user is given the
3875 opportunity to re-edit a failed history substitution.
3878 If set, and Readline is being used, the results of history
3879 substitution are not immediately passed to the shell parser.
3880 Instead, the resulting line is loaded into the Readline
3881 editing buffer, allowing further modification.
3884 If set, and Readline is being used, Bash will attempt to
3885 perform hostname completion when a word containing a `@' is
3886 being completed (*note Commands For Completion::). This
3887 option is enabled by default.
3890 If set, Bash will send `SIGHUP' to all jobs when an
3891 interactive login shell exits (*note Signals::).
3893 `interactive_comments'
3894 Allow a word beginning with `#' to cause that word and all
3895 remaining characters on that line to be ignored in an
3896 interactive shell. This option is enabled by default.
3899 If enabled, and the `cmdhist' option is enabled, multi-line
3900 commands are saved to the history with embedded newlines
3901 rather than using semicolon separators where possible.
3904 The shell sets this option if it is started as a login shell
3905 (*note Invoking Bash::). The value may not be changed.
3908 If set, and a file that Bash is checking for mail has been
3909 accessed since the last time it was checked, the message
3910 `"The mail in MAILFILE has been read"' is displayed.
3912 `no_empty_cmd_completion'
3913 If set, and Readline is being used, Bash will not attempt to
3914 search the `PATH' for possible completions when completion is
3915 attempted on an empty line.
3918 If set, Bash matches filenames in a case-insensitive fashion
3919 when performing filename expansion.
3922 If set, Bash matches patterns in a case-insensitive fashion
3923 when performing matching while executing `case' or `[['
3924 conditional commands.
3927 If set, Bash allows filename patterns which match no files to
3928 expand to a null string, rather than themselves.
3931 If set, the programmable completion facilities (*note
3932 Programmable Completion::) are enabled. This option is
3936 If set, prompt strings undergo parameter expansion, command
3937 substitution, arithmetic expansion, and quote removal after
3938 being expanded as described below (*note Printing a Prompt::).
3939 This option is enabled by default.
3942 The shell sets this option if it is started in restricted mode
3943 (*note The Restricted Shell::). The value may not be changed.
3944 This is not reset when the startup files are executed,
3945 allowing the startup files to discover whether or not a shell
3949 If this is set, the `shift' builtin prints an error message
3950 when the shift count exceeds the number of positional
3954 If set, the `source' builtin uses the value of `PATH' to find
3955 the directory containing the file supplied as an argument.
3956 This option is enabled by default.
3959 If set, the `echo' builtin expands backslash-escape sequences
3963 The return status when listing options is zero if all OPTNAMES are
3964 enabled, non-zero otherwise. When setting or unsetting options,
3965 the return status is zero unless an OPTNAME is not a valid shell
3970 File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
3972 4.4 Special Builtins
3973 ====================
3975 For historical reasons, the POSIX standard has classified several
3976 builtin commands as _special_. When Bash is executing in POSIX mode,
3977 the special builtins differ from other builtin commands in three
3980 1. Special builtins are found before shell functions during command
3983 2. If a special builtin returns an error status, a non-interactive
3986 3. Assignment statements preceding the command stay in effect in the
3987 shell environment after the command completes.
3989 When Bash is not executing in POSIX mode, these builtins behave no
3990 differently than the rest of the Bash builtin commands. The Bash POSIX
3991 mode is described in *note Bash POSIX Mode::.
3993 These are the POSIX special builtins:
3994 break : . continue eval exec exit export readonly return set
3998 File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
4005 * Bourne Shell Variables:: Variables which Bash uses in the same way
4006 as the Bourne Shell.
4007 * Bash Variables:: List of variables that exist in Bash.
4009 This chapter describes the shell variables that Bash uses. Bash
4010 automatically assigns default values to a number of variables.
4013 File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
4015 5.1 Bourne Shell Variables
4016 ==========================
4018 Bash uses certain shell variables in the same way as the Bourne shell.
4019 In some cases, Bash assigns a default value to the variable.
4022 A colon-separated list of directories used as a search path for
4023 the `cd' builtin command.
4026 The current user's home directory; the default for the `cd' builtin
4027 command. The value of this variable is also used by tilde
4028 expansion (*note Tilde Expansion::).
4031 A list of characters that separate fields; used when the shell
4032 splits words as part of expansion.
4035 If this parameter is set to a filename and the `MAILPATH' variable
4036 is not set, Bash informs the user of the arrival of mail in the
4040 A colon-separated list of filenames which the shell periodically
4041 checks for new mail. Each list entry can specify the message that
4042 is printed when new mail arrives in the mail file by separating
4043 the file name from the message with a `?'. When used in the text
4044 of the message, `$_' expands to the name of the current mail file.
4047 The value of the last option argument processed by the `getopts'
4051 The index of the last option argument processed by the `getopts'
4055 A colon-separated list of directories in which the shell looks for
4056 commands. A zero-length (null) directory name in the value of
4057 `PATH' indicates the current directory. A null directory name may
4058 appear as two adjacent colons, or as an initial or trailing colon.
4061 The primary prompt string. The default value is `\s-\v\$ '.
4062 *Note Printing a Prompt::, for the complete list of escape
4063 sequences that are expanded before `PS1' is displayed.
4066 The secondary prompt string. The default value is `> '.
4070 File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
4075 These variables are set or used by Bash, but other shells do not
4076 normally treat them specially.
4078 A few variables used by Bash are described in different chapters:
4079 variables for controlling the job control facilities (*note Job Control
4083 The full pathname used to execute the current instance of Bash.
4086 A colon-separated list of enabled shell options. Each word in the
4087 list is a valid argument for the `-s' option to the `shopt'
4088 builtin command (*note The Shopt Builtin::). The options
4089 appearing in `BASHOPTS' are those reported as `on' by `shopt'. If
4090 this variable is in the environment when Bash starts up, each
4091 shell option in the list will be enabled before reading any
4092 startup files. This variable is readonly.
4095 Expands to the process id of the current Bash process. This
4096 differs from `$$' under certain circumstances, such as subshells
4097 that do not require Bash to be re-initialized.
4100 An associative array variable whose members correspond to the
4101 internal list of aliases as maintained by the `alias' builtin
4102 (*note Bourne Shell Builtins::). Elements added to this array
4103 appear in the alias list; unsetting array elements cause aliases
4104 to be removed from the alias list.
4107 An array variable whose values are the number of parameters in each
4108 frame of the current bash execution call stack. The number of
4109 parameters to the current subroutine (shell function or script
4110 executed with `.' or `source') is at the top of the stack. When a
4111 subroutine is executed, the number of parameters passed is pushed
4112 onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in
4113 extended debugging mode (see *note The Shopt Builtin:: for a
4114 description of the `extdebug' option to the `shopt' builtin).
4117 An array variable containing all of the parameters in the current
4118 bash execution call stack. The final parameter of the last
4119 subroutine call is at the top of the stack; the first parameter of
4120 the initial call is at the bottom. When a subroutine is executed,
4121 the parameters supplied are pushed onto `BASH_ARGV'. The shell
4122 sets `BASH_ARGV' only when in extended debugging mode (see *note
4123 The Shopt Builtin:: for a description of the `extdebug' option to
4124 the `shopt' builtin).
4127 An associative array variable whose members correspond to the
4128 internal hash table of commands as maintained by the `hash' builtin
4129 (*note Bourne Shell Builtins::). Elements added to this array
4130 appear in the hash table; unsetting array elements cause commands
4131 to be removed from the hash table.
4134 The command currently being executed or about to be executed,
4135 unless the shell is executing a command as the result of a trap,
4136 in which case it is the command executing at the time of the trap.
4139 If this variable is set when Bash is invoked to execute a shell
4140 script, its value is expanded and used as the name of a startup
4141 file to read before executing the script. *Note Bash Startup
4144 `BASH_EXECUTION_STRING'
4145 The command argument to the `-c' invocation option.
4148 An array variable whose members are the line numbers in source
4149 files corresponding to each member of FUNCNAME.
4150 `${BASH_LINENO[$i]}' is the line number in the source file where
4151 `${FUNCNAME[$i]}' was called (or `${BASH_LINENO[$i-1]}' if
4152 referenced within another shell function). The corresponding
4153 source file name is `${BASH_SOURCE[$i]}'. Use `LINENO' to obtain
4154 the current line number.
4157 An array variable whose members are assigned by the `=~' binary
4158 operator to the `[[' conditional command (*note Conditional
4159 Constructs::). The element with index 0 is the portion of the
4160 string matching the entire regular expression. The element with
4161 index N is the portion of the string matching the Nth
4162 parenthesized subexpression. This variable is read-only.
4165 An array variable whose members are the source filenames
4166 corresponding to the elements in the `FUNCNAME' array variable.
4169 Incremented by one each time a subshell or subshell environment is
4170 spawned. The initial value is 0.
4173 A readonly array variable (*note Arrays::) whose members hold
4174 version information for this instance of Bash. The values
4175 assigned to the array members are as follows:
4178 The major version number (the RELEASE).
4181 The minor version number (the VERSION).
4190 The release status (e.g., BETA1).
4193 The value of `MACHTYPE'.
4197 The version number of the current instance of Bash.
4200 If set to an integer corresponding to a valid file descriptor, Bash
4201 will write the trace output generated when `set -x' is enabled to
4202 that file descriptor. This allows tracing output to be separated
4203 from diagnostic and error messages. The file descriptor is closed
4204 when `BASH_XTRACEFD' is unset or assigned a new value. Unsetting
4205 `BASH_XTRACEFD' or assigning it the empty string causes the trace
4206 output to be sent to the standard error. Note that setting
4207 `BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
4208 unsetting it will result in the standard error being closed.
4211 Used by the `select' builtin command to determine the terminal
4212 width when printing selection lists. Automatically set upon
4213 receipt of a `SIGWINCH'.
4216 An index into `${COMP_WORDS}' of the word containing the current
4217 cursor position. This variable is available only in shell
4218 functions invoked by the programmable completion facilities (*note
4219 Programmable Completion::).
4222 The current command line. This variable is available only in
4223 shell functions and external commands invoked by the programmable
4224 completion facilities (*note Programmable Completion::).
4227 The index of the current cursor position relative to the beginning
4228 of the current command. If the current cursor position is at the
4229 end of the current command, the value of this variable is equal to
4230 `${#COMP_LINE}'. This variable is available only in shell
4231 functions and external commands invoked by the programmable
4232 completion facilities (*note Programmable Completion::).
4235 Set to an integer value corresponding to the type of completion
4236 attempted that caused a completion function to be called: TAB, for
4237 normal completion, `?', for listing completions after successive
4238 tabs, `!', for listing alternatives on partial word completion,
4239 `@', to list completions if the word is not unmodified, or `%',
4240 for menu completion. This variable is available only in shell
4241 functions and external commands invoked by the programmable
4242 completion facilities (*note Programmable Completion::).
4245 The key (or final key of a key sequence) used to invoke the current
4246 completion function.
4249 The set of characters that the Readline library treats as word
4250 separators when performing word completion. If `COMP_WORDBREAKS'
4251 is unset, it loses its special properties, even if it is
4255 An array variable consisting of the individual words in the
4256 current command line. The line is split into words as Readline
4257 would split it, using `COMP_WORDBREAKS' as described above. This
4258 variable is available only in shell functions invoked by the
4259 programmable completion facilities (*note Programmable
4263 An array variable from which Bash reads the possible completions
4264 generated by a shell function invoked by the programmable
4265 completion facility (*note Programmable Completion::).
4268 An array variable containing the current contents of the directory
4269 stack. Directories appear in the stack in the order they are
4270 displayed by the `dirs' builtin. Assigning to members of this
4271 array variable may be used to modify directories already in the
4272 stack, but the `pushd' and `popd' builtins must be used to add and
4273 remove directories. Assignment to this variable will not change
4274 the current directory. If `DIRSTACK' is unset, it loses its
4275 special properties, even if it is subsequently reset.
4278 If Bash finds this variable in the environment when the shell
4279 starts with value `t', it assumes that the shell is running in an
4280 emacs shell buffer and disables line editing.
4283 The numeric effective user id of the current user. This variable
4287 The editor used as a default by the `-e' option to the `fc'
4291 A colon-separated list of suffixes to ignore when performing
4292 filename completion. A file name whose suffix matches one of the
4293 entries in `FIGNORE' is excluded from the list of matched file
4294 names. A sample value is `.o:~'
4297 An array variable containing the names of all shell functions
4298 currently in the execution call stack. The element with index 0
4299 is the name of any currently-executing shell function. The
4300 bottom-most element is `"main"'. This variable exists only when a
4301 shell function is executing. Assignments to `FUNCNAME' have no
4302 effect and return an error status. If `FUNCNAME' is unset, it
4303 loses its special properties, even if it is subsequently reset.
4306 A colon-separated list of patterns defining the set of filenames to
4307 be ignored by filename expansion. If a filename matched by a
4308 filename expansion pattern also matches one of the patterns in
4309 `GLOBIGNORE', it is removed from the list of matches.
4312 An array variable containing the list of groups of which the
4313 current user is a member. Assignments to `GROUPS' have no effect
4314 and return an error status. If `GROUPS' is unset, it loses its
4315 special properties, even if it is subsequently reset.
4318 Up to three characters which control history expansion, quick
4319 substitution, and tokenization (*note History Interaction::). The
4320 first character is the HISTORY EXPANSION character, that is, the
4321 character which signifies the start of a history expansion,
4322 normally `!'. The second character is the character which
4323 signifies `quick substitution' when seen as the first character on
4324 a line, normally `^'. The optional third character is the
4325 character which indicates that the remainder of the line is a
4326 comment when found as the first character of a word, usually `#'.
4327 The history comment character causes history substitution to be
4328 skipped for the remaining words on the line. It does not
4329 necessarily cause the shell parser to treat the rest of the line
4333 The history number, or index in the history list, of the current
4334 command. If `HISTCMD' is unset, it loses its special properties,
4335 even if it is subsequently reset.
4338 A colon-separated list of values controlling how commands are
4339 saved on the history list. If the list of values includes
4340 `ignorespace', lines which begin with a space character are not
4341 saved in the history list. A value of `ignoredups' causes lines
4342 which match the previous history entry to not be saved. A value
4343 of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'.
4344 A value of `erasedups' causes all previous lines matching the
4345 current line to be removed from the history list before that line
4346 is saved. Any value not in the above list is ignored. If
4347 `HISTCONTROL' is unset, or does not include a valid value, all
4348 lines read by the shell parser are saved on the history list,
4349 subject to the value of `HISTIGNORE'. The second and subsequent
4350 lines of a multi-line compound command are not tested, and are
4351 added to the history regardless of the value of `HISTCONTROL'.
4354 The name of the file to which the command history is saved. The
4355 default value is `~/.bash_history'.
4358 The maximum number of lines contained in the history file. When
4359 this variable is assigned a value, the history file is truncated,
4360 if necessary, by removing the oldest entries, to contain no more
4361 than that number of lines. The history file is also truncated to
4362 this size after writing it when an interactive shell exits. The
4363 default value is 500.
4366 A colon-separated list of patterns used to decide which command
4367 lines should be saved on the history list. Each pattern is
4368 anchored at the beginning of the line and must match the complete
4369 line (no implicit `*' is appended). Each pattern is tested
4370 against the line after the checks specified by `HISTCONTROL' are
4371 applied. In addition to the normal shell pattern matching
4372 characters, `&' matches the previous history line. `&' may be
4373 escaped using a backslash; the backslash is removed before
4374 attempting a match. The second and subsequent lines of a
4375 multi-line compound command are not tested, and are added to the
4376 history regardless of the value of `HISTIGNORE'.
4378 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
4379 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
4380 identical to `ignorespace'. Combining these two patterns,
4381 separating them with a colon, provides the functionality of
4385 The maximum number of commands to remember on the history list.
4386 The default value is 500.
4389 If this variable is set and not null, its value is used as a
4390 format string for STRFTIME to print the time stamp associated with
4391 each history entry displayed by the `history' builtin. If this
4392 variable is set, time stamps are written to the history file so
4393 they may be preserved across shell sessions. This uses the
4394 history comment character to distinguish timestamps from other
4398 Contains the name of a file in the same format as `/etc/hosts' that
4399 should be read when the shell needs to complete a hostname. The
4400 list of possible hostname completions may be changed while the
4401 shell is running; the next time hostname completion is attempted
4402 after the value is changed, Bash adds the contents of the new file
4403 to the existing list. If `HOSTFILE' is set, but has no value, or
4404 does not name a readable file, Bash attempts to read `/etc/hosts'
4405 to obtain the list of possible hostname completions. When
4406 `HOSTFILE' is unset, the hostname list is cleared.
4409 The name of the current host.
4412 A string describing the machine Bash is running on.
4415 Controls the action of the shell on receipt of an `EOF' character
4416 as the sole input. If set, the value denotes the number of
4417 consecutive `EOF' characters that can be read as the first
4418 character on an input line before the shell will exit. If the
4419 variable exists but does not have a numeric value (or has no
4420 value) then the default is 10. If the variable does not exist,
4421 then `EOF' signifies the end of input to the shell. This is only
4422 in effect for interactive shells.
4425 The name of the Readline initialization file, overriding the
4426 default of `~/.inputrc'.
4429 Used to determine the locale category for any category not
4430 specifically selected with a variable starting with `LC_'.
4433 This variable overrides the value of `LANG' and any other `LC_'
4434 variable specifying a locale category.
4437 This variable determines the collation order used when sorting the
4438 results of filename expansion, and determines the behavior of
4439 range expressions, equivalence classes, and collating sequences
4440 within filename expansion and pattern matching (*note Filename
4444 This variable determines the interpretation of characters and the
4445 behavior of character classes within filename expansion and pattern
4446 matching (*note Filename Expansion::).
4449 This variable determines the locale used to translate double-quoted
4450 strings preceded by a `$' (*note Locale Translation::).
4453 This variable determines the locale category used for number
4457 The line number in the script or shell function currently
4461 Used by the `select' builtin command to determine the column length
4462 for printing selection lists. Automatically set upon receipt of a
4466 A string that fully describes the system type on which Bash is
4467 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
4470 How often (in seconds) that the shell should check for mail in the
4471 files specified in the `MAILPATH' or `MAIL' variables. The
4472 default is 60 seconds. When it is time to check for mail, the
4473 shell does so before displaying the primary prompt. If this
4474 variable is unset, or set to a value that is not a number greater
4475 than or equal to zero, the shell disables mail checking.
4478 The previous working directory as set by the `cd' builtin.
4481 If set to the value 1, Bash displays error messages generated by
4482 the `getopts' builtin command.
4485 A string describing the operating system Bash is running on.
4488 An array variable (*note Arrays::) containing a list of exit
4489 status values from the processes in the most-recently-executed
4490 foreground pipeline (which may contain only a single command).
4493 If this variable is in the environment when `bash' starts, the
4494 shell enters POSIX mode (*note Bash POSIX Mode::) before reading
4495 the startup files, as if the `--posix' invocation option had been
4496 supplied. If it is set while the shell is running, `bash' enables
4497 POSIX mode, as if the command
4502 The process ID of the shell's parent process. This variable is
4506 If set, the value is interpreted as a command to execute before
4507 the printing of each primary prompt (`$PS1').
4510 If set to a number greater than zero, the value is used as the
4511 number of trailing directory components to retain when expanding
4512 the `\w' and `\W' prompt string escapes (*note Printing a
4513 Prompt::). Characters removed are replaced with an ellipsis.
4516 The value of this variable is used as the prompt for the `select'
4517 command. If this variable is not set, the `select' command
4521 The value is the prompt printed before the command line is echoed
4522 when the `-x' option is set (*note The Set Builtin::). The first
4523 character of `PS4' is replicated multiple times, as necessary, to
4524 indicate multiple levels of indirection. The default is `+ '.
4527 The current working directory as set by the `cd' builtin.
4530 Each time this parameter is referenced, a random integer between 0
4531 and 32767 is generated. Assigning a value to this variable seeds
4532 the random number generator.
4535 The default variable for the `read' builtin.
4538 This variable expands to the number of seconds since the shell was
4539 started. Assignment to this variable resets the count to the
4540 value assigned, and the expanded value becomes the value assigned
4541 plus the number of seconds since the assignment.
4544 The full pathname to the shell is kept in this environment
4545 variable. If it is not set when the shell starts, Bash assigns to
4546 it the full pathname of the current user's login shell.
4549 A colon-separated list of enabled shell options. Each word in the
4550 list is a valid argument for the `-o' option to the `set' builtin
4551 command (*note The Set Builtin::). The options appearing in
4552 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4553 variable is in the environment when Bash starts up, each shell
4554 option in the list will be enabled before reading any startup
4555 files. This variable is readonly.
4558 Incremented by one each time a new instance of Bash is started.
4559 This is intended to be a count of how deeply your Bash shells are
4563 The value of this parameter is used as a format string specifying
4564 how the timing information for pipelines prefixed with the `time'
4565 reserved word should be displayed. The `%' character introduces an
4566 escape sequence that is expanded to a time value or other
4567 information. The escape sequences and their meanings are as
4568 follows; the braces denote optional portions.
4574 The elapsed time in seconds.
4577 The number of CPU seconds spent in user mode.
4580 The number of CPU seconds spent in system mode.
4583 The CPU percentage, computed as (%U + %S) / %R.
4585 The optional P is a digit specifying the precision, the number of
4586 fractional digits after a decimal point. A value of 0 causes no
4587 decimal point or fraction to be output. At most three places
4588 after the decimal point may be specified; values of P greater than
4589 3 are changed to 3. If P is not specified, the value 3 is used.
4591 The optional `l' specifies a longer format, including minutes, of
4592 the form MMmSS.FFs. The value of P determines whether or not the
4593 fraction is included.
4595 If this variable is not set, Bash acts as if it had the value
4596 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4597 If the value is null, no timing information is displayed. A
4598 trailing newline is added when the format string is displayed.
4601 If set to a value greater than zero, `TMOUT' is treated as the
4602 default timeout for the `read' builtin (*note Bash Builtins::).
4603 The `select' command (*note Conditional Constructs::) terminates
4604 if input does not arrive after `TMOUT' seconds when input is coming
4607 In an interactive shell, the value is interpreted as the number of
4608 seconds to wait for input after issuing the primary prompt when
4609 the shell is interactive. Bash terminates after that number of
4610 seconds if input does not arrive.
4613 If set, Bash uses its value as the name of a directory in which
4614 Bash creates temporary files for the shell's use.
4617 The numeric real user id of the current user. This variable is
4622 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
4627 This section describes features unique to Bash.
4631 * Invoking Bash:: Command line options that you can give
4633 * Bash Startup Files:: When and how Bash executes scripts.
4634 * Interactive Shells:: What an interactive shell is.
4635 * Bash Conditional Expressions:: Primitives used in composing expressions for
4637 * Shell Arithmetic:: Arithmetic on shell variables.
4638 * Aliases:: Substituting one command for another.
4639 * Arrays:: Array Variables.
4640 * The Directory Stack:: History of visited directories.
4641 * Printing a Prompt:: Controlling the PS1 string.
4642 * The Restricted Shell:: A more controlled mode of shell execution.
4643 * Bash POSIX Mode:: Making Bash behave more closely to what
4644 the POSIX standard specifies.
4647 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
4652 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4653 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
4654 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4656 In addition to the single-character shell command-line options
4657 (*note The Set Builtin::), there are several multi-character options
4658 that you can use. These options must appear on the command line before
4659 the single-character options to be recognized.
4662 Arrange for the debugger profile to be executed before the shell
4663 starts. Turns on extended debugging mode (see *note The Shopt
4664 Builtin:: for a description of the `extdebug' option to the `shopt'
4665 builtin) and shell function tracing (see *note The Set Builtin::
4666 for a description of the `-o functrace' option).
4669 A list of all double-quoted strings preceded by `$' is printed on
4670 the standard output in the GNU `gettext' PO (portable object) file
4671 format. Equivalent to `-D' except for the output format.
4677 Display a usage message on standard output and exit successfully.
4679 `--init-file FILENAME'
4681 Execute commands from FILENAME (instead of `~/.bashrc') in an
4688 Do not use the GNU Readline library (*note Command Line Editing::)
4689 to read command lines when the shell is interactive.
4692 Don't load the system-wide startup file `/etc/profile' or any of
4693 the personal initialization files `~/.bash_profile',
4694 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
4698 Don't read the `~/.bashrc' initialization file in an interactive
4699 shell. This is on by default if the shell is invoked as `sh'.
4702 Change the behavior of Bash where the default operation differs
4703 from the POSIX standard to match the standard. This is intended
4704 to make Bash behave as a strict superset of that standard. *Note
4705 Bash POSIX Mode::, for a description of the Bash POSIX mode.
4708 Make the shell a restricted shell (*note The Restricted Shell::).
4711 Equivalent to `-v'. Print shell input lines as they're read.
4714 Show version information for this instance of Bash on the standard
4715 output and exit successfully.
4718 There are several single-character options that may be supplied at
4719 invocation which are not available with the `set' builtin.
4722 Read and execute commands from STRING after processing the
4723 options, then exit. Any remaining arguments are assigned to the
4724 positional parameters, starting with `$0'.
4727 Force the shell to run interactively. Interactive shells are
4728 described in *note Interactive Shells::.
4731 Make this shell act as if it had been directly invoked by login.
4732 When the shell is interactive, this is equivalent to starting a
4733 login shell with `exec -l bash'. When the shell is not
4734 interactive, the login shell startup files will be executed.
4735 `exec bash -l' or `exec bash --login' will replace the current
4736 shell with a Bash login shell. *Note Bash Startup Files::, for a
4737 description of the special behavior of a login shell.
4740 Make the shell a restricted shell (*note The Restricted Shell::).
4743 If this option is present, or if no arguments remain after option
4744 processing, then commands are read from the standard input. This
4745 option allows the positional parameters to be set when invoking an
4749 A list of all double-quoted strings preceded by `$' is printed on
4750 the standard output. These are the strings that are subject to
4751 language translation when the current locale is not `C' or `POSIX'
4752 (*note Locale Translation::). This implies the `-n' option; no
4753 commands will be executed.
4755 `[-+]O [SHOPT_OPTION]'
4756 SHOPT_OPTION is one of the shell options accepted by the `shopt'
4757 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
4758 `-O' sets the value of that option; `+O' unsets it. If
4759 SHOPT_OPTION is not supplied, the names and values of the shell
4760 options accepted by `shopt' are printed on the standard output.
4761 If the invocation option is `+O', the output is displayed in a
4762 format that may be reused as input.
4765 A `--' signals the end of options and disables further option
4766 processing. Any arguments after the `--' are treated as filenames
4770 A _login_ shell is one whose first character of argument zero is
4771 `-', or one invoked with the `--login' option.
4773 An _interactive_ shell is one started without non-option arguments,
4774 unless `-s' is specified, without specifying the `-c' option, and whose
4775 input and output are both connected to terminals (as determined by
4776 `isatty(3)'), or one started with the `-i' option. *Note Interactive
4777 Shells::, for more information.
4779 If arguments remain after option processing, and neither the `-c'
4780 nor the `-s' option has been supplied, the first argument is assumed to
4781 be the name of a file containing shell commands (*note Shell Scripts::).
4782 When Bash is invoked in this fashion, `$0' is set to the name of the
4783 file, and the positional parameters are set to the remaining arguments.
4784 Bash reads and executes commands from this file, then exits. Bash's
4785 exit status is the exit status of the last command executed in the
4786 script. If no commands are executed, the exit status is 0.
4789 File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
4791 6.2 Bash Startup Files
4792 ======================
4794 This section describes how Bash executes its startup files. If any of
4795 the files exist but cannot be read, Bash reports an error. Tildes are
4796 expanded in file names as described above under Tilde Expansion (*note
4799 Interactive shells are described in *note Interactive Shells::.
4801 Invoked as an interactive login shell, or with `--login'
4802 ........................................................
4804 When Bash is invoked as an interactive login shell, or as a
4805 non-interactive shell with the `--login' option, it first reads and
4806 executes commands from the file `/etc/profile', if that file exists.
4807 After reading that file, it looks for `~/.bash_profile',
4808 `~/.bash_login', and `~/.profile', in that order, and reads and
4809 executes commands from the first one that exists and is readable. The
4810 `--noprofile' option may be used when the shell is started to inhibit
4813 When a login shell exits, Bash reads and executes commands from the
4814 file `~/.bash_logout', if it exists.
4816 Invoked as an interactive non-login shell
4817 .........................................
4819 When an interactive shell that is not a login shell is started, Bash
4820 reads and executes commands from `~/.bashrc', if that file exists.
4821 This may be inhibited by using the `--norc' option. The `--rcfile
4822 FILE' option will force Bash to read and execute commands from FILE
4823 instead of `~/.bashrc'.
4825 So, typically, your `~/.bash_profile' contains the line
4826 `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'
4827 after (or before) any login-specific initializations.
4829 Invoked non-interactively
4830 .........................
4832 When Bash is started non-interactively, to run a shell script, for
4833 example, it looks for the variable `BASH_ENV' in the environment,
4834 expands its value if it appears there, and uses the expanded value as
4835 the name of a file to read and execute. Bash behaves as if the
4836 following command were executed:
4837 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
4838 but the value of the `PATH' variable is not used to search for the
4841 As noted above, if a non-interactive shell is invoked with the
4842 `--login' option, Bash attempts to read and execute commands from the
4843 login shell startup files.
4845 Invoked with name `sh'
4846 ......................
4848 If Bash is invoked with the name `sh', it tries to mimic the startup
4849 behavior of historical versions of `sh' as closely as possible, while
4850 conforming to the POSIX standard as well.
4852 When invoked as an interactive login shell, or as a non-interactive
4853 shell with the `--login' option, it first attempts to read and execute
4854 commands from `/etc/profile' and `~/.profile', in that order. The
4855 `--noprofile' option may be used to inhibit this behavior. When
4856 invoked as an interactive shell with the name `sh', Bash looks for the
4857 variable `ENV', expands its value if it is defined, and uses the
4858 expanded value as the name of a file to read and execute. Since a
4859 shell invoked as `sh' does not attempt to read and execute commands
4860 from any other startup files, the `--rcfile' option has no effect. A
4861 non-interactive shell invoked with the name `sh' does not attempt to
4862 read any other startup files.
4864 When invoked as `sh', Bash enters POSIX mode after the startup files
4867 Invoked in POSIX mode
4868 .....................
4870 When Bash is started in POSIX mode, as with the `--posix' command line
4871 option, it follows the POSIX standard for startup files. In this mode,
4872 interactive shells expand the `ENV' variable and commands are read and
4873 executed from the file whose name is the expanded value. No other
4874 startup files are read.
4876 Invoked by remote shell daemon
4877 ..............................
4879 Bash attempts to determine when it is being run with its standard input
4880 connected to a a network connection, as if by the remote shell daemon,
4881 usually `rshd', or the secure shell daemon `sshd'. If Bash determines
4882 it is being run in this fashion, it reads and executes commands from
4883 `~/.bashrc', if that file exists and is readable. It will not do this
4884 if invoked as `sh'. The `--norc' option may be used to inhibit this
4885 behavior, and the `--rcfile' option may be used to force another file
4886 to be read, but `rshd' does not generally invoke the shell with those
4887 options or allow them to be specified.
4889 Invoked with unequal effective and real UID/GIDs
4890 ................................................
4892 If Bash is started with the effective user (group) id not equal to the
4893 real user (group) id, and the `-p' option is not supplied, no startup
4894 files are read, shell functions are not inherited from the environment,
4895 the `SHELLOPTS', `BASHOPTS', `CDPATH', and `GLOBIGNORE' variables, if
4896 they appear in the environment, are ignored, and the effective user id
4897 is set to the real user id. If the `-p' option is supplied at
4898 invocation, the startup behavior is the same, but the effective user id
4902 File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
4904 6.3 Interactive Shells
4905 ======================
4909 * What is an Interactive Shell?:: What determines whether a shell is Interactive.
4910 * Is this Shell Interactive?:: How to tell if a shell is interactive.
4911 * Interactive Shell Behavior:: What changes in a interactive shell?
4914 File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
4916 6.3.1 What is an Interactive Shell?
4917 -----------------------------------
4919 An interactive shell is one started without non-option arguments,
4920 unless `-s' is specified, without specifying the `-c' option, and whose
4921 input and error output are both connected to terminals (as determined
4922 by `isatty(3)'), or one started with the `-i' option.
4924 An interactive shell generally reads from and writes to a user's
4927 The `-s' invocation option may be used to set the positional
4928 parameters when an interactive shell is started.
4931 File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
4933 6.3.2 Is this Shell Interactive?
4934 --------------------------------
4936 To determine within a startup script whether or not Bash is running
4937 interactively, test the value of the `-' special parameter. It
4938 contains `i' when the shell is interactive. For example:
4941 *i*) echo This shell is interactive ;;
4942 *) echo This shell is not interactive ;;
4945 Alternatively, startup scripts may examine the variable `PS1'; it is
4946 unset in non-interactive shells, and set in interactive shells. Thus:
4948 if [ -z "$PS1" ]; then
4949 echo This shell is not interactive
4951 echo This shell is interactive
4955 File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
4957 6.3.3 Interactive Shell Behavior
4958 --------------------------------
4960 When the shell is running interactively, it changes its behavior in
4963 1. Startup files are read and executed as described in *note Bash
4966 2. Job Control (*note Job Control::) is enabled by default. When job
4967 control is in effect, Bash ignores the keyboard-generated job
4968 control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
4970 3. Bash expands and displays `PS1' before reading the first line of a
4971 command, and expands and displays `PS2' before reading the second
4972 and subsequent lines of a multi-line command.
4974 4. Bash executes the value of the `PROMPT_COMMAND' variable as a
4975 command before printing the primary prompt, `$PS1' (*note Bash
4978 5. Readline (*note Command Line Editing::) is used to read commands
4979 from the user's terminal.
4981 6. Bash inspects the value of the `ignoreeof' option to `set -o'
4982 instead of exiting immediately when it receives an `EOF' on its
4983 standard input when reading a command (*note The Set Builtin::).
4985 7. Command history (*note Bash History Facilities::) and history
4986 expansion (*note History Interaction::) are enabled by default.
4987 Bash will save the command history to the file named by `$HISTFILE'
4988 when an interactive shell exits.
4990 8. Alias expansion (*note Aliases::) is performed by default.
4992 9. In the absence of any traps, Bash ignores `SIGTERM' (*note
4995 10. In the absence of any traps, `SIGINT' is caught and handled
4996 ((*note Signals::). `SIGINT' will interrupt some shell builtins.
4998 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
4999 the `huponexit' shell option has been enabled (*note Signals::).
5001 12. The `-n' invocation option is ignored, and `set -n' has no effect
5002 (*note The Set Builtin::).
5004 13. Bash will check for mail periodically, depending on the values of
5005 the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
5008 14. Expansion errors due to references to unbound shell variables after
5009 `set -u' has been enabled will not cause the shell to exit (*note
5012 15. The shell will not exit on expansion errors caused by VAR being
5013 unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
5016 16. Redirection errors encountered by shell builtins will not cause the
5019 17. When running in POSIX mode, a special builtin returning an error
5020 status will not cause the shell to exit (*note Bash POSIX Mode::).
5022 18. A failed `exec' will not cause the shell to exit (*note Bourne
5025 19. Parser syntax errors will not cause the shell to exit.
5027 20. Simple spelling correction for directory arguments to the `cd'
5028 builtin is enabled by default (see the description of the `cdspell'
5029 option to the `shopt' builtin in *note The Shopt Builtin::).
5031 21. The shell will check the value of the `TMOUT' variable and exit if
5032 a command is not read within the specified number of seconds after
5033 printing `$PS1' (*note Bash Variables::).
5037 File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
5039 6.4 Bash Conditional Expressions
5040 ================================
5042 Conditional expressions are used by the `[[' compound command and the
5043 `test' and `[' builtin commands.
5045 Expressions may be unary or binary. Unary expressions are often
5046 used to examine the status of a file. There are string operators and
5047 numeric comparison operators as well. If the FILE argument to one of
5048 the primaries is of the form `/dev/fd/N', then file descriptor N is
5049 checked. If the FILE argument to one of the primaries is one of
5050 `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
5051 2, respectively, is checked.
5053 When used with `[[', The `<' and `>' operators sort
5054 lexicographically using the current locale.
5056 Unless otherwise specified, primaries that operate on files follow
5057 symbolic links and operate on the target of the link, rather than the
5061 True if FILE exists.
5064 True if FILE exists and is a block special file.
5067 True if FILE exists and is a character special file.
5070 True if FILE exists and is a directory.
5073 True if FILE exists.
5076 True if FILE exists and is a regular file.
5079 True if FILE exists and its set-group-id bit is set.
5082 True if FILE exists and is a symbolic link.
5085 True if FILE exists and its "sticky" bit is set.
5088 True if FILE exists and is a named pipe (FIFO).
5091 True if FILE exists and is readable.
5094 True if FILE exists and has a size greater than zero.
5097 True if file descriptor FD is open and refers to a terminal.
5100 True if FILE exists and its set-user-id bit is set.
5103 True if FILE exists and is writable.
5106 True if FILE exists and is executable.
5109 True if FILE exists and is owned by the effective user id.
5112 True if FILE exists and is owned by the effective group id.
5115 True if FILE exists and is a symbolic link.
5118 True if FILE exists and is a socket.
5121 True if FILE exists and has been modified since it was last read.
5124 True if FILE1 is newer (according to modification date) than
5125 FILE2, or if FILE1 exists and FILE2 does not.
5128 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
5132 True if FILE1 and FILE2 refer to the same device and inode numbers.
5135 True if shell option OPTNAME is enabled. The list of options
5136 appears in the description of the `-o' option to the `set' builtin
5137 (*note The Set Builtin::).
5140 True if the length of STRING is zero.
5144 True if the length of STRING is non-zero.
5146 `STRING1 == STRING2'
5148 True if the strings are equal. `=' should be used with the `test'
5149 command for POSIX conformance.
5151 `STRING1 != STRING2'
5152 True if the strings are not equal.
5155 True if STRING1 sorts before STRING2 lexicographically.
5158 True if STRING1 sorts after STRING2 lexicographically.
5161 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
5162 arithmetic binary operators return true if ARG1 is equal to, not
5163 equal to, less than, less than or equal to, greater than, or
5164 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
5165 positive or negative integers.
5169 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
5171 6.5 Shell Arithmetic
5172 ====================
5174 The shell allows arithmetic expressions to be evaluated, as one of the
5175 shell expansions or by the `let' and the `-i' option to the `declare'
5178 Evaluation is done in fixed-width integers with no check for
5179 overflow, though division by 0 is trapped and flagged as an error. The
5180 operators and their precedence, associativity, and values are the same
5181 as in the C language. The following list of operators is grouped into
5182 levels of equal-precedence operators. The levels are listed in order
5183 of decreasing precedence.
5186 variable post-increment and post-decrement
5189 variable pre-increment and pre-decrement
5192 unary minus and plus
5195 logical and bitwise negation
5201 multiplication, division, remainder
5204 addition, subtraction
5207 left and right bitwise shifts
5213 equality and inequality
5219 bitwise exclusive OR
5230 `expr ? expr : expr'
5231 conditional operator
5233 `= *= /= %= += -= <<= >>= &= ^= |='
5239 Shell variables are allowed as operands; parameter expansion is
5240 performed before the expression is evaluated. Within an expression,
5241 shell variables may also be referenced by name without using the
5242 parameter expansion syntax. A shell variable that is null or unset
5243 evaluates to 0 when referenced by name without using the parameter
5244 expansion syntax. The value of a variable is evaluated as an
5245 arithmetic expression when it is referenced, or when a variable which
5246 has been given the INTEGER attribute using `declare -i' is assigned a
5247 value. A null value evaluates to 0. A shell variable need not have
5248 its integer attribute turned on to be used in an expression.
5250 Constants with a leading 0 are interpreted as octal numbers. A
5251 leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
5252 form [BASE`#']N, where BASE is a decimal number between 2 and 64
5253 representing the arithmetic base, and N is a number in that base. If
5254 BASE`#' is omitted, then base 10 is used. The digits greater than 9
5255 are represented by the lowercase letters, the uppercase letters, `@',
5256 and `_', in that order. If BASE is less than or equal to 36, lowercase
5257 and uppercase letters may be used interchangeably to represent numbers
5260 Operators are evaluated in order of precedence. Sub-expressions in
5261 parentheses are evaluated first and may override the precedence rules
5265 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
5270 ALIASES allow a string to be substituted for a word when it is used as
5271 the first word of a simple command. The shell maintains a list of
5272 aliases that may be set and unset with the `alias' and `unalias'
5275 The first word of each simple command, if unquoted, is checked to see
5276 if it has an alias. If so, that word is replaced by the text of the
5277 alias. The characters `/', `$', ``', `=' and any of the shell
5278 metacharacters or quoting characters listed above may not appear in an
5279 alias name. The replacement text may contain any valid shell input,
5280 including shell metacharacters. The first word of the replacement text
5281 is tested for aliases, but a word that is identical to an alias being
5282 expanded is not expanded a second time. This means that one may alias
5283 `ls' to `"ls -F"', for instance, and Bash does not try to recursively
5284 expand the replacement text. If the last character of the alias value
5285 is a space or tab character, then the next command word following the
5286 alias is also checked for alias expansion.
5288 Aliases are created and listed with the `alias' command, and removed
5289 with the `unalias' command.
5291 There is no mechanism for using arguments in the replacement text,
5292 as in `csh'. If arguments are needed, a shell function should be used
5293 (*note Shell Functions::).
5295 Aliases are not expanded when the shell is not interactive, unless
5296 the `expand_aliases' shell option is set using `shopt' (*note The Shopt
5299 The rules concerning the definition and use of aliases are somewhat
5300 confusing. Bash always reads at least one complete line of input
5301 before executing any of the commands on that line. Aliases are
5302 expanded when a command is read, not when it is executed. Therefore, an
5303 alias definition appearing on the same line as another command does not
5304 take effect until the next line of input is read. The commands
5305 following the alias definition on that line are not affected by the new
5306 alias. This behavior is also an issue when functions are executed.
5307 Aliases are expanded when a function definition is read, not when the
5308 function is executed, because a function definition is itself a
5309 compound command. As a consequence, aliases defined in a function are
5310 not available until after that function is executed. To be safe,
5311 always put alias definitions on a separate line, and do not use `alias'
5312 in compound commands.
5314 For almost every purpose, shell functions are preferred over aliases.
5317 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
5322 Bash provides one-dimensional indexed and associative array variables.
5323 Any variable may be used as an indexed array; the `declare' builtin
5324 will explicitly declare an array. There is no maximum limit on the
5325 size of an array, nor any requirement that members be indexed or
5326 assigned contiguously. Indexed arrays are referenced using integers
5327 (including arithmetic expressions (*note Shell Arithmetic::) and are
5328 zero-based; associative arrays use arbitrary strings.
5330 An indexed array is created automatically if any variable is
5331 assigned to using the syntax
5332 name[SUBSCRIPT]=VALUE
5334 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
5335 to a number greater than or equal to zero. To explicitly declare an
5339 declare -a NAME[SUBSCRIPT]
5340 is also accepted; the SUBSCRIPT is ignored.
5342 Associative arrays are created using
5345 Attributes may be specified for an array variable using the
5346 `declare' and `readonly' builtins. Each attribute applies to all
5347 members of an array.
5349 Arrays are assigned to using compound assignments of the form
5350 name=(value1 ... valueN)
5351 where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array
5352 assignments do not require the bracket and subscript. When assigning
5353 to indexed arrays, if the optional subscript is supplied, that index is
5354 assigned to; otherwise the index of the element assigned is the last
5355 index assigned to by the statement plus one. Indexing starts at zero.
5357 When assigning to an associative array, the subscript is required.
5359 This syntax is also accepted by the `declare' builtin. Individual
5360 array elements may be assigned to using the `name['SUBSCRIPT`]='VALUE
5361 syntax introduced above.
5363 Any element of an array may be referenced using
5364 `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
5365 with the shell's filename expansion operators. If the SUBSCRIPT is `@'
5366 or `*', the word expands to all members of the array NAME. These
5367 subscripts differ only when the word appears within double quotes. If
5368 the word is double-quoted, `${name[*]}' expands to a single word with
5369 the value of each array member separated by the first character of the
5370 `IFS' variable, and `${name[@]}' expands each element of NAME to a
5371 separate word. When there are no array members, `${name[@]}' expands
5372 to nothing. If the double-quoted expansion occurs within a word, the
5373 expansion of the first parameter is joined with the beginning part of
5374 the original word, and the expansion of the last parameter is joined
5375 with the last part of the original word. This is analogous to the
5376 expansion of the special parameters `@' and `*'.
5377 `${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'.
5378 If SUBSCRIPT is `@' or `*', the expansion is the number of elements in
5379 the array. Referencing an array variable without a subscript is
5380 equivalent to referencing with a subscript of 0.
5382 An array variable is considered set if a subscript has been assigned
5383 a value. The null string is a valid value.
5385 The `unset' builtin is used to destroy arrays. `unset'
5386 NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care
5387 must be taken to avoid unwanted side effects caused by filename
5388 expansion. `unset' NAME, where NAME is an array, removes the entire
5389 array. A subscript of `*' or `@' also removes the entire array.
5391 The `declare', `local', and `readonly' builtins each accept a `-a'
5392 option to specify an indexed array and a `-A' option to specify an
5393 associative array. The `read' builtin accepts a `-a' option to assign
5394 a list of words read from the standard input to an array, and can read
5395 values from the standard input into individual array elements. The
5396 `set' and `declare' builtins display array values in a way that allows
5397 them to be reused as input.
5400 File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
5402 6.8 The Directory Stack
5403 =======================
5407 * Directory Stack Builtins:: Bash builtin commands to manipulate
5408 the directory stack.
5410 The directory stack is a list of recently-visited directories. The
5411 `pushd' builtin adds directories to the stack as it changes the current
5412 directory, and the `popd' builtin removes specified directories from
5413 the stack and changes the current directory to the directory removed.
5414 The `dirs' builtin displays the contents of the directory stack.
5416 The contents of the directory stack are also visible as the value of
5417 the `DIRSTACK' shell variable.
5420 File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
5422 6.8.1 Directory Stack Builtins
5423 ------------------------------
5426 dirs [+N | -N] [-clpv]
5427 Display the list of currently remembered directories. Directories
5428 are added to the list with the `pushd' command; the `popd' command
5429 removes directories from the list.
5431 Displays the Nth directory (counting from the left of the
5432 list printed by `dirs' when invoked without options), starting
5436 Displays the Nth directory (counting from the right of the
5437 list printed by `dirs' when invoked without options), starting
5441 Clears the directory stack by deleting all of the elements.
5444 Produces a longer listing; the default listing format uses a
5445 tilde to denote the home directory.
5448 Causes `dirs' to print the directory stack with one entry per
5452 Causes `dirs' to print the directory stack with one entry per
5453 line, prefixing each entry with its index in the stack.
5458 Remove the top entry from the directory stack, and `cd' to the new
5459 top directory. When no arguments are given, `popd' removes the
5460 top directory from the stack and performs a `cd' to the new top
5461 directory. The elements are numbered from 0 starting at the first
5462 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
5465 Removes the Nth directory (counting from the left of the list
5466 printed by `dirs'), starting with zero.
5469 Removes the Nth directory (counting from the right of the
5470 list printed by `dirs'), starting with zero.
5473 Suppresses the normal change of directory when removing
5474 directories from the stack, so that only the stack is
5478 pushd [-n] [+N | -N | DIR ]
5480 Save the current directory on the top of the directory stack and
5481 then `cd' to DIR. With no arguments, `pushd' exchanges the top
5485 Suppresses the normal change of directory when adding
5486 directories to the stack, so that only the stack is
5490 Brings the Nth directory (counting from the left of the list
5491 printed by `dirs', starting with zero) to the top of the list
5492 by rotating the stack.
5495 Brings the Nth directory (counting from the right of the list
5496 printed by `dirs', starting with zero) to the top of the list
5497 by rotating the stack.
5500 Makes the current working directory be the top of the stack,
5501 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
5505 File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
5507 6.9 Controlling the Prompt
5508 ==========================
5510 The value of the variable `PROMPT_COMMAND' is examined just before Bash
5511 prints each primary prompt. If `PROMPT_COMMAND' is set and has a
5512 non-null value, then the value is executed just as if it had been typed
5513 on the command line.
5515 In addition, the following table describes the special characters
5516 which can appear in the prompt variables:
5522 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
5525 The FORMAT is passed to `strftime'(3) and the result is inserted
5526 into the prompt string; an empty FORMAT results in a
5527 locale-specific time representation. The braces are required.
5530 An escape character.
5533 The hostname, up to the first `.'.
5539 The number of jobs currently managed by the shell.
5542 The basename of the shell's terminal device name.
5551 The name of the shell, the basename of `$0' (the portion following
5555 The time, in 24-hour HH:MM:SS format.
5558 The time, in 12-hour HH:MM:SS format.
5561 The time, in 12-hour am/pm format.
5564 The time, in 24-hour HH:MM format.
5567 The username of the current user.
5570 The version of Bash (e.g., 2.00)
5573 The release of Bash, version + patchlevel (e.g., 2.00.0)
5576 The current working directory, with `$HOME' abbreviated with a
5577 tilde (uses the `$PROMPT_DIRTRIM' variable).
5580 The basename of `$PWD', with `$HOME' abbreviated with a tilde.
5583 The history number of this command.
5586 The command number of this command.
5589 If the effective uid is 0, `#', otherwise `$'.
5592 The character whose ASCII code is the octal value NNN.
5598 Begin a sequence of non-printing characters. This could be used to
5599 embed a terminal control sequence into the prompt.
5602 End a sequence of non-printing characters.
5604 The command number and the history number are usually different: the
5605 history number of a command is its position in the history list, which
5606 may include commands restored from the history file (*note Bash History
5607 Facilities::), while the command number is the position in the sequence
5608 of commands executed during the current shell session.
5610 After the string is decoded, it is expanded via parameter expansion,
5611 command substitution, arithmetic expansion, and quote removal, subject
5612 to the value of the `promptvars' shell option (*note Bash Builtins::).
5615 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
5617 6.10 The Restricted Shell
5618 =========================
5620 If Bash is started with the name `rbash', or the `--restricted' or `-r'
5621 option is supplied at invocation, the shell becomes restricted. A
5622 restricted shell is used to set up an environment more controlled than
5623 the standard shell. A restricted shell behaves identically to `bash'
5624 with the exception that the following are disallowed or not performed:
5626 * Changing directories with the `cd' builtin.
5628 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
5629 `BASH_ENV' variables.
5631 * Specifying command names containing slashes.
5633 * Specifying a filename containing a slash as an argument to the `.'
5636 * Specifying a filename containing a slash as an argument to the `-p'
5637 option to the `hash' builtin command.
5639 * Importing function definitions from the shell environment at
5642 * Parsing the value of `SHELLOPTS' from the shell environment at
5645 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
5646 redirection operators.
5648 * Using the `exec' builtin to replace the shell with another command.
5650 * Adding or deleting builtin commands with the `-f' and `-d' options
5651 to the `enable' builtin.
5653 * Using the `enable' builtin command to enable disabled shell
5656 * Specifying the `-p' option to the `command' builtin.
5658 * Turning off restricted mode with `set +r' or `set +o restricted'.
5660 These restrictions are enforced after any startup files are read.
5662 When a command that is found to be a shell script is executed (*note
5663 Shell Scripts::), `rbash' turns off any restrictions in the shell
5664 spawned to execute the script.
5667 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
5669 6.11 Bash POSIX Mode
5670 ====================
5672 Starting Bash with the `--posix' command-line option or executing `set
5673 -o posix' while Bash is running will cause Bash to conform more closely
5674 to the POSIX standard by changing the behavior to match that specified
5675 by POSIX in areas where the Bash default differs.
5677 When invoked as `sh', Bash enters POSIX mode after reading the
5680 The following list is what's changed when `POSIX mode' is in effect:
5682 1. When a command in the hash table no longer exists, Bash will
5683 re-search `$PATH' to find the new location. This is also
5684 available with `shopt -s checkhash'.
5686 2. The message printed by the job control code and builtins when a job
5687 exits with a non-zero status is `Done(status)'.
5689 3. The message printed by the job control code and builtins when a job
5690 is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
5693 4. The `bg' builtin uses the required format to describe each job
5694 placed in the background, which does not include an indication of
5695 whether the job is the current or previous job.
5697 5. Reserved words appearing in a context where reserved words are
5698 recognized do not undergo alias expansion.
5700 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number
5701 and `!!' to `!' are enabled, and parameter expansion is performed
5702 on the values of `PS1' and `PS2' regardless of the setting of the
5703 `promptvars' option.
5705 7. The POSIX startup files are executed (`$ENV') rather than the
5708 8. Tilde expansion is only performed on assignments preceding a
5709 command name, rather than on all assignment statements on the line.
5711 9. The default history file is `~/.sh_history' (this is the default
5712 value of `$HISTFILE').
5714 10. The output of `kill -l' prints all the signal names on a single
5715 line, separated by spaces, without the `SIG' prefix.
5717 11. The `kill' builtin does not accept signal names with a `SIG'
5720 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
5723 13. Non-interactive shells exit if a syntax error in an arithmetic
5724 expansion results in an invalid expression.
5726 14. Redirection operators do not perform filename expansion on the word
5727 in the redirection unless the shell is interactive.
5729 15. Redirection operators do not perform word splitting on the word in
5732 16. Function names must be valid shell `name's. That is, they may not
5733 contain characters other than letters, digits, and underscores, and
5734 may not start with a digit. Declaring a function with an invalid
5735 name causes a fatal syntax error in non-interactive shells.
5737 17. POSIX special builtins are found before shell functions during
5740 18. If a POSIX special builtin returns an error status, a
5741 non-interactive shell exits. The fatal errors are those listed in
5742 the POSIX standard, and include things like passing incorrect
5743 options, redirection errors, variable assignment errors for
5744 assignments preceding the command name, and so on.
5746 19. If `CDPATH' is set, the `cd' builtin will not implicitly append
5747 the current directory to it. This means that `cd' will fail if no
5748 valid directory name can be constructed from any of the entries in
5749 `$CDPATH', even if the a directory with the same name as the name
5750 given as an argument to `cd' exists in the current directory.
5752 20. A non-interactive shell exits with an error status if a variable
5753 assignment error occurs when no command name follows the assignment
5754 statements. A variable assignment error occurs, for example, when
5755 trying to assign a value to a readonly variable.
5757 21. A non-interactive shell exits with an error status if the iteration
5758 variable in a `for' statement or the selection variable in a
5759 `select' statement is a readonly variable.
5761 22. Process substitution is not available.
5763 23. Assignment statements preceding POSIX special builtins persist in
5764 the shell environment after the builtin completes.
5766 24. Assignment statements preceding shell function calls persist in the
5767 shell environment after the function returns, as if a POSIX
5768 special builtin command had been executed.
5770 25. The `export' and `readonly' builtin commands display their output
5771 in the format required by POSIX.
5773 26. The `trap' builtin displays signal names without the leading `SIG'.
5775 27. The `trap' builtin doesn't check the first argument for a possible
5776 signal specification and revert the signal handling to the original
5777 disposition if it is, unless that argument consists solely of
5778 digits and is a valid signal number. If users want to reset the
5779 handler for a given signal to the original disposition, they
5780 should use `-' as the first argument.
5782 28. The `.' and `source' builtins do not search the current directory
5783 for the filename argument if it is not found by searching `PATH'.
5785 29. Subshells spawned to execute command substitutions inherit the
5786 value of the `-e' option from the parent shell. When not in POSIX
5787 mode, Bash clears the `-e' option in such subshells.
5789 30. Alias expansion is always enabled, even in non-interactive shells.
5791 31. When the `alias' builtin displays alias definitions, it does not
5792 display them with a leading `alias ' unless the `-p' option is
5795 32. When the `set' builtin is invoked without options, it does not
5796 display shell function names and definitions.
5798 33. When the `set' builtin is invoked without options, it displays
5799 variable values without quotes, unless they contain shell
5800 metacharacters, even if the result contains nonprinting characters.
5802 34. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
5803 constructed from `$PWD' and the directory name supplied as an
5804 argument does not refer to an existing directory, `cd' will fail
5805 instead of falling back to PHYSICAL mode.
5807 35. When the `pwd' builtin is supplied the `-P' option, it resets
5808 `$PWD' to a pathname containing no symlinks.
5810 36. The `pwd' builtin verifies that the value it prints is the same as
5811 the current directory, even if it is not asked to check the file
5812 system with the `-P' option.
5814 37. When listing the history, the `fc' builtin does not include an
5815 indication of whether or not a history entry has been modified.
5817 38. The default editor used by `fc' is `ed'.
5819 39. The `type' and `command' builtins will not report a non-executable
5820 file as having been found, though the shell will attempt to
5821 execute such a file if it is the only so-named file found in
5824 40. The `vi' editing mode will invoke the `vi' editor directly when
5825 the `v' command is run, instead of checking `$VISUAL' and
5828 41. When the `xpg_echo' option is enabled, Bash does not attempt to
5829 interpret any arguments to `echo' as options. Each argument is
5830 displayed, after escape characters are converted.
5832 42. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
5835 43. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
5836 interrupt the `wait' builtin and cause it to return immediately.
5837 The trap command is run once for each child that exits.
5840 There is other POSIX behavior that Bash does not implement by
5841 default even when in POSIX mode. Specifically:
5843 1. The `fc' builtin checks `$EDITOR' as a program to edit history
5844 entries if `FCEDIT' is unset, rather than defaulting directly to
5845 `ed'. `fc' uses `ed' if `EDITOR' is unset.
5847 2. As noted above, Bash requires the `xpg_echo' option to be enabled
5848 for the `echo' builtin to be fully conformant.
5851 Bash can be configured to be POSIX-conformant by default, by
5852 specifying the `--enable-strict-posix-default' to `configure' when
5853 building (*note Optional Features::).
5856 File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
5861 This chapter discusses what job control is, how it works, and how Bash
5862 allows you to access its facilities.
5866 * Job Control Basics:: How job control works.
5867 * Job Control Builtins:: Bash builtin commands used to interact
5869 * Job Control Variables:: Variables Bash uses to customize job
5873 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
5875 7.1 Job Control Basics
5876 ======================
5878 Job control refers to the ability to selectively stop (suspend) the
5879 execution of processes and continue (resume) their execution at a later
5880 point. A user typically employs this facility via an interactive
5881 interface supplied jointly by the operating system kernel's terminal
5884 The shell associates a JOB with each pipeline. It keeps a table of
5885 currently executing jobs, which may be listed with the `jobs' command.
5886 When Bash starts a job asynchronously, it prints a line that looks like:
5888 indicating that this job is job number 1 and that the process ID of
5889 the last process in the pipeline associated with this job is 25647.
5890 All of the processes in a single pipeline are members of the same job.
5891 Bash uses the JOB abstraction as the basis for job control.
5893 To facilitate the implementation of the user interface to job
5894 control, the operating system maintains the notion of a current terminal
5895 process group ID. Members of this process group (processes whose
5896 process group ID is equal to the current terminal process group ID)
5897 receive keyboard-generated signals such as `SIGINT'. These processes
5898 are said to be in the foreground. Background processes are those whose
5899 process group ID differs from the terminal's; such processes are immune
5900 to keyboard-generated signals. Only foreground processes are allowed
5901 to read from or, if the user so specifies with `stty tostop', write to
5902 the terminal. Background processes which attempt to read from (write
5903 to when `stty tostop' is in effect) the terminal are sent a `SIGTTIN'
5904 (`SIGTTOU') signal by the kernel's terminal driver, which, unless
5905 caught, suspends the process.
5907 If the operating system on which Bash is running supports job
5908 control, Bash contains facilities to use it. Typing the SUSPEND
5909 character (typically `^Z', Control-Z) while a process is running causes
5910 that process to be stopped and returns control to Bash. Typing the
5911 DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
5912 process to be stopped when it attempts to read input from the terminal,
5913 and control to be returned to Bash. The user then manipulates the
5914 state of this job, using the `bg' command to continue it in the
5915 background, the `fg' command to continue it in the foreground, or the
5916 `kill' command to kill it. A `^Z' takes effect immediately, and has
5917 the additional side effect of causing pending output and typeahead to
5920 There are a number of ways to refer to a job in the shell. The
5921 character `%' introduces a job specification (JOBSPEC).
5923 Job number `n' may be referred to as `%n'. The symbols `%%' and
5924 `%+' refer to the shell's notion of the current job, which is the last
5925 job stopped while it was in the foreground or started in the background.
5926 A single `%' (with no accompanying job specification) also refers to
5927 the current job. The previous job may be referenced using `%-'. If
5928 there is only a single job, `%+' and `%-' can both be used to refer to
5929 that job. In output pertaining to jobs (e.g., the output of the `jobs'
5930 command), the current job is always flagged with a `+', and the
5931 previous job with a `-'.
5933 A job may also be referred to using a prefix of the name used to
5934 start it, or using a substring that appears in its command line. For
5935 example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other
5936 hand, refers to any job containing the string `ce' in its command line.
5937 If the prefix or substring matches more than one job, Bash reports an
5940 Simply naming a job can be used to bring it into the foreground:
5941 `%1' is a synonym for `fg %1', bringing job 1 from the background into
5942 the foreground. Similarly, `%1 &' resumes job 1 in the background,
5943 equivalent to `bg %1'
5945 The shell learns immediately whenever a job changes state.
5946 Normally, Bash waits until it is about to print a prompt before
5947 reporting changes in a job's status so as to not interrupt any other
5948 output. If the `-b' option to the `set' builtin is enabled, Bash
5949 reports such changes immediately (*note The Set Builtin::). Any trap
5950 on `SIGCHLD' is executed for each child process that exits.
5952 If an attempt to exit Bash is made while jobs are stopped, (or
5953 running, if the `checkjobs' option is enabled - see *note The Shopt
5954 Builtin::), the shell prints a warning message, and if the `checkjobs'
5955 option is enabled, lists the jobs and their statuses. The `jobs'
5956 command may then be used to inspect their status. If a second attempt
5957 to exit is made without an intervening command, Bash does not print
5958 another warning, and any stopped jobs are terminated.
5961 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
5963 7.2 Job Control Builtins
5964 ========================
5968 Resume each suspended job JOBSPEC in the background, as if it had
5969 been started with `&'. If JOBSPEC is not supplied, the current
5970 job is used. The return status is zero unless it is run when job
5971 control is not enabled, or, when run with job control enabled, any
5972 JOBSPEC was not found or specifies a job that was started without
5977 Resume the job JOBSPEC in the foreground and make it the current
5978 job. If JOBSPEC is not supplied, the current job is used. The
5979 return status is that of the command placed into the foreground,
5980 or non-zero if run when job control is disabled or, when run with
5981 job control enabled, JOBSPEC does not specify a valid job or
5982 JOBSPEC specifies a job that was started without job control.
5985 jobs [-lnprs] [JOBSPEC]
5986 jobs -x COMMAND [ARGUMENTS]
5988 The first form lists the active jobs. The options have the
5992 List process IDs in addition to the normal information.
5995 Display information only about jobs that have changed status
5996 since the user was last notified of their status.
5999 List only the process ID of the job's process group leader.
6002 Restrict output to running jobs.
6005 Restrict output to stopped jobs.
6007 If JOBSPEC is given, output is restricted to information about
6008 that job. If JOBSPEC is not supplied, the status of all jobs is
6011 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
6012 in COMMAND or ARGUMENTS with the corresponding process group ID,
6013 and executes COMMAND, passing it ARGUMENTs, returning its exit
6017 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
6018 kill -l [EXIT_STATUS]
6019 Send a signal specified by SIGSPEC or SIGNUM to the process named
6020 by job specification JOBSPEC or process ID PID. SIGSPEC is either
6021 a case-insensitive signal name such as `SIGINT' (with or without
6022 the `SIG' prefix) or a signal number; SIGNUM is a signal number.
6023 If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The
6024 `-l' option lists the signal names. If any arguments are supplied
6025 when `-l' is given, the names of the signals corresponding to the
6026 arguments are listed, and the return status is zero. EXIT_STATUS
6027 is a number specifying a signal number or the exit status of a
6028 process terminated by a signal. The return status is zero if at
6029 least one signal was successfully sent, or non-zero if an error
6030 occurs or an invalid option is encountered.
6033 wait [JOBSPEC or PID ...]
6034 Wait until the child process specified by each process ID PID or
6035 job specification JOBSPEC exits and return the exit status of the
6036 last command waited for. If a job spec is given, all processes in
6037 the job are waited for. If no arguments are given, all currently
6038 active child processes are waited for, and the return status is
6039 zero. If neither JOBSPEC nor PID specifies an active child process
6040 of the shell, the return status is 127.
6043 disown [-ar] [-h] [JOBSPEC ...]
6044 Without options, each JOBSPEC is removed from the table of active
6045 jobs. If the `-h' option is given, the job is not removed from
6046 the table, but is marked so that `SIGHUP' is not sent to the job
6047 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
6048 neither the `-a' nor `-r' option is supplied, the current job is
6049 used. If no JOBSPEC is supplied, the `-a' option means to remove
6050 or mark all jobs; the `-r' option without a JOBSPEC argument
6051 restricts operation to running jobs.
6055 Suspend the execution of this shell until it receives a `SIGCONT'
6056 signal. A login shell cannot be suspended; the `-f' option can be
6057 used to override this and force the suspension.
6060 When job control is not active, the `kill' and `wait' builtins do
6061 not accept JOBSPEC arguments. They must be supplied process IDs.
6064 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
6066 7.3 Job Control Variables
6067 =========================
6070 This variable controls how the shell interacts with the user and
6071 job control. If this variable exists then single word simple
6072 commands without redirections are treated as candidates for
6073 resumption of an existing job. There is no ambiguity allowed; if
6074 there is more than one job beginning with the string typed, then
6075 the most recently accessed job will be selected. The name of a
6076 stopped job, in this context, is the command line used to start
6077 it. If this variable is set to the value `exact', the string
6078 supplied must match the name of a stopped job exactly; if set to
6079 `substring', the string supplied needs to match a substring of the
6080 name of a stopped job. The `substring' value provides
6081 functionality analogous to the `%?' job ID (*note Job Control
6082 Basics::). If set to any other value, the supplied string must be
6083 a prefix of a stopped job's name; this provides functionality
6084 analogous to the `%' job ID.
6088 File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
6090 8 Command Line Editing
6091 **********************
6093 This chapter describes the basic features of the GNU command line
6094 editing interface. Command line editing is provided by the Readline
6095 library, which is used by several different programs, including Bash.
6096 Command line editing is enabled by default when using an interactive
6097 shell, unless the `--noediting' option is supplied at shell invocation.
6098 Line editing is also used when using the `-e' option to the `read'
6099 builtin command (*note Bash Builtins::). By default, the line editing
6100 commands are similar to those of emacs. A vi-style line editing
6101 interface is also available. Line editing can be enabled at any time
6102 using the `-o emacs' or `-o vi' options to the `set' builtin command
6103 (*note The Set Builtin::), or disabled using the `+o emacs' or `+o vi'
6108 * Introduction and Notation:: Notation used in this text.
6109 * Readline Interaction:: The minimum set of commands for editing a line.
6110 * Readline Init File:: Customizing Readline from a user's view.
6111 * Bindable Readline Commands:: A description of most of the Readline commands
6112 available for binding
6113 * Readline vi Mode:: A short description of how to make Readline
6114 behave like the vi editor.
6116 * Programmable Completion:: How to specify the possible completions for
6118 * Programmable Completion Builtins:: Builtin commands to specify how to
6119 complete arguments for a particular command.
6122 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
6124 8.1 Introduction to Line Editing
6125 ================================
6127 The following paragraphs describe the notation used to represent
6130 The text `C-k' is read as `Control-K' and describes the character
6131 produced when the <k> key is pressed while the Control key is depressed.
6133 The text `M-k' is read as `Meta-K' and describes the character
6134 produced when the Meta key (if you have one) is depressed, and the <k>
6135 key is pressed. The Meta key is labeled <ALT> on many keyboards. On
6136 keyboards with two keys labeled <ALT> (usually to either side of the
6137 space bar), the <ALT> on the left side is generally set to work as a
6138 Meta key. The <ALT> key on the right may also be configured to work as
6139 a Meta key or may be configured as some other modifier, such as a
6140 Compose key for typing accented characters.
6142 If you do not have a Meta or <ALT> key, or another key working as a
6143 Meta key, the identical keystroke can be generated by typing <ESC>
6144 _first_, and then typing <k>. Either process is known as "metafying"
6147 The text `M-C-k' is read as `Meta-Control-k' and describes the
6148 character produced by "metafying" `C-k'.
6150 In addition, several keys have their own names. Specifically,
6151 <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
6152 when seen in this text, or in an init file (*note Readline Init File::).
6153 If your keyboard lacks a <LFD> key, typing <C-j> will produce the
6154 desired character. The <RET> key may be labeled <Return> or <Enter> on
6158 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
6160 8.2 Readline Interaction
6161 ========================
6163 Often during an interactive session you type in a long line of text,
6164 only to notice that the first word on the line is misspelled. The
6165 Readline library gives you a set of commands for manipulating the text
6166 as you type it in, allowing you to just fix your typo, and not forcing
6167 you to retype the majority of the line. Using these editing commands,
6168 you move the cursor to the place that needs correction, and delete or
6169 insert the text of the corrections. Then, when you are satisfied with
6170 the line, you simply press <RET>. You do not have to be at the end of
6171 the line to press <RET>; the entire line is accepted regardless of the
6172 location of the cursor within the line.
6176 * Readline Bare Essentials:: The least you need to know about Readline.
6177 * Readline Movement Commands:: Moving about the input line.
6178 * Readline Killing Commands:: How to delete text, and how to get it back!
6179 * Readline Arguments:: Giving numeric arguments to commands.
6180 * Searching:: Searching through previous lines.
6183 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
6185 8.2.1 Readline Bare Essentials
6186 ------------------------------
6188 In order to enter characters into the line, simply type them. The typed
6189 character appears where the cursor was, and then the cursor moves one
6190 space to the right. If you mistype a character, you can use your erase
6191 character to back up and delete the mistyped character.
6193 Sometimes you may mistype a character, and not notice the error
6194 until you have typed several other characters. In that case, you can
6195 type `C-b' to move the cursor to the left, and then correct your
6196 mistake. Afterwards, you can move the cursor to the right with `C-f'.
6198 When you add text in the middle of a line, you will notice that
6199 characters to the right of the cursor are `pushed over' to make room
6200 for the text that you have inserted. Likewise, when you delete text
6201 behind the cursor, characters to the right of the cursor are `pulled
6202 back' to fill in the blank space created by the removal of the text. A
6203 list of the bare essentials for editing the text of an input line
6207 Move back one character.
6210 Move forward one character.
6212 <DEL> or <Backspace>
6213 Delete the character to the left of the cursor.
6216 Delete the character underneath the cursor.
6219 Insert the character into the line at the cursor.
6222 Undo the last editing command. You can undo all the way back to an
6225 (Depending on your configuration, the <Backspace> key be set to delete
6226 the character to the left of the cursor and the <DEL> key set to delete
6227 the character underneath the cursor, like `C-d', rather than the
6228 character to the left of the cursor.)
6231 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
6233 8.2.2 Readline Movement Commands
6234 --------------------------------
6236 The above table describes the most basic keystrokes that you need in
6237 order to do editing of the input line. For your convenience, many
6238 other commands have been added in addition to `C-b', `C-f', `C-d', and
6239 <DEL>. Here are some commands for moving more rapidly about the line.
6242 Move to the start of the line.
6245 Move to the end of the line.
6248 Move forward a word, where a word is composed of letters and
6252 Move backward a word.
6255 Clear the screen, reprinting the current line at the top.
6257 Notice how `C-f' moves forward a character, while `M-f' moves
6258 forward a word. It is a loose convention that control keystrokes
6259 operate on characters while meta keystrokes operate on words.
6262 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
6264 8.2.3 Readline Killing Commands
6265 -------------------------------
6267 "Killing" text means to delete the text from the line, but to save it
6268 away for later use, usually by "yanking" (re-inserting) it back into
6269 the line. (`Cut' and `paste' are more recent jargon for `kill' and
6272 If the description for a command says that it `kills' text, then you
6273 can be sure that you can get the text back in a different (or the same)
6276 When you use a kill command, the text is saved in a "kill-ring".
6277 Any number of consecutive kills save all of the killed text together, so
6278 that when you yank it back, you get it all. The kill ring is not line
6279 specific; the text that you killed on a previously typed line is
6280 available to be yanked back later, when you are typing another line.
6282 Here is the list of commands for killing text.
6285 Kill the text from the current cursor position to the end of the
6289 Kill from the cursor to the end of the current word, or, if between
6290 words, to the end of the next word. Word boundaries are the same
6291 as those used by `M-f'.
6294 Kill from the cursor the start of the current word, or, if between
6295 words, to the start of the previous word. Word boundaries are the
6296 same as those used by `M-b'.
6299 Kill from the cursor to the previous whitespace. This is
6300 different than `M-<DEL>' because the word boundaries differ.
6303 Here is how to "yank" the text back into the line. Yanking means to
6304 copy the most-recently-killed text from the kill buffer.
6307 Yank the most recently killed text back into the buffer at the
6311 Rotate the kill-ring, and yank the new top. You can only do this
6312 if the prior command is `C-y' or `M-y'.
6315 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
6317 8.2.4 Readline Arguments
6318 ------------------------
6320 You can pass numeric arguments to Readline commands. Sometimes the
6321 argument acts as a repeat count, other times it is the sign of the
6322 argument that is significant. If you pass a negative argument to a
6323 command which normally acts in a forward direction, that command will
6324 act in a backward direction. For example, to kill text back to the
6325 start of the line, you might type `M-- C-k'.
6327 The general way to pass numeric arguments to a command is to type
6328 meta digits before the command. If the first `digit' typed is a minus
6329 sign (`-'), then the sign of the argument will be negative. Once you
6330 have typed one meta digit to get the argument started, you can type the
6331 remainder of the digits, and then the command. For example, to give
6332 the `C-d' command an argument of 10, you could type `M-1 0 C-d', which
6333 will delete the next ten characters on the input line.
6336 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
6338 8.2.5 Searching for Commands in the History
6339 -------------------------------------------
6341 Readline provides commands for searching through the command history
6342 (*note Bash History Facilities::) for lines containing a specified
6343 string. There are two search modes: "incremental" and
6346 Incremental searches begin before the user has finished typing the
6347 search string. As each character of the search string is typed,
6348 Readline displays the next entry from the history matching the string
6349 typed so far. An incremental search requires only as many characters
6350 as needed to find the desired history entry. To search backward in the
6351 history for a particular string, type `C-r'. Typing `C-s' searches
6352 forward through the history. The characters present in the value of
6353 the `isearch-terminators' variable are used to terminate an incremental
6354 search. If that variable has not been assigned a value, the <ESC> and
6355 `C-J' characters will terminate an incremental search. `C-g' will
6356 abort an incremental search and restore the original line. When the
6357 search is terminated, the history entry containing the search string
6358 becomes the current line.
6360 To find other matching entries in the history list, type `C-r' or
6361 `C-s' as appropriate. This will search backward or forward in the
6362 history for the next entry matching the search string typed so far.
6363 Any other key sequence bound to a Readline command will terminate the
6364 search and execute that command. For instance, a <RET> will terminate
6365 the search and accept the line, thereby executing the command from the
6366 history list. A movement command will terminate the search, make the
6367 last line found the current line, and begin editing.
6369 Readline remembers the last incremental search string. If two
6370 `C-r's are typed without any intervening characters defining a new
6371 search string, any remembered search string is used.
6373 Non-incremental searches read the entire search string before
6374 starting to search for matching history lines. The search string may be
6375 typed by the user or be part of the contents of the current line.
6378 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
6380 8.3 Readline Init File
6381 ======================
6383 Although the Readline library comes with a set of Emacs-like
6384 keybindings installed by default, it is possible to use a different set
6385 of keybindings. Any user can customize programs that use Readline by
6386 putting commands in an "inputrc" file, conventionally in his home
6387 directory. The name of this file is taken from the value of the shell
6388 variable `INPUTRC'. If that variable is unset, the default is
6389 `~/.inputrc'. If that file does not exist or cannot be read, the
6390 ultimate default is `/etc/inputrc'.
6392 When a program which uses the Readline library starts up, the init
6393 file is read, and the key bindings are set.
6395 In addition, the `C-x C-r' command re-reads this init file, thus
6396 incorporating any changes that you might have made to it.
6400 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
6402 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
6404 * Sample Init File:: An example inputrc file.
6407 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
6409 8.3.1 Readline Init File Syntax
6410 -------------------------------
6412 There are only a few basic constructs allowed in the Readline init
6413 file. Blank lines are ignored. Lines beginning with a `#' are
6414 comments. Lines beginning with a `$' indicate conditional constructs
6415 (*note Conditional Init Constructs::). Other lines denote variable
6416 settings and key bindings.
6419 You can modify the run-time behavior of Readline by altering the
6420 values of variables in Readline using the `set' command within the
6421 init file. The syntax is simple:
6425 Here, for example, is how to change from the default Emacs-like
6426 key binding to use `vi' line editing commands:
6430 Variable names and values, where appropriate, are recognized
6431 without regard to case. Unrecognized variable names are ignored.
6433 Boolean variables (those that can be set to on or off) are set to
6434 on if the value is null or empty, ON (case-insensitive), or 1.
6435 Any other value results in the variable being set to off.
6437 The `bind -V' command lists the current Readline variable names
6438 and values. *Note Bash Builtins::.
6440 A great deal of run-time behavior is changeable with the following
6444 Controls what happens when Readline wants to ring the
6445 terminal bell. If set to `none', Readline never rings the
6446 bell. If set to `visible', Readline uses a visible bell if
6447 one is available. If set to `audible' (the default),
6448 Readline attempts to ring the terminal's bell.
6450 `bind-tty-special-chars'
6451 If set to `on', Readline attempts to bind the control
6452 characters treated specially by the kernel's terminal driver
6453 to their Readline equivalents.
6456 The string to insert at the beginning of the line when the
6457 `insert-comment' command is executed. The default value is
6460 `completion-ignore-case'
6461 If set to `on', Readline performs filename matching and
6462 completion in a case-insensitive fashion. The default value
6465 `completion-prefix-display-length'
6466 The length in characters of the common prefix of a list of
6467 possible completions that is displayed without modification.
6468 When set to a value greater than zero, common prefixes longer
6469 than this value are replaced with an ellipsis when displaying
6470 possible completions.
6472 `completion-query-items'
6473 The number of possible completions that determines when the
6474 user is asked whether the list of possibilities should be
6475 displayed. If the number of possible completions is greater
6476 than this value, Readline will ask the user whether or not he
6477 wishes to view them; otherwise, they are simply listed. This
6478 variable must be set to an integer value greater than or
6479 equal to 0. A negative value means Readline should never ask.
6480 The default limit is `100'.
6483 If set to `on', Readline will convert characters with the
6484 eighth bit set to an ASCII key sequence by stripping the
6485 eighth bit and prefixing an <ESC> character, converting them
6486 to a meta-prefixed key sequence. The default value is `on'.
6488 `disable-completion'
6489 If set to `On', Readline will inhibit word completion.
6490 Completion characters will be inserted into the line as if
6491 they had been mapped to `self-insert'. The default is `off'.
6494 The `editing-mode' variable controls which default set of key
6495 bindings is used. By default, Readline starts up in Emacs
6496 editing mode, where the keystrokes are most similar to Emacs.
6497 This variable can be set to either `emacs' or `vi'.
6499 `echo-control-characters'
6500 When set to `on', on operating systems that indicate they
6501 support it, readline echoes a character corresponding to a
6502 signal generated from the keyboard. The default is `on'.
6505 When set to `on', Readline will try to enable the application
6506 keypad when it is called. Some systems need this to enable
6507 the arrow keys. The default is `off'.
6510 When set to `on', Readline will try to enable any meta
6511 modifier key the terminal claims to support when it is
6512 called. On many terminals, the meta key is used to send
6513 eight-bit characters. The default is `on'.
6516 If set to `on', tilde expansion is performed when Readline
6517 attempts word completion. The default is `off'.
6519 `history-preserve-point'
6520 If set to `on', the history code attempts to place the point
6521 (the current cursor position) at the same location on each
6522 history line retrieved with `previous-history' or
6523 `next-history'. The default is `off'.
6526 Set the maximum number of history entries saved in the
6527 history list. If set to zero, the number of entries in the
6528 history list is not limited.
6530 `horizontal-scroll-mode'
6531 This variable can be set to either `on' or `off'. Setting it
6532 to `on' means that the text of the lines being edited will
6533 scroll horizontally on a single screen line when they are
6534 longer than the width of the screen, instead of wrapping onto
6535 a new screen line. By default, this variable is set to `off'.
6538 If set to `on', Readline will enable eight-bit input (it will
6539 not clear the eighth bit in the characters it reads),
6540 regardless of what the terminal claims it can support. The
6541 default value is `off'. The name `meta-flag' is a synonym
6544 `isearch-terminators'
6545 The string of characters that should terminate an incremental
6546 search without subsequently executing the character as a
6547 command (*note Searching::). If this variable has not been
6548 given a value, the characters <ESC> and `C-J' will terminate
6549 an incremental search.
6552 Sets Readline's idea of the current keymap for key binding
6553 commands. Acceptable `keymap' names are `emacs',
6554 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
6555 `vi-command', and `vi-insert'. `vi' is equivalent to
6556 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
6557 default value is `emacs'. The value of the `editing-mode'
6558 variable also affects the default keymap.
6561 If set to `on', completed directory names have a slash
6562 appended. The default is `on'.
6564 `mark-modified-lines'
6565 This variable, when set to `on', causes Readline to display an
6566 asterisk (`*') at the start of history lines which have been
6567 modified. This variable is `off' by default.
6569 `mark-symlinked-directories'
6570 If set to `on', completed names which are symbolic links to
6571 directories have a slash appended (subject to the value of
6572 `mark-directories'). The default is `off'.
6574 `match-hidden-files'
6575 This variable, when set to `on', causes Readline to match
6576 files whose names begin with a `.' (hidden files) when
6577 performing filename completion, unless the leading `.' is
6578 supplied by the user in the filename to be completed. This
6579 variable is `on' by default.
6582 If set to `on', Readline will display characters with the
6583 eighth bit set directly rather than as a meta-prefixed escape
6584 sequence. The default is `off'.
6587 If set to `on', Readline uses an internal `more'-like pager
6588 to display a screenful of possible completions at a time.
6589 This variable is `on' by default.
6591 `print-completions-horizontally'
6592 If set to `on', Readline will display completions with matches
6593 sorted horizontally in alphabetical order, rather than down
6594 the screen. The default is `off'.
6596 `revert-all-at-newline'
6597 If set to `on', Readline will undo all changes to history
6598 lines before returning when `accept-line' is executed. By
6599 default, history lines may be modified and retain individual
6600 undo lists across calls to `readline'. The default is `off'.
6602 `show-all-if-ambiguous'
6603 This alters the default behavior of the completion functions.
6604 If set to `on', words which have more than one possible
6605 completion cause the matches to be listed immediately instead
6606 of ringing the bell. The default value is `off'.
6608 `show-all-if-unmodified'
6609 This alters the default behavior of the completion functions
6610 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
6611 `on', words which have more than one possible completion
6612 without any possible partial completion (the possible
6613 completions don't share a common prefix) cause the matches to
6614 be listed immediately instead of ringing the bell. The
6615 default value is `off'.
6617 `skip-completed-text'
6618 If set to `on', this alters the default completion behavior
6619 when inserting a single match into the line. It's only
6620 active when performing completion in the middle of a word.
6621 If enabled, readline does not insert characters from the
6622 completion that match characters after point in the word
6623 being completed, so portions of the word following the cursor
6624 are not duplicated. For instance, if this is enabled,
6625 attempting completion when the cursor is after the `e' in
6626 `Makefile' will result in `Makefile' rather than
6627 `Makefilefile', assuming there is a single possible
6628 completion. The default value is `off'.
6631 If set to `on', a character denoting a file's type is
6632 appended to the filename when listing possible completions.
6633 The default is `off'.
6637 The syntax for controlling key bindings in the init file is
6638 simple. First you need to find the name of the command that you
6639 want to change. The following sections contain tables of the
6640 command name, the default keybinding, if any, and a short
6641 description of what the command does.
6643 Once you know the name of the command, simply place on a line in
6644 the init file the name of the key you wish to bind the command to,
6645 a colon, and then the name of the command. There can be no space
6646 between the key name and the colon - that will be interpreted as
6647 part of the key name. The name of the key can be expressed in
6648 different ways, depending on what you find most comfortable.
6650 In addition to command names, readline allows keys to be bound to
6651 a string that is inserted when the key is pressed (a MACRO).
6653 The `bind -p' command displays Readline function names and
6654 bindings in a format that can put directly into an initialization
6655 file. *Note Bash Builtins::.
6657 KEYNAME: FUNCTION-NAME or MACRO
6658 KEYNAME is the name of a key spelled out in English. For
6660 Control-u: universal-argument
6661 Meta-Rubout: backward-kill-word
6662 Control-o: "> output"
6664 In the above example, `C-u' is bound to the function
6665 `universal-argument', `M-DEL' is bound to the function
6666 `backward-kill-word', and `C-o' is bound to run the macro
6667 expressed on the right hand side (that is, to insert the text
6668 `> output' into the line).
6670 A number of symbolic character names are recognized while
6671 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
6672 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
6674 "KEYSEQ": FUNCTION-NAME or MACRO
6675 KEYSEQ differs from KEYNAME above in that strings denoting an
6676 entire key sequence can be specified, by placing the key
6677 sequence in double quotes. Some GNU Emacs style key escapes
6678 can be used, as in the following example, but the special
6679 character names are not recognized.
6681 "\C-u": universal-argument
6682 "\C-x\C-r": re-read-init-file
6683 "\e[11~": "Function Key 1"
6685 In the above example, `C-u' is again bound to the function
6686 `universal-argument' (just as it was in the first example),
6687 `C-x C-r' is bound to the function `re-read-init-file', and
6688 `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function
6692 The following GNU Emacs style escape sequences are available when
6693 specifying key sequences:
6708 <">, a double quotation mark
6711 <'>, a single quote or apostrophe
6713 In addition to the GNU Emacs style escape sequences, a second set
6714 of backslash escapes is available:
6741 the eight-bit character whose value is the octal value NNN
6742 (one to three digits)
6745 the eight-bit character whose value is the hexadecimal value
6746 HH (one or two hex digits)
6748 When entering the text of a macro, single or double quotes must be
6749 used to indicate a macro definition. Unquoted text is assumed to
6750 be a function name. In the macro body, the backslash escapes
6751 described above are expanded. Backslash will quote any other
6752 character in the macro text, including `"' and `''. For example,
6753 the following binding will make `C-x \' insert a single `\' into
6759 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
6761 8.3.2 Conditional Init Constructs
6762 ---------------------------------
6764 Readline implements a facility similar in spirit to the conditional
6765 compilation features of the C preprocessor which allows key bindings
6766 and variable settings to be performed as the result of tests. There
6767 are four parser directives used.
6770 The `$if' construct allows bindings to be made based on the
6771 editing mode, the terminal being used, or the application using
6772 Readline. The text of the test extends to the end of the line; no
6773 characters are required to isolate it.
6776 The `mode=' form of the `$if' directive is used to test
6777 whether Readline is in `emacs' or `vi' mode. This may be
6778 used in conjunction with the `set keymap' command, for
6779 instance, to set bindings in the `emacs-standard' and
6780 `emacs-ctlx' keymaps only if Readline is starting out in
6784 The `term=' form may be used to include terminal-specific key
6785 bindings, perhaps to bind the key sequences output by the
6786 terminal's function keys. The word on the right side of the
6787 `=' is tested against both the full name of the terminal and
6788 the portion of the terminal name before the first `-'. This
6789 allows `sun' to match both `sun' and `sun-cmd', for instance.
6792 The APPLICATION construct is used to include
6793 application-specific settings. Each program using the
6794 Readline library sets the APPLICATION NAME, and you can test
6795 for a particular value. This could be used to bind key
6796 sequences to functions useful for a specific program. For
6797 instance, the following command adds a key sequence that
6798 quotes the current or previous word in Bash:
6800 # Quote the current or previous word
6801 "\C-xq": "\eb\"\ef\""
6805 This command, as seen in the previous example, terminates an `$if'
6809 Commands in this branch of the `$if' directive are executed if the
6813 This directive takes a single filename as an argument and reads
6814 commands and bindings from that file. For example, the following
6815 directive reads from `/etc/inputrc':
6816 $include /etc/inputrc
6819 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
6821 8.3.3 Sample Init File
6822 ----------------------
6824 Here is an example of an INPUTRC file. This illustrates key binding,
6825 variable assignment, and conditional syntax.
6828 # This file controls the behaviour of line input editing for
6829 # programs that use the GNU Readline library. Existing
6830 # programs include FTP, Bash, and GDB.
6832 # You can re-read the inputrc file with C-x C-r.
6833 # Lines beginning with '#' are comments.
6835 # First, include any systemwide bindings and variable
6836 # assignments from /etc/Inputrc
6837 $include /etc/Inputrc
6840 # Set various bindings for emacs mode.
6842 set editing-mode emacs
6846 Meta-Control-h: backward-kill-word Text after the function name is ignored
6849 # Arrow keys in keypad mode
6851 #"\M-OD": backward-char
6852 #"\M-OC": forward-char
6853 #"\M-OA": previous-history
6854 #"\M-OB": next-history
6856 # Arrow keys in ANSI mode
6858 "\M-[D": backward-char
6859 "\M-[C": forward-char
6860 "\M-[A": previous-history
6861 "\M-[B": next-history
6863 # Arrow keys in 8 bit keypad mode
6865 #"\M-\C-OD": backward-char
6866 #"\M-\C-OC": forward-char
6867 #"\M-\C-OA": previous-history
6868 #"\M-\C-OB": next-history
6870 # Arrow keys in 8 bit ANSI mode
6872 #"\M-\C-[D": backward-char
6873 #"\M-\C-[C": forward-char
6874 #"\M-\C-[A": previous-history
6875 #"\M-\C-[B": next-history
6881 # An old-style binding. This happens to be the default.
6884 # Macros that are convenient for shell interaction
6887 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
6888 # prepare to type a quoted word --
6889 # insert open and close double quotes
6890 # and move to just after the open quote
6891 "\C-x\"": "\"\"\C-b"
6892 # insert a backslash (testing backslash escapes
6893 # in sequences and macros)
6895 # Quote the current or previous word
6896 "\C-xq": "\eb\"\ef\""
6897 # Add a binding to refresh the line, which is unbound
6898 "\C-xr": redraw-current-line
6899 # Edit variable on current line.
6900 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
6903 # use a visible bell if one is available
6904 set bell-style visible
6906 # don't strip characters to 7 bits when reading
6909 # allow iso-latin1 characters to be inserted rather
6910 # than converted to prefix-meta sequences
6911 set convert-meta off
6913 # display characters with the eighth bit set directly
6914 # rather than as meta-prefixed characters
6917 # if there are more than 150 possible completions for
6918 # a word, ask the user if he wants to see all of them
6919 set completion-query-items 150
6925 "\M-.": yank-last-arg
6929 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
6931 8.4 Bindable Readline Commands
6932 ==============================
6936 * Commands For Moving:: Moving about the line.
6937 * Commands For History:: Getting at previous lines.
6938 * Commands For Text:: Commands for changing text.
6939 * Commands For Killing:: Commands for killing and yanking.
6940 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
6941 * Commands For Completion:: Getting Readline to do the typing for you.
6942 * Keyboard Macros:: Saving and re-executing typed characters
6943 * Miscellaneous Commands:: Other miscellaneous commands.
6945 This section describes Readline commands that may be bound to key
6946 sequences. You can list your key bindings by executing `bind -P' or,
6947 for a more terse format, suitable for an INPUTRC file, `bind -p'.
6948 (*Note Bash Builtins::.) Command names without an accompanying key
6949 sequence are unbound by default.
6951 In the following descriptions, "point" refers to the current cursor
6952 position, and "mark" refers to a cursor position saved by the
6953 `set-mark' command. The text between the point and mark is referred to
6957 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
6959 8.4.1 Commands For Moving
6960 -------------------------
6962 `beginning-of-line (C-a)'
6963 Move to the start of the current line.
6966 Move to the end of the line.
6968 `forward-char (C-f)'
6969 Move forward a character.
6971 `backward-char (C-b)'
6972 Move back a character.
6974 `forward-word (M-f)'
6975 Move forward to the end of the next word. Words are composed of
6978 `backward-word (M-b)'
6979 Move back to the start of the current or previous word. Words are
6980 composed of letters and digits.
6982 `shell-forward-word ()'
6983 Move forward to the end of the next word. Words are delimited by
6984 non-quoted shell metacharacters.
6986 `shell-backward-word ()'
6987 Move back to the start of the current or previous word. Words are
6988 delimited by non-quoted shell metacharacters.
6990 `clear-screen (C-l)'
6991 Clear the screen and redraw the current line, leaving the current
6992 line at the top of the screen.
6994 `redraw-current-line ()'
6995 Refresh the current line. By default, this is unbound.
6999 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
7001 8.4.2 Commands For Manipulating The History
7002 -------------------------------------------
7004 `accept-line (Newline or Return)'
7005 Accept the line regardless of where the cursor is. If this line is
7006 non-empty, add it to the history list according to the setting of
7007 the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a
7008 modified history line, then restore the history line to its
7011 `previous-history (C-p)'
7012 Move `back' through the history list, fetching the previous
7015 `next-history (C-n)'
7016 Move `forward' through the history list, fetching the next command.
7018 `beginning-of-history (M-<)'
7019 Move to the first line in the history.
7021 `end-of-history (M->)'
7022 Move to the end of the input history, i.e., the line currently
7025 `reverse-search-history (C-r)'
7026 Search backward starting at the current line and moving `up'
7027 through the history as necessary. This is an incremental search.
7029 `forward-search-history (C-s)'
7030 Search forward starting at the current line and moving `down'
7031 through the the history as necessary. This is an incremental
7034 `non-incremental-reverse-search-history (M-p)'
7035 Search backward starting at the current line and moving `up'
7036 through the history as necessary using a non-incremental search
7037 for a string supplied by the user.
7039 `non-incremental-forward-search-history (M-n)'
7040 Search forward starting at the current line and moving `down'
7041 through the the history as necessary using a non-incremental search
7042 for a string supplied by the user.
7044 `history-search-forward ()'
7045 Search forward through the history for the string of characters
7046 between the start of the current line and the point. This is a
7047 non-incremental search. By default, this command is unbound.
7049 `history-search-backward ()'
7050 Search backward through the history for the string of characters
7051 between the start of the current line and the point. This is a
7052 non-incremental search. By default, this command is unbound.
7054 `yank-nth-arg (M-C-y)'
7055 Insert the first argument to the previous command (usually the
7056 second word on the previous line) at point. With an argument N,
7057 insert the Nth word from the previous command (the words in the
7058 previous command begin with word 0). A negative argument inserts
7059 the Nth word from the end of the previous command. Once the
7060 argument N is computed, the argument is extracted as if the `!N'
7061 history expansion had been specified.
7063 `yank-last-arg (M-. or M-_)'
7064 Insert last argument to the previous command (the last word of the
7065 previous history entry). With an argument, behave exactly like
7066 `yank-nth-arg'. Successive calls to `yank-last-arg' move back
7067 through the history list, inserting the last argument of each line
7068 in turn. The history expansion facilities are used to extract the
7069 last argument, as if the `!$' history expansion had been specified.
7073 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
7075 8.4.3 Commands For Changing Text
7076 --------------------------------
7079 Delete the character at point. If point is at the beginning of
7080 the line, there are no characters in the line, and the last
7081 character typed was not bound to `delete-char', then return EOF.
7083 `backward-delete-char (Rubout)'
7084 Delete the character behind the cursor. A numeric argument means
7085 to kill the characters instead of deleting them.
7087 `forward-backward-delete-char ()'
7088 Delete the character under the cursor, unless the cursor is at the
7089 end of the line, in which case the character behind the cursor is
7090 deleted. By default, this is not bound to a key.
7092 `quoted-insert (C-q or C-v)'
7093 Add the next character typed to the line verbatim. This is how to
7094 insert key sequences like `C-q', for example.
7096 `self-insert (a, b, A, 1, !, ...)'
7099 `transpose-chars (C-t)'
7100 Drag the character before the cursor forward over the character at
7101 the cursor, moving the cursor forward as well. If the insertion
7102 point is at the end of the line, then this transposes the last two
7103 characters of the line. Negative arguments have no effect.
7105 `transpose-words (M-t)'
7106 Drag the word before point past the word after point, moving point
7107 past that word as well. If the insertion point is at the end of
7108 the line, this transposes the last two words on the line.
7111 Uppercase the current (or following) word. With a negative
7112 argument, uppercase the previous word, but do not move the cursor.
7114 `downcase-word (M-l)'
7115 Lowercase the current (or following) word. With a negative
7116 argument, lowercase the previous word, but do not move the cursor.
7118 `capitalize-word (M-c)'
7119 Capitalize the current (or following) word. With a negative
7120 argument, capitalize the previous word, but do not move the cursor.
7123 Toggle overwrite mode. With an explicit positive numeric argument,
7124 switches to overwrite mode. With an explicit non-positive numeric
7125 argument, switches to insert mode. This command affects only
7126 `emacs' mode; `vi' mode does overwrite differently. Each call to
7127 `readline()' starts in insert mode.
7129 In overwrite mode, characters bound to `self-insert' replace the
7130 text at point rather than pushing the text to the right.
7131 Characters bound to `backward-delete-char' replace the character
7132 before point with a space.
7134 By default, this command is unbound.
7138 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
7140 8.4.4 Killing And Yanking
7141 -------------------------
7144 Kill the text from point to the end of the line.
7146 `backward-kill-line (C-x Rubout)'
7147 Kill backward to the beginning of the line.
7149 `unix-line-discard (C-u)'
7150 Kill backward from the cursor to the beginning of the current line.
7152 `kill-whole-line ()'
7153 Kill all characters on the current line, no matter where point is.
7154 By default, this is unbound.
7157 Kill from point to the end of the current word, or if between
7158 words, to the end of the next word. Word boundaries are the same
7161 `backward-kill-word (M-<DEL>)'
7162 Kill the word behind point. Word boundaries are the same as
7165 `shell-kill-word ()'
7166 Kill from point to the end of the current word, or if between
7167 words, to the end of the next word. Word boundaries are the same
7168 as `shell-forward-word'.
7170 `backward-kill-word ()'
7171 Kill the word behind point. Word boundaries are the same as
7172 `shell-backward-word'.
7174 `unix-word-rubout (C-w)'
7175 Kill the word behind point, using white space as a word boundary.
7176 The killed text is saved on the kill-ring.
7178 `unix-filename-rubout ()'
7179 Kill the word behind point, using white space and the slash
7180 character as the word boundaries. The killed text is saved on the
7183 `delete-horizontal-space ()'
7184 Delete all spaces and tabs around point. By default, this is
7188 Kill the text in the current region. By default, this command is
7191 `copy-region-as-kill ()'
7192 Copy the text in the region to the kill buffer, so it can be yanked
7193 right away. By default, this command is unbound.
7195 `copy-backward-word ()'
7196 Copy the word before point to the kill buffer. The word
7197 boundaries are the same as `backward-word'. By default, this
7200 `copy-forward-word ()'
7201 Copy the word following point to the kill buffer. The word
7202 boundaries are the same as `forward-word'. By default, this
7206 Yank the top of the kill ring into the buffer at point.
7209 Rotate the kill-ring, and yank the new top. You can only do this
7210 if the prior command is `yank' or `yank-pop'.
7213 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
7215 8.4.5 Specifying Numeric Arguments
7216 ----------------------------------
7218 `digit-argument (M-0, M-1, ... M--)'
7219 Add this digit to the argument already accumulating, or start a new
7220 argument. `M--' starts a negative argument.
7222 `universal-argument ()'
7223 This is another way to specify an argument. If this command is
7224 followed by one or more digits, optionally with a leading minus
7225 sign, those digits define the argument. If the command is
7226 followed by digits, executing `universal-argument' again ends the
7227 numeric argument, but is otherwise ignored. As a special case, if
7228 this command is immediately followed by a character that is
7229 neither a digit or minus sign, the argument count for the next
7230 command is multiplied by four. The argument count is initially
7231 one, so executing this function the first time makes the argument
7232 count four, a second time makes the argument count sixteen, and so
7233 on. By default, this is not bound to a key.
7236 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
7238 8.4.6 Letting Readline Type For You
7239 -----------------------------------
7242 Attempt to perform completion on the text before point. The
7243 actual completion performed is application-specific. Bash
7244 attempts completion treating the text as a variable (if the text
7245 begins with `$'), username (if the text begins with `~'), hostname
7246 (if the text begins with `@'), or command (including aliases and
7247 functions) in turn. If none of these produces a match, filename
7248 completion is attempted.
7250 `possible-completions (M-?)'
7251 List the possible completions of the text before point.
7253 `insert-completions (M-*)'
7254 Insert all completions of the text before point that would have
7255 been generated by `possible-completions'.
7258 Similar to `complete', but replaces the word to be completed with
7259 a single match from the list of possible completions. Repeated
7260 execution of `menu-complete' steps through the list of possible
7261 completions, inserting each match in turn. At the end of the list
7262 of completions, the bell is rung (subject to the setting of
7263 `bell-style') and the original text is restored. An argument of N
7264 moves N positions forward in the list of matches; a negative
7265 argument may be used to move backward through the list. This
7266 command is intended to be bound to <TAB>, but is unbound by
7269 `menu-complete-backward ()'
7270 Identical to `menu-complete', but moves backward through the list
7271 of possible completions, as if `menu-complete' had been given a
7274 `delete-char-or-list ()'
7275 Deletes the character under the cursor if not at the beginning or
7276 end of the line (like `delete-char'). If at the end of the line,
7277 behaves identically to `possible-completions'. This command is
7280 `complete-filename (M-/)'
7281 Attempt filename completion on the text before point.
7283 `possible-filename-completions (C-x /)'
7284 List the possible completions of the text before point, treating
7287 `complete-username (M-~)'
7288 Attempt completion on the text before point, treating it as a
7291 `possible-username-completions (C-x ~)'
7292 List the possible completions of the text before point, treating
7295 `complete-variable (M-$)'
7296 Attempt completion on the text before point, treating it as a
7299 `possible-variable-completions (C-x $)'
7300 List the possible completions of the text before point, treating
7301 it as a shell variable.
7303 `complete-hostname (M-@)'
7304 Attempt completion on the text before point, treating it as a
7307 `possible-hostname-completions (C-x @)'
7308 List the possible completions of the text before point, treating
7311 `complete-command (M-!)'
7312 Attempt completion on the text before point, treating it as a
7313 command name. Command completion attempts to match the text
7314 against aliases, reserved words, shell functions, shell builtins,
7315 and finally executable filenames, in that order.
7317 `possible-command-completions (C-x !)'
7318 List the possible completions of the text before point, treating
7319 it as a command name.
7321 `dynamic-complete-history (M-<TAB>)'
7322 Attempt completion on the text before point, comparing the text
7323 against lines from the history list for possible completion
7327 Attempt menu completion on the text before point, comparing the
7328 text against lines from the history list for possible completion
7331 `complete-into-braces (M-{)'
7332 Perform filename completion and insert the list of possible
7333 completions enclosed within braces so the list is available to the
7334 shell (*note Brace Expansion::).
7338 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
7340 8.4.7 Keyboard Macros
7341 ---------------------
7343 `start-kbd-macro (C-x ()'
7344 Begin saving the characters typed into the current keyboard macro.
7346 `end-kbd-macro (C-x ))'
7347 Stop saving the characters typed into the current keyboard macro
7348 and save the definition.
7350 `call-last-kbd-macro (C-x e)'
7351 Re-execute the last keyboard macro defined, by making the
7352 characters in the macro appear as if typed at the keyboard.
7356 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
7358 8.4.8 Some Miscellaneous Commands
7359 ---------------------------------
7361 `re-read-init-file (C-x C-r)'
7362 Read in the contents of the INPUTRC file, and incorporate any
7363 bindings or variable assignments found there.
7366 Abort the current editing command and ring the terminal's bell
7367 (subject to the setting of `bell-style').
7369 `do-uppercase-version (M-a, M-b, M-X, ...)'
7370 If the metafied character X is lowercase, run the command that is
7371 bound to the corresponding uppercase character.
7373 `prefix-meta (<ESC>)'
7374 Metafy the next character typed. This is for keyboards without a
7375 meta key. Typing `<ESC> f' is equivalent to typing `M-f'.
7377 `undo (C-_ or C-x C-u)'
7378 Incremental undo, separately remembered for each line.
7381 Undo all changes made to this line. This is like executing the
7382 `undo' command enough times to get back to the beginning.
7384 `tilde-expand (M-&)'
7385 Perform tilde expansion on the current word.
7388 Set the mark to the point. If a numeric argument is supplied, the
7389 mark is set to that position.
7391 `exchange-point-and-mark (C-x C-x)'
7392 Swap the point with the mark. The current cursor position is set
7393 to the saved position, and the old cursor position is saved as the
7396 `character-search (C-])'
7397 A character is read and point is moved to the next occurrence of
7398 that character. A negative count searches for previous
7401 `character-search-backward (M-C-])'
7402 A character is read and point is moved to the previous occurrence
7403 of that character. A negative count searches for subsequent
7406 `skip-csi-sequence ()'
7407 Read enough characters to consume a multi-key sequence such as
7408 those defined for keys like Home and End. Such sequences begin
7409 with a Control Sequence Indicator (CSI), usually ESC-[. If this
7410 sequence is bound to "\e[", keys producing such sequences will
7411 have no effect unless explicitly bound to a readline command,
7412 instead of inserting stray characters into the editing buffer.
7413 This is unbound by default, but usually bound to ESC-[.
7415 `insert-comment (M-#)'
7416 Without a numeric argument, the value of the `comment-begin'
7417 variable is inserted at the beginning of the current line. If a
7418 numeric argument is supplied, this command acts as a toggle: if
7419 the characters at the beginning of the line do not match the value
7420 of `comment-begin', the value is inserted, otherwise the
7421 characters in `comment-begin' are deleted from the beginning of
7422 the line. In either case, the line is accepted as if a newline
7423 had been typed. The default value of `comment-begin' causes this
7424 command to make the current line a shell comment. If a numeric
7425 argument causes the comment character to be removed, the line will
7426 be executed by the shell.
7429 Print all of the functions and their key bindings to the Readline
7430 output stream. If a numeric argument is supplied, the output is
7431 formatted in such a way that it can be made part of an INPUTRC
7432 file. This command is unbound by default.
7435 Print all of the settable variables and their values to the
7436 Readline output stream. If a numeric argument is supplied, the
7437 output is formatted in such a way that it can be made part of an
7438 INPUTRC file. This command is unbound by default.
7441 Print all of the Readline key sequences bound to macros and the
7442 strings they output. If a numeric argument is supplied, the
7443 output is formatted in such a way that it can be made part of an
7444 INPUTRC file. This command is unbound by default.
7446 `glob-complete-word (M-g)'
7447 The word before point is treated as a pattern for pathname
7448 expansion, with an asterisk implicitly appended. This pattern is
7449 used to generate a list of matching file names for possible
7452 `glob-expand-word (C-x *)'
7453 The word before point is treated as a pattern for pathname
7454 expansion, and the list of matching file names is inserted,
7455 replacing the word. If a numeric argument is supplied, a `*' is
7456 appended before pathname expansion.
7458 `glob-list-expansions (C-x g)'
7459 The list of expansions that would have been generated by
7460 `glob-expand-word' is displayed, and the line is redrawn. If a
7461 numeric argument is supplied, a `*' is appended before pathname
7464 `display-shell-version (C-x C-v)'
7465 Display version information about the current instance of Bash.
7467 `shell-expand-line (M-C-e)'
7468 Expand the line as the shell does. This performs alias and
7469 history expansion as well as all of the shell word expansions
7470 (*note Shell Expansions::).
7472 `history-expand-line (M-^)'
7473 Perform history expansion on the current line.
7476 Perform history expansion on the current line and insert a space
7477 (*note History Interaction::).
7479 `alias-expand-line ()'
7480 Perform alias expansion on the current line (*note Aliases::).
7482 `history-and-alias-expand-line ()'
7483 Perform history and alias expansion on the current line.
7485 `insert-last-argument (M-. or M-_)'
7486 A synonym for `yank-last-arg'.
7488 `operate-and-get-next (C-o)'
7489 Accept the current line for execution and fetch the next line
7490 relative to the current line from the history for editing. Any
7491 argument is ignored.
7493 `edit-and-execute-command (C-xC-e)'
7494 Invoke an editor on the current command line, and execute the
7495 result as shell commands. Bash attempts to invoke `$VISUAL',
7496 `$EDITOR', and `emacs' as the editor, in that order.
7500 File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
7502 8.5 Readline vi Mode
7503 ====================
7505 While the Readline library does not have a full set of `vi' editing
7506 functions, it does contain enough to allow simple editing of the line.
7507 The Readline `vi' mode behaves as specified in the POSIX 1003.2
7510 In order to switch interactively between `emacs' and `vi' editing
7511 modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
7512 Builtin::). The Readline default is `emacs' mode.
7514 When you enter a line in `vi' mode, you are already placed in
7515 `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
7516 you into `command' mode, where you can edit the text of the line with
7517 the standard `vi' movement keys, move to previous history lines with
7518 `k' and subsequent lines with `j', and so forth.
7521 File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
7523 8.6 Programmable Completion
7524 ===========================
7526 When word completion is attempted for an argument to a command for
7527 which a completion specification (a COMPSPEC) has been defined using
7528 the `complete' builtin (*note Programmable Completion Builtins::), the
7529 programmable completion facilities are invoked.
7531 First, the command name is identified. If a compspec has been
7532 defined for that command, the compspec is used to generate the list of
7533 possible completions for the word. If the command word is the empty
7534 string (completion attempted at the beginning of an empty line), any
7535 compspec defined with the `-E' option to `complete' is used. If the
7536 command word is a full pathname, a compspec for the full pathname is
7537 searched for first. If no compspec is found for the full pathname, an
7538 attempt is made to find a compspec for the portion following the final
7539 slash. If those searches do not result in a compspec, any compspec
7540 defined with the `-D' option to `complete' is used as the default.
7542 Once a compspec has been found, it is used to generate the list of
7543 matching words. If a compspec is not found, the default Bash completion
7544 described above (*note Commands For Completion::) is performed.
7546 First, the actions specified by the compspec are used. Only matches
7547 which are prefixed by the word being completed are returned. When the
7548 `-f' or `-d' option is used for filename or directory name completion,
7549 the shell variable `FIGNORE' is used to filter the matches. *Note Bash
7550 Variables::, for a description of `FIGNORE'.
7552 Any completions specified by a filename expansion pattern to the
7553 `-G' option are generated next. The words generated by the pattern
7554 need not match the word being completed. The `GLOBIGNORE' shell
7555 variable is not used to filter the matches, but the `FIGNORE' shell
7558 Next, the string specified as the argument to the `-W' option is
7559 considered. The string is first split using the characters in the `IFS'
7560 special variable as delimiters. Shell quoting is honored. Each word
7561 is then expanded using brace expansion, tilde expansion, parameter and
7562 variable expansion, command substitution, and arithmetic expansion, as
7563 described above (*note Shell Expansions::). The results are split
7564 using the rules described above (*note Word Splitting::). The results
7565 of the expansion are prefix-matched against the word being completed,
7566 and the matching words become the possible completions.
7568 After these matches have been generated, any shell function or
7569 command specified with the `-F' and `-C' options is invoked. When the
7570 command or function is invoked, the `COMP_LINE', `COMP_POINT',
7571 `COMP_KEY', and `COMP_TYPE' variables are assigned values as described
7572 above (*note Bash Variables::). If a shell function is being invoked,
7573 the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
7574 function or command is invoked, the first argument is the name of the
7575 command whose arguments are being completed, the second argument is the
7576 word being completed, and the third argument is the word preceding the
7577 word being completed on the current command line. No filtering of the
7578 generated completions against the word being completed is performed;
7579 the function or command has complete freedom in generating the matches.
7581 Any function specified with `-F' is invoked first. The function may
7582 use any of the shell facilities, including the `compgen' and `compopt'
7583 builtins described below (*note Programmable Completion Builtins::), to
7584 generate the matches. It must put the possible completions in the
7585 `COMPREPLY' array variable.
7587 Next, any command specified with the `-C' option is invoked in an
7588 environment equivalent to command substitution. It should print a list
7589 of completions, one per line, to the standard output. Backslash may be
7590 used to escape a newline, if necessary.
7592 After all of the possible completions are generated, any filter
7593 specified with the `-X' option is applied to the list. The filter is a
7594 pattern as used for pathname expansion; a `&' in the pattern is
7595 replaced with the text of the word being completed. A literal `&' may
7596 be escaped with a backslash; the backslash is removed before attempting
7597 a match. Any completion that matches the pattern will be removed from
7598 the list. A leading `!' negates the pattern; in this case any
7599 completion not matching the pattern will be removed.
7601 Finally, any prefix and suffix specified with the `-P' and `-S'
7602 options are added to each member of the completion list, and the result
7603 is returned to the Readline completion code as the list of possible
7606 If the previously-applied actions do not generate any matches, and
7607 the `-o dirnames' option was supplied to `complete' when the compspec
7608 was defined, directory name completion is attempted.
7610 If the `-o plusdirs' option was supplied to `complete' when the
7611 compspec was defined, directory name completion is attempted and any
7612 matches are added to the results of the other actions.
7614 By default, if a compspec is found, whatever it generates is
7615 returned to the completion code as the full set of possible completions.
7616 The default Bash completions are not attempted, and the Readline default
7617 of filename completion is disabled. If the `-o bashdefault' option was
7618 supplied to `complete' when the compspec was defined, the default Bash
7619 completions are attempted if the compspec generates no matches. If the
7620 `-o default' option was supplied to `complete' when the compspec was
7621 defined, Readline's default completion will be performed if the
7622 compspec (and, if attempted, the default Bash completions) generate no
7625 When a compspec indicates that directory name completion is desired,
7626 the programmable completion functions force Readline to append a slash
7627 to completed names which are symbolic links to directories, subject to
7628 the value of the MARK-DIRECTORIES Readline variable, regardless of the
7629 setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
7631 There is some support for dynamically modifying completions. This is
7632 most useful when used in combination with a default completion specified
7633 with `-D'. It's possible for shell functions executed as completion
7634 handlers to indicate that completion should be retried by returning an
7635 exit status of 124. If a shell function returns 124, and changes the
7636 compspec associated with the command on which completion is being
7637 attempted (supplied as the first argument when the function is
7638 executed), programmable completion restarts from the beginning, with an
7639 attempt to find a compspec for that command. This allows a set of
7640 completions to be built dynamically as completion is attempted, rather
7641 than being loaded all at once.
7643 For instance, assuming that there is a library of compspecs, each
7644 kept in a file corresponding to the name of the command, the following
7645 default completion function would load completions dynamically:
7647 _completion_loader()
7649 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
7651 complete -D -F _completion_loader
7654 File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
7656 8.7 Programmable Completion Builtins
7657 ====================================
7659 Two builtin commands are available to manipulate the programmable
7660 completion facilities.
7663 `compgen [OPTION] [WORD]'
7665 Generate possible completion matches for WORD according to the
7666 OPTIONs, which may be any option accepted by the `complete'
7667 builtin with the exception of `-p' and `-r', and write the matches
7668 to the standard output. When using the `-F' or `-C' options, the
7669 various shell variables set by the programmable completion
7670 facilities, while available, will not have useful values.
7672 The matches will be generated in the same way as if the
7673 programmable completion code had generated them directly from a
7674 completion specification with the same flags. If WORD is
7675 specified, only those completions matching WORD will be displayed.
7677 The return value is true unless an invalid option is supplied, or
7678 no matches were generated.
7681 `complete [-abcdefgjksuv] [-o COMP-OPTION] [-DE] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
7682 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
7683 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]'
7684 `complete -pr [-DE] [NAME ...]'
7686 Specify how arguments to each NAME should be completed. If the
7687 `-p' option is supplied, or if no options are supplied, existing
7688 completion specifications are printed in a way that allows them to
7689 be reused as input. The `-r' option removes a completion
7690 specification for each NAME, or, if no NAMEs are supplied, all
7691 completion specifications. The `-D' option indicates that the
7692 remaining options and actions should apply to the "default"
7693 command completion; that is, completion attempted on a command for
7694 which no completion has previously been defined. The `-E' option
7695 indicates that the remaining options and actions should apply to
7696 "empty" command completion; that is, completion attempted on a
7699 The process of applying these completion specifications when word
7700 completion is attempted is described above (*note Programmable
7701 Completion::). The `-D' option takes precedence over `-E'.
7703 Other options, if specified, have the following meanings. The
7704 arguments to the `-G', `-W', and `-X' options (and, if necessary,
7705 the `-P' and `-S' options) should be quoted to protect them from
7706 expansion before the `complete' builtin is invoked.
7709 The COMP-OPTION controls several aspects of the compspec's
7710 behavior beyond the simple generation of completions.
7711 COMP-OPTION may be one of:
7714 Perform the rest of the default Bash completions if the
7715 compspec generates no matches.
7718 Use Readline's default filename completion if the
7719 compspec generates no matches.
7722 Perform directory name completion if the compspec
7723 generates no matches.
7726 Tell Readline that the compspec generates filenames, so
7727 it can perform any filename-specific processing (like
7728 adding a slash to directory names quoting special
7729 characters, or suppressing trailing spaces). This
7730 option is intended to be used with shell functions
7731 specified with `-F'.
7734 Tell Readline not to append a space (the default) to
7735 words completed at the end of the line.
7738 After any matches defined by the compspec are generated,
7739 directory name completion is attempted and any matches
7740 are added to the results of the other actions.
7744 The ACTION may be one of the following to generate a list of
7745 possible completions:
7748 Alias names. May also be specified as `-a'.
7751 Array variable names.
7754 Readline key binding names (*note Bindable Readline
7758 Names of shell builtin commands. May also be specified
7762 Command names. May also be specified as `-c'.
7765 Directory names. May also be specified as `-d'.
7768 Names of disabled shell builtins.
7771 Names of enabled shell builtins.
7774 Names of exported shell variables. May also be
7778 File names. May also be specified as `-f'.
7781 Names of shell functions.
7784 Group names. May also be specified as `-g'.
7787 Help topics as accepted by the `help' builtin (*note
7791 Hostnames, as taken from the file specified by the
7792 `HOSTFILE' shell variable (*note Bash Variables::).
7795 Job names, if job control is active. May also be
7799 Shell reserved words. May also be specified as `-k'.
7802 Names of running jobs, if job control is active.
7805 Service names. May also be specified as `-s'.
7808 Valid arguments for the `-o' option to the `set' builtin
7809 (*note The Set Builtin::).
7812 Shell option names as accepted by the `shopt' builtin
7813 (*note Bash Builtins::).
7819 Names of stopped jobs, if job control is active.
7822 User names. May also be specified as `-u'.
7825 Names of all shell variables. May also be specified as
7829 The filename expansion pattern GLOBPAT is expanded to generate
7830 the possible completions.
7833 The WORDLIST is split using the characters in the `IFS'
7834 special variable as delimiters, and each resultant word is
7835 expanded. The possible completions are the members of the
7836 resultant list which match the word being completed.
7839 COMMAND is executed in a subshell environment, and its output
7840 is used as the possible completions.
7843 The shell function FUNCTION is executed in the current shell
7844 environment. When it finishes, the possible completions are
7845 retrieved from the value of the `COMPREPLY' array variable.
7848 FILTERPAT is a pattern as used for filename expansion. It is
7849 applied to the list of possible completions generated by the
7850 preceding options and arguments, and each completion matching
7851 FILTERPAT is removed from the list. A leading `!' in
7852 FILTERPAT negates the pattern; in this case, any completion
7853 not matching FILTERPAT is removed.
7856 PREFIX is added at the beginning of each possible completion
7857 after all other options have been applied.
7860 SUFFIX is appended to each possible completion after all
7861 other options have been applied.
7863 The return value is true unless an invalid option is supplied, an
7864 option other than `-p' or `-r' is supplied without a NAME
7865 argument, an attempt is made to remove a completion specification
7866 for a NAME for which no specification exists, or an error occurs
7867 adding a completion specification.
7870 `compopt' [-o OPTION] [-DE] [+o OPTION] [NAME]
7871 Modify completion options for each NAME according to the OPTIONs,
7872 or for the currently-execution completion if no NAMEs are supplied.
7873 If no OPTIONs are given, display the completion options for each
7874 NAME or the current completion. The possible values of OPTION are
7875 those valid for the `complete' builtin described above. The `-D'
7876 option indicates that the remaining options should apply to the
7877 "default" command completion; that is, completion attempted on a
7878 command for which no completion has previously been defined. The
7879 `-E' option indicates that the remaining options should apply to
7880 "empty" command completion; that is, completion attempted on a
7883 The `-D' option takes precedence over `-E'.
7885 The return value is true unless an invalid option is supplied, an
7886 attempt is made to modify the options for a NAME for which no
7887 completion specification exists, or an output error occurs.
7891 File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
7893 9 Using History Interactively
7894 *****************************
7896 This chapter describes how to use the GNU History Library
7897 interactively, from a user's standpoint. It should be considered a
7898 user's guide. For information on using the GNU History Library in
7899 other programs, see the GNU Readline Library Manual.
7903 * Bash History Facilities:: How Bash lets you manipulate your command
7905 * Bash History Builtins:: The Bash builtin commands that manipulate
7906 the command history.
7907 * History Interaction:: What it feels like using History as a user.
7910 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
7912 9.1 Bash History Facilities
7913 ===========================
7915 When the `-o history' option to the `set' builtin is enabled (*note The
7916 Set Builtin::), the shell provides access to the "command history", the
7917 list of commands previously typed. The value of the `HISTSIZE' shell
7918 variable is used as the number of commands to save in a history list.
7919 The text of the last `$HISTSIZE' commands (default 500) is saved. The
7920 shell stores each command in the history list prior to parameter and
7921 variable expansion but after history expansion is performed, subject to
7922 the values of the shell variables `HISTIGNORE' and `HISTCONTROL'.
7924 When the shell starts up, the history is initialized from the file
7925 named by the `HISTFILE' variable (default `~/.bash_history'). The file
7926 named by the value of `HISTFILE' is truncated, if necessary, to contain
7927 no more than the number of lines specified by the value of the
7928 `HISTFILESIZE' variable. When an interactive shell exits, the last
7929 `$HISTSIZE' lines are copied from the history list to the file named by
7930 `$HISTFILE'. If the `histappend' shell option is set (*note Bash
7931 Builtins::), the lines are appended to the history file, otherwise the
7932 history file is overwritten. If `HISTFILE' is unset, or if the history
7933 file is unwritable, the history is not saved. After saving the
7934 history, the history file is truncated to contain no more than
7935 `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
7938 If the `HISTTIMEFORMAT' is set, the time stamp information
7939 associated with each history entry is written to the history file,
7940 marked with the history comment character. When the history file is
7941 read, lines beginning with the history comment character followed
7942 immediately by a digit are interpreted as timestamps for the previous
7945 The builtin command `fc' may be used to list or edit and re-execute
7946 a portion of the history list. The `history' builtin may be used to
7947 display or modify the history list and manipulate the history file.
7948 When using command-line editing, search commands are available in each
7949 editing mode that provide access to the history list (*note Commands
7952 The shell allows control over which commands are saved on the history
7953 list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
7954 the shell to save only a subset of the commands entered. The `cmdhist'
7955 shell option, if enabled, causes the shell to attempt to save each line
7956 of a multi-line command in the same history entry, adding semicolons
7957 where necessary to preserve syntactic correctness. The `lithist' shell
7958 option causes the shell to save the command with embedded newlines
7959 instead of semicolons. The `shopt' builtin is used to set these
7960 options. *Note Bash Builtins::, for a description of `shopt'.
7963 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
7965 9.2 Bash History Builtins
7966 =========================
7968 Bash provides two builtin commands which manipulate the history list
7972 `fc [-e ENAME] [-lnr] [FIRST] [LAST]'
7973 `fc -s [PAT=REP] [COMMAND]'
7975 Fix Command. In the first form, a range of commands from FIRST to
7976 LAST is selected from the history list. Both FIRST and LAST may
7977 be specified as a string (to locate the most recent command
7978 beginning with that string) or as a number (an index into the
7979 history list, where a negative number is used as an offset from the
7980 current command number). If LAST is not specified it is set to
7981 FIRST. If FIRST is not specified it is set to the previous
7982 command for editing and -16 for listing. If the `-l' flag is
7983 given, the commands are listed on standard output. The `-n' flag
7984 suppresses the command numbers when listing. The `-r' flag
7985 reverses the order of the listing. Otherwise, the editor given by
7986 ENAME is invoked on a file containing those commands. If ENAME is
7987 not given, the value of the following variable expansion is used:
7988 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
7989 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
7990 that is set, or `vi' if neither is set. When editing is complete,
7991 the edited commands are echoed and executed.
7993 In the second form, COMMAND is re-executed after each instance of
7994 PAT in the selected command is replaced by REP.
7996 A useful alias to use with the `fc' command is `r='fc -s'', so
7997 that typing `r cc' runs the last command beginning with `cc' and
7998 typing `r' re-executes the last command (*note Aliases::).
8004 history [-anrw] [FILENAME]
8007 With no options, display the history list with line numbers.
8008 Lines prefixed with a `*' have been modified. An argument of N
8009 lists only the last N lines. If the shell variable
8010 `HISTTIMEFORMAT' is set and not null, it is used as a format
8011 string for STRFTIME to display the time stamp associated with each
8012 displayed history entry. No intervening blank is printed between
8013 the formatted time stamp and the history line.
8015 Options, if supplied, have the following meanings:
8018 Clear the history list. This may be combined with the other
8019 options to replace the history list completely.
8022 Delete the history entry at position OFFSET. OFFSET should
8023 be specified as it appears when the history is displayed.
8026 Append the new history lines (history lines entered since the
8027 beginning of the current Bash session) to the history file.
8030 Append the history lines not already read from the history
8031 file to the current history list. These are lines appended
8032 to the history file since the beginning of the current Bash
8036 Read the current history file and append its contents to the
8040 Write out the current history to the history file.
8043 Perform history substitution on the ARGs and display the
8044 result on the standard output, without storing the results in
8048 The ARGs are added to the end of the history list as a single
8052 When any of the `-w', `-r', `-a', or `-n' options is used, if
8053 FILENAME is given, then it is used as the history file. If not,
8054 then the value of the `HISTFILE' variable is used.
8058 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
8060 9.3 History Expansion
8061 =====================
8063 The History library provides a history expansion feature that is similar
8064 to the history expansion provided by `csh'. This section describes the
8065 syntax used to manipulate the history information.
8067 History expansions introduce words from the history list into the
8068 input stream, making it easy to repeat commands, insert the arguments
8069 to a previous command into the current input line, or fix errors in
8070 previous commands quickly.
8072 History expansion takes place in two parts. The first is to
8073 determine which line from the history list should be used during
8074 substitution. The second is to select portions of that line for
8075 inclusion into the current one. The line selected from the history is
8076 called the "event", and the portions of that line that are acted upon
8077 are called "words". Various "modifiers" are available to manipulate
8078 the selected words. The line is broken into words in the same fashion
8079 that Bash does, so that several words surrounded by quotes are
8080 considered one word. History expansions are introduced by the
8081 appearance of the history expansion character, which is `!' by default.
8082 Only `\' and `'' may be used to escape the history expansion character.
8084 Several shell options settable with the `shopt' builtin (*note Bash
8085 Builtins::) may be used to tailor the behavior of history expansion.
8086 If the `histverify' shell option is enabled, and Readline is being
8087 used, history substitutions are not immediately passed to the shell
8088 parser. Instead, the expanded line is reloaded into the Readline
8089 editing buffer for further modification. If Readline is being used,
8090 and the `histreedit' shell option is enabled, a failed history
8091 expansion will be reloaded into the Readline editing buffer for
8092 correction. The `-p' option to the `history' builtin command may be
8093 used to see what a history expansion will do before using it. The `-s'
8094 option to the `history' builtin may be used to add commands to the end
8095 of the history list without actually executing them, so that they are
8096 available for subsequent recall. This is most useful in conjunction
8099 The shell allows control of the various characters used by the
8100 history expansion mechanism with the `histchars' variable, as explained
8101 above (*note Bash Variables::). The shell uses the history comment
8102 character to mark history timestamps when writing the history file.
8106 * Event Designators:: How to specify which history line to use.
8107 * Word Designators:: Specifying which words are of interest.
8108 * Modifiers:: Modifying the results of substitution.
8111 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
8113 9.3.1 Event Designators
8114 -----------------------
8116 An event designator is a reference to a command line entry in the
8120 Start a history substitution, except when followed by a space, tab,
8121 the end of the line, `=' or `(' (when the `extglob' shell option
8122 is enabled using the `shopt' builtin).
8125 Refer to command line N.
8128 Refer to the command N lines back.
8131 Refer to the previous command. This is a synonym for `!-1'.
8134 Refer to the most recent command starting with STRING.
8137 Refer to the most recent command containing STRING. The trailing
8138 `?' may be omitted if the STRING is followed immediately by a
8142 Quick Substitution. Repeat the last command, replacing STRING1
8143 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
8146 The entire command line typed so far.
8150 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
8152 9.3.2 Word Designators
8153 ----------------------
8155 Word designators are used to select desired words from the event. A
8156 `:' separates the event specification from the word designator. It may
8157 be omitted if the word designator begins with a `^', `$', `*', `-', or
8158 `%'. Words are numbered from the beginning of the line, with the first
8159 word being denoted by 0 (zero). Words are inserted into the current
8160 line separated by single spaces.
8165 designates the preceding command. When you type this, the
8166 preceding command is repeated in toto.
8169 designates the last argument of the preceding command. This may be
8173 designates the second argument of the most recent command starting
8174 with the letters `fi'.
8176 Here are the word designators:
8179 The `0'th word. For many applications, this is the command word.
8185 The first argument; that is, word 1.
8191 The word matched by the most recent `?STRING?' search.
8194 A range of words; `-Y' abbreviates `0-Y'.
8197 All of the words, except the `0'th. This is a synonym for `1-$'.
8198 It is not an error to use `*' if there is just one word in the
8199 event; the empty string is returned in that case.
8205 Abbreviates `X-$' like `X*', but omits the last word.
8208 If a word designator is supplied without an event specification, the
8209 previous command is used as the event.
8212 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
8217 After the optional word designator, you can add a sequence of one or
8218 more of the following modifiers, each preceded by a `:'.
8221 Remove a trailing pathname component, leaving only the head.
8224 Remove all leading pathname components, leaving the tail.
8227 Remove a trailing suffix of the form `.SUFFIX', leaving the
8231 Remove all but the trailing suffix.
8234 Print the new command but do not execute it.
8237 Quote the substituted words, escaping further substitutions.
8240 Quote the substituted words as with `q', but break into words at
8241 spaces, tabs, and newlines.
8244 Substitute NEW for the first occurrence of OLD in the event line.
8245 Any delimiter may be used in place of `/'. The delimiter may be
8246 quoted in OLD and NEW with a single backslash. If `&' appears in
8247 NEW, it is replaced by OLD. A single backslash will quote the
8248 `&'. The final delimiter is optional if it is the last character
8252 Repeat the previous substitution.
8256 Cause changes to be applied over the entire event line. Used in
8257 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
8260 Apply the following `s' modifier once to each word in the event.
8264 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
8269 This chapter provides basic instructions for installing Bash on the
8270 various supported platforms. The distribution supports the GNU
8271 operating systems, nearly every version of Unix, and several non-Unix
8272 systems such as BeOS and Interix. Other independent ports exist for
8273 MS-DOS, OS/2, and Windows platforms.
8277 * Basic Installation:: Installation instructions.
8278 * Compilers and Options:: How to set special options for various
8280 * Compiling For Multiple Architectures:: How to compile Bash for more
8281 than one kind of system from
8282 the same source tree.
8283 * Installation Names:: How to set the various paths used by the installation.
8284 * Specifying the System Type:: How to configure Bash for a particular system.
8285 * Sharing Defaults:: How to share default configuration values among GNU
8287 * Operation Controls:: Options recognized by the configuration program.
8288 * Optional Features:: How to enable and disable optional features when
8292 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
8294 10.1 Basic Installation
8295 =======================
8297 These are installation instructions for Bash.
8299 The simplest way to compile Bash is:
8301 1. `cd' to the directory containing the source code and type
8302 `./configure' to configure Bash for your system. If you're using
8303 `csh' on an old version of System V, you might need to type `sh
8304 ./configure' instead to prevent `csh' from trying to execute
8307 Running `configure' takes some time. While running, it prints
8308 messages telling which features it is checking for.
8310 2. Type `make' to compile Bash and build the `bashbug' bug reporting
8313 3. Optionally, type `make tests' to run the Bash test suite.
8315 4. Type `make install' to install `bash' and `bashbug'. This will
8316 also install the manual pages and Info file.
8319 The `configure' shell script attempts to guess correct values for
8320 various system-dependent variables used during compilation. It uses
8321 those values to create a `Makefile' in each directory of the package
8322 (the top directory, the `builtins', `doc', and `support' directories,
8323 each directory under `lib', and several others). It also creates a
8324 `config.h' file containing system-dependent definitions. Finally, it
8325 creates a shell script named `config.status' that you can run in the
8326 future to recreate the current configuration, a file `config.cache'
8327 that saves the results of its tests to speed up reconfiguring, and a
8328 file `config.log' containing compiler output (useful mainly for
8329 debugging `configure'). If at some point `config.cache' contains
8330 results you don't want to keep, you may remove or edit it.
8332 To find out more about the options and arguments that the
8333 `configure' script understands, type
8335 bash-2.04$ ./configure --help
8337 at the Bash prompt in your Bash source directory.
8339 If you need to do unusual things to compile Bash, please try to
8340 figure out how `configure' could check whether or not to do them, and
8341 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
8342 considered for the next release.
8344 The file `configure.in' is used to create `configure' by a program
8345 called Autoconf. You only need `configure.in' if you want to change it
8346 or regenerate `configure' using a newer version of Autoconf. If you do
8347 this, make sure you are using Autoconf version 2.50 or newer.
8349 You can remove the program binaries and object files from the source
8350 code directory by typing `make clean'. To also remove the files that
8351 `configure' created (so you can compile Bash for a different kind of
8352 computer), type `make distclean'.
8355 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
8357 10.2 Compilers and Options
8358 ==========================
8360 Some systems require unusual options for compilation or linking that
8361 the `configure' script does not know about. You can give `configure'
8362 initial values for variables by setting them in the environment. Using
8363 a Bourne-compatible shell, you can do that on the command line like
8366 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
8368 On systems that have the `env' program, you can do it like this:
8370 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
8372 The configuration process uses GCC to build Bash if it is available.
8375 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
8377 10.3 Compiling For Multiple Architectures
8378 =========================================
8380 You can compile Bash for more than one kind of computer at the same
8381 time, by placing the object files for each architecture in their own
8382 directory. To do this, you must use a version of `make' that supports
8383 the `VPATH' variable, such as GNU `make'. `cd' to the directory where
8384 you want the object files and executables to go and run the `configure'
8385 script from the source directory. You may need to supply the
8386 `--srcdir=PATH' argument to tell `configure' where the source files
8387 are. `configure' automatically checks for the source code in the
8388 directory that `configure' is in and in `..'.
8390 If you have to use a `make' that does not supports the `VPATH'
8391 variable, you can compile Bash for one architecture at a time in the
8392 source code directory. After you have installed Bash for one
8393 architecture, use `make distclean' before reconfiguring for another
8396 Alternatively, if your system supports symbolic links, you can use
8397 the `support/mkclone' script to create a build tree which has symbolic
8398 links back to each file in the source directory. Here's an example
8399 that creates a build directory in the current directory from a source
8400 directory `/usr/gnu/src/bash-2.0':
8402 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
8404 The `mkclone' script requires Bash, so you must have already built Bash
8405 for at least one architecture before you can create build directories
8406 for other architectures.
8409 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
8411 10.4 Installation Names
8412 =======================
8414 By default, `make install' will install into `/usr/local/bin',
8415 `/usr/local/man', etc. You can specify an installation prefix other
8416 than `/usr/local' by giving `configure' the option `--prefix=PATH', or
8417 by specifying a value for the `DESTDIR' `make' variable when running
8420 You can specify separate installation prefixes for
8421 architecture-specific files and architecture-independent files. If you
8422 give `configure' the option `--exec-prefix=PATH', `make install' will
8423 use PATH as the prefix for installing programs and libraries.
8424 Documentation and other data files will still use the regular prefix.
8427 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
8429 10.5 Specifying the System Type
8430 ===============================
8432 There may be some features `configure' can not figure out
8433 automatically, but need to determine by the type of host Bash will run
8434 on. Usually `configure' can figure that out, but if it prints a
8435 message saying it can not guess the host type, give it the
8436 `--host=TYPE' option. `TYPE' can either be a short name for the system
8437 type, such as `sun4', or a canonical name with three fields:
8438 `CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
8440 See the file `support/config.sub' for the possible values of each
8444 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
8446 10.6 Sharing Defaults
8447 =====================
8449 If you want to set default values for `configure' scripts to share, you
8450 can create a site shell script called `config.site' that gives default
8451 values for variables like `CC', `cache_file', and `prefix'. `configure'
8452 looks for `PREFIX/share/config.site' if it exists, then
8453 `PREFIX/etc/config.site' if it exists. Or, you can set the
8454 `CONFIG_SITE' environment variable to the location of the site script.
8455 A warning: the Bash `configure' looks for a site script, but not all
8456 `configure' scripts do.
8459 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
8461 10.7 Operation Controls
8462 =======================
8464 `configure' recognizes the following options to control how it operates.
8467 Use and save the results of the tests in FILE instead of
8468 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
8469 debugging `configure'.
8472 Print a summary of the options to `configure', and exit.
8477 Do not print messages saying which checks are being made.
8480 Look for the Bash source code in directory DIR. Usually
8481 `configure' can determine that directory automatically.
8484 Print the version of Autoconf used to generate the `configure'
8487 `configure' also accepts some other, not widely used, boilerplate
8488 options. `configure --help' prints the complete list.
8491 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
8493 10.8 Optional Features
8494 ======================
8496 The Bash `configure' has a number of `--enable-FEATURE' options, where
8497 FEATURE indicates an optional part of Bash. There are also several
8498 `--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
8499 or `purify'. To turn off the default use of a package, use
8500 `--without-PACKAGE'. To configure Bash without a feature that is
8501 enabled by default, use `--disable-FEATURE'.
8503 Here is a complete list of the `--enable-' and `--with-' options
8504 that the Bash `configure' recognizes.
8507 Define if you are using the Andrew File System from Transarc.
8509 `--with-bash-malloc'
8510 Use the Bash version of `malloc' in the directory `lib/malloc'.
8511 This is not the same `malloc' that appears in GNU libc, but an
8512 older version originally derived from the 4.2 BSD `malloc'. This
8513 `malloc' is very fast, but wastes some space on each allocation.
8514 This option is enabled by default. The `NOTES' file contains a
8515 list of systems for which this should be turned off, and
8516 `configure' disables this option automatically for a number of
8520 Use the curses library instead of the termcap library. This should
8521 be supplied if your system has an inadequate or incomplete termcap
8525 A synonym for `--with-bash-malloc'.
8527 `--with-installed-readline[=PREFIX]'
8528 Define this to make Bash link with a locally-installed version of
8529 Readline rather than the version in `lib/readline'. This works
8530 only with Readline 5.0 and later versions. If PREFIX is `yes' or
8531 not supplied, `configure' uses the values of the make variables
8532 `includedir' and `libdir', which are subdirectories of `prefix' by
8533 default, to find the installed version of Readline if it is not in
8534 the standard system include and library directories. If PREFIX is
8535 `no', Bash links with the version in `lib/readline'. If PREFIX is
8536 set to any other value, `configure' treats it as a directory
8537 pathname and looks for the installed version of Readline in
8538 subdirectories of that directory (include files in
8539 PREFIX/`include' and the library in PREFIX/`lib').
8542 Define this to use the Purify memory allocation checker from
8545 `--enable-minimal-config'
8546 This produces a shell with minimal features, close to the
8547 historical Bourne shell.
8549 There are several `--enable-' options that alter how Bash is
8550 compiled and linked, rather than changing run-time features.
8552 `--enable-largefile'
8553 Enable support for large files
8554 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
8555 the operating system requires special compiler options to build
8556 programs which can access large files. This is enabled by
8557 default, if the operating system provides large file support.
8559 `--enable-profiling'
8560 This builds a Bash binary that produces profiling information to be
8561 processed by `gprof' each time it is executed.
8563 `--enable-static-link'
8564 This causes Bash to be linked statically, if `gcc' is being used.
8565 This could be used to build a version to use as root's shell.
8567 The `minimal-config' option can be used to disable all of the
8568 following options, but it is processed first, so individual options may
8569 be enabled using `enable-FEATURE'.
8571 All of the following options except for `disabled-builtins' and
8572 `xpg-echo-default' are enabled by default, unless the operating system
8573 does not provide the necessary support.
8576 Allow alias expansion and include the `alias' and `unalias'
8577 builtins (*note Aliases::).
8579 `--enable-arith-for-command'
8580 Include support for the alternate form of the `for' command that
8581 behaves like the C language `for' statement (*note Looping
8584 `--enable-array-variables'
8585 Include support for one-dimensional array shell variables (*note
8588 `--enable-bang-history'
8589 Include support for `csh'-like history substitution (*note History
8592 `--enable-brace-expansion'
8593 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
8594 See *note Brace Expansion::, for a complete description.
8596 `--enable-casemod-attributes'
8597 Include support for case-modifying attributes in the `declare'
8598 builtin and assignment statements. Variables with the UPPERCASE
8599 attribute, for example, will have their values converted to
8600 uppercase upon assignment.
8602 `--enable-casemod-expansion'
8603 Include support for case-modifying word expansions.
8605 `--enable-command-timing'
8606 Include support for recognizing `time' as a reserved word and for
8607 displaying timing statistics for the pipeline following `time'
8608 (*note Pipelines::). This allows pipelines as well as shell
8609 builtins and functions to be timed.
8611 `--enable-cond-command'
8612 Include support for the `[[' conditional command. (*note
8613 Conditional Constructs::).
8615 `--enable-cond-regexp'
8616 Include support for matching POSIX regular expressions using the
8617 `=~' binary operator in the `[[' conditional command. (*note
8618 Conditional Constructs::).
8620 `--enable-coprocesses'
8621 Include support for coprocesses and the `coproc' reserved word
8622 (*note Pipelines::).
8625 Include support for the bash debugger (distributed separately).
8627 `--enable-directory-stack'
8628 Include support for a `csh'-like directory stack and the `pushd',
8629 `popd', and `dirs' builtins (*note The Directory Stack::).
8631 `--enable-disabled-builtins'
8632 Allow builtin commands to be invoked via `builtin xxx' even after
8633 `xxx' has been disabled using `enable -n xxx'. See *note Bash
8634 Builtins::, for details of the `builtin' and `enable' builtin
8637 `--enable-dparen-arithmetic'
8638 Include support for the `((...))' command (*note Conditional
8641 `--enable-extended-glob'
8642 Include support for the extended pattern matching features
8643 described above under *note Pattern Matching::.
8645 `--enable-extended-glob-default'
8646 Set the default value of the EXTGLOB shell option described above
8647 under *note The Shopt Builtin:: to be enabled.
8649 `--enable-help-builtin'
8650 Include the `help' builtin, which displays help on shell builtins
8651 and variables (*note Bash Builtins::).
8654 Include command history and the `fc' and `history' builtin
8655 commands (*note Bash History Facilities::).
8657 `--enable-job-control'
8658 This enables the job control features (*note Job Control::), if
8659 the operating system supports them.
8661 `--enable-multibyte'
8662 This enables support for multibyte characters if the operating
8663 system provides the necessary support.
8665 `--enable-net-redirections'
8666 This enables the special handling of filenames of the form
8667 `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
8668 redirections (*note Redirections::).
8670 `--enable-process-substitution'
8671 This enables process substitution (*note Process Substitution::) if
8672 the operating system provides the necessary support.
8675 Enable the programmable completion facilities (*note Programmable
8676 Completion::). If Readline is not enabled, this option has no
8679 `--enable-prompt-string-decoding'
8680 Turn on the interpretation of a number of backslash-escaped
8681 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
8682 strings. See *note Printing a Prompt::, for a complete list of
8683 prompt string escape sequences.
8686 Include support for command-line editing and history with the Bash
8687 version of the Readline library (*note Command Line Editing::).
8689 `--enable-restricted'
8690 Include support for a "restricted shell". If this is enabled,
8691 Bash, when called as `rbash', enters a restricted mode. See *note
8692 The Restricted Shell::, for a description of restricted mode.
8695 Include the `select' builtin, which allows the generation of simple
8696 menus (*note Conditional Constructs::).
8698 `--enable-separate-helpfiles'
8699 Use external files for the documentation displayed by the `help'
8700 builtin instead of storing the text internally.
8702 `--enable-single-help-strings'
8703 Store the text displayed by the `help' builtin as a single string
8704 for each help topic. This aids in translating the text to
8705 different languages. You may need to disable this if your
8706 compiler cannot handle very long string literals.
8708 `--enable-strict-posix-default'
8709 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
8711 `--enable-usg-echo-default'
8712 A synonym for `--enable-xpg-echo-default'.
8714 `--enable-xpg-echo-default'
8715 Make the `echo' builtin expand backslash-escaped characters by
8716 default, without requiring the `-e' option. This sets the default
8717 value of the `xpg_echo' shell option to `on', which makes the Bash
8718 `echo' behave more like the version specified in the Single Unix
8719 Specification, version 3. *Note Bash Builtins::, for a
8720 description of the escape sequences that `echo' recognizes.
8723 The file `config-top.h' contains C Preprocessor `#define' statements
8724 for options which are not settable from `configure'. Some of these are
8725 not meant to be changed; beware of the consequences if you do. Read
8726 the comments associated with each definition for more information about
8730 File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
8732 Appendix A Reporting Bugs
8733 *************************
8735 Please report all bugs you find in Bash. But first, you should make
8736 sure that it really is a bug, and that it appears in the latest version
8737 of Bash. The latest version of Bash is always available for FTP from
8738 `ftp://ftp.gnu.org/pub/gnu/bash/'.
8740 Once you have determined that a bug actually exists, use the
8741 `bashbug' command to submit a bug report. If you have a fix, you are
8742 encouraged to mail that as well! Suggestions and `philosophical' bug
8743 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
8744 newsgroup `gnu.bash.bug'.
8746 All bug reports should include:
8747 * The version number of Bash.
8749 * The hardware and operating system.
8751 * The compiler used to compile Bash.
8753 * A description of the bug behaviour.
8755 * A short script or `recipe' which exercises the bug and may be used
8758 `bashbug' inserts the first three items automatically into the template
8759 it provides for filing a bug report.
8761 Please send all reports concerning this manual to
8762 <chet.ramey@case.edu>.
8765 File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
8767 Appendix B Major Differences From The Bourne Shell
8768 **************************************************
8770 Bash implements essentially the same grammar, parameter and variable
8771 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
8772 POSIX standard as the specification of how these features are to be
8773 implemented. There are some differences between the traditional Bourne
8774 shell and Bash; this section quickly details the differences of
8775 significance. A number of these differences are explained in greater
8776 depth in previous sections. This section uses the version of `sh'
8777 included in SVR4.2 (the last version of the historical Bourne shell) as
8778 the baseline reference.
8780 * Bash is POSIX-conformant, even where the POSIX specification
8781 differs from traditional `sh' behavior (*note Bash POSIX Mode::).
8783 * Bash has multi-character invocation options (*note Invoking
8786 * Bash has command-line editing (*note Command Line Editing::) and
8789 * Bash provides a programmable word completion mechanism (*note
8790 Programmable Completion::), and builtin commands `complete',
8791 `compgen', and `compopt', to manipulate it.
8793 * Bash has command history (*note Bash History Facilities::) and the
8794 `history' and `fc' builtins to manipulate it. The Bash history
8795 list maintains timestamp information and uses the value of the
8796 `HISTTIMEFORMAT' variable to display it.
8798 * Bash implements `csh'-like history expansion (*note History
8801 * Bash has one-dimensional array variables (*note Arrays::), and the
8802 appropriate variable expansions and assignment syntax to use them.
8803 Several of the Bash builtins take options to act on arrays. Bash
8804 provides a number of built-in array variables.
8806 * The `$'...'' quoting syntax, which expands ANSI-C
8807 backslash-escaped characters in the text between the single quotes,
8808 is supported (*note ANSI-C Quoting::).
8810 * Bash supports the `$"..."' quoting syntax to do locale-specific
8811 translation of the characters between the double quotes. The
8812 `-D', `--dump-strings', and `--dump-po-strings' invocation options
8813 list the translatable strings found in a script (*note Locale
8816 * Bash implements the `!' keyword to negate the return value of a
8817 pipeline (*note Pipelines::). Very useful when an `if' statement
8818 needs to act only if a test fails. The Bash `-o pipefail' option
8819 to `set' will cause a pipeline to return a failure status if any
8822 * Bash has the `time' reserved word and command timing (*note
8823 Pipelines::). The display of the timing statistics may be
8824 controlled with the `TIMEFORMAT' variable.
8826 * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
8827 for command, similar to the C language (*note Looping
8830 * Bash includes the `select' compound command, which allows the
8831 generation of simple menus (*note Conditional Constructs::).
8833 * Bash includes the `[[' compound command, which makes conditional
8834 testing part of the shell grammar (*note Conditional
8835 Constructs::), including optional regular expression matching.
8837 * Bash provides optional case-insensitive matching for the `case' and
8840 * Bash includes brace expansion (*note Brace Expansion::) and tilde
8841 expansion (*note Tilde Expansion::).
8843 * Bash implements command aliases and the `alias' and `unalias'
8844 builtins (*note Aliases::).
8846 * Bash provides shell arithmetic, the `((' compound command (*note
8847 Conditional Constructs::), and arithmetic expansion (*note Shell
8850 * Variables present in the shell's initial environment are
8851 automatically exported to child processes. The Bourne shell does
8852 not normally do this unless the variables are explicitly marked
8853 using the `export' command.
8855 * Bash supports the `+=' assignment operator, which appends to the
8856 value of the variable named on the left hand side.
8858 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
8859 expansions to remove leading or trailing substrings from variable
8860 values (*note Shell Parameter Expansion::).
8862 * The expansion `${#xx}', which returns the length of `${xx}', is
8863 supported (*note Shell Parameter Expansion::).
8865 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
8866 substring of `var''s value of length LENGTH, beginning at OFFSET,
8867 is present (*note Shell Parameter Expansion::).
8869 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
8870 PATTERN and replaces it with REPLACEMENT in the value of `var', is
8871 available (*note Shell Parameter Expansion::).
8873 * The expansion `${!PREFIX}*' expansion, which expands to the names
8874 of all shell variables whose names begin with PREFIX, is available
8875 (*note Shell Parameter Expansion::).
8877 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
8878 Parameter Expansion::).
8880 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
8882 * The POSIX `$()' form of command substitution is implemented (*note
8883 Command Substitution::), and preferred to the Bourne shell's ```'
8884 (which is also implemented for backwards compatibility).
8886 * Bash has process substitution (*note Process Substitution::).
8888 * Bash automatically assigns variables that provide information
8889 about the current user (`UID', `EUID', and `GROUPS'), the current
8890 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
8891 instance of Bash that is running (`BASH', `BASH_VERSION', and
8892 `BASH_VERSINFO'). *Note Bash Variables::, for details.
8894 * The `IFS' variable is used to split only the results of expansion,
8895 not all words (*note Word Splitting::). This closes a
8896 longstanding shell security hole.
8898 * Bash implements the full set of POSIX filename expansion operators,
8899 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
8900 SYMBOLS (*note Filename Expansion::).
8902 * Bash implements extended pattern matching features when the
8903 `extglob' shell option is enabled (*note Pattern Matching::).
8905 * It is possible to have a variable and a function with the same
8906 name; `sh' does not separate the two name spaces.
8908 * Bash functions are permitted to have local variables using the
8909 `local' builtin, and thus useful recursive functions may be written
8910 (*note Bash Builtins::).
8912 * Variable assignments preceding commands affect only that command,
8913 even builtins and functions (*note Environment::). In `sh', all
8914 variable assignments preceding commands are global unless the
8915 command is executed from the file system.
8917 * Bash performs filename expansion on filenames specified as operands
8918 to input and output redirection operators (*note Redirections::).
8920 * Bash contains the `<>' redirection operator, allowing a file to be
8921 opened for both reading and writing, and the `&>' redirection
8922 operator, for directing standard output and standard error to the
8923 same file (*note Redirections::).
8925 * Bash includes the `<<<' redirection operator, allowing a string to
8926 be used as the standard input to a command.
8928 * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection
8929 operators, which move one file descriptor to another.
8931 * Bash treats a number of filenames specially when they are used in
8932 redirection operators (*note Redirections::).
8934 * Bash can open network connections to arbitrary machines and
8935 services with the redirection operators (*note Redirections::).
8937 * The `noclobber' option is available to avoid overwriting existing
8938 files with output redirection (*note The Set Builtin::). The `>|'
8939 redirection operator may be used to override `noclobber'.
8941 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::)
8942 each take `-L' and `-P' options to switch between logical and
8945 * Bash allows a function to override a builtin with the same name,
8946 and provides access to that builtin's functionality within the
8947 function via the `builtin' and `command' builtins (*note Bash
8950 * The `command' builtin allows selective disabling of functions when
8951 command lookup is performed (*note Bash Builtins::).
8953 * Individual builtins may be enabled or disabled using the `enable'
8954 builtin (*note Bash Builtins::).
8956 * The Bash `exec' builtin takes additional options that allow users
8957 to control the contents of the environment passed to the executed
8958 command, and what the zeroth argument to the command is to be
8959 (*note Bourne Shell Builtins::).
8961 * Shell functions may be exported to children via the environment
8962 using `export -f' (*note Shell Functions::).
8964 * The Bash `export', `readonly', and `declare' builtins can take a
8965 `-f' option to act on shell functions, a `-p' option to display
8966 variables with various attributes set in a format that can be used
8967 as shell input, a `-n' option to remove various variable
8968 attributes, and `name=value' arguments to set variable attributes
8969 and values simultaneously.
8971 * The Bash `hash' builtin allows a name to be associated with an
8972 arbitrary filename, even when that filename cannot be found by
8973 searching the `$PATH', using `hash -p' (*note Bourne Shell
8976 * Bash includes a `help' builtin for quick reference to shell
8977 facilities (*note Bash Builtins::).
8979 * The `printf' builtin is available to display formatted output
8980 (*note Bash Builtins::).
8982 * The Bash `read' builtin (*note Bash Builtins::) will read a line
8983 ending in `\' with the `-r' option, and will use the `REPLY'
8984 variable as a default if no non-option arguments are supplied.
8985 The Bash `read' builtin also accepts a prompt string with the `-p'
8986 option and will use Readline to obtain the line when given the
8987 `-e' option. The `read' builtin also has additional options to
8988 control input: the `-s' option will turn off echoing of input
8989 characters as they are read, the `-t' option will allow `read' to
8990 time out if input does not arrive within a specified number of
8991 seconds, the `-n' option will allow reading only a specified
8992 number of characters rather than a full line, and the `-d' option
8993 will read until a particular character rather than newline.
8995 * The `return' builtin may be used to abort execution of scripts
8996 executed with the `.' or `source' builtins (*note Bourne Shell
8999 * Bash includes the `shopt' builtin, for finer control of shell
9000 optional capabilities (*note The Shopt Builtin::), and allows
9001 these options to be set and unset at shell invocation (*note
9004 * Bash has much more optional behavior controllable with the `set'
9005 builtin (*note The Set Builtin::).
9007 * The `-x' (`xtrace') option displays commands other than simple
9008 commands when performing an execution trace (*note The Set
9011 * The `test' builtin (*note Bourne Shell Builtins::) is slightly
9012 different, as it implements the POSIX algorithm, which specifies
9013 the behavior based on the number of arguments.
9015 * Bash includes the `caller' builtin, which displays the context of
9016 any active subroutine call (a shell function or a script executed
9017 with the `.' or `source' builtins). This supports the bash
9020 * The `trap' builtin (*note Bourne Shell Builtins::) allows a
9021 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
9022 specified with a `DEBUG' trap are executed before every simple
9023 command, `for' command, `case' command, `select' command, every
9024 arithmetic `for' command, and before the first command executes in
9025 a shell function. The `DEBUG' trap is not inherited by shell
9026 functions unless the function has been given the `trace' attribute
9027 or the `functrace' option has been enabled using the `shopt'
9028 builtin. The `extdebug' shell option has additional effects on the
9031 The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR'
9032 pseudo-signal specification, similar to `EXIT' and `DEBUG'.
9033 Commands specified with an `ERR' trap are executed after a simple
9034 command fails, with a few exceptions. The `ERR' trap is not
9035 inherited by shell functions unless the `-o errtrace' option to
9036 the `set' builtin is enabled.
9038 The `trap' builtin (*note Bourne Shell Builtins::) allows a
9039 `RETURN' pseudo-signal specification, similar to `EXIT' and
9040 `DEBUG'. Commands specified with an `RETURN' trap are executed
9041 before execution resumes after a shell function or a shell script
9042 executed with `.' or `source' returns. The `RETURN' trap is not
9043 inherited by shell functions unless the function has been given
9044 the `trace' attribute or the `functrace' option has been enabled
9045 using the `shopt' builtin.
9047 * The Bash `type' builtin is more extensive and gives more
9048 information about the names it finds (*note Bash Builtins::).
9050 * The Bash `umask' builtin permits a `-p' option to cause the output
9051 to be displayed in the form of a `umask' command that may be
9052 reused as input (*note Bourne Shell Builtins::).
9054 * Bash implements a `csh'-like directory stack, and provides the
9055 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
9056 Directory Stack::). Bash also makes the directory stack visible
9057 as the value of the `DIRSTACK' shell variable.
9059 * Bash interprets special backslash-escaped characters in the prompt
9060 strings when interactive (*note Printing a Prompt::).
9062 * The Bash restricted mode is more useful (*note The Restricted
9063 Shell::); the SVR4.2 shell restricted mode is too limited.
9065 * The `disown' builtin can remove a job from the internal shell job
9066 table (*note Job Control Builtins::) or suppress the sending of
9067 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
9069 * Bash includes a number of features to support a separate debugger
9072 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
9073 `priv') not present in Bash.
9075 * Bash does not have the `stop' or `newgrp' builtins.
9077 * Bash does not use the `SHACCT' variable or perform shell
9080 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
9083 More features unique to Bash may be found in *note Bash Features::.
9085 B.1 Implementation Differences From The SVR4.2 Shell
9086 ====================================================
9088 Since Bash is a completely new implementation, it does not suffer from
9089 many of the limitations of the SVR4.2 shell. For instance:
9091 * Bash does not fork a subshell when redirecting into or out of a
9092 shell control structure such as an `if' or `while' statement.
9094 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
9095 silently insert a needed closing quote at `EOF' under certain
9096 circumstances. This can be the cause of some hard-to-find errors.
9098 * The SVR4.2 shell uses a baroque memory management scheme based on
9099 trapping `SIGSEGV'. If the shell is started from a process with
9100 `SIGSEGV' blocked (e.g., by using the `system()' C library
9101 function call), it misbehaves badly.
9103 * In a questionable attempt at security, the SVR4.2 shell, when
9104 invoked without the `-p' option, will alter its real and effective
9105 UID and GID if they are less than some magic threshold value,
9106 commonly 100. This can lead to unexpected results.
9108 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
9109 `SIGALRM', or `SIGCHLD'.
9111 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
9112 `PS1', or `PS2' variables to be unset.
9114 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
9116 * Bash allows multiple option arguments when it is invoked (`-x -v');
9117 the SVR4.2 shell allows only one option argument (`-xv'). In
9118 fact, some versions of the shell dump core if the second argument
9121 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
9122 script only if one of the POSIX special builtins fails, and only
9123 for certain failures, as enumerated in the POSIX standard.
9125 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
9126 turns on job control).
9129 File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
9131 Appendix C GNU Free Documentation License
9132 *****************************************
9134 Version 1.3, 3 November 2008
9136 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
9139 Everyone is permitted to copy and distribute verbatim copies
9140 of this license document, but changing it is not allowed.
9144 The purpose of this License is to make a manual, textbook, or other
9145 functional and useful document "free" in the sense of freedom: to
9146 assure everyone the effective freedom to copy and redistribute it,
9147 with or without modifying it, either commercially or
9148 noncommercially. Secondarily, this License preserves for the
9149 author and publisher a way to get credit for their work, while not
9150 being considered responsible for modifications made by others.
9152 This License is a kind of "copyleft", which means that derivative
9153 works of the document must themselves be free in the same sense.
9154 It complements the GNU General Public License, which is a copyleft
9155 license designed for free software.
9157 We have designed this License in order to use it for manuals for
9158 free software, because free software needs free documentation: a
9159 free program should come with manuals providing the same freedoms
9160 that the software does. But this License is not limited to
9161 software manuals; it can be used for any textual work, regardless
9162 of subject matter or whether it is published as a printed book.
9163 We recommend this License principally for works whose purpose is
9164 instruction or reference.
9166 1. APPLICABILITY AND DEFINITIONS
9168 This License applies to any manual or other work, in any medium,
9169 that contains a notice placed by the copyright holder saying it
9170 can be distributed under the terms of this License. Such a notice
9171 grants a world-wide, royalty-free license, unlimited in duration,
9172 to use that work under the conditions stated herein. The
9173 "Document", below, refers to any such manual or work. Any member
9174 of the public is a licensee, and is addressed as "you". You
9175 accept the license if you copy, modify or distribute the work in a
9176 way requiring permission under copyright law.
9178 A "Modified Version" of the Document means any work containing the
9179 Document or a portion of it, either copied verbatim, or with
9180 modifications and/or translated into another language.
9182 A "Secondary Section" is a named appendix or a front-matter section
9183 of the Document that deals exclusively with the relationship of the
9184 publishers or authors of the Document to the Document's overall
9185 subject (or to related matters) and contains nothing that could
9186 fall directly within that overall subject. (Thus, if the Document
9187 is in part a textbook of mathematics, a Secondary Section may not
9188 explain any mathematics.) The relationship could be a matter of
9189 historical connection with the subject or with related matters, or
9190 of legal, commercial, philosophical, ethical or political position
9193 The "Invariant Sections" are certain Secondary Sections whose
9194 titles are designated, as being those of Invariant Sections, in
9195 the notice that says that the Document is released under this
9196 License. If a section does not fit the above definition of
9197 Secondary then it is not allowed to be designated as Invariant.
9198 The Document may contain zero Invariant Sections. If the Document
9199 does not identify any Invariant Sections then there are none.
9201 The "Cover Texts" are certain short passages of text that are
9202 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
9203 that says that the Document is released under this License. A
9204 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
9205 be at most 25 words.
9207 A "Transparent" copy of the Document means a machine-readable copy,
9208 represented in a format whose specification is available to the
9209 general public, that is suitable for revising the document
9210 straightforwardly with generic text editors or (for images
9211 composed of pixels) generic paint programs or (for drawings) some
9212 widely available drawing editor, and that is suitable for input to
9213 text formatters or for automatic translation to a variety of
9214 formats suitable for input to text formatters. A copy made in an
9215 otherwise Transparent file format whose markup, or absence of
9216 markup, has been arranged to thwart or discourage subsequent
9217 modification by readers is not Transparent. An image format is
9218 not Transparent if used for any substantial amount of text. A
9219 copy that is not "Transparent" is called "Opaque".
9221 Examples of suitable formats for Transparent copies include plain
9222 ASCII without markup, Texinfo input format, LaTeX input format,
9223 SGML or XML using a publicly available DTD, and
9224 standard-conforming simple HTML, PostScript or PDF designed for
9225 human modification. Examples of transparent image formats include
9226 PNG, XCF and JPG. Opaque formats include proprietary formats that
9227 can be read and edited only by proprietary word processors, SGML or
9228 XML for which the DTD and/or processing tools are not generally
9229 available, and the machine-generated HTML, PostScript or PDF
9230 produced by some word processors for output purposes only.
9232 The "Title Page" means, for a printed book, the title page itself,
9233 plus such following pages as are needed to hold, legibly, the
9234 material this License requires to appear in the title page. For
9235 works in formats which do not have any title page as such, "Title
9236 Page" means the text near the most prominent appearance of the
9237 work's title, preceding the beginning of the body of the text.
9239 The "publisher" means any person or entity that distributes copies
9240 of the Document to the public.
9242 A section "Entitled XYZ" means a named subunit of the Document
9243 whose title either is precisely XYZ or contains XYZ in parentheses
9244 following text that translates XYZ in another language. (Here XYZ
9245 stands for a specific section name mentioned below, such as
9246 "Acknowledgements", "Dedications", "Endorsements", or "History".)
9247 To "Preserve the Title" of such a section when you modify the
9248 Document means that it remains a section "Entitled XYZ" according
9251 The Document may include Warranty Disclaimers next to the notice
9252 which states that this License applies to the Document. These
9253 Warranty Disclaimers are considered to be included by reference in
9254 this License, but only as regards disclaiming warranties: any other
9255 implication that these Warranty Disclaimers may have is void and
9256 has no effect on the meaning of this License.
9260 You may copy and distribute the Document in any medium, either
9261 commercially or noncommercially, provided that this License, the
9262 copyright notices, and the license notice saying this License
9263 applies to the Document are reproduced in all copies, and that you
9264 add no other conditions whatsoever to those of this License. You
9265 may not use technical measures to obstruct or control the reading
9266 or further copying of the copies you make or distribute. However,
9267 you may accept compensation in exchange for copies. If you
9268 distribute a large enough number of copies you must also follow
9269 the conditions in section 3.
9271 You may also lend copies, under the same conditions stated above,
9272 and you may publicly display copies.
9274 3. COPYING IN QUANTITY
9276 If you publish printed copies (or copies in media that commonly
9277 have printed covers) of the Document, numbering more than 100, and
9278 the Document's license notice requires Cover Texts, you must
9279 enclose the copies in covers that carry, clearly and legibly, all
9280 these Cover Texts: Front-Cover Texts on the front cover, and
9281 Back-Cover Texts on the back cover. Both covers must also clearly
9282 and legibly identify you as the publisher of these copies. The
9283 front cover must present the full title with all words of the
9284 title equally prominent and visible. You may add other material
9285 on the covers in addition. Copying with changes limited to the
9286 covers, as long as they preserve the title of the Document and
9287 satisfy these conditions, can be treated as verbatim copying in
9290 If the required texts for either cover are too voluminous to fit
9291 legibly, you should put the first ones listed (as many as fit
9292 reasonably) on the actual cover, and continue the rest onto
9295 If you publish or distribute Opaque copies of the Document
9296 numbering more than 100, you must either include a
9297 machine-readable Transparent copy along with each Opaque copy, or
9298 state in or with each Opaque copy a computer-network location from
9299 which the general network-using public has access to download
9300 using public-standard network protocols a complete Transparent
9301 copy of the Document, free of added material. If you use the
9302 latter option, you must take reasonably prudent steps, when you
9303 begin distribution of Opaque copies in quantity, to ensure that
9304 this Transparent copy will remain thus accessible at the stated
9305 location until at least one year after the last time you
9306 distribute an Opaque copy (directly or through your agents or
9307 retailers) of that edition to the public.
9309 It is requested, but not required, that you contact the authors of
9310 the Document well before redistributing any large number of
9311 copies, to give them a chance to provide you with an updated
9312 version of the Document.
9316 You may copy and distribute a Modified Version of the Document
9317 under the conditions of sections 2 and 3 above, provided that you
9318 release the Modified Version under precisely this License, with
9319 the Modified Version filling the role of the Document, thus
9320 licensing distribution and modification of the Modified Version to
9321 whoever possesses a copy of it. In addition, you must do these
9322 things in the Modified Version:
9324 A. Use in the Title Page (and on the covers, if any) a title
9325 distinct from that of the Document, and from those of
9326 previous versions (which should, if there were any, be listed
9327 in the History section of the Document). You may use the
9328 same title as a previous version if the original publisher of
9329 that version gives permission.
9331 B. List on the Title Page, as authors, one or more persons or
9332 entities responsible for authorship of the modifications in
9333 the Modified Version, together with at least five of the
9334 principal authors of the Document (all of its principal
9335 authors, if it has fewer than five), unless they release you
9336 from this requirement.
9338 C. State on the Title page the name of the publisher of the
9339 Modified Version, as the publisher.
9341 D. Preserve all the copyright notices of the Document.
9343 E. Add an appropriate copyright notice for your modifications
9344 adjacent to the other copyright notices.
9346 F. Include, immediately after the copyright notices, a license
9347 notice giving the public permission to use the Modified
9348 Version under the terms of this License, in the form shown in
9351 G. Preserve in that license notice the full lists of Invariant
9352 Sections and required Cover Texts given in the Document's
9355 H. Include an unaltered copy of this License.
9357 I. Preserve the section Entitled "History", Preserve its Title,
9358 and add to it an item stating at least the title, year, new
9359 authors, and publisher of the Modified Version as given on
9360 the Title Page. If there is no section Entitled "History" in
9361 the Document, create one stating the title, year, authors,
9362 and publisher of the Document as given on its Title Page,
9363 then add an item describing the Modified Version as stated in
9364 the previous sentence.
9366 J. Preserve the network location, if any, given in the Document
9367 for public access to a Transparent copy of the Document, and
9368 likewise the network locations given in the Document for
9369 previous versions it was based on. These may be placed in
9370 the "History" section. You may omit a network location for a
9371 work that was published at least four years before the
9372 Document itself, or if the original publisher of the version
9373 it refers to gives permission.
9375 K. For any section Entitled "Acknowledgements" or "Dedications",
9376 Preserve the Title of the section, and preserve in the
9377 section all the substance and tone of each of the contributor
9378 acknowledgements and/or dedications given therein.
9380 L. Preserve all the Invariant Sections of the Document,
9381 unaltered in their text and in their titles. Section numbers
9382 or the equivalent are not considered part of the section
9385 M. Delete any section Entitled "Endorsements". Such a section
9386 may not be included in the Modified Version.
9388 N. Do not retitle any existing section to be Entitled
9389 "Endorsements" or to conflict in title with any Invariant
9392 O. Preserve any Warranty Disclaimers.
9394 If the Modified Version includes new front-matter sections or
9395 appendices that qualify as Secondary Sections and contain no
9396 material copied from the Document, you may at your option
9397 designate some or all of these sections as invariant. To do this,
9398 add their titles to the list of Invariant Sections in the Modified
9399 Version's license notice. These titles must be distinct from any
9400 other section titles.
9402 You may add a section Entitled "Endorsements", provided it contains
9403 nothing but endorsements of your Modified Version by various
9404 parties--for example, statements of peer review or that the text
9405 has been approved by an organization as the authoritative
9406 definition of a standard.
9408 You may add a passage of up to five words as a Front-Cover Text,
9409 and a passage of up to 25 words as a Back-Cover Text, to the end
9410 of the list of Cover Texts in the Modified Version. Only one
9411 passage of Front-Cover Text and one of Back-Cover Text may be
9412 added by (or through arrangements made by) any one entity. If the
9413 Document already includes a cover text for the same cover,
9414 previously added by you or by arrangement made by the same entity
9415 you are acting on behalf of, you may not add another; but you may
9416 replace the old one, on explicit permission from the previous
9417 publisher that added the old one.
9419 The author(s) and publisher(s) of the Document do not by this
9420 License give permission to use their names for publicity for or to
9421 assert or imply endorsement of any Modified Version.
9423 5. COMBINING DOCUMENTS
9425 You may combine the Document with other documents released under
9426 this License, under the terms defined in section 4 above for
9427 modified versions, provided that you include in the combination
9428 all of the Invariant Sections of all of the original documents,
9429 unmodified, and list them all as Invariant Sections of your
9430 combined work in its license notice, and that you preserve all
9431 their Warranty Disclaimers.
9433 The combined work need only contain one copy of this License, and
9434 multiple identical Invariant Sections may be replaced with a single
9435 copy. If there are multiple Invariant Sections with the same name
9436 but different contents, make the title of each such section unique
9437 by adding at the end of it, in parentheses, the name of the
9438 original author or publisher of that section if known, or else a
9439 unique number. Make the same adjustment to the section titles in
9440 the list of Invariant Sections in the license notice of the
9443 In the combination, you must combine any sections Entitled
9444 "History" in the various original documents, forming one section
9445 Entitled "History"; likewise combine any sections Entitled
9446 "Acknowledgements", and any sections Entitled "Dedications". You
9447 must delete all sections Entitled "Endorsements."
9449 6. COLLECTIONS OF DOCUMENTS
9451 You may make a collection consisting of the Document and other
9452 documents released under this License, and replace the individual
9453 copies of this License in the various documents with a single copy
9454 that is included in the collection, provided that you follow the
9455 rules of this License for verbatim copying of each of the
9456 documents in all other respects.
9458 You may extract a single document from such a collection, and
9459 distribute it individually under this License, provided you insert
9460 a copy of this License into the extracted document, and follow
9461 this License in all other respects regarding verbatim copying of
9464 7. AGGREGATION WITH INDEPENDENT WORKS
9466 A compilation of the Document or its derivatives with other
9467 separate and independent documents or works, in or on a volume of
9468 a storage or distribution medium, is called an "aggregate" if the
9469 copyright resulting from the compilation is not used to limit the
9470 legal rights of the compilation's users beyond what the individual
9471 works permit. When the Document is included in an aggregate, this
9472 License does not apply to the other works in the aggregate which
9473 are not themselves derivative works of the Document.
9475 If the Cover Text requirement of section 3 is applicable to these
9476 copies of the Document, then if the Document is less than one half
9477 of the entire aggregate, the Document's Cover Texts may be placed
9478 on covers that bracket the Document within the aggregate, or the
9479 electronic equivalent of covers if the Document is in electronic
9480 form. Otherwise they must appear on printed covers that bracket
9481 the whole aggregate.
9485 Translation is considered a kind of modification, so you may
9486 distribute translations of the Document under the terms of section
9487 4. Replacing Invariant Sections with translations requires special
9488 permission from their copyright holders, but you may include
9489 translations of some or all Invariant Sections in addition to the
9490 original versions of these Invariant Sections. You may include a
9491 translation of this License, and all the license notices in the
9492 Document, and any Warranty Disclaimers, provided that you also
9493 include the original English version of this License and the
9494 original versions of those notices and disclaimers. In case of a
9495 disagreement between the translation and the original version of
9496 this License or a notice or disclaimer, the original version will
9499 If a section in the Document is Entitled "Acknowledgements",
9500 "Dedications", or "History", the requirement (section 4) to
9501 Preserve its Title (section 1) will typically require changing the
9506 You may not copy, modify, sublicense, or distribute the Document
9507 except as expressly provided under this License. Any attempt
9508 otherwise to copy, modify, sublicense, or distribute it is void,
9509 and will automatically terminate your rights under this License.
9511 However, if you cease all violation of this License, then your
9512 license from a particular copyright holder is reinstated (a)
9513 provisionally, unless and until the copyright holder explicitly
9514 and finally terminates your license, and (b) permanently, if the
9515 copyright holder fails to notify you of the violation by some
9516 reasonable means prior to 60 days after the cessation.
9518 Moreover, your license from a particular copyright holder is
9519 reinstated permanently if the copyright holder notifies you of the
9520 violation by some reasonable means, this is the first time you have
9521 received notice of violation of this License (for any work) from
9522 that copyright holder, and you cure the violation prior to 30 days
9523 after your receipt of the notice.
9525 Termination of your rights under this section does not terminate
9526 the licenses of parties who have received copies or rights from
9527 you under this License. If your rights have been terminated and
9528 not permanently reinstated, receipt of a copy of some or all of
9529 the same material does not give you any rights to use it.
9531 10. FUTURE REVISIONS OF THIS LICENSE
9533 The Free Software Foundation may publish new, revised versions of
9534 the GNU Free Documentation License from time to time. Such new
9535 versions will be similar in spirit to the present version, but may
9536 differ in detail to address new problems or concerns. See
9537 `http://www.gnu.org/copyleft/'.
9539 Each version of the License is given a distinguishing version
9540 number. If the Document specifies that a particular numbered
9541 version of this License "or any later version" applies to it, you
9542 have the option of following the terms and conditions either of
9543 that specified version or of any later version that has been
9544 published (not as a draft) by the Free Software Foundation. If
9545 the Document does not specify a version number of this License,
9546 you may choose any version ever published (not as a draft) by the
9547 Free Software Foundation. If the Document specifies that a proxy
9548 can decide which future versions of this License can be used, that
9549 proxy's public statement of acceptance of a version permanently
9550 authorizes you to choose that version for the Document.
9554 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
9555 World Wide Web server that publishes copyrightable works and also
9556 provides prominent facilities for anybody to edit those works. A
9557 public wiki that anybody can edit is an example of such a server.
9558 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
9559 site means any set of copyrightable works thus published on the MMC
9562 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
9563 license published by Creative Commons Corporation, a not-for-profit
9564 corporation with a principal place of business in San Francisco,
9565 California, as well as future copyleft versions of that license
9566 published by that same organization.
9568 "Incorporate" means to publish or republish a Document, in whole or
9569 in part, as part of another Document.
9571 An MMC is "eligible for relicensing" if it is licensed under this
9572 License, and if all works that were first published under this
9573 License somewhere other than this MMC, and subsequently
9574 incorporated in whole or in part into the MMC, (1) had no cover
9575 texts or invariant sections, and (2) were thus incorporated prior
9576 to November 1, 2008.
9578 The operator of an MMC Site may republish an MMC contained in the
9579 site under CC-BY-SA on the same site at any time before August 1,
9580 2009, provided the MMC is eligible for relicensing.
9583 ADDENDUM: How to use this License for your documents
9584 ====================================================
9586 To use this License in a document you have written, include a copy of
9587 the License in the document and put the following copyright and license
9588 notices just after the title page:
9590 Copyright (C) YEAR YOUR NAME.
9591 Permission is granted to copy, distribute and/or modify this document
9592 under the terms of the GNU Free Documentation License, Version 1.3
9593 or any later version published by the Free Software Foundation;
9594 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9595 Texts. A copy of the license is included in the section entitled ``GNU
9596 Free Documentation License''.
9598 If you have Invariant Sections, Front-Cover Texts and Back-Cover
9599 Texts, replace the "with...Texts." line with this:
9601 with the Invariant Sections being LIST THEIR TITLES, with
9602 the Front-Cover Texts being LIST, and with the Back-Cover Texts
9605 If you have Invariant Sections without Cover Texts, or some other
9606 combination of the three, merge those two alternatives to suit the
9609 If your document contains nontrivial examples of program code, we
9610 recommend releasing these examples in parallel under your choice of
9611 free software license, such as the GNU General Public License, to
9612 permit their use in free software.
9615 File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
9622 * Builtin Index:: Index of Bash builtin commands.
9623 * Reserved Word Index:: Index of Bash reserved words.
9624 * Variable Index:: Quick reference helps you find the
9626 * Function Index:: Index of bindable Readline functions.
9627 * Concept Index:: General index for concepts described in
9631 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
9633 D.1 Index of Shell Builtin Commands
9634 ===================================
9639 * .: Bourne Shell Builtins.
9641 * :: Bourne Shell Builtins.
9643 * [: Bourne Shell Builtins.
9645 * alias: Bash Builtins. (line 11)
9646 * bg: Job Control Builtins.
9648 * bind: Bash Builtins. (line 21)
9649 * break: Bourne Shell Builtins.
9651 * builtin: Bash Builtins. (line 98)
9652 * caller: Bash Builtins. (line 106)
9653 * cd: Bourne Shell Builtins.
9655 * command: Bash Builtins. (line 123)
9656 * compgen: Programmable Completion Builtins.
9658 * complete: Programmable Completion Builtins.
9660 * compopt: Programmable Completion Builtins.
9662 * continue: Bourne Shell Builtins.
9664 * declare: Bash Builtins. (line 142)
9665 * dirs: Directory Stack Builtins.
9667 * disown: Job Control Builtins.
9669 * echo: Bash Builtins. (line 221)
9670 * enable: Bash Builtins. (line 273)
9671 * eval: Bourne Shell Builtins.
9673 * exec: Bourne Shell Builtins.
9675 * exit: Bourne Shell Builtins.
9677 * export: Bourne Shell Builtins.
9679 * fc: Bash History Builtins.
9681 * fg: Job Control Builtins.
9683 * getopts: Bourne Shell Builtins.
9685 * hash: Bourne Shell Builtins.
9687 * help: Bash Builtins. (line 301)
9688 * history: Bash History Builtins.
9690 * jobs: Job Control Builtins.
9692 * kill: Job Control Builtins.
9694 * let: Bash Builtins. (line 321)
9695 * local: Bash Builtins. (line 328)
9696 * logout: Bash Builtins. (line 338)
9697 * mapfile: Bash Builtins. (line 342)
9698 * popd: Directory Stack Builtins.
9700 * printf: Bash Builtins. (line 388)
9701 * pushd: Directory Stack Builtins.
9703 * pwd: Bourne Shell Builtins.
9705 * read: Bash Builtins. (line 413)
9706 * readarray: Bash Builtins. (line 493)
9707 * readonly: Bourne Shell Builtins.
9709 * return: Bourne Shell Builtins.
9711 * set: The Set Builtin. (line 11)
9712 * shift: Bourne Shell Builtins.
9714 * shopt: The Shopt Builtin. (line 9)
9715 * source: Bash Builtins. (line 501)
9716 * suspend: Job Control Builtins.
9718 * test: Bourne Shell Builtins.
9720 * times: Bourne Shell Builtins.
9722 * trap: Bourne Shell Builtins.
9724 * type: Bash Builtins. (line 505)
9725 * typeset: Bash Builtins. (line 536)
9726 * ulimit: Bash Builtins. (line 542)
9727 * umask: Bourne Shell Builtins.
9729 * unalias: Bash Builtins. (line 630)
9730 * unset: Bourne Shell Builtins.
9732 * wait: Job Control Builtins.
9736 File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
9738 D.2 Index of Shell Reserved Words
9739 =================================
9744 * !: Pipelines. (line 9)
9745 * [[: Conditional Constructs.
9747 * ]]: Conditional Constructs.
9749 * case: Conditional Constructs.
9751 * do: Looping Constructs. (line 12)
9752 * done: Looping Constructs. (line 12)
9753 * elif: Conditional Constructs.
9755 * else: Conditional Constructs.
9757 * esac: Conditional Constructs.
9759 * fi: Conditional Constructs.
9761 * for: Looping Constructs. (line 29)
9762 * function: Shell Functions. (line 13)
9763 * if: Conditional Constructs.
9765 * in: Conditional Constructs.
9767 * select: Conditional Constructs.
9769 * then: Conditional Constructs.
9771 * time: Pipelines. (line 9)
9772 * until: Looping Constructs. (line 12)
9773 * while: Looping Constructs. (line 20)
9774 * {: Command Grouping. (line 21)
9775 * }: Command Grouping. (line 21)
9778 File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
9780 D.3 Parameter and Variable Index
9781 ================================
9786 * !: Special Parameters. (line 46)
9787 * #: Special Parameters. (line 30)
9788 * $: Special Parameters. (line 42)
9789 * *: Special Parameters. (line 9)
9790 * -: Special Parameters. (line 37)
9791 * 0: Special Parameters. (line 50)
9792 * ?: Special Parameters. (line 33)
9793 * @: Special Parameters. (line 19)
9794 * _: Special Parameters. (line 59)
9795 * auto_resume: Job Control Variables.
9797 * BASH: Bash Variables. (line 13)
9798 * BASH_ALIASES: Bash Variables. (line 30)
9799 * BASH_ARGC: Bash Variables. (line 37)
9800 * BASH_ARGV: Bash Variables. (line 47)
9801 * BASH_CMDS: Bash Variables. (line 57)
9802 * BASH_COMMAND: Bash Variables. (line 64)
9803 * BASH_ENV: Bash Variables. (line 69)
9804 * BASH_EXECUTION_STRING: Bash Variables. (line 75)
9805 * BASH_LINENO: Bash Variables. (line 78)
9806 * BASH_REMATCH: Bash Variables. (line 87)
9807 * BASH_SOURCE: Bash Variables. (line 95)
9808 * BASH_SUBSHELL: Bash Variables. (line 99)
9809 * BASH_VERSINFO: Bash Variables. (line 103)
9810 * BASH_VERSION: Bash Variables. (line 127)
9811 * BASH_XTRACEFD: Bash Variables. (line 130)
9812 * BASHOPTS: Bash Variables. (line 16)
9813 * BASHPID: Bash Variables. (line 25)
9814 * bell-style: Readline Init File Syntax.
9816 * bind-tty-special-chars: Readline Init File Syntax.
9818 * CDPATH: Bourne Shell Variables.
9820 * COLUMNS: Bash Variables. (line 141)
9821 * comment-begin: Readline Init File Syntax.
9823 * COMP_CWORD: Bash Variables. (line 146)
9824 * COMP_KEY: Bash Variables. (line 175)
9825 * COMP_LINE: Bash Variables. (line 152)
9826 * COMP_POINT: Bash Variables. (line 157)
9827 * COMP_TYPE: Bash Variables. (line 165)
9828 * COMP_WORDBREAKS: Bash Variables. (line 179)
9829 * COMP_WORDS: Bash Variables. (line 185)
9830 * completion-prefix-display-length: Readline Init File Syntax.
9832 * completion-query-items: Readline Init File Syntax.
9834 * COMPREPLY: Bash Variables. (line 193)
9835 * convert-meta: Readline Init File Syntax.
9837 * DIRSTACK: Bash Variables. (line 198)
9838 * disable-completion: Readline Init File Syntax.
9840 * editing-mode: Readline Init File Syntax.
9842 * EMACS: Bash Variables. (line 208)
9843 * enable-keypad: Readline Init File Syntax.
9845 * EUID: Bash Variables. (line 213)
9846 * expand-tilde: Readline Init File Syntax.
9848 * FCEDIT: Bash Variables. (line 217)
9849 * FIGNORE: Bash Variables. (line 221)
9850 * FUNCNAME: Bash Variables. (line 227)
9851 * GLOBIGNORE: Bash Variables. (line 236)
9852 * GROUPS: Bash Variables. (line 242)
9853 * histchars: Bash Variables. (line 248)
9854 * HISTCMD: Bash Variables. (line 263)
9855 * HISTCONTROL: Bash Variables. (line 268)
9856 * HISTFILE: Bash Variables. (line 284)
9857 * HISTFILESIZE: Bash Variables. (line 288)
9858 * HISTIGNORE: Bash Variables. (line 296)
9859 * history-preserve-point: Readline Init File Syntax.
9861 * history-size: Readline Init File Syntax.
9863 * HISTSIZE: Bash Variables. (line 315)
9864 * HISTTIMEFORMAT: Bash Variables. (line 319)
9865 * HOME: Bourne Shell Variables.
9867 * horizontal-scroll-mode: Readline Init File Syntax.
9869 * HOSTFILE: Bash Variables. (line 328)
9870 * HOSTNAME: Bash Variables. (line 339)
9871 * HOSTTYPE: Bash Variables. (line 342)
9872 * IFS: Bourne Shell Variables.
9874 * IGNOREEOF: Bash Variables. (line 345)
9875 * input-meta: Readline Init File Syntax.
9877 * INPUTRC: Bash Variables. (line 355)
9878 * isearch-terminators: Readline Init File Syntax.
9880 * keymap: Readline Init File Syntax.
9882 * LANG: Bash Variables. (line 359)
9883 * LC_ALL: Bash Variables. (line 363)
9884 * LC_COLLATE: Bash Variables. (line 367)
9885 * LC_CTYPE: Bash Variables. (line 374)
9886 * LC_MESSAGES <1>: Locale Translation. (line 11)
9887 * LC_MESSAGES: Bash Variables. (line 379)
9888 * LC_NUMERIC: Bash Variables. (line 383)
9889 * LINENO: Bash Variables. (line 387)
9890 * LINES: Bash Variables. (line 391)
9891 * MACHTYPE: Bash Variables. (line 396)
9892 * MAIL: Bourne Shell Variables.
9894 * MAILCHECK: Bash Variables. (line 400)
9895 * MAILPATH: Bourne Shell Variables.
9897 * mark-modified-lines: Readline Init File Syntax.
9899 * mark-symlinked-directories: Readline Init File Syntax.
9901 * match-hidden-files: Readline Init File Syntax.
9903 * meta-flag: Readline Init File Syntax.
9905 * OLDPWD: Bash Variables. (line 408)
9906 * OPTARG: Bourne Shell Variables.
9908 * OPTERR: Bash Variables. (line 411)
9909 * OPTIND: Bourne Shell Variables.
9911 * OSTYPE: Bash Variables. (line 415)
9912 * output-meta: Readline Init File Syntax.
9914 * page-completions: Readline Init File Syntax.
9916 * PATH: Bourne Shell Variables.
9918 * PIPESTATUS: Bash Variables. (line 418)
9919 * POSIXLY_CORRECT: Bash Variables. (line 423)
9920 * PPID: Bash Variables. (line 432)
9921 * PROMPT_COMMAND: Bash Variables. (line 436)
9922 * PROMPT_DIRTRIM: Bash Variables. (line 440)
9923 * PS1: Bourne Shell Variables.
9925 * PS2: Bourne Shell Variables.
9927 * PS3: Bash Variables. (line 446)
9928 * PS4: Bash Variables. (line 451)
9929 * PWD: Bash Variables. (line 457)
9930 * RANDOM: Bash Variables. (line 460)
9931 * REPLY: Bash Variables. (line 465)
9932 * revert-all-at-newline: Readline Init File Syntax.
9934 * SECONDS: Bash Variables. (line 468)
9935 * SHELL: Bash Variables. (line 474)
9936 * SHELLOPTS: Bash Variables. (line 479)
9937 * SHLVL: Bash Variables. (line 488)
9938 * show-all-if-ambiguous: Readline Init File Syntax.
9940 * show-all-if-unmodified: Readline Init File Syntax.
9942 * skip-completed-text: Readline Init File Syntax.
9944 * TEXTDOMAIN: Locale Translation. (line 11)
9945 * TEXTDOMAINDIR: Locale Translation. (line 11)
9946 * TIMEFORMAT: Bash Variables. (line 493)
9947 * TMOUT: Bash Variables. (line 531)
9948 * TMPDIR: Bash Variables. (line 543)
9949 * UID: Bash Variables. (line 547)
9950 * visible-stats: Readline Init File Syntax.
9954 File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
9962 * abort (C-g): Miscellaneous Commands.
9964 * accept-line (Newline or Return): Commands For History. (line 6)
9965 * backward-char (C-b): Commands For Moving. (line 15)
9966 * backward-delete-char (Rubout): Commands For Text. (line 11)
9967 * backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
9968 * backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
9969 * backward-word (M-b): Commands For Moving. (line 22)
9970 * beginning-of-history (M-<): Commands For History. (line 20)
9971 * beginning-of-line (C-a): Commands For Moving. (line 6)
9972 * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
9973 * capitalize-word (M-c): Commands For Text. (line 46)
9974 * character-search (C-]): Miscellaneous Commands.
9976 * character-search-backward (M-C-]): Miscellaneous Commands.
9978 * clear-screen (C-l): Commands For Moving. (line 34)
9979 * complete (<TAB>): Commands For Completion.
9981 * copy-backward-word (): Commands For Killing. (line 58)
9982 * copy-forward-word (): Commands For Killing. (line 63)
9983 * copy-region-as-kill (): Commands For Killing. (line 54)
9984 * delete-char (C-d): Commands For Text. (line 6)
9985 * delete-char-or-list (): Commands For Completion.
9987 * delete-horizontal-space (): Commands For Killing. (line 46)
9988 * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
9989 * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
9991 * downcase-word (M-l): Commands For Text. (line 42)
9992 * dump-functions (): Miscellaneous Commands.
9994 * dump-macros (): Miscellaneous Commands.
9996 * dump-variables (): Miscellaneous Commands.
9998 * end-kbd-macro (C-x )): Keyboard Macros. (line 9)
9999 * end-of-history (M->): Commands For History. (line 23)
10000 * end-of-line (C-e): Commands For Moving. (line 9)
10001 * exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
10003 * forward-backward-delete-char (): Commands For Text. (line 15)
10004 * forward-char (C-f): Commands For Moving. (line 12)
10005 * forward-search-history (C-s): Commands For History. (line 31)
10006 * forward-word (M-f): Commands For Moving. (line 18)
10007 * history-search-backward (): Commands For History. (line 51)
10008 * history-search-forward (): Commands For History. (line 46)
10009 * insert-comment (M-#): Miscellaneous Commands.
10011 * insert-completions (M-*): Commands For Completion.
10013 * kill-line (C-k): Commands For Killing. (line 6)
10014 * kill-region (): Commands For Killing. (line 50)
10015 * kill-whole-line (): Commands For Killing. (line 15)
10016 * kill-word (M-d): Commands For Killing. (line 19)
10017 * menu-complete (): Commands For Completion.
10019 * menu-complete-backward (): Commands For Completion.
10021 * next-history (C-n): Commands For History. (line 17)
10022 * non-incremental-forward-search-history (M-n): Commands For History.
10024 * non-incremental-reverse-search-history (M-p): Commands For History.
10026 * overwrite-mode (): Commands For Text. (line 50)
10027 * possible-completions (M-?): Commands For Completion.
10029 * prefix-meta (<ESC>): Miscellaneous Commands.
10031 * previous-history (C-p): Commands For History. (line 13)
10032 * quoted-insert (C-q or C-v): Commands For Text. (line 20)
10033 * re-read-init-file (C-x C-r): Miscellaneous Commands.
10035 * redraw-current-line (): Commands For Moving. (line 38)
10036 * reverse-search-history (C-r): Commands For History. (line 27)
10037 * revert-line (M-r): Miscellaneous Commands.
10039 * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
10040 * set-mark (C-@): Miscellaneous Commands.
10042 * skip-csi-sequence (): Miscellaneous Commands.
10044 * start-kbd-macro (C-x (): Keyboard Macros. (line 6)
10045 * transpose-chars (C-t): Commands For Text. (line 27)
10046 * transpose-words (M-t): Commands For Text. (line 33)
10047 * undo (C-_ or C-x C-u): Miscellaneous Commands.
10049 * universal-argument (): Numeric Arguments. (line 10)
10050 * unix-filename-rubout (): Commands For Killing. (line 41)
10051 * unix-line-discard (C-u): Commands For Killing. (line 12)
10052 * unix-word-rubout (C-w): Commands For Killing. (line 37)
10053 * upcase-word (M-u): Commands For Text. (line 38)
10054 * yank (C-y): Commands For Killing. (line 68)
10055 * yank-last-arg (M-. or M-_): Commands For History. (line 65)
10056 * yank-nth-arg (M-C-y): Commands For History. (line 56)
10057 * yank-pop (M-y): Commands For Killing. (line 71)
10060 File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
10068 * alias expansion: Aliases. (line 6)
10069 * arithmetic evaluation: Shell Arithmetic. (line 6)
10070 * arithmetic expansion: Arithmetic Expansion.
10072 * arithmetic, shell: Shell Arithmetic. (line 6)
10073 * arrays: Arrays. (line 6)
10074 * background: Job Control Basics. (line 6)
10075 * Bash configuration: Basic Installation. (line 6)
10076 * Bash installation: Basic Installation. (line 6)
10077 * Bourne shell: Basic Shell Features.
10079 * brace expansion: Brace Expansion. (line 6)
10080 * builtin: Definitions. (line 17)
10081 * command editing: Readline Bare Essentials.
10083 * command execution: Command Search and Execution.
10085 * command expansion: Simple Command Expansion.
10087 * command history: Bash History Facilities.
10089 * command search: Command Search and Execution.
10091 * command substitution: Command Substitution.
10093 * command timing: Pipelines. (line 9)
10094 * commands, compound: Compound Commands. (line 6)
10095 * commands, conditional: Conditional Constructs.
10097 * commands, grouping: Command Grouping. (line 6)
10098 * commands, lists: Lists. (line 6)
10099 * commands, looping: Looping Constructs. (line 6)
10100 * commands, pipelines: Pipelines. (line 6)
10101 * commands, shell: Shell Commands. (line 6)
10102 * commands, simple: Simple Commands. (line 6)
10103 * comments, shell: Comments. (line 6)
10104 * completion builtins: Programmable Completion Builtins.
10106 * configuration: Basic Installation. (line 6)
10107 * control operator: Definitions. (line 21)
10108 * coprocess: Coprocesses. (line 6)
10109 * directory stack: The Directory Stack. (line 6)
10110 * editing command lines: Readline Bare Essentials.
10112 * environment: Environment. (line 6)
10113 * evaluation, arithmetic: Shell Arithmetic. (line 6)
10114 * event designators: Event Designators. (line 6)
10115 * execution environment: Command Execution Environment.
10117 * exit status <1>: Exit Status. (line 6)
10118 * exit status: Definitions. (line 26)
10119 * expansion: Shell Expansions. (line 6)
10120 * expansion, arithmetic: Arithmetic Expansion.
10122 * expansion, brace: Brace Expansion. (line 6)
10123 * expansion, filename: Filename Expansion. (line 9)
10124 * expansion, parameter: Shell Parameter Expansion.
10126 * expansion, pathname: Filename Expansion. (line 9)
10127 * expansion, tilde: Tilde Expansion. (line 6)
10128 * expressions, arithmetic: Shell Arithmetic. (line 6)
10129 * expressions, conditional: Bash Conditional Expressions.
10131 * field: Definitions. (line 30)
10132 * filename: Definitions. (line 35)
10133 * filename expansion: Filename Expansion. (line 9)
10134 * foreground: Job Control Basics. (line 6)
10135 * functions, shell: Shell Functions. (line 6)
10136 * history builtins: Bash History Builtins.
10138 * history events: Event Designators. (line 7)
10139 * history expansion: History Interaction. (line 6)
10140 * history list: Bash History Facilities.
10142 * History, how to use: Programmable Completion Builtins.
10144 * identifier: Definitions. (line 51)
10145 * initialization file, readline: Readline Init File. (line 6)
10146 * installation: Basic Installation. (line 6)
10147 * interaction, readline: Readline Interaction.
10149 * interactive shell <1>: Interactive Shells. (line 6)
10150 * interactive shell: Invoking Bash. (line 127)
10151 * internationalization: Locale Translation. (line 6)
10152 * job: Definitions. (line 38)
10153 * job control <1>: Job Control Basics. (line 6)
10154 * job control: Definitions. (line 42)
10155 * kill ring: Readline Killing Commands.
10157 * killing text: Readline Killing Commands.
10159 * localization: Locale Translation. (line 6)
10160 * login shell: Invoking Bash. (line 124)
10161 * matching, pattern: Pattern Matching. (line 6)
10162 * metacharacter: Definitions. (line 46)
10163 * name: Definitions. (line 51)
10164 * native languages: Locale Translation. (line 6)
10165 * notation, readline: Readline Bare Essentials.
10167 * operator, shell: Definitions. (line 57)
10168 * parameter expansion: Shell Parameter Expansion.
10170 * parameters: Shell Parameters. (line 6)
10171 * parameters, positional: Positional Parameters.
10173 * parameters, special: Special Parameters. (line 6)
10174 * pathname expansion: Filename Expansion. (line 9)
10175 * pattern matching: Pattern Matching. (line 6)
10176 * pipeline: Pipelines. (line 6)
10177 * POSIX: Definitions. (line 9)
10178 * POSIX Mode: Bash POSIX Mode. (line 6)
10179 * process group: Definitions. (line 62)
10180 * process group ID: Definitions. (line 66)
10181 * process substitution: Process Substitution.
10183 * programmable completion: Programmable Completion.
10185 * prompting: Printing a Prompt. (line 6)
10186 * quoting: Quoting. (line 6)
10187 * quoting, ANSI: ANSI-C Quoting. (line 6)
10188 * Readline, how to use: Job Control Variables.
10190 * redirection: Redirections. (line 6)
10191 * reserved word: Definitions. (line 70)
10192 * restricted shell: The Restricted Shell.
10194 * return status: Definitions. (line 75)
10195 * shell arithmetic: Shell Arithmetic. (line 6)
10196 * shell function: Shell Functions. (line 6)
10197 * shell script: Shell Scripts. (line 6)
10198 * shell variable: Shell Parameters. (line 6)
10199 * shell, interactive: Interactive Shells. (line 6)
10200 * signal: Definitions. (line 78)
10201 * signal handling: Signals. (line 6)
10202 * special builtin <1>: Special Builtins. (line 6)
10203 * special builtin: Definitions. (line 82)
10204 * startup files: Bash Startup Files. (line 6)
10205 * suspending jobs: Job Control Basics. (line 6)
10206 * tilde expansion: Tilde Expansion. (line 6)
10207 * token: Definitions. (line 86)
10208 * translation, native languages: Locale Translation. (line 6)
10209 * variable, shell: Shell Parameters. (line 6)
10210 * variables, readline: Readline Init File Syntax.
10212 * word: Definitions. (line 90)
10213 * word splitting: Word Splitting. (line 6)
10214 * yanking text: Readline Killing Commands.
10221 Node: Introduction
\7f3185
10222 Node: What is Bash?
\7f3413
10223 Node: What is a shell?
\7f4526
10224 Node: Definitions
\7f7066
10225 Node: Basic Shell Features
\7f9984
10226 Node: Shell Syntax
\7f11203
10227 Node: Shell Operation
\7f12233
10228 Node: Quoting
\7f13527
10229 Node: Escape Character
\7f14830
10230 Node: Single Quotes
\7f15315
10231 Node: Double Quotes
\7f15663
10232 Node: ANSI-C Quoting
\7f16788
10233 Node: Locale Translation
\7f17773
10234 Node: Comments
\7f18669
10235 Node: Shell Commands
\7f19287
10236 Node: Simple Commands
\7f20111
10237 Node: Pipelines
\7f20742
10238 Node: Lists
\7f22998
10239 Node: Compound Commands
\7f24727
10240 Node: Looping Constructs
\7f25531
10241 Node: Conditional Constructs
\7f27986
10242 Node: Command Grouping
\7f36099
10243 Node: Coprocesses
\7f37578
10244 Node: Shell Functions
\7f39222
10245 Node: Shell Parameters
\7f43776
10246 Node: Positional Parameters
\7f46192
10247 Node: Special Parameters
\7f47092
10248 Node: Shell Expansions
\7f50056
10249 Node: Brace Expansion
\7f51981
10250 Node: Tilde Expansion
\7f54736
10251 Node: Shell Parameter Expansion
\7f57087
10252 Node: Command Substitution
\7f65988
10253 Node: Arithmetic Expansion
\7f67321
10254 Node: Process Substitution
\7f68171
10255 Node: Word Splitting
\7f69221
10256 Node: Filename Expansion
\7f70844
10257 Node: Pattern Matching
\7f72983
10258 Node: Quote Removal
\7f76622
10259 Node: Redirections
\7f76917
10260 Node: Executing Commands
\7f85442
10261 Node: Simple Command Expansion
\7f86112
10262 Node: Command Search and Execution
\7f88042
10263 Node: Command Execution Environment
\7f90379
10264 Node: Environment
\7f93365
10265 Node: Exit Status
\7f95025
10266 Node: Signals
\7f96646
10267 Node: Shell Scripts
\7f98614
10268 Node: Shell Builtin Commands
\7f101132
10269 Node: Bourne Shell Builtins
\7f103160
10270 Node: Bash Builtins
\7f120536
10271 Node: Modifying Shell Behavior
\7f145364
10272 Node: The Set Builtin
\7f145709
10273 Node: The Shopt Builtin
\7f155233
10274 Node: Special Builtins
\7f166095
10275 Node: Shell Variables
\7f167074
10276 Node: Bourne Shell Variables
\7f167514
10277 Node: Bash Variables
\7f169495
10278 Node: Bash Features
\7f192981
10279 Node: Invoking Bash
\7f193864
10280 Node: Bash Startup Files
\7f199673
10281 Node: Interactive Shells
\7f204685
10282 Node: What is an Interactive Shell?
\7f205095
10283 Node: Is this Shell Interactive?
\7f205744
10284 Node: Interactive Shell Behavior
\7f206559
10285 Node: Bash Conditional Expressions
\7f209839
10286 Node: Shell Arithmetic
\7f213488
10287 Node: Aliases
\7f216234
10288 Node: Arrays
\7f218806
10289 Node: The Directory Stack
\7f222764
10290 Node: Directory Stack Builtins
\7f223478
10291 Node: Printing a Prompt
\7f226370
10292 Node: The Restricted Shell
\7f229122
10293 Node: Bash POSIX Mode
\7f230954
10294 Node: Job Control
\7f239011
10295 Node: Job Control Basics
\7f239471
10296 Node: Job Control Builtins
\7f244188
10297 Node: Job Control Variables
\7f248552
10298 Node: Command Line Editing
\7f249710
10299 Node: Introduction and Notation
\7f251277
10300 Node: Readline Interaction
\7f252899
10301 Node: Readline Bare Essentials
\7f254090
10302 Node: Readline Movement Commands
\7f255879
10303 Node: Readline Killing Commands
\7f256844
10304 Node: Readline Arguments
\7f258764
10305 Node: Searching
\7f259808
10306 Node: Readline Init File
\7f261994
10307 Node: Readline Init File Syntax
\7f263141
10308 Node: Conditional Init Constructs
\7f277628
10309 Node: Sample Init File
\7f280161
10310 Node: Bindable Readline Commands
\7f283278
10311 Node: Commands For Moving
\7f284485
10312 Node: Commands For History
\7f285629
10313 Node: Commands For Text
\7f288784
10314 Node: Commands For Killing
\7f291457
10315 Node: Numeric Arguments
\7f293908
10316 Node: Commands For Completion
\7f295047
10317 Node: Keyboard Macros
\7f299007
10318 Node: Miscellaneous Commands
\7f299578
10319 Node: Readline vi Mode
\7f305384
10320 Node: Programmable Completion
\7f306298
10321 Node: Programmable Completion Builtins
\7f313504
10322 Node: Using History Interactively
\7f322640
10323 Node: Bash History Facilities
\7f323324
10324 Node: Bash History Builtins
\7f326238
10325 Node: History Interaction
\7f330095
10326 Node: Event Designators
\7f332800
10327 Node: Word Designators
\7f333815
10328 Node: Modifiers
\7f335454
10329 Node: Installing Bash
\7f336858
10330 Node: Basic Installation
\7f337995
10331 Node: Compilers and Options
\7f340687
10332 Node: Compiling For Multiple Architectures
\7f341428
10333 Node: Installation Names
\7f343092
10334 Node: Specifying the System Type
\7f343910
10335 Node: Sharing Defaults
\7f344626
10336 Node: Operation Controls
\7f345299
10337 Node: Optional Features
\7f346257
10338 Node: Reporting Bugs
\7f355816
10339 Node: Major Differences From The Bourne Shell
\7f357017
10340 Node: GNU Free Documentation License
\7f373704
10341 Node: Indexes
\7f398900
10342 Node: Builtin Index
\7f399354
10343 Node: Reserved Word Index
\7f406181
10344 Node: Variable Index
\7f408629
10345 Node: Function Index
\7f420722
10346 Node: Concept Index
\7f427731