/usr/bin/bash: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
bash - GNU Bourne-Again SHell | bash - GNU Bourne-Again SHell | ||
SYNOPSIS | == SYNOPSIS == | ||
bash [options] [command_string | file] | bash [options] [command_string | file] | ||
COPYRIGHT | == COPYRIGHT == | ||
Bash is Copyright (C) 1989-2020 by the Free Software Foundation, Inc. | Bash is Copyright (C) 1989-2020 by the Free Software Foundation, Inc. | ||
DESCRIPTION | == DESCRIPTION == | ||
Bash is an sh-compatible command language interpreter that executes commands read from the stan‐ | Bash is an sh-compatible command language interpreter that executes commands read from the stan‐ | ||
dard input or from a file. Bash also incorporates useful features from the Korn and C shells | dard input or from a file. Bash also incorporates useful features from the Korn and C shells | ||
Line 16: | Line 16: | ||
fault. | fault. | ||
OPTIONS | == OPTIONS == | ||
All of the single-character shell options documented in the description of the set builtin com‐ | All of the single-character shell options documented in the description of the set builtin com‐ | ||
mand, including -o, can be used as options when the shell is invoked. In addition, bash inter‐ | mand, including -o, can be used as options when the shell is invoked. In addition, bash inter‐ | ||
Line 95: | Line 95: | ||
cessfully. | cessfully. | ||
ARGUMENTS | == ARGUMENTS == | ||
If arguments remain after option processing, and neither the -c nor the -s option has been sup‐ | If arguments remain after option processing, and neither the -c nor the -s option has been sup‐ | ||
plied, the first argument is assumed to be the name of a file containing shell commands. If bash | plied, the first argument is assumed to be the name of a file containing shell commands. If bash | ||
Line 105: | Line 105: | ||
script. | script. | ||
INVOCATION | == INVOCATION == | ||
A login shell is one whose first character of argument zero is a -, or one started with the --lo‐ | A login shell is one whose first character of argument zero is a -, or one started with the --lo‐ | ||
gin option. | gin option. | ||
Line 170: | Line 170: | ||
not reset. | not reset. | ||
DEFINITIONS | == DEFINITIONS == | ||
The following definitions are used throughout the rest of this document. | The following definitions are used throughout the rest of this document. | ||
blank A space or tab. | blank A space or tab. | ||
Line 183: | Line 183: | ||
|| & && ; ;; ;& ;;& ( ) | |& <newline> | || & && ; ;; ;& ;;& ( ) | |& <newline> | ||
RESERVED WORDS | == RESERVED WORDS == | ||
Reserved words are words that have a special meaning to the shell. The following words are rec‐ | Reserved words are words that have a special meaning to the shell. The following words are rec‐ | ||
ognized as reserved when unquoted and either the first word of a command (see SHELL GRAMMAR be‐ | ognized as reserved when unquoted and either the first word of a command (see SHELL GRAMMAR be‐ | ||
Line 192: | Line 192: | ||
]] | ]] | ||
SHELL GRAMMAR | == SHELL GRAMMAR == | ||
===Simple Commands=== | |||
A simple command is a sequence of optional variable assignments followed by blank-separated words | A simple command is a sequence of optional variable assignments followed by blank-separated words | ||
and redirections, and terminated by a control operator. The first word specifies the command to | and redirections, and terminated by a control operator. The first word specifies the command to | ||
Line 202: | Line 202: | ||
signal n. | signal n. | ||
===Pipelines === | |||
A pipeline is a sequence of one or more commands separated by one of the control operators | or | A pipeline is a sequence of one or more commands separated by one of the control operators | or | ||
|&. The format for a pipeline is: | |&. The format for a pipeline is: | ||
Line 238: | Line 238: | ||
line may be run by the shell process. | line may be run by the shell process. | ||
=== Lists === | |||
A list is a sequence of one or more pipelines separated by one of the operators ;, &, &&, or ||, | A list is a sequence of one or more pipelines separated by one of the operators ;, &, &&, or ||, | ||
and optionally terminated by one of ;, &, or <newline>. | and optionally terminated by one of ;, &, or <newline>. | ||
Line 269: | Line 269: | ||
of AND and OR lists is the exit status of the last command executed in the list. | of AND and OR lists is the exit status of the last command executed in the list. | ||
=== Compound Commands === | |||
A compound command is one of the following. In most cases a list in a command's description may | A compound command is one of the following. In most cases a list in a command's description may | ||
be separated from the rest of the command by one or more newlines, and may be followed by a new‐ | be separated from the rest of the command by one or more newlines, and may be followed by a new‐ | ||
Line 407: | Line 407: | ||
is the exit status of the last command executed in list-2, or zero if none was executed. | is the exit status of the last command executed in list-2, or zero if none was executed. | ||
=== Coprocesses === | |||
A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed | A coprocess is a shell command preceded by the coproc reserved word. A coprocess is executed | ||
asynchronously in a subshell, as if the command had been terminated with the & control operator, | asynchronously in a subshell, as if the command had been terminated with the & control operator, | ||
Line 433: | Line 433: | ||
cess. The return status of a coprocess is the exit status of command. | cess. The return status of a coprocess is the exit status of command. | ||
=== Shell Function Definitions === | |||
A shell function is an object that is called like a simple command and executes a compound com‐ | A shell function is an object that is called like a simple command and executes a compound com‐ | ||
mand with a new set of positional parameters. Shell functions are declared as follows: | mand with a new set of positional parameters. Shell functions are declared as follows: | ||
Line 454: | Line 454: | ||
the body. (See FUNCTIONS below.) | the body. (See FUNCTIONS below.) | ||
COMMENTS | == COMMENTS == | ||
In a non-interactive shell, or an interactive shell in which the interactive_comments option to | In a non-interactive shell, or an interactive shell in which the interactive_comments option to | ||
the shopt builtin is enabled (see SHELL BUILTIN COMMANDS below), a word beginning with # causes | the shopt builtin is enabled (see SHELL BUILTIN COMMANDS below), a word beginning with # causes | ||
Line 461: | Line 461: | ||
is on by default in interactive shells. | is on by default in interactive shells. | ||
QUOTING | == QUOTING == | ||
Quoting is used to remove the special meaning of certain characters or words to the shell. Quot‐ | Quoting is used to remove the special meaning of certain characters or words to the shell. Quot‐ | ||
ing can be used to disable special treatment for special characters, to prevent reserved words | ing can be used to disable special treatment for special characters, to prevent reserved words | ||
Line 528: | Line 528: | ||
the string is translated and replaced, the replacement is double-quoted. | the string is translated and replaced, the replacement is double-quoted. | ||
PARAMETERS | == PARAMETERS == | ||
A parameter is an entity that stores values. It can be a name, a number, or one of the special | A parameter is an entity that stores values. It can be a name, a number, or one of the special | ||
characters listed below under Special Parameters. A variable is a parameter denoted by a name. | characters listed below under Special Parameters. A variable is a parameter denoted by a name. | ||
Line 582: | Line 582: | ||
a nameref variable as an argument, the variable referenced by the nameref variable will be unset. | a nameref variable as an argument, the variable referenced by the nameref variable will be unset. | ||
=== Positional Parameters === | |||
A positional parameter is a parameter denoted by one or more digits, other than the single digit | A positional parameter is a parameter denoted by one or more digits, other than the single digit | ||
0. Positional parameters are assigned from the shell's arguments when it is invoked, and may be | 0. Positional parameters are assigned from the shell's arguments when it is invoked, and may be | ||
Line 592: | Line 592: | ||
closed in braces (see EXPANSION below). | closed in braces (see EXPANSION below). | ||
=== Special Parameters === | |||
The shell treats several parameters specially. These parameters may only be referenced; assign‐ | The shell treats several parameters specially. These parameters may only be referenced; assign‐ | ||
ment to them is not allowed. | ment to them is not allowed. | ||
Line 627: | Line 627: | ||
given by argument zero. | given by argument zero. | ||
=== Shell Variables === | |||
The following variables are set by the shell: | The following variables are set by the shell: | ||
Line 1,122: | Line 1,122: | ||
comment. | comment. | ||
=== Arrays === | |||
Bash provides one-dimensional indexed and associative array variables. Any variable may be used | Bash provides one-dimensional indexed and associative array variables. Any variable may be used | ||
as an indexed array; the declare builtin will explicitly declare an array. There is no maximum | as an indexed array; the declare builtin will explicitly declare an array. There is no maximum | ||
Line 1,203: | Line 1,203: | ||
as assignments. | as assignments. | ||
EXPANSION | == EXPANSION == | ||
Expansion is performed on the command line after it has been split into words. There are seven | Expansion is performed on the command line after it has been split into words. There are seven | ||
kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, | kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, | ||
Line 1,224: | Line 1,224: | ||
plained above (see PARAMETERS). | plained above (see PARAMETERS). | ||
=== Brace Expansion === | |||
Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is | Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is | ||
similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace | similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace | ||
Line 1,270: | Line 1,270: | ||
COMMANDS below). | COMMANDS below). | ||
=== Tilde Expansion === | |||
If a word begins with an unquoted tilde character (`~'), all of the characters preceding the | If a word begins with an unquoted tilde character (`~'), all of the characters preceding the | ||
first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde- | first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde- | ||
Line 1,298: | Line 1,298: | ||
not do this, except for the declaration commands listed above, when in posix mode. | not do this, except for the declaration commands listed above, when in posix mode. | ||
=== Parameter Expansion === | |||
The `$' character introduces parameter expansion, command substitution, or arithmetic expansion. | The `$' character introduces parameter expansion, command substitution, or arithmetic expansion. | ||
The parameter name or symbol to be expanded may be enclosed in braces, which are optional but | The parameter name or symbol to be expanded may be enclosed in braces, which are optional but | ||
Line 1,489: | Line 1,489: | ||
scribed below. | scribed below. | ||
=== Command Substitution === | |||
Command substitution allows the output of a command to replace the command name. There are two | Command substitution allows the output of a command to replace the command name. There are two | ||
forms: | forms: | ||
Line 1,513: | Line 1,513: | ||
performed on the results. | performed on the results. | ||
=== Arithmetic Expansion === | |||
Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of | Arithmetic expansion allows the evaluation of an arithmetic expression and the substitution of | ||
the result. The format for arithmetic expansion is: | the result. The format for arithmetic expansion is: | ||
Line 1,529: | Line 1,529: | ||
expression is invalid, bash prints a message indicating failure and no substitution occurs. | expression is invalid, bash prints a message indicating failure and no substitution occurs. | ||
=== Process Substitution === | |||
Process substitution allows a process's input or output to be referred to using a filename. It | Process substitution allows a process's input or output to be referred to using a filename. It | ||
takes the form of <(list) or >(list). The process list is run asynchronously, and its input or | takes the form of <(list) or >(list). The process list is run asynchronously, and its input or | ||
Line 1,541: | Line 1,541: | ||
pansion, command substitution, and arithmetic expansion. | pansion, command substitution, and arithmetic expansion. | ||
=== Word Splitting === | |||
The shell scans the results of parameter expansion, command substitution, and arithmetic expan‐ | The shell scans the results of parameter expansion, command substitution, and arithmetic expan‐ | ||
sion that did not occur within double quotes for word splitting. | sion that did not occur within double quotes for word splitting. | ||
Line 1,565: | Line 1,565: | ||
Note that if no expansion occurs, no splitting is performed. | Note that if no expansion occurs, no splitting is performed. | ||
=== Pathname Expansion === | |||
After word splitting, unless the -f option has been set, bash scans each word for the characters | After word splitting, unless the -f option has been set, bash scans each word for the characters | ||
*, ?, and [. If one of these characters appears, and is not quoted, then the word is regarded as | *, ?, and [. If one of these characters appears, and is not quoted, then the word is regarded as | ||
Line 1,595: | Line 1,595: | ||
set. The pattern matching honors the setting of the extglob shell option. | set. The pattern matching honors the setting of the extglob shell option. | ||
=== Pattern Matching === | |||
Any character that appears in a pattern, other than the special pattern characters described be‐ | Any character that appears in a pattern, other than the special pattern characters described be‐ | ||
Line 1,654: | Line 1,654: | ||
shorter strings, or using arrays of strings instead of a single long string, may be faster. | shorter strings, or using arrays of strings instead of a single long string, may be faster. | ||
=== Quote Removal === | |||
After the preceding expansions, all unquoted occurrences of the characters \, ', and " that did | After the preceding expansions, all unquoted occurrences of the characters \, ', and " that did | ||
not result from one of the above expansions are removed. | not result from one of the above expansions are removed. | ||
REDIRECTION | == REDIRECTION == | ||
Before a command is executed, its input and output may be redirected using a special notation in‐ | Before a command is executed, its input and output may be redirected using a special notation in‐ | ||
terpreted by the shell. Redirection allows commands' file handles to be duplicated, opened, | terpreted by the shell. Redirection allows commands' file handles to be duplicated, opened, | ||
Line 1,721: | Line 1,721: | ||
Note that the exec builtin command can make redirections take effect in the current shell. | Note that the exec builtin command can make redirections take effect in the current shell. | ||
=== Redirecting Input === | |||
Redirection of input causes the file whose name results from the expansion of word to be opened | Redirection of input causes the file whose name results from the expansion of word to be opened | ||
for reading on file descriptor n, or the standard input (file descriptor 0) if n is not speci‐ | for reading on file descriptor n, or the standard input (file descriptor 0) if n is not speci‐ | ||
Line 1,730: | Line 1,730: | ||
[n]<word | [n]<word | ||
=== Redirecting Output === | |||
Redirection of output causes the file whose name results from the expansion of word to be opened | Redirection of output causes the file whose name results from the expansion of word to be opened | ||
for writing on file descriptor n, or the standard output (file descriptor 1) if n is not speci‐ | for writing on file descriptor n, or the standard output (file descriptor 1) if n is not speci‐ | ||
Line 1,745: | Line 1,745: | ||
the file named by word exists. | the file named by word exists. | ||
=== Appending Redirected Output === | |||
Redirection of output in this fashion causes the file whose name results from the expansion of | Redirection of output in this fashion causes the file whose name results from the expansion of | ||
word to be opened for appending on file descriptor n, or the standard output (file descriptor 1) | word to be opened for appending on file descriptor n, or the standard output (file descriptor 1) | ||
Line 1,754: | Line 1,754: | ||
[n]>>word | [n]>>word | ||
=== Redirecting Standard Output and Standard Error === | |||
This construct allows both the standard output (file descriptor 1) and the standard error output | This construct allows both the standard output (file descriptor 1) and the standard error output | ||
(file descriptor 2) to be redirected to the file whose name is the expansion of word. | (file descriptor 2) to be redirected to the file whose name is the expansion of word. | ||
Line 1,771: | Line 1,771: | ||
operators apply (see Duplicating File Descriptors below) for compatibility reasons. | operators apply (see Duplicating File Descriptors below) for compatibility reasons. | ||
=== Appending Standard Output and Standard Error === | |||
This construct allows both the standard output (file descriptor 1) and the standard error output | This construct allows both the standard output (file descriptor 1) and the standard error output | ||
(file descriptor 2) to be appended to the file whose name is the expansion of word. | (file descriptor 2) to be appended to the file whose name is the expansion of word. | ||
Line 1,785: | Line 1,785: | ||
(see Duplicating File Descriptors below). | (see Duplicating File Descriptors below). | ||
=== Here Documents === | |||
This type of redirection instructs the shell to read input from the current source until a line | This type of redirection instructs the shell to read input from the current source until a line | ||
containing only delimiter (with no trailing blanks) is seen. All of the lines read up to that | containing only delimiter (with no trailing blanks) is seen. All of the lines read up to that | ||
Line 1,807: | Line 1,807: | ||
dented in a natural fashion. | dented in a natural fashion. | ||
=== Here Strings === | |||
A variant of here documents, the format is: | A variant of here documents, the format is: | ||
Line 1,817: | Line 1,817: | ||
its standard input (or file descriptor n if n is specified). | its standard input (or file descriptor n if n is specified). | ||
=== Duplicating File Descriptors === | |||
The redirection operator | The redirection operator | ||
Line 1,838: | Line 1,838: | ||
output and standard error are redirected as described previously. | output and standard error are redirected as described previously. | ||
=== Moving File Descriptors === | |||
The redirection operator | The redirection operator | ||
Line 1,853: | Line 1,853: | ||
if n is not specified. | if n is not specified. | ||
=== Opening File Descriptors for Reading and Writing === | |||
The redirection operator | The redirection operator | ||
Line 1,862: | Line 1,862: | ||
is created. | is created. | ||
ALIASES | == ALIASES == | ||
Aliases allow a string to be substituted for a word when it is used as the first word of a simple | Aliases allow a string to be substituted for a word when it is used as the first word of a simple | ||
command. The shell maintains a list of aliases that may be set and unset with the alias and una‐ | command. The shell maintains a list of aliases that may be set and unset with the alias and una‐ | ||
Line 1,897: | Line 1,897: | ||
For almost every purpose, aliases are superseded by shell functions. | For almost every purpose, aliases are superseded by shell functions. | ||
FUNCTIONS | == FUNCTIONS == | ||
A shell function, defined as described above under SHELL GRAMMAR, stores a series of commands for | A shell function, defined as described above under SHELL GRAMMAR, stores a series of commands for | ||
later execution. When the name of a shell function is used as a simple command name, the list of | later execution. When the name of a shell function is used as a simple command name, the list of | ||
Line 1,961: | Line 1,961: | ||
the number of recursive calls. | the number of recursive calls. | ||
ARITHMETIC EVALUATION | == ARITHMETIC EVALUATION == | ||
The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let | The shell allows arithmetic expressions to be evaluated, under certain circumstances (see the let | ||
and declare builtin commands, the (( compound command, and Arithmetic Expansion). Evaluation is | and declare builtin commands, the (( compound command, and Arithmetic Expansion). Evaluation is | ||
Line 2,014: | Line 2,014: | ||
first and may override the precedence rules above. | first and may override the precedence rules above. | ||
CONDITIONAL EXPRESSIONS | == CONDITIONAL EXPRESSIONS == | ||
Conditional expressions are used by the [[ compound command and the test and [ builtin commands | Conditional expressions are used by the [[ compound command and the test and [ builtin commands | ||
to test file attributes and perform string and arithmetic comparisons. The test and [ commands | to test file attributes and perform string and arithmetic comparisons. The test and [ commands | ||
Line 2,116: | Line 2,116: | ||
pressions (see ARITHMETIC EVALUATION above). | pressions (see ARITHMETIC EVALUATION above). | ||
SIMPLE COMMAND EXPANSION | == SIMPLE COMMAND EXPANSION == | ||
When a simple command is executed, the shell performs the following expansions, assignments, and | When a simple command is executed, the shell performs the following expansions, assignments, and | ||
redirections, from left to right, in the following order. | redirections, from left to right, in the following order. | ||
Line 2,146: | Line 2,146: | ||
were no command substitutions, the command exits with a status of zero. | were no command substitutions, the command exits with a status of zero. | ||
COMMAND EXECUTION | == COMMAND EXECUTION == | ||
After a command has been split into words, if it results in a simple command and an optional list | After a command has been split into words, if it results in a simple command and an optional list | ||
of arguments, the following actions are taken. | of arguments, the following actions are taken. | ||
Line 2,181: | Line 2,181: | ||
lowed by the name of the program, followed by the command arguments, if any. | lowed by the name of the program, followed by the command arguments, if any. | ||
COMMAND EXECUTION ENVIRONMENT | == COMMAND EXECUTION ENVIRONMENT == | ||
The shell has an execution environment, which consists of the following: | The shell has an execution environment, which consists of the following: | ||
Line 2,241: | Line 2,241: | ||
tors of the calling shell as modified by redirections. | tors of the calling shell as modified by redirections. | ||
ENVIRONMENT | == ENVIRONMENT == | ||
When a program is invoked it is given an array of strings called the environment. This is a list | When a program is invoked it is given an array of strings called the environment. This is a list | ||
of name-value pairs, of the form name=value. | of name-value pairs, of the form name=value. | ||
Line 2,264: | Line 2,264: | ||
and passed to that command in its environment. | and passed to that command in its environment. | ||
EXIT STATUS | == EXIT STATUS == | ||
The exit status of an executed command is the value returned by the waitpid system call or equiv‐ | The exit status of an executed command is the value returned by the waitpid system call or equiv‐ | ||
alent function. Exit statuses fall between 0 and 255, though, as explained below, the shell may | alent function. Exit statuses fall between 0 and 255, though, as explained below, the shell may | ||
Line 2,288: | Line 2,288: | ||
in which case it exits with a non-zero value. See also the exit builtin command below. | in which case it exits with a non-zero value. See also the exit builtin command below. | ||
SIGNALS | == SIGNALS == | ||
When bash is interactive, in the absence of any traps, it ignores SIGTERM (so that kill 0 does | When bash is interactive, in the absence of any traps, it ignores SIGTERM (so that kill 0 does | ||
not kill an interactive shell), and SIGINT is caught and handled (so that the wait builtin is in‐ | not kill an interactive shell), and SIGINT is caught and handled (so that the wait builtin is in‐ | ||
Line 2,314: | Line 2,314: | ||
after which the trap is executed. | after which the trap is executed. | ||
JOB CONTROL | == JOB CONTROL == | ||
Job control refers to the ability to selectively stop (suspend) the execution of processes and | Job control refers to the ability to selectively stop (suspend) the execution of processes and | ||
continue (resume) their execution at a later point. A user typically employs this facility via | continue (resume) their execution at a later point. A user typically employs this facility via | ||
Line 2,381: | Line 2,381: | ||
job or process terminates before returning. | job or process terminates before returning. | ||
PROMPTING | == PROMPTING == | ||
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a | When executing interactively, bash displays the primary prompt PS1 when it is ready to read a | ||
command, and the secondary prompt PS2 when it needs more input to complete a command. Bash dis‐ | command, and the secondary prompt PS2 when it needs more input to complete a command. Bash dis‐ | ||
Line 2,430: | Line 2,430: | ||
appear within command substitution or contain characters special to word expansion. | appear within command substitution or contain characters special to word expansion. | ||
READLINE | == READLINE == | ||
This is the library that handles reading input when using an interactive shell, unless the | This is the library that handles reading input when using an interactive shell, unless the | ||
--noediting option is given at shell invocation. Line editing is also used when using the -e op‐ | --noediting option is given at shell invocation. Line editing is also used when using the -e op‐ | ||
Line 2,439: | Line 2,439: | ||
builtin. | builtin. | ||
=== Readline Notation === | |||
In this section, the Emacs-style notation is used to denote keystrokes. Control keys are denoted | In this section, the Emacs-style notation is used to denote keystrokes. Control keys are denoted | ||
by C-key, e.g., C-n means Control-N. Similarly, meta keys are denoted by M-key, so M-x means | by C-key, e.g., C-n means Control-N. Similarly, meta keys are denoted by M-key, so M-x means | ||
Line 2,456: | Line 2,456: | ||
separate the chunks of text on the kill ring. | separate the chunks of text on the kill ring. | ||
=== Readline Initialization === | |||
Readline is customized by putting commands in an initialization file (the inputrc file). The | Readline is customized by putting commands in an initialization file (the inputrc file). The | ||
name of this file is taken from the value of the INPUTRC variable. If that variable is unset, | name of this file is taken from the value of the INPUTRC variable. If that variable is unset, | ||
Line 2,482: | Line 2,482: | ||
the key is pressed (a macro). | the key is pressed (a macro). | ||
=== Readline Key Bindings === | |||
The syntax for controlling key bindings in the inputrc file is simple. All that is required is | The syntax for controlling key bindings in the inputrc file is simple. All that is required is | ||
the name of the command or the text of a macro and a key sequence to which it should be bound. | the name of the command or the text of a macro and a key sequence to which it should be bound. | ||
Line 2,542: | Line 2,542: | ||
set builtin command (see SHELL BUILTIN COMMANDS below). | set builtin command (see SHELL BUILTIN COMMANDS below). | ||
=== Readline Variables === | |||
Readline has variables that can be used to further customize its behavior. A variable may be set | Readline has variables that can be used to further customize its behavior. A variable may be set | ||
in the inputrc file with a statement of the form | in the inputrc file with a statement of the form | ||
Line 2,734: | Line 2,734: | ||
filename when listing possible completions. | filename when listing possible completions. | ||
=== Readline Conditional Constructs === | |||
Readline implements a facility similar in spirit to the conditional compilation features of the C | 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 | preprocessor which allows key bindings and variable settings to be performed as the result of | ||
Line 2,795: | Line 2,795: | ||
$include /etc/inputrc | $include /etc/inputrc | ||
=== Searching === | |||
Readline provides commands for searching through the command history (see HISTORY below) for | Readline provides commands for searching through the command history (see HISTORY below) for | ||
lines containing a specified string. There are two search modes: incremental and non-incremen‐ | lines containing a specified string. There are two search modes: incremental and non-incremen‐ | ||
Line 2,822: | Line 2,822: | ||
rent line. | rent line. | ||
=== Readline Command Names === | |||
The following is a list of the names of the commands and the default key sequences to which they | The following is a list of the names of the commands and the default key sequences to which they | ||
are bound. Command names without an accompanying key sequence are unbound by default. In the | are bound. Command names without an accompanying key sequence are unbound by default. In the | ||
Line 2,869: | Line 2,869: | ||
Refresh the current line. | Refresh the current line. | ||
=== Commands for Manipulating the History === | |||
accept-line (Newline, Return) | accept-line (Newline, Return) | ||
Accept the line regardless of where the cursor is. If this line is non-empty, add it to | Accept the line regardless of where the cursor is. If this line is non-empty, add it to | ||
Line 2,948: | Line 2,948: | ||
Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order. | Bash attempts to invoke $VISUAL, $EDITOR, and emacs as the editor, in that order. | ||
=== Commands for Changing Text === | |||
end-of-file (usually C-d) | end-of-file (usually C-d) | ||
The character indicating end-of-file as set, for example, by ``stty''. If this character | The character indicating end-of-file as set, for example, by ``stty''. If this character | ||
Line 2,994: | Line 2,994: | ||
mand is unbound. | mand is unbound. | ||
=== Killing and Yanking === | |||
kill-line (C-k) | kill-line (C-k) | ||
Kill the text from point to the end of the line. | Kill the text from point to the end of the line. | ||
Line 3,038: | Line 3,038: | ||
Rotate the kill ring, and yank the new top. Only works following yank or yank-pop. | Rotate the kill ring, and yank the new top. Only works following yank or yank-pop. | ||
=== Numeric Arguments === | |||
digit-argument (M-0, M-1, ..., M--) | digit-argument (M-0, M-1, ..., M--) | ||
Add this digit to the argument already accumulating, or start a new argument. M-- starts | Add this digit to the argument already accumulating, or start a new argument. M-- starts | ||
Line 3,052: | Line 3,052: | ||
ment count sixteen, and so on. | ment count sixteen, and so on. | ||
=== Completing === | |||
complete (TAB) | complete (TAB) | ||
Attempt to perform completion on the text before point. Bash attempts completion treating | Attempt to perform completion on the text before point. Bash attempts completion treating | ||
Line 3,111: | Line 3,111: | ||
braces so the list is available to the shell (see Brace Expansion above). | braces so the list is available to the shell (see Brace Expansion above). | ||
=== Keyboard Macros === | |||
start-kbd-macro (C-x () | start-kbd-macro (C-x () | ||
Begin saving the characters typed into the current keyboard macro. | Begin saving the characters typed into the current keyboard macro. | ||
Line 3,122: | Line 3,122: | ||
Print the last keyboard macro defined in a format suitable for the inputrc file. | Print the last keyboard macro defined in a format suitable for the inputrc file. | ||
=== Miscellaneous === | |||
re-read-init-file (C-x C-r) | re-read-init-file (C-x C-r) | ||
Read in the contents of the inputrc file, and incorporate any bindings or variable assign‐ | Read in the contents of the inputrc file, and incorporate any bindings or variable assign‐ | ||
Line 3,195: | Line 3,195: | ||
Display version information about the current instance of bash. | Display version information about the current instance of bash. | ||
=== Programmable Completion === | |||
When word completion is attempted for an argument to a command for which a completion specifica‐ | When word completion is attempted for an argument to a command for which a completion specifica‐ | ||
tion (a compspec) has been defined using the complete builtin (see SHELL BUILTIN COMMANDS below), | tion (a compspec) has been defined using the complete builtin (see SHELL BUILTIN COMMANDS below), | ||
Line 3,297: | Line 3,297: | ||
complete -D -F _completion_loader -o bashdefault -o default | complete -D -F _completion_loader -o bashdefault -o default | ||
HISTORY | == HISTORY == | ||
When the -o history option to the set builtin is enabled, the shell provides access to the com‐ | When the -o history option to the set builtin is enabled, the shell provides access to the com‐ | ||
mand history, the list of commands previously typed. The value of the HISTSIZE variable is used | mand history, the list of commands previously typed. The value of the HISTSIZE variable is used | ||
Line 3,336: | Line 3,336: | ||
COMMANDS for information on setting and unsetting shell options. | COMMANDS for information on setting and unsetting shell options. | ||
HISTORY EXPANSION | == HISTORY EXPANSION == | ||
The shell supports a history expansion feature that is similar to the history expansion in csh. | The shell supports a history expansion feature that is similar to the history expansion in csh. | ||
This section describes what syntax features are available. This feature is enabled by default | This section describes what syntax features are available. This feature is enabled by default | ||
Line 3,379: | Line 3,379: | ||
character to mark history timestamps when writing the history file. | character to mark history timestamps when writing the history file. | ||
=== Event Designators === | |||
An event designator is a reference to a command line entry in the history list. Unless the ref‐ | An event designator is a reference to a command line entry in the history list. Unless the ref‐ | ||
erence is absolute, events are relative to the current position in the history list. | erence is absolute, events are relative to the current position in the history list. | ||
Line 3,401: | Line 3,401: | ||
!# The entire command line typed so far. | !# The entire command line typed so far. | ||
=== Word Designators === | |||
Word designators are used to select desired words from the event. A : separates the event speci‐ | Word designators are used to select desired words from the event. A : separates the event speci‐ | ||
fication from the word designator. It may be omitted if the word designator begins with a ^, $, | fication from the word designator. It may be omitted if the word designator begins with a ^, $, | ||
Line 3,424: | Line 3,424: | ||
the event. | the event. | ||
=== Modifiers === | |||
After the optional word designator, there may appear a sequence of one or more of the following | After the optional word designator, there may appear a sequence of one or more of the following | ||
modifiers, each preceded by a `:'. These modify, or edit, the word or words selected from the | modifiers, each preceded by a `:'. These modify, or edit, the word or words selected from the | ||
Line 3,452: | Line 3,452: | ||
G Apply the following `s' or `&' modifier once to each word in the event line. | G Apply the following `s' or `&' modifier once to each word in the event line. | ||
SHELL BUILTIN COMMANDS | == SHELL BUILTIN COMMANDS == | ||
Unless otherwise noted, each builtin command documented in this section as accepting options pre‐ | Unless otherwise noted, each builtin command documented in this section as accepting options pre‐ | ||
ceded by - accepts -- to signify the end of the options. The :, true, false, and test/[ builtins | ceded by - accepts -- to signify the end of the options. The :, true, false, and test/[ builtins | ||
Line 4,916: | Line 4,916: | ||
turn status is the exit status of the last process or job waited for. | turn status is the exit status of the last process or job waited for. | ||
SHELL COMPATIBILITY MODE | == SHELL COMPATIBILITY MODE == | ||
Bash-4.0 introduced the concept of a `shell compatibility level', specified as a set of options | Bash-4.0 introduced the concept of a `shell compatibility level', specified as a set of options | ||
to the shopt builtin compat31, compat32, compat40, compat41, and so on). There is only one cur‐ | to the shopt builtin compat31, compat32, compat40, compat41, and so on). There is only one cur‐ | ||
Line 5,014: | Line 5,014: | ||
as input. Bash-5.1 suppresses that message when the -l option is supplied. | as input. Bash-5.1 suppresses that message when the -l option is supplied. | ||
RESTRICTED SHELL | == RESTRICTED SHELL == | ||
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell be‐ | If bash is started with the name rbash, or the -r option is supplied at invocation, the shell be‐ | ||
comes restricted. A restricted shell is used to set up an environment more controlled than the | comes restricted. A restricted shell is used to set up an environment more controlled than the | ||
Line 5,055: | Line 5,055: | ||
rbash turns off any restrictions in the shell spawned to execute the script. | rbash turns off any restrictions in the shell spawned to execute the script. | ||
SEE ALSO | == SEE ALSO == | ||
Bash Reference Manual, Brian Fox and Chet Ramey | Bash Reference Manual, Brian Fox and Chet Ramey | ||
The Gnu Readline Library, Brian Fox and Chet Ramey | The Gnu Readline Library, Brian Fox and Chet Ramey | ||
Line 5,066: | Line 5,066: | ||
readline(3) | readline(3) | ||
FILES | == FILES == | ||
/bin/bash | /bin/bash | ||
The bash executable | The bash executable | ||
Line 5,084: | Line 5,084: | ||
Individual readline initialization file | Individual readline initialization file | ||
AUTHORS | == AUTHORS == | ||
Brian Fox, Free Software Foundation | Brian Fox, Free Software Foundation | ||
bfox@gnu.org | bfox@gnu.org | ||
Line 5,091: | Line 5,091: | ||
chet.ramey@case.edu | chet.ramey@case.edu | ||
BUG REPORTS | == BUG REPORTS == | ||
If you find a bug in bash, you should report it. But first, you should make sure that it really | If you find a bug in bash, you should report it. 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 is always avail‐ | is a bug, and that it appears in the latest version of bash. The latest version is always avail‐ | ||
Line 5,114: | Line 5,114: | ||
Comments and bug reports concerning this manual page should be directed to chet.ramey@case.edu. | Comments and bug reports concerning this manual page should be directed to chet.ramey@case.edu. | ||
BUGS | == BUGS == | ||
It's too big and too slow. | It's too big and too slow. | ||