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.3, last updated 20 January 1999,
13 of `The GNU Bash Reference Manual',
14 for `Bash', Version 2.03.
16 Copyright (C) 1991-1999 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.3, last updated 20 January 1999, of `The GNU Bash
42 Reference Manual', for `Bash', Version 2.03.
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 the expanded value of
1236 PARAMETER. If PATTERN begins with `%', it must match at the end
1237 of the expanded value of PARAMETER. If STRING is null, matches of
1238 PATTERN are deleted and the `/' following PATTERN may be omitted.
1239 If PARAMETER is `@' or `*', the substitution operation is applied
1240 to each positional parameter in turn, and the expansion is the
1241 resultant list. If PARAMETER is an array variable subscripted
1242 with `@' or `*', the substitution operation is applied to each
1243 member of the array in turn, and the expansion is the resultant
1247 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1249 Command Substitution
1250 --------------------
1252 Command substitution allows the output of a command to replace the
1253 command name. There are two forms:
1259 Bash performs the expansion by executing COMMAND and replacing the
1260 command substitution with the standard output of the command, with any
1261 trailing newlines deleted. Embedded newlines are not deleted, but they
1262 may be removed during word splitting. The command substitution `$(cat
1263 FILE)' can be replaced by the equivalent but faster `$(< FILE)'.
1265 When the old-style backquote form of substitution is used, backslash
1266 retains its literal meaning except when followed by `$', ``', or `\'.
1267 The first backquote not preceded by a backslash terminates the command
1268 substitution. When using the `$(COMMAND)' form, all characters between
1269 the parentheses make up the command; none are treated specially.
1271 Command substitutions may be nested. To nest when using the
1272 backquoted form, escape the inner backquotes with backslashes.
1274 If the substitution appears within double quotes, word splitting and
1275 filename expansion are not performed on the results.
1278 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1280 Arithmetic Expansion
1281 --------------------
1283 Arithmetic expansion allows the evaluation of an arithmetic
1284 expression and the substitution of the result. The format for
1285 arithmetic expansion is:
1289 The expression is treated as if it were within double quotes, but a
1290 double quote inside the parentheses is not treated specially. All
1291 tokens in the expression undergo parameter expansion, command
1292 substitution, and quote removal. Arithmetic substitutions may be
1295 The evaluation is performed according to the rules listed below
1296 (*note Shell Arithmetic::.). If the expression is invalid, Bash prints
1297 a message indicating failure to the standard error and no substitution
1301 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1303 Process Substitution
1304 --------------------
1306 Process substitution is supported on systems that support named
1307 pipes (FIFOs) or the `/dev/fd' method of naming open files. It takes
1314 The process LIST is run with its input or output connected to a FIFO or
1315 some file in `/dev/fd'. The name of this file is passed as an argument
1316 to the current command as the result of the expansion. If the
1317 `>(LIST)' form is used, writing to the file will provide input for
1318 LIST. If the `<(LIST)' form is used, the file passed as an argument
1319 should be read to obtain the output of LIST.
1321 When available, process substitution is performed simultaneously with
1322 parameter and variable expansion, command substitution, and arithmetic
1326 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1331 The shell scans the results of parameter expansion, command
1332 substitution, and arithmetic expansion that did not occur within double
1333 quotes for word splitting.
1335 The shell treats each character of `$IFS' as a delimiter, and splits
1336 the results of the other expansions into words on these characters. If
1337 `IFS' is unset, or its value is exactly `<space><tab><newline>', the
1338 default, then any sequence of `IFS' characters serves to delimit words.
1339 If `IFS' has a value other than the default, then sequences of the
1340 whitespace characters `space' and `tab' are ignored at the beginning
1341 and end of the word, as long as the whitespace character is in the
1342 value of `IFS' (an `IFS' whitespace character). Any character in `IFS'
1343 that is not `IFS' whitespace, along with any adjacent `IFS' whitespace
1344 characters, delimits a field. A sequence of `IFS' whitespace
1345 characters is also treated as a delimiter. If the value of `IFS' is
1346 null, no word splitting occurs.
1348 Explicit null arguments (`""' or `''') are retained. Unquoted
1349 implicit null arguments, resulting from the expansion of PARAMETERs
1350 that have no values, are removed. If a parameter with no value is
1351 expanded within double quotes, a null argument results and is retained.
1353 Note that if no expansion occurs, no splitting is performed.
1356 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
1363 * Pattern Matching:: How the shell matches patterns.
1365 After word splitting, unless the `-f' option has been set (*note The
1366 Set Builtin::.), Bash scans each word for the characters `*', `?', `(',
1367 and `['. If one of these characters appears, then the word is regarded
1368 as a PATTERN, and replaced with an alphabetically sorted list of file
1369 names matching the pattern. If no matching file names are found, and
1370 the shell option `nullglob' is disabled, the word is left unchanged.
1371 If the `nullglob' option is set, and no matches are found, the word is
1372 removed. If the shell option `nocaseglob' is enabled, the match is
1373 performed without regard to the case of alphabetic characters.
1375 When a pattern is used for filename generation, the character `.' at
1376 the start of a filename or immediately following a slash must be
1377 matched explicitly, unless the shell option `dotglob' is set. When
1378 matching a file name, the slash character must always be matched
1379 explicitly. In other cases, the `.' character is not treated specially.
1381 See the description of `shopt' in *Note Bash Builtins::, for a
1382 description of the `nocaseglob', `nullglob', and `dotglob' options.
1384 The `GLOBIGNORE' shell variable may be used to restrict the set of
1385 filenames matching a pattern. If `GLOBIGNORE' is set, each matching
1386 filename that also matches one of the patterns in `GLOBIGNORE' is
1387 removed from the list of matches. The filenames `.' and `..' are
1388 always ignored, even when `GLOBIGNORE' is set. However, setting
1389 `GLOBIGNORE' has the effect of enabling the `dotglob' shell option, so
1390 all other filenames beginning with a `.' will match. To get the old
1391 behavior of ignoring filenames beginning with a `.', make `.*' one of
1392 the patterns in `GLOBIGNORE'. The `dotglob' option is disabled when
1393 `GLOBIGNORE' is unset.
1396 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
1401 Any character that appears in a pattern, other than the special
1402 pattern characters described below, matches itself. The NUL character
1403 may not occur in a pattern. The special pattern characters must be
1404 quoted if they are to be matched literally.
1406 The special pattern characters have the following meanings:
1408 Matches any string, including the null string.
1411 Matches any single character.
1414 Matches any one of the enclosed characters. A pair of characters
1415 separated by a minus sign denotes a RANGE; any character lexically
1416 between those two characters, inclusive, is matched. If the first
1417 character following the `[' is a `!' or a `^' then any character
1418 not enclosed is matched. A `-' may be matched by including it as
1419 the first or last character in the set. A `]' may be matched by
1420 including it as the first character in the set.
1422 Within `[' and `]', CHARACTER CLASSES can be specified using the
1423 syntax `[:'CLASS`:]', where CLASS is one of the following classes
1424 defined in the POSIX.2 standard:
1425 alnum alpha ascii blank cntrl digit graph lower
1426 print punct space upper xdigit
1428 A character class matches any character belonging to that class.
1430 Within `[' and `]', an EQUIVALENCE CLASS can be specified using
1431 the syntax `[='C`=]', which matches all characters with the same
1432 collation weight (as defined by the current locale) as the
1435 Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the
1436 collating symbol SYMBOL.
1438 If the `extglob' shell option is enabled using the `shopt' builtin,
1439 several extended pattern matching operators are recognized. In the
1440 following description, a PATTERN-LIST is a list of one or more patterns
1441 separated by a `|'. Composite patterns may be formed using one or more
1442 of the following sub-patterns:
1445 Matches zero or one occurrence of the given patterns.
1448 Matches zero or more occurrences of the given patterns.
1451 Matches one or more occurrences of the given patterns.
1454 Matches exactly one of the given patterns.
1457 Matches anything except one of the given patterns.
1460 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
1465 After the preceding expansions, all unquoted occurrences of the
1466 characters `\', `'', and `"' that did not result from one of the above
1467 expansions are removed.
1470 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
1475 Before a command is executed, its input and output may be REDIRECTED
1476 using a special notation interpreted by the shell. Redirection may
1477 also be used to open and close files for the current shell execution
1478 environment. The following redirection operators may precede or appear
1479 anywhere within a simple command or may follow a command. Redirections
1480 are processed in the order they appear, from left to right.
1482 In the following descriptions, if the file descriptor number is
1483 omitted, and the first character of the redirection operator is `<',
1484 the redirection refers to the standard input (file descriptor 0). If
1485 the first character of the redirection operator is `>', the redirection
1486 refers to the standard output (file descriptor 1).
1488 The word following the redirection operator in the following
1489 descriptions, unless otherwise noted, is subjected to brace expansion,
1490 tilde expansion, parameter expansion, command substitution, arithmetic
1491 expansion, quote removal, and filename expansion. If it expands to
1492 more than one word, Bash reports an error.
1494 Note that the order of redirections is significant. For example,
1498 directs both standard output and standard error to the file DIRLIST,
1502 directs only the standard output to file DIRLIST, because the standard
1503 error was duplicated as standard output before the standard output was
1504 redirected to DIRLIST.
1506 A failure to open or create a file causes the redirection to fail.
1511 Redirection of input causes the file whose name results from the
1512 expansion of WORD to be opened for reading on file descriptor `n', or
1513 the standard input (file descriptor 0) if `n' is not specified.
1515 The general format for redirecting input is:
1521 Redirection of output causes the file whose name results from the
1522 expansion of WORD to be opened for writing on file descriptor `n', or
1523 the standard output (file descriptor 1) if `n' is not specified. If
1524 the file does not exist it is created; if it does exist it is truncated
1527 The general format for redirecting output is:
1530 If the redirection operator is `>', and the `noclobber' option to
1531 the `set' builtin has been enabled, the redirection will fail if the
1532 filename whose name results from the expansion of WORD exists and is a
1533 regular file. If the redirection operator is `>|', or the redirection
1534 operator is `>' and the `noclobber' option is not enabled, the
1535 redirection is attempted even if the file named by WORD exists.
1537 Appending Redirected Output
1538 ---------------------------
1540 Redirection of output in this fashion causes the file whose name
1541 results from the expansion of WORD to be opened for appending on file
1542 descriptor `n', or the standard output (file descriptor 1) if `n' is
1543 not specified. If the file does not exist it is created.
1545 The general format for appending output is:
1548 Redirecting Standard Output and Standard Error
1549 ----------------------------------------------
1551 Bash allows both the standard output (file descriptor 1) and the
1552 standard error output (file descriptor 2) to be redirected to the file
1553 whose name is the expansion of WORD with this construct.
1555 There are two formats for redirecting standard output and standard
1562 Of the two forms, the first is preferred. This is semantically
1569 This type of redirection instructs the shell to read input from the
1570 current source until a line containing only WORD (with no trailing
1571 blanks) is seen. All of the lines read up to that point are then used
1572 as the standard input for a command.
1574 The format of here-documents is as follows:
1579 No parameter expansion, command substitution, filename expansion, or
1580 arithmetic expansion is performed on WORD. If any characters in WORD
1581 are quoted, the DELIMITER is the result of quote removal on WORD, and
1582 the lines in the here-document are not expanded. If WORD is unquoted,
1583 all lines of the here-document are subjected to parameter expansion,
1584 command substitution, and arithmetic expansion. In the latter case,
1585 the pair `\newline' is ignored, and `\' must be used to quote the
1586 characters `\', `$', and ``'.
1588 If the redirection operator is `<<-', then all leading tab
1589 characters are stripped from input lines and the line containing
1590 DELIMITER. This allows here-documents within shell scripts to be
1591 indented in a natural fashion.
1593 Duplicating File Descriptors
1594 ----------------------------
1596 The redirection operator
1599 is used to duplicate input file descriptors. If WORD expands to one or
1600 more digits, the file descriptor denoted by `n' is made to be a copy of
1601 that file descriptor. If the digits in WORD do not specify a file
1602 descriptor open for input, a redirection error occurs. If WORD
1603 evaluates to `-', file descriptor `n' is closed. If `n' is not
1604 specified, the standard input (file descriptor 0) is used.
1609 is used similarly to duplicate output file descriptors. If `n' is not
1610 specified, the standard output (file descriptor 1) is used. If the
1611 digits in WORD do not specify a file descriptor open for output, a
1612 redirection error occurs. As a special case, if `n' is omitted, and
1613 WORD does not expand to one or more digits, the standard output and
1614 standard error are redirected as described previously.
1616 Opening File Descriptors for Reading and Writing
1617 ------------------------------------------------
1619 The redirection operator
1622 causes the file whose name is the expansion of WORD to be opened for
1623 both reading and writing on file descriptor `n', or on file descriptor
1624 0 if `n' is not specified. If the file does not exist, it is created.
1627 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
1634 * Simple Command Expansion:: How Bash expands simple commands before
1637 * Command Search and Execution:: How Bash finds commands and runs them.
1639 * Command Execution Environment:: The environment in which Bash
1640 executes commands that are not
1643 * Environment:: The environment given to a command.
1645 * Exit Status:: The status returned by commands and how Bash
1648 * Signals:: What happens when Bash or a command it runs
1652 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
1654 Simple Command Expansion
1655 ------------------------
1657 When a simple command is executed, the shell performs the following
1658 expansions, assignments, and redirections, from left to right.
1660 1. The words that the parser has marked as variable assignments (those
1661 preceding the command name) and redirections are saved for later
1664 2. The words that are not variable assignments or redirections are
1665 expanded (*note Shell Expansions::.). If any words remain after
1666 expansion, the first word is taken to be the name of the command
1667 and the remaining words are the arguments.
1669 3. Redirections are performed as described above (*note
1672 4. The text after the `=' in each variable assignment undergoes tilde
1673 expansion, parameter expansion, command substitution, arithmetic
1674 expansion, and quote removal before being assigned to the variable.
1676 If no command name results, the variable assignments affect the
1677 current shell environment. Otherwise, the variables are added to the
1678 environment of the executed command and do not affect the current shell
1679 environment. If any of the assignments attempts to assign a value to a
1680 readonly variable, an error occurs, and the command exits with a
1683 If no command name results, redirections are performed, but do not
1684 affect the current shell environment. A redirection error causes the
1685 command to exit with a non-zero status.
1687 If there is a command name left after expansion, execution proceeds
1688 as described below. Otherwise, the command exits. If one of the
1689 expansions contained a command substitution, the exit status of the
1690 command is the exit status of the last command substitution performed.
1691 If there were no command substitutions, the command exits with a status
1695 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
1697 Command Search and Execution
1698 ----------------------------
1700 After a command has been split into words, if it results in a simple
1701 command and an optional list of arguments, the following actions are
1704 1. If the command name contains no slashes, the shell attempts to
1705 locate it. If there exists a shell function by that name, that
1706 function is invoked as described above in *Note Shell Functions::.
1708 2. If the name does not match a function, the shell searches for it
1709 in the list of shell builtins. If a match is found, that builtin
1712 3. If the name is neither a shell function nor a builtin, and
1713 contains no slashes, Bash searches each element of `$PATH' for a
1714 directory containing an executable file by that name. Bash uses a
1715 hash table to remember the full pathnames of executable files to
1716 avoid multiple `PATH' searches (see the description of `hash' in
1717 *Note Bourne Shell Builtins::). A full search of the directories
1718 in `$PATH' is performed only if the command is not found in the
1719 hash table. If the search is unsuccessful, the shell prints an
1720 error message and returns an exit status of 127.
1722 4. If the search is successful, or if the command name contains one
1723 or more slashes, the shell executes the named program in a
1724 separate execution environment. Argument 0 is set to the name
1725 given, and the remaining arguments to the command are set to the
1726 arguments supplied, if any.
1728 5. If this execution fails because the file is not in executable
1729 format, and the file is not a directory, it is assumed to be a
1730 SHELL SCRIPT and the shell executes it as described in *Note Shell
1733 6. If the command was not begun asynchronously, the shell waits for
1734 the command to complete and collects its exit status.
1738 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
1740 Command Execution Environment
1741 -----------------------------
1743 The shell has an EXECUTION ENVIRONMENT, which consists of the
1746 * open files inherited by the shell at invocation, as modified by
1747 redirections supplied to the `exec' builtin
1749 * the current working directory as set by `cd', `pushd', or `popd',
1750 or inherited by the shell at invocation
1752 * the file creation mode mask as set by `umask' or inherited from
1755 * current traps set by `trap'
1757 * shell parameters that are set by variable assignment or with `set'
1758 or inherited from the shell's parent in the environment
1760 * shell functions defined during execution or inherited from the
1761 shell's parent in the environment
1763 * options enabled at invocation (either by default or with
1764 command-line arguments) or by `set'
1766 * options enabled by `shopt'
1768 * shell aliases defined with `alias' (*note Aliases::.)
1770 * various process IDs, including those of background jobs (*note
1771 Lists::.), the value of `$$', and the value of `$PPID'
1773 When a simple command other than a builtin or shell function is to
1774 be executed, it is invoked in a separate execution environment that
1775 consists of the following. Unless otherwise noted, the values are
1776 inherited from the shell.
1778 * the shell's open files, plus any modifications and additions
1779 specified by redirections to the command
1781 * the current working directory
1783 * the file creation mode mask
1785 * shell variables marked for export, along with variables exported
1786 for the command, passed in the environment (*note Environment::.)
1788 * traps caught by the shell are reset to the values inherited from
1789 the shell's parent, and traps ignored by the shell are ignored
1791 A command invoked in this separate environment cannot affect the
1792 shell's execution environment.
1794 Command substitution and asynchronous commands are invoked in a
1795 subshell environment that is a duplicate of the shell environment,
1796 except that traps caught by the shell are reset to the values that the
1797 shell inherited from its parent at invocation. Builtin commands that
1798 are invoked as part of a pipeline are also executed in a subshell
1799 environment. Changes made to the subshell environment cannot affect
1800 the shell's execution environment.
1803 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
1808 When a program is invoked it is given an array of strings called the
1809 ENVIRONMENT. This is a list of name-value pairs, of the form
1812 Bash allows you to manipulate the environment in several ways. On
1813 invocation, the shell scans its own environment and creates a parameter
1814 for each name found, automatically marking it for EXPORT to child
1815 processes. Executed commands inherit the environment. The `export'
1816 and `declare -x' commands allow parameters and functions to be added to
1817 and deleted from the environment. If the value of a parameter in the
1818 environment is modified, the new value becomes part of the environment,
1819 replacing the old. The environment inherited by any executed command
1820 consists of the shell's initial environment, whose values may be
1821 modified in the shell, less any pairs removed by the `unset' and
1822 `export -n' commands, plus any additions via the `export' and `declare
1825 The environment for any simple command or function may be augmented
1826 temporarily by prefixing it with parameter assignments, as described in
1827 *Note Shell Parameters::. These assignment statements affect only the
1828 environment seen by that command.
1830 If the `-k' option is set (*note The Set Builtin::.), then all
1831 parameter assignments are placed in the environment for a command, not
1832 just those that precede the command name.
1834 When Bash invokes an external command, the variable `$_' is set to
1835 the full path name of the command and passed to that command in its
1839 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
1844 For the shell's purposes, a command which exits with a zero exit
1845 status has succeeded. A non-zero exit status indicates failure. This
1846 seemingly counter-intuitive scheme is used so there is one well-defined
1847 way to indicate success and a variety of ways to indicate various
1848 failure modes. When a command terminates on a fatal signal whose
1849 number is N, Bash uses the value 128+N as the exit status.
1851 If a command is not found, the child process created to execute it
1852 returns a status of 127. If a command is found but is not executable,
1853 the return status is 126.
1855 If a command fails because of an error during expansion or
1856 redirection, the exit status is greater than zero.
1858 The exit status is used by the Bash conditional commands (*note
1859 Conditional Constructs::.) and some of the list constructs (*note
1862 All of the Bash builtins return an exit status of zero if they
1863 succeed and a non-zero status on failure, so they may be used by the
1864 conditional and list constructs. All builtins return an exit status of
1865 2 to indicate incorrect usage.
1868 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
1873 When Bash is interactive, in the absence of any traps, it ignores
1874 `SIGTERM' (so that `kill 0' does not kill an interactive shell), and
1875 `SIGINT' is caught and handled (so that the `wait' builtin is
1876 interruptible). When Bash receives a `SIGINT', it breaks out of any
1877 executing loops. In all cases, Bash ignores `SIGQUIT'. If job control
1878 is in effect (*note Job Control::.), Bash ignores `SIGTTIN', `SIGTTOU',
1881 Commands started by Bash have signal handlers set to the values
1882 inherited by the shell from its parent. When job control is not in
1883 effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' as well.
1884 Commands run as a result of command substitution ignore the
1885 keyboard-generated job control signals `SIGTTIN', `SIGTTOU', and
1888 The shell exits by default upon receipt of a `SIGHUP'. Before
1889 exiting, it resends the `SIGHUP' to all jobs, running or stopped.
1890 Stopped jobs are sent `SIGCONT' to ensure that they receive the
1891 `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to a
1892 particular job, it should be removed from the jobs table with the
1893 `disown' builtin (*note Job Control Builtins::.) or marked to not
1894 receive `SIGHUP' using `disown -h'.
1896 If the `huponexit' shell option has been set with `shopt' (*note
1897 Bash Builtins::.), Bash sends a `SIGHUP' to all jobs when an
1898 interactive login shell exits.
1900 When Bash receives a signal for which a trap has been set while
1901 waiting for a command to complete, the trap will not be executed until
1902 the command completes. When Bash is waiting for an asynchronous
1903 command via the `wait' builtin, the reception of a signal for which a
1904 trap has been set will cause the `wait' builtin to return immediately
1905 with an exit status greater than 128, immediately after which the trap
1909 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
1914 A shell script is a text file containing shell commands. When such
1915 a file is used as the first non-option argument when invoking Bash, and
1916 neither the `-c' nor `-s' option is supplied (*note Invoking Bash::.),
1917 Bash reads and executes commands from the file, then exits. This mode
1918 of operation creates a non-interactive shell. When Bash runs a shell
1919 script, it sets the special parameter `0' to the name of the file,
1920 rather than the name of the shell, and the positional parameters are
1921 set to the remaining arguments, if any are given. If no additional
1922 arguments are supplied, the positional parameters are unset.
1924 A shell script may be made executable by using the `chmod' command
1925 to turn on the execute bit. When Bash finds such a file while
1926 searching the `$PATH' for a command, it spawns a subshell to execute
1927 it. In other words, executing
1930 is equivalent to executing
1931 bash filename ARGUMENTS
1933 if `filename' is an executable shell script. This subshell
1934 reinitializes itself, so that the effect is as if a new shell had been
1935 invoked to interpret the script, with the exception that the locations
1936 of commands remembered by the parent (see the description of `hash' in
1937 *Note Bourne Shell Builtins::) are retained by the child.
1939 Most versions of Unix make this a part of the kernel's command
1940 execution mechanism. If the first line of a script begins with the two
1941 characters `#!', the remainder of the line specifies an interpreter for
1942 the program. The arguments to the interpreter consist of a single
1943 optional argument following the interpreter name on the first line of
1944 the script file, followed by the name of the script file, followed by
1945 the rest of the arguments. Bash will perform this action on operating
1946 systems that do not handle it themselves. Note that some older
1947 versions of Unix limit the interpreter name and argument to a maximum
1951 File: bashref.info, Node: Bourne Shell Features, Next: Bash Features, Prev: Basic Shell Features, Up: Top
1953 Bourne Shell Style Features
1954 ***************************
1958 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
1960 * Bourne Shell Variables:: Variables which Bash uses in the same way
1961 as the Bourne Shell.
1962 * Other Bourne Shell Features:: Addtional aspects of Bash which behave in
1963 the same way as the Bourne Shell.
1965 This section briefly summarizes things which Bash inherits from the
1966 Bourne Shell: builtins, variables, and other features. It also lists
1967 the significant differences between Bash and the Bourne Shell. Many of
1968 the builtins have been extended by POSIX or Bash.
1971 File: bashref.info, Node: Bourne Shell Builtins, Next: Bourne Shell Variables, Up: Bourne Shell Features
1973 Bourne Shell Builtins
1974 =====================
1976 The following shell builtin commands are inherited from the Bourne
1977 Shell. These commands are implemented as specified by the POSIX 1003.2
1982 Do nothing beyond expanding ARGUMENTS and performing redirections.
1983 The return status is zero.
1986 . FILENAME [ARGUMENTS]
1987 Read and execute commands from the FILENAME argument in the
1988 current shell context. If FILENAME does not contain a slash, the
1989 `$PATH' variable is used to find FILENAME. The current directory
1990 is searched if FILENAME is not found in `$PATH'. If any ARGUMENTS
1991 are supplied, they become the positional parameters when FILENAME
1992 is executed. Otherwise the positional parameters are unchanged.
1993 The return status is the exit status of the last command executed,
1994 or zero if no commands are executed. If FILENAME is not found, or
1995 cannot be read, the return status is non-zero.
1999 Exit from a `for', `while', `until', or `select' loop. If N is
2000 supplied, the Nth enclosing loop is exited. N must be greater
2001 than or equal to 1. The return status is zero unless N is not
2002 greater than or equal to 1.
2005 cd [-LP] [DIRECTORY]
2006 Change the current working directory to DIRECTORY. If DIRECTORY
2007 is not given, the value of the `HOME' shell variable is used. If
2008 the shell variable `CDPATH' exists, it is used as a search path.
2009 If DIRECTORY begins with a slash, `CDPATH' is not used. The `-P'
2010 option means to not follow symbolic links; symbolic links are
2011 followed by default or with the `-L' option. If DIRECTORY is `-',
2012 it is equivalent to `$OLDPWD'. The return status is zero if the
2013 directory is successfully changed, non-zero otherwise.
2017 Resume the next iteration of an enclosing `for', `while', `until',
2018 or `select' loop. If N is supplied, the execution of the Nth
2019 enclosing loop is resumed. N must be greater than or equal to 1.
2020 The return status is zero unless N is not greater than or equal to
2025 The arguments are concatenated together into a single command,
2026 which is then read and executed, and its exit status returned as
2027 the exit status of `eval'. If there are no arguments or only
2028 empty arguments, the return status is zero.
2031 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2032 If COMMAND is supplied, it replaces the shell without creating a
2033 new process. If the `-l' option is supplied, the shell places a
2034 dash in the zeroth arg passed to COMMAND. This is what the
2035 `login' program does. The `-c' option causes COMMAND to be
2036 executed with an empty environment. If `-a' is supplied, the
2037 shell passes NAME as the zeroth argument to COMMAND. If no
2038 COMMAND is specified, redirections may be used to affect the
2039 current shell environment. If there are no redirection errors, the
2040 return status is zero; otherwise the return status is non-zero.
2044 Exit the shell, returning a status of N to the shell's parent.
2045 Any trap on `EXIT' is executed before the shell terminates.
2048 export [-fn] [-p] [NAME[=VALUE]]
2049 Mark each NAME to be passed to child processes in the environment.
2050 If the `-f' option is supplied, the NAMEs refer to shell
2051 functions; otherwise the names refer to shell variables. The `-n'
2052 option means to no longer mark each NAME for export. If no NAMES
2053 are supplied, or if the `-p' option is given, a list of exported
2054 names is displayed. The `-p' option displays output in a form
2055 that may be reused as input. The return status is zero unless an
2056 invalid option is supplied, one of the names is not a valid shell
2057 variable name, or `-f' is supplied with a name that is not a shell
2061 getopts OPTSTRING NAME [ARGS]
2062 `getopts' is used by shell scripts to parse positional parameters.
2063 OPTSTRING contains the option letters to be recognized; if a letter
2064 is followed by a colon, the option is expected to have an
2065 argument, which should be separated from it by white space. Each
2066 time it is invoked, `getopts' places the next option in the shell
2067 variable NAME, initializing NAME if it does not exist, and the
2068 index of the next argument to be processed into the variable
2069 `OPTIND'. `OPTIND' is initialized to 1 each time the shell or a
2070 shell script is invoked. When an option requires an argument,
2071 `getopts' places that argument into the variable `OPTARG'. The
2072 shell does not reset `OPTIND' automatically; it must be manually
2073 reset between multiple calls to `getopts' within the same shell
2074 invocation if a new set of parameters is to be used.
2076 When the end of options is encountered, `getopts' exits with a
2077 return value greater than zero. `OPTIND' is set to the index of
2078 the first non-option argument, and `name' is set to `?'.
2080 `getopts' normally parses the positional parameters, but if more
2081 arguments are given in ARGS, `getopts' parses those instead.
2083 `getopts' can report errors in two ways. If the first character of
2084 OPTSTRING is a colon, SILENT error reporting is used. In normal
2085 operation diagnostic messages are printed when invalid options or
2086 missing option arguments are encountered. If the variable `OPTERR'
2087 is set to 0, no error messages will be displayed, even if the first
2088 character of `optstring' is not a colon.
2090 If an invalid option is seen, `getopts' places `?' into NAME and,
2091 if not silent, prints an error message and unsets `OPTARG'. If
2092 `getopts' is silent, the option character found is placed in
2093 `OPTARG' and no diagnostic message is printed.
2095 If a required argument is not found, and `getopts' is not silent,
2096 a question mark (`?') is placed in NAME, `OPTARG' is unset, and a
2097 diagnostic message is printed. If `getopts' is silent, then a
2098 colon (`:') is placed in NAME and `OPTARG' is set to the option
2102 hash [-r] [-p FILENAME] [NAME]
2103 Remember the full pathnames of commands specified as NAME
2104 arguments, so they need not be searched for on subsequent
2105 invocations. The commands are found by searching through the
2106 directories listed in `$PATH'. The `-p' option inhibits the path
2107 search, and FILENAME is used as the location of NAME. The `-r'
2108 option causes the shell to forget all remembered locations. If no
2109 arguments are given, information about remembered commands is
2110 printed. The return status is zero unless a NAME is not found or
2111 an invalid option is supplied.
2115 Print the current working directory. If the `-P' option is
2116 supplied, the path printed will not contain symbolic links. If
2117 the `-L' option is supplied, the path printed may contain symbolic
2118 links. The return status is zero unless an error is encountered
2119 while determining the name of the current directory or an invalid
2123 readonly [-apf] [NAME] ...
2124 Mark each NAME as readonly. The values of these names may not be
2125 changed by subsequent assignment. If the `-f' option is supplied,
2126 each NAME refers to a shell function. The `-a' option means each
2127 NAME refers to an array variable. If no NAME arguments are given,
2128 or if the `-p' option is supplied, a list of all readonly names is
2129 printed. The `-p' option causes output to be displayed in a
2130 format that may be reused as input. The return status is zero
2131 unless an invalid option is supplied, one of the NAME arguments is
2132 not a valid shell variable or function name, or the `-f' option is
2133 supplied with a name that is not a shell function.
2137 Cause a shell function to exit with the return value N. This may
2138 also be used to terminate execution of a script being executed
2139 with the `.' builtin, returning either N or the exit status of the
2140 last command executed within the script as the exit status of the
2141 script. The return status is false if `return' is used outside a
2142 function and not during the execution of a script by `.'.
2146 Shift the positional parameters to the left by N. The positional
2147 parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N+1.
2148 Parameters represented by the numbers `$#' to N+1 are unset. N
2149 must be a non-negative number less than or equal to `$#'. If N is
2150 zero or greater than `$#', the positional parameters are not
2151 changed. The return status is zero unless N is greater than `$#'
2152 or less than zero, non-zero otherwise.
2156 Evaluate a conditional expression EXPR. Each operator and operand
2157 must be a separate argument. Expressions are composed of the
2158 primaries described below in *Note Bash Conditional Expressions::.
2160 Expressions may be combined using the following operators, listed
2161 in decreasing order of precedence.
2164 True if EXPR is false.
2167 Returns the value of EXPR. This may be used to override the
2168 normal precedence of operators.
2171 True if both EXPR1 and EXPR2 are true.
2174 True if either EXPR1 or EXPR2 is true.
2176 The `test' and `[' builtins evaluate conditional expressions using
2177 a set of rules based on the number of arguments.
2180 The expression is false.
2183 The expression is true if and only if the argument is not
2187 If the first argument is `!', the expression is true if and
2188 only if the second argument is null. If the first argument
2189 is one of the unary conditional operators (*note Bash
2190 Conditional Expressions::.), the expression is true if the
2191 unary test is true. If the first argument is not a valid
2192 unary operator, the expression is false.
2195 If the second argument is one of the binary conditional
2196 operators (*note Bash Conditional Expressions::.), the result
2197 of the expression is the result of the binary test using the
2198 first and third arguments as operands. If the first argument
2199 is `!', the value is the negation of the two-argument test
2200 using the second and third arguments. If the first argument
2201 is exactly `(' and the third argument is exactly `)', the
2202 result is the one-argument test of the second argument.
2203 Otherwise, the expression is false. The `-a' and `-o'
2204 operators are considered binary operators in this case.
2207 If the first argument is `!', the result is the negation of
2208 the three-argument expression composed of the remaining
2209 arguments. Otherwise, the expression is parsed and evaluated
2210 according to precedence using the rules listed above.
2213 The expression is parsed and evaluated according to precedence
2214 using the rules listed above.
2218 Print out the user and system times used by the shell and its
2219 children. The return status is zero.
2222 trap [-lp] [ARG] [SIGSPEC ...]
2223 The commands in ARG are to be read and executed when the shell
2224 receives signal SIGSPEC. If ARG is absent or equal to `-', all
2225 specified signals are reset to the values they had when the shell
2226 was started. If ARG is the null string, then the signal specified
2227 by each SIGSPEC is ignored by the shell and commands it invokes.
2228 If ARG is `-p', the shell displays the trap commands associated
2229 with each SIGSPEC. If no arguments are supplied, or only `-p' is
2230 given, `trap' prints the list of commands associated with each
2231 signal number in a form that may be reused as shell input. Each
2232 SIGSPEC is either a signal name such as `SIGINT' (with or without
2233 the `SIG' prefix) or a signal number. If a SIGSPEC is `0' or
2234 `EXIT', ARG is executed when the shell exits. If a SIGSPEC is
2235 `DEBUG', the command ARG is executed after every simple command.
2236 The `-l' option causes the shell to print a list of signal names
2237 and their corresponding numbers.
2239 Signals ignored upon entry to the shell cannot be trapped or reset.
2240 Trapped signals are reset to their original values in a child
2241 process when it is created.
2243 The return status is zero unless a SIGSPEC does not specify a
2247 umask [-p] [-S] [MODE]
2248 Set the shell process's file creation mask to MODE. If MODE
2249 begins with a digit, it is interpreted as an octal number; if not,
2250 it is interpreted as a symbolic mode mask similar to that accepted
2251 by the `chmod' command. If MODE is omitted, the current value of
2252 the mask is printed. If the `-S' option is supplied without a
2253 MODE argument, the mask is printed in a symbolic format. If the
2254 `-p' option is supplied, and MODE is omitted, the output is in a
2255 form that may be reused as input. The return status is zero if
2256 the mode is successfully changed or if no MODE argument is
2257 supplied, and non-zero otherwise.
2261 Each variable or function NAME is removed. If no options are
2262 supplied, or the `-v' option is given, each NAME refers to a shell
2263 variable. If the `-f' option is given, the NAMEs refer to shell
2264 functions, and the function definition is removed. Readonly
2265 variables and functions may not be unset. The return status is
2266 zero unless a NAME does not exist or is readonly.
2269 File: bashref.info, Node: Bourne Shell Variables, Next: Other Bourne Shell Features, Prev: Bourne Shell Builtins, Up: Bourne Shell Features
2271 Bourne Shell Variables
2272 ======================
2274 Bash uses certain shell variables in the same way as the Bourne
2275 shell. In some cases, Bash assigns a default value to the variable.
2278 A colon-separated list of directories used as a search path for
2279 the `cd' builtin command.
2282 The current user's home directory; the default for the `cd' builtin
2283 command. The value of this variable is also used by tilde
2284 expansion (*note Tilde Expansion::.).
2287 A list of characters that separate fields; used when the shell
2288 splits words as part of expansion.
2291 If this parameter is set to a filename and the `MAILPATH' variable
2292 is not set, Bash informs the user of the arrival of mail in the
2296 A colon-separated list of filenames which the shell periodically
2297 checks for new mail. Each list entry can specify the message that
2298 is printed when new mail arrives in the mail file by separating
2299 the file name from the message with a `?'. When used in the text
2300 of the message, `$_' expands to the name of the current mail file.
2303 The value of the last option argument processed by the `getopts'
2307 The index of the last option argument processed by the `getopts'
2311 A colon-separated list of directories in which the shell looks for
2315 The primary prompt string. The default value is `\s-\v\$ '.
2318 The secondary prompt string. The default value is `> '.
2321 File: bashref.info, Node: Other Bourne Shell Features, Prev: Bourne Shell Variables, Up: Bourne Shell Features
2323 Other Bourne Shell Features
2324 ===========================
2328 * Major Differences From The Bourne Shell:: Major differences between
2329 Bash and the Bourne shell.
2331 Bash implements essentially the same grammar, parameter and variable
2332 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
2333 POSIX 1003.2 standard as the specification of how these features are to
2334 be implemented. There are some differences between the traditional
2335 Bourne shell and Bash; this section quickly details the differences of
2336 significance. A number of these differences are explained in greater
2337 depth in subsequent sections.
2340 File: bashref.info, Node: Major Differences From The Bourne Shell, Up: Other Bourne Shell Features
2342 Major Differences From The SVR4.2 Bourne Shell
2343 ----------------------------------------------
2345 * Bash is POSIX-conformant, even where the POSIX specification
2346 differs from traditional `sh' behavior.
2348 * Bash has multi-character invocation options (*note Invoking
2351 * Bash has command-line editing (*note Command Line Editing::.) and
2354 * Bash has command history (*note Bash History Facilities::.) and the
2355 `history' and `fc' builtins to manipulate it.
2357 * Bash implements `csh'-like history expansion (*note History
2360 * Bash has one-dimensional array variables (*note Arrays::.), and the
2361 appropriate variable expansions and assignment syntax to use them.
2362 Several of the Bash builtins take options to act on arrays. Bash
2363 provides a number of built-in array variables.
2365 * The `$'...'' quoting syntax, which expands ANSI-C
2366 backslash-escaped characters in the text between the single quotes,
2367 is supported (*note ANSI-C Quoting::.).
2369 * Bash supports the `$"..."' quoting syntax to do locale-specific
2370 translation of the characters between the double quotes. The
2371 `-D', `--dump-strings', and `--dump-po-strings' invocation options
2372 list the translatable strings found in a script (*note Locale
2375 * Bash implements the `!' keyword to negate the return value of a
2376 pipeline (*note Pipelines::.). Very useful when an `if' statement
2377 needs to act only if a test fails.
2379 * Bash has the `time' reserved word and command timing (*note
2380 Pipelines::.). The display of the timing statistics may be
2381 controlled with the `TIMEFORMAT' variable.
2383 * Bash includes the `select' compound command, which allows the
2384 generation of simple menus (*note Conditional Constructs::.).
2386 * Bash includes the `[[' compound command, which makes conditional
2387 testing part of the shell grammar (*note Conditional
2390 * Bash includes brace expansion (*note Brace Expansion::.) and tilde
2391 expansion (*note Tilde Expansion::.).
2393 * Bash implements command aliases and the `alias' and `unalias'
2394 builtins (*note Aliases::.).
2396 * Bash provides shell arithmetic, the `((' compound command (*note
2397 Conditional Constructs::.), and arithmetic expansion (*note Shell
2400 * Variables present in the shell's initial environment are
2401 automatically exported to child processes. The Bourne shell does
2402 not normally do this unless the variables are explicitly marked
2403 using the `export' command.
2405 * Bash includes the POSIX pattern removal `%', `#', `%%' and `##'
2406 expansions to remove leading or trailing substrings from variable
2407 values (*note Shell Parameter Expansion::.).
2409 * The expansion `${#xx}', which returns the length of `${xx}', is
2410 supported (*note Shell Parameter Expansion::.).
2412 * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the
2413 substring of `var''s value of length LENGTH, beginning at OFFSET,
2414 is present (*note Shell Parameter Expansion::.).
2416 * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches
2417 PATTERN and replaces it with REPLACEMENT in the value of `var', is
2418 available (*note Shell Parameter Expansion::.).
2420 * Bash has INDIRECT variable expansion using `${!word}' (*note Shell
2421 Parameter Expansion::.).
2423 * Bash can expand positional parameters beyond `$9' using `${NUM}'.
2425 * The POSIX `$()' form of command substitution is implemented (*note
2426 Command Substitution::.), and preferred to the Bourne shell's ```'
2427 (which is also implemented for backwards compatibility).
2429 * Bash has process substitution (*note Process Substitution::.).
2431 * Bash automatically assigns variables that provide information
2432 about the current user (`UID', `EUID', and `GROUPS'), the current
2433 host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the
2434 instance of Bash that is running (`BASH', `BASH_VERSION', and
2435 `BASH_VERSINFO'). *Note Bash Variables::, for details.
2437 * The `IFS' variable is used to split only the results of expansion,
2438 not all words (*note Word Splitting::.). This closes a
2439 longstanding shell security hole.
2441 * Bash implements the full set of POSIX.2 filename expansion
2442 operators, including CHARACTER CLASSES, EQUIVALENCE CLASSES, and
2443 COLLATING SYMBOLS (*note Filename Expansion::.).
2445 * Bash implements extended pattern matching features when the
2446 `extglob' shell option is enabled (*note Pattern Matching::.).
2448 * It is possible to have a variable and a function with the same
2449 name; `sh' does not separate the two name spaces.
2451 * Bash functions are permitted to have local variables using the
2452 `local' builtin, and thus useful recursive functions may be
2455 * Variable assignments preceding commands affect only that command,
2456 even builtins and functions (*note Environment::.). In `sh', all
2457 variable assignments preceding commands are global unless the
2458 command is executed from the file system.
2460 * Bash performs filename expansion on filenames specified as operands
2461 to input and output redirection operators.
2463 * Bash contains the `<>' redirection operator, allowing a file to be
2464 opened for both reading and writing, and the `&>' redirection
2465 operator, for directing standard output and standard error to the
2466 same file (*note Redirections::.).
2468 * The `noclobber' option is available to avoid overwriting existing
2469 files with output redirection (*note The Set Builtin::.). The
2470 `>|' redirection operator may be used to override `noclobber'.
2472 * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::.)
2473 each take `-L' and `-P' builtins to switch between logical and
2476 * Bash allows a function to override a builtin with the same name,
2477 and provides access to that builtin's functionality within the
2478 function via the `builtin' and `command' builtins (*note Bash
2481 * The `command' builtin allows selective disabling of functions when
2482 command lookup is performed (*note Bash Builtins::.).
2484 * Individual builtins may be enabled or disabled using the `enable'
2485 builtin (*note Bash Builtins::.).
2487 * The Bash `exec' builtin takes additional options that allow users
2488 to control the contents of the environment passed to the executed
2489 command, and what the zeroth argument to the command is to be
2490 (*note Bourne Shell Builtins::.).
2492 * Shell functions may be exported to children via the environment
2493 using `export -f' (*note Shell Functions::.).
2495 * The Bash `export', `readonly', and `declare' builtins can take a
2496 `-f' option to act on shell functions, a `-p' option to display
2497 variables with various attributes set in a format that can be used
2498 as shell input, a `-n' option to remove various variable
2499 attributes, and `name=value' arguments to set variable attributes
2500 and values simultaneously.
2502 * The Bash `hash' builtin allows a name to be associated with an
2503 arbitrary filename, even when that filename cannot be found by
2504 searching the `$PATH', using `hash -p' (*note Bourne Shell
2507 * Bash includes a `help' builtin for quick reference to shell
2508 facilities (*note Bash Builtins::.).
2510 * The `printf' builtin is available to display formatted output
2511 (*note Bash Builtins::.).
2513 * The Bash `read' builtin (*note Bash Builtins::.) will read a line
2514 ending in `\' with the `-r' option, and will use the `REPLY'
2515 variable as a default if no arguments are supplied. The Bash
2516 `read' builtin also accepts a prompt string with the `-p' option
2517 and will use Readline to obtain the line when given the `-e'
2520 * The `return' builtin may be used to abort execution of scripts
2521 executed with the `.' or `source' builtins (*note Bourne Shell
2524 * Bash includes the `shopt' builtin, for finer control of shell
2525 optional capabilities (*note Bash Builtins::.).
2527 * Bash has much more optional behavior controllable with the `set'
2528 builtin (*note The Set Builtin::.).
2530 * The `test' builtin (*note Bourne Shell Builtins::.) is slightly
2531 different, as it implements the POSIX algorithm, which specifies
2532 the behavior based on the number of arguments.
2534 * The `trap' builtin (*note Bourne Shell Builtins::.) allows a
2535 `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands
2536 specified with a `DEBUG' trap are executed after every simple
2537 command. The `DEBUG' trap is not inherited by shell functions.
2539 * The Bash `type' builtin is more extensive and gives more
2540 information about the names it finds (*note Bash Builtins::.).
2542 * The Bash `umask' builtin permits a `-p' option to cause the output
2543 to be displayed in the form of a `umask' command that may be
2544 reused as input (*note Bourne Shell Builtins::.).
2546 * Bash implements a `csh'-like directory stack, and provides the
2547 `pushd', `popd', and `dirs' builtins to manipulate it (*note The
2548 Directory Stack::.). Bash also makes the directory stack visible
2549 as the value of the `DIRSTACK' shell variable.
2551 * Bash interprets special backslash-escaped characters in the prompt
2552 strings when interactive (*note Printing a Prompt::.).
2554 * The Bash restricted mode is more useful (*note The Restricted
2555 Shell::.); the SVR4.2 shell restricted mode is too limited.
2557 * The `disown' builtin can remove a job from the internal shell job
2558 table (*note Job Control Builtins::.) or suppress the sending of
2559 `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'.
2561 * The SVR4.2 shell has two privilege-related builtins (`mldmode' and
2562 `priv') not present in Bash.
2564 * Bash does not have the `stop' or `newgrp' builtins.
2566 * Bash does not use the `SHACCT' variable or perform shell
2569 * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'.
2571 More features unique to Bash may be found in *Note Bash Features::.
2573 Implementation Differences From The SVR4.2 Shell
2574 ------------------------------------------------
2576 Since Bash is a completely new implementation, it does not suffer
2577 from many of the limitations of the SVR4.2 shell. For instance:
2579 * Bash does not fork a subshell when redirecting into or out of a
2580 shell control structure such as an `if' or `while' statement.
2582 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
2583 silently insert a needed closing quote at `EOF' under certain
2584 circumstances. This can be the cause of some hard-to-find errors.
2586 * The SVR4.2 shell uses a baroque memory management scheme based on
2587 trapping `SIGSEGV'. If the shell is started from a process with
2588 `SIGSEGV' blocked (e.g., by using the `system()' C library
2589 function call), it misbehaves badly.
2591 * In a questionable attempt at security, the SVR4.2 shell, when
2592 invoked without the `-p' option, will alter its real and effective
2593 UID and GID if they are less than some magic threshold value,
2594 commonly 100. This can lead to unexpected results.
2596 * The SVR4.2 shell does not allow users to trap `SIGSEGV',
2597 `SIGALRM', or `SIGCHLD'.
2599 * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH',
2600 `PS1', or `PS2' variables to be unset.
2602 * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'.
2604 * Bash allows multiple option arguments when it is invoked (`-x -v');
2605 the SVR4.2 shell allows only one option argument (`-xv'). In
2606 fact, some versions of the shell dump core if the second argument
2609 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
2610 script only if one of the POSIX.2 special builtins fails, and only
2611 for certain failures, as enumerated in the POSIX.2 standard.
2613 * The SVR4.2 shell behaves differently when invoked as `jsh' (it
2614 turns on job control).
2617 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Bourne Shell Features, Up: Top
2622 This section describes features unique to Bash.
2626 * Invoking Bash:: Command line options that you can give
2628 * Bash Startup Files:: When and how Bash executes scripts.
2629 * Is This Shell Interactive?:: Determining the state of a running Bash.
2630 * Bash Builtins:: Table of builtins specific to Bash.
2631 * The Set Builtin:: This builtin is so overloaded it
2632 deserves its own section.
2633 * Bash Conditional Expressions:: Primitives used in composing expressions for
2635 * Bash Variables:: List of variables that exist in Bash.
2636 * Shell Arithmetic:: Arithmetic on shell variables.
2637 * Aliases:: Substituting one command for another.
2638 * Arrays:: Array Variables.
2639 * The Directory Stack:: History of visited directories.
2640 * Printing a Prompt:: Controlling the PS1 string.
2641 * The Restricted Shell:: A more controlled mode of shell execution.
2642 * Bash POSIX Mode:: Making Bash behave more closely to what
2643 the POSIX standard specifies.
2646 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
2651 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...]
2652 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] -c STRING [ARGUMENT ...]
2653 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...]
2655 In addition to the single-character shell command-line options
2656 (*note The Set Builtin::.), there are several multi-character options
2657 that you can use. These options must appear on the command line before
2658 the single-character options in order for them to be recognized.
2661 Equivalent to `-D', but the output is in the GNU `gettext' PO
2662 (portable object) file format.
2668 Display a usage message on standard output and exit sucessfully.
2671 Make this shell act as if it were directly invoked by login. This
2672 is equivalent to `exec -l bash' but can be issued from another
2673 shell, such as `csh'. `exec bash --login' will replace the
2674 current shell with a Bash login shell.
2677 Do not use the GNU Readline library (*note Command Line Editing::.)
2678 to read interactive command lines.
2681 Don't load the system-wide startup file `/etc/profile' or any of
2682 the personal initialization files `~/.bash_profile',
2683 `~/.bash_login', or `~/.profile' when Bash is invoked as a login
2687 Don't read the `~/.bashrc' initialization file in an interactive
2688 shell. This is on by default if the shell is invoked as `sh'.
2691 Change the behavior of Bash where the default operation differs
2692 from the POSIX 1003.2 standard to match the standard. This is
2693 intended to make Bash behave as a strict superset of that
2694 standard. *Note Bash POSIX Mode::, for a description of the Bash
2698 Execute commands from FILENAME (instead of `~/.bashrc') in an
2702 Make the shell a restricted shell (*note The Restricted Shell::.).
2708 Show version information for this instance of Bash on the standard
2709 output and exit successfully.
2711 There are several single-character options that may be supplied at
2712 invocation which are not available with the `set' builtin.
2715 Read and execute commands from STRING after processing the
2716 options, then exit. Any remaining arguments are assigned to the
2717 positional parameters, starting with `$0'.
2720 Force the shell to run interactively.
2723 Make the shell a restricted shell (*note The Restricted Shell::.).
2726 If this option is present, or if no arguments remain after option
2727 processing, then commands are read from the standard input. This
2728 option allows the positional parameters to be set when invoking an
2732 A list of all double-quoted strings preceded by `$' is printed on
2733 the standard ouput. These are the strings that are subject to
2734 language translation when the current locale is not `C' or `POSIX'
2735 (*note Locale Translation::.). This implies the `-n' option; no
2736 commands will be executed.
2739 A `--' signals the end of options and disables further option
2740 processing. Any arguments after the `--' are treated as filenames
2743 An *interactive* shell is one whose input and output are both
2744 connected to terminals (as determined by `isatty(3)'), or one started
2745 with the `-i' option.
2747 If arguments remain after option processing, and neither the `-c'
2748 nor the `-s' option has been supplied, the first argument is assumed to
2749 be the name of a file containing shell commands (*note Shell
2750 Scripts::.). When Bash is invoked in this fashion, `$0' is set to the
2751 name of the file, and the positional parameters are set to the
2752 remaining arguments. Bash reads and executes commands from this file,
2753 then exits. Bash's exit status is the exit status of the last command
2754 executed in the script. If no commands are executed, the exit status
2758 File: bashref.info, Node: Bash Startup Files, Next: Is This Shell Interactive?, Prev: Invoking Bash, Up: Bash Features
2763 This section describs how Bash executes its startup files. If any
2764 of the files exist but cannot be read, Bash reports an error. Tildes
2765 are expanded in file names as described above under Tilde Expansion
2766 (*note Tilde Expansion::.).
2768 When Bash is invoked as an interactive login shell, or as a
2769 non-interactive shell with the `--login' option, it first reads and
2770 executes commands from the file `/etc/profile', if that file exists.
2771 After reading that file, it looks for `~/.bash_profile',
2772 `~/.bash_login', and `~/.profile', in that order, and reads and
2773 executes commands from the first one that exists and is readable. The
2774 `--noprofile' option may be used when the shell is started to inhibit
2777 When a login shell exits, Bash reads and executes commands from the
2778 file `~/.bash_logout', if it exists.
2780 When an interactive shell that is not a login shell is started, Bash
2781 reads and executes commands from `~/.bashrc', if that file exists.
2782 This may be inhibited by using the `--norc' option. The `--rcfile
2783 FILE' option will force Bash to read and execute commands from FILE
2784 instead of `~/.bashrc'.
2786 So, typically, your `~/.bash_profile' contains the line
2787 `if [ -f `~/.bashrc' ]; then . `~/.bashrc'; fi'
2789 after (or before) any login-specific initializations.
2791 When Bash is started non-interactively, to run a shell script, for
2792 example, it looks for the variable `BASH_ENV' in the environment,
2793 expands its value if it appears there, and uses the expanded value as
2794 the name of a file to read and execute. Bash behaves as if the
2795 following command were executed:
2796 `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi'
2798 but the value of the `PATH' variable is not used to search for the file
2801 If Bash is invoked with the name `sh', it tries to mimic the startup
2802 behavior of historical versions of `sh' as closely as possible, while
2803 conforming to the POSIX standard as well.
2805 When invoked as an interactive login shell, or as a non-interactive
2806 shell with the `--login' option, it first attempts to read and execute
2807 commands from `/etc/profile' and `~/.profile', in that order. The
2808 `--noprofile' option may be used to inhibit this behavior. When
2809 invoked as an interactive shell with the name `sh', Bash looks for the
2810 variable `ENV', expands its value if it is defined, and uses the
2811 expanded value as the name of a file to read and execute. Since a
2812 shell invoked as `sh' does not attempt to read and execute commands
2813 from any other startup files, the `--rcfile' option has no effect. A
2814 non-interactive shell invoked with the name `sh' does not attempt to
2815 read any other startup files.
2817 When invoked as `sh', Bash enters POSIX mode after the startup files
2820 When Bash is started in POSIX mode, as with the `--posix' command
2821 line option, it follows the POSIX standard for startup files. In this
2822 mode, interactive shells expand the `ENV' variable and commands are
2823 read and executed from the file whose name is the expanded value. No
2824 other startup files are read.
2826 Bash attempts to determine when it is being run by the remote shell
2827 daemon, usually `rshd'. If Bash determines it is being run by rshd, it
2828 reads and executes commands from `~/.bashrc', if that file exists and
2829 is readable. It will not do this if invoked as `sh'. The `--norc'
2830 option may be used to inhibit this behavior, and the `--rcfile' option
2831 may be used to force another file to be read, but `rshd' does not
2832 generally invoke the shell with those options or allow them to be
2835 If Bash is started with the effective user (group) id not equal to
2836 the real user (group) id, and the `-p' option is not supplied, no
2837 startup files are read, shell functions are not inherited from the
2838 environment, the `SHELLOPTS' variable, if it appears in the
2839 environment, is ignored, and the effective user id is set to the real
2840 user id. If the `-p' option is supplied at invocation, the startup
2841 behavior is the same, but the effective user id is not reset.
2844 File: bashref.info, Node: Is This Shell Interactive?, Next: Bash Builtins, Prev: Bash Startup Files, Up: Bash Features
2846 Is This Shell Interactive?
2847 ==========================
2849 As defined in *Note Invoking Bash::, an interactive shell is one
2850 whose input and output are both connected to terminals (as determined
2851 by `isatty(3)'), or one started with the `-i' option.
2853 To determine within a startup script whether Bash is running
2854 interactively or not, examine the variable `$PS1'; it is unset in
2855 non-interactive shells, and set in interactive shells. Thus:
2857 if [ -z "$PS1" ]; then
2858 echo This shell is not interactive
2860 echo This shell is interactive
2863 Alternatively, startup scripts may test the value of the `-' special
2864 parameter. It contains `i' when the shell is interactive. For example:
2867 *i*) echo This shell is interactive ;;
2868 *) echo This shell is not interactive ;;
2872 File: bashref.info, Node: Bash Builtins, Next: The Set Builtin, Prev: Is This Shell Interactive?, Up: Bash Features
2874 Bash Builtin Commands
2875 =====================
2877 This section describes builtin commands which are unique to or have
2878 been extended in Bash.
2881 bind [-m KEYMAP] [-lpsvPSV]
2882 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
2883 bind [-m KEYMAP] -f FILENAME
2884 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
2886 Display current Readline (*note Command Line Editing::.) key and
2887 function bindings, or bind a key sequence to a Readline function
2888 or macro. The binding syntax accepted is identical to that of
2889 `.inputrc' (*note Readline Init File::.), but each binding must be
2890 passed as a separate argument: e.g.,
2891 `"\C-x\C-r":re-read-init-file'. Options, if supplied, have the
2895 Use KEYMAP as the keymap to be affected by the subsequent
2896 bindings. Acceptable KEYMAP names are `emacs',
2897 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
2898 `vi-command', and `vi-insert'. `vi' is equivalent to
2899 `vi-command'; `emacs' is equivalent to `emacs-standard'.
2902 List the names of all Readline functions.
2905 Display Readline function names and bindings in such a way
2906 that they can be re-read.
2909 List current Readline function names and bindings.
2912 Display Readline variable names and values in such a way that
2913 they can be re-read.
2916 List current Readline variable names and values.
2919 Display Readline key sequences bound to macros and the
2920 strings they output in such a way that they can be re-read.
2923 Display Readline key sequences bound to macros and the
2924 strings they output.
2927 Read key bindings from FILENAME.
2930 Query about which keys invoke the named FUNCTION.
2933 Unbind all keys bound to the named FUNCTION.
2936 Remove any current binding for KEYSEQ.
2938 The return status is zero unless an invalid option is supplied or
2942 builtin [SHELL-BUILTIN [ARGS]]
2943 Run a shell builtin, passing it ARGS, and return its exit status.
2944 This is useful when defining a shell function with the same name
2945 as a shell builtin, retaining the functionality of the builtin
2946 within the function. The return status is non-zero if
2947 SHELL-BUILTIN is not a shell builtin command.
2950 command [-pVv] COMMAND [ARGUMENTS ...]
2951 Runs COMMAND with ARGUMENTS ignoring any shell function named
2952 COMMAND. Only shell builtin commands or commands found by
2953 searching the `PATH' are executed. If there is a shell function
2954 named `ls', running `command ls' within the function will execute
2955 the external command `ls' instead of calling the function
2956 recursively. The `-p' option means to use a default value for
2957 `$PATH' that is guaranteed to find all of the standard utilities.
2958 The return status in this case is 127 if COMMAND cannot be found
2959 or an error occurred, and the exit status of COMMAND otherwise.
2961 If either the `-V' or `-v' option is supplied, a description of
2962 COMMAND is printed. The `-v' option causes a single word
2963 indicating the command or file name used to invoke COMMAND to be
2964 displayed; the `-V' option produces a more verbose description.
2965 In this case, the return status is zero if COMMAND is found, and
2969 declare [-afFrxi] [-p] [NAME[=VALUE]]
2971 Declare variables and give them attributes. If no NAMEs are
2972 given, then display the values of variables instead.
2974 The `-p' option will display the attributes and values of each
2975 NAME. When `-p' is used, additional options are ignored. The
2976 `-F' option inhibits the display of function definitions; only the
2977 function name and attributes are printed. `-F' implies `-f'. The
2978 following options can be used to restrict output to variables with
2979 the specified attributes or to give variables attributes:
2982 Each NAME is an array variable (*note Arrays::.).
2985 Use function names only.
2988 The variable is to be treated as an integer; arithmetic
2989 evaluation (*note Shell Arithmetic::.) is performed when the
2990 variable is assigned a value.
2993 Make NAMEs readonly. These names cannot then be assigned
2994 values by subsequent assignment statements or unset.
2997 Mark each NAME for export to subsequent commands via the
3000 Using `+' instead of `-' turns off the attribute instead. When
3001 used in a function, `declare' makes each NAME local, as with the
3004 The return status is zero unless an invalid option is encountered,
3005 an attempt is made to define a function using `-f foo=bar', an
3006 attempt is made to assign a value to a readonly variable, an
3007 attempt is made to assign a value to an array variable without
3008 using the compound assignment syntax (*note Arrays::.), one of the
3009 NAMES is not a valid shell variable name, an attempt is made to
3010 turn off readonly status for a readonly variable, an attempt is
3011 made to turn off array status for an array variable, or an attempt
3012 is made to display a non-existent function with `-f'.
3015 echo [-neE] [ARG ...]
3016 Output the ARGs, separated by spaces, terminated with a newline.
3017 The return status is always 0. If `-n' is specified, the trailing
3018 newline is suppressed. If the `-e' option is given,
3019 interpretation of the following backslash-escaped characters is
3020 enabled. The `-E' option disables the interpretation of these
3021 escape characters, even on systems where they are interpreted by
3022 default. `echo' interprets the following escape sequences:
3030 suppress trailing newline
3054 the character whose `ASCII' code is the octal value NNN (one
3058 the character whose `ASCII' code is the hexadecimal value NNN
3059 (one to three digits)
3062 enable [-n] [-p] [-f FILENAME] [-ads] [NAME ...]
3063 Enable and disable builtin shell commands. Disabling a builtin
3064 allows a disk command which has the same name as a shell builtin
3065 to be executed with specifying a full pathname, even though the
3066 shell normally searches for builtins before disk commands. If
3067 `-n' is used, the NAMEs become disabled. Otherwise NAMEs are
3068 enabled. For example, to use the `test' binary found via `$PATH'
3069 instead of the shell builtin version, type `enable -n test'.
3071 If the `-p' option is supplied, or no NAME arguments appear, a
3072 list of shell builtins is printed. With no other arguments, the
3073 list consists of all enabled shell builtins. The `-a' option
3074 means to list each builtin with an indication of whether or not it
3077 The `-f' option means to load the new builtin command NAME from
3078 shared object FILENAME, on systems that support dynamic loading.
3079 The `-d' option will delete a builtin loaded with `-f'.
3081 If there are no options, a list of the shell builtins is displayed.
3082 The `-s' option restricts `enable' to the POSIX special builtins.
3083 If `-s' is used with `-f', the new builtin becomes a special
3086 The return status is zero unless a NAME is not a shell builtin or
3087 there is an error loading a new builtin from a shared object.
3091 Display helpful information about builtin commands. If PATTERN is
3092 specified, `help' gives detailed help on all commands matching
3093 PATTERN, otherwise a list of the builtins is printed. The return
3094 status is zero unless no command matches PATTERN.
3097 let EXPRESSION [EXPRESSION]
3098 The `let' builtin allows arithmetic to be performed on shell
3099 variables. Each EXPRESSION is evaluated according to the rules
3100 given below in *Note Shell Arithmetic::. If the last EXPRESSION
3101 evaluates to 0, `let' returns 1; otherwise 0 is returned.
3105 For each argument, a local variable named NAME is created, and
3106 assigned VALUE. `local' can only be used within a function; it
3107 makes the variable NAME have a visible scope restricted to that
3108 function and its children. The return status is zero unless
3109 `local' is used outside a function or an invalid NAME is supplied.
3113 Exit a login shell, returning a status of N to the shell's parent.
3116 `printf' FORMAT [ARGUMENTS]
3117 Write the formatted ARGUMENTS to the standard output under the
3118 control of the FORMAT. The FORMAT is a character string which
3119 contains three types of objects: plain characters, which are
3120 simply copied to standard output, character escape sequences,
3121 which are converted and copied to the standard output, and format
3122 specifications, each of which causes printing of the next
3123 successive ARGUMENT. In addition to the standard `printf(1)'
3124 formats, `%b' causes `printf' to expand backslash escape sequences
3125 in the corresponding ARGUMENT, and `%q' causes `printf' to output
3126 the corresponding ARGUMENT in a format that can be reused as shell
3129 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3130 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3131 format specifications behave as if a zero value or null string, as
3132 appropriate, had been supplied.
3135 read [-a ANAME] [-p PROMPT] [-er] [NAME ...]
3136 One line is read from the standard input, and the first word is
3137 assigned to the first NAME, the second word to the second NAME,
3138 and so on, with leftover words and their intervening separators
3139 assigned to the last NAME. If there are fewer words read from the
3140 standard input than names, the remaining names are assigned empty
3141 values. The characters in the value of the `IFS' variable are
3142 used to split the line into words. The backslash character `\'
3143 may be used to remove any special meaning for the next character
3144 read and for line continuation. If no names are supplied, the
3145 line read is assigned to the variable `REPLY'. The return code is
3146 zero, unless end-of-file is encountered. Options, if supplied,
3147 have the following meanings:
3150 If this option is given, backslash does not act as an escape
3151 character. The backslash is considered to be part of the
3152 line. In particular, a backslash-newline pair may not be
3153 used as a line continuation.
3156 Display PROMPT, without a trailing newline, before attempting
3157 to read any input. The prompt is displayed only if input is
3158 coming from a terminal.
3161 The words are assigned to sequential indices of the array
3162 variable ANAME, starting at 0. All elements are removed from
3163 ANAME before the assignment. Other NAME arguments are
3167 Readline (*note Command Line Editing::.) is used to obtain
3171 shopt [-pqsu] [-o] [OPTNAME ...]
3172 Toggle the values of variables controlling optional shell behavior.
3173 With no options, or with the `-p' option, a list of all settable
3174 options is displayed, with an indication of whether or not each is
3175 set. The `-p' option causes output to be displayed in a form that
3176 may be reused as input. Other options have the following meanings:
3179 Enable (set) each OPTNAME.
3182 Disable (unset) each OPTNAME.
3185 Suppresses normal output; the return status indicates whether
3186 the OPTNAME is set or unset. If multiple OPTNAME arguments
3187 are given with `-q', the return status is zero if all
3188 OPTNAMES are enabled; non-zero otherwise.
3191 Restricts the values of OPTNAME to be those defined for the
3192 `-o' option to the `set' builtin (*note The Set Builtin::.).
3194 If either `-s' or `-u' is used with no OPTNAME arguments, the
3195 display is limited to those options which are set or unset,
3198 Unless otherwise noted, the `shopt' options are disabled (off) by
3201 The return status when listing options is zero if all OPTNAMES are
3202 enabled, non-zero otherwise. When setting or unsetting options,
3203 the return status is zero unless an OPTNAME is not a valid shell
3206 The list of `shopt' options is:
3208 If this is set, an argument to the `cd' builtin command that
3209 is not a directory is assumed to be the name of a variable
3210 whose value is the directory to change to.
3213 If set, minor errors in the spelling of a directory component
3214 in a `cd' command will be corrected. The errors checked for
3215 are transposed characters, a missing character, and a
3216 character too many. If a correction is found, the corrected
3217 path is printed, and the command proceeds. This option is
3218 only used by interactive shells.
3221 If this is set, Bash checks that a command found in the hash
3222 table exists before trying to execute it. If a hashed
3223 command no longer exists, a normal path search is performed.
3226 If set, Bash checks the window size after each command and,
3227 if necessary, updates the values of `LINES' and `COLUMNS'.
3230 If set, Bash attempts to save all lines of a multiple-line
3231 command in the same history entry. This allows easy
3232 re-editing of multi-line commands.
3235 If set, Bash includes filenames beginning with a `.' in the
3236 results of filename expansion.
3239 If this is set, a non-interactive shell will not exit if it
3240 cannot execute the file specified as an argument to the `exec'
3241 builtin command. An interactive shell does not exit if `exec'
3245 If set, aliases are expanded as described below< under Aliases
3246 (*note Aliases::.). This option is enabled by default for
3250 If set, the extended pattern matching features described above
3251 (*note Pattern Matching::.) are enabled.
3254 If set, the history list is appended to the file named by the
3255 value of the `HISTFILE' variable when the shell exits, rather
3256 than overwriting the file.
3259 If set, and Readline is being used, a user is given the
3260 opportunity to re-edit a failed history substitution.
3263 If set, and Readline is being used, the results of history
3264 substitution are not immediately passed to the shell parser.
3265 Instead, the resulting line is loaded into the Readline
3266 editing buffer, allowing further modification.
3269 If set, and Readline is being used, Bash will attempt to
3270 perform hostname completion when a word containing a `@' is
3271 being completed (*note Commands For Completion::.). This
3272 option is enabled by default.
3275 If set, Bash will send `SIGHUP' to all jobs when an
3276 interactive login shell exits (*note Signals::.).
3278 `interactive_comments'
3279 Allow a word beginning with `#' to cause that word and all
3280 remaining characters on that line to be ignored in an
3281 interactive shell. This option is enabled by default.
3284 If enabled, and the `cmdhist' option is enabled, multi-line
3285 commands are saved to the history with embedded newlines
3286 rather than using semicolon separators where possible.
3289 If set, and a file that Bash is checking for mail has been
3290 accessed since the last time it was checked, the message
3291 `"The mail in MAILFILE has been read"' is displayed.
3294 If set, Bash matches filenames in a case-insensitive fashion
3295 when performing filename expansion.
3298 If set, Bash allows filename patterns which match no files to
3299 expand to a null string, rather than themselves.
3302 If set, prompt strings undergo variable and parameter
3303 expansion after being expanded (*note Printing a Prompt::.).
3304 This option is enabled by default.
3307 The shell sets this option if it is started in restricted mode
3308 (*note The Restricted Shell::.). The value may not be
3309 changed. This is not reset when the startup files are
3310 executed, allowing the startup files to discover whether or
3311 not a shell is restricted.
3314 If this is set, the `shift' builtin prints an error message
3315 when the shift count exceeds the number of positional
3319 If set, the `source' builtin uses the value of `PATH' to find
3320 the directory containing the file supplied as an argument.
3321 This option is enabled by default.
3323 The return status when listing options is zero if all OPTNAMES are
3324 enabled, non-zero otherwise. When setting or unsetting options,
3325 the return status is zero unless an OPTNAME is not a valid shell
3330 A synonym for `.' (*note Bourne Shell Builtins::.).
3333 type [-atp] [NAME ...]
3334 For each NAME, indicate how it would be interpreted if used as a
3337 If the `-t' option is used, `type' prints a single word which is
3338 one of `alias', `function', `builtin', `file' or `keyword', if
3339 NAME is an alias, shell function, shell builtin, disk file, or
3340 shell reserved word, respectively. If the NAME is not found, then
3341 nothing is printed, and `type' returns a failure status.
3343 If the `-p' option is used, `type' either returns the name of the
3344 disk file that would be executed, or nothing if `-t' would not
3347 If the `-a' option is used, `type' returns all of the places that
3348 contain an executable named FILE. This includes aliases and
3349 functions, if and only if the `-p' option is not also used.
3351 The return status is zero if any of the NAMES are found, non-zero
3355 typeset [-afFrxi] [-p] [NAME[=VALUE]]
3356 The `typeset' command is supplied for compatibility with the Korn
3357 shell; however, it has been deprecated in favor of the `declare'
3361 ulimit [-acdflmnpstuvSH] [LIMIT]
3362 `ulimit' provides control over the resources available to processes
3363 started by the shell, on systems that allow such control. If an
3364 option is given, it is interpreted as follows:
3366 Change and report the soft limit associated with a resource.
3369 Change and report the hard limit associated with a resource.
3372 All current limits are reported.
3375 The maximum size of core files created.
3378 The maximum size of a process's data segment.
3381 The maximum size of files created by the shell.
3384 The maximum size that may be locked into memory.
3387 The maximum resident set size.
3390 The maximum number of open file descriptors.
3393 The pipe buffer size.
3396 The maximum stack size.
3399 The maximum amount of cpu time in seconds.
3402 The maximum number of processes available to a single user.
3405 The maximum amount of virtual memory available to the process.
3407 If LIMIT is given, it is the new value of the specified resource.
3408 Otherwise, the current value of the soft limit for the specified
3409 resource is printed, unless the `-H' option is supplied. When
3410 setting new limits, if neither `-H' nor `-S' is supplied, both the
3411 hard and soft limits are set. If no option is given, then `-f' is
3412 assumed. Values are in 1024-byte increments, except for `-t',
3413 which is in seconds, `-p', which is in units of 512-byte blocks,
3414 and `-n' and `-u', which are unscaled values.
3416 The return status is zero unless an invalid option is supplied, a
3417 non-numeric argument other than `unlimited' is supplied as a
3418 LIMIT, or an error occurs while setting a new limit.
3421 File: bashref.info, Node: The Set Builtin, Next: Bash Conditional Expressions, Prev: Bash Builtins, Up: Bash Features
3426 This builtin is so complicated that it deserves its own section.
3429 set [--abefhkmnptuvxBCHP] [-o OPTION] [ARGUMENT ...]
3431 If no options or arguments are supplied, `set' displays the names
3432 and values of all shell variables and functions, sorted according
3433 to the current locale, in a format that may be reused as input.
3435 When options are supplied, they set or unset shell attributes.
3436 Options, if specified, have the following meanings:
3439 Mark variables which are modified or created for export.
3442 Cause the status of terminated background jobs to be reported
3443 immediately, rather than before printing the next primary
3447 Exit immediately if a simple command (*note Simple
3448 Commands::.) exits with a non-zero status, unless the command
3449 that fails is part of an `until' or `while' loop, part of an
3450 `if' statement, part of a `&&' or `||' list, or if the
3451 command's return status is being inverted using `!'.
3454 Disable file name generation (globbing).
3457 Locate and remember (hash) commands as they are looked up for
3458 execution. This option is enabled by default.
3461 All arguments in the form of assignment statements are placed
3462 in the environment for a command, not just those that precede
3466 Job control is enabled (*note Job Control::.).
3469 Read commands but do not execute them; this may be used to
3470 check a script for syntax errors. This option is ignored by
3474 Set the option corresponding to OPTION-NAME:
3483 Use an `emacs'-style line editing interface (*note
3484 Command Line Editing::.).
3496 Enable command history, as described in *Note Bash
3497 History Facilities::. This option is on by default in
3501 An interactive shell will not exit upon reading EOF.
3531 Change the behavior of Bash where the default operation
3532 differs from the POSIX 1003.2 standard to match the
3533 standard (*note Bash POSIX Mode::.). This is intended
3534 to make Bash behave as a strict superset of that
3544 Use a `vi'-style line editing interface.
3550 Turn on privileged mode. In this mode, the `$BASH_ENV' and
3551 `$ENV' files are not processed, shell functions are not
3552 inherited from the environment, and the `SHELLOPTS' variable,
3553 if it appears in the environment, is ignored. If the shell
3554 is started with the effective user (group) id not equal to the
3555 real user (group) id, and the `-p' option is not supplied,
3556 these actions are taken and the effective user id is set to
3557 the real user id. If the `-p' option is supplied at startup,
3558 the effective user id is not reset. Turning this option off
3559 causes the effective user and group ids to be set to the real
3563 Exit after reading and executing one command.
3566 Treat unset variables as an error when performing parameter
3567 expansion. An error message will be written to the standard
3568 error, and a non-interactive shell will exit.
3571 Print shell input lines as they are read.
3574 Print a trace of simple commands and their arguments after
3575 they are expanded and before they are executed.
3578 The shell will perform brace expansion (*note Brace
3579 Expansion::.). This option is on by default.
3582 Prevent output redirection using `>', `>&', and `<>' from
3583 overwriting existing files.
3586 Enable `!' style history substitution (*note History
3587 Interaction::.). This option is on by default for
3591 If set, do not follow symbolic links when performing commands
3592 such as `cd' which change the current directory. The
3593 physical directory is used instead. By default, Bash follows
3594 the logical chain of directories when performing commands
3595 which change the current directory.
3597 For example, if `/usr/sys' is a symbolic link to
3598 `/usr/local/sys' then:
3599 $ cd /usr/sys; echo $PWD
3604 If `set -P' is on, then:
3605 $ cd /usr/sys; echo $PWD
3611 If no arguments follow this option, then the positional
3612 parameters are unset. Otherwise, the positional parameters
3613 are set to the ARGUMENTS, even if some of them begin with a
3617 Signal the end of options, cause all remaining ARGUMENTS to
3618 be assigned to the positional parameters. The `-x' and `-v'
3619 options are turned off. If there are no arguments, the
3620 positional parameters remain unchanged.
3622 Using `+' rather than `-' causes these options to be turned off.
3623 The options can also be used upon invocation of the shell. The
3624 current set of options may be found in `$-'.
3626 The remaining N ARGUMENTS are positional parameters and are
3627 assigned, in order, to `$1', `$2', ... `$N'. The special
3628 parameter `#' is set to N.
3630 The return status is always zero unless an invalid option is
3634 File: bashref.info, Node: Bash Conditional Expressions, Next: Bash Variables, Prev: The Set Builtin, Up: Bash Features
3636 Bash Conditional Expressions
3637 ============================
3639 Conditional expressions are used by the `[[' compound command and
3640 the `test' and `[' builtin commands.
3642 Expressions may be unary or binary. Unary expressions are often
3643 used to examine the status of a file. There are string operators and
3644 numeric comparison operators as well. If any FILE argument to one of
3645 the primaries is of the form `/dev/fd/N', then file descriptor N is
3649 True if FILE exists.
3652 True if FILE exists and is a block special file.
3655 True if FILE exists and is a character special file.
3658 True if FILE exists and is a directory.
3661 True if FILE exists.
3664 True if FILE exists and is a regular file.
3667 True if FILE exists and its set-group-id bit is set.
3670 True if FILE exists and is a symbolic link.
3673 True if FILE exists and its "sticky" bit is set.
3676 True if FILE exists and is a named pipe (FIFO).
3679 True if FILE exists and is readable.
3682 True if FILE exists and has a size greater than zero.
3685 True if file descriptor FD is open and refers to a terminal.
3688 True if FILE exists and its set-user-id bit is set.
3691 True if FILE exists and is writable.
3694 True if FILE exists and is executable.
3697 True if FILE exists and is owned by the effective user id.
3700 True if FILE exists and is owned by the effective group id.
3703 True if FILE exists and is a symbolic link.
3706 True if FILE exists and is a socket.
3709 True if FILE exists and has been modified since it was last read.
3712 True if FILE1 is newer (according to modification date) than FILE2.
3715 True if FILE1 is older than FILE2.
3718 True if FILE1 and FILE2 have the same device and inode numbers.
3721 True if shell option OPTNAME is enabled. The list of options
3722 appears in the description of the `-o' option to the `set' builtin
3723 (*note The Set Builtin::.).
3726 True if the length of STRING is zero.
3730 True if the length of STRING is non-zero.
3732 `STRING1 == STRING2'
3733 True if the strings are equal. `=' may be used in place of `=='.
3735 `STRING1 != STRING2'
3736 True if the strings are not equal.
3739 True if STRING1 sorts before STRING2 lexicographically in the
3743 True if STRING1 sorts after STRING2 lexicographically in the
3747 `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These
3748 arithmetic binary operators return true if ARG1 is equal to, not
3749 equal to, less than, less than or equal to, greater than, or
3750 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
3751 positive or negative integers.
3754 File: bashref.info, Node: Bash Variables, Next: Shell Arithmetic, Prev: Bash Conditional Expressions, Up: Bash Features
3759 These variables are set or used by Bash, but other shells do not
3760 normally treat them specially.
3763 The full pathname used to execute the current instance of Bash.
3766 If this variable is set when Bash is invoked to execute a shell
3767 script, its value is expanded and used as the name of a startup
3768 file to read before executing the script. *Note Bash Startup
3772 The version number of the current instance of Bash.
3775 A readonly array variable whose members hold version information
3776 for this instance of Bash. The values assigned to the array
3777 members are as follows:
3780 The major version number (the RELEASE).
3783 The minor version number (the VERSION).
3792 The release status (e.g., BETA1).
3795 The value of `MACHTYPE'.
3798 An array variable (*note Arrays::.) containing the current
3799 contents of the directory stack. Directories appear in the stack
3800 in the order they are displayed by the `dirs' builtin. Assigning
3801 to members of this array variable may be used to modify
3802 directories already in the stack, but the `pushd' and `popd'
3803 builtins must be used to add and remove directories. Assignment
3804 to this variable will not change the current directory. If
3805 `DIRSTACK' is unset, it loses its special properties, even if it
3806 is subsequently reset.
3809 The numeric effective user id of the current user. This variable
3813 The editor used as a default by the `-e' option to the `fc'
3817 A colon-separated list of suffixes to ignore when performing
3818 filename completion. A file name whose suffix matches one of the
3819 entries in `FIGNORE' is excluded from the list of matched file
3820 names. A sample value is `.o:~'
3823 A colon-separated list of patterns defining the set of filenames to
3824 be ignored by filename expansion. If a filename matched by a
3825 filename expansion pattern also matches one of the patterns in
3826 `GLOBIGNORE', it is removed from the list of matches.
3829 An array variable containing the list of groups of which the
3830 current user is a member. This variable is readonly.
3833 Up to three characters which control history expansion, quick
3834 substitution, and tokenization (*note History Interaction::.).
3835 The first character is the "history-expansion-char", that is, the
3836 character which signifies the start of a history expansion,
3837 normally `!'. The second character is the character which
3838 signifies `quick substitution' when seen as the first character on
3839 a line, normally `^'. The optional third character is the
3840 character which indicates that the remainder of the line is a
3841 comment when found as the first character of a word, usually `#'.
3842 The history comment character causes history substitution to be
3843 skipped for the remaining words on the line. It does not
3844 necessarily cause the shell parser to treat the rest of the line
3848 The history number, or index in the history list, of the current
3849 command. If `HISTCMD' is unset, it loses its special properties,
3850 even if it is subsequently reset.
3853 Set to a value of `ignorespace', it means don't enter lines which
3854 begin with a space or tab into the history list. Set to a value
3855 of `ignoredups', it means don't enter lines which match the last
3856 entered line. A value of `ignoreboth' combines the two options.
3857 Unset, or set to any other value than those above, means to save
3858 all lines on the history list. The second and subsequent lines of
3859 a multi-line compound command are not tested, and are added to the
3860 history regardless of the value of `HISTCONTROL'.
3863 A colon-separated list of patterns used to decide which command
3864 lines should be saved on the history list. Each pattern is
3865 anchored at the beginning of the line and must fully specify the
3866 line (no implicit `*' is appended). Each pattern is tested
3867 against the line after the checks specified by `HISTCONTROL' are
3868 applied. In addition to the normal shell pattern matching
3869 characters, `&' matches the previous history line. `&' may be
3870 escaped using a backslash. The backslash is removed before
3871 attempting a match. The second and subsequent lines of a
3872 multi-line compound command are not tested, and are added to the
3873 history regardless of the value of `HISTIGNORE'.
3875 `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of
3876 `&' is identical to `ignoredups', and a pattern of `[ ]*' is
3877 identical to `ignorespace'. Combining these two patterns,
3878 separating them with a colon, provides the functionality of
3882 The name of the file to which the command history is saved. The
3883 default is `~/.bash_history'.
3886 The maximum number of commands to remember on the history list.
3887 The default value is 500.
3890 The maximum number of lines contained in the history file. When
3891 this variable is assigned a value, the history file is truncated,
3892 if necessary, to contain no more than that number of lines. The
3893 default value is 500. The history file is also truncated to this
3894 size after writing it when an interactive shell exits.
3897 Contains the name of a file in the same format as `/etc/hosts' that
3898 should be read when the shell needs to complete a hostname. You
3899 can change the file interactively; the next time you attempt to
3900 complete a hostname, Bash will add the contents of the new file to
3901 the already existing database.
3904 The name of the current host.
3907 A string describing the machine Bash is running on.
3910 Controls the action of the shell on receipt of an `EOF' character
3911 as the sole input. If set, the value denotes the number of
3912 consecutive `EOF' characters that can be read as the first
3913 character on an input line before the shell will exit. If the
3914 variable exists but does not have a numeric value (or has no
3915 value) then the default is 10. If the variable does not exist,
3916 then `EOF' signifies the end of input to the shell. This is only
3917 in effect for interactive shells.
3920 The name of the Readline startup file, overriding the default of
3924 Used to determine the locale category for any category not
3925 specifically selected with a variable starting with `LC_'.
3928 This variable overrides the value of `LANG' and any other `LC_'
3929 variable specifying a locale category.
3932 This variable determines the collation order used when sorting the
3933 results of filename expansion, and determines the behavior of
3934 range expressions, equivalence classes, and collating sequences
3935 within filename expansion and pattern matching (*note Filename
3939 This variable determines the interpretation of characters and the
3940 behavior of character classes within filename expansion and pattern
3941 matching (*note Filename Expansion::.).
3944 This variable determines the locale used to translate double-quoted
3945 strings preceded by a `$' (*note Locale Translation::.).
3948 The line number in the script or shell function currently
3952 A string that fully describes the system type on which Bash is
3953 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
3956 How often (in seconds) that the shell should check for mail in the
3957 files specified in the `MAILPATH' or `MAIL' variables.
3960 The previous working directory as set by the `cd' builtin.
3963 If set to the value 1, Bash displays error messages generated by
3964 the `getopts' builtin command.
3967 A string describing the operating system Bash is running on.
3970 An array variable (*note Arrays::.) containing a list of exit
3971 status values from the processes in the most-recently-executed
3972 foreground pipeline (which may contain only a single command).
3975 The process id of the shell's parent process. This variable is
3979 If present, this contains a string which is a command to execute
3980 before the printing of each primary prompt (`$PS1').
3983 The value of this variable is used as the prompt for the `select'
3984 command. If this variable is not set, the `select' command
3988 This is the prompt printed before the command line is echoed when
3989 the `-x' option is set (*note The Set Builtin::.). The first
3990 character of `PS4' is replicated multiple times, as necessary, to
3991 indicate multiple levels of indirection. The default is `+ '.
3994 The current working directory as set by the `cd' builtin.
3997 Each time this parameter is referenced, a random integer between 0
3998 and 32767 is generated. Assigning a value to this variable seeds
3999 the random number generator.
4002 The default variable for the `read' builtin.
4005 This variable expands to the number of seconds since the shell was
4006 started. Assignment to this variable resets the count to the
4007 value assigned, and the expanded value becomes the value assigned
4008 plus the number of seconds since the assignment.
4011 A colon-separated list of enabled shell options. Each word in the
4012 list is a valid argument for the `-o' option to the `set' builtin
4013 command (*note The Set Builtin::.). The options appearing in
4014 `SHELLOPTS' are those reported as `on' by `set -o'. If this
4015 variable is in the environment when Bash starts up, each shell
4016 option in the list will be enabled before reading any startup
4017 files. This variable is readonly.
4020 Incremented by one each time a new instance of Bash is started.
4021 This is intended to be a count of how deeply your Bash shells are
4025 The value of this parameter is used as a format string specifying
4026 how the timing information for pipelines prefixed with the `time'
4027 reserved word should be displayed. The `%' character introduces an
4028 escape sequence that is expanded to a time value or other
4029 information. The escape sequences and their meanings are as
4030 follows; the braces denote optional portions.
4036 The elapsed time in seconds.
4039 The number of CPU seconds spent in user mode.
4042 The number of CPU seconds spent in system mode.
4045 The CPU percentage, computed as (%U + %S) / %R.
4047 The optional P is a digit specifying the precision, the number of
4048 fractional digits after a decimal point. A value of 0 causes no
4049 decimal point or fraction to be output. At most three places
4050 after the decimal point may be specified; values of P greater than
4051 3 are changed to 3. If P is not specified, the value 3 is used.
4053 The optional `l' specifies a longer format, including minutes, of
4054 the form MMmSS.FFs. The value of P determines whether or not the
4055 fraction is included.
4057 If this variable is not set, Bash acts as if it had the value
4058 `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS''
4059 If the value is null, no timing information is displayed. A
4060 trailing newline is added when the format string is displayed.
4063 If set to a value greater than zero, the value is interpreted as
4064 the number of seconds to wait for input after issuing the primary
4065 prompt. Bash terminates after that number of seconds if input does
4069 The numeric real user id of the current user. This variable is
4073 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Variables, Up: Bash Features
4078 The shell allows arithmetic expressions to be evaluated, as one of
4079 the shell expansions or by the `let' builtin.
4081 Evaluation is done in long integers with no check for overflow,
4082 though division by 0 is trapped and flagged as an error. The following
4083 list of operators is grouped into levels of equal-precedence operators.
4084 The levels are listed in order of decreasing precedence.
4087 unary minus and plus
4090 logical and bitwise negation
4096 multiplication, division, remainder
4099 addition, subtraction
4102 left and right bitwise shifts
4108 equality and inequality
4114 bitwise exclusive OR
4125 `expr ? expr : expr'
4126 conditional evaluation
4128 `= *= /= %= += -= <<= >>= &= ^= |='
4131 Shell variables are allowed as operands; parameter expansion is
4132 performed before the expression is evaluated. The value of a parameter
4133 is coerced to a long integer within an expression. A shell variable
4134 need not have its integer attribute turned on to be used in an
4137 Constants with a leading 0 are interpreted as octal numbers. A
4138 leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the
4139 form [BASE`#']N, where BASE is a decimal number between 2 and 64
4140 representing the arithmetic base, and N is a number in that base. If
4141 BASE is omitted, then base 10 is used. The digits greater than 9 are
4142 represented by the lowercase letters, the uppercase letters, `_', and
4143 `@', in that order. If BASE is less than or equal to 36, lowercase and
4144 uppercase letters may be used interchangably to represent numbers
4147 Operators are evaluated in order of precedence. Sub-expressions in
4148 parentheses are evaluated first and may override the precedence rules
4152 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
4159 * Alias Builtins:: Builtins commands to maniuplate aliases.
4161 Aliases allow a string to be substituted for a word when it is used
4162 as the first word of a simple command. The shell maintains a list of
4163 ALIASES that may be set and unset with the `alias' and `unalias'
4166 The first word of each simple command, if unquoted, is checked to see
4167 if it has an alias. If so, that word is replaced by the text of the
4168 alias. The alias name and the replacement text may contain any valid
4169 shell input, including shell metacharacters, with the exception that
4170 the alias name may not contain `='. The first word of the replacement
4171 text is tested for aliases, but a word that is identical to an alias
4172 being expanded is not expanded a second time. This means that one may
4173 alias `ls' to `"ls -F"', for instance, and Bash does not try to
4174 recursively expand the replacement text. If the last character of the
4175 alias value is a space or tab character, then the next command word
4176 following the alias is also checked for alias expansion.
4178 Aliases are created and listed with the `alias' command, and removed
4179 with the `unalias' command.
4181 There is no mechanism for using arguments in the replacement text,
4182 as in `csh'. If arguments are needed, a shell function should be used
4183 (*note Shell Functions::.).
4185 Aliases are not expanded when the shell is not interactive, unless
4186 the `expand_aliases' shell option is set using `shopt' (*note Bash
4189 The rules concerning the definition and use of aliases are somewhat
4190 confusing. Bash always reads at least one complete line of input
4191 before executing any of the commands on that line. Aliases are
4192 expanded when a command is read, not when it is executed. Therefore, an
4193 alias definition appearing on the same line as another command does not
4194 take effect until the next line of input is read. The commands
4195 following the alias definition on that line are not affected by the new
4196 alias. This behavior is also an issue when functions are executed.
4197 Aliases are expanded when a function definition is read, not when the
4198 function is executed, because a function definition is itself a
4199 compound command. As a consequence, aliases defined in a function are
4200 not available until after that function is executed. To be safe,
4201 always put alias definitions on a separate line, and do not use `alias'
4202 in compound commands.
4204 For almost every purpose, aliases are superseded by shell functions.
4207 File: bashref.info, Node: Alias Builtins, Up: Aliases
4213 alias [`-p'] [NAME[=VALUE] ...]
4215 Without arguments or with the `-p' option, `alias' prints the list
4216 of aliases on the standard output in a form that allows them to be
4217 reused as input. If arguments are supplied, an alias is defined
4218 for each NAME whose VALUE is given. If no VALUE is given, the name
4219 and value of the alias is printed.
4222 unalias [-a] [NAME ... ]
4224 Remove each NAME from the list of aliases. If `-a' is supplied,
4225 all aliases are removed.
4228 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
4233 Bash provides one-dimensional array variables. Any variable may be
4234 used as an array; the `declare' builtin will explicitly declare an
4235 array. There is no maximum limit on the size of an array, nor any
4236 requirement that members be indexed or assigned contiguously. Arrays
4239 An array is created automatically if any variable is assigned to
4241 name[SUBSCRIPT]=VALUE
4243 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
4244 to a number greater than or equal to zero. To explicitly declare an
4249 declare -a NAME[SUBSCRIPT]
4251 is also accepted; the SUBSCRIPT is ignored. Attributes may be
4252 specified for an array variable using the `declare' and `readonly'
4253 builtins. Each attribute applies to all members of an array.
4255 Arrays are assigned to using compound assignments of the form
4256 name=(value1 ... valueN)
4258 where each VALUE is of the form `[[SUBSCRIPT]=]'STRING. If the
4259 optional subscript is supplied, that index is assigned to; otherwise
4260 the index of the element assigned is the last index assigned to by the
4261 statement plus one. Indexing starts at zero. This syntax is also
4262 accepted by the `declare' builtin. Individual array elements may be
4263 assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above.
4265 Any element of an array may be referenced using
4266 `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts
4267 with the shell's filename expansion operators. If the SUBSCRIPT is `@'
4268 or `*', the word expands to all members of the array NAME. These
4269 subscripts differ only when the word appears within double quotes. If
4270 the word is double-quoted, `${name[*]}' expands to a single word with
4271 the value of each array member separated by the first character of the
4272 `IFS' variable, and `${name[@]}' expands each element of NAME to a
4273 separate word. When there are no array members, `${name[@]}' expands
4274 to nothing. This is analogous to the expansion of the special
4275 parameters `@' and `*'. `${#name['SUBSCRIPT`]}' expands to the length
4276 of `${name['SUBSCRIPT`]}'. If SUBSCRIPT is `@' or `*', the expansion
4277 is the number of elements in the array. Referencing an array variable
4278 without a subscript is equivalent to referencing element zero.
4280 The `unset' builtin is used to destroy arrays. `unset'
4281 `name[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
4282 `unset' NAME, where NAME is an array, removes the entire array. A
4283 subscript of `*' or `@' also removes the entire array.
4285 The `declare', `local', and `readonly' builtins each accept a `-a'
4286 option to specify an array. The `read' builtin accepts a `-a' option
4287 to assign a list of words read from the standard input to an array, and
4288 can read values from the standard input into individual array elements.
4289 The `set' and `declare' builtins display array values in a way that
4290 allows them to be reused as input.
4293 File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features
4298 The directory stack is a list of recently-visited directories. The
4299 `pushd' builtin adds directories to the stack as it changes the current
4300 directory, and the `popd' builtin removes specified directories from
4301 the stack and changes the current directory to the directory removed.
4302 The `dirs' builtin displays the contents of the directory stack.
4304 The contents of the directory stack are also visible as the value of
4305 the `DIRSTACK' shell variable.
4308 dirs [+N | -N] [-clvp]
4309 Display the list of currently remembered directories. Directories
4310 are added to the list with the `pushd' command; the `popd' command
4311 removes directories from the list.
4313 Displays the Nth directory (counting from the left of the
4314 list printed by `dirs' when invoked without options), starting
4318 Displays the Nth directory (counting from the right of the
4319 list printed by `dirs' when invoked without options), starting
4323 Clears the directory stack by deleting all of the elements.
4326 Produces a longer listing; the default listing format uses a
4327 tilde to denote the home directory.
4330 Causes `dirs' to print the directory stack with one entry per
4334 Causes `dirs' to print the directory stack with one entry per
4335 line, prefixing each entry with its index in the stack.
4340 Remove the top entry from the directory stack, and `cd' to the new
4341 top directory. When no arguments are given, `popd' removes the
4342 top directory from the stack and performs a `cd' to the new top
4343 directory. The elements are numbered from 0 starting at the first
4344 directory listed with `dirs'; i.e., `popd' is equivalent to `popd
4347 Removes the Nth directory (counting from the left of the list
4348 printed by `dirs'), starting with zero.
4351 Removes the Nth directory (counting from the right of the
4352 list printed by `dirs'), starting with zero.
4355 Suppresses the normal change of directory when removing
4356 directories from the stack, so that only the stack is
4360 pushd [DIR | +N | -N] [-n]
4362 Save the current directory on the top of the directory stack and
4363 then `cd' to DIR. With no arguments, `pushd' exchanges the top
4367 Brings the Nth directory (counting from the left of the list
4368 printed by `dirs', starting with zero) to the top of the list
4369 by rotating the stack.
4372 Brings the Nth directory (counting from the right of the list
4373 printed by `dirs', starting with zero) to the top of the list
4374 by rotating the stack.
4377 Suppresses the normal change of directory when adding
4378 directories to the stack, so that only the stack is
4382 Makes the current working directory be the top of the stack,
4383 and then executes the equivalent of ``cd' DIR'. `cd's to DIR.
4386 File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
4388 Controlling the Prompt
4389 ======================
4391 The value of the variable `PROMPT_COMMAND' is examined just before
4392 Bash prints each primary prompt. If it is set and non-null, then the
4393 value is executed just as if it had been typed on the command line.
4395 In addition, the following table describes the special characters
4396 which can appear in the prompt variables:
4402 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
4405 An escape character.
4408 The hostname, up to the first `.'.
4420 The name of the shell, the basename of `$0' (the portion following
4424 The time, in 24-hour HH:MM:SS format.
4427 The time, in 12-hour HH:MM:SS format.
4430 The time, in 12-hour am/pm format.
4433 The username of the current user.
4436 The version of Bash (e.g., 2.00)
4439 The release of Bash, version + patchlevel (e.g., 2.00.0)
4442 The current working directory.
4445 The basename of `$PWD'.
4448 The history number of this command.
4451 The command number of this command.
4454 If the effective uid is 0, `#', otherwise `$'.
4457 The character whose ASCII code is the octal value NNN.
4463 Begin a sequence of non-printing characters. This could be used to
4464 embed a terminal control sequence into the prompt.
4467 End a sequence of non-printing characters.
4470 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features
4472 The Restricted Shell
4473 ====================
4475 If Bash is started with the name `rbash', or the `--restricted'
4476 option is supplied at invocation, the shell becomes restricted. A
4477 restricted shell is used to set up an environment more controlled than
4478 the standard shell. A restricted shell behaves identically to `bash'
4479 with the exception that the following are disallowed:
4480 * Changing directories with the `cd' builtin.
4482 * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or
4483 `BASH_ENV' variables.
4485 * Specifying command names containing slashes.
4487 * Specifying a filename containing a slash as an argument to the `.'
4490 * Importing function definitions from the shell environment at
4493 * Parsing the value of `SHELLOPTS' from the shell environment at
4496 * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>'
4497 redirection operators.
4499 * Using the `exec' builtin to replace the shell with another command.
4501 * Adding or deleting builtin commands with the `-f' and `-d' options
4502 to the `enable' builtin.
4504 * Specifying the `-p' option to the `command' builtin.
4506 * Turning off restricted mode with `set +r' or `set +o restricted'.
4509 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
4514 Starting Bash with the `--posix' command-line option or executing
4515 `set -o posix' while Bash is running will cause Bash to conform more
4516 closely to the POSIX.2 standard by changing the behavior to match that
4517 specified by POSIX.2 in areas where the Bash default differs.
4519 The following list is what's changed when `POSIX mode' is in effect:
4521 1. When a command in the hash table no longer exists, Bash will
4522 re-search `$PATH' to find the new location. This is also
4523 available with `shopt -s checkhash'.
4525 2. The `>&' redirection does not redirect stdout and stderr.
4527 3. The message printed by the job control code and builtins when a job
4528 exits with a non-zero status is `Done(status)'.
4530 4. Reserved words may not be aliased.
4532 5. The POSIX.2 `PS1' and `PS2' expansions of `!' to the history
4533 number and `!!' to `!' are enabled, and parameter expansion is
4534 performed on the values of `PS1' and `PS2' regardless of the
4535 setting of the `promptvars' option.
4537 6. Interactive comments are enabled by default. (Bash has them on by
4540 7. The POSIX.2 startup files are executed (`$ENV') rather than the
4543 8. Tilde expansion is only performed on assignments preceding a
4544 command name, rather than on all assignment statements on the line.
4546 9. The default history file is `~/.sh_history' (this is the default
4547 value of `$HISTFILE').
4549 10. The output of `kill -l' prints all the signal names on a single
4550 line, separated by spaces.
4552 11. Non-interactive shells exit if FILENAME in `.' FILENAME is not
4555 12. Non-interactive shells exit if a syntax error in an arithmetic
4556 expansion results in an invalid expression.
4558 13. Redirection operators do not perform filename expansion on the word
4559 in the redirection unless the shell is interactive.
4561 14. Function names must be valid shell `name's. That is, they may not
4562 contain characters other than letters, digits, and underscores, and
4563 may not start with a digit. Declaring a function with an invalid
4564 name causes a fatal syntax error in non-interactive shells.
4566 15. POSIX.2 `special' builtins are found before shell functions during
4569 16. If a POSIX.2 special builtin returns an error status, a
4570 non-interactive shell exits. The fatal errors are those listed in
4571 the POSIX.2 standard, and include things like passing incorrect
4572 options, redirection errors, variable assignment errors for
4573 assignments preceding the command name, and so on.
4575 17. If the `cd' builtin finds a directory to change to using
4576 `$CDPATH', the value it assigns to the `PWD' variable does not
4577 contain any symbolic links, as if `cd -P' had been executed.
4579 18. If `$CDPATH' is set, the `cd' builtin will not implicitly append
4580 the current directory to it. This means that `cd' will fail if no
4581 valid directory name can be constructed from any of the entries in
4582 `$CDPATH', even if the a directory with the same name as the name
4583 given as an argument to `cd' exists in the current directory.
4585 19. A non-interactive shell exits with an error status if a variable
4586 assignment error occurs when no command name follows the assignment
4587 statements. A variable assignment error occurs, for example, when
4588 trying to assign a value to a readonly variable.
4590 20. A non-interactive shell exits with an error status if the iteration
4591 variable in a `for' statement or the selection variable in a
4592 `select' statement is a readonly variable.
4594 21. Process substitution is not available.
4596 22. Assignment statements preceding POSIX.2 special builtins persist
4597 in the shell environment after the builtin completes.
4599 23. The `export' and `readonly' builtin commands display their output
4600 in the format required by POSIX.2.
4603 There is other POSIX.2 behavior that Bash does not implement.
4606 1. Assignment statements affect the execution environment of all
4607 builtins, not just special ones.
4610 File: bashref.info, Node: Job Control, Next: Using History Interactively, Prev: Bash Features, Up: Top
4615 This chapter discusses what job control is, how it works, and how
4616 Bash allows you to access its facilities.
4620 * Job Control Basics:: How job control works.
4621 * Job Control Builtins:: Bash builtin commands used to interact
4623 * Job Control Variables:: Variables Bash uses to customize job
4627 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
4632 Job control refers to the ability to selectively stop (suspend) the
4633 execution of processes and continue (resume) their execution at a later
4634 point. A user typically employs this facility via an interactive
4635 interface supplied jointly by the system's terminal driver and Bash.
4637 The shell associates a JOB with each pipeline. It keeps a table of
4638 currently executing jobs, which may be listed with the `jobs' command.
4639 When Bash starts a job asynchronously, it prints a line that looks like:
4642 indicating that this job is job number 1 and that the process ID of the
4643 last process in the pipeline associated with this job is 25647. All of
4644 the processes in a single pipeline are members of the same job. Bash
4645 uses the JOB abstraction as the basis for job control.
4647 To facilitate the implementation of the user interface to job
4648 control, the system maintains the notion of a current terminal process
4649 group ID. Members of this process group (processes whose process group
4650 ID is equal to the current terminal process group ID) receive
4651 keyboard-generated signals such as `SIGINT'. These processes are said
4652 to be in the foreground. Background processes are those whose process
4653 group ID differs from the terminal's; such processes are immune to
4654 keyboard-generated signals. Only foreground processes are allowed to
4655 read from or write to the terminal. Background processes which attempt
4656 to read from (write to) the terminal are sent a `SIGTTIN' (`SIGTTOU')
4657 signal by the terminal driver, which, unless caught, suspends the
4660 If the operating system on which Bash is running supports job
4661 control, Bash contains facilities to use it. Typing the SUSPEND
4662 character (typically `^Z', Control-Z) while a process is running causes
4663 that process to be stopped and returns control to Bash. Typing the
4664 DELAYED SUSPEND character (typically `^Y', Control-Y) causes the
4665 process to be stopped when it attempts to read input from the terminal,
4666 and control to be returned to Bash. The user then manipulates the
4667 state of this job, using the `bg' command to continue it in the
4668 background, the `fg' command to continue it in the foreground, or the
4669 `kill' command to kill it. A `^Z' takes effect immediately, and has
4670 the additional side effect of causing pending output and typeahead to
4673 There are a number of ways to refer to a job in the shell. The
4674 character `%' introduces a job name. Job number `n' may be referred to
4675 as `%n'. A job may also be referred to using a prefix of the name used
4676 to start it, or using a substring that appears in its command line.
4677 For example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the
4678 other hand, refers to any job containing the string `ce' in its command
4679 line. If the prefix or substring matches more than one job, Bash
4680 reports an error. The symbols `%%' and `%+' refer to the shell's
4681 notion of the current job, which is the last job stopped while it was
4682 in the foreground or started in the background. The previous job may
4683 be referenced using `%-'. In output pertaining to jobs (e.g., the
4684 output of the `jobs' command), the current job is always flagged with a
4685 `+', and the previous job with a `-'.
4687 Simply naming a job can be used to bring it into the foreground:
4688 `%1' is a synonym for `fg %1', bringing job 1 from the background into
4689 the foreground. Similarly, `%1 &' resumes job 1 in the background,
4690 equivalent to `bg %1'
4692 The shell learns immediately whenever a job changes state.
4693 Normally, Bash waits until it is about to print a prompt before
4694 reporting changes in a job's status so as to not interrupt any other
4695 output. If the the `-b' option to the `set' builtin is enabled, Bash
4696 reports such changes immediately (*note The Set Builtin::.).
4698 If an attempt to exit Bash is while jobs are stopped, the shell
4699 prints a message warning that there are stopped jobs. The `jobs'
4700 command may then be used to inspect their status. If a second attempt
4701 to exit is made without an intervening command, Bash does not print
4702 another warning, and the stopped jobs are terminated.
4705 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
4707 Job Control Builtins
4708 ====================
4712 Resume the suspended job JOBSPEC in the background, as if it had
4713 been started with `&'. If JOBSPEC is not supplied, the current
4714 job is used. The return status is zero unless it is run when job
4715 control is not enabled, or, when run with job control enabled, if
4716 JOBSPEC was not found or JOBSPEC specifies a job that was started
4717 without job control.
4721 Resume the job JOBSPEC in the foreground and make it the current
4722 job. If JOBSPEC is not supplied, the current job is used. The
4723 return status is that of the command placed into the foreground,
4724 or non-zero if run when job control is disabled or, when run with
4725 job control enabled, JOBSPEC does not specify a valid job or
4726 JOBSPEC specifies a job that was started without job control.
4729 jobs [-lpnrs] [JOBSPEC]
4730 jobs -x COMMAND [ARGUMENTS]
4732 The first form lists the active jobs. The options have the
4736 List process IDs in addition to the normal information.
4739 Display information only about jobs that have changed status
4740 since the user was last notified of their status.
4743 List only the process ID of the job's process group leader.
4746 Restrict output to running jobs.
4749 Restrict output to stopped jobs.
4751 If JOBSPEC is given, output is restricted to information about
4752 that job. If JOBSPEC is not supplied, the status of all jobs is
4755 If the `-x' option is supplied, `jobs' replaces any JOBSPEC found
4756 in COMMAND or ARGUMENTS with the corresponding process group ID,
4757 and executes COMMAND, passing it ARGUMENTs, returning its exit
4761 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
4762 kill -l [EXIT_STATUS]
4763 Send a signal specified by SIGSPEC or SIGNUM to the process named
4764 by job specification JOBSPEC or process ID PID. SIGSPEC is either
4765 a signal name such as `SIGINT' (with or without the `SIG' prefix)
4766 or a signal number; SIGNUM is a signal number. If SIGSPEC and
4767 SIGNUM are not present, `SIGTERM' is used. The `-l' option lists
4768 the signal names. If any arguments are supplied when `-l' is
4769 given, the names of the signals corresponding to the arguments are
4770 listed, and the return status is zero. EXIT_STATUS is a number
4771 specifying a signal number or the exit status of a process
4772 terminated by a signal. The return status is zero if at least one
4773 signal was successfully sent, or non-zero if an error occurs or an
4774 invalid option is encountered.
4778 Wait until the child process specified by process ID PID or job
4779 specification JOBSPEC exits and return the exit status of the last
4780 command waited for. If a job spec is given, all processes in the
4781 job are waited for. If no arguments are given, all currently
4782 active child processes are waited for, and the return status is
4783 zero. If neither JOBSPEC nor PID specifies an active child process
4784 of the shell, the return status is 127.
4787 disown [-ar] [-h] [JOBSPEC ...]
4788 Without options, each JOBSPEC is removed from the table of active
4789 jobs. If the `-h' option is given, the job is not removed from
4790 the table, but is marked so that `SIGHUP' is not sent to the job
4791 if the shell receives a `SIGHUP'. If JOBSPEC is not present, and
4792 neither the `-a' nor `-r' option is supplied, the current job is
4793 used. If no JOBSPEC is supplied, the `-a' option means to remove
4794 or mark all jobs; the `-r' option without a JOBSPEC argument
4795 restricts operation to running jobs.
4799 Suspend the execution of this shell until it receives a `SIGCONT'
4800 signal. The `-f' option means to suspend even if the shell is a
4803 When job control is not active, the `kill' and `wait' builtins do
4804 not accept JOBSPEC arguments. They must be supplied process IDs.
4807 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
4809 Job Control Variables
4810 =====================
4813 This variable controls how the shell interacts with the user and
4814 job control. If this variable exists then single word simple
4815 commands without redirections are treated as candidates for
4816 resumption of an existing job. There is no ambiguity allowed; if
4817 there is more than one job beginning with the string typed, then
4818 the most recently accessed job will be selected. The name of a
4819 stopped job, in this context, is the command line used to start
4820 it. If this variable is set to the value `exact', the string
4821 supplied must match the name of a stopped job exactly; if set to
4822 `substring', the string supplied needs to match a substring of the
4823 name of a stopped job. The `substring' value provides
4824 functionality analogous to the `%?' job ID (*note Job Control
4825 Basics::.). If set to any other value, the supplied string must
4826 be a prefix of a stopped job's name; this provides functionality
4827 analogous to the `%' job ID.
4830 File: bashref.info, Node: Using History Interactively, Next: Command Line Editing, Prev: Job Control, Up: Top
4832 Using History Interactively
4833 ***************************
4835 This chapter describes how to use the GNU History Library
4836 interactively, from a user's standpoint. It should be considered a
4837 user's guide. For information on using the GNU History Library in
4838 other programs, see the GNU Readline Library Manual.
4842 * Bash History Facilities:: How Bash lets you manipulate your command
4844 * Bash History Builtins:: The Bash builtin commands that manipulate
4845 the command history.
4846 * History Interaction:: What it feels like using History as a user.
4849 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
4851 Bash History Facilities
4852 =======================
4854 When the `-o history' option to the `set' builtin is enabled (*note
4855 The Set Builtin::.), the shell provides access to the COMMAND HISTORY,
4856 the list of commands previously typed. The text of the last `HISTSIZE'
4857 commands (default 500) is saved in a history list. The shell stores
4858 each command in the history list prior to parameter and variable
4859 expansion but after history expansion is performed, subject to the
4860 values of the shell variables `HISTIGNORE' and `HISTCONTROL'. When the
4861 shell starts up, the history is initialized from the file named by the
4862 `HISTFILE' variable (default `~/.bash_history'). `HISTFILE' is
4863 truncated, if necessary, to contain no more than the number of lines
4864 specified by the value of the `HISTFILESIZE' variable. When an
4865 interactive shell exits, the last `HISTSIZE' lines are copied from the
4866 history list to `HISTFILE'. If the `histappend' shell option is set
4867 (*note Bash Builtins::.), the lines are appended to the history file,
4868 otherwise the history file is overwritten. If `HISTFILE' is unset, or
4869 if the history file is unwritable, the history is not saved. After
4870 saving the history, the history file is truncated to contain no more
4871 than `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no
4872 truncation is performed.
4874 The builtin command `fc' may be used to list or edit and re-execute
4875 a portion of the history list. The `history' builtin can be used to
4876 display or modify the history list and manipulate the history file.
4877 When using the command-line editing, search commands are available in
4878 each editing mode that provide access to the history list.
4880 The shell allows control over which commands are saved on the history
4881 list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause
4882 the shell to save only a subset of the commands entered. The `cmdhist'
4883 shell option, if enabled, causes the shell to attempt to save each line
4884 of a multi-line command in the same history entry, adding semicolons
4885 where necessary to preserve syntactic correctness. The `lithist' shell
4886 option causes the shell to save the command with embedded newlines
4887 instead of semicolons. *Note Bash Builtins::, for a description of
4891 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
4893 Bash History Builtins
4894 =====================
4896 Bash provides two builtin commands that allow you to manipulate the
4897 history list and history file.
4900 `fc [-e ENAME] [-nlr] [FIRST] [LAST]'
4901 `fc -s [PAT=REP] [COMMAND]'
4903 Fix Command. In the first form, a range of commands from FIRST to
4904 LAST is selected from the history list. Both FIRST and LAST may
4905 be specified as a string (to locate the most recent command
4906 beginning with that string) or as a number (an index into the
4907 history list, where a negative number is used as an offset from the
4908 current command number). If LAST is not specified it is set to
4909 FIRST. If FIRST is not specified it is set to the previous
4910 command for editing and -16 for listing. If the `-l' flag is
4911 given, the commands are listed on standard output. The `-n' flag
4912 suppresses the command numbers when listing. The `-r' flag
4913 reverses the order of the listing. Otherwise, the editor given by
4914 ENAME is invoked on a file containing those commands. If ENAME is
4915 not given, the value of the following variable expansion is used:
4916 `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
4917 `FCEDIT' variable if set, or the value of the `EDITOR' variable if
4918 that is set, or `vi' if neither is set. When editing is complete,
4919 the edited commands are echoed and executed.
4921 In the second form, COMMAND is re-executed after each instance of
4922 PAT in the selected command is replaced by REP.
4924 A useful alias to use with the `fc' command is `r='fc -s'', so
4925 that typing `r cc' runs the last command beginning with `cc' and
4926 typing `r' re-executes the last command (*note Aliases::.).
4930 history [-anrw] [FILENAME]
4933 Display the history list with line numbers. Lines prefixed with
4934 with a `*' have been modified. An argument of N says to list only
4935 the last N lines. Options, if supplied, have the following
4939 Write out the current history to the history file.
4942 Read the current history file and append its contents to the
4946 Append the new history lines (history lines entered since the
4947 beginning of the current Bash session) to the history file.
4950 Append the history lines not already read from the history
4951 file to the current history list. These are lines appended
4952 to the history file since the beginning of the current Bash
4956 Clear the history list. This may be combined with the other
4957 options to replace the history list completely.
4960 The ARGs are added to the end of the history list as a single
4964 Perform history substitution on the ARGs and display the
4965 result on the standard output, without storing the results in
4968 When the `-w', `-r', `-a', or `-n' option is used, if FILENAME is
4969 given, then it is used as the history file. If not, then the
4970 value of the `HISTFILE' variable is used.
4973 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
4978 The History library provides a history expansion feature that is
4979 similar to the history expansion provided by `csh'. This section
4980 describes the syntax used to manipulate the history information.
4982 History expansions introduce words from the history list into the
4983 input stream, making it easy to repeat commands, insert the arguments
4984 to a previous command into the current input line, or fix errors in
4985 previous commands quickly.
4987 History expansion takes place in two parts. The first is to
4988 determine which line from the history list should be used during
4989 substitution. The second is to select portions of that line for
4990 inclusion into the current one. The line selected from the history is
4991 called the "event", and the portions of that line that are acted upon
4992 are called "words". Various "modifiers" are available to manipulate
4993 the selected words. The line is broken into words in the same fashion
4994 that Bash does, so that several words surrounded by quotes are
4995 considered one word. History expansions are introduced by the
4996 appearance of the history expansion character, which is `!' by default.
4997 Only `\' and `'' may be used to escape the history expansion character.
4999 Several shell options settable with the `shopt' builtin (*note Bash
5000 Builtins::.) may be used to tailor the behavior of history expansion.
5001 If the `histverify' shell option is enabled, and Readline is being
5002 used, history substitutions are not immediately passed to the shell
5003 parser. Instead, the expanded line is reloaded into the Readline
5004 editing buffer for further modification. If Readline is being used,
5005 and the `histreedit' shell option is enabled, a failed history
5006 expansion will be reloaded into the Readline editing buffer for
5007 correction. The `-p' option to the `history' builtin command may be
5008 used to see what a history expansion will do before using it. The `-s'
5009 option to the `history' builtin may be used to add commands to the end
5010 of the history list without actually executing them, so that they are
5011 available for subsequent recall. This is most useful in conjunction
5014 The shell allows control of the various characters used by the
5015 history expansion mechanism with the `histchars' variable.
5019 * Event Designators:: How to specify which history line to use.
5020 * Word Designators:: Specifying which words are of interest.
5021 * Modifiers:: Modifying the results of substitution.
5024 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
5029 An event designator is a reference to a command line entry in the
5033 Start a history substitution, except when followed by a space, tab,
5034 the end of the line, `=' or `('.
5037 Refer to command line N.
5040 Refer to the command N lines back.
5043 Refer to the previous command. This is a synonym for `!-1'.
5046 Refer to the most recent command starting with STRING.
5049 Refer to the most recent command containing STRING. The trailing
5050 `?' may be omitted if the STRING is followed immediately by a
5054 Quick Substitution. Repeat the last command, replacing STRING1
5055 with STRING2. Equivalent to `!!:s/STRING1/STRING2/'.
5058 The entire command line typed so far.
5061 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
5066 Word designators are used to select desired words from the event. A
5067 `:' separates the event specification from the word designator. It may
5068 be omitted if the word designator begins with a `^', `$', `*', `-', or
5069 `%'. Words are numbered from the beginning of the line, with the first
5070 word being denoted by 0 (zero). Words are inserted into the current
5071 line separated by single spaces.
5074 The `0'th word. For many applications, this is the command word.
5080 The first argument; that is, word 1.
5086 The word matched by the most recent `?STRING?' search.
5089 A range of words; `-Y' abbreviates `0-Y'.
5092 All of the words, except the `0'th. This is a synonym for `1-$'.
5093 It is not an error to use `*' if there is just one word in the
5094 event; the empty string is returned in that case.
5100 Abbreviates `X-$' like `X*', but omits the last word.
5102 If a word designator is supplied without an event specification, the
5103 previous command is used as the event.
5106 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
5111 After the optional word designator, you can add a sequence of one or
5112 more of the following modifiers, each preceded by a `:'.
5115 Remove a trailing pathname component, leaving only the head.
5118 Remove all leading pathname components, leaving the tail.
5121 Remove a trailing suffix of the form `.SUFFIX', leaving the
5125 Remove all but the trailing suffix.
5128 Print the new command but do not execute it.
5131 Quote the substituted words, escaping further substitutions.
5134 Quote the substituted words as with `q', but break into words at
5135 spaces, tabs, and newlines.
5138 Substitute NEW for the first occurrence of OLD in the event line.
5139 Any delimiter may be used in place of `/'. The delimiter may be
5140 quoted in OLD and NEW with a single backslash. If `&' appears in
5141 NEW, it is replaced by OLD. A single backslash will quote the
5142 `&'. The final delimiter is optional if it is the last character
5146 Repeat the previous substitution.
5149 Cause changes to be applied over the entire event line. Used in
5150 conjunction with `s', as in `gs/OLD/NEW/', or with `&'.
5153 File: bashref.info, Node: Command Line Editing, Next: Installing Bash, Prev: Using History Interactively, Up: Top
5155 Command Line Editing
5156 ********************
5158 This chapter describes the basic features of the GNU command line
5163 * Introduction and Notation:: Notation used in this text.
5164 * Readline Interaction:: The minimum set of commands for editing a line.
5165 * Readline Init File:: Customizing Readline from a user's view.
5166 * Bindable Readline Commands:: A description of most of the Readline commands
5167 available for binding
5168 * Readline vi Mode:: A short description of how to make Readline
5169 behave like the vi editor.
5172 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
5174 Introduction to Line Editing
5175 ============================
5177 The following paragraphs describe the notation used to represent
5180 The text <C-k> is read as `Control-K' and describes the character
5181 produced when the <k> key is pressed while the Control key is depressed.
5183 The text <M-k> is read as `Meta-K' and describes the character
5184 produced when the meta key (if you have one) is depressed, and the <k>
5185 key is pressed. If you do not have a meta key, the identical keystroke
5186 can be generated by typing <ESC> first, and then typing <k>. Either
5187 process is known as "metafying" the <k> key.
5189 The text <M-C-k> is read as `Meta-Control-k' and describes the
5190 character produced by "metafying" <C-k>.
5192 In addition, several keys have their own names. Specifically,
5193 <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves
5194 when seen in this text, or in an init file (*note Readline Init
5198 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
5200 Readline Interaction
5201 ====================
5203 Often during an interactive session you type in a long line of text,
5204 only to notice that the first word on the line is misspelled. The
5205 Readline library gives you a set of commands for manipulating the text
5206 as you type it in, allowing you to just fix your typo, and not forcing
5207 you to retype the majority of the line. Using these editing commands,
5208 you move the cursor to the place that needs correction, and delete or
5209 insert the text of the corrections. Then, when you are satisfied with
5210 the line, you simply press <RETURN>. You do not have to be at the end
5211 of the line to press <RETURN>; the entire line is accepted regardless
5212 of the location of the cursor within the line.
5216 * Readline Bare Essentials:: The least you need to know about Readline.
5217 * Readline Movement Commands:: Moving about the input line.
5218 * Readline Killing Commands:: How to delete text, and how to get it back!
5219 * Readline Arguments:: Giving numeric arguments to commands.
5220 * Searching:: Searching through previous lines.
5223 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
5225 Readline Bare Essentials
5226 ------------------------
5228 In order to enter characters into the line, simply type them. The
5229 typed character appears where the cursor was, and then the cursor moves
5230 one space to the right. If you mistype a character, you can use your
5231 erase character to back up and delete the mistyped character.
5233 Sometimes you may miss typing a character that you wanted to type,
5234 and not notice your error until you have typed several other
5235 characters. In that case, you can type <C-b> to move the cursor to the
5236 left, and then correct your mistake. Afterwards, you can move the
5237 cursor to the right with <C-f>.
5239 When you add text in the middle of a line, you will notice that
5240 characters to the right of the cursor are `pushed over' to make room
5241 for the text that you have inserted. Likewise, when you delete text
5242 behind the cursor, characters to the right of the cursor are `pulled
5243 back' to fill in the blank space created by the removal of the text. A
5244 list of the basic bare essentials for editing the text of an input line
5248 Move back one character.
5251 Move forward one character.
5254 Delete the character to the left of the cursor.
5257 Delete the character underneath the cursor.
5260 Insert the character into the line at the cursor.
5263 Undo the last editing command. You can undo all the way back to an
5267 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
5269 Readline Movement Commands
5270 --------------------------
5272 The above table describes the most basic possible keystrokes that
5273 you need in order to do editing of the input line. For your
5274 convenience, many other commands have been added in addition to <C-b>,
5275 <C-f>, <C-d>, and <DEL>. Here are some commands for moving more rapidly
5279 Move to the start of the line.
5282 Move to the end of the line.
5285 Move forward a word, where a word is composed of letters and
5289 Move backward a word.
5292 Clear the screen, reprinting the current line at the top.
5294 Notice how <C-f> moves forward a character, while <M-f> moves
5295 forward a word. It is a loose convention that control keystrokes
5296 operate on characters while meta keystrokes operate on words.
5299 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
5301 Readline Killing Commands
5302 -------------------------
5304 "Killing" text means to delete the text from the line, but to save
5305 it away for later use, usually by "yanking" (re-inserting) it back into
5306 the line. If the description for a command says that it `kills' text,
5307 then you can be sure that you can get the text back in a different (or
5308 the same) place later.
5310 When you use a kill command, the text is saved in a "kill-ring".
5311 Any number of consecutive kills save all of the killed text together, so
5312 that when you yank it back, you get it all. The kill ring is not line
5313 specific; the text that you killed on a previously typed line is
5314 available to be yanked back later, when you are typing another line.
5316 Here is the list of commands for killing text.
5319 Kill the text from the current cursor position to the end of the
5323 Kill from the cursor to the end of the current word, or if between
5324 words, to the end of the next word.
5327 Kill from the cursor the start of the previous word, or if between
5328 words, to the start of the previous word.
5331 Kill from the cursor to the previous whitespace. This is
5332 different than <M-DEL> because the word boundaries differ.
5334 Here is how to "yank" the text back into the line. Yanking means to
5335 copy the most-recently-killed text from the kill buffer.
5338 Yank the most recently killed text back into the buffer at the
5342 Rotate the kill-ring, and yank the new top. You can only do this
5343 if the prior command is <C-y> or <M-y>.
5346 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
5351 You can pass numeric arguments to Readline commands. Sometimes the
5352 argument acts as a repeat count, other times it is the sign of the
5353 argument that is significant. If you pass a negative argument to a
5354 command which normally acts in a forward direction, that command will
5355 act in a backward direction. For example, to kill text back to the
5356 start of the line, you might type `M-- C-k'.
5358 The general way to pass numeric arguments to a command is to type
5359 meta digits before the command. If the first `digit' typed is a minus
5360 sign (<->), then the sign of the argument will be negative. Once you
5361 have typed one meta digit to get the argument started, you can type the
5362 remainder of the digits, and then the command. For example, to give
5363 the <C-d> command an argument of 10, you could type `M-1 0 C-d'.
5366 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
5368 Searching for Commands in the History
5369 -------------------------------------
5371 Readline provides commands for searching through the command history
5372 (*note Bash History Facilities::.) for lines containing a specified
5373 string. There are two search modes: INCREMENTAL and NON-INCREMENTAL.
5375 Incremental searches begin before the user has finished typing the
5376 search string. As each character of the search string is typed,
5377 Readline displays the next entry from the history matching the string
5378 typed so far. An incremental search requires only as many characters
5379 as needed to find the desired history entry. The characters present in
5380 the value of the ISEARCH-TERMINATORS variable are used to terminate an
5381 incremental search. If that variable has not been assigned a value,
5382 the <ESC> and <C-J> characters will terminate an incremental search.
5383 <C-g> will abort an incremental search and restore the original line.
5384 When the search is terminated, the history entry containing the search
5385 string becomes the current line. To find other matching entries in the
5386 history list, type <C-s> or <C-r> as appropriate. This will search
5387 backward or forward in the history for the next entry matching the
5388 search string typed so far. Any other key sequence bound to a Readline
5389 command will terminate the search and execute that command. For
5390 instance, a <RET> will terminate the search and accept the line,
5391 thereby executing the command from the history list.
5393 Non-incremental searches read the entire search string before
5394 starting to search for matching history lines. The search string may be
5395 typed by the user or be part of the contents of the current line.
5398 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
5403 Although the Readline library comes with a set of `emacs'-like
5404 keybindings installed by default, it is possible to use a different set
5405 of keybindings. Any user can customize programs that use Readline by
5406 putting commands in an "inputrc" file in his home directory. The name
5407 of this file is taken from the value of the shell variable `INPUTRC'.
5408 If that variable is unset, the default is `~/.inputrc'.
5410 When a program which uses the Readline library starts up, the init
5411 file is read, and the key bindings are set.
5413 In addition, the `C-x C-r' command re-reads this init file, thus
5414 incorporating any changes that you might have made to it.
5418 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
5420 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
5422 * Sample Init File:: An example inputrc file.
5425 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
5427 Readline Init File Syntax
5428 -------------------------
5430 There are only a few basic constructs allowed in the Readline init
5431 file. Blank lines are ignored. Lines beginning with a `#' are
5432 comments. Lines beginning with a `$' indicate conditional constructs
5433 (*note Conditional Init Constructs::.). Other lines denote variable
5434 settings and key bindings.
5437 You can modify the run-time behavior of Readline by altering the
5438 values of variables in Readline using the `set' command within the
5439 init file. Here is how to change from the default Emacs-like key
5440 binding to use `vi' line editing commands:
5444 A great deal of run-time behavior is changeable with the following
5448 Controls what happens when Readline wants to ring the
5449 terminal bell. If set to `none', Readline never rings the
5450 bell. If set to `visible', Readline uses a visible bell if
5451 one is available. If set to `audible' (the default),
5452 Readline attempts to ring the terminal's bell.
5455 The string to insert at the beginning of the line when the
5456 `insert-comment' command is executed. The default value is
5459 `completion-ignore-case'
5460 If set to `on', Readline performs filename matching and
5461 completion in a case-insensitive fashion. The default value
5464 `completion-query-items'
5465 The number of possible completions that determines when the
5466 user is asked whether he wants to see the list of
5467 possibilities. If the number of possible completions is
5468 greater than this value, Readline will ask the user whether
5469 or not he wishes to view them; otherwise, they are simply
5470 listed. The default limit is `100'.
5473 If set to `on', Readline will convert characters with the
5474 eighth bit set to an ASCII key sequence by stripping the
5475 eighth bit and prepending an <ESC> character, converting them
5476 to a meta-prefixed key sequence. The default value is `on'.
5478 `disable-completion'
5479 If set to `On', Readline will inhibit word completion.
5480 Completion characters will be inserted into the line as if
5481 they had been mapped to `self-insert'. The default is `off'.
5484 The `editing-mode' variable controls which default set of key
5485 bindings is used. By default, Readline starts up in Emacs
5486 editing mode, where the keystrokes are most similar to Emacs.
5487 This variable can be set to either `emacs' or `vi'.
5490 When set to `on', Readline will try to enable the application
5491 keypad when it is called. Some systems need this to enable
5492 the arrow keys. The default is `off'.
5495 If set to `on', tilde expansion is performed when Readline
5496 attempts word completion. The default is `off'.
5498 `horizontal-scroll-mode'
5499 This variable can be set to either `on' or `off'. Setting it
5500 to `on' means that the text of the lines being edited will
5501 scroll horizontally on a single screen line when they are
5502 longer than the width of the screen, instead of wrapping onto
5503 a new screen line. By default, this variable is set to `off'.
5506 If set to `on', Readline will enable eight-bit input (it will
5507 not strip the eighth bit from the characters it reads),
5508 regardless of what the terminal claims it can support. The
5509 default value is `off'. The name `meta-flag' is a synonym
5512 `isearch-terminators'
5513 The string of characters that should terminate an incremental
5514 search without subsequently executing the character as a
5515 command (*note Searching::.). If this variable has not been
5516 given a value, the characters <ESC> and <C-J> will terminate
5517 an incremental search.
5520 Sets Readline's idea of the current keymap for key binding
5521 commands. Acceptable `keymap' names are `emacs',
5522 `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
5523 `vi-command', and `vi-insert'. `vi' is equivalent to
5524 `vi-command'; `emacs' is equivalent to `emacs-standard'. The
5525 default value is `emacs'. The value of the `editing-mode'
5526 variable also affects the default keymap.
5529 If set to `on', completed directory names have a slash
5530 appended. The default is `on'.
5532 `mark-modified-lines'
5533 This variable, when set to `on', causes Readline to display an
5534 asterisk (`*') at the start of history lines which have been
5535 modified. This variable is `off' by default.
5538 If set to `on', Readline will display characters with the
5539 eighth bit set directly rather than as a meta-prefixed escape
5540 sequence. The default is `off'.
5542 `print-completions-horizontally'
5543 If set to `on', Readline will display completions with matches
5544 sorted horizontally in alphabetical order, rather than down
5545 the screen. The default is `off'.
5547 `show-all-if-ambiguous'
5548 This alters the default behavior of the completion functions.
5549 If set to `on', words which have more than one possible
5550 completion cause the matches to be listed immediately instead
5551 of ringing the bell. The default value is `off'.
5554 If set to `on', a character denoting a file's type is
5555 appended to the filename when listing possible completions.
5556 The default is `off'.
5559 The syntax for controlling key bindings in the init file is
5560 simple. First you have to know the name of the command that you
5561 want to change. The following sections contain tables of the
5562 command name, the default keybinding, if any, and a short
5563 description of what the command does.
5565 Once you know the name of the command, simply place the name of
5566 the key you wish to bind the command to, a colon, and then the
5567 name of the command on a line in the init file. The name of the
5568 key can be expressed in different ways, depending on which is most
5569 comfortable for you.
5571 KEYNAME: FUNCTION-NAME or MACRO
5572 KEYNAME is the name of a key spelled out in English. For
5574 Control-u: universal-argument
5575 Meta-Rubout: backward-kill-word
5576 Control-o: "> output"
5578 In the above example, <C-u> is bound to the function
5579 `universal-argument', and <C-o> is bound to run the macro
5580 expressed on the right hand side (that is, to insert the text
5581 `> output' into the line).
5583 "KEYSEQ": FUNCTION-NAME or MACRO
5584 KEYSEQ differs from KEYNAME above in that strings denoting an
5585 entire key sequence can be specified, by placing the key
5586 sequence in double quotes. Some GNU Emacs style key escapes
5587 can be used, as in the following example, but the special
5588 character names are not recognized.
5590 "\C-u": universal-argument
5591 "\C-x\C-r": re-read-init-file
5592 "\e[11~": "Function Key 1"
5594 In the above example, <C-u> is bound to the function
5595 `universal-argument' (just as it was in the first example),
5596 `<C-x> <C-r>' is bound to the function `re-read-init-file',
5597 and `<ESC> <[> <1> <1> <~>' is bound to insert the text
5600 The following GNU Emacs style escape sequences are available when
5601 specifying key sequences:
5621 In addition to the GNU Emacs style escape sequences, a second set
5622 of backslash escapes is available:
5649 the character whose ASCII code is the octal value NNN (one to
5653 the character whose ASCII code is the hexadecimal value NNN
5654 (one to three digits)
5656 When entering the text of a macro, single or double quotes must be
5657 used to indicate a macro definition. Unquoted text is assumed to
5658 be a function name. In the macro body, the backslash escapes
5659 described above are expanded. Backslash will quote any other
5660 character in the macro text, including `"' and `''. For example,
5661 the following binding will make `C-x \' insert a single `\' into
5666 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
5668 Conditional Init Constructs
5669 ---------------------------
5671 Readline implements a facility similar in spirit to the conditional
5672 compilation features of the C preprocessor which allows key bindings
5673 and variable settings to be performed as the result of tests. There
5674 are four parser directives used.
5677 The `$if' construct allows bindings to be made based on the
5678 editing mode, the terminal being used, or the application using
5679 Readline. The text of the test extends to the end of the line; no
5680 characters are required to isolate it.
5683 The `mode=' form of the `$if' directive is used to test
5684 whether Readline is in `emacs' or `vi' mode. This may be
5685 used in conjunction with the `set keymap' command, for
5686 instance, to set bindings in the `emacs-standard' and
5687 `emacs-ctlx' keymaps only if Readline is starting out in
5691 The `term=' form may be used to include terminal-specific key
5692 bindings, perhaps to bind the key sequences output by the
5693 terminal's function keys. The word on the right side of the
5694 `=' is tested against both the full name of the terminal and
5695 the portion of the terminal name before the first `-'. This
5696 allows `sun' to match both `sun' and `sun-cmd', for instance.
5699 The APPLICATION construct is used to include
5700 application-specific settings. Each program using the
5701 Readline library sets the APPLICATION NAME, and you can test
5702 for it. This could be used to bind key sequences to
5703 functions useful for a specific program. For instance, the
5704 following command adds a key sequence that quotes the current
5705 or previous word in Bash:
5707 # Quote the current or previous word
5708 "\C-xq": "\eb\"\ef\""
5712 This command, as seen in the previous example, terminates an `$if'
5716 Commands in this branch of the `$if' directive are executed if the
5720 This directive takes a single filename as an argument and reads
5721 commands and bindings from that file.
5722 $include /etc/inputrc
5725 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
5730 Here is an example of an inputrc file. This illustrates key
5731 binding, variable assignment, and conditional syntax.
5734 # This file controls the behaviour of line input editing for
5735 # programs that use the Gnu Readline library. Existing programs
5736 # include FTP, Bash, and Gdb.
5738 # You can re-read the inputrc file with C-x C-r.
5739 # Lines beginning with '#' are comments.
5741 # First, include any systemwide bindings and variable assignments from
5743 $include /etc/Inputrc
5746 # Set various bindings for emacs mode.
5748 set editing-mode emacs
5752 Meta-Control-h: backward-kill-word Text after the function name is ignored
5755 # Arrow keys in keypad mode
5757 #"\M-OD": backward-char
5758 #"\M-OC": forward-char
5759 #"\M-OA": previous-history
5760 #"\M-OB": next-history
5762 # Arrow keys in ANSI mode
5764 "\M-[D": backward-char
5765 "\M-[C": forward-char
5766 "\M-[A": previous-history
5767 "\M-[B": next-history
5769 # Arrow keys in 8 bit keypad mode
5771 #"\M-\C-OD": backward-char
5772 #"\M-\C-OC": forward-char
5773 #"\M-\C-OA": previous-history
5774 #"\M-\C-OB": next-history
5776 # Arrow keys in 8 bit ANSI mode
5778 #"\M-\C-[D": backward-char
5779 #"\M-\C-[C": forward-char
5780 #"\M-\C-[A": previous-history
5781 #"\M-\C-[B": next-history
5787 # An old-style binding. This happens to be the default.
5790 # Macros that are convenient for shell interaction
5793 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
5794 # prepare to type a quoted word -- insert open and close double quotes
5795 # and move to just after the open quote
5796 "\C-x\"": "\"\"\C-b"
5797 # insert a backslash (testing backslash escapes in sequences and macros)
5799 # Quote the current or previous word
5800 "\C-xq": "\eb\"\ef\""
5801 # Add a binding to refresh the line, which is unbound
5802 "\C-xr": redraw-current-line
5803 # Edit variable on current line.
5804 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
5807 # use a visible bell if one is available
5808 set bell-style visible
5810 # don't strip characters to 7 bits when reading
5813 # allow iso-latin1 characters to be inserted rather than converted to
5814 # prefix-meta sequences
5815 set convert-meta off
5817 # display characters with the eighth bit set directly rather than
5818 # as meta-prefixed characters
5821 # if there are more than 150 possible completions for a word, ask the
5822 # user if he wants to see all of them
5823 set completion-query-items 150
5829 "\M-.": yank-last-arg
5833 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
5835 Bindable Readline Commands
5836 ==========================
5840 * Commands For Moving:: Moving about the line.
5841 * Commands For History:: Getting at previous lines.
5842 * Commands For Text:: Commands for changing text.
5843 * Commands For Killing:: Commands for killing and yanking.
5844 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
5845 * Commands For Completion:: Getting Readline to do the typing for you.
5846 * Keyboard Macros:: Saving and re-executing typed characters
5847 * Miscellaneous Commands:: Other miscellaneous commands.
5849 This section describes Readline commands that may be bound to key
5853 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
5858 `beginning-of-line (C-a)'
5859 Move to the start of the current line.
5862 Move to the end of the line.
5864 `forward-char (C-f)'
5865 Move forward a character.
5867 `backward-char (C-b)'
5868 Move back a character.
5870 `forward-word (M-f)'
5871 Move forward to the end of the next word. Words are composed of
5874 `backward-word (M-b)'
5875 Move back to the start of this, or the previous, word. Words are
5876 composed of letters and digits.
5878 `clear-screen (C-l)'
5879 Clear the screen and redraw the current line, leaving the current
5880 line at the top of the screen.
5882 `redraw-current-line ()'
5883 Refresh the current line. By default, this is unbound.
5886 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
5888 Commands For Manipulating The History
5889 -------------------------------------
5891 `accept-line (Newline, Return)'
5892 Accept the line regardless of where the cursor is. If this line is
5893 non-empty, add it to the history list according to the setting of
5894 the `HISTCONTROL' and `HISTIGNORE' variables. If this line was a
5895 history line, then restore the history line to its original state.
5897 `previous-history (C-p)'
5898 Move `up' through the history list.
5900 `next-history (C-n)'
5901 Move `down' through the history list.
5903 `beginning-of-history (M-<)'
5904 Move to the first line in the history.
5906 `end-of-history (M->)'
5907 Move to the end of the input history, i.e., the line currently
5910 `reverse-search-history (C-r)'
5911 Search backward starting at the current line and moving `up'
5912 through the history as necessary. This is an incremental search.
5914 `forward-search-history (C-s)'
5915 Search forward starting at the current line and moving `down'
5916 through the the history as necessary. This is an incremental
5919 `non-incremental-reverse-search-history (M-p)'
5920 Search backward starting at the current line and moving `up'
5921 through the history as necessary using a non-incremental search
5922 for a string supplied by the user.
5924 `non-incremental-forward-search-history (M-n)'
5925 Search forward starting at the current line and moving `down'
5926 through the the history as necessary using a non-incremental search
5927 for a string supplied by the user.
5929 `history-search-forward ()'
5930 Search forward through the history for the string of characters
5931 between the start of the current line and the current cursor
5932 position (the POINT). This is a non-incremental search. By
5933 default, this command is unbound.
5935 `history-search-backward ()'
5936 Search backward through the history for the string of characters
5937 between the start of the current line and the point. This is a
5938 non-incremental search. By default, this command is unbound.
5940 `yank-nth-arg (M-C-y)'
5941 Insert the first argument to the previous command (usually the
5942 second word on the previous line). With an argument N, insert the
5943 Nth word from the previous command (the words in the previous
5944 command begin with word 0). A negative argument inserts the Nth
5945 word from the end of the previous command.
5947 `yank-last-arg (M-., M-_)'
5948 Insert last argument to the previous command (the last word of the
5949 previous history entry). With an argument, behave exactly like
5950 `yank-nth-arg'. Successive calls to `yank-last-arg' move back
5951 through the history list, inserting the last argument of each line
5955 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
5957 Commands For Changing Text
5958 --------------------------
5961 Delete the character under the cursor. If the cursor is at the
5962 beginning of the line, there are no characters in the line, and
5963 the last character typed was not bound to `delete-char', then
5966 `backward-delete-char (Rubout)'
5967 Delete the character behind the cursor. A numeric argument means
5968 to kill the characters instead of deleting them.
5970 `forward-backward-delete-char ()'
5971 Delete the character under the cursor, unless the cursor is at the
5972 end of the line, in which case the character behind the cursor is
5973 deleted. By default, this is not bound to a key.
5975 `quoted-insert (C-q, C-v)'
5976 Add the next character typed to the line verbatim. This is how to
5977 insert key sequences like <C-q>, for example.
5979 `self-insert (a, b, A, 1, !, ...)'
5982 `transpose-chars (C-t)'
5983 Drag the character before the cursor forward over the character at
5984 the cursor, moving the cursor forward as well. If the insertion
5985 point is at the end of the line, then this transposes the last two
5986 characters of the line. Negative arguments don't work.
5988 `transpose-words (M-t)'
5989 Drag the word behind the cursor past the word in front of the
5990 cursor moving the cursor over that word as well.
5993 Uppercase the current (or following) word. With a negative
5994 argument, uppercase the previous word, but do not move the cursor.
5996 `downcase-word (M-l)'
5997 Lowercase the current (or following) word. With a negative
5998 argument, lowercase the previous word, but do not move the cursor.
6000 `capitalize-word (M-c)'
6001 Capitalize the current (or following) word. With a negative
6002 argument, capitalize the previous word, but do not move the cursor.
6005 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
6011 Kill the text from the current cursor position to the end of the
6014 `backward-kill-line (C-x Rubout)'
6015 Kill backward to the beginning of the line.
6017 `unix-line-discard (C-u)'
6018 Kill backward from the cursor to the beginning of the current line.
6019 The killed text is saved on the kill-ring.
6021 `kill-whole-line ()'
6022 Kill all characters on the current line, no matter where the
6023 cursor is. By default, this is unbound.
6026 Kill from the cursor to the end of the current word, or if between
6027 words, to the end of the next word. Word boundaries are the same
6030 `backward-kill-word (M-DEL)'
6031 Kill the word behind the cursor. Word boundaries are the same as
6034 `unix-word-rubout (C-w)'
6035 Kill the word behind the cursor, using white space as a word
6036 boundary. The killed text is saved on the kill-ring.
6038 `delete-horizontal-space ()'
6039 Delete all spaces and tabs around point. By default, this is
6043 Kill the text between the point and the *mark* (saved cursor
6044 position). This text is referred to as the REGION. By default,
6045 this command is unbound.
6047 `copy-region-as-kill ()'
6048 Copy the text in the region to the kill buffer, so it can be yanked
6049 right away. By default, this command is unbound.
6051 `copy-backward-word ()'
6052 Copy the word before point to the kill buffer. The word
6053 boundaries are the same as `backward-word'. By default, this
6056 `copy-forward-word ()'
6057 Copy the word following point to the kill buffer. The word
6058 boundaries are the same as `forward-word'. By default, this
6062 Yank the top of the kill ring into the buffer at the current
6066 Rotate the kill-ring, and yank the new top. You can only do this
6067 if the prior command is yank or yank-pop.
6070 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
6072 Specifying Numeric Arguments
6073 ----------------------------
6075 `digit-argument (M-0, M-1, ... M--)'
6076 Add this digit to the argument already accumulating, or start a new
6077 argument. <M-> starts a negative argument.
6079 `universal-argument ()'
6080 This is another way to specify an argument. If this command is
6081 followed by one or more digits, optionally with a leading minus
6082 sign, those digits define the argument. If the command is
6083 followed by digits, executing `universal-argument' again ends the
6084 numeric argument, but is otherwise ignored. As a special case, if
6085 this command is immediately followed by a character that is
6086 neither a digit or minus sign, the argument count for the next
6087 command is multiplied by four. The argument count is initially
6088 one, so executing this function the first time makes the argument
6089 count four, a second time makes the argument count sixteen, and so
6090 on. By default, this is not bound to a key.
6093 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
6095 Letting Readline Type For You
6096 -----------------------------
6099 Attempt to do completion on the text before the cursor. This is
6100 application-specific. Generally, if you are typing a filename
6101 argument, you can do filename completion; if you are typing a
6102 command, you can do command completion; if you are typing in a
6103 symbol to GDB, you can do symbol name completion; if you are
6104 typing in a variable to Bash, you can do variable name completion,
6105 and so on. Bash attempts completion treating the text as a
6106 variable (if the text begins with `$'), username (if the text
6107 begins with `~'), hostname (if the text begins with `@'), or
6108 command (including aliases and functions) in turn. If none of
6109 these produces a match, filename completion is attempted.
6111 `possible-completions (M-?)'
6112 List the possible completions of the text before the cursor.
6114 `insert-completions (M-*)'
6115 Insert all completions of the text before point that would have
6116 been generated by `possible-completions'.
6119 Similar to `complete', but replaces the word to be completed with
6120 a single match from the list of possible completions. Repeated
6121 execution of `menu-complete' steps through the list of possible
6122 completions, inserting each match in turn. At the end of the list
6123 of completions, the bell is rung and the original text is restored.
6124 An argument of N moves N positions forward in the list of matches;
6125 a negative argument may be used to move backward through the list.
6126 This command is intended to be bound to `TAB', but is unbound by
6129 `delete-char-or-list ()'
6130 Deletes the character under the cursor if not at the beginning or
6131 end of the line (like `delete-char'). If at the end of the line,
6132 behaves identically to `possible-completions'. This command is
6135 `complete-filename (M-/)'
6136 Attempt filename completion on the text before point.
6138 `possible-filename-completions (C-x /)'
6139 List the possible completions of the text before point, treating
6142 `complete-username (M-~)'
6143 Attempt completion on the text before point, treating it as a
6146 `possible-username-completions (C-x ~)'
6147 List the possible completions of the text before point, treating
6150 `complete-variable (M-$)'
6151 Attempt completion on the text before point, treating it as a
6154 `possible-variable-completions (C-x $)'
6155 List the possible completions of the text before point, treating
6156 it as a shell variable.
6158 `complete-hostname (M-@)'
6159 Attempt completion on the text before point, treating it as a
6162 `possible-hostname-completions (C-x @)'
6163 List the possible completions of the text before point, treating
6166 `complete-command (M-!)'
6167 Attempt completion on the text before point, treating it as a
6168 command name. Command completion attempts to match the text
6169 against aliases, reserved words, shell functions, shell builtins,
6170 and finally executable filenames, in that order.
6172 `possible-command-completions (C-x !)'
6173 List the possible completions of the text before point, treating
6174 it as a command name.
6176 `dynamic-complete-history (M-TAB)'
6177 Attempt completion on the text before point, comparing the text
6178 against lines from the history list for possible completion
6181 `complete-into-braces (M-{)'
6182 Perform filename completion and return the list of possible
6183 completions enclosed within braces so the list is available to the
6184 shell (*note Brace Expansion::.).
6187 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
6192 `start-kbd-macro (C-x ()'
6193 Begin saving the characters typed into the current keyboard macro.
6195 `end-kbd-macro (C-x ))'
6196 Stop saving the characters typed into the current keyboard macro
6197 and save the definition.
6199 `call-last-kbd-macro (C-x e)'
6200 Re-execute the last keyboard macro defined, by making the
6201 characters in the macro appear as if typed at the keyboard.
6204 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
6206 Some Miscellaneous Commands
6207 ---------------------------
6209 `re-read-init-file (C-x C-r)'
6210 Read in the contents of the inputrc file, and incorporate any
6211 bindings or variable assignments found there.
6214 Abort the current editing command and ring the terminal's bell
6215 (subject to the setting of `bell-style').
6217 `do-uppercase-version (M-a, M-b, M-X, ...)'
6218 If the metafied character X is lowercase, run the command that is
6219 bound to the corresponding uppercase character.
6222 Make the next character typed be metafied. This is for keyboards
6223 without a meta key. Typing `ESC f' is equivalent to typing `M-f'.
6225 `undo (C-_, C-x C-u)'
6226 Incremental undo, separately remembered for each line.
6229 Undo all changes made to this line. This is like executing the
6230 `undo' command enough times to get back to the beginning.
6232 `tilde-expand (M-&)'
6233 Perform tilde expansion on the current word.
6236 Set the mark to the current point. If a numeric argument is
6237 supplied, the mark is set to that position.
6239 `exchange-point-and-mark (C-x C-x)'
6240 Swap the point with the mark. The current cursor position is set
6241 to the saved position, and the old cursor position is saved as the
6244 `character-search (C-])'
6245 A character is read and point is moved to the next occurrence of
6246 that character. A negative count searches for previous
6249 `character-search-backward (M-C-])'
6250 A character is read and point is moved to the previous occurrence
6251 of that character. A negative count searches for subsequent
6254 `insert-comment (M-#)'
6255 The value of the `comment-begin' variable is inserted at the
6256 beginning of the current line, and the line is accepted as if a
6257 newline had been typed. This makes the current line a shell
6261 Print all of the functions and their key bindings to the Readline
6262 output stream. If a numeric argument is supplied, the output is
6263 formatted in such a way that it can be made part of an INPUTRC
6264 file. This command is unbound by default.
6267 Print all of the settable variables and their values to the
6268 Readline output stream. If a numeric argument is supplied, the
6269 output is formatted in such a way that it can be made part of an
6270 INPUTRC file. This command is unbound by default.
6273 Print all of the Readline key sequences bound to macros and the
6274 strings they ouput. If a numeric argument is supplied, the output
6275 is formatted in such a way that it can be made part of an INPUTRC
6276 file. This command is unbound by default.
6278 `glob-expand-word (C-x *)'
6279 The word before point is treated as a pattern for pathname
6280 expansion, and the list of matching file names is inserted,
6283 `glob-list-expansions (C-x g)'
6284 The list of expansions that would have been generated by
6285 `glob-expand-word' is displayed, and the line is redrawn.
6287 `display-shell-version (C-x C-v)'
6288 Display version information about the current instance of Bash.
6290 `shell-expand-line (M-C-e)'
6291 Expand the line as the shell does. This performs alias and
6292 history expansion as well as all of the shell word expansions
6293 (*note Shell Expansions::.).
6295 `history-expand-line (M-^)'
6296 Perform history expansion on the current line.
6299 Perform history expansion on the current line and insert a space
6300 (*note History Interaction::.).
6302 `alias-expand-line ()'
6303 Perform alias expansion on the current line (*note Aliases::.).
6305 `history-and-alias-expand-line ()'
6306 Perform history and alias expansion on the current line.
6308 `insert-last-argument (M-., M-_)'
6309 A synonym for `yank-last-arg'.
6311 `operate-and-get-next (C-o)'
6312 Accept the current line for execution and fetch the next line
6313 relative to the current line from the history for editing. Any
6314 argument is ignored.
6316 `emacs-editing-mode (C-e)'
6317 When in `vi' editing mode, this causes a switch back to `emacs'
6318 editing mode, as if the command `set -o emacs' had been executed.
6321 File: bashref.info, Node: Readline vi Mode, Prev: Bindable Readline Commands, Up: Command Line Editing
6326 While the Readline library does not have a full set of `vi' editing
6327 functions, it does contain enough to allow simple editing of the line.
6328 The Readline `vi' mode behaves as specified in the POSIX 1003.2
6331 In order to switch interactively between `emacs' and `vi' editing
6332 modes, use the `set -o emacs' and `set -o vi' commands (*note The Set
6333 Builtin::.). The Readline default is `emacs' mode.
6335 When you enter a line in `vi' mode, you are already placed in
6336 `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches
6337 you into `command' mode, where you can edit the text of the line with
6338 the standard `vi' movement keys, move to previous history lines with
6339 `k' and subsequent lines with `j', and so forth.
6342 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Command Line Editing, Up: Top
6347 This chapter provides basic instructions for installing Bash on the
6348 various supported platforms. The distribution supports nearly every
6349 version of Unix (and, someday, GNU). Other independent ports exist for
6350 MS-DOS, OS/2, Windows 95, and Windows NT.
6354 * Basic Installation:: Installation instructions.
6356 * Compilers and Options:: How to set special options for various
6359 * Compiling For Multiple Architectures:: How to compile Bash for more
6360 than one kind of system from
6361 the same source tree.
6363 * Installation Names:: How to set the various paths used by the installation.
6365 * Specifying the System Type:: How to configure Bash for a particular system.
6367 * Sharing Defaults:: How to share default configuration values among GNU
6370 * Operation Controls:: Options recognized by the configuration program.
6372 * Optional Features:: How to enable and disable optional features when
6376 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
6381 These are installation instructions for Bash.
6383 The `configure' shell script attempts to guess correct values for
6384 various system-dependent variables used during compilation. It uses
6385 those values to create a `Makefile' in each directory of the package
6386 (the top directory, the `builtins' and `doc' directories, and the each
6387 directory under `lib'). It also creates a `config.h' file containing
6388 system-dependent definitions. Finally, it creates a shell script named
6389 `config.status' that you can run in the future to recreate the current
6390 configuration, a file `config.cache' that saves the results of its
6391 tests to speed up reconfiguring, and a file `config.log' containing
6392 compiler output (useful mainly for debugging `configure'). If at some
6393 point `config.cache' contains results you don't want to keep, you may
6396 If you need to do unusual things to compile Bash, please try to
6397 figure out how `configure' could check whether or not to do them, and
6398 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
6399 considered for the next release.
6401 The file `configure.in' is used to create `configure' by a program
6402 called Autoconf. You only need `configure.in' if you want to change it
6403 or regenerate `configure' using a newer version of Autoconf. If you do
6404 this, make sure you are using Autoconf version 2.10 or newer.
6406 If you need to change `configure.in' or regenerate `configure', you
6407 will need to create two files: `_distribution' and `_patchlevel'.
6408 `_distribution' should contain the major and minor version numbers of
6409 the Bash distribution, for example `2.01'. `_patchlevel' should
6410 contain the patch level of the Bash distribution, `0' for example. The
6411 script `support/mkconffiles' has been provided to automate the creation
6414 The simplest way to compile Bash is:
6416 1. `cd' to the directory containing the source code and type
6417 `./configure' to configure Bash for your system. If you're using
6418 `csh' on an old version of System V, you might need to type `sh
6419 ./configure' instead to prevent `csh' from trying to execute
6422 Running `configure' takes awhile. While running, it prints some
6423 messages telling which features it is checking for.
6425 2. Type `make' to compile Bash and build the `bashbug' bug reporting
6428 3. Optionally, type `make tests' to run the Bash test suite.
6430 4. Type `make install' to install `bash' and `bashbug'. This will
6431 also install the manual pages and Info file.
6434 You can remove the program binaries and object files from the source
6435 code directory by typing `make clean'. To also remove the files that
6436 `configure' created (so you can compile Bash for a different kind of
6437 computer), type `make distclean'.
6440 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
6442 Compilers and Options
6443 =====================
6445 Some systems require unusual options for compilation or linking that
6446 the `configure' script does not know about. You can give `configure'
6447 initial values for variables by setting them in the environment. Using
6448 a Bourne-compatible shell, you can do that on the command line like
6451 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
6453 On systems that have the `env' program, you can do it like this:
6455 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
6457 The configuration process uses GCC to build Bash if it is available.
6460 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
6462 Compiling For Multiple Architectures
6463 ====================================
6465 You can compile Bash for more than one kind of computer at the same
6466 time, by placing the object files for each architecture in their own
6467 directory. To do this, you must use a version of `make' that supports
6468 the `VPATH' variable, such as GNU `make'. `cd' to the directory where
6469 you want the object files and executables to go and run the `configure'
6470 script from the source directory. You may need to supply the
6471 `--srcdir=PATH' argument to tell `configure' where the source files
6472 are. `configure' automatically checks for the source code in the
6473 directory that `configure' is in and in `..'.
6475 If you have to use a `make' that does not supports the `VPATH'
6476 variable, you can compile Bash for one architecture at a time in the
6477 source code directory. After you have installed Bash for one
6478 architecture, use `make distclean' before reconfiguring for another
6481 Alternatively, if your system supports symbolic links, you can use
6482 the `support/mkclone' script to create a build tree which has symbolic
6483 links back to each file in the source directory. Here's an example
6484 that creates a build directory in the current directory from a source
6485 directory `/usr/gnu/src/bash-2.0':
6487 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
6489 The `mkclone' script requires Bash, so you must have already built Bash
6490 for at least one architecture before you can create build directories
6491 for other architectures.
6494 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
6499 By default, `make install' will install into `/usr/local/bin',
6500 `/usr/local/man', etc. You can specify an installation prefix other
6501 than `/usr/local' by giving `configure' the option `--prefix=PATH'.
6503 You can specify separate installation prefixes for
6504 architecture-specific files and architecture-independent files. If you
6505 give `configure' the option `--exec-prefix=PATH', `make install' will
6506 use `PATH' as the prefix for installing programs and libraries.
6507 Documentation and other data files will still use the regular prefix.
6510 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
6512 Specifying the System Type
6513 ==========================
6515 There may be some features `configure' can not figure out
6516 automatically, but needs to determine by the type of host Bash will run
6517 on. Usually `configure' can figure that out, but if it prints a
6518 message saying it can not guess the host type, give it the
6519 `--host=TYPE' option. `TYPE' can either be a short name for the system
6520 type, such as `sun4', or a canonical name with three fields:
6521 `CPU-COMPANY-SYSTEM' (e.g., `sparc-sun-sunos4.1.2').
6523 See the file `support/config.sub' for the possible values of each field.
6526 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
6531 If you want to set default values for `configure' scripts to share,
6532 you can create a site shell script called `config.site' that gives
6533 default values for variables like `CC', `cache_file', and `prefix'.
6534 `configure' looks for `PREFIX/share/config.site' if it exists, then
6535 `PREFIX/etc/config.site' if it exists. Or, you can set the
6536 `CONFIG_SITE' environment variable to the location of the site script.
6537 A warning: the Bash `configure' looks for a site script, but not all
6538 `configure' scripts do.
6541 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
6546 `configure' recognizes the following options to control how it
6550 Use and save the results of the tests in FILE instead of
6551 `./config.cache'. Set FILE to `/dev/null' to disable caching, for
6552 debugging `configure'.
6555 Print a summary of the options to `configure', and exit.
6560 Do not print messages saying which checks are being made.
6563 Look for the Bash source code in directory DIR. Usually
6564 `configure' can determine that directory automatically.
6567 Print the version of Autoconf used to generate the `configure'
6570 `configure' also accepts some other, not widely used, boilerplate
6574 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
6579 The Bash `configure' has a number of `--enable-FEATURE' options,
6580 where FEATURE indicates an optional part of Bash. There are also
6581 several `--with-PACKAGE' options, where PACKAGE is something like
6582 `gnu-malloc' or `purify'. To turn off the default use of a package, use
6583 `--without-PACKAGE'. To configure Bash without a feature that is
6584 enabled by default, use `--disable-FEATURE'.
6586 Here is a complete list of the `--enable-' and `--with-' options
6587 that the Bash `configure' recognizes.
6590 Define if you are using the Andrew File System from Transarc.
6593 Use the curses library instead of the termcap library. This should
6594 be supplied if your system has an inadequate or incomplete termcap
6597 `--with-glibc-malloc'
6598 Use the GNU libc version of `malloc' in `lib/malloc/gmalloc.c'.
6599 This is not the version of `malloc' that appears in glibc version
6600 2, but a modified version of the `malloc' from glibc version 1.
6601 This is somewhat slower than the default `malloc', but wastes less
6602 space on a per-allocation basis, and will return memory to the
6603 operating system under some circumstances.
6606 Use the GNU version of `malloc' in `lib/malloc/malloc.c'. This is
6607 not the same `malloc' that appears in GNU libc, but an older
6608 version derived from the 4.2 BSD `malloc'. This `malloc' is very
6609 fast, but wastes some space on each allocation. This option is
6610 enabled by default. The `NOTES' file contains a list of systems
6611 for which this should be turned off, and `configure' disables this
6612 option automatically for a number of systems.
6614 `--with-installed-readline'
6615 Define this to make bash link with a locally-installed version of
6616 Readline rather than the version in lib/readline. This works only
6617 with readline 4.0 and later versions.
6620 Define this to use the Purify memory allocation checker from Pure
6623 `--enable-minimal-config'
6624 This produces a shell with minimal features, close to the
6625 historical Bourne shell.
6627 There are several `--enable-' options that alter how Bash is
6628 compiled and linked, rather than changing run-time features.
6630 `--enable-profiling'
6631 This builds a Bash binary that produces profiling information to be
6632 processed by `gprof' each time it is executed.
6634 `--enable-static-link'
6635 This causes Bash to be linked statically, if `gcc' is being used.
6636 This could be used to build a version to use as root's shell.
6638 The `minimal-config' option can be used to disable all of the
6639 following options, but it is processed first, so individual options may
6640 be enabled using `enable-FEATURE'.
6642 All of the following options except for `disabled-builtins' and
6643 `usg-echo-default' are enabled by default, unless the operating system
6644 does not provide the necessary support.
6647 Allow alias expansion and include the `alias' and `unalias'
6648 builtins (*note Aliases::.).
6650 `--enable-array-variables'
6651 Include support for one-dimensional array shell variables (*note
6654 `--enable-bang-history'
6655 Include support for `csh'-like history substitution (*note History
6658 `--enable-brace-expansion'
6659 Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ).
6660 See *Note Brace Expansion::, for a complete description.
6662 `--enable-command-timing'
6663 Include support for recognizing `time' as a reserved word and for
6664 displaying timing statistics for the pipeline following `time'.
6665 This allows pipelines as well as shell builtins and functions to
6668 `--enable-cond-command'
6669 Include support for the `[[' conditional command (*note
6670 Conditional Constructs::.).
6672 `--enable-directory-stack'
6673 Include support for a `csh'-like directory stack and the `pushd',
6674 `popd', and `dirs' builtins (*note The Directory Stack::.).
6676 `--enable-disabled-builtins'
6677 Allow builtin commands to be invoked via `builtin xxx' even after
6678 `xxx' has been disabled using `enable -n xxx'. See *Note Bash
6679 Builtins::, for details of the `builtin' and `enable' builtin
6682 `--enable-dparen-arithmetic'
6683 Include support for the `((...))' command (*note Conditional
6686 `--enable-extended-glob'
6687 Include support for the extended pattern matching features
6688 described above under *Note Pattern Matching::.
6690 `--enable-help-builtin'
6691 Include the `help' builtin, which displays help on shell builtins
6695 Include command history and the `fc' and `history' builtin
6698 `--enable-job-control'
6699 This enables the job control features (*note Job Control::.), if
6700 the operating system supports them.
6702 `--enable-process-substitution'
6703 This enables process substitution (*note Process Substitution::.)
6704 if the operating system provides the necessary support.
6706 `--enable-prompt-string-decoding'
6707 Turn on the interpretation of a number of backslash-escaped
6708 characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt
6709 strings. See *Note Printing a Prompt::, for a complete list of
6710 prompt string escape sequences.
6713 Include support for command-line editing and history with the Bash
6714 version of the Readline library (*note Command Line Editing::.).
6716 `--enable-restricted'
6717 Include support for a "restricted shell". If this is enabled,
6718 Bash, when called as `rbash', enters a restricted mode. See *Note
6719 The Restricted Shell::, for a description of restricted mode.
6722 Include the `select' builtin, which allows the generation of simple
6723 menus (*note Conditional Constructs::.).
6725 `--enable-usg-echo-default'
6726 Make the `echo' builtin expand backslash-escaped characters by
6727 default, without requiring the `-e' option. This makes the Bash
6728 `echo' behave more like the System V version.
6730 The file `config.h.top' contains C Preprocessor `#define' statements
6731 for options which are not settable from `configure'. Some of these are
6732 not meant to be changed; beware of the consequences if you do. Read
6733 the comments associated with each definition for more information about
6737 File: bashref.info, Node: Reporting Bugs, Next: Builtin Index, Prev: Installing Bash, Up: Top
6742 Please report all bugs you find in Bash. But first, you should make
6743 sure that it really is a bug, and that it appears in the latest version
6744 of Bash that you have.
6746 Once you have determined that a bug actually exists, use the
6747 `bashbug' command to submit a bug report. If you have a fix, you are
6748 encouraged to mail that as well! Suggestions and `philosophical' bug
6749 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
6750 newsgroup `gnu.bash.bug'.
6752 All bug reports should include:
6753 * The version number of Bash.
6755 * The hardware and operating system.
6757 * The compiler used to compile Bash.
6759 * A description of the bug behaviour.
6761 * A short script or `recipe' which exercises the bug and may be used
6764 `bashbug' inserts the first three items automatically into the template
6765 it provides for filing a bug report.
6767 Please send all reports concerning this manual to <chet@po.CWRU.Edu>.
6770 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Prev: Reporting Bugs, Up: Top
6772 Index of Shell Builtin Commands
6773 *******************************
6777 * .: Bourne Shell Builtins.
6778 * :: Bourne Shell Builtins.
6779 * [: Bourne Shell Builtins.
6780 * alias: Alias Builtins.
6781 * bg: Job Control Builtins.
6782 * bind: Bash Builtins.
6783 * break: Bourne Shell Builtins.
6784 * builtin: Bash Builtins.
6785 * cd: Bourne Shell Builtins.
6786 * command: Bash Builtins.
6787 * continue: Bourne Shell Builtins.
6788 * declare: Bash Builtins.
6789 * dirs: The Directory Stack.
6790 * disown: Job Control Builtins.
6791 * echo: Bash Builtins.
6792 * enable: Bash Builtins.
6793 * eval: Bourne Shell Builtins.
6794 * exec: Bourne Shell Builtins.
6795 * exit: Bourne Shell Builtins.
6796 * export: Bourne Shell Builtins.
6797 * fc: Bash History Builtins.
6798 * fg: Job Control Builtins.
6799 * getopts: Bourne Shell Builtins.
6800 * hash: Bourne Shell Builtins.
6801 * help: Bash Builtins.
6802 * history: Bash History Builtins.
6803 * jobs: Job Control Builtins.
6804 * kill: Job Control Builtins.
6805 * let: Bash Builtins.
6806 * local: Bash Builtins.
6807 * logout: Bash Builtins.
6808 * popd: The Directory Stack.
6809 * printf: Bash Builtins.
6810 * pushd: The Directory Stack.
6811 * pwd: Bourne Shell Builtins.
6812 * read: Bash Builtins.
6813 * readonly: Bourne Shell Builtins.
6814 * return: Bourne Shell Builtins.
6815 * set: The Set Builtin.
6816 * shift: Bourne Shell Builtins.
6817 * shopt: Bash Builtins.
6818 * source: Bash Builtins.
6819 * suspend: Job Control Builtins.
6820 * test: Bourne Shell Builtins.
6821 * times: Bourne Shell Builtins.
6822 * trap: Bourne Shell Builtins.
6823 * type: Bash Builtins.
6824 * typeset: Bash Builtins.
6825 * ulimit: Bash Builtins.
6826 * umask: Bourne Shell Builtins.
6827 * unalias: Alias Builtins.
6828 * unset: Bourne Shell Builtins.
6829 * wait: Job Control Builtins.
6832 File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Top
6834 Shell Reserved Words
6835 ********************
6840 * [[: Conditional Constructs.
6841 * ]]: Conditional Constructs.
6842 * case: Conditional Constructs.
6843 * do: Looping Constructs.
6844 * done: Looping Constructs.
6845 * elif: Conditional Constructs.
6846 * else: Conditional Constructs.
6847 * esac: Conditional Constructs.
6848 * fi: Conditional Constructs.
6849 * for: Looping Constructs.
6850 * function: Shell Functions.
6851 * if: Conditional Constructs.
6852 * in: Conditional Constructs.
6853 * select: Conditional Constructs.
6854 * then: Conditional Constructs.
6856 * until: Looping Constructs.
6857 * while: Looping Constructs.
6858 * {: Command Grouping.
6859 * }: Command Grouping.
6862 File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Top
6864 Parameter and Variable Index
6865 ****************************
6869 * !: Special Parameters.
6870 * #: Special Parameters.
6871 * $: Special Parameters.
6872 * *: Special Parameters.
6873 * -: Special Parameters.
6874 * 0: Special Parameters.
6875 * ?: Special Parameters.
6876 * @: Special Parameters.
6877 * _: Special Parameters.
6878 * auto_resume: Job Control Variables.
6879 * BASH: Bash Variables.
6880 * BASH_ENV: Bash Variables.
6881 * BASH_VERSINFO: Bash Variables.
6882 * BASH_VERSION: Bash Variables.
6883 * bell-style: Readline Init File Syntax.
6884 * CDPATH: Bourne Shell Variables.
6885 * comment-begin: Readline Init File Syntax.
6886 * completion-query-items: Readline Init File Syntax.
6887 * convert-meta: Readline Init File Syntax.
6888 * DIRSTACK: Bash Variables.
6889 * disable-completion: Readline Init File Syntax.
6890 * editing-mode: Readline Init File Syntax.
6891 * enable-keypad: Readline Init File Syntax.
6892 * EUID: Bash Variables.
6893 * expand-tilde: Readline Init File Syntax.
6894 * FCEDIT: Bash Variables.
6895 * FIGNORE: Bash Variables.
6896 * GLOBIGNORE: Bash Variables.
6897 * GROUPS: Bash Variables.
6898 * histchars: Bash Variables.
6899 * HISTCMD: Bash Variables.
6900 * HISTCONTROL: Bash Variables.
6901 * HISTFILE: Bash Variables.
6902 * HISTFILESIZE: Bash Variables.
6903 * HISTIGNORE: Bash Variables.
6904 * HISTSIZE: Bash Variables.
6905 * HOME: Bourne Shell Variables.
6906 * horizontal-scroll-mode: Readline Init File Syntax.
6907 * HOSTFILE: Bash Variables.
6908 * HOSTNAME: Bash Variables.
6909 * HOSTTYPE: Bash Variables.
6910 * IFS: Bourne Shell Variables.
6911 * IGNOREEOF: Bash Variables.
6912 * input-meta: Readline Init File Syntax.
6913 * INPUTRC: Bash Variables.
6914 * isearch-terminators: Readline Init File Syntax.
6915 * keymap: Readline Init File Syntax.
6916 * LANG: Bash Variables.
6917 * LC_ALL: Bash Variables.
6918 * LC_COLLATE: Bash Variables.
6919 * LC_CTYPE: Bash Variables.
6920 * LC_MESSAGES: Bash Variables.
6921 * LINENO: Bash Variables.
6922 * MACHTYPE: Bash Variables.
6923 * MAIL: Bourne Shell Variables.
6924 * MAILCHECK: Bash Variables.
6925 * MAILPATH: Bourne Shell Variables.
6926 * mark-modified-lines: Readline Init File Syntax.
6927 * meta-flag: Readline Init File Syntax.
6928 * OLDPWD: Bash Variables.
6929 * OPTARG: Bourne Shell Variables.
6930 * OPTERR: Bash Variables.
6931 * OPTIND: Bourne Shell Variables.
6932 * OSTYPE: Bash Variables.
6933 * output-meta: Readline Init File Syntax.
6934 * PATH: Bourne Shell Variables.
6935 * PIPESTATUS: Bash Variables.
6936 * PPID: Bash Variables.
6937 * PROMPT_COMMAND: Bash Variables.
6938 * PS1: Bourne Shell Variables.
6939 * PS2: Bourne Shell Variables.
6940 * PS3: Bash Variables.
6941 * PS4: Bash Variables.
6942 * PWD: Bash Variables.
6943 * RANDOM: Bash Variables.
6944 * REPLY: Bash Variables.
6945 * SECONDS: Bash Variables.
6946 * SHELLOPTS: Bash Variables.
6947 * SHLVL: Bash Variables.
6948 * show-all-if-ambiguous: Readline Init File Syntax.
6949 * TIMEFORMAT: Bash Variables.
6950 * TMOUT: Bash Variables.
6951 * UID: Bash Variables.
6952 * visible-stats: Readline Init File Syntax.
6955 File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Top
6962 * abort (C-g): Miscellaneous Commands.
6963 * accept-line (Newline, Return): Commands For History.
6964 * backward-char (C-b): Commands For Moving.
6965 * backward-delete-char (Rubout): Commands For Text.
6966 * backward-kill-line (C-x Rubout): Commands For Killing.
6967 * backward-kill-word (M-DEL): Commands For Killing.
6968 * backward-word (M-b): Commands For Moving.
6969 * beginning-of-history (M-<): Commands For History.
6970 * beginning-of-line (C-a): Commands For Moving.
6971 * call-last-kbd-macro (C-x e): Keyboard Macros.
6972 * capitalize-word (M-c): Commands For Text.
6973 * character-search (C-]): Miscellaneous Commands.
6974 * character-search-backward (M-C-]): Miscellaneous Commands.
6975 * clear-screen (C-l): Commands For Moving.
6976 * complete (TAB): Commands For Completion.
6977 * copy-backward-word (): Commands For Killing.
6978 * copy-forward-word (): Commands For Killing.
6979 * copy-region-as-kill (): Commands For Killing.
6980 * delete-char (C-d): Commands For Text.
6981 * delete-char-or-list (): Commands For Completion.
6982 * delete-horizontal-space (): Commands For Killing.
6983 * digit-argument (M-0, M-1, ... M--): Numeric Arguments.
6984 * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands.
6985 * downcase-word (M-l): Commands For Text.
6986 * dump-functions (): Miscellaneous Commands.
6987 * dump-macros (): Miscellaneous Commands.
6988 * dump-variables (): Miscellaneous Commands.
6989 * end-kbd-macro (C-x )): Keyboard Macros.
6990 * end-of-history (M->): Commands For History.
6991 * end-of-line (C-e): Commands For Moving.
6992 * exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
6993 * forward-backward-delete-char (): Commands For Text.
6994 * forward-char (C-f): Commands For Moving.
6995 * forward-search-history (C-s): Commands For History.
6996 * forward-word (M-f): Commands For Moving.
6997 * history-search-backward (): Commands For History.
6998 * history-search-forward (): Commands For History.
6999 * insert-comment (M-#): Miscellaneous Commands.
7000 * insert-completions (M-*): Commands For Completion.
7001 * kill-line (C-k): Commands For Killing.
7002 * kill-region (): Commands For Killing.
7003 * kill-whole-line (): Commands For Killing.
7004 * kill-word (M-d): Commands For Killing.
7005 * menu-complete (): Commands For Completion.
7006 * next-history (C-n): Commands For History.
7007 * non-incremental-forward-search-history (M-n): Commands For History.
7008 * non-incremental-reverse-search-history (M-p): Commands For History.
7009 * possible-completions (M-?): Commands For Completion.
7010 * prefix-meta (ESC): Miscellaneous Commands.
7011 * previous-history (C-p): Commands For History.
7012 * quoted-insert (C-q, C-v): Commands For Text.
7013 * re-read-init-file (C-x C-r): Miscellaneous Commands.
7014 * redraw-current-line (): Commands For Moving.
7015 * reverse-search-history (C-r): Commands For History.
7016 * revert-line (M-r): Miscellaneous Commands.
7017 * self-insert (a, b, A, 1, !, ...): Commands For Text.
7018 * set-mark (C-@): Miscellaneous Commands.
7019 * start-kbd-macro (C-x (): Keyboard Macros.
7020 * transpose-chars (C-t): Commands For Text.
7021 * transpose-words (M-t): Commands For Text.
7022 * undo (C-_, C-x C-u): Miscellaneous Commands.
7023 * universal-argument (): Numeric Arguments.
7024 * unix-line-discard (C-u): Commands For Killing.
7025 * unix-word-rubout (C-w): Commands For Killing.
7026 * upcase-word (M-u): Commands For Text.
7027 * yank (C-y): Commands For Killing.
7028 * yank-last-arg (M-., M-_): Commands For History.
7029 * yank-nth-arg (M-C-y): Commands For History.
7030 * yank-pop (M-y): Commands For Killing.
7033 File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Top
7040 * alias expansion: Aliases.
7041 * arithmetic evaluation: Shell Arithmetic.
7042 * arithmetic expansion: Arithmetic Expansion.
7043 * arithmetic, shell: Shell Arithmetic.
7045 * background: Job Control Basics.
7046 * Bash configuration: Basic Installation.
7047 * Bash installation: Basic Installation.
7048 * Bourne shell: Basic Shell Features.
7049 * brace expansion: Brace Expansion.
7050 * builtin: Definitions.
7051 * command editing: Readline Bare Essentials.
7052 * command execution: Command Search and Execution.
7053 * command expansion: Simple Command Expansion.
7054 * command history: Bash History Facilities.
7055 * command search: Command Search and Execution.
7056 * command substitution: Command Substitution.
7057 * command timing: Pipelines.
7058 * commands, conditional: Conditional Constructs.
7059 * commands, grouping: Command Grouping.
7060 * commands, lists: Lists.
7061 * commands, looping: Looping Constructs.
7062 * commands, pipelines: Pipelines.
7063 * commands, shell: Shell Commands.
7064 * commands, simple: Simple Commands.
7065 * comments, shell: Comments.
7066 * configuration: Basic Installation.
7067 * control operator: Definitions.
7068 * directory stack: The Directory Stack.
7069 * editing command lines: Readline Bare Essentials.
7070 * environment: Environment.
7071 * evaluation, arithmetic: Shell Arithmetic.
7072 * event designators: Event Designators.
7073 * execution environment: Command Execution Environment.
7074 * exit status <1>: Exit Status.
7075 * exit status: Definitions.
7076 * expansion: Shell Expansions.
7077 * expansion, arithmetic: Arithmetic Expansion.
7078 * expansion, brace: Brace Expansion.
7079 * expansion, filename: Filename Expansion.
7080 * expansion, parameter: Shell Parameter Expansion.
7081 * expansion, pathname: Filename Expansion.
7082 * expansion, tilde: Tilde Expansion.
7083 * expressions, arithmetic: Shell Arithmetic.
7084 * expressions, conditional: Bash Conditional Expressions.
7085 * field: Definitions.
7086 * filename: Definitions.
7087 * filename expansion: Filename Expansion.
7088 * foreground: Job Control Basics.
7089 * functions, shell: Shell Functions.
7090 * history builtins: Bash History Builtins.
7091 * history events: Event Designators.
7092 * history expansion: History Interaction.
7093 * history list: Bash History Facilities.
7094 * History, how to use: Job Control Variables.
7095 * identifier: Definitions.
7096 * initialization file, readline: Readline Init File.
7097 * installation: Basic Installation.
7098 * interaction, readline: Readline Interaction.
7099 * interactive shell <1>: Is This Shell Interactive?.
7100 * interactive shell: Invoking Bash.
7102 * job control <1>: Definitions.
7103 * job control: Job Control Basics.
7104 * kill ring: Readline Killing Commands.
7105 * killing text: Readline Killing Commands.
7106 * localization: Locale Translation.
7107 * matching, pattern: Pattern Matching.
7108 * metacharacter: Definitions.
7109 * name: Definitions.
7110 * notation, readline: Readline Bare Essentials.
7111 * operator, shell: Definitions.
7112 * parameter expansion: Shell Parameter Expansion.
7113 * parameters: Shell Parameters.
7114 * parameters, positional: Positional Parameters.
7115 * parameters, special: Special Parameters.
7116 * pathname expansion: Filename Expansion.
7117 * pattern matching: Pattern Matching.
7118 * pipeline: Pipelines.
7119 * POSIX: Definitions.
7120 * POSIX Mode: Bash POSIX Mode.
7121 * process group: Definitions.
7122 * process group ID: Definitions.
7123 * process substitution: Process Substitution.
7124 * prompting: Printing a Prompt.
7126 * quoting, ANSI: ANSI-C Quoting.
7127 * Readline, how to use: Modifiers.
7128 * redirection: Redirections.
7129 * reserved word: Definitions.
7130 * restricted shell: The Restricted Shell.
7131 * return status: Definitions.
7132 * shell arithmetic: Shell Arithmetic.
7133 * shell function: Shell Functions.
7134 * shell script: Shell Scripts.
7135 * shell variable: Shell Parameters.
7136 * signal: Definitions.
7137 * signal handling: Signals.
7138 * special builtin: Definitions.
7139 * startup files: Bash Startup Files.
7140 * suspending jobs: Job Control Basics.
7141 * tilde expansion: Tilde Expansion.
7142 * token: Definitions.
7143 * variable, shell: Shell Parameters.
7144 * word: Definitions.
7145 * word splitting: Word Splitting.
7146 * yanking text: Readline Killing Commands.
7152 Node: Introduction
\7f3146
7153 Node: What is Bash?
\7f3371
7154 Node: What is a shell?
\7f4465
7155 Node: Definitions
\7f6487
7156 Node: Basic Shell Features
\7f9148
7157 Node: Shell Syntax
\7f10371
7158 Node: Shell Operation
\7f10660
7159 Node: Quoting
\7f11954
7160 Node: Escape Character
\7f12979
7161 Node: Single Quotes
\7f13451
7162 Node: Double Quotes
\7f13780
7163 Node: ANSI-C Quoting
\7f14678
7164 Node: Locale Translation
\7f15547
7165 Node: Comments
\7f15968
7166 Node: Shell Commands
\7f16582
7167 Node: Simple Commands
\7f17093
7168 Node: Pipelines
\7f17652
7170 Node: Looping Constructs
\7f20634
7171 Node: Conditional Constructs
\7f22239
7172 Node: Command Grouping
\7f28177
7173 Node: Shell Functions
\7f29554
7174 Node: Shell Parameters
\7f31518
7175 Node: Positional Parameters
\7f32844
7176 Node: Special Parameters
\7f33593
7177 Node: Shell Expansions
\7f36214
7178 Node: Brace Expansion
\7f38137
7179 Node: Tilde Expansion
\7f39698
7180 Node: Shell Parameter Expansion
\7f42030
7181 Node: Command Substitution
\7f48426
7182 Node: Arithmetic Expansion
\7f49700
7183 Node: Process Substitution
\7f50545
7184 Node: Word Splitting
\7f51439
7185 Node: Filename Expansion
\7f52891
7186 Node: Pattern Matching
\7f54855
7187 Node: Quote Removal
\7f57244
7188 Node: Redirections
\7f57530
7189 Node: Executing Commands
\7f63600
7190 Node: Simple Command Expansion
\7f64267
7191 Node: Command Search and Execution
\7f66190
7192 Node: Command Execution Environment
\7f68193
7193 Node: Environment
\7f70647
7194 Node: Exit Status
\7f72304
7195 Node: Signals
\7f73501
7196 Node: Shell Scripts
\7f75396
7197 Node: Bourne Shell Features
\7f77432
7198 Node: Bourne Shell Builtins
\7f78162
7199 Node: Bourne Shell Variables
\7f92273
7200 Node: Other Bourne Shell Features
\7f93978
7201 Node: Major Differences From The Bourne Shell
\7f94721
7202 Node: Bash Features
\7f106910
7203 Node: Invoking Bash
\7f108013
7204 Node: Bash Startup Files
\7f112198
7205 Node: Is This Shell Interactive?
\7f116342
7206 Node: Bash Builtins
\7f117313
7207 Node: The Set Builtin
\7f138717
7208 Node: Bash Conditional Expressions
\7f145533
7209 Node: Bash Variables
\7f148666
7210 Node: Shell Arithmetic
\7f161096
7211 Node: Aliases
\7f163144
7212 Node: Alias Builtins
\7f165719
7213 Node: Arrays
\7f166335
7214 Node: The Directory Stack
\7f169356
7215 Node: Printing a Prompt
\7f172706
7216 Node: The Restricted Shell
\7f174369
7217 Node: Bash POSIX Mode
\7f175730
7218 Node: Job Control
\7f179891
7219 Node: Job Control Basics
\7f180357
7220 Node: Job Control Builtins
\7f184556
7221 Node: Job Control Variables
\7f188848
7222 Node: Using History Interactively
\7f189998
7223 Node: Bash History Facilities
\7f190677
7224 Node: Bash History Builtins
\7f193018
7225 Node: History Interaction
\7f196386
7226 Node: Event Designators
\7f198938
7227 Node: Word Designators
\7f199865
7228 Node: Modifiers
\7f201114
7229 Node: Command Line Editing
\7f202431
7230 Node: Introduction and Notation
\7f203091
7231 Node: Readline Interaction
\7f204129
7232 Node: Readline Bare Essentials
\7f205321
7233 Node: Readline Movement Commands
\7f206861
7234 Node: Readline Killing Commands
\7f207826
7235 Node: Readline Arguments
\7f209541
7236 Node: Searching
\7f210515
7237 Node: Readline Init File
\7f212263
7238 Node: Readline Init File Syntax
\7f213302
7239 Node: Conditional Init Constructs
\7f222508
7240 Node: Sample Init File
\7f224946
7241 Node: Bindable Readline Commands
\7f228115
7242 Node: Commands For Moving
\7f228865
7243 Node: Commands For History
\7f229712
7244 Node: Commands For Text
\7f232541
7245 Node: Commands For Killing
\7f234508
7246 Node: Numeric Arguments
\7f236657
7247 Node: Commands For Completion
\7f237783
7248 Node: Keyboard Macros
\7f241615
7249 Node: Miscellaneous Commands
\7f242173
7250 Node: Readline vi Mode
\7f246493
7251 Node: Installing Bash
\7f247371
7252 Node: Basic Installation
\7f248448
7253 Node: Compilers and Options
\7f251358
7254 Node: Compiling For Multiple Architectures
\7f252092
7255 Node: Installation Names
\7f253749
7256 Node: Specifying the System Type
\7f254474
7257 Node: Sharing Defaults
\7f255178
7258 Node: Operation Controls
\7f255843
7259 Node: Optional Features
\7f256748
7260 Node: Reporting Bugs
\7f263158
7261 Node: Builtin Index
\7f264229
7262 Node: Reserved Word Index
\7f267632
7263 Node: Variable Index
\7f269090
7264 Node: Function Index
\7f274363
7265 Node: Concept Index
\7f278853