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.2, 28 December 2010).
7 This is Edition 4.2, last updated 28 December 2010, of `The GNU Bash
8 Reference Manual', for `Bash', Version 4.2.
10 Copyright (C) 1988-2010 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.2, 28 December 2010).
43 This is Edition 4.2, last updated 28 December 2010, of `The GNU Bash
44 Reference Manual', for `Bash', Version 4.2.
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 the Unicode (ISO/IEC 10646) character whose value is the
482 hexadecimal value HHHH (one to four hex digits)
485 the Unicode (ISO/IEC 10646) character whose value is the
486 hexadecimal value HHHHHHHH (one to eight hex digits)
489 a control-X character
491 The expanded result is single-quoted, as if the dollar sign had not
495 File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
497 3.1.2.5 Locale-Specific Translation
498 ...................................
500 A double-quoted string preceded by a dollar sign (`$') will cause the
501 string to be translated according to the current locale. If the
502 current locale is `C' or `POSIX', the dollar sign is ignored. If the
503 string is translated and replaced, the replacement is double-quoted.
505 Some systems use the message catalog selected by the `LC_MESSAGES'
506 shell variable. Others create the name of the message catalog from the
507 value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of
508 `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the
509 `TEXTDOMAINDIR' variable to the location of the message catalog files.
510 Still others use both variables in this fashion:
511 `TEXTDOMAINDIR'/`LC_MESSAGES'/LC_MESSAGES/`TEXTDOMAIN'.mo.
514 File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
519 In a non-interactive shell, or an interactive shell in which the
520 `interactive_comments' option to the `shopt' builtin is enabled (*note
521 The Shopt Builtin::), a word beginning with `#' causes that word and
522 all remaining characters on that line to be ignored. An interactive
523 shell without the `interactive_comments' option enabled does not allow
524 comments. The `interactive_comments' option is on by default in
525 interactive shells. *Note Interactive Shells::, for a description of
526 what makes a shell interactive.
529 File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
534 A simple shell command such as `echo a b c' consists of the command
535 itself followed by arguments, separated by spaces.
537 More complex shell commands are composed of simple commands arranged
538 together in a variety of ways: in a pipeline in which the output of one
539 command becomes the input of a second, in a loop or conditional
540 construct, or in some other grouping.
544 * Simple Commands:: The most common type of command.
545 * Pipelines:: Connecting the input and output of several
547 * Lists:: How to execute commands sequentially.
548 * Compound Commands:: Shell commands for control flow.
549 * Coprocesses:: Two-way communication between commands.
550 * GNU Parallel:: Running commands in parallel.
553 File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
555 3.2.1 Simple Commands
556 ---------------------
558 A simple command is the kind of command encountered most often. It's
559 just a sequence of words separated by `blank's, terminated by one of
560 the shell's control operators (*note Definitions::). The first word
561 generally specifies a command to be executed, with the rest of the
562 words being that command's arguments.
564 The return status (*note Exit Status::) of a simple command is its
565 exit status as provided by the POSIX 1003.1 `waitpid' function, or
566 128+N if the command was terminated by signal N.
569 File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
574 A `pipeline' is a sequence of simple commands separated by one of the
575 control operators `|' or `|&'.
577 The format for a pipeline is
578 [`time' [`-p']] [`!'] COMMAND1 [ [`|' or `|&'] COMMAND2 ...]
580 The output of each command in the pipeline is connected via a pipe to
581 the input of the next command. That is, each command reads the
582 previous command's output. This connection is performed before any
583 redirections specified by the command.
585 If `|&' is used, the standard error of COMMAND1 is connected to
586 COMMAND2's standard input through the pipe; it is shorthand for `2>&1
587 |'. This implicit redirection of the standard error is performed after
588 any redirections specified by the command.
590 The reserved word `time' causes timing statistics to be printed for
591 the pipeline once it finishes. The statistics currently consist of
592 elapsed (wall-clock) time and user and system time consumed by the
593 command's execution. The `-p' option changes the output format to that
594 specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX
595 Mode::), it does not recognize `time' as a reserved word if the next
596 token begins with a `-'. The `TIMEFORMAT' variable may be set to a
597 format string that specifies how the timing information should be
598 displayed. *Note Bash Variables::, for a description of the available
599 formats. The use of `time' as a reserved word permits the timing of
600 shell builtins, shell functions, and pipelines. An external `time'
601 command cannot time these easily.
603 When the shell is in POSIX mode (*note Bash POSIX Mode::), `time'
604 may be followed by a newline. In this case, the shell displays the
605 total user and system time consumed by the shell and its children. The
606 `TIMEFORMAT' variable may be used to specify the format of the time
609 If the pipeline is not executed asynchronously (*note Lists::), the
610 shell waits for all commands in the pipeline to complete.
612 Each command in a pipeline is executed in its own subshell (*note
613 Command Execution Environment::). The exit status of a pipeline is the
614 exit status of the last command in the pipeline, unless the `pipefail'
615 option is enabled (*note The Set Builtin::). If `pipefail' is enabled,
616 the pipeline's return status is the value of the last (rightmost)
617 command to exit with a non-zero status, or zero if all commands exit
618 successfully. If the reserved word `!' precedes the pipeline, the exit
619 status is the logical negation of the exit status as described above.
620 The shell waits for all commands in the pipeline to terminate before
624 File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
626 3.2.3 Lists of Commands
627 -----------------------
629 A `list' is a sequence of one or more pipelines separated by one of the
630 operators `;', `&', `&&', or `||', and optionally terminated by one of
631 `;', `&', or a `newline'.
633 Of these list operators, `&&' and `||' have equal precedence,
634 followed by `;' and `&', which have equal precedence.
636 A sequence of one or more newlines may appear in a `list' to delimit
637 commands, equivalent to a semicolon.
639 If a command is terminated by the control operator `&', the shell
640 executes the command asynchronously in a subshell. This is known as
641 executing the command in the BACKGROUND. The shell does not wait for
642 the command to finish, and the return status is 0 (true). When job
643 control is not active (*note Job Control::), the standard input for
644 asynchronous commands, in the absence of any explicit redirections, is
645 redirected from `/dev/null'.
647 Commands separated by a `;' are executed sequentially; the shell
648 waits for each command to terminate in turn. The return status is the
649 exit status of the last command executed.
651 AND and OR lists are sequences of one or more pipelines separated by
652 the control operators `&&' and `||', respectively. AND and OR lists
653 are executed with left associativity.
655 An AND list has the form
658 COMMAND2 is executed if, and only if, COMMAND1 returns an exit status
661 An OR list has the form
664 COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
667 The return status of AND and OR lists is the exit status of the last
668 command executed in the list.
671 File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
673 3.2.4 Compound Commands
674 -----------------------
678 * Looping Constructs:: Shell commands for iterative action.
679 * Conditional Constructs:: Shell commands for conditional execution.
680 * Command Grouping:: Ways to group commands.
682 Compound commands are the shell programming constructs. Each
683 construct begins with a reserved word or control operator and is
684 terminated by a corresponding reserved word or operator. Any
685 redirections (*note Redirections::) associated with a compound command
686 apply to all commands within that compound command unless explicitly
689 Bash provides looping constructs, conditional commands, and
690 mechanisms to group commands and execute them as a unit.
693 File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
695 3.2.4.1 Looping Constructs
696 ..........................
698 Bash supports the following looping constructs.
700 Note that wherever a `;' appears in the description of a command's
701 syntax, it may be replaced with one or more newlines.
704 The syntax of the `until' command is:
705 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
706 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
707 status which is not zero. The return status is the exit status of
708 the last command executed in CONSEQUENT-COMMANDS, or zero if none
712 The syntax of the `while' command is:
713 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
715 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
716 status of zero. The return status is the exit status of the last
717 command executed in CONSEQUENT-COMMANDS, or zero if none was
721 The syntax of the `for' command is:
723 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
724 Expand WORDS, and execute COMMANDS once for each member in the
725 resultant list, with NAME bound to the current member. If `in
726 WORDS' is not present, the `for' command executes the COMMANDS
727 once for each positional parameter that is set, as if `in "$@"'
728 had been specified (*note Special Parameters::). The return
729 status is the exit status of the last command that executes. If
730 there are no items in the expansion of WORDS, no commands are
731 executed, and the return status is zero.
733 An alternate form of the `for' command is also supported:
735 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
736 First, the arithmetic expression EXPR1 is evaluated according to
737 the rules described below (*note Shell Arithmetic::). The
738 arithmetic expression EXPR2 is then evaluated repeatedly until it
739 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
740 COMMANDS are executed and the arithmetic expression EXPR3 is
741 evaluated. If any expression is omitted, it behaves as if it
742 evaluates to 1. The return value is the exit status of the last
743 command in COMMANDS that is executed, or false if any of the
744 expressions is invalid.
747 The `break' and `continue' builtins (*note Bourne Shell Builtins::)
748 may be used to control loop execution.
751 File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
753 3.2.4.2 Conditional Constructs
754 ..............................
757 The syntax of the `if' command is:
759 if TEST-COMMANDS; then
761 [elif MORE-TEST-COMMANDS; then
763 [else ALTERNATE-CONSEQUENTS;]
766 The TEST-COMMANDS list is executed, and if its return status is
767 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
768 returns a non-zero status, each `elif' list is executed in turn,
769 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
770 is executed and the command completes. If `else
771 ALTERNATE-CONSEQUENTS' is present, and the final command in the
772 final `if' or `elif' clause has a non-zero exit status, then
773 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
774 status of the last command executed, or zero if no condition
778 The syntax of the `case' command is:
780 `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
782 `case' will selectively execute the COMMAND-LIST corresponding to
783 the first PATTERN that matches WORD. If the shell option
784 `nocasematch' (see the description of `shopt' in *note The Shopt
785 Builtin::) is enabled, the match is performed without regard to
786 the case of alphabetic characters. The `|' is used to separate
787 multiple patterns, and the `)' operator terminates a pattern list.
788 A list of patterns and an associated command-list is known as a
791 Each clause must be terminated with `;;', `;&', or `;;&'. The
792 WORD undergoes tilde expansion, parameter expansion, command
793 substitution, arithmetic expansion, and quote removal before
794 matching is attempted. Each PATTERN undergoes tilde expansion,
795 parameter expansion, command substitution, and arithmetic
798 There may be an arbitrary number of `case' clauses, each terminated
799 by a `;;', `;&', or `;;&'. The first pattern that matches
800 determines the command-list that is executed.
802 Here is an example using `case' in a script that could be used to
803 describe one interesting feature of an animal:
805 echo -n "Enter the name of an animal: "
807 echo -n "The $ANIMAL has "
809 horse | dog | cat) echo -n "four";;
810 man | kangaroo ) echo -n "two";;
811 *) echo -n "an unknown number of";;
815 If the `;;' operator is used, no subsequent matches are attempted
816 after the first pattern match. Using `;&' in place of `;;'
817 causes execution to continue with the COMMAND-LIST associated with
818 the next clause, if any. Using `;;&' in place of `;;' causes the
819 shell to test the patterns in the next clause, if any, and execute
820 any associated COMMAND-LIST on a successful match.
822 The return status is zero if no PATTERN is matched. Otherwise, the
823 return status is the exit status of the COMMAND-LIST executed.
826 The `select' construct allows the easy generation of menus. It
827 has almost the same syntax as the `for' command:
829 select NAME [in WORDS ...]; do COMMANDS; done
831 The list of words following `in' is expanded, generating a list of
832 items. The set of expanded words is printed on the standard error
833 output stream, each preceded by a number. If the `in WORDS' is
834 omitted, the positional parameters are printed, as if `in "$@"'
835 had been specified. The `PS3' prompt is then displayed and a line
836 is read from the standard input. If the line consists of a number
837 corresponding to one of the displayed words, then the value of
838 NAME is set to that word. If the line is empty, the words and
839 prompt are displayed again. If `EOF' is read, the `select'
840 command completes. Any other value read causes NAME to be set to
841 null. The line read is saved in the variable `REPLY'.
843 The COMMANDS are executed after each selection until a `break'
844 command is executed, at which point the `select' command completes.
846 Here is an example that allows the user to pick a filename from the
847 current directory, and displays the name and index of the file
852 echo you picked $fname \($REPLY\)
859 The arithmetic EXPRESSION is evaluated according to the rules
860 described below (*note Shell Arithmetic::). If the value of the
861 expression is non-zero, the return status is 0; otherwise the
862 return status is 1. This is exactly equivalent to
864 *Note Bash Builtins::, for a full description of the `let' builtin.
869 Return a status of 0 or 1 depending on the evaluation of the
870 conditional expression EXPRESSION. Expressions are composed of
871 the primaries described below in *note Bash Conditional
872 Expressions::. Word splitting and filename expansion are not
873 performed on the words between the `[[' and `]]'; tilde expansion,
874 parameter and variable expansion, arithmetic expansion, command
875 substitution, process substitution, and quote removal are
876 performed. Conditional operators such as `-f' must be unquoted to
877 be recognized as primaries.
879 When used with `[[', the `<' and `>' operators sort
880 lexicographically using the current locale.
882 When the `==' and `!=' operators are used, the string to the right
883 of the operator is considered a pattern and matched according to
884 the rules described below in *note Pattern Matching::. If the
885 shell option `nocasematch' (see the description of `shopt' in
886 *note The Shopt Builtin::) is enabled, the match is performed
887 without regard to the case of alphabetic characters. The return
888 value is 0 if the string matches (`==') or does not match
889 (`!=')the pattern, and 1 otherwise. Any part of the pattern may
890 be quoted to force it to be matched as a string.
892 An additional binary operator, `=~', is available, with the same
893 precedence as `==' and `!='. When it is used, the string to the
894 right of the operator is considered an extended regular expression
895 and matched accordingly (as in regex3)). The return value is 0 if
896 the string matches the pattern, and 1 otherwise. If the regular
897 expression is syntactically incorrect, the conditional
898 expression's return value is 2. If the shell option `nocasematch'
899 (see the description of `shopt' in *note The Shopt Builtin::) is
900 enabled, the match is performed without regard to the case of
901 alphabetic characters. Any part of the pattern may be quoted to
902 force it to be matched as a string. Substrings matched by
903 parenthesized subexpressions within the regular expression are
904 saved in the array variable `BASH_REMATCH'. The element of
905 `BASH_REMATCH' with index 0 is the portion of the string matching
906 the entire regular expression. The element of `BASH_REMATCH' with
907 index N is the portion of the string matching the Nth
908 parenthesized subexpression.
910 Expressions may be combined using the following operators, listed
911 in decreasing order of precedence:
914 Returns the value of EXPRESSION. This may be used to
915 override the normal precedence of operators.
918 True if EXPRESSION is false.
920 `EXPRESSION1 && EXPRESSION2'
921 True if both EXPRESSION1 and EXPRESSION2 are true.
923 `EXPRESSION1 || EXPRESSION2'
924 True if either EXPRESSION1 or EXPRESSION2 is true.
925 The `&&' and `||' operators do not evaluate EXPRESSION2 if the
926 value of EXPRESSION1 is sufficient to determine the return value
927 of the entire conditional expression.
931 File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
933 3.2.4.3 Grouping Commands
934 .........................
936 Bash provides two ways to group a list of commands to be executed as a
937 unit. When commands are grouped, redirections may be applied to the
938 entire command list. For example, the output of all the commands in
939 the list may be redirected to a single stream.
944 Placing a list of commands between parentheses causes a subshell
945 environment to be created (*note Command Execution Environment::),
946 and each of the commands in LIST to be executed in that subshell.
947 Since the LIST is executed in a subshell, variable assignments do
948 not remain in effect after the subshell completes.
953 Placing a list of commands between curly braces causes the list to
954 be executed in the current shell context. No subshell is created.
955 The semicolon (or newline) following LIST is required.
957 In addition to the creation of a subshell, there is a subtle
958 difference between these two constructs due to historical reasons. The
959 braces are `reserved words', so they must be separated from the LIST by
960 `blank's or other shell metacharacters. The parentheses are
961 `operators', and are recognized as separate tokens by the shell even if
962 they are not separated from the LIST by whitespace.
964 The exit status of both of these constructs is the exit status of
968 File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
973 A `coprocess' is a shell command preceded by the `coproc' reserved word.
974 A coprocess is executed asynchronously in a subshell, as if the command
975 had been terminated with the `&' control operator, with a two-way pipe
976 established between the executing shell and the coprocess.
978 The format for a coprocess is:
979 `coproc' [NAME] COMMAND [REDIRECTIONS]
981 This creates a coprocess named NAME. If NAME is not supplied, the
982 default name is COPROC. NAME must not be supplied if COMMAND is a
983 simple command (*note Simple Commands::); otherwise, it is interpreted
984 as the first word of the simple command.
986 When the coproc is executed, the shell creates an array variable
987 (*note Arrays::) named NAME in the context of the executing shell. The
988 standard output of COMMAND is connected via a pipe to a file descriptor
989 in the executing shell, and that file descriptor is assigned to NAME[0].
990 The standard input of COMMAND is connected via a pipe to a file
991 descriptor in the executing shell, and that file descriptor is assigned
992 to NAME[1]. This pipe is established before any redirections specified
993 by the command (*note Redirections::). The file descriptors can be
994 utilized as arguments to shell commands and redirections using standard
997 The process ID of the shell spawned to execute the coprocess is
998 available as the value of the variable NAME_PID. The `wait' builtin
999 command may be used to wait for the coprocess to terminate.
1001 The return status of a coprocess is the exit status of COMMAND.
1004 File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1009 GNU Parallel, as its name suggests, can be used to build and run
1010 commands in parallel. You may run the same command with different
1011 arguments, whether they are filenames, usernames, hostnames, or lines
1014 For a complete description, refer to the GNU Parallel documentation.
1015 A few examples should provide a brief introduction to its use.
1017 For example, it is easy to prefix each line in a text file with a
1019 cat file | parallel -k echo prefix_string
1020 The `-k' option is required to preserve the lines' order.
1022 Similarly, you can append a specified string to each line in a text
1024 cat file | parallel -k echo {} append_string
1026 You can use Parallel to move files from the current directory when
1027 the number of files is too large to process with one `mv' invocation:
1028 ls | parallel mv {} destdir
1030 As you can see, the {} is replaced with each line read from standard
1031 input. This will run as many `mv' commands as there are files in the
1032 current directory. You can emulate a parallel `xargs' by adding the
1034 ls | parallel -X mv {} destdir
1036 GNU Parallel can replace certain common idioms that operate on lines
1037 read from a file (in this case, filenames):
1038 for x in $(cat list); do
1039 do-something1 $x config-$x
1041 done | process-output
1043 with a more compact syntax reminiscent of lambdas:
1044 cat list | parallel "do-something1 {} config-{} ; do-something2 < {}" | process-output
1046 Parallel provides a built-in mechanism to remove filename
1047 extensions, which lends itself to batch file transformations or
1049 ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
1050 This will recompress all files in the current directory with names
1051 ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
1053 If a command generates output, you may want to preserve the input
1054 order in the output. For instance, the following command
1055 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel traceroute
1056 will display as output the traceroute invocation that finishes
1057 first. Using the `-k' option, as we saw above
1058 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel -k traceroute
1059 will ensure that the output of `traceroute foss.org.my' is displayed
1063 File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
1068 Shell functions are a way to group commands for later execution using a
1069 single name for the group. They are executed just like a "regular"
1070 command. When the name of a shell function is used as a simple command
1071 name, the list of commands associated with that function name is
1072 executed. Shell functions are executed in the current shell context;
1073 no new process is created to interpret them.
1075 Functions are declared using this syntax:
1076 NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
1079 `function' NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
1081 This defines a shell function named NAME. The reserved word
1082 `function' is optional. If the `function' reserved word is supplied,
1083 the parentheses are optional. The BODY of the function is the compound
1084 command COMPOUND-COMMAND (*note Compound Commands::). That command is
1085 usually a LIST enclosed between { and }, but may be any compound
1086 command listed above. COMPOUND-COMMAND is executed whenever NAME is
1087 specified as the name of a command. Any redirections (*note
1088 Redirections::) associated with the shell function are performed when
1089 the function is executed.
1091 A function definition may be deleted using the `-f' option to the
1092 `unset' builtin (*note Bourne Shell Builtins::).
1094 The exit status of a function definition is zero unless a syntax
1095 error occurs or a readonly function with the same name already exists.
1096 When executed, the exit status of a function is the exit status of the
1097 last command executed in the body.
1099 Note that for historical reasons, in the most common usage the curly
1100 braces that surround the body of the function must be separated from
1101 the body by `blank's or newlines. This is because the braces are
1102 reserved words and are only recognized as such when they are separated
1103 from the command list by whitespace or another shell metacharacter.
1104 Also, when using the braces, the LIST must be terminated by a semicolon,
1105 a `&', or a newline.
1107 When a function is executed, the arguments to the function become
1108 the positional parameters during its execution (*note Positional
1109 Parameters::). The special parameter `#' that expands to the number of
1110 positional parameters is updated to reflect the change. Special
1111 parameter `0' is unchanged. The first element of the `FUNCNAME'
1112 variable is set to the name of the function while the function is
1115 All other aspects of the shell execution environment are identical
1116 between a function and its caller with these exceptions: the `DEBUG'
1117 and `RETURN' traps are not inherited unless the function has been given
1118 the `trace' attribute using the `declare' builtin or the `-o functrace'
1119 option has been enabled with the `set' builtin, (in which case all
1120 functions inherit the `DEBUG' and `RETURN' traps), and the `ERR' trap
1121 is not inherited unless the `-o errtrace' shell option has been enabled.
1122 *Note Bourne Shell Builtins::, for the description of the `trap'
1125 The `FUNCNEST' variable, if set to a numeric value greater than 0,
1126 defines a maximum function nesting level. Function invocations that
1127 exceed the limit cause the entire command to abort.
1129 If the builtin command `return' is executed in a function, the
1130 function completes and execution resumes with the next command after
1131 the function call. Any command associated with the `RETURN' trap is
1132 executed before execution resumes. When a function completes, the
1133 values of the positional parameters and the special parameter `#' are
1134 restored to the values they had prior to the function's execution. If
1135 a numeric argument is given to `return', that is the function's return
1136 status; otherwise the function's return status is the exit status of
1137 the last command executed before the `return'.
1139 Variables local to the function may be declared with the `local'
1140 builtin. These variables are visible only to the function and the
1141 commands it invokes.
1143 Function names and definitions may be listed with the `-f' option to
1144 the `declare' or `typeset' builtin commands (*note Bash Builtins::).
1145 The `-F' option to `declare' or `typeset' will list the function names
1146 only (and optionally the source file and line number, if the `extdebug'
1147 shell option is enabled). Functions may be exported so that subshells
1148 automatically have them defined with the `-f' option to the `export'
1149 builtin (*note Bourne Shell Builtins::). Note that shell functions and
1150 variables with the same name may result in multiple identically-named
1151 entries in the environment passed to the shell's children. Care should
1152 be taken in cases where this may cause a problem.
1154 Functions may be recursive. The `FUNCNEST' variable may be used to
1155 limit the depth of the function call stack and restrict the number of
1156 function invocations. By default, no limit is placed on the number of
1160 File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1162 3.4 Shell Parameters
1163 ====================
1167 * Positional Parameters:: The shell's command-line arguments.
1168 * Special Parameters:: Parameters denoted by special characters.
1170 A PARAMETER is an entity that stores values. It can be a `name', a
1171 number, or one of the special characters listed below. A VARIABLE is a
1172 parameter denoted by a `name'. A variable has a VALUE and zero or more
1173 ATTRIBUTES. Attributes are assigned using the `declare' builtin command
1174 (see the description of the `declare' builtin in *note Bash Builtins::).
1176 A parameter is set if it has been assigned a value. The null string
1177 is a valid value. Once a variable is set, it may be unset only by using
1178 the `unset' builtin command.
1180 A variable may be assigned to by a statement of the form
1182 If VALUE is not given, the variable is assigned the null string. All
1183 VALUEs undergo tilde expansion, parameter and variable expansion,
1184 command substitution, arithmetic expansion, and quote removal (detailed
1185 below). If the variable has its `integer' attribute set, then VALUE is
1186 evaluated as an arithmetic expression even if the `$((...))' expansion
1187 is not used (*note Arithmetic Expansion::). Word splitting is not
1188 performed, with the exception of `"$@"' as explained below. Filename
1189 expansion is not performed. Assignment statements may also appear as
1190 arguments to the `alias', `declare', `typeset', `export', `readonly',
1191 and `local' builtin commands.
1193 In the context where an assignment statement is assigning a value to
1194 a shell variable or array index (*note Arrays::), the `+=' operator can
1195 be used to append to or add to the variable's previous value. When
1196 `+=' is applied to a variable for which the INTEGER attribute has been
1197 set, VALUE is evaluated as an arithmetic expression and added to the
1198 variable's current value, which is also evaluated. When `+=' is
1199 applied to an array variable using compound assignment (*note
1200 Arrays::), the variable's value is not unset (as it is when using `='),
1201 and new values are appended to the array beginning at one greater than
1202 the array's maximum index (for indexed arrays), or added as additional
1203 key-value pairs in an associative array. When applied to a
1204 string-valued variable, VALUE is expanded and appended to the
1208 File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1210 3.4.1 Positional Parameters
1211 ---------------------------
1213 A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
1214 other than the single digit `0'. Positional parameters are assigned
1215 from the shell's arguments when it is invoked, and may be reassigned
1216 using the `set' builtin command. Positional parameter `N' may be
1217 referenced as `${N}', or as `$N' when `N' consists of a single digit.
1218 Positional parameters may not be assigned to with assignment statements.
1219 The `set' and `shift' builtins are used to set and unset them (*note
1220 Shell Builtin Commands::). The positional parameters are temporarily
1221 replaced when a shell function is executed (*note Shell Functions::).
1223 When a positional parameter consisting of more than a single digit
1224 is expanded, it must be enclosed in braces.
1227 File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1229 3.4.2 Special Parameters
1230 ------------------------
1232 The shell treats several parameters specially. These parameters may
1233 only be referenced; assignment to them is not allowed.
1236 Expands to the positional parameters, starting from one. When the
1237 expansion occurs within double quotes, it expands to a single word
1238 with the value of each parameter separated by the first character
1239 of the `IFS' special variable. That is, `"$*"' is equivalent to
1240 `"$1C$2C..."', where C is the first character of the value of the
1241 `IFS' variable. If `IFS' is unset, the parameters are separated
1242 by spaces. If `IFS' is null, the parameters are joined without
1243 intervening separators.
1246 Expands to the positional parameters, starting from one. When the
1247 expansion occurs within double quotes, each parameter expands to a
1248 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
1249 If the double-quoted expansion occurs within a word, the expansion
1250 of the first parameter is joined with the beginning part of the
1251 original word, and the expansion of the last parameter is joined
1252 with the last part of the original word. When there are no
1253 positional parameters, `"$@"' and `$@' expand to nothing (i.e.,
1257 Expands to the number of positional parameters in decimal.
1260 Expands to the exit status of the most recently executed foreground
1264 (A hyphen.) Expands to the current option flags as specified upon
1265 invocation, by the `set' builtin command, or those set by the
1266 shell itself (such as the `-i' option).
1269 Expands to the process ID of the shell. In a `()' subshell, it
1270 expands to the process ID of the invoking shell, not the subshell.
1273 Expands to the process ID of the most recently executed background
1274 (asynchronous) command.
1277 Expands to the name of the shell or shell script. This is set at
1278 shell initialization. If Bash is invoked with a file of commands
1279 (*note Shell Scripts::), `$0' is set to the name of that file. If
1280 Bash is started with the `-c' option (*note Invoking Bash::), then
1281 `$0' is set to the first argument after the string to be executed,
1282 if one is present. Otherwise, it is set to the filename used to
1283 invoke Bash, as given by argument zero.
1286 (An underscore.) At shell startup, set to the absolute pathname
1287 used to invoke the shell or shell script being executed as passed
1288 in the environment or argument list. Subsequently, expands to the
1289 last argument to the previous command, after expansion. Also set
1290 to the full pathname used to invoke each command executed and
1291 placed in the environment exported to that command. When checking
1292 mail, this parameter holds the name of the mail file.
1295 File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1297 3.5 Shell Expansions
1298 ====================
1300 Expansion is performed on the command line after it has been split into
1301 `token's. There are seven kinds of expansion performed:
1306 * parameter and variable expansion
1308 * command substitution
1310 * arithmetic expansion
1314 * filename expansion
1318 * Brace Expansion:: Expansion of expressions within braces.
1319 * Tilde Expansion:: Expansion of the ~ character.
1320 * Shell Parameter Expansion:: How Bash expands variables to their values.
1321 * Command Substitution:: Using the output of a command as an argument.
1322 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
1323 * Process Substitution:: A way to write and read to and from a
1325 * Word Splitting:: How the results of expansion are split into separate
1327 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
1328 * Quote Removal:: How and when quote characters are removed from
1331 The order of expansions is: brace expansion, tilde expansion,
1332 parameter, variable, and arithmetic expansion and command substitution
1333 (done in a left-to-right fashion), word splitting, and filename
1336 On systems that can support it, there is an additional expansion
1337 available: PROCESS SUBSTITUTION. This is performed at the same time as
1338 parameter, variable, and arithmetic expansion and command substitution.
1340 Only brace expansion, word splitting, and filename expansion can
1341 change the number of words of the expansion; other expansions expand a
1342 single word to a single word. The only exceptions to this are the
1343 expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"'
1346 After all expansions, `quote removal' (*note Quote Removal::) is
1350 File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1352 3.5.1 Brace Expansion
1353 ---------------------
1355 Brace expansion is a mechanism by which arbitrary strings may be
1356 generated. This mechanism is similar to FILENAME EXPANSION (*note
1357 Filename Expansion::), but the file names generated need not exist.
1358 Patterns to be brace expanded take the form of an optional PREAMBLE,
1359 followed by either a series of comma-separated strings or a seqeunce
1360 expression between a pair of braces, followed by an optional POSTSCRIPT.
1361 The preamble is prefixed to each string contained within the braces, and
1362 the postscript is then appended to each resulting string, expanding left
1365 Brace expansions may be nested. The results of each expanded string
1366 are not sorted; left to right order is preserved. For example,
1367 bash$ echo a{d,c,b}e
1370 A sequence expression takes the form `{X..Y[..INCR]}', where X and Y
1371 are either integers or single characters, and INCR, an optional
1372 increment, is an integer. When integers are supplied, the expression
1373 expands to each number between X and Y, inclusive. Supplied integers
1374 may be prefixed with `0' to force each term to have the same width.
1375 When either X or Y begins with a zero, the shell attempts to force all
1376 generated terms to contain the same number of digits, zero-padding
1377 where necessary. When characters are supplied, the expression expands
1378 to each character lexicographically between X and Y, inclusive. Note
1379 that both X and Y must be of the same type. When the increment is
1380 supplied, it is used as the difference between each term. The default
1381 increment is 1 or -1 as appropriate.
1383 Brace expansion is performed before any other expansions, and any
1384 characters special to other expansions are preserved in the result. It
1385 is strictly textual. Bash does not apply any syntactic interpretation
1386 to the context of the expansion or the text between the braces. To
1387 avoid conflicts with parameter expansion, the string `${' is not
1388 considered eligible for brace expansion.
1390 A correctly-formed brace expansion must contain unquoted opening and
1391 closing braces, and at least one unquoted comma or a valid sequence
1392 expression. Any incorrectly formed brace expansion is left unchanged.
1394 A { or `,' may be quoted with a backslash to prevent its being
1395 considered part of a brace expression. To avoid conflicts with
1396 parameter expansion, the string `${' is not considered eligible for
1399 This construct is typically used as shorthand when the common prefix
1400 of the strings to be generated is longer than in the above example:
1401 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1403 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1406 File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1408 3.5.2 Tilde Expansion
1409 ---------------------
1411 If a word begins with an unquoted tilde character (`~'), all of the
1412 characters up to the first unquoted slash (or all characters, if there
1413 is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1414 characters in the tilde-prefix are quoted, the characters in the
1415 tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1416 If this login name is the null string, the tilde is replaced with the
1417 value of the `HOME' shell variable. If `HOME' is unset, the home
1418 directory of the user executing the shell is substituted instead.
1419 Otherwise, the tilde-prefix is replaced with the home directory
1420 associated with the specified login name.
1422 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1423 replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1424 the shell variable `OLDPWD', if it is set, is substituted.
1426 If the characters following the tilde in the tilde-prefix consist of
1427 a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1428 replaced with the corresponding element from the directory stack, as it
1429 would be displayed by the `dirs' builtin invoked with the characters
1430 following tilde in the tilde-prefix as an argument (*note The Directory
1431 Stack::). If the tilde-prefix, sans the tilde, consists of a number
1432 without a leading `+' or `-', `+' is assumed.
1434 If the login name is invalid, or the tilde expansion fails, the word
1437 Each variable assignment is checked for unquoted tilde-prefixes
1438 immediately following a `:' or the first `='. In these cases, tilde
1439 expansion is also performed. Consequently, one may use file names with
1440 tildes in assignments to `PATH', `MAILPATH', and `CDPATH', and the
1441 shell assigns the expanded value.
1443 The following table shows how Bash treats unquoted tilde-prefixes:
1446 The value of `$HOME'
1452 The subdirectory `foo' of the home directory of the user `fred'
1458 `${OLDPWD-'~-'}/foo'
1461 The string that would be displayed by `dirs +N'
1464 The string that would be displayed by `dirs +N'
1467 The string that would be displayed by `dirs -N'
1471 File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1473 3.5.3 Shell Parameter Expansion
1474 -------------------------------
1476 The `$' character introduces parameter expansion, command substitution,
1477 or arithmetic expansion. The parameter name or symbol to be expanded
1478 may be enclosed in braces, which are optional but serve to protect the
1479 variable to be expanded from characters immediately following it which
1480 could be interpreted as part of the name.
1482 When braces are used, the matching ending brace is the first `}' not
1483 escaped by a backslash or within a quoted string, and not within an
1484 embedded arithmetic expansion, command substitution, or parameter
1487 The basic form of parameter expansion is ${PARAMETER}. The value of
1488 PARAMETER is substituted. The braces are required when PARAMETER is a
1489 positional parameter with more than one digit, or when PARAMETER is
1490 followed by a character that is not to be interpreted as part of its
1493 If the first character of PARAMETER is an exclamation point (!), a
1494 level of variable indirection is introduced. Bash uses the value of
1495 the variable formed from the rest of PARAMETER as the name of the
1496 variable; this variable is then expanded and that value is used in the
1497 rest of the substitution, rather than the value of PARAMETER itself.
1498 This is known as `indirect expansion'. The exceptions to this are the
1499 expansions of ${!PREFIX
1500 } and ${!NAME[@]} described below. The exclamation point must
1501 immediately follow the left brace in order to introduce indirection.
1503 In each of the cases below, WORD is subject to tilde expansion,
1504 parameter expansion, command substitution, and arithmetic expansion.
1506 When not performing substring expansion, using the form described
1507 below, Bash tests for a parameter that is unset or null. Omitting the
1508 colon results in a test only for a parameter that is unset. Put
1509 another way, if the colon is included, the operator tests for both
1510 PARAMETER's existence and that its value is not null; if the colon is
1511 omitted, the operator tests only for existence.
1513 `${PARAMETER:-WORD}'
1514 If PARAMETER is unset or null, the expansion of WORD is
1515 substituted. Otherwise, the value of PARAMETER is substituted.
1517 `${PARAMETER:=WORD}'
1518 If PARAMETER is unset or null, the expansion of WORD is assigned
1519 to PARAMETER. The value of PARAMETER is then substituted.
1520 Positional parameters and special parameters may not be assigned to
1523 `${PARAMETER:?WORD}'
1524 If PARAMETER is null or unset, the expansion of WORD (or a message
1525 to that effect if WORD is not present) is written to the standard
1526 error and the shell, if it is not interactive, exits. Otherwise,
1527 the value of PARAMETER is substituted.
1529 `${PARAMETER:+WORD}'
1530 If PARAMETER is null or unset, nothing is substituted, otherwise
1531 the expansion of WORD is substituted.
1533 `${PARAMETER:OFFSET}'
1534 `${PARAMETER:OFFSET:LENGTH}'
1535 Expands to up to LENGTH characters of PARAMETER starting at the
1536 character specified by OFFSET. If LENGTH is omitted, expands to
1537 the substring of PARAMETER starting at the character specified by
1538 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
1539 Arithmetic::). This is referred to as Substring Expansion.
1541 If OFFSET evaluates to a number less than zero, the value is used
1542 as an offset from the end of the value of PARAMETER. If LENGTH
1543 evaluates to a number less than zero, and PARAMETER is not `@' and
1544 not an indexed or associative array, it is interpreted as an
1545 offset from the end of the value of PARAMETER rather than a number
1546 of characters, and the expansion is the characters between the two
1547 offsets. If PARAMETER is `@', the result is LENGTH positional
1548 parameters beginning at OFFSET. If PARAMETER is an indexed array
1549 name subscripted by `@' or `*', the result is the LENGTH members
1550 of the array beginning with `${PARAMETER[OFFSET]}'. A negative
1551 OFFSET is taken relative to one greater than the maximum index of
1552 the specified array. Substring expansion applied to an
1553 associative array produces undefined results.
1555 Note that a negative offset must be separated from the colon by at
1556 least one space to avoid being confused with the `:-' expansion.
1557 Substring indexing is zero-based unless the positional parameters
1558 are used, in which case the indexing starts at 1 by default. If
1559 OFFSET is 0, and the positional parameters are used, `$@' is
1560 prefixed to the list.
1564 Expands to the names of variables whose names begin with PREFIX,
1565 separated by the first character of the `IFS' special variable.
1566 When `@' is used and the expansion appears within double quotes,
1567 each variable name expands to a separate word.
1571 If NAME is an array variable, expands to the list of array indices
1572 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1573 NAME is set and null otherwise. When `@' is used and the
1574 expansion appears within double quotes, each key expands to a
1578 The length in characters of the expanded value of PARAMETER is
1579 substituted. If PARAMETER is `*' or `@', the value substituted is
1580 the number of positional parameters. If PARAMETER is an array
1581 name subscripted by `*' or `@', the value substituted is the
1582 number of elements in the array.
1585 `${PARAMETER##WORD}'
1586 The WORD is expanded to produce a pattern just as in filename
1587 expansion (*note Filename Expansion::). If the pattern matches
1588 the beginning of the expanded value of PARAMETER, then the result
1589 of the expansion is the expanded value of PARAMETER with the
1590 shortest matching pattern (the `#' case) or the longest matching
1591 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1592 pattern removal operation is applied to each positional parameter
1593 in turn, and the expansion is the resultant list. If PARAMETER is
1594 an array variable subscripted with `@' or `*', the pattern removal
1595 operation is applied to each member of the array in turn, and the
1596 expansion is the resultant list.
1599 `${PARAMETER%%WORD}'
1600 The WORD is expanded to produce a pattern just as in filename
1601 expansion. If the pattern matches a trailing portion of the
1602 expanded value of PARAMETER, then the result of the expansion is
1603 the value of PARAMETER with the shortest matching pattern (the `%'
1604 case) or the longest matching pattern (the `%%' case) deleted. If
1605 PARAMETER is `@' or `*', the pattern removal operation is applied
1606 to each positional parameter in turn, and the expansion is the
1607 resultant list. If PARAMETER is an array variable subscripted
1608 with `@' or `*', the pattern removal operation is applied to each
1609 member of the array in turn, and the expansion is the resultant
1612 `${PARAMETER/PATTERN/STRING}'
1613 The PATTERN is expanded to produce a pattern just as in filename
1614 expansion. PARAMETER is expanded and the longest match of PATTERN
1615 against its value is replaced with STRING. If PATTERN begins with
1616 `/', all matches of PATTERN are replaced with STRING. Normally
1617 only the first match is replaced. If PATTERN begins with `#', it
1618 must match at the beginning of the expanded value of PARAMETER.
1619 If PATTERN begins with `%', it must match at the end of the
1620 expanded value of PARAMETER. If STRING is null, matches of
1621 PATTERN are deleted and the `/' following PATTERN may be omitted.
1622 If PARAMETER is `@' or `*', the substitution operation is applied
1623 to each positional parameter in turn, and the expansion is the
1624 resultant list. If PARAMETER is an array variable subscripted
1625 with `@' or `*', the substitution operation is applied to each
1626 member of the array in turn, and the expansion is the resultant
1629 `${PARAMETER^PATTERN}'
1630 `${PARAMETER^^PATTERN}'
1631 `${PARAMETER,PATTERN}'
1632 `${PARAMETER,,PATTERN}'
1633 This expansion modifies the case of alphabetic characters in
1634 PARAMETER. The PATTERN is expanded to produce a pattern just as in
1635 filename expansion. The `^' operator converts lowercase letters
1636 matching PATTERN to uppercase; the `,' operator converts matching
1637 uppercase letters to lowercase. The `^^' and `,,' expansions
1638 convert each matched character in the expanded value; the `^' and
1639 `,' expansions match and convert only the first character in the
1640 expanded value. If PATTERN is omitted, it is treated like a `?',
1641 which matches every character. If PARAMETER is `@' or `*', the
1642 case modification operation is applied to each positional
1643 parameter in turn, and the expansion is the resultant list. If
1644 PARAMETER is an array variable subscripted with `@' or `*', the
1645 case modification operation is applied to each member of the array
1646 in turn, and the expansion is the resultant list.
1650 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1652 3.5.4 Command Substitution
1653 --------------------------
1655 Command substitution allows the output of a command to replace the
1656 command itself. Command substitution occurs when a command is enclosed
1662 Bash performs the expansion by executing COMMAND and replacing the
1663 command substitution with the standard output of the command, with any
1664 trailing newlines deleted. Embedded newlines are not deleted, but they
1665 may be removed during word splitting. The command substitution `$(cat
1666 FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
1668 When the old-style backquote form of substitution is used, backslash
1669 retains its literal meaning except when followed by `$', ``', or `\'.
1670 The first backquote not preceded by a backslash terminates the command
1671 substitution. When using the `$(COMMAND)' form, all characters between
1672 the parentheses make up the command; none are treated specially.
1674 Command substitutions may be nested. To nest when using the
1675 backquoted form, escape the inner backquotes with backslashes.
1677 If the substitution appears within double quotes, word splitting and
1678 filename expansion are not performed on the results.
1681 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1683 3.5.5 Arithmetic Expansion
1684 --------------------------
1686 Arithmetic expansion allows the evaluation of an arithmetic expression
1687 and the substitution of the result. The format for arithmetic
1692 The expression is treated as if it were within double quotes, but a
1693 double quote inside the parentheses is not treated specially. All
1694 tokens in the expression undergo parameter expansion, command
1695 substitution, and quote removal. Arithmetic expansions may be nested.
1697 The evaluation is performed according to the rules listed below
1698 (*note Shell Arithmetic::). If the expression is invalid, Bash prints
1699 a message indicating failure to the standard error and no substitution
1703 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1705 3.5.6 Process Substitution
1706 --------------------------
1708 Process substitution is supported on systems that support named pipes
1709 (FIFOs) or the `/dev/fd' method of naming open files. It takes the
1714 The process LIST is run with its input or output connected to a FIFO
1715 or some file in `/dev/fd'. The name of this file is passed as an
1716 argument to the current command as the result of the expansion. If the
1717 `>(LIST)' form is used, writing to the file will provide input for
1718 LIST. If the `<(LIST)' form is used, the file passed as an argument
1719 should be read to obtain the output of LIST. Note that no space may
1720 appear between the `<' or `>' and the left parenthesis, otherwise the
1721 construct would be interpreted as a redirection.
1723 When available, process substitution is performed simultaneously with
1724 parameter and variable expansion, command substitution, and arithmetic
1728 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1730 3.5.7 Word Splitting
1731 --------------------
1733 The shell scans the results of parameter expansion, command
1734 substitution, and arithmetic expansion that did not occur within double
1735 quotes for word splitting.
1737 The shell treats each character of `$IFS' as a delimiter, and splits
1738 the results of the other expansions into words on these characters. If
1739 `IFS' is unset, or its value is exactly `<space><tab><newline>', the
1740 default, then sequences of ` <space>', `<tab>', and `<newline>' at the
1741 beginning and end of the results of the previous expansions are
1742 ignored, and any sequence of `IFS' characters not at the beginning or
1743 end serves to delimit words. If `IFS' has a value other than the
1744 default, then sequences of the whitespace characters `space' and `tab'
1745 are ignored at the beginning and end of the word, as long as the
1746 whitespace character is in the value of `IFS' (an `IFS' whitespace
1747 character). Any character in `IFS' that is not `IFS' whitespace, along
1748 with any adjacent `IFS' whitespace characters, delimits a field. A
1749 sequence of `IFS' whitespace characters is also treated as a delimiter.
1750 If the value of `IFS' is null, no word splitting occurs.
1752 Explicit null arguments (`""' or `''') are retained. Unquoted
1753 implicit null arguments, resulting from the expansion of parameters
1754 that have no values, are removed. If a parameter with no value is
1755 expanded within double quotes, a null argument results and is retained.
1757 Note that if no expansion occurs, no splitting is performed.
1760 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1762 3.5.8 Filename Expansion
1763 ------------------------
1767 * Pattern Matching:: How the shell matches patterns.
1769 After word splitting, unless the `-f' option has been set (*note The
1770 Set Builtin::), Bash scans each word for the characters `*', `?', and
1771 `['. If one of these characters appears, then the word is regarded as
1772 a PATTERN, and replaced with an alphabetically sorted list of file
1773 names matching the pattern. If no matching file names are found, and
1774 the shell option `nullglob' is disabled, the word is left unchanged.
1775 If the `nullglob' option is set, and no matches are found, the word is
1776 removed. If the `failglob' shell option is set, and no matches are
1777 found, an error message is printed and the command is not executed. If
1778 the shell option `nocaseglob' is enabled, the match is performed
1779 without regard to the case of alphabetic characters.
1781 When a pattern is used for filename expansion, the character `.' at
1782 the start of a filename or immediately following a slash must be
1783 matched explicitly, unless the shell option `dotglob' is set. When
1784 matching a file name, the slash character must always be matched
1785 explicitly. In other cases, the `.' character is not treated specially.
1787 See the description of `shopt' in *note The Shopt Builtin::, for a
1788 description of the `nocaseglob', `nullglob', `failglob', and `dotglob'
1791 The `GLOBIGNORE' shell variable may be used to restrict the set of
1792 filenames matching a pattern. If `GLOBIGNORE' is set, each matching
1793 filename that also matches one of the patterns in `GLOBIGNORE' is
1794 removed from the list of matches. The filenames `.' and `..' are
1795 always ignored when `GLOBIGNORE' is set and not null. However, setting
1796 `GLOBIGNORE' to a non-null value has the effect of enabling the
1797 `dotglob' shell option, so all other filenames beginning with a `.'
1798 will match. To get the old behavior of ignoring filenames beginning
1799 with a `.', make `.*' one of the patterns in `GLOBIGNORE'. The
1800 `dotglob' option is disabled when `GLOBIGNORE' is unset.
1803 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1805 3.5.8.1 Pattern Matching
1806 ........................
1808 Any character that appears in a pattern, other than the special pattern
1809 characters described below, matches itself. The NUL character may not
1810 occur in a pattern. A backslash escapes the following character; the
1811 escaping backslash is discarded when matching. The special pattern
1812 characters must be quoted if they are to be matched literally.
1814 The special pattern characters have the following meanings:
1816 Matches any string, including the null string. When the
1817 `globstar' shell option is enabled, and `*' is used in a filename
1818 expansion context, two adjacent `*'s used as a single pattern will
1819 match all files and zero or more directories and subdirectories.
1820 If followed by a `/', two adjacent `*'s will match only
1821 directories and subdirectories.
1824 Matches any single character.
1827 Matches any one of the enclosed characters. A pair of characters
1828 separated by a hyphen denotes a RANGE EXPRESSION; any character
1829 that sorts between those two characters, inclusive, using the
1830 current locale's collating sequence and character set, is matched.
1831 If the first character following the `[' is a `!' or a `^' then
1832 any character not enclosed is matched. A `-' may be matched by
1833 including it as the first or last character in the set. A `]' may
1834 be matched by including it as the first character in the set. The
1835 sorting order of characters in range expressions is determined by
1836 the current locale and the value of the `LC_COLLATE' shell
1839 For example, in the default C locale, `[a-dx-z]' is equivalent to
1840 `[abcdxyz]'. Many locales sort characters in dictionary order,
1841 and in these locales `[a-dx-z]' is typically not equivalent to
1842 `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for
1843 example. To obtain the traditional interpretation of ranges in
1844 bracket expressions, you can force the use of the C locale by
1845 setting the `LC_COLLATE' or `LC_ALL' environment variable to the
1848 Within `[' and `]', CHARACTER CLASSES can be specified using the
1849 syntax `[:'CLASS`:]', where CLASS is one of the following classes
1850 defined in the POSIX standard:
1851 alnum alpha ascii blank cntrl digit graph lower
1852 print punct space upper word xdigit
1853 A character class matches any character belonging to that class.
1854 The `word' character class matches letters, digits, and the
1857 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1858 the syntax `[='C`=]', which matches all characters with the same
1859 collation weight (as defined by the current locale) as the
1862 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
1863 collating symbol SYMBOL.
1865 If the `extglob' shell option is enabled using the `shopt' builtin,
1866 several extended pattern matching operators are recognized. In the
1867 following description, a PATTERN-LIST is a list of one or more patterns
1868 separated by a `|'. Composite patterns may be formed using one or more
1869 of the following sub-patterns:
1872 Matches zero or one occurrence of the given patterns.
1875 Matches zero or more occurrences of the given patterns.
1878 Matches one or more occurrences of the given patterns.
1881 Matches one of the given patterns.
1884 Matches anything except one of the given patterns.
1887 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1892 After the preceding expansions, all unquoted occurrences of the
1893 characters `\', `'', and `"' that did not result from one of the above
1894 expansions are removed.
1897 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1902 Before a command is executed, its input and output may be REDIRECTED
1903 using a special notation interpreted by the shell. Redirection may
1904 also be used to open and close files for the current shell execution
1905 environment. The following redirection operators may precede or appear
1906 anywhere within a simple command or may follow a command. Redirections
1907 are processed in the order they appear, from left to right.
1909 Each redirection that may be preceded by a file descriptor number
1910 may instead be preceded by a word of the form {VARNAME}. In this case,
1911 for each redirection operator except >&- and <&-, the shell will
1912 allocate a file descriptor greater than 10 and assign it to {VARNAME}.
1913 If >&- or <&- is preceded by {VARNAME}, the value of VARNAME defines
1914 the file descriptor to close.
1916 In the following descriptions, if the file descriptor number is
1917 omitted, and the first character of the redirection operator is `<',
1918 the redirection refers to the standard input (file descriptor 0). If
1919 the first character of the redirection operator is `>', the redirection
1920 refers to the standard output (file descriptor 1).
1922 The word following the redirection operator in the following
1923 descriptions, unless otherwise noted, is subjected to brace expansion,
1924 tilde expansion, parameter expansion, command substitution, arithmetic
1925 expansion, quote removal, filename expansion, and word splitting. If
1926 it expands to more than one word, Bash reports an error.
1928 Note that the order of redirections is significant. For example,
1931 directs both standard output (file descriptor 1) and standard error
1932 (file descriptor 2) to the file DIRLIST, while the command
1934 directs only the standard output to file DIRLIST, because the
1935 standard error was made a copy of the standard output before the
1936 standard output was redirected to DIRLIST.
1938 Bash handles several filenames specially when they are used in
1939 redirections, as described in the following table:
1942 If FD is a valid integer, file descriptor FD is duplicated.
1945 File descriptor 0 is duplicated.
1948 File descriptor 1 is duplicated.
1951 File descriptor 2 is duplicated.
1953 `/dev/tcp/HOST/PORT'
1954 If HOST is a valid hostname or Internet address, and PORT is an
1955 integer port number or service name, Bash attempts to open a TCP
1956 connection to the corresponding socket.
1958 `/dev/udp/HOST/PORT'
1959 If HOST is a valid hostname or Internet address, and PORT is an
1960 integer port number or service name, Bash attempts to open a UDP
1961 connection to the corresponding socket.
1964 A failure to open or create a file causes the redirection to fail.
1966 Redirections using file descriptors greater than 9 should be used
1967 with care, as they may conflict with file descriptors the shell uses
1970 3.6.1 Redirecting Input
1971 -----------------------
1973 Redirection of input causes the file whose name results from the
1974 expansion of WORD to be opened for reading on file descriptor `n', or
1975 the standard input (file descriptor 0) if `n' is not specified.
1977 The general format for redirecting input is:
1980 3.6.2 Redirecting Output
1981 ------------------------
1983 Redirection of output causes the file whose name results from the
1984 expansion of WORD to be opened for writing on file descriptor N, or the
1985 standard output (file descriptor 1) if N is not specified. If the file
1986 does not exist it is created; if it does exist it is truncated to zero
1989 The general format for redirecting output is:
1992 If the redirection operator is `>', and the `noclobber' option to
1993 the `set' builtin has been enabled, the redirection will fail if the
1994 file whose name results from the expansion of WORD exists and is a
1995 regular file. If the redirection operator is `>|', or the redirection
1996 operator is `>' and the `noclobber' option is not enabled, the
1997 redirection is attempted even if the file named by WORD exists.
1999 3.6.3 Appending Redirected Output
2000 ---------------------------------
2002 Redirection of output in this fashion causes the file whose name
2003 results from the expansion of WORD to be opened for appending on file
2004 descriptor N, or the standard output (file descriptor 1) if N is not
2005 specified. If the file does not exist it is created.
2007 The general format for appending output is:
2010 3.6.4 Redirecting Standard Output and Standard Error
2011 ----------------------------------------------------
2013 This construct allows both the standard output (file descriptor 1) and
2014 the standard error output (file descriptor 2) to be redirected to the
2015 file whose name is the expansion of WORD.
2017 There are two formats for redirecting standard output and standard
2022 Of the two forms, the first is preferred. This is semantically
2026 3.6.5 Appending Standard Output and Standard Error
2027 --------------------------------------------------
2029 This construct allows both the standard output (file descriptor 1) and
2030 the standard error output (file descriptor 2) to be appended to the
2031 file whose name is the expansion of WORD.
2033 The format for appending standard output and standard error is:
2035 This is semantically equivalent to
2038 3.6.6 Here Documents
2039 --------------------
2041 This type of redirection instructs the shell to read input from the
2042 current source until a line containing only WORD (with no trailing
2043 blanks) is seen. All of the lines read up to that point are then used
2044 as the standard input for a command.
2046 The format of here-documents is:
2051 No parameter expansion, command substitution, arithmetic expansion,
2052 or filename expansion is performed on WORD. If any characters in WORD
2053 are quoted, the DELIMITER is the result of quote removal on WORD, and
2054 the lines in the here-document are not expanded. If WORD is unquoted,
2055 all lines of the here-document are subjected to parameter expansion,
2056 command substitution, and arithmetic expansion. In the latter case,
2057 the character sequence `\newline' is ignored, and `\' must be used to
2058 quote the characters `\', `$', and ``'.
2060 If the redirection operator is `<<-', then all leading tab
2061 characters are stripped from input lines and the line containing
2062 DELIMITER. This allows here-documents within shell scripts to be
2063 indented in a natural fashion.
2068 A variant of here documents, the format is:
2071 The WORD is expanded and supplied to the command on its standard
2074 3.6.8 Duplicating File Descriptors
2075 ----------------------------------
2077 The redirection operator
2079 is used to duplicate input file descriptors. If WORD expands to one
2080 or more digits, the file descriptor denoted by N is made to be a copy
2081 of that file descriptor. If the digits in WORD do not specify a file
2082 descriptor open for input, a redirection error occurs. If WORD
2083 evaluates to `-', file descriptor N is closed. If N is not specified,
2084 the standard input (file descriptor 0) is used.
2088 is used similarly to duplicate output file descriptors. If N is not
2089 specified, the standard output (file descriptor 1) is used. If the
2090 digits in WORD do not specify a file descriptor open for output, a
2091 redirection error occurs. As a special case, if N is omitted, and WORD
2092 does not expand to one or more digits, the standard output and standard
2093 error are redirected as described previously.
2095 3.6.9 Moving File Descriptors
2096 -----------------------------
2098 The redirection operator
2100 moves the file descriptor DIGIT to file descriptor N, or the
2101 standard input (file descriptor 0) if N is not specified. DIGIT is
2102 closed after being duplicated to N.
2104 Similarly, the redirection operator
2106 moves the file descriptor DIGIT to file descriptor N, or the
2107 standard output (file descriptor 1) if N is not specified.
2109 3.6.10 Opening File Descriptors for Reading and Writing
2110 -------------------------------------------------------
2112 The redirection operator
2114 causes the file whose name is the expansion of WORD to be opened for
2115 both reading and writing on file descriptor N, or on file descriptor 0
2116 if N is not specified. If the file does not exist, it is created.
2119 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2121 3.7 Executing Commands
2122 ======================
2126 * Simple Command Expansion:: How Bash expands simple commands before
2128 * Command Search and Execution:: How Bash finds commands and runs them.
2129 * Command Execution Environment:: The environment in which Bash
2130 executes commands that are not
2132 * Environment:: The environment given to a command.
2133 * Exit Status:: The status returned by commands and how Bash
2135 * Signals:: What happens when Bash or a command it runs
2139 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2141 3.7.1 Simple Command Expansion
2142 ------------------------------
2144 When a simple command is executed, the shell performs the following
2145 expansions, assignments, and redirections, from left to right.
2147 1. The words that the parser has marked as variable assignments (those
2148 preceding the command name) and redirections are saved for later
2151 2. The words that are not variable assignments or redirections are
2152 expanded (*note Shell Expansions::). If any words remain after
2153 expansion, the first word is taken to be the name of the command
2154 and the remaining words are the arguments.
2156 3. Redirections are performed as described above (*note
2159 4. The text after the `=' in each variable assignment undergoes tilde
2160 expansion, parameter expansion, command substitution, arithmetic
2161 expansion, and quote removal before being assigned to the variable.
2163 If no command name results, the variable assignments affect the
2164 current shell environment. Otherwise, the variables are added to the
2165 environment of the executed command and do not affect the current shell
2166 environment. If any of the assignments attempts to assign a value to a
2167 readonly variable, an error occurs, and the command exits with a
2170 If no command name results, redirections are performed, but do not
2171 affect the current shell environment. A redirection error causes the
2172 command to exit with a non-zero status.
2174 If there is a command name left after expansion, execution proceeds
2175 as described below. Otherwise, the command exits. If one of the
2176 expansions contained a command substitution, the exit status of the
2177 command is the exit status of the last command substitution performed.
2178 If there were no command substitutions, the command exits with a status
2182 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2184 3.7.2 Command Search and Execution
2185 ----------------------------------
2187 After a command has been split into words, if it results in a simple
2188 command and an optional list of arguments, the following actions are
2191 1. If the command name contains no slashes, the shell attempts to
2192 locate it. If there exists a shell function by that name, that
2193 function is invoked as described in *note Shell Functions::.
2195 2. If the name does not match a function, the shell searches for it
2196 in the list of shell builtins. If a match is found, that builtin
2199 3. If the name is neither a shell function nor a builtin, and
2200 contains no slashes, Bash searches each element of `$PATH' for a
2201 directory containing an executable file by that name. Bash uses a
2202 hash table to remember the full pathnames of executable files to
2203 avoid multiple `PATH' searches (see the description of `hash' in
2204 *note Bourne Shell Builtins::). A full search of the directories
2205 in `$PATH' is performed only if the command is not found in the
2206 hash table. If the search is unsuccessful, the shell searches for
2207 a defined shell function named `command_not_found_handle'. If
2208 that function exists, it is invoked with the original command and
2209 the original command's arguments as its arguments, and the
2210 function's exit status becomes the exit status of the shell. If
2211 that function is not defined, the shell prints an error message
2212 and returns an exit status of 127.
2214 4. If the search is successful, or if the command name contains one
2215 or more slashes, the shell executes the named program in a
2216 separate execution environment. Argument 0 is set to the name
2217 given, and the remaining arguments to the command are set to the
2218 arguments supplied, if any.
2220 5. If this execution fails because the file is not in executable
2221 format, and the file is not a directory, it is assumed to be a
2222 SHELL SCRIPT and the shell executes it as described in *note Shell
2225 6. If the command was not begun asynchronously, the shell waits for
2226 the command to complete and collects its exit status.
2230 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2232 3.7.3 Command Execution Environment
2233 -----------------------------------
2235 The shell has an EXECUTION ENVIRONMENT, which consists of the following:
2237 * open files inherited by the shell at invocation, as modified by
2238 redirections supplied to the `exec' builtin
2240 * the current working directory as set by `cd', `pushd', or `popd',
2241 or inherited by the shell at invocation
2243 * the file creation mode mask as set by `umask' or inherited from
2246 * current traps set by `trap'
2248 * shell parameters that are set by variable assignment or with `set'
2249 or inherited from the shell's parent in the environment
2251 * shell functions defined during execution or inherited from the
2252 shell's parent in the environment
2254 * options enabled at invocation (either by default or with
2255 command-line arguments) or by `set'
2257 * options enabled by `shopt' (*note The Shopt Builtin::)
2259 * shell aliases defined with `alias' (*note Aliases::)
2261 * various process IDs, including those of background jobs (*note
2262 Lists::), the value of `$$', and the value of `$PPID'
2265 When a simple command other than a builtin or shell function is to
2266 be executed, it is invoked in a separate execution environment that
2267 consists of the following. Unless otherwise noted, the values are
2268 inherited from the shell.
2270 * the shell's open files, plus any modifications and additions
2271 specified by redirections to the command
2273 * the current working directory
2275 * the file creation mode mask
2277 * shell variables and functions marked for export, along with
2278 variables exported for the command, passed in the environment
2279 (*note Environment::)
2281 * traps caught by the shell are reset to the values inherited from
2282 the shell's parent, and traps ignored by the shell are ignored
2285 A command invoked in this separate environment cannot affect the
2286 shell's execution environment.
2288 Command substitution, commands grouped with parentheses, and
2289 asynchronous commands are invoked in a subshell environment that is a
2290 duplicate of the shell environment, except that traps caught by the
2291 shell are reset to the values that the shell inherited from its parent
2292 at invocation. Builtin commands that are invoked as part of a pipeline
2293 are also executed in a subshell environment. Changes made to the
2294 subshell environment cannot affect the shell's execution environment.
2296 Subshells spawned to execute command substitutions inherit the value
2297 of the `-e' option from the parent shell. When not in POSIX mode, Bash
2298 clears the `-e' option in such subshells.
2300 If a command is followed by a `&' and job control is not active, the
2301 default standard input for the command is the empty file `/dev/null'.
2302 Otherwise, the invoked command inherits the file descriptors of the
2303 calling shell as modified by redirections.
2306 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2311 When a program is invoked it is given an array of strings called the
2312 ENVIRONMENT. This is a list of name-value pairs, of the form
2315 Bash provides several ways to manipulate the environment. On
2316 invocation, the shell scans its own environment and creates a parameter
2317 for each name found, automatically marking it for EXPORT to child
2318 processes. Executed commands inherit the environment. The `export'
2319 and `declare -x' commands allow parameters and functions to be added to
2320 and deleted from the environment. If the value of a parameter in the
2321 environment is modified, the new value becomes part of the environment,
2322 replacing the old. The environment inherited by any executed command
2323 consists of the shell's initial environment, whose values may be
2324 modified in the shell, less any pairs removed by the `unset' and
2325 `export -n' commands, plus any additions via the `export' and `declare
2328 The environment for any simple command or function may be augmented
2329 temporarily by prefixing it with parameter assignments, as described in
2330 *note Shell Parameters::. These assignment statements affect only the
2331 environment seen by that command.
2333 If the `-k' option is set (*note The Set Builtin::), then all
2334 parameter assignments are placed in the environment for a command, not
2335 just those that precede the command name.
2337 When Bash invokes an external command, the variable `$_' is set to
2338 the full path name of the command and passed to that command in its
2342 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2347 The exit status of an executed command is the value returned by the
2348 WAITPID system call or equivalent function. Exit statuses fall between
2349 0 and 255, though, as explained below, the shell may use values above
2350 125 specially. Exit statuses from shell builtins and compound commands
2351 are also limited to this range. Under certain circumstances, the shell
2352 will use special values to indicate specific failure modes.
2354 For the shell's purposes, a command which exits with a zero exit
2355 status has succeeded. A non-zero exit status indicates failure. This
2356 seemingly counter-intuitive scheme is used so there is one well-defined
2357 way to indicate success and a variety of ways to indicate various
2358 failure modes. When a command terminates on a fatal signal whose
2359 number is N, Bash uses the value 128+N as the exit status.
2361 If a command is not found, the child process created to execute it
2362 returns a status of 127. If a command is found but is not executable,
2363 the return status is 126.
2365 If a command fails because of an error during expansion or
2366 redirection, the exit status is greater than zero.
2368 The exit status is used by the Bash conditional commands (*note
2369 Conditional Constructs::) and some of the list constructs (*note
2372 All of the Bash builtins return an exit status of zero if they
2373 succeed and a non-zero status on failure, so they may be used by the
2374 conditional and list constructs. All builtins return an exit status of
2375 2 to indicate incorrect usage.
2378 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2383 When Bash is interactive, in the absence of any traps, it ignores
2384 `SIGTERM' (so that `kill 0' does not kill an interactive shell), and
2385 `SIGINT' is caught and handled (so that the `wait' builtin is
2386 interruptible). When Bash receives a `SIGINT', it breaks out of any
2387 executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
2388 is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU',
2391 Non-builtin commands started by Bash have signal handlers set to the
2392 values inherited by the shell from its parent. When job control is not
2393 in effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' in
2394 addition to these inherited handlers. Commands run as a result of
2395 command substitution ignore the keyboard-generated job control signals
2396 `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
2398 The shell exits by default upon receipt of a `SIGHUP'. Before
2399 exiting, an interactive shell resends the `SIGHUP' to all jobs, running
2400 or stopped. Stopped jobs are sent `SIGCONT' to ensure that they receive
2401 the `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to
2402 a particular job, it should be removed from the jobs table with the
2403 `disown' builtin (*note Job Control Builtins::) or marked to not
2404 receive `SIGHUP' using `disown -h'.
2406 If the `huponexit' shell option has been set with `shopt' (*note
2407 The Shopt Builtin::), Bash sends a `SIGHUP' to all jobs when an
2408 interactive login shell exits.
2410 If Bash is waiting for a command to complete and receives a signal
2411 for which a trap has been set, the trap will not be executed until the
2412 command completes. When Bash is waiting for an asynchronous command
2413 via the `wait' builtin, the reception of a signal for which a trap has
2414 been set will cause the `wait' builtin to return immediately with an
2415 exit status greater than 128, immediately after which the trap is
2419 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2424 A shell script is a text file containing shell commands. When such a
2425 file is used as the first non-option argument when invoking Bash, and
2426 neither the `-c' nor `-s' option is supplied (*note Invoking Bash::),
2427 Bash reads and executes commands from the file, then exits. This mode
2428 of operation creates a non-interactive shell. The shell first searches
2429 for the file in the current directory, and looks in the directories in
2430 `$PATH' if not found there.
2432 When Bash runs a shell script, it sets the special parameter `0' to
2433 the name of the file, rather than the name of the shell, and the
2434 positional parameters are set to the remaining arguments, if any are
2435 given. If no additional arguments are supplied, the positional
2436 parameters are unset.
2438 A shell script may be made executable by using the `chmod' command
2439 to turn on the execute bit. When Bash finds such a file while
2440 searching the `$PATH' for a command, it spawns a subshell to execute
2441 it. In other words, executing
2443 is equivalent to executing
2444 bash filename ARGUMENTS
2446 if `filename' is an executable shell script. This subshell
2447 reinitializes itself, so that the effect is as if a new shell had been
2448 invoked to interpret the script, with the exception that the locations
2449 of commands remembered by the parent (see the description of `hash' in
2450 *note Bourne Shell Builtins::) are retained by the child.
2452 Most versions of Unix make this a part of the operating system's
2453 command execution mechanism. If the first line of a script begins with
2454 the two characters `#!', the remainder of the line specifies an
2455 interpreter for the program. Thus, you can specify Bash, `awk', Perl,
2456 or some other interpreter and write the rest of the script file in that
2459 The arguments to the interpreter consist of a single optional
2460 argument following the interpreter name on the first line of the script
2461 file, followed by the name of the script file, followed by the rest of
2462 the arguments. Bash will perform this action on operating systems that
2463 do not handle it themselves. Note that some older versions of Unix
2464 limit the interpreter name and argument to a maximum of 32 characters.
2466 Bash scripts often begin with `#! /bin/bash' (assuming that Bash has
2467 been installed in `/bin'), since this ensures that Bash will be used to
2468 interpret the script, even if it is executed under another shell.
2471 File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
2473 4 Shell Builtin Commands
2474 ************************
2478 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2480 * Bash Builtins:: Table of builtins specific to Bash.
2481 * Modifying Shell Behavior:: Builtins to modify shell attributes and
2483 * Special Builtins:: Builtin commands classified specially by
2486 Builtin commands are contained within the shell itself. When the
2487 name of a builtin command is used as the first word of a simple command
2488 (*note Simple Commands::), the shell executes the command directly,
2489 without invoking another program. Builtin commands are necessary to
2490 implement functionality impossible or inconvenient to obtain with
2493 This section briefly describes the builtins which Bash inherits from
2494 the Bourne Shell, as well as the builtin commands which are unique to
2495 or have been extended in Bash.
2497 Several builtin commands are described in other chapters: builtin
2498 commands which provide the Bash interface to the job control facilities
2499 (*note Job Control Builtins::), the directory stack (*note Directory
2500 Stack Builtins::), the command history (*note Bash History Builtins::),
2501 and the programmable completion facilities (*note Programmable
2502 Completion Builtins::).
2504 Many of the builtins have been extended by POSIX or Bash.
2506 Unless otherwise noted, each builtin command documented as accepting
2507 options preceded by `-' accepts `--' to signify the end of the options.
2508 The `:', `true', `false', and `test' builtins do not accept options and
2509 do not treat `--' specially. The `exit', `logout', `break',
2510 `continue', `let', and `shift' builtins accept and process arguments
2511 beginning with `-' without requiring `--'. Other builtins that accept
2512 arguments but are not specified as accepting options interpret
2513 arguments beginning with `-' as invalid options and require `--' to
2514 prevent this interpretation.
2517 File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
2519 4.1 Bourne Shell Builtins
2520 =========================
2522 The following shell builtin commands are inherited from the Bourne
2523 Shell. These commands are implemented as specified by the POSIX
2528 Do nothing beyond expanding ARGUMENTS and performing redirections.
2529 The return status is zero.
2532 . FILENAME [ARGUMENTS]
2533 Read and execute commands from the FILENAME argument in the
2534 current shell context. If FILENAME does not contain a slash, the
2535 `PATH' variable is used to find FILENAME. When Bash is not in
2536 POSIX mode, the current directory is searched if FILENAME is not
2537 found in `$PATH'. If any ARGUMENTS are supplied, they become the
2538 positional parameters when FILENAME is executed. Otherwise the
2539 positional parameters are unchanged. The return status is the
2540 exit status of the last command executed, or zero if no commands
2541 are executed. If FILENAME is not found, or cannot be read, the
2542 return status is non-zero. This builtin is equivalent to `source'.
2546 Exit from a `for', `while', `until', or `select' loop. If N is
2547 supplied, the Nth enclosing loop is exited. N must be greater
2548 than or equal to 1. The return status is zero unless N is not
2549 greater than or equal to 1.
2552 cd [-L|[-P [-e]]] [DIRECTORY]
2553 Change the current working directory to DIRECTORY. If DIRECTORY
2554 is not given, the value of the `HOME' shell variable is used. If
2555 the shell variable `CDPATH' exists, it is used as a search path.
2556 If DIRECTORY begins with a slash, `CDPATH' is not used.
2558 The `-P' option means to not follow symbolic links; symbolic links
2559 are followed by default or with the `-L' option. If the `-e'
2560 option is supplied with `-P' and the current working directory
2561 cannot be successfully determined after a successful directory
2562 change, `cd' will return an unsuccessful status. If DIRECTORY is
2563 `-', it is equivalent to `$OLDPWD'.
2565 If a non-empty directory name from `CDPATH' is used, or if `-' is
2566 the first argument, and the directory change is successful, the
2567 absolute pathname of the new working directory is written to the
2570 The return status is zero if the directory is successfully changed,
2575 Resume the next iteration of an enclosing `for', `while', `until',
2576 or `select' loop. If N is supplied, the execution of the Nth
2577 enclosing loop is resumed. N must be greater than or equal to 1.
2578 The return status is zero unless N is not greater than or equal to
2583 The arguments are concatenated together into a single command,
2584 which is then read and executed, and its exit status returned as
2585 the exit status of `eval'. If there are no arguments or only
2586 empty arguments, the return status is zero.
2589 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2590 If COMMAND is supplied, it replaces the shell without creating a
2591 new process. If the `-l' option is supplied, the shell places a
2592 dash at the beginning of the zeroth argument passed to COMMAND.
2593 This is what the `login' program does. The `-c' option causes
2594 COMMAND to be executed with an empty environment. If `-a' is
2595 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2596 If no COMMAND is specified, redirections may be used to affect the
2597 current shell environment. If there are no redirection errors, the
2598 return status is zero; otherwise the return status is non-zero.
2602 Exit the shell, returning a status of N to the shell's parent. If
2603 N is omitted, the exit status is that of the last command executed.
2604 Any trap on `EXIT' is executed before the shell terminates.
2607 export [-fn] [-p] [NAME[=VALUE]]
2608 Mark each NAME to be passed to child processes in the environment.
2609 If the `-f' option is supplied, the NAMEs refer to shell
2610 functions; otherwise the names refer to shell variables. The `-n'
2611 option means to no longer mark each NAME for export. If no NAMES
2612 are supplied, or if the `-p' option is given, a list of exported
2613 names is displayed. The `-p' option displays output in a form
2614 that may be reused as input. If a variable name is followed by
2615 =VALUE, the value of the variable is set to VALUE.
2617 The return status is zero unless an invalid option is supplied,
2618 one of the names is not a valid shell variable name, or `-f' is
2619 supplied with a name that is not a shell function.
2622 getopts OPTSTRING NAME [ARGS]
2623 `getopts' is used by shell scripts to parse positional parameters.
2624 OPTSTRING contains the option characters to be recognized; if a
2625 character is followed by a colon, the option is expected to have an
2626 argument, which should be separated from it by white space. The
2627 colon (`:') and question mark (`?') may not be used as option
2628 characters. Each time it is invoked, `getopts' places the next
2629 option in the shell variable NAME, initializing NAME if it does
2630 not exist, and the index of the next argument to be processed into
2631 the variable `OPTIND'. `OPTIND' is initialized to 1 each time the
2632 shell or a shell script is invoked. When an option requires an
2633 argument, `getopts' places that argument into the variable
2634 `OPTARG'. The shell does not reset `OPTIND' automatically; it
2635 must be manually reset between multiple calls to `getopts' within
2636 the same shell invocation if a new set of parameters is to be used.
2638 When the end of options is encountered, `getopts' exits with a
2639 return value greater than zero. `OPTIND' is set to the index of
2640 the first non-option argument, and NAME is set to `?'.
2642 `getopts' normally parses the positional parameters, but if more
2643 arguments are given in ARGS, `getopts' parses those instead.
2645 `getopts' can report errors in two ways. If the first character of
2646 OPTSTRING is a colon, SILENT error reporting is used. In normal
2647 operation diagnostic messages are printed when invalid options or
2648 missing option arguments are encountered. If the variable `OPTERR'
2649 is set to 0, no error messages will be displayed, even if the first
2650 character of `optstring' is not a colon.
2652 If an invalid option is seen, `getopts' places `?' into NAME and,
2653 if not silent, prints an error message and unsets `OPTARG'. If
2654 `getopts' is silent, the option character found is placed in
2655 `OPTARG' and no diagnostic message is printed.
2657 If a required argument is not found, and `getopts' is not silent,
2658 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2659 diagnostic message is printed. If `getopts' is silent, then a
2660 colon (`:') is placed in NAME and `OPTARG' is set to the option
2664 hash [-r] [-p FILENAME] [-dt] [NAME]
2665 Each time `hash' is invoked, it remembers the full pathnames of the
2666 commands specified as NAME arguments, so they need not be searched
2667 for on subsequent invocations. The commands are found by
2668 searching through the directories listed in `$PATH'. Any
2669 previously-remembered pathname is discarded. The `-p' option
2670 inhibits the path search, and FILENAME is used as the location of
2671 NAME. The `-r' option causes the shell to forget all remembered
2672 locations. The `-d' option causes the shell to forget the
2673 remembered location of each NAME. If the `-t' option is supplied,
2674 the full pathname to which each NAME corresponds is printed. If
2675 multiple NAME arguments are supplied with `-t' the NAME is printed
2676 before the hashed full pathname. The `-l' option causes output to
2677 be displayed in a format that may be reused as input. If no
2678 arguments are given, or if only `-l' is supplied, information
2679 about remembered commands is printed. The return status is zero
2680 unless a NAME is not found or an invalid option is supplied.
2684 Print the absolute pathname of the current working directory. If
2685 the `-P' option is supplied, the pathname printed will not contain
2686 symbolic links. If the `-L' option is supplied, the pathname
2687 printed may contain symbolic links. The return status is zero
2688 unless an error is encountered while determining the name of the
2689 current directory or an invalid option is supplied.
2692 readonly [-aApf] [NAME[=VALUE]] ...
2693 Mark each NAME as readonly. The values of these names may not be
2694 changed by subsequent assignment. If the `-f' option is supplied,
2695 each NAME refers to a shell function. The `-a' option means each
2696 NAME refers to an indexed array variable; the `-A' option means
2697 each NAME refers to an associative array variable. If no NAME
2698 arguments are given, or if the `-p' option is supplied, a list of
2699 all readonly names is printed. The `-p' option causes output to
2700 be displayed in a format that may be reused as input. If a
2701 variable name is followed by =VALUE, the value of the variable is
2702 set to VALUE. The return status is zero unless an invalid option
2703 is supplied, one of the NAME arguments is not a valid shell
2704 variable or function name, or the `-f' option is supplied with a
2705 name that is not a shell function.
2709 Cause a shell function to exit with the return value N. If N is
2710 not supplied, the return value is the exit status of the last
2711 command executed in the function. This may also be used to
2712 terminate execution of a script being executed with the `.' (or
2713 `source') builtin, returning either N or the exit status of the
2714 last command executed within the script as the exit status of the
2715 script. Any command associated with the `RETURN' trap is executed
2716 before execution resumes after the function or script. The return
2717 status is non-zero if `return' is used outside a function and not
2718 during the execution of a script by `.' or `source'.
2722 Shift the positional parameters to the left by N. The positional
2723 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N.
2724 Parameters represented by the numbers `$#' to `$#'-N+1 are unset.
2725 N must be a non-negative number less than or equal to `$#'. If N
2726 is zero or greater than `$#', the positional parameters are not
2727 changed. If N is not supplied, it is assumed to be 1. The return
2728 status is zero unless N is greater than `$#' or less than zero,
2733 Evaluate a conditional expression EXPR. Each operator and operand
2734 must be a separate argument. Expressions are composed of the
2735 primaries described below in *note Bash Conditional Expressions::.
2736 `test' does not accept any options, nor does it accept and ignore
2737 an argument of `--' as signifying the end of options.
2739 When the `[' form is used, the last argument to the command must
2742 Expressions may be combined using the following operators, listed
2743 in decreasing order of precedence. The evaluation depends on the
2744 number of arguments; see below. Operator precedence is used when
2745 there are five or more arguments.
2748 True if EXPR is false.
2751 Returns the value of EXPR. This may be used to override the
2752 normal precedence of operators.
2755 True if both EXPR1 and EXPR2 are true.
2758 True if either EXPR1 or EXPR2 is true.
2760 The `test' and `[' builtins evaluate conditional expressions using
2761 a set of rules based on the number of arguments.
2764 The expression is false.
2767 The expression is true if and only if the argument is not
2771 If the first argument is `!', the expression is true if and
2772 only if the second argument is null. If the first argument
2773 is one of the unary conditional operators (*note Bash
2774 Conditional Expressions::), the expression is true if the
2775 unary test is true. If the first argument is not a valid
2776 unary operator, the expression is false.
2779 The following conditions are applied in the order listed. If
2780 the second argument is one of the binary conditional
2781 operators (*note Bash Conditional Expressions::), the result
2782 of the expression is the result of the binary test using the
2783 first and third arguments as operands. The `-a' and `-o'
2784 operators are considered binary operators when there are
2785 three arguments. If the first argument is `!', the value is
2786 the negation of the two-argument test using the second and
2787 third arguments. If the first argument is exactly `(' and
2788 the third argument is exactly `)', the result is the
2789 one-argument test of the second argument. Otherwise, the
2790 expression is false.
2793 If the first argument is `!', the result is the negation of
2794 the three-argument expression composed of the remaining
2795 arguments. Otherwise, the expression is parsed and evaluated
2796 according to precedence using the rules listed above.
2799 The expression is parsed and evaluated according to precedence
2800 using the rules listed above.
2802 When used with `test' or `[', the `<' and `>' operators sort
2803 lexicographically using ASCII ordering.
2807 Print out the user and system times used by the shell and its
2808 children. The return status is zero.
2811 trap [-lp] [ARG] [SIGSPEC ...]
2812 The commands in ARG are to be read and executed when the shell
2813 receives signal SIGSPEC. If ARG is absent (and there is a single
2814 SIGSPEC) or equal to `-', each specified signal's disposition is
2815 reset to the value it had when the shell was started. If ARG is
2816 the null string, then the signal specified by each SIGSPEC is
2817 ignored by the shell and commands it invokes. If ARG is not
2818 present and `-p' has been supplied, the shell displays the trap
2819 commands associated with each SIGSPEC. If no arguments are
2820 supplied, or only `-p' is given, `trap' prints the list of commands
2821 associated with each signal number in a form that may be reused as
2822 shell input. The `-l' option causes the shell to print a list of
2823 signal names and their corresponding numbers. Each SIGSPEC is
2824 either a signal name or a signal number. Signal names are case
2825 insensitive and the `SIG' prefix is optional.
2827 If a SIGSPEC is `0' or `EXIT', ARG is executed when the shell
2828 exits. If a SIGSPEC is `DEBUG', the command ARG is executed
2829 before every simple command, `for' command, `case' command,
2830 `select' command, every arithmetic `for' command, and before the
2831 first command executes in a shell function. Refer to the
2832 description of the `extdebug' option to the `shopt' builtin (*note
2833 The Shopt Builtin::) for details of its effect on the `DEBUG' trap.
2834 If a SIGSPEC is `RETURN', the command ARG is executed each time a
2835 shell function or a script executed with the `.' or `source'
2836 builtins finishes executing.
2838 If a SIGSPEC is `ERR', the command ARG is executed whenever a
2839 simple command has a non-zero exit status, subject to the
2840 following conditions. The `ERR' trap is not executed if the
2841 failed command is part of the command list immediately following
2842 an `until' or `while' keyword, part of the test following the `if'
2843 or `elif' reserved words, part of a command executed in a `&&' or
2844 `||' list, or if the command's return status is being inverted
2845 using `!'. These are the same conditions obeyed by the `errexit'
2848 Signals ignored upon entry to the shell cannot be trapped or reset.
2849 Trapped signals that are not being ignored are reset to their
2850 original values in a subshell or subshell environment when one is
2853 The return status is zero unless a SIGSPEC does not specify a
2857 umask [-p] [-S] [MODE]
2858 Set the shell process's file creation mask to MODE. If MODE
2859 begins with a digit, it is interpreted as an octal number; if not,
2860 it is interpreted as a symbolic mode mask similar to that accepted
2861 by the `chmod' command. If MODE is omitted, the current value of
2862 the mask is printed. If the `-S' option is supplied without a
2863 MODE argument, the mask is printed in a symbolic format. If the
2864 `-p' option is supplied, and MODE is omitted, the output is in a
2865 form that may be reused as input. The return status is zero if
2866 the mode is successfully changed or if no MODE argument is
2867 supplied, and non-zero otherwise.
2869 Note that when the mode is interpreted as an octal number, each
2870 number of the umask is subtracted from `7'. Thus, a umask of `022'
2871 results in permissions of `755'.
2875 Each variable or function NAME is removed. If no options are
2876 supplied, or the `-v' option is given, each NAME refers to a shell
2877 variable. If the `-f' option is given, the NAMEs refer to shell
2878 functions, and the function definition is removed. Readonly
2879 variables and functions may not be unset. The return status is
2880 zero unless a NAME is readonly.
2883 File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
2885 4.2 Bash Builtin Commands
2886 =========================
2888 This section describes builtin commands which are unique to or have
2889 been extended in Bash. Some of these commands are specified in the
2893 alias [`-p'] [NAME[=VALUE] ...]
2895 Without arguments or with the `-p' option, `alias' prints the list
2896 of aliases on the standard output in a form that allows them to be
2897 reused as input. If arguments are supplied, an alias is defined
2898 for each NAME whose VALUE is given. If no VALUE is given, the name
2899 and value of the alias is printed. Aliases are described in *note
2903 bind [-m KEYMAP] [-lpsvPSV]
2904 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2905 bind [-m KEYMAP] -f FILENAME
2906 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
2907 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
2908 bind READLINE-COMMAND
2910 Display current Readline (*note Command Line Editing::) key and
2911 function bindings, bind a key sequence to a Readline function or
2912 macro, or set a Readline variable. Each non-option argument is a
2913 command as it would appear in a Readline initialization file
2914 (*note Readline Init File::), but each binding or command must be
2915 passed as a separate argument; e.g.,
2916 `"\C-x\C-r":re-read-init-file'.
2918 Options, if supplied, have the following meanings:
2921 Use KEYMAP as the keymap to be affected by the subsequent
2922 bindings. Acceptable KEYMAP names are `emacs',
2923 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
2924 `vi-command', and `vi-insert'. `vi' is equivalent to
2925 `vi-command'; `emacs' is equivalent to `emacs-standard'.
2928 List the names of all Readline functions.
2931 Display Readline function names and bindings in such a way
2932 that they can be used as input or in a Readline
2933 initialization file.
2936 List current Readline function names and bindings.
2939 Display Readline variable names and values in such a way that
2940 they can be used as input or in a Readline initialization
2944 List current Readline variable names and values.
2947 Display Readline key sequences bound to macros and the
2948 strings they output in such a way that they can be used as
2949 input or in a Readline initialization file.
2952 Display Readline key sequences bound to macros and the
2953 strings they output.
2956 Read key bindings from FILENAME.
2959 Query about which keys invoke the named FUNCTION.
2962 Unbind all keys bound to the named FUNCTION.
2965 Remove any current binding for KEYSEQ.
2967 `-x KEYSEQ:SHELL-COMMAND'
2968 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
2969 When SHELL-COMMAND is executed, the shell sets the
2970 `READLINE_LINE' variable to the contents of the Readline line
2971 buffer and the `READLINE_POINT' variable to the current
2972 location of the insertion point. If the executed command
2973 changes the value of `READLINE_LINE' or `READLINE_POINT',
2974 those new values will be reflected in the editing state.
2976 The return status is zero unless an invalid option is supplied or
2980 builtin [SHELL-BUILTIN [ARGS]]
2981 Run a shell builtin, passing it ARGS, and return its exit status.
2982 This is useful when defining a shell function with the same name
2983 as a shell builtin, retaining the functionality of the builtin
2984 within the function. The return status is non-zero if
2985 SHELL-BUILTIN is not a shell builtin command.
2989 Returns the context of any active subroutine call (a shell
2990 function or a script executed with the `.' or `source' builtins).
2992 Without EXPR, `caller' displays the line number and source
2993 filename of the current subroutine call. If a non-negative
2994 integer is supplied as EXPR, `caller' displays the line number,
2995 subroutine name, and source file corresponding to that position in
2996 the current execution call stack. This extra information may be
2997 used, for example, to print a stack trace. The current frame is
3000 The return value is 0 unless the shell is not executing a
3001 subroutine call or EXPR does not correspond to a valid position in
3005 command [-pVv] COMMAND [ARGUMENTS ...]
3006 Runs COMMAND with ARGUMENTS ignoring any shell function named
3007 COMMAND. Only shell builtin commands or commands found by
3008 searching the `PATH' are executed. If there is a shell function
3009 named `ls', running `command ls' within the function will execute
3010 the external command `ls' instead of calling the function
3011 recursively. The `-p' option means to use a default value for
3012 `PATH' that is guaranteed to find all of the standard utilities.
3013 The return status in this case is 127 if COMMAND cannot be found
3014 or an error occurred, and the exit status of COMMAND otherwise.
3016 If either the `-V' or `-v' option is supplied, a description of
3017 COMMAND is printed. The `-v' option causes a single word
3018 indicating the command or file name used to invoke COMMAND to be
3019 displayed; the `-V' option produces a more verbose description.
3020 In this case, the return status is zero if COMMAND is found, and
3024 declare [-aAfFilrtux] [-p] [NAME[=VALUE] ...]
3026 Declare variables and give them attributes. If no NAMEs are
3027 given, then display the values of variables instead.
3029 The `-p' option will display the attributes and values of each
3030 NAME. When `-p' is used with NAME arguments, additional options
3033 When `-p' is supplied without NAME arguments, `declare' will
3034 display the attributes and values of all variables having the
3035 attributes specified by the additional options. If no other
3036 options are supplied with `-p', `declare' will display the
3037 attributes and values of all shell variables. The `-f' option
3038 will restrict the display to shell functions.
3040 The `-F' option inhibits the display of function definitions; only
3041 the function name and attributes are printed. If the `extdebug'
3042 shell option is enabled using `shopt' (*note The Shopt Builtin::),
3043 the source file name and line number where the function is defined
3044 are displayed as well. `-F' implies `-f'.
3046 The `-g' option forces variables to be created or modified at the
3047 global scope, even when \fBdeclare\fP is executed in a shell
3048 function. It is ignored in all other cases.
3050 The following options can be used to restrict output to variables
3051 with the specified attributes or to give variables attributes:
3054 Each NAME is an indexed array variable (*note Arrays::).
3057 Each NAME is an associative array variable (*note Arrays::).
3060 Use function names only.
3063 The variable is to be treated as an integer; arithmetic
3064 evaluation (*note Shell Arithmetic::) is performed when the
3065 variable is assigned a value.
3068 When the variable is assigned a value, all upper-case
3069 characters are converted to lower-case. The upper-case
3070 attribute is disabled.
3073 Make NAMEs readonly. These names cannot then be assigned
3074 values by subsequent assignment statements or unset.
3077 Give each NAME the `trace' attribute. Traced functions
3078 inherit the `DEBUG' and `RETURN' traps from the calling shell.
3079 The trace attribute has no special meaning for variables.
3082 When the variable is assigned a value, all lower-case
3083 characters are converted to upper-case. The lower-case
3084 attribute is disabled.
3087 Mark each NAME for export to subsequent commands via the
3090 Using `+' instead of `-' turns off the attribute instead, with the
3091 exceptions that `+a' may not be used to destroy an array variable
3092 and `+r' will not remove the readonly attribute. When used in a
3093 function, `declare' makes each NAME local, as with the `local'
3094 command, unless the `-g' option is used. If a variable name is
3095 followed by =VALUE, the value of the variable is set to VALUE.
3097 The return status is zero unless an invalid option is encountered,
3098 an attempt is made to define a function using `-f foo=bar', an
3099 attempt is made to assign a value to a readonly variable, an
3100 attempt is made to assign a value to an array variable without
3101 using the compound assignment syntax (*note Arrays::), one of the
3102 NAMES is not a valid shell variable name, an attempt is made to
3103 turn off readonly status for a readonly variable, an attempt is
3104 made to turn off array status for an array variable, or an attempt
3105 is made to display a non-existent function with `-f'.
3108 echo [-neE] [ARG ...]
3109 Output the ARGs, separated by spaces, terminated with a newline.
3110 The return status is always 0. If `-n' is specified, the trailing
3111 newline is suppressed. If the `-e' option is given,
3112 interpretation of the following backslash-escaped characters is
3113 enabled. The `-E' option disables the interpretation of these
3114 escape characters, even on systems where they are interpreted by
3115 default. The `xpg_echo' shell option may be used to dynamically
3116 determine whether or not `echo' expands these escape characters by
3117 default. `echo' does not interpret `--' to mean the end of
3120 `echo' interprets the following escape sequences:
3128 suppress further output
3153 the eight-bit character whose value is the octal value NNN
3154 (zero to three octal digits)
3157 the eight-bit character whose value is the hexadecimal value
3158 HH (one or two hex digits)
3161 the Unicode (ISO/IEC 10646) character whose value is the
3162 hexadecimal value HHHH (one to four hex digits)
3165 the Unicode (ISO/IEC 10646) character whose value is the
3166 hexadecimal value HHHHHHHH (one to eight hex digits)
3169 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3170 Enable and disable builtin shell commands. Disabling a builtin
3171 allows a disk command which has the same name as a shell builtin
3172 to be executed without specifying a full pathname, even though the
3173 shell normally searches for builtins before disk commands. If
3174 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3175 enabled. For example, to use the `test' binary found via `$PATH'
3176 instead of the shell builtin version, type `enable -n test'.
3178 If the `-p' option is supplied, or no NAME arguments appear, a
3179 list of shell builtins is printed. With no other arguments, the
3180 list consists of all enabled shell builtins. The `-a' option
3181 means to list each builtin with an indication of whether or not it
3184 The `-f' option means to load the new builtin command NAME from
3185 shared object FILENAME, on systems that support dynamic loading.
3186 The `-d' option will delete a builtin loaded with `-f'.
3188 If there are no options, a list of the shell builtins is displayed.
3189 The `-s' option restricts `enable' to the POSIX special builtins.
3190 If `-s' is used with `-f', the new builtin becomes a special
3191 builtin (*note Special Builtins::).
3193 The return status is zero unless a NAME is not a shell builtin or
3194 there is an error loading a new builtin from a shared object.
3197 help [-dms] [PATTERN]
3198 Display helpful information about builtin commands. If PATTERN is
3199 specified, `help' gives detailed help on all commands matching
3200 PATTERN, otherwise a list of the builtins is printed.
3202 Options, if supplied, have the following meanings:
3205 Display a short description of each PATTERN
3208 Display the description of each PATTERN in a manpage-like
3212 Display only a short usage synopsis for each PATTERN
3214 The return status is zero unless no command matches PATTERN.
3217 let EXPRESSION [EXPRESSION]
3218 The `let' builtin allows arithmetic to be performed on shell
3219 variables. Each EXPRESSION is evaluated according to the rules
3220 given below in *note Shell Arithmetic::. If the last EXPRESSION
3221 evaluates to 0, `let' returns 1; otherwise 0 is returned.
3224 local [OPTION] NAME[=VALUE] ...
3225 For each argument, a local variable named NAME is created, and
3226 assigned VALUE. The OPTION can be any of the options accepted by
3227 `declare'. `local' can only be used within a function; it makes
3228 the variable NAME have a visible scope restricted to that function
3229 and its children. The return status is zero unless `local' is
3230 used outside a function, an invalid NAME is supplied, or NAME is a
3235 Exit a login shell, returning a status of N to the shell's parent.
3238 mapfile [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3239 -C CALLBACK] [-c QUANTUM] [ARRAY]
3240 Read lines from the standard input into the indexed array variable
3241 ARRAY, or from file descriptor FD if the `-u' option is supplied.
3242 The variable `MAPFILE' is the default ARRAY. Options, if
3243 supplied, have the following meanings:
3245 Copy at most COUNT lines. If COUNT is 0, all lines are
3249 Begin assigning to ARRAY at index ORIGIN. The default index
3253 Discard the first COUNT lines read.
3256 Remove a trailing newline from each line read.
3259 Read lines from file descriptor FD instead of the standard
3263 Evaluate CALLBACK each time QUANTUMP lines are read. The
3264 `-c' option specifies QUANTUM.
3267 Specify the number of lines read between each call to
3270 If `-C' is specified without `-c', the default quantum is 5000.
3271 When CALLBACK is evaluated, it is supplied the index of the next
3272 array element to be assigned and the line to be assigned to that
3273 element as additional arguments. CALLBACK is evaluated after the
3274 line is read but before the array element is assigned.
3276 If not supplied with an explicit origin, `mapfile' will clear ARRAY
3277 before assigning to it.
3279 `mapfile' returns successfully unless an invalid option or option
3280 argument is supplied, ARRAY is invalid or unassignable, or ARRAY
3281 is not an indexed array.
3284 printf [-v VAR] FORMAT [ARGUMENTS]
3285 Write the formatted ARGUMENTS to the standard output under the
3286 control of the FORMAT. The `-v' option causes the output to be
3287 assigned to the variable VAR rather than being printed to the
3290 The FORMAT is a character string which contains three types of
3291 objects: plain characters, which are simply copied to standard
3292 output, character escape sequences, which are converted and copied
3293 to the standard output, and format specifications, each of which
3294 causes printing of the next successive ARGUMENT. In addition to
3295 the standard `printf(1)' formats, `printf' interprets the
3296 following extensions:
3299 causes `printf' to expand backslash escape sequences in the
3300 corresponding ARGUMENT, (except that `\c' terminates output,
3301 backslashes in `\'', `\"', and `\?' are not removed, and
3302 octal escapes beginning with `\0' may contain up to four
3306 causes `printf' to output the corresponding ARGUMENT in a
3307 format that can be reused as shell input.
3310 causes `printf' to output the date-time string resulting from
3311 using DATEFMT as a format string for `strftime'(3). The
3312 corresponding ARGUMENT is an integer representing the number
3313 of seconds since the epoch. Two special argument values may
3314 be used: -1 represents the current time, and -2 represents
3315 the time the shell was invoked.
3317 Arguments to non-string format specifiers are treated as C
3318 language constants, except that a leading plus or minus sign is
3319 allowed, and if the leading character is a single or double quote,
3320 the value is the ASCII value of the following character.
3322 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3323 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3324 format specifications behave as if a zero value or null string, as
3325 appropriate, had been supplied. The return value is zero on
3326 success, non-zero on failure.
3329 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3330 One line is read from the standard input, or from the file
3331 descriptor FD supplied as an argument to the `-u' option, and the
3332 first word is assigned to the first NAME, the second word to the
3333 second NAME, and so on, with leftover words and their intervening
3334 separators assigned to the last NAME. If there are fewer words
3335 read from the input stream than names, the remaining names are
3336 assigned empty values. The characters in the value of the `IFS'
3337 variable are used to split the line into words. The backslash
3338 character `\' may be used to remove any special meaning for the
3339 next character read and for line continuation. If no names are
3340 supplied, the line read is assigned to the variable `REPLY'. The
3341 return code is zero, unless end-of-file is encountered, `read'
3342 times out (in which case the return code is greater than 128), or
3343 an invalid file descriptor is supplied as the argument to `-u'.
3345 Options, if supplied, have the following meanings:
3348 The words are assigned to sequential indices of the array
3349 variable ANAME, starting at 0. All elements are removed from
3350 ANAME before the assignment. Other NAME arguments are
3354 The first character of DELIM is used to terminate the input
3355 line, rather than newline.
3358 Readline (*note Command Line Editing::) is used to obtain the
3359 line. Readline uses the current (or default, if line editing
3360 was not previously active) editing settings.
3363 If Readline is being used to read the line, TEXT is placed
3364 into the editing buffer before editing begins.
3367 `read' returns after reading NCHARS characters rather than
3368 waiting for a complete line of input, but honor a delimiter
3369 if fewer than NCHARS characters are read before the delimiter.
3372 `read' returns after reading exactly NCHARS characters rather
3373 than waiting for a complete line of input, unless EOF is
3374 encountered or `read' times out. Delimiter characters
3375 encountered in the input are not treated specially and do not
3376 cause `read' to return until NCHARS characters are read.
3379 Display PROMPT, without a trailing newline, before attempting
3380 to read any input. The prompt is displayed only if input is
3381 coming from a terminal.
3384 If this option is given, backslash does not act as an escape
3385 character. The backslash is considered to be part of the
3386 line. In particular, a backslash-newline pair may not be
3387 used as a line continuation.
3390 Silent mode. If input is coming from a terminal, characters
3394 Cause `read' to time out and return failure if a complete
3395 line of input is not read within TIMEOUT seconds. TIMEOUT
3396 may be a decimal number with a fractional portion following
3397 the decimal point. This option is only effective if `read'
3398 is reading input from a terminal, pipe, or other special
3399 file; it has no effect when reading from regular files. If
3400 TIMEOUT is 0, `read' returns success if input is available on
3401 the specified file descriptor, failure otherwise. The exit
3402 status is greater than 128 if the timeout is exceeded.
3405 Read input from file descriptor FD.
3409 readarray [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD] [
3410 -C CALLBACK] [-c QUANTUM] [ARRAY]
3411 Read lines from the standard input into the indexed array variable
3412 ARRAY, or from file descriptor FD if the `-u' option is supplied.
3414 A synonym for `mapfile'.
3418 A synonym for `.' (*note Bourne Shell Builtins::).
3421 type [-afptP] [NAME ...]
3422 For each NAME, indicate how it would be interpreted if used as a
3425 If the `-t' option is used, `type' prints a single word which is
3426 one of `alias', `function', `builtin', `file' or `keyword', if
3427 NAME is an alias, shell function, shell builtin, disk file, or
3428 shell reserved word, respectively. If the NAME is not found, then
3429 nothing is printed, and `type' returns a failure status.
3431 If the `-p' option is used, `type' either returns the name of the
3432 disk file that would be executed, or nothing if `-t' would not
3435 The `-P' option forces a path search for each NAME, even if `-t'
3436 would not return `file'.
3438 If a command is hashed, `-p' and `-P' print the hashed value, not
3439 necessarily the file that appears first in `$PATH'.
3441 If the `-a' option is used, `type' returns all of the places that
3442 contain an executable named FILE. This includes aliases and
3443 functions, if and only if the `-p' option is not also used.
3445 If the `-f' option is used, `type' does not attempt to find shell
3446 functions, as with the `command' builtin.
3448 The return status is zero if all of the NAMES are found, non-zero
3449 if any are not found.
3452 typeset [-afFrxi] [-p] [NAME[=VALUE] ...]
3453 The `typeset' command is supplied for compatibility with the Korn
3454 shell; however, it has been deprecated in favor of the `declare'
3458 ulimit [-abcdefilmnpqrstuvxHST] [LIMIT]
3459 `ulimit' provides control over the resources available to processes
3460 started by the shell, on systems that allow such control. If an
3461 option is given, it is interpreted as follows:
3463 Change and report the soft limit associated with a resource.
3466 Change and report the hard limit associated with a resource.
3469 All current limits are reported.
3472 The maximum socket buffer size.
3475 The maximum size of core files created.
3478 The maximum size of a process's data segment.
3481 The maximum scheduling priority ("nice").
3484 The maximum size of files written by the shell and its
3488 The maximum number of pending signals.
3491 The maximum size that may be locked into memory.
3494 The maximum resident set size (many systems do not honor this
3498 The maximum number of open file descriptors (most systems do
3499 not allow this value to be set).
3502 The pipe buffer size.
3505 The maximum number of bytes in POSIX message queues.
3508 The maximum real-time scheduling priority.
3511 The maximum stack size.
3514 The maximum amount of cpu time in seconds.
3517 The maximum number of processes available to a single user.
3520 The maximum amount of virtual memory available to the shell,
3521 and, on some systems, to its children.
3524 The maximum number of file locks.
3527 The maximum number of threads.
3530 If LIMIT is given, it is the new value of the specified resource;
3531 the special LIMIT values `hard', `soft', and `unlimited' stand for
3532 the current hard limit, the current soft limit, and no limit,
3533 respectively. A hard limit cannot be increased by a non-root user
3534 once it is set; a soft limit may be increased up to the value of
3535 the hard limit. Otherwise, the current value of the soft limit
3536 for the specified resource is printed, unless the `-H' option is
3537 supplied. When setting new limits, if neither `-H' nor `-S' is
3538 supplied, both the hard and soft limits are set. If no option is
3539 given, then `-f' is assumed. Values are in 1024-byte increments,
3540 except for `-t', which is in seconds, `-p', which is in units of
3541 512-byte blocks, and `-n' and `-u', which are unscaled values.
3543 The return status is zero unless an invalid option or argument is
3544 supplied, or an error occurs while setting a new limit.
3547 unalias [-a] [NAME ... ]
3549 Remove each NAME from the list of aliases. If `-a' is supplied,
3550 all aliases are removed. Aliases are described in *note Aliases::.
3554 File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
3556 4.3 Modifying Shell Behavior
3557 ============================
3561 * The Set Builtin:: Change the values of shell attributes and
3562 positional parameters.
3563 * The Shopt Builtin:: Modify shell optional behavior.
3566 File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3568 4.3.1 The Set Builtin
3569 ---------------------
3571 This builtin is so complicated that it deserves its own section. `set'
3572 allows you to change the values of shell options and set the positional
3573 parameters, or to display the names and values of shell variables.
3576 set [--abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [ARGUMENT ...]
3577 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [ARGUMENT ...]
3579 If no options or arguments are supplied, `set' displays the names
3580 and values of all shell variables and functions, sorted according
3581 to the current locale, in a format that may be reused as input for
3582 setting or resetting the currently-set variables. Read-only
3583 variables cannot be reset. In POSIX mode, only shell variables
3586 When options are supplied, they set or unset shell attributes.
3587 Options, if specified, have the following meanings:
3590 Mark variables and function which are modified or created for
3591 export to the environment of subsequent commands.
3594 Cause the status of terminated background jobs to be reported
3595 immediately, rather than before printing the next primary
3599 Exit immediately if a pipeline (*note Pipelines::), which may
3600 consist of a single simple command (*note Simple Commands::),
3601 a subshell command enclosed in parentheses (*note Command
3602 Grouping::), or one of the commands executed as part of a
3603 command list enclosed by braces (*note Command Grouping::)
3604 returns a non-zero status. The shell does not exit if the
3605 command that fails is part of the command list immediately
3606 following a `while' or `until' keyword, part of the test in
3607 an `if' statement, part of any command executed in a `&&' or
3608 `||' list except the command following the final `&&' or `||',
3609 any command in a pipeline but the last, or if the command's
3610 return status is being inverted with `!'. A trap on `ERR',
3611 if set, is executed before the shell exits.
3613 This option applies to the shell environment and each
3614 subshell environment separately (*note Command Execution
3615 Environment::), and may cause subshells to exit before
3616 executing all the commands in the subshell.
3619 Disable filename expansion (globbing).
3622 Locate and remember (hash) commands as they are looked up for
3623 execution. This option is enabled by default.
3626 All arguments in the form of assignment statements are placed
3627 in the environment for a command, not just those that precede
3631 Job control is enabled (*note Job Control::).
3634 Read commands but do not execute them; this may be used to
3635 check a script for syntax errors. This option is ignored by
3639 Set the option corresponding to OPTION-NAME:
3648 Use an `emacs'-style line editing interface (*note
3649 Command Line Editing::). This also affects the editing
3650 interface used for `read -e'.
3668 Enable command history, as described in *note Bash
3669 History Facilities::. This option is on by default in
3673 An interactive shell will not exit upon reading EOF.
3706 If set, the return value of a pipeline is the value of
3707 the last (rightmost) command to exit with a non-zero
3708 status, or zero if all commands in the pipeline exit
3709 successfully. This option is disabled by default.
3712 Change the behavior of Bash where the default operation
3713 differs from the POSIX standard to match the standard
3714 (*note Bash POSIX Mode::). This is intended to make
3715 Bash behave as a strict superset of that standard.
3724 Use a `vi'-style line editing interface. This also
3725 affects the editing interface used for `read -e'.
3731 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3732 `$ENV' files are not processed, shell functions are not
3733 inherited from the environment, and the `SHELLOPTS',
3734 `BASHOPTS', `CDPATH' and `GLOBIGNORE' variables, if they
3735 appear in the environment, are ignored. If the shell is
3736 started with the effective user (group) id not equal to the
3737 real user (group) id, and the `-p' option is not supplied,
3738 these actions are taken and the effective user id is set to
3739 the real user id. If the `-p' option is supplied at startup,
3740 the effective user id is not reset. Turning this option off
3741 causes the effective user and group ids to be set to the real
3745 Exit after reading and executing one command.
3748 Treat unset variables and parameters other than the special
3749 parameters `@' or `*' as an error when performing parameter
3750 expansion. An error message will be written to the standard
3751 error, and a non-interactive shell will exit.
3754 Print shell input lines as they are read.
3757 Print a trace of simple commands, `for' commands, `case'
3758 commands, `select' commands, and arithmetic `for' commands
3759 and their arguments or associated word lists after they are
3760 expanded and before they are executed. The value of the `PS4'
3761 variable is expanded and the resultant value is printed before
3762 the command and its expanded arguments.
3765 The shell will perform brace expansion (*note Brace
3766 Expansion::). This option is on by default.
3769 Prevent output redirection using `>', `>&', and `<>' from
3770 overwriting existing files.
3773 If set, any trap on `ERR' is inherited by shell functions,
3774 command substitutions, and commands executed in a subshell
3775 environment. The `ERR' trap is normally not inherited in
3779 Enable `!' style history substitution (*note History
3780 Interaction::). This option is on by default for interactive
3784 If set, do not follow symbolic links when performing commands
3785 such as `cd' which change the current directory. The
3786 physical directory is used instead. By default, Bash follows
3787 the logical chain of directories when performing commands
3788 which change the current directory.
3790 For example, if `/usr/sys' is a symbolic link to
3791 `/usr/local/sys' then:
3792 $ cd /usr/sys; echo $PWD
3797 If `set -P' is on, then:
3798 $ cd /usr/sys; echo $PWD
3804 If set, any trap on `DEBUG' and `RETURN' are inherited by
3805 shell functions, command substitutions, and commands executed
3806 in a subshell environment. The `DEBUG' and `RETURN' traps
3807 are normally not inherited in such cases.
3810 If no arguments follow this option, then the positional
3811 parameters are unset. Otherwise, the positional parameters
3812 are set to the ARGUMENTS, even if some of them begin with a
3816 Signal the end of options, cause all remaining ARGUMENTS to
3817 be assigned to the positional parameters. The `-x' and `-v'
3818 options are turned off. If there are no arguments, the
3819 positional parameters remain unchanged.
3821 Using `+' rather than `-' causes these options to be turned off.
3822 The options can also be used upon invocation of the shell. The
3823 current set of options may be found in `$-'.
3825 The remaining N ARGUMENTS are positional parameters and are
3826 assigned, in order, to `$1', `$2', ... `$N'. The special
3827 parameter `#' is set to N.
3829 The return status is always zero unless an invalid option is
3833 File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
3835 4.3.2 The Shopt Builtin
3836 -----------------------
3838 This builtin allows you to change additional shell optional behavior.
3841 shopt [-pqsu] [-o] [OPTNAME ...]
3842 Toggle the values of variables controlling optional shell behavior.
3843 With no options, or with the `-p' option, a list of all settable
3844 options is displayed, with an indication of whether or not each is
3845 set. The `-p' option causes output to be displayed in a form that
3846 may be reused as input. Other options have the following meanings:
3849 Enable (set) each OPTNAME.
3852 Disable (unset) each OPTNAME.
3855 Suppresses normal output; the return status indicates whether
3856 the OPTNAME is set or unset. If multiple OPTNAME arguments
3857 are given with `-q', the return status is zero if all
3858 OPTNAMES are enabled; non-zero otherwise.
3861 Restricts the values of OPTNAME to be those defined for the
3862 `-o' option to the `set' builtin (*note The Set Builtin::).
3864 If either `-s' or `-u' is used with no OPTNAME arguments, the
3865 display is limited to those options which are set or unset,
3868 Unless otherwise noted, the `shopt' options are disabled (off) by
3871 The return status when listing options is zero if all OPTNAMES are
3872 enabled, non-zero otherwise. When setting or unsetting options,
3873 the return status is zero unless an OPTNAME is not a valid shell
3876 The list of `shopt' options is:
3878 If set, a command name that is the name of a directory is
3879 executed as if it were the argument to the `cd' command.
3880 This option is only used by interactive shells.
3883 If this is set, an argument to the `cd' builtin command that
3884 is not a directory is assumed to be the name of a variable
3885 whose value is the directory to change to.
3888 If set, minor errors in the spelling of a directory component
3889 in a `cd' command will be corrected. The errors checked for
3890 are transposed characters, a missing character, and a
3891 character too many. If a correction is found, the corrected
3892 path is printed, and the command proceeds. This option is
3893 only used by interactive shells.
3896 If this is set, Bash checks that a command found in the hash
3897 table exists before trying to execute it. If a hashed
3898 command no longer exists, a normal path search is performed.
3901 If set, Bash lists the status of any stopped and running jobs
3902 before exiting an interactive shell. If any jobs are
3903 running, this causes the exit to be deferred until a second
3904 exit is attempted without an intervening command (*note Job
3905 Control::). The shell always postpones exiting if any jobs
3909 If set, Bash checks the window size after each command and,
3910 if necessary, updates the values of `LINES' and `COLUMNS'.
3913 If set, Bash attempts to save all lines of a multiple-line
3914 command in the same history entry. This allows easy
3915 re-editing of multi-line commands.
3918 If set, Bash changes its behavior to that of version 3.1 with
3919 respect to quoted arguments to the conditional command's `=~'
3923 If set, Bash changes its behavior to that of version 3.2 with
3924 respect to locale-specific string comparison when using the
3925 `[[' conditional command's `<' and `>' operators. Bash
3926 versions prior to bash-4.0 use ASCII collation and strcmp(3);
3927 bash-4.1 and later use the current locale's collation
3928 sequence and strcoll(3).
3931 If set, Bash changes its behavior to that of version 4.0 with
3932 respect to locale-specific string comparison when using the
3933 `[[' conditional command's `<' and `>' operators (see
3934 previous item) and the effect of interrupting a command list.
3937 If set, Bash, when in posix mode, treats a single quote in a
3938 double-quoted parameter expansion as a special character.
3939 The single quotes must match (an even number) and the
3940 characters between the single quotes are considered quoted.
3941 This is the behavior of POSIX mode through version 4.1. The
3942 default Bash behavior remains as in previous versions.
3945 If set, Bash attempts spelling correction on directory names
3946 during word completion if the directory name initially
3947 supplied does not exist.
3950 If set, Bash includes filenames beginning with a `.' in the
3951 results of filename expansion.
3954 If this is set, a non-interactive shell will not exit if it
3955 cannot execute the file specified as an argument to the `exec'
3956 builtin command. An interactive shell does not exit if `exec'
3960 If set, aliases are expanded as described below under Aliases,
3961 *note Aliases::. This option is enabled by default for
3965 If set, behavior intended for use by debuggers is enabled:
3967 1. The `-F' option to the `declare' builtin (*note Bash
3968 Builtins::) displays the source file name and line
3969 number corresponding to each function name supplied as
3972 2. If the command run by the `DEBUG' trap returns a
3973 non-zero value, the next command is skipped and not
3976 3. If the command run by the `DEBUG' trap returns a value
3977 of 2, and the shell is executing in a subroutine (a
3978 shell function or a shell script executed by the `.' or
3979 `source' builtins), a call to `return' is simulated.
3981 4. `BASH_ARGC' and `BASH_ARGV' are updated as described in
3982 their descriptions (*note Bash Variables::).
3984 5. Function tracing is enabled: command substitution,
3985 shell functions, and subshells invoked with `( COMMAND
3986 )' inherit the `DEBUG' and `RETURN' traps.
3988 6. Error tracing is enabled: command substitution, shell
3989 functions, and subshells invoked with `( COMMAND )'
3990 inherit the `ERR' trap.
3993 If set, the extended pattern matching features described above
3994 (*note Pattern Matching::) are enabled.
3997 If set, `$'STRING'' and `$"STRING"' quoting is performed
3998 within `${PARAMETER}' expansions enclosed in double quotes.
3999 This option is enabled by default.
4002 If set, patterns which fail to match filenames during
4003 filename expansion result in an expansion error.
4006 If set, the suffixes specified by the `FIGNORE' shell variable
4007 cause words to be ignored when performing word completion
4008 even if the ignored words are the only possible completions.
4009 *Note Bash Variables::, for a description of `FIGNORE'. This
4010 option is enabled by default.
4013 If set, the pattern `**' used in a filename expansion context
4014 will match a files and zero or more directories and
4015 subdirectories. If the pattern is followed by a `/', only
4016 directories and subdirectories match.
4019 If set, shell error messages are written in the standard GNU
4020 error message format.
4023 If set, the history list is appended to the file named by the
4024 value of the `HISTFILE' variable when the shell exits, rather
4025 than overwriting the file.
4028 If set, and Readline is being used, a user is given the
4029 opportunity to re-edit a failed history substitution.
4032 If set, and Readline is being used, the results of history
4033 substitution are not immediately passed to the shell parser.
4034 Instead, the resulting line is loaded into the Readline
4035 editing buffer, allowing further modification.
4038 If set, and Readline is being used, Bash will attempt to
4039 perform hostname completion when a word containing a `@' is
4040 being completed (*note Commands For Completion::). This
4041 option is enabled by default.
4044 If set, Bash will send `SIGHUP' to all jobs when an
4045 interactive login shell exits (*note Signals::).
4047 `interactive_comments'
4048 Allow a word beginning with `#' to cause that word and all
4049 remaining characters on that line to be ignored in an
4050 interactive shell. This option is enabled by default.
4053 If set, and job control is not active, the shell runs the
4054 last command of a pipeline not executed in the background in
4055 the current shell environment.
4058 If enabled, and the `cmdhist' option is enabled, multi-line
4059 commands are saved to the history with embedded newlines
4060 rather than using semicolon separators where possible.
4063 The shell sets this option if it is started as a login shell
4064 (*note Invoking Bash::). The value may not be changed.
4067 If set, and a file that Bash is checking for mail has been
4068 accessed since the last time it was checked, the message
4069 `"The mail in MAILFILE has been read"' is displayed.
4071 `no_empty_cmd_completion'
4072 If set, and Readline is being used, Bash will not attempt to
4073 search the `PATH' for possible completions when completion is
4074 attempted on an empty line.
4077 If set, Bash matches filenames in a case-insensitive fashion
4078 when performing filename expansion.
4081 If set, Bash matches patterns in a case-insensitive fashion
4082 when performing matching while executing `case' or `[['
4083 conditional commands.
4086 If set, Bash allows filename patterns which match no files to
4087 expand to a null string, rather than themselves.
4090 If set, the programmable completion facilities (*note
4091 Programmable Completion::) are enabled. This option is
4095 If set, prompt strings undergo parameter expansion, command
4096 substitution, arithmetic expansion, and quote removal after
4097 being expanded as described below (*note Printing a Prompt::).
4098 This option is enabled by default.
4101 The shell sets this option if it is started in restricted mode
4102 (*note The Restricted Shell::). The value may not be changed.
4103 This is not reset when the startup files are executed,
4104 allowing the startup files to discover whether or not a shell
4108 If this is set, the `shift' builtin prints an error message
4109 when the shift count exceeds the number of positional
4113 If set, the `source' builtin uses the value of `PATH' to find
4114 the directory containing the file supplied as an argument.
4115 This option is enabled by default.
4118 If set, the `echo' builtin expands backslash-escape sequences
4122 The return status when listing options is zero if all OPTNAMES are
4123 enabled, non-zero otherwise. When setting or unsetting options,
4124 the return status is zero unless an OPTNAME is not a valid shell
4129 File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
4131 4.4 Special Builtins
4132 ====================
4134 For historical reasons, the POSIX standard has classified several
4135 builtin commands as _special_. When Bash is executing in POSIX mode,
4136 the special builtins differ from other builtin commands in three
4139 1. Special builtins are found before shell functions during command
4142 2. If a special builtin returns an error status, a non-interactive
4145 3. Assignment statements preceding the command stay in effect in the
4146 shell environment after the command completes.
4148 When Bash is not executing in POSIX mode, these builtins behave no
4149 differently than the rest of the Bash builtin commands. The Bash POSIX
4150 mode is described in *note Bash POSIX Mode::.
4152 These are the POSIX special builtins:
4153 break : . continue eval exec exit export readonly return set
4157 File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
4164 * Bourne Shell Variables:: Variables which Bash uses in the same way
4165 as the Bourne Shell.
4166 * Bash Variables:: List of variables that exist in Bash.
4168 This chapter describes the shell variables that Bash uses. Bash
4169 automatically assigns default values to a number of variables.
4172 File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
4174 5.1 Bourne Shell Variables
4175 ==========================
4177 Bash uses certain shell variables in the same way as the Bourne shell.
4178 In some cases, Bash assigns a default value to the variable.
4181 A colon-separated list of directories used as a search path for
4182 the `cd' builtin command.
4185 The current user's home directory; the default for the `cd' builtin
4186 command. The value of this variable is also used by tilde
4187 expansion (*note Tilde Expansion::).
4190 A list of characters that separate fields; used when the shell
4191 splits words as part of expansion.
4194 If this parameter is set to a filename or directory name and the
4195 `MAILPATH' variable is not set, Bash informs the user of the
4196 arrival of mail in the specified file or Maildir-format directory.
4199 A colon-separated list of filenames which the shell periodically
4200 checks for new mail. Each list entry can specify the message that
4201 is printed when new mail arrives in the mail file by separating
4202 the file name from the message with a `?'. When used in the text
4203 of the message, `$_' expands to the name of the current mail file.
4206 The value of the last option argument processed by the `getopts'
4210 The index of the last option argument processed by the `getopts'
4214 A colon-separated list of directories in which the shell looks for
4215 commands. A zero-length (null) directory name in the value of
4216 `PATH' indicates the current directory. A null directory name may
4217 appear as two adjacent colons, or as an initial or trailing colon.
4220 The primary prompt string. The default value is `\s-\v\$ '.
4221 *Note Printing a Prompt::, for the complete list of escape
4222 sequences that are expanded before `PS1' is displayed.
4225 The secondary prompt string. The default value is `> '.
4229 File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
4234 These variables are set or used by Bash, but other shells do not
4235 normally treat them specially.
4237 A few variables used by Bash are described in different chapters:
4238 variables for controlling the job control facilities (*note Job Control
4242 The full pathname used to execute the current instance of Bash.
4245 A colon-separated list of enabled shell options. Each word in the
4246 list is a valid argument for the `-s' option to the `shopt'
4247 builtin command (*note The Shopt Builtin::). The options
4248 appearing in `BASHOPTS' are those reported as `on' by `shopt'. If
4249 this variable is in the environment when Bash starts up, each
4250 shell option in the list will be enabled before reading any
4251 startup files. This variable is readonly.
4254 Expands to the process ID of the current Bash process. This
4255 differs from `$$' under certain circumstances, such as subshells
4256 that do not require Bash to be re-initialized.
4259 An associative array variable whose members correspond to the
4260 internal list of aliases as maintained by the `alias' builtin.
4261 (*note Bourne Shell Builtins::). Elements added to this array
4262 appear in the alias list; unsetting array elements cause aliases
4263 to be removed from the alias list.
4266 An array variable whose values are the number of parameters in each
4267 frame of the current bash execution call stack. The number of
4268 parameters to the current subroutine (shell function or script
4269 executed with `.' or `source') is at the top of the stack. When a
4270 subroutine is executed, the number of parameters passed is pushed
4271 onto `BASH_ARGC'. The shell sets `BASH_ARGC' only when in
4272 extended debugging mode (see *note The Shopt Builtin:: for a
4273 description of the `extdebug' option to the `shopt' builtin).
4276 An array variable containing all of the parameters in the current
4277 bash execution call stack. The final parameter of the last
4278 subroutine call is at the top of the stack; the first parameter of
4279 the initial call is at the bottom. When a subroutine is executed,
4280 the parameters supplied are pushed onto `BASH_ARGV'. The shell
4281 sets `BASH_ARGV' only when in extended debugging mode (see *note
4282 The Shopt Builtin:: for a description of the `extdebug' option to
4283 the `shopt' builtin).
4286 An associative array variable whose members correspond to the
4287 internal hash table of commands as maintained by the `hash' builtin
4288 (*note Bourne Shell Builtins::). Elements added to this array
4289 appear in the hash table; unsetting array elements cause commands
4290 to be removed from the hash table.
4293 The command currently being executed or about to be executed,
4294 unless the shell is executing a command as the result of a trap,
4295 in which case it is the command executing at the time of the trap.
4298 If this variable is set when Bash is invoked to execute a shell
4299 script, its value is expanded and used as the name of a startup
4300 file to read before executing the script. *Note Bash Startup
4303 `BASH_EXECUTION_STRING'
4304 The command argument to the `-c' invocation option.
4307 An array variable whose members are the line numbers in source
4308 files where each corresponding member of FUNCNAME was invoked.
4309 `${BASH_LINENO[$i]}' is the line number in the source file
4310 (`${BASH_SOURCE[$i+1]}') where `${FUNCNAME[$i]}' was called (or
4311 `${BASH_LINENO[$i-1]}' if referenced within another shell
4312 function). Use `LINENO' to obtain the current line number.
4315 An array variable whose members are assigned by the `=~' binary
4316 operator to the `[[' conditional command (*note Conditional
4317 Constructs::). The element with index 0 is the portion of the
4318 string matching the entire regular expression. The element with
4319 index N is the portion of the string matching the Nth
4320 parenthesized subexpression. This variable is read-only.
4323 An array variable whose members are the source filenames where the
4324 corresponding shell function names in the `FUNCNAME' array
4325 variable are defined. The shell function `${FUNCNAME[$i]}' is
4326 defined in the file `${BASH_SOURCE[$i]}' and called from
4327 `${BASH_SOURCE[$i+1]}'
4330 Incremented by one each time a subshell or subshell environment is
4331 spawned. The initial value is 0.
4334 A readonly array variable (*note Arrays::) whose members hold
4335 version information for this instance of Bash. The values
4336 assigned to the array members are as follows:
4339 The major version number (the RELEASE).
4342 The minor version number (the VERSION).
4351 The release status (e.g., BETA1).
4354 The value of `MACHTYPE'.
4358 The version number of the current instance of Bash.
4361 If set to an integer corresponding to a valid file descriptor, Bash
4362 will write the trace output generated when `set -x' is enabled to
4363 that file descriptor. This allows tracing output to be separated
4364 from diagnostic and error messages. The file descriptor is closed
4365 when `BASH_XTRACEFD' is unset or assigned a new value. Unsetting
4366 `BASH_XTRACEFD' or assigning it the empty string causes the trace
4367 output to be sent to the standard error. Note that setting
4368 `BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
4369 unsetting it will result in the standard error being closed.
4372 Used by the `select' command to determine the terminal width when
4373 printing selection lists. Automatically set upon receipt of a
4377 An index into `${COMP_WORDS}' of the word containing the current
4378 cursor position. This variable is available only in shell
4379 functions invoked by the programmable completion facilities (*note
4380 Programmable Completion::).
4383 The current command line. This variable is available only in
4384 shell functions and external commands invoked by the programmable
4385 completion facilities (*note Programmable Completion::).
4388 The index of the current cursor position relative to the beginning
4389 of the current command. If the current cursor position is at the
4390 end of the current command, the value of this variable is equal to
4391 `${#COMP_LINE}'. This variable is available only in shell
4392 functions and external commands invoked by the programmable
4393 completion facilities (*note Programmable Completion::).
4396 Set to an integer value corresponding to the type of completion
4397 attempted that caused a completion function to be called: TAB, for
4398 normal completion, `?', for listing completions after successive
4399 tabs, `!', for listing alternatives on partial word completion,
4400 `@', to list completions if the word is not unmodified, or `%',
4401 for menu completion. This variable is available only in shell
4402 functions and external commands invoked by the programmable
4403 completion facilities (*note Programmable Completion::).
4406 The key (or final key of a key sequence) used to invoke the current
4407 completion function.
4410 The set of characters that the Readline library treats as word
4411 separators when performing word completion. If `COMP_WORDBREAKS'
4412 is unset, it loses its special properties, even if it is
4416 An array variable consisting of the individual words in the
4417 current command line. The line is split into words as Readline
4418 would split it, using `COMP_WORDBREAKS' as described above. This
4419 variable is available only in shell functions invoked by the
4420 programmable completion facilities (*note Programmable
4424 An array variable from which Bash reads the possible completions
4425 generated by a shell function invoked by the programmable
4426 completion facility (*note Programmable Completion::).
4429 An array variable created to hold the file descriptors for output
4430 from and input to an unnamed coprocess (*note Coprocesses::).
4433 An array variable containing the current contents of the directory
4434 stack. Directories appear in the stack in the order they are
4435 displayed by the `dirs' builtin. Assigning to members of this
4436 array variable may be used to modify directories already in the
4437 stack, but the `pushd' and `popd' builtins must be used to add and
4438 remove directories. Assignment to this variable will not change
4439 the current directory. If `DIRSTACK' is unset, it loses its
4440 special properties, even if it is subsequently reset.
4443 If Bash finds this variable in the environment when the shell
4444 starts with value `t', it assumes that the shell is running in an
4445 Emacs shell buffer and disables line editing.
4448 Similar to `BASH_ENV'; used when the shell is invoked in POSIX
4449 Mode (*note Bash POSIX Mode::).
4452 The numeric effective user id of the current user. This variable
4456 The editor used as a default by the `-e' option to the `fc'
4460 A colon-separated list of suffixes to ignore when performing
4461 filename completion. A file name whose suffix matches one of the
4462 entries in `FIGNORE' is excluded from the list of matched file
4463 names. A sample value is `.o:~'
4466 An array variable containing the names of all shell functions
4467 currently in the execution call stack. The element with index 0
4468 is the name of any currently-executing shell function. The
4469 bottom-most element (the one with the highest index) is `"main"'.
4470 This variable exists only when a shell function is executing.
4471 Assignments to `FUNCNAME' have no effect and return an error
4472 status. If `FUNCNAME' is unset, it loses its special properties,
4473 even if it is subsequently reset.
4475 This variable can be used with `BASH_LINENO' and `BASH_SOURCE'.
4476 Each element of `FUNCNAME' has corresponding elements in
4477 `BASH_LINENO' and `BASH_SOURCE' to describe the call stack. For
4478 instance, `${FUNCNAME[$i]}' was called from the file
4479 `${BASH_SOURCE[$i+1]}' at line number `${BASH_LINENO[$i]}'. The
4480 `caller' builtin displays the current call stack using this
4484 If set to a numeric value greater than 0, defines a maximum
4485 function nesting level. Function invocations that exceed this
4486 nesting level will cause the current command to abort.
4489 A colon-separated list of patterns defining the set of filenames to
4490 be ignored by filename expansion. If a filename matched by a
4491 filename expansion pattern also matches one of the patterns in
4492 `GLOBIGNORE', it is removed from the list of matches.
4495 An array variable containing the list of groups of which the
4496 current user is a member. Assignments to `GROUPS' have no effect
4497 and return an error status. If `GROUPS' is unset, it loses its
4498 special properties, even if it is subsequently reset.
4501 Up to three characters which control history expansion, quick
4502 substitution, and tokenization (*note History Interaction::). The
4503 first character is the HISTORY EXPANSION character, that is, the
4504 character which signifies the start of a history expansion,
4505 normally `!'. The second character is the character which
4506 signifies `quick substitution' when seen as the first character on
4507 a line, normally `^'. The optional third character is the
4508 character which indicates that the remainder of the line is a
4509 comment when found as the first character of a word, usually `#'.
4510 The history comment character causes history substitution to be
4511 skipped for the remaining words on the line. It does not
4512 necessarily cause the shell parser to treat the rest of the line
4516 The history number, or index in the history list, of the current
4517 command. If `HISTCMD' is unset, it loses its special properties,
4518 even if it is subsequently reset.
4521 A colon-separated list of values controlling how commands are
4522 saved on the history list. If the list of values includes
4523 `ignorespace', lines which begin with a space character are not
4524 saved in the history list. A value of `ignoredups' causes lines
4525 which match the previous history entry to not be saved. A value
4526 of `ignoreboth' is shorthand for `ignorespace' and `ignoredups'.
4527 A value of `erasedups' causes all previous lines matching the
4528 current line to be removed from the history list before that line
4529 is saved. Any value not in the above list is ignored. If
4530 `HISTCONTROL' is unset, or does not include a valid value, all
4531 lines read by the shell parser are saved on the history list,
4532 subject to the value of `HISTIGNORE'. The second and subsequent
4533 lines of a multi-line compound command are not tested, and are
4534 added to the history regardless of the value of `HISTCONTROL'.
4537 The name of the file to which the command history is saved. The
4538 default value is `~/.bash_history'.
4541 The maximum number of lines contained in the history file. When
4542 this variable is assigned a value, the history file is truncated,
4543 if necessary, by removing the oldest entries, to contain no more
4544 than that number of lines. The history file is also truncated to
4545 this size after writing it when an interactive shell exits. The
4546 default value is 500.
4549 A colon-separated list of patterns used to decide which command
4550 lines should be saved on the history list. Each pattern is
4551 anchored at the beginning of the line and must match the complete
4552 line (no implicit `*' is appended). Each pattern is tested
4553 against the line after the checks specified by `HISTCONTROL' are
4554 applied. In addition to the normal shell pattern matching
4555 characters, `&' matches the previous history line. `&' may be
4556 escaped using a backslash; the backslash is removed before
4557 attempting a match. The second and subsequent lines of a
4558 multi-line compound command are not tested, and are added to the
4559 history regardless of the value of `HISTIGNORE'.
4561 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
4562 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
4563 identical to `ignorespace'. Combining these two patterns,
4564 separating them with a colon, provides the functionality of
4568 The maximum number of commands to remember on the history list.
4569 The default value is 500.
4572 If this variable is set and not null, its value is used as a
4573 format string for STRFTIME to print the time stamp associated with
4574 each history entry displayed by the `history' builtin. If this
4575 variable is set, time stamps are written to the history file so
4576 they may be preserved across shell sessions. This uses the
4577 history comment character to distinguish timestamps from other
4581 Contains the name of a file in the same format as `/etc/hosts' that
4582 should be read when the shell needs to complete a hostname. The
4583 list of possible hostname completions may be changed while the
4584 shell is running; the next time hostname completion is attempted
4585 after the value is changed, Bash adds the contents of the new file
4586 to the existing list. If `HOSTFILE' is set, but has no value, or
4587 does not name a readable file, Bash attempts to read `/etc/hosts'
4588 to obtain the list of possible hostname completions. When
4589 `HOSTFILE' is unset, the hostname list is cleared.
4592 The name of the current host.
4595 A string describing the machine Bash is running on.
4598 Controls the action of the shell on receipt of an `EOF' character
4599 as the sole input. If set, the value denotes the number of
4600 consecutive `EOF' characters that can be read as the first
4601 character on an input line before the shell will exit. If the
4602 variable exists but does not have a numeric value (or has no
4603 value) then the default is 10. If the variable does not exist,
4604 then `EOF' signifies the end of input to the shell. This is only
4605 in effect for interactive shells.
4608 The name of the Readline initialization file, overriding the
4609 default of `~/.inputrc'.
4612 Used to determine the locale category for any category not
4613 specifically selected with a variable starting with `LC_'.
4616 This variable overrides the value of `LANG' and any other `LC_'
4617 variable specifying a locale category.
4620 This variable determines the collation order used when sorting the
4621 results of filename expansion, and determines the behavior of
4622 range expressions, equivalence classes, and collating sequences
4623 within filename expansion and pattern matching (*note Filename
4627 This variable determines the interpretation of characters and the
4628 behavior of character classes within filename expansion and pattern
4629 matching (*note Filename Expansion::).
4632 This variable determines the locale used to translate double-quoted
4633 strings preceded by a `$' (*note Locale Translation::).
4636 This variable determines the locale category used for number
4640 The line number in the script or shell function currently
4644 Used by the `select' command to determine the column length for
4645 printing selection lists. Automatically set upon receipt of a
4649 A string that fully describes the system type on which Bash is
4650 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
4653 How often (in seconds) that the shell should check for mail in the
4654 files specified in the `MAILPATH' or `MAIL' variables. The
4655 default is 60 seconds. When it is time to check for mail, the
4656 shell does so before displaying the primary prompt. If this
4657 variable is unset, or set to a value that is not a number greater
4658 than or equal to zero, the shell disables mail checking.
4661 An array variable created to hold the text read by the `mapfile'
4662 builtin when no variable name is supplied.
4665 The previous working directory as set by the `cd' builtin.
4668 If set to the value 1, Bash displays error messages generated by
4669 the `getopts' builtin command.
4672 A string describing the operating system Bash is running on.
4675 An array variable (*note Arrays::) containing a list of exit
4676 status values from the processes in the most-recently-executed
4677 foreground pipeline (which may contain only a single command).
4680 If this variable is in the environment when `bash' starts, the
4681 shell enters POSIX mode (*note Bash POSIX Mode::) before reading
4682 the startup files, as if the `--posix' invocation option had been
4683 supplied. If it is set while the shell is running, `bash' enables
4684 POSIX mode, as if the command
4689 The process ID of the shell's parent process. This variable is
4693 If set, the value is interpreted as a command to execute before
4694 the printing of each primary prompt (`$PS1').
4697 If set to a number greater than zero, the value is used as the
4698 number of trailing directory components to retain when expanding
4699 the `\w' and `\W' prompt string escapes (*note Printing a
4700 Prompt::). Characters removed are replaced with an ellipsis.
4703 The value of this variable is used as the prompt for the `select'
4704 command. If this variable is not set, the `select' command
4708 The value is the prompt printed before the command line is echoed
4709 when the `-x' option is set (*note The Set Builtin::). The first
4710 character of `PS4' is replicated multiple times, as necessary, to
4711 indicate multiple levels of indirection. The default is `+ '.
4714 The current working directory as set by the `cd' builtin.
4717 Each time this parameter is referenced, a random integer between 0
4718 and 32767 is generated. Assigning a value to this variable seeds
4719 the random number generator.
4722 The contents of the Readline line buffer, for use with `bind -x'
4723 (*note Bash Builtins::).
4726 The position of the insertion point in the Readline line buffer,
4727 for use with `bind -x' (*note Bash Builtins::).
4730 The default variable for the `read' builtin.
4733 This variable expands to the number of seconds since the shell was
4734 started. Assignment to this variable resets the count to the
4735 value assigned, and the expanded value becomes the value assigned
4736 plus the number of seconds since the assignment.
4739 The full pathname to the shell is kept in this environment
4740 variable. If it is not set when the shell starts, Bash assigns to
4741 it the full pathname of the current user's login shell.
4744 A colon-separated list of enabled shell options. Each word in the
4745 list is a valid argument for the `-o' option to the `set' builtin
4746 command (*note The Set Builtin::). The options appearing in
4747 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4748 variable is in the environment when Bash starts up, each shell
4749 option in the list will be enabled before reading any startup
4750 files. This variable is readonly.
4753 Incremented by one each time a new instance of Bash is started.
4754 This is intended to be a count of how deeply your Bash shells are
4758 The value of this parameter is used as a format string specifying
4759 how the timing information for pipelines prefixed with the `time'
4760 reserved word should be displayed. The `%' character introduces an
4761 escape sequence that is expanded to a time value or other
4762 information. The escape sequences and their meanings are as
4763 follows; the braces denote optional portions.
4769 The elapsed time in seconds.
4772 The number of CPU seconds spent in user mode.
4775 The number of CPU seconds spent in system mode.
4778 The CPU percentage, computed as (%U + %S) / %R.
4780 The optional P is a digit specifying the precision, the number of
4781 fractional digits after a decimal point. A value of 0 causes no
4782 decimal point or fraction to be output. At most three places
4783 after the decimal point may be specified; values of P greater than
4784 3 are changed to 3. If P is not specified, the value 3 is used.
4786 The optional `l' specifies a longer format, including minutes, of
4787 the form MMmSS.FFs. The value of P determines whether or not the
4788 fraction is included.
4790 If this variable is not set, Bash acts as if it had the value
4791 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4792 If the value is null, no timing information is displayed. A
4793 trailing newline is added when the format string is displayed.
4796 If set to a value greater than zero, `TMOUT' is treated as the
4797 default timeout for the `read' builtin (*note Bash Builtins::).
4798 The `select' command (*note Conditional Constructs::) terminates
4799 if input does not arrive after `TMOUT' seconds when input is coming
4802 In an interactive shell, the value is interpreted as the number of
4803 seconds to wait for input after issuing the primary prompt when
4804 the shell is interactive. Bash terminates after that number of
4805 seconds if input does not arrive.
4808 If set, Bash uses its value as the name of a directory in which
4809 Bash creates temporary files for the shell's use.
4812 The numeric real user id of the current user. This variable is
4817 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
4822 This section describes features unique to Bash.
4826 * Invoking Bash:: Command line options that you can give
4828 * Bash Startup Files:: When and how Bash executes scripts.
4829 * Interactive Shells:: What an interactive shell is.
4830 * Bash Conditional Expressions:: Primitives used in composing expressions for
4832 * Shell Arithmetic:: Arithmetic on shell variables.
4833 * Aliases:: Substituting one command for another.
4834 * Arrays:: Array Variables.
4835 * The Directory Stack:: History of visited directories.
4836 * Printing a Prompt:: Controlling the PS1 string.
4837 * The Restricted Shell:: A more controlled mode of shell execution.
4838 * Bash POSIX Mode:: Making Bash behave more closely to what
4839 the POSIX standard specifies.
4842 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
4847 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4848 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
4849 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
4851 All of the single-character options used with the `set' builtin
4852 (*note The Set Builtin::) can be used as options when the shell is
4853 invoked. In addition, there are several multi-character options that
4854 you can use. These options must appear on the command line before the
4855 single-character options to be recognized.
4858 Arrange for the debugger profile to be executed before the shell
4859 starts. Turns on extended debugging mode (see *note The Shopt
4860 Builtin:: for a description of the `extdebug' option to the `shopt'
4864 A list of all double-quoted strings preceded by `$' is printed on
4865 the standard output in the GNU `gettext' PO (portable object) file
4866 format. Equivalent to `-D' except for the output format.
4872 Display a usage message on standard output and exit successfully.
4874 `--init-file FILENAME'
4876 Execute commands from FILENAME (instead of `~/.bashrc') in an
4883 Do not use the GNU Readline library (*note Command Line Editing::)
4884 to read command lines when the shell is interactive.
4887 Don't load the system-wide startup file `/etc/profile' or any of
4888 the personal initialization files `~/.bash_profile',
4889 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
4893 Don't read the `~/.bashrc' initialization file in an interactive
4894 shell. This is on by default if the shell is invoked as `sh'.
4897 Change the behavior of Bash where the default operation differs
4898 from the POSIX standard to match the standard. This is intended
4899 to make Bash behave as a strict superset of that standard. *Note
4900 Bash POSIX Mode::, for a description of the Bash POSIX mode.
4903 Make the shell a restricted shell (*note The Restricted Shell::).
4906 Equivalent to `-v'. Print shell input lines as they're read.
4909 Show version information for this instance of Bash on the standard
4910 output and exit successfully.
4913 There are several single-character options that may be supplied at
4914 invocation which are not available with the `set' builtin.
4917 Read and execute commands from STRING after processing the
4918 options, then exit. Any remaining arguments are assigned to the
4919 positional parameters, starting with `$0'.
4922 Force the shell to run interactively. Interactive shells are
4923 described in *note Interactive Shells::.
4926 Make this shell act as if it had been directly invoked by login.
4927 When the shell is interactive, this is equivalent to starting a
4928 login shell with `exec -l bash'. When the shell is not
4929 interactive, the login shell startup files will be executed.
4930 `exec bash -l' or `exec bash --login' will replace the current
4931 shell with a Bash login shell. *Note Bash Startup Files::, for a
4932 description of the special behavior of a login shell.
4935 Make the shell a restricted shell (*note The Restricted Shell::).
4938 If this option is present, or if no arguments remain after option
4939 processing, then commands are read from the standard input. This
4940 option allows the positional parameters to be set when invoking an
4944 A list of all double-quoted strings preceded by `$' is printed on
4945 the standard output. These are the strings that are subject to
4946 language translation when the current locale is not `C' or `POSIX'
4947 (*note Locale Translation::). This implies the `-n' option; no
4948 commands will be executed.
4950 `[-+]O [SHOPT_OPTION]'
4951 SHOPT_OPTION is one of the shell options accepted by the `shopt'
4952 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
4953 `-O' sets the value of that option; `+O' unsets it. If
4954 SHOPT_OPTION is not supplied, the names and values of the shell
4955 options accepted by `shopt' are printed on the standard output.
4956 If the invocation option is `+O', the output is displayed in a
4957 format that may be reused as input.
4960 A `--' signals the end of options and disables further option
4961 processing. Any arguments after the `--' are treated as filenames
4965 A _login_ shell is one whose first character of argument zero is
4966 `-', or one invoked with the `--login' option.
4968 An _interactive_ shell is one started without non-option arguments,
4969 unless `-s' is specified, without specifying the `-c' option, and whose
4970 input and output are both connected to terminals (as determined by
4971 `isatty(3)'), or one started with the `-i' option. *Note Interactive
4972 Shells::, for more information.
4974 If arguments remain after option processing, and neither the `-c'
4975 nor the `-s' option has been supplied, the first argument is assumed to
4976 be the name of a file containing shell commands (*note Shell Scripts::).
4977 When Bash is invoked in this fashion, `$0' is set to the name of the
4978 file, and the positional parameters are set to the remaining arguments.
4979 Bash reads and executes commands from this file, then exits. Bash's
4980 exit status is the exit status of the last command executed in the
4981 script. If no commands are executed, the exit status is 0.
4984 File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
4986 6.2 Bash Startup Files
4987 ======================
4989 This section describes how Bash executes its startup files. If any of
4990 the files exist but cannot be read, Bash reports an error. Tildes are
4991 expanded in file names as described above under Tilde Expansion (*note
4994 Interactive shells are described in *note Interactive Shells::.
4996 Invoked as an interactive login shell, or with `--login'
4997 ........................................................
4999 When Bash is invoked as an interactive login shell, or as a
5000 non-interactive shell with the `--login' option, it first reads and
5001 executes commands from the file `/etc/profile', if that file exists.
5002 After reading that file, it looks for `~/.bash_profile',
5003 `~/.bash_login', and `~/.profile', in that order, and reads and
5004 executes commands from the first one that exists and is readable. The
5005 `--noprofile' option may be used when the shell is started to inhibit
5008 When a login shell exits, Bash reads and executes commands from the
5009 file `~/.bash_logout', if it exists.
5011 Invoked as an interactive non-login shell
5012 .........................................
5014 When an interactive shell that is not a login shell is started, Bash
5015 reads and executes commands from `~/.bashrc', if that file exists.
5016 This may be inhibited by using the `--norc' option. The `--rcfile
5017 FILE' option will force Bash to read and execute commands from FILE
5018 instead of `~/.bashrc'.
5020 So, typically, your `~/.bash_profile' contains the line
5021 `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi'
5022 after (or before) any login-specific initializations.
5024 Invoked non-interactively
5025 .........................
5027 When Bash is started non-interactively, to run a shell script, for
5028 example, it looks for the variable `BASH_ENV' in the environment,
5029 expands its value if it appears there, and uses the expanded value as
5030 the name of a file to read and execute. Bash behaves as if the
5031 following command were executed:
5032 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
5033 but the value of the `PATH' variable is not used to search for the
5036 As noted above, if a non-interactive shell is invoked with the
5037 `--login' option, Bash attempts to read and execute commands from the
5038 login shell startup files.
5040 Invoked with name `sh'
5041 ......................
5043 If Bash is invoked with the name `sh', it tries to mimic the startup
5044 behavior of historical versions of `sh' as closely as possible, while
5045 conforming to the POSIX standard as well.
5047 When invoked as an interactive login shell, or as a non-interactive
5048 shell with the `--login' option, it first attempts to read and execute
5049 commands from `/etc/profile' and `~/.profile', in that order. The
5050 `--noprofile' option may be used to inhibit this behavior. When
5051 invoked as an interactive shell with the name `sh', Bash looks for the
5052 variable `ENV', expands its value if it is defined, and uses the
5053 expanded value as the name of a file to read and execute. Since a
5054 shell invoked as `sh' does not attempt to read and execute commands
5055 from any other startup files, the `--rcfile' option has no effect. A
5056 non-interactive shell invoked with the name `sh' does not attempt to
5057 read any other startup files.
5059 When invoked as `sh', Bash enters POSIX mode after the startup files
5062 Invoked in POSIX mode
5063 .....................
5065 When Bash is started in POSIX mode, as with the `--posix' command line
5066 option, it follows the POSIX standard for startup files. In this mode,
5067 interactive shells expand the `ENV' variable and commands are read and
5068 executed from the file whose name is the expanded value. No other
5069 startup files are read.
5071 Invoked by remote shell daemon
5072 ..............................
5074 Bash attempts to determine when it is being run with its standard input
5075 connected to a network connection, as when executed by the remote shell
5076 daemon, usually `rshd', or the secure shell daemon `sshd'. If Bash
5077 determines it is being run in this fashion, it reads and executes
5078 commands from `~/.bashrc', if that file exists and is readable. It
5079 will not do this if invoked as `sh'. The `--norc' option may be used
5080 to inhibit this behavior, and the `--rcfile' option may be used to
5081 force another file to be read, but `rshd' does not generally invoke the
5082 shell with those options or allow them to be specified.
5084 Invoked with unequal effective and real UID/GIDs
5085 ................................................
5087 If Bash is started with the effective user (group) id not equal to the
5088 real user (group) id, and the `-p' option is not supplied, no startup
5089 files are read, shell functions are not inherited from the environment,
5090 the `SHELLOPTS', `BASHOPTS', `CDPATH', and `GLOBIGNORE' variables, if
5091 they appear in the environment, are ignored, and the effective user id
5092 is set to the real user id. If the `-p' option is supplied at
5093 invocation, the startup behavior is the same, but the effective user id
5097 File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
5099 6.3 Interactive Shells
5100 ======================
5104 * What is an Interactive Shell?:: What determines whether a shell is Interactive.
5105 * Is this Shell Interactive?:: How to tell if a shell is interactive.
5106 * Interactive Shell Behavior:: What changes in a interactive shell?
5109 File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
5111 6.3.1 What is an Interactive Shell?
5112 -----------------------------------
5114 An interactive shell is one started without non-option arguments,
5115 unless `-s' is specified, without specifying the `-c' option, and whose
5116 input and error output are both connected to terminals (as determined
5117 by `isatty(3)'), or one started with the `-i' option.
5119 An interactive shell generally reads from and writes to a user's
5122 The `-s' invocation option may be used to set the positional
5123 parameters when an interactive shell is started.
5126 File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
5128 6.3.2 Is this Shell Interactive?
5129 --------------------------------
5131 To determine within a startup script whether or not Bash is running
5132 interactively, test the value of the `-' special parameter. It
5133 contains `i' when the shell is interactive. For example:
5136 *i*) echo This shell is interactive ;;
5137 *) echo This shell is not interactive ;;
5140 Alternatively, startup scripts may examine the variable `PS1'; it is
5141 unset in non-interactive shells, and set in interactive shells. Thus:
5143 if [ -z "$PS1" ]; then
5144 echo This shell is not interactive
5146 echo This shell is interactive
5150 File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
5152 6.3.3 Interactive Shell Behavior
5153 --------------------------------
5155 When the shell is running interactively, it changes its behavior in
5158 1. Startup files are read and executed as described in *note Bash
5161 2. Job Control (*note Job Control::) is enabled by default. When job
5162 control is in effect, Bash ignores the keyboard-generated job
5163 control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'.
5165 3. Bash expands and displays `PS1' before reading the first line of a
5166 command, and expands and displays `PS2' before reading the second
5167 and subsequent lines of a multi-line command.
5169 4. Bash executes the value of the `PROMPT_COMMAND' variable as a
5170 command before printing the primary prompt, `$PS1' (*note Bash
5173 5. Readline (*note Command Line Editing::) is used to read commands
5174 from the user's terminal.
5176 6. Bash inspects the value of the `ignoreeof' option to `set -o'
5177 instead of exiting immediately when it receives an `EOF' on its
5178 standard input when reading a command (*note The Set Builtin::).
5180 7. Command history (*note Bash History Facilities::) and history
5181 expansion (*note History Interaction::) are enabled by default.
5182 Bash will save the command history to the file named by `$HISTFILE'
5183 when an interactive shell exits.
5185 8. Alias expansion (*note Aliases::) is performed by default.
5187 9. In the absence of any traps, Bash ignores `SIGTERM' (*note
5190 10. In the absence of any traps, `SIGINT' is caught and handled
5191 ((*note Signals::). `SIGINT' will interrupt some shell builtins.
5193 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if
5194 the `huponexit' shell option has been enabled (*note Signals::).
5196 12. The `-n' invocation option is ignored, and `set -n' has no effect
5197 (*note The Set Builtin::).
5199 13. Bash will check for mail periodically, depending on the values of
5200 the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note
5203 14. Expansion errors due to references to unbound shell variables after
5204 `set -u' has been enabled will not cause the shell to exit (*note
5207 15. The shell will not exit on expansion errors caused by VAR being
5208 unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter
5211 16. Redirection errors encountered by shell builtins will not cause the
5214 17. When running in POSIX mode, a special builtin returning an error
5215 status will not cause the shell to exit (*note Bash POSIX Mode::).
5217 18. A failed `exec' will not cause the shell to exit (*note Bourne
5220 19. Parser syntax errors will not cause the shell to exit.
5222 20. Simple spelling correction for directory arguments to the `cd'
5223 builtin is enabled by default (see the description of the `cdspell'
5224 option to the `shopt' builtin in *note The Shopt Builtin::).
5226 21. The shell will check the value of the `TMOUT' variable and exit if
5227 a command is not read within the specified number of seconds after
5228 printing `$PS1' (*note Bash Variables::).
5232 File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
5234 6.4 Bash Conditional Expressions
5235 ================================
5237 Conditional expressions are used by the `[[' compound command and the
5238 `test' and `[' builtin commands.
5240 Expressions may be unary or binary. Unary expressions are often
5241 used to examine the status of a file. There are string operators and
5242 numeric comparison operators as well. If the FILE argument to one of
5243 the primaries is of the form `/dev/fd/N', then file descriptor N is
5244 checked. If the FILE argument to one of the primaries is one of
5245 `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or
5246 2, respectively, is checked.
5248 When used with `[[', the `<' and `>' operators sort
5249 lexicographically using the current locale. The `test' command uses
5252 Unless otherwise specified, primaries that operate on files follow
5253 symbolic links and operate on the target of the link, rather than the
5257 True if FILE exists.
5260 True if FILE exists and is a block special file.
5263 True if FILE exists and is a character special file.
5266 True if FILE exists and is a directory.
5269 True if FILE exists.
5272 True if FILE exists and is a regular file.
5275 True if FILE exists and its set-group-id bit is set.
5278 True if FILE exists and is a symbolic link.
5281 True if FILE exists and its "sticky" bit is set.
5284 True if FILE exists and is a named pipe (FIFO).
5287 True if FILE exists and is readable.
5290 True if FILE exists and has a size greater than zero.
5293 True if file descriptor FD is open and refers to a terminal.
5296 True if FILE exists and its set-user-id bit is set.
5299 True if FILE exists and is writable.
5302 True if FILE exists and is executable.
5305 True if FILE exists and is owned by the effective group id.
5308 True if FILE exists and is a symbolic link.
5311 True if FILE exists and has been modified since it was last read.
5314 True if FILE exists and is owned by the effective user id.
5317 True if FILE exists and is a socket.
5320 True if FILE1 and FILE2 refer to the same device and inode numbers.
5323 True if FILE1 is newer (according to modification date) than
5324 FILE2, or if FILE1 exists and FILE2 does not.
5327 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
5331 True if the shell option OPTNAME is enabled. The list of options
5332 appears in the description of the `-o' option to the `set' builtin
5333 (*note The Set Builtin::).
5336 True if the shell variable VARNAME is set (has been assigned a
5340 True if the length of STRING is zero.
5344 True if the length of STRING is non-zero.
5346 `STRING1 == STRING2'
5348 True if the strings are equal. `=' should be used with the `test'
5349 command for POSIX conformance.
5351 `STRING1 != STRING2'
5352 True if the strings are not equal.
5355 True if STRING1 sorts before STRING2 lexicographically.
5358 True if STRING1 sorts after STRING2 lexicographically.
5361 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
5362 arithmetic binary operators return true if ARG1 is equal to, not
5363 equal to, less than, less than or equal to, greater than, or
5364 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
5365 positive or negative integers.
5369 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
5371 6.5 Shell Arithmetic
5372 ====================
5374 The shell allows arithmetic expressions to be evaluated, as one of the
5375 shell expansions or by the `let' and the `-i' option to the `declare'
5378 Evaluation is done in fixed-width integers with no check for
5379 overflow, though division by 0 is trapped and flagged as an error. The
5380 operators and their precedence, associativity, and values are the same
5381 as in the C language. The following list of operators is grouped into
5382 levels of equal-precedence operators. The levels are listed in order
5383 of decreasing precedence.
5386 variable post-increment and post-decrement
5389 variable pre-increment and pre-decrement
5392 unary minus and plus
5395 logical and bitwise negation
5401 multiplication, division, remainder
5404 addition, subtraction
5407 left and right bitwise shifts
5413 equality and inequality
5419 bitwise exclusive OR
5430 `expr ? expr : expr'
5431 conditional operator
5433 `= *= /= %= += -= <<= >>= &= ^= |='
5439 Shell variables are allowed as operands; parameter expansion is
5440 performed before the expression is evaluated. Within an expression,
5441 shell variables may also be referenced by name without using the
5442 parameter expansion syntax. A shell variable that is null or unset
5443 evaluates to 0 when referenced by name without using the parameter
5444 expansion syntax. The value of a variable is evaluated as an
5445 arithmetic expression when it is referenced, or when a variable which
5446 has been given the INTEGER attribute using `declare -i' is assigned a
5447 value. A null value evaluates to 0. A shell variable need not have
5448 its INTEGER attribute turned on to be used in an expression.
5450 Constants with a leading 0 are interpreted as octal numbers. A
5451 leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
5452 form [BASE`#']N, where the optional BASE is a decimal number between 2
5453 and 64 representing the arithmetic base, and N is a number in that
5454 base. If BASE`#' is omitted, then base 10 is used. The digits greater
5455 than 9 are represented by the lowercase letters, the uppercase letters,
5456 `@', and `_', in that order. If BASE is less than or equal to 36,
5457 lowercase and uppercase letters may be used interchangeably to
5458 represent numbers between 10 and 35.
5460 Operators are evaluated in order of precedence. Sub-expressions in
5461 parentheses are evaluated first and may override the precedence rules
5465 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
5470 ALIASES allow a string to be substituted for a word when it is used as
5471 the first word of a simple command. The shell maintains a list of
5472 aliases that may be set and unset with the `alias' and `unalias'
5475 The first word of each simple command, if unquoted, is checked to see
5476 if it has an alias. If so, that word is replaced by the text of the
5477 alias. The characters `/', `$', ``', `=' and any of the shell
5478 metacharacters or quoting characters listed above may not appear in an
5479 alias name. The replacement text may contain any valid shell input,
5480 including shell metacharacters. The first word of the replacement text
5481 is tested for aliases, but a word that is identical to an alias being
5482 expanded is not expanded a second time. This means that one may alias
5483 `ls' to `"ls -F"', for instance, and Bash does not try to recursively
5484 expand the replacement text. If the last character of the alias value
5485 is a space or tab character, then the next command word following the
5486 alias is also checked for alias expansion.
5488 Aliases are created and listed with the `alias' command, and removed
5489 with the `unalias' command.
5491 There is no mechanism for using arguments in the replacement text,
5492 as in `csh'. If arguments are needed, a shell function should be used
5493 (*note Shell Functions::).
5495 Aliases are not expanded when the shell is not interactive, unless
5496 the `expand_aliases' shell option is set using `shopt' (*note The Shopt
5499 The rules concerning the definition and use of aliases are somewhat
5500 confusing. Bash always reads at least one complete line of input
5501 before executing any of the commands on that line. Aliases are
5502 expanded when a command is read, not when it is executed. Therefore, an
5503 alias definition appearing on the same line as another command does not
5504 take effect until the next line of input is read. The commands
5505 following the alias definition on that line are not affected by the new
5506 alias. This behavior is also an issue when functions are executed.
5507 Aliases are expanded when a function definition is read, not when the
5508 function is executed, because a function definition is itself a
5509 compound command. As a consequence, aliases defined in a function are
5510 not available until after that function is executed. To be safe,
5511 always put alias definitions on a separate line, and do not use `alias'
5512 in compound commands.
5514 For almost every purpose, shell functions are preferred over aliases.
5517 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
5522 Bash provides one-dimensional indexed and associative array variables.
5523 Any variable may be used as an indexed array; the `declare' builtin
5524 will explicitly declare an array. There is no maximum limit on the
5525 size of an array, nor any requirement that members be indexed or
5526 assigned contiguously. Indexed arrays are referenced using integers
5527 (including arithmetic expressions (*note Shell Arithmetic::) and are
5528 zero-based; associative arrays use arbitrary strings.
5530 An indexed array is created automatically if any variable is
5531 assigned to using the syntax
5532 name[SUBSCRIPT]=VALUE
5534 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
5535 to a number. If SUBSCRIPT evaluates to a number less than zero, it is
5536 used as an offset from one greater than the array's maximum index (so a
5537 subcript of -1 refers to the last element of the array). To explicitly
5538 declare an array, use
5541 declare -a NAME[SUBSCRIPT]
5542 is also accepted; the SUBSCRIPT is ignored.
5544 Associative arrays are created using
5547 Attributes may be specified for an array variable using the
5548 `declare' and `readonly' builtins. Each attribute applies to all
5549 members of an array.
5551 Arrays are assigned to using compound assignments of the form
5552 name=(value1 ... valueN)
5553 where each VALUE is of the form `[SUBSCRIPT]='STRING. Indexed array
5554 assignments do not require the bracket and subscript. When assigning
5555 to indexed arrays, if the optional subscript is supplied, that index is
5556 assigned to; otherwise the index of the element assigned is the last
5557 index assigned to by the statement plus one. Indexing starts at zero.
5559 When assigning to an associative array, the subscript is required.
5561 This syntax is also accepted by the `declare' builtin. Individual
5562 array elements may be assigned to using the `name['SUBSCRIPT`]='VALUE
5563 syntax introduced above.
5565 Any element of an array may be referenced using
5566 `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
5567 with the shell's filename expansion operators. If the SUBSCRIPT is `@'
5568 or `*', the word expands to all members of the array NAME. These
5569 subscripts differ only when the word appears within double quotes. If
5570 the word is double-quoted, `${name[*]}' expands to a single word with
5571 the value of each array member separated by the first character of the
5572 `IFS' variable, and `${name[@]}' expands each element of NAME to a
5573 separate word. When there are no array members, `${name[@]}' expands
5574 to nothing. If the double-quoted expansion occurs within a word, the
5575 expansion of the first parameter is joined with the beginning part of
5576 the original word, and the expansion of the last parameter is joined
5577 with the last part of the original word. This is analogous to the
5578 expansion of the special parameters `@' and `*'.
5579 `${#name['SUBSCRIPT`]}' expands to the length of `${name['SUBSCRIPT`]}'.
5580 If SUBSCRIPT is `@' or `*', the expansion is the number of elements in
5581 the array. Referencing an array variable without a subscript is
5582 equivalent to referencing with a subscript of 0.
5584 An array variable is considered set if a subscript has been assigned
5585 a value. The null string is a valid value.
5587 The `unset' builtin is used to destroy arrays. `unset'
5588 NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. Care
5589 must be taken to avoid unwanted side effects caused by filename
5590 expansion. `unset' NAME, where NAME is an array, removes the entire
5591 array. A subscript of `*' or `@' also removes the entire array.
5593 The `declare', `local', and `readonly' builtins each accept a `-a'
5594 option to specify an indexed array and a `-A' option to specify an
5595 associative array. The `read' builtin accepts a `-a' option to assign
5596 a list of words read from the standard input to an array, and can read
5597 values from the standard input into individual array elements. The
5598 `set' and `declare' builtins display array values in a way that allows
5599 them to be reused as input.
5602 File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
5604 6.8 The Directory Stack
5605 =======================
5609 * Directory Stack Builtins:: Bash builtin commands to manipulate
5610 the directory stack.
5612 The directory stack is a list of recently-visited directories. The
5613 `pushd' builtin adds directories to the stack as it changes the current
5614 directory, and the `popd' builtin removes specified directories from
5615 the stack and changes the current directory to the directory removed.
5616 The `dirs' builtin displays the contents of the directory stack.
5618 The contents of the directory stack are also visible as the value of
5619 the `DIRSTACK' shell variable.
5622 File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
5624 6.8.1 Directory Stack Builtins
5625 ------------------------------
5628 dirs [+N | -N] [-clpv]
5629 Display the list of currently remembered directories. Directories
5630 are added to the list with the `pushd' command; the `popd' command
5631 removes directories from the list.
5633 Displays the Nth directory (counting from the left of the
5634 list printed by `dirs' when invoked without options), starting
5638 Displays the Nth directory (counting from the right of the
5639 list printed by `dirs' when invoked without options), starting
5643 Clears the directory stack by deleting all of the elements.
5646 Produces a longer listing; the default listing format uses a
5647 tilde to denote the home directory.
5650 Causes `dirs' to print the directory stack with one entry per
5654 Causes `dirs' to print the directory stack with one entry per
5655 line, prefixing each entry with its index in the stack.
5660 Remove the top entry from the directory stack, and `cd' to the new
5661 top directory. When no arguments are given, `popd' removes the
5662 top directory from the stack and performs a `cd' to the new top
5663 directory. The elements are numbered from 0 starting at the first
5664 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
5667 Removes the Nth directory (counting from the left of the list
5668 printed by `dirs'), starting with zero.
5671 Removes the Nth directory (counting from the right of the
5672 list printed by `dirs'), starting with zero.
5675 Suppresses the normal change of directory when removing
5676 directories from the stack, so that only the stack is
5680 pushd [-n] [+N | -N | DIR ]
5682 Save the current directory on the top of the directory stack and
5683 then `cd' to DIR. With no arguments, `pushd' exchanges the top
5687 Suppresses the normal change of directory when adding
5688 directories to the stack, so that only the stack is
5692 Brings the Nth directory (counting from the left of the list
5693 printed by `dirs', starting with zero) to the top of the list
5694 by rotating the stack.
5697 Brings the Nth directory (counting from the right of the list
5698 printed by `dirs', starting with zero) to the top of the list
5699 by rotating the stack.
5702 Makes the current working directory be the top of the stack,
5703 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
5707 File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
5709 6.9 Controlling the Prompt
5710 ==========================
5712 The value of the variable `PROMPT_COMMAND' is examined just before Bash
5713 prints each primary prompt. If `PROMPT_COMMAND' is set and has a
5714 non-null value, then the value is executed just as if it had been typed
5715 on the command line.
5717 In addition, the following table describes the special characters
5718 which can appear in the prompt variables:
5724 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
5727 The FORMAT is passed to `strftime'(3) and the result is inserted
5728 into the prompt string; an empty FORMAT results in a
5729 locale-specific time representation. The braces are required.
5732 An escape character.
5735 The hostname, up to the first `.'.
5741 The number of jobs currently managed by the shell.
5744 The basename of the shell's terminal device name.
5753 The name of the shell, the basename of `$0' (the portion following
5757 The time, in 24-hour HH:MM:SS format.
5760 The time, in 12-hour HH:MM:SS format.
5763 The time, in 12-hour am/pm format.
5766 The time, in 24-hour HH:MM format.
5769 The username of the current user.
5772 The version of Bash (e.g., 2.00)
5775 The release of Bash, version + patchlevel (e.g., 2.00.0)
5778 The current working directory, with `$HOME' abbreviated with a
5779 tilde (uses the `$PROMPT_DIRTRIM' variable).
5782 The basename of `$PWD', with `$HOME' abbreviated with a tilde.
5785 The history number of this command.
5788 The command number of this command.
5791 If the effective uid is 0, `#', otherwise `$'.
5794 The character whose ASCII code is the octal value NNN.
5800 Begin a sequence of non-printing characters. This could be used to
5801 embed a terminal control sequence into the prompt.
5804 End a sequence of non-printing characters.
5806 The command number and the history number are usually different: the
5807 history number of a command is its position in the history list, which
5808 may include commands restored from the history file (*note Bash History
5809 Facilities::), while the command number is the position in the sequence
5810 of commands executed during the current shell session.
5812 After the string is decoded, it is expanded via parameter expansion,
5813 command substitution, arithmetic expansion, and quote removal, subject
5814 to the value of the `promptvars' shell option (*note Bash Builtins::).
5817 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
5819 6.10 The Restricted Shell
5820 =========================
5822 If Bash is started with the name `rbash', or the `--restricted' or `-r'
5823 option is supplied at invocation, the shell becomes restricted. A
5824 restricted shell is used to set up an environment more controlled than
5825 the standard shell. A restricted shell behaves identically to `bash'
5826 with the exception that the following are disallowed or not performed:
5828 * Changing directories with the `cd' builtin.
5830 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
5831 `BASH_ENV' variables.
5833 * Specifying command names containing slashes.
5835 * Specifying a filename containing a slash as an argument to the `.'
5838 * Specifying a filename containing a slash as an argument to the `-p'
5839 option to the `hash' builtin command.
5841 * Importing function definitions from the shell environment at
5844 * Parsing the value of `SHELLOPTS' from the shell environment at
5847 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
5848 redirection operators.
5850 * Using the `exec' builtin to replace the shell with another command.
5852 * Adding or deleting builtin commands with the `-f' and `-d' options
5853 to the `enable' builtin.
5855 * Using the `enable' builtin command to enable disabled shell
5858 * Specifying the `-p' option to the `command' builtin.
5860 * Turning off restricted mode with `set +r' or `set +o restricted'.
5862 These restrictions are enforced after any startup files are read.
5864 When a command that is found to be a shell script is executed (*note
5865 Shell Scripts::), `rbash' turns off any restrictions in the shell
5866 spawned to execute the script.
5869 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
5871 6.11 Bash POSIX Mode
5872 ====================
5874 Starting Bash with the `--posix' command-line option or executing `set
5875 -o posix' while Bash is running will cause Bash to conform more closely
5876 to the POSIX standard by changing the behavior to match that specified
5877 by POSIX in areas where the Bash default differs.
5879 When invoked as `sh', Bash enters POSIX mode after reading the
5882 The following list is what's changed when `POSIX mode' is in effect:
5884 1. When a command in the hash table no longer exists, Bash will
5885 re-search `$PATH' to find the new location. This is also
5886 available with `shopt -s checkhash'.
5888 2. The message printed by the job control code and builtins when a job
5889 exits with a non-zero status is `Done(status)'.
5891 3. The message printed by the job control code and builtins when a job
5892 is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example,
5895 4. The `bg' builtin uses the required format to describe each job
5896 placed in the background, which does not include an indication of
5897 whether the job is the current or previous job.
5899 5. Reserved words appearing in a context where reserved words are
5900 recognized do not undergo alias expansion.
5902 6. The POSIX `PS1' and `PS2' expansions of `!' to the history number
5903 and `!!' to `!' are enabled, and parameter expansion is performed
5904 on the values of `PS1' and `PS2' regardless of the setting of the
5905 `promptvars' option.
5907 7. The POSIX startup files are executed (`$ENV') rather than the
5910 8. Tilde expansion is only performed on assignments preceding a
5911 command name, rather than on all assignment statements on the line.
5913 9. The default history file is `~/.sh_history' (this is the default
5914 value of `$HISTFILE').
5916 10. The output of `kill -l' prints all the signal names on a single
5917 line, separated by spaces, without the `SIG' prefix.
5919 11. The `kill' builtin does not accept signal names with a `SIG'
5922 12. Non-interactive shells exit if FILENAME in `.' FILENAME is not
5925 13. Non-interactive shells exit if a syntax error in an arithmetic
5926 expansion results in an invalid expression.
5928 14. Non-interactive shells exit if there is a syntax error in a script
5929 read with the `.' or `source' builtins, or in a string processed by
5932 15. Redirection operators do not perform filename expansion on the word
5933 in the redirection unless the shell is interactive.
5935 16. Redirection operators do not perform word splitting on the word in
5938 17. Function names must be valid shell `name's. That is, they may not
5939 contain characters other than letters, digits, and underscores, and
5940 may not start with a digit. Declaring a function with an invalid
5941 name causes a fatal syntax error in non-interactive shells.
5943 18. POSIX special builtins are found before shell functions during
5946 19. The `time' reserved word may be used by itself as a command. When
5947 used in this way, it displays timing statistics for the shell and
5948 its completed children. The `TIMEFORMAT' variable controls the
5949 format of the timing information.
5951 20. When parsing and expanding a ${...} expansion that appears within
5952 double quotes, single quotes are no longer special and cannot be
5953 used to quote a closing brace or other special character, unless
5954 the operator is one of those defined to perform pattern removal.
5955 In this case, they do not have to appear as matched pairs.
5957 21. The parser does not recognize `time' as a reserved word if the next
5958 token begins with a `-'.
5960 22. If a POSIX special builtin returns an error status, a
5961 non-interactive shell exits. The fatal errors are those listed in
5962 the POSIX standard, and include things like passing incorrect
5963 options, redirection errors, variable assignment errors for
5964 assignments preceding the command name, and so on.
5966 23. A non-interactive shell exits with an error status if a variable
5967 assignment error occurs when no command name follows the assignment
5968 statements. A variable assignment error occurs, for example, when
5969 trying to assign a value to a readonly variable.
5971 24. A non-interactive shell exists with an error status if a variable
5972 assignment error occurs in an assignment statement preceding a
5973 special builtin, but not with any other simple command.
5975 25. A non-interactive shell exits with an error status if the iteration
5976 variable in a `for' statement or the selection variable in a
5977 `select' statement is a readonly variable.
5979 26. Process substitution is not available.
5981 27. Assignment statements preceding POSIX special builtins persist in
5982 the shell environment after the builtin completes.
5984 28. Assignment statements preceding shell function calls persist in the
5985 shell environment after the function returns, as if a POSIX
5986 special builtin command had been executed.
5988 29. The `export' and `readonly' builtin commands display their output
5989 in the format required by POSIX.
5991 30. The `trap' builtin displays signal names without the leading `SIG'.
5993 31. The `trap' builtin doesn't check the first argument for a possible
5994 signal specification and revert the signal handling to the original
5995 disposition if it is, unless that argument consists solely of
5996 digits and is a valid signal number. If users want to reset the
5997 handler for a given signal to the original disposition, they
5998 should use `-' as the first argument.
6000 32. The `.' and `source' builtins do not search the current directory
6001 for the filename argument if it is not found by searching `PATH'.
6003 33. Subshells spawned to execute command substitutions inherit the
6004 value of the `-e' option from the parent shell. When not in POSIX
6005 mode, Bash clears the `-e' option in such subshells.
6007 34. Alias expansion is always enabled, even in non-interactive shells.
6009 35. When the `alias' builtin displays alias definitions, it does not
6010 display them with a leading `alias ' unless the `-p' option is
6013 36. When the `set' builtin is invoked without options, it does not
6014 display shell function names and definitions.
6016 37. When the `set' builtin is invoked without options, it displays
6017 variable values without quotes, unless they contain shell
6018 metacharacters, even if the result contains nonprinting characters.
6020 38. When the `cd' builtin is invoked in LOGICAL mode, and the pathname
6021 constructed from `$PWD' and the directory name supplied as an
6022 argument does not refer to an existing directory, `cd' will fail
6023 instead of falling back to PHYSICAL mode.
6025 39. The `pwd' builtin verifies that the value it prints is the same as
6026 the current directory, even if it is not asked to check the file
6027 system with the `-P' option.
6029 40. When listing the history, the `fc' builtin does not include an
6030 indication of whether or not a history entry has been modified.
6032 41. The default editor used by `fc' is `ed'.
6034 42. The `type' and `command' builtins will not report a non-executable
6035 file as having been found, though the shell will attempt to
6036 execute such a file if it is the only so-named file found in
6039 43. The `vi' editing mode will invoke the `vi' editor directly when
6040 the `v' command is run, instead of checking `$VISUAL' and
6043 44. When the `xpg_echo' option is enabled, Bash does not attempt to
6044 interpret any arguments to `echo' as options. Each argument is
6045 displayed, after escape characters are converted.
6047 45. The `ulimit' builtin uses a block size of 512 bytes for the `-c'
6050 46. The arrival of `SIGCHLD' when a trap is set on `SIGCHLD' does not
6051 interrupt the `wait' builtin and cause it to return immediately.
6052 The trap command is run once for each child that exits.
6055 There is other POSIX behavior that Bash does not implement by
6056 default even when in POSIX mode. Specifically:
6058 1. The `fc' builtin checks `$EDITOR' as a program to edit history
6059 entries if `FCEDIT' is unset, rather than defaulting directly to
6060 `ed'. `fc' uses `ed' if `EDITOR' is unset.
6062 2. As noted above, Bash requires the `xpg_echo' option to be enabled
6063 for the `echo' builtin to be fully conformant.
6066 Bash can be configured to be POSIX-conformant by default, by
6067 specifying the `--enable-strict-posix-default' to `configure' when
6068 building (*note Optional Features::).
6071 File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
6076 This chapter discusses what job control is, how it works, and how Bash
6077 allows you to access its facilities.
6081 * Job Control Basics:: How job control works.
6082 * Job Control Builtins:: Bash builtin commands used to interact
6084 * Job Control Variables:: Variables Bash uses to customize job
6088 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
6090 7.1 Job Control Basics
6091 ======================
6093 Job control refers to the ability to selectively stop (suspend) the
6094 execution of processes and continue (resume) their execution at a later
6095 point. A user typically employs this facility via an interactive
6096 interface supplied jointly by the operating system kernel's terminal
6099 The shell associates a JOB with each pipeline. It keeps a table of
6100 currently executing jobs, which may be listed with the `jobs' command.
6101 When Bash starts a job asynchronously, it prints a line that looks like:
6103 indicating that this job is job number 1 and that the process ID of
6104 the last process in the pipeline associated with this job is 25647.
6105 All of the processes in a single pipeline are members of the same job.
6106 Bash uses the JOB abstraction as the basis for job control.
6108 To facilitate the implementation of the user interface to job
6109 control, the operating system maintains the notion of a current terminal
6110 process group ID. Members of this process group (processes whose
6111 process group ID is equal to the current terminal process group ID)
6112 receive keyboard-generated signals such as `SIGINT'. These processes
6113 are said to be in the foreground. Background processes are those whose
6114 process group ID differs from the terminal's; such processes are immune
6115 to keyboard-generated signals. Only foreground processes are allowed
6116 to read from or, if the user so specifies with `stty tostop', write to
6117 the terminal. Background processes which attempt to read from (write
6118 to when `stty tostop' is in effect) the terminal are sent a `SIGTTIN'
6119 (`SIGTTOU') signal by the kernel's terminal driver, which, unless
6120 caught, suspends the process.
6122 If the operating system on which Bash is running supports job
6123 control, Bash contains facilities to use it. Typing the SUSPEND
6124 character (typically `^Z', Control-Z) while a process is running causes
6125 that process to be stopped and returns control to Bash. Typing the
6126 DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
6127 process to be stopped when it attempts to read input from the terminal,
6128 and control to be returned to Bash. The user then manipulates the
6129 state of this job, using the `bg' command to continue it in the
6130 background, the `fg' command to continue it in the foreground, or the
6131 `kill' command to kill it. A `^Z' takes effect immediately, and has
6132 the additional side effect of causing pending output and typeahead to
6135 There are a number of ways to refer to a job in the shell. The
6136 character `%' introduces a job specification (JOBSPEC).
6138 Job number `n' may be referred to as `%n'. The symbols `%%' and
6139 `%+' refer to the shell's notion of the current job, which is the last
6140 job stopped while it was in the foreground or started in the background.
6141 A single `%' (with no accompanying job specification) also refers to
6142 the current job. The previous job may be referenced using `%-'. If
6143 there is only a single job, `%+' and `%-' can both be used to refer to
6144 that job. In output pertaining to jobs (e.g., the output of the `jobs'
6145 command), the current job is always flagged with a `+', and the
6146 previous job with a `-'.
6148 A job may also be referred to using a prefix of the name used to
6149 start it, or using a substring that appears in its command line. For
6150 example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other
6151 hand, refers to any job containing the string `ce' in its command line.
6152 If the prefix or substring matches more than one job, Bash reports an
6155 Simply naming a job can be used to bring it into the foreground:
6156 `%1' is a synonym for `fg %1', bringing job 1 from the background into
6157 the foreground. Similarly, `%1 &' resumes job 1 in the background,
6158 equivalent to `bg %1'
6160 The shell learns immediately whenever a job changes state.
6161 Normally, Bash waits until it is about to print a prompt before
6162 reporting changes in a job's status so as to not interrupt any other
6163 output. If the `-b' option to the `set' builtin is enabled, Bash
6164 reports such changes immediately (*note The Set Builtin::). Any trap
6165 on `SIGCHLD' is executed for each child process that exits.
6167 If an attempt to exit Bash is made while jobs are stopped, (or
6168 running, if the `checkjobs' option is enabled - see *note The Shopt
6169 Builtin::), the shell prints a warning message, and if the `checkjobs'
6170 option is enabled, lists the jobs and their statuses. The `jobs'
6171 command may then be used to inspect their status. If a second attempt
6172 to exit is made without an intervening command, Bash does not print
6173 another warning, and any stopped jobs are terminated.
6176 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
6178 7.2 Job Control Builtins
6179 ========================
6183 Resume each suspended job JOBSPEC in the background, as if it had
6184 been started with `&'. If JOBSPEC is not supplied, the current
6185 job is used. The return status is zero unless it is run when job
6186 control is not enabled, or, when run with job control enabled, any
6187 JOBSPEC was not found or specifies a job that was started without
6192 Resume the job JOBSPEC in the foreground and make it the current
6193 job. If JOBSPEC is not supplied, the current job is used. The
6194 return status is that of the command placed into the foreground,
6195 or non-zero if run when job control is disabled or, when run with
6196 job control enabled, JOBSPEC does not specify a valid job or
6197 JOBSPEC specifies a job that was started without job control.
6200 jobs [-lnprs] [JOBSPEC]
6201 jobs -x COMMAND [ARGUMENTS]
6203 The first form lists the active jobs. The options have the
6207 List process IDs in addition to the normal information.
6210 Display information only about jobs that have changed status
6211 since the user was last notified of their status.
6214 List only the process ID of the job's process group leader.
6217 Restrict output to running jobs.
6220 Restrict output to stopped jobs.
6222 If JOBSPEC is given, output is restricted to information about
6223 that job. If JOBSPEC is not supplied, the status of all jobs is
6226 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
6227 in COMMAND or ARGUMENTS with the corresponding process group ID,
6228 and executes COMMAND, passing it ARGUMENTs, returning its exit
6232 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
6233 kill -l [EXIT_STATUS]
6234 Send a signal specified by SIGSPEC or SIGNUM to the process named
6235 by job specification JOBSPEC or process ID PID. SIGSPEC is either
6236 a case-insensitive signal name such as `SIGINT' (with or without
6237 the `SIG' prefix) or a signal number; SIGNUM is a signal number.
6238 If SIGSPEC and SIGNUM are not present, `SIGTERM' is used. The
6239 `-l' option lists the signal names. If any arguments are supplied
6240 when `-l' is given, the names of the signals corresponding to the
6241 arguments are listed, and the return status is zero. EXIT_STATUS
6242 is a number specifying a signal number or the exit status of a
6243 process terminated by a signal. The return status is zero if at
6244 least one signal was successfully sent, or non-zero if an error
6245 occurs or an invalid option is encountered.
6248 wait [JOBSPEC or PID ...]
6249 Wait until the child process specified by each process ID PID or
6250 job specification JOBSPEC exits and return the exit status of the
6251 last command waited for. If a job spec is given, all processes in
6252 the job are waited for. If no arguments are given, all currently
6253 active child processes are waited for, and the return status is
6254 zero. If neither JOBSPEC nor PID specifies an active child process
6255 of the shell, the return status is 127.
6258 disown [-ar] [-h] [JOBSPEC ...]
6259 Without options, each JOBSPEC is removed from the table of active
6260 jobs. If the `-h' option is given, the job is not removed from
6261 the table, but is marked so that `SIGHUP' is not sent to the job
6262 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
6263 neither the `-a' nor `-r' option is supplied, the current job is
6264 used. If no JOBSPEC is supplied, the `-a' option means to remove
6265 or mark all jobs; the `-r' option without a JOBSPEC argument
6266 restricts operation to running jobs.
6270 Suspend the execution of this shell until it receives a `SIGCONT'
6271 signal. A login shell cannot be suspended; the `-f' option can be
6272 used to override this and force the suspension.
6275 When job control is not active, the `kill' and `wait' builtins do
6276 not accept JOBSPEC arguments. They must be supplied process IDs.
6279 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
6281 7.3 Job Control Variables
6282 =========================
6285 This variable controls how the shell interacts with the user and
6286 job control. If this variable exists then single word simple
6287 commands without redirections are treated as candidates for
6288 resumption of an existing job. There is no ambiguity allowed; if
6289 there is more than one job beginning with the string typed, then
6290 the most recently accessed job will be selected. The name of a
6291 stopped job, in this context, is the command line used to start
6292 it. If this variable is set to the value `exact', the string
6293 supplied must match the name of a stopped job exactly; if set to
6294 `substring', the string supplied needs to match a substring of the
6295 name of a stopped job. The `substring' value provides
6296 functionality analogous to the `%?' job ID (*note Job Control
6297 Basics::). If set to any other value, the supplied string must be
6298 a prefix of a stopped job's name; this provides functionality
6299 analogous to the `%' job ID.
6303 File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
6305 8 Command Line Editing
6306 **********************
6308 This chapter describes the basic features of the GNU command line
6309 editing interface. Command line editing is provided by the Readline
6310 library, which is used by several different programs, including Bash.
6311 Command line editing is enabled by default when using an interactive
6312 shell, unless the `--noediting' option is supplied at shell invocation.
6313 Line editing is also used when using the `-e' option to the `read'
6314 builtin command (*note Bash Builtins::). By default, the line editing
6315 commands are similar to those of Emacs. A vi-style line editing
6316 interface is also available. Line editing can be enabled at any time
6317 using the `-o emacs' or `-o vi' options to the `set' builtin command
6318 (*note The Set Builtin::), or disabled using the `+o emacs' or `+o vi'
6323 * Introduction and Notation:: Notation used in this text.
6324 * Readline Interaction:: The minimum set of commands for editing a line.
6325 * Readline Init File:: Customizing Readline from a user's view.
6326 * Bindable Readline Commands:: A description of most of the Readline commands
6327 available for binding
6328 * Readline vi Mode:: A short description of how to make Readline
6329 behave like the vi editor.
6331 * Programmable Completion:: How to specify the possible completions for
6333 * Programmable Completion Builtins:: Builtin commands to specify how to
6334 complete arguments for a particular command.
6337 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
6339 8.1 Introduction to Line Editing
6340 ================================
6342 The following paragraphs describe the notation used to represent
6345 The text `C-k' is read as `Control-K' and describes the character
6346 produced when the <k> key is pressed while the Control key is depressed.
6348 The text `M-k' is read as `Meta-K' and describes the character
6349 produced when the Meta key (if you have one) is depressed, and the <k>
6350 key is pressed. The Meta key is labeled <ALT> on many keyboards. On
6351 keyboards with two keys labeled <ALT> (usually to either side of the
6352 space bar), the <ALT> on the left side is generally set to work as a
6353 Meta key. The <ALT> key on the right may also be configured to work as
6354 a Meta key or may be configured as some other modifier, such as a
6355 Compose key for typing accented characters.
6357 If you do not have a Meta or <ALT> key, or another key working as a
6358 Meta key, the identical keystroke can be generated by typing <ESC>
6359 _first_, and then typing <k>. Either process is known as "metafying"
6362 The text `M-C-k' is read as `Meta-Control-k' and describes the
6363 character produced by "metafying" `C-k'.
6365 In addition, several keys have their own names. Specifically,
6366 <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
6367 when seen in this text, or in an init file (*note Readline Init File::).
6368 If your keyboard lacks a <LFD> key, typing <C-j> will produce the
6369 desired character. The <RET> key may be labeled <Return> or <Enter> on
6373 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
6375 8.2 Readline Interaction
6376 ========================
6378 Often during an interactive session you type in a long line of text,
6379 only to notice that the first word on the line is misspelled. The
6380 Readline library gives you a set of commands for manipulating the text
6381 as you type it in, allowing you to just fix your typo, and not forcing
6382 you to retype the majority of the line. Using these editing commands,
6383 you move the cursor to the place that needs correction, and delete or
6384 insert the text of the corrections. Then, when you are satisfied with
6385 the line, you simply press <RET>. You do not have to be at the end of
6386 the line to press <RET>; the entire line is accepted regardless of the
6387 location of the cursor within the line.
6391 * Readline Bare Essentials:: The least you need to know about Readline.
6392 * Readline Movement Commands:: Moving about the input line.
6393 * Readline Killing Commands:: How to delete text, and how to get it back!
6394 * Readline Arguments:: Giving numeric arguments to commands.
6395 * Searching:: Searching through previous lines.
6398 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
6400 8.2.1 Readline Bare Essentials
6401 ------------------------------
6403 In order to enter characters into the line, simply type them. The typed
6404 character appears where the cursor was, and then the cursor moves one
6405 space to the right. If you mistype a character, you can use your erase
6406 character to back up and delete the mistyped character.
6408 Sometimes you may mistype a character, and not notice the error
6409 until you have typed several other characters. In that case, you can
6410 type `C-b' to move the cursor to the left, and then correct your
6411 mistake. Afterwards, you can move the cursor to the right with `C-f'.
6413 When you add text in the middle of a line, you will notice that
6414 characters to the right of the cursor are `pushed over' to make room
6415 for the text that you have inserted. Likewise, when you delete text
6416 behind the cursor, characters to the right of the cursor are `pulled
6417 back' to fill in the blank space created by the removal of the text. A
6418 list of the bare essentials for editing the text of an input line
6422 Move back one character.
6425 Move forward one character.
6427 <DEL> or <Backspace>
6428 Delete the character to the left of the cursor.
6431 Delete the character underneath the cursor.
6434 Insert the character into the line at the cursor.
6437 Undo the last editing command. You can undo all the way back to an
6440 (Depending on your configuration, the <Backspace> key be set to delete
6441 the character to the left of the cursor and the <DEL> key set to delete
6442 the character underneath the cursor, like `C-d', rather than the
6443 character to the left of the cursor.)
6446 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
6448 8.2.2 Readline Movement Commands
6449 --------------------------------
6451 The above table describes the most basic keystrokes that you need in
6452 order to do editing of the input line. For your convenience, many
6453 other commands have been added in addition to `C-b', `C-f', `C-d', and
6454 <DEL>. Here are some commands for moving more rapidly about the line.
6457 Move to the start of the line.
6460 Move to the end of the line.
6463 Move forward a word, where a word is composed of letters and
6467 Move backward a word.
6470 Clear the screen, reprinting the current line at the top.
6472 Notice how `C-f' moves forward a character, while `M-f' moves
6473 forward a word. It is a loose convention that control keystrokes
6474 operate on characters while meta keystrokes operate on words.
6477 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
6479 8.2.3 Readline Killing Commands
6480 -------------------------------
6482 "Killing" text means to delete the text from the line, but to save it
6483 away for later use, usually by "yanking" (re-inserting) it back into
6484 the line. (`Cut' and `paste' are more recent jargon for `kill' and
6487 If the description for a command says that it `kills' text, then you
6488 can be sure that you can get the text back in a different (or the same)
6491 When you use a kill command, the text is saved in a "kill-ring".
6492 Any number of consecutive kills save all of the killed text together, so
6493 that when you yank it back, you get it all. The kill ring is not line
6494 specific; the text that you killed on a previously typed line is
6495 available to be yanked back later, when you are typing another line.
6497 Here is the list of commands for killing text.
6500 Kill the text from the current cursor position to the end of the
6504 Kill from the cursor to the end of the current word, or, if between
6505 words, to the end of the next word. Word boundaries are the same
6506 as those used by `M-f'.
6509 Kill from the cursor the start of the current word, or, if between
6510 words, to the start of the previous word. Word boundaries are the
6511 same as those used by `M-b'.
6514 Kill from the cursor to the previous whitespace. This is
6515 different than `M-<DEL>' because the word boundaries differ.
6518 Here is how to "yank" the text back into the line. Yanking means to
6519 copy the most-recently-killed text from the kill buffer.
6522 Yank the most recently killed text back into the buffer at the
6526 Rotate the kill-ring, and yank the new top. You can only do this
6527 if the prior command is `C-y' or `M-y'.
6530 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
6532 8.2.4 Readline Arguments
6533 ------------------------
6535 You can pass numeric arguments to Readline commands. Sometimes the
6536 argument acts as a repeat count, other times it is the sign of the
6537 argument that is significant. If you pass a negative argument to a
6538 command which normally acts in a forward direction, that command will
6539 act in a backward direction. For example, to kill text back to the
6540 start of the line, you might type `M-- C-k'.
6542 The general way to pass numeric arguments to a command is to type
6543 meta digits before the command. If the first `digit' typed is a minus
6544 sign (`-'), then the sign of the argument will be negative. Once you
6545 have typed one meta digit to get the argument started, you can type the
6546 remainder of the digits, and then the command. For example, to give
6547 the `C-d' command an argument of 10, you could type `M-1 0 C-d', which
6548 will delete the next ten characters on the input line.
6551 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
6553 8.2.5 Searching for Commands in the History
6554 -------------------------------------------
6556 Readline provides commands for searching through the command history
6557 (*note Bash History Facilities::) for lines containing a specified
6558 string. There are two search modes: "incremental" and
6561 Incremental searches begin before the user has finished typing the
6562 search string. As each character of the search string is typed,
6563 Readline displays the next entry from the history matching the string
6564 typed so far. An incremental search requires only as many characters
6565 as needed to find the desired history entry. To search backward in the
6566 history for a particular string, type `C-r'. Typing `C-s' searches
6567 forward through the history. The characters present in the value of
6568 the `isearch-terminators' variable are used to terminate an incremental
6569 search. If that variable has not been assigned a value, the <ESC> and
6570 `C-J' characters will terminate an incremental search. `C-g' will
6571 abort an incremental search and restore the original line. When the
6572 search is terminated, the history entry containing the search string
6573 becomes the current line.
6575 To find other matching entries in the history list, type `C-r' or
6576 `C-s' as appropriate. This will search backward or forward in the
6577 history for the next entry matching the search string typed so far.
6578 Any other key sequence bound to a Readline command will terminate the
6579 search and execute that command. For instance, a <RET> will terminate
6580 the search and accept the line, thereby executing the command from the
6581 history list. A movement command will terminate the search, make the
6582 last line found the current line, and begin editing.
6584 Readline remembers the last incremental search string. If two
6585 `C-r's are typed without any intervening characters defining a new
6586 search string, any remembered search string is used.
6588 Non-incremental searches read the entire search string before
6589 starting to search for matching history lines. The search string may be
6590 typed by the user or be part of the contents of the current line.
6593 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
6595 8.3 Readline Init File
6596 ======================
6598 Although the Readline library comes with a set of Emacs-like
6599 keybindings installed by default, it is possible to use a different set
6600 of keybindings. Any user can customize programs that use Readline by
6601 putting commands in an "inputrc" file, conventionally in his home
6602 directory. The name of this file is taken from the value of the shell
6603 variable `INPUTRC'. If that variable is unset, the default is
6604 `~/.inputrc'. If that file does not exist or cannot be read, the
6605 ultimate default is `/etc/inputrc'.
6607 When a program which uses the Readline library starts up, the init
6608 file is read, and the key bindings are set.
6610 In addition, the `C-x C-r' command re-reads this init file, thus
6611 incorporating any changes that you might have made to it.
6615 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
6617 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
6619 * Sample Init File:: An example inputrc file.
6622 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
6624 8.3.1 Readline Init File Syntax
6625 -------------------------------
6627 There are only a few basic constructs allowed in the Readline init
6628 file. Blank lines are ignored. Lines beginning with a `#' are
6629 comments. Lines beginning with a `$' indicate conditional constructs
6630 (*note Conditional Init Constructs::). Other lines denote variable
6631 settings and key bindings.
6634 You can modify the run-time behavior of Readline by altering the
6635 values of variables in Readline using the `set' command within the
6636 init file. The syntax is simple:
6640 Here, for example, is how to change from the default Emacs-like
6641 key binding to use `vi' line editing commands:
6645 Variable names and values, where appropriate, are recognized
6646 without regard to case. Unrecognized variable names are ignored.
6648 Boolean variables (those that can be set to on or off) are set to
6649 on if the value is null or empty, ON (case-insensitive), or 1.
6650 Any other value results in the variable being set to off.
6652 The `bind -V' command lists the current Readline variable names
6653 and values. *Note Bash Builtins::.
6655 A great deal of run-time behavior is changeable with the following
6659 Controls what happens when Readline wants to ring the
6660 terminal bell. If set to `none', Readline never rings the
6661 bell. If set to `visible', Readline uses a visible bell if
6662 one is available. If set to `audible' (the default),
6663 Readline attempts to ring the terminal's bell.
6665 `bind-tty-special-chars'
6666 If set to `on', Readline attempts to bind the control
6667 characters treated specially by the kernel's terminal driver
6668 to their Readline equivalents.
6671 The string to insert at the beginning of the line when the
6672 `insert-comment' command is executed. The default value is
6675 `completion-display-width'
6676 The number of screen columns used to display possible matches
6677 when performing completion. The value is ignored if it is
6678 less than 0 or greater than the terminal screen width. A
6679 value of 0 will cause matches to be displayed one per line.
6680 The default value is -1.
6682 `completion-ignore-case'
6683 If set to `on', Readline performs filename matching and
6684 completion in a case-insensitive fashion. The default value
6687 `completion-map-case'
6688 If set to `on', and COMPLETION-IGNORE-CASE is enabled,
6689 Readline treats hyphens (`-') and underscores (`_') as
6690 equivalent when performing case-insensitive filename matching
6693 `completion-prefix-display-length'
6694 The length in characters of the common prefix of a list of
6695 possible completions that is displayed without modification.
6696 When set to a value greater than zero, common prefixes longer
6697 than this value are replaced with an ellipsis when displaying
6698 possible completions.
6700 `completion-query-items'
6701 The number of possible completions that determines when the
6702 user is asked whether the list of possibilities should be
6703 displayed. If the number of possible completions is greater
6704 than this value, Readline will ask the user whether or not he
6705 wishes to view them; otherwise, they are simply listed. This
6706 variable must be set to an integer value greater than or
6707 equal to 0. A negative value means Readline should never ask.
6708 The default limit is `100'.
6711 If set to `on', Readline will convert characters with the
6712 eighth bit set to an ASCII key sequence by stripping the
6713 eighth bit and prefixing an <ESC> character, converting them
6714 to a meta-prefixed key sequence. The default value is `on'.
6716 `disable-completion'
6717 If set to `On', Readline will inhibit word completion.
6718 Completion characters will be inserted into the line as if
6719 they had been mapped to `self-insert'. The default is `off'.
6722 The `editing-mode' variable controls which default set of key
6723 bindings is used. By default, Readline starts up in Emacs
6724 editing mode, where the keystrokes are most similar to Emacs.
6725 This variable can be set to either `emacs' or `vi'.
6727 `echo-control-characters'
6728 When set to `on', on operating systems that indicate they
6729 support it, readline echoes a character corresponding to a
6730 signal generated from the keyboard. The default is `on'.
6733 When set to `on', Readline will try to enable the application
6734 keypad when it is called. Some systems need this to enable
6735 the arrow keys. The default is `off'.
6738 When set to `on', Readline will try to enable any meta
6739 modifier key the terminal claims to support when it is
6740 called. On many terminals, the meta key is used to send
6741 eight-bit characters. The default is `on'.
6744 If set to `on', tilde expansion is performed when Readline
6745 attempts word completion. The default is `off'.
6747 `history-preserve-point'
6748 If set to `on', the history code attempts to place the point
6749 (the current cursor position) at the same location on each
6750 history line retrieved with `previous-history' or
6751 `next-history'. The default is `off'.
6754 Set the maximum number of history entries saved in the
6755 history list. If set to zero, the number of entries in the
6756 history list is not limited.
6758 `horizontal-scroll-mode'
6759 This variable can be set to either `on' or `off'. Setting it
6760 to `on' means that the text of the lines being edited will
6761 scroll horizontally on a single screen line when they are
6762 longer than the width of the screen, instead of wrapping onto
6763 a new screen line. By default, this variable is set to `off'.
6766 If set to `on', Readline will enable eight-bit input (it will
6767 not clear the eighth bit in the characters it reads),
6768 regardless of what the terminal claims it can support. The
6769 default value is `off'. The name `meta-flag' is a synonym
6772 `isearch-terminators'
6773 The string of characters that should terminate an incremental
6774 search without subsequently executing the character as a
6775 command (*note Searching::). If this variable has not been
6776 given a value, the characters <ESC> and `C-J' will terminate
6777 an incremental search.
6780 Sets Readline's idea of the current keymap for key binding
6781 commands. Acceptable `keymap' names are `emacs',
6782 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move',
6783 `vi-command', and `vi-insert'. `vi' is equivalent to
6784 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
6785 default value is `emacs'. The value of the `editing-mode'
6786 variable also affects the default keymap.
6789 If set to `on', completed directory names have a slash
6790 appended. The default is `on'.
6792 `mark-modified-lines'
6793 This variable, when set to `on', causes Readline to display an
6794 asterisk (`*') at the start of history lines which have been
6795 modified. This variable is `off' by default.
6797 `mark-symlinked-directories'
6798 If set to `on', completed names which are symbolic links to
6799 directories have a slash appended (subject to the value of
6800 `mark-directories'). The default is `off'.
6802 `match-hidden-files'
6803 This variable, when set to `on', causes Readline to match
6804 files whose names begin with a `.' (hidden files) when
6805 performing filename completion. If set to `off', the leading
6806 `.' must be supplied by the user in the filename to be
6807 completed. This variable is `on' by default.
6809 `menu-complete-display-prefix'
6810 If set to `on', menu completion displays the common prefix of
6811 the list of possible completions (which may be empty) before
6812 cycling through the list. The default is `off'.
6815 If set to `on', Readline will display characters with the
6816 eighth bit set directly rather than as a meta-prefixed escape
6817 sequence. The default is `off'.
6820 If set to `on', Readline uses an internal `more'-like pager
6821 to display a screenful of possible completions at a time.
6822 This variable is `on' by default.
6824 `print-completions-horizontally'
6825 If set to `on', Readline will display completions with matches
6826 sorted horizontally in alphabetical order, rather than down
6827 the screen. The default is `off'.
6829 `revert-all-at-newline'
6830 If set to `on', Readline will undo all changes to history
6831 lines before returning when `accept-line' is executed. By
6832 default, history lines may be modified and retain individual
6833 undo lists across calls to `readline'. The default is `off'.
6835 `show-all-if-ambiguous'
6836 This alters the default behavior of the completion functions.
6837 If set to `on', words which have more than one possible
6838 completion cause the matches to be listed immediately instead
6839 of ringing the bell. The default value is `off'.
6841 `show-all-if-unmodified'
6842 This alters the default behavior of the completion functions
6843 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
6844 `on', words which have more than one possible completion
6845 without any possible partial completion (the possible
6846 completions don't share a common prefix) cause the matches to
6847 be listed immediately instead of ringing the bell. The
6848 default value is `off'.
6850 `skip-completed-text'
6851 If set to `on', this alters the default completion behavior
6852 when inserting a single match into the line. It's only
6853 active when performing completion in the middle of a word.
6854 If enabled, readline does not insert characters from the
6855 completion that match characters after point in the word
6856 being completed, so portions of the word following the cursor
6857 are not duplicated. For instance, if this is enabled,
6858 attempting completion when the cursor is after the `e' in
6859 `Makefile' will result in `Makefile' rather than
6860 `Makefilefile', assuming there is a single possible
6861 completion. The default value is `off'.
6864 If set to `on', a character denoting a file's type is
6865 appended to the filename when listing possible completions.
6866 The default is `off'.
6870 The syntax for controlling key bindings in the init file is
6871 simple. First you need to find the name of the command that you
6872 want to change. The following sections contain tables of the
6873 command name, the default keybinding, if any, and a short
6874 description of what the command does.
6876 Once you know the name of the command, simply place on a line in
6877 the init file the name of the key you wish to bind the command to,
6878 a colon, and then the name of the command. There can be no space
6879 between the key name and the colon - that will be interpreted as
6880 part of the key name. The name of the key can be expressed in
6881 different ways, depending on what you find most comfortable.
6883 In addition to command names, readline allows keys to be bound to
6884 a string that is inserted when the key is pressed (a MACRO).
6886 The `bind -p' command displays Readline function names and
6887 bindings in a format that can put directly into an initialization
6888 file. *Note Bash Builtins::.
6890 KEYNAME: FUNCTION-NAME or MACRO
6891 KEYNAME is the name of a key spelled out in English. For
6893 Control-u: universal-argument
6894 Meta-Rubout: backward-kill-word
6895 Control-o: "> output"
6897 In the above example, `C-u' is bound to the function
6898 `universal-argument', `M-DEL' is bound to the function
6899 `backward-kill-word', and `C-o' is bound to run the macro
6900 expressed on the right hand side (that is, to insert the text
6901 `> output' into the line).
6903 A number of symbolic character names are recognized while
6904 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
6905 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
6907 "KEYSEQ": FUNCTION-NAME or MACRO
6908 KEYSEQ differs from KEYNAME above in that strings denoting an
6909 entire key sequence can be specified, by placing the key
6910 sequence in double quotes. Some GNU Emacs style key escapes
6911 can be used, as in the following example, but the special
6912 character names are not recognized.
6914 "\C-u": universal-argument
6915 "\C-x\C-r": re-read-init-file
6916 "\e[11~": "Function Key 1"
6918 In the above example, `C-u' is again bound to the function
6919 `universal-argument' (just as it was in the first example),
6920 `C-x C-r' is bound to the function `re-read-init-file', and
6921 `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function
6925 The following GNU Emacs style escape sequences are available when
6926 specifying key sequences:
6941 <">, a double quotation mark
6944 <'>, a single quote or apostrophe
6946 In addition to the GNU Emacs style escape sequences, a second set
6947 of backslash escapes is available:
6974 the eight-bit character whose value is the octal value NNN
6975 (one to three digits)
6978 the eight-bit character whose value is the hexadecimal value
6979 HH (one or two hex digits)
6981 When entering the text of a macro, single or double quotes must be
6982 used to indicate a macro definition. Unquoted text is assumed to
6983 be a function name. In the macro body, the backslash escapes
6984 described above are expanded. Backslash will quote any other
6985 character in the macro text, including `"' and `''. For example,
6986 the following binding will make `C-x \' insert a single `\' into
6992 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
6994 8.3.2 Conditional Init Constructs
6995 ---------------------------------
6997 Readline implements a facility similar in spirit to the conditional
6998 compilation features of the C preprocessor which allows key bindings
6999 and variable settings to be performed as the result of tests. There
7000 are four parser directives used.
7003 The `$if' construct allows bindings to be made based on the
7004 editing mode, the terminal being used, or the application using
7005 Readline. The text of the test extends to the end of the line; no
7006 characters are required to isolate it.
7009 The `mode=' form of the `$if' directive is used to test
7010 whether Readline is in `emacs' or `vi' mode. This may be
7011 used in conjunction with the `set keymap' command, for
7012 instance, to set bindings in the `emacs-standard' and
7013 `emacs-ctlx' keymaps only if Readline is starting out in
7017 The `term=' form may be used to include terminal-specific key
7018 bindings, perhaps to bind the key sequences output by the
7019 terminal's function keys. The word on the right side of the
7020 `=' is tested against both the full name of the terminal and
7021 the portion of the terminal name before the first `-'. This
7022 allows `sun' to match both `sun' and `sun-cmd', for instance.
7025 The APPLICATION construct is used to include
7026 application-specific settings. Each program using the
7027 Readline library sets the APPLICATION NAME, and you can test
7028 for a particular value. This could be used to bind key
7029 sequences to functions useful for a specific program. For
7030 instance, the following command adds a key sequence that
7031 quotes the current or previous word in Bash:
7033 # Quote the current or previous word
7034 "\C-xq": "\eb\"\ef\""
7038 This command, as seen in the previous example, terminates an `$if'
7042 Commands in this branch of the `$if' directive are executed if the
7046 This directive takes a single filename as an argument and reads
7047 commands and bindings from that file. For example, the following
7048 directive reads from `/etc/inputrc':
7049 $include /etc/inputrc
7052 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
7054 8.3.3 Sample Init File
7055 ----------------------
7057 Here is an example of an INPUTRC file. This illustrates key binding,
7058 variable assignment, and conditional syntax.
7061 # This file controls the behaviour of line input editing for
7062 # programs that use the GNU Readline library. Existing
7063 # programs include FTP, Bash, and GDB.
7065 # You can re-read the inputrc file with C-x C-r.
7066 # Lines beginning with '#' are comments.
7068 # First, include any systemwide bindings and variable
7069 # assignments from /etc/Inputrc
7070 $include /etc/Inputrc
7073 # Set various bindings for emacs mode.
7075 set editing-mode emacs
7079 Meta-Control-h: backward-kill-word Text after the function name is ignored
7082 # Arrow keys in keypad mode
7084 #"\M-OD": backward-char
7085 #"\M-OC": forward-char
7086 #"\M-OA": previous-history
7087 #"\M-OB": next-history
7089 # Arrow keys in ANSI mode
7091 "\M-[D": backward-char
7092 "\M-[C": forward-char
7093 "\M-[A": previous-history
7094 "\M-[B": next-history
7096 # Arrow keys in 8 bit keypad mode
7098 #"\M-\C-OD": backward-char
7099 #"\M-\C-OC": forward-char
7100 #"\M-\C-OA": previous-history
7101 #"\M-\C-OB": next-history
7103 # Arrow keys in 8 bit ANSI mode
7105 #"\M-\C-[D": backward-char
7106 #"\M-\C-[C": forward-char
7107 #"\M-\C-[A": previous-history
7108 #"\M-\C-[B": next-history
7114 # An old-style binding. This happens to be the default.
7117 # Macros that are convenient for shell interaction
7120 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7121 # prepare to type a quoted word --
7122 # insert open and close double quotes
7123 # and move to just after the open quote
7124 "\C-x\"": "\"\"\C-b"
7125 # insert a backslash (testing backslash escapes
7126 # in sequences and macros)
7128 # Quote the current or previous word
7129 "\C-xq": "\eb\"\ef\""
7130 # Add a binding to refresh the line, which is unbound
7131 "\C-xr": redraw-current-line
7132 # Edit variable on current line.
7133 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
7136 # use a visible bell if one is available
7137 set bell-style visible
7139 # don't strip characters to 7 bits when reading
7142 # allow iso-latin1 characters to be inserted rather
7143 # than converted to prefix-meta sequences
7144 set convert-meta off
7146 # display characters with the eighth bit set directly
7147 # rather than as meta-prefixed characters
7150 # if there are more than 150 possible completions for
7151 # a word, ask the user if he wants to see all of them
7152 set completion-query-items 150
7158 "\M-.": yank-last-arg
7162 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
7164 8.4 Bindable Readline Commands
7165 ==============================
7169 * Commands For Moving:: Moving about the line.
7170 * Commands For History:: Getting at previous lines.
7171 * Commands For Text:: Commands for changing text.
7172 * Commands For Killing:: Commands for killing and yanking.
7173 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
7174 * Commands For Completion:: Getting Readline to do the typing for you.
7175 * Keyboard Macros:: Saving and re-executing typed characters
7176 * Miscellaneous Commands:: Other miscellaneous commands.
7178 This section describes Readline commands that may be bound to key
7179 sequences. You can list your key bindings by executing `bind -P' or,
7180 for a more terse format, suitable for an INPUTRC file, `bind -p'.
7181 (*Note Bash Builtins::.) Command names without an accompanying key
7182 sequence are unbound by default.
7184 In the following descriptions, "point" refers to the current cursor
7185 position, and "mark" refers to a cursor position saved by the
7186 `set-mark' command. The text between the point and mark is referred to
7190 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
7192 8.4.1 Commands For Moving
7193 -------------------------
7195 `beginning-of-line (C-a)'
7196 Move to the start of the current line.
7199 Move to the end of the line.
7201 `forward-char (C-f)'
7202 Move forward a character.
7204 `backward-char (C-b)'
7205 Move back a character.
7207 `forward-word (M-f)'
7208 Move forward to the end of the next word. Words are composed of
7211 `backward-word (M-b)'
7212 Move back to the start of the current or previous word. Words are
7213 composed of letters and digits.
7215 `shell-forward-word ()'
7216 Move forward to the end of the next word. Words are delimited by
7217 non-quoted shell metacharacters.
7219 `shell-backward-word ()'
7220 Move back to the start of the current or previous word. Words are
7221 delimited by non-quoted shell metacharacters.
7223 `clear-screen (C-l)'
7224 Clear the screen and redraw the current line, leaving the current
7225 line at the top of the screen.
7227 `redraw-current-line ()'
7228 Refresh the current line. By default, this is unbound.
7232 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
7234 8.4.2 Commands For Manipulating The History
7235 -------------------------------------------
7237 `accept-line (Newline or Return)'
7238 Accept the line regardless of where the cursor is. If this line is
7239 non-empty, add it to the history list according to the setting of
7240 the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a
7241 modified history line, then restore the history line to its
7244 `previous-history (C-p)'
7245 Move `back' through the history list, fetching the previous
7248 `next-history (C-n)'
7249 Move `forward' through the history list, fetching the next command.
7251 `beginning-of-history (M-<)'
7252 Move to the first line in the history.
7254 `end-of-history (M->)'
7255 Move to the end of the input history, i.e., the line currently
7258 `reverse-search-history (C-r)'
7259 Search backward starting at the current line and moving `up'
7260 through the history as necessary. This is an incremental search.
7262 `forward-search-history (C-s)'
7263 Search forward starting at the current line and moving `down'
7264 through the the history as necessary. This is an incremental
7267 `non-incremental-reverse-search-history (M-p)'
7268 Search backward starting at the current line and moving `up'
7269 through the history as necessary using a non-incremental search
7270 for a string supplied by the user.
7272 `non-incremental-forward-search-history (M-n)'
7273 Search forward starting at the current line and moving `down'
7274 through the the history as necessary using a non-incremental search
7275 for a string supplied by the user.
7277 `history-search-forward ()'
7278 Search forward through the history for the string of characters
7279 between the start of the current line and the point. This is a
7280 non-incremental search. By default, this command is unbound.
7282 `history-search-backward ()'
7283 Search backward through the history for the string of characters
7284 between the start of the current line and the point. This is a
7285 non-incremental search. By default, this command is unbound.
7287 `yank-nth-arg (M-C-y)'
7288 Insert the first argument to the previous command (usually the
7289 second word on the previous line) at point. With an argument N,
7290 insert the Nth word from the previous command (the words in the
7291 previous command begin with word 0). A negative argument inserts
7292 the Nth word from the end of the previous command. Once the
7293 argument N is computed, the argument is extracted as if the `!N'
7294 history expansion had been specified.
7296 `yank-last-arg (M-. or M-_)'
7297 Insert last argument to the previous command (the last word of the
7298 previous history entry). With a numeric argument, behave exactly
7299 like `yank-nth-arg'. Successive calls to `yank-last-arg' move
7300 back through the history list, inserting the last word (or the
7301 word specified by the argument to the first call) of each line in
7302 turn. Any numeric argument supplied to these successive calls
7303 determines the direction to move through the history. A negative
7304 argument switches the direction through the history (back or
7305 forward). The history expansion facilities are used to extract
7306 the last argument, as if the `!$' history expansion had been
7311 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
7313 8.4.3 Commands For Changing Text
7314 --------------------------------
7317 Delete the character at point. If point is at the beginning of
7318 the line, there are no characters in the line, and the last
7319 character typed was not bound to `delete-char', then return EOF.
7321 `backward-delete-char (Rubout)'
7322 Delete the character behind the cursor. A numeric argument means
7323 to kill the characters instead of deleting them.
7325 `forward-backward-delete-char ()'
7326 Delete the character under the cursor, unless the cursor is at the
7327 end of the line, in which case the character behind the cursor is
7328 deleted. By default, this is not bound to a key.
7330 `quoted-insert (C-q or C-v)'
7331 Add the next character typed to the line verbatim. This is how to
7332 insert key sequences like `C-q', for example.
7334 `self-insert (a, b, A, 1, !, ...)'
7337 `transpose-chars (C-t)'
7338 Drag the character before the cursor forward over the character at
7339 the cursor, moving the cursor forward as well. If the insertion
7340 point is at the end of the line, then this transposes the last two
7341 characters of the line. Negative arguments have no effect.
7343 `transpose-words (M-t)'
7344 Drag the word before point past the word after point, moving point
7345 past that word as well. If the insertion point is at the end of
7346 the line, this transposes the last two words on the line.
7349 Uppercase the current (or following) word. With a negative
7350 argument, uppercase the previous word, but do not move the cursor.
7352 `downcase-word (M-l)'
7353 Lowercase the current (or following) word. With a negative
7354 argument, lowercase the previous word, but do not move the cursor.
7356 `capitalize-word (M-c)'
7357 Capitalize the current (or following) word. With a negative
7358 argument, capitalize the previous word, but do not move the cursor.
7361 Toggle overwrite mode. With an explicit positive numeric argument,
7362 switches to overwrite mode. With an explicit non-positive numeric
7363 argument, switches to insert mode. This command affects only
7364 `emacs' mode; `vi' mode does overwrite differently. Each call to
7365 `readline()' starts in insert mode.
7367 In overwrite mode, characters bound to `self-insert' replace the
7368 text at point rather than pushing the text to the right.
7369 Characters bound to `backward-delete-char' replace the character
7370 before point with a space.
7372 By default, this command is unbound.
7376 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
7378 8.4.4 Killing And Yanking
7379 -------------------------
7382 Kill the text from point to the end of the line.
7384 `backward-kill-line (C-x Rubout)'
7385 Kill backward to the beginning of the line.
7387 `unix-line-discard (C-u)'
7388 Kill backward from the cursor to the beginning of the current line.
7390 `kill-whole-line ()'
7391 Kill all characters on the current line, no matter where point is.
7392 By default, this is unbound.
7395 Kill from point to the end of the current word, or if between
7396 words, to the end of the next word. Word boundaries are the same
7399 `backward-kill-word (M-<DEL>)'
7400 Kill the word behind point. Word boundaries are the same as
7403 `shell-kill-word ()'
7404 Kill from point to the end of the current word, or if between
7405 words, to the end of the next word. Word boundaries are the same
7406 as `shell-forward-word'.
7408 `shell-backward-kill-word ()'
7409 Kill the word behind point. Word boundaries are the same as
7410 `shell-backward-word'.
7412 `unix-word-rubout (C-w)'
7413 Kill the word behind point, using white space as a word boundary.
7414 The killed text is saved on the kill-ring.
7416 `unix-filename-rubout ()'
7417 Kill the word behind point, using white space and the slash
7418 character as the word boundaries. The killed text is saved on the
7421 `delete-horizontal-space ()'
7422 Delete all spaces and tabs around point. By default, this is
7426 Kill the text in the current region. By default, this command is
7429 `copy-region-as-kill ()'
7430 Copy the text in the region to the kill buffer, so it can be yanked
7431 right away. By default, this command is unbound.
7433 `copy-backward-word ()'
7434 Copy the word before point to the kill buffer. The word
7435 boundaries are the same as `backward-word'. By default, this
7438 `copy-forward-word ()'
7439 Copy the word following point to the kill buffer. The word
7440 boundaries are the same as `forward-word'. By default, this
7444 Yank the top of the kill ring into the buffer at point.
7447 Rotate the kill-ring, and yank the new top. You can only do this
7448 if the prior command is `yank' or `yank-pop'.
7451 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
7453 8.4.5 Specifying Numeric Arguments
7454 ----------------------------------
7456 `digit-argument (M-0, M-1, ... M--)'
7457 Add this digit to the argument already accumulating, or start a new
7458 argument. `M--' starts a negative argument.
7460 `universal-argument ()'
7461 This is another way to specify an argument. If this command is
7462 followed by one or more digits, optionally with a leading minus
7463 sign, those digits define the argument. If the command is
7464 followed by digits, executing `universal-argument' again ends the
7465 numeric argument, but is otherwise ignored. As a special case, if
7466 this command is immediately followed by a character that is
7467 neither a digit or minus sign, the argument count for the next
7468 command is multiplied by four. The argument count is initially
7469 one, so executing this function the first time makes the argument
7470 count four, a second time makes the argument count sixteen, and so
7471 on. By default, this is not bound to a key.
7474 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
7476 8.4.6 Letting Readline Type For You
7477 -----------------------------------
7480 Attempt to perform completion on the text before point. The
7481 actual completion performed is application-specific. Bash
7482 attempts completion treating the text as a variable (if the text
7483 begins with `$'), username (if the text begins with `~'), hostname
7484 (if the text begins with `@'), or command (including aliases and
7485 functions) in turn. If none of these produces a match, filename
7486 completion is attempted.
7488 `possible-completions (M-?)'
7489 List the possible completions of the text before point. When
7490 displaying completions, Readline sets the number of columns used
7491 for display to the value of `completion-display-width', the value
7492 of the environment variable `COLUMNS', or the screen width, in
7495 `insert-completions (M-*)'
7496 Insert all completions of the text before point that would have
7497 been generated by `possible-completions'.
7500 Similar to `complete', but replaces the word to be completed with
7501 a single match from the list of possible completions. Repeated
7502 execution of `menu-complete' steps through the list of possible
7503 completions, inserting each match in turn. At the end of the list
7504 of completions, the bell is rung (subject to the setting of
7505 `bell-style') and the original text is restored. An argument of N
7506 moves N positions forward in the list of matches; a negative
7507 argument may be used to move backward through the list. This
7508 command is intended to be bound to <TAB>, but is unbound by
7511 `menu-complete-backward ()'
7512 Identical to `menu-complete', but moves backward through the list
7513 of possible completions, as if `menu-complete' had been given a
7516 `delete-char-or-list ()'
7517 Deletes the character under the cursor if not at the beginning or
7518 end of the line (like `delete-char'). If at the end of the line,
7519 behaves identically to `possible-completions'. This command is
7522 `complete-filename (M-/)'
7523 Attempt filename completion on the text before point.
7525 `possible-filename-completions (C-x /)'
7526 List the possible completions of the text before point, treating
7529 `complete-username (M-~)'
7530 Attempt completion on the text before point, treating it as a
7533 `possible-username-completions (C-x ~)'
7534 List the possible completions of the text before point, treating
7537 `complete-variable (M-$)'
7538 Attempt completion on the text before point, treating it as a
7541 `possible-variable-completions (C-x $)'
7542 List the possible completions of the text before point, treating
7543 it as a shell variable.
7545 `complete-hostname (M-@)'
7546 Attempt completion on the text before point, treating it as a
7549 `possible-hostname-completions (C-x @)'
7550 List the possible completions of the text before point, treating
7553 `complete-command (M-!)'
7554 Attempt completion on the text before point, treating it as a
7555 command name. Command completion attempts to match the text
7556 against aliases, reserved words, shell functions, shell builtins,
7557 and finally executable filenames, in that order.
7559 `possible-command-completions (C-x !)'
7560 List the possible completions of the text before point, treating
7561 it as a command name.
7563 `dynamic-complete-history (M-<TAB>)'
7564 Attempt completion on the text before point, comparing the text
7565 against lines from the history list for possible completion
7569 Attempt menu completion on the text before point, comparing the
7570 text against lines from the history list for possible completion
7573 `complete-into-braces (M-{)'
7574 Perform filename completion and insert the list of possible
7575 completions enclosed within braces so the list is available to the
7576 shell (*note Brace Expansion::).
7580 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
7582 8.4.7 Keyboard Macros
7583 ---------------------
7585 `start-kbd-macro (C-x ()'
7586 Begin saving the characters typed into the current keyboard macro.
7588 `end-kbd-macro (C-x ))'
7589 Stop saving the characters typed into the current keyboard macro
7590 and save the definition.
7592 `call-last-kbd-macro (C-x e)'
7593 Re-execute the last keyboard macro defined, by making the
7594 characters in the macro appear as if typed at the keyboard.
7598 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
7600 8.4.8 Some Miscellaneous Commands
7601 ---------------------------------
7603 `re-read-init-file (C-x C-r)'
7604 Read in the contents of the INPUTRC file, and incorporate any
7605 bindings or variable assignments found there.
7608 Abort the current editing command and ring the terminal's bell
7609 (subject to the setting of `bell-style').
7611 `do-uppercase-version (M-a, M-b, M-X, ...)'
7612 If the metafied character X is lowercase, run the command that is
7613 bound to the corresponding uppercase character.
7615 `prefix-meta (<ESC>)'
7616 Metafy the next character typed. This is for keyboards without a
7617 meta key. Typing `<ESC> f' is equivalent to typing `M-f'.
7619 `undo (C-_ or C-x C-u)'
7620 Incremental undo, separately remembered for each line.
7623 Undo all changes made to this line. This is like executing the
7624 `undo' command enough times to get back to the beginning.
7626 `tilde-expand (M-&)'
7627 Perform tilde expansion on the current word.
7630 Set the mark to the point. If a numeric argument is supplied, the
7631 mark is set to that position.
7633 `exchange-point-and-mark (C-x C-x)'
7634 Swap the point with the mark. The current cursor position is set
7635 to the saved position, and the old cursor position is saved as the
7638 `character-search (C-])'
7639 A character is read and point is moved to the next occurrence of
7640 that character. A negative count searches for previous
7643 `character-search-backward (M-C-])'
7644 A character is read and point is moved to the previous occurrence
7645 of that character. A negative count searches for subsequent
7648 `skip-csi-sequence ()'
7649 Read enough characters to consume a multi-key sequence such as
7650 those defined for keys like Home and End. Such sequences begin
7651 with a Control Sequence Indicator (CSI), usually ESC-[. If this
7652 sequence is bound to "\e[", keys producing such sequences will
7653 have no effect unless explicitly bound to a readline command,
7654 instead of inserting stray characters into the editing buffer.
7655 This is unbound by default, but usually bound to ESC-[.
7657 `insert-comment (M-#)'
7658 Without a numeric argument, the value of the `comment-begin'
7659 variable is inserted at the beginning of the current line. If a
7660 numeric argument is supplied, this command acts as a toggle: if
7661 the characters at the beginning of the line do not match the value
7662 of `comment-begin', the value is inserted, otherwise the
7663 characters in `comment-begin' are deleted from the beginning of
7664 the line. In either case, the line is accepted as if a newline
7665 had been typed. The default value of `comment-begin' causes this
7666 command to make the current line a shell comment. If a numeric
7667 argument causes the comment character to be removed, the line will
7668 be executed by the shell.
7671 Print all of the functions and their key bindings to the Readline
7672 output stream. If a numeric argument is supplied, the output is
7673 formatted in such a way that it can be made part of an INPUTRC
7674 file. This command is unbound by default.
7677 Print all of the settable variables and their values to the
7678 Readline output stream. If a numeric argument is supplied, the
7679 output is formatted in such a way that it can be made part of an
7680 INPUTRC file. This command is unbound by default.
7683 Print all of the Readline key sequences bound to macros and the
7684 strings they output. If a numeric argument is supplied, the
7685 output is formatted in such a way that it can be made part of an
7686 INPUTRC file. This command is unbound by default.
7688 `glob-complete-word (M-g)'
7689 The word before point is treated as a pattern for pathname
7690 expansion, with an asterisk implicitly appended. This pattern is
7691 used to generate a list of matching file names for possible
7694 `glob-expand-word (C-x *)'
7695 The word before point is treated as a pattern for pathname
7696 expansion, and the list of matching file names is inserted,
7697 replacing the word. If a numeric argument is supplied, a `*' is
7698 appended before pathname expansion.
7700 `glob-list-expansions (C-x g)'
7701 The list of expansions that would have been generated by
7702 `glob-expand-word' is displayed, and the line is redrawn. If a
7703 numeric argument is supplied, a `*' is appended before pathname
7706 `display-shell-version (C-x C-v)'
7707 Display version information about the current instance of Bash.
7709 `shell-expand-line (M-C-e)'
7710 Expand the line as the shell does. This performs alias and
7711 history expansion as well as all of the shell word expansions
7712 (*note Shell Expansions::).
7714 `history-expand-line (M-^)'
7715 Perform history expansion on the current line.
7718 Perform history expansion on the current line and insert a space
7719 (*note History Interaction::).
7721 `alias-expand-line ()'
7722 Perform alias expansion on the current line (*note Aliases::).
7724 `history-and-alias-expand-line ()'
7725 Perform history and alias expansion on the current line.
7727 `insert-last-argument (M-. or M-_)'
7728 A synonym for `yank-last-arg'.
7730 `operate-and-get-next (C-o)'
7731 Accept the current line for execution and fetch the next line
7732 relative to the current line from the history for editing. Any
7733 argument is ignored.
7735 `edit-and-execute-command (C-xC-e)'
7736 Invoke an editor on the current command line, and execute the
7737 result as shell commands. Bash attempts to invoke `$VISUAL',
7738 `$EDITOR', and `emacs' as the editor, in that order.
7742 File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
7744 8.5 Readline vi Mode
7745 ====================
7747 While the Readline library does not have a full set of `vi' editing
7748 functions, it does contain enough to allow simple editing of the line.
7749 The Readline `vi' mode behaves as specified in the POSIX standard.
7751 In order to switch interactively between `emacs' and `vi' editing
7752 modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
7753 Builtin::). The Readline default is `emacs' mode.
7755 When you enter a line in `vi' mode, you are already placed in
7756 `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
7757 you into `command' mode, where you can edit the text of the line with
7758 the standard `vi' movement keys, move to previous history lines with
7759 `k' and subsequent lines with `j', and so forth.
7762 File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
7764 8.6 Programmable Completion
7765 ===========================
7767 When word completion is attempted for an argument to a command for
7768 which a completion specification (a COMPSPEC) has been defined using
7769 the `complete' builtin (*note Programmable Completion Builtins::), the
7770 programmable completion facilities are invoked.
7772 First, the command name is identified. If a compspec has been
7773 defined for that command, the compspec is used to generate the list of
7774 possible completions for the word. If the command word is the empty
7775 string (completion attempted at the beginning of an empty line), any
7776 compspec defined with the `-E' option to `complete' is used. If the
7777 command word is a full pathname, a compspec for the full pathname is
7778 searched for first. If no compspec is found for the full pathname, an
7779 attempt is made to find a compspec for the portion following the final
7780 slash. If those searches do not result in a compspec, any compspec
7781 defined with the `-D' option to `complete' is used as the default.
7783 Once a compspec has been found, it is used to generate the list of
7784 matching words. If a compspec is not found, the default Bash completion
7785 described above (*note Commands For Completion::) is performed.
7787 First, the actions specified by the compspec are used. Only matches
7788 which are prefixed by the word being completed are returned. When the
7789 `-f' or `-d' option is used for filename or directory name completion,
7790 the shell variable `FIGNORE' is used to filter the matches. *Note Bash
7791 Variables::, for a description of `FIGNORE'.
7793 Any completions specified by a filename expansion pattern to the
7794 `-G' option are generated next. The words generated by the pattern
7795 need not match the word being completed. The `GLOBIGNORE' shell
7796 variable is not used to filter the matches, but the `FIGNORE' shell
7799 Next, the string specified as the argument to the `-W' option is
7800 considered. The string is first split using the characters in the `IFS'
7801 special variable as delimiters. Shell quoting is honored. Each word
7802 is then expanded using brace expansion, tilde expansion, parameter and
7803 variable expansion, command substitution, and arithmetic expansion, as
7804 described above (*note Shell Expansions::). The results are split
7805 using the rules described above (*note Word Splitting::). The results
7806 of the expansion are prefix-matched against the word being completed,
7807 and the matching words become the possible completions.
7809 After these matches have been generated, any shell function or
7810 command specified with the `-F' and `-C' options is invoked. When the
7811 command or function is invoked, the `COMP_LINE', `COMP_POINT',
7812 `COMP_KEY', and `COMP_TYPE' variables are assigned values as described
7813 above (*note Bash Variables::). If a shell function is being invoked,
7814 the `COMP_WORDS' and `COMP_CWORD' variables are also set. When the
7815 function or command is invoked, the first argument is the name of the
7816 command whose arguments are being completed, the second argument is the
7817 word being completed, and the third argument is the word preceding the
7818 word being completed on the current command line. No filtering of the
7819 generated completions against the word being completed is performed;
7820 the function or command has complete freedom in generating the matches.
7822 Any function specified with `-F' is invoked first. The function may
7823 use any of the shell facilities, including the `compgen' and `compopt'
7824 builtins described below (*note Programmable Completion Builtins::), to
7825 generate the matches. It must put the possible completions in the
7826 `COMPREPLY' array variable.
7828 Next, any command specified with the `-C' option is invoked in an
7829 environment equivalent to command substitution. It should print a list
7830 of completions, one per line, to the standard output. Backslash may be
7831 used to escape a newline, if necessary.
7833 After all of the possible completions are generated, any filter
7834 specified with the `-X' option is applied to the list. The filter is a
7835 pattern as used for pathname expansion; a `&' in the pattern is
7836 replaced with the text of the word being completed. A literal `&' may
7837 be escaped with a backslash; the backslash is removed before attempting
7838 a match. Any completion that matches the pattern will be removed from
7839 the list. A leading `!' negates the pattern; in this case any
7840 completion not matching the pattern will be removed.
7842 Finally, any prefix and suffix specified with the `-P' and `-S'
7843 options are added to each member of the completion list, and the result
7844 is returned to the Readline completion code as the list of possible
7847 If the previously-applied actions do not generate any matches, and
7848 the `-o dirnames' option was supplied to `complete' when the compspec
7849 was defined, directory name completion is attempted.
7851 If the `-o plusdirs' option was supplied to `complete' when the
7852 compspec was defined, directory name completion is attempted and any
7853 matches are added to the results of the other actions.
7855 By default, if a compspec is found, whatever it generates is
7856 returned to the completion code as the full set of possible completions.
7857 The default Bash completions are not attempted, and the Readline default
7858 of filename completion is disabled. If the `-o bashdefault' option was
7859 supplied to `complete' when the compspec was defined, the default Bash
7860 completions are attempted if the compspec generates no matches. If the
7861 `-o default' option was supplied to `complete' when the compspec was
7862 defined, Readline's default completion will be performed if the
7863 compspec (and, if attempted, the default Bash completions) generate no
7866 When a compspec indicates that directory name completion is desired,
7867 the programmable completion functions force Readline to append a slash
7868 to completed names which are symbolic links to directories, subject to
7869 the value of the MARK-DIRECTORIES Readline variable, regardless of the
7870 setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
7872 There is some support for dynamically modifying completions. This is
7873 most useful when used in combination with a default completion specified
7874 with `-D'. It's possible for shell functions executed as completion
7875 handlers to indicate that completion should be retried by returning an
7876 exit status of 124. If a shell function returns 124, and changes the
7877 compspec associated with the command on which completion is being
7878 attempted (supplied as the first argument when the function is
7879 executed), programmable completion restarts from the beginning, with an
7880 attempt to find a new compspec for that command. This allows a set of
7881 completions to be built dynamically as completion is attempted, rather
7882 than being loaded all at once.
7884 For instance, assuming that there is a library of compspecs, each
7885 kept in a file corresponding to the name of the command, the following
7886 default completion function would load completions dynamically:
7888 _completion_loader()
7890 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
7892 complete -D -F _completion_loader
7895 File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing
7897 8.7 Programmable Completion Builtins
7898 ====================================
7900 Two builtin commands are available to manipulate the programmable
7901 completion facilities.
7904 `compgen [OPTION] [WORD]'
7906 Generate possible completion matches for WORD according to the
7907 OPTIONs, which may be any option accepted by the `complete'
7908 builtin with the exception of `-p' and `-r', and write the matches
7909 to the standard output. When using the `-F' or `-C' options, the
7910 various shell variables set by the programmable completion
7911 facilities, while available, will not have useful values.
7913 The matches will be generated in the same way as if the
7914 programmable completion code had generated them directly from a
7915 completion specification with the same flags. If WORD is
7916 specified, only those completions matching WORD will be displayed.
7918 The return value is true unless an invalid option is supplied, or
7919 no matches were generated.
7922 `complete [-abcdefgjksuv] [-o COMP-OPTION] [-DE] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
7923 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
7924 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]'
7925 `complete -pr [-DE] [NAME ...]'
7927 Specify how arguments to each NAME should be completed. If the
7928 `-p' option is supplied, or if no options are supplied, existing
7929 completion specifications are printed in a way that allows them to
7930 be reused as input. The `-r' option removes a completion
7931 specification for each NAME, or, if no NAMEs are supplied, all
7932 completion specifications. The `-D' option indicates that the
7933 remaining options and actions should apply to the "default"
7934 command completion; that is, completion attempted on a command for
7935 which no completion has previously been defined. The `-E' option
7936 indicates that the remaining options and actions should apply to
7937 "empty" command completion; that is, completion attempted on a
7940 The process of applying these completion specifications when word
7941 completion is attempted is described above (*note Programmable
7942 Completion::). The `-D' option takes precedence over `-E'.
7944 Other options, if specified, have the following meanings. The
7945 arguments to the `-G', `-W', and `-X' options (and, if necessary,
7946 the `-P' and `-S' options) should be quoted to protect them from
7947 expansion before the `complete' builtin is invoked.
7950 The COMP-OPTION controls several aspects of the compspec's
7951 behavior beyond the simple generation of completions.
7952 COMP-OPTION may be one of:
7955 Perform the rest of the default Bash completions if the
7956 compspec generates no matches.
7959 Use Readline's default filename completion if the
7960 compspec generates no matches.
7963 Perform directory name completion if the compspec
7964 generates no matches.
7967 Tell Readline that the compspec generates filenames, so
7968 it can perform any filename-specific processing (like
7969 adding a slash to directory names quoting special
7970 characters, or suppressing trailing spaces). This
7971 option is intended to be used with shell functions
7972 specified with `-F'.
7975 Tell Readline not to append a space (the default) to
7976 words completed at the end of the line.
7979 After any matches defined by the compspec are generated,
7980 directory name completion is attempted and any matches
7981 are added to the results of the other actions.
7985 The ACTION may be one of the following to generate a list of
7986 possible completions:
7989 Alias names. May also be specified as `-a'.
7992 Array variable names.
7995 Readline key binding names (*note Bindable Readline
7999 Names of shell builtin commands. May also be specified
8003 Command names. May also be specified as `-c'.
8006 Directory names. May also be specified as `-d'.
8009 Names of disabled shell builtins.
8012 Names of enabled shell builtins.
8015 Names of exported shell variables. May also be
8019 File names. May also be specified as `-f'.
8022 Names of shell functions.
8025 Group names. May also be specified as `-g'.
8028 Help topics as accepted by the `help' builtin (*note
8032 Hostnames, as taken from the file specified by the
8033 `HOSTFILE' shell variable (*note Bash Variables::).
8036 Job names, if job control is active. May also be
8040 Shell reserved words. May also be specified as `-k'.
8043 Names of running jobs, if job control is active.
8046 Service names. May also be specified as `-s'.
8049 Valid arguments for the `-o' option to the `set' builtin
8050 (*note The Set Builtin::).
8053 Shell option names as accepted by the `shopt' builtin
8054 (*note Bash Builtins::).
8060 Names of stopped jobs, if job control is active.
8063 User names. May also be specified as `-u'.
8066 Names of all shell variables. May also be specified as
8070 COMMAND is executed in a subshell environment, and its output
8071 is used as the possible completions.
8074 The shell function FUNCTION is executed in the current shell
8075 environment. When it finishes, the possible completions are
8076 retrieved from the value of the `COMPREPLY' array variable.
8079 The filename expansion pattern GLOBPAT is expanded to generate
8080 the possible completions.
8083 PREFIX is added at the beginning of each possible completion
8084 after all other options have been applied.
8087 SUFFIX is appended to each possible completion after all
8088 other options have been applied.
8091 The WORDLIST is split using the characters in the `IFS'
8092 special variable as delimiters, and each resultant word is
8093 expanded. The possible completions are the members of the
8094 resultant list which match the word being completed.
8097 FILTERPAT is a pattern as used for filename expansion. It is
8098 applied to the list of possible completions generated by the
8099 preceding options and arguments, and each completion matching
8100 FILTERPAT is removed from the list. A leading `!' in
8101 FILTERPAT negates the pattern; in this case, any completion
8102 not matching FILTERPAT is removed.
8104 The return value is true unless an invalid option is supplied, an
8105 option other than `-p' or `-r' is supplied without a NAME
8106 argument, an attempt is made to remove a completion specification
8107 for a NAME for which no specification exists, or an error occurs
8108 adding a completion specification.
8111 `compopt' [-o OPTION] [-DE] [+o OPTION] [NAME]
8112 Modify completion options for each NAME according to the OPTIONs,
8113 or for the currently-executing completion if no NAMEs are supplied.
8114 If no OPTIONs are given, display the completion options for each
8115 NAME or the current completion. The possible values of OPTION are
8116 those valid for the `complete' builtin described above. The `-D'
8117 option indicates that the remaining options should apply to the
8118 "default" command completion; that is, completion attempted on a
8119 command for which no completion has previously been defined. The
8120 `-E' option indicates that the remaining options should apply to
8121 "empty" command completion; that is, completion attempted on a
8124 The `-D' option takes precedence over `-E'.
8126 The return value is true unless an invalid option is supplied, an
8127 attempt is made to modify the options for a NAME for which no
8128 completion specification exists, or an output error occurs.
8132 File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
8134 9 Using History Interactively
8135 *****************************
8137 This chapter describes how to use the GNU History Library
8138 interactively, from a user's standpoint. It should be considered a
8139 user's guide. For information on using the GNU History Library in
8140 other programs, see the GNU Readline Library Manual.
8144 * Bash History Facilities:: How Bash lets you manipulate your command
8146 * Bash History Builtins:: The Bash builtin commands that manipulate
8147 the command history.
8148 * History Interaction:: What it feels like using History as a user.
8151 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
8153 9.1 Bash History Facilities
8154 ===========================
8156 When the `-o history' option to the `set' builtin is enabled (*note The
8157 Set Builtin::), the shell provides access to the "command history", the
8158 list of commands previously typed. The value of the `HISTSIZE' shell
8159 variable is used as the number of commands to save in a history list.
8160 The text of the last `$HISTSIZE' commands (default 500) is saved. The
8161 shell stores each command in the history list prior to parameter and
8162 variable expansion but after history expansion is performed, subject to
8163 the values of the shell variables `HISTIGNORE' and `HISTCONTROL'.
8165 When the shell starts up, the history is initialized from the file
8166 named by the `HISTFILE' variable (default `~/.bash_history'). The file
8167 named by the value of `HISTFILE' is truncated, if necessary, to contain
8168 no more than the number of lines specified by the value of the
8169 `HISTFILESIZE' variable. When an interactive shell exits, the last
8170 `$HISTSIZE' lines are copied from the history list to the file named by
8171 `$HISTFILE'. If the `histappend' shell option is set (*note Bash
8172 Builtins::), the lines are appended to the history file, otherwise the
8173 history file is overwritten. If `HISTFILE' is unset, or if the history
8174 file is unwritable, the history is not saved. After saving the
8175 history, the history file is truncated to contain no more than
8176 `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is
8179 If the `HISTTIMEFORMAT' is set, the time stamp information
8180 associated with each history entry is written to the history file,
8181 marked with the history comment character. When the history file is
8182 read, lines beginning with the history comment character followed
8183 immediately by a digit are interpreted as timestamps for the previous
8186 The builtin command `fc' may be used to list or edit and re-execute
8187 a portion of the history list. The `history' builtin may be used to
8188 display or modify the history list and manipulate the history file.
8189 When using command-line editing, search commands are available in each
8190 editing mode that provide access to the history list (*note Commands
8193 The shell allows control over which commands are saved on the history
8194 list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
8195 the shell to save only a subset of the commands entered. The `cmdhist'
8196 shell option, if enabled, causes the shell to attempt to save each line
8197 of a multi-line command in the same history entry, adding semicolons
8198 where necessary to preserve syntactic correctness. The `lithist' shell
8199 option causes the shell to save the command with embedded newlines
8200 instead of semicolons. The `shopt' builtin is used to set these
8201 options. *Note Bash Builtins::, for a description of `shopt'.
8204 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
8206 9.2 Bash History Builtins
8207 =========================
8209 Bash provides two builtin commands which manipulate the history list
8213 `fc [-e ENAME] [-lnr] [FIRST] [LAST]'
8214 `fc -s [PAT=REP] [COMMAND]'
8216 Fix Command. In the first form, a range of commands from FIRST to
8217 LAST is selected from the history list. Both FIRST and LAST may
8218 be specified as a string (to locate the most recent command
8219 beginning with that string) or as a number (an index into the
8220 history list, where a negative number is used as an offset from the
8221 current command number). If LAST is not specified it is set to
8222 FIRST. If FIRST is not specified it is set to the previous
8223 command for editing and -16 for listing. If the `-l' flag is
8224 given, the commands are listed on standard output. The `-n' flag
8225 suppresses the command numbers when listing. The `-r' flag
8226 reverses the order of the listing. Otherwise, the editor given by
8227 ENAME is invoked on a file containing those commands. If ENAME is
8228 not given, the value of the following variable expansion is used:
8229 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
8230 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
8231 that is set, or `vi' if neither is set. When editing is complete,
8232 the edited commands are echoed and executed.
8234 In the second form, COMMAND is re-executed after each instance of
8235 PAT in the selected command is replaced by REP.
8237 A useful alias to use with the `fc' command is `r='fc -s'', so
8238 that typing `r cc' runs the last command beginning with `cc' and
8239 typing `r' re-executes the last command (*note Aliases::).
8245 history [-anrw] [FILENAME]
8248 With no options, display the history list with line numbers.
8249 Lines prefixed with a `*' have been modified. An argument of N
8250 lists only the last N lines. If the shell variable
8251 `HISTTIMEFORMAT' is set and not null, it is used as a format
8252 string for STRFTIME to display the time stamp associated with each
8253 displayed history entry. No intervening blank is printed between
8254 the formatted time stamp and the history line.
8256 Options, if supplied, have the following meanings:
8259 Clear the history list. This may be combined with the other
8260 options to replace the history list completely.
8263 Delete the history entry at position OFFSET. OFFSET should
8264 be specified as it appears when the history is displayed.
8267 Append the new history lines (history lines entered since the
8268 beginning of the current Bash session) to the history file.
8271 Append the history lines not already read from the history
8272 file to the current history list. These are lines appended
8273 to the history file since the beginning of the current Bash
8277 Read the current history file and append its contents to the
8281 Write out the current history to the history file.
8284 Perform history substitution on the ARGs and display the
8285 result on the standard output, without storing the results in
8289 The ARGs are added to the end of the history list as a single
8293 When any of the `-w', `-r', `-a', or `-n' options is used, if
8294 FILENAME is given, then it is used as the history file. If not,
8295 then the value of the `HISTFILE' variable is used.
8299 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
8301 9.3 History Expansion
8302 =====================
8304 The History library provides a history expansion feature that is similar
8305 to the history expansion provided by `csh'. This section describes the
8306 syntax used to manipulate the history information.
8308 History expansions introduce words from the history list into the
8309 input stream, making it easy to repeat commands, insert the arguments
8310 to a previous command into the current input line, or fix errors in
8311 previous commands quickly.
8313 History expansion takes place in two parts. The first is to
8314 determine which line from the history list should be used during
8315 substitution. The second is to select portions of that line for
8316 inclusion into the current one. The line selected from the history is
8317 called the "event", and the portions of that line that are acted upon
8318 are called "words". Various "modifiers" are available to manipulate
8319 the selected words. The line is broken into words in the same fashion
8320 that Bash does, so that several words surrounded by quotes are
8321 considered one word. History expansions are introduced by the
8322 appearance of the history expansion character, which is `!' by default.
8323 Only `\' and `'' may be used to escape the history expansion character.
8325 Several shell options settable with the `shopt' builtin (*note Bash
8326 Builtins::) may be used to tailor the behavior of history expansion.
8327 If the `histverify' shell option is enabled, and Readline is being
8328 used, history substitutions are not immediately passed to the shell
8329 parser. Instead, the expanded line is reloaded into the Readline
8330 editing buffer for further modification. If Readline is being used,
8331 and the `histreedit' shell option is enabled, a failed history
8332 expansion will be reloaded into the Readline editing buffer for
8333 correction. The `-p' option to the `history' builtin command may be
8334 used to see what a history expansion will do before using it. The `-s'
8335 option to the `history' builtin may be used to add commands to the end
8336 of the history list without actually executing them, so that they are
8337 available for subsequent recall. This is most useful in conjunction
8340 The shell allows control of the various characters used by the
8341 history expansion mechanism with the `histchars' variable, as explained
8342 above (*note Bash Variables::). The shell uses the history comment
8343 character to mark history timestamps when writing the history file.
8347 * Event Designators:: How to specify which history line to use.
8348 * Word Designators:: Specifying which words are of interest.
8349 * Modifiers:: Modifying the results of substitution.
8352 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
8354 9.3.1 Event Designators
8355 -----------------------
8357 An event designator is a reference to a command line entry in the
8358 history list. Unless the reference is absolute, events are relative to
8359 the current position in the history list.
8362 Start a history substitution, except when followed by a space, tab,
8363 the end of the line, `=' or `(' (when the `extglob' shell option
8364 is enabled using the `shopt' builtin).
8367 Refer to command line N.
8370 Refer to the command N lines back.
8373 Refer to the previous command. This is a synonym for `!-1'.
8376 Refer to the most recent command preceding the current position in
8377 the history list starting with STRING.
8380 Refer to the most recent command preceding the current position in
8381 the history list containing STRING. The trailing `?' may be
8382 omitted if the STRING is followed immediately by a newline.
8385 Quick Substitution. Repeat the last command, replacing STRING1
8386 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
8389 The entire command line typed so far.
8393 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
8395 9.3.2 Word Designators
8396 ----------------------
8398 Word designators are used to select desired words from the event. A
8399 `:' separates the event specification from the word designator. It may
8400 be omitted if the word designator begins with a `^', `$', `*', `-', or
8401 `%'. Words are numbered from the beginning of the line, with the first
8402 word being denoted by 0 (zero). Words are inserted into the current
8403 line separated by single spaces.
8408 designates the preceding command. When you type this, the
8409 preceding command is repeated in toto.
8412 designates the last argument of the preceding command. This may be
8416 designates the second argument of the most recent command starting
8417 with the letters `fi'.
8419 Here are the word designators:
8422 The `0'th word. For many applications, this is the command word.
8428 The first argument; that is, word 1.
8434 The word matched by the most recent `?STRING?' search.
8437 A range of words; `-Y' abbreviates `0-Y'.
8440 All of the words, except the `0'th. This is a synonym for `1-$'.
8441 It is not an error to use `*' if there is just one word in the
8442 event; the empty string is returned in that case.
8448 Abbreviates `X-$' like `X*', but omits the last word.
8451 If a word designator is supplied without an event specification, the
8452 previous command is used as the event.
8455 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
8460 After the optional word designator, you can add a sequence of one or
8461 more of the following modifiers, each preceded by a `:'.
8464 Remove a trailing pathname component, leaving only the head.
8467 Remove all leading pathname components, leaving the tail.
8470 Remove a trailing suffix of the form `.SUFFIX', leaving the
8474 Remove all but the trailing suffix.
8477 Print the new command but do not execute it.
8480 Quote the substituted words, escaping further substitutions.
8483 Quote the substituted words as with `q', but break into words at
8484 spaces, tabs, and newlines.
8487 Substitute NEW for the first occurrence of OLD in the event line.
8488 Any delimiter may be used in place of `/'. The delimiter may be
8489 quoted in OLD and NEW with a single backslash. If `&' appears in
8490 NEW, it is replaced by OLD. A single backslash will quote the
8491 `&'. The final delimiter is optional if it is the last character
8495 Repeat the previous substitution.
8499 Cause changes to be applied over the entire event line. Used in
8500 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
8503 Apply the following `s' modifier once to each word in the event.
8507 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
8512 This chapter provides basic instructions for installing Bash on the
8513 various supported platforms. The distribution supports the GNU
8514 operating systems, nearly every version of Unix, and several non-Unix
8515 systems such as BeOS and Interix. Other independent ports exist for
8516 MS-DOS, OS/2, and Windows platforms.
8520 * Basic Installation:: Installation instructions.
8521 * Compilers and Options:: How to set special options for various
8523 * Compiling For Multiple Architectures:: How to compile Bash for more
8524 than one kind of system from
8525 the same source tree.
8526 * Installation Names:: How to set the various paths used by the installation.
8527 * Specifying the System Type:: How to configure Bash for a particular system.
8528 * Sharing Defaults:: How to share default configuration values among GNU
8530 * Operation Controls:: Options recognized by the configuration program.
8531 * Optional Features:: How to enable and disable optional features when
8535 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
8537 10.1 Basic Installation
8538 =======================
8540 These are installation instructions for Bash.
8542 The simplest way to compile Bash is:
8544 1. `cd' to the directory containing the source code and type
8545 `./configure' to configure Bash for your system. If you're using
8546 `csh' on an old version of System V, you might need to type `sh
8547 ./configure' instead to prevent `csh' from trying to execute
8550 Running `configure' takes some time. While running, it prints
8551 messages telling which features it is checking for.
8553 2. Type `make' to compile Bash and build the `bashbug' bug reporting
8556 3. Optionally, type `make tests' to run the Bash test suite.
8558 4. Type `make install' to install `bash' and `bashbug'. This will
8559 also install the manual pages and Info file.
8562 The `configure' shell script attempts to guess correct values for
8563 various system-dependent variables used during compilation. It uses
8564 those values to create a `Makefile' in each directory of the package
8565 (the top directory, the `builtins', `doc', and `support' directories,
8566 each directory under `lib', and several others). It also creates a
8567 `config.h' file containing system-dependent definitions. Finally, it
8568 creates a shell script named `config.status' that you can run in the
8569 future to recreate the current configuration, a file `config.cache'
8570 that saves the results of its tests to speed up reconfiguring, and a
8571 file `config.log' containing compiler output (useful mainly for
8572 debugging `configure'). If at some point `config.cache' contains
8573 results you don't want to keep, you may remove or edit it.
8575 To find out more about the options and arguments that the
8576 `configure' script understands, type
8578 bash-2.04$ ./configure --help
8580 at the Bash prompt in your Bash source directory.
8582 If you need to do unusual things to compile Bash, please try to
8583 figure out how `configure' could check whether or not to do them, and
8584 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
8585 considered for the next release.
8587 The file `configure.in' is used to create `configure' by a program
8588 called Autoconf. You only need `configure.in' if you want to change it
8589 or regenerate `configure' using a newer version of Autoconf. If you do
8590 this, make sure you are using Autoconf version 2.50 or newer.
8592 You can remove the program binaries and object files from the source
8593 code directory by typing `make clean'. To also remove the files that
8594 `configure' created (so you can compile Bash for a different kind of
8595 computer), type `make distclean'.
8598 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
8600 10.2 Compilers and Options
8601 ==========================
8603 Some systems require unusual options for compilation or linking that
8604 the `configure' script does not know about. You can give `configure'
8605 initial values for variables by setting them in the environment. Using
8606 a Bourne-compatible shell, you can do that on the command line like
8609 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
8611 On systems that have the `env' program, you can do it like this:
8613 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
8615 The configuration process uses GCC to build Bash if it is available.
8618 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
8620 10.3 Compiling For Multiple Architectures
8621 =========================================
8623 You can compile Bash for more than one kind of computer at the same
8624 time, by placing the object files for each architecture in their own
8625 directory. To do this, you must use a version of `make' that supports
8626 the `VPATH' variable, such as GNU `make'. `cd' to the directory where
8627 you want the object files and executables to go and run the `configure'
8628 script from the source directory. You may need to supply the
8629 `--srcdir=PATH' argument to tell `configure' where the source files
8630 are. `configure' automatically checks for the source code in the
8631 directory that `configure' is in and in `..'.
8633 If you have to use a `make' that does not supports the `VPATH'
8634 variable, you can compile Bash for one architecture at a time in the
8635 source code directory. After you have installed Bash for one
8636 architecture, use `make distclean' before reconfiguring for another
8639 Alternatively, if your system supports symbolic links, you can use
8640 the `support/mkclone' script to create a build tree which has symbolic
8641 links back to each file in the source directory. Here's an example
8642 that creates a build directory in the current directory from a source
8643 directory `/usr/gnu/src/bash-2.0':
8645 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
8647 The `mkclone' script requires Bash, so you must have already built Bash
8648 for at least one architecture before you can create build directories
8649 for other architectures.
8652 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
8654 10.4 Installation Names
8655 =======================
8657 By default, `make install' will install into `/usr/local/bin',
8658 `/usr/local/man', etc. You can specify an installation prefix other
8659 than `/usr/local' by giving `configure' the option `--prefix=PATH', or
8660 by specifying a value for the `DESTDIR' `make' variable when running
8663 You can specify separate installation prefixes for
8664 architecture-specific files and architecture-independent files. If you
8665 give `configure' the option `--exec-prefix=PATH', `make install' will
8666 use PATH as the prefix for installing programs and libraries.
8667 Documentation and other data files will still use the regular prefix.
8670 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
8672 10.5 Specifying the System Type
8673 ===============================
8675 There may be some features `configure' can not figure out
8676 automatically, but need to determine by the type of host Bash will run
8677 on. Usually `configure' can figure that out, but if it prints a
8678 message saying it can not guess the host type, give it the
8679 `--host=TYPE' option. `TYPE' can either be a short name for the system
8680 type, such as `sun4', or a canonical name with three fields:
8681 `CPU-COMPANY-SYSTEM' (e.g., `i386-unknown-freebsd4.2').
8683 See the file `support/config.sub' for the possible values of each
8687 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
8689 10.6 Sharing Defaults
8690 =====================
8692 If you want to set default values for `configure' scripts to share, you
8693 can create a site shell script called `config.site' that gives default
8694 values for variables like `CC', `cache_file', and `prefix'. `configure'
8695 looks for `PREFIX/share/config.site' if it exists, then
8696 `PREFIX/etc/config.site' if it exists. Or, you can set the
8697 `CONFIG_SITE' environment variable to the location of the site script.
8698 A warning: the Bash `configure' looks for a site script, but not all
8699 `configure' scripts do.
8702 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
8704 10.7 Operation Controls
8705 =======================
8707 `configure' recognizes the following options to control how it operates.
8710 Use and save the results of the tests in FILE instead of
8711 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
8712 debugging `configure'.
8715 Print a summary of the options to `configure', and exit.
8720 Do not print messages saying which checks are being made.
8723 Look for the Bash source code in directory DIR. Usually
8724 `configure' can determine that directory automatically.
8727 Print the version of Autoconf used to generate the `configure'
8730 `configure' also accepts some other, not widely used, boilerplate
8731 options. `configure --help' prints the complete list.
8734 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
8736 10.8 Optional Features
8737 ======================
8739 The Bash `configure' has a number of `--enable-FEATURE' options, where
8740 FEATURE indicates an optional part of Bash. There are also several
8741 `--with-PACKAGE' options, where PACKAGE is something like `bash-malloc'
8742 or `purify'. To turn off the default use of a package, use
8743 `--without-PACKAGE'. To configure Bash without a feature that is
8744 enabled by default, use `--disable-FEATURE'.
8746 Here is a complete list of the `--enable-' and `--with-' options
8747 that the Bash `configure' recognizes.
8750 Define if you are using the Andrew File System from Transarc.
8752 `--with-bash-malloc'
8753 Use the Bash version of `malloc' in the directory `lib/malloc'.
8754 This is not the same `malloc' that appears in GNU libc, but an
8755 older version originally derived from the 4.2 BSD `malloc'. This
8756 `malloc' is very fast, but wastes some space on each allocation.
8757 This option is enabled by default. The `NOTES' file contains a
8758 list of systems for which this should be turned off, and
8759 `configure' disables this option automatically for a number of
8763 Use the curses library instead of the termcap library. This should
8764 be supplied if your system has an inadequate or incomplete termcap
8768 A synonym for `--with-bash-malloc'.
8770 `--with-installed-readline[=PREFIX]'
8771 Define this to make Bash link with a locally-installed version of
8772 Readline rather than the version in `lib/readline'. This works
8773 only with Readline 5.0 and later versions. If PREFIX is `yes' or
8774 not supplied, `configure' uses the values of the make variables
8775 `includedir' and `libdir', which are subdirectories of `prefix' by
8776 default, to find the installed version of Readline if it is not in
8777 the standard system include and library directories. If PREFIX is
8778 `no', Bash links with the version in `lib/readline'. If PREFIX is
8779 set to any other value, `configure' treats it as a directory
8780 pathname and looks for the installed version of Readline in
8781 subdirectories of that directory (include files in
8782 PREFIX/`include' and the library in PREFIX/`lib').
8785 Define this to use the Purify memory allocation checker from
8788 `--enable-minimal-config'
8789 This produces a shell with minimal features, close to the
8790 historical Bourne shell.
8792 There are several `--enable-' options that alter how Bash is
8793 compiled and linked, rather than changing run-time features.
8795 `--enable-largefile'
8796 Enable support for large files
8797 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
8798 the operating system requires special compiler options to build
8799 programs which can access large files. This is enabled by
8800 default, if the operating system provides large file support.
8802 `--enable-profiling'
8803 This builds a Bash binary that produces profiling information to be
8804 processed by `gprof' each time it is executed.
8806 `--enable-static-link'
8807 This causes Bash to be linked statically, if `gcc' is being used.
8808 This could be used to build a version to use as root's shell.
8810 The `minimal-config' option can be used to disable all of the
8811 following options, but it is processed first, so individual options may
8812 be enabled using `enable-FEATURE'.
8814 All of the following options except for `disabled-builtins' and
8815 `xpg-echo-default' are enabled by default, unless the operating system
8816 does not provide the necessary support.
8819 Allow alias expansion and include the `alias' and `unalias'
8820 builtins (*note Aliases::).
8822 `--enable-arith-for-command'
8823 Include support for the alternate form of the `for' command that
8824 behaves like the C language `for' statement (*note Looping
8827 `--enable-array-variables'
8828 Include support for one-dimensional array shell variables (*note
8831 `--enable-bang-history'
8832 Include support for `csh'-like history substitution (*note History
8835 `--enable-brace-expansion'
8836 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
8837 See *note Brace Expansion::, for a complete description.
8839 `--enable-casemod-attributes'
8840 Include support for case-modifying attributes in the `declare'
8841 builtin and assignment statements. Variables with the UPPERCASE
8842 attribute, for example, will have their values converted to
8843 uppercase upon assignment.
8845 `--enable-casemod-expansion'
8846 Include support for case-modifying word expansions.
8848 `--enable-command-timing'
8849 Include support for recognizing `time' as a reserved word and for
8850 displaying timing statistics for the pipeline following `time'
8851 (*note Pipelines::). This allows pipelines as well as shell
8852 builtins and functions to be timed.
8854 `--enable-cond-command'
8855 Include support for the `[[' conditional command. (*note
8856 Conditional Constructs::).
8858 `--enable-cond-regexp'
8859 Include support for matching POSIX regular expressions using the
8860 `=~' binary operator in the `[[' conditional command. (*note
8861 Conditional Constructs::).
8863 `--enable-coprocesses'
8864 Include support for coprocesses and the `coproc' reserved word
8865 (*note Pipelines::).
8868 Include support for the bash debugger (distributed separately).
8870 `--enable-directory-stack'
8871 Include support for a `csh'-like directory stack and the `pushd',
8872 `popd', and `dirs' builtins (*note The Directory Stack::).
8874 `--enable-disabled-builtins'
8875 Allow builtin commands to be invoked via `builtin xxx' even after
8876 `xxx' has been disabled using `enable -n xxx'. See *note Bash
8877 Builtins::, for details of the `builtin' and `enable' builtin
8880 `--enable-dparen-arithmetic'
8881 Include support for the `((...))' command (*note Conditional
8884 `--enable-extended-glob'
8885 Include support for the extended pattern matching features
8886 described above under *note Pattern Matching::.
8888 `--enable-extended-glob-default'
8889 Set the default value of the EXTGLOB shell option described above
8890 under *note The Shopt Builtin:: to be enabled.
8892 `--enable-help-builtin'
8893 Include the `help' builtin, which displays help on shell builtins
8894 and variables (*note Bash Builtins::).
8897 Include command history and the `fc' and `history' builtin
8898 commands (*note Bash History Facilities::).
8900 `--enable-job-control'
8901 This enables the job control features (*note Job Control::), if
8902 the operating system supports them.
8904 `--enable-multibyte'
8905 This enables support for multibyte characters if the operating
8906 system provides the necessary support.
8908 `--enable-net-redirections'
8909 This enables the special handling of filenames of the form
8910 `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in
8911 redirections (*note Redirections::).
8913 `--enable-process-substitution'
8914 This enables process substitution (*note Process Substitution::) if
8915 the operating system provides the necessary support.
8918 Enable the programmable completion facilities (*note Programmable
8919 Completion::). If Readline is not enabled, this option has no
8922 `--enable-prompt-string-decoding'
8923 Turn on the interpretation of a number of backslash-escaped
8924 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
8925 strings. See *note Printing a Prompt::, for a complete list of
8926 prompt string escape sequences.
8929 Include support for command-line editing and history with the Bash
8930 version of the Readline library (*note Command Line Editing::).
8932 `--enable-restricted'
8933 Include support for a "restricted shell". If this is enabled,
8934 Bash, when called as `rbash', enters a restricted mode. See *note
8935 The Restricted Shell::, for a description of restricted mode.
8938 Include the `select' compound command, which allows the generation
8939 of simple menus (*note Conditional Constructs::).
8941 `--enable-separate-helpfiles'
8942 Use external files for the documentation displayed by the `help'
8943 builtin instead of storing the text internally.
8945 `--enable-single-help-strings'
8946 Store the text displayed by the `help' builtin as a single string
8947 for each help topic. This aids in translating the text to
8948 different languages. You may need to disable this if your
8949 compiler cannot handle very long string literals.
8951 `--enable-strict-posix-default'
8952 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
8954 `--enable-usg-echo-default'
8955 A synonym for `--enable-xpg-echo-default'.
8957 `--enable-xpg-echo-default'
8958 Make the `echo' builtin expand backslash-escaped characters by
8959 default, without requiring the `-e' option. This sets the default
8960 value of the `xpg_echo' shell option to `on', which makes the Bash
8961 `echo' behave more like the version specified in the Single Unix
8962 Specification, version 3. *Note Bash Builtins::, for a
8963 description of the escape sequences that `echo' recognizes.
8966 The file `config-top.h' contains C Preprocessor `#define' statements
8967 for options which are not settable from `configure'. Some of these are
8968 not meant to be changed; beware of the consequences if you do. Read
8969 the comments associated with each definition for more information about
8973 File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
8975 Appendix A Reporting Bugs
8976 *************************
8978 Please report all bugs you find in Bash. But first, you should make
8979 sure that it really is a bug, and that it appears in the latest version
8980 of Bash. The latest version of Bash is always available for FTP from
8981 `ftp://ftp.gnu.org/pub/gnu/bash/'.
8983 Once you have determined that a bug actually exists, use the
8984 `bashbug' command to submit a bug report. If you have a fix, you are
8985 encouraged to mail that as well! Suggestions and `philosophical' bug
8986 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
8987 newsgroup `gnu.bash.bug'.
8989 All bug reports should include:
8990 * The version number of Bash.
8992 * The hardware and operating system.
8994 * The compiler used to compile Bash.
8996 * A description of the bug behaviour.
8998 * A short script or `recipe' which exercises the bug and may be used
9001 `bashbug' inserts the first three items automatically into the template
9002 it provides for filing a bug report.
9004 Please send all reports concerning this manual to
9005 <chet.ramey@case.edu>.
9008 File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
9010 Appendix B Major Differences From The Bourne Shell
9011 **************************************************
9013 Bash implements essentially the same grammar, parameter and variable
9014 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
9015 POSIX standard as the specification of how these features are to be
9016 implemented. There are some differences between the traditional Bourne
9017 shell and Bash; this section quickly details the differences of
9018 significance. A number of these differences are explained in greater
9019 depth in previous sections. This section uses the version of `sh'
9020 included in SVR4.2 (the last version of the historical Bourne shell) as
9021 the baseline reference.
9023 * Bash is POSIX-conformant, even where the POSIX specification
9024 differs from traditional `sh' behavior (*note Bash POSIX Mode::).
9026 * Bash has multi-character invocation options (*note Invoking
9029 * Bash has command-line editing (*note Command Line Editing::) and
9032 * Bash provides a programmable word completion mechanism (*note
9033 Programmable Completion::), and builtin commands `complete',
9034 `compgen', and `compopt', to manipulate it.
9036 * Bash has command history (*note Bash History Facilities::) and the
9037 `history' and `fc' builtins to manipulate it. The Bash history
9038 list maintains timestamp information and uses the value of the
9039 `HISTTIMEFORMAT' variable to display it.
9041 * Bash implements `csh'-like history expansion (*note History
9044 * Bash has one-dimensional array variables (*note Arrays::), and the
9045 appropriate variable expansions and assignment syntax to use them.
9046 Several of the Bash builtins take options to act on arrays. Bash
9047 provides a number of built-in array variables.
9049 * The `$'...'' quoting syntax, which expands ANSI-C
9050 backslash-escaped characters in the text between the single quotes,
9051 is supported (*note ANSI-C Quoting::).
9053 * Bash supports the `$"..."' quoting syntax to do locale-specific
9054 translation of the characters between the double quotes. The
9055 `-D', `--dump-strings', and `--dump-po-strings' invocation options
9056 list the translatable strings found in a script (*note Locale
9059 * Bash implements the `!' keyword to negate the return value of a
9060 pipeline (*note Pipelines::). Very useful when an `if' statement
9061 needs to act only if a test fails. The Bash `-o pipefail' option
9062 to `set' will cause a pipeline to return a failure status if any
9065 * Bash has the `time' reserved word and command timing (*note
9066 Pipelines::). The display of the timing statistics may be
9067 controlled with the `TIMEFORMAT' variable.
9069 * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
9070 for command, similar to the C language (*note Looping
9073 * Bash includes the `select' compound command, which allows the
9074 generation of simple menus (*note Conditional Constructs::).
9076 * Bash includes the `[[' compound command, which makes conditional
9077 testing part of the shell grammar (*note Conditional
9078 Constructs::), including optional regular expression matching.
9080 * Bash provides optional case-insensitive matching for the `case' and
9083 * Bash includes brace expansion (*note Brace Expansion::) and tilde
9084 expansion (*note Tilde Expansion::).
9086 * Bash implements command aliases and the `alias' and `unalias'
9087 builtins (*note Aliases::).
9089 * Bash provides shell arithmetic, the `((' compound command (*note
9090 Conditional Constructs::), and arithmetic expansion (*note Shell
9093 * Variables present in the shell's initial environment are
9094 automatically exported to child processes. The Bourne shell does
9095 not normally do this unless the variables are explicitly marked
9096 using the `export' command.
9098 * Bash supports the `+=' assignment operator, which appends to the
9099 value of the variable named on the left hand side.
9101 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
9102 expansions to remove leading or trailing substrings from variable
9103 values (*note Shell Parameter Expansion::).
9105 * The expansion `${#xx}', which returns the length of `${xx}', is
9106 supported (*note Shell Parameter Expansion::).
9108 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
9109 substring of `var''s value of length LENGTH, beginning at OFFSET,
9110 is present (*note Shell Parameter Expansion::).
9112 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
9113 PATTERN and replaces it with REPLACEMENT in the value of `var', is
9114 available (*note Shell Parameter Expansion::).
9116 * The expansion `${!PREFIX}*' expansion, which expands to the names
9117 of all shell variables whose names begin with PREFIX, is available
9118 (*note Shell Parameter Expansion::).
9120 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
9121 Parameter Expansion::).
9123 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
9125 * The POSIX `$()' form of command substitution is implemented (*note
9126 Command Substitution::), and preferred to the Bourne shell's ```'
9127 (which is also implemented for backwards compatibility).
9129 * Bash has process substitution (*note Process Substitution::).
9131 * Bash automatically assigns variables that provide information
9132 about the current user (`UID', `EUID', and `GROUPS'), the current
9133 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
9134 instance of Bash that is running (`BASH', `BASH_VERSION', and
9135 `BASH_VERSINFO'). *Note Bash Variables::, for details.
9137 * The `IFS' variable is used to split only the results of expansion,
9138 not all words (*note Word Splitting::). This closes a
9139 longstanding shell security hole.
9141 * Bash implements the full set of POSIX filename expansion operators,
9142 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
9143 SYMBOLS (*note Filename Expansion::).
9145 * Bash implements extended pattern matching features when the
9146 `extglob' shell option is enabled (*note Pattern Matching::).
9148 * It is possible to have a variable and a function with the same
9149 name; `sh' does not separate the two name spaces.
9151 * Bash functions are permitted to have local variables using the
9152 `local' builtin, and thus useful recursive functions may be written
9153 (*note Bash Builtins::).
9155 * Variable assignments preceding commands affect only that command,
9156 even builtins and functions (*note Environment::). In `sh', all
9157 variable assignments preceding commands are global unless the
9158 command is executed from the file system.
9160 * Bash performs filename expansion on filenames specified as operands
9161 to input and output redirection operators (*note Redirections::).
9163 * Bash contains the `<>' redirection operator, allowing a file to be
9164 opened for both reading and writing, and the `&>' redirection
9165 operator, for directing standard output and standard error to the
9166 same file (*note Redirections::).
9168 * Bash includes the `<<<' redirection operator, allowing a string to
9169 be used as the standard input to a command.
9171 * Bash implements the `[n]<&WORD' and `[n]>&WORD' redirection
9172 operators, which move one file descriptor to another.
9174 * Bash treats a number of filenames specially when they are used in
9175 redirection operators (*note Redirections::).
9177 * Bash can open network connections to arbitrary machines and
9178 services with the redirection operators (*note Redirections::).
9180 * The `noclobber' option is available to avoid overwriting existing
9181 files with output redirection (*note The Set Builtin::). The `>|'
9182 redirection operator may be used to override `noclobber'.
9184 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::)
9185 each take `-L' and `-P' options to switch between logical and
9188 * Bash allows a function to override a builtin with the same name,
9189 and provides access to that builtin's functionality within the
9190 function via the `builtin' and `command' builtins (*note Bash
9193 * The `command' builtin allows selective disabling of functions when
9194 command lookup is performed (*note Bash Builtins::).
9196 * Individual builtins may be enabled or disabled using the `enable'
9197 builtin (*note Bash Builtins::).
9199 * The Bash `exec' builtin takes additional options that allow users
9200 to control the contents of the environment passed to the executed
9201 command, and what the zeroth argument to the command is to be
9202 (*note Bourne Shell Builtins::).
9204 * Shell functions may be exported to children via the environment
9205 using `export -f' (*note Shell Functions::).
9207 * The Bash `export', `readonly', and `declare' builtins can take a
9208 `-f' option to act on shell functions, a `-p' option to display
9209 variables with various attributes set in a format that can be used
9210 as shell input, a `-n' option to remove various variable
9211 attributes, and `name=value' arguments to set variable attributes
9212 and values simultaneously.
9214 * The Bash `hash' builtin allows a name to be associated with an
9215 arbitrary filename, even when that filename cannot be found by
9216 searching the `$PATH', using `hash -p' (*note Bourne Shell
9219 * Bash includes a `help' builtin for quick reference to shell
9220 facilities (*note Bash Builtins::).
9222 * The `printf' builtin is available to display formatted output
9223 (*note Bash Builtins::).
9225 * The Bash `read' builtin (*note Bash Builtins::) will read a line
9226 ending in `\' with the `-r' option, and will use the `REPLY'
9227 variable as a default if no non-option arguments are supplied.
9228 The Bash `read' builtin also accepts a prompt string with the `-p'
9229 option and will use Readline to obtain the line when given the
9230 `-e' option. The `read' builtin also has additional options to
9231 control input: the `-s' option will turn off echoing of input
9232 characters as they are read, the `-t' option will allow `read' to
9233 time out if input does not arrive within a specified number of
9234 seconds, the `-n' option will allow reading only a specified
9235 number of characters rather than a full line, and the `-d' option
9236 will read until a particular character rather than newline.
9238 * The `return' builtin may be used to abort execution of scripts
9239 executed with the `.' or `source' builtins (*note Bourne Shell
9242 * Bash includes the `shopt' builtin, for finer control of shell
9243 optional capabilities (*note The Shopt Builtin::), and allows
9244 these options to be set and unset at shell invocation (*note
9247 * Bash has much more optional behavior controllable with the `set'
9248 builtin (*note The Set Builtin::).
9250 * The `-x' (`xtrace') option displays commands other than simple
9251 commands when performing an execution trace (*note The Set
9254 * The `test' builtin (*note Bourne Shell Builtins::) is slightly
9255 different, as it implements the POSIX algorithm, which specifies
9256 the behavior based on the number of arguments.
9258 * Bash includes the `caller' builtin, which displays the context of
9259 any active subroutine call (a shell function or a script executed
9260 with the `.' or `source' builtins). This supports the bash
9263 * The `trap' builtin (*note Bourne Shell Builtins::) allows a
9264 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
9265 specified with a `DEBUG' trap are executed before every simple
9266 command, `for' command, `case' command, `select' command, every
9267 arithmetic `for' command, and before the first command executes in
9268 a shell function. The `DEBUG' trap is not inherited by shell
9269 functions unless the function has been given the `trace' attribute
9270 or the `functrace' option has been enabled using the `shopt'
9271 builtin. The `extdebug' shell option has additional effects on the
9274 The `trap' builtin (*note Bourne Shell Builtins::) allows an `ERR'
9275 pseudo-signal specification, similar to `EXIT' and `DEBUG'.
9276 Commands specified with an `ERR' trap are executed after a simple
9277 command fails, with a few exceptions. The `ERR' trap is not
9278 inherited by shell functions unless the `-o errtrace' option to
9279 the `set' builtin is enabled.
9281 The `trap' builtin (*note Bourne Shell Builtins::) allows a
9282 `RETURN' pseudo-signal specification, similar to `EXIT' and
9283 `DEBUG'. Commands specified with an `RETURN' trap are executed
9284 before execution resumes after a shell function or a shell script
9285 executed with `.' or `source' returns. The `RETURN' trap is not
9286 inherited by shell functions unless the function has been given
9287 the `trace' attribute or the `functrace' option has been enabled
9288 using the `shopt' builtin.
9290 * The Bash `type' builtin is more extensive and gives more
9291 information about the names it finds (*note Bash Builtins::).
9293 * The Bash `umask' builtin permits a `-p' option to cause the output
9294 to be displayed in the form of a `umask' command that may be
9295 reused as input (*note Bourne Shell Builtins::).
9297 * Bash implements a `csh'-like directory stack, and provides the
9298 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
9299 Directory Stack::). Bash also makes the directory stack visible
9300 as the value of the `DIRSTACK' shell variable.
9302 * Bash interprets special backslash-escaped characters in the prompt
9303 strings when interactive (*note Printing a Prompt::).
9305 * The Bash restricted mode is more useful (*note The Restricted
9306 Shell::); the SVR4.2 shell restricted mode is too limited.
9308 * The `disown' builtin can remove a job from the internal shell job
9309 table (*note Job Control Builtins::) or suppress the sending of
9310 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
9312 * Bash includes a number of features to support a separate debugger
9315 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
9316 `priv') not present in Bash.
9318 * Bash does not have the `stop' or `newgrp' builtins.
9320 * Bash does not use the `SHACCT' variable or perform shell
9323 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
9326 More features unique to Bash may be found in *note Bash Features::.
9328 B.1 Implementation Differences From The SVR4.2 Shell
9329 ====================================================
9331 Since Bash is a completely new implementation, it does not suffer from
9332 many of the limitations of the SVR4.2 shell. For instance:
9334 * Bash does not fork a subshell when redirecting into or out of a
9335 shell control structure such as an `if' or `while' statement.
9337 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
9338 silently insert a needed closing quote at `EOF' under certain
9339 circumstances. This can be the cause of some hard-to-find errors.
9341 * The SVR4.2 shell uses a baroque memory management scheme based on
9342 trapping `SIGSEGV'. If the shell is started from a process with
9343 `SIGSEGV' blocked (e.g., by using the `system()' C library
9344 function call), it misbehaves badly.
9346 * In a questionable attempt at security, the SVR4.2 shell, when
9347 invoked without the `-p' option, will alter its real and effective
9348 UID and GID if they are less than some magic threshold value,
9349 commonly 100. This can lead to unexpected results.
9351 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
9352 `SIGALRM', or `SIGCHLD'.
9354 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
9355 `PS1', or `PS2' variables to be unset.
9357 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
9359 * Bash allows multiple option arguments when it is invoked (`-x -v');
9360 the SVR4.2 shell allows only one option argument (`-xv'). In
9361 fact, some versions of the shell dump core if the second argument
9364 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
9365 script only if one of the POSIX special builtins fails, and only
9366 for certain failures, as enumerated in the POSIX standard.
9368 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
9369 turns on job control).
9372 File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
9374 Appendix C GNU Free Documentation License
9375 *****************************************
9377 Version 1.3, 3 November 2008
9379 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
9382 Everyone is permitted to copy and distribute verbatim copies
9383 of this license document, but changing it is not allowed.
9387 The purpose of this License is to make a manual, textbook, or other
9388 functional and useful document "free" in the sense of freedom: to
9389 assure everyone the effective freedom to copy and redistribute it,
9390 with or without modifying it, either commercially or
9391 noncommercially. Secondarily, this License preserves for the
9392 author and publisher a way to get credit for their work, while not
9393 being considered responsible for modifications made by others.
9395 This License is a kind of "copyleft", which means that derivative
9396 works of the document must themselves be free in the same sense.
9397 It complements the GNU General Public License, which is a copyleft
9398 license designed for free software.
9400 We have designed this License in order to use it for manuals for
9401 free software, because free software needs free documentation: a
9402 free program should come with manuals providing the same freedoms
9403 that the software does. But this License is not limited to
9404 software manuals; it can be used for any textual work, regardless
9405 of subject matter or whether it is published as a printed book.
9406 We recommend this License principally for works whose purpose is
9407 instruction or reference.
9409 1. APPLICABILITY AND DEFINITIONS
9411 This License applies to any manual or other work, in any medium,
9412 that contains a notice placed by the copyright holder saying it
9413 can be distributed under the terms of this License. Such a notice
9414 grants a world-wide, royalty-free license, unlimited in duration,
9415 to use that work under the conditions stated herein. The
9416 "Document", below, refers to any such manual or work. Any member
9417 of the public is a licensee, and is addressed as "you". You
9418 accept the license if you copy, modify or distribute the work in a
9419 way requiring permission under copyright law.
9421 A "Modified Version" of the Document means any work containing the
9422 Document or a portion of it, either copied verbatim, or with
9423 modifications and/or translated into another language.
9425 A "Secondary Section" is a named appendix or a front-matter section
9426 of the Document that deals exclusively with the relationship of the
9427 publishers or authors of the Document to the Document's overall
9428 subject (or to related matters) and contains nothing that could
9429 fall directly within that overall subject. (Thus, if the Document
9430 is in part a textbook of mathematics, a Secondary Section may not
9431 explain any mathematics.) The relationship could be a matter of
9432 historical connection with the subject or with related matters, or
9433 of legal, commercial, philosophical, ethical or political position
9436 The "Invariant Sections" are certain Secondary Sections whose
9437 titles are designated, as being those of Invariant Sections, in
9438 the notice that says that the Document is released under this
9439 License. If a section does not fit the above definition of
9440 Secondary then it is not allowed to be designated as Invariant.
9441 The Document may contain zero Invariant Sections. If the Document
9442 does not identify any Invariant Sections then there are none.
9444 The "Cover Texts" are certain short passages of text that are
9445 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
9446 that says that the Document is released under this License. A
9447 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
9448 be at most 25 words.
9450 A "Transparent" copy of the Document means a machine-readable copy,
9451 represented in a format whose specification is available to the
9452 general public, that is suitable for revising the document
9453 straightforwardly with generic text editors or (for images
9454 composed of pixels) generic paint programs or (for drawings) some
9455 widely available drawing editor, and that is suitable for input to
9456 text formatters or for automatic translation to a variety of
9457 formats suitable for input to text formatters. A copy made in an
9458 otherwise Transparent file format whose markup, or absence of
9459 markup, has been arranged to thwart or discourage subsequent
9460 modification by readers is not Transparent. An image format is
9461 not Transparent if used for any substantial amount of text. A
9462 copy that is not "Transparent" is called "Opaque".
9464 Examples of suitable formats for Transparent copies include plain
9465 ASCII without markup, Texinfo input format, LaTeX input format,
9466 SGML or XML using a publicly available DTD, and
9467 standard-conforming simple HTML, PostScript or PDF designed for
9468 human modification. Examples of transparent image formats include
9469 PNG, XCF and JPG. Opaque formats include proprietary formats that
9470 can be read and edited only by proprietary word processors, SGML or
9471 XML for which the DTD and/or processing tools are not generally
9472 available, and the machine-generated HTML, PostScript or PDF
9473 produced by some word processors for output purposes only.
9475 The "Title Page" means, for a printed book, the title page itself,
9476 plus such following pages as are needed to hold, legibly, the
9477 material this License requires to appear in the title page. For
9478 works in formats which do not have any title page as such, "Title
9479 Page" means the text near the most prominent appearance of the
9480 work's title, preceding the beginning of the body of the text.
9482 The "publisher" means any person or entity that distributes copies
9483 of the Document to the public.
9485 A section "Entitled XYZ" means a named subunit of the Document
9486 whose title either is precisely XYZ or contains XYZ in parentheses
9487 following text that translates XYZ in another language. (Here XYZ
9488 stands for a specific section name mentioned below, such as
9489 "Acknowledgements", "Dedications", "Endorsements", or "History".)
9490 To "Preserve the Title" of such a section when you modify the
9491 Document means that it remains a section "Entitled XYZ" according
9494 The Document may include Warranty Disclaimers next to the notice
9495 which states that this License applies to the Document. These
9496 Warranty Disclaimers are considered to be included by reference in
9497 this License, but only as regards disclaiming warranties: any other
9498 implication that these Warranty Disclaimers may have is void and
9499 has no effect on the meaning of this License.
9503 You may copy and distribute the Document in any medium, either
9504 commercially or noncommercially, provided that this License, the
9505 copyright notices, and the license notice saying this License
9506 applies to the Document are reproduced in all copies, and that you
9507 add no other conditions whatsoever to those of this License. You
9508 may not use technical measures to obstruct or control the reading
9509 or further copying of the copies you make or distribute. However,
9510 you may accept compensation in exchange for copies. If you
9511 distribute a large enough number of copies you must also follow
9512 the conditions in section 3.
9514 You may also lend copies, under the same conditions stated above,
9515 and you may publicly display copies.
9517 3. COPYING IN QUANTITY
9519 If you publish printed copies (or copies in media that commonly
9520 have printed covers) of the Document, numbering more than 100, and
9521 the Document's license notice requires Cover Texts, you must
9522 enclose the copies in covers that carry, clearly and legibly, all
9523 these Cover Texts: Front-Cover Texts on the front cover, and
9524 Back-Cover Texts on the back cover. Both covers must also clearly
9525 and legibly identify you as the publisher of these copies. The
9526 front cover must present the full title with all words of the
9527 title equally prominent and visible. You may add other material
9528 on the covers in addition. Copying with changes limited to the
9529 covers, as long as they preserve the title of the Document and
9530 satisfy these conditions, can be treated as verbatim copying in
9533 If the required texts for either cover are too voluminous to fit
9534 legibly, you should put the first ones listed (as many as fit
9535 reasonably) on the actual cover, and continue the rest onto
9538 If you publish or distribute Opaque copies of the Document
9539 numbering more than 100, you must either include a
9540 machine-readable Transparent copy along with each Opaque copy, or
9541 state in or with each Opaque copy a computer-network location from
9542 which the general network-using public has access to download
9543 using public-standard network protocols a complete Transparent
9544 copy of the Document, free of added material. If you use the
9545 latter option, you must take reasonably prudent steps, when you
9546 begin distribution of Opaque copies in quantity, to ensure that
9547 this Transparent copy will remain thus accessible at the stated
9548 location until at least one year after the last time you
9549 distribute an Opaque copy (directly or through your agents or
9550 retailers) of that edition to the public.
9552 It is requested, but not required, that you contact the authors of
9553 the Document well before redistributing any large number of
9554 copies, to give them a chance to provide you with an updated
9555 version of the Document.
9559 You may copy and distribute a Modified Version of the Document
9560 under the conditions of sections 2 and 3 above, provided that you
9561 release the Modified Version under precisely this License, with
9562 the Modified Version filling the role of the Document, thus
9563 licensing distribution and modification of the Modified Version to
9564 whoever possesses a copy of it. In addition, you must do these
9565 things in the Modified Version:
9567 A. Use in the Title Page (and on the covers, if any) a title
9568 distinct from that of the Document, and from those of
9569 previous versions (which should, if there were any, be listed
9570 in the History section of the Document). You may use the
9571 same title as a previous version if the original publisher of
9572 that version gives permission.
9574 B. List on the Title Page, as authors, one or more persons or
9575 entities responsible for authorship of the modifications in
9576 the Modified Version, together with at least five of the
9577 principal authors of the Document (all of its principal
9578 authors, if it has fewer than five), unless they release you
9579 from this requirement.
9581 C. State on the Title page the name of the publisher of the
9582 Modified Version, as the publisher.
9584 D. Preserve all the copyright notices of the Document.
9586 E. Add an appropriate copyright notice for your modifications
9587 adjacent to the other copyright notices.
9589 F. Include, immediately after the copyright notices, a license
9590 notice giving the public permission to use the Modified
9591 Version under the terms of this License, in the form shown in
9594 G. Preserve in that license notice the full lists of Invariant
9595 Sections and required Cover Texts given in the Document's
9598 H. Include an unaltered copy of this License.
9600 I. Preserve the section Entitled "History", Preserve its Title,
9601 and add to it an item stating at least the title, year, new
9602 authors, and publisher of the Modified Version as given on
9603 the Title Page. If there is no section Entitled "History" in
9604 the Document, create one stating the title, year, authors,
9605 and publisher of the Document as given on its Title Page,
9606 then add an item describing the Modified Version as stated in
9607 the previous sentence.
9609 J. Preserve the network location, if any, given in the Document
9610 for public access to a Transparent copy of the Document, and
9611 likewise the network locations given in the Document for
9612 previous versions it was based on. These may be placed in
9613 the "History" section. You may omit a network location for a
9614 work that was published at least four years before the
9615 Document itself, or if the original publisher of the version
9616 it refers to gives permission.
9618 K. For any section Entitled "Acknowledgements" or "Dedications",
9619 Preserve the Title of the section, and preserve in the
9620 section all the substance and tone of each of the contributor
9621 acknowledgements and/or dedications given therein.
9623 L. Preserve all the Invariant Sections of the Document,
9624 unaltered in their text and in their titles. Section numbers
9625 or the equivalent are not considered part of the section
9628 M. Delete any section Entitled "Endorsements". Such a section
9629 may not be included in the Modified Version.
9631 N. Do not retitle any existing section to be Entitled
9632 "Endorsements" or to conflict in title with any Invariant
9635 O. Preserve any Warranty Disclaimers.
9637 If the Modified Version includes new front-matter sections or
9638 appendices that qualify as Secondary Sections and contain no
9639 material copied from the Document, you may at your option
9640 designate some or all of these sections as invariant. To do this,
9641 add their titles to the list of Invariant Sections in the Modified
9642 Version's license notice. These titles must be distinct from any
9643 other section titles.
9645 You may add a section Entitled "Endorsements", provided it contains
9646 nothing but endorsements of your Modified Version by various
9647 parties--for example, statements of peer review or that the text
9648 has been approved by an organization as the authoritative
9649 definition of a standard.
9651 You may add a passage of up to five words as a Front-Cover Text,
9652 and a passage of up to 25 words as a Back-Cover Text, to the end
9653 of the list of Cover Texts in the Modified Version. Only one
9654 passage of Front-Cover Text and one of Back-Cover Text may be
9655 added by (or through arrangements made by) any one entity. If the
9656 Document already includes a cover text for the same cover,
9657 previously added by you or by arrangement made by the same entity
9658 you are acting on behalf of, you may not add another; but you may
9659 replace the old one, on explicit permission from the previous
9660 publisher that added the old one.
9662 The author(s) and publisher(s) of the Document do not by this
9663 License give permission to use their names for publicity for or to
9664 assert or imply endorsement of any Modified Version.
9666 5. COMBINING DOCUMENTS
9668 You may combine the Document with other documents released under
9669 this License, under the terms defined in section 4 above for
9670 modified versions, provided that you include in the combination
9671 all of the Invariant Sections of all of the original documents,
9672 unmodified, and list them all as Invariant Sections of your
9673 combined work in its license notice, and that you preserve all
9674 their Warranty Disclaimers.
9676 The combined work need only contain one copy of this License, and
9677 multiple identical Invariant Sections may be replaced with a single
9678 copy. If there are multiple Invariant Sections with the same name
9679 but different contents, make the title of each such section unique
9680 by adding at the end of it, in parentheses, the name of the
9681 original author or publisher of that section if known, or else a
9682 unique number. Make the same adjustment to the section titles in
9683 the list of Invariant Sections in the license notice of the
9686 In the combination, you must combine any sections Entitled
9687 "History" in the various original documents, forming one section
9688 Entitled "History"; likewise combine any sections Entitled
9689 "Acknowledgements", and any sections Entitled "Dedications". You
9690 must delete all sections Entitled "Endorsements."
9692 6. COLLECTIONS OF DOCUMENTS
9694 You may make a collection consisting of the Document and other
9695 documents released under this License, and replace the individual
9696 copies of this License in the various documents with a single copy
9697 that is included in the collection, provided that you follow the
9698 rules of this License for verbatim copying of each of the
9699 documents in all other respects.
9701 You may extract a single document from such a collection, and
9702 distribute it individually under this License, provided you insert
9703 a copy of this License into the extracted document, and follow
9704 this License in all other respects regarding verbatim copying of
9707 7. AGGREGATION WITH INDEPENDENT WORKS
9709 A compilation of the Document or its derivatives with other
9710 separate and independent documents or works, in or on a volume of
9711 a storage or distribution medium, is called an "aggregate" if the
9712 copyright resulting from the compilation is not used to limit the
9713 legal rights of the compilation's users beyond what the individual
9714 works permit. When the Document is included in an aggregate, this
9715 License does not apply to the other works in the aggregate which
9716 are not themselves derivative works of the Document.
9718 If the Cover Text requirement of section 3 is applicable to these
9719 copies of the Document, then if the Document is less than one half
9720 of the entire aggregate, the Document's Cover Texts may be placed
9721 on covers that bracket the Document within the aggregate, or the
9722 electronic equivalent of covers if the Document is in electronic
9723 form. Otherwise they must appear on printed covers that bracket
9724 the whole aggregate.
9728 Translation is considered a kind of modification, so you may
9729 distribute translations of the Document under the terms of section
9730 4. Replacing Invariant Sections with translations requires special
9731 permission from their copyright holders, but you may include
9732 translations of some or all Invariant Sections in addition to the
9733 original versions of these Invariant Sections. You may include a
9734 translation of this License, and all the license notices in the
9735 Document, and any Warranty Disclaimers, provided that you also
9736 include the original English version of this License and the
9737 original versions of those notices and disclaimers. In case of a
9738 disagreement between the translation and the original version of
9739 this License or a notice or disclaimer, the original version will
9742 If a section in the Document is Entitled "Acknowledgements",
9743 "Dedications", or "History", the requirement (section 4) to
9744 Preserve its Title (section 1) will typically require changing the
9749 You may not copy, modify, sublicense, or distribute the Document
9750 except as expressly provided under this License. Any attempt
9751 otherwise to copy, modify, sublicense, or distribute it is void,
9752 and will automatically terminate your rights under this License.
9754 However, if you cease all violation of this License, then your
9755 license from a particular copyright holder is reinstated (a)
9756 provisionally, unless and until the copyright holder explicitly
9757 and finally terminates your license, and (b) permanently, if the
9758 copyright holder fails to notify you of the violation by some
9759 reasonable means prior to 60 days after the cessation.
9761 Moreover, your license from a particular copyright holder is
9762 reinstated permanently if the copyright holder notifies you of the
9763 violation by some reasonable means, this is the first time you have
9764 received notice of violation of this License (for any work) from
9765 that copyright holder, and you cure the violation prior to 30 days
9766 after your receipt of the notice.
9768 Termination of your rights under this section does not terminate
9769 the licenses of parties who have received copies or rights from
9770 you under this License. If your rights have been terminated and
9771 not permanently reinstated, receipt of a copy of some or all of
9772 the same material does not give you any rights to use it.
9774 10. FUTURE REVISIONS OF THIS LICENSE
9776 The Free Software Foundation may publish new, revised versions of
9777 the GNU Free Documentation License from time to time. Such new
9778 versions will be similar in spirit to the present version, but may
9779 differ in detail to address new problems or concerns. See
9780 `http://www.gnu.org/copyleft/'.
9782 Each version of the License is given a distinguishing version
9783 number. If the Document specifies that a particular numbered
9784 version of this License "or any later version" applies to it, you
9785 have the option of following the terms and conditions either of
9786 that specified version or of any later version that has been
9787 published (not as a draft) by the Free Software Foundation. If
9788 the Document does not specify a version number of this License,
9789 you may choose any version ever published (not as a draft) by the
9790 Free Software Foundation. If the Document specifies that a proxy
9791 can decide which future versions of this License can be used, that
9792 proxy's public statement of acceptance of a version permanently
9793 authorizes you to choose that version for the Document.
9797 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
9798 World Wide Web server that publishes copyrightable works and also
9799 provides prominent facilities for anybody to edit those works. A
9800 public wiki that anybody can edit is an example of such a server.
9801 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
9802 site means any set of copyrightable works thus published on the MMC
9805 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
9806 license published by Creative Commons Corporation, a not-for-profit
9807 corporation with a principal place of business in San Francisco,
9808 California, as well as future copyleft versions of that license
9809 published by that same organization.
9811 "Incorporate" means to publish or republish a Document, in whole or
9812 in part, as part of another Document.
9814 An MMC is "eligible for relicensing" if it is licensed under this
9815 License, and if all works that were first published under this
9816 License somewhere other than this MMC, and subsequently
9817 incorporated in whole or in part into the MMC, (1) had no cover
9818 texts or invariant sections, and (2) were thus incorporated prior
9819 to November 1, 2008.
9821 The operator of an MMC Site may republish an MMC contained in the
9822 site under CC-BY-SA on the same site at any time before August 1,
9823 2009, provided the MMC is eligible for relicensing.
9826 ADDENDUM: How to use this License for your documents
9827 ====================================================
9829 To use this License in a document you have written, include a copy of
9830 the License in the document and put the following copyright and license
9831 notices just after the title page:
9833 Copyright (C) YEAR YOUR NAME.
9834 Permission is granted to copy, distribute and/or modify this document
9835 under the terms of the GNU Free Documentation License, Version 1.3
9836 or any later version published by the Free Software Foundation;
9837 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
9838 Texts. A copy of the license is included in the section entitled ``GNU
9839 Free Documentation License''.
9841 If you have Invariant Sections, Front-Cover Texts and Back-Cover
9842 Texts, replace the "with...Texts." line with this:
9844 with the Invariant Sections being LIST THEIR TITLES, with
9845 the Front-Cover Texts being LIST, and with the Back-Cover Texts
9848 If you have Invariant Sections without Cover Texts, or some other
9849 combination of the three, merge those two alternatives to suit the
9852 If your document contains nontrivial examples of program code, we
9853 recommend releasing these examples in parallel under your choice of
9854 free software license, such as the GNU General Public License, to
9855 permit their use in free software.
9858 File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
9865 * Builtin Index:: Index of Bash builtin commands.
9866 * Reserved Word Index:: Index of Bash reserved words.
9867 * Variable Index:: Quick reference helps you find the
9869 * Function Index:: Index of bindable Readline functions.
9870 * Concept Index:: General index for concepts described in
9874 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
9876 D.1 Index of Shell Builtin Commands
9877 ===================================
9882 * .: Bourne Shell Builtins.
9884 * :: Bourne Shell Builtins.
9886 * [: Bourne Shell Builtins.
9888 * alias: Bash Builtins. (line 11)
9889 * bg: Job Control Builtins.
9891 * bind: Bash Builtins. (line 21)
9892 * break: Bourne Shell Builtins.
9894 * builtin: Bash Builtins. (line 98)
9895 * caller: Bash Builtins. (line 106)
9896 * cd: Bourne Shell Builtins.
9898 * command: Bash Builtins. (line 123)
9899 * compgen: Programmable Completion Builtins.
9901 * complete: Programmable Completion Builtins.
9903 * compopt: Programmable Completion Builtins.
9905 * continue: Bourne Shell Builtins.
9907 * declare: Bash Builtins. (line 142)
9908 * dirs: Directory Stack Builtins.
9910 * disown: Job Control Builtins.
9912 * echo: Bash Builtins. (line 226)
9913 * enable: Bash Builtins. (line 287)
9914 * eval: Bourne Shell Builtins.
9916 * exec: Bourne Shell Builtins.
9918 * exit: Bourne Shell Builtins.
9920 * export: Bourne Shell Builtins.
9922 * fc: Bash History Builtins.
9924 * fg: Job Control Builtins.
9926 * getopts: Bourne Shell Builtins.
9928 * hash: Bourne Shell Builtins.
9930 * help: Bash Builtins. (line 315)
9931 * history: Bash History Builtins.
9933 * jobs: Job Control Builtins.
9935 * kill: Job Control Builtins.
9937 * let: Bash Builtins. (line 335)
9938 * local: Bash Builtins. (line 342)
9939 * logout: Bash Builtins. (line 352)
9940 * mapfile: Bash Builtins. (line 356)
9941 * popd: Directory Stack Builtins.
9943 * printf: Bash Builtins. (line 402)
9944 * pushd: Directory Stack Builtins.
9946 * pwd: Bourne Shell Builtins.
9948 * read: Bash Builtins. (line 447)
9949 * readarray: Bash Builtins. (line 527)
9950 * readonly: Bourne Shell Builtins.
9952 * return: Bourne Shell Builtins.
9954 * set: The Set Builtin. (line 11)
9955 * shift: Bourne Shell Builtins.
9957 * shopt: The Shopt Builtin. (line 9)
9958 * source: Bash Builtins. (line 535)
9959 * suspend: Job Control Builtins.
9961 * test: Bourne Shell Builtins.
9963 * times: Bourne Shell Builtins.
9965 * trap: Bourne Shell Builtins.
9967 * type: Bash Builtins. (line 539)
9968 * typeset: Bash Builtins. (line 570)
9969 * ulimit: Bash Builtins. (line 576)
9970 * umask: Bourne Shell Builtins.
9972 * unalias: Bash Builtins. (line 665)
9973 * unset: Bourne Shell Builtins.
9975 * wait: Job Control Builtins.
9979 File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
9981 D.2 Index of Shell Reserved Words
9982 =================================
9987 * !: Pipelines. (line 9)
9988 * [[: Conditional Constructs.
9990 * ]]: Conditional Constructs.
9992 * case: Conditional Constructs.
9994 * do: Looping Constructs. (line 12)
9995 * done: Looping Constructs. (line 12)
9996 * elif: Conditional Constructs.
9998 * else: Conditional Constructs.
10000 * esac: Conditional Constructs.
10002 * fi: Conditional Constructs.
10004 * for: Looping Constructs. (line 29)
10005 * function: Shell Functions. (line 13)
10006 * if: Conditional Constructs.
10008 * in: Conditional Constructs.
10010 * select: Conditional Constructs.
10012 * then: Conditional Constructs.
10014 * time: Pipelines. (line 9)
10015 * until: Looping Constructs. (line 12)
10016 * while: Looping Constructs. (line 20)
10017 * {: Command Grouping. (line 21)
10018 * }: Command Grouping. (line 21)
10021 File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
10023 D.3 Parameter and Variable Index
10024 ================================
10029 * !: Special Parameters. (line 46)
10030 * #: Special Parameters. (line 30)
10031 * $: Special Parameters. (line 42)
10032 * *: Special Parameters. (line 9)
10033 * -: Special Parameters. (line 37)
10034 * 0: Special Parameters. (line 50)
10035 * ?: Special Parameters. (line 33)
10036 * @: Special Parameters. (line 19)
10037 * _: Special Parameters. (line 59)
10038 * auto_resume: Job Control Variables.
10040 * BASH: Bash Variables. (line 13)
10041 * BASH_ALIASES: Bash Variables. (line 30)
10042 * BASH_ARGC: Bash Variables. (line 37)
10043 * BASH_ARGV: Bash Variables. (line 47)
10044 * BASH_CMDS: Bash Variables. (line 57)
10045 * BASH_COMMAND: Bash Variables. (line 64)
10046 * BASH_ENV: Bash Variables. (line 69)
10047 * BASH_EXECUTION_STRING: Bash Variables. (line 75)
10048 * BASH_LINENO: Bash Variables. (line 78)
10049 * BASH_REMATCH: Bash Variables. (line 86)
10050 * BASH_SOURCE: Bash Variables. (line 94)
10051 * BASH_SUBSHELL: Bash Variables. (line 101)
10052 * BASH_VERSINFO: Bash Variables. (line 105)
10053 * BASH_VERSION: Bash Variables. (line 129)
10054 * BASH_XTRACEFD: Bash Variables. (line 132)
10055 * BASHOPTS: Bash Variables. (line 16)
10056 * BASHPID: Bash Variables. (line 25)
10057 * bell-style: Readline Init File Syntax.
10059 * bind-tty-special-chars: Readline Init File Syntax.
10061 * CDPATH: Bourne Shell Variables.
10063 * COLUMNS: Bash Variables. (line 143)
10064 * comment-begin: Readline Init File Syntax.
10066 * COMP_CWORD: Bash Variables. (line 148)
10067 * COMP_KEY: Bash Variables. (line 177)
10068 * COMP_LINE: Bash Variables. (line 154)
10069 * COMP_POINT: Bash Variables. (line 159)
10070 * COMP_TYPE: Bash Variables. (line 167)
10071 * COMP_WORDBREAKS: Bash Variables. (line 181)
10072 * COMP_WORDS: Bash Variables. (line 187)
10073 * completion-display-width: Readline Init File Syntax.
10075 * completion-ignore-case: Readline Init File Syntax.
10077 * completion-map-case: Readline Init File Syntax.
10079 * completion-prefix-display-length: Readline Init File Syntax.
10081 * completion-query-items: Readline Init File Syntax.
10083 * COMPREPLY: Bash Variables. (line 195)
10084 * convert-meta: Readline Init File Syntax.
10086 * COPROC: Bash Variables. (line 200)
10087 * DIRSTACK: Bash Variables. (line 204)
10088 * disable-completion: Readline Init File Syntax.
10090 * editing-mode: Readline Init File Syntax.
10092 * EMACS: Bash Variables. (line 214)
10093 * enable-keypad: Readline Init File Syntax.
10095 * ENV: Bash Variables. (line 219)
10096 * EUID: Bash Variables. (line 223)
10097 * expand-tilde: Readline Init File Syntax.
10099 * FCEDIT: Bash Variables. (line 227)
10100 * FIGNORE: Bash Variables. (line 231)
10101 * FUNCNAME: Bash Variables. (line 237)
10102 * FUNCNEST: Bash Variables. (line 255)
10103 * GLOBIGNORE: Bash Variables. (line 260)
10104 * GROUPS: Bash Variables. (line 266)
10105 * histchars: Bash Variables. (line 272)
10106 * HISTCMD: Bash Variables. (line 287)
10107 * HISTCONTROL: Bash Variables. (line 292)
10108 * HISTFILE: Bash Variables. (line 308)
10109 * HISTFILESIZE: Bash Variables. (line 312)
10110 * HISTIGNORE: Bash Variables. (line 320)
10111 * history-preserve-point: Readline Init File Syntax.
10113 * history-size: Readline Init File Syntax.
10115 * HISTSIZE: Bash Variables. (line 339)
10116 * HISTTIMEFORMAT: Bash Variables. (line 343)
10117 * HOME: Bourne Shell Variables.
10119 * horizontal-scroll-mode: Readline Init File Syntax.
10121 * HOSTFILE: Bash Variables. (line 352)
10122 * HOSTNAME: Bash Variables. (line 363)
10123 * HOSTTYPE: Bash Variables. (line 366)
10124 * IFS: Bourne Shell Variables.
10126 * IGNOREEOF: Bash Variables. (line 369)
10127 * input-meta: Readline Init File Syntax.
10129 * INPUTRC: Bash Variables. (line 379)
10130 * isearch-terminators: Readline Init File Syntax.
10132 * keymap: Readline Init File Syntax.
10134 * LANG: Bash Variables. (line 383)
10135 * LC_ALL: Bash Variables. (line 387)
10136 * LC_COLLATE: Bash Variables. (line 391)
10137 * LC_CTYPE: Bash Variables. (line 398)
10138 * LC_MESSAGES <1>: Locale Translation. (line 11)
10139 * LC_MESSAGES: Bash Variables. (line 403)
10140 * LC_NUMERIC: Bash Variables. (line 407)
10141 * LINENO: Bash Variables. (line 411)
10142 * LINES: Bash Variables. (line 415)
10143 * MACHTYPE: Bash Variables. (line 420)
10144 * MAIL: Bourne Shell Variables.
10146 * MAILCHECK: Bash Variables. (line 424)
10147 * MAILPATH: Bourne Shell Variables.
10149 * MAPFILE: Bash Variables. (line 432)
10150 * mark-modified-lines: Readline Init File Syntax.
10152 * mark-symlinked-directories: Readline Init File Syntax.
10154 * match-hidden-files: Readline Init File Syntax.
10156 * menu-complete-display-prefix: Readline Init File Syntax.
10158 * meta-flag: Readline Init File Syntax.
10160 * OLDPWD: Bash Variables. (line 436)
10161 * OPTARG: Bourne Shell Variables.
10163 * OPTERR: Bash Variables. (line 439)
10164 * OPTIND: Bourne Shell Variables.
10166 * OSTYPE: Bash Variables. (line 443)
10167 * output-meta: Readline Init File Syntax.
10169 * page-completions: Readline Init File Syntax.
10171 * PATH: Bourne Shell Variables.
10173 * PIPESTATUS: Bash Variables. (line 446)
10174 * POSIXLY_CORRECT: Bash Variables. (line 451)
10175 * PPID: Bash Variables. (line 460)
10176 * PROMPT_COMMAND: Bash Variables. (line 464)
10177 * PROMPT_DIRTRIM: Bash Variables. (line 468)
10178 * PS1: Bourne Shell Variables.
10180 * PS2: Bourne Shell Variables.
10182 * PS3: Bash Variables. (line 474)
10183 * PS4: Bash Variables. (line 479)
10184 * PWD: Bash Variables. (line 485)
10185 * RANDOM: Bash Variables. (line 488)
10186 * READLINE_LINE: Bash Variables. (line 493)
10187 * READLINE_POINT: Bash Variables. (line 497)
10188 * REPLY: Bash Variables. (line 501)
10189 * revert-all-at-newline: Readline Init File Syntax.
10191 * SECONDS: Bash Variables. (line 504)
10192 * SHELL: Bash Variables. (line 510)
10193 * SHELLOPTS: Bash Variables. (line 515)
10194 * SHLVL: Bash Variables. (line 524)
10195 * show-all-if-ambiguous: Readline Init File Syntax.
10197 * show-all-if-unmodified: Readline Init File Syntax.
10199 * skip-completed-text: Readline Init File Syntax.
10201 * TEXTDOMAIN: Locale Translation. (line 11)
10202 * TEXTDOMAINDIR: Locale Translation. (line 11)
10203 * TIMEFORMAT: Bash Variables. (line 529)
10204 * TMOUT: Bash Variables. (line 567)
10205 * TMPDIR: Bash Variables. (line 579)
10206 * UID: Bash Variables. (line 583)
10207 * visible-stats: Readline Init File Syntax.
10211 File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
10219 * abort (C-g): Miscellaneous Commands.
10221 * accept-line (Newline or Return): Commands For History. (line 6)
10222 * backward-char (C-b): Commands For Moving. (line 15)
10223 * backward-delete-char (Rubout): Commands For Text. (line 11)
10224 * backward-kill-line (C-x Rubout): Commands For Killing. (line 9)
10225 * backward-kill-word (M-<DEL>): Commands For Killing. (line 24)
10226 * backward-word (M-b): Commands For Moving. (line 22)
10227 * beginning-of-history (M-<): Commands For History. (line 20)
10228 * beginning-of-line (C-a): Commands For Moving. (line 6)
10229 * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
10230 * capitalize-word (M-c): Commands For Text. (line 46)
10231 * character-search (C-]): Miscellaneous Commands.
10233 * character-search-backward (M-C-]): Miscellaneous Commands.
10235 * clear-screen (C-l): Commands For Moving. (line 34)
10236 * complete (<TAB>): Commands For Completion.
10238 * copy-backward-word (): Commands For Killing. (line 58)
10239 * copy-forward-word (): Commands For Killing. (line 63)
10240 * copy-region-as-kill (): Commands For Killing. (line 54)
10241 * delete-char (C-d): Commands For Text. (line 6)
10242 * delete-char-or-list (): Commands For Completion.
10244 * delete-horizontal-space (): Commands For Killing. (line 46)
10245 * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
10246 * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
10248 * downcase-word (M-l): Commands For Text. (line 42)
10249 * dump-functions (): Miscellaneous Commands.
10251 * dump-macros (): Miscellaneous Commands.
10253 * dump-variables (): Miscellaneous Commands.
10255 * end-kbd-macro (C-x )): Keyboard Macros. (line 9)
10256 * end-of-history (M->): Commands For History. (line 23)
10257 * end-of-line (C-e): Commands For Moving. (line 9)
10258 * exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
10260 * forward-backward-delete-char (): Commands For Text. (line 15)
10261 * forward-char (C-f): Commands For Moving. (line 12)
10262 * forward-search-history (C-s): Commands For History. (line 31)
10263 * forward-word (M-f): Commands For Moving. (line 18)
10264 * history-search-backward (): Commands For History. (line 51)
10265 * history-search-forward (): Commands For History. (line 46)
10266 * insert-comment (M-#): Miscellaneous Commands.
10268 * insert-completions (M-*): Commands For Completion.
10270 * kill-line (C-k): Commands For Killing. (line 6)
10271 * kill-region (): Commands For Killing. (line 50)
10272 * kill-whole-line (): Commands For Killing. (line 15)
10273 * kill-word (M-d): Commands For Killing. (line 19)
10274 * menu-complete (): Commands For Completion.
10276 * menu-complete-backward (): Commands For Completion.
10278 * next-history (C-n): Commands For History. (line 17)
10279 * non-incremental-forward-search-history (M-n): Commands For History.
10281 * non-incremental-reverse-search-history (M-p): Commands For History.
10283 * overwrite-mode (): Commands For Text. (line 50)
10284 * possible-completions (M-?): Commands For Completion.
10286 * prefix-meta (<ESC>): Miscellaneous Commands.
10288 * previous-history (C-p): Commands For History. (line 13)
10289 * quoted-insert (C-q or C-v): Commands For Text. (line 20)
10290 * re-read-init-file (C-x C-r): Miscellaneous Commands.
10292 * redraw-current-line (): Commands For Moving. (line 38)
10293 * reverse-search-history (C-r): Commands For History. (line 27)
10294 * revert-line (M-r): Miscellaneous Commands.
10296 * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 24)
10297 * set-mark (C-@): Miscellaneous Commands.
10299 * skip-csi-sequence (): Miscellaneous Commands.
10301 * start-kbd-macro (C-x (): Keyboard Macros. (line 6)
10302 * transpose-chars (C-t): Commands For Text. (line 27)
10303 * transpose-words (M-t): Commands For Text. (line 33)
10304 * undo (C-_ or C-x C-u): Miscellaneous Commands.
10306 * universal-argument (): Numeric Arguments. (line 10)
10307 * unix-filename-rubout (): Commands For Killing. (line 41)
10308 * unix-line-discard (C-u): Commands For Killing. (line 12)
10309 * unix-word-rubout (C-w): Commands For Killing. (line 37)
10310 * upcase-word (M-u): Commands For Text. (line 38)
10311 * yank (C-y): Commands For Killing. (line 68)
10312 * yank-last-arg (M-. or M-_): Commands For History. (line 65)
10313 * yank-nth-arg (M-C-y): Commands For History. (line 56)
10314 * yank-pop (M-y): Commands For Killing. (line 71)
10317 File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
10325 * alias expansion: Aliases. (line 6)
10326 * arithmetic evaluation: Shell Arithmetic. (line 6)
10327 * arithmetic expansion: Arithmetic Expansion.
10329 * arithmetic, shell: Shell Arithmetic. (line 6)
10330 * arrays: Arrays. (line 6)
10331 * background: Job Control Basics. (line 6)
10332 * Bash configuration: Basic Installation. (line 6)
10333 * Bash installation: Basic Installation. (line 6)
10334 * Bourne shell: Basic Shell Features.
10336 * brace expansion: Brace Expansion. (line 6)
10337 * builtin: Definitions. (line 17)
10338 * command editing: Readline Bare Essentials.
10340 * command execution: Command Search and Execution.
10342 * command expansion: Simple Command Expansion.
10344 * command history: Bash History Facilities.
10346 * command search: Command Search and Execution.
10348 * command substitution: Command Substitution.
10350 * command timing: Pipelines. (line 9)
10351 * commands, compound: Compound Commands. (line 6)
10352 * commands, conditional: Conditional Constructs.
10354 * commands, grouping: Command Grouping. (line 6)
10355 * commands, lists: Lists. (line 6)
10356 * commands, looping: Looping Constructs. (line 6)
10357 * commands, pipelines: Pipelines. (line 6)
10358 * commands, shell: Shell Commands. (line 6)
10359 * commands, simple: Simple Commands. (line 6)
10360 * comments, shell: Comments. (line 6)
10361 * completion builtins: Programmable Completion Builtins.
10363 * configuration: Basic Installation. (line 6)
10364 * control operator: Definitions. (line 21)
10365 * coprocess: Coprocesses. (line 6)
10366 * directory stack: The Directory Stack. (line 6)
10367 * editing command lines: Readline Bare Essentials.
10369 * environment: Environment. (line 6)
10370 * evaluation, arithmetic: Shell Arithmetic. (line 6)
10371 * event designators: Event Designators. (line 6)
10372 * execution environment: Command Execution Environment.
10374 * exit status <1>: Exit Status. (line 6)
10375 * exit status: Definitions. (line 26)
10376 * expansion: Shell Expansions. (line 6)
10377 * expansion, arithmetic: Arithmetic Expansion.
10379 * expansion, brace: Brace Expansion. (line 6)
10380 * expansion, filename: Filename Expansion. (line 9)
10381 * expansion, parameter: Shell Parameter Expansion.
10383 * expansion, pathname: Filename Expansion. (line 9)
10384 * expansion, tilde: Tilde Expansion. (line 6)
10385 * expressions, arithmetic: Shell Arithmetic. (line 6)
10386 * expressions, conditional: Bash Conditional Expressions.
10388 * field: Definitions. (line 30)
10389 * filename: Definitions. (line 35)
10390 * filename expansion: Filename Expansion. (line 9)
10391 * foreground: Job Control Basics. (line 6)
10392 * functions, shell: Shell Functions. (line 6)
10393 * history builtins: Bash History Builtins.
10395 * history events: Event Designators. (line 8)
10396 * history expansion: History Interaction. (line 6)
10397 * history list: Bash History Facilities.
10399 * History, how to use: Programmable Completion Builtins.
10401 * identifier: Definitions. (line 51)
10402 * initialization file, readline: Readline Init File. (line 6)
10403 * installation: Basic Installation. (line 6)
10404 * interaction, readline: Readline Interaction.
10406 * interactive shell <1>: Interactive Shells. (line 6)
10407 * interactive shell: Invoking Bash. (line 127)
10408 * internationalization: Locale Translation. (line 6)
10409 * job: Definitions. (line 38)
10410 * job control <1>: Job Control Basics. (line 6)
10411 * job control: Definitions. (line 42)
10412 * kill ring: Readline Killing Commands.
10414 * killing text: Readline Killing Commands.
10416 * localization: Locale Translation. (line 6)
10417 * login shell: Invoking Bash. (line 124)
10418 * matching, pattern: Pattern Matching. (line 6)
10419 * metacharacter: Definitions. (line 46)
10420 * name: Definitions. (line 51)
10421 * native languages: Locale Translation. (line 6)
10422 * notation, readline: Readline Bare Essentials.
10424 * operator, shell: Definitions. (line 57)
10425 * parameter expansion: Shell Parameter Expansion.
10427 * parameters: Shell Parameters. (line 6)
10428 * parameters, positional: Positional Parameters.
10430 * parameters, special: Special Parameters. (line 6)
10431 * pathname expansion: Filename Expansion. (line 9)
10432 * pattern matching: Pattern Matching. (line 6)
10433 * pipeline: Pipelines. (line 6)
10434 * POSIX: Definitions. (line 9)
10435 * POSIX Mode: Bash POSIX Mode. (line 6)
10436 * process group: Definitions. (line 62)
10437 * process group ID: Definitions. (line 66)
10438 * process substitution: Process Substitution.
10440 * programmable completion: Programmable Completion.
10442 * prompting: Printing a Prompt. (line 6)
10443 * quoting: Quoting. (line 6)
10444 * quoting, ANSI: ANSI-C Quoting. (line 6)
10445 * Readline, how to use: Job Control Variables.
10447 * redirection: Redirections. (line 6)
10448 * reserved word: Definitions. (line 70)
10449 * restricted shell: The Restricted Shell.
10451 * return status: Definitions. (line 75)
10452 * shell arithmetic: Shell Arithmetic. (line 6)
10453 * shell function: Shell Functions. (line 6)
10454 * shell script: Shell Scripts. (line 6)
10455 * shell variable: Shell Parameters. (line 6)
10456 * shell, interactive: Interactive Shells. (line 6)
10457 * signal: Definitions. (line 78)
10458 * signal handling: Signals. (line 6)
10459 * special builtin <1>: Special Builtins. (line 6)
10460 * special builtin: Definitions. (line 82)
10461 * startup files: Bash Startup Files. (line 6)
10462 * suspending jobs: Job Control Basics. (line 6)
10463 * tilde expansion: Tilde Expansion. (line 6)
10464 * token: Definitions. (line 86)
10465 * translation, native languages: Locale Translation. (line 6)
10466 * variable, shell: Shell Parameters. (line 6)
10467 * variables, readline: Readline Init File Syntax.
10469 * word: Definitions. (line 90)
10470 * word splitting: Word Splitting. (line 6)
10471 * yanking text: Readline Killing Commands.
10478 Node: Introduction
\x7f3185
10479 Node: What is Bash?
\x7f3413
10480 Node: What is a shell?
\x7f4526
10481 Node: Definitions
\x7f7066
10482 Node: Basic Shell Features
\x7f9984
10483 Node: Shell Syntax
\x7f11203
10484 Node: Shell Operation
\x7f12233
10485 Node: Quoting
\x7f13527
10486 Node: Escape Character
\x7f14830
10487 Node: Single Quotes
\x7f15315
10488 Node: Double Quotes
\x7f15663
10489 Node: ANSI-C Quoting
\x7f16788
10490 Node: Locale Translation
\x7f18032
10491 Node: Comments
\x7f18928
10492 Node: Shell Commands
\x7f19546
10493 Node: Simple Commands
\x7f20418
10494 Node: Pipelines
\x7f21049
10495 Node: Lists
\x7f23743
10496 Node: Compound Commands
\x7f25472
10497 Node: Looping Constructs
\x7f26276
10498 Node: Conditional Constructs
\x7f28735
10499 Node: Command Grouping
\x7f36848
10500 Node: Coprocesses
\x7f38327
10501 Node: GNU Parallel
\x7f39992
10502 Node: Shell Functions
\x7f42460
10503 Node: Shell Parameters
\x7f47404
10504 Node: Positional Parameters
\x7f49820
10505 Node: Special Parameters
\x7f50720
10506 Node: Shell Expansions
\x7f53684
10507 Node: Brace Expansion
\x7f55609
10508 Node: Tilde Expansion
\x7f58364
10509 Node: Shell Parameter Expansion
\x7f60715
10510 Node: Command Substitution
\x7f69850
10511 Node: Arithmetic Expansion
\x7f71183
10512 Node: Process Substitution
\x7f72033
10513 Node: Word Splitting
\x7f73083
10514 Node: Filename Expansion
\x7f74706
10515 Node: Pattern Matching
\x7f76845
10516 Node: Quote Removal
\x7f80484
10517 Node: Redirections
\x7f80779
10518 Node: Executing Commands
\x7f89304
10519 Node: Simple Command Expansion
\x7f89974
10520 Node: Command Search and Execution
\x7f91904
10521 Node: Command Execution Environment
\x7f94241
10522 Node: Environment
\x7f97227
10523 Node: Exit Status
\x7f98887
10524 Node: Signals
\x7f100508
10525 Node: Shell Scripts
\x7f102476
10526 Node: Shell Builtin Commands
\x7f104994
10527 Node: Bourne Shell Builtins
\x7f107022
10528 Node: Bash Builtins
\x7f124952
10529 Node: Modifying Shell Behavior
\x7f151166
10530 Node: The Set Builtin
\x7f151511
10531 Node: The Shopt Builtin
\x7f161045
10532 Node: Special Builtins
\x7f173217
10533 Node: Shell Variables
\x7f174196
10534 Node: Bourne Shell Variables
\x7f174636
10535 Node: Bash Variables
\x7f176663
10536 Node: Bash Features
\x7f201572
10537 Node: Invoking Bash
\x7f202455
10538 Node: Bash Startup Files
\x7f208219
10539 Node: Interactive Shells
\x7f213240
10540 Node: What is an Interactive Shell?
\x7f213650
10541 Node: Is this Shell Interactive?
\x7f214299
10542 Node: Interactive Shell Behavior
\x7f215114
10543 Node: Bash Conditional Expressions
\x7f218394
10544 Node: Shell Arithmetic
\x7f222183
10545 Node: Aliases
\x7f224942
10546 Node: Arrays
\x7f227514
10547 Node: The Directory Stack
\x7f231629
10548 Node: Directory Stack Builtins
\x7f232343
10549 Node: Printing a Prompt
\x7f235235
10550 Node: The Restricted Shell
\x7f237987
10551 Node: Bash POSIX Mode
\x7f239819
10552 Node: Job Control
\x7f248480
10553 Node: Job Control Basics
\x7f248940
10554 Node: Job Control Builtins
\x7f253657
10555 Node: Job Control Variables
\x7f258021
10556 Node: Command Line Editing
\x7f259179
10557 Node: Introduction and Notation
\x7f260746
10558 Node: Readline Interaction
\x7f262368
10559 Node: Readline Bare Essentials
\x7f263559
10560 Node: Readline Movement Commands
\x7f265348
10561 Node: Readline Killing Commands
\x7f266313
10562 Node: Readline Arguments
\x7f268233
10563 Node: Searching
\x7f269277
10564 Node: Readline Init File
\x7f271463
10565 Node: Readline Init File Syntax
\x7f272610
10566 Node: Conditional Init Constructs
\x7f287952
10567 Node: Sample Init File
\x7f290485
10568 Node: Bindable Readline Commands
\x7f293602
10569 Node: Commands For Moving
\x7f294809
10570 Node: Commands For History
\x7f295953
10571 Node: Commands For Text
\x7f299388
10572 Node: Commands For Killing
\x7f302061
10573 Node: Numeric Arguments
\x7f304518
10574 Node: Commands For Completion
\x7f305657
10575 Node: Keyboard Macros
\x7f309849
10576 Node: Miscellaneous Commands
\x7f310420
10577 Node: Readline vi Mode
\x7f316226
10578 Node: Programmable Completion
\x7f317133
10579 Node: Programmable Completion Builtins
\x7f324343
10580 Node: Using History Interactively
\x7f333479
10581 Node: Bash History Facilities
\x7f334163
10582 Node: Bash History Builtins
\x7f337077
10583 Node: History Interaction
\x7f340934
10584 Node: Event Designators
\x7f343639
10585 Node: Word Designators
\x7f344861
10586 Node: Modifiers
\x7f346500
10587 Node: Installing Bash
\x7f347904
10588 Node: Basic Installation
\x7f349041
10589 Node: Compilers and Options
\x7f351733
10590 Node: Compiling For Multiple Architectures
\x7f352474
10591 Node: Installation Names
\x7f354138
10592 Node: Specifying the System Type
\x7f354956
10593 Node: Sharing Defaults
\x7f355672
10594 Node: Operation Controls
\x7f356345
10595 Node: Optional Features
\x7f357303
10596 Node: Reporting Bugs
\x7f366871
10597 Node: Major Differences From The Bourne Shell
\x7f368072
10598 Node: GNU Free Documentation License
\x7f384759
10599 Node: Indexes
\x7f409955
10600 Node: Builtin Index
\x7f410409
10601 Node: Reserved Word Index
\x7f417236
10602 Node: Variable Index
\x7f419684
10603 Node: Function Index
\x7f432779
10604 Node: Concept Index
\x7f439788