Chapter 8: Command Line Editing 95 1C- control prefix 1M- meta prefix 1e an escape character 11 backslash 0, a double quotation mark ‘, 0, a single quote or apostrophe In addition to the GNU Emacs style escape sequences, a second set of backslash escapes is available: \a alert (bell) \b backspace \d delete form feed \n newline \r carriage return \t horizontal tab \v vertical tab \mut the eight-bit character whose value is the octal value nnn (one to three digits) \ :UN the eight-bit character whose value is the hexadecimal value HH (one or two hex digits) When entering the text of a macro, single or double quotes must be used to indicate a macro definition. Unquoted text is assumed to be a function name. In the macro body, the backslash escapes described above are expanded. Backslash will quote any other character in the macro text, including th' and "'. For example, the following binding will make `C-x \' insert a single `V into the line: " \C —x\\ " : n\V 8.3.2 Conditional Init Constructs Readline implements a facility similar in spirit to the conditional compilation features of the C preprocessor which allows key bindings and variable settings to be performed as the result of tests. There are four parser directives used. $if The $if construct allows bindings to be made based on the editing mode, the terminal being used, or the application using Readline. The text of the test extends to the end of the line; no characters are required to isolate it. mode The mode= form of the $if directive is used to test whether Readline is in emacs or vi mode. This may be used in conjunction with the `set keymap' command, for instance, to set bindings in the emacs- standard and emacs-ctlx keymaps only if Readline is starting out in emacs mode. EFTA00315949
96 Bash Reference Manual term The term= form may be used to include terminal-specific key bind- ings, perhaps to bind the key sequences output by the terminal's function keys. The word on the right side of the =' is tested against both the full name of the terminal and the portion of the terminal name before the first `-'. This allows sun to match both sun and sun-cmd, for instance. application The application construct is used to include application-specific set- tings. Each program using the Readline library sets the application name, and you can test for a particular value. This could be used to bind key sequences to functions useful for a specific program. For instance, the following command adds a key sequence that quotes the current or previous word in Bash: $if Bash # Quote the current or previous word "\C-xq": "\eb\"\ef\"" $endif $endif This command, as seen in the previous example, terminates an $if command. $else Commands in this branch of the $if directive are executed if the test fails. $include This directive takes a single filename as an argument and reads commands and bindings from that file. For example, the following directive reads from Ifetc/inputrc': $include /etc/inputrc 8.3.3 Sample Init File Here is an example of an inputrc file. This illustrates key binding, variable assignment, and conditional syntax. EFTA00315950
Chapter 8: Command Line Editing 97 # This file controls the behaviour of line input editing for # programs that use the GNU Readline library. Existing # programs include FTP, Bash, and GDB. # You can re-read the inputrc file with C-x C-r. # Lines beginning with '#' are comments. # First, include any systemwide bindings and variable # assignments from /etc/Inputrc $include /etc/Inputrc # Set various bindings for emacs mode. set editing-mode emacs $if mode=emacs Meta-Control-h: backward-kill-word Text after the function name is ignored # Arrow keys in keypad mode #"\M-OD": backward-char #"\M-OC": forward-char #"\M-0A": previous-history #"\M-OB": next-history # Arrow keys in ANSI mode "\M-ED": backward-char "\M-LC": forward-char "\M-LA": previous-history "\M-LB": next-history # Arrow keys in 8 bit keypad mode #"\M-\C-OD": backward-char #"\M-\C-OC": forward-char #"\M-\C-0A": previous-history #"\M-\C-OB": next-history # Arrow keys in 8 bit ANSI mode #"\M-\C-ID": backward-char #"\M-\C-[C": forward-char EFTA00315951
98 Rash Reference Manual #"\M-\C-fA": #"\M-\C-fB": C-q: quoted-insert $endif previous-history next-history # An old-style binding. This happens to be the default. TAB: complete # Macros that are convenient for shell interaction $if Bash # edit the path "\C-xp": "PATH=WATHI\e\C-e\C-a\ef\C-f" # prepare to type a quoted word -- # insert open and close double quotes # and move to just after the open quote "\C-x\"": "\"\"\C-b" # insert a backslash (testing backslash escapes # in sequences and macros) "\C-x\\": ow. # Quote the current or previous word "\C-xq": "\eb\"\ef\"" # Add a binding to refresh the line, which is unbound "\C-xr": redraw-current-line # Edit variable on current line. "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" $endif # use a visible bell if one is available set bell-style visible # don't strip characters to 7 bits when reading set input-meta on # allow iso-latinl characters to be inserted rather # than converted to prefix-meta sequences set convert-meta off # display characters with the eighth bit set directly # rather than as meta-prefixed characters set output-meta on # if there are more than 150 possible completions for # a word, ask the user if he wants to see all of them set completion-query-items 150 EFTA00315952
Chapter 8: Command Line Editing 99 # For FTP #if Ftp "\C-xg": "get \M-?" "\C-xt": "put \M-?" "\M-.": yank-last-arg $endif 8.4 Bindable Readline Commands This section describes Readline commands that may be bound to key sequences. You can list your key bindings by executing bind -P or, for a more terse format, suitable for an input= file, bind -p. (See Section 4.2 [Bash Builtins], page 39.) Command names without an accompanying key sequence are unbound by default. In the following descriptions, point refers to the current cursor position, and mark refers to a cursor position saved by the set-mark command. The text between the point and mark is referred to as the region. 8.4.1 Commands For Moving beginning-of-line (C-a) Move to the start of the current line. end-of-line (C-e) Move to the end of the line. forward-char (C-f) Move forward a character. backward-char (C-b) Move back a character. forward-word (M-f) Move forward to the end of the next word. Words are composed of letters and digits. backward-word (M-b) Move back to the start of the current or previous word. Words are composed of letters and digits. clear-screen (C-1) Clear the screen and redraw the current line, leaving the current line at the top of the screen. redraw-current-line () Refresh the current line. By default, this is unbound. 8.4.2 Commands For Manipulating The History accept-line (Newline or Return) Accept the line regardless of where the cursor is. If this line is non-empty, add it to the history list according to the setting of the HISTCONTROL and HISTIGNORE EFTA00315953
100 Bash Reference Manual variables. If this line is a modified history line, then restore the history line to its original state. previous-history (C-p) Move `back' through the history list, fetching the previous command. next-history (C-n) Move `forward' through the history list, fetching the next command. beginning-of-history (M-<) Move to the first line in the history. end-of-history (M->) Move to the end of the input history, i.e., the line currently being entered. reverse-search-history (C-r) Search backward starting at the current line and moving `up' through the his- tory as necessary. This is an incremental search. forward-search-history (C-a) Search forward starting at the current line and moving `down' through the the history as necessary. This is an incremental search. non-incremental-reverse-search-history (M-p) Search backward starting at the current line and moving `up' through the his- tory as necessary using a non-incremental search for a string supplied by the user. non-incremental-forward-search-history (M-n) Search forward starting at the current line and moving `down' through the the history as necessary using a non-incremental search for a string supplied by the user. history-sear ch-f orward Search forward through the history for the string of characters between the start of the current line and the point. This is a non-incremental search. By default, this command is unbound. history-search-backward () Search backward through the history for the string of characters between the start of the current line and the point. This is a non-incremental search. By default, this command is unbound. yank-nth-arg (M-C-y) Insert the first argument to the previous command (usually the second word on the previous line) at point. With an argument n, insert the nth word from the previous command (the words in the previous command begin with word 0). A negative argument inserts the nth word from the end of the previous command. Once the argument n is computed, the argument is extracted as if the ' In' history expansion had been specified. yank-last-arg (M-. or M-_) Insert last argument to the previous command (the last word of the previous history entry). With an argument, behave exactly like yank-nth-arg. Succes- sive calls to yank-last-arg move back through the history list, inserting the EFTA00315954
Chapter 8: Command Line Editing 101 last argument of each line in turn. The history expansion facilities are used to extract the last argument, as if the ! $' history expansion had been specified. 8.4.3 Commands For Changing Text delete-char (C-d) Delete the character at point. If point is at the beginning of the line, there are no characters in the line, and the last character typed was not bound to delete-char, then return EOF. backward-delete-char (Rubout) Delete the character behind the cursor. A numeric argument means to kill the characters instead of deleting them. forward-backward-delete-char O Delete the character under the cursor, unless the cursor is at the end of the line, in which case the character behind the cursor is deleted. By default, this is not bound to a key. quoted-insert (C-q or C-v) Add the next character typed to the line verbatim. This is how to insert key sequences like C-q, for example. self-insert (a, b, A, 1, !, ) Insert yourself. transpose-chars (C-t) Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line. Negative arguments have no effect. transpose-words (N-t) Drag the word before point past the word after point, moving point past that word as well. If the insertion point is at the end of the line, this transposes the last two words on the line. upcase-word (4-u) Uppercase the current (or following) word. With a negative argument, upper- case the previous word, but do not move the cursor. downcase-word (N-1) Lowercase the current (or following) word. With a negative argument, lowercase the previous word, but do not move the cursor. capitalize-word (4-c) Capitalize the current (or following) word. With a negative argument, capitalize the previous word, but do not move the cursor. overwrite-mode O Toggle overwrite mode. With an explicit positive numeric argument, switches to overwrite mode. With an explicit non-positive numeric argument, switches to EFTA00315955
102 Bash Reference Manual insert mode. This command affects only emacs mode; vi mode does overwrite differently. Each call to readline() starts in insert mode. In overwrite mode, characters bound to self-insert replace the text at point rather than pushing the text to the right. Characters bound to backward- delete-char replace the character before point with a space. By default, this command is unbound. 8.4.4 Killing And Yanking kill-line (C-k) Kill the text from point to the end of the line. backward-kill-line (C-x Rubout) Kill backward to the beginning of the line. unix-line-discard (C-u) Kill backward from the cursor to the beginning of the current line. kill-whole-line O Kill all characters on the current line, no matter where point is. By default, this is unbound. kill-word (M-d) Kill from point to the end of the current word, or if between words, to the end of the next word. Word boundaries are the same as forward-word. backward-kill-word (M-(DEL)) Kill the word behind point. Word boundaries are the same as backward-word. unix-word-rubout (C-w) Kill the word behind point, using white space as a word boundary. The killed text is saved on the kill-ring. unix-f ilename-rubout Kill the word behind point, using white space and the slash character as the word boundaries. The killed text is saved on the kill-ring. delete-horizontal-space O Delete all spaces and tabs around point. By default, this is unbound. kill-region () Kill the text in the current region. By default, this command is unbound. copy-region-as-kill O Copy the text in the region to the kill buffer, so it can be yanked right away. By default, this command is unbound. copy-backward-word O Copy the word before point to the kill buffer. The word boundaries are the same as backward-word. By default, this command is unbound. copy-forward-word O Copy the word following point to the kill buffer. The word boundaries are the same as forward-word. By default, this command is unbound. EFTA00315956
Chapter 8: Command Line Editing 103 yank CC-y) Yank the top of the kill ring into the buffer at point. yank-pop (M-y) Rotate the kill-ring, and yank the new top. You can only do this if the prior command is yank or yank-pop. 8.4.5 Specifying Numeric Arguments digit-argument 04-0, 14-1, Add this digit to the argument already accumulating, or start a new argument. M-- starts a negative argument. universal-argument O This is another way to specify, an argument. If this command is followed by one or more digits, optionally with a leading minus sign, those digits define the ar- gument. If the conunand is followed by digits, executing universal-argument again ends the numeric argument, but is otherwise ignored. As a special case, if this command is immediately followed by a character that is neither a digit or minus sign, the argument count for the next command is multiplied by four. The argument count is initially one, so executing this function the first time makes the argument count four, a second time makes the argument count six- teen, and so on. By default, this is not bound to a key. 8.4.6 Letting Readline Type For You complete (M)) Attempt to perform completion on the text before point. The actual completion performed is application-specific. Bash attempts completion treating the text as a variable (if the text begins with username (if the text begins with 41, hostname (if the text begins with 'or), or command (including aliases and functions) in turn. If none of these produces a match, filename completion is attempted. possible-completions CM-?) List the possible completions of the text before point. insert-completions (M-*) Insert all completions of the text before point that would have been generated by possible-completions. menu-complete O Similar to complete, but replaces the word to be completed with a single match from the list of possible completions. Repeated execution of menu-complete steps through the list of possible completions, inserting each match in turn. At the end of the list of completions, the bell is rung (subject to the setting of bell-style) and the original text is restored. An argument of n moves n positions forward in the list of matches; a negative argument may be used to move backward through the list. This command is intended to be bound to MB), but is unbound by default. EFTA00315957
104 Bash Reference Manual delete-char-or-list O Deletes the character under the cursor if not at the beginning or end of the line (like delete-char). If at the end of the line, behaves identically to possible- completions. This command is unbound by default. complete-filename (M-/) Attempt filename completion on the text before point. possible-filename-completions (C-x I) List the possible completions of the text before point, treating it as a filename. complete-username (ME") Attempt completion on the text before point, treating it as a username. possible-username-completions (C-x ") List the possible completions of the text before point, treating it as a username. complete-variable (M-$) Attempt completion on the text before point, treating it as a shell variable. possible-variable-completions (C-x $) List the possible completions of the text before point, treating it as a shell variable. complete-hostname (M-0) Attempt completion on the text before point, treating it as a hostname. possible-hostname-completions (C-x 0) List the possible completions of the text before point, treating it as a hostname. complete-command (M- ! ) Attempt completion on the text before point, treating it as a command name. Command completion attempts to match the text against aliases, reserved words, shell functions, shell builtins, and finally executable filenames, in that order. possible-command-completions (C-x !) List the possible completions of the text before point, treating it as a command name. dynamic-complete-history (M- Attempt completion on the text before point, comparing the text against lines from the history list for possible completion matches. complete-into-braces (M-{) Perform filename completion and insert the list of possible completions enclosed within braces so the list is available to the shell (see Section 3.5.1 [Brace Ex- pansion], page 17). 8.4.7 Keyboard Macros start-kbd-macro (C-x () Begin saving the characters typed into the current keyboard macro. EFTA00315958
Chapter 8: Command Line Editing 105 end-kbd-macro (C-x )) Stop saving the characters typed into the current keyboard macro and save the definition. call -kbd-macro (C-x e) Re-execute the last keyboard macro defined, by making the characters in the macro appear as if typed at the keyboard. 8.4.8 Some Miscellaneous Commands re-read-unit-file (C-x C-r) Read in the contents of the inputrc file, and incorporate any bindings or variable assignments found there. abort (C-g) Abort the current editing command and ring the terminal's bell (subject to the setting of bell-style). do-uppercase-version (M-a, M-b, M-x, . ..) If the metafied character x is lowercase, run the command that is bound to the corresponding uppercase character. prefix-meta ( ) Metafy the next character typed. This is for keyboards without a meta key. Typing `iM• f' is equivalent to typing M-f. undo (C-_ or C-x C-u) Incremental undo, separately remembered for each line. revert-line (M-r) Undo all changes made to this line. This is like executing the undo command enough times to get back to the beginning. tilde-expand (11-&) Perform tilde expansion on the current word. set-mark (C-Q) Set the mark to the point. If a numeric argument is supplied, the mark is set to that position. exchange-point-and-mark (C-x C-x) Swap the point with the mark. The current cursor position is set to the saved position, and the old cursor position is saved as the mark. character-search (C-] ) A character is read and point is moved to the next occurrence of that character. A negative count searches for previous occurrences. character-search-backward (M-C-]) A character is read and point is moved to the previous occurrence of that character. A negative count searches for subsequent occurrences. EFTA00315959
106 Bash Reference Manual insert-comment (M-#) Without a numeric argument, the value of the comment-begin variable is in- serted at the beginning of the current line. If a numeric argument is supplied, this command acts as a toggle: if the characters at the beginning of the line do not match the value of comment-begin, the value is inserted, otherwise the characters in comment-begin are deleted from the beginning of the line. In either case, the line is accepted as if a newline had been typed. The default value of comment-begin causes this command to make the current line a shell comment. If a numeric argument causes the comment character to be removed, the line will be executed by the shell. dump-functions O Print all of the functions and their key bindings to the Readline output stream. If a numeric argument is supplied, the output is formatted in such a way that it can he made part of an inputrc file. This command is unbound by default. dump-variables O Print all of the settable variables and their values to the Readline output stream. If a numeric argument is supplied, the output is formatted in such a way that it can be made part of an inputrc file. This command is unbound by default. dump-macros O Print all of the Readline key sequences bound to macros and the strings they output. If a numeric argument is supplied, the output is formatted in such a way that it can be made part of an inputrc file. This command is unbound by default. glob-complete-word (4-g) The word before point is treated as a pattern for pathname expansion, with an asterisk implicitly appended. This pattern is used to generate a list of matching file names for possible completions. glob-expand-word (C-x *) The word before point is treated as a pattern for pathname expansion, and the list of matching file names is inserted, replacing the word. If a numeric argument is supplied, a `*' is appended before pathname expansion. glob-list -expansions (C-x g) The list of expansions that would have been generated by glob-expand-word is displayed, and the line is redrawn. If a numeric argument is supplied, a `*. is appended before pathname expansion. display-shell-version (C-x C-v) Display version information about the current instance of Bash. shell-expand-line (M-C-e) Expand the line as the shell does. This performs alias and history expansion as well as all of the shell word expansions (see Section 3.5 [Shell Expansions], page 17). history-expand-line (M--) Perform history expansion on the current line. EFTA00315960
Chapter 8: Command Line Editing 107 magic-space () Perform history expansion on the current line and insert a space (see Section 9.3 [History Interaction], page 115). alias-expand-line () Perform alias expansion on the current line (see Section 6.6 [Aliases], page 73). history-and-alias-expand-line O Perform history and alias expansion on the current line. insert-last-argument (M-. or M-_) A synonym for yank-last-arg. operate-and-get-next (C-o) Accept the current line for execution and fetch the next line relative to the current line from the history for editing. Any argument is ignored. edit-and-execute-command (C-xC-e) Invoke an editor on the current command line, and execute the result as shell commands. Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order. 8.5 Readline vi Mode While the Readline library does not have a full set of vi editing functions, it does contain enough to allow simple editing of the line. The Readline vi mode behaves as specified in the POSIX 1003.2 standard. In order to switch interactively between emacs and vi editing modes, use the `set -o emacs' and `set -o vi' commands (see Section 4.3 [The Set Builtin], page 51). The Readline default is emacs mode. When you enter a line in vi mode, you are already placed in `insertion' mode, as if you had typed an 9.'. Pressing (PSC) switches you into `command' mode, where you can edit the text of the line with the standard vi movement keys, move to previous history lines with `If and subsequent lines with `f, and so forth. 8.6 Programmable Completion When word completion is attempted for an argument to a command for which a comple- tion specification (a compspec) has been defined using the complete builtin (see Section 8.7 [Programmable Completion Builtins], page 109), the programmable completion facilities are invoked. First, the command name is identified. If a compspec has been defined for that command, the compspec is used to generate the list of possible completions for the word. If the command word is a full pathname, a compspec for the full pathname is searched for first. If no compspec is found for the full pathname, an attempt is made to find a compspec for the portion following the final slash. Once a compspec has been found, it is used to generate the list of matching words. If a compspec is not found, the default Bash completion described above (see Section 8.4.6 [Commands For Completion], page 103) is performed. EFTA00315961
108 Bash Reference Manual First, the actions specified by the compspec are used. Only matches which are prefixed by the word being completed are returned. When the '-f' or '-d' option is used for filename or directory name completion, the shell variable FIGNORE is used to filter the matches. See Section 5.2 [Bash Variables], page 55, for a description of FIGNORE. Any completions specified by a filename expansion pattern to the '-G' option are gener- ated next. The words generated by the pattern need not match the word being completed. The GLOBIGNORE shell variable is not used to filter the matches, but the FIGNORE shell variable is used. Next, the string specified as the argument to the '-W' option is considered. The string is first split using the characters in the IFS special variable as delimiters. Shell quoting is honored. Each word is then expanded using brace expansion, tilde expansion, parameter and variable expansion, command substitution, and arithmetic expansion, as described above (see Section 3.5 [Shell Expansions], page 17). The results are split using the rules described above (see Section 3.5.7 [Word Splitting], page 22). The results of the expansion are prefix-matched against the word being completed, and the matching words become the possible completions. After these matches have been generated, any shell function or command specified with the `-F' and `-C' options is invoked. When the command or function is invoked, the COMP_ LINE and COMP POINT variables are assigned values as described above (see Section 5.2 [Bash Variables], page 55). If a shell function is being invoked, the COMP_WORDS and COMP_CWORD variables are also set. When the function or command is invoked, the first argument is the name of the command whose arguments are being completed, the second argument is the word being completed, and the third argument is the word preceding the word being completed on the current command line. No filtering of the generated completions against the word being completed is performed; the function or command has complete freedom in generating the matches. Any function specified with '-F' is invoked first. The function may use any of the shell facilities, including the compgen builtin described below (see Section 8.7 [Programmable Completion Builtins], page 109), to generate the matches. It must put the possible comple- tions in the COMPREPLY array variable. Next, any command specified with the `-C' option is invoked in an environment equivalent to command substitution. It should print a list of completions, one per line, to the standard output. Backslash may be used to escape a newline, if necessary. After all of the possible completions are generated, any filter specified with the `-r option is applied to the list. The filter is a pattern as used for pathname expansion; a 1' in the pattern is replaced with the text of the word being completed. A literal may be escaped with a backslash; the backslash is removed before attempting a match. Any completion that matches the pattern will be removed from the list. A leading r negates the pattern; in this case any completion not matching the pattern will be removed. Finally, any prefix and suffix specified with the `-P' and `-5' options are added to each member of the completion list, and the result is returned to the Readline completion code as the list of possible completions. If the previously-applied actions do not generate any matches, and the '-o dirnames' op- tion was supplied to complete when the compspec was defined, directory name completion is attempted. EFTA00315962
Chapter 8: Command Line Editing 109 If the '-o plusdirs' option was supplied to complete when the compspec was defined, directory name completion is attempted and any matches are added to the results of the other actions. By default, if a compspec is found, whatever it generates is returned to the completion code as the full set of possible completions. The default Bash completions are not attempted, and the Readline default of filename completion is disabled. If the '-o bashdefault' option was supplied to complete when the compspec was defined, the default Bash completions are attempted if the compspec generates no matches. If the '-o default' option was supplied to complete when the compspec was defined, Readline's default completion will be performed if the compspec (and, if attempted, the default Bash completions) generate no matches. When a compspec indicates that directory name completion is desired, the programmable completion functions force Readline to append a slash to completed names which are sym- bolic links to directories, subject to the value of the mark-directories Readline variable, regardless of the setting of the mark-symlinked-directories Readline variable. 8.7 Programmable Completion Builtins Two builtin commands are available to manipulate the programmable completion facil- ities. compgen compgen [option] [word] Generate possible completion matches for word according to the options, which may be any option accepted by the complete builtin with the exception of `-p' and '-r', and write the matches to the standard output. When using the or `-C' options, the various shell variables set by the programmable completion facilities, while available, will not have useful values. The matches will be generated in the same way as if the programmable com- pletion code had generated them directly from a completion specification with the same flags. If word is specified, only those completions matching word will be displayed. The return value is true unless an invalid option is supplied, or no matches were generated. complete complete [-abcdefgjksuv] [-o comp-option] [-A action] [-G glob- pat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] name [name complete -pr [name . . .] Specify how arguments to each name should be completed. If the `-p' option is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be reused as input. The `-r' option removes a completion specification for each name, or, if no names are supplied, all completion specifications. EFTA00315963
110 Bash Reference Manual The process of applying these completion specifications when word completion is attempted is described above (see Section 8.6 [Programmable Completion], page 107). Other options, if specified, have the following meanings. The arguments to the '-G', '-W', and '-]1' options (and, if necessary, the `-P' and `-S' options) should be quoted to protect them from expansion before the complete builtin is invoked. -o comp-option The comp-option controls several aspects of the compspec's behav- ior beyond the simple generation of completions. comp-option may be one of: baandef ault Perform the rest of the default Bash completions if the compspec generates no matches. default Use Readline's default filename completion if the comp- spec generates no matches. dirnames Perform directory name completion if the compspec generates no matches. filenames Tell Readline that the compspec generates filenames, so it can perform any filename-specific processing (like adding a slash to directory names or suppressing trail- ing spaces). This option is intended to be used with shell functions specified with `-r. nos pace Tell Readline not to append a space (the default) to words completed at the end of the line. plusdirs After any matches defined by the compspec are gener- ated, directory name completion is attempted and any matches are added to the results of the other actions. -A action The action may be one of the following to generate a list of possible completions: alias Alias names. May also be specified as '-a'. arrayvar Array variable names. binding Readline key binding names (see Section 8.4 [Bindable Readline Commands], page 99). builtin Names of shell builtin commands. May also be specified as `-b'. command Command names. May also be specified as `-e. directory Directory names. May also be specified as `-d'. EFTA00315964
Chapter 8: Command Line Editing 111 disabled Names of disabled shell builtins. enabled Names of enabled shell builtins. export Names of exported shell variables. May also be speci- fied as 1-e'. file File names. May also be specified as 1-f. function Names of shell functions. group Group names. May also be specified as 1-e. helptopi c Help topics as accepted by the help builtin (see Sec- tion 4.2 [Bash Builtins], page 39). hostname Hostnames, as taken from the file specified by the HOSTFILE shell variable (see Section 5.2 [Bash Variables], page 55). job Job names, if job control is active. May also be speci- fied as 1-j'. keyword Shell reserved words. May also be specified as `-k'. running Names of running jobs, if job control is active. service Service names. May also be specified as 1-s'. setopt Valid arguments for the 1-o' option to the set builtin (see Section 4.3 [The Set Builtin], page 51). shopt Shell option names as accepted by the shopt builtin (see Section 4.2 [Bash Builtins], page 39). signal Signal names. stopped Names of stopped jobs, if job control is active. user User names. May also be specified as `-te. variable Names of all shell variables. May also be specified as 1-v'. - G globpat The filename expansion pattern globpat is expanded to generate the possible completions. - W wordlist The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is expanded. The possible completions are the members of the resultant list which match the word being completed. - C command command is executed in a subshell environment, and its output is used as the possible completions. EFTA00315965
112 Bash Reference Manual - F function The shell function function is executed in the current shell environ- ment. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable. - X filterpat filterpat is a pattern as used for filename expansion. It is applied to the list of possible completions generated by the preceding options and arguments, and each completion matching filterpat is removed from the list. A leading `!'in filterpat negates the pattern; in this case, any completion not matching filterpat is removed. - P prefix prefix is added at the beginning of each possible completion after all other options have been applied. - S suffix suffix is appended to each possible completion after all other options have been applied. The return value is true unless an invalid option is supplied, an option other than `-p' or `-r' is supplied without a name argument, an attempt is made to remove a completion specification for a name for which no specification exists, or an error occurs adding a completion specification. EFTA00315966
Chapter 9: Using History Interactively 113 9 Using History Interactively This chapter describes how to use the GNU History Library interactively, from a user's standpoint. It should be considered a user's guide. For information on using the GNU History Library in other programs, see the GNU Headline Library Manual. 9.1 Bash History Facilities When the '-o history' option to the set builtin is enabled (see Section 4.3 [The Set Builtin], page 51), the shell provides access to the command history, the list of commands previously typed. The value of the HISTSIZE shell variable is used as the number of com- mands to save in a history list. The text of the last $HISTSIZE commands (default 500) is saved. The shell stores each command in the history list prior to parameter and vari- able expansion but after history expansion is performed, subject to the values of the shell variables HISTIGNORE and HISTCONTROL. When the shell starts up, the history is initialized from the file named by the HISTFILE variable (default `"/.bash_history'). The file named by the value of HISTFILE is truncated, if necessary, to contain no more than the number of lines specified by the value of the HISTFILESIZE variable. When an interactive shell exits, the last $HISTSIZE lines are copied from the history list to the file named by $HISTFILE. If the histappend shell option is set (see Section 4.2 [Bash Builtins], page 39), the lines are appended to the history file, otherwise the history file is overwritten. If HISTFILE is unset, or if the history file is unwritable, the history is not saved. After saving the history, the history file is truncated to contain no more than $HISTFILESIZE lines. If HISTFILESIZE is not set, no truncation is performed. If the HISTTIMEFORMAT is set, the time stamp information associated with each history entry is written to the history file. The builtin command f c may be used to list or edit and re-execute a portion of the history list. The history builtin may be used to display or modify the history list and manipulate the history file. When using command-line editing, search commands are available in each editing mode that provide access to the history list (see Section 8.4.2 [Commands For History], page 99). The shell allows control over which commands are saved on the history list. The HISTCONTROL and HISTIGNORE variables may be set to cause the shell to save only a subset of the commands entered. The andhist shell option, if enabled, causes the shell to attempt to save each line of a multi-line command in the same history entry, adding semicolons where necessary to preserve syntactic correctness. The lithist shell option causes the shell to save the command with embedded newlines instead of semicolons. The shopt builtin is used to set these options. See Section 4.2 [Bash Builtins], page 39, for a description of shopt. 9.2 Bash History Builtins Bash provides two builtin commands which manipulate the history list and history file. fc EFTA00315967
114 Bash Reference Manual fc [-e ename] [-ills] [first] [last] fc -a [pat =rep] [command] Fix Command. In the first form, a range of commands from first to last is selected from the history list. Both first and last may be specified as a string (to locate the most recent command beginning with that string) or as a number (an index into the history list, where a negative number is used as an offset from the current command number). If last is not specified it is set to first. If first is not specified it is set to the previous command for editing and —16 for listing. If the '-1' flag is given, the commands are listed on standard output. The `-n' flag suppresses the command numbers when listing. The `-r' flag reverses the order of the listing. Otherwise, the editor given by ename is invoked on a file containing those commands. If ename is not given, the value of the following variable expansion is used: ${FCEDIT: -1{EDITOR: -vi}}, This says to use the value of the FCEDIT variable if set, or the value of the EDITOR variable if that is set, or vi if neither is set. When editing is complete, the edited commands are echoed and executed. In the second form, command is re-executed after each instance of pat in the selected command is replaced by rep. A useful alias to use with the fe command is r='fc -s', so that typing `r cc' runs the last command beginning with ee and typing `r' re-executes the last command (see Section 6.6 [Aliases], page 73). history history [n] history -c history -d offset history [-anrw] [filename] history -ps arg With no options. display the history list with line numbers. Lines prefixed with a `4.' have been modified. An argument of n lists only the last n lines. If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string for strftime to display the time stamp associated with each displayed history entry. No intervening blank is printed between the formatted time stamp and the history line. Options, if supplied, have the following meanings: - e Clear the history list. This may be combined with the other options to replace the history list completely. - d offset - a - n Delete the history entry at position offset. offset should be specified as it appears when the history is displayed. Append the new history lines (history lines entered since the be- ginning of the current Bash session) to the history file. Append the history lines not already read from the history file to the current history list. These are lines appended to the history file since the beginning of the current Bash session. EFTA00315968
Chapter 9: Using History Interactively 115 - r - w Read the current history file and append its contents to the history list. Write out the current history to the history file. - p Perform history substitution on the ergs and display the result on the standard output, without storing the results in the history list. - s The ergs are added to the end of the history list as a single entry. When any of the '-w', `-r', '-a', or '-n' options is used, if filename is given, then it is used as the history file. If not, then the value of the HISTFILE variable is used. 9.3 History Expansion The History library provides a history expansion feature that is similar to the history expansion provided by esh. This section describes the syntax used to manipulate the history information. History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly. History expansion takes place in two parts. The first is to determine which line from the history list should be used during substitution. The second is to select portions of that line for inclusion into the current one. The line selected front the history is called the event, and the portions of that line that are acted upon are called words. Various modifiers are available to manipulate the selected words. The line is broken into words in the same fashion that Bash does, so that several words surrounded by quotes are considered one word. History expansions are introduced by the appearance of the history expansion character, which is ! ' by default. Only `\' and may be used to escape the history expansion character. Several shell options settable with the shopt builtin (see Section 4.2 [Bash Builtins], page 39) may be used to tailor the behavior of history expansion. If the histverify shell option is enabled, and Readline is being used, history substitutions are not immediately passed to the shell parser. Instead, the expanded line is reloaded into the Readline editing buffer for further modification. If Readline is being used, and the histreedit shell option is enabled, a failed history expansion will be reloaded into the Readline editing buffer for correction. The `-p' option to the history builtin command may be used to see what a history expansion will do before using it. The `-s' option to the history builtin may be used to add commands to the end of the history list without actually executing them, so that they are available for subsequent recall. This is most useful in conjunction with Readline. The shell allows control of the various characters used by the history expansion mecha- nism with the histchars variable. 9.3.1 Event Designators An event designator is a reference to a command line entry in the history list. EFTA00315969
116 Bash Reference Manual Start a history substitution, except when followed by a space, tab, the end of the line, 1=' or (' (when the extglob shell option is enabled using the ahopt builtin). In Refer to command line n. l-n Refer to the command n lines back. !! Refer to the previous command. This is a synonym for ! -1'. !string Refer to the most recent command starting with string. !?string[?] Refer to the most recent command containing string. The trailing '7' may be omitted if the string is followed immediately by a newline. stringl -string2 Quick Substitution. Repeat the last command, replacing stringl with string2. Equivalent to !! : s/stringl/string2/. !St The entire command line typed so far. 9.3.2 Word Designators Word designators are used to select desired words from the event. A separates the event specification from the word designator. It may be omitted if the word designator begins with a `$', or 'y.'. Words are numbered from the beginning of the line, with the first word being denoted by 0 (zero). Words are inserted into the current line separated by single spaces. For example, !! designates the preceding command. When you type this, the preceding com- mand is repeated in toto. !! :$ designates the last argument of the preceding command. This may be shortened to !$. !ft:2 designates the second argument of the most recent command starting with the letters fi. Here are the word designators: 0 (zero) The 0th word. For many applications, this is the command word. n The nth word. The first argument; that is, word 1. The last argument. The word matched by the most recent `?string?' search. x-y A range of words; `-y' abbreviates '0-y'. All of the words, eve.pt the 0th. This is a synonym for '1-$'. It is not an error to use `*' if there is just one word in the event; the empty string is returned in that case. EFTA00315970
Chapter 9: Using History Interactively 117 xi Abbreviates ix-$' x- Abbreviates ix-$' like 'xi', but omits the last word. If a word designator is supplied without an event specification, the previous command is used as the event. 9.3.3 Modifiers After the optional word designator, you can add a sequence of one or more of the following modifiers, each preceded by a':'. h Remove a trailing pathname component, leaving only the head. t Remove all leading pathname components, leaving the tail. Remove a trailing suffix of the form suffix', leaving the basename. e Remove all but the trailing suffix. p Print the new command but do not execute it. q Quote the substituted words, escaping further substitutions. x Quote the substituted words as with 'q', but break into words at spaces, tabs, and newlines. s/old/new/ Substitute new for the first occurrence of old in the event line. Any delimiter may be used in place of The delimiter may be quoted in old and new with a single backslash. If 'Se appears in new, it is replaced by old. A single backslash will quote the If. The final delimiter is optional if it is the last character on the input line. Repeat the previous substitution. g a Cause changes to be applied over the entire event line. Used in conjunction with 'a', as in Weld/nevi, or with le. Apply the following 'a' modifier once to each word in the event. EFTA00315971
118 Bash Reference Manual EFTA00315972
Chapter 10: Installing Bash 119 10 Installing Bash This chapter provides basic instructions for installing Bash on the various supported platforms. The distribution supports the GNU operating systems, nearly every version of Unix, and several non-Unix systems such as BeOS and Interix. Other independent ports exist for MS-DOS, OS/2, and Windows platforms. 10.1 Basic Installation These are installation instructions for Bash. The simplest way to compile Bash is: 1. cd to the directory containing the source code and type `. /conf igure' to configure Bash for your system. If you're using csh on an old version of System V, you might need to type 'sh /configure' instead to prevent csh from trying to execute configure itself. Running configure takes some time. While running, it prints messages telling which features it is checking for. 2. Type `make' to compile Bash and build the bashbug bug reporting script. 3. Optionally, type `make tests' to run the Bash test suite. 4. Type `make install' to install bash and bashbug. This will also install the manual pages and Info file. The configure shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a Ifakefile' in each directory of the package (the top directory, the `builtins', `doe, and `support' directories, each directory under lib', and several others). It also creates a iconfig.h' file containing system-dependent definitions. Finally, it creates a shell script named conf ig. status that you can run in the future to recreate the current configuration, a file 'config. cache' that saves the results of its tests to speed up reconfiguring, and a file `conf ig. log' containing compiler output (useful mainly for debugging configure). If at some point `conf ig. cache' contains results you don't want to keep, you may remove or edit it. To find out more about the options and arguments that the configure script under- stands, type bash-2.04$ . /conf igure --help at the Bash prompt in your Bash source directory. If you need to do unusual things to compile Bash, please try to figure out how configure could check whether or not to do them, and mail dills or instructions to [email protected] so they can be considered for the next release. The file `configure. in' is used to create configure by a program called Autoconf. You only need `configure. in' if you want to change it or regenerate configure using a newer version of Autoconf. If you do this, make sure you are using Autoconf version 2.50 or newer. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that configure created (so you can compile Bash for a different kind of computer), type `make distclean'. EFTA00315973
120 Bash Reference Manual 10.2 Compilers and Options Some systems require unusual options for compilation or linking that the configure script does not know about. You can give configure initial values for variables by setting them in the environment. Using a Bourne-compatible shell, you can do that on the command line like this: CC=c89 CFLAGS=-02 LIBS=-1posix ./configure On systems that have the env program, you can do it like this: env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure The configuration process uses GCC to build Bash if it is available. 10.3 Compiling For Multiple Architectures You can compile Bash for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you must use a version of make that supports the VPATH variable, such as GNU make. cd to the directory where you want the object files and executables to go and run the configure script from the source directory. You may need to supply the `--arcdir=PATH' argument to tell configure where the source files are. configure automatically checks for the source code in the directory that configure is in and in `..'. If you have to use a make that does not supports the VPATH variable, you can compile Bash for one architecture at a time in the source code directory. After you have installed Bash for one architecture, use `make distclean' before reconfiguring for another architecture. Alternatively, if your system supports symbolic links, you can use the `support/mkelone' script to create a build tree which has symbolic links back to each file in the source directory. Here's an example that creates a build directory in the current directory from a source directory `/usr/gnu/arc/bash-2.0': bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/srabash-2 .0 . The mkclone script requires Bash, so you must have already built Bash for at least one architecture before you can create build directories for other architectures. 10.4 Installation Names By default, 'make install' will install into Vusr/local/bin', Vusr/local/man', etc. You can specify an installation prefix other than lusr/locar by giving configure the option `--prefix=PATIr, or by specifying a value for the DESTDIR `make' variable when running `make install'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you give configure the option 1--exec-prefix=PATH., `make install' will use PATH as the prefix for installing programs and libraries. Documentation and other data files will still use the regular prefix. EFTA00315974
Chapter 10: Installing Bash 121 10.5 Specifying the System Type There may be some features configure can not figure out automatically, but need to determine by the type of host Bash will run on. Usually configure can figure that out, but if it prints a message saying it can not guess the host type, give it the `--host=TYPE' option. `TYPE' can either be a short name for the system type, such as `sun4', or a canonical name with three fields: `CPU-COMPANY-SYSTEM' `1386-unknown-freebsd4.2). See the file csupport/conf ig. sub' for the possible values of each field. 10.6 Sharing Defaults If you want to set default values for configure scripts to share, you can create a site shell script called config.site that gives default values for variables like CC, cache_ file, and prefix. configure looks for 'PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the CONFIG_SITE environment vari- able to the location of the site script. A warning: the Bash configure looks for a site script, but not all configure scripts do. 10.7 Operation Controls configure recognizes the following options to control how it operates. - -cache-f ile=file Use and save the results of the tests in file instead of /conf ig. cache'. Set file to `Rev/null' to disable caching, for debugging configure. - -help Print a summary of the options to configure, and exit. - -quiet - -silent -q Do not print messages saying which checks are being made. - -srcdir=dir Look for the Bash source code in directory dir. Usually configure can deter- mine that directory automatically. - -version Print the version of Autoconf used to generate the configure script, and exit. configure also accepts some other, not widely used, boilerplate options. `configure - -help' prints the complete list. 10.8 Optional Features The Bash configure has a number of `--enable-feature' options, where feature in- dicates an optional part of Bash. There are also several 1--with-package options, where package is something like `bash-malloc' or `purify'. To turn off the default use of a pack- age, use `--without-package'. To configure Bash without a feature that is enabled by default, use `--disable-feature'. EFTA00315975
122 Bash Reference Manual Here is a complete list of the '--enable-' and `--with-' options that the Bash configure recognizes. - -with -afs Define if you are using the Andrew File System from 'I1ansarc. - -with-bash-malloc Use the Bash version of malloc in the directory lib/malloc'. This is not the same malloc that appears in GNU libc, but an older version originally derived from the 4.2 BSD malloc. This malloc is very fast, but wastes some space on each allocation. This option is enabled by default. The `NOTES' file contains a list of systems for which this should be turned off, and configure disables this option automatically for a number of systems. - -with-curses Use the curses library instead of the termcap library. This should be supplied if your system has an inadequate or incomplete termcap database. - -with-gnu-malloc A synonym for --with-bash-malloc. - -with-installed-readline [=PREFIX] Define this to make Bash link with a locally-installed version of Readline rather than the version in 1.i.b/readline'. This works only with Readline 5.0 and later versions. If PREFIX is yes or not supplied, configure uses the values of the make variables includedir and libdir, which are subdirectories of prefix by default, to find the installed version of Readline if it is not in the standard system include and library directories. If PREFIX is no, Bash links with the version in 1.ibireadline. If PREFIX is set to any other value, configure treats it as a directory pathname and looks for the installed version of Readline in subdirectories of that directory (include files in PREFIX/include and the library in PREFIX/lib). - -with-purify Define this to use the Purify memory allocation checker from Rational Software. - -enable-minimal-conf ig This produces a shell with minimal features, close to the historical Bourne shell. There are several '--enable-' options that alter how Bash is compiled and linked, rather than changing run-time features. - -enable-largef ile Enable support for large files file/x_open.20Mar96 .html) if the operating system requires special compiler options to build programs which can access large files. This is enabled by default, if the operating system provides large file support. - -enable-profiling This builds a Bash binary that produces profiling information to be processed by gprof each time it is executed. EFTA00315976
Chapter 10: Installing Bash 123 --enable-static-link This causes Bash to be linked statically, if gee is being used. This could be used to build a version to use as root's shell. The `minimal-config' option can be used to disable all of the following options, but it is processed first, so individual options may be enabled using `enable-feature'. All of the following options except for `clisabled-builtins' and `xpg-echo-default' are enabled by default, unless the operating system does not provide the necessary support. --enable-alias Allow alias expansion and include the alias and unalias builtins (see Sec- tion 6.6 [Aliases], page 73). --enable-arith-f or-command Include support for the alternate form of the for command that behaves like the C language for statement (see Section 3.2.4.1 [Looping Constructs], page 9). --enable-array-variables Include support for one-dimensional array shell variables (see Section 6.7 [Ar- rays], page 74). - -enable-bang-history Include support for csh-like history substitution (see Section 9.3 [History In- teraction], page 115). - -enable-brace-expansion Include csh-like brace expansion ( b{a,b}e bac bbc ). See Section 3.5.1 [Brace Expansion], page 17, for a complete description. - -enable-command-timing Include support for recognizing time as a reserved word and for displaying timing statistics for the pipeline following time (see Section 3.2.2 [Pipelines], page 8). This allows pipelines as well as shell builtins and functions to be tinted. - -enable-toad-command Include support for the 11 conditional command. (see Section 3.2.4.2 [Condi- tional Constructs], page 10). - -enable-cond-regexp Include support for matching POSIX regular expressions using the `="' binary operator in the EL conditional command. (see Section 3.2.4.2 [Conditional Con- structs], page 10). - -enable-debugger Include support for the bash debugger (distributed separately). --enable-directory-stack Include support for a csh-like directory stack and the pushd, popd, and dirs builtins (see Section 6.8 (The Directory Stack], page 75). --enable-disabled-builtins Allow builtin commands to be invoked via `builtin xxx' even after xxx has been disabled using `enable -n xxx'. See Section 4.2 [Bash Builtins], page 39, for details of the builtin and enable builtin commands. EFTA00315977
124 Bash Reference Manual - -enable-dparen-arithmetic Include support for the ((. ..)) command (see Section 3.2.4.2 [Conditional Constructs], page 10). - -enable-extended-glob Include support for the extended pattern matching features described above under Section 3.5.8.1 [Pattern Matching], page 23. --enable-help-builtin Include the help builtin, which displays help on shell builtins and variables (see Section 4.2 [Bash Builtins], page 39). --enable-history Include command history and the fc and history builtin commands (see Sec- tion 9.1 [Bash History Facilities], page 113). --enable-job-control This enables the job control features (see Chapter 7 [Job Control], page 83), if the operating system supports them. - -enable-multibyte This enables support for multibyte characters if the operating system provides the necessary support. --enable-net-redirections This enables the special handling of filenames of the form idevitcp/host/port and /dev/udp/host /port when used in redirections (see Section 3.6 [Redirec- tions], page 25). --enable-process-substitution This enables process substitution (see Section 3.5.6 [Process Substitution], page 22) if the operating system provides the necessary support. - -enable-progcomp Enable the programmable completion facilities (see Section 8.6 [Programmable Completion], page 107). If Readline is not enabled, this option has no effect. - -enable-prompt-string-decoding Turn on the interpretation of a number of backslash-escaped characters in the $PSI, $PS2, $PS3, and $PS4 prompt strings. See Section 6.9 [Printing a Prompt], page 77, for a complete list of prompt string escape sequences. --enable-readline Include support for command-line editing and history with the Bash version of the Readline library (see Chapter 8 [Command Line Editing], page 87). --enable-restricted Include support for a restricted shell. If this is enabled, Bash, when called as rbash, enters a restricted mode. See Section 6.10 [The Restricted Shell], page 78, for a description of restricted mode. --enable-select Include the select builtin, which allows the generation of simple menus (see Section 3.2.4.2 [Conditional Constructs], page 10). EFTA00315978
Chapter 10: Installing Bash 125 - -enable-separate-helpf iles Use external files for the documentation displayed by the help builtin instead of storing the text internally. --enable-single-help-strings Store the text displayed by the help builtin as a single string for each help topic. This aids in translating the text to different languages. You may need to disable this if your compiler cannot handle very long string literals. --enable-strict-posix-default Make Bash Postx-conformant by default (see Section 6.11 [Bash POS1X Mode], page 78). - -enable-usg-echo-default A synonym for --enable-xpg-echo-default. - -enable-xpg-echo-default Make the echo builtin expand backslash-escaped characters by default_ without requiring the `-e' option. This sets the default value of the xpg_echo shell option to on, which makes the Bash echo behave more like the version specified in the Single Unix Specification, version 3. See Section 4.2 [Bash Builtins], page 39, for a description of the escape sequences that echo recognizes. The file `conf ig-top h' contains C Preprocessor lcief ine' statements for options which are not settable from configure. Some of these are not meant to be changed; beware of the consequences if you do. Read the comments associated with each definition for more information about its effect. EFTA00315979
126 Bash Reference Manual EFTA00315980
Appendix A: Reporting Bugs 127 Appendix A Reporting Bugs Please report all bugs you find in Bash. But first, you should make sure that it really is a bug, and that it appears in the latest version of Bash. The latest version of Bash is always available for FTP from f tp : //f tp . gnu. org/pub/bash/. Once you have determined that a bug actually exists, use the bashbug command to submit a bug report. If you have a fix, you are encouraged to mail that as well! Suggestions and 'philosophical' bug reports may be mailed to bug-bashCsu. org or posted to the Usenet newsgroup gnu. bash. bug. All bug reports should include: • The version number of Bash. • The hardware and operating system. • The compiler used to compile Bash. • A description of the bug behaviour. • A short script or 'recipe' which exercises the bug and may be used to reproduce it. bashbug inserts the first three items automatically into the template it provides for filing a bug report. Please send all reports concerning this manual to chetepo. CWRU. Edu. EFTA00315981
128 Bash Reference Manual EFTA00315982
Appendix B: Major Differences From The Bourne Shell 129 Appendix B Major Differences From The Bourne Shell Bash implements essentially the same grammar, parameter and variable expansion, redi- rection, and quoting as the Bourne Shell. Bash uses the POSIX 1003.2 standard as the spec- ification of how these features are to be implemented. There are some differences between the traditional Bourne shell and Bash; this section quickly details the differences of signif- icance. A number of these differences are explained in greater depth in previous sections. This section uses the version of sh included in SVR4.2 (the last version of the historical Bourne shell) as the baseline reference. • Bash is Postx-conformant, even where the POSIX specification differs from traditional ah behavior (see Section 6.11 [Bash POSIX Mode], page 78). • Bash has multi-character invocation options (see Section 6.1 [Invoking Bash], page 65). • Bash has command-line editing (see Chapter 8 [Command Line Editing], page 87) and the bind builtin. • Bash provides a programmable word completion mechanism (see Section 8.6 [Pro- grammable Completion], page 107), and two builtin commands, complete and compgen, to manipulate it. • Bash has command history (see Section 9.1 [Bash History Facilities], page 113) and the history and f c builtins to manipulate it. The Bash history list maintains timestamp information and uses the value of the HISTTIMEF0RMAT variable to display it. • Bash implements csh-like history expansion (see Section 9.3 [History Interaction], page 115). • Bash has one-dimensional array variables (see Section 6.7 [Arrays], page 74), and the appropriate variable expansions and assignment syntax to use them. Several of the Bash builtins take options to act on arrays. Bash provides a number of built-in array variables. • The $' ' quoting syntax, which expands ANSI-C backslash-escaped characters in the text between the single quotes, is supported (see Section 3.1.2.4 [ANSI-C Quoting], page 6). • Bash supports the $" " quoting syntax to do locale-specific translation of the characters between the double quotes. The `-D', 4—dump-strings', and I--dump-po-strings' invocation options list the translatable strings found in a script (see Section 3.1.2.5 [Locale Translation], page 7). • Bash implements the ! keyword to negate the return value of a pipeline (see Sec- tion 3.2.2 [Pipelines], page 8). Very useful when an if statement needs to act only if a test fails. The Bash '-o pipef ail' option to set will cause a pipeline to return a failure status if any command fails. • Bash has the time reserved word and command timing (see Section 3.2.2 [Pipelines], page 8). The display of the tinting statistics may be controlled with the TIMEF0RMAT variable. • Bash implements the for (( exprl ; expr2 ; expr3 )) arithmetic for command, sim- ilar to the C language (see Section 3.2.4.1 [Looping Constructs], page 9). • Bash includes the select compound command, which allows the generation of simple menus (see Section 3.2.4.2 [Conditional Constructs], page 10). EFTA00315983
130 Bash Reference Manual • Bash includes the IL compound command, which makes conditional testing part of the shell grammar (see Section 3.2.4.2 [Conditional Constructs], page 10), including optional regular expression matching. • Bash provides optional case-insensitive matching for the case and [1 constructs. • Bash includes brace expansion (see Section 3.5.1 [Brace Expansion], page 17) and tilde expansion (see Section 3.5.2 [Tilde Expansion], page 18). • Bash implements command aliases and the alias and unalias builtins (see Section 6.6 [Aliases], page 73). • Bash provides shell arithmetic, the ( ( compotmd command (see Section 3.2.4.2 [Con- ditional Constructs], page 10), and arithmetic expansion (see Section 6.5 [Shell Arith- metic], page 72). • Variables present in the shell's initial environment are automatically exported to child processes. The Bourne shell does not normally do this unless the variables are explicitly marked using the export command. • Bash supports the `4-=' assignment operator, which appends to the value of the variable named on the left hand side. • Bash includes the POSIX pattern removal `%', "%%' an ## expansions to remove leading or trailing substrings front variable values (see Section 3.5.3 [Shell Parameter Expansion], page 19). • The expansion ${#xx}, which returns the length of ${xx}, is supported (see Sec- tion 3.5.3 [Shell Parameter Expansion], page 19). • The expansion ${var : offset1:length]}, which expands to the substring of var's value of length length, beginning at offset, is present (see Section 3.5.3 [Shell Parameter Expansion], page 19). • The expansion ${var/1/]pattern[/replacement]}, which matches pattern and replaces it with replacement in the value of var, is available (see Section 3.5.3 [Shell Parameter Expansion], page 19). • The expansion ${iprefix}* expansion, which expands to the names of all shell vari- ables whose names begin with prefix, is available (see Section 3.5.3 [Shell Parameter Expansion], page 19). • Bash has indirect variable expansion using ${ word} (see Section 3.5.3 [Shell Parameter Expansion], page 19). • Bash can expand positional parameters beyond $9 using ${num}. • The POSIX $ O form of command substitution is implemented (see Section 3.5.4 [Com- mand Substitution], page 21), and preferred to the Bourne shell's " (which is also implemented for backwards compatibility). • Bash has process substitution (see Section 3.5.6 [Process Substitution], page 22). • Bash automatically assigns variables that provide information about the current user (UID, EUID, and GROUPS), the current host (HOSTTYPE, OSTYPE, MACHTYPE, and HOSTNAME), and the instance of Bash that is running (BASH, BASH_VERSION, and BASH_VERSINFO). See Section 5.2 [Bash Variables], page 55, for details. • The IFS variable is used to split only the results of expansion, not all words (see Section 3.5.7 [Word Splitting], page 22). This closes a longstanding shell security hole. EFTA00315984
Appendix B: Major Differences From The Bourne Shell 131 • Bash implements the full set of POSIX 1003.2 filename expansion operators, including character classes, equivalence classes, and collating symbols (see Section 3.5.8 [Filename Expansion], page 23). • Bash implements extended pattern matching features when the extglob shell option is enabled (see Section 3.5.8.1 [Pattern Matching], page 23). • It is possible to have a variable and a function with the same name; sh does not separate the two name spaces. • Bash functions are permitted to have local variables using the local builtin, and thus useful recursive functions may be written (see Section 4.2 [Bash Builtins], page 39). • Variable assignments preceding commands affect only that command, even builtins and functions (see Section 3.7.4 [Environment], page 30). In sh, all variable assignments preceding commands are global unless the command is executed from the file system. • Bash performs filename expansion on filenames specified as operands to input and output redirection operators (see Section 3.6 [Redirection], page 25). • Bash contains the '0' redirection operator, allowing a file to be opened for both read- ing and writing, and the 'to' redirection operator, for directing standard output and standard error to the same file (see Section 3.6 [Redirections], page 25). • Bash includes the '<<<' redirection operator, allowing a string to be used as the standard input to a command. • Bash implements the En) <&uord' and ' In) >ttuord' redirection operators, which move one file descriptor to another. • Bash treats a number of filenames specially when they are used in redirection operators (see Section 3.6 [Redirections], page 25). • Bash can open network connections to arbitrary machines and services with the redi- rection operators (see Section 3.6 [Redirection], page 25). • The noclobber option is available to avoid overwriting existing files with output redi- rection (see Section 4.3 [The Set Builtin], page 51). The '>1' redirection operator may be used to override noclobber. • The Bash cd and pwd builtins (see Section 4.1 [Bourne Shell Builtins], page 33) each take `-l; and `-1,' options to switch between logical and physical modes. • Bash allows a function to override a builtin with the same name, and provides access to that builtin's functionality within the function via the builtin and command builtins (see Section 4.2 [Bash Builtins], page 39). • The command builtin allows selective disabling of functions when command lookup is performed (see Section 4.2 [Bash Builtins], page 39). • Individual builtins may be enabled or disabled using the enable builtin (see Section 4.2 [Bash Builtins], page 39). • The Bash exec builtin takes additional options that allow users to control the contents of the environment passed to the executed command, and what the zeroth argument to the command is to be (see Section 4.1 [Bourne Shell Builtins], page 33). • Shell functions may be exported to children via the environment using export -f (see Section 3.3 [Shell Functions], page 14). EFTA00315985
132 Bash Reference Manual • The Bash export, readonly, and declare builtins can take a `-f' option to act on shell functions, a `-p' option to display variables with various attributes set in a format that can be used as shell input, a `-n' option to remove various variable attributes, and `name--value' arguments to set variable attributes and values simultaneously. • The Bash hash builtin allows a name to be associated with an arbitrary filename, even when that filename cannot be found by searching the $PATH, using `hash -p' (see Section 4.1 [Bourne Shell Builtins], page 33). • Bash includes a help builtin for quick reference to shell facilities (see Section 4.2 [Bash Builtins], page 39). • The printf builtin is available to display formatted output (see Section 4.2 [Bash Builtins], page 39). • The Bash read builtin (see Section 4.2 [Bash Builtins], page 39) will read a line ending in`\' with the `-r' option, and will use the REPLY variable as a default if no non-option arguments are supplied. The Bash read builtin also accepts a prompt string with the `-p' option and will use Readline to obtain the line when given the `-e' option. The read builtin also has additional options to control input: the `-s' option will turn off echoing of input characters as they are read, the `-t' option will allow read to time out if input does not arrive within a specified number of seconds, the `-n' option will allow reading only a specified number of characters rather than a full line, and the `-d' option will read until a particular character rather than newline. • The return builtin may be used to abort execution of scripts executed with the . or source builtins (see Section 4.1 [Bourne Shell Builtins], page 33). • Bash includes the shopt builtin, for finer control of shell optional capabilities (see Section 4.2 [Bash Builtins], page 39), and allows these options to be set and unset at shell invocation (see Section 6.1 [Invoking Bash], page 65). • Bash has much more optional behavior controllable with the set builtin (see Section 4.3 [The Set Builtin], page 51). • The `-x' (xtrace) option displays commands other than simple commands when per- forming an execution trace (see Section 4.3 [The Set Builtin], page 51). • The teat builtin (see Section 4.1 [Bourne Shell Builtins], page 33) is slightly different, as it implements the POSIX algorithm, which specifies the behavior based on the number of arguments. • Bash includes the caller builtin, which displays the context of any active subroutine call (a shell function or a script executed with the . or source builtins). This supports the bash debugger. • The trap builtin (see Section 4.1 [Bourne Shell Builtins], page 33) allows a DEBUG pseudo-signal specification, similar to EXIT. Commands specified with a DEBUG trap are executed before every simple command, for command, case command, select command, every arithmetic for command, and before the first command executes in a shell function. The DEBUG trap is not inherited by shell functions unless the function has been given the trace attribute or the f unctrace option has been enabled using the shopt builtin. The extdebug shell option has additional effects on the DEBUG trap. The trap builtin (see Section 4.1 [Bourne Shell Builtins], page 33) allows an ERR pseudo- signal specification, similar to EXIT and DEBUG. Commands specified with an ERR trap EFTA00315986
Appendix B: Major Differences From The Bourne Shell 133 are executed after a simple command fails, with a few exceptions. The ERR trap is not inherited by shell functions unless the -o errtrace option to the set builtin is enabled. The trap builtin (see Section 4.1 [Bourne Shell Builtins], page 33) allows a RETURN pseudo-signal specification, similar to EXIT and DEBUG. Commands specified with an RETURN trap are executed before execution resumes after a shell function or a shell script executed with . or source returns. The RETURN trap is not inherited by shell functions unless the function has been given the trace attribute or the funetrace option has been enabled using the shopt builtin. • The Bash type builtin is more extensive and gives more information about the names it finds (see Section 4.2 [Bash Builtins], page 39). • The Bash umask builtin permits a `-p' option to cause the output to be displayed in the form of a umask command that may be reused as input (see Section 4.1 [Bourne Shell Builtins], page 33). • Bash implements a esh-like directory stack, and provides the pushd, popd, and dirs builtins to manipulate it (see Section 6.8 [The Directory Stack], page 75). Bash also makes the directory stack visible as the value of the DIRSTACK shell variable. • Bash interprets special backslash-escaped characters in the prompt strings when inter- active (see Section 6.9 [Printing a Prompt], page 77). • The Bash restricted mode is more useful (see Section 6.10 [The Restricted Shell], page 78); the SVR4.2 shell restricted mode is too limited. • The disown builtin can remove a job from the internal shell job table (see Section 7.2 [Job Control Builtins], page 84) or suppress the sending of SIGHUP to a job when the shell exits as the result of a SIGHUP. • Bash includes a number of features to support a separate debugger for shell scripts. • The SVR4.2 shell has two privilege-related builtins (mbimode and priv) not present in Bash. • Bash does not have the stop or newgrp builtins. • Bash does not use the SHACCT variable or perform shell accounting. • The SVR4.2 sh uses a TIMEOUT variable like Bash uses TMOUT. More features unique to Bash may be found in Chapter 6 [Bash Features], page 65. B.1 Implementation Differences From The SVR4.2 Shell Since Bash is a completely new implementation, it does not suffer front many of the limitations of the SVR4.2 shell. For instance: • Bash does not fork a subshell when redirecting into or out of a shell control structure such as an if or while statement. • Bash does not allow unbalanced quotes. The SVR4.2 shell will silently insert a needed closing quote at EOF under certain circumstances. This can be the cause of some hard- to-find errors. • The SVR4.2 shell uses a baroque memory management scheme based on trapping SIGSEGV. If the shell is started from a process with SIGSEGV blocked (e.g., by using the system() C library function call), it misbehaves badly. EFTA00315987
134 Bash Reference Manual • In a questionable attempt at security, the SVR4.2 shell, when invoked without the `-p' option, will alter its real and effective MD and Gm if they are less than some magic threshold value, commonly 100. This can lead to unexpected results. • The SVR4.2 shell does not allow users to trap SIGSEGV, SIGALRM, or SIGCHLD. • The SVR4.2 shell does not allow the IFS, MAILCHECK, PATH, PS1, or PS2 variables to be unset. • The SVR4.2 shell treats as the undocumented equivalent of `I'. • Bash allows multiple option arguments when it is invoked (-x -v); the SVR4.2 shell allows only one option argument (-xv). In fact, some versions of the shell dump core if the second argument begins with a • The SVR4.2 shell exits a script if any builtin fails; Bash exits a script only if one of the POSIX 1003.2 special builtins fails, and only for certain failures, as enumerated in the POSIX 1003.2 standard. • The SVR4.2 shell behaves differently when invoked as jab (it turns on job control). EFTA00315988
Appendix C: Copying This Manual 135 Appendix C Copying This Manual C.1 GNU Free Documentation License Version 1.2, November 2002 Copyright C) 2000,2001,2002 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 0. PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document free in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or non- commercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. 1. APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related EFTA00315989
136 Bash Reference Manual matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images com- posed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTEX input format, SCAB, or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNC, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. EFTA00315990
Appendix C: Copying This Manual 137 2. VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. 3. COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. 4. MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: EFTA00315991
138 Bash Reference Manual A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. C. State on the Title page the name of the publisher of the Modified Version, as the publisher. D. Preserve all the copyright notices of the Document. E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. C. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. H. Include an unaltered copy of this License. I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Docu- ment, create one stating the title, year, authors, and publisher of the Docmnent as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. .1. Preserve the network location, if any, given in the Docmnent for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. M. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. 0. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at EFTA00315992
Appendix C: Copying This Manual 139 your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties—for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. 5. COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the vari- ous original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements." 6. COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individu- ally under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. EFTA00315993
140 Bash Reference Manual 7. AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. 8. TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document wider the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "His- tory", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. 9. TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 10. FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License front time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http : //www . gnu . org/copylefti. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. EFTA00315994
Appendix C: Copying This Manual 141 C.1.1 ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (C) year your name. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this: with the Invariant Sections being list their titles, with the Front-Cover Texts being list, and with the Back-Cover Texts being list. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software. EFTA00315995
142 Bash Reference Manual EFTA00315996
Index of Shell Builtin Conunands 143 Index of Shell Builtin Commands H 33 33 hash help history J 35 43 114 jobs 84 37 kill 85 A alias 39 IJ let 43 local 43 B logout 44 bg 84 bind 39 /) break 33 builtin 40 popd printf 76 44 pushd 76 C pwd 36 caller 40 cd 34 R. command 41 read 44 compgen 109 readonly 36 complete 109 return 36 continue 34 S D set 51 declare 41 shift 36 dirs 75 shopt 45 disown 85 source 49 suspend 85 E T echo 42 test 37 enable 43 times 38 eval 34 trap 38 exec 34 type 49 exit 34 typeset 49 export 34 U F ulimit 50 fc 113 umask 38 fg 84 unalias 50 unset 39 getopts 35 wait 85 EFTA00315997
144 Bash Reference Manual EFTA00315998
Index of Shell Reserved Words 145 Index of Shell Reserved Words ! [ 11 8 12 E elif else esac F 10 10 11 fi 10 for 10 1 function 14 3] 12 r 1 if 10 { in 11 4 13 s select 11 13 T then 10 time 8 case " U until 9 D do 9 done 9 while 10 EFTA00315999
146 Bash Reference Manual EFTA00316000
Parameter and Variable Index 147 Parameter and Variable Index bind-tty-special-chars 91 16 C CDPATH 55 16 COLUMNS 57 comment-begin 91 COMP_CWORD 57 COMP_LINE 57 $ 16 COMP POINT 57 COMP_WORDBREAKS 57 COMP WORDS 57 * completion-query-items 91 16 COMPREPLY 58 convert-meta 92 D 16 DIRSTACK 58 disable-completion 92 9 16 E editing-mode 92 EMACS 58 C 16 enable-keypad 92 EUID 58 expand-tilde 92 16 0 FCEDIT FIGNORE 58 58 16 FUNCNAME 58 A auto_resume 86 GLOBIGNORE 58 GROUPS 58 B BASH 55 BASH_ARGC 56 histchars 58 BASH_ARGV 56 HISTCMD 59 BASH COMMAND 56 HISTCONTROL 59 BASH_ENV 56 HISTFILE 59 BASH_EXECUTION_STRING 56 HISTFILESIZE 59 BASH_LINENO 56 HISTIGNORE 59 BASH_REMATCH 56 history-preserve-point 92 BASH_SOURCE 56 HISTSIZE 59 BASH_SUBSHELL 56 HISTTIMEFORMAT 59 BASH_VERSINFO 56 HOME 55 BASH VERSION 57 horizontal-scroll-mode 92 bell-style 91 HOSTFILE 60 EFTA00316001
148 Bash Reference Manual HOSTNAME 60 output-meta 93 HOSTTYPE 60 I P page-completions 93 IFS 55 PATH 55 IGNOREEOF 60 PIPESTATUS 61 input-meta 92 POSITLY_CORRECT 61 INPUTRC 60 PPID 61 isearch-terminators 92 PROMPT_COMMAND 61 PS1 55 PS2 55 PS3 61 keymap 92 PS4 61 PWD 61 LANG 60 LC_ALL 60 RANDOM 61 LC_COLLATE 60 REPLY 61 LC_CTYPE 60 LC_MESSAGES 7,60 S LC_NUMERIC 60 LINENO 60 SECONDS 62 LINES 61 SHELL 62 SHELLOPTS 62 SHLVL 62 Pyl show-all-if-ambiguous 93 MACHTYPE 61 show-all-if-unmodified 93 MAIL 55 MAILCHECK 61 T MAILPATH 55 TEXTDOMAIN 7 mark-modified-lines 93 TEXTDOMAINDIR 7 mark-symlinked-directories 93 TIMEFORMAT 62 match-hidden-files 93 TROUT 62 meta-flag 92 TMPDIR 63 0 OLDPWD 61 UID 63 OPTARC 55 OPTERR 61 OPIIND 55 V OSTYPE 61 visible-stats 94 EFTA00316002
Function Index 149 Function Index A abort (C-g) 105 accept-line (Newlin or Return) alias-expand-line () B 99 107 backward-char (C-b) backward-delete-char (Rubout) 101 backward-kill-line (C-x Rubout) 102 backward-kill-word (M-{DEL)) 102 backward-word (M-b) 99 beginning-of-history (K-<) 100 beginning-of-line (C-a) 99 C 99 call-last-kbd-macro (C-x e) 105 capitalize-word (M-c) 101 character-search (C-]) 105 character-search-backward CM-C-7) 105 clear-screen (C-1) 99 complete ( 103 complete-command (M-I) 104 complete-filename (M-/) 104 complete-hostname (M-0) 104 complete-into-braces (K-{) 104 complete-username (M--) 104 complete-variable (M-$) 104 copy-backward-word () 102 copy-forward-word () 102 copy-region-as-kill () 102 D delete-char (C-d) 101 delete-char-or-list () 104 delete-horizontal-space () 102 digit-argument (M-0, M-a, M--) 103 display-shell-version (C-x C-v) 106 do-uppercase-version (K-a, M-b, M-x, ...) 105 downcase-word (M-1) 101 dump-functions () 106 dump-macros () 106 dump-variables () 106 dynamic-complete-history (M-CrAP) 104 E edit-and-execute-command (C-xC-e) 107 end-kbd-macro (C-x )) 105 end-of-history (M->) 100 end-of-line (C-e) 99 exchange-point-and-mark (C-x C-x) 105 F forward-backward-delete-char () 101 forward-char (C-f) forward-search-history (C-s) 100 99 99 forward-word (M-f) G glob-complete-word (M-g) 106 glob-expand-word (C-xs) 106 glob-list-expansions (C-x g) 106 H history-and-alias-expand-line () 107 history-expand-line (M--) 106 history-search-backward () 100 history-search-forward () 100 I insert-comment (M-#) 106 insert-completions (M-4.) 103 insert-last-argument (M-. or M - ) 107 K kill-line (C-k) 102 kill-region () 102 kill-whole-line () 102 kill-word (K-d) 102 M magic-space () 107 menu-complete () 103 N next-history (C-n) 100 non-incremental-forward-search-history (K-n) 100 non-incremental-reverse-search-history (K-p) 100 EFTA00316003
150 Bash Reference Manual O operate-and-get-next (C-o) 107 overwrite-mode () 101 P possible-command-completions (C-x !) 104 possible-completions (M-?) 103 possible-filename-completions (C-x /) 104 possible -hostname -completions (C -x 4) 104 possible -username -completions (C-x ") 104 possible-variable-completions (C-x S) 104 prefix-meta ((C/) 105 previous-history (C-p) 100 Q quoted-insert (C-q or C-v) 101 R re-read-init-file (C-x C-r) redraw-current-line () reverse-search-history (C-r) revert-line (M-r) S self-insert (a, b, A, 1, I, ) 101 set-mark (C-0) 105 shell-expand-line (M-C-e) 106 start -kbd -macro (C-x () 104 T tilde-expand (14-&) 105 transpose-chars (C-t) 101 transpose-words (M-t) 101 U undo (C-_ or C -x C -u) 105 universal-argument () 103 unix-filename-rubout () 102 unix-line-discard (C-u) 102 unix-word-rubout (C-w) 102 upcase-word (M-u) 101 Y 105 yank (C-y) 103 99 yank-last -arg (M-. or M -_) 100 100 yank-nth -arg (M-C-y) 100 105 yank-pop (6-y) 103 EFTA00316004
Concept Index 151 Concept Index A alias expansion 73 arithmetic evaluation 72 arithmetic expansion 22 arithmetic, shell 72 arrays 74 B FDL, GNU Free Documentation License 135 background 83 field 3 Bash configuration 119 filename 3 Bash installation 119 filename expansion 23 Bourne shell 5 foreground 83 brace expansion 17 functions. shell 14 builtin 3 expansion, parameter 19 expansion, pathname 23 expansion, tilde 18 expressions, arithmetic 72 expressions, conditional 71 F C H command editing 87 history builtins 113 command execution 29 history events 115 command expansion 28 history expansion 115 command history 113 history list 113 command search 29 History, how to use 112 command substitution 21 command timing 8 commands. compound 9 I commands. conditional 10 identifier 3 commands. grouping 13 initialization file, readline 90 commands. lists 9 installation 119 commands, looping 9 interaction. readline 87 commands, pipelines 8 interactive shell 67, 69 commands, shell 8 internationalization 7 commands. simple 8 comments, shell 7 completion builtins 109 J configuration 119 control operator 3 job 3 job control 3, 83 D directory stack 75 E K kill ring killing text 89 89 editing command lines 87 environment 30 L evaluation, arithmetic 72 localization 7 event designators 115 login shell 67 execution environment 29 exit status 3, 31 expansion 17 M expansion, arithmetic 22 expansion, brace 17 matching, pattern 23 expansion, filename 23 metacharacter 3 EFTA00316005
152 N name 3 native languages 7 notation, readline 87 0 operator, shell 3 P parameter expansion 19 parameters IS parameters, positional IS parameters, special 16 patliname expansion 23 pattern matching 23 pipeline 8 POSIX 3 POSIX Mode 78 process group 3 process group ID 3 process substitution 22 programmable completion 107 prompting 77 Q quoting 6 quoting, ANSI 6 NewHine, how to use 86 redirection 25 Bash Reference Manual reserved word 3 restricted shell 78 return status 3 S shell arithmetic 72 shell function 14 shell script 32 shell variable 15 shell, interactive 69 signal 4 signal handling 31 special builtin 4, 54 startup files 67 suspending jobs 83 T tilde expansion token 18 4 translation, native languages 7 variable, shell 15 variables, readline 91 W word 4 word splitting 22 yanking text 89 EFTA00316006


