1 This is Info file bashref.info, produced by Makeinfo version 1.67 from
2 the input file /usr/homes/chet/src/bash/src/doc/bashref.texi.
4 INFO-DIR-SECTION Utilities
6 * Bash: (bash). The GNU Bourne-Again SHell.
9 This text is a brief description of the features that are present in
12 This is Edition 2.2, last updated 1 April 1998,
13 of `The GNU Bash Reference Manual',
14 for `Bash', Version 2.02.
16 Copyright (C) 1991, 1993, 1996, 1997 Free Software Foundation, Inc.
18 Permission is granted to make and distribute verbatim copies of
19 this manual provided the copyright notice and this permission notice
20 are preserved on all copies.
22 Permission is granted to copy and distribute modified versions of this
23 manual under the conditions for verbatim copying, provided that the entire
24 resulting derived work is distributed under the terms of a permission
25 notice identical to this one.
27 Permission is granted to copy and distribute translations of this manual
28 into another language, under the above conditions for modified versions,
29 except that this permission notice may be stated in a translation approved
30 by the Free Software Foundation.
33 File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
38 This text is a brief description of the features that are present in
41 This is Edition 2.2, last updated 1 April 1998, of `The GNU Bash
42 Reference Manual', for `Bash', Version 2.02.
44 Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc.
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.
61 * Definitions:: Some definitions used in the rest of this
64 * Basic Shell Features:: The shell "building blocks".
66 * Bourne Shell Features:: Features similar to those found in the
69 * Bash Features:: Features found only in Bash.
71 * Job Control:: A chapter describing what job control is
72 and how Bash allows you to use it.
74 * Using History Interactively:: Chapter dealing with history expansion
77 * Command Line Editing:: Chapter describing the command line
80 * Installing Bash:: How to build and install Bash on your system.
82 * Reporting Bugs:: How to report bugs in Bash.
84 * Builtin Index:: Index of Bash builtin commands.
86 * Reserved Word Index:: Index of Bash reserved words.
88 * Variable Index:: Quick reference helps you find the
91 * Function Index:: Index of bindable Readline functions.
93 * Concept Index:: General index for concepts described in
97 File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top
104 * What is Bash?:: A short description of Bash.
106 * What is a shell?:: A brief introduction to shells.
109 File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
114 Bash is the shell, or command language interpreter, that will appear
115 in the GNU operating system. The name is an acronym for the
116 `Bourne-Again SHell', a pun on Steve Bourne, the author of the direct
117 ancestor of the current Unix shell `/bin/sh', which appeared in the
118 Seventh Edition Bell Labs Research version of Unix.
120 Bash is an `sh'-compatible shell that incorporates useful features
121 from the Korn shell `ksh' and the C shell `csh'. It is intended to be
122 a conformant implementation of the IEEE POSIX Shell and Tools
123 specification (IEEE Working Group 1003.2). It offers functional
124 improvements over `sh' for both interactive and programming use.
126 While the GNU operating system will include a version of `csh', Bash
127 will be the default shell. Like other GNU software, Bash is quite
128 portable. It currently runs on nearly every version of Unix and a few
129 other operating systems - independently-supported ports exist for
130 MS-DOS, OS/2, Windows 95, and Windows NT.
133 File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
138 At its base, a shell is simply a macro processor that executes
139 commands. A Unix shell is both a command interpreter, which provides
140 the user interface to the rich set of Unix utilities, and a programming
141 language, allowing these utilitites to be combined. Files containing
142 commands can be created, and become commands themselves. These new
143 commands have the same status as system commands in directories like
144 `/bin', allowing users or groups to establish custom environments.
146 A shell allows execution of Unix commands, both synchronously and
147 asynchronously. The shell waits for synchronous commands to complete
148 before accepting more input; asynchronous commands continue to execute
149 in parallel with the shell while it reads and executes additional
150 commands. The "redirection" constructs permit fine-grained control of
151 the input and output of those commands, and the shell allows control
152 over the contents of their environment. Unix shells also provide a
153 small set of built-in commands ("builtins") implementing functionality
154 impossible (e.g., `cd', `break', `continue', and `exec'), or
155 inconvenient (`history', `getopts', `kill', or `pwd', for example) to
156 obtain via separate utilities. Shells may be used interactively or
157 non-interactively: they accept input typed from the keyboard or from a
158 file. All of the shell builtins are described in subsequent sections.
160 While executing commands is essential, most of the power (and
161 complexity) of shells is due to their embedded programming languages.
162 Like any high-level language, the shell provides variables, flow
163 control constructs, quoting, and functions.
165 Shells have begun offering features geared specifically for
166 interactive use rather than to augment the programming language. These
167 interactive features include job control, command line editing, history
168 and aliases. Each of these features is described in this manual.
171 File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
176 These definitions are used throughout the remainder of this manual.
179 A family of open system standards based on Unix. Bash is
180 concerned with POSIX 1003.2, the Shell and Tools Standard.
183 A space or tab character.
186 A command that is implemented internally by the shell itself,
187 rather than by an executable program somewhere in the file system.
190 A `word' that performs a control function. It is a `newline' or
191 one of the following: `||', `&&', `&', `;', `;;', `|', `(', or `)'.
194 The value returned by a command to its caller.
197 A unit of text that is the result of one of the shell expansions.
198 After expansion, when executing a command, the resulting fields
199 are used as the command name and arguments.
202 A string of characters used to identify a file.
205 A set of processes comprising a pipeline, and any processes
206 descended from it, that are all in the same process group.
209 A mechanism by which users can selectively stop (suspend) and
210 restart (resume) execution of processes.
213 A character that, when unquoted, separates words. A metacharacter
214 is a `blank' or one of the following characters: `|', `&', `;',
215 `(', `)', `<', or `>'.
218 A `word' consisting solely of letters, numbers, and underscores,
219 and beginning with a letter or underscore. `Name's are used as
220 shell variable and function names. Also referred to as an
224 A `control operator' or a `redirection operator'. *Note
225 Redirections::, for a list of redirection operators.
228 A collection of related processes each having the same process
232 A unique identifer 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 kernal 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 `token' that is not an `operator'.
259 File: bashref.info, Node: Basic Shell Features, Next: Bourne Shell Features, Prev: Definitions, Up: Top
264 Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is
265 the traditional Unix shell originally written by Stephen Bourne. All
266 of the Bourne shell builtin commands are available in Bash, and the
267 rules for evaluation and quoting are taken from the POSIX 1003.2
268 specification for the `standard' Unix shell.
270 This chapter briefly summarizes the shell's `building blocks':
271 commands, control structures, shell functions, shell parameters, shell
272 expansions, redirections, which are a way to direct input and output
273 from and to named files, and how the shell executes commands.
277 * Shell Syntax:: What your input means to the shell.
278 * Shell Commands:: The types of commands you can use.
279 * Shell Functions:: Grouping commands by name.
280 * Shell Parameters:: Special shell variables.
281 * Shell Expansions:: How Bash expands variables and the various
282 expansions available.
283 * Redirections:: A way to control where input and output go.
284 * Executing Commands:: What happens when you run a command.
285 * Shell Scripts:: Executing files of shell commands.
288 File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
295 * Shell Operation:: The basic operation of the shell.
297 * Quoting:: How to remove the special meaning from characters.
299 * Comments:: How to specify comments.
302 File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
307 The following is a brief description of the shell's operation when it
308 reads and executes a command. Basically, the shell does the following:
310 1. Reads its input from a file (*note Shell Scripts::.), from a string
311 supplied as an argument to the `-c' invocation option (*note
312 Invoking Bash::.), or from the user's terminal.
314 2. Breaks the input into words and operators, obeying the quoting
315 rules described in *Note Quoting::. These tokens are separated by
316 `metacharacters'. Alias expansion is performed by this step
319 3. Parses the tokens into simple and compound commands (*note Shell
322 4. Performs the various shell expansions (*note Shell Expansions::.),
323 breaking the expanded tokens into lists of filenames (*note
324 Filename Expansion::.) and commands and arguments.
326 5. Performs any necessary redirections (*note Redirections::.) and
327 removes the redirection operators and their operands from the
330 6. Executes the command (*note Executing Commands::.).
332 7. Optionally waits for the command to complete and collects its exit
333 status (*note Exit Status::.).
337 File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
344 * Escape Character:: How to remove the special meaning from a single
346 * Single Quotes:: How to inhibit all interpretation of a sequence
348 * Double Quotes:: How to suppress most of the interpretation of a
349 sequence of characters.
350 * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings.
352 * Locale Translation:: How to translate strings into different languages.
354 Quoting is used to remove the special meaning of certain characters
355 or words to the shell. Quoting can be used to disable special
356 treatment for special characters, to prevent reserved words from being
357 recognized as such, and to prevent parameter expansion.
359 Each of the shell metacharacters (*note Definitions::.) has special
360 meaning to the shell and must be quoted if it is to represent itself.
361 There are three quoting mechanisms: the ESCAPE CHARACTER, single
362 quotes, and double quotes.
365 File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
370 A non-quoted backslash `\' is the Bash escape character. It
371 preserves the literal value of the next character that follows, with
372 the exception of `newline'. If a `\newline' pair appears, and the
373 backslash itself is not quoted, the `\newline' is treated as a line
374 continuation (that is, it is removed from the input stream and
375 effectively ignored).
378 File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
383 Enclosing characters in single quotes preserves the literal value of
384 each character within the quotes. A single quote may not occur between
385 single quotes, even when preceded by a backslash.
388 File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
393 Enclosing characters in double quotes preserves the literal value of
394 all characters within the quotes, with the exception of `$', ``', and
395 `\'. The characters `$' and ``' retain their special meaning within
396 double quotes (*note Shell Expansions::.). The backslash retains its
397 special meaning only when followed by one of the following characters:
398 `$', ``', `"', `\', or `newline'. Within double quotes, backslashes
399 that are followed by one of these characters are removed. Backslashes
400 preceding characters without a special meaning are left unmodified. A
401 double quote may be quoted within double quotes by preceding it with a
404 The special parameters `*' and `@' have special meaning when in
405 double quotes (*note Shell Parameter Expansion::.).
408 File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
413 Words of the form `$'STRING'' are treated specially. The word
414 expands to STRING, with backslash-escaped characters replaced as
415 specifed by the ANSI C standard. Backslash escape sequences, if
416 present, are decoded as follows:
425 an escape character (not ANSI C)
446 the character whose `ASCII' code is the octal value NNN (one to
450 the character whose `ASCII' code is the hexadecimal value NNN (one
453 The result is single-quoted, as if the dollar sign had not been present.
456 File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
458 Locale-Specific Translation
459 ...........................
461 A double-quoted string preceded by a dollar sign (`$') will cause
462 the string to be translated according to the current locale. If the
463 current locale is `C' or `POSIX', the dollar sign is ignored. If the
464 string is translated and replaced, the replacement is double-quoted.
467 File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
472 In a non-interactive shell, or an interactive shell in which the
473 `interactive_comments' option to the `shopt' builtin is enabled (*note
474 Bash Builtins::.), a word beginning with `#' causes that word and all
475 remaining characters on that line to be ignored. An interactive shell
476 without the `interactive_comments' option enabled does not allow
477 comments. The `interactive_comments' option is on by default in
478 interactive shells. *Note Is This Shell Interactive?::, for a
479 description of what makes a shell interactive.
482 File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
489 * Simple Commands:: The most common type of command.
490 * Pipelines:: Connecting the input and output of several
492 * Lists:: How to execute commands sequentially.
493 * Looping Constructs:: Shell commands for iterative action.
494 * Conditional Constructs:: Shell commands for conditional execution.
495 * Command Grouping:: Ways to group commands.
498 File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
503 A simple command is the kind of command encountered most often.
504 It's just a sequence of words separated by `blank's, terminated by one
505 of the shell's control operators (*note Definitions::.). The first
506 word generally specifies a command to be executed.
508 The return status (*note Exit Status::.) of a simple command is its
509 exit status as provided by the POSIX.1 `waitpid' function, or 128+N if
510 the command was terminated by signal N.
513 File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
518 A `pipeline' is a sequence of simple commands separated by `|'.
520 The format for a pipeline is
521 [`time' [`-p']] [`!'] COMMAND1 [`|' COMMAND2 ...]
523 The output of each command in the pipeline is connected to the input of
524 the next command. That is, each command reads the previous command's
527 The reserved word `time' causes timing statistics to be printed for
528 the pipeline once it finishes. The statistics currently consist of
529 elapsed (wall-clock) time and user and system time consumed by the
530 command's execution. The `-p' option changes the output format to that
531 specified by POSIX. The `TIMEFORMAT' variable may be set to a format
532 string that specifies how the timing information should be displayed.
533 *Note Bash Variables::, for a description of the available formats.
534 The use of `time' as a reserved word permits the timing of shell
535 builtins, shell functions, and pipelines. An external `time' command
536 cannot time these easily.
538 If the pipeline is not executed asynchronously (*note Lists::.), the
539 shell waits for all commands in the pipeline to complete.
541 Each command in a pipeline is executed in its own subshell (*note
542 Command Execution Environment::.). The exit status of a pipeline is
543 the exit status of the last command in the pipeline. If the reserved
544 word `!' precedes the pipeline, the exit status is the logical negation
545 of the exit status of the last command.
548 File: bashref.info, Node: Lists, Next: Looping Constructs, Prev: Pipelines, Up: Shell Commands
553 A `list' is a sequence of one or more pipelines separated by one of
554 the operators `;', `&', `&&', or `||', and optionally terminated by one
555 of `;', `&', or a `newline'.
557 Of these list operators, `&&' and `||' have equal precedence,
558 followed by `;' and `&', which have equal precedence.
560 If a command is terminated by the control operator `&', the shell
561 executes the command asynchronously in a subshell. This is known as
562 executing the command in the BACKGROUND. The shell does not wait for
563 the command to finish, and the return status is 0 (true). The standard
564 input for asynchronous commands, in the absence of any explicit
565 redirections, is redirected from `/dev/null'.
567 Commands separated by a `;' are executed sequentially; the shell
568 waits for each command to terminate in turn. The return status is the
569 exit status of the last command executed.
571 The control operators `&&' and `||' denote AND lists and OR lists,
572 respectively. An AND list has the form
575 COMMAND2 is executed if, and only if, COMMAND returns an exit status of
578 An OR list has the form
581 COMMAND2 is executed if, and only if, COMMAND returns a non-zero exit
584 The return status of AND and OR lists is the exit status of the last
585 command executed in the list.
588 File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Prev: Lists, Up: Shell Commands
593 Bash supports the following looping constructs.
595 Note that wherever you see a `;' in the description of a command's
596 syntax, it may be replaced with one or more newlines.
599 The syntax of the `until' command is:
600 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
601 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
602 status which is not zero. The return status is the exit status of
603 the last command executed in CONSEQUENT-COMMANDS, or zero if none
607 The syntax of the `while' command is:
608 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
610 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
611 status of zero. The return status is the exit status of the last
612 command executed in CONSEQUENT-COMMANDS, or zero if none was
616 The syntax of the `for' command is:
618 for NAME [in WORDS ...]; do COMMANDS; done
619 Expand WORDS, and execute COMMANDS once for each member in the
620 resultant list, with NAME bound to the current member. If `in
621 WORDS' is not present, `in "$@"' is assumed. The return status is
622 the exit status of the last command that executes. If there are
623 no items in the expansion of WORDS, no commands are executed, and
624 the return status is zero.
626 The `break' and `continue' builtins (*note Bourne Shell Builtins::.)
627 may be used to control loop execution.
630 File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Shell Commands
632 Conditional Constructs
633 ----------------------
636 The syntax of the `if' command is:
638 if TEST-COMMANDS; then
640 [elif MORE-TEST-COMMANDS; then
642 [else ALTERNATE-CONSEQUENTS;]
645 The TEST-COMMANDS list is executed, and if its return status is
646 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
647 returns a non-zero status, each `elif' list is executed in turn,
648 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
649 is executed and the command completes. If `else
650 ALTERNATE-CONSEQUENTS' is present, and the final command in the
651 final `if' or `elif' clause has a non-zero exit status, then
652 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
653 status of the last command executed, or zero if no condition
657 The syntax of the `case' command is:
659 `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac'
661 `case' will selectively execute the COMMAND-LIST corresponding to
662 the first PATTERN that matches WORD. The `|' is used to separate
663 multiple patterns, and the `)' operator terminates a pattern list.
664 A list of patterns and an associated command-list is known as a
665 CLAUSE. Each clause must be terminated with `;;'. The WORD
666 undergoes tilde expansion, parameter expansion, command
667 substitution, arithmetic expansion, and quote removal before
668 matching is attempted. Each PATTERN undergoes tilde expansion,
669 parameter expansion, command substitution, and arithmetic
672 There may be an arbitrary number of `case' clauses, each terminated
673 by a `;;'. The first pattern that matches determines the
674 command-list that is executed.
676 Here is an example using `case' in a script that could be used to
677 describe one interesting feature of an animal:
679 echo -n "Enter the name of an animal: "
681 echo -n "The $ANIMAL has "
683 horse | dog | cat) echo -n "four";;
684 man | kangaroo ) echo -n "two";;
685 *) echo -n "an unknown number of";;
689 The return status is zero if no PATTERN is matched. Otherwise, the
690 return status is the exit status of the COMMAND-LIST executed.
693 The `select' construct allows the easy generation of menus. It
694 has almost the same syntax as the `for' command:
696 select NAME [in WORDS ...]; do COMMANDS; done
698 The list of words following `in' is expanded, generating a list of
699 items. The set of expanded words is printed on the standard error
700 output stream, each preceded by a number. If the `in WORDS' is
701 omitted, the positional parameters are printed, as if `in "$@"'
702 had been specifed. The `PS3' prompt is then displayed and a line
703 is read from the standard input. If the line consists of a number
704 corresponding to one of the displayed words, then the value of
705 NAME is set to that word. If the line is empty, the words and
706 prompt are displayed again. If `EOF' is read, the `select'
707 command completes. Any other value read causes NAME to be set to
708 null. The line read is saved in the variable `REPLY'.
710 The COMMANDS are executed after each selection until a `break' or
711 `return' command is executed, at which point the `select' command
714 Here is an example that allows the user to pick a filename from the
715 current directory, and displays the name and index of the file
720 echo you picked $fname \($REPLY\)
727 The arithmetic EXPRESSION is evaluated according to the rules
728 described below (*note Shell Arithmetic::.). If the value of the
729 expression is non-zero, the return status is 0; otherwise the
730 return status is 1. This is exactly equivalent to
733 *Note Bash Builtins::, for a full description of the `let' builtin.
738 Return a status of 0 or 1 depending on the evaluation of the
739 conditional expression EXPRESSION. Expressions are composed of
740 the primaries described below in *Note Bash Conditional
741 Expressions::. Word splitting and filename expansion are not
742 performed on the words between the `[[' and `]]'; tilde expansion,
743 parameter and variable expansion, arithmetic expansion, command
744 substitution, process substitution, and quote removal are
747 When the `==' and `!=' operators are used, the string to the right
748 of the operator is considered a pattern and matched according to
749 the rules described below in *Note Pattern Matching::. The return
750 value is 0 if the string matches or does not match the pattern,
751 respectively, and 1 otherwise. Any part of the pattern may be
752 quoted to force it to be matched as a string.
754 Expressions may be combined using the following operators, listed
755 in decreasing order of precedence:
758 Returns the value of EXPRESSION. This may be used to
759 override the normal precedence of operators.
762 True if EXPRESSION is false.
764 `EXPRESSION1 && EXPRESSION2'
765 True if both EXPRESSION1 and EXPRESSION2 are true.
767 `EXPRESSION1 || EXPRESSION2'
768 True if either EXPRESSION1 or EXPRESSION2 is true.
770 The && and || commands do not execute EXPRESSION2 if the value of
771 EXPRESSION1 is sufficient to determine the return value of the
772 entire conditional expression.
775 File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Shell Commands
780 Bash provides two ways to group a list of commands to be executed as
781 a unit. When commands are grouped, redirections may be applied to the
782 entire command list. For example, the output of all the commands in
783 the list may be redirected to a single stream.
788 Placing a list of commands between parentheses causes a subshell
789 to be created, and each of the commands in LIST to be executed in
790 that subshell. Since the LIST is executed in a subshell, variable
791 assignments do not remain in effect after the subshell completes.
796 Placing a list of commands between curly braces causes the list to
797 be executed in the current shell context. No subshell is created.
798 The semicolon (or newline) following LIST is required.
800 In addition to the creation of a subshell, there is a subtle
801 difference between these two constructs due to historical reasons. The
802 braces are `reserved words', so they must be separated from the LIST by
803 `blank's. The parentheses are `operators', and are recognized as
804 separate tokens by the shell even if they are not separated from the
807 The exit status of both of these constructs is the exit status of
811 File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
816 Shell functions are a way to group commands for later execution
817 using a single name for the group. They are executed just like a
818 "regular" command. Shell functions are executed in the current shell
819 context; no new process is created to interpret them.
821 Functions are declared using this syntax:
822 [ `function' ] NAME () { COMMAND-LIST; }
824 This defines a shell function named NAME. The reserved word
825 `function' is optional. If the `function' reserved word is supplied,
826 the parentheses are optional. The BODY of the function is the
827 COMMAND-LIST between { and }. This list is executed whenever NAME is
828 specified as the name of a command. The exit status of a function is
829 the exit status of the last command executed in the body.
831 When a function is executed, the arguments to the function become
832 the positional parameters during its execution (*note Positional
833 Parameters::.). The special parameter `#' that expands to the number of
834 positional parameters is updated to reflect the change. Positional
835 parameter `0' is unchanged.
837 If the builtin command `return' is executed in a function, the
838 function completes and execution resumes with the next command after
839 the function call. When a function completes, the values of the
840 positional parameters and the special parameter `#' are restored to the
841 values they had prior to the function's execution. If a numeric
842 argument is given to `return', that is the function's return status;
843 otherwise the functions's return status is the exit status of the last
844 command executed before the `return'.
846 Variables local to the function may be declared with the `local'
847 builtin. These variables are visible only to the function and the
850 Functions may be recursive. No limit is placed on the number of
854 File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
861 * Positional Parameters:: The shell's command-line arguments.
862 * Special Parameters:: Parameters with special meanings.
864 A PARAMETER is an entity that stores values. It can be a `name', a
865 number, or one of the special characters listed below. For the shell's
866 purposes, a VARIABLE is a parameter denoted by a `name'.
868 A parameter is set if it has been assigned a value. The null string
869 is a valid value. Once a variable is set, it may be unset only by using
870 the `unset' builtin command.
872 A variable may be assigned to by a statement of the form
875 If VALUE is not given, the variable is assigned the null string. All
876 VALUEs undergo tilde expansion, parameter and variable expansion,
877 command substitution, arithmetic expansion, and quote removal (detailed
878 below). If the variable has its `integer' attribute set (see the
879 description of the `declare' builtin in *Note Bash Builtins::), then
880 VALUE is subject to arithmetic expansion even if the `$((...))'
881 expansion is not used (*note Arithmetic Expansion::.). Word splitting
882 is not performed, with the exception of `"$@"' as explained below.
883 Filename expansion is not performed.
886 File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
888 Positional Parameters
889 ---------------------
891 A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
892 other than the single digit `0'. Positional parameters are assigned
893 from the shell's arguments when it is invoked, and may be reassigned
894 using the `set' builtin command. Positional parameter `N' may be
895 referenced as `${N}'. Positional parameters may not be assigned to
896 with assignment statements. The positional parameters are temporarily
897 replaced when a shell function is executed (*note Shell Functions::.).
899 When a positional parameter consisting of more than a single digit
900 is expanded, it must be enclosed in braces.
903 File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
908 The shell treats several parameters specially. These parameters may
909 only be referenced; assignment to them is not allowed.
912 Expands to the positional parameters, starting from one. When the
913 expansion occurs within double quotes, it expands to a single word
914 with the value of each parameter separated by the first character
915 of the `IFS' special variable. That is, `"$*"' is equivalent to
916 `"$1C$2C..."', where C is the first character of the value of the
917 `IFS' variable. If `IFS' is unset, the parameters are separated
918 by spaces. If `IFS' is null, the parameters are joined without
919 intervening separators.
922 Expands to the positional parameters, starting from one. When the
923 expansion occurs within double quotes, each parameter expands to a
924 separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'.
925 When there are no positional parameters, `"$@"' and `$@' expand to
926 nothing (i.e., they are removed).
929 Expands to the number of positional parameters in decimal.
932 Expands to the exit status of the most recently executed foreground
936 Expands to the current option flags as specified upon invocation,
937 by the `set' builtin command, or those set by the shell itself
938 (such as the `-i' option).
941 Expands to the process ID of the shell. In a `()' subshell, it
942 expands to the process ID of the invoking shell, not the subshell.
945 Expands to the process ID of the most recently executed background
946 (asynchronous) command.
949 Expands to the name of the shell or shell script. This is set at
950 shell initialization. If Bash is invoked with a file of commands
951 (*note Shell Scripts::.), `$0' is set to the name of that file.
952 If Bash is started with the `-c' option (*note Invoking Bash::.),
953 then `$0' is set to the first argument after the string to be
954 executed, if one is present. Otherwise, it is set to the filename
955 used to invoke Bash, as given by argument zero.
958 At shell startup, set to the absolute filename of the shell or
959 shell script being executed as passed in the argument list.
960 Subsequently, expands to the last argument to the previous command,
961 after expansion. Also set to the full pathname of each command
962 executed and placed in the environment exported to that command.
963 When checking mail, this parameter holds the name of the mail file.
966 File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
971 Expansion is performed on the command line after it has been split
972 into `token's. There are seven kinds of expansion performed:
977 * parameter and variable expansion
979 * command substitution
981 * arithmetic expansion
989 * Brace Expansion:: Expansion of expressions within braces.
990 * Tilde Expansion:: Expansion of the ~ character.
991 * Shell Parameter Expansion:: How Bash expands variables to their values.
992 * Command Substitution:: Using the output of a command as an argument.
993 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
994 * Process Substitution:: A way to write and read to and from a
996 * Word Splitting:: How the results of expansion are split into separate
998 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
999 * Quote Removal:: How and when quote characters are removed from
1002 The order of expansions is: brace expansion, tilde expansion,
1003 parameter, variable, and arithmetic expansion and command substitution
1004 (done in a left-to-right fashion), word splitting, and filename
1007 On systems that can support it, there is an additional expansion
1008 available: PROCESS SUBSTITUTION. This is performed at the same time as
1009 parameter, variable, and arithmetic expansion and command substitution.
1011 Only brace expansion, word splitting, and filename expansion can
1012 change the number of words of the expansion; other expansions expand a
1013 single word to a single word. The only exceptions to this are the
1014 expansions of `"$@"' (*note Special Parameters::.) and `"${NAME[@]}"'
1017 After all expansions, `quote removal' (*note Quote Removal::.) is
1021 File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1026 Brace expansion is a mechanism by which arbitrary strings may be
1027 generated. This mechanism is similar to FILENAME EXPANSION (*note
1028 Filename Expansion::.), but the file names generated need not exist.
1029 Patterns to be brace expanded take the form of an optional PREAMBLE,
1030 followed by a series of comma-separated strings between a pair of
1031 braces, followed by an optional POSTSCRIPT. The preamble is prepended
1032 to each string contained within the braces, and the postscript is then
1033 appended to each resulting string, expanding left to right.
1035 Brace expansions may be nested. The results of each expanded string
1036 are not sorted; left to right order is preserved. For example,
1037 bash$ echo a{d,c,b}e
1040 Brace expansion is performed before any other expansions, and any
1041 characters special to other expansions are preserved in the result. It
1042 is strictly textual. Bash does not apply any syntactic interpretation
1043 to the context of the expansion or the text between the braces.
1045 A correctly-formed brace expansion must contain unquoted opening and
1046 closing braces, and at least one unquoted comma. Any incorrectly
1047 formed brace expansion is left unchanged.
1049 This construct is typically used as shorthand when the common prefix
1050 of the strings to be generated is longer than in the above example:
1051 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1053 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1056 File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1061 If a word begins with an unquoted tilde character (`~'), all of the
1062 characters up to the first unquoted slash (or all characters, if there
1063 is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1064 characters in the tilde-prefix are quoted, the characters in the
1065 tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1066 If this login name is the null string, the tilde is replaced with the
1067 value of the `HOME' shell variable. If `HOME' is unset, the home
1068 directory of the user executing the shell is substituted instead.
1069 Otherwise, the tilde-prefix is replaced with the home directory
1070 associated with the specified login name.
1072 If the tilde-prefix is `~+', the value of the shell variable `PWD'
1073 replaces the tilde-prefix. If the tilde-prefix is `~-', the value of
1074 the shell variable `OLDPWD', if it is set, is substituted.
1076 If the characters following the tilde in the tilde-prefix consist of
1077 a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is
1078 replaced with the corresponding element from the directory stack, as it
1079 would be displayed by the `dirs' builtin invoked with the characters
1080 following tilde in the tilde-prefix as an argument (*note The Directory
1081 Stack::.). If the tilde-prefix, sans the tilde, consists of a number
1082 without a leading `+' or `-', `+' is assumed.
1084 If the login name is invalid, or the tilde expansion fails, the word
1087 Each variable assignment is checked for unquoted tilde-prefixes
1088 immediately following a `:' or `='. In these cases, tilde expansion is
1089 also performed. Consequently, one may use file names with tildes in
1090 assignments to `PATH', `MAILPATH', and `CDPATH', and the shell assigns
1093 The following table shows how Bash treats unquoted tilde-prefixes:
1096 The value of `$HOME'
1102 The subdirectory `foo' of the home directory of the user `fred'
1108 `${OLDPWD-'~-'}/foo'
1111 The string that would be displayed by `dirs +N'
1114 The string that would be displayed by `dirs +N'
1117 The string that would be displayed by `dirs -N'
1120 File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1122 Shell Parameter Expansion
1123 -------------------------
1125 The `$' character introduces parameter expansion, command
1126 substitution, or arithmetic expansion. The parameter name or symbol to
1127 be expanded may be enclosed in braces, which are optional but serve to
1128 protect the variable to be expanded from characters immediately
1129 following it which could be interpreted as part of the name.
1131 When braces are used, the matching ending brace is the first `}' not
1132 escaped by a backslash or within a quoted string, and not within an
1133 embedded arithmetic expansion, command substitution, or parameter
1136 The basic form of parameter expansion is ${PARAMETER}. The value of
1137 PARAMETER is substituted. The braces are required when PARAMETER is a
1138 positional parameter with more than one digit, or when PARAMETER is
1139 followed by a character that is not to be interpreted as part of its
1142 If the first character of PARAMETER is an exclamation point, a level
1143 of variable indirection is introduced. Bash uses the value of the
1144 variable formed from the rest of PARAMETER as the name of the variable;
1145 this variable is then expanded and that value is used in the rest of
1146 the substitution, rather than the value of PARAMETER itself. This is
1147 known as `indirect expansion'.
1149 In each of the cases below, WORD is subject to tilde expansion,
1150 parameter expansion, command substitution, and arithmetic expansion.
1151 When not performing substring expansion, Bash tests for a parameter
1152 that is unset or null; omitting the colon results in a test only for a
1153 parameter that is unset.
1155 `${PARAMETER:-WORD}'
1156 If PARAMETER is unset or null, the expansion of WORD is
1157 substituted. Otherwise, the value of PARAMETER is substituted.
1159 `${PARAMETER:=WORD}'
1160 If PARAMETER is unset or null, the expansion of WORD is assigned
1161 to PARAMETER. The value of PARAMETER is then substituted.
1162 Positional parameters and special parameters may not be assigned
1165 `${PARAMETER:?WORD}'
1166 If PARAMETER is null or unset, the expansion of WORD (or a message
1167 to that effect if WORD is not present) is written to the standard
1168 error and the shell, if it is not interactive, exits. Otherwise,
1169 the value of PARAMETER is substituted.
1171 `${PARAMETER:+WORD}'
1172 If PARAMETER is null or unset, nothing is substituted, otherwise
1173 the expansion of WORD is substituted.
1175 `${PARAMETER:OFFSET}'
1176 `${PARAMETER:OFFSET:LENGTH}'
1177 Expands to up to LENGTH characters of PARAMETER, starting at the
1178 character specified by OFFSET. If LENGTH is omitted, expands to
1179 the substring of PARAMETER, starting at the character specified by
1180 OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell
1181 Arithmetic::.). This is referred to as Substring Expansion.
1183 LENGTH must evaluate to a number greater than or equal to zero.
1184 If OFFSET evaluates to a number less than zero, the value is used
1185 as an offset from the end of the value of PARAMETER. If PARAMETER
1186 is `@', the result is LENGTH positional parameters beginning at
1187 OFFSET. If PARAMETER is an array name indexed by `@' or `*', the
1188 result is the LENGTH members of the array beginning with
1189 `${PARAMETER[OFFSET]}'. Substring indexing is zero-based unless
1190 the positional parameters are used, in which case the indexing
1194 The length in characters of the expanded value of PARAMETER is
1195 substituted. If PARAMETER is `*' or `@', the value substituted is
1196 the number of positional parameters. If PARAMETER is an array
1197 name subscripted by `*' or `@', the value substituted is the
1198 number of elements in the array.
1201 `${PARAMETER##WORD}'
1202 The WORD is expanded to produce a pattern just as in filename
1203 expansion (*note Filename Expansion::.). If the pattern matches
1204 the beginning of the expanded value of PARAMETER, then the result
1205 of the expansion is the expanded value of PARAMETER with the
1206 shortest matching pattern (the `#' case) or the longest matching
1207 pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the
1208 pattern removal operation is applied to each positional parameter
1209 in turn, and the expansion is the resultant list. If PARAMETER is
1210 an array variable subscripted with `@' or `*', the pattern removal
1211 operation is applied to each member of the array in turn, and the
1212 expansion is the resultant list.
1215 `${PARAMETER%%WORD}'
1216 The WORD is expanded to produce a pattern just as in filename
1217 expansion. If the pattern matches a trailing portion of the
1218 expanded value of PARAMETER, then the result of the expansion is
1219 the value of PARAMETER with the shortest matching pattern (the `%'
1220 case) or the longest matching pattern (the `%%' case) deleted. If
1221 PARAMETER is `@' or `*', the pattern removal operation is applied
1222 to each positional parameter in turn, and the expansion is the
1223 resultant list. If PARAMETER is an array variable subscripted
1224 with `@' or `*', the pattern removal operation is applied to each
1225 member of the array in turn, and the expansion is the resultant
1228 `${PARAMETER/PATTERN/STRING}'
1229 `${PARAMETER//PATTERN/STRING}'
1230 The PATTERN is expanded to produce a pattern just as in filename
1231 expansion. PARAMETER is expanded and the longest match of PATTERN
1232 against its value is replaced with STRING. In the first form,
1233 only the first match is replaced. The second form causes all
1234 matches of PATTERN to be replaced with STRING. If PATTERN begins
1235 with `#', it must match at the beginning of STRING. If PATTERN
1236 begins with `%', it must match at the end of STRING. If STRING is
1237 null, matches of PATTERN are deleted and the `/' following PATTERN
1238 may be omitted. If PARAMETER is `@' or `*', the substitution
1239 operation is applied to each positional parameter in turn, and the
1240 expansion is the resultant list. If PARAMETER is an array
1241 variable subscripted with `@' or `*', the substitution operation
1242 is applied to each member of the array in turn, and the expansion
1243 is the resultant list.
1246 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1248 Command Substitution
1249 --------------------
1251 Command substitution allows the output of a command to replace the
1252 command name. There are two forms:
1258 Bash performs the expansion by executing COMMAND and replacing the
1259 command substitution with the standard output of the command, with any
1260 trailing newlines deleted. Embedded newlines are not deleted, but they
1261 may be removed during word splitting. The command substitution `$(cat
1262 FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
1264 When the old-style backquote form of substitution is used, backslash
1265 retains its literal meaning except when followed by `$', ``', or `\'.
1266 The first backquote not preceded by a backslash terminates the command
1267 substitution. When using the `$(COMMAND)' form, all characters between
1268 the parentheses make up the command; none are treated specially.
1270 Command substitutions may be nested. To nest when using the
1271 backquoted form, escape the inner backquotes with backslashes.
1273 If the substitution appears within double quotes, word splitting and
1274 filename expansion are not performed on the results.
1277 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1279 Arithmetic Expansion
1280 --------------------
1282 Arithmetic expansion allows the evaluation of an arithmetic
1283 expression and the substitution of the result. The format for
1284 arithmetic expansion is:
1288 The expression is treated as if it were within double quotes, but a
1289 double quote inside the parentheses is not treated specially. All
1290 tokens in the expression undergo parameter expansion, command
1291 substitution, and quote removal. Arithmetic substitutions may be
1294 The evaluation is performed according to the rules listed below
1295 (*note Shell Arithmetic::.). If the expression is invalid, Bash prints
1296 a message indicating failure to the standard error and no substitution
1300 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1302 Process Substitution
1303 --------------------
1305 Process substitution is supported on systems that support named
1306 pipes (FIFOs) or the `/dev/fd' method of naming open files. It takes
1313 The process LIST is run with its input or output connected to a FIFO or
1314 some file in `/dev/fd'. The name of this file is passed as an argument
1315 to the current command as the result of the expansion. If the
1316 `>(LIST)' form is used, writing to the file will provide input for
1317 LIST. If the `<(LIST)' form is used, the file passed as an argument
1318 should be read to obtain the output of LIST.
1320 When available, process substitution is performed simultaneously with
1321 parameter and variable expansion, command substitution, and arithmetic
1325 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1330 The shell scans the results of parameter expansion, command
1331 substitution, and arithmetic expansion that did not occur within double
1332 quotes for word splitting.
1334 The shell treats each character of `$IFS' as a delimiter, and splits
1335 the results of the other expansions into words on these characters. If
1336 `IFS' is unset, or its value is exactly `<space><tab><newline>', the
1337 default, then any sequence of `IFS' characters serves to delimit words.
1338 If `IFS' has a value other than the default, then sequences of the
1339 whitespace characters `space' and `tab' are ignored at the beginning
1340 and end of the word, as long as the whitespace character is in the
1341 value of `IFS' (an `IFS' whitespace character). Any character in `IFS'
1342 that is not `IFS' whitespace, along with any adjacent `IFS' whitespace
1343 characters, delimits a field. A sequence of `IFS' whitespace
1344 characters is also treated as a delimiter. If the value of `IFS' is
1345 null, no word splitting occurs.
1347 Explicit null arguments (`""' or `''') are retained. Unquoted
1348 implicit null arguments, resulting from the expansion of PARAMETERs
1349 that have no values, are removed. If a parameter with no value is
1350 expanded within double quotes, a null argument results and is retained.
1352 Note that if no expansion occurs, no splitting is performed.
1355 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1362 * Pattern Matching:: How the shell matches patterns.
1364 After word splitting, unless the `-f' option has been set (*note The
1365 Set Builtin::.), Bash scans each word for the characters `*', `?', `(',
1366 and `['. If one of these characters appears, then the word is regarded
1367 as a PATTERN, and replaced with an alphabetically sorted list of file
1368 names matching the pattern. If no matching file names are found, and
1369 the shell option `nullglob' is disabled, the word is left unchanged.
1370 If the `nullglob' option is set, and no matches are found, the word is
1371 removed. If the shell option `nocaseglob' is enabled, the match is
1372 performed without regard to the case of alphabetic characters.
1374 When a pattern is used for filename generation, the character `.' at
1375 the start of a filename or immediately following a slash must be
1376 matched explicitly, unless the shell option `dotglob' is set. When
1377 matching a file name, the slash character must always be matched
1378 explicitly. In other cases, the `.' character is not treated specially.
1380 See the description of `shopt' in *Note Bash Builtins::, for a
1381 description of the `nocaseglob', `nullglob', and `dotglob' options.
1383 The `GLOBIGNORE' shell variable may be used to restrict the set of
1384 filenames matching a pattern. If `GLOBIGNORE' is set, each matching
1385 filename that also matches one of the patterns in `GLOBIGNORE' is
1386 removed from the list of matches. The filenames `.' and `..' are
1387 always ignored, even when `GLOBIGNORE' is set. However, setting
1388 `GLOBIGNORE' has the effect of enabling the `dotglob' shell option, so
1389 all other filenames beginning with a `.' will match. To get the old
1390 behavior of ignoring filenames beginning with a `.', make `.*' one of
1391 the patterns in `GLOBIGNORE'. The `dotglob' option is disabled when
1392 `GLOBIGNORE' is unset.
1395 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1400 Any character that appears in a pattern, other than the special
1401 pattern characters described below, matches itself. The NUL character
1402 may not occur in a pattern. The special pattern characters must be
1403 quoted if they are to be matched literally.
1405 The special pattern characters have the following meanings:
1407 Matches any string, including the null string.
1410 Matches any single character.
1413 Matches any one of the enclosed characters. A pair of characters
1414 separated by a minus sign denotes a RANGE; any character lexically
1415 between those two characters, inclusive, is matched. If the first
1416 character following the `[' is a `!' or a `^' then any character
1417 not enclosed is matched. A `-' may be matched by including it as
1418 the first or last character in the set. A `]' may be matched by
1419 including it as the first character in the set.
1421 Within `[' and `]', CHARACTER CLASSES can be specified using the
1422 syntax `[:'CLASS`:]', where CLASS is one of the following classes
1423 defined in the POSIX.2 standard:
1424 alnum alpha ascii blank cntrl digit graph lower
1425 print punct space upper xdigit
1427 A character class matches any character belonging to that class.
1429 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1430 the syntax `[='C`=]', which matches all characters with the same
1431 collation weight (as defined by the current locale) as the
1434 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
1435 collating symbol SYMBOL.
1437 If the `extglob' shell option is enabled using the `shopt' builtin,
1438 several extended pattern matching operators are recognized. In the
1439 following description, a PATTERN-LIST is a list of one or more patterns
1440 separated by a `|'. Composite patterns may be formed using one or more
1441 of the following sub-patterns:
1444 Matches zero or one occurrence of the given patterns.
1447 Matches zero or more occurrences of the given patterns.
1450 Matches one or more occurrences of the given patterns.
1453 Matches exactly one of the given patterns.
1456 Matches anything except one of the given patterns.
1459 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1464 After the preceding expansions, all unquoted occurrences of the
1465 characters `\', `'', and `"' that did not result from one of the above
1466 expansions are removed.
1469 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1474 Before a command is executed, its input and output may be REDIRECTED
1475 using a special notation interpreted by the shell. Redirection may
1476 also be used to open and close files for the current shell execution
1477 environment. The following redirection operators may precede or appear
1478 anywhere within a simple command or may follow a command. Redirections
1479 are processed in the order they appear, from left to right.
1481 In the following descriptions, if the file descriptor number is
1482 omitted, and the first character of the redirection operator is `<',
1483 the redirection refers to the standard input (file descriptor 0). If
1484 the first character of the redirection operator is `>', the redirection
1485 refers to the standard output (file descriptor 1).
1487 The word following the redirection operator in the following
1488 descriptions, unless otherwise noted, is subjected to brace expansion,
1489 tilde expansion, parameter expansion, command substitution, arithmetic
1490 expansion, quote removal, and filename expansion. If it expands to
1491 more than one word, Bash reports an error.
1493 Note that the order of redirections is significant. For example,
1497 directs both standard output and standard error to the file DIRLIST,
1501 directs only the standard output to file DIRLIST, because the standard
1502 error was duplicated as standard output before the standard output was
1503 redirected to DIRLIST.
1505 A failure to open or create a file causes the redirection to fail.
1510 Redirection of input causes the file whose name results from the
1511 expansion of WORD to be opened for reading on file descriptor `n', or
1512 the standard input (file descriptor 0) if `n' is not specified.
1514 The general format for redirecting input is:
1520 Redirection of output causes the file whose name results from the
1521 expansion of WORD to be opened for writing on file descriptor `n', or
1522 the standard output (file descriptor 1) if `n' is not specified. If
1523 the file does not exist it is created; if it does exist it is truncated
1526 The general format for redirecting output is:
1529 If the redirection operator is `>', and the `noclobber' option to
1530 the `set' builtin has been enabled, the redirection will fail if the
1531 filename whose name results from the expansion of WORD exists and is a
1532 regular file. If the redirection operator is `>|', or the redirection
1533 operator is `>' and the `noclobber' option is not enabled, the
1534 redirection is attempted even if the file named by WORD exists.
1536 Appending Redirected Output
1537 ---------------------------
1539 Redirection of output in this fashion causes the file whose name
1540 results from the expansion of WORD to be opened for appending on file
1541 descriptor `n', or the standard output (file descriptor 1) if `n' is
1542 not specified. If the file does not exist it is created.
1544 The general format for appending output is:
1547 Redirecting Standard Output and Standard Error
1548 ----------------------------------------------
1550 Bash allows both the standard output (file descriptor 1) and the
1551 standard error output (file descriptor 2) to be redirected to the file
1552 whose name is the expansion of WORD with this construct.
1554 There are two formats for redirecting standard output and standard
1561 Of the two forms, the first is preferred. This is semantically
1568 This type of redirection instructs the shell to read input from the
1569 current source until a line containing only WORD (with no trailing
1570 blanks) is seen. All of the lines read up to that point are then used
1571 as the standard input for a command.
1573 The format of here-documents is as follows:
1578 No parameter expansion, command substitution, filename expansion, or
1579 arithmetic expansion is performed on WORD. If any characters in WORD
1580 are quoted, the DELIMITER is the result of quote removal on WORD, and
1581 the lines in the here-document are not expanded. If WORD is unquoted,
1582 all lines of the here-document are subjected to parameter expansion,
1583 command substitution, and arithmetic expansion. In the latter case,
1584 the pair `\newline' is ignored, and `\' must be used to quote the
1585 characters `\', `$', and ``'.
1587 If the redirection operator is `<<-', then all leading tab
1588 characters are stripped from input lines and the line containing
1589 DELIMITER. This allows here-documents within shell scripts to be
1590 indented in a natural fashion.
1592 Duplicating File Descriptors
1593 ----------------------------
1595 The redirection operator
1598 is used to duplicate input file descriptors. If WORD expands to one or
1599 more digits, the file descriptor denoted by `n' is made to be a copy of
1600 that file descriptor. If the digits in WORD do not specify a file
1601 descriptor open for input, a redirection error occurs. If WORD
1602 evaluates to `-', file descriptor `n' is closed. If `n' is not
1603 specified, the standard input (file descriptor 0) is used.
1608 is used similarly to duplicate output file descriptors. If `n' is not
1609 specified, the standard output (file descriptor 1) is used. If the
1610 digits in WORD do not specify a file descriptor open for output, a
1611 redirection error occurs. As a special case, if `n' is omitted, and
1612 WORD does not expand to one or more digits, the standard output and
1613 standard error are redirected as described previously.
1615 Opening File Descriptors for Reading and Writing
1616 ------------------------------------------------
1618 The redirection operator
1621 causes the file whose name is the expansion of WORD to be opened for
1622 both reading and writing on file descriptor `n', or on file descriptor
1623 0 if `n' is not specified. If the file does not exist, it is created.
1626 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
1633 * Simple Command Expansion:: How Bash expands simple commands before
1636 * Command Search and Execution:: How Bash finds commands and runs them.
1638 * Command Execution Environment:: The environment in which Bash
1639 executes commands that are not
1642 * Environment:: The environment given to a command.
1644 * Exit Status:: The status returned by commands and how Bash
1647 * Signals:: What happens when Bash or a command it runs
1651 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
1653 Simple Command Expansion
1654 ------------------------
1656 When a simple command is executed, the shell performs the following
1657 expansions, assignments, and redirections, from left to right.
1659 1. The words that the parser has marked as variable assignments (those
1660 preceding the command name) and redirections are saved for later
1663 2. The words that are not variable assignments or redirections are
1664 expanded (*note Shell Expansions::.). If any words remain after
1665 expansion, the first word is taken to be the name of the command
1666 and the remaining words are the arguments.
1668 3. Redirections are performed as described above (*note
1671 4. The text after the `=' in each variable assignment undergoes tilde
1672 expansion, parameter expansion, command substitution, arithmetic
1673 expansion, and quote removal before being assigned to the variable.
1675 If no command name results, the variable assignments affect the
1676 current shell environment. Otherwise, the variables are added to the
1677 environment of the executed command and do not affect the current shell
1678 environment. If any of the assignments attempts to assign a value to a
1679 readonly variable, an error occurs, and the command exits with a
1682 If no command name results, redirections are performed, but do not
1683 affect the current shell environment. A redirection error causes the
1684 command to exit with a non-zero status.
1686 If there is a command name left after expansion, execution proceeds
1687 as described below. Otherwise, the command exits. If one of the
1688 expansions contained a command substitution, the exit status of the
1689 command is the exit status of the last command substitution performed.
1690 If there were no command substitutions, the command exits with a status
1694 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
1696 Command Search and Execution
1697 ----------------------------
1699 After a command has been split into words, if it results in a simple
1700 command and an optional list of arguments, the following actions are
1703 1. If the command name contains no slashes, the shell attempts to
1704 locate it. If there exists a shell function by that name, that
1705 function is invoked as described above in *Note Shell Functions::.
1707 2. If the name does not match a function, the shell searches for it
1708 in the list of shell builtins. If a match is found, that builtin
1711 3. If the name is neither a shell function nor a builtin, and
1712 contains no slashes, Bash searches each element of `$PATH' for a
1713 directory containing an executable file by that name. Bash uses a
1714 hash table to remember the full pathnames of executable files to
1715 avoid multiple `PATH' searches (see the description of `hash' in
1716 *Note Bourne Shell Builtins::). A full search of the directories
1717 in `$PATH' is performed only if the command is not found in the
1718 hash table. If the search is unsuccessful, the shell prints an
1719 error message and returns an exit status of 127.
1721 4. If the search is successful, or if the command name contains one
1722 or more slashes, the shell executes the named program in a
1723 separate execution environment. Argument 0 is set to the name
1724 given, and the remaining arguments to the command are set to the
1725 arguments supplied, if any.
1727 5. If this execution fails because the file is not in executable
1728 format, and the file is not a directory, it is assumed to be a
1729 SHELL SCRIPT and the shell executes it as described in *Note Shell
1732 6. If the command was not begun asynchronously, the shell waits for
1733 the command to complete and collects its exit status.
1737 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
1739 Command Execution Environment
1740 -----------------------------
1742 The shell has an EXECUTION ENVIRONMENT, which consists of the
1745 * open files inherited by the shell at invocation, as modified by
1746 redirections supplied to the `exec' builtin
1748 * the current working directory as set by `cd', `pushd', or `popd',
1749 or inherited by the shell at invocation
1751 * the file creation mode mask as set by `umask' or inherited from
1754 * current traps set by `trap'
1756 * shell parameters that are set by variable assignment or with `set'
1757 or inherited from the shell's parent in the environment
1759 * shell functions defined during execution or inherited from the
1760 shell's parent in the environment
1762 * options enabled at invocation (either by default or with
1763 command-line arguments) or by `set'
1765 * options enabled by `shopt'
1767 * shell aliases defined with `alias' (*note Aliases::.)
1769 * various process IDs, including those of background jobs (*note
1770 Lists::.), the value of `$$', and the value of `$PPID'
1772 When a simple command other than a builtin or shell function is to
1773 be executed, it is invoked in a separate execution environment that
1774 consists of the following. Unless otherwise noted, the values are
1775 inherited from the shell.
1777 * the shell's open files, plus any modifications and additions
1778 specified by redirections to the command
1780 * the current working directory
1782 * the file creation mode mask
1784 * shell variables marked for export, along with variables exported
1785 for the command, passed in the environment (*note Environment::.)
1787 * traps caught by the shell are reset to the values inherited from
1788 the shell's parent, and traps ignored by the shell are ignored
1790 A command invoked in this separate environment cannot affect the
1791 shell's execution environment.
1793 Command substitution and asynchronous commands are invoked in a
1794 subshell environment that is a duplicate of the shell environment,
1795 except that traps caught by the shell are reset to the values that the
1796 shell inherited from its parent at invocation. Builtin commands that
1797 are invoked as part of a pipeline are also executed in a subshell
1798 environment. Changes made to the subshell environment cannot affect
1799 the shell's execution environment.
1802 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
1807 When a program is invoked it is given an array of strings called the
1808 ENVIRONMENT. This is a list of name-value pairs, of the form
1811 Bash allows you to manipulate the environment in several ways. On
1812 invocation, the shell scans its own environment and creates a parameter
1813 for each name found, automatically marking it for EXPORT to child
1814 processes. Executed commands inherit the environment. The `export'
1815 and `declare -x' commands allow parameters and functions to be added to
1816 and deleted from the environment. If the value of a parameter in the
1817 environment is modified, the new value becomes part of the environment,
1818 replacing the old. The environment inherited by any executed command
1819 consists of the shell's initial environment, whose values may be
1820 modified in the shell, less any pairs removed by the `unset' and
1821 `export -n' commands, plus any additions via the `export' and `declare
1824 The environment for any simple command or function may be augmented
1825 temporarily by prefixing it with parameter assignments, as described in
1826 *Note Shell Parameters::. These assignment statements affect only the
1827 environment seen by that command.
1829 If the `-k' option is set (*note The Set Builtin::.), then all
1830 parameter assignments are placed in the environment for a command, not
1831 just those that precede the command name.
1833 When Bash invokes an external command, the variable `$_' is set to
1834 the full path name of the command and passed to that command in its
1838 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
1843 For the shell's purposes, a command which exits with a zero exit
1844 status has succeeded. A non-zero exit status indicates failure. This
1845 seemingly counter-intuitive scheme is used so there is one well-defined
1846 way to indicate success and a variety of ways to indicate various
1847 failure modes. When a command terminates on a fatal signal whose
1848 number is N, Bash uses the value 128+N as the exit status.
1850 If a command is not found, the child process created to execute it
1851 returns a status of 127. If a command is found but is not executable,
1852 the return status is 126.
1854 If a command fails because of an error during expansion or
1855 redirection, the exit status is greater than zero.
1857 The exit status is used by the Bash conditional commands (*note
1858 Conditional Constructs::.) and some of the list constructs (*note
1861 All of the Bash builtins return an exit status of zero if they
1862 succeed and a non-zero status on failure, so they may be used by the
1863 conditional and list constructs. All builtins return an exit status of
1864 2 to indicate incorrect usage.
1867 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
1872 When Bash is interactive, in the absence of any traps, it ignores
1873 `SIGTERM' (so that `kill 0' does not kill an interactive shell), and
1874 `SIGINT' is caught and handled (so that the `wait' builtin is
1875 interruptible). When Bash receives a `SIGINT', it breaks out of any
1876 executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
1877 is in effect (*note Job Control::.), Bash ignores `SIGTTIN', `SIGTTOU',
1880 Commands started by Bash have signal handlers set to the values
1881 inherited by the shell from its parent. When job control is not in
1882 effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' as well.
1883 Commands run as a result of command substitution ignore the
1884 keyboard-generated job control signals `SIGTTIN', `SIGTTOU', and
1887 The shell exits by default upon receipt of a `SIGHUP'. Before
1888 exiting, it resends the `SIGHUP' to all jobs, running or stopped.
1889 Stopped jobs are sent `SIGCONT' to ensure that they receive the
1890 `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to a
1891 particular job, it should be removed from the jobs table with the
1892 `disown' builtin (*note Job Control Builtins::.) or marked to not
1893 receive `SIGHUP' using `disown -h'.
1895 If the `huponexit' shell option has been set with `shopt' (*note
1896 Bash Builtins::.), Bash sends a `SIGHUP' to all jobs when an
1897 interactive login shell exits.
1899 When Bash receives a signal for which a trap has been set while
1900 waiting for a command to complete, the trap will not be executed until
1901 the command completes. When Bash is waiting for an asynchronous
1902 command via the `wait' builtin, the reception of a signal for which a
1903 trap has been set will cause the `wait' builtin to return immediately
1904 with an exit status greater than 128, immediately after which the trap
1908 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
1913 A shell script is a text file containing shell commands. When such
1914 a file is used as the first non-option argument when invoking Bash, and
1915 neither the `-c' nor `-s' option is supplied (*note Invoking Bash::.),
1916 Bash reads and executes commands from the file, then exits. This mode
1917 of operation creates a non-interactive shell. When Bash runs a shell
1918 script, it sets the special parameter `0' to the name of the file,
1919 rather than the name of the shell, and the positional parameters are
1920 set to the remaining arguments, if any are given. If no additional
1921 arguments are supplied, the positional parameters are unset.
1923 A shell script may be made executable by using the `chmod' command
1924 to turn on the execute bit. When Bash finds such a file while
1925 searching the `$PATH' for a command, it spawns a subshell to execute
1926 it. In other words, executing
1929 is equivalent to executing
1930 bash filename ARGUMENTS
1932 if `filename' is an executable shell script. This subshell
1933 reinitializes itself, so that the effect is as if a new shell had been
1934 invoked to interpret the script, with the exception that the locations
1935 of commands remembered by the parent (see the description of `hash' in
1936 *Note Bourne Shell Builtins::) are retained by the child.
1938 Most versions of Unix make this a part of the kernel's command
1939 execution mechanism. If the first line of a script begins with the two
1940 characters `#!', the remainder of the line specifies an interpreter for
1941 the program. The arguments to the interpreter consist of a single
1942 optional argument following the interpreter name on the first line of
1943 the script file, followed by the name of the script file, followed by
1944 the rest of the arguments. Bash will perform this action on operating
1945 systems that do not handle it themselves. Note that some older
1946 versions of Unix limit the interpreter name and argument to a maximum
1950 File: bashref.info, Node: Bourne Shell Features, Next: Bash Features, Prev: Basic Shell Features, Up: Top
1952 Bourne Shell Style Features
1953 ***************************
1957 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
1959 * Bourne Shell Variables:: Variables which Bash uses in the same way
1960 as the Bourne Shell.
1961 * Other Bourne Shell Features:: Addtional aspects of Bash which behave in
1962 the same way as the Bourne Shell.
1964 This section briefly summarizes things which Bash inherits from the
1965 Bourne Shell: builtins, variables, and other features. It also lists
1966 the significant differences between Bash and the Bourne Shell. Many of
1967 the builtins have been extended by POSIX or Bash.
1970 File: bashref.info, Node: Bourne Shell Builtins, Next: Bourne Shell Variables, Up: Bourne Shell Features
1972 Bourne Shell Builtins
1973 =====================
1975 The following shell builtin commands are inherited from the Bourne
1976 Shell. These commands are implemented as specified by the POSIX 1003.2
1981 Do nothing beyond expanding ARGUMENTS and performing redirections.
1982 The return status is zero.
1986 Read and execute commands from the FILENAME argument in the
1987 current shell context. If FILENAME does not contain a slash, the
1988 `$PATH' variable is used to find FILENAME. The current directory
1989 is searched if FILENAME is not found in `$PATH'. The return
1990 status is the exit status of the last command executed, or zero if
1991 no commands are executed. If FILENAME is not found, or cannot be
1992 read, the return status is non-zero.
1996 Exit from a `for', `while', `until', or `select' loop. If N is
1997 supplied, the Nth enclosing loop is exited. N must be greater
1998 than or equal to 1. The return status is zero unless N is not
1999 greater than or equal to 1.
2002 cd [-LP] [DIRECTORY]
2003 Change the current working directory to DIRECTORY. If DIRECTORY
2004 is not given, the value of the `HOME' shell variable is used. If
2005 the shell variable `CDPATH' exists, it is used as a search path.
2006 If DIRECTORY begins with a slash, `CDPATH' is not used. The `-P'
2007 option means to not follow symbolic links; symbolic links are
2008 followed by default or with the `-L' option. If DIRECTORY is `-',
2009 it is equivalent to `$OLDPWD'. The return status is zero if the
2010 directory is successfully changed, non-zero otherwise.
2014 Resume the next iteration of an enclosing `for', `while', `until',
2015 or `select' loop. If N is supplied, the execution of the Nth
2016 enclosing loop is resumed. N must be greater than or equal to 1.
2017 The return status is zero unless N is not greater than or equal to
2022 The arguments are concatenated together into a single command,
2023 which is then read and executed, and its exit status returned as
2024 the exit status of `eval'. If there are no arguments or only
2025 empty arguments, the return status is zero.
2028 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2029 If COMMAND is supplied, it replaces the shell without creating a
2030 new process. If the `-l' option is supplied, the shell places a
2031 dash in the zeroth arg passed to COMMAND. This is what the
2032 `login' program does. The `-c' option causes COMMAND to be
2033 executed with an empty environment. If `-a' is supplied, the
2034 shell passes NAME as the zeroth argument to COMMAND. If no
2035 COMMAND is specified, redirections may be used to affect the
2036 current shell environment. If there are no redirection errors, the
2037 return status is zero; otherwise the return status is non-zero.
2041 Exit the shell, returning a status of N to the shell's parent.
2042 Any trap on `EXIT' is executed before the shell terminates.
2045 export [-fn] [-p] [NAME[=VALUE]]
2046 Mark each NAME to be passed to child processes in the environment.
2047 If the `-f' option is supplied, the NAMEs refer to shell
2048 functions; otherwise the names refer to shell variables. The `-n'
2049 option means to no longer mark each NAME for export. If no NAMES
2050 are supplied, or if the `-p' option is given, a list of exported
2051 names is displayed. The `-p' option displays output in a form
2052 that may be reused as input. The return status is zero unless an
2053 invalid option is supplied, one of the names is not a valid shell
2054 variable name, or `-f' is supplied with a name that is not a shell
2058 getopts OPTSTRING NAME [ARGS]
2059 `getopts' is used by shell scripts to parse positional parameters.
2060 OPTSTRING contains the option letters to be recognized; if a letter
2061 is followed by a colon, the option is expected to have an
2062 argument, which should be separated from it by white space. Each
2063 time it is invoked, `getopts' places the next option in the shell
2064 variable NAME, initializing NAME if it does not exist, and the
2065 index of the next argument to be processed into the variable
2066 `OPTIND'. `OPTIND' is initialized to 1 each time the shell or a
2067 shell script is invoked. When an option requires an argument,
2068 `getopts' places that argument into the variable `OPTARG'. The
2069 shell does not reset `OPTIND' automatically; it must be manually
2070 reset between multiple calls to `getopts' within the same shell
2071 invocation if a new set of parameters is to be used.
2073 When the end of options is encountered, `getopts' exits with a
2074 return value greater than zero. `OPTIND' is set to the index of
2075 the first non-option argument, and `name' is set to `?'.
2077 `getopts' normally parses the positional parameters, but if more
2078 arguments are given in ARGS, `getopts' parses those instead.
2080 `getopts' can report errors in two ways. If the first character of
2081 OPTSTRING is a colon, SILENT error reporting is used. In normal
2082 operation diagnostic messages are printed when invalid options or
2083 missing option arguments are encountered. If the variable `OPTERR'
2084 is set to 0, no error messages will be displayed, even if the first
2085 character of `optstring' is not a colon.
2087 If an invalid option is seen, `getopts' places `?' into NAME and,
2088 if not silent, prints an error message and unsets `OPTARG'. If
2089 `getopts' is silent, the option character found is placed in
2090 `OPTARG' and no diagnostic message is printed.
2092 If a required argument is not found, and `getopts' is not silent,
2093 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2094 diagnostic message is printed. If `getopts' is silent, then a
2095 colon (`:') is placed in NAME and `OPTARG' is set to the option
2099 hash [-r] [-p FILENAME] [NAME]
2100 Remember the full pathnames of commands specified as NAME
2101 arguments, so they need not be searched for on subsequent
2102 invocations. The commands are found by searching through the
2103 directories listed in `$PATH'. The `-p' option inhibits the path
2104 search, and FILENAME is used as the location of NAME. The `-r'
2105 option causes the shell to forget all remembered locations. If no
2106 arguments are given, information about remembered commands is
2107 printed. The return status is zero unless a NAME is not found or
2108 an invalid option is supplied.
2112 Print the current working directory. If the `-P' option is
2113 supplied, the path printed will not contain symbolic links. If
2114 the `-L' option is supplied, the path printed may contain symbolic
2115 links. The return status is zero unless an error is encountered
2116 while determining the name of the current directory or an invalid
2120 readonly [-apf] [NAME] ...
2121 Mark each NAME as readonly. The values of these names may not be
2122 changed by subsequent assignment. If the `-f' option is supplied,
2123 each NAME refers to a shell function. The `-a' option means each
2124 NAME refers to an array variable. If no NAME arguments are given,
2125 or if the `-p' option is supplied, a list of all readonly names is
2126 printed. The `-p' option causes output to be displayed in a
2127 format that may be reused as input. The return status is zero
2128 unless an invalid option is supplied, one of the NAME arguments is
2129 not a valid shell variable or function name, or the `-f' option is
2130 supplied with a name that is not a shell function.
2134 Cause a shell function to exit with the return value N. This may
2135 also be used to terminate execution of a script being executed
2136 with the `.' builtin, returning either N or the exit status of the
2137 last command executed within the script as the exit status of the
2138 script. The return status is false if `return' is used outside a
2139 function and not during the execution of a script by `.'.
2143 Shift the positional parameters to the left by N. The positional
2144 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N+1.
2145 Parameters represented by the numbers `$#' to N+1 are unset. N
2146 must be a non-negative number less than or equal to `$#'. If N is
2147 zero or greater than `$#', the positional parameters are not
2148 changed. The return status is zero unless N is greater than `$#'
2149 or less than zero, non-zero otherwise.
2153 Evaluate a conditional expression EXPR. Each operator and operand
2154 must be a separate argument. Expressions are composed of the
2155 primaries described below in *Note Bash Conditional Expressions::.
2157 Expressions may be combined using the following operators, listed
2158 in decreasing order of precedence.
2161 True if EXPR is false.
2164 Returns the value of EXPR. This may be used to override the
2165 normal precedence of operators.
2168 True if both EXPR1 and EXPR2 are true.
2171 True if either EXPR1 or EXPR2 is true.
2173 The `test' and `[' builtins evaluate conditional expressions using
2174 a set of rules based on the number of arguments.
2177 The expression is false.
2180 The expression is true if and only if the argument is not
2184 If the first argument is `!', the expression is true if and
2185 only if the second argument is null. If the first argument
2186 is one of the unary conditional operators (*note Bash
2187 Conditional Expressions::.), the expression is true if the
2188 unary test is true. If the first argument is not a valid
2189 unary operator, the expression is false.
2192 If the second argument is one of the binary conditional
2193 operators (*note Bash Conditional Expressions::.), the result
2194 of the expression is the result of the binary test using the
2195 first and third arguments as operands. If the first argument
2196 is `!', the value is the negation of the two-argument test
2197 using the second and third arguments. If the first argument
2198 is exactly `(' and the third argument is exactly `)', the
2199 result is the one-argument test of the second argument.
2200 Otherwise, the expression is false. The `-a' and `-o'
2201 operators are considered binary operators in this case.
2204 If the first argument is `!', the result is the negation of
2205 the three-argument expression composed of the remaining
2206 arguments. Otherwise, the expression is parsed and evaluated
2207 according to precedence using the rules listed above.
2210 The expression is parsed and evaluated according to precedence
2211 using the rules listed above.
2215 Print out the user and system times used by the shell and its
2216 children. The return status is zero.
2219 trap [-lp] [ARG] [SIGSPEC ...]
2220 The commands in ARG are to be read and executed when the shell
2221 receives signal SIGSPEC. If ARG is absent or equal to `-', all
2222 specified signals are reset to the values they had when the shell
2223 was started. If ARG is the null string, then the signal specified
2224 by each SIGSPEC is ignored by the shell and commands it invokes.
2225 If ARG is `-p', the shell displays the trap commands associated
2226 with each SIGSPEC. If no arguments are supplied, or only `-p' is
2227 given, `trap' prints the list of commands associated with each
2228 signal number in a form that may be reused as shell input. Each
2229 SIGSPEC is either a signal name such as `SIGINT' (with or without
2230 the `SIG' prefix) or a signal number. If a SIGSPEC is `0' or
2231 `EXIT', ARG is executed when the shell exits. If a SIGSPEC is
2232 `DEBUG', the command ARG is executed after every simple command.
2233 The `-l' option causes the shell to print a list of signal names
2234 and their corresponding numbers.
2236 Signals ignored upon entry to the shell cannot be trapped or reset.
2237 Trapped signals are reset to their original values in a child
2238 process when it is created.
2240 The return status is zero unless a SIGSPEC does not specify a
2244 umask [-p] [-S] [MODE]
2245 Set the shell process's file creation mask to MODE. If MODE
2246 begins with a digit, it is interpreted as an octal number; if not,
2247 it is interpreted as a symbolic mode mask similar to that accepted
2248 by the `chmod' command. If MODE is omitted, the current value of
2249 the mask is printed. If the `-S' option is supplied without a
2250 MODE argument, the mask is printed in a symbolic format. If the
2251 `-p' option is supplied, and MODE is omitted, the output is in a
2252 form that may be reused as input. The return status is zero if
2253 the mode is successfully changed or if no MODE argument is
2254 supplied, and non-zero otherwise.
2258 Each variable or function NAME is removed. If no options are
2259 supplied, or the `-v' option is given, each NAME refers to a shell
2260 variable. If the `-f' option is given, the NAMEs refer to shell
2261 functions, and the function definition is removed. Readonly
2262 variables and functions may not be unset. The return status is
2263 zero unless a NAME does not exist or is readonly.
2266 File: bashref.info, Node: Bourne Shell Variables, Next: Other Bourne Shell Features, Prev: Bourne Shell Builtins, Up: Bourne Shell Features
2268 Bourne Shell Variables
2269 ======================
2271 Bash uses certain shell variables in the same way as the Bourne
2272 shell. In some cases, Bash assigns a default value to the variable.
2275 A colon-separated list of directories used as a search path for
2276 the `cd' builtin command.
2279 The current user's home directory; the default for the `cd' builtin
2280 command. The value of this variable is also used by tilde
2281 expansion (*note Tilde Expansion::.).
2284 A list of characters that separate fields; used when the shell
2285 splits words as part of expansion.
2288 If this parameter is set to a filename and the `MAILPATH' variable
2289 is not set, Bash informs the user of the arrival of mail in the
2293 A colon-separated list of filenames which the shell periodically
2294 checks for new mail. Each list entry can specify the message that
2295 is printed when new mail arrives in the mail file by separating
2296 the file name from the message with a `?'. When used in the text
2297 of the message, `$_' expands to the name of the current mail file.
2300 The value of the last option argument processed by the `getopts'
2304 The index of the last option argument processed by the `getopts'
2308 A colon-separated list of directories in which the shell looks for
2312 The primary prompt string. The default value is `\s-\v\$ '.
2315 The secondary prompt string. The default value is `> '.
2318 File: bashref.info, Node: Other Bourne Shell Features, Prev: Bourne Shell Variables, Up: Bourne Shell Features
2320 Other Bourne Shell Features
2321 ===========================
2325 * Major Differences From The Bourne Shell:: Major differences between
2326 Bash and the Bourne shell.
2328 Bash implements essentially the same grammar, parameter and variable
2329 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
2330 POSIX 1003.2 standard as the specification of how these features are to
2331 be implemented. There are some differences between the traditional
2332 Bourne shell and Bash; this section quickly details the differences of
2333 significance. A number of these differences are explained in greater
2334 depth in subsequent sections.
2337 File: bashref.info, Node: Major Differences From The Bourne Shell, Up: Other Bourne Shell Features
2339 Major Differences From The SVR4.2 Bourne Shell
2340 ----------------------------------------------
2342 * Bash is POSIX-conformant, even where the POSIX specification
2343 differs from traditional `sh' behavior.
2345 * Bash has multi-character invocation options (*note Invoking
2348 * Bash has command-line editing (*note Command Line Editing::.) and
2351 * Bash has command history (*note Bash History Facilities::.) and the
2352 `history' and `fc' builtins to manipulate it.
2354 * Bash implements `csh'-like history expansion (*note History
2357 * Bash has one-dimensional array variables (*note Arrays::.), and the
2358 appropriate variable expansions and assignment syntax to use them.
2359 Several of the Bash builtins take options to act on arrays. Bash
2360 provides a number of built-in array variables.
2362 * The `$'...'' quoting syntax, which expands ANSI-C
2363 backslash-escaped characters in the text between the single quotes,
2364 is supported (*note ANSI-C Quoting::.).
2366 * Bash supports the `$"..."' quoting syntax to do locale-specific
2367 translation of the characters between the double quotes. The
2368 `-D', `--dump-strings', and `--dump-po-strings' invocation options
2369 list the translatable strings found in a script (*note Locale
2372 * Bash implements the `!' keyword to negate the return value of a
2373 pipeline (*note Pipelines::.). Very useful when an `if' statement
2374 needs to act only if a test fails.
2376 * Bash has the `time' reserved word and command timing (*note
2377 Pipelines::.). The display of the timing statistics may be
2378 controlled with the `TIMEFORMAT' variable.
2380 * Bash includes the `select' compound command, which allows the
2381 generation of simple menus (*note Conditional Constructs::.).
2383 * Bash includes the `[[' compound command, which makes conditional
2384 testing part of the shell grammar (*note Conditional
2387 * Bash includes brace expansion (*note Brace Expansion::.) and tilde
2388 expansion (*note Tilde Expansion::.).
2390 * Bash implements command aliases and the `alias' and `unalias'
2391 builtins (*note Aliases::.).
2393 * Bash provides shell arithmetic, the `((' compound command (*note
2394 Conditional Constructs::.), and arithmetic expansion (*note Shell
2397 * Variables present in the shell's initial environment are
2398 automatically exported to child processes. The Bourne shell does
2399 not normally do this unless the variables are explicitly marked
2400 using the `export' command.
2402 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
2403 expansions to remove leading or trailing substrings from variable
2404 values (*note Shell Parameter Expansion::.).
2406 * The expansion `${#xx}', which returns the length of `${xx}', is
2407 supported (*note Shell Parameter Expansion::.).
2409 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
2410 substring of `var''s value of length LENGTH, beginning at OFFSET,
2411 is present (*note Shell Parameter Expansion::.).
2413 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
2414 PATTERN and replaces it with REPLACEMENT in the value of `var', is
2415 available (*note Shell Parameter Expansion::.).
2417 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
2418 Parameter Expansion::.).
2420 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
2422 * The POSIX `$()' form of command substitution is implemented (*note
2423 Command Substitution::.), and preferred to the Bourne shell's ```'
2424 (which is also implemented for backwards compatibility).
2426 * Bash has process substitution (*note Process Substitution::.).
2428 * Bash automatically assigns variables that provide information
2429 about the current user (`UID', `EUID', and `GROUPS'), the current
2430 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
2431 instance of Bash that is running (`BASH', `BASH_VERSION', and
2432 `BASH_VERSINFO'). *Note Bash Variables::, for details.
2434 * The `IFS' variable is used to split only the results of expansion,
2435 not all words (*note Word Splitting::.). This closes a
2436 longstanding shell security hole.
2438 * Bash implements the full set of POSIX.2 filename expansion
2439 operators, including CHARACTER CLASSES, EQUIVALENCE CLASSES, and
2440 COLLATING SYMBOLS (*note Filename Expansion::.).
2442 * Bash implements extended pattern matching features when the
2443 `extglob' shell option is enabled (*note Pattern Matching::.).
2445 * It is possible to have a variable and a function with the same
2446 name; `sh' does not separate the two name spaces.
2448 * Bash functions are permitted to have local variables using the
2449 `local' builtin, and thus useful recursive functions may be
2452 * Variable assignments preceding commands affect only that command,
2453 even builtins and functions (*note Environment::.). In `sh', all
2454 variable assignments preceding commands are global unless the
2455 command is executed from the file system.
2457 * Bash performs filename expansion on filenames specified as operands
2458 to input and output redirection operators.
2460 * Bash contains the `<>' redirection operator, allowing a file to be
2461 opened for both reading and writing, and the `&>' redirection
2462 operator, for directing standard output and standard error to the
2463 same file (*note Redirections::.).
2465 * The `noclobber' option is available to avoid overwriting existing
2466 files with output redirection (*note The Set Builtin::.). The
2467 `>|' redirection operator may be used to override `noclobber'.
2469 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::.)
2470 each take `-L' and `-P' builtins to switch between logical and
2473 * Bash allows a function to override a builtin with the same name,
2474 and provides access to that builtin's functionality within the
2475 function via the `builtin' and `command' builtins (*note Bash
2478 * The `command' builtin allows selective disabling of functions when
2479 command lookup is performed (*note Bash Builtins::.).
2481 * Individual builtins may be enabled or disabled using the `enable'
2482 builtin (*note Bash Builtins::.).
2484 * The Bash `exec' builtin takes additional options that allow users
2485 to control the contents of the environment passed to the executed
2486 command, and what the zeroth argument to the command is to be
2487 (*note Bourne Shell Builtins::.).
2489 * Shell functions may be exported to children via the environment
2490 using `export -f' (*note Shell Functions::.).
2492 * The Bash `export', `readonly', and `declare' builtins can take a
2493 `-f' option to act on shell functions, a `-p' option to display
2494 variables with various attributes set in a format that can be used
2495 as shell input, a `-n' option to remove various variable
2496 attributes, and `name=value' arguments to set variable attributes
2497 and values simultaneously.
2499 * The Bash `hash' builtin allows a name to be associated with an
2500 arbitrary filename, even when that filename cannot be found by
2501 searching the `$PATH', using `hash -p' (*note Bourne Shell
2504 * Bash includes a `help' builtin for quick reference to shell
2505 facilities (*note Bash Builtins::.).
2507 * The `printf' builtin is available to display formatted output
2508 (*note Bash Builtins::.).
2510 * The Bash `read' builtin (*note Bash Builtins::.) will read a line
2511 ending in `\' with the `-r' option, and will use the `REPLY'
2512 variable as a default if no arguments are supplied. The Bash
2513 `read' builtin also accepts a prompt string with the `-p' option
2514 and will use Readline to obtain the line when given the `-e'
2517 * The `return' builtin may be used to abort execution of scripts
2518 executed with the `.' or `source' builtins (*note Bourne Shell
2521 * Bash includes the `shopt' builtin, for finer control of shell
2522 optional capabilities (*note Bash Builtins::.).
2524 * Bash has much more optional behavior controllable with the `set'
2525 builtin (*note The Set Builtin::.).
2527 * The `test' builtin (*note Bourne Shell Builtins::.) is slightly
2528 different, as it implements the POSIX algorithm, which specifies
2529 the behavior based on the number of arguments.
2531 * The `trap' builtin (*note Bourne Shell Builtins::.) allows a
2532 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
2533 specified with a `DEBUG' trap are executed after every simple
2534 command. The `DEBUG' trap is not inherited by shell functions.
2536 * The Bash `type' builtin is more extensive and gives more
2537 information about the names it finds (*note Bash Builtins::.).
2539 * The Bash `umask' builtin permits a `-p' option to cause the output
2540 to be displayed in the form of a `umask' command that may be
2541 reused as input (*note Bourne Shell Builtins::.).
2543 * Bash implements a `csh'-like directory stack, and provides the
2544 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
2545 Directory Stack::.). Bash also makes the directory stack visible
2546 as the value of the `DIRSTACK' shell variable.
2548 * Bash interprets special backslash-escaped characters in the prompt
2549 strings when interactive (*note Printing a Prompt::.).
2551 * The Bash restricted mode is more useful (*note The Restricted
2552 Shell::.); the SVR4.2 shell restricted mode is too limited.
2554 * The `disown' builtin can remove a job from the internal shell job
2555 table (*note Job Control Builtins::.) or suppress the sending of
2556 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
2558 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
2559 `priv') not present in Bash.
2561 * Bash does not have the `stop' or `newgrp' builtins.
2563 * Bash does not use the `SHACCT' variable or perform shell
2566 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
2568 More features unique to Bash may be found in *Note Bash Features::.
2570 Implementation Differences From The SVR4.2 Shell
2571 ------------------------------------------------
2573 Since Bash is a completely new implementation, it does not suffer
2574 from many of the limitations of the SVR4.2 shell. For instance:
2576 * Bash does not fork a subshell when redirecting into or out of a
2577 shell control structure such as an `if' or `while' statement.
2579 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
2580 silently insert a needed closing quote at `EOF' under certain
2581 circumstances. This can be the cause of some hard-to-find errors.
2583 * The SVR4.2 shell uses a baroque memory management scheme based on
2584 trapping `SIGSEGV'. If the shell is started from a process with
2585 `SIGSEGV' blocked (e.g., by using the `system()' C library
2586 function call), it misbehaves badly.
2588 * In a questionable attempt at security, the SVR4.2 shell, when
2589 invoked without the `-p' option, will alter its real and effective
2590 UID and GID if they are less than some magic threshold value,
2591 commonly 100. This can lead to unexpected results.
2593 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
2594 `SIGALRM', or `SIGCHLD'.
2596 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
2597 `PS1', or `PS2' variables to be unset.
2599 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
2601 * Bash allows multiple option arguments when it is invoked (`-x -v');
2602 the SVR4.2 shell allows only one option argument (`-xv'). In
2603 fact, some versions of the shell dump core if the second argument
2606 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
2607 script only if one of the POSIX.2 special builtins fails, and only
2608 for certain failures, as enumerated in the POSIX.2 standard.
2610 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
2611 turns on job control).
2614 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Bourne Shell Features, Up: Top
2619 This section describes features unique to Bash.
2623 * Invoking Bash:: Command line options that you can give
2625 * Bash Startup Files:: When and how Bash executes scripts.
2626 * Is This Shell Interactive?:: Determining the state of a running Bash.
2627 * Bash Builtins:: Table of builtins specific to Bash.
2628 * The Set Builtin:: This builtin is so overloaded it
2629 deserves its own section.
2630 * Bash Conditional Expressions:: Primitives used in composing expressions for
2632 * Bash Variables:: List of variables that exist in Bash.
2633 * Shell Arithmetic:: Arithmetic on shell variables.
2634 * Aliases:: Substituting one command for another.
2635 * Arrays:: Array Variables.
2636 * The Directory Stack:: History of visited directories.
2637 * Printing a Prompt:: Controlling the PS1 string.
2638 * The Restricted Shell:: A more controlled mode of shell execution.
2639 * Bash POSIX Mode:: Making Bash behave more closely to what
2640 the POSIX standard specifies.
2643 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
2648 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...]
2649 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] -c STRING [ARGUMENT ...]
2650 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...]
2652 In addition to the single-character shell command-line options
2653 (*note The Set Builtin::.), there are several multi-character options
2654 that you can use. These options must appear on the command line before
2655 the single-character options in order for them to be recognized.
2658 Equivalent to `-D', but the output is in the GNU `gettext' PO
2659 (portable object) file format.
2665 Display a usage message on standard output and exit sucessfully.
2668 Make this shell act as if it were directly invoked by login. This
2669 is equivalent to `exec -l bash' but can be issued from another
2670 shell, such as `csh'. `exec bash --login' will replace the
2671 current shell with a Bash login shell.
2674 Do not use the GNU Readline library (*note Command Line Editing::.)
2675 to read interactive command lines.
2678 Don't load the system-wide startup file `/etc/profile' or any of
2679 the personal initialization files `~/.bash_profile',
2680 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
2684 Don't read the `~/.bashrc' initialization file in an interactive
2685 shell. This is on by default if the shell is invoked as `sh'.
2688 Change the behavior of Bash where the default operation differs
2689 from the POSIX 1003.2 standard to match the standard. This is
2690 intended to make Bash behave as a strict superset of that
2691 standard. *Note Bash POSIX Mode::, for a description of the Bash
2695 Execute commands from FILENAME (instead of `~/.bashrc') in an
2699 Make the shell a restricted shell (*note The Restricted Shell::.).
2705 Show version information for this instance of Bash on the standard
2706 output and exit successfully.
2708 There are several single-character options that may be supplied at
2709 invocation which are not available with the `set' builtin.
2712 Read and execute commands from STRING after processing the
2713 options, then exit. Any remaining arguments are assigned to the
2714 positional parameters, starting with `$0'.
2717 Force the shell to run interactively.
2720 Make the shell a restricted shell (*note The Restricted Shell::.).
2723 If this option is present, or if no arguments remain after option
2724 processing, then commands are read from the standard input. This
2725 option allows the positional parameters to be set when invoking an
2729 A list of all double-quoted strings preceded by `$' is printed on
2730 the standard ouput. These are the strings that are subject to
2731 language translation when the current locale is not `C' or `POSIX'
2732 (*note Locale Translation::.). This implies the `-n' option; no
2733 commands will be executed.
2736 A `--' signals the end of options and disables further option
2737 processing. Any arguments after the `--' are treated as filenames
2740 An *interactive* shell is one whose input and output are both
2741 connected to terminals (as determined by `isatty(3)'), or one started
2742 with the `-i' option.
2744 If arguments remain after option processing, and neither the `-c'
2745 nor the `-s' option has been supplied, the first argument is assumed to
2746 be the name of a file containing shell commands (*note Shell
2747 Scripts::.). When Bash is invoked in this fashion, `$0' is set to the
2748 name of the file, and the positional parameters are set to the
2749 remaining arguments. Bash reads and executes commands from this file,
2750 then exits. Bash's exit status is the exit status of the last command
2751 executed in the script. If no commands are executed, the exit status
2755 File: bashref.info, Node: Bash Startup Files, Next: Is This Shell Interactive?, Prev: Invoking Bash, Up: Bash Features
2760 This section describs how Bash executes its startup files. If any
2761 of the files exist but cannot be read, Bash reports an error. Tildes
2762 are expanded in file names as described above under Tilde Expansion
2763 (*note Tilde Expansion::.).
2765 When Bash is invoked as an interactive login shell, it first reads
2766 and executes commands from the file `/etc/profile', if that file exists.
2767 After reading that file, it looks for `~/.bash_profile',
2768 `~/.bash_login', and `~/.profile', in that order, and reads and
2769 executes commands from the first one that exists and is readable. The
2770 `--noprofile' option may be used when the shell is started to inhibit
2773 When a login shell exits, Bash reads and executes commands from the
2774 file `~/.bash_logout', if it exists.
2776 When an interactive shell that is not a login shell is started, Bash
2777 reads and executes commands from `~/.bashrc', if that file exists.
2778 This may be inhibited by using the `--norc' option. The `--rcfile
2779 FILE' option will force Bash to read and execute commands from FILE
2780 instead of `~/.bashrc'.
2782 So, typically, your `~/.bash_profile' contains the line
2783 `if [ -f `~/.bashrc' ]; then . `~/.bashrc'; fi'
2785 after (or before) any login-specific initializations.
2787 When Bash is started non-interactively, to run a shell script, for
2788 example, it looks for the variable `BASH_ENV' in the environment,
2789 expands its value if it appears there, and uses the expanded value as
2790 the name of a file to read and execute. Bash behaves as if the
2791 following command were executed:
2792 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
2794 but the value of the `PATH' variable is not used to search for the file
2797 If Bash is invoked with the name `sh', it tries to mimic the startup
2798 behavior of historical versions of `sh' as closely as possible, while
2799 conforming to the POSIX standard as well.
2801 When invoked as an interactive login shell, it first attempts to read
2802 and execute commands from `/etc/profile' and `~/.profile', in that
2803 order. The `--noprofile' option may be used to inhibit this behavior.
2804 When invoked as an interactive shell with the name `sh', Bash looks for
2805 the variable `ENV', expands its value if it is defined, and uses the
2806 expanded value as the name of a file to read and execute. Since a
2807 shell invoked as `sh' does not attempt to read and execute commands
2808 from any other startup files, the `--rcfile' option has no effect. A
2809 non-interactive shell invoked with the name `sh' does not attempt to
2810 read any startup files.
2812 When invoked as `sh', Bash enters POSIX mode after the startup files
2815 When Bash is started in POSIX mode, as with the `--posix' command
2816 line option, it follows the POSIX standard for startup files. In this
2817 mode, interactive shells expand the `ENV' variable and commands are
2818 read and executed from the file whose name is the expanded value. No
2819 other startup files are read.
2821 Bash attempts to determine when it is being run by the remote shell
2822 daemon, usually `rshd'. If Bash determines it is being run by rshd, it
2823 reads and executes commands from `~/.bashrc', if that file exists and
2824 is readable. It will not do this if invoked as `sh'. The `--norc'
2825 option may be used to inhibit this behavior, and the `--rcfile' option
2826 may be used to force another file to be read, but `rshd' does not
2827 generally invoke the shell with those options or allow them to be
2831 File: bashref.info, Node: Is This Shell Interactive?, Next: Bash Builtins, Prev: Bash Startup Files, Up: Bash Features
2833 Is This Shell Interactive?
2834 ==========================
2836 As defined in *Note Invoking Bash::, an interactive shell is one
2837 whose input and output are both connected to terminals (as determined
2838 by `isatty(3)'), or one started with the `-i' option.
2840 To determine within a startup script whether Bash is running
2841 interactively or not, examine the variable `$PS1'; it is unset in
2842 non-interactive shells, and set in interactive shells. Thus:
2844 if [ -z "$PS1" ]; then
2845 echo This shell is not interactive
2847 echo This shell is interactive
2850 Alternatively, startup scripts may test the value of the `-' special
2851 parameter. It contains `i' when the shell is interactive. For example:
2854 *i*) echo This shell is interactive ;;
2855 *) echo This shell is not interactive ;;
2859 File: bashref.info, Node: Bash Builtins, Next: The Set Builtin, Prev: Is This Shell Interactive?, Up: Bash Features
2861 Bash Builtin Commands
2862 =====================
2864 This section describes builtin commands which are unique to or have
2865 been extended in Bash.
2868 bind [-m KEYMAP] [-lpsvPSV]
2869 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2870 bind [-m KEYMAP] -f FILENAME
2871 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
2873 Display current Readline (*note Command Line Editing::.) key and
2874 function bindings, or bind a key sequence to a Readline function
2875 or macro. The binding syntax accepted is identical to that of
2876 `.inputrc' (*note Readline Init File::.), but each binding must be
2877 passed as a separate argument: e.g.,
2878 `"\C-x\C-r":re-read-init-file'. Options, if supplied, have the
2882 Use KEYMAP as the keymap to be affected by the subsequent
2883 bindings. Acceptable KEYMAP names are `emacs',
2884 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
2885 `vi-command', and `vi-insert'. `vi' is equivalent to
2886 `vi-command'; `emacs' is equivalent to `emacs-standard'.
2889 List the names of all Readline functions.
2892 Display Readline function names and bindings in such a way
2893 that they can be re-read.
2896 List current Readline function names and bindings.
2899 Display Readline variable names and values in such a way that
2900 they can be re-read.
2903 List current Readline variable names and values.
2906 Display Readline key sequences bound to macros and the
2907 strings they output in such a way that they can be re-read.
2910 Display Readline key sequences bound to macros and the
2911 strings they output.
2914 Read key bindings from FILENAME.
2917 Query about which keys invoke the named FUNCTION.
2920 Unbind all keys bound to the named FUNCTION.
2923 Remove any current binding for KEYSEQ.
2925 The return status is zero unless an invalid option is supplied or
2929 builtin [SHELL-BUILTIN [ARGS]]
2930 Run a shell builtin, passing it ARGS, and return its exit status.
2931 This is useful when defining a shell function with the same name
2932 as a shell builtin, retaining the functionality of the builtin
2933 within the function. The return status is non-zero if
2934 SHELL-BUILTIN is not a shell builtin command.
2937 command [-pVv] COMMAND [ARGUMENTS ...]
2938 Runs COMMAND with ARGUMENTS ignoring any shell function named
2939 COMMAND. Only shell builtin commands or commands found by
2940 searching the `PATH' are executed. If there is a shell function
2941 named `ls', running `command ls' within the function will execute
2942 the external command `ls' instead of calling the function
2943 recursively. The `-p' option means to use a default value for
2944 `$PATH' that is guaranteed to find all of the standard utilities.
2945 The return status in this case is 127 if COMMAND cannot be found
2946 or an error occurred, and the exit status of COMMAND otherwise.
2948 If either the `-V' or `-v' option is supplied, a description of
2949 COMMAND is printed. The `-v' option causes a single word
2950 indicating the command or file name used to invoke COMMAND to be
2951 displayed; the `-V' option produces a more verbose description.
2952 In this case, the return status is zero if COMMAND is found, and
2956 declare [-afFrxi] [-p] [NAME[=VALUE]]
2958 Declare variables and give them attributes. If no NAMEs are
2959 given, then display the values of variables instead.
2961 The `-p' option will display the attributes and values of each
2962 NAME. When `-p' is used, additional options are ignored. The
2963 `-F' option inhibits the display of function definitions; only the
2964 function name and attributes are printed. `-F' implies `-f'. The
2965 following options can be used to restrict output to variables with
2966 the specified attributes or to give variables attributes:
2969 Each NAME is an array variable (*note Arrays::.).
2972 Use function names only.
2975 The variable is to be treated as an integer; arithmetic
2976 evaluation (*note Shell Arithmetic::.) is performed when the
2977 variable is assigned a value.
2980 Make NAMEs readonly. These names cannot then be assigned
2981 values by subsequent assignment statements or unset.
2984 Mark each NAME for export to subsequent commands via the
2987 Using `+' instead of `-' turns off the attribute instead. When
2988 used in a function, `declare' makes each NAME local, as with the
2991 The return status is zero unless an invalid option is encountered,
2992 an attempt is made to define a function using `-f foo=bar', an
2993 attempt is made to assign a value to a readonly variable, an
2994 attempt is made to assign a value to an array variable without
2995 using the compound assignment syntax (*note Arrays::.), one of the
2996 NAMES is not a valid shell variable name, an attempt is made to
2997 turn off readonly status for a readonly variable, an attempt is
2998 made to turn off array status for an array variable, or an attempt
2999 is made to display a non-existent function with `-f'.
3002 echo [-neE] [ARG ...]
3003 Output the ARGs, separated by spaces, terminated with a newline.
3004 The return status is always 0. If `-n' is specified, the trailing
3005 newline is suppressed. If the `-e' option is given,
3006 interpretation of the following backslash-escaped characters is
3007 enabled. The `-E' option disables the interpretation of these
3008 escape characters, even on systems where they are interpreted by
3009 default. `echo' interprets the following escape sequences:
3017 suppress trailing newline
3041 the character whose `ASCII' code is the octal value NNN (one
3045 the character whose `ASCII' code is the hexadecimal value NNN
3046 (one to three digits)
3049 enable [-n] [-p] [-f FILENAME] [-ads] [NAME ...]
3050 Enable and disable builtin shell commands. Disabling a builtin
3051 allows a disk command which has the same name as a shell builtin
3052 to be executed with specifying a full pathname, even though the
3053 shell normally searches for builtins before disk commands. If
3054 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3055 enabled. For example, to use the `test' binary found via `$PATH'
3056 instead of the shell builtin version, type `enable -n test'.
3058 If the `-p' option is supplied, or no NAME arguments appear, a
3059 list of shell builtins is printed. With no other arguments, the
3060 list consists of all enabled shell builtins. The `-a' option
3061 means to list each builtin with an indication of whether or not it
3064 The `-f' option means to load the new builtin command NAME from
3065 shared object FILENAME, on systems that support dynamic loading.
3066 The `-d' option will delete a builtin loaded with `-f'.
3068 If there are no options, a list of the shell builtins is displayed.
3069 The `-s' option restricts `enable' to the POSIX special builtins.
3070 If `-s' is used with `-f', the new builtin becomes a special
3073 The return status is zero unless a NAME is not a shell builtin or
3074 there is an error loading a new builtin from a shared object.
3078 Display helpful information about builtin commands. If PATTERN is
3079 specified, `help' gives detailed help on all commands matching
3080 PATTERN, otherwise a list of the builtins is printed. The return
3081 status is zero unless no command matches PATTERN.
3084 let EXPRESSION [EXPRESSION]
3085 The `let' builtin allows arithmetic to be performed on shell
3086 variables. Each EXPRESSION is evaluated according to the rules
3087 given below in *Note Shell Arithmetic::. If the last EXPRESSION
3088 evaluates to 0, `let' returns 1; otherwise 0 is returned.
3092 For each argument, a local variable named NAME is created, and
3093 assigned VALUE. `local' can only be used within a function; it
3094 makes the variable NAME have a visible scope restricted to that
3095 function and its children. The return status is zero unless
3096 `local' is used outside a function or an invalid NAME is supplied.
3100 Exit a login shell, returning a status of N to the shell's parent.
3103 `printf' FORMAT [ARGUMENTS]
3104 Write the formatted ARGUMENTS to the standard output under the
3105 control of the FORMAT. The FORMAT is a character string which
3106 contains three types of objects: plain characters, which are
3107 simply copied to standard output, character escape sequences,
3108 which are converted and copied to the standard output, and format
3109 specifications, each of which causes printing of the next
3110 successive ARGUMENT. In addition to the standard `printf(1)'
3111 formats, `%b' causes `printf' to expand backslash escape sequences
3112 in the corresponding ARGUMENT, and `%q' causes `printf' to output
3113 the corresponding ARGUMENT in a format that can be reused as shell
3116 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3117 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3118 format specifications behave as if a zero value or null string, as
3119 appropriate, had been supplied.
3122 read [-a ANAME] [-p PROMPT] [-er] [NAME ...]
3123 One line is read from the standard input, and the first word is
3124 assigned to the first NAME, the second word to the second NAME,
3125 and so on, with leftover words and their intervening separators
3126 assigned to the last NAME. If there are fewer words read from the
3127 standard input than names, the remaining names are assigned empty
3128 values. The characters in the value of the `IFS' variable are
3129 used to split the line into words. If no names are supplied, the
3130 line read is assigned to the variable `REPLY'. The return code is
3131 zero, unless end-of-file is encountered. Options, if supplied,
3132 have the following meanings:
3135 If this option is given, a backslash-newline pair is not
3136 ignored, and the backslash is considered to be part of the
3140 Display PROMPT, without a trailing newline, before attempting
3141 to read any input. The prompt is displayed only if input is
3142 coming from a terminal.
3145 The words are assigned to sequential indices of the array
3146 variable ANAME, starting at 0. All elements are removed from
3147 ANAME before the assignment. Other NAME arguments are
3151 Readline (*note Command Line Editing::.) is used to obtain
3155 shopt [-pqsu] [-o] [OPTNAME ...]
3156 Toggle the values of variables controlling optional shell behavior.
3157 With no options, or with the `-p' option, a list of all settable
3158 options is displayed, with an indication of whether or not each is
3159 set. The `-p' option causes output to be displayed in a form that
3160 may be reused as input. Other options have the following meanings:
3163 Enable (set) each OPTNAME.
3166 Disable (unset) each OPTNAME.
3169 Suppresses normal output; the return status indicates whether
3170 the OPTNAME is set or unset. If multiple OPTNAME arguments
3171 are given with `-q', the return status is zero if all
3172 OPTNAMES are enabled; non-zero otherwise.
3175 Restricts the values of OPTNAME to be those defined for the
3176 `-o' option to the `set' builtin (*note The Set Builtin::.).
3178 If either `-s' or `-u' is used with no OPTNAME arguments, the
3179 display is limited to those options which are set or unset,
3182 Unless otherwise noted, the `shopt' options are disabled (off) by
3185 The return status when listing options is zero if all OPTNAMES are
3186 enabled, non-zero otherwise. When setting or unsetting options,
3187 the return status is zero unless an OPTNAME is not a valid shell
3190 The list of `shopt' options is:
3192 If this is set, an argument to the `cd' builtin command that
3193 is not a directory is assumed to be the name of a variable
3194 whose value is the directory to change to.
3197 If set, minor errors in the spelling of a directory component
3198 in a `cd' command will be corrected. The errors checked for
3199 are transposed characters, a missing character, and a
3200 character too many. If a correction is found, the corrected
3201 path is printed, and the command proceeds. This option is
3202 only used by interactive shells.
3205 If this is set, Bash checks that a command found in the hash
3206 table exists before trying to execute it. If a hashed
3207 command no longer exists, a normal path search is performed.
3210 If set, Bash checks the window size after each command and,
3211 if necessary, updates the values of `LINES' and `COLUMNS'.
3214 If set, Bash attempts to save all lines of a multiple-line
3215 command in the same history entry. This allows easy
3216 re-editing of multi-line commands.
3219 If set, Bash includes filenames beginning with a `.' in the
3220 results of filename expansion.
3223 If this is set, a non-interactive shell will not exit if it
3224 cannot execute the file specified as an argument to the `exec'
3225 builtin command. An interactive shell does not exit if `exec'
3229 If set, aliases are expanded as described below< under Aliases
3230 (*note Aliases::.). This option is enabled by default for
3234 If set, the extended pattern matching features described above
3235 (*note Pattern Matching::.) are enabled.
3238 If set, the history list is appended to the file named by the
3239 value of the `HISTFILE' variable when the shell exits, rather
3240 than overwriting the file.
3243 If set, and Readline is being used, a user is given the
3244 opportunity to re-edit a failed history substitution.
3247 If set, and Readline is being used, the results of history
3248 substitution are not immediately passed to the shell parser.
3249 Instead, the resulting line is loaded into the Readline
3250 editing buffer, allowing further modification.
3253 If set, and Readline is being used, Bash will attempt to
3254 perform hostname completion when a word containing a `@' is
3255 being completed (*note Commands For Completion::.). This
3256 option is enabled by default.
3259 If set, Bash will send `SIGHUP' to all jobs when an
3260 interactive login shell exits (*note Signals::.).
3262 `interactive_comments'
3263 Allow a word beginning with `#' to cause that word and all
3264 remaining characters on that line to be ignored in an
3265 interactive shell. This option is enabled by default.
3268 If enabled, and the `cmdhist' option is enabled, multi-line
3269 commands are saved to the history with embedded newlines
3270 rather than using semicolon separators where possible.
3273 If set, and a file that Bash is checking for mail has been
3274 accessed since the last time it was checked, the message
3275 `"The mail in MAILFILE has been read"' is displayed.
3278 If set, Bash matches filenames in a case-insensitive fashion
3279 when performing filename expansion.
3282 If set, Bash allows filename patterns which match no files to
3283 expand to a null string, rather than themselves.
3286 If set, prompt strings undergo variable and parameter
3287 expansion after being expanded (*note Printing a Prompt::.).
3288 This option is enabled by default.
3291 If this is set, the `shift' builtin prints an error message
3292 when the shift count exceeds the number of positional
3296 If set, the `source' builtin uses the value of `PATH' to find
3297 the directory containing the file supplied as an argument.
3298 This option is enabled by default.
3300 The return status when listing options is zero if all OPTNAMES are
3301 enabled, non-zero otherwise. When setting or unsetting options,
3302 the return status is zero unless an OPTNAME is not a valid shell
3307 A synonym for `.' (*note Bourne Shell Builtins::.).
3310 type [-atp] [NAME ...]
3311 For each NAME, indicate how it would be interpreted if used as a
3314 If the `-t' option is used, `type' prints a single word which is
3315 one of `alias', `function', `builtin', `file' or `keyword', if
3316 NAME is an alias, shell function, shell builtin, disk file, or
3317 shell reserved word, respectively. If the NAME is not found, then
3318 nothing is printed, and `type' returns a failure status.
3320 If the `-p' option is used, `type' either returns the name of the
3321 disk file that would be executed, or nothing if `-t' would not
3324 If the `-a' option is used, `type' returns all of the places that
3325 contain an executable named FILE. This includes aliases and
3326 functions, if and only if the `-p' option is not also used.
3328 The return status is zero if any of the NAMES are found, non-zero
3332 typeset [-afFrxi] [-p] [NAME[=VALUE]]
3333 The `typeset' command is supplied for compatibility with the Korn
3334 shell; however, it has been deprecated in favor of the `declare'
3338 ulimit [-acdflmnpstuvSH] [LIMIT]
3339 `ulimit' provides control over the resources available to processes
3340 started by the shell, on systems that allow such control. If an
3341 option is given, it is interpreted as follows:
3343 Change and report the soft limit associated with a resource.
3346 Change and report the hard limit associated with a resource.
3349 All current limits are reported.
3352 The maximum size of core files created.
3355 The maximum size of a process's data segment.
3358 The maximum size of files created by the shell.
3361 The maximum size that may be locked into memory.
3364 The maximum resident set size.
3367 The maximum number of open file descriptors.
3370 The pipe buffer size.
3373 The maximum stack size.
3376 The maximum amount of cpu time in seconds.
3379 The maximum number of processes available to a single user.
3382 The maximum amount of virtual memory available to the process.
3384 If LIMIT is given, it is the new value of the specified resource.
3385 Otherwise, the current value of the soft limit for the specified
3386 resource is printed, unless the `-H' option is supplied. When
3387 setting new limits, if neither `-H' nor `-S' is supplied, both the
3388 hard and soft limits are set. If no option is given, then `-f' is
3389 assumed. Values are in 1024-byte increments, except for `-t',
3390 which is in seconds, `-p', which is in units of 512-byte blocks,
3391 and `-n' and `-u', which are unscaled values.
3393 The return status is zero unless an invalid option is supplied, a
3394 non-numeric argument other than `unlimited' is supplied as a
3395 LIMIT, or an error occurs while setting a new limit.
3398 File: bashref.info, Node: The Set Builtin, Next: Bash Conditional Expressions, Prev: Bash Builtins, Up: Bash Features
3403 This builtin is so complicated that it deserves its own section.
3406 set [--abefhkmnptuvxBCHP] [-o OPTION] [ARGUMENT ...]
3408 If no options or arguments are supplied, `set' displays the names
3409 and values of all shell variables and functions, sorted according
3410 to the current locale, in a format that may be reused as input.
3412 When options are supplied, they set or unset shell attributes.
3413 Options, if specified, have the following meanings:
3416 Mark variables which are modified or created for export.
3419 Cause the status of terminated background jobs to be reported
3420 immediately, rather than before printing the next primary
3424 Exit immediately if a simple command (*note Simple
3425 Commands::.) exits with a non-zero status, unless the command
3426 that fails is part of an `until' or `while' loop, part of an
3427 `if' statement, part of a `&&' or `||' list, or if the
3428 command's return status is being inverted using `!'.
3431 Disable file name generation (globbing).
3434 Locate and remember (hash) commands as they are looked up for
3435 execution. This option is enabled by default.
3438 All arguments in the form of assignment statements are placed
3439 in the environment for a command, not just those that precede
3443 Job control is enabled (*note Job Control::.).
3446 Read commands but do not execute them; this may be used to
3447 check a script for syntax errors. This option is ignored by
3451 Set the option corresponding to OPTION-NAME:
3460 Use an `emacs'-style line editing interface (*note
3461 Command Line Editing::.).
3473 Enable command history, as described in *Note Bash
3474 History Facilities::. This option is on by default in
3478 An interactive shell will not exit upon reading EOF.
3508 Change the behavior of Bash where the default operation
3509 differs from the POSIX 1003.2 standard to match the
3510 standard (*note Bash POSIX Mode::.). This is intended
3511 to make Bash behave as a strict superset of that
3521 Use a `vi'-style line editing interface.
3527 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3528 `$ENV' files are not processed, shell functions are not
3529 inherited from the environment, and the `SHELLOPTS' variable,
3530 if it appears in the environment, is ignored. This is
3531 enabled automatically on startup if the effective user
3532 (group) id is not equal to the real user (group) id. Turning
3533 this option off causes the effective user and group ids to be
3534 set to the real user and group ids.
3537 Exit after reading and executing one command.
3540 Treat unset variables as an error when performing parameter
3541 expansion. An error message will be written to the standard
3542 error, and a non-interactive shell will exit.
3545 Print shell input lines as they are read.
3548 Print a trace of simple commands and their arguments after
3549 they are expanded and before they are executed.
3552 The shell will perform brace expansion (*note Brace
3553 Expansion::.). This option is on by default.
3556 Prevent output redirection using `>', `>&', and `<>' from
3557 overwriting existing files.
3560 Enable `!' style history substitution (*note History
3561 Interaction::.). This option is on by default for
3565 If set, do not follow symbolic links when performing commands
3566 such as `cd' which change the current directory. The
3567 physical directory is used instead. By default, Bash follows
3568 the logical chain of directories when performing commands
3569 which change the current directory.
3571 For example, if `/usr/sys' is a symbolic link to
3572 `/usr/local/sys' then:
3573 $ cd /usr/sys; echo $PWD
3578 If `set -P' is on, then:
3579 $ cd /usr/sys; echo $PWD
3585 If no arguments follow this option, then the positional
3586 parameters are unset. Otherwise, the positional parameters
3587 are set to the ARGUMENTS, even if some of them begin with a
3591 Signal the end of options, cause all remaining ARGUMENTS to
3592 be assigned to the positional parameters. The `-x' and `-v'
3593 options are turned off. If there are no arguments, the
3594 positional parameters remain unchanged.
3596 Using `+' rather than `-' causes these options to be turned off.
3597 The options can also be used upon invocation of the shell. The
3598 current set of options may be found in `$-'.
3600 The remaining N ARGUMENTS are positional parameters and are
3601 assigned, in order, to `$1', `$2', ... `$N'. The special
3602 parameter `#' is set to N.
3604 The return status is always zero unless an invalid option is
3608 File: bashref.info, Node: Bash Conditional Expressions, Next: Bash Variables, Prev: The Set Builtin, Up: Bash Features
3610 Bash Conditional Expressions
3611 ============================
3613 Conditional expressions are used by the `[[' compound command and
3614 the `test' and `[' builtin commands.
3616 Expressions may be unary or binary. Unary expressions are often
3617 used to examine the status of a file. There are string operators and
3618 numeric comparison operators as well. If any FILE argument to one of
3619 the primaries is of the form `/dev/fd/N', then file descriptor N is
3623 True if FILE exists.
3626 True if FILE exists and is a block special file.
3629 True if FILE exists and is a character special file.
3632 True if FILE exists and is a directory.
3635 True if FILE exists.
3638 True if FILE exists and is a regular file.
3641 True if FILE exists and its set-group-id bit is set.
3644 True if FILE exists and its "sticky" bit is set.
3647 True if FILE exists and is a named pipe (FIFO).
3650 True if FILE exists and is readable.
3653 True if FILE exists and has a size greater than zero.
3656 True if file descriptor FD is open and refers to a terminal.
3659 True if FILE exists and its set-user-id bit is set.
3662 True if FILE exists and is writable.
3665 True if FILE exists and is executable.
3668 True if FILE exists and is owned by the effective user id.
3671 True if FILE exists and is owned by the effective group id.
3674 True if FILE exists and is a symbolic link.
3677 True if FILE exists and is a socket.
3680 True if FILE exists and has been modified since it was last read.
3683 True if FILE1 is newer (according to modification date) than FILE2.
3686 True if FILE1 is older than FILE2.
3689 True if FILE1 and FILE2 have the same device and inode numbers.
3692 True if shell option OPTNAME is enabled. The list of options
3693 appears in the description of the `-o' option to the `set' builtin
3694 (*note The Set Builtin::.).
3697 True if the length of STRING is zero.
3701 True if the length of STRING is non-zero.
3703 `STRING1 == STRING2'
3704 True if the strings are equal. `=' may be used in place of `=='.
3706 `STRING1 != STRING2'
3707 True if the strings are not equal.
3710 True if STRING1 sorts before STRING2 lexicographically in the
3714 True if STRING1 sorts after STRING2 lexicographically in the
3718 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
3719 arithmetic binary operators return true if ARG1 is equal to, not
3720 equal to, less than, less than or equal to, greater than, or
3721 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
3722 positive or negative integers.
3725 File: bashref.info, Node: Bash Variables, Next: Shell Arithmetic, Prev: Bash Conditional Expressions, Up: Bash Features
3730 These variables are set or used by Bash, but other shells do not
3731 normally treat them specially.
3734 The full pathname used to execute the current instance of Bash.
3737 If this variable is set when Bash is invoked to execute a shell
3738 script, its value is expanded and used as the name of a startup
3739 file to read before executing the script. *Note Bash Startup
3743 The version number of the current instance of Bash.
3746 A readonly array variable whose members hold version information
3747 for this instance of Bash. The values assigned to the array
3748 members are as follows:
3751 The major version number (the RELEASE).
3754 The minor version number (the VERSION).
3763 The release status (e.g., BETA1).
3766 The value of `MACHTYPE'.
3769 An array variable (*note Arrays::.) containing the current
3770 contents of the directory stack. Directories appear in the stack
3771 in the order they are displayed by the `dirs' builtin. Assigning
3772 to members of this array variable may be used to modify
3773 directories already in the stack, but the `pushd' and `popd'
3774 builtins must be used to add and remove directories. Assignment
3775 to this variable will not change the current directory. If
3776 `DIRSTACK' is unset, it loses its special properties, even if it
3777 is subsequently reset.
3780 The numeric effective user id of the current user. This variable
3784 The editor used as a default by the `-e' option to the `fc'
3788 A colon-separated list of suffixes to ignore when performing
3789 filename completion. A file name whose suffix matches one of the
3790 entries in `FIGNORE' is excluded from the list of matched file
3791 names. A sample value is `.o:~'
3794 A colon-separated list of patterns defining the set of filenames to
3795 be ignored by filename expansion. If a filename matched by a
3796 filename expansion pattern also matches one of the patterns in
3797 `GLOBIGNORE', it is removed from the list of matches.
3800 An array variable containing the list of groups of which the
3801 current user is a member. This variable is readonly.
3804 Up to three characters which control history expansion, quick
3805 substitution, and tokenization (*note History Interaction::.).
3806 The first character is the "history-expansion-char", that is, the
3807 character which signifies the start of a history expansion,
3808 normally `!'. The second character is the character which
3809 signifies `quick substitution' when seen as the first character on
3810 a line, normally `^'. The optional third character is the
3811 character which indicates that the remainder of the line is a
3812 comment when found as the first character of a word, usually `#'.
3813 The history comment character causes history substitution to be
3814 skipped for the remaining words on the line. It does not
3815 necessarily cause the shell parser to treat the rest of the line
3819 The history number, or index in the history list, of the current
3820 command. If `HISTCMD' is unset, it loses its special properties,
3821 even if it is subsequently reset.
3824 Set to a value of `ignorespace', it means don't enter lines which
3825 begin with a space or tab into the history list. Set to a value
3826 of `ignoredups', it means don't enter lines which match the last
3827 entered line. A value of `ignoreboth' combines the two options.
3828 Unset, or set to any other value than those above, means to save
3829 all lines on the history list. The second and subsequent lines of
3830 a multi-line compound command are not tested, and are added to the
3831 history regardless of the value of `HISTCONTROL'.
3834 A colon-separated list of patterns used to decide which command
3835 lines should be saved on the history list. Each pattern is
3836 anchored at the beginning of the line and must fully specify the
3837 line (no implicit `*' is appended). Each pattern is tested
3838 against the line after the checks specified by `HISTCONTROL' are
3839 applied. In addition to the normal shell pattern matching
3840 characters, `&' matches the previous history line. `&' may be
3841 escaped using a backslash. The backslash is removed before
3842 attempting a match. The second and subsequent lines of a
3843 multi-line compound command are not tested, and are added to the
3844 history regardless of the value of `HISTIGNORE'.
3846 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
3847 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
3848 identical to `ignorespace'. Combining these two patterns,
3849 separating them with a colon, provides the functionality of
3853 The name of the file to which the command history is saved. The
3854 default is `~/.bash_history'.
3857 The maximum number of commands to remember on the history list.
3858 The default value is 500.
3861 The maximum number of lines contained in the history file. When
3862 this variable is assigned a value, the history file is truncated,
3863 if necessary, to contain no more than that number of lines. The
3864 default value is 500. The history file is also truncated to this
3865 size after writing it when an interactive shell exits.
3868 Contains the name of a file in the same format as `/etc/hosts' that
3869 should be read when the shell needs to complete a hostname. You
3870 can change the file interactively; the next time you attempt to
3871 complete a hostname, Bash will add the contents of the new file to
3872 the already existing database.
3875 The name of the current host.
3878 A string describing the machine Bash is running on.
3881 Controls the action of the shell on receipt of an `EOF' character
3882 as the sole input. If set, the value denotes the number of
3883 consecutive `EOF' characters that can be read as the first
3884 character on an input line before the shell will exit. If the
3885 variable exists but does not have a numeric value (or has no
3886 value) then the default is 10. If the variable does not exist,
3887 then `EOF' signifies the end of input to the shell. This is only
3888 in effect for interactive shells.
3891 The name of the Readline startup file, overriding the default of
3895 Used to determine the locale category for any category not
3896 specifically selected with a variable starting with `LC_'.
3899 This variable overrides the value of `LANG' and any other `LC_'
3900 variable specifying a locale category.
3903 This variable determines the collation order used when sorting the
3904 results of filename expansion, and determines the behavior of
3905 range expressions, equivalence classes, and collating sequences
3906 within filename expansion and pattern matching (*note Filename
3910 This variable determines the interpretation of characters and the
3911 behavior of character classes within filename expansion and pattern
3912 matching (*note Filename Expansion::.).
3915 This variable determines the locale used to translate double-quoted
3916 strings preceded by a `$' (*note Locale Translation::.).
3919 The line number in the script or shell function currently
3923 A string that fully describes the system type on which Bash is
3924 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
3927 How often (in seconds) that the shell should check for mail in the
3928 files specified in the `MAILPATH' or `MAIL' variables.
3931 The previous working directory as set by the `cd' builtin.
3934 If set to the value 1, Bash displays error messages generated by
3935 the `getopts' builtin command.
3938 A string describing the operating system Bash is running on.
3941 An array variable (*note Arrays::.) containing a list of exit
3942 status values from the processes in the most-recently-executed
3943 foreground pipeline (which may contain only a single command).
3946 The process id of the shell's parent process. This variable is
3950 If present, this contains a string which is a command to execute
3951 before the printing of each primary prompt (`$PS1').
3954 The value of this variable is used as the prompt for the `select'
3955 command. If this variable is not set, the `select' command
3959 This is the prompt printed before the command line is echoed when
3960 the `-x' option is set (*note The Set Builtin::.). The first
3961 character of `PS4' is replicated multiple times, as necessary, to
3962 indicate multiple levels of indirection. The default is `+ '.
3965 The current working directory as set by the `cd' builtin.
3968 Each time this parameter is referenced, a random integer between 0
3969 and 32767 is generated. Assigning a value to this variable seeds
3970 the random number generator.
3973 The default variable for the `read' builtin.
3976 This variable expands to the number of seconds since the shell was
3977 started. Assignment to this variable resets the count to the
3978 value assigned, and the expanded value becomes the value assigned
3979 plus the number of seconds since the assignment.
3982 A colon-separated list of enabled shell options. Each word in the
3983 list is a valid argument for the `-o' option to the `set' builtin
3984 command (*note The Set Builtin::.). The options appearing in
3985 `SHELLOPTS' are those reported as `on' by `set -o'. If this
3986 variable is in the environment when Bash starts up, each shell
3987 option in the list will be enabled before reading any startup
3988 files. This variable is readonly.
3991 Incremented by one each time a new instance of Bash is started.
3992 This is intended to be a count of how deeply your Bash shells are
3996 The value of this parameter is used as a format string specifying
3997 how the timing information for pipelines prefixed with the `time'
3998 reserved word should be displayed. The `%' character introduces an
3999 escape sequence that is expanded to a time value or other
4000 information. The escape sequences and their meanings are as
4001 follows; the braces denote optional portions.
4007 The elapsed time in seconds.
4010 The number of CPU seconds spent in user mode.
4013 The number of CPU seconds spent in system mode.
4016 The CPU percentage, computed as (%U + %S) / %R.
4018 The optional P is a digit specifying the precision, the number of
4019 fractional digits after a decimal point. A value of 0 causes no
4020 decimal point or fraction to be output. At most three places
4021 after the decimal point may be specified; values of P greater than
4022 3 are changed to 3. If P is not specified, the value 3 is used.
4024 The optional `l' specifies a longer format, including minutes, of
4025 the form MMmSS.FFs. The value of P determines whether or not the
4026 fraction is included.
4028 If this variable is not set, Bash acts as if it had the value
4029 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4030 If the value is null, no timing information is displayed. A
4031 trailing newline is added when the format string is displayed.
4034 If set to a value greater than zero, the value is interpreted as
4035 the number of seconds to wait for input after issuing the primary
4036 prompt. Bash terminates after that number of seconds if input does
4040 The numeric real user id of the current user. This variable is
4044 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Variables, Up: Bash Features
4049 The shell allows arithmetic expressions to be evaluated, as one of
4050 the shell expansions or by the `let' builtin.
4052 Evaluation is done in long integers with no check for overflow,
4053 though division by 0 is trapped and flagged as an error. The following
4054 list of operators is grouped into levels of equal-precedence operators.
4055 The levels are listed in order of decreasing precedence.
4058 unary minus and plus
4061 logical and bitwise negation
4067 multiplication, division, remainder
4070 addition, subtraction
4073 left and right bitwise shifts
4079 equality and inequality
4085 bitwise exclusive OR
4096 `expr ? expr : expr'
4097 conditional evaluation
4099 `= *= /= %= += -= <<= >>= &= ^= |='
4102 Shell variables are allowed as operands; parameter expansion is
4103 performed before the expression is evaluated. The value of a parameter
4104 is coerced to a long integer within an expression. A shell variable
4105 need not have its integer attribute turned on to be used in an
4108 Constants with a leading 0 are interpreted as octal numbers. A
4109 leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
4110 form [BASE`#']N, where BASE is a decimal number between 2 and 64
4111 representing the arithmetic base, and N is a number in that base. If
4112 BASE is omitted, then base 10 is used. The digits greater than 9 are
4113 represented by the lowercase letters, the uppercase letters, `_', and
4114 `@', in that order. If BASE is less than or equal to 36, lowercase and
4115 uppercase letters may be used interchangably to represent numbers
4118 Operators are evaluated in order of precedence. Sub-expressions in
4119 parentheses are evaluated first and may override the precedence rules
4123 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
4130 * Alias Builtins:: Builtins commands to maniuplate aliases.
4132 Aliases allow a string to be substituted for a word when it is used
4133 as the first word of a simple command. The shell maintains a list of
4134 ALIASES that may be set and unset with the `alias' and `unalias'
4137 The first word of each simple command, if unquoted, is checked to see
4138 if it has an alias. If so, that word is replaced by the text of the
4139 alias. The alias name and the replacement text may contain any valid
4140 shell input, including shell metacharacters, with the exception that
4141 the alias name may not contain `='. The first word of the replacement
4142 text is tested for aliases, but a word that is identical to an alias
4143 being expanded is not expanded a second time. This means that one may
4144 alias `ls' to `"ls -F"', for instance, and Bash does not try to
4145 recursively expand the replacement text. If the last character of the
4146 alias value is a space or tab character, then the next command word
4147 following the alias is also checked for alias expansion.
4149 Aliases are created and listed with the `alias' command, and removed
4150 with the `unalias' command.
4152 There is no mechanism for using arguments in the replacement text,
4153 as in `csh'. If arguments are needed, a shell function should be used
4154 (*note Shell Functions::.).
4156 Aliases are not expanded when the shell is not interactive, unless
4157 the `expand_aliases' shell option is set using `shopt' (*note Bash
4160 The rules concerning the definition and use of aliases are somewhat
4161 confusing. Bash always reads at least one complete line of input
4162 before executing any of the commands on that line. Aliases are
4163 expanded when a command is read, not when it is executed. Therefore, an
4164 alias definition appearing on the same line as another command does not
4165 take effect until the next line of input is read. The commands
4166 following the alias definition on that line are not affected by the new
4167 alias. This behavior is also an issue when functions are executed.
4168 Aliases are expanded when a function definition is read, not when the
4169 function is executed, because a function definition is itself a
4170 compound command. As a consequence, aliases defined in a function are
4171 not available until after that function is executed. To be safe,
4172 always put alias definitions on a separate line, and do not use `alias'
4173 in compound commands.
4175 For almost every purpose, aliases are superseded by shell functions.
4178 File: bashref.info, Node: Alias Builtins, Up: Aliases
4184 alias [`-p'] [NAME[=VALUE] ...]
4186 Without arguments or with the `-p' option, `alias' prints the list
4187 of aliases on the standard output in a form that allows them to be
4188 reused as input. If arguments are supplied, an alias is defined
4189 for each NAME whose VALUE is given. If no VALUE is given, the name
4190 and value of the alias is printed.
4193 unalias [-a] [NAME ... ]
4195 Remove each NAME from the list of aliases. If `-a' is supplied,
4196 all aliases are removed.
4199 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
4204 Bash provides one-dimensional array variables. Any variable may be
4205 used as an array; the `declare' builtin will explicitly declare an
4206 array. There is no maximum limit on the size of an array, nor any
4207 requirement that members be indexed or assigned contiguously. Arrays
4210 An array is created automatically if any variable is assigned to
4212 name[SUBSCRIPT]=VALUE
4214 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
4215 to a number greater than or equal to zero. To explicitly declare an
4220 declare -a NAME[SUBSCRIPT]
4222 is also accepted; the SUBSCRIPT is ignored. Attributes may be
4223 specified for an array variable using the `declare' and `readonly'
4224 builtins. Each attribute applies to all members of an array.
4226 Arrays are assigned to using compound assignments of the form
4227 name=(value1 ... valueN)
4229 where each VALUE is of the form `[[SUBSCRIPT]=]'STRING. If the
4230 optional subscript is supplied, that index is assigned to; otherwise
4231 the index of the element assigned is the last index assigned to by the
4232 statement plus one. Indexing starts at zero. This syntax is also
4233 accepted by the `declare' builtin. Individual array elements may be
4234 assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above.
4236 Any element of an array may be referenced using
4237 `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
4238 with the shell's filename expansion operators. If the SUBSCRIPT is `@'
4239 or `*', the word expands to all members of the array NAME. These
4240 subscripts differ only when the word appears within double quotes. If
4241 the word is double-quoted, `${name[*]}' expands to a single word with
4242 the value of each array member separated by the first character of the
4243 `IFS' variable, and `${name[@]}' expands each element of NAME to a
4244 separate word. When there are no array members, `${name[@]}' expands
4245 to nothing. This is analogous to the expansion of the special
4246 parameters `@' and `*'. `${#name['SUBSCRIPT`]}' expands to the length
4247 of `${name['SUBSCRIPT`]}'. If SUBSCRIPT is `@' or `*', the expansion
4248 is the number of elements in the array. Referencing an array variable
4249 without a subscript is equivalent to referencing element zero.
4251 The `unset' builtin is used to destroy arrays. `unset'
4252 `name[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
4253 `unset' NAME, where NAME is an array, removes the entire array. A
4254 subscript of `*' or `@' also removes the entire array.
4256 The `declare', `local', and `readonly' builtins each accept a `-a'
4257 option to specify an array. The `read' builtin accepts a `-a' option
4258 to assign a list of words read from the standard input to an array, and
4259 can read values from the standard input into individual array elements.
4260 The `set' and `declare' builtins display array values in a way that
4261 allows them to be reused as input.
4264 File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
4269 The directory stack is a list of recently-visited directories. The
4270 `pushd' builtin adds directories to the stack as it changes the current
4271 directory, and the `popd' builtin removes specified directories from
4272 the stack and changes the current directory to the directory removed.
4273 The `dirs' builtin displays the contents of the directory stack.
4275 The contents of the directory stack are also visible as the value of
4276 the `DIRSTACK' shell variable.
4279 dirs [+N | -N] [-clvp]
4280 Display the list of currently remembered directories. Directories
4281 are added to the list with the `pushd' command; the `popd' command
4282 removes directories from the list.
4284 Displays the Nth directory (counting from the left of the
4285 list printed by `dirs' when invoked without options), starting
4289 Displays the Nth directory (counting from the right of the
4290 list printed by `dirs' when invoked without options), starting
4294 Clears the directory stack by deleting all of the elements.
4297 Produces a longer listing; the default listing format uses a
4298 tilde to denote the home directory.
4301 Causes `dirs' to print the directory stack with one entry per
4305 Causes `dirs' to print the directory stack with one entry per
4306 line, prefixing each entry with its index in the stack.
4311 Remove the top entry from the directory stack, and `cd' to the new
4312 top directory. When no arguments are given, `popd' removes the
4313 top directory from the stack and performs a `cd' to the new top
4314 directory. The elements are numbered from 0 starting at the first
4315 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
4318 Removes the Nth directory (counting from the left of the list
4319 printed by `dirs'), starting with zero.
4322 Removes the Nth directory (counting from the right of the
4323 list printed by `dirs'), starting with zero.
4326 Suppresses the normal change of directory when removing
4327 directories from the stack, so that only the stack is
4331 pushd [DIR | +N | -N] [-n]
4333 Save the current directory on the top of the directory stack and
4334 then `cd' to DIR. With no arguments, `pushd' exchanges the top
4338 Brings the Nth directory (counting from the left of the list
4339 printed by `dirs', starting with zero) to the top of the list
4340 by rotating the stack.
4343 Brings the Nth directory (counting from the right of the list
4344 printed by `dirs', starting with zero) to the top of the list
4345 by rotating the stack.
4348 Suppresses the normal change of directory when adding
4349 directories to the stack, so that only the stack is
4353 Makes the current working directory be the top of the stack,
4354 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
4357 File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
4359 Controlling the Prompt
4360 ======================
4362 The value of the variable `PROMPT_COMMAND' is examined just before
4363 Bash prints each primary prompt. If it is set and non-null, then the
4364 value is executed just as if it had been typed on the command line.
4366 In addition, the following table describes the special characters
4367 which can appear in the prompt variables:
4373 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
4376 An escape character.
4379 The hostname, up to the first `.'.
4391 The name of the shell, the basename of `$0' (the portion following
4395 The time, in 24-hour HH:MM:SS format.
4398 The time, in 12-hour HH:MM:SS format.
4401 The time, in 12-hour am/pm format.
4404 The username of the current user.
4407 The version of Bash (e.g., 2.00)
4410 The release of Bash, version + patchlevel (e.g., 2.00.0)
4413 The current working directory.
4416 The basename of `$PWD'.
4419 The history number of this command.
4422 The command number of this command.
4425 If the effective uid is 0, `#', otherwise `$'.
4428 The character whose ASCII code is the octal value NNN.
4434 Begin a sequence of non-printing characters. This could be used to
4435 embed a terminal control sequence into the prompt.
4438 End a sequence of non-printing characters.
4441 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
4443 The Restricted Shell
4444 ====================
4446 If Bash is started with the name `rbash', or the `--restricted'
4447 option is supplied at invocation, the shell becomes restricted. A
4448 restricted shell is used to set up an environment more controlled than
4449 the standard shell. A restricted shell behaves identically to `bash'
4450 with the exception that the following are disallowed:
4451 * Changing directories with the `cd' builtin.
4453 * Setting or unsetting the values of the `SHELL' or `PATH' variables.
4455 * Specifying command names containing slashes.
4457 * Specifying a filename containing a slash as an argument to the `.'
4460 * Importing function definitions from the shell environment at
4463 * Parsing the value of `SHELLOPTS' from the shell environment at
4466 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
4467 redirection operators.
4469 * Using the `exec' builtin to replace the shell with another command.
4471 * Adding or deleting builtin commands with the `-f' and `-d' options
4472 to the `enable' builtin.
4474 * Specifying the `-p' option to the `command' builtin.
4476 * Turning off restricted mode with `set +r' or `set +o restricted'.
4479 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
4484 Starting Bash with the `--posix' command-line option or executing
4485 `set -o posix' while Bash is running will cause Bash to conform more
4486 closely to the POSIX.2 standard by changing the behavior to match that
4487 specified by POSIX.2 in areas where the Bash default differs.
4489 The following list is what's changed when `POSIX mode' is in effect:
4491 1. When a command in the hash table no longer exists, Bash will
4492 re-search `$PATH' to find the new location. This is also
4493 available with `shopt -s checkhash'.
4495 2. The `>&' redirection does not redirect stdout and stderr.
4497 3. The message printed by the job control code and builtins when a job
4498 exits with a non-zero status is `Done(status)'.
4500 4. Reserved words may not be aliased.
4502 5. The POSIX.2 `PS1' and `PS2' expansions of `!' to the history
4503 number and `!!' to `!' are enabled, and parameter expansion is
4504 performed on the values of `PS1' and `PS2' regardless of the
4505 setting of the `promptvars' option.
4507 6. Interactive comments are enabled by default. (Bash has them on by
4510 7. The POSIX.2 startup files are executed (`$ENV') rather than the
4513 8. Tilde expansion is only performed on assignments preceding a
4514 command name, rather than on all assignment statements on the line.
4516 9. The default history file is `~/.sh_history' (this is the default
4517 value of `$HISTFILE').
4519 10. The output of `kill -l' prints all the signal names on a single
4520 line, separated by spaces.
4522 11. Non-interactive shells exit if FILENAME in `.' FILENAME is not
4525 12. Non-interactive shells exit if a syntax error in an arithmetic
4526 expansion results in an invalid expression.
4528 13. Redirection operators do not perform filename expansion on the word
4529 in the redirection unless the shell is interactive.
4531 14. Function names must be valid shell `name's. That is, they may not
4532 contain characters other than letters, digits, and underscores, and
4533 may not start with a digit. Declaring a function with an invalid
4534 name causes a fatal syntax error in non-interactive shells.
4536 15. POSIX.2 `special' builtins are found before shell functions during
4539 16. If a POSIX.2 special builtin returns an error status, a
4540 non-interactive shell exits. The fatal errors are those listed in
4541 the POSIX.2 standard, and include things like passing incorrect
4542 options, redirection errors, variable assignment errors for
4543 assignments preceding the command name, and so on.
4545 17. If the `cd' builtin finds a directory to change to using
4546 `$CDPATH', the value it assigns to the `PWD' variable does not
4547 contain any symbolic links, as if `cd -P' had been executed.
4549 18. If `$CDPATH' is set, the `cd' builtin will not implicitly append
4550 the current directory to it. This means that `cd' will fail if no
4551 valid directory name can be constructed from any of the entries in
4552 `$CDPATH', even if the a directory with the same name as the name
4553 given as an argument to `cd' exists in the current directory.
4555 19. A non-interactive shell exits with an error status if a variable
4556 assignment error occurs when no command name follows the assignment
4557 statements. A variable assignment error occurs, for example, when
4558 trying to assign a value to a readonly variable.
4560 20. A non-interactive shell exits with an error status if the iteration
4561 variable in a `for' statement or the selection variable in a
4562 `select' statement is a readonly variable.
4564 21. Process substitution is not available.
4566 22. Assignment statements preceding POSIX.2 special builtins persist
4567 in the shell environment after the builtin completes.
4569 23. The `export' and `readonly' builtin commands display their output
4570 in the format required by POSIX.2.
4573 There is other POSIX.2 behavior that Bash does not implement.
4576 1. Assignment statements affect the execution environment of all
4577 builtins, not just special ones.
4580 File: bashref.info, Node: Job Control, Next: Using History Interactively, Prev: Bash Features, Up: Top
4585 This chapter discusses what job control is, how it works, and how
4586 Bash allows you to access its facilities.
4590 * Job Control Basics:: How job control works.
4591 * Job Control Builtins:: Bash builtin commands used to interact
4593 * Job Control Variables:: Variables Bash uses to customize job
4597 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
4602 Job control refers to the ability to selectively stop (suspend) the
4603 execution of processes and continue (resume) their execution at a later
4604 point. A user typically employs this facility via an interactive
4605 interface supplied jointly by the system's terminal driver and Bash.
4607 The shell associates a JOB with each pipeline. It keeps a table of
4608 currently executing jobs, which may be listed with the `jobs' command.
4609 When Bash starts a job asynchronously, it prints a line that looks like:
4612 indicating that this job is job number 1 and that the process ID of the
4613 last process in the pipeline associated with this job is 25647. All of
4614 the processes in a single pipeline are members of the same job. Bash
4615 uses the JOB abstraction as the basis for job control.
4617 To facilitate the implementation of the user interface to job
4618 control, the system maintains the notion of a current terminal process
4619 group ID. Members of this process group (processes whose process group
4620 ID is equal to the current terminal process group ID) receive
4621 keyboard-generated signals such as `SIGINT'. These processes are said
4622 to be in the foreground. Background processes are those whose process
4623 group ID differs from the terminal's; such processes are immune to
4624 keyboard-generated signals. Only foreground processes are allowed to
4625 read from or write to the terminal. Background processes which attempt
4626 to read from (write to) the terminal are sent a `SIGTTIN' (`SIGTTOU')
4627 signal by the terminal driver, which, unless caught, suspends the
4630 If the operating system on which Bash is running supports job
4631 control, Bash contains facilities to use it. Typing the SUSPEND
4632 character (typically `^Z', Control-Z) while a process is running causes
4633 that process to be stopped and returns control to Bash. Typing the
4634 DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
4635 process to be stopped when it attempts to read input from the terminal,
4636 and control to be returned to Bash. The user then manipulates the
4637 state of this job, using the `bg' command to continue it in the
4638 background, the `fg' command to continue it in the foreground, or the
4639 `kill' command to kill it. A `^Z' takes effect immediately, and has
4640 the additional side effect of causing pending output and typeahead to
4643 There are a number of ways to refer to a job in the shell. The
4644 character `%' introduces a job name. Job number `n' may be referred to
4645 as `%n'. A job may also be referred to using a prefix of the name used
4646 to start it, or using a substring that appears in its command line.
4647 For example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the
4648 other hand, refers to any job containing the string `ce' in its command
4649 line. If the prefix or substring matches more than one job, Bash
4650 reports an error. The symbols `%%' and `%+' refer to the shell's
4651 notion of the current job, which is the last job stopped while it was
4652 in the foreground or started in the background. The previous job may
4653 be referenced using `%-'. In output pertaining to jobs (e.g., the
4654 output of the `jobs' command), the current job is always flagged with a
4655 `+', and the previous job with a `-'.
4657 Simply naming a job can be used to bring it into the foreground:
4658 `%1' is a synonym for `fg %1', bringing job 1 from the background into
4659 the foreground. Similarly, `%1 &' resumes job 1 in the background,
4660 equivalent to `bg %1'
4662 The shell learns immediately whenever a job changes state.
4663 Normally, Bash waits until it is about to print a prompt before
4664 reporting changes in a job's status so as to not interrupt any other
4665 output. If the the `-b' option to the `set' builtin is enabled, Bash
4666 reports such changes immediately (*note The Set Builtin::.).
4668 If an attempt to exit Bash is while jobs are stopped, the shell
4669 prints a message warning that there are stopped jobs. The `jobs'
4670 command may then be used to inspect their status. If a second attempt
4671 to exit is made without an intervening command, Bash does not print
4672 another warning, and the stopped jobs are terminated.
4675 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
4677 Job Control Builtins
4678 ====================
4682 Resume the suspended job JOBSPEC in the background, as if it had
4683 been started with `&'. If JOBSPEC is not supplied, the current
4684 job is used. The return status is zero unless it is run when job
4685 control is not enabled, or, when run with job control enabled, if
4686 JOBSPEC was not found or JOBSPEC specifies a job that was started
4687 without job control.
4691 Resume the job JOBSPEC in the foreground and make it the current
4692 job. If JOBSPEC is not supplied, the current job is used. The
4693 return status is that of the command placed into the foreground,
4694 or non-zero if run when job control is disabled or, when run with
4695 job control enabled, JOBSPEC does not specify a valid job or
4696 JOBSPEC specifies a job that was started without job control.
4699 jobs [-lpnrs] [JOBSPEC]
4700 jobs -x COMMAND [ARGUMENTS]
4702 The first form lists the active jobs. The options have the
4706 List process IDs in addition to the normal information.
4709 Display information only about jobs that have changed status
4710 since the user was last notified of their status.
4713 List only the process ID of the job's process group leader.
4716 Restrict output to running jobs.
4719 Restrict output to stopped jobs.
4721 If JOBSPEC is given, output is restricted to information about
4722 that job. If JOBSPEC is not supplied, the status of all jobs is
4725 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
4726 in COMMAND or ARGUMENTS with the corresponding process group ID,
4727 and executes COMMAND, passing it ARGUMENTs, returning its exit
4731 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
4732 kill -l [EXIT_STATUS]
4733 Send a signal specified by SIGSPEC or SIGNUM to the process named
4734 by job specification JOBSPEC or process ID PID. SIGSPEC is either
4735 a signal name such as `SIGINT' (with or without the `SIG' prefix)
4736 or a signal number; SIGNUM is a signal number. If SIGSPEC and
4737 SIGNUM are not present, `SIGTERM' is used. The `-l' option lists
4738 the signal names. If any arguments are supplied when `-l' is
4739 given, the names of the signals corresponding to the arguments are
4740 listed, and the return status is zero. EXIT_STATUS is a number
4741 specifying a signal number or the exit status of a process
4742 terminated by a signal. The return status is zero if at least one
4743 signal was successfully sent, or non-zero if an error occurs or an
4744 invalid option is encountered.
4748 Wait until the child process specified by process ID PID or job
4749 specification JOBSPEC exits and return the exit status of the last
4750 command waited for. If a job spec is given, all processes in the
4751 job are waited for. If no arguments are given, all currently
4752 active child processes are waited for, and the return status is
4753 zero. If neither JOBSPEC nor PID specifies an active child process
4754 of the shell, the return status is 127.
4757 disown [-ar] [-h] [JOBSPEC ...]
4758 Without options, each JOBSPEC is removed from the table of active
4759 jobs. If the `-h' option is given, the job is not removed from
4760 the table, but is marked so that `SIGHUP' is not sent to the job
4761 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
4762 neither the `-a' nor `-r' option is supplied, the current job is
4763 used. If no JOBSPEC is supplied, the `-a' option means to remove
4764 or mark all jobs; the `-r' option without a JOBSPEC argument
4765 restricts operation to running jobs.
4769 Suspend the execution of this shell until it receives a `SIGCONT'
4770 signal. The `-f' option means to suspend even if the shell is a
4773 When job control is not active, the `kill' and `wait' builtins do
4774 not accept JOBSPEC arguments. They must be supplied process IDs.
4777 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
4779 Job Control Variables
4780 =====================
4783 This variable controls how the shell interacts with the user and
4784 job control. If this variable exists then single word simple
4785 commands without redirections are treated as candidates for
4786 resumption of an existing job. There is no ambiguity allowed; if
4787 there is more than one job beginning with the string typed, then
4788 the most recently accessed job will be selected. The name of a
4789 stopped job, in this context, is the command line used to start
4790 it. If this variable is set to the value `exact', the string
4791 supplied must match the name of a stopped job exactly; if set to
4792 `substring', the string supplied needs to match a substring of the
4793 name of a stopped job. The `substring' value provides
4794 functionality analogous to the `%?' job ID (*note Job Control
4795 Basics::.). If set to any other value, the supplied string must
4796 be a prefix of a stopped job's name; this provides functionality
4797 analogous to the `%' job ID.
4800 File: bashref.info, Node: Using History Interactively, Next: Command Line Editing, Prev: Job Control, Up: Top
4802 Using History Interactively
4803 ***************************
4805 This chapter describes how to use the GNU History Library
4806 interactively, from a user's standpoint. It should be considered a
4807 user's guide. For information on using the GNU History Library in
4808 other programs, see the GNU Readline Library Manual.
4812 * Bash History Facilities:: How Bash lets you manipulate your command
4814 * Bash History Builtins:: The Bash builtin commands that manipulate
4815 the command history.
4816 * History Interaction:: What it feels like using History as a user.
4819 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
4821 Bash History Facilities
4822 =======================
4824 When the `-o history' option to the `set' builtin is enabled (*note
4825 The Set Builtin::.), the shell provides access to the COMMAND HISTORY,
4826 the list of commands previously typed. The text of the last `HISTSIZE'
4827 commands (default 500) is saved in a history list. The shell stores
4828 each command in the history list prior to parameter and variable
4829 expansion but after history expansion is performed, subject to the
4830 values of the shell variables `HISTIGNORE' and `HISTCONTROL'. When the
4831 shell starts up, the history is initialized from the file named by the
4832 `HISTFILE' variable (default `~/.bash_history'). `HISTFILE' is
4833 truncated, if necessary, to contain no more than the number of lines
4834 specified by the value of the `HISTFILESIZE' variable. When an
4835 interactive shell exits, the last `HISTSIZE' lines are copied from the
4836 history list to `HISTFILE'. If the `histappend' shell option is set
4837 (*note Bash Builtins::.), the lines are appended to the history file,
4838 otherwise the history file is overwritten. If `HISTFILE' is unset, or
4839 if the history file is unwritable, the history is not saved. After
4840 saving the history, the history file is truncated to contain no more
4841 than `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no
4842 truncation is performed.
4844 The builtin command `fc' may be used to list or edit and re-execute
4845 a portion of the history list. The `history' builtin can be used to
4846 display or modify the history list and manipulate the history file.
4847 When using the command-line editing, search commands are available in
4848 each editing mode that provide access to the history list.
4850 The shell allows control over which commands are saved on the history
4851 list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
4852 the shell to save only a subset of the commands entered. The `cmdhist'
4853 shell option, if enabled, causes the shell to attempt to save each line
4854 of a multi-line command in the same history entry, adding semicolons
4855 where necessary to preserve syntactic correctness. The `lithist' shell
4856 option causes the shell to save the command with embedded newlines
4857 instead of semicolons. *Note Bash Builtins::, for a description of
4861 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
4863 Bash History Builtins
4864 =====================
4866 Bash provides two builtin commands that allow you to manipulate the
4867 history list and history file.
4870 `fc [-e ENAME] [-nlr] [FIRST] [LAST]'
4871 `fc -s [PAT=REP] [COMMAND]'
4873 Fix Command. In the first form, a range of commands from FIRST to
4874 LAST is selected from the history list. Both FIRST and LAST may
4875 be specified as a string (to locate the most recent command
4876 beginning with that string) or as a number (an index into the
4877 history list, where a negative number is used as an offset from the
4878 current command number). If LAST is not specified it is set to
4879 FIRST. If FIRST is not specified it is set to the previous
4880 command for editing and -16 for listing. If the `-l' flag is
4881 given, the commands are listed on standard output. The `-n' flag
4882 suppresses the command numbers when listing. The `-r' flag
4883 reverses the order of the listing. Otherwise, the editor given by
4884 ENAME is invoked on a file containing those commands. If ENAME is
4885 not given, the value of the following variable expansion is used:
4886 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
4887 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
4888 that is set, or `vi' if neither is set. When editing is complete,
4889 the edited commands are echoed and executed.
4891 In the second form, COMMAND is re-executed after each instance of
4892 PAT in the selected command is replaced by REP.
4894 A useful alias to use with the `fc' command is `r='fc -s'', so
4895 that typing `r cc' runs the last command beginning with `cc' and
4896 typing `r' re-executes the last command (*note Aliases::.).
4900 history [-anrw] [FILENAME]
4903 Display the history list with line numbers. Lines prefixed with
4904 with a `*' have been modified. An argument of N says to list only
4905 the last N lines. Options, if supplied, have the following
4909 Write out the current history to the history file.
4912 Read the current history file and append its contents to the
4916 Append the new history lines (history lines entered since the
4917 beginning of the current Bash session) to the history file.
4920 Append the history lines not already read from the history
4921 file to the current history list. These are lines appended
4922 to the history file since the beginning of the current Bash
4926 Clear the history list. This may be combined with the other
4927 options to replace the history list completely.
4930 The ARGs are added to the end of the history list as a single
4934 Perform history substitution on the ARGs and display the
4935 result on the standard output, without storing the results in
4938 When the `-w', `-r', `-a', or `-n' option is used, if FILENAME is
4939 given, then it is used as the history file. If not, then the
4940 value of the `HISTFILE' variable is used.
4943 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
4948 The History library provides a history expansion feature that is
4949 similar to the history expansion provided by `csh'. This section
4950 describes the syntax used to manipulate the history information.
4952 History expansions introduce words from the history list into the
4953 input stream, making it easy to repeat commands, insert the arguments
4954 to a previous command into the current input line, or fix errors in
4955 previous commands quickly.
4957 History expansion takes place in two parts. The first is to
4958 determine which line from the history list should be used during
4959 substitution. The second is to select portions of that line for
4960 inclusion into the current one. The line selected from the history is
4961 called the "event", and the portions of that line that are acted upon
4962 are called "words". Various "modifiers" are available to manipulate
4963 the selected words. The line is broken into words in the same fashion
4964 that Bash does, so that several words surrounded by quotes are
4965 considered one word. History expansions are introduced by the
4966 appearance of the history expansion character, which is `!' by default.
4967 Only `\' and `'' may be used to escape the history expansion character.
4969 Several shell options settable with the `shopt' builtin (*note Bash
4970 Builtins::.) may be used to tailor the behavior of history expansion.
4971 If the `histverify' shell option is enabled, and Readline is being
4972 used, history substitutions are not immediately passed to the shell
4973 parser. Instead, the expanded line is reloaded into the Readline
4974 editing buffer for further modification. If Readline is being used,
4975 and the `histreedit' shell option is enabled, a failed history
4976 expansion will be reloaded into the Readline editing buffer for
4977 correction. The `-p' option to the `history' builtin command may be
4978 used to see what a history expansion will do before using it. The `-s'
4979 option to the `history' builtin may be used to add commands to the end
4980 of the history list without actually executing them, so that they are
4981 available for subsequent recall. This is most useful in conjunction
4984 The shell allows control of the various characters used by the
4985 history expansion mechanism with the `histchars' variable.
4989 * Event Designators:: How to specify which history line to use.
4990 * Word Designators:: Specifying which words are of interest.
4991 * Modifiers:: Modifying the results of substitution.
4994 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
4999 An event designator is a reference to a command line entry in the
5003 Start a history substitution, except when followed by a space, tab,
5004 the end of the line, `=' or `('.
5007 Refer to command line N.
5010 Refer to the command N lines back.
5013 Refer to the previous command. This is a synonym for `!-1'.
5016 Refer to the most recent command starting with STRING.
5019 Refer to the most recent command containing STRING. The trailing
5020 `?' may be omitted if the STRING is followed immediately by a
5024 Quick Substitution. Repeat the last command, replacing STRING1
5025 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
5028 The entire command line typed so far.
5031 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
5036 Word designators are used to select desired words from the event. A
5037 `:' separates the event specification from the word designator. It may
5038 be omitted if the word designator begins with a `^', `$', `*', `-', or
5039 `%'. Words are numbered from the beginning of the line, with the first
5040 word being denoted by 0 (zero). Words are inserted into the current
5041 line separated by single spaces.
5044 The `0'th word. For many applications, this is the command word.
5050 The first argument; that is, word 1.
5056 The word matched by the most recent `?STRING?' search.
5059 A range of words; `-Y' abbreviates `0-Y'.
5062 All of the words, except the `0'th. This is a synonym for `1-$'.
5063 It is not an error to use `*' if there is just one word in the
5064 event; the empty string is returned in that case.
5070 Abbreviates `X-$' like `X*', but omits the last word.
5072 If a word designator is supplied without an event specification, the
5073 previous command is used as the event.
5076 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
5081 After the optional word designator, you can add a sequence of one or
5082 more of the following modifiers, each preceded by a `:'.
5085 Remove a trailing pathname component, leaving only the head.
5088 Remove all leading pathname components, leaving the tail.
5091 Remove a trailing suffix of the form `.SUFFIX', leaving the
5095 Remove all but the trailing suffix.
5098 Print the new command but do not execute it.
5101 Quote the substituted words, escaping further substitutions.
5104 Quote the substituted words as with `q', but break into words at
5105 spaces, tabs, and newlines.
5108 Substitute NEW for the first occurrence of OLD in the event line.
5109 Any delimiter may be used in place of `/'. The delimiter may be
5110 quoted in OLD and NEW with a single backslash. If `&' appears in
5111 NEW, it is replaced by OLD. A single backslash will quote the
5112 `&'. The final delimiter is optional if it is the last character
5116 Repeat the previous substitution.
5119 Cause changes to be applied over the entire event line. Used in
5120 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
5123 File: bashref.info, Node: Command Line Editing, Next: Installing Bash, Prev: Using History Interactively, Up: Top
5125 Command Line Editing
5126 ********************
5128 This chapter describes the basic features of the GNU command line
5133 * Introduction and Notation:: Notation used in this text.
5134 * Readline Interaction:: The minimum set of commands for editing a line.
5135 * Readline Init File:: Customizing Readline from a user's view.
5136 * Bindable Readline Commands:: A description of most of the Readline commands
5137 available for binding
5138 * Readline vi Mode:: A short description of how to make Readline
5139 behave like the vi editor.
5142 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
5144 Introduction to Line Editing
5145 ============================
5147 The following paragraphs describe the notation used to represent
5150 The text <C-k> is read as `Control-K' and describes the character
5151 produced when the <k> key is pressed while the Control key is depressed.
5153 The text <M-k> is read as `Meta-K' and describes the character
5154 produced when the meta key (if you have one) is depressed, and the <k>
5155 key is pressed. If you do not have a meta key, the identical keystroke
5156 can be generated by typing <ESC> first, and then typing <k>. Either
5157 process is known as "metafying" the <k> key.
5159 The text <M-C-k> is read as `Meta-Control-k' and describes the
5160 character produced by "metafying" <C-k>.
5162 In addition, several keys have their own names. Specifically,
5163 <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
5164 when seen in this text, or in an init file (*note Readline Init
5168 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
5170 Readline Interaction
5171 ====================
5173 Often during an interactive session you type in a long line of text,
5174 only to notice that the first word on the line is misspelled. The
5175 Readline library gives you a set of commands for manipulating the text
5176 as you type it in, allowing you to just fix your typo, and not forcing
5177 you to retype the majority of the line. Using these editing commands,
5178 you move the cursor to the place that needs correction, and delete or
5179 insert the text of the corrections. Then, when you are satisfied with
5180 the line, you simply press <RETURN>. You do not have to be at the end
5181 of the line to press <RETURN>; the entire line is accepted regardless
5182 of the location of the cursor within the line.
5186 * Readline Bare Essentials:: The least you need to know about Readline.
5187 * Readline Movement Commands:: Moving about the input line.
5188 * Readline Killing Commands:: How to delete text, and how to get it back!
5189 * Readline Arguments:: Giving numeric arguments to commands.
5190 * Searching:: Searching through previous lines.
5193 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
5195 Readline Bare Essentials
5196 ------------------------
5198 In order to enter characters into the line, simply type them. The
5199 typed character appears where the cursor was, and then the cursor moves
5200 one space to the right. If you mistype a character, you can use your
5201 erase character to back up and delete the mistyped character.
5203 Sometimes you may miss typing a character that you wanted to type,
5204 and not notice your error until you have typed several other
5205 characters. In that case, you can type <C-b> to move the cursor to the
5206 left, and then correct your mistake. Afterwards, you can move the
5207 cursor to the right with <C-f>.
5209 When you add text in the middle of a line, you will notice that
5210 characters to the right of the cursor are `pushed over' to make room
5211 for the text that you have inserted. Likewise, when you delete text
5212 behind the cursor, characters to the right of the cursor are `pulled
5213 back' to fill in the blank space created by the removal of the text. A
5214 list of the basic bare essentials for editing the text of an input line
5218 Move back one character.
5221 Move forward one character.
5224 Delete the character to the left of the cursor.
5227 Delete the character underneath the cursor.
5230 Insert the character into the line at the cursor.
5233 Undo the last editing command. You can undo all the way back to an
5237 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
5239 Readline Movement Commands
5240 --------------------------
5242 The above table describes the most basic possible keystrokes that
5243 you need in order to do editing of the input line. For your
5244 convenience, many other commands have been added in addition to <C-b>,
5245 <C-f>, <C-d>, and <DEL>. Here are some commands for moving more rapidly
5249 Move to the start of the line.
5252 Move to the end of the line.
5255 Move forward a word, where a word is composed of letters and
5259 Move backward a word.
5262 Clear the screen, reprinting the current line at the top.
5264 Notice how <C-f> moves forward a character, while <M-f> moves
5265 forward a word. It is a loose convention that control keystrokes
5266 operate on characters while meta keystrokes operate on words.
5269 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
5271 Readline Killing Commands
5272 -------------------------
5274 "Killing" text means to delete the text from the line, but to save
5275 it away for later use, usually by "yanking" (re-inserting) it back into
5276 the line. If the description for a command says that it `kills' text,
5277 then you can be sure that you can get the text back in a different (or
5278 the same) place later.
5280 When you use a kill command, the text is saved in a "kill-ring".
5281 Any number of consecutive kills save all of the killed text together, so
5282 that when you yank it back, you get it all. The kill ring is not line
5283 specific; the text that you killed on a previously typed line is
5284 available to be yanked back later, when you are typing another line.
5286 Here is the list of commands for killing text.
5289 Kill the text from the current cursor position to the end of the
5293 Kill from the cursor to the end of the current word, or if between
5294 words, to the end of the next word.
5297 Kill from the cursor the start of the previous word, or if between
5298 words, to the start of the previous word.
5301 Kill from the cursor to the previous whitespace. This is
5302 different than <M-DEL> because the word boundaries differ.
5304 Here is how to "yank" the text back into the line. Yanking means to
5305 copy the most-recently-killed text from the kill buffer.
5308 Yank the most recently killed text back into the buffer at the
5312 Rotate the kill-ring, and yank the new top. You can only do this
5313 if the prior command is <C-y> or <M-y>.
5316 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
5321 You can pass numeric arguments to Readline commands. Sometimes the
5322 argument acts as a repeat count, other times it is the sign of the
5323 argument that is significant. If you pass a negative argument to a
5324 command which normally acts in a forward direction, that command will
5325 act in a backward direction. For example, to kill text back to the
5326 start of the line, you might type `M-- C-k'.
5328 The general way to pass numeric arguments to a command is to type
5329 meta digits before the command. If the first `digit' typed is a minus
5330 sign (<->), then the sign of the argument will be negative. Once you
5331 have typed one meta digit to get the argument started, you can type the
5332 remainder of the digits, and then the command. For example, to give
5333 the <C-d> command an argument of 10, you could type `M-1 0 C-d'.
5336 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
5338 Searching for Commands in the History
5339 -------------------------------------
5341 Readline provides commands for searching through the command history
5342 (*note Bash History Facilities::.) for lines containing a specified
5343 string. There are two search modes: INCREMENTAL and NON-INCREMENTAL.
5345 Incremental searches begin before the user has finished typing the
5346 search string. As each character of the search string is typed,
5347 Readline displays the next entry from the history matching the string
5348 typed so far. An incremental search requires only as many characters
5349 as needed to find the desired history entry. The <ESC> character is
5350 used to terminate an incremental search. <C-j> will also terminate the
5351 search. <C-g> will abort an incremental search and restore the
5352 original line. When the search is terminated, the history entry
5353 containing the search string becomes the current line. To find other
5354 matching entries in the history list, type <C-s> or <C-r> as
5355 appropriate. This will search backward or forward in the history for
5356 the next entry matching the search string typed so far. Any other key
5357 sequence bound to a Readline command will terminate the search and
5358 execute that command. For instance, a <RET> will terminate the search
5359 and accept the line, thereby executing the command from the history
5362 Non-incremental searches read the entire search string before
5363 starting to search for matching history lines. The search string may be
5364 typed by the user or be part of the contents of the current line.
5367 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
5372 Although the Readline library comes with a set of `emacs'-like
5373 keybindings installed by default, it is possible to use a different set
5374 of keybindings. Any user can customize programs that use Readline by
5375 putting commands in an "inputrc" file in his home directory. The name
5376 of this file is taken from the value of the shell variable `INPUTRC'.
5377 If that variable is unset, the default is `~/.inputrc'.
5379 When a program which uses the Readline library starts up, the init
5380 file is read, and the key bindings are set.
5382 In addition, the `C-x C-r' command re-reads this init file, thus
5383 incorporating any changes that you might have made to it.
5387 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
5389 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
5391 * Sample Init File:: An example inputrc file.
5394 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
5396 Readline Init File Syntax
5397 -------------------------
5399 There are only a few basic constructs allowed in the Readline init
5400 file. Blank lines are ignored. Lines beginning with a `#' are
5401 comments. Lines beginning with a `$' indicate conditional constructs
5402 (*note Conditional Init Constructs::.). Other lines denote variable
5403 settings and key bindings.
5406 You can modify the run-time behavior of Readline by altering the
5407 values of variables in Readline using the `set' command within the
5408 init file. Here is how to change from the default Emacs-like key
5409 binding to use `vi' line editing commands:
5413 A great deal of run-time behavior is changeable with the following
5417 Controls what happens when Readline wants to ring the
5418 terminal bell. If set to `none', Readline never rings the
5419 bell. If set to `visible', Readline uses a visible bell if
5420 one is available. If set to `audible' (the default),
5421 Readline attempts to ring the terminal's bell.
5424 The string to insert at the beginning of the line when the
5425 `insert-comment' command is executed. The default value is
5428 `completion-ignore-case'
5429 If set to `on', Readline performs filename matching and
5430 completion in a case-insensitive fashion. The default value
5433 `completion-query-items'
5434 The number of possible completions that determines when the
5435 user is asked whether he wants to see the list of
5436 possibilities. If the number of possible completions is
5437 greater than this value, Readline will ask the user whether
5438 or not he wishes to view them; otherwise, they are simply
5439 listed. The default limit is `100'.
5442 If set to `on', Readline will convert characters with the
5443 eighth bit set to an ASCII key sequence by stripping the
5444 eighth bit and prepending an <ESC> character, converting them
5445 to a meta-prefixed key sequence. The default value is `on'.
5447 `disable-completion'
5448 If set to `On', Readline will inhibit word completion.
5449 Completion characters will be inserted into the line as if
5450 they had been mapped to `self-insert'. The default is `off'.
5453 The `editing-mode' variable controls which default set of key
5454 bindings is used. By default, Readline starts up in Emacs
5455 editing mode, where the keystrokes are most similar to Emacs.
5456 This variable can be set to either `emacs' or `vi'.
5459 When set to `on', Readline will try to enable the application
5460 keypad when it is called. Some systems need this to enable
5461 the arrow keys. The default is `off'.
5464 If set to `on', tilde expansion is performed when Readline
5465 attempts word completion. The default is `off'.
5467 `horizontal-scroll-mode'
5468 This variable can be set to either `on' or `off'. Setting it
5469 to `on' means that the text of the lines being edited will
5470 scroll horizontally on a single screen line when they are
5471 longer than the width of the screen, instead of wrapping onto
5472 a new screen line. By default, this variable is set to `off'.
5475 Sets Readline's idea of the current keymap for key binding
5476 commands. Acceptable `keymap' names are `emacs',
5477 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
5478 `vi-command', and `vi-insert'. `vi' is equivalent to
5479 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
5480 default value is `emacs'. The value of the `editing-mode'
5481 variable also affects the default keymap.
5484 If set to `on', completed directory names have a slash
5485 appended. The default is `on'.
5487 `mark-modified-lines'
5488 This variable, when set to `on', causes Readline to display an
5489 asterisk (`*') at the start of history lines which have been
5490 modified. This variable is `off' by default.
5493 If set to `on', Readline will enable eight-bit input (it will
5494 not strip the eighth bit from the characters it reads),
5495 regardless of what the terminal claims it can support. The
5496 default value is `off'. The name `meta-flag' is a synonym
5500 If set to `on', Readline will display characters with the
5501 eighth bit set directly rather than as a meta-prefixed escape
5502 sequence. The default is `off'.
5504 `print-completions-horizontally'
5505 If set to `on', Readline will display completions with matches
5506 sorted horizontally in alphabetical order, rather than down
5507 the screen. The default is `off'.
5509 `show-all-if-ambiguous'
5510 This alters the default behavior of the completion functions.
5511 If set to `on', words which have more than one possible
5512 completion cause the matches to be listed immediately instead
5513 of ringing the bell. The default value is `off'.
5516 If set to `on', a character denoting a file's type is
5517 appended to the filename when listing possible completions.
5518 The default is `off'.
5521 The syntax for controlling key bindings in the init file is
5522 simple. First you have to know the name of the command that you
5523 want to change. The following sections contain tables of the
5524 command name, the default keybinding, if any, and a short
5525 description of what the command does.
5527 Once you know the name of the command, simply place the name of
5528 the key you wish to bind the command to, a colon, and then the
5529 name of the command on a line in the init file. The name of the
5530 key can be expressed in different ways, depending on which is most
5531 comfortable for you.
5533 KEYNAME: FUNCTION-NAME or MACRO
5534 KEYNAME is the name of a key spelled out in English. For
5536 Control-u: universal-argument
5537 Meta-Rubout: backward-kill-word
5538 Control-o: "> output"
5540 In the above example, <C-u> is bound to the function
5541 `universal-argument', and <C-o> is bound to run the macro
5542 expressed on the right hand side (that is, to insert the text
5543 `> output' into the line).
5545 "KEYSEQ": FUNCTION-NAME or MACRO
5546 KEYSEQ differs from KEYNAME above in that strings denoting an
5547 entire key sequence can be specified, by placing the key
5548 sequence in double quotes. Some GNU Emacs style key escapes
5549 can be used, as in the following example, but the special
5550 character names are not recognized.
5552 "\C-u": universal-argument
5553 "\C-x\C-r": re-read-init-file
5554 "\e[11~": "Function Key 1"
5556 In the above example, <C-u> is bound to the function
5557 `universal-argument' (just as it was in the first example),
5558 `<C-x> <C-r>' is bound to the function `re-read-init-file',
5559 and `<ESC> <[> <1> <1> <~>' is bound to insert the text
5562 The following GNU Emacs style escape sequences are available when
5563 specifying key sequences:
5583 In addition to the GNU Emacs style escape sequences, a second set
5584 of backslash escapes is available:
5611 the character whose ASCII code is the octal value NNN (one to
5615 the character whose ASCII code is the hexadecimal value NNN
5616 (one to three digits)
5618 When entering the text of a macro, single or double quotes must be
5619 used to indicate a macro definition. Unquoted text is assumed to
5620 be a function name. In the macro body, the backslash escapes
5621 described above are expanded. Backslash will quote any other
5622 character in the macro text, including `"' and `''. For example,
5623 the following binding will make `C-x \' insert a single `\' into
5628 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
5630 Conditional Init Constructs
5631 ---------------------------
5633 Readline implements a facility similar in spirit to the conditional
5634 compilation features of the C preprocessor which allows key bindings
5635 and variable settings to be performed as the result of tests. There
5636 are four parser directives used.
5639 The `$if' construct allows bindings to be made based on the
5640 editing mode, the terminal being used, or the application using
5641 Readline. The text of the test extends to the end of the line; no
5642 characters are required to isolate it.
5645 The `mode=' form of the `$if' directive is used to test
5646 whether Readline is in `emacs' or `vi' mode. This may be
5647 used in conjunction with the `set keymap' command, for
5648 instance, to set bindings in the `emacs-standard' and
5649 `emacs-ctlx' keymaps only if Readline is starting out in
5653 The `term=' form may be used to include terminal-specific key
5654 bindings, perhaps to bind the key sequences output by the
5655 terminal's function keys. The word on the right side of the
5656 `=' is tested against both the full name of the terminal and
5657 the portion of the terminal name before the first `-'. This
5658 allows `sun' to match both `sun' and `sun-cmd', for instance.
5661 The APPLICATION construct is used to include
5662 application-specific settings. Each program using the
5663 Readline library sets the APPLICATION NAME, and you can test
5664 for it. This could be used to bind key sequences to
5665 functions useful for a specific program. For instance, the
5666 following command adds a key sequence that quotes the current
5667 or previous word in Bash:
5669 # Quote the current or previous word
5670 "\C-xq": "\eb\"\ef\""
5674 This command, as seen in the previous example, terminates an `$if'
5678 Commands in this branch of the `$if' directive are executed if the
5682 This directive takes a single filename as an argument and reads
5683 commands and bindings from that file.
5684 $include /etc/inputrc
5687 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
5692 Here is an example of an inputrc file. This illustrates key
5693 binding, variable assignment, and conditional syntax.
5696 # This file controls the behaviour of line input editing for
5697 # programs that use the Gnu Readline library. Existing programs
5698 # include FTP, Bash, and Gdb.
5700 # You can re-read the inputrc file with C-x C-r.
5701 # Lines beginning with '#' are comments.
5703 # First, include any systemwide bindings and variable assignments from
5705 $include /etc/Inputrc
5708 # Set various bindings for emacs mode.
5710 set editing-mode emacs
5714 Meta-Control-h: backward-kill-word Text after the function name is ignored
5717 # Arrow keys in keypad mode
5719 #"\M-OD": backward-char
5720 #"\M-OC": forward-char
5721 #"\M-OA": previous-history
5722 #"\M-OB": next-history
5724 # Arrow keys in ANSI mode
5726 "\M-[D": backward-char
5727 "\M-[C": forward-char
5728 "\M-[A": previous-history
5729 "\M-[B": next-history
5731 # Arrow keys in 8 bit keypad mode
5733 #"\M-\C-OD": backward-char
5734 #"\M-\C-OC": forward-char
5735 #"\M-\C-OA": previous-history
5736 #"\M-\C-OB": next-history
5738 # Arrow keys in 8 bit ANSI mode
5740 #"\M-\C-[D": backward-char
5741 #"\M-\C-[C": forward-char
5742 #"\M-\C-[A": previous-history
5743 #"\M-\C-[B": next-history
5749 # An old-style binding. This happens to be the default.
5752 # Macros that are convenient for shell interaction
5755 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
5756 # prepare to type a quoted word -- insert open and close double quotes
5757 # and move to just after the open quote
5758 "\C-x\"": "\"\"\C-b"
5759 # insert a backslash (testing backslash escapes in sequences and macros)
5761 # Quote the current or previous word
5762 "\C-xq": "\eb\"\ef\""
5763 # Add a binding to refresh the line, which is unbound
5764 "\C-xr": redraw-current-line
5765 # Edit variable on current line.
5766 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
5769 # use a visible bell if one is available
5770 set bell-style visible
5772 # don't strip characters to 7 bits when reading
5775 # allow iso-latin1 characters to be inserted rather than converted to
5776 # prefix-meta sequences
5777 set convert-meta off
5779 # display characters with the eighth bit set directly rather than
5780 # as meta-prefixed characters
5783 # if there are more than 150 possible completions for a word, ask the
5784 # user if he wants to see all of them
5785 set completion-query-items 150
5791 "\M-.": yank-last-arg
5795 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
5797 Bindable Readline Commands
5798 ==========================
5802 * Commands For Moving:: Moving about the line.
5803 * Commands For History:: Getting at previous lines.
5804 * Commands For Text:: Commands for changing text.
5805 * Commands For Killing:: Commands for killing and yanking.
5806 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
5807 * Commands For Completion:: Getting Readline to do the typing for you.
5808 * Keyboard Macros:: Saving and re-executing typed characters
5809 * Miscellaneous Commands:: Other miscellaneous commands.
5811 This section describes Readline commands that may be bound to key
5815 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
5820 `beginning-of-line (C-a)'
5821 Move to the start of the current line.
5824 Move to the end of the line.
5826 `forward-char (C-f)'
5827 Move forward a character.
5829 `backward-char (C-b)'
5830 Move back a character.
5832 `forward-word (M-f)'
5833 Move forward to the end of the next word. Words are composed of
5836 `backward-word (M-b)'
5837 Move back to the start of this, or the previous, word. Words are
5838 composed of letters and digits.
5840 `clear-screen (C-l)'
5841 Clear the screen and redraw the current line, leaving the current
5842 line at the top of the screen.
5844 `redraw-current-line ()'
5845 Refresh the current line. By default, this is unbound.
5848 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
5850 Commands For Manipulating The History
5851 -------------------------------------
5853 `accept-line (Newline, Return)'
5854 Accept the line regardless of where the cursor is. If this line is
5855 non-empty, add it to the history list according to the setting of
5856 the `HISTCONTROL' and `HISTIGNORE' variables. If this line was a
5857 history line, then restore the history line to its original state.
5859 `previous-history (C-p)'
5860 Move `up' through the history list.
5862 `next-history (C-n)'
5863 Move `down' through the history list.
5865 `beginning-of-history (M-<)'
5866 Move to the first line in the history.
5868 `end-of-history (M->)'
5869 Move to the end of the input history, i.e., the line currently
5872 `reverse-search-history (C-r)'
5873 Search backward starting at the current line and moving `up'
5874 through the history as necessary. This is an incremental search.
5876 `forward-search-history (C-s)'
5877 Search forward starting at the current line and moving `down'
5878 through the the history as necessary. This is an incremental
5881 `non-incremental-reverse-search-history (M-p)'
5882 Search backward starting at the current line and moving `up'
5883 through the history as necessary using a non-incremental search
5884 for a string supplied by the user.
5886 `non-incremental-forward-search-history (M-n)'
5887 Search forward starting at the current line and moving `down'
5888 through the the history as necessary using a non-incremental search
5889 for a string supplied by the user.
5891 `history-search-forward ()'
5892 Search forward through the history for the string of characters
5893 between the start of the current line and the current cursor
5894 position (the POINT). This is a non-incremental search. By
5895 default, this command is unbound.
5897 `history-search-backward ()'
5898 Search backward through the history for the string of characters
5899 between the start of the current line and the point. This is a
5900 non-incremental search. By default, this command is unbound.
5902 `yank-nth-arg (M-C-y)'
5903 Insert the first argument to the previous command (usually the
5904 second word on the previous line). With an argument N, insert the
5905 Nth word from the previous command (the words in the previous
5906 command begin with word 0). A negative argument inserts the Nth
5907 word from the end of the previous command.
5909 `yank-last-arg (M-., M-_)'
5910 Insert last argument to the previous command (the last word of the
5911 previous history entry). With an argument, behave exactly like
5912 `yank-nth-arg'. Successive calls to `yank-last-arg' move back
5913 through the history list, inserting the last argument of each line
5917 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
5919 Commands For Changing Text
5920 --------------------------
5923 Delete the character under the cursor. If the cursor is at the
5924 beginning of the line, there are no characters in the line, and
5925 the last character typed was not bound to `delete-char', then
5928 `backward-delete-char (Rubout)'
5929 Delete the character behind the cursor. A numeric argument means
5930 to kill the characters instead of deleting them.
5932 `quoted-insert (C-q, C-v)'
5933 Add the next character typed to the line verbatim. This is how to
5934 insert key sequences like <C-q>, for example.
5936 `self-insert (a, b, A, 1, !, ...)'
5939 `transpose-chars (C-t)'
5940 Drag the character before the cursor forward over the character at
5941 the cursor, moving the cursor forward as well. If the insertion
5942 point is at the end of the line, then this transposes the last two
5943 characters of the line. Negative arguments don't work.
5945 `transpose-words (M-t)'
5946 Drag the word behind the cursor past the word in front of the
5947 cursor moving the cursor over that word as well.
5950 Uppercase the current (or following) word. With a negative
5951 argument, uppercase the previous word, but do not move the cursor.
5953 `downcase-word (M-l)'
5954 Lowercase the current (or following) word. With a negative
5955 argument, lowercase the previous word, but do not move the cursor.
5957 `capitalize-word (M-c)'
5958 Capitalize the current (or following) word. With a negative
5959 argument, capitalize the previous word, but do not move the cursor.
5962 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
5968 Kill the text from the current cursor position to the end of the
5971 `backward-kill-line (C-x Rubout)'
5972 Kill backward to the beginning of the line.
5974 `unix-line-discard (C-u)'
5975 Kill backward from the cursor to the beginning of the current line.
5976 The killed text is saved on the kill-ring.
5978 `kill-whole-line ()'
5979 Kill all characters on the current line, no matter where the
5980 cursor is. By default, this is unbound.
5983 Kill from the cursor to the end of the current word, or if between
5984 words, to the end of the next word. Word boundaries are the same
5987 `backward-kill-word (M-DEL)'
5988 Kill the word behind the cursor. Word boundaries are the same as
5991 `unix-word-rubout (C-w)'
5992 Kill the word behind the cursor, using white space as a word
5993 boundary. The killed text is saved on the kill-ring.
5995 `delete-horizontal-space ()'
5996 Delete all spaces and tabs around point. By default, this is
6000 Kill the text between the point and the *mark* (saved cursor
6001 position). This text is referred to as the REGION. By default,
6002 this command is unbound.
6004 `copy-region-as-kill ()'
6005 Copy the text in the region to the kill buffer, so it can be yanked
6006 right away. By default, this command is unbound.
6008 `copy-backward-word ()'
6009 Copy the word before point to the kill buffer. The word
6010 boundaries are the same as `backward-word'. By default, this
6013 `copy-forward-word ()'
6014 Copy the word following point to the kill buffer. The word
6015 boundaries are the same as `forward-word'. By default, this
6019 Yank the top of the kill ring into the buffer at the current
6023 Rotate the kill-ring, and yank the new top. You can only do this
6024 if the prior command is yank or yank-pop.
6027 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
6029 Specifying Numeric Arguments
6030 ----------------------------
6032 `digit-argument (M-0, M-1, ... M--)'
6033 Add this digit to the argument already accumulating, or start a new
6034 argument. <M-> starts a negative argument.
6036 `universal-argument ()'
6037 This is another way to specify an argument. If this command is
6038 followed by one or more digits, optionally with a leading minus
6039 sign, those digits define the argument. If the command is
6040 followed by digits, executing `universal-argument' again ends the
6041 numeric argument, but is otherwise ignored. As a special case, if
6042 this command is immediately followed by a character that is
6043 neither a digit or minus sign, the argument count for the next
6044 command is multiplied by four. The argument count is initially
6045 one, so executing this function the first time makes the argument
6046 count four, a second time makes the argument count sixteen, and so
6047 on. By default, this is not bound to a key.
6050 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
6052 Letting Readline Type For You
6053 -----------------------------
6056 Attempt to do completion on the text before the cursor. This is
6057 application-specific. Generally, if you are typing a filename
6058 argument, you can do filename completion; if you are typing a
6059 command, you can do command completion; if you are typing in a
6060 symbol to GDB, you can do symbol name completion; if you are
6061 typing in a variable to Bash, you can do variable name completion,
6062 and so on. Bash attempts completion treating the text as a
6063 variable (if the text begins with `$'), username (if the text
6064 begins with `~'), hostname (if the text begins with `@'), or
6065 command (including aliases and functions) in turn. If none of
6066 these produces a match, filename completion is attempted.
6068 `possible-completions (M-?)'
6069 List the possible completions of the text before the cursor.
6071 `insert-completions (M-*)'
6072 Insert all completions of the text before point that would have
6073 been generated by `possible-completions'.
6076 Similar to `complete', but replaces the word to be completed with
6077 a single match from the list of possible completions. Repeated
6078 execution of `menu-complete' steps through the list of possible
6079 completions, inserting each match in turn. At the end of the list
6080 of completions, the bell is rung and the original text is restored.
6081 An argument of N moves N positions forward in the list of matches;
6082 a negative argument may be used to move backward through the list.
6083 This command is intended to be bound to `TAB', but is unbound by
6086 `complete-filename (M-/)'
6087 Attempt filename completion on the text before point.
6089 `possible-filename-completions (C-x /)'
6090 List the possible completions of the text before point, treating
6093 `complete-username (M-~)'
6094 Attempt completion on the text before point, treating it as a
6097 `possible-username-completions (C-x ~)'
6098 List the possible completions of the text before point, treating
6101 `complete-variable (M-$)'
6102 Attempt completion on the text before point, treating it as a
6105 `possible-variable-completions (C-x $)'
6106 List the possible completions of the text before point, treating
6107 it as a shell variable.
6109 `complete-hostname (M-@)'
6110 Attempt completion on the text before point, treating it as a
6113 `possible-hostname-completions (C-x @)'
6114 List the possible completions of the text before point, treating
6117 `complete-command (M-!)'
6118 Attempt completion on the text before point, treating it as a
6119 command name. Command completion attempts to match the text
6120 against aliases, reserved words, shell functions, shell builtins,
6121 and finally executable filenames, in that order.
6123 `possible-command-completions (C-x !)'
6124 List the possible completions of the text before point, treating
6125 it as a command name.
6127 `dynamic-complete-history (M-TAB)'
6128 Attempt completion on the text before point, comparing the text
6129 against lines from the history list for possible completion
6132 `complete-into-braces (M-{)'
6133 Perform filename completion and return the list of possible
6134 completions enclosed within braces so the list is available to the
6135 shell (*note Brace Expansion::.).
6138 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
6143 `start-kbd-macro (C-x ()'
6144 Begin saving the characters typed into the current keyboard macro.
6146 `end-kbd-macro (C-x ))'
6147 Stop saving the characters typed into the current keyboard macro
6148 and save the definition.
6150 `call-last-kbd-macro (C-x e)'
6151 Re-execute the last keyboard macro defined, by making the
6152 characters in the macro appear as if typed at the keyboard.
6155 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
6157 Some Miscellaneous Commands
6158 ---------------------------
6160 `re-read-init-file (C-x C-r)'
6161 Read in the contents of the inputrc file, and incorporate any
6162 bindings or variable assignments found there.
6165 Abort the current editing command and ring the terminal's bell
6166 (subject to the setting of `bell-style').
6168 `do-uppercase-version (M-a, M-b, M-X, ...)'
6169 If the metafied character X is lowercase, run the command that is
6170 bound to the corresponding uppercase character.
6173 Make the next character typed be metafied. This is for keyboards
6174 without a meta key. Typing `ESC f' is equivalent to typing `M-f'.
6176 `undo (C-_, C-x C-u)'
6177 Incremental undo, separately remembered for each line.
6180 Undo all changes made to this line. This is like executing the
6181 `undo' command enough times to get back to the beginning.
6183 `tilde-expand (M-~)'
6184 Perform tilde expansion on the current word.
6187 Set the mark to the current point. If a numeric argument is
6188 supplied, the mark is set to that position.
6190 `exchange-point-and-mark (C-x C-x)'
6191 Swap the point with the mark. The current cursor position is set
6192 to the saved position, and the old cursor position is saved as the
6195 `character-search (C-])'
6196 A character is read and point is moved to the next occurrence of
6197 that character. A negative count searches for previous
6200 `character-search-backward (M-C-])'
6201 A character is read and point is moved to the previous occurrence
6202 of that character. A negative count searches for subsequent
6205 `insert-comment (M-#)'
6206 The value of the `comment-begin' variable is inserted at the
6207 beginning of the current line, and the line is accepted as if a
6208 newline had been typed. This makes the current line a shell
6212 Print all of the functions and their key bindings to the Readline
6213 output stream. If a numeric argument is supplied, the output is
6214 formatted in such a way that it can be made part of an INPUTRC
6215 file. This command is unbound by default.
6218 Print all of the settable variables and their values to the
6219 Readline output stream. If a numeric argument is supplied, the
6220 output is formatted in such a way that it can be made part of an
6221 INPUTRC file. This command is unbound by default.
6224 Print all of the Readline key sequences bound to macros and the
6225 strings they ouput. If a numeric argument is supplied, the output
6226 is formatted in such a way that it can be made part of an INPUTRC
6227 file. This command is unbound by default.
6229 `glob-expand-word (C-x *)'
6230 The word before point is treated as a pattern for pathname
6231 expansion, and the list of matching file names is inserted,
6234 `glob-list-expansions (C-x g)'
6235 The list of expansions that would have been generated by
6236 `glob-expand-word' is displayed, and the line is redrawn.
6238 `display-shell-version (C-x C-v)'
6239 Display version information about the current instance of Bash.
6241 `shell-expand-line (M-C-e)'
6242 Expand the line as the shell does. This performs alias and
6243 history expansion as well as all of the shell word expansions
6244 (*note Shell Expansions::.).
6246 `history-expand-line (M-^)'
6247 Perform history expansion on the current line.
6250 Perform history expansion on the current line and insert a space
6251 (*note History Interaction::.).
6253 `alias-expand-line ()'
6254 Perform alias expansion on the current line (*note Aliases::.).
6256 `history-and-alias-expand-line ()'
6257 Perform history and alias expansion on the current line.
6259 `insert-last-argument (M-., M-_)'
6260 A synonym for `yank-last-arg'.
6262 `operate-and-get-next (C-o)'
6263 Accept the current line for execution and fetch the next line
6264 relative to the current line from the history for editing. Any
6265 argument is ignored.
6267 `emacs-editing-mode (C-e)'
6268 When in `vi' editing mode, this causes a switch back to `emacs'
6269 editing mode, as if the command `set -o emacs' had been executed.
6272 File: bashref.info, Node: Readline vi Mode, Prev: Bindable Readline Commands, Up: Command Line Editing
6277 While the Readline library does not have a full set of `vi' editing
6278 functions, it does contain enough to allow simple editing of the line.
6279 The Readline `vi' mode behaves as specified in the POSIX 1003.2
6282 In order to switch interactively between `emacs' and `vi' editing
6283 modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
6284 Builtin::.). The Readline default is `emacs' mode.
6286 When you enter a line in `vi' mode, you are already placed in
6287 `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
6288 you into `command' mode, where you can edit the text of the line with
6289 the standard `vi' movement keys, move to previous history lines with
6290 `k' and subsequent lines with `j', and so forth.
6293 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Command Line Editing, Up: Top
6298 This chapter provides basic instructions for installing Bash on the
6299 various supported platforms. The distribution supports nearly every
6300 version of Unix (and, someday, GNU). Other independent ports exist for
6301 MS-DOS, OS/2, Windows 95, and Windows NT.
6305 * Basic Installation:: Installation instructions.
6307 * Compilers and Options:: How to set special options for various
6310 * Compiling For Multiple Architectures:: How to compile Bash for more
6311 than one kind of system from
6312 the same source tree.
6314 * Installation Names:: How to set the various paths used by the installation.
6316 * Specifying the System Type:: How to configure Bash for a particular system.
6318 * Sharing Defaults:: How to share default configuration values among GNU
6321 * Operation Controls:: Options recognized by the configuration program.
6323 * Optional Features:: How to enable and disable optional features when
6327 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
6332 These are installation instructions for Bash.
6334 The `configure' shell script attempts to guess correct values for
6335 various system-dependent variables used during compilation. It uses
6336 those values to create a `Makefile' in each directory of the package
6337 (the top directory, the `builtins' and `doc' directories, and the each
6338 directory under `lib'). It also creates a `config.h' file containing
6339 system-dependent definitions. Finally, it creates a shell script named
6340 `config.status' that you can run in the future to recreate the current
6341 configuration, a file `config.cache' that saves the results of its
6342 tests to speed up reconfiguring, and a file `config.log' containing
6343 compiler output (useful mainly for debugging `configure'). If at some
6344 point `config.cache' contains results you don't want to keep, you may
6347 If you need to do unusual things to compile Bash, please try to
6348 figure out how `configure' could check whether or not to do them, and
6349 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
6350 considered for the next release.
6352 The file `configure.in' is used to create `configure' by a program
6353 called Autoconf. You only need `configure.in' if you want to change it
6354 or regenerate `configure' using a newer version of Autoconf. If you do
6355 this, make sure you are using Autoconf version 2.10 or newer.
6357 If you need to change `configure.in' or regenerate `configure', you
6358 will need to create two files: `_distribution' and `_patchlevel'.
6359 `_distribution' should contain the major and minor version numbers of
6360 the Bash distribution, for example `2.01'. `_patchlevel' should
6361 contain the patch level of the Bash distribution, `0' for example. The
6362 script `support/mkconffiles' has been provided to automate the creation
6365 The simplest way to compile Bash is:
6367 1. `cd' to the directory containing the source code and type
6368 `./configure' to configure Bash for your system. If you're using
6369 `csh' on an old version of System V, you might need to type `sh
6370 ./configure' instead to prevent `csh' from trying to execute
6373 Running `configure' takes awhile. While running, it prints some
6374 messages telling which features it is checking for.
6376 2. Type `make' to compile Bash and build the `bashbug' bug reporting
6379 3. Optionally, type `make tests' to run the Bash test suite.
6381 4. Type `make install' to install `bash' and `bashbug'. This will
6382 also install the manual pages and Info file.
6385 You can remove the program binaries and object files from the source
6386 code directory by typing `make clean'. To also remove the files that
6387 `configure' created (so you can compile Bash for a different kind of
6388 computer), type `make distclean'.
6391 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
6393 Compilers and Options
6394 =====================
6396 Some systems require unusual options for compilation or linking that
6397 the `configure' script does not know about. You can give `configure'
6398 initial values for variables by setting them in the environment. Using
6399 a Bourne-compatible shell, you can do that on the command line like
6402 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
6404 On systems that have the `env' program, you can do it like this:
6406 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
6408 The configuration process uses GCC to build Bash if it is available.
6411 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
6413 Compiling For Multiple Architectures
6414 ====================================
6416 You can compile Bash for more than one kind of computer at the same
6417 time, by placing the object files for each architecture in their own
6418 directory. To do this, you must use a version of `make' that supports
6419 the `VPATH' variable, such as GNU `make'. `cd' to the directory where
6420 you want the object files and executables to go and run the `configure'
6421 script from the source directory. You may need to supply the
6422 `--srcdir=PATH' argument to tell `configure' where the source files
6423 are. `configure' automatically checks for the source code in the
6424 directory that `configure' is in and in `..'.
6426 If you have to use a `make' that does not supports the `VPATH'
6427 variable, you can compile Bash for one architecture at a time in the
6428 source code directory. After you have installed Bash for one
6429 architecture, use `make distclean' before reconfiguring for another
6432 Alternatively, if your system supports symbolic links, you can use
6433 the `support/mkclone' script to create a build tree which has symbolic
6434 links back to each file in the source directory. Here's an example
6435 that creates a build directory in the current directory from a source
6436 directory `/usr/gnu/src/bash-2.0':
6438 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
6440 The `mkclone' script requires Bash, so you must have already built Bash
6441 for at least one architecture before you can create build directories
6442 for other architectures.
6445 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
6450 By default, `make install' will install into `/usr/local/bin',
6451 `/usr/local/man', etc. You can specify an installation prefix other
6452 than `/usr/local' by giving `configure' the option `--prefix=PATH'.
6454 You can specify separate installation prefixes for
6455 architecture-specific files and architecture-independent files. If you
6456 give `configure' the option `--exec-prefix=PATH', `make install' will
6457 use `PATH' as the prefix for installing programs and libraries.
6458 Documentation and other data files will still use the regular prefix.
6461 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
6463 Specifying the System Type
6464 ==========================
6466 There may be some features `configure' can not figure out
6467 automatically, but needs to determine by the type of host Bash will run
6468 on. Usually `configure' can figure that out, but if it prints a
6469 message saying it can not guess the host type, give it the
6470 `--host=TYPE' option. `TYPE' can either be a short name for the system
6471 type, such as `sun4', or a canonical name with three fields:
6472 `CPU-COMPANY-SYSTEM' (e.g., `sparc-sun-sunos4.1.2').
6474 See the file `support/config.sub' for the possible values of each field.
6477 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
6482 If you want to set default values for `configure' scripts to share,
6483 you can create a site shell script called `config.site' that gives
6484 default values for variables like `CC', `cache_file', and `prefix'.
6485 `configure' looks for `PREFIX/share/config.site' if it exists, then
6486 `PREFIX/etc/config.site' if it exists. Or, you can set the
6487 `CONFIG_SITE' environment variable to the location of the site script.
6488 A warning: the Bash `configure' looks for a site script, but not all
6489 `configure' scripts do.
6492 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
6497 `configure' recognizes the following options to control how it
6501 Use and save the results of the tests in FILE instead of
6502 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
6503 debugging `configure'.
6506 Print a summary of the options to `configure', and exit.
6511 Do not print messages saying which checks are being made.
6514 Look for the Bash source code in directory DIR. Usually
6515 `configure' can determine that directory automatically.
6518 Print the version of Autoconf used to generate the `configure'
6521 `configure' also accepts some other, not widely used, boilerplate
6525 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
6530 The Bash `configure' has a number of `--enable-FEATURE' options,
6531 where FEATURE indicates an optional part of Bash. There are also
6532 several `--with-PACKAGE' options, where PACKAGE is something like
6533 `gnu-malloc' or `purify'. To turn off the default use of a package, use
6534 `--without-PACKAGE'. To configure Bash without a feature that is
6535 enabled by default, use `--disable-FEATURE'.
6537 Here is a complete list of the `--enable-' and `--with-' options
6538 that the Bash `configure' recognizes.
6541 Define if you are using the Andrew File System from Transarc.
6544 Use the curses library instead of the termcap library. This should
6545 be supplied if your system has an inadequate or incomplete termcap
6548 `--with-glibc-malloc'
6549 Use the GNU libc version of `malloc' in `lib/malloc/gmalloc.c'.
6550 This is not the version of `malloc' that appears in glibc version
6551 2, but a modified version of the `malloc' from glibc version 1.
6552 This is somewhat slower than the default `malloc', but wastes less
6553 space on a per-allocation basis, and will return memory to the
6554 operating system under some circumstances.
6557 Use the GNU version of `malloc' in `lib/malloc/malloc.c'. This is
6558 not the same `malloc' that appears in GNU libc, but an older
6559 version derived from the 4.2 BSD `malloc'. This `malloc' is very
6560 fast, but wastes some space on each allocation. This option is
6561 enabled by default. The `NOTES' file contains a list of systems
6562 for which this should be turned off, and `configure' disables this
6563 option automatically for a number of systems.
6566 Define this to use the Purify memory allocation checker from Pure
6569 `--enable-minimal-config'
6570 This produces a shell with minimal features, close to the
6571 historical Bourne shell.
6573 There are several `--enable-' options that alter how Bash is
6574 compiled and linked, rather than changing run-time features.
6576 `--enable-profiling'
6577 This builds a Bash binary that produces profiling information to be
6578 processed by `gprof' each time it is executed.
6580 `--enable-static-link'
6581 This causes Bash to be linked statically, if `gcc' is being used.
6582 This could be used to build a version to use as root's shell.
6584 The `minimal-config' option can be used to disable all of the
6585 following options, but it is processed first, so individual options may
6586 be enabled using `enable-FEATURE'.
6588 All of the following options except for `disabled-builtins' and
6589 `usg-echo-default' are enabled by default, unless the operating system
6590 does not provide the necessary support.
6593 Allow alias expansion and include the `alias' and `unalias'
6594 builtins (*note Aliases::.).
6596 `--enable-array-variables'
6597 Include support for one-dimensional array shell variables (*note
6600 `--enable-bang-history'
6601 Include support for `csh'-like history substitution (*note History
6604 `--enable-brace-expansion'
6605 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
6606 See *Note Brace Expansion::, for a complete description.
6608 `--enable-command-timing'
6609 Include support for recognizing `time' as a reserved word and for
6610 displaying timing statistics for the pipeline following `time'.
6611 This allows pipelines as well as shell builtins and functions to
6614 `--enable-cond-command'
6615 Include support for the `[[' conditional command (*note
6616 Conditional Constructs::.).
6618 `--enable-directory-stack'
6619 Include support for a `csh'-like directory stack and the `pushd',
6620 `popd', and `dirs' builtins (*note The Directory Stack::.).
6622 `--enable-disabled-builtins'
6623 Allow builtin commands to be invoked via `builtin xxx' even after
6624 `xxx' has been disabled using `enable -n xxx'. See *Note Bash
6625 Builtins::, for details of the `builtin' and `enable' builtin
6628 `--enable-dparen-arithmetic'
6629 Include support for the `((...))' command (*note Conditional
6632 `--enable-extended-glob'
6633 Include support for the extended pattern matching features
6634 described above under *Note Pattern Matching::.
6636 `--enable-help-builtin'
6637 Include the `help' builtin, which displays help on shell builtins
6641 Include command history and the `fc' and `history' builtin
6644 `--enable-job-control'
6645 This enables the job control features (*note Job Control::.), if
6646 the operating system supports them.
6648 `--enable-process-substitution'
6649 This enables process substitution (*note Process Substitution::.)
6650 if the operating system provides the necessary support.
6652 `--enable-prompt-string-decoding'
6653 Turn on the interpretation of a number of backslash-escaped
6654 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
6655 strings. See *Note Printing a Prompt::, for a complete list of
6656 prompt string escape sequences.
6659 Include support for command-line editing and history with the Bash
6660 version of the Readline library (*note Command Line Editing::.).
6662 `--enable-restricted'
6663 Include support for a "restricted shell". If this is enabled,
6664 Bash, when called as `rbash', enters a restricted mode. See *Note
6665 The Restricted Shell::, for a description of restricted mode.
6668 Include the `select' builtin, which allows the generation of simple
6669 menus (*note Conditional Constructs::.).
6671 `--enable-usg-echo-default'
6672 Make the `echo' builtin expand backslash-escaped characters by
6673 default, without requiring the `-e' option. This makes the Bash
6674 `echo' behave more like the System V version.
6676 The file `config.h.top' contains C Preprocessor `#define' statements
6677 for options which are not settable from `configure'. Some of these are
6678 not meant to be changed; beware of the consequences if you do. Read
6679 the comments associated with each definition for more information about
6683 File: bashref.info, Node: Reporting Bugs, Next: Builtin Index, Prev: Installing Bash, Up: Top
6688 Please report all bugs you find in Bash. But first, you should make
6689 sure that it really is a bug, and that it appears in the latest version
6690 of Bash that you have.
6692 Once you have determined that a bug actually exists, use the
6693 `bashbug' command to submit a bug report. If you have a fix, you are
6694 encouraged to mail that as well! Suggestions and `philosophical' bug
6695 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
6696 newsgroup `gnu.bash.bug'.
6698 All bug reports should include:
6699 * The version number of Bash.
6701 * The hardware and operating system.
6703 * The compiler used to compile Bash.
6705 * A description of the bug behaviour.
6707 * A short script or `recipe' which exercises the bug and may be used
6710 `bashbug' inserts the first three items automatically into the template
6711 it provides for filing a bug report.
6713 Please send all reports concerning this manual to <chet@po.CWRU.Edu>.
6716 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Prev: Reporting Bugs, Up: Top
6718 Index of Shell Builtin Commands
6719 *******************************
6723 * .: Bourne Shell Builtins.
6724 * :: Bourne Shell Builtins.
6725 * [: Bourne Shell Builtins.
6726 * alias: Alias Builtins.
6727 * bg: Job Control Builtins.
6728 * bind: Bash Builtins.
6729 * break: Bourne Shell Builtins.
6730 * builtin: Bash Builtins.
6731 * cd: Bourne Shell Builtins.
6732 * command: Bash Builtins.
6733 * continue: Bourne Shell Builtins.
6734 * declare: Bash Builtins.
6735 * dirs: The Directory Stack.
6736 * disown: Job Control Builtins.
6737 * echo: Bash Builtins.
6738 * enable: Bash Builtins.
6739 * eval: Bourne Shell Builtins.
6740 * exec: Bourne Shell Builtins.
6741 * exit: Bourne Shell Builtins.
6742 * export: Bourne Shell Builtins.
6743 * fc: Bash History Builtins.
6744 * fg: Job Control Builtins.
6745 * getopts: Bourne Shell Builtins.
6746 * hash: Bourne Shell Builtins.
6747 * help: Bash Builtins.
6748 * history: Bash History Builtins.
6749 * jobs: Job Control Builtins.
6750 * kill: Job Control Builtins.
6751 * let: Bash Builtins.
6752 * local: Bash Builtins.
6753 * logout: Bash Builtins.
6754 * popd: The Directory Stack.
6755 * printf: Bash Builtins.
6756 * pushd: The Directory Stack.
6757 * pwd: Bourne Shell Builtins.
6758 * read: Bash Builtins.
6759 * readonly: Bourne Shell Builtins.
6760 * return: Bourne Shell Builtins.
6761 * set: The Set Builtin.
6762 * shift: Bourne Shell Builtins.
6763 * shopt: Bash Builtins.
6764 * source: Bash Builtins.
6765 * suspend: Job Control Builtins.
6766 * test: Bourne Shell Builtins.
6767 * times: Bourne Shell Builtins.
6768 * trap: Bourne Shell Builtins.
6769 * type: Bash Builtins.
6770 * typeset: Bash Builtins.
6771 * ulimit: Bash Builtins.
6772 * umask: Bourne Shell Builtins.
6773 * unalias: Alias Builtins.
6774 * unset: Bourne Shell Builtins.
6775 * wait: Job Control Builtins.
6778 File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Top
6780 Shell Reserved Words
6781 ********************
6786 * [[: Conditional Constructs.
6787 * ]]: Conditional Constructs.
6788 * case: Conditional Constructs.
6789 * do: Looping Constructs.
6790 * done: Looping Constructs.
6791 * elif: Conditional Constructs.
6792 * else: Conditional Constructs.
6793 * esac: Conditional Constructs.
6794 * fi: Conditional Constructs.
6795 * for: Looping Constructs.
6796 * function: Shell Functions.
6797 * if: Conditional Constructs.
6798 * in: Conditional Constructs.
6799 * select: Conditional Constructs.
6800 * then: Conditional Constructs.
6802 * until: Looping Constructs.
6803 * while: Looping Constructs.
6804 * {: Command Grouping.
6805 * }: Command Grouping.
6808 File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Top
6810 Parameter and Variable Index
6811 ****************************
6815 * !: Special Parameters.
6816 * #: Special Parameters.
6817 * $: Special Parameters.
6818 * *: Special Parameters.
6819 * -: Special Parameters.
6820 * 0: Special Parameters.
6821 * ?: Special Parameters.
6822 * @: Special Parameters.
6823 * _: Special Parameters.
6824 * auto_resume: Job Control Variables.
6825 * BASH: Bash Variables.
6826 * BASH_ENV: Bash Variables.
6827 * BASH_VERSINFO: Bash Variables.
6828 * BASH_VERSION: Bash Variables.
6829 * bell-style: Readline Init File Syntax.
6830 * CDPATH: Bourne Shell Variables.
6831 * comment-begin: Readline Init File Syntax.
6832 * completion-query-items: Readline Init File Syntax.
6833 * convert-meta: Readline Init File Syntax.
6834 * DIRSTACK: Bash Variables.
6835 * disable-completion: Readline Init File Syntax.
6836 * editing-mode: Readline Init File Syntax.
6837 * enable-keypad: Readline Init File Syntax.
6838 * EUID: Bash Variables.
6839 * expand-tilde: Readline Init File Syntax.
6840 * FCEDIT: Bash Variables.
6841 * FIGNORE: Bash Variables.
6842 * GLOBIGNORE: Bash Variables.
6843 * GROUPS: Bash Variables.
6844 * histchars: Bash Variables.
6845 * HISTCMD: Bash Variables.
6846 * HISTCONTROL: Bash Variables.
6847 * HISTFILE: Bash Variables.
6848 * HISTFILESIZE: Bash Variables.
6849 * HISTIGNORE: Bash Variables.
6850 * HISTSIZE: Bash Variables.
6851 * HOME: Bourne Shell Variables.
6852 * horizontal-scroll-mode: Readline Init File Syntax.
6853 * HOSTFILE: Bash Variables.
6854 * HOSTNAME: Bash Variables.
6855 * HOSTTYPE: Bash Variables.
6856 * IFS: Bourne Shell Variables.
6857 * IGNOREEOF: Bash Variables.
6858 * input-meta: Readline Init File Syntax.
6859 * INPUTRC: Bash Variables.
6860 * keymap: Readline Init File Syntax.
6861 * LANG: Bash Variables.
6862 * LC_ALL: Bash Variables.
6863 * LC_COLLATE: Bash Variables.
6864 * LC_CTYPE: Bash Variables.
6865 * LC_MESSAGES: Bash Variables.
6866 * LINENO: Bash Variables.
6867 * MACHTYPE: Bash Variables.
6868 * MAIL: Bourne Shell Variables.
6869 * MAILCHECK: Bash Variables.
6870 * MAILPATH: Bourne Shell Variables.
6871 * mark-modified-lines: Readline Init File Syntax.
6872 * meta-flag: Readline Init File Syntax.
6873 * OLDPWD: Bash Variables.
6874 * OPTARG: Bourne Shell Variables.
6875 * OPTERR: Bash Variables.
6876 * OPTIND: Bourne Shell Variables.
6877 * OSTYPE: Bash Variables.
6878 * output-meta: Readline Init File Syntax.
6879 * PATH: Bourne Shell Variables.
6880 * PIPESTATUS: Bash Variables.
6881 * PPID: Bash Variables.
6882 * PROMPT_COMMAND: Bash Variables.
6883 * PS1: Bourne Shell Variables.
6884 * PS2: Bourne Shell Variables.
6885 * PS3: Bash Variables.
6886 * PS4: Bash Variables.
6887 * PWD: Bash Variables.
6888 * RANDOM: Bash Variables.
6889 * REPLY: Bash Variables.
6890 * SECONDS: Bash Variables.
6891 * SHELLOPTS: Bash Variables.
6892 * SHLVL: Bash Variables.
6893 * show-all-if-ambiguous: Readline Init File Syntax.
6894 * TIMEFORMAT: Bash Variables.
6895 * TMOUT: Bash Variables.
6896 * UID: Bash Variables.
6897 * visible-stats: Readline Init File Syntax.
6900 File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Top
6907 * abort (C-g): Miscellaneous Commands.
6908 * accept-line (Newline, Return): Commands For History.
6909 * backward-char (C-b): Commands For Moving.
6910 * backward-delete-char (Rubout): Commands For Text.
6911 * backward-kill-line (C-x Rubout): Commands For Killing.
6912 * backward-kill-word (M-DEL): Commands For Killing.
6913 * backward-word (M-b): Commands For Moving.
6914 * beginning-of-history (M-<): Commands For History.
6915 * beginning-of-line (C-a): Commands For Moving.
6916 * call-last-kbd-macro (C-x e): Keyboard Macros.
6917 * capitalize-word (M-c): Commands For Text.
6918 * character-search (C-]): Miscellaneous Commands.
6919 * character-search-backward (M-C-]): Miscellaneous Commands.
6920 * clear-screen (C-l): Commands For Moving.
6921 * complete (TAB): Commands For Completion.
6922 * copy-backward-word (): Commands For Killing.
6923 * copy-forward-word (): Commands For Killing.
6924 * copy-region-as-kill (): Commands For Killing.
6925 * delete-char (C-d): Commands For Text.
6926 * delete-horizontal-space (): Commands For Killing.
6927 * digit-argument (M-0, M-1, ... M--): Numeric Arguments.
6928 * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
6929 * downcase-word (M-l): Commands For Text.
6930 * dump-functions (): Miscellaneous Commands.
6931 * dump-macros (): Miscellaneous Commands.
6932 * dump-variables (): Miscellaneous Commands.
6933 * end-kbd-macro (C-x )): Keyboard Macros.
6934 * end-of-history (M->): Commands For History.
6935 * end-of-line (C-e): Commands For Moving.
6936 * exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
6937 * forward-char (C-f): Commands For Moving.
6938 * forward-search-history (C-s): Commands For History.
6939 * forward-word (M-f): Commands For Moving.
6940 * history-search-backward (): Commands For History.
6941 * history-search-forward (): Commands For History.
6942 * insert-comment (M-#): Miscellaneous Commands.
6943 * insert-completions (M-*): Commands For Completion.
6944 * kill-line (C-k): Commands For Killing.
6945 * kill-region (): Commands For Killing.
6946 * kill-whole-line (): Commands For Killing.
6947 * kill-word (M-d): Commands For Killing.
6948 * menu-complete (): Commands For Completion.
6949 * next-history (C-n): Commands For History.
6950 * non-incremental-forward-search-history (M-n): Commands For History.
6951 * non-incremental-reverse-search-history (M-p): Commands For History.
6952 * possible-completions (M-?): Commands For Completion.
6953 * prefix-meta (ESC): Miscellaneous Commands.
6954 * previous-history (C-p): Commands For History.
6955 * quoted-insert (C-q, C-v): Commands For Text.
6956 * re-read-init-file (C-x C-r): Miscellaneous Commands.
6957 * redraw-current-line (): Commands For Moving.
6958 * reverse-search-history (C-r): Commands For History.
6959 * revert-line (M-r): Miscellaneous Commands.
6960 * self-insert (a, b, A, 1, !, ...): Commands For Text.
6961 * set-mark (C-@): Miscellaneous Commands.
6962 * start-kbd-macro (C-x (): Keyboard Macros.
6963 * tilde-expand (M-~): Miscellaneous Commands.
6964 * transpose-chars (C-t): Commands For Text.
6965 * transpose-words (M-t): Commands For Text.
6966 * undo (C-_, C-x C-u): Miscellaneous Commands.
6967 * universal-argument (): Numeric Arguments.
6968 * unix-line-discard (C-u): Commands For Killing.
6969 * unix-word-rubout (C-w): Commands For Killing.
6970 * upcase-word (M-u): Commands For Text.
6971 * yank (C-y): Commands For Killing.
6972 * yank-last-arg (M-., M-_): Commands For History.
6973 * yank-nth-arg (M-C-y): Commands For History.
6974 * yank-pop (M-y): Commands For Killing.
6977 File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Top
6984 * alias expansion: Aliases.
6985 * arithmetic evaluation: Shell Arithmetic.
6986 * arithmetic expansion: Arithmetic Expansion.
6987 * arithmetic, shell: Shell Arithmetic.
6989 * background: Job Control Basics.
6990 * Bash configuration: Basic Installation.
6991 * Bash installation: Basic Installation.
6992 * Bourne shell: Basic Shell Features.
6993 * brace expansion: Brace Expansion.
6994 * builtin: Definitions.
6995 * command editing: Readline Bare Essentials.
6996 * command execution: Command Search and Execution.
6997 * command expansion: Simple Command Expansion.
6998 * command history: Bash History Facilities.
6999 * command search: Command Search and Execution.
7000 * command substitution: Command Substitution.
7001 * command timing: Pipelines.
7002 * commands, conditional: Conditional Constructs.
7003 * commands, grouping: Command Grouping.
7004 * commands, lists: Lists.
7005 * commands, looping: Looping Constructs.
7006 * commands, pipelines: Pipelines.
7007 * commands, shell: Shell Commands.
7008 * commands, simple: Simple Commands.
7009 * comments, shell: Comments.
7010 * configuration: Basic Installation.
7011 * control operator: Definitions.
7012 * directory stack: The Directory Stack.
7013 * editing command lines: Readline Bare Essentials.
7014 * environment: Environment.
7015 * evaluation, arithmetic: Shell Arithmetic.
7016 * event designators: Event Designators.
7017 * execution environment: Command Execution Environment.
7018 * exit status <1>: Exit Status.
7019 * exit status: Definitions.
7020 * expansion: Shell Expansions.
7021 * expansion, arithmetic: Arithmetic Expansion.
7022 * expansion, brace: Brace Expansion.
7023 * expansion, filename: Filename Expansion.
7024 * expansion, parameter: Shell Parameter Expansion.
7025 * expansion, pathname: Filename Expansion.
7026 * expansion, tilde: Tilde Expansion.
7027 * expressions, arithmetic: Shell Arithmetic.
7028 * expressions, conditional: Bash Conditional Expressions.
7029 * field: Definitions.
7030 * filename: Definitions.
7031 * filename expansion: Filename Expansion.
7032 * foreground: Job Control Basics.
7033 * functions, shell: Shell Functions.
7034 * history builtins: Bash History Builtins.
7035 * history events: Event Designators.
7036 * history expansion: History Interaction.
7037 * history list: Bash History Facilities.
7038 * History, how to use: Job Control Variables.
7039 * identifier: Definitions.
7040 * initialization file, readline: Readline Init File.
7041 * installation: Basic Installation.
7042 * interaction, readline: Readline Interaction.
7043 * interactive shell <1>: Is This Shell Interactive?.
7044 * interactive shell: Invoking Bash.
7046 * job control <1>: Definitions.
7047 * job control: Job Control Basics.
7048 * kill ring: Readline Killing Commands.
7049 * killing text: Readline Killing Commands.
7050 * localization: Locale Translation.
7051 * matching, pattern: Pattern Matching.
7052 * metacharacter: Definitions.
7053 * name: Definitions.
7054 * notation, readline: Readline Bare Essentials.
7055 * operator, shell: Definitions.
7056 * parameter expansion: Shell Parameter Expansion.
7057 * parameters: Shell Parameters.
7058 * parameters, positional: Positional Parameters.
7059 * parameters, special: Special Parameters.
7060 * pathname expansion: Filename Expansion.
7061 * pattern matching: Pattern Matching.
7062 * pipeline: Pipelines.
7063 * POSIX: Definitions.
7064 * POSIX Mode: Bash POSIX Mode.
7065 * process group: Definitions.
7066 * process group ID: Definitions.
7067 * process substitution: Process Substitution.
7068 * prompting: Printing a Prompt.
7070 * quoting, ANSI: ANSI-C Quoting.
7071 * Readline, how to use: Modifiers.
7072 * redirection: Redirections.
7073 * reserved word: Definitions.
7074 * restricted shell: The Restricted Shell.
7075 * return status: Definitions.
7076 * shell arithmetic: Shell Arithmetic.
7077 * shell function: Shell Functions.
7078 * shell script: Shell Scripts.
7079 * shell variable: Shell Parameters.
7080 * signal: Definitions.
7081 * signal handling: Signals.
7082 * special builtin: Definitions.
7083 * startup files: Bash Startup Files.
7084 * suspending jobs: Job Control Basics.
7085 * tilde expansion: Tilde Expansion.
7086 * token: Definitions.
7087 * variable, shell: Shell Parameters.
7088 * word: Definitions.
7089 * word splitting: Word Splitting.
7090 * yanking text: Readline Killing Commands.
7096 Node: Introduction
\7f3153
7097 Node: What is Bash?
\7f3378
7098 Node: What is a shell?
\7f4472
7099 Node: Definitions
\7f6494
7100 Node: Basic Shell Features
\7f9155
7101 Node: Shell Syntax
\7f10378
7102 Node: Shell Operation
\7f10667
7103 Node: Quoting
\7f11961
7104 Node: Escape Character
\7f12986
7105 Node: Single Quotes
\7f13458
7106 Node: Double Quotes
\7f13787
7107 Node: ANSI-C Quoting
\7f14685
7108 Node: Locale Translation
\7f15554
7109 Node: Comments
\7f15975
7110 Node: Shell Commands
\7f16589
7111 Node: Simple Commands
\7f17100
7112 Node: Pipelines
\7f17659
7114 Node: Looping Constructs
\7f20641
7115 Node: Conditional Constructs
\7f22246
7116 Node: Command Grouping
\7f28184
7117 Node: Shell Functions
\7f29561
7118 Node: Shell Parameters
\7f31525
7119 Node: Positional Parameters
\7f32851
7120 Node: Special Parameters
\7f33600
7121 Node: Shell Expansions
\7f36221
7122 Node: Brace Expansion
\7f38144
7123 Node: Tilde Expansion
\7f39705
7124 Node: Shell Parameter Expansion
\7f42037
7125 Node: Command Substitution
\7f48379
7126 Node: Arithmetic Expansion
\7f49653
7127 Node: Process Substitution
\7f50498
7128 Node: Word Splitting
\7f51392
7129 Node: Filename Expansion
\7f52844
7130 Node: Pattern Matching
\7f54808
7131 Node: Quote Removal
\7f57197
7132 Node: Redirections
\7f57483
7133 Node: Executing Commands
\7f63553
7134 Node: Simple Command Expansion
\7f64220
7135 Node: Command Search and Execution
\7f66143
7136 Node: Command Execution Environment
\7f68146
7137 Node: Environment
\7f70600
7138 Node: Exit Status
\7f72257
7139 Node: Signals
\7f73454
7140 Node: Shell Scripts
\7f75349
7141 Node: Bourne Shell Features
\7f77385
7142 Node: Bourne Shell Builtins
\7f78115
7143 Node: Bourne Shell Variables
\7f92056
7144 Node: Other Bourne Shell Features
\7f93761
7145 Node: Major Differences From The Bourne Shell
\7f94504
7146 Node: Bash Features
\7f106693
7147 Node: Invoking Bash
\7f107796
7148 Node: Bash Startup Files
\7f111981
7149 Node: Is This Shell Interactive?
\7f115540
7150 Node: Bash Builtins
\7f116511
7151 Node: The Set Builtin
\7f137351
7152 Node: Bash Conditional Expressions
\7f143960
7153 Node: Bash Variables
\7f147033
7154 Node: Shell Arithmetic
\7f159463
7155 Node: Aliases
\7f161511
7156 Node: Alias Builtins
\7f164086
7157 Node: Arrays
\7f164702
7158 Node: The Directory Stack
\7f167723
7159 Node: Printing a Prompt
\7f171073
7160 Node: The Restricted Shell
\7f172736
7161 Node: Bash POSIX Mode
\7f174072
7162 Node: Job Control
\7f178233
7163 Node: Job Control Basics
\7f178699
7164 Node: Job Control Builtins
\7f182898
7165 Node: Job Control Variables
\7f187190
7166 Node: Using History Interactively
\7f188340
7167 Node: Bash History Facilities
\7f189019
7168 Node: Bash History Builtins
\7f191360
7169 Node: History Interaction
\7f194728
7170 Node: Event Designators
\7f197280
7171 Node: Word Designators
\7f198207
7172 Node: Modifiers
\7f199456
7173 Node: Command Line Editing
\7f200773
7174 Node: Introduction and Notation
\7f201433
7175 Node: Readline Interaction
\7f202471
7176 Node: Readline Bare Essentials
\7f203663
7177 Node: Readline Movement Commands
\7f205203
7178 Node: Readline Killing Commands
\7f206168
7179 Node: Readline Arguments
\7f207883
7180 Node: Searching
\7f208857
7181 Node: Readline Init File
\7f210475
7182 Node: Readline Init File Syntax
\7f211514
7183 Node: Conditional Init Constructs
\7f220379
7184 Node: Sample Init File
\7f222817
7185 Node: Bindable Readline Commands
\7f225986
7186 Node: Commands For Moving
\7f226736
7187 Node: Commands For History
\7f227583
7188 Node: Commands For Text
\7f230412
7189 Node: Commands For Killing
\7f232146
7190 Node: Numeric Arguments
\7f234295
7191 Node: Commands For Completion
\7f235421
7192 Node: Keyboard Macros
\7f238991
7193 Node: Miscellaneous Commands
\7f239549
7194 Node: Readline vi Mode
\7f243869
7195 Node: Installing Bash
\7f244747
7196 Node: Basic Installation
\7f245824
7197 Node: Compilers and Options
\7f248734
7198 Node: Compiling For Multiple Architectures
\7f249468
7199 Node: Installation Names
\7f251125
7200 Node: Specifying the System Type
\7f251850
7201 Node: Sharing Defaults
\7f252554
7202 Node: Operation Controls
\7f253219
7203 Node: Optional Features
\7f254124
7204 Node: Reporting Bugs
\7f260319
7205 Node: Builtin Index
\7f261390
7206 Node: Reserved Word Index
\7f264793
7207 Node: Variable Index
\7f266251
7208 Node: Function Index
\7f271456
7209 Node: Concept Index
\7f275885