1BASH(1) General Commands Manual BASH(1)
2
3
4
6 bash - GNU Bourne-Again SHell
7
9 bash [options] [command_string | file]
10
12 Bash is Copyright (C) 1989-2018 by the Free Software Foundation, Inc.
13
15 Bash is an sh-compatible command language interpreter that executes
16 commands read from the standard input or from a file. Bash also incor‐
17 porates useful features from the Korn and C shells (ksh and csh).
18
19 Bash is intended to be a conformant implementation of the Shell and
20 Utilities portion of the IEEE POSIX specification (IEEE Standard
21 1003.1). Bash can be configured to be POSIX-conformant by default.
22
24 All of the single-character shell options documented in the description
25 of the set builtin command, including -o, can be used as options when
26 the shell is invoked. In addition, bash interprets the following
27 options when it is invoked:
28
29 -c If the -c option is present, then commands are read from the
30 first non-option argument command_string. If there are argu‐
31 ments after the command_string, the first argument is
32 assigned to $0 and any remaining arguments are assigned to
33 the positional parameters. The assignment to $0 sets the
34 name of the shell, which is used in warning and error mes‐
35 sages.
36 -i If the -i option is present, the shell is interactive.
37 -l Make bash act as if it had been invoked as a login shell (see
38 INVOCATION below).
39 -r If the -r option is present, the shell becomes restricted
40 (see RESTRICTED SHELL below).
41 -s If the -s option is present, or if no arguments remain after
42 option processing, then commands are read from the standard
43 input. This option allows the positional parameters to be
44 set when invoking an interactive shell or when reading input
45 through a pipe.
46 -D A list of all double-quoted strings preceded by $ is printed
47 on the standard output. These are the strings that are sub‐
48 ject to language translation when the current locale is not C
49 or POSIX. This implies the -n option; no commands will be
50 executed.
51 [-+]O [shopt_option]
52 shopt_option is one of the shell options accepted by the
53 shopt builtin (see SHELL BUILTIN COMMANDS below). If
54 shopt_option is present, -O sets the value of that option; +O
55 unsets it. If shopt_option is not supplied, the names and
56 values of the shell options accepted by shopt are printed on
57 the standard output. If the invocation option is +O, the
58 output is displayed in a format that may be reused as input.
59 -- A -- signals the end of options and disables further option
60 processing. Any arguments after the -- are treated as file‐
61 names and arguments. An argument of - is equivalent to --.
62
63 Bash also interprets a number of multi-character options. These
64 options must appear on the command line before the single-character
65 options to be recognized.
66
67 --debugger
68 Arrange for the debugger profile to be executed before the shell
69 starts. Turns on extended debugging mode (see the description
70 of the extdebug option to the shopt builtin below).
71 --dump-po-strings
72 Equivalent to -D, but the output is in the GNU gettext po (por‐
73 table object) file format.
74 --dump-strings
75 Equivalent to -D.
76 --help Display a usage message on standard output and exit success‐
77 fully.
78 --init-file file
79 --rcfile file
80 Execute commands from file instead of the standard personal ini‐
81 tialization file ~/.bashrc if the shell is interactive (see
82 INVOCATION below).
83
84 --login
85 Equivalent to -l.
86
87 --noediting
88 Do not use the GNU readline library to read command lines when
89 the shell is interactive.
90
91 --noprofile
92 Do not read either the system-wide startup file /etc/profile or
93 any of the personal initialization files ~/.bash_profile,
94 ~/.bash_login, or ~/.profile. By default, bash reads these
95 files when it is invoked as a login shell (see INVOCATION
96 below).
97
98 --norc Do not read and execute the personal initialization file
99 ~/.bashrc if the shell is interactive. This option is on by
100 default if the shell is invoked as sh.
101
102 --posix
103 Change the behavior of bash where the default operation differs
104 from the POSIX standard to match the standard (posix mode). See
105 SEE ALSO below for a reference to a document that details how
106 posix mode affects bash's behavior.
107
108 --restricted
109 The shell becomes restricted (see RESTRICTED SHELL below).
110
111 --rpm-requires
112 Produce the list of files that are required for the shell script
113 to run. This implies '-n' and is subject to the same limita‐
114 tions as compile time error checking checking; Command substitu‐
115 tions, Conditional expressions and eval builtin are not parsed
116 so some dependencies may be missed.
117
118 --verbose
119 Equivalent to -v.
120
121 --version
122 Show version information for this instance of bash on the stan‐
123 dard output and exit successfully.
124
126 If arguments remain after option processing, and neither the -c nor the
127 -s option has been supplied, the first argument is assumed to be the
128 name of a file containing shell commands. If bash is invoked in this
129 fashion, $0 is set to the name of the file, and the positional parame‐
130 ters are set to the remaining arguments. Bash reads and executes com‐
131 mands from this file, then exits. Bash's exit status is the exit sta‐
132 tus of the last command executed in the script. If no commands are
133 executed, the exit status is 0. An attempt is first made to open the
134 file in the current directory, and, if no file is found, then the shell
135 searches the directories in PATH for the script.
136
138 A login shell is one whose first character of argument zero is a -, or
139 one started with the --login option.
140
141 An interactive shell is one started without non-option arguments
142 (unless -s is specified) and without the -c option whose standard input
143 and error are both connected to terminals (as determined by isatty(3)),
144 or one started with the -i option. PS1 is set and $- includes i if
145 bash is interactive, allowing a shell script or a startup file to test
146 this state.
147
148 The following paragraphs describe how bash executes its startup files.
149 If any of the files exist but cannot be read, bash reports an error.
150 Tildes are expanded in filenames as described below under Tilde Expan‐
151 sion in the EXPANSION section.
152
153 When bash is invoked as an interactive login shell, or as a non-inter‐
154 active shell with the --login option, it first reads and executes com‐
155 mands from the file /etc/profile, if that file exists. After reading
156 that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
157 in that order, and reads and executes commands from the first one that
158 exists and is readable. The --noprofile option may be used when the
159 shell is started to inhibit this behavior.
160
161 When an interactive login shell exits, or a non-interactive login shell
162 executes the exit builtin command, bash reads and executes commands
163 from the files ~/.bash_logout and /etc/bash.bash_logout, if the files
164 exists.
165
166 When an interactive shell that is not a login shell is started, bash
167 reads and executes commands from ~/.bashrc, if that file exists. This
168 may be inhibited by using the --norc option. The --rcfile file option
169 will force bash to read and execute commands from file instead of
170 ~/.bashrc.
171
172 When bash is started non-interactively, to run a shell script, for
173 example, it looks for the variable BASH_ENV in the environment, expands
174 its value if it appears there, and uses the expanded value as the name
175 of a file to read and execute. Bash behaves as if the following com‐
176 mand were executed:
177 if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
178 but the value of the PATH variable is not used to search for the file‐
179 name.
180
181 If bash is invoked with the name sh, it tries to mimic the startup
182 behavior of historical versions of sh as closely as possible, while
183 conforming to the POSIX standard as well. When invoked as an interac‐
184 tive login shell, or a non-interactive shell with the --login option,
185 it first attempts to read and execute commands from /etc/profile and
186 ~/.profile, in that order. The --noprofile option may be used to
187 inhibit this behavior. When invoked as an interactive shell with the
188 name sh, bash looks for the variable ENV, expands its value if it is
189 defined, and uses the expanded value as the name of a file to read and
190 execute. Since a shell invoked as sh does not attempt to read and exe‐
191 cute commands from any other startup files, the --rcfile option has no
192 effect. A non-interactive shell invoked with the name sh does not
193 attempt to read any other startup files. When invoked as sh, bash
194 enters posix mode after the startup files are read.
195
196 When bash is started in posix mode, as with the --posix command line
197 option, it follows the POSIX standard for startup files. In this mode,
198 interactive shells expand the ENV variable and commands are read and
199 executed from the file whose name is the expanded value. No other
200 startup files are read.
201
202 Bash attempts to determine when it is being run with its standard input
203 connected to a network connection, as when executed by the remote shell
204 daemon, usually rshd, or the secure shell daemon sshd. If bash deter‐
205 mines it is being run in this fashion, it reads and executes commands
206 from ~/.bashrc, if that file exists and is readable. It will not do
207 this if invoked as sh. The --norc option may be used to inhibit this
208 behavior, and the --rcfile option may be used to force another file to
209 be read, but neither rshd nor sshd generally invoke the shell with
210 those options or allow them to be specified.
211
212 If the shell is started with the effective user (group) id not equal to
213 the real user (group) id, and the -p option is not supplied, no startup
214 files are read, shell functions are not inherited from the environment,
215 the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they
216 appear in the environment, are ignored, and the effective user id is
217 set to the real user id. If the -p option is supplied at invocation,
218 the startup behavior is the same, but the effective user id is not
219 reset.
220
222 The following definitions are used throughout the rest of this docu‐
223 ment.
224 blank A space or tab.
225 word A sequence of characters considered as a single unit by the
226 shell. Also known as a token.
227 name A word consisting only of alphanumeric characters and under‐
228 scores, and beginning with an alphabetic character or an under‐
229 score. Also referred to as an identifier.
230 metacharacter
231 A character that, when unquoted, separates words. One of the
232 following:
233 | & ; ( ) < > space tab newline
234 control operator
235 A token that performs a control function. It is one of the fol‐
236 lowing symbols:
237 || & && ; ;; ;& ;;& ( ) | |& <newline>
238
240 Reserved words are words that have a special meaning to the shell. The
241 following words are recognized as reserved when unquoted and either the
242 first word of a simple command (see SHELL GRAMMAR below) or the third
243 word of a case or for command:
244
245 ! case coproc do done elif else esac fi for function if in select
246 then until while { } time [[ ]]
247
249 Simple Commands
250 A simple command is a sequence of optional variable assignments fol‐
251 lowed by blank-separated words and redirections, and terminated by a
252 control operator. The first word specifies the command to be executed,
253 and is passed as argument zero. The remaining words are passed as
254 arguments to the invoked command.
255
256 The return value of a simple command is its exit status, or 128+n if
257 the command is terminated by signal n.
258
259 Pipelines
260 A pipeline is a sequence of one or more commands separated by one of
261 the control operators | or |&. The format for a pipeline is:
262
263 [time [-p]] [ ! ] command [ [|⎪|&] command2 ... ]
264
265 The standard output of command is connected via a pipe to the standard
266 input of command2. This connection is performed before any redirec‐
267 tions specified by the command (see REDIRECTION below). If |& is used,
268 command's standard error, in addition to its standard output, is con‐
269 nected to command2's standard input through the pipe; it is shorthand
270 for 2>&1 |. This implicit redirection of the standard error to the
271 standard output is performed after any redirections specified by the
272 command.
273
274 The return status of a pipeline is the exit status of the last command,
275 unless the pipefail option is enabled. If pipefail is enabled, the
276 pipeline's return status is the value of the last (rightmost) command
277 to exit with a non-zero status, or zero if all commands exit success‐
278 fully. If the reserved word ! precedes a pipeline, the exit status of
279 that pipeline is the logical negation of the exit status as described
280 above. The shell waits for all commands in the pipeline to terminate
281 before returning a value.
282
283 If the time reserved word precedes a pipeline, the elapsed as well as
284 user and system time consumed by its execution are reported when the
285 pipeline terminates. The -p option changes the output format to that
286 specified by POSIX. When the shell is in posix mode, it does not rec‐
287 ognize time as a reserved word if the next token begins with a `-'.
288 The TIMEFORMAT variable may be set to a format string that specifies
289 how the timing information should be displayed; see the description of
290 TIMEFORMAT under Shell Variables below.
291
292 When the shell is in posix mode, time may be followed by a newline. In
293 this case, the shell displays the total user and system time consumed
294 by the shell and its children. The TIMEFORMAT variable may be used to
295 specify the format of the time information.
296
297 Each command in a pipeline is executed as a separate process (i.e., in
298 a subshell). See COMMAND EXECUTION ENVIRONMENT for a description of a
299 subshell environment. If the lastpipe option is enabled using the
300 shopt builtin (see the description of shopt below), the last element of
301 a pipeline may be run by the shell process.
302
303 Lists
304 A list is a sequence of one or more pipelines separated by one of the
305 operators ;, &, &&, or ||, and optionally terminated by one of ;, &, or
306 <newline>.
307
308 Of these list operators, && and || have equal precedence, followed by ;
309 and &, which have equal precedence.
310
311 A sequence of one or more newlines may appear in a list instead of a
312 semicolon to delimit commands.
313
314 If a command is terminated by the control operator &, the shell exe‐
315 cutes the command in the background in a subshell. The shell does not
316 wait for the command to finish, and the return status is 0. These are
317 referred to as asynchronous commands. Commands separated by a ; are
318 executed sequentially; the shell waits for each command to terminate in
319 turn. The return status is the exit status of the last command exe‐
320 cuted.
321
322 AND and OR lists are sequences of one or more pipelines separated by
323 the && and || control operators, respectively. AND and OR lists are
324 executed with left associativity. An AND list has the form
325
326 command1 && command2
327
328 command2 is executed if, and only if, command1 returns an exit status
329 of zero (success).
330
331 An OR list has the form
332
333 command1 || command2
334
335 command2 is executed if, and only if, command1 returns a non-zero exit
336 status. The return status of AND and OR lists is the exit status of
337 the last command executed in the list.
338
339 Compound Commands
340 A compound command is one of the following. In most cases a list in a
341 command's description may be separated from the rest of the command by
342 one or more newlines, and may be followed by a newline in place of a
343 semicolon.
344
345 (list) list is executed in a subshell environment (see COMMAND EXECU‐
346 TION ENVIRONMENT below). Variable assignments and builtin com‐
347 mands that affect the shell's environment do not remain in
348 effect after the command completes. The return status is the
349 exit status of list.
350
351 { list; }
352 list is simply executed in the current shell environment. list
353 must be terminated with a newline or semicolon. This is known
354 as a group command. The return status is the exit status of
355 list. Note that unlike the metacharacters ( and ), { and } are
356 reserved words and must occur where a reserved word is permitted
357 to be recognized. Since they do not cause a word break, they
358 must be separated from list by whitespace or another shell
359 metacharacter.
360
361 ((expression))
362 The expression is evaluated according to the rules described
363 below under ARITHMETIC EVALUATION. If the value of the expres‐
364 sion is non-zero, the return status is 0; otherwise the return
365 status is 1. This is exactly equivalent to let "expression".
366
367 [[ expression ]]
368 Return a status of 0 or 1 depending on the evaluation of the
369 conditional expression expression. Expressions are composed of
370 the primaries described below under CONDITIONAL EXPRESSIONS.
371 Word splitting and pathname expansion are not performed on the
372 words between the [[ and ]]; tilde expansion, parameter and
373 variable expansion, arithmetic expansion, command substitution,
374 process substitution, and quote removal are performed. Condi‐
375 tional operators such as -f must be unquoted to be recognized as
376 primaries.
377
378 When used with [[, the < and > operators sort lexicographically
379 using the current locale.
380
381 When the == and != operators are used, the string to the right
382 of the operator is considered a pattern and matched according to
383 the rules described below under Pattern Matching, as if the ext‐
384 glob shell option were enabled. The = operator is equivalent to
385 ==. If the nocasematch shell option is enabled, the match is
386 performed without regard to the case of alphabetic characters.
387 The return value is 0 if the string matches (==) or does not
388 match (!=) the pattern, and 1 otherwise. Any part of the pat‐
389 tern may be quoted to force the quoted portion to be matched as
390 a string.
391
392 An additional binary operator, =~, is available, with the same
393 precedence as == and !=. When it is used, the string to the
394 right of the operator is considered a POSIX extended regular
395 expression and matched accordingly (as in regex(3)). The return
396 value is 0 if the string matches the pattern, and 1 otherwise.
397 If the regular expression is syntactically incorrect, the condi‐
398 tional expression's return value is 2. If the nocasematch shell
399 option is enabled, the match is performed without regard to the
400 case of alphabetic characters. Any part of the pattern may be
401 quoted to force the quoted portion to be matched as a string.
402 Bracket expressions in regular expressions must be treated care‐
403 fully, since normal quoting characters lose their meanings
404 between brackets. If the pattern is stored in a shell variable,
405 quoting the variable expansion forces the entire pattern to be
406 matched as a string. Substrings matched by parenthesized subex‐
407 pressions within the regular expression are saved in the array
408 variable BASH_REMATCH. The element of BASH_REMATCH with index 0
409 is the portion of the string matching the entire regular expres‐
410 sion. The element of BASH_REMATCH with index n is the portion
411 of the string matching the nth parenthesized subexpression.
412
413 Expressions may be combined using the following operators,
414 listed in decreasing order of precedence:
415
416 ( expression )
417 Returns the value of expression. This may be used to
418 override the normal precedence of operators.
419 ! expression
420 True if expression is false.
421 expression1 && expression2
422 True if both expression1 and expression2 are true.
423 expression1 || expression2
424 True if either expression1 or expression2 is true.
425
426 The && and || operators do not evaluate expression2 if the value
427 of expression1 is sufficient to determine the return value of
428 the entire conditional expression.
429
430 for name [ [ in [ word ... ] ] ; ] do list ; done
431 The list of words following in is expanded, generating a list of
432 items. The variable name is set to each element of this list in
433 turn, and list is executed each time. If the in word is omit‐
434 ted, the for command executes list once for each positional
435 parameter that is set (see PARAMETERS below). The return status
436 is the exit status of the last command that executes. If the
437 expansion of the items following in results in an empty list, no
438 commands are executed, and the return status is 0.
439
440 for (( expr1 ; expr2 ; expr3 )) ; do list ; done
441 First, the arithmetic expression expr1 is evaluated according to
442 the rules described below under ARITHMETIC EVALUATION. The
443 arithmetic expression expr2 is then evaluated repeatedly until
444 it evaluates to zero. Each time expr2 evaluates to a non-zero
445 value, list is executed and the arithmetic expression expr3 is
446 evaluated. If any expression is omitted, it behaves as if it
447 evaluates to 1. The return value is the exit status of the last
448 command in list that is executed, or false if any of the expres‐
449 sions is invalid.
450
451 select name [ in word ] ; do list ; done
452 The list of words following in is expanded, generating a list of
453 items. The set of expanded words is printed on the standard
454 error, each preceded by a number. If the in word is omitted,
455 the positional parameters are printed (see PARAMETERS below).
456 The PS3 prompt is then displayed and a line read from the stan‐
457 dard input. If the line consists of a number corresponding to
458 one of the displayed words, then the value of name is set to
459 that word. If the line is empty, the words and prompt are dis‐
460 played again. If EOF is read, the command completes. Any other
461 value read causes name to be set to null. The line read is
462 saved in the variable REPLY. The list is executed after each
463 selection until a break command is executed. The exit status of
464 select is the exit status of the last command executed in list,
465 or zero if no commands were executed.
466
467 case word in [ [(] pattern [ | pattern ] ... ) list ;; ] ... esac
468 A case command first expands word, and tries to match it against
469 each pattern in turn, using the matching rules described under
470 Pattern Matching below. The word is expanded using tilde expan‐
471 sion, parameter and variable expansion, arithmetic expansion,
472 command substitution, process substitution and quote removal.
473 Each pattern examined is expanded using tilde expansion, parame‐
474 ter and variable expansion, arithmetic expansion, command sub‐
475 stitution, and process substitution. If the nocasematch shell
476 option is enabled, the match is performed without regard to the
477 case of alphabetic characters. When a match is found, the cor‐
478 responding list is executed. If the ;; operator is used, no
479 subsequent matches are attempted after the first pattern match.
480 Using ;& in place of ;; causes execution to continue with the
481 list associated with the next set of patterns. Using ;;& in
482 place of ;; causes the shell to test the next pattern list in
483 the statement, if any, and execute any associated list on a suc‐
484 cessful match. The exit status is zero if no pattern matches.
485 Otherwise, it is the exit status of the last command executed in
486 list.
487
488 if list; then list; [ elif list; then list; ] ... [ else list; ] fi
489 The if list is executed. If its exit status is zero, the then
490 list is executed. Otherwise, each elif list is executed in
491 turn, and if its exit status is zero, the corresponding then
492 list is executed and the command completes. Otherwise, the else
493 list is executed, if present. The exit status is the exit sta‐
494 tus of the last command executed, or zero if no condition tested
495 true.
496
497 while list-1; do list-2; done
498 until list-1; do list-2; done
499 The while command continuously executes the list list-2 as long
500 as the last command in the list list-1 returns an exit status of
501 zero. The until command is identical to the while command,
502 except that the test is negated: list-2 is executed as long as
503 the last command in list-1 returns a non-zero exit status. The
504 exit status of the while and until commands is the exit status
505 of the last command executed in list-2, or zero if none was exe‐
506 cuted.
507
508 Coprocesses
509 A coprocess is a shell command preceded by the coproc reserved word. A
510 coprocess is executed asynchronously in a subshell, as if the command
511 had been terminated with the & control operator, with a two-way pipe
512 established between the executing shell and the coprocess.
513
514 The format for a coprocess is:
515
516 coproc [NAME] command [redirections]
517
518 This creates a coprocess named NAME. If NAME is not supplied, the
519 default name is COPROC. NAME must not be supplied if command is a sim‐
520 ple command (see above); otherwise, it is interpreted as the first word
521 of the simple command. When the coprocess is executed, the shell cre‐
522 ates an array variable (see Arrays below) named NAME in the context of
523 the executing shell. The standard output of command is connected via a
524 pipe to a file descriptor in the executing shell, and that file
525 descriptor is assigned to NAME[0]. The standard input of command is
526 connected via a pipe to a file descriptor in the executing shell, and
527 that file descriptor is assigned to NAME[1]. This pipe is established
528 before any redirections specified by the command (see REDIRECTION
529 below). The file descriptors can be utilized as arguments to shell
530 commands and redirections using standard word expansions. Other than
531 those created to execute command and process substitutions, the file
532 descriptors are not available in subshells. The process ID of the
533 shell spawned to execute the coprocess is available as the value of the
534 variable NAME_PID. The wait builtin command may be used to wait for
535 the coprocess to terminate.
536
537 Since the coprocess is created as an asynchronous command, the coproc
538 command always returns success. The return status of a coprocess is
539 the exit status of command.
540
541 Shell Function Definitions
542 A shell function is an object that is called like a simple command and
543 executes a compound command with a new set of positional parameters.
544 Shell functions are declared as follows:
545
546 name () compound-command [redirection]
547 function name [()] compound-command [redirection]
548 This defines a function named name. The reserved word function
549 is optional. If the function reserved word is supplied, the
550 parentheses are optional. The body of the function is the com‐
551 pound command compound-command (see Compound Commands above).
552 That command is usually a list of commands between { and }, but
553 may be any command listed under Compound Commands above, with
554 one exception: If the function reserved word is used, but the
555 parentheses are not supplied, the braces are required. com‐
556 pound-command is executed whenever name is specified as the name
557 of a simple command. When in posix mode, name may not be the
558 name of one of the POSIX special builtins. Any redirections
559 (see REDIRECTION below) specified when a function is defined are
560 performed when the function is executed. The exit status of a
561 function definition is zero unless a syntax error occurs or a
562 readonly function with the same name already exists. When exe‐
563 cuted, the exit status of a function is the exit status of the
564 last command executed in the body. (See FUNCTIONS below.)
565
567 In a non-interactive shell, or an interactive shell in which the inter‐
568 active_comments option to the shopt builtin is enabled (see SHELL
569 BUILTIN COMMANDS below), a word beginning with # causes that word and
570 all remaining characters on that line to be ignored. An interactive
571 shell without the interactive_comments option enabled does not allow
572 comments. The interactive_comments option is on by default in interac‐
573 tive shells.
574
576 Quoting is used to remove the special meaning of certain characters or
577 words to the shell. Quoting can be used to disable special treatment
578 for special characters, to prevent reserved words from being recognized
579 as such, and to prevent parameter expansion.
580
581 Each of the metacharacters listed above under DEFINITIONS has special
582 meaning to the shell and must be quoted if it is to represent itself.
583
584 When the command history expansion facilities are being used (see HIS‐
585 TORY EXPANSION below), the history expansion character, usually !, must
586 be quoted to prevent history expansion.
587
588 There are three quoting mechanisms: the escape character, single
589 quotes, and double quotes.
590
591 A non-quoted backslash (\) is the escape character. It preserves the
592 literal value of the next character that follows, with the exception of
593 <newline>. If a \<newline> pair appears, and the backslash is not
594 itself quoted, the \<newline> is treated as a line continuation (that
595 is, it is removed from the input stream and effectively ignored).
596
597 Enclosing characters in single quotes preserves the literal value of
598 each character within the quotes. A single quote may not occur between
599 single quotes, even when preceded by a backslash.
600
601 Enclosing characters in double quotes preserves the literal value of
602 all characters within the quotes, with the exception of $, `, \, and,
603 when history expansion is enabled, !. When the shell is in posix mode,
604 the ! has no special meaning within double quotes, even when history
605 expansion is enabled. The characters $ and ` retain their special
606 meaning within double quotes. The backslash retains its special mean‐
607 ing only when followed by one of the following characters: $, `, ", \,
608 or <newline>. A double quote may be quoted within double quotes by
609 preceding it with a backslash. If enabled, history expansion will be
610 performed unless an ! appearing in double quotes is escaped using a
611 backslash. The backslash preceding the ! is not removed.
612
613 The special parameters * and @ have special meaning when in double
614 quotes (see PARAMETERS below).
615
616 Words of the form $'string' are treated specially. The word expands to
617 string, with backslash-escaped characters replaced as specified by the
618 ANSI C standard. Backslash escape sequences, if present, are decoded
619 as follows:
620 \a alert (bell)
621 \b backspace
622 \e
623 \E an escape character
624 \f form feed
625 \n new line
626 \r carriage return
627 \t horizontal tab
628 \v vertical tab
629 \\ backslash
630 \' single quote
631 \" double quote
632 \? question mark
633 \nnn the eight-bit character whose value is the octal value
634 nnn (one to three octal digits)
635 \xHH the eight-bit character whose value is the hexadecimal
636 value HH (one or two hex digits)
637 \uHHHH the Unicode (ISO/IEC 10646) character whose value is the
638 hexadecimal value HHHH (one to four hex digits)
639 \UHHHHHHHH
640 the Unicode (ISO/IEC 10646) character whose value is the
641 hexadecimal value HHHHHHHH (one to eight hex digits)
642 \cx a control-x character
643
644 The expanded result is single-quoted, as if the dollar sign had not
645 been present.
646
647 A double-quoted string preceded by a dollar sign ($"string") will cause
648 the string to be translated according to the current locale. If the
649 current locale is C or POSIX, the dollar sign is ignored. If the
650 string is translated and replaced, the replacement is double-quoted.
651
653 A parameter is an entity that stores values. It can be a name, a num‐
654 ber, or one of the special characters listed below under Special Param‐
655 eters. A variable is a parameter denoted by a name. A variable has a
656 value and zero or more attributes. Attributes are assigned using the
657 declare builtin command (see declare below in SHELL BUILTIN COMMANDS).
658
659 A parameter is set if it has been assigned a value. The null string is
660 a valid value. Once a variable is set, it may be unset only by using
661 the unset builtin command (see SHELL BUILTIN COMMANDS below).
662
663 A variable may be assigned to by a statement of the form
664
665 name=[value]
666
667 If value is not given, the variable is assigned the null string. All
668 values undergo tilde expansion, parameter and variable expansion, com‐
669 mand substitution, arithmetic expansion, and quote removal (see EXPAN‐
670 SION below). If the variable has its integer attribute set, then value
671 is evaluated as an arithmetic expression even if the $((...)) expansion
672 is not used (see Arithmetic Expansion below). Word splitting is not
673 performed, with the exception of "$@" as explained below under Special
674 Parameters. Pathname expansion is not performed. Assignment state‐
675 ments may also appear as arguments to the alias, declare, typeset,
676 export, readonly, and local builtin commands (declaration commands).
677 When in posix mode, these builtins may appear in a command after one or
678 more instances of the command builtin and retain these assignment
679 statement properties.
680
681 In the context where an assignment statement is assigning a value to a
682 shell variable or array index, the += operator can be used to append to
683 or add to the variable's previous value. This includes arguments to
684 builtin commands such as declare that accept assignment statements
685 (declaration commands). When += is applied to a variable for which the
686 integer attribute has been set, value is evaluated as an arithmetic
687 expression and added to the variable's current value, which is also
688 evaluated. When += is applied to an array variable using compound
689 assignment (see Arrays below), the variable's value is not unset (as it
690 is when using =), and new values are appended to the array beginning at
691 one greater than the array's maximum index (for indexed arrays) or
692 added as additional key-value pairs in an associative array. When
693 applied to a string-valued variable, value is expanded and appended to
694 the variable's value.
695
696 A variable can be assigned the nameref attribute using the -n option to
697 the declare or local builtin commands (see the descriptions of declare
698 and local below) to create a nameref, or a reference to another vari‐
699 able. This allows variables to be manipulated indirectly. Whenever
700 the nameref variable is referenced, assigned to, unset, or has its
701 attributes modified (other than using or changing the nameref attribute
702 itself), the operation is actually performed on the variable specified
703 by the nameref variable's value. A nameref is commonly used within
704 shell functions to refer to a variable whose name is passed as an argu‐
705 ment to the function. For instance, if a variable name is passed to a
706 shell function as its first argument, running
707 declare -n ref=$1
708 inside the function creates a nameref variable ref whose value is the
709 variable name passed as the first argument. References and assignments
710 to ref, and changes to its attributes, are treated as references,
711 assignments, and attribute modifications to the variable whose name was
712 passed as $1. If the control variable in a for loop has the nameref
713 attribute, the list of words can be a list of shell variables, and a
714 name reference will be established for each word in the list, in turn,
715 when the loop is executed. Array variables cannot be given the nameref
716 attribute. However, nameref variables can reference array variables
717 and subscripted array variables. Namerefs can be unset using the -n
718 option to the unset builtin. Otherwise, if unset is executed with the
719 name of a nameref variable as an argument, the variable referenced by
720 the nameref variable will be unset.
721
722 Positional Parameters
723 A positional parameter is a parameter denoted by one or more digits,
724 other than the single digit 0. Positional parameters are assigned from
725 the shell's arguments when it is invoked, and may be reassigned using
726 the set builtin command. Positional parameters may not be assigned to
727 with assignment statements. The positional parameters are temporarily
728 replaced when a shell function is executed (see FUNCTIONS below).
729
730 When a positional parameter consisting of more than a single digit is
731 expanded, it must be enclosed in braces (see EXPANSION below).
732
733 Special Parameters
734 The shell treats several parameters specially. These parameters may
735 only be referenced; assignment to them is not allowed.
736 * Expands to the positional parameters, starting from one. When
737 the expansion is not within double quotes, each positional
738 parameter expands to a separate word. In contexts where it is
739 performed, those words are subject to further word splitting and
740 pathname expansion. When the expansion occurs within double
741 quotes, it expands to a single word with the value of each
742 parameter separated by the first character of the IFS special
743 variable. That is, "$*" is equivalent to "$1c$2c...", where c
744 is the first character of the value of the IFS variable. If IFS
745 is unset, the parameters are separated by spaces. If IFS is
746 null, the parameters are joined without intervening separators.
747 @ Expands to the positional parameters, starting from one. In
748 contexts where word splitting is performed, this expands each
749 positional parameter to a separate word; if not within double
750 quotes, these words are subject to word splitting. In contexts
751 where word splitting is not performed, this expands to a single
752 word with each positional parameter separated by a space. When
753 the expansion occurs within double quotes, each parameter
754 expands to a separate word. That is, "$@" is equivalent to "$1"
755 "$2" ... If the double-quoted expansion occurs within a word,
756 the expansion of the first parameter is joined with the begin‐
757 ning part of the original word, and the expansion of the last
758 parameter is joined with the last part of the original word.
759 When there are no positional parameters, "$@" and $@ expand to
760 nothing (i.e., they are removed).
761 # Expands to the number of positional parameters in decimal.
762 ? Expands to the exit status of the most recently executed fore‐
763 ground pipeline.
764 - Expands to the current option flags as specified upon invoca‐
765 tion, by the set builtin command, or those set by the shell
766 itself (such as the -i option).
767 $ Expands to the process ID of the shell. In a () subshell, it
768 expands to the process ID of the current shell, not the sub‐
769 shell.
770 ! Expands to the process ID of the job most recently placed into
771 the background, whether executed as an asynchronous command or
772 using the bg builtin (see JOB CONTROL below).
773 0 Expands to the name of the shell or shell script. This is set
774 at shell initialization. If bash is invoked with a file of com‐
775 mands, $0 is set to the name of that file. If bash is started
776 with the -c option, then $0 is set to the first argument after
777 the string to be executed, if one is present. Otherwise, it is
778 set to the filename used to invoke bash, as given by argument
779 zero.
780 _ At shell startup, set to the absolute pathname used to invoke
781 the shell or shell script being executed as passed in the envi‐
782 ronment or argument list. Subsequently, expands to the last
783 argument to the previous simple command executed in the fore‐
784 ground, after expansion. Also set to the full pathname used to
785 invoke each command executed and placed in the environment
786 exported to that command. When checking mail, this parameter
787 holds the name of the mail file currently being checked.
788
789 Shell Variables
790 The following variables are set by the shell:
791
792 BASH Expands to the full filename used to invoke this instance of
793 bash.
794 BASHOPTS
795 A colon-separated list of enabled shell options. Each word in
796 the list is a valid argument for the -s option to the shopt
797 builtin command (see SHELL BUILTIN COMMANDS below). The options
798 appearing in BASHOPTS are those reported as on by shopt. If
799 this variable is in the environment when bash starts up, each
800 shell option in the list will be enabled before reading any
801 startup files. This variable is read-only.
802 BASHPID
803 Expands to the process ID of the current bash process. This
804 differs from $$ under certain circumstances, such as subshells
805 that do not require bash to be re-initialized. Assignments to
806 BASHPID have no effect. If BASHPID is unset, it loses its spe‐
807 cial properties, even if it is subsequently reset.
808 BASH_ALIASES
809 An associative array variable whose members correspond to the
810 internal list of aliases as maintained by the alias builtin.
811 Elements added to this array appear in the alias list; however,
812 unsetting array elements currently does not cause aliases to be
813 removed from the alias list. If BASH_ALIASES is unset, it loses
814 its special properties, even if it is subsequently reset.
815 BASH_ARGC
816 An array variable whose values are the number of parameters in
817 each frame of the current bash execution call stack. The number
818 of parameters to the current subroutine (shell function or
819 script executed with . or source) is at the top of the stack.
820 When a subroutine is executed, the number of parameters passed
821 is pushed onto BASH_ARGC. The shell sets BASH_ARGC only when in
822 extended debugging mode (see the description of the extdebug
823 option to the shopt builtin below). Setting extdebug after the
824 shell has started to execute a script, or referencing this vari‐
825 able when extdebug is not set, may result in inconsistent val‐
826 ues.
827 BASH_ARGV
828 An array variable containing all of the parameters in the cur‐
829 rent bash execution call stack. The final parameter of the last
830 subroutine call is at the top of the stack; the first parameter
831 of the initial call is at the bottom. When a subroutine is exe‐
832 cuted, the parameters supplied are pushed onto BASH_ARGV. The
833 shell sets BASH_ARGV only when in extended debugging mode (see
834 the description of the extdebug option to the shopt builtin
835 below). Setting extdebug after the shell has started to execute
836 a script, or referencing this variable when extdebug is not set,
837 may result in inconsistent values.
838 BASH_ARGV0
839 When referenced, this variable expands to the name of the shell
840 or shell script (identical to $0; see the description of special
841 parameter 0 above). Assignment to BASH_ARGV0 causes the value
842 assigned to also be assigned to $0. If BASH_ARGV0 is unset, it
843 loses its special properties, even if it is subsequently reset.
844 BASH_CMDS
845 An associative array variable whose members correspond to the
846 internal hash table of commands as maintained by the hash
847 builtin. Elements added to this array appear in the hash table;
848 however, unsetting array elements currently does not cause com‐
849 mand names to be removed from the hash table. If BASH_CMDS is
850 unset, it loses its special properties, even if it is subse‐
851 quently reset.
852 BASH_COMMAND
853 The command currently being executed or about to be executed,
854 unless the shell is executing a command as the result of a trap,
855 in which case it is the command executing at the time of the
856 trap.
857 BASH_EXECUTION_STRING
858 The command argument to the -c invocation option.
859 BASH_LINENO
860 An array variable whose members are the line numbers in source
861 files where each corresponding member of FUNCNAME was invoked.
862 ${BASH_LINENO[$i]} is the line number in the source file
863 (${BASH_SOURCE[$i+1]}) where ${FUNCNAME[$i]} was called (or
864 ${BASH_LINENO[$i-1]} if referenced within another shell func‐
865 tion). Use LINENO to obtain the current line number.
866 BASH_LOADABLES_PATH
867 A colon-separated list of directories in which the shell looks
868 for dynamically loadable builtins specified by the enable com‐
869 mand.
870 BASH_REMATCH
871 An array variable whose members are assigned by the =~ binary
872 operator to the [[ conditional command. The element with index
873 0 is the portion of the string matching the entire regular
874 expression. The element with index n is the portion of the
875 string matching the nth parenthesized subexpression. This vari‐
876 able is read-only.
877 BASH_SOURCE
878 An array variable whose members are the source filenames where
879 the corresponding shell function names in the FUNCNAME array
880 variable are defined. The shell function ${FUNCNAME[$i]} is
881 defined in the file ${BASH_SOURCE[$i]} and called from
882 ${BASH_SOURCE[$i+1]}.
883 BASH_SUBSHELL
884 Incremented by one within each subshell or subshell environment
885 when the shell begins executing in that environment. The ini‐
886 tial value is 0.
887 BASH_VERSINFO
888 A readonly array variable whose members hold version information
889 for this instance of bash. The values assigned to the array
890 members are as follows:
891 BASH_VERSINFO[0] The major version number (the release).
892 BASH_VERSINFO[1] The minor version number (the version).
893 BASH_VERSINFO[2] The patch level.
894 BASH_VERSINFO[3] The build version.
895 BASH_VERSINFO[4] The release status (e.g., beta1).
896 BASH_VERSINFO[5] The value of MACHTYPE.
897 BASH_VERSION
898 Expands to a string describing the version of this instance of
899 bash.
900 COMP_CWORD
901 An index into ${COMP_WORDS} of the word containing the current
902 cursor position. This variable is available only in shell func‐
903 tions invoked by the programmable completion facilities (see
904 Programmable Completion below).
905 COMP_KEY
906 The key (or final key of a key sequence) used to invoke the cur‐
907 rent completion function.
908 COMP_LINE
909 The current command line. This variable is available only in
910 shell functions and external commands invoked by the program‐
911 mable completion facilities (see Programmable Completion below).
912 COMP_POINT
913 The index of the current cursor position relative to the begin‐
914 ning of the current command. If the current cursor position is
915 at the end of the current command, the value of this variable is
916 equal to ${#COMP_LINE}. This variable is available only in
917 shell functions and external commands invoked by the program‐
918 mable completion facilities (see Programmable Completion below).
919 COMP_TYPE
920 Set to an integer value corresponding to the type of completion
921 attempted that caused a completion function to be called: TAB,
922 for normal completion, ?, for listing completions after succes‐
923 sive tabs, !, for listing alternatives on partial word comple‐
924 tion, @, to list completions if the word is not unmodified, or
925 %, for menu completion. This variable is available only in
926 shell functions and external commands invoked by the program‐
927 mable completion facilities (see Programmable Completion below).
928 COMP_WORDBREAKS
929 The set of characters that the readline library treats as word
930 separators when performing word completion. If COMP_WORDBREAKS
931 is unset, it loses its special properties, even if it is subse‐
932 quently reset.
933 COMP_WORDS
934 An array variable (see Arrays below) consisting of the individ‐
935 ual words in the current command line. The line is split into
936 words as readline would split it, using COMP_WORDBREAKS as
937 described above. This variable is available only in shell func‐
938 tions invoked by the programmable completion facilities (see
939 Programmable Completion below).
940 COPROC An array variable (see Arrays below) created to hold the file
941 descriptors for output from and input to an unnamed coprocess
942 (see Coprocesses above).
943 DIRSTACK
944 An array variable (see Arrays below) containing the current con‐
945 tents of the directory stack. Directories appear in the stack
946 in the order they are displayed by the dirs builtin. Assigning
947 to members of this array variable may be used to modify directo‐
948 ries already in the stack, but the pushd and popd builtins must
949 be used to add and remove directories. Assignment to this vari‐
950 able will not change the current directory. If DIRSTACK is
951 unset, it loses its special properties, even if it is subse‐
952 quently reset.
953 EPOCHREALTIME
954 Each time this parameter is referenced, it expands to the number
955 of seconds since the Unix Epoch (see time(3)) as a floating
956 point value with micro-second granularity. Assignments to
957 EPOCHREALTIME are ignored. If EPOCHREALTIME is unset, it loses
958 its special properties, even if it is subsequently reset.
959 EPOCHSECONDS
960 Each time this parameter is referenced, it expands to the number
961 of seconds since the Unix Epoch (see time(3)). Assignments to
962 EPOCHSECONDS are ignored. If EPOCHSECONDS is unset, it loses
963 its special properties, even if it is subsequently reset.
964 EUID Expands to the effective user ID of the current user, initial‐
965 ized at shell startup. This variable is readonly.
966 FUNCNAME
967 An array variable containing the names of all shell functions
968 currently in the execution call stack. The element with index 0
969 is the name of any currently-executing shell function. The bot‐
970 tom-most element (the one with the highest index) is "main".
971 This variable exists only when a shell function is executing.
972 Assignments to FUNCNAME have no effect. If FUNCNAME is unset,
973 it loses its special properties, even if it is subsequently
974 reset.
975
976 This variable can be used with BASH_LINENO and BASH_SOURCE.
977 Each element of FUNCNAME has corresponding elements in
978 BASH_LINENO and BASH_SOURCE to describe the call stack. For
979 instance, ${FUNCNAME[$i]} was called from the file
980 ${BASH_SOURCE[$i+1]} at line number ${BASH_LINENO[$i]}. The
981 caller builtin displays the current call stack using this infor‐
982 mation.
983 GROUPS An array variable containing the list of groups of which the
984 current user is a member. Assignments to GROUPS have no effect.
985 If GROUPS is unset, it loses its special properties, even if it
986 is subsequently reset.
987 HISTCMD
988 The history number, or index in the history list, of the current
989 command. If HISTCMD is unset, it loses its special properties,
990 even if it is subsequently reset.
991 HOSTNAME
992 Automatically set to the name of the current host.
993 HOSTTYPE
994 Automatically set to a string that uniquely describes the type
995 of machine on which bash is executing. The default is system-
996 dependent.
997 LINENO Each time this parameter is referenced, the shell substitutes a
998 decimal number representing the current sequential line number
999 (starting with 1) within a script or function. When not in a
1000 script or function, the value substituted is not guaranteed to
1001 be meaningful. If LINENO is unset, it loses its special proper‐
1002 ties, even if it is subsequently reset.
1003 MACHTYPE
1004 Automatically set to a string that fully describes the system
1005 type on which bash is executing, in the standard GNU cpu-com‐
1006 pany-system format. The default is system-dependent.
1007 MAPFILE
1008 An array variable (see Arrays below) created to hold the text
1009 read by the mapfile builtin when no variable name is supplied.
1010 OLDPWD The previous working directory as set by the cd command.
1011 OPTARG The value of the last option argument processed by the getopts
1012 builtin command (see SHELL BUILTIN COMMANDS below).
1013 OPTIND The index of the next argument to be processed by the getopts
1014 builtin command (see SHELL BUILTIN COMMANDS below).
1015 OSTYPE Automatically set to a string that describes the operating sys‐
1016 tem on which bash is executing. The default is system-depen‐
1017 dent.
1018 PIPESTATUS
1019 An array variable (see Arrays below) containing a list of exit
1020 status values from the processes in the most-recently-executed
1021 foreground pipeline (which may contain only a single command).
1022 PPID The process ID of the shell's parent. This variable is read‐
1023 only.
1024 PWD The current working directory as set by the cd command.
1025 RANDOM Each time this parameter is referenced, a random integer between
1026 0 and 32767 is generated. The sequence of random numbers may be
1027 initialized by assigning a value to RANDOM. If RANDOM is unset,
1028 it loses its special properties, even if it is subsequently
1029 reset.
1030 READLINE_LINE
1031 The contents of the readline line buffer, for use with "bind -x"
1032 (see SHELL BUILTIN COMMANDS below).
1033 READLINE_POINT
1034 The position of the insertion point in the readline line buffer,
1035 for use with "bind -x" (see SHELL BUILTIN COMMANDS below).
1036 REPLY Set to the line of input read by the read builtin command when
1037 no arguments are supplied.
1038 SECONDS
1039 Each time this parameter is referenced, the number of seconds
1040 since shell invocation is returned. If a value is assigned to
1041 SECONDS, the value returned upon subsequent references is the
1042 number of seconds since the assignment plus the value assigned.
1043 If SECONDS is unset, it loses its special properties, even if it
1044 is subsequently reset.
1045 SHELLOPTS
1046 A colon-separated list of enabled shell options. Each word in
1047 the list is a valid argument for the -o option to the set
1048 builtin command (see SHELL BUILTIN COMMANDS below). The options
1049 appearing in SHELLOPTS are those reported as on by set -o. If
1050 this variable is in the environment when bash starts up, each
1051 shell option in the list will be enabled before reading any
1052 startup files. This variable is read-only.
1053 SHLVL Incremented by one each time an instance of bash is started.
1054 UID Expands to the user ID of the current user, initialized at shell
1055 startup. This variable is readonly.
1056
1057 The following variables are used by the shell. In some cases, bash
1058 assigns a default value to a variable; these cases are noted below.
1059
1060 BASH_COMPAT
1061 The value is used to set the shell's compatibility level. See
1062 the description of the shopt builtin below under SHELL BUILTIN
1063 COMMANDS for a description of the various compatibility levels
1064 and their effects. The value may be a decimal number (e.g.,
1065 4.2) or an integer (e.g., 42) corresponding to the desired com‐
1066 patibility level. If BASH_COMPAT is unset or set to the empty
1067 string, the compatibility level is set to the default for the
1068 current version. If BASH_COMPAT is set to a value that is not
1069 one of the valid compatibility levels, the shell prints an error
1070 message and sets the compatibility level to the default for the
1071 current version. The valid compatibility levels correspond to
1072 the compatibility options accepted by the shopt builtin
1073 described below (for example, compat42 means that 4.2 and 42 are
1074 valid values). The current version is also a valid value.
1075 BASH_ENV
1076 If this parameter is set when bash is executing a shell script,
1077 its value is interpreted as a filename containing commands to
1078 initialize the shell, as in ~/.bashrc. The value of BASH_ENV is
1079 subjected to parameter expansion, command substitution, and
1080 arithmetic expansion before being interpreted as a filename.
1081 PATH is not used to search for the resultant filename.
1082 BASH_XTRACEFD
1083 If set to an integer corresponding to a valid file descriptor,
1084 bash will write the trace output generated when set -x is
1085 enabled to that file descriptor. The file descriptor is closed
1086 when BASH_XTRACEFD is unset or assigned a new value. Unsetting
1087 BASH_XTRACEFD or assigning it the empty string causes the trace
1088 output to be sent to the standard error. Note that setting
1089 BASH_XTRACEFD to 2 (the standard error file descriptor) and then
1090 unsetting it will result in the standard error being closed.
1091 CDPATH The search path for the cd command. This is a colon-separated
1092 list of directories in which the shell looks for destination
1093 directories specified by the cd command. A sample value is
1094 ".:~:/usr".
1095 CHILD_MAX
1096 Set the number of exited child status values for the shell to
1097 remember. Bash will not allow this value to be decreased below
1098 a POSIX-mandated minimum, and there is a maximum value (cur‐
1099 rently 8192) that this may not exceed. The minimum value is
1100 system-dependent.
1101 COLUMNS
1102 Used by the select compound command to determine the terminal
1103 width when printing selection lists. Automatically set if the
1104 checkwinsize option is enabled or in an interactive shell upon
1105 receipt of a SIGWINCH.
1106 COMPREPLY
1107 An array variable from which bash reads the possible completions
1108 generated by a shell function invoked by the programmable com‐
1109 pletion facility (see Programmable Completion below). Each
1110 array element contains one possible completion.
1111 EMACS If bash finds this variable in the environment when the shell
1112 starts with value "t", it assumes that the shell is running in
1113 an Emacs shell buffer and disables line editing.
1114 ENV Similar to BASH_ENV; used when the shell is invoked in posix
1115 mode.
1116 EXECIGNORE
1117 A colon-separated list of shell patterns (see Pattern Matching)
1118 defining the list of filenames to be ignored by command search
1119 using PATH. Files whose full pathnames match one of these pat‐
1120 terns are not considered executable files for the purposes of
1121 completion and command execution via PATH lookup. This does not
1122 affect the behavior of the [, test, and [[ commands. Full path‐
1123 names in the command hash table are not subject to EXECIGNORE.
1124 Use this variable to ignore shared library files that have the
1125 executable bit set, but are not executable files. The pattern
1126 matching honors the setting of the extglob shell option.
1127 FCEDIT The default editor for the fc builtin command.
1128 FIGNORE
1129 A colon-separated list of suffixes to ignore when performing
1130 filename completion (see READLINE below). A filename whose suf‐
1131 fix matches one of the entries in FIGNORE is excluded from the
1132 list of matched filenames. A sample value is ".o:~".
1133 FUNCNEST
1134 If set to a numeric value greater than 0, defines a maximum
1135 function nesting level. Function invocations that exceed this
1136 nesting level will cause the current command to abort.
1137 GLOBIGNORE
1138 A colon-separated list of patterns defining the set of file
1139 names to be ignored by pathname expansion. If a file name
1140 matched by a pathname expansion pattern also matches one of the
1141 patterns in GLOBIGNORE, it is removed from the list of matches.
1142 HISTCONTROL
1143 A colon-separated list of values controlling how commands are
1144 saved on the history list. If the list of values includes
1145 ignorespace, lines which begin with a space character are not
1146 saved in the history list. A value of ignoredups causes lines
1147 matching the previous history entry to not be saved. A value of
1148 ignoreboth is shorthand for ignorespace and ignoredups. A value
1149 of erasedups causes all previous lines matching the current line
1150 to be removed from the history list before that line is saved.
1151 Any value not in the above list is ignored. If HISTCONTROL is
1152 unset, or does not include a valid value, all lines read by the
1153 shell parser are saved on the history list, subject to the value
1154 of HISTIGNORE. The second and subsequent lines of a multi-line
1155 compound command are not tested, and are added to the history
1156 regardless of the value of HISTCONTROL.
1157 HISTFILE
1158 The name of the file in which command history is saved (see HIS‐
1159 TORY below). The default value is ~/.bash_history. If unset,
1160 the command history is not saved when a shell exits.
1161 HISTFILESIZE
1162 The maximum number of lines contained in the history file. When
1163 this variable is assigned a value, the history file is trun‐
1164 cated, if necessary, to contain no more than that number of
1165 lines by removing the oldest entries. The history file is also
1166 truncated to this size after writing it when a shell exits. If
1167 the value is 0, the history file is truncated to zero size.
1168 Non-numeric values and numeric values less than zero inhibit
1169 truncation. The shell sets the default value to the value of
1170 HISTSIZE after reading any startup files.
1171 HISTIGNORE
1172 A colon-separated list of patterns used to decide which command
1173 lines should be saved on the history list. Each pattern is
1174 anchored at the beginning of the line and must match the com‐
1175 plete line (no implicit `*' is appended). Each pattern is
1176 tested against the line after the checks specified by HISTCON‐
1177 TROL are applied. In addition to the normal shell pattern
1178 matching characters, `&' matches the previous history line. `&'
1179 may be escaped using a backslash; the backslash is removed
1180 before attempting a match. The second and subsequent lines of a
1181 multi-line compound command are not tested, and are added to the
1182 history regardless of the value of HISTIGNORE. The pattern
1183 matching honors the setting of the extglob shell option.
1184 HISTSIZE
1185 The number of commands to remember in the command history (see
1186 HISTORY below). If the value is 0, commands are not saved in
1187 the history list. Numeric values less than zero result in every
1188 command being saved on the history list (there is no limit).
1189 The shell sets the default value to 500 after reading any
1190 startup files.
1191 HISTTIMEFORMAT
1192 If this variable is set and not null, its value is used as a
1193 format string for strftime(3) to print the time stamp associated
1194 with each history entry displayed by the history builtin. If
1195 this variable is set, time stamps are written to the history
1196 file so they may be preserved across shell sessions. This uses
1197 the history comment character to distinguish timestamps from
1198 other history lines.
1199 HOME The home directory of the current user; the default argument for
1200 the cd builtin command. The value of this variable is also used
1201 when performing tilde expansion.
1202 HOSTFILE
1203 Contains the name of a file in the same format as /etc/hosts
1204 that should be read when the shell needs to complete a hostname.
1205 The list of possible hostname completions may be changed while
1206 the shell is running; the next time hostname completion is
1207 attempted after the value is changed, bash adds the contents of
1208 the new file to the existing list. If HOSTFILE is set, but has
1209 no value, or does not name a readable file, bash attempts to
1210 read /etc/hosts to obtain the list of possible hostname comple‐
1211 tions. When HOSTFILE is unset, the hostname list is cleared.
1212 IFS The Internal Field Separator that is used for word splitting
1213 after expansion and to split lines into words with the read
1214 builtin command. The default value is ``<space><tab><new‐
1215 line>''.
1216 IGNOREEOF
1217 Controls the action of an interactive shell on receipt of an EOF
1218 character as the sole input. If set, the value is the number of
1219 consecutive EOF characters which must be typed as the first
1220 characters on an input line before bash exits. If the variable
1221 exists but does not have a numeric value, or has no value, the
1222 default value is 10. If it does not exist, EOF signifies the
1223 end of input to the shell.
1224 INPUTRC
1225 The filename for the readline startup file, overriding the
1226 default of ~/.inputrc (see READLINE below).
1227 INSIDE_EMACS
1228 If this variable appears in the environment when the shell
1229 starts, bash assumes that it is running inside an Emacs shell
1230 buffer and may disable line editing, depending on the value of
1231 TERM.
1232 LANG Used to determine the locale category for any category not
1233 specifically selected with a variable starting with LC_.
1234 LC_ALL This variable overrides the value of LANG and any other LC_
1235 variable specifying a locale category.
1236 LC_COLLATE
1237 This variable determines the collation order used when sorting
1238 the results of pathname expansion, and determines the behavior
1239 of range expressions, equivalence classes, and collating
1240 sequences within pathname expansion and pattern matching.
1241 LC_CTYPE
1242 This variable determines the interpretation of characters and
1243 the behavior of character classes within pathname expansion and
1244 pattern matching.
1245 LC_MESSAGES
1246 This variable determines the locale used to translate double-
1247 quoted strings preceded by a $.
1248 LC_NUMERIC
1249 This variable determines the locale category used for number
1250 formatting.
1251 LC_TIME
1252 This variable determines the locale category used for data and
1253 time formatting.
1254 LINES Used by the select compound command to determine the column
1255 length for printing selection lists. Automatically set if the
1256 checkwinsize option is enabled or in an interactive shell upon
1257 receipt of a SIGWINCH.
1258 MAIL If this parameter is set to a file or directory name and the
1259 MAILPATH variable is not set, bash informs the user of the
1260 arrival of mail in the specified file or Maildir-format direc‐
1261 tory.
1262 MAILCHECK
1263 Specifies how often (in seconds) bash checks for mail. The
1264 default is 60 seconds. When it is time to check for mail, the
1265 shell does so before displaying the primary prompt. If this
1266 variable is unset, or set to a value that is not a number
1267 greater than or equal to zero, the shell disables mail checking.
1268 MAILPATH
1269 A colon-separated list of filenames to be checked for mail. The
1270 message to be printed when mail arrives in a particular file may
1271 be specified by separating the filename from the message with a
1272 `?'. When used in the text of the message, $_ expands to the
1273 name of the current mailfile. Example:
1274 MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has
1275 mail!"'
1276 Bash can be configured to supply a default value for this vari‐
1277 able (there is no value by default), but the location of the
1278 user mail files that it uses is system dependent (e.g.,
1279 /var/mail/$USER).
1280 OPTERR If set to the value 1, bash displays error messages generated by
1281 the getopts builtin command (see SHELL BUILTIN COMMANDS below).
1282 OPTERR is initialized to 1 each time the shell is invoked or a
1283 shell script is executed.
1284 PATH The search path for commands. It is a colon-separated list of
1285 directories in which the shell looks for commands (see COMMAND
1286 EXECUTION below). A zero-length (null) directory name in the
1287 value of PATH indicates the current directory. A null directory
1288 name may appear as two adjacent colons, or as an initial or
1289 trailing colon. The default path is system-dependent, and is
1290 set by the administrator who installs bash. A common value is
1291 ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''.
1292 POSIXLY_CORRECT
1293 If this variable is in the environment when bash starts, the
1294 shell enters posix mode before reading the startup files, as if
1295 the --posix invocation option had been supplied. If it is set
1296 while the shell is running, bash enables posix mode, as if the
1297 command set -o posix had been executed. When the shell enters
1298 posix mode, it sets this variable if it was not already set.
1299 PROMPT_COMMAND
1300 If set, the value is executed as a command prior to issuing each
1301 primary prompt.
1302 PROMPT_DIRTRIM
1303 If set to a number greater than zero, the value is used as the
1304 number of trailing directory components to retain when expanding
1305 the \w and \W prompt string escapes (see PROMPTING below).
1306 Characters removed are replaced with an ellipsis.
1307 PS0 The value of this parameter is expanded (see PROMPTING below)
1308 and displayed by interactive shells after reading a command and
1309 before the command is executed.
1310 PS1 The value of this parameter is expanded (see PROMPTING below)
1311 and used as the primary prompt string. The default value is
1312 ``\s-\v\$ ''.
1313 PS2 The value of this parameter is expanded as with PS1 and used as
1314 the secondary prompt string. The default is ``> ''.
1315 PS3 The value of this parameter is used as the prompt for the select
1316 command (see SHELL GRAMMAR above).
1317 PS4 The value of this parameter is expanded as with PS1 and the
1318 value is printed before each command bash displays during an
1319 execution trace. The first character of the expanded value of
1320 PS4 is replicated multiple times, as necessary, to indicate mul‐
1321 tiple levels of indirection. The default is ``+ ''.
1322 SHELL The full pathname to the shell is kept in this environment vari‐
1323 able. If it is not set when the shell starts, bash assigns to
1324 it the full pathname of the current user's login shell.
1325 TIMEFORMAT
1326 The value of this parameter is used as a format string specify‐
1327 ing how the timing information for pipelines prefixed with the
1328 time reserved word should be displayed. The % character intro‐
1329 duces an escape sequence that is expanded to a time value or
1330 other information. The escape sequences and their meanings are
1331 as follows; the braces denote optional portions.
1332 %% A literal %.
1333 %[p][l]R The elapsed time in seconds.
1334 %[p][l]U The number of CPU seconds spent in user mode.
1335 %[p][l]S The number of CPU seconds spent in system mode.
1336 %P The CPU percentage, computed as (%U + %S) / %R.
1337
1338 The optional p is a digit specifying the precision, the number
1339 of fractional digits after a decimal point. A value of 0 causes
1340 no decimal point or fraction to be output. At most three places
1341 after the decimal point may be specified; values of p greater
1342 than 3 are changed to 3. If p is not specified, the value 3 is
1343 used.
1344
1345 The optional l specifies a longer format, including minutes, of
1346 the form MMmSS.FFs. The value of p determines whether or not
1347 the fraction is included.
1348
1349 If this variable is not set, bash acts as if it had the value
1350 $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'. If the value is null,
1351 no timing information is displayed. A trailing newline is added
1352 when the format string is displayed.
1353 TMOUT If set to a value greater than zero, TMOUT is treated as the
1354 default timeout for the read builtin. The select command termi‐
1355 nates if input does not arrive after TMOUT seconds when input is
1356 coming from a terminal. In an interactive shell, the value is
1357 interpreted as the number of seconds to wait for a line of input
1358 after issuing the primary prompt. Bash terminates after waiting
1359 for that number of seconds if a complete line of input does not
1360 arrive.
1361 TMPDIR If set, bash uses its value as the name of a directory in which
1362 bash creates temporary files for the shell's use.
1363 auto_resume
1364 This variable controls how the shell interacts with the user and
1365 job control. If this variable is set, single word simple com‐
1366 mands without redirections are treated as candidates for resump‐
1367 tion of an existing stopped job. There is no ambiguity allowed;
1368 if there is more than one job beginning with the string typed,
1369 the job most recently accessed is selected. The name of a
1370 stopped job, in this context, is the command line used to start
1371 it. If set to the value exact, the string supplied must match
1372 the name of a stopped job exactly; if set to substring, the
1373 string supplied needs to match a substring of the name of a
1374 stopped job. The substring value provides functionality analo‐
1375 gous to the %? job identifier (see JOB CONTROL below). If set
1376 to any other value, the supplied string must be a prefix of a
1377 stopped job's name; this provides functionality analogous to the
1378 %string job identifier.
1379 histchars
1380 The two or three characters which control history expansion and
1381 tokenization (see HISTORY EXPANSION below). The first character
1382 is the history expansion character, the character which signals
1383 the start of a history expansion, normally `!'. The second
1384 character is the quick substitution character, which is used as
1385 shorthand for re-running the previous command entered, substi‐
1386 tuting one string for another in the command. The default is
1387 `^'. The optional third character is the character which indi‐
1388 cates that the remainder of the line is a comment when found as
1389 the first character of a word, normally `#'. The history com‐
1390 ment character causes history substitution to be skipped for the
1391 remaining words on the line. It does not necessarily cause the
1392 shell parser to treat the rest of the line as a comment.
1393
1394 Arrays
1395 Bash provides one-dimensional indexed and associative array variables.
1396 Any variable may be used as an indexed array; the declare builtin will
1397 explicitly declare an array. There is no maximum limit on the size of
1398 an array, nor any requirement that members be indexed or assigned con‐
1399 tiguously. Indexed arrays are referenced using integers (including
1400 arithmetic expressions) and are zero-based; associative arrays are ref‐
1401 erenced using arbitrary strings. Unless otherwise noted, indexed array
1402 indices must be non-negative integers.
1403
1404 An indexed array is created automatically if any variable is assigned
1405 to using the syntax name[subscript]=value. The subscript is treated as
1406 an arithmetic expression that must evaluate to a number. To explicitly
1407 declare an indexed array, use declare -a name (see SHELL BUILTIN COM‐
1408 MANDS below). declare -a name[subscript] is also accepted; the sub‐
1409 script is ignored.
1410
1411 Associative arrays are created using declare -A name.
1412
1413 Attributes may be specified for an array variable using the declare and
1414 readonly builtins. Each attribute applies to all members of an array.
1415
1416 Arrays are assigned to using compound assignments of the form
1417 name=(value1 ... valuen), where each value is of the form [sub‐
1418 script]=string. Indexed array assignments do not require anything but
1419 string. When assigning to indexed arrays, if the optional brackets and
1420 subscript are supplied, that index is assigned to; otherwise the index
1421 of the element assigned is the last index assigned to by the statement
1422 plus one. Indexing starts at zero.
1423
1424 When assigning to an associative array, the subscript is required.
1425
1426 This syntax is also accepted by the declare builtin. Individual array
1427 elements may be assigned to using the name[subscript]=value syntax
1428 introduced above. When assigning to an indexed array, if name is sub‐
1429 scripted by a negative number, that number is interpreted as relative
1430 to one greater than the maximum index of name, so negative indices
1431 count back from the end of the array, and an index of -1 references the
1432 last element.
1433
1434 Any element of an array may be referenced using ${name[subscript]}.
1435 The braces are required to avoid conflicts with pathname expansion. If
1436 subscript is @ or *, the word expands to all members of name. These
1437 subscripts differ only when the word appears within double quotes. If
1438 the word is double-quoted, ${name[*]} expands to a single word with the
1439 value of each array member separated by the first character of the IFS
1440 special variable, and ${name[@]} expands each element of name to a sep‐
1441 arate word. When there are no array members, ${name[@]} expands to
1442 nothing. If the double-quoted expansion occurs within a word, the
1443 expansion of the first parameter is joined with the beginning part of
1444 the original word, and the expansion of the last parameter is joined
1445 with the last part of the original word. This is analogous to the
1446 expansion of the special parameters * and @ (see Special Parameters
1447 above). ${#name[subscript]} expands to the length of ${name[sub‐
1448 script]}. If subscript is * or @, the expansion is the number of ele‐
1449 ments in the array. If the subscript used to reference an element of
1450 an indexed array evaluates to a number less than zero, it is inter‐
1451 preted as relative to one greater than the maximum index of the array,
1452 so negative indices count back from the end of the array, and an index
1453 of -1 references the last element.
1454
1455 Referencing an array variable without a subscript is equivalent to ref‐
1456 erencing the array with a subscript of 0. Any reference to a variable
1457 using a valid subscript is legal, and bash will create an array if nec‐
1458 essary.
1459
1460 An array variable is considered set if a subscript has been assigned a
1461 value. The null string is a valid value.
1462
1463 It is possible to obtain the keys (indices) of an array as well as the
1464 values. ${!name[@]} and ${!name[*]} expand to the indices assigned in
1465 array variable name. The treatment when in double quotes is similar to
1466 the expansion of the special parameters @ and * within double quotes.
1467
1468 The unset builtin is used to destroy arrays. unset name[subscript]
1469 destroys the array element at index subscript, for both indexed and
1470 associative arrays. Negative subscripts to indexed arrays are inter‐
1471 preted as described above. Unsetting the last element of an array
1472 variable does not unset the variable. unset name, where name is an
1473 array, or unset name[subscript], where subscript is * or @, removes the
1474 entire array.
1475
1476 When using a variable name with a subscript as an argument to a com‐
1477 mand, such as with unset, without using the word expansion syntax
1478 described above, the argument is subject to pathname expansion. If
1479 pathname expansion is not desired, the argument should be quoted.
1480
1481 The declare, local, and readonly builtins each accept a -a option to
1482 specify an indexed array and a -A option to specify an associative
1483 array. If both options are supplied, -A takes precedence. The read
1484 builtin accepts a -a option to assign a list of words read from the
1485 standard input to an array. The set and declare builtins display array
1486 values in a way that allows them to be reused as assignments.
1487
1489 Expansion is performed on the command line after it has been split into
1490 words. There are seven kinds of expansion performed: brace expansion,
1491 tilde expansion, parameter and variable expansion, command substitu‐
1492 tion, arithmetic expansion, word splitting, and pathname expansion.
1493
1494 The order of expansions is: brace expansion; tilde expansion, parameter
1495 and variable expansion, arithmetic expansion, and command substitution
1496 (done in a left-to-right fashion); word splitting; and pathname expan‐
1497 sion.
1498
1499 On systems that can support it, there is an additional expansion avail‐
1500 able: process substitution. This is performed at the same time as
1501 tilde, parameter, variable, and arithmetic expansion and command sub‐
1502 stitution.
1503
1504 After these expansions are performed, quote characters present in the
1505 original word are removed unless they have been quoted themselves
1506 (quote removal).
1507
1508 Only brace expansion, word splitting, and pathname expansion can
1509 increase the number of words of the expansion; other expansions expand
1510 a single word to a single word. The only exceptions to this are the
1511 expansions of "$@" and "${name[@]}", and, in most cases, $* and
1512 ${name[*]} as explained above (see PARAMETERS).
1513
1514 Brace Expansion
1515 Brace expansion is a mechanism by which arbitrary strings may be gener‐
1516 ated. This mechanism is similar to pathname expansion, but the file‐
1517 names generated need not exist. Patterns to be brace expanded take the
1518 form of an optional preamble, followed by either a series of comma-sep‐
1519 arated strings or a sequence expression between a pair of braces, fol‐
1520 lowed by an optional postscript. The preamble is prefixed to each
1521 string contained within the braces, and the postscript is then appended
1522 to each resulting string, expanding left to right.
1523
1524 Brace expansions may be nested. The results of each expanded string
1525 are not sorted; left to right order is preserved. For example,
1526 a{d,c,b}e expands into `ade ace abe'.
1527
1528 A sequence expression takes the form {x..y[..incr]}, where x and y are
1529 either integers or single characters, and incr, an optional increment,
1530 is an integer. When integers are supplied, the expression expands to
1531 each number between x and y, inclusive. Supplied integers may be pre‐
1532 fixed with 0 to force each term to have the same width. When either x
1533 or y begins with a zero, the shell attempts to force all generated
1534 terms to contain the same number of digits, zero-padding where neces‐
1535 sary. When characters are supplied, the expression expands to each
1536 character lexicographically between x and y, inclusive, using the
1537 default C locale. Note that both x and y must be of the same type.
1538 When the increment is supplied, it is used as the difference between
1539 each term. The default increment is 1 or -1 as appropriate.
1540
1541 Brace expansion is performed before any other expansions, and any char‐
1542 acters special to other expansions are preserved in the result. It is
1543 strictly textual. Bash does not apply any syntactic interpretation to
1544 the context of the expansion or the text between the braces.
1545
1546 A correctly-formed brace expansion must contain unquoted opening and
1547 closing braces, and at least one unquoted comma or a valid sequence
1548 expression. Any incorrectly formed brace expansion is left unchanged.
1549 A { or , may be quoted with a backslash to prevent its being considered
1550 part of a brace expression. To avoid conflicts with parameter expan‐
1551 sion, the string ${ is not considered eligible for brace expansion, and
1552 inhibits brace expansion until the closing }.
1553
1554 This construct is typically used as shorthand when the common prefix of
1555 the strings to be generated is longer than in the above example:
1556
1557 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1558 or
1559 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1560
1561 Brace expansion introduces a slight incompatibility with historical
1562 versions of sh. sh does not treat opening or closing braces specially
1563 when they appear as part of a word, and preserves them in the output.
1564 Bash removes braces from words as a consequence of brace expansion.
1565 For example, a word entered to sh as file{1,2} appears identically in
1566 the output. The same word is output as file1 file2 after expansion by
1567 bash. If strict compatibility with sh is desired, start bash with the
1568 +B option or disable brace expansion with the +B option to the set com‐
1569 mand (see SHELL BUILTIN COMMANDS below).
1570
1571 Tilde Expansion
1572 If a word begins with an unquoted tilde character (`~'), all of the
1573 characters preceding the first unquoted slash (or all characters, if
1574 there is no unquoted slash) are considered a tilde-prefix. If none of
1575 the characters in the tilde-prefix are quoted, the characters in the
1576 tilde-prefix following the tilde are treated as a possible login name.
1577 If this login name is the null string, the tilde is replaced with the
1578 value of the shell parameter HOME. If HOME is unset, the home direc‐
1579 tory of the user executing the shell is substituted instead. Other‐
1580 wise, the tilde-prefix is replaced with the home directory associated
1581 with the specified login name.
1582
1583 If the tilde-prefix is a `~+', the value of the shell variable PWD
1584 replaces the tilde-prefix. If the tilde-prefix is a `~-', the value of
1585 the shell variable OLDPWD, if it is set, is substituted. If the char‐
1586 acters following the tilde in the tilde-prefix consist of a number N,
1587 optionally prefixed by a `+' or a `-', the tilde-prefix is replaced
1588 with the corresponding element from the directory stack, as it would be
1589 displayed by the dirs builtin invoked with the tilde-prefix as an argu‐
1590 ment. If the characters following the tilde in the tilde-prefix con‐
1591 sist of a number without a leading `+' or `-', `+' is assumed.
1592
1593 If the login name is invalid, or the tilde expansion fails, the word is
1594 unchanged.
1595
1596 Each variable assignment is checked for unquoted tilde-prefixes immedi‐
1597 ately following a : or the first =. In these cases, tilde expansion is
1598 also performed. Consequently, one may use filenames with tildes in
1599 assignments to PATH, MAILPATH, and CDPATH, and the shell assigns the
1600 expanded value.
1601
1602 Bash also performs tilde expansion on words satisfying the conditions
1603 of variable assignments (as described above under PARAMETERS) when they
1604 appear as arguments to simple commands. Bash does not do this, except
1605 for the declaration commands listed above, when in posix mode.
1606
1607 Parameter Expansion
1608 The `$' character introduces parameter expansion, command substitution,
1609 or arithmetic expansion. The parameter name or symbol to be expanded
1610 may be enclosed in braces, which are optional but serve to protect the
1611 variable to be expanded from characters immediately following it which
1612 could be interpreted as part of the name.
1613
1614 When braces are used, the matching ending brace is the first `}' not
1615 escaped by a backslash or within a quoted string, and not within an
1616 embedded arithmetic expansion, command substitution, or parameter
1617 expansion.
1618
1619 ${parameter}
1620 The value of parameter is substituted. The braces are required
1621 when parameter is a positional parameter with more than one
1622 digit, or when parameter is followed by a character which is not
1623 to be interpreted as part of its name. The parameter is a shell
1624 parameter as described above PARAMETERS) or an array reference
1625 (Arrays).
1626
1627 If the first character of parameter is an exclamation point (!), and
1628 parameter is not a nameref, it introduces a level of indirection. Bash
1629 uses the value formed by expanding the rest of parameter as the new
1630 parameter; this is then expanded and that value is used in the rest of
1631 the expansion, rather than the expansion of the original parameter.
1632 This is known as indirect expansion. The value is subject to tilde
1633 expansion, parameter expansion, command substitution, and arithmetic
1634 expansion. If parameter is a nameref, this expands to the name of the
1635 parameter referenced by parameter instead of performing the complete
1636 indirect expansion. The exceptions to this are the expansions of
1637 ${!prefix*} and ${!name[@]} described below. The exclamation point
1638 must immediately follow the left brace in order to introduce indirec‐
1639 tion.
1640
1641 In each of the cases below, word is subject to tilde expansion, parame‐
1642 ter expansion, command substitution, and arithmetic expansion.
1643
1644 When not performing substring expansion, using the forms documented
1645 below (e.g., :-), bash tests for a parameter that is unset or null.
1646 Omitting the colon results in a test only for a parameter that is
1647 unset.
1648
1649 ${parameter:-word}
1650 Use Default Values. If parameter is unset or null, the expan‐
1651 sion of word is substituted. Otherwise, the value of parameter
1652 is substituted.
1653 ${parameter:=word}
1654 Assign Default Values. If parameter is unset or null, the
1655 expansion of word is assigned to parameter. The value of param‐
1656 eter is then substituted. Positional parameters and special
1657 parameters may not be assigned to in this way.
1658 ${parameter:?word}
1659 Display Error if Null or Unset. If parameter is null or unset,
1660 the expansion of word (or a message to that effect if word is
1661 not present) is written to the standard error and the shell, if
1662 it is not interactive, exits. Otherwise, the value of parameter
1663 is substituted.
1664 ${parameter:+word}
1665 Use Alternate Value. If parameter is null or unset, nothing is
1666 substituted, otherwise the expansion of word is substituted.
1667 ${parameter:offset}
1668 ${parameter:offset:length}
1669 Substring Expansion. Expands to up to length characters of the
1670 value of parameter starting at the character specified by off‐
1671 set. If parameter is @, an indexed array subscripted by @ or *,
1672 or an associative array name, the results differ as described
1673 below. If length is omitted, expands to the substring of the
1674 value of parameter starting at the character specified by offset
1675 and extending to the end of the value. length and offset are
1676 arithmetic expressions (see ARITHMETIC EVALUATION below).
1677
1678 If offset evaluates to a number less than zero, the value is
1679 used as an offset in characters from the end of the value of
1680 parameter. If length evaluates to a number less than zero, it
1681 is interpreted as an offset in characters from the end of the
1682 value of parameter rather than a number of characters, and the
1683 expansion is the characters between offset and that result.
1684 Note that a negative offset must be separated from the colon by
1685 at least one space to avoid being confused with the :- expan‐
1686 sion.
1687
1688 If parameter is @, the result is length positional parameters
1689 beginning at offset. A negative offset is taken relative to one
1690 greater than the greatest positional parameter, so an offset of
1691 -1 evaluates to the last positional parameter. It is an expan‐
1692 sion error if length evaluates to a number less than zero.
1693
1694 If parameter is an indexed array name subscripted by @ or *, the
1695 result is the length members of the array beginning with
1696 ${parameter[offset]}. A negative offset is taken relative to
1697 one greater than the maximum index of the specified array. It
1698 is an expansion error if length evaluates to a number less than
1699 zero.
1700
1701 Substring expansion applied to an associative array produces
1702 undefined results.
1703
1704 Substring indexing is zero-based unless the positional parame‐
1705 ters are used, in which case the indexing starts at 1 by
1706 default. If offset is 0, and the positional parameters are
1707 used, $0 is prefixed to the list.
1708
1709 ${!prefix*}
1710 ${!prefix@}
1711 Names matching prefix. Expands to the names of variables whose
1712 names begin with prefix, separated by the first character of the
1713 IFS special variable. When @ is used and the expansion appears
1714 within double quotes, each variable name expands to a separate
1715 word.
1716
1717 ${!name[@]}
1718 ${!name[*]}
1719 List of array keys. If name is an array variable, expands to
1720 the list of array indices (keys) assigned in name. If name is
1721 not an array, expands to 0 if name is set and null otherwise.
1722 When @ is used and the expansion appears within double quotes,
1723 each key expands to a separate word.
1724
1725 ${#parameter}
1726 Parameter length. The length in characters of the value of
1727 parameter is substituted. If parameter is * or @, the value
1728 substituted is the number of positional parameters. If parame‐
1729 ter is an array name subscripted by * or @, the value substi‐
1730 tuted is the number of elements in the array. If parameter is
1731 an indexed array name subscripted by a negative number, that
1732 number is interpreted as relative to one greater than the maxi‐
1733 mum index of parameter, so negative indices count back from the
1734 end of the array, and an index of -1 references the last ele‐
1735 ment.
1736
1737 ${parameter#word}
1738 ${parameter##word}
1739 Remove matching prefix pattern. The word is expanded to produce
1740 a pattern just as in pathname expansion, and matched against the
1741 expanded value of parameter using the rules described under Pat‐
1742 tern Matching below. If the pattern matches the beginning of
1743 the value of parameter, then the result of the expansion is the
1744 expanded value of parameter with the shortest matching pattern
1745 (the ``#'' case) or the longest matching pattern (the ``##''
1746 case) deleted. If parameter is @ or *, the pattern removal
1747 operation is applied to each positional parameter in turn, and
1748 the expansion is the resultant list. If parameter is an array
1749 variable subscripted with @ or *, the pattern removal operation
1750 is applied to each member of the array in turn, and the expan‐
1751 sion is the resultant list.
1752
1753 ${parameter%word}
1754 ${parameter%%word}
1755 Remove matching suffix pattern. The word is expanded to produce
1756 a pattern just as in pathname expansion, and matched against the
1757 expanded value of parameter using the rules described under Pat‐
1758 tern Matching below. If the pattern matches a trailing portion
1759 of the expanded value of parameter, then the result of the
1760 expansion is the expanded value of parameter with the shortest
1761 matching pattern (the ``%'' case) or the longest matching pat‐
1762 tern (the ``%%'' case) deleted. If parameter is @ or *, the
1763 pattern removal operation is applied to each positional parame‐
1764 ter in turn, and the expansion is the resultant list. If param‐
1765 eter is an array variable subscripted with @ or *, the pattern
1766 removal operation is applied to each member of the array in
1767 turn, and the expansion is the resultant list.
1768
1769 ${parameter/pattern/string}
1770 Pattern substitution. The pattern is expanded to produce a pat‐
1771 tern just as in pathname expansion, Parameter is expanded and
1772 the longest match of pattern against its value is replaced with
1773 string. The match is performed using the rules described under
1774 Pattern Matching below. If pattern begins with /, all matches
1775 of pattern are replaced with string. Normally only the first
1776 match is replaced. If pattern begins with #, it must match at
1777 the beginning of the expanded value of parameter. If pattern
1778 begins with %, it must match at the end of the expanded value of
1779 parameter. If string is null, matches of pattern are deleted
1780 and the / following pattern may be omitted. If the nocasematch
1781 shell option is enabled, the match is performed without regard
1782 to the case of alphabetic characters. If parameter is @ or *,
1783 the substitution operation is applied to each positional parame‐
1784 ter in turn, and the expansion is the resultant list. If param‐
1785 eter is an array variable subscripted with @ or *, the substitu‐
1786 tion operation is applied to each member of the array in turn,
1787 and the expansion is the resultant list.
1788
1789 ${parameter^pattern}
1790 ${parameter^^pattern}
1791 ${parameter,pattern}
1792 ${parameter,,pattern}
1793 Case modification. This expansion modifies the case of alpha‐
1794 betic characters in parameter. The pattern is expanded to pro‐
1795 duce a pattern just as in pathname expansion. Each character in
1796 the expanded value of parameter is tested against pattern, and,
1797 if it matches the pattern, its case is converted. The pattern
1798 should not attempt to match more than one character. The ^
1799 operator converts lowercase letters matching pattern to upper‐
1800 case; the , operator converts matching uppercase letters to low‐
1801 ercase. The ^^ and ,, expansions convert each matched character
1802 in the expanded value; the ^ and , expansions match and convert
1803 only the first character in the expanded value. If pattern is
1804 omitted, it is treated like a ?, which matches every character.
1805 If parameter is @ or *, the case modification operation is
1806 applied to each positional parameter in turn, and the expansion
1807 is the resultant list. If parameter is an array variable sub‐
1808 scripted with @ or *, the case modification operation is applied
1809 to each member of the array in turn, and the expansion is the
1810 resultant list.
1811
1812 ${parameter@operator}
1813 Parameter transformation. The expansion is either a transforma‐
1814 tion of the value of parameter or information about parameter
1815 itself, depending on the value of operator. Each operator is a
1816 single letter:
1817
1818 Q The expansion is a string that is the value of parameter
1819 quoted in a format that can be reused as input.
1820 E The expansion is a string that is the value of parameter
1821 with backslash escape sequences expanded as with the
1822 $'...' quoting mechanism.
1823 P The expansion is a string that is the result of expanding
1824 the value of parameter as if it were a prompt string (see
1825 PROMPTING below).
1826 A The expansion is a string in the form of an assignment
1827 statement or declare command that, if evaluated, will
1828 recreate parameter with its attributes and value.
1829 a The expansion is a string consisting of flag values rep‐
1830 resenting parameter's attributes.
1831
1832 If parameter is @ or *, the operation is applied to each posi‐
1833 tional parameter in turn, and the expansion is the resultant
1834 list. If parameter is an array variable subscripted with @ or
1835 *, the operation is applied to each member of the array in turn,
1836 and the expansion is the resultant list.
1837
1838 The result of the expansion is subject to word splitting and
1839 pathname expansion as described below.
1840
1841 Command Substitution
1842 Command substitution allows the output of a command to replace the com‐
1843 mand name. There are two forms:
1844
1845 $(command)
1846 or
1847 `command`
1848
1849 Bash performs the expansion by executing command in a subshell environ‐
1850 ment and replacing the command substitution with the standard output of
1851 the command, with any trailing newlines deleted. Embedded newlines are
1852 not deleted, but they may be removed during word splitting. The com‐
1853 mand substitution $(cat file) can be replaced by the equivalent but
1854 faster $(< file).
1855
1856 When the old-style backquote form of substitution is used, backslash
1857 retains its literal meaning except when followed by $, `, or \. The
1858 first backquote not preceded by a backslash terminates the command sub‐
1859 stitution. When using the $(command) form, all characters between the
1860 parentheses make up the command; none are treated specially.
1861
1862 Command substitutions may be nested. To nest when using the backquoted
1863 form, escape the inner backquotes with backslashes.
1864
1865 If the substitution appears within double quotes, word splitting and
1866 pathname expansion are not performed on the results.
1867
1868 Arithmetic Expansion
1869 Arithmetic expansion allows the evaluation of an arithmetic expression
1870 and the substitution of the result. The format for arithmetic expan‐
1871 sion is:
1872
1873 $((expression))
1874
1875 The expression is treated as if it were within double quotes, but a
1876 double quote inside the parentheses is not treated specially. All
1877 tokens in the expression undergo parameter and variable expansion, com‐
1878 mand substitution, and quote removal. The result is treated as the
1879 arithmetic expression to be evaluated. Arithmetic expansions may be
1880 nested.
1881
1882 The evaluation is performed according to the rules listed below under
1883 ARITHMETIC EVALUATION. If expression is invalid, bash prints a message
1884 indicating failure and no substitution occurs.
1885
1886 Process Substitution
1887 Process substitution allows a process's input or output to be referred
1888 to using a filename. It takes the form of <(list) or >(list). The
1889 process list is run asynchronously, and its input or output appears as
1890 a filename. This filename is passed as an argument to the current com‐
1891 mand as the result of the expansion. If the >(list) form is used,
1892 writing to the file will provide input for list. If the <(list) form
1893 is used, the file passed as an argument should be read to obtain the
1894 output of list. Process substitution is supported on systems that sup‐
1895 port named pipes (FIFOs) or the /dev/fd method of naming open files.
1896
1897 When available, process substitution is performed simultaneously with
1898 parameter and variable expansion, command substitution, and arithmetic
1899 expansion.
1900
1901 Word Splitting
1902 The shell scans the results of parameter expansion, command substitu‐
1903 tion, and arithmetic expansion that did not occur within double quotes
1904 for word splitting.
1905
1906 The shell treats each character of IFS as a delimiter, and splits the
1907 results of the other expansions into words using these characters as
1908 field terminators. If IFS is unset, or its value is exactly
1909 <space><tab><newline>, the default, then sequences of <space>, <tab>,
1910 and <newline> at the beginning and end of the results of the previous
1911 expansions are ignored, and any sequence of IFS characters not at the
1912 beginning or end serves to delimit words. If IFS has a value other
1913 than the default, then sequences of the whitespace characters space,
1914 tab, and newline are ignored at the beginning and end of the word, as
1915 long as the whitespace character is in the value of IFS (an IFS white‐
1916 space character). Any character in IFS that is not IFS whitespace,
1917 along with any adjacent IFS whitespace characters, delimits a field. A
1918 sequence of IFS whitespace characters is also treated as a delimiter.
1919 If the value of IFS is null, no word splitting occurs.
1920
1921 Explicit null arguments ("" or '') are retained and passed to commands
1922 as empty strings. Unquoted implicit null arguments, resulting from the
1923 expansion of parameters that have no values, are removed. If a parame‐
1924 ter with no value is expanded within double quotes, a null argument
1925 results and is retained and passed to a command as an empty string.
1926 When a quoted null argument appears as part of a word whose expansion
1927 is non-null, the null argument is removed. That is, the word -d''
1928 becomes -d after word splitting and null argument removal.
1929
1930 Note that if no expansion occurs, no splitting is performed.
1931
1932 Pathname Expansion
1933 After word splitting, unless the -f option has been set, bash scans
1934 each word for the characters *, ?, and [. If one of these characters
1935 appears, then the word is regarded as a pattern, and replaced with an
1936 alphabetically sorted list of filenames matching the pattern (see Pat‐
1937 tern Matching below). If no matching filenames are found, and the
1938 shell option nullglob is not enabled, the word is left unchanged. If
1939 the nullglob option is set, and no matches are found, the word is
1940 removed. If the failglob shell option is set, and no matches are
1941 found, an error message is printed and the command is not executed. If
1942 the shell option nocaseglob is enabled, the match is performed without
1943 regard to the case of alphabetic characters. When a pattern is used
1944 for pathname expansion, the character ``.'' at the start of a name or
1945 immediately following a slash must be matched explicitly, unless the
1946 shell option dotglob is set. The filenames ``.'' and ``..'' must
1947 always be matched explicitly, even if dotglob is set. In other cases,
1948 the ``.'' character is not treated specially. When matching a path‐
1949 name, the slash character must always be matched explicitly by a slash
1950 in the pattern, but in other matching contexts it can be matched by a
1951 special pattern character as described below under Pattern Matching.
1952 See the description of shopt below under SHELL BUILTIN COMMANDS for a
1953 description of the nocaseglob, nullglob, failglob, and dotglob shell
1954 options.
1955
1956 The GLOBIGNORE shell variable may be used to restrict the set of file
1957 names matching a pattern. If GLOBIGNORE is set, each matching file
1958 name that also matches one of the patterns in GLOBIGNORE is removed
1959 from the list of matches. If the nocaseglob option is set, the match‐
1960 ing against the patterns in GLOBIGNORE is performed without regard to
1961 case. The filenames ``.'' and ``..'' are always ignored when GLOBIG‐
1962 NORE is set and not null. However, setting GLOBIGNORE to a non-null
1963 value has the effect of enabling the dotglob shell option, so all other
1964 filenames beginning with a ``.'' will match. To get the old behavior
1965 of ignoring filenames beginning with a ``.'', make ``.*'' one of the
1966 patterns in GLOBIGNORE. The dotglob option is disabled when GLOBIGNORE
1967 is unset. The pattern matching honors the setting of the extglob shell
1968 option.
1969
1970 Pattern Matching
1971
1972 Any character that appears in a pattern, other than the special pattern
1973 characters described below, matches itself. The NUL character may not
1974 occur in a pattern. A backslash escapes the following character; the
1975 escaping backslash is discarded when matching. The special pattern
1976 characters must be quoted if they are to be matched literally.
1977
1978 The special pattern characters have the following meanings:
1979
1980 * Matches any string, including the null string. When the
1981 globstar shell option is enabled, and * is used in a
1982 pathname expansion context, two adjacent *s used as a
1983 single pattern will match all files and zero or more
1984 directories and subdirectories. If followed by a /, two
1985 adjacent *s will match only directories and subdirecto‐
1986 ries.
1987 ? Matches any single character.
1988 [...] Matches any one of the enclosed characters. A pair of
1989 characters separated by a hyphen denotes a range expres‐
1990 sion; any character that falls between those two charac‐
1991 ters, inclusive, using the current locale's collating
1992 sequence and character set, is matched. If the first
1993 character following the [ is a ! or a ^ then any charac‐
1994 ter not enclosed is matched. The sorting order of char‐
1995 acters in range expressions is determined by the current
1996 locale and the values of the LC_COLLATE or LC_ALL shell
1997 variables, if set. To obtain the traditional interpreta‐
1998 tion of range expressions, where [a-d] is equivalent to
1999 [abcd], set value of the LC_ALL shell variable to C, or
2000 enable the globasciiranges shell option. A - may be
2001 matched by including it as the first or last character in
2002 the set. A ] may be matched by including it as the first
2003 character in the set.
2004
2005 Within [ and ], character classes can be specified using
2006 the syntax [:class:], where class is one of the following
2007 classes defined in the POSIX standard:
2008 alnum alpha ascii blank cntrl digit graph lower print
2009 punct space upper word xdigit
2010 A character class matches any character belonging to that
2011 class. The word character class matches letters, digits,
2012 and the character _.
2013
2014 Within [ and ], an equivalence class can be specified
2015 using the syntax [=c=], which matches all characters with
2016 the same collation weight (as defined by the current
2017 locale) as the character c.
2018
2019 Within [ and ], the syntax [.symbol.] matches the collat‐
2020 ing symbol symbol.
2021
2022 If the extglob shell option is enabled using the shopt builtin, several
2023 extended pattern matching operators are recognized. In the following
2024 description, a pattern-list is a list of one or more patterns separated
2025 by a |. Composite patterns may be formed using one or more of the fol‐
2026 lowing sub-patterns:
2027
2028 ?(pattern-list)
2029 Matches zero or one occurrence of the given patterns
2030 *(pattern-list)
2031 Matches zero or more occurrences of the given patterns
2032 +(pattern-list)
2033 Matches one or more occurrences of the given patterns
2034 @(pattern-list)
2035 Matches one of the given patterns
2036 !(pattern-list)
2037 Matches anything except one of the given patterns
2038
2039 Complicated extended pattern matching against long strings is slow,
2040 especially when the patterns contain alternations and the strings con‐
2041 tain multiple matches. Using separate matches against shorter strings,
2042 or using arrays of strings instead of a single long string, may be
2043 faster.
2044
2045 Quote Removal
2046 After the preceding expansions, all unquoted occurrences of the charac‐
2047 ters \, ', and " that did not result from one of the above expansions
2048 are removed.
2049
2051 Before a command is executed, its input and output may be redirected
2052 using a special notation interpreted by the shell. Redirection allows
2053 commands' file handles to be duplicated, opened, closed, made to refer
2054 to different files, and can change the files the command reads from and
2055 writes to. Redirection may also be used to modify file handles in the
2056 current shell execution environment. The following redirection opera‐
2057 tors may precede or appear anywhere within a simple command or may fol‐
2058 low a command. Redirections are processed in the order they appear,
2059 from left to right.
2060
2061 Each redirection that may be preceded by a file descriptor number may
2062 instead be preceded by a word of the form {varname}. In this case, for
2063 each redirection operator except >&- and <&-, the shell will allocate a
2064 file descriptor greater than or equal to 10 and assign it to varname.
2065 If >&- or <&- is preceded by {varname}, the value of varname defines
2066 the file descriptor to close. If {varname} is supplied, the redirect‐
2067 ion persists beyond the scope of the command, allowing the shell pro‐
2068 grammer to manage the file descriptor himself.
2069
2070 In the following descriptions, if the file descriptor number is omit‐
2071 ted, and the first character of the redirection operator is <, the re‐
2072 direction refers to the standard input (file descriptor 0). If the
2073 first character of the redirection operator is >, the redirection
2074 refers to the standard output (file descriptor 1).
2075
2076 The word following the redirection operator in the following descrip‐
2077 tions, unless otherwise noted, is subjected to brace expansion, tilde
2078 expansion, parameter and variable expansion, command substitution,
2079 arithmetic expansion, quote removal, pathname expansion, and word
2080 splitting. If it expands to more than one word, bash reports an error.
2081
2082 Note that the order of redirections is significant. For example, the
2083 command
2084
2085 ls > dirlist 2>&1
2086
2087 directs both standard output and standard error to the file dirlist,
2088 while the command
2089
2090 ls 2>&1 > dirlist
2091
2092 directs only the standard output to file dirlist, because the standard
2093 error was duplicated from the standard output before the standard out‐
2094 put was redirected to dirlist.
2095
2096 Bash handles several filenames specially when they are used in redirec‐
2097 tions, as described in the following table. If the operating system on
2098 which bash is running provides these special files, bash will use them;
2099 otherwise it will emulate them internally with the behavior described
2100 below.
2101
2102 /dev/fd/fd
2103 If fd is a valid integer, file descriptor fd is dupli‐
2104 cated.
2105 /dev/stdin
2106 File descriptor 0 is duplicated.
2107 /dev/stdout
2108 File descriptor 1 is duplicated.
2109 /dev/stderr
2110 File descriptor 2 is duplicated.
2111 /dev/tcp/host/port
2112 If host is a valid hostname or Internet address, and port
2113 is an integer port number or service name, bash attempts
2114 to open the corresponding TCP socket.
2115 /dev/udp/host/port
2116 If host is a valid hostname or Internet address, and port
2117 is an integer port number or service name, bash attempts
2118 to open the corresponding UDP socket.
2119
2120 A failure to open or create a file causes the redirection to fail.
2121
2122 Redirections using file descriptors greater than 9 should be used with
2123 care, as they may conflict with file descriptors the shell uses inter‐
2124 nally.
2125
2126 Redirecting Input
2127 Redirection of input causes the file whose name results from the expan‐
2128 sion of word to be opened for reading on file descriptor n, or the
2129 standard input (file descriptor 0) if n is not specified.
2130
2131 The general format for redirecting input is:
2132
2133 [n]<word
2134
2135 Redirecting Output
2136 Redirection of output causes the file whose name results from the
2137 expansion of word to be opened for writing on file descriptor n, or the
2138 standard output (file descriptor 1) if n is not specified. If the file
2139 does not exist it is created; if it does exist it is truncated to zero
2140 size.
2141
2142 The general format for redirecting output is:
2143
2144 [n]>word
2145
2146 If the redirection operator is >, and the noclobber option to the set
2147 builtin has been enabled, the redirection will fail if the file whose
2148 name results from the expansion of word exists and is a regular file.
2149 If the redirection operator is >|, or the redirection operator is > and
2150 the noclobber option to the set builtin command is not enabled, the re‐
2151 direction is attempted even if the file named by word exists.
2152
2153 Appending Redirected Output
2154 Redirection of output in this fashion causes the file whose name
2155 results from the expansion of word to be opened for appending on file
2156 descriptor n, or the standard output (file descriptor 1) if n is not
2157 specified. If the file does not exist it is created.
2158
2159 The general format for appending output is:
2160
2161 [n]>>word
2162
2163 Redirecting Standard Output and Standard Error
2164 This construct allows both the standard output (file descriptor 1) and
2165 the standard error output (file descriptor 2) to be redirected to the
2166 file whose name is the expansion of word.
2167
2168 There are two formats for redirecting standard output and standard
2169 error:
2170
2171 &>word
2172 and
2173 >&word
2174
2175 Of the two forms, the first is preferred. This is semantically equiva‐
2176 lent to
2177
2178 >word 2>&1
2179
2180 When using the second form, word may not expand to a number or -. If
2181 it does, other redirection operators apply (see Duplicating File
2182 Descriptors below) for compatibility reasons.
2183
2184 Appending Standard Output and Standard Error
2185 This construct allows both the standard output (file descriptor 1) and
2186 the standard error output (file descriptor 2) to be appended to the
2187 file whose name is the expansion of word.
2188
2189 The format for appending standard output and standard error is:
2190
2191 &>>word
2192
2193 This is semantically equivalent to
2194
2195 >>word 2>&1
2196
2197 (see Duplicating File Descriptors below).
2198
2199 Here Documents
2200 This type of redirection instructs the shell to read input from the
2201 current source until a line containing only delimiter (with no trailing
2202 blanks) is seen. All of the lines read up to that point are then used
2203 as the standard input (or file descriptor n if n is specified) for a
2204 command.
2205
2206 The format of here-documents is:
2207
2208 [n]<<[-]word
2209 here-document
2210 delimiter
2211
2212 No parameter and variable expansion, command substitution, arithmetic
2213 expansion, or pathname expansion is performed on word. If any part of
2214 word is quoted, the delimiter is the result of quote removal on word,
2215 and the lines in the here-document are not expanded. If word is
2216 unquoted, all lines of the here-document are subjected to parameter
2217 expansion, command substitution, and arithmetic expansion, the charac‐
2218 ter sequence \<newline> is ignored, and \ must be used to quote the
2219 characters \, $, and `.
2220
2221 If the redirection operator is <<-, then all leading tab characters are
2222 stripped from input lines and the line containing delimiter. This
2223 allows here-documents within shell scripts to be indented in a natural
2224 fashion.
2225
2226 Here Strings
2227 A variant of here documents, the format is:
2228
2229 [n]<<<word
2230
2231 The word undergoes tilde expansion, parameter and variable expansion,
2232 command substitution, arithmetic expansion, and quote removal. Path‐
2233 name expansion and word splitting are not performed. The result is
2234 supplied as a single string, with a newline appended, to the command on
2235 its standard input (or file descriptor n if n is specified).
2236
2237 Duplicating File Descriptors
2238 The redirection operator
2239
2240 [n]<&word
2241
2242 is used to duplicate input file descriptors. If word expands to one or
2243 more digits, the file descriptor denoted by n is made to be a copy of
2244 that file descriptor. If the digits in word do not specify a file
2245 descriptor open for input, a redirection error occurs. If word evalu‐
2246 ates to -, file descriptor n is closed. If n is not specified, the
2247 standard input (file descriptor 0) is used.
2248
2249 The operator
2250
2251 [n]>&word
2252
2253 is used similarly to duplicate output file descriptors. If n is not
2254 specified, the standard output (file descriptor 1) is used. If the
2255 digits in word do not specify a file descriptor open for output, a re‐
2256 direction error occurs. If word evaluates to -, file descriptor n is
2257 closed. As a special case, if n is omitted, and word does not expand
2258 to one or more digits or -, the standard output and standard error are
2259 redirected as described previously.
2260
2261 Moving File Descriptors
2262 The redirection operator
2263
2264 [n]<&digit-
2265
2266 moves the file descriptor digit to file descriptor n, or the standard
2267 input (file descriptor 0) if n is not specified. digit is closed after
2268 being duplicated to n.
2269
2270 Similarly, the redirection operator
2271
2272 [n]>&digit-
2273
2274 moves the file descriptor digit to file descriptor n, or the standard
2275 output (file descriptor 1) if n is not specified.
2276
2277 Opening File Descriptors for Reading and Writing
2278 The redirection operator
2279
2280 [n]<>word
2281
2282 causes the file whose name is the expansion of word to be opened for
2283 both reading and writing on file descriptor n, or on file descriptor 0
2284 if n is not specified. If the file does not exist, it is created.
2285
2287 Aliases allow a string to be substituted for a word when it is used as
2288 the first word of a simple command. The shell maintains a list of
2289 aliases that may be set and unset with the alias and unalias builtin
2290 commands (see SHELL BUILTIN COMMANDS below). The first word of each
2291 simple command, if unquoted, is checked to see if it has an alias. If
2292 so, that word is replaced by the text of the alias. The characters /,
2293 $, `, and = and any of the shell metacharacters or quoting characters
2294 listed above may not appear in an alias name. The replacement text may
2295 contain any valid shell input, including shell metacharacters. The
2296 first word of the replacement text is tested for aliases, but a word
2297 that is identical to an alias being expanded is not expanded a second
2298 time. This means that one may alias ls to ls -F, for instance, and
2299 bash does not try to recursively expand the replacement text. If the
2300 last character of the alias value is a blank, then the next command
2301 word following the alias is also checked for alias expansion.
2302
2303 Aliases are created and listed with the alias command, and removed with
2304 the unalias command.
2305
2306 There is no mechanism for using arguments in the replacement text. If
2307 arguments are needed, a shell function should be used (see FUNCTIONS
2308 below).
2309
2310 Aliases are not expanded when the shell is not interactive, unless the
2311 expand_aliases shell option is set using shopt (see the description of
2312 shopt under SHELL BUILTIN COMMANDS below).
2313
2314 The rules concerning the definition and use of aliases are somewhat
2315 confusing. Bash always reads at least one complete line of input, and
2316 all lines that make up a compound command, before executing any of the
2317 commands on that line or the compound command. Aliases are expanded
2318 when a command is read, not when it is executed. Therefore, an alias
2319 definition appearing on the same line as another command does not take
2320 effect until the next line of input is read. The commands following
2321 the alias definition on that line are not affected by the new alias.
2322 This behavior is also an issue when functions are executed. Aliases
2323 are expanded when a function definition is read, not when the function
2324 is executed, because a function definition is itself a command. As a
2325 consequence, aliases defined in a function are not available until
2326 after that function is executed. To be safe, always put alias defini‐
2327 tions on a separate line, and do not use alias in compound commands.
2328
2329 For almost every purpose, aliases are superseded by shell functions.
2330
2332 A shell function, defined as described above under SHELL GRAMMAR,
2333 stores a series of commands for later execution. When the name of a
2334 shell function is used as a simple command name, the list of commands
2335 associated with that function name is executed. Functions are executed
2336 in the context of the current shell; no new process is created to
2337 interpret them (contrast this with the execution of a shell script).
2338 When a function is executed, the arguments to the function become the
2339 positional parameters during its execution. The special parameter # is
2340 updated to reflect the change. Special parameter 0 is unchanged. The
2341 first element of the FUNCNAME variable is set to the name of the func‐
2342 tion while the function is executing.
2343
2344 All other aspects of the shell execution environment are identical
2345 between a function and its caller with these exceptions: the DEBUG and
2346 RETURN traps (see the description of the trap builtin under SHELL
2347 BUILTIN COMMANDS below) are not inherited unless the function has been
2348 given the trace attribute (see the description of the declare builtin
2349 below) or the -o functrace shell option has been enabled with the set
2350 builtin (in which case all functions inherit the DEBUG and RETURN
2351 traps), and the ERR trap is not inherited unless the -o errtrace shell
2352 option has been enabled.
2353
2354 Variables local to the function may be declared with the local builtin
2355 command. Ordinarily, variables and their values are shared between the
2356 function and its caller. If a variable is declared local, the vari‐
2357 able's visible scope is restricted to that function and its children
2358 (including the functions it calls). Local variables "shadow" variables
2359 with the same name declared at previous scopes. For instance, a local
2360 variable declared in a function hides a global variable of the same
2361 name: references and assignments refer to the local variable, leaving
2362 the global variable unmodified. When the function returns, the global
2363 variable is once again visible.
2364
2365 The shell uses dynamic scoping to control a variable's visibility
2366 within functions. With dynamic scoping, visible variables and their
2367 values are a result of the sequence of function calls that caused exe‐
2368 cution to reach the current function. The value of a variable that a
2369 function sees depends on its value within its caller, if any, whether
2370 that caller is the "global" scope or another shell function. This is
2371 also the value that a local variable declaration "shadows", and the
2372 value that is restored when the function returns.
2373
2374 For example, if a variable var is declared as local in function func1,
2375 and func1 calls another function func2, references to var made from
2376 within func2 will resolve to the local variable var from func1, shadow‐
2377 ing any global variable named var.
2378
2379 The unset builtin also acts using the same dynamic scope: if a variable
2380 is local to the current scope, unset will unset it; otherwise the unset
2381 will refer to the variable found in any calling scope as described
2382 above. If a variable at the current local scope is unset, it will
2383 remain so until it is reset in that scope or until the function
2384 returns. Once the function returns, any instance of the variable at a
2385 previous scope will become visible. If the unset acts on a variable at
2386 a previous scope, any instance of a variable with that name that had
2387 been shadowed will become visible.
2388
2389 The FUNCNEST variable, if set to a numeric value greater than 0,
2390 defines a maximum function nesting level. Function invocations that
2391 exceed the limit cause the entire command to abort.
2392
2393 If the builtin command return is executed in a function, the function
2394 completes and execution resumes with the next command after the func‐
2395 tion call. Any command associated with the RETURN trap is executed
2396 before execution resumes. When a function completes, the values of the
2397 positional parameters and the special parameter # are restored to the
2398 values they had prior to the function's execution.
2399
2400 Function names and definitions may be listed with the -f option to the
2401 declare or typeset builtin commands. The -F option to declare or type‐
2402 set will list the function names only (and optionally the source file
2403 and line number, if the extdebug shell option is enabled). Functions
2404 may be exported so that subshells automatically have them defined with
2405 the -f option to the export builtin. A function definition may be
2406 deleted using the -f option to the unset builtin.
2407
2408 Functions may be recursive. The FUNCNEST variable may be used to limit
2409 the depth of the function call stack and restrict the number of func‐
2410 tion invocations. By default, no limit is imposed on the number of
2411 recursive calls.
2412
2414 The shell allows arithmetic expressions to be evaluated, under certain
2415 circumstances (see the let and declare builtin commands, the (( com‐
2416 pound command, and Arithmetic Expansion). Evaluation is done in fixed-
2417 width integers with no check for overflow, though division by 0 is
2418 trapped and flagged as an error. The operators and their precedence,
2419 associativity, and values are the same as in the C language. The fol‐
2420 lowing list of operators is grouped into levels of equal-precedence
2421 operators. The levels are listed in order of decreasing precedence.
2422
2423 id++ id--
2424 variable post-increment and post-decrement
2425 - + unary minus and plus
2426 ++id --id
2427 variable pre-increment and pre-decrement
2428 ! ~ logical and bitwise negation
2429 ** exponentiation
2430 * / % multiplication, division, remainder
2431 + - addition, subtraction
2432 << >> left and right bitwise shifts
2433 <= >= < >
2434 comparison
2435 == != equality and inequality
2436 & bitwise AND
2437 ^ bitwise exclusive OR
2438 | bitwise OR
2439 && logical AND
2440 || logical OR
2441 expr?expr:expr
2442 conditional operator
2443 = *= /= %= += -= <<= >>= &= ^= |=
2444 assignment
2445 expr1 , expr2
2446 comma
2447
2448 Shell variables are allowed as operands; parameter expansion is per‐
2449 formed before the expression is evaluated. Within an expression, shell
2450 variables may also be referenced by name without using the parameter
2451 expansion syntax. A shell variable that is null or unset evaluates to
2452 0 when referenced by name without using the parameter expansion syntax.
2453 The value of a variable is evaluated as an arithmetic expression when
2454 it is referenced, or when a variable which has been given the integer
2455 attribute using declare -i is assigned a value. A null value evaluates
2456 to 0. A shell variable need not have its integer attribute turned on
2457 to be used in an expression.
2458
2459 Constants with a leading 0 are interpreted as octal numbers. A leading
2460 0x or 0X denotes hexadecimal. Otherwise, numbers take the form
2461 [base#]n, where the optional base is a decimal number between 2 and 64
2462 representing the arithmetic base, and n is a number in that base. If
2463 base# is omitted, then base 10 is used. When specifying n, the digits
2464 greater than 9 are represented by the lowercase letters, the uppercase
2465 letters, @, and _, in that order. If base is less than or equal to 36,
2466 lowercase and uppercase letters may be used interchangeably to repre‐
2467 sent numbers between 10 and 35.
2468
2469 Operators are evaluated in order of precedence. Sub-expressions in
2470 parentheses are evaluated first and may override the precedence rules
2471 above.
2472
2474 Conditional expressions are used by the [[ compound command and the
2475 test and [ builtin commands to test file attributes and perform string
2476 and arithmetic comparisons. The test abd [ commands determine their
2477 behavior based on the number of arguments; see the descriptions of
2478 those commands for any other command-specific actions.
2479
2480 Expressions are formed from the following unary or binary primaries.
2481 Bash handles several filenames specially when they are used in expres‐
2482 sions. If the operating system on which bash is running provides these
2483 special files, bash will use them; otherwise it will emulate them
2484 internally with this behavior: If any file argument to one of the pri‐
2485 maries is of the form /dev/fd/n, then file descriptor n is checked. If
2486 the file argument to one of the primaries is one of /dev/stdin,
2487 /dev/stdout, or /dev/stderr, file descriptor 0, 1, or 2, respectively,
2488 is checked.
2489
2490 Unless otherwise specified, primaries that operate on files follow sym‐
2491 bolic links and operate on the target of the link, rather than the link
2492 itself.
2493
2494 When used with [[, the < and > operators sort lexicographically using
2495 the current locale. The test command sorts using ASCII ordering.
2496
2497 -a file
2498 True if file exists.
2499 -b file
2500 True if file exists and is a block special file.
2501 -c file
2502 True if file exists and is a character special file.
2503 -d file
2504 True if file exists and is a directory.
2505 -e file
2506 True if file exists.
2507 -f file
2508 True if file exists and is a regular file.
2509 -g file
2510 True if file exists and is set-group-id.
2511 -h file
2512 True if file exists and is a symbolic link.
2513 -k file
2514 True if file exists and its ``sticky'' bit is set.
2515 -p file
2516 True if file exists and is a named pipe (FIFO).
2517 -r file
2518 True if file exists and is readable.
2519 -s file
2520 True if file exists and has a size greater than zero.
2521 -t fd True if file descriptor fd is open and refers to a terminal.
2522 -u file
2523 True if file exists and its set-user-id bit is set.
2524 -w file
2525 True if file exists and is writable.
2526 -x file
2527 True if file exists and is executable.
2528 -G file
2529 True if file exists and is owned by the effective group id.
2530 -L file
2531 True if file exists and is a symbolic link.
2532 -N file
2533 True if file exists and has been modified since it was last
2534 read.
2535 -O file
2536 True if file exists and is owned by the effective user id.
2537 -S file
2538 True if file exists and is a socket.
2539 file1 -ef file2
2540 True if file1 and file2 refer to the same device and inode num‐
2541 bers.
2542 file1 -nt file2
2543 True if file1 is newer (according to modification date) than
2544 file2, or if file1 exists and file2 does not.
2545 file1 -ot file2
2546 True if file1 is older than file2, or if file2 exists and file1
2547 does not.
2548 -o optname
2549 True if the shell option optname is enabled. See the list of
2550 options under the description of the -o option to the set
2551 builtin below.
2552 -v varname
2553 True if the shell variable varname is set (has been assigned a
2554 value).
2555 -R varname
2556 True if the shell variable varname is set and is a name refer‐
2557 ence.
2558 -z string
2559 True if the length of string is zero.
2560 string
2561 -n string
2562 True if the length of string is non-zero.
2563
2564 string1 == string2
2565 string1 = string2
2566 True if the strings are equal. = should be used with the test
2567 command for POSIX conformance. When used with the [[ command,
2568 this performs pattern matching as described above (Compound Com‐
2569 mands).
2570
2571 string1 != string2
2572 True if the strings are not equal.
2573
2574 string1 < string2
2575 True if string1 sorts before string2 lexicographically.
2576
2577 string1 > string2
2578 True if string1 sorts after string2 lexicographically.
2579
2580 arg1 OP arg2
2581 OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic
2582 binary operators return true if arg1 is equal to, not equal to,
2583 less than, less than or equal to, greater than, or greater than
2584 or equal to arg2, respectively. Arg1 and arg2 may be positive
2585 or negative integers. When used with the [[ command, Arg1 and
2586 Arg2 are evaluated as arithmetic expressions (see ARITHMETIC
2587 EVALUATION above).
2588
2590 When a simple command is executed, the shell performs the following
2591 expansions, assignments, and redirections, from left to right.
2592
2593 1. The words that the parser has marked as variable assignments
2594 (those preceding the command name) and redirections are saved
2595 for later processing.
2596
2597 2. The words that are not variable assignments or redirections are
2598 expanded. If any words remain after expansion, the first word
2599 is taken to be the name of the command and the remaining words
2600 are the arguments.
2601
2602 3. Redirections are performed as described above under REDIRECTION.
2603
2604 4. The text after the = in each variable assignment undergoes tilde
2605 expansion, parameter expansion, command substitution, arithmetic
2606 expansion, and quote removal before being assigned to the vari‐
2607 able.
2608
2609 If no command name results, the variable assignments affect the current
2610 shell environment. Otherwise, the variables are added to the environ‐
2611 ment of the executed command and do not affect the current shell envi‐
2612 ronment. If any of the assignments attempts to assign a value to a
2613 readonly variable, an error occurs, and the command exits with a non-
2614 zero status.
2615
2616 If no command name results, redirections are performed, but do not
2617 affect the current shell environment. A redirection error causes the
2618 command to exit with a non-zero status.
2619
2620 If there is a command name left after expansion, execution proceeds as
2621 described below. Otherwise, the command exits. If one of the expan‐
2622 sions contained a command substitution, the exit status of the command
2623 is the exit status of the last command substitution performed. If
2624 there were no command substitutions, the command exits with a status of
2625 zero.
2626
2628 After a command has been split into words, if it results in a simple
2629 command and an optional list of arguments, the following actions are
2630 taken.
2631
2632 If the command name contains no slashes, the shell attempts to locate
2633 it. If there exists a shell function by that name, that function is
2634 invoked as described above in FUNCTIONS. If the name does not match a
2635 function, the shell searches for it in the list of shell builtins. If
2636 a match is found, that builtin is invoked.
2637
2638 If the name is neither a shell function nor a builtin, and contains no
2639 slashes, bash searches each element of the PATH for a directory con‐
2640 taining an executable file by that name. Bash uses a hash table to
2641 remember the full pathnames of executable files (see hash under SHELL
2642 BUILTIN COMMANDS below). A full search of the directories in PATH is
2643 performed only if the command is not found in the hash table. If the
2644 search is unsuccessful, the shell searches for a defined shell function
2645 named command_not_found_handle. If that function exists, it is invoked
2646 in a separate execution environment with the original command and the
2647 original command's arguments as its arguments, and the function's exit
2648 status becomes the exit status of that subshell. If that function is
2649 not defined, the shell prints an error message and returns an exit sta‐
2650 tus of 127.
2651
2652 If the search is successful, or if the command name contains one or
2653 more slashes, the shell executes the named program in a separate execu‐
2654 tion environment. Argument 0 is set to the name given, and the remain‐
2655 ing arguments to the command are set to the arguments given, if any.
2656
2657 If this execution fails because the file is not in executable format,
2658 and the file is not a directory, it is assumed to be a shell script, a
2659 file containing shell commands. A subshell is spawned to execute it.
2660 This subshell reinitializes itself, so that the effect is as if a new
2661 shell had been invoked to handle the script, with the exception that
2662 the locations of commands remembered by the parent (see hash below
2663 under SHELL BUILTIN COMMANDS) are retained by the child.
2664
2665 If the program is a file beginning with #!, the remainder of the first
2666 line specifies an interpreter for the program. The shell executes the
2667 specified interpreter on operating systems that do not handle this exe‐
2668 cutable format themselves. The arguments to the interpreter consist of
2669 a single optional argument following the interpreter name on the first
2670 line of the program, followed by the name of the program, followed by
2671 the command arguments, if any.
2672
2674 The shell has an execution environment, which consists of the follow‐
2675 ing:
2676
2677 · open files inherited by the shell at invocation, as modified by
2678 redirections supplied to the exec builtin
2679
2680 · the current working directory as set by cd, pushd, or popd, or
2681 inherited by the shell at invocation
2682
2683 · the file creation mode mask as set by umask or inherited from
2684 the shell's parent
2685
2686 · current traps set by trap
2687
2688 · shell parameters that are set by variable assignment or with set
2689 or inherited from the shell's parent in the environment
2690
2691 · shell functions defined during execution or inherited from the
2692 shell's parent in the environment
2693
2694 · options enabled at invocation (either by default or with com‐
2695 mand-line arguments) or by set
2696
2697 · options enabled by shopt
2698
2699 · shell aliases defined with alias
2700
2701 · various process IDs, including those of background jobs, the
2702 value of $$, and the value of PPID
2703
2704 When a simple command other than a builtin or shell function is to be
2705 executed, it is invoked in a separate execution environment that con‐
2706 sists of the following. Unless otherwise noted, the values are inher‐
2707 ited from the shell.
2708
2709
2710 · the shell's open files, plus any modifications and additions
2711 specified by redirections to the command
2712
2713 · the current working directory
2714
2715 · the file creation mode mask
2716
2717 · shell variables and functions marked for export, along with
2718 variables exported for the command, passed in the environment
2719
2720 · traps caught by the shell are reset to the values inherited from
2721 the shell's parent, and traps ignored by the shell are ignored
2722
2723 A command invoked in this separate environment cannot affect the
2724 shell's execution environment.
2725
2726 Command substitution, commands grouped with parentheses, and asynchro‐
2727 nous commands are invoked in a subshell environment that is a duplicate
2728 of the shell environment, except that traps caught by the shell are
2729 reset to the values that the shell inherited from its parent at invoca‐
2730 tion. Builtin commands that are invoked as part of a pipeline are also
2731 executed in a subshell environment. Changes made to the subshell envi‐
2732 ronment cannot affect the shell's execution environment.
2733
2734 Subshells spawned to execute command substitutions inherit the value of
2735 the -e option from the parent shell. When not in posix mode, bash
2736 clears the -e option in such subshells.
2737
2738 If a command is followed by a & and job control is not active, the
2739 default standard input for the command is the empty file /dev/null.
2740 Otherwise, the invoked command inherits the file descriptors of the
2741 calling shell as modified by redirections.
2742
2744 When a program is invoked it is given an array of strings called the
2745 environment. This is a list of name-value pairs, of the form
2746 name=value.
2747
2748 The shell provides several ways to manipulate the environment. On
2749 invocation, the shell scans its own environment and creates a parameter
2750 for each name found, automatically marking it for export to child pro‐
2751 cesses. Executed commands inherit the environment. The export and
2752 declare -x commands allow parameters and functions to be added to and
2753 deleted from the environment. If the value of a parameter in the envi‐
2754 ronment is modified, the new value becomes part of the environment,
2755 replacing the old. The environment inherited by any executed command
2756 consists of the shell's initial environment, whose values may be modi‐
2757 fied in the shell, less any pairs removed by the unset command, plus
2758 any additions via the export and declare -x commands.
2759
2760 The environment for any simple command or function may be augmented
2761 temporarily by prefixing it with parameter assignments, as described
2762 above in PARAMETERS. These assignment statements affect only the envi‐
2763 ronment seen by that command.
2764
2765 If the -k option is set (see the set builtin command below), then all
2766 parameter assignments are placed in the environment for a command, not
2767 just those that precede the command name.
2768
2769 When bash invokes an external command, the variable _ is set to the
2770 full filename of the command and passed to that command in its environ‐
2771 ment.
2772
2774 The exit status of an executed command is the value returned by the
2775 waitpid system call or equivalent function. Exit statuses fall between
2776 0 and 255, though, as explained below, the shell may use values above
2777 125 specially. Exit statuses from shell builtins and compound commands
2778 are also limited to this range. Under certain circumstances, the shell
2779 will use special values to indicate specific failure modes.
2780
2781 For the shell's purposes, a command which exits with a zero exit status
2782 has succeeded. An exit status of zero indicates success. A non-zero
2783 exit status indicates failure. When a command terminates on a fatal
2784 signal N, bash uses the value of 128+N as the exit status.
2785
2786 If a command is not found, the child process created to execute it
2787 returns a status of 127. If a command is found but is not executable,
2788 the return status is 126.
2789
2790 If a command fails because of an error during expansion or redirection,
2791 the exit status is greater than zero.
2792
2793 Shell builtin commands return a status of 0 (true) if successful, and
2794 non-zero (false) if an error occurs while they execute. All builtins
2795 return an exit status of 2 to indicate incorrect usage, generally
2796 invalid options or missing arguments.
2797
2798 Bash itself returns the exit status of the last command executed,
2799 unless a syntax error occurs, in which case it exits with a non-zero
2800 value. See also the exit builtin command below.
2801
2803 When bash is interactive, in the absence of any traps, it ignores
2804 SIGTERM (so that kill 0 does not kill an interactive shell), and SIGINT
2805 is caught and handled (so that the wait builtin is interruptible). In
2806 all cases, bash ignores SIGQUIT. If job control is in effect, bash
2807 ignores SIGTTIN, SIGTTOU, and SIGTSTP.
2808
2809 Non-builtin commands run by bash have signal handlers set to the values
2810 inherited by the shell from its parent. When job control is not in
2811 effect, asynchronous commands ignore SIGINT and SIGQUIT in addition to
2812 these inherited handlers. Commands run as a result of command substi‐
2813 tution ignore the keyboard-generated job control signals SIGTTIN, SIGT‐
2814 TOU, and SIGTSTP.
2815
2816 The shell exits by default upon receipt of a SIGHUP. Before exiting,
2817 an interactive shell resends the SIGHUP to all jobs, running or
2818 stopped. Stopped jobs are sent SIGCONT to ensure that they receive the
2819 SIGHUP. To prevent the shell from sending the signal to a particular
2820 job, it should be removed from the jobs table with the disown builtin
2821 (see SHELL BUILTIN COMMANDS below) or marked to not receive SIGHUP
2822 using disown -h.
2823
2824 If the huponexit shell option has been set with shopt, bash sends a
2825 SIGHUP to all jobs when an interactive login shell exits.
2826
2827 If bash is waiting for a command to complete and receives a signal for
2828 which a trap has been set, the trap will not be executed until the com‐
2829 mand completes. When bash is waiting for an asynchronous command via
2830 the wait builtin, the reception of a signal for which a trap has been
2831 set will cause the wait builtin to return immediately with an exit sta‐
2832 tus greater than 128, immediately after which the trap is executed.
2833
2835 Job control refers to the ability to selectively stop (suspend) the
2836 execution of processes and continue (resume) their execution at a later
2837 point. A user typically employs this facility via an interactive
2838 interface supplied jointly by the operating system kernel's terminal
2839 driver and bash.
2840
2841 The shell associates a job with each pipeline. It keeps a table of
2842 currently executing jobs, which may be listed with the jobs command.
2843 When bash starts a job asynchronously (in the background), it prints a
2844 line that looks like:
2845
2846 [1] 25647
2847
2848 indicating that this job is job number 1 and that the process ID of the
2849 last process in the pipeline associated with this job is 25647. All of
2850 the processes in a single pipeline are members of the same job. Bash
2851 uses the job abstraction as the basis for job control.
2852
2853 To facilitate the implementation of the user interface to job control,
2854 the operating system maintains the notion of a current terminal process
2855 group ID. Members of this process group (processes whose process group
2856 ID is equal to the current terminal process group ID) receive keyboard-
2857 generated signals such as SIGINT. These processes are said to be in
2858 the foreground. Background processes are those whose process group ID
2859 differs from the terminal's; such processes are immune to keyboard-gen‐
2860 erated signals. Only foreground processes are allowed to read from or,
2861 if the user so specifies with stty tostop, write to the terminal.
2862 Background processes which attempt to read from (write to when stty
2863 tostop is in effect) the terminal are sent a SIGTTIN (SIGTTOU) signal
2864 by the kernel's terminal driver, which, unless caught, suspends the
2865 process.
2866
2867 If the operating system on which bash is running supports job control,
2868 bash contains facilities to use it. Typing the suspend character (typ‐
2869 ically ^Z, Control-Z) while a process is running causes that process to
2870 be stopped and returns control to bash. Typing the delayed suspend
2871 character (typically ^Y, Control-Y) causes the process to be stopped
2872 when it attempts to read input from the terminal, and control to be
2873 returned to bash. The user may then manipulate the state of this job,
2874 using the bg command to continue it in the background, the fg command
2875 to continue it in the foreground, or the kill command to kill it. A ^Z
2876 takes effect immediately, and has the additional side effect of causing
2877 pending output and typeahead to be discarded.
2878
2879 There are a number of ways to refer to a job in the shell. The charac‐
2880 ter % introduces a job specification (jobspec). Job number n may be
2881 referred to as %n. A job may also be referred to using a prefix of the
2882 name used to start it, or using a substring that appears in its command
2883 line. For example, %ce refers to a stopped ce job. If a prefix
2884 matches more than one job, bash reports an error. Using %?ce, on the
2885 other hand, refers to any job containing the string ce in its command
2886 line. If the substring matches more than one job, bash reports an
2887 error. The symbols %% and %+ refer to the shell's notion of the cur‐
2888 rent job, which is the last job stopped while it was in the foreground
2889 or started in the background. The previous job may be referenced using
2890 %-. If there is only a single job, %+ and %- can both be used to refer
2891 to that job. In output pertaining to jobs (e.g., the output of the
2892 jobs command), the current job is always flagged with a +, and the pre‐
2893 vious job with a -. A single % (with no accompanying job specifica‐
2894 tion) also refers to the current job.
2895
2896 Simply naming a job can be used to bring it into the foreground: %1 is
2897 a synonym for ``fg %1'', bringing job 1 from the background into the
2898 foreground. Similarly, ``%1 &'' resumes job 1 in the background,
2899 equivalent to ``bg %1''.
2900
2901 The shell learns immediately whenever a job changes state. Normally,
2902 bash waits until it is about to print a prompt before reporting changes
2903 in a job's status so as to not interrupt any other output. If the -b
2904 option to the set builtin command is enabled, bash reports such changes
2905 immediately. Any trap on SIGCHLD is executed for each child that
2906 exits.
2907
2908 If an attempt to exit bash is made while jobs are stopped (or, if the
2909 checkjobs shell option has been enabled using the shopt builtin, run‐
2910 ning), the shell prints a warning message, and, if the checkjobs option
2911 is enabled, lists the jobs and their statuses. The jobs command may
2912 then be used to inspect their status. If a second attempt to exit is
2913 made without an intervening command, the shell does not print another
2914 warning, and any stopped jobs are terminated.
2915
2916 When the shell is waiting for a job or process using the wait builtin,
2917 and job control is enabled, wait will return when the job changes
2918 state. The -f option will force wait to wait until the job or process
2919 terminates before returning.
2920
2922 When executing interactively, bash displays the primary prompt PS1 when
2923 it is ready to read a command, and the secondary prompt PS2 when it
2924 needs more input to complete a command. Bash displays PS0 after it
2925 reads a command but before executing it. Bash displays PS4 as
2926 described above before tracing each command when the -x option is
2927 enabled. Bash allows these prompt strings to be customized by insert‐
2928 ing a number of backslash-escaped special characters that are decoded
2929 as follows:
2930 \a an ASCII bell character (07)
2931 \d the date in "Weekday Month Date" format (e.g., "Tue May
2932 26")
2933 \D{format}
2934 the format is passed to strftime(3) and the result is
2935 inserted into the prompt string; an empty format results
2936 in a locale-specific time representation. The braces are
2937 required
2938 \e an ASCII escape character (033)
2939 \h the hostname up to the first `.'
2940 \H the hostname
2941 \j the number of jobs currently managed by the shell
2942 \l the basename of the shell's terminal device name
2943 \n newline
2944 \r carriage return
2945 \s the name of the shell, the basename of $0 (the portion
2946 following the final slash)
2947 \t the current time in 24-hour HH:MM:SS format
2948 \T the current time in 12-hour HH:MM:SS format
2949 \@ the current time in 12-hour am/pm format
2950 \A the current time in 24-hour HH:MM format
2951 \u the username of the current user
2952 \v the version of bash (e.g., 2.00)
2953 \V the release of bash, version + patch level (e.g., 2.00.0)
2954 \w the current working directory, with $HOME abbreviated
2955 with a tilde (uses the value of the PROMPT_DIRTRIM vari‐
2956 able)
2957 \W the basename of the current working directory, with $HOME
2958 abbreviated with a tilde
2959 \! the history number of this command
2960 \# the command number of this command
2961 \$ if the effective UID is 0, a #, otherwise a $
2962 \nnn the character corresponding to the octal number nnn
2963 \\ a backslash
2964 \[ begin a sequence of non-printing characters, which could
2965 be used to embed a terminal control sequence into the
2966 prompt
2967 \] end a sequence of non-printing characters
2968
2969 The command number and the history number are usually different: the
2970 history number of a command is its position in the history list, which
2971 may include commands restored from the history file (see HISTORY
2972 below), while the command number is the position in the sequence of
2973 commands executed during the current shell session. After the string
2974 is decoded, it is expanded via parameter expansion, command substitu‐
2975 tion, arithmetic expansion, and quote removal, subject to the value of
2976 the promptvars shell option (see the description of the shopt command
2977 under SHELL BUILTIN COMMANDS below).
2978
2980 This is the library that handles reading input when using an interac‐
2981 tive shell, unless the --noediting option is given at shell invocation.
2982 Line editing is also used when using the -e option to the read builtin.
2983 By default, the line editing commands are similar to those of Emacs. A
2984 vi-style line editing interface is also available. Line editing can be
2985 enabled at any time using the -o emacs or -o vi options to the set
2986 builtin (see SHELL BUILTIN COMMANDS below). To turn off line editing
2987 after the shell is running, use the +o emacs or +o vi options to the
2988 set builtin.
2989
2990 Readline Notation
2991 In this section, the Emacs-style notation is used to denote keystrokes.
2992 Control keys are denoted by C-key, e.g., C-n means Control-N. Simi‐
2993 larly, meta keys are denoted by M-key, so M-x means Meta-X. (On key‐
2994 boards without a meta key, M-x means ESC x, i.e., press the Escape key
2995 then the x key. This makes ESC the meta prefix. The combination M-C-x
2996 means ESC-Control-x, or press the Escape key then hold the Control key
2997 while pressing the x key.)
2998
2999 Readline commands may be given numeric arguments, which normally act as
3000 a repeat count. Sometimes, however, it is the sign of the argument
3001 that is significant. Passing a negative argument to a command that
3002 acts in the forward direction (e.g., kill-line) causes that command to
3003 act in a backward direction. Commands whose behavior with arguments
3004 deviates from this are noted below.
3005
3006 When a command is described as killing text, the text deleted is saved
3007 for possible future retrieval (yanking). The killed text is saved in a
3008 kill ring. Consecutive kills cause the text to be accumulated into one
3009 unit, which can be yanked all at once. Commands which do not kill text
3010 separate the chunks of text on the kill ring.
3011
3012 Readline Initialization
3013 Readline is customized by putting commands in an initialization file
3014 (the inputrc file). The name of this file is taken from the value of
3015 the INPUTRC variable. If that variable is unset, the default is
3016 ~/.inputrc. When a program which uses the readline library starts up,
3017 the initialization file is read, and the key bindings and variables are
3018 set. There are only a few basic constructs allowed in the readline
3019 initialization file. Blank lines are ignored. Lines beginning with a
3020 # are comments. Lines beginning with a $ indicate conditional con‐
3021 structs. Other lines denote key bindings and variable settings.
3022
3023 The default key-bindings may be changed with an inputrc file. Other
3024 programs that use this library may add their own commands and bindings.
3025
3026 For example, placing
3027
3028 M-Control-u: universal-argument
3029 or
3030 C-Meta-u: universal-argument
3031 into the inputrc would make M-C-u execute the readline command univer‐
3032 sal-argument.
3033
3034 The following symbolic character names are recognized: RUBOUT, DEL,
3035 ESC, LFD, NEWLINE, RET, RETURN, SPC, SPACE, and TAB.
3036
3037 In addition to command names, readline allows keys to be bound to a
3038 string that is inserted when the key is pressed (a macro).
3039
3040 Readline Key Bindings
3041 The syntax for controlling key bindings in the inputrc file is simple.
3042 All that is required is the name of the command or the text of a macro
3043 and a key sequence to which it should be bound. The name may be speci‐
3044 fied in one of two ways: as a symbolic key name, possibly with Meta- or
3045 Control- prefixes, or as a key sequence.
3046
3047 When using the form keyname:function-name or macro, keyname is the name
3048 of a key spelled out in English. For example:
3049
3050 Control-u: universal-argument
3051 Meta-Rubout: backward-kill-word
3052 Control-o: "> output"
3053
3054 In the above example, C-u is bound to the function universal-argument,
3055 M-DEL is bound to the function backward-kill-word, and C-o is bound to
3056 run the macro expressed on the right hand side (that is, to insert the
3057 text ``> output'' into the line).
3058
3059 In the second form, "keyseq":function-name or macro, keyseq differs
3060 from keyname above in that strings denoting an entire key sequence may
3061 be specified by placing the sequence within double quotes. Some GNU
3062 Emacs style key escapes can be used, as in the following example, but
3063 the symbolic character names are not recognized.
3064
3065 "\C-u": universal-argument
3066 "\C-x\C-r": re-read-init-file
3067 "\e[11~": "Function Key 1"
3068
3069 In this example, C-u is again bound to the function universal-argument.
3070 C-x C-r is bound to the function re-read-init-file, and ESC [ 1 1 ~ is
3071 bound to insert the text ``Function Key 1''.
3072
3073 The full set of GNU Emacs style escape sequences is
3074 \C- control prefix
3075 \M- meta prefix
3076 \e an escape character
3077 \\ backslash
3078 \" literal "
3079 \' literal '
3080
3081 In addition to the GNU Emacs style escape sequences, a second set of
3082 backslash escapes is available:
3083 \a alert (bell)
3084 \b backspace
3085 \d delete
3086 \f form feed
3087 \n newline
3088 \r carriage return
3089 \t horizontal tab
3090 \v vertical tab
3091 \nnn the eight-bit character whose value is the octal value
3092 nnn (one to three digits)
3093 \xHH the eight-bit character whose value is the hexadecimal
3094 value HH (one or two hex digits)
3095
3096 When entering the text of a macro, single or double quotes must be used
3097 to indicate a macro definition. Unquoted text is assumed to be a func‐
3098 tion name. In the macro body, the backslash escapes described above
3099 are expanded. Backslash will quote any other character in the macro
3100 text, including " and '.
3101
3102 Bash allows the current readline key bindings to be displayed or modi‐
3103 fied with the bind builtin command. The editing mode may be switched
3104 during interactive use by using the -o option to the set builtin com‐
3105 mand (see SHELL BUILTIN COMMANDS below).
3106
3107 Readline Variables
3108 Readline has variables that can be used to further customize its behav‐
3109 ior. A variable may be set in the inputrc file with a statement of the
3110 form
3111
3112 set variable-name value
3113
3114 Except where noted, readline variables can take the values On or Off
3115 (without regard to case). Unrecognized variable names are ignored.
3116 When a variable value is read, empty or null values, "on" (case-insen‐
3117 sitive), and "1" are equivalent to On. All other values are equivalent
3118 to Off. The variables and their default values are:
3119
3120 bell-style (audible)
3121 Controls what happens when readline wants to ring the terminal
3122 bell. If set to none, readline never rings the bell. If set to
3123 visible, readline uses a visible bell if one is available. If
3124 set to audible, readline attempts to ring the terminal's bell.
3125 bind-tty-special-chars (On)
3126 If set to On, readline attempts to bind the control characters
3127 treated specially by the kernel's terminal driver to their read‐
3128 line equivalents.
3129 blink-matching-paren (Off)
3130 If set to On, readline attempts to briefly move the cursor to an
3131 opening parenthesis when a closing parenthesis is inserted.
3132 colored-completion-prefix (Off)
3133 If set to On, when listing completions, readline displays the
3134 common prefix of the set of possible completions using a differ‐
3135 ent color. The color definitions are taken from the value of
3136 the LS_COLORS environment variable.
3137 colored-stats (Off)
3138 If set to On, readline displays possible completions using dif‐
3139 ferent colors to indicate their file type. The color defini‐
3140 tions are taken from the value of the LS_COLORS environment
3141 variable.
3142 comment-begin (``#'')
3143 The string that is inserted when the readline insert-comment
3144 command is executed. This command is bound to M-# in emacs mode
3145 and to # in vi command mode.
3146 completion-display-width (-1)
3147 The number of screen columns used to display possible matches
3148 when performing completion. The value is ignored if it is less
3149 than 0 or greater than the terminal screen width. A value of 0
3150 will cause matches to be displayed one per line. The default
3151 value is -1.
3152 completion-ignore-case (Off)
3153 If set to On, readline performs filename matching and completion
3154 in a case-insensitive fashion.
3155 completion-map-case (Off)
3156 If set to On, and completion-ignore-case is enabled, readline
3157 treats hyphens (-) and underscores (_) as equivalent when per‐
3158 forming case-insensitive filename matching and completion.
3159 completion-prefix-display-length (0)
3160 The length in characters of the common prefix of a list of pos‐
3161 sible completions that is displayed without modification. When
3162 set to a value greater than zero, common prefixes longer than
3163 this value are replaced with an ellipsis when displaying possi‐
3164 ble completions.
3165 completion-query-items (100)
3166 This determines when the user is queried about viewing the num‐
3167 ber of possible completions generated by the possible-comple‐
3168 tions command. It may be set to any integer value greater than
3169 or equal to zero. If the number of possible completions is
3170 greater than or equal to the value of this variable, the user is
3171 asked whether or not he wishes to view them; otherwise they are
3172 simply listed on the terminal.
3173 convert-meta (On)
3174 If set to On, readline will convert characters with the eighth
3175 bit set to an ASCII key sequence by stripping the eighth bit and
3176 prefixing an escape character (in effect, using escape as the
3177 meta prefix). The default is On, but readline will set it to
3178 Off if the locale contains eight-bit characters.
3179 disable-completion (Off)
3180 If set to On, readline will inhibit word completion. Completion
3181 characters will be inserted into the line as if they had been
3182 mapped to self-insert.
3183 echo-control-characters (On)
3184 When set to On, on operating systems that indicate they support
3185 it, readline echoes a character corresponding to a signal gener‐
3186 ated from the keyboard.
3187 editing-mode (emacs)
3188 Controls whether readline begins with a set of key bindings sim‐
3189 ilar to Emacs or vi. editing-mode can be set to either emacs or
3190 vi.
3191 emacs-mode-string (@)
3192 If the show-mode-in-prompt variable is enabled, this string is
3193 displayed immediately before the last line of the primary prompt
3194 when emacs editing mode is active. The value is expanded like a
3195 key binding, so the standard set of meta- and control prefixes
3196 and backslash escape sequences is available. Use the \1 and \2
3197 escapes to begin and end sequences of non-printing characters,
3198 which can be used to embed a terminal control sequence into the
3199 mode string.
3200 enable-bracketed-paste (Off)
3201 When set to On, readline will configure the terminal in a way
3202 that will enable it to insert each paste into the editing buffer
3203 as a single string of characters, instead of treating each char‐
3204 acter as if it had been read from the keyboard. This can pre‐
3205 vent pasted characters from being interpreted as editing com‐
3206 mands.
3207 enable-keypad (Off)
3208 When set to On, readline will try to enable the application key‐
3209 pad when it is called. Some systems need this to enable the
3210 arrow keys.
3211 enable-meta-key (On)
3212 When set to On, readline will try to enable any meta modifier
3213 key the terminal claims to support when it is called. On many
3214 terminals, the meta key is used to send eight-bit characters.
3215 expand-tilde (Off)
3216 If set to On, tilde expansion is performed when readline
3217 attempts word completion.
3218 history-preserve-point (Off)
3219 If set to On, the history code attempts to place point at the
3220 same location on each history line retrieved with previous-his‐
3221 tory or next-history.
3222 history-size (unset)
3223 Set the maximum number of history entries saved in the history
3224 list. If set to zero, any existing history entries are deleted
3225 and no new entries are saved. If set to a value less than zero,
3226 the number of history entries is not limited. By default, the
3227 number of history entries is set to the value of the HISTSIZE
3228 shell variable. If an attempt is made to set history-size to a
3229 non-numeric value, the maximum number of history entries will be
3230 set to 500.
3231 horizontal-scroll-mode (Off)
3232 When set to On, makes readline use a single line for display,
3233 scrolling the input horizontally on a single screen line when it
3234 becomes longer than the screen width rather than wrapping to a
3235 new line.
3236 input-meta (Off)
3237 If set to On, readline will enable eight-bit input (that is, it
3238 will not strip the eighth bit from the characters it reads),
3239 regardless of what the terminal claims it can support. The name
3240 meta-flag is a synonym for this variable. The default is Off,
3241 but readline will set it to On if the locale contains eight-bit
3242 characters.
3243 isearch-terminators (``C-[C-J'')
3244 The string of characters that should terminate an incremental
3245 search without subsequently executing the character as a com‐
3246 mand. If this variable has not been given a value, the charac‐
3247 ters ESC and C-J will terminate an incremental search.
3248 keymap (emacs)
3249 Set the current readline keymap. The set of valid keymap names
3250 is emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-com‐
3251 mand, and vi-insert. vi is equivalent to vi-command; emacs is
3252 equivalent to emacs-standard. The default value is emacs; the
3253 value of editing-mode also affects the default keymap.
3254 keyseq-timeout (500)
3255 Specifies the duration readline will wait for a character when
3256 reading an ambiguous key sequence (one that can form a complete
3257 key sequence using the input read so far, or can take additional
3258 input to complete a longer key sequence). If no input is
3259 received within the timeout, readline will use the shorter but
3260 complete key sequence. The value is specified in milliseconds,
3261 so a value of 1000 means that readline will wait one second for
3262 additional input. If this variable is set to a value less than
3263 or equal to zero, or to a non-numeric value, readline will wait
3264 until another key is pressed to decide which key sequence to
3265 complete.
3266 mark-directories (On)
3267 If set to On, completed directory names have a slash appended.
3268 mark-modified-lines (Off)
3269 If set to On, history lines that have been modified are dis‐
3270 played with a preceding asterisk (*).
3271 mark-symlinked-directories (Off)
3272 If set to On, completed names which are symbolic links to direc‐
3273 tories have a slash appended (subject to the value of
3274 mark-directories).
3275 match-hidden-files (On)
3276 This variable, when set to On, causes readline to match files
3277 whose names begin with a `.' (hidden files) when performing
3278 filename completion. If set to Off, the leading `.' must be
3279 supplied by the user in the filename to be completed.
3280 menu-complete-display-prefix (Off)
3281 If set to On, menu completion displays the common prefix of the
3282 list of possible completions (which may be empty) before cycling
3283 through the list.
3284 output-meta (Off)
3285 If set to On, readline will display characters with the eighth
3286 bit set directly rather than as a meta-prefixed escape sequence.
3287 The default is Off, but readline will set it to On if the locale
3288 contains eight-bit characters.
3289 page-completions (On)
3290 If set to On, readline uses an internal more-like pager to dis‐
3291 play a screenful of possible completions at a time.
3292 print-completions-horizontally (Off)
3293 If set to On, readline will display completions with matches
3294 sorted horizontally in alphabetical order, rather than down the
3295 screen.
3296 revert-all-at-newline (Off)
3297 If set to On, readline will undo all changes to history lines
3298 before returning when accept-line is executed. By default, his‐
3299 tory lines may be modified and retain individual undo lists
3300 across calls to readline.
3301 show-all-if-ambiguous (Off)
3302 This alters the default behavior of the completion functions.
3303 If set to On, words which have more than one possible completion
3304 cause the matches to be listed immediately instead of ringing
3305 the bell.
3306 show-all-if-unmodified (Off)
3307 This alters the default behavior of the completion functions in
3308 a fashion similar to show-all-if-ambiguous. If set to On, words
3309 which have more than one possible completion without any possi‐
3310 ble partial completion (the possible completions don't share a
3311 common prefix) cause the matches to be listed immediately
3312 instead of ringing the bell.
3313 show-mode-in-prompt (Off)
3314 If set to On, add a string to the beginning of the prompt indi‐
3315 cating the editing mode: emacs, vi command, or vi insertion.
3316 The mode strings are user-settable (e.g., emacs-mode-string).
3317 skip-completed-text (Off)
3318 If set to On, this alters the default completion behavior when
3319 inserting a single match into the line. It's only active when
3320 performing completion in the middle of a word. If enabled,
3321 readline does not insert characters from the completion that
3322 match characters after point in the word being completed, so
3323 portions of the word following the cursor are not duplicated.
3324 vi-cmd-mode-string ((cmd))
3325 If the show-mode-in-prompt variable is enabled, this string is
3326 displayed immediately before the last line of the primary prompt
3327 when vi editing mode is active and in command mode. The value
3328 is expanded like a key binding, so the standard set of meta- and
3329 control prefixes and backslash escape sequences is available.
3330 Use the \1 and \2 escapes to begin and end sequences of non-
3331 printing characters, which can be used to embed a terminal con‐
3332 trol sequence into the mode string.
3333 vi-ins-mode-string ((ins))
3334 If the show-mode-in-prompt variable is enabled, this string is
3335 displayed immediately before the last line of the primary prompt
3336 when vi editing mode is active and in insertion mode. The value
3337 is expanded like a key binding, so the standard set of meta- and
3338 control prefixes and backslash escape sequences is available.
3339 Use the \1 and \2 escapes to begin and end sequences of non-
3340 printing characters, which can be used to embed a terminal con‐
3341 trol sequence into the mode string.
3342 visible-stats (Off)
3343 If set to On, a character denoting a file's type as reported by
3344 stat(2) is appended to the filename when listing possible com‐
3345 pletions.
3346
3347 Readline Conditional Constructs
3348 Readline implements a facility similar in spirit to the conditional
3349 compilation features of the C preprocessor which allows key bindings
3350 and variable settings to be performed as the result of tests. There
3351 are four parser directives used.
3352
3353 $if The $if construct allows bindings to be made based on the edit‐
3354 ing mode, the terminal being used, or the application using
3355 readline. The text of the test, after any comparison operator,
3356 extends to the end of the line; unless otherwise noted, no
3357 characters are required to isolate it.
3358
3359 mode The mode= form of the $if directive is used to test
3360 whether readline is in emacs or vi mode. This may be
3361 used in conjunction with the set keymap command, for
3362 instance, to set bindings in the emacs-standard and
3363 emacs-ctlx keymaps only if readline is starting out in
3364 emacs mode.
3365
3366 term The term= form may be used to include terminal-specific
3367 key bindings, perhaps to bind the key sequences output by
3368 the terminal's function keys. The word on the right side
3369 of the = is tested against both the full name of the ter‐
3370 minal and the portion of the terminal name before the
3371 first -. This allows sun to match both sun and sun-cmd,
3372 for instance.
3373
3374 version
3375 The version test may be used to perform comparisons
3376 against specific readline versions. The version expands
3377 to the current readline version. The set of comparison
3378 operators includes =, (and ==), !=, <=, >=, <, and >.
3379 The version number supplied on the right side of the
3380 operator consists of a major version number, an optional
3381 decimal point, and an optional minor version (e.g., 7.1).
3382 If the minor version is omitted, it is assumed to be 0.
3383 The operator may be separated from the string version and
3384 from the version number argument by whitespace.
3385
3386 application
3387 The application construct is used to include application-
3388 specific settings. Each program using the readline
3389 library sets the application name, and an initialization
3390 file can test for a particular value. This could be used
3391 to bind key sequences to functions useful for a specific
3392 program. For instance, the following command adds a key
3393 sequence that quotes the current or previous word in
3394 bash:
3395
3396 $if Bash
3397 # Quote the current or previous word
3398 "\C-xq": "\eb\"\ef\""
3399 $endif
3400
3401 variable
3402 The variable construct provides simple equality tests for
3403 readline variables and values. The permitted comparison
3404 operators are =, ==, and !=. The variable name must be
3405 separated from the comparison operator by whitespace; the
3406 operator may be separated from the value on the right
3407 hand side by whitespace. Both string and boolean vari‐
3408 ables may be tested. Boolean variables must be tested
3409 against the values on and off.
3410
3411 $endif This command, as seen in the previous example, terminates an $if
3412 command.
3413
3414 $else Commands in this branch of the $if directive are executed if the
3415 test fails.
3416
3417 $include
3418 This directive takes a single filename as an argument and reads
3419 commands and bindings from that file. For example, the follow‐
3420 ing directive would read /etc/inputrc:
3421
3422 $include /etc/inputrc
3423
3424 Searching
3425 Readline provides commands for searching through the command history
3426 (see HISTORY below) for lines containing a specified string. There are
3427 two search modes: incremental and non-incremental.
3428
3429 Incremental searches begin before the user has finished typing the
3430 search string. As each character of the search string is typed, read‐
3431 line displays the next entry from the history matching the string typed
3432 so far. An incremental search requires only as many characters as
3433 needed to find the desired history entry. The characters present in
3434 the value of the isearch-terminators variable are used to terminate an
3435 incremental search. If that variable has not been assigned a value the
3436 Escape and Control-J characters will terminate an incremental search.
3437 Control-G will abort an incremental search and restore the original
3438 line. When the search is terminated, the history entry containing the
3439 search string becomes the current line.
3440
3441 To find other matching entries in the history list, type Control-S or
3442 Control-R as appropriate. This will search backward or forward in the
3443 history for the next entry matching the search string typed so far.
3444 Any other key sequence bound to a readline command will terminate the
3445 search and execute that command. For instance, a newline will termi‐
3446 nate the search and accept the line, thereby executing the command from
3447 the history list.
3448
3449 Readline remembers the last incremental search string. If two Control-
3450 Rs are typed without any intervening characters defining a new search
3451 string, any remembered search string is used.
3452
3453 Non-incremental searches read the entire search string before starting
3454 to search for matching history lines. The search string may be typed
3455 by the user or be part of the contents of the current line.
3456
3457 Readline Command Names
3458 The following is a list of the names of the commands and the default
3459 key sequences to which they are bound. Command names without an accom‐
3460 panying key sequence are unbound by default. In the following descrip‐
3461 tions, point refers to the current cursor position, and mark refers to
3462 a cursor position saved by the set-mark command. The text between the
3463 point and mark is referred to as the region.
3464
3465 Commands for Moving
3466 beginning-of-line (C-a)
3467 Move to the start of the current line.
3468 end-of-line (C-e)
3469 Move to the end of the line.
3470 forward-char (C-f)
3471 Move forward a character.
3472 backward-char (C-b)
3473 Move back a character.
3474 forward-word (M-f)
3475 Move forward to the end of the next word. Words are composed of
3476 alphanumeric characters (letters and digits).
3477 backward-word (M-b)
3478 Move back to the start of the current or previous word. Words
3479 are composed of alphanumeric characters (letters and digits).
3480 shell-forward-word
3481 Move forward to the end of the next word. Words are delimited
3482 by non-quoted shell metacharacters.
3483 shell-backward-word
3484 Move back to the start of the current or previous word. Words
3485 are delimited by non-quoted shell metacharacters.
3486 previous-screen-line
3487 Attempt to move point to the same physical screen column on the
3488 previous physical screen line. This will not have the desired
3489 effect if the current Readline line does not take up more than
3490 one physical line or if point is not greater than the length of
3491 the prompt plus the screen width.
3492 next-screen-line
3493 Attempt to move point to the same physical screen column on the
3494 next physical screen line. This will not have the desired effect
3495 if the current Readline line does not take up more than one
3496 physical line or if the length of the current Readline line is
3497 not greater than the length of the prompt plus the screen width.
3498 clear-screen (C-l)
3499 Clear the screen leaving the current line at the top of the
3500 screen. With an argument, refresh the current line without
3501 clearing the screen.
3502 redraw-current-line
3503 Refresh the current line.
3504
3505 Commands for Manipulating the History
3506 accept-line (Newline, Return)
3507 Accept the line regardless of where the cursor is. If this line
3508 is non-empty, add it to the history list according to the state
3509 of the HISTCONTROL variable. If the line is a modified history
3510 line, then restore the history line to its original state.
3511 previous-history (C-p)
3512 Fetch the previous command from the history list, moving back in
3513 the list.
3514 next-history (C-n)
3515 Fetch the next command from the history list, moving forward in
3516 the list.
3517 beginning-of-history (M-<)
3518 Move to the first line in the history.
3519 end-of-history (M->)
3520 Move to the end of the input history, i.e., the line currently
3521 being entered.
3522 reverse-search-history (C-r)
3523 Search backward starting at the current line and moving `up'
3524 through the history as necessary. This is an incremental
3525 search.
3526 forward-search-history (C-s)
3527 Search forward starting at the current line and moving `down'
3528 through the history as necessary. This is an incremental
3529 search.
3530 non-incremental-reverse-search-history (M-p)
3531 Search backward through the history starting at the current line
3532 using a non-incremental search for a string supplied by the
3533 user.
3534 non-incremental-forward-search-history (M-n)
3535 Search forward through the history using a non-incremental
3536 search for a string supplied by the user.
3537 history-search-forward
3538 Search forward through the history for the string of characters
3539 between the start of the current line and the point. This is a
3540 non-incremental search.
3541 history-search-backward
3542 Search backward through the history for the string of characters
3543 between the start of the current line and the point. This is a
3544 non-incremental search.
3545 history-substring-search-backward
3546 Search backward through the history for the string of characters
3547 between the start of the current line and the current cursor
3548 position (the point). The search string may match anywhere in a
3549 history line. This is a non-incremental search.
3550 history-substring-search-forward
3551 Search forward through the history for the string of characters
3552 between the start of the current line and the point. The search
3553 string may match anywhere in a history line. This is a non-
3554 incremental search.
3555 yank-nth-arg (M-C-y)
3556 Insert the first argument to the previous command (usually the
3557 second word on the previous line) at point. With an argument n,
3558 insert the nth word from the previous command (the words in the
3559 previous command begin with word 0). A negative argument
3560 inserts the nth word from the end of the previous command. Once
3561 the argument n is computed, the argument is extracted as if the
3562 "!n" history expansion had been specified.
3563 yank-last-arg (M-., M-_)
3564 Insert the last argument to the previous command (the last word
3565 of the previous history entry). With a numeric argument, behave
3566 exactly like yank-nth-arg. Successive calls to yank-last-arg
3567 move back through the history list, inserting the last word (or
3568 the word specified by the argument to the first call) of each
3569 line in turn. Any numeric argument supplied to these successive
3570 calls determines the direction to move through the history. A
3571 negative argument switches the direction through the history
3572 (back or forward). The history expansion facilities are used to
3573 extract the last word, as if the "!$" history expansion had been
3574 specified.
3575 shell-expand-line (M-C-e)
3576 Expand the line as the shell does. This performs alias and his‐
3577 tory expansion as well as all of the shell word expansions. See
3578 HISTORY EXPANSION below for a description of history expansion.
3579 history-expand-line (M-^)
3580 Perform history expansion on the current line. See HISTORY
3581 EXPANSION below for a description of history expansion.
3582 magic-space
3583 Perform history expansion on the current line and insert a
3584 space. See HISTORY EXPANSION below for a description of history
3585 expansion.
3586 alias-expand-line
3587 Perform alias expansion on the current line. See ALIASES above
3588 for a description of alias expansion.
3589 history-and-alias-expand-line
3590 Perform history and alias expansion on the current line.
3591 insert-last-argument (M-., M-_)
3592 A synonym for yank-last-arg.
3593 operate-and-get-next (C-o)
3594 Accept the current line for execution and fetch the next line
3595 relative to the current line from the history for editing. A
3596 numeric argument, if supplied, specifies the history entry to
3597 use instead of the current line.
3598 edit-and-execute-command (C-x C-e)
3599 Invoke an editor on the current command line, and execute the
3600 result as shell commands. Bash attempts to invoke $VISUAL,
3601 $EDITOR, and emacs as the editor, in that order.
3602
3603 Commands for Changing Text
3604 end-of-file (usually C-d)
3605 The character indicating end-of-file as set, for example, by
3606 ``stty''. If this character is read when there are no charac‐
3607 ters on the line, and point is at the beginning of the line,
3608 Readline interprets it as the end of input and returns EOF.
3609 delete-char (C-d)
3610 Delete the character at point. If this function is bound to the
3611 same character as the tty EOF character, as C-d commonly is, see
3612 above for the effects.
3613 backward-delete-char (Rubout)
3614 Delete the character behind the cursor. When given a numeric
3615 argument, save the deleted text on the kill ring.
3616 forward-backward-delete-char
3617 Delete the character under the cursor, unless the cursor is at
3618 the end of the line, in which case the character behind the cur‐
3619 sor is deleted.
3620 quoted-insert (C-q, C-v)
3621 Add the next character typed to the line verbatim. This is how
3622 to insert characters like C-q, for example.
3623 tab-insert (C-v TAB)
3624 Insert a tab character.
3625 self-insert (a, b, A, 1, !, ...)
3626 Insert the character typed.
3627 transpose-chars (C-t)
3628 Drag the character before point forward over the character at
3629 point, moving point forward as well. If point is at the end of
3630 the line, then this transposes the two characters before point.
3631 Negative arguments have no effect.
3632 transpose-words (M-t)
3633 Drag the word before point past the word after point, moving
3634 point over that word as well. If point is at the end of the
3635 line, this transposes the last two words on the line.
3636 upcase-word (M-u)
3637 Uppercase the current (or following) word. With a negative
3638 argument, uppercase the previous word, but do not move point.
3639 downcase-word (M-l)
3640 Lowercase the current (or following) word. With a negative
3641 argument, lowercase the previous word, but do not move point.
3642 capitalize-word (M-c)
3643 Capitalize the current (or following) word. With a negative
3644 argument, capitalize the previous word, but do not move point.
3645 overwrite-mode
3646 Toggle overwrite mode. With an explicit positive numeric argu‐
3647 ment, switches to overwrite mode. With an explicit non-positive
3648 numeric argument, switches to insert mode. This command affects
3649 only emacs mode; vi mode does overwrite differently. Each call
3650 to readline() starts in insert mode. In overwrite mode, charac‐
3651 ters bound to self-insert replace the text at point rather than
3652 pushing the text to the right. Characters bound to back‐
3653 ward-delete-char replace the character before point with a
3654 space. By default, this command is unbound.
3655
3656 Killing and Yanking
3657 kill-line (C-k)
3658 Kill the text from point to the end of the line.
3659 backward-kill-line (C-x Rubout)
3660 Kill backward to the beginning of the line.
3661 unix-line-discard (C-u)
3662 Kill backward from point to the beginning of the line. The
3663 killed text is saved on the kill-ring.
3664 kill-whole-line
3665 Kill all characters on the current line, no matter where point
3666 is.
3667 kill-word (M-d)
3668 Kill from point to the end of the current word, or if between
3669 words, to the end of the next word. Word boundaries are the
3670 same as those used by forward-word.
3671 backward-kill-word (M-Rubout)
3672 Kill the word behind point. Word boundaries are the same as
3673 those used by backward-word.
3674 shell-kill-word
3675 Kill from point to the end of the current word, or if between
3676 words, to the end of the next word. Word boundaries are the
3677 same as those used by shell-forward-word.
3678 shell-backward-kill-word
3679 Kill the word behind point. Word boundaries are the same as
3680 those used by shell-backward-word.
3681 unix-word-rubout (C-w)
3682 Kill the word behind point, using white space as a word bound‐
3683 ary. The killed text is saved on the kill-ring.
3684 unix-filename-rubout
3685 Kill the word behind point, using white space and the slash
3686 character as the word boundaries. The killed text is saved on
3687 the kill-ring.
3688 delete-horizontal-space (M-\)
3689 Delete all spaces and tabs around point.
3690 kill-region
3691 Kill the text in the current region.
3692 copy-region-as-kill
3693 Copy the text in the region to the kill buffer.
3694 copy-backward-word
3695 Copy the word before point to the kill buffer. The word bound‐
3696 aries are the same as backward-word.
3697 copy-forward-word
3698 Copy the word following point to the kill buffer. The word
3699 boundaries are the same as forward-word.
3700 yank (C-y)
3701 Yank the top of the kill ring into the buffer at point.
3702 yank-pop (M-y)
3703 Rotate the kill ring, and yank the new top. Only works follow‐
3704 ing yank or yank-pop.
3705
3706 Numeric Arguments
3707 digit-argument (M-0, M-1, ..., M--)
3708 Add this digit to the argument already accumulating, or start a
3709 new argument. M-- starts a negative argument.
3710 universal-argument
3711 This is another way to specify an argument. If this command is
3712 followed by one or more digits, optionally with a leading minus
3713 sign, those digits define the argument. If the command is fol‐
3714 lowed by digits, executing universal-argument again ends the
3715 numeric argument, but is otherwise ignored. As a special case,
3716 if this command is immediately followed by a character that is
3717 neither a digit nor minus sign, the argument count for the next
3718 command is multiplied by four. The argument count is initially
3719 one, so executing this function the first time makes the argu‐
3720 ment count four, a second time makes the argument count sixteen,
3721 and so on.
3722
3723 Completing
3724 complete (TAB)
3725 Attempt to perform completion on the text before point. Bash
3726 attempts completion treating the text as a variable (if the text
3727 begins with $), username (if the text begins with ~), hostname
3728 (if the text begins with @), or command (including aliases and
3729 functions) in turn. If none of these produces a match, filename
3730 completion is attempted.
3731 possible-completions (M-?)
3732 List the possible completions of the text before point.
3733 insert-completions (M-*)
3734 Insert all completions of the text before point that would have
3735 been generated by possible-completions.
3736 menu-complete
3737 Similar to complete, but replaces the word to be completed with
3738 a single match from the list of possible completions. Repeated
3739 execution of menu-complete steps through the list of possible
3740 completions, inserting each match in turn. At the end of the
3741 list of completions, the bell is rung (subject to the setting of
3742 bell-style) and the original text is restored. An argument of n
3743 moves n positions forward in the list of matches; a negative
3744 argument may be used to move backward through the list. This
3745 command is intended to be bound to TAB, but is unbound by
3746 default.
3747 menu-complete-backward
3748 Identical to menu-complete, but moves backward through the list
3749 of possible completions, as if menu-complete had been given a
3750 negative argument. This command is unbound by default.
3751 delete-char-or-list
3752 Deletes the character under the cursor if not at the beginning
3753 or end of the line (like delete-char). If at the end of the
3754 line, behaves identically to possible-completions. This command
3755 is unbound by default.
3756 complete-filename (M-/)
3757 Attempt filename completion on the text before point.
3758 possible-filename-completions (C-x /)
3759 List the possible completions of the text before point, treating
3760 it as a filename.
3761 complete-username (M-~)
3762 Attempt completion on the text before point, treating it as a
3763 username.
3764 possible-username-completions (C-x ~)
3765 List the possible completions of the text before point, treating
3766 it as a username.
3767 complete-variable (M-$)
3768 Attempt completion on the text before point, treating it as a
3769 shell variable.
3770 possible-variable-completions (C-x $)
3771 List the possible completions of the text before point, treating
3772 it as a shell variable.
3773 complete-hostname (M-@)
3774 Attempt completion on the text before point, treating it as a
3775 hostname.
3776 possible-hostname-completions (C-x @)
3777 List the possible completions of the text before point, treating
3778 it as a hostname.
3779 complete-command (M-!)
3780 Attempt completion on the text before point, treating it as a
3781 command name. Command completion attempts to match the text
3782 against aliases, reserved words, shell functions, shell
3783 builtins, and finally executable filenames, in that order.
3784 possible-command-completions (C-x !)
3785 List the possible completions of the text before point, treating
3786 it as a command name.
3787 dynamic-complete-history (M-TAB)
3788 Attempt completion on the text before point, comparing the text
3789 against lines from the history list for possible completion
3790 matches.
3791 dabbrev-expand
3792 Attempt menu completion on the text before point, comparing the
3793 text against lines from the history list for possible completion
3794 matches.
3795 complete-into-braces (M-{)
3796 Perform filename completion and insert the list of possible com‐
3797 pletions enclosed within braces so the list is available to the
3798 shell (see Brace Expansion above).
3799
3800 Keyboard Macros
3801 start-kbd-macro (C-x ()
3802 Begin saving the characters typed into the current keyboard
3803 macro.
3804 end-kbd-macro (C-x ))
3805 Stop saving the characters typed into the current keyboard macro
3806 and store the definition.
3807 call-last-kbd-macro (C-x e)
3808 Re-execute the last keyboard macro defined, by making the char‐
3809 acters in the macro appear as if typed at the keyboard.
3810 print-last-kbd-macro ()
3811 Print the last keyboard macro defined in a format suitable for
3812 the inputrc file.
3813
3814 Miscellaneous
3815 re-read-init-file (C-x C-r)
3816 Read in the contents of the inputrc file, and incorporate any
3817 bindings or variable assignments found there.
3818 abort (C-g)
3819 Abort the current editing command and ring the terminal's bell
3820 (subject to the setting of bell-style).
3821 do-lowercase-version (M-A, M-B, M-x, ...)
3822 If the metafied character x is uppercase, run the command that
3823 is bound to the corresponding metafied lowercase character. The
3824 behavior is undefined if x is already lowercase.
3825 prefix-meta (ESC)
3826 Metafy the next character typed. ESC f is equivalent to Meta-f.
3827 undo (C-_, C-x C-u)
3828 Incremental undo, separately remembered for each line.
3829 revert-line (M-r)
3830 Undo all changes made to this line. This is like executing the
3831 undo command enough times to return the line to its initial
3832 state.
3833 tilde-expand (M-&)
3834 Perform tilde expansion on the current word.
3835 set-mark (C-@, M-<space>)
3836 Set the mark to the point. If a numeric argument is supplied,
3837 the mark is set to that position.
3838 exchange-point-and-mark (C-x C-x)
3839 Swap the point with the mark. The current cursor position is
3840 set to the saved position, and the old cursor position is saved
3841 as the mark.
3842 character-search (C-])
3843 A character is read and point is moved to the next occurrence of
3844 that character. A negative count searches for previous occur‐
3845 rences.
3846 character-search-backward (M-C-])
3847 A character is read and point is moved to the previous occur‐
3848 rence of that character. A negative count searches for subse‐
3849 quent occurrences.
3850 skip-csi-sequence
3851 Read enough characters to consume a multi-key sequence such as
3852 those defined for keys like Home and End. Such sequences begin
3853 with a Control Sequence Indicator (CSI), usually ESC-[. If this
3854 sequence is bound to "\[", keys producing such sequences will
3855 have no effect unless explicitly bound to a readline command,
3856 instead of inserting stray characters into the editing buffer.
3857 This is unbound by default, but usually bound to ESC-[.
3858 insert-comment (M-#)
3859 Without a numeric argument, the value of the readline com‐
3860 ment-begin variable is inserted at the beginning of the current
3861 line. If a numeric argument is supplied, this command acts as a
3862 toggle: if the characters at the beginning of the line do not
3863 match the value of comment-begin, the value is inserted, other‐
3864 wise the characters in comment-begin are deleted from the begin‐
3865 ning of the line. In either case, the line is accepted as if a
3866 newline had been typed. The default value of comment-begin
3867 causes this command to make the current line a shell comment.
3868 If a numeric argument causes the comment character to be
3869 removed, the line will be executed by the shell.
3870 glob-complete-word (M-g)
3871 The word before point is treated as a pattern for pathname
3872 expansion, with an asterisk implicitly appended. This pattern
3873 is used to generate a list of matching filenames for possible
3874 completions.
3875 glob-expand-word (C-x *)
3876 The word before point is treated as a pattern for pathname
3877 expansion, and the list of matching filenames is inserted,
3878 replacing the word. If a numeric argument is supplied, an
3879 asterisk is appended before pathname expansion.
3880 glob-list-expansions (C-x g)
3881 The list of expansions that would have been generated by
3882 glob-expand-word is displayed, and the line is redrawn. If a
3883 numeric argument is supplied, an asterisk is appended before
3884 pathname expansion.
3885 dump-functions
3886 Print all of the functions and their key bindings to the read‐
3887 line output stream. If a numeric argument is supplied, the out‐
3888 put is formatted in such a way that it can be made part of an
3889 inputrc file.
3890 dump-variables
3891 Print all of the settable readline variables and their values to
3892 the readline output stream. If a numeric argument is supplied,
3893 the output is formatted in such a way that it can be made part
3894 of an inputrc file.
3895 dump-macros
3896 Print all of the readline key sequences bound to macros and the
3897 strings they output. If a numeric argument is supplied, the
3898 output is formatted in such a way that it can be made part of an
3899 inputrc file.
3900 display-shell-version (C-x C-v)
3901 Display version information about the current instance of bash.
3902
3903 Programmable Completion
3904 When word completion is attempted for an argument to a command for
3905 which a completion specification (a compspec) has been defined using
3906 the complete builtin (see SHELL BUILTIN COMMANDS below), the program‐
3907 mable completion facilities are invoked.
3908
3909 First, the command name is identified. If the command word is the
3910 empty string (completion attempted at the beginning of an empty line),
3911 any compspec defined with the -E option to complete is used. If a
3912 compspec has been defined for that command, the compspec is used to
3913 generate the list of possible completions for the word. If the command
3914 word is a full pathname, a compspec for the full pathname is searched
3915 for first. If no compspec is found for the full pathname, an attempt
3916 is made to find a compspec for the portion following the final slash.
3917 If those searches do not result in a compspec, any compspec defined
3918 with the -D option to complete is used as the default. If there is no
3919 default compspec, bash attempts alias expansion on the command word as
3920 a final resort, and attempts to find a compspec for the command word
3921 from any successful expansion.
3922
3923 Once a compspec has been found, it is used to generate the list of
3924 matching words. If a compspec is not found, the default bash comple‐
3925 tion as described above under Completing is performed.
3926
3927 First, the actions specified by the compspec are used. Only matches
3928 which are prefixed by the word being completed are returned. When the
3929 -f or -d option is used for filename or directory name completion, the
3930 shell variable FIGNORE is used to filter the matches.
3931
3932 Any completions specified by a pathname expansion pattern to the -G
3933 option are generated next. The words generated by the pattern need not
3934 match the word being completed. The GLOBIGNORE shell variable is not
3935 used to filter the matches, but the FIGNORE variable is used.
3936
3937 Next, the string specified as the argument to the -W option is consid‐
3938 ered. The string is first split using the characters in the IFS spe‐
3939 cial variable as delimiters. Shell quoting is honored. Each word is
3940 then expanded using brace expansion, tilde expansion, parameter and
3941 variable expansion, command substitution, and arithmetic expansion, as
3942 described above under EXPANSION. The results are split using the rules
3943 described above under Word Splitting. The results of the expansion are
3944 prefix-matched against the word being completed, and the matching words
3945 become the possible completions.
3946
3947 After these matches have been generated, any shell function or command
3948 specified with the -F and -C options is invoked. When the command or
3949 function is invoked, the COMP_LINE, COMP_POINT, COMP_KEY, and COMP_TYPE
3950 variables are assigned values as described above under Shell Variables.
3951 If a shell function is being invoked, the COMP_WORDS and COMP_CWORD
3952 variables are also set. When the function or command is invoked, the
3953 first argument ($1) is the name of the command whose arguments are
3954 being completed, the second argument ($2) is the word being completed,
3955 and the third argument ($3) is the word preceding the word being com‐
3956 pleted on the current command line. No filtering of the generated com‐
3957 pletions against the word being completed is performed; the function or
3958 command has complete freedom in generating the matches.
3959
3960 Any function specified with -F is invoked first. The function may use
3961 any of the shell facilities, including the compgen builtin described
3962 below, to generate the matches. It must put the possible completions
3963 in the COMPREPLY array variable, one per array element.
3964
3965 Next, any command specified with the -C option is invoked in an envi‐
3966 ronment equivalent to command substitution. It should print a list of
3967 completions, one per line, to the standard output. Backslash may be
3968 used to escape a newline, if necessary.
3969
3970 After all of the possible completions are generated, any filter speci‐
3971 fied with the -X option is applied to the list. The filter is a pat‐
3972 tern as used for pathname expansion; a & in the pattern is replaced
3973 with the text of the word being completed. A literal & may be escaped
3974 with a backslash; the backslash is removed before attempting a match.
3975 Any completion that matches the pattern will be removed from the list.
3976 A leading ! negates the pattern; in this case any completion not match‐
3977 ing the pattern will be removed. If the nocasematch shell option is
3978 enabled, the match is performed without regard to the case of alpha‐
3979 betic characters.
3980
3981 Finally, any prefix and suffix specified with the -P and -S options are
3982 added to each member of the completion list, and the result is returned
3983 to the readline completion code as the list of possible completions.
3984
3985 If the previously-applied actions do not generate any matches, and the
3986 -o dirnames option was supplied to complete when the compspec was
3987 defined, directory name completion is attempted.
3988
3989 If the -o plusdirs option was supplied to complete when the compspec
3990 was defined, directory name completion is attempted and any matches are
3991 added to the results of the other actions.
3992
3993 By default, if a compspec is found, whatever it generates is returned
3994 to the completion code as the full set of possible completions. The
3995 default bash completions are not attempted, and the readline default of
3996 filename completion is disabled. If the -o bashdefault option was sup‐
3997 plied to complete when the compspec was defined, the bash default com‐
3998 pletions are attempted if the compspec generates no matches. If the -o
3999 default option was supplied to complete when the compspec was defined,
4000 readline's default completion will be performed if the compspec (and,
4001 if attempted, the default bash completions) generate no matches.
4002
4003 When a compspec indicates that directory name completion is desired,
4004 the programmable completion functions force readline to append a slash
4005 to completed names which are symbolic links to directories, subject to
4006 the value of the mark-directories readline variable, regardless of the
4007 setting of the mark-symlinked-directories readline variable.
4008
4009 There is some support for dynamically modifying completions. This is
4010 most useful when used in combination with a default completion speci‐
4011 fied with complete -D. It's possible for shell functions executed as
4012 completion handlers to indicate that completion should be retried by
4013 returning an exit status of 124. If a shell function returns 124, and
4014 changes the compspec associated with the command on which completion is
4015 being attempted (supplied as the first argument when the function is
4016 executed), programmable completion restarts from the beginning, with an
4017 attempt to find a new compspec for that command. This allows a set of
4018 completions to be built dynamically as completion is attempted, rather
4019 than being loaded all at once.
4020
4021 For instance, assuming that there is a library of compspecs, each kept
4022 in a file corresponding to the name of the command, the following
4023 default completion function would load completions dynamically:
4024
4025 _completion_loader()
4026 {
4027 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
4028 }
4029 complete -D -F _completion_loader -o bashdefault -o default
4030
4031
4033 When the -o history option to the set builtin is enabled, the shell
4034 provides access to the command history, the list of commands previously
4035 typed. The value of the HISTSIZE variable is used as the number of
4036 commands to save in a history list. The text of the last HISTSIZE com‐
4037 mands (default 500) is saved. The shell stores each command in the
4038 history list prior to parameter and variable expansion (see EXPANSION
4039 above) but after history expansion is performed, subject to the values
4040 of the shell variables HISTIGNORE and HISTCONTROL.
4041
4042 On startup, the history is initialized from the file named by the vari‐
4043 able HISTFILE (default ~/.bash_history). The file named by the value
4044 of HISTFILE is truncated, if necessary, to contain no more than the
4045 number of lines specified by the value of HISTFILESIZE. If HISTFILE‐
4046 SIZE is unset, or set to null, a non-numeric value, or a numeric value
4047 less than zero, the history file is not truncated. When the history
4048 file is read, lines beginning with the history comment character fol‐
4049 lowed immediately by a digit are interpreted as timestamps for the fol‐
4050 lowing history line. These timestamps are optionally displayed depend‐
4051 ing on the value of the HISTTIMEFORMAT variable. When a shell with
4052 history enabled exits, the last $HISTSIZE lines are copied from the
4053 history list to $HISTFILE. If the histappend shell option is enabled
4054 (see the description of shopt under SHELL BUILTIN COMMANDS below), the
4055 lines are appended to the history file, otherwise the history file is
4056 overwritten. If HISTFILE is unset, or if the history file is
4057 unwritable, the history is not saved. If the HISTTIMEFORMAT variable
4058 is set, time stamps are written to the history file, marked with the
4059 history comment character, so they may be preserved across shell ses‐
4060 sions. This uses the history comment character to distinguish time‐
4061 stamps from other history lines. After saving the history, the history
4062 file is truncated to contain no more than HISTFILESIZE lines. If HIST‐
4063 FILESIZE is unset, or set to null, a non-numeric value, or a numeric
4064 value less than zero, the history file is not truncated.
4065
4066 The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used
4067 to list or edit and re-execute a portion of the history list. The his‐
4068 tory builtin may be used to display or modify the history list and
4069 manipulate the history file. When using command-line editing, search
4070 commands are available in each editing mode that provide access to the
4071 history list.
4072
4073 The shell allows control over which commands are saved on the history
4074 list. The HISTCONTROL and HISTIGNORE variables may be set to cause the
4075 shell to save only a subset of the commands entered. The cmdhist shell
4076 option, if enabled, causes the shell to attempt to save each line of a
4077 multi-line command in the same history entry, adding semicolons where
4078 necessary to preserve syntactic correctness. The lithist shell option
4079 causes the shell to save the command with embedded newlines instead of
4080 semicolons. See the description of the shopt builtin below under SHELL
4081 BUILTIN COMMANDS for information on setting and unsetting shell
4082 options.
4083
4085 The shell supports a history expansion feature that is similar to the
4086 history expansion in csh. This section describes what syntax features
4087 are available. This feature is enabled by default for interactive
4088 shells, and can be disabled using the +H option to the set builtin com‐
4089 mand (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not
4090 perform history expansion by default.
4091
4092 History expansions introduce words from the history list into the input
4093 stream, making it easy to repeat commands, insert the arguments to a
4094 previous command into the current input line, or fix errors in previous
4095 commands quickly.
4096
4097 History expansion is performed immediately after a complete line is
4098 read, before the shell breaks it into words, and is performed on each
4099 line individually without taking quoting on previous lines into
4100 account. It takes place in two parts. The first is to determine which
4101 line from the history list to use during substitution. The second is
4102 to select portions of that line for inclusion into the current one.
4103 The line selected from the history is the event, and the portions of
4104 that line that are acted upon are words. Various modifiers are avail‐
4105 able to manipulate the selected words. The line is broken into words
4106 in the same fashion as when reading input, so that several metacharac‐
4107 ter-separated words surrounded by quotes are considered one word. His‐
4108 tory expansions are introduced by the appearance of the history expan‐
4109 sion character, which is ! by default. Only backslash (\) and single
4110 quotes can quote the history expansion character, but the history
4111 expansion character is also treated as quoted if it immediately pre‐
4112 cedes the closing double quote in a double-quoted string.
4113
4114 Several characters inhibit history expansion if found immediately fol‐
4115 lowing the history expansion character, even if it is unquoted: space,
4116 tab, newline, carriage return, and =. If the extglob shell option is
4117 enabled, ( will also inhibit expansion.
4118
4119 Several shell options settable with the shopt builtin may be used to
4120 tailor the behavior of history expansion. If the histverify shell
4121 option is enabled (see the description of the shopt builtin below), and
4122 readline is being used, history substitutions are not immediately
4123 passed to the shell parser. Instead, the expanded line is reloaded
4124 into the readline editing buffer for further modification. If readline
4125 is being used, and the histreedit shell option is enabled, a failed
4126 history substitution will be reloaded into the readline editing buffer
4127 for correction. The -p option to the history builtin command may be
4128 used to see what a history expansion will do before using it. The -s
4129 option to the history builtin may be used to add commands to the end of
4130 the history list without actually executing them, so that they are
4131 available for subsequent recall.
4132
4133 The shell allows control of the various characters used by the history
4134 expansion mechanism (see the description of histchars above under Shell
4135 Variables). The shell uses the history comment character to mark his‐
4136 tory timestamps when writing the history file.
4137
4138 Event Designators
4139 An event designator is a reference to a command line entry in the his‐
4140 tory list. Unless the reference is absolute, events are relative to
4141 the current position in the history list.
4142
4143 ! Start a history substitution, except when followed by a blank,
4144 newline, carriage return, = or ( (when the extglob shell option
4145 is enabled using the shopt builtin).
4146 !n Refer to command line n.
4147 !-n Refer to the current command minus n.
4148 !! Refer to the previous command. This is a synonym for `!-1'.
4149 !string
4150 Refer to the most recent command preceding the current position
4151 in the history list starting with string.
4152 !?string[?]
4153 Refer to the most recent command preceding the current position
4154 in the history list containing string. The trailing ? may be
4155 omitted if string is followed immediately by a newline.
4156 ^string1^string2^
4157 Quick substitution. Repeat the previous command, replacing
4158 string1 with string2. Equivalent to ``!!:s/string1/string2/''
4159 (see Modifiers below).
4160 !# The entire command line typed so far.
4161
4162 Word Designators
4163 Word designators are used to select desired words from the event. A :
4164 separates the event specification from the word designator. It may be
4165 omitted if the word designator begins with a ^, $, *, -, or %. Words
4166 are numbered from the beginning of the line, with the first word being
4167 denoted by 0 (zero). Words are inserted into the current line sepa‐
4168 rated by single spaces.
4169
4170 0 (zero)
4171 The zeroth word. For the shell, this is the command word.
4172 n The nth word.
4173 ^ The first argument. That is, word 1.
4174 $ The last word. This is usually the last argument, but will
4175 expand to the zeroth word if there is only one word in the line.
4176 % The word matched by the most recent `?string?' search.
4177 x-y A range of words; `-y' abbreviates `0-y'.
4178 * All of the words but the zeroth. This is a synonym for `1-$'.
4179 It is not an error to use * if there is just one word in the
4180 event; the empty string is returned in that case.
4181 x* Abbreviates x-$.
4182 x- Abbreviates x-$ like x*, but omits the last word.
4183
4184 If a word designator is supplied without an event specification, the
4185 previous command is used as the event.
4186
4187 Modifiers
4188 After the optional word designator, there may appear a sequence of one
4189 or more of the following modifiers, each preceded by a `:'.
4190
4191 h Remove a trailing filename component, leaving only the head.
4192 t Remove all leading filename components, leaving the tail.
4193 r Remove a trailing suffix of the form .xxx, leaving the basename.
4194 e Remove all but the trailing suffix.
4195 p Print the new command but do not execute it.
4196 q Quote the substituted words, escaping further substitutions.
4197 x Quote the substituted words as with q, but break into words at
4198 blanks and newlines.
4199 s/old/new/
4200 Substitute new for the first occurrence of old in the event
4201 line. Any delimiter can be used in place of /. The final
4202 delimiter is optional if it is the last character of the event
4203 line. The delimiter may be quoted in old and new with a single
4204 backslash. If & appears in new, it is replaced by old. A sin‐
4205 gle backslash will quote the &. If old is null, it is set to
4206 the last old substituted, or, if no previous history substitu‐
4207 tions took place, the last string in a !?string[?] search.
4208 & Repeat the previous substitution.
4209 g Cause changes to be applied over the entire event line. This is
4210 used in conjunction with `:s' (e.g., `:gs/old/new/') or `:&'.
4211 If used with `:s', any delimiter can be used in place of /, and
4212 the final delimiter is optional if it is the last character of
4213 the event line. An a may be used as a synonym for g.
4214 G Apply the following `s' modifier once to each word in the event
4215 line.
4216
4218 Unless otherwise noted, each builtin command documented in this section
4219 as accepting options preceded by - accepts -- to signify the end of the
4220 options. The :, true, false, and test/[ builtins do not accept options
4221 and do not treat -- specially. The exit, logout, return, break, con‐
4222 tinue, let, and shift builtins accept and process arguments beginning
4223 with - without requiring --. Other builtins that accept arguments but
4224 are not specified as accepting options interpret arguments beginning
4225 with - as invalid options and require -- to prevent this interpreta‐
4226 tion.
4227 : [arguments]
4228 No effect; the command does nothing beyond expanding arguments
4229 and performing any specified redirections. The return status is
4230 zero.
4231
4232 . filename [arguments]
4233 source filename [arguments]
4234 Read and execute commands from filename in the current shell
4235 environment and return the exit status of the last command exe‐
4236 cuted from filename. If filename does not contain a slash,
4237 filenames in PATH are used to find the directory containing
4238 filename. The file searched for in PATH need not be executable.
4239 When bash is not in posix mode, the current directory is
4240 searched if no file is found in PATH. If the sourcepath option
4241 to the shopt builtin command is turned off, the PATH is not
4242 searched. If any arguments are supplied, they become the posi‐
4243 tional parameters when filename is executed. Otherwise the
4244 positional parameters are unchanged. If the -T option is
4245 enabled, source inherits any trap on DEBUG; if it is not, any
4246 DEBUG trap string is saved and restored around the call to
4247 source, and source unsets the DEBUG trap while it executes. If
4248 -T is not set, and the sourced file changes the DEBUG trap, the
4249 new value is retained when source completes. The return status
4250 is the status of the last command exited within the script (0 if
4251 no commands are executed), and false if filename is not found or
4252 cannot be read.
4253
4254 alias [-p] [name[=value] ...]
4255 Alias with no arguments or with the -p option prints the list of
4256 aliases in the form alias name=value on standard output. When
4257 arguments are supplied, an alias is defined for each name whose
4258 value is given. A trailing space in value causes the next word
4259 to be checked for alias substitution when the alias is expanded.
4260 For each name in the argument list for which no value is sup‐
4261 plied, the name and value of the alias is printed. Alias
4262 returns true unless a name is given for which no alias has been
4263 defined.
4264
4265 bg [jobspec ...]
4266 Resume each suspended job jobspec in the background, as if it
4267 had been started with &. If jobspec is not present, the shell's
4268 notion of the current job is used. bg jobspec returns 0 unless
4269 run when job control is disabled or, when run with job control
4270 enabled, any specified jobspec was not found or was started
4271 without job control.
4272
4273 bind [-m keymap] [-lpsvPSVX]
4274 bind [-m keymap] [-q function] [-u function] [-r keyseq]
4275 bind [-m keymap] -f filename
4276 bind [-m keymap] -x keyseq:shell-command
4277 bind [-m keymap] keyseq:function-name
4278 bind [-m keymap] keyseq:readline-command
4279 Display current readline key and function bindings, bind a key
4280 sequence to a readline function or macro, or set a readline
4281 variable. Each non-option argument is a command as it would
4282 appear in .inputrc, but each binding or command must be passed
4283 as a separate argument; e.g., '"\C-x\C-r": re-read-init-file'.
4284 Options, if supplied, have the following meanings:
4285 -m keymap
4286 Use keymap as the keymap to be affected by the subsequent
4287 bindings. Acceptable keymap names are emacs, emacs-stan‐
4288 dard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command,
4289 and vi-insert. vi is equivalent to vi-command (vi-move
4290 is also a synonym); emacs is equivalent to emacs-stan‐
4291 dard.
4292 -l List the names of all readline functions.
4293 -p Display readline function names and bindings in such a
4294 way that they can be re-read.
4295 -P List current readline function names and bindings.
4296 -s Display readline key sequences bound to macros and the
4297 strings they output in such a way that they can be re-
4298 read.
4299 -S Display readline key sequences bound to macros and the
4300 strings they output.
4301 -v Display readline variable names and values in such a way
4302 that they can be re-read.
4303 -V List current readline variable names and values.
4304 -f filename
4305 Read key bindings from filename.
4306 -q function
4307 Query about which keys invoke the named function.
4308 -u function
4309 Unbind all keys bound to the named function.
4310 -r keyseq
4311 Remove any current binding for keyseq.
4312 -x keyseq:shell-command
4313 Cause shell-command to be executed whenever keyseq is
4314 entered. When shell-command is executed, the shell sets
4315 the READLINE_LINE variable to the contents of the read‐
4316 line line buffer and the READLINE_POINT variable to the
4317 current location of the insertion point. If the executed
4318 command changes the value of READLINE_LINE or READ‐
4319 LINE_POINT, those new values will be reflected in the
4320 editing state.
4321 -X List all key sequences bound to shell commands and the
4322 associated commands in a format that can be reused as
4323 input.
4324
4325 The return value is 0 unless an unrecognized option is given or
4326 an error occurred.
4327
4328 break [n]
4329 Exit from within a for, while, until, or select loop. If n is
4330 specified, break n levels. n must be ≥ 1. If n is greater than
4331 the number of enclosing loops, all enclosing loops are exited.
4332 The return value is 0 unless n is not greater than or equal to
4333 1.
4334
4335 builtin shell-builtin [arguments]
4336 Execute the specified shell builtin, passing it arguments, and
4337 return its exit status. This is useful when defining a function
4338 whose name is the same as a shell builtin, retaining the func‐
4339 tionality of the builtin within the function. The cd builtin is
4340 commonly redefined this way. The return status is false if
4341 shell-builtin is not a shell builtin command.
4342
4343 caller [expr]
4344 Returns the context of any active subroutine call (a shell func‐
4345 tion or a script executed with the . or source builtins). With‐
4346 out expr, caller displays the line number and source filename of
4347 the current subroutine call. If a non-negative integer is sup‐
4348 plied as expr, caller displays the line number, subroutine name,
4349 and source file corresponding to that position in the current
4350 execution call stack. This extra information may be used, for
4351 example, to print a stack trace. The current frame is frame 0.
4352 The return value is 0 unless the shell is not executing a sub‐
4353 routine call or expr does not correspond to a valid position in
4354 the call stack.
4355
4356 cd [-L|[-P [-e]] [-@]] [dir]
4357 Change the current directory to dir. if dir is not supplied,
4358 the value of the HOME shell variable is the default. Any addi‐
4359 tional arguments following dir are ignored. The variable CDPATH
4360 defines the search path for the directory containing dir: each
4361 directory name in CDPATH is searched for dir. Alternative
4362 directory names in CDPATH are separated by a colon (:). A null
4363 directory name in CDPATH is the same as the current directory,
4364 i.e., ``.''. If dir begins with a slash (/), then CDPATH is not
4365 used. The -P option causes cd to use the physical directory
4366 structure by resolving symbolic links while traversing dir and
4367 before processing instances of .. in dir (see also the -P option
4368 to the set builtin command); the -L option forces symbolic links
4369 to be followed by resolving the link after processing instances
4370 of .. in dir. If .. appears in dir, it is processed by removing
4371 the immediately previous pathname component from dir, back to a
4372 slash or the beginning of dir. If the -e option is supplied
4373 with -P, and the current working directory cannot be success‐
4374 fully determined after a successful directory change, cd will
4375 return an unsuccessful status. On systems that support it, the
4376 -@ option presents the extended attributes associated with a
4377 file as a directory. An argument of - is converted to $OLDPWD
4378 before the directory change is attempted. If a non-empty direc‐
4379 tory name from CDPATH is used, or if - is the first argument,
4380 and the directory change is successful, the absolute pathname of
4381 the new working directory is written to the standard output.
4382 The return value is true if the directory was successfully
4383 changed; false otherwise.
4384
4385 command [-pVv] command [arg ...]
4386 Run command with args suppressing the normal shell function
4387 lookup. Only builtin commands or commands found in the PATH are
4388 executed. If the -p option is given, the search for command is
4389 performed using a default value for PATH that is guaranteed to
4390 find all of the standard utilities. If either the -V or -v
4391 option is supplied, a description of command is printed. The -v
4392 option causes a single word indicating the command or filename
4393 used to invoke command to be displayed; the -V option produces a
4394 more verbose description. If the -V or -v option is supplied,
4395 the exit status is 0 if command was found, and 1 if not. If
4396 neither option is supplied and an error occurred or command can‐
4397 not be found, the exit status is 127. Otherwise, the exit sta‐
4398 tus of the command builtin is the exit status of command.
4399
4400 compgen [option] [word]
4401 Generate possible completion matches for word according to the
4402 options, which may be any option accepted by the complete
4403 builtin with the exception of -p and -r, and write the matches
4404 to the standard output. When using the -F or -C options, the
4405 various shell variables set by the programmable completion
4406 facilities, while available, will not have useful values.
4407
4408 The matches will be generated in the same way as if the program‐
4409 mable completion code had generated them directly from a comple‐
4410 tion specification with the same flags. If word is specified,
4411 only those completions matching word will be displayed.
4412
4413 The return value is true unless an invalid option is supplied,
4414 or no matches were generated.
4415
4416 complete [-abcdefgjksuv] [-o comp-option] [-DEI] [-A action] [-G glob‐
4417 pat] [-W wordlist] [-F function] [-C command]
4418 [-X filterpat] [-P prefix] [-S suffix] name [name ...]
4419 complete -pr [-DEI] [name ...]
4420 Specify how arguments to each name should be completed. If the
4421 -p option is supplied, or if no options are supplied, existing
4422 completion specifications are printed in a way that allows them
4423 to be reused as input. The -r option removes a completion spec‐
4424 ification for each name, or, if no names are supplied, all com‐
4425 pletion specifications. The -D option indicates that other sup‐
4426 plied options and actions should apply to the ``default'' com‐
4427 mand completion; that is, completion attempted on a command for
4428 which no completion has previously been defined. The -E option
4429 indicates that other supplied options and actions should apply
4430 to ``empty'' command completion; that is, completion attempted
4431 on a blank line. The -I option indicates that other supplied
4432 options and actions should apply to completion on the inital
4433 non-assignment word on the line, or after a command delimiter
4434 such as ; or |, which is usually command name completion. If
4435 multiple options are supplied, the -D option takes precedence
4436 over -E, and both take precedence over -I. If any of -D, -E, or
4437 -I are supplied, any other name arguments are ignored; these
4438 completions only apply to the case specified by the option.
4439
4440 The process of applying these completion specifications when
4441 word completion is attempted is described above under Program‐
4442 mable Completion.
4443
4444 Other options, if specified, have the following meanings. The
4445 arguments to the -G, -W, and -X options (and, if necessary, the
4446 -P and -S options) should be quoted to protect them from expan‐
4447 sion before the complete builtin is invoked.
4448 -o comp-option
4449 The comp-option controls several aspects of the comp‐
4450 spec's behavior beyond the simple generation of comple‐
4451 tions. comp-option may be one of:
4452 bashdefault
4453 Perform the rest of the default bash completions
4454 if the compspec generates no matches.
4455 default Use readline's default filename completion if
4456 the compspec generates no matches.
4457 dirnames
4458 Perform directory name completion if the comp‐
4459 spec generates no matches.
4460 filenames
4461 Tell readline that the compspec generates file‐
4462 names, so it can perform any filename-specific
4463 processing (like adding a slash to directory
4464 names, quoting special characters, or suppress‐
4465 ing trailing spaces). Intended to be used with
4466 shell functions.
4467 noquote Tell readline not to quote the completed words
4468 if they are filenames (quoting filenames is the
4469 default).
4470 nosort Tell readline not to sort the list of possible
4471 completions alphabetically.
4472 nospace Tell readline not to append a space (the
4473 default) to words completed at the end of the
4474 line.
4475 plusdirs
4476 After any matches defined by the compspec are
4477 generated, directory name completion is
4478 attempted and any matches are added to the
4479 results of the other actions.
4480 -A action
4481 The action may be one of the following to generate a
4482 list of possible completions:
4483 alias Alias names. May also be specified as -a.
4484 arrayvar
4485 Array variable names.
4486 binding Readline key binding names.
4487 builtin Names of shell builtin commands. May also be
4488 specified as -b.
4489 command Command names. May also be specified as -c.
4490 directory
4491 Directory names. May also be specified as -d.
4492 disabled
4493 Names of disabled shell builtins.
4494 enabled Names of enabled shell builtins.
4495 export Names of exported shell variables. May also be
4496 specified as -e.
4497 file File names. May also be specified as -f.
4498 function
4499 Names of shell functions.
4500 group Group names. May also be specified as -g.
4501 helptopic
4502 Help topics as accepted by the help builtin.
4503 hostname
4504 Hostnames, as taken from the file specified by
4505 the HOSTFILE shell variable.
4506 job Job names, if job control is active. May also
4507 be specified as -j.
4508 keyword Shell reserved words. May also be specified as
4509 -k.
4510 running Names of running jobs, if job control is active.
4511 service Service names. May also be specified as -s.
4512 setopt Valid arguments for the -o option to the set
4513 builtin.
4514 shopt Shell option names as accepted by the shopt
4515 builtin.
4516 signal Signal names.
4517 stopped Names of stopped jobs, if job control is active.
4518 user User names. May also be specified as -u.
4519 variable
4520 Names of all shell variables. May also be spec‐
4521 ified as -v.
4522 -C command
4523 command is executed in a subshell environment, and its
4524 output is used as the possible completions.
4525 -F function
4526 The shell function function is executed in the current
4527 shell environment. When the function is executed, the
4528 first argument ($1) is the name of the command whose
4529 arguments are being completed, the second argument ($2)
4530 is the word being completed, and the third argument ($3)
4531 is the word preceding the word being completed on the
4532 current command line. When it finishes, the possible
4533 completions are retrieved from the value of the COMPRE‐
4534 PLY array variable.
4535 -G globpat
4536 The pathname expansion pattern globpat is expanded to
4537 generate the possible completions.
4538 -P prefix
4539 prefix is added at the beginning of each possible com‐
4540 pletion after all other options have been applied.
4541 -S suffix
4542 suffix is appended to each possible completion after all
4543 other options have been applied.
4544 -W wordlist
4545 The wordlist is split using the characters in the IFS
4546 special variable as delimiters, and each resultant word
4547 is expanded. Shell quoting is honored within wordlist,
4548 in order to provide a mechanism for the words to contain
4549 shell metacharacters or characters in the value of IFS.
4550 The possible completions are the members of the resul‐
4551 tant list which match the word being completed.
4552 -X filterpat
4553 filterpat is a pattern as used for pathname expansion.
4554 It is applied to the list of possible completions gener‐
4555 ated by the preceding options and arguments, and each
4556 completion matching filterpat is removed from the list.
4557 A leading ! in filterpat negates the pattern; in this
4558 case, any completion not matching filterpat is removed.
4559
4560 The return value is true unless an invalid option is supplied,
4561 an option other than -p or -r is supplied without a name argu‐
4562 ment, an attempt is made to remove a completion specification
4563 for a name for which no specification exists, or an error occurs
4564 adding a completion specification.
4565
4566 compopt [-o option] [-DEI] [+o option] [name]
4567 Modify completion options for each name according to the
4568 options, or for the currently-executing completion if no names
4569 are supplied. If no options are given, display the completion
4570 options for each name or the current completion. The possible
4571 values of option are those valid for the complete builtin
4572 described above. The -D option indicates that other supplied
4573 options should apply to the ``default'' command completion; that
4574 is, completion attempted on a command for which no completion
4575 has previously been defined. The -E option indicates that other
4576 supplied options should apply to ``empty'' command completion;
4577 that is, completion attempted on a blank line. The -I option
4578 indicates that other supplied options should apply to completion
4579 on the inital non-assignment word on the line, or after a com‐
4580 mand delimiter such as ; or |, which is usually command name
4581 completion.
4582
4583 The return value is true unless an invalid option is supplied,
4584 an attempt is made to modify the options for a name for which no
4585 completion specification exists, or an output error occurs.
4586
4587 continue [n]
4588 Resume the next iteration of the enclosing for, while, until, or
4589 select loop. If n is specified, resume at the nth enclosing
4590 loop. n must be ≥ 1. If n is greater than the number of
4591 enclosing loops, the last enclosing loop (the ``top-level''
4592 loop) is resumed. The return value is 0 unless n is not greater
4593 than or equal to 1.
4594
4595 declare [-aAfFgilnrtux] [-p] [name[=value] ...]
4596 typeset [-aAfFgilnrtux] [-p] [name[=value] ...]
4597 Declare variables and/or give them attributes. If no names are
4598 given then display the values of variables. The -p option will
4599 display the attributes and values of each name. When -p is used
4600 with name arguments, additional options, other than -f and -F,
4601 are ignored. When -p is supplied without name arguments, it
4602 will display the attributes and values of all variables having
4603 the attributes specified by the additional options. If no other
4604 options are supplied with -p, declare will display the
4605 attributes and values of all shell variables. The -f option
4606 will restrict the display to shell functions. The -F option
4607 inhibits the display of function definitions; only the function
4608 name and attributes are printed. If the extdebug shell option
4609 is enabled using shopt, the source file name and line number
4610 where each name is defined are displayed as well. The -F option
4611 implies -f. The -g option forces variables to be created or
4612 modified at the global scope, even when declare is executed in a
4613 shell function. It is ignored in all other cases. The follow‐
4614 ing options can be used to restrict output to variables with the
4615 specified attribute or to give variables attributes:
4616 -a Each name is an indexed array variable (see Arrays
4617 above).
4618 -A Each name is an associative array variable (see Arrays
4619 above).
4620 -f Use function names only.
4621 -i The variable is treated as an integer; arithmetic evalua‐
4622 tion (see ARITHMETIC EVALUATION above) is performed when
4623 the variable is assigned a value.
4624 -l When the variable is assigned a value, all upper-case
4625 characters are converted to lower-case. The upper-case
4626 attribute is disabled.
4627 -n Give each name the nameref attribute, making it a name
4628 reference to another variable. That other variable is
4629 defined by the value of name. All references, assign‐
4630 ments, and attribute modifications to name, except those
4631 using or changing the -n attribute itself, are performed
4632 on the variable referenced by name's value. The nameref
4633 attribute cannot be applied to array variables.
4634 -r Make names readonly. These names cannot then be assigned
4635 values by subsequent assignment statements or unset.
4636 -t Give each name the trace attribute. Traced functions
4637 inherit the DEBUG and RETURN traps from the calling
4638 shell. The trace attribute has no special meaning for
4639 variables.
4640 -u When the variable is assigned a value, all lower-case
4641 characters are converted to upper-case. The lower-case
4642 attribute is disabled.
4643 -x Mark names for export to subsequent commands via the
4644 environment.
4645
4646 Using `+' instead of `-' turns off the attribute instead, with
4647 the exceptions that +a and +A may not be used to destroy array
4648 variables and +r will not remove the readonly attribute. When
4649 used in a function, declare and typeset make each name local, as
4650 with the local command, unless the -g option is supplied. If a
4651 variable name is followed by =value, the value of the variable
4652 is set to value. When using -a or -A and the compound assign‐
4653 ment syntax to create array variables, additional attributes do
4654 not take effect until subsequent assignments. The return value
4655 is 0 unless an invalid option is encountered, an attempt is made
4656 to define a function using ``-f foo=bar'', an attempt is made to
4657 assign a value to a readonly variable, an attempt is made to
4658 assign a value to an array variable without using the compound
4659 assignment syntax (see Arrays above), one of the names is not a
4660 valid shell variable name, an attempt is made to turn off read‐
4661 only status for a readonly variable, an attempt is made to turn
4662 off array status for an array variable, or an attempt is made to
4663 display a non-existent function with -f.
4664
4665 dirs [-clpv] [+n] [-n]
4666 Without options, displays the list of currently remembered
4667 directories. The default display is on a single line with
4668 directory names separated by spaces. Directories are added to
4669 the list with the pushd command; the popd command removes
4670 entries from the list. The current directory is always the
4671 first directory in the stack.
4672 -c Clears the directory stack by deleting all of the
4673 entries.
4674 -l Produces a listing using full pathnames; the default
4675 listing format uses a tilde to denote the home directory.
4676 -p Print the directory stack with one entry per line.
4677 -v Print the directory stack with one entry per line, pre‐
4678 fixing each entry with its index in the stack.
4679 +n Displays the nth entry counting from the left of the list
4680 shown by dirs when invoked without options, starting with
4681 zero.
4682 -n Displays the nth entry counting from the right of the
4683 list shown by dirs when invoked without options, starting
4684 with zero.
4685
4686 The return value is 0 unless an invalid option is supplied or n
4687 indexes beyond the end of the directory stack.
4688
4689 disown [-ar] [-h] [jobspec ... | pid ... ]
4690 Without options, remove each jobspec from the table of active
4691 jobs. If jobspec is not present, and neither the -a nor the -r
4692 option is supplied, the current job is used. If the -h option
4693 is given, each jobspec is not removed from the table, but is
4694 marked so that SIGHUP is not sent to the job if the shell
4695 receives a SIGHUP. If no jobspec is supplied, the -a option
4696 means to remove or mark all jobs; the -r option without a job‐
4697 spec argument restricts operation to running jobs. The return
4698 value is 0 unless a jobspec does not specify a valid job.
4699
4700 echo [-neE] [arg ...]
4701 Output the args, separated by spaces, followed by a newline.
4702 The return status is 0 unless a write error occurs. If -n is
4703 specified, the trailing newline is suppressed. If the -e option
4704 is given, interpretation of the following backslash-escaped
4705 characters is enabled. The -E option disables the interpreta‐
4706 tion of these escape characters, even on systems where they are
4707 interpreted by default. The xpg_echo shell option may be used
4708 to dynamically determine whether or not echo expands these
4709 escape characters by default. echo does not interpret -- to
4710 mean the end of options. echo interprets the following escape
4711 sequences:
4712 \a alert (bell)
4713 \b backspace
4714 \c suppress further output
4715 \e
4716 \E an escape character
4717 \f form feed
4718 \n new line
4719 \r carriage return
4720 \t horizontal tab
4721 \v vertical tab
4722 \\ backslash
4723 \0nnn the eight-bit character whose value is the octal value
4724 nnn (zero to three octal digits)
4725 \xHH the eight-bit character whose value is the hexadecimal
4726 value HH (one or two hex digits)
4727 \uHHHH the Unicode (ISO/IEC 10646) character whose value is the
4728 hexadecimal value HHHH (one to four hex digits)
4729 \UHHHHHHHH
4730 the Unicode (ISO/IEC 10646) character whose value is the
4731 hexadecimal value HHHHHHHH (one to eight hex digits)
4732
4733 enable [-a] [-dnps] [-f filename] [name ...]
4734 Enable and disable builtin shell commands. Disabling a builtin
4735 allows a disk command which has the same name as a shell builtin
4736 to be executed without specifying a full pathname, even though
4737 the shell normally searches for builtins before disk commands.
4738 If -n is used, each name is disabled; otherwise, names are
4739 enabled. For example, to use the test binary found via the PATH
4740 instead of the shell builtin version, run ``enable -n test''.
4741 The -f option means to load the new builtin command name from
4742 shared object filename, on systems that support dynamic loading.
4743 The -d option will delete a builtin previously loaded with -f.
4744 If no name arguments are given, or if the -p option is supplied,
4745 a list of shell builtins is printed. With no other option argu‐
4746 ments, the list consists of all enabled shell builtins. If -n
4747 is supplied, only disabled builtins are printed. If -a is sup‐
4748 plied, the list printed includes all builtins, with an indica‐
4749 tion of whether or not each is enabled. If -s is supplied, the
4750 output is restricted to the POSIX special builtins. The return
4751 value is 0 unless a name is not a shell builtin or there is an
4752 error loading a new builtin from a shared object.
4753
4754 eval [arg ...]
4755 The args are read and concatenated together into a single com‐
4756 mand. This command is then read and executed by the shell, and
4757 its exit status is returned as the value of eval. If there are
4758 no args, or only null arguments, eval returns 0.
4759
4760 exec [-cl] [-a name] [command [arguments]]
4761 If command is specified, it replaces the shell. No new process
4762 is created. The arguments become the arguments to command. If
4763 the -l option is supplied, the shell places a dash at the begin‐
4764 ning of the zeroth argument passed to command. This is what
4765 login(1) does. The -c option causes command to be executed with
4766 an empty environment. If -a is supplied, the shell passes name
4767 as the zeroth argument to the executed command. If command can‐
4768 not be executed for some reason, a non-interactive shell exits,
4769 unless the execfail shell option is enabled. In that case, it
4770 returns failure. An interactive shell returns failure if the
4771 file cannot be executed. A subshell exits unconditionally if
4772 exec fails. If command is not specified, any redirections take
4773 effect in the current shell, and the return status is 0. If
4774 there is a redirection error, the return status is 1.
4775
4776 exit [n]
4777 Cause the shell to exit with a status of n. If n is omitted,
4778 the exit status is that of the last command executed. A trap on
4779 EXIT is executed before the shell terminates.
4780
4781 export [-fn] [name[=word]] ...
4782 export -p
4783 The supplied names are marked for automatic export to the envi‐
4784 ronment of subsequently executed commands. If the -f option is
4785 given, the names refer to functions. If no names are given, or
4786 if the -p option is supplied, a list of names of all exported
4787 variables is printed. The -n option causes the export property
4788 to be removed from each name. If a variable name is followed by
4789 =word, the value of the variable is set to word. export returns
4790 an exit status of 0 unless an invalid option is encountered, one
4791 of the names is not a valid shell variable name, or -f is sup‐
4792 plied with a name that is not a function.
4793
4794 fc [-e ename] [-lnr] [first] [last]
4795 fc -s [pat=rep] [cmd]
4796 The first form selects a range of commands from first to last
4797 from the history list and displays or edits and re-executes
4798 them. First and last may be specified as a string (to locate
4799 the last command beginning with that string) or as a number (an
4800 index into the history list, where a negative number is used as
4801 an offset from the current command number). If last is not
4802 specified, it is set to the current command for listing (so that
4803 ``fc -l -10'' prints the last 10 commands) and to first other‐
4804 wise. If first is not specified, it is set to the previous com‐
4805 mand for editing and -16 for listing.
4806
4807 The -n option suppresses the command numbers when listing. The
4808 -r option reverses the order of the commands. If the -l option
4809 is given, the commands are listed on standard output. Other‐
4810 wise, the editor given by ename is invoked on a file containing
4811 those commands. If ename is not given, the value of the FCEDIT
4812 variable is used, and the value of EDITOR if FCEDIT is not set.
4813 If neither variable is set, vi is used. When editing is com‐
4814 plete, the edited commands are echoed and executed.
4815
4816 In the second form, command is re-executed after each instance
4817 of pat is replaced by rep. Command is interpreted the same as
4818 first above. A useful alias to use with this is ``r="fc -s"'',
4819 so that typing ``r cc'' runs the last command beginning with
4820 ``cc'' and typing ``r'' re-executes the last command.
4821
4822 If the first form is used, the return value is 0 unless an
4823 invalid option is encountered or first or last specify history
4824 lines out of range. If the -e option is supplied, the return
4825 value is the value of the last command executed or failure if an
4826 error occurs with the temporary file of commands. If the second
4827 form is used, the return status is that of the command re-exe‐
4828 cuted, unless cmd does not specify a valid history line, in
4829 which case fc returns failure.
4830
4831 fg [jobspec]
4832 Resume jobspec in the foreground, and make it the current job.
4833 If jobspec is not present, the shell's notion of the current job
4834 is used. The return value is that of the command placed into
4835 the foreground, or failure if run when job control is disabled
4836 or, when run with job control enabled, if jobspec does not spec‐
4837 ify a valid job or jobspec specifies a job that was started
4838 without job control.
4839
4840 getopts optstring name [args]
4841 getopts is used by shell procedures to parse positional parame‐
4842 ters. optstring contains the option characters to be recog‐
4843 nized; if a character is followed by a colon, the option is
4844 expected to have an argument, which should be separated from it
4845 by white space. The colon and question mark characters may not
4846 be used as option characters. Each time it is invoked, getopts
4847 places the next option in the shell variable name, initializing
4848 name if it does not exist, and the index of the next argument to
4849 be processed into the variable OPTIND. OPTIND is initialized to
4850 1 each time the shell or a shell script is invoked. When an
4851 option requires an argument, getopts places that argument into
4852 the variable OPTARG. The shell does not reset OPTIND automati‐
4853 cally; it must be manually reset between multiple calls to
4854 getopts within the same shell invocation if a new set of parame‐
4855 ters is to be used.
4856
4857 When the end of options is encountered, getopts exits with a
4858 return value greater than zero. OPTIND is set to the index of
4859 the first non-option argument, and name is set to ?.
4860
4861 getopts normally parses the positional parameters, but if more
4862 arguments are given in args, getopts parses those instead.
4863
4864 getopts can report errors in two ways. If the first character
4865 of optstring is a colon, silent error reporting is used. In
4866 normal operation, diagnostic messages are printed when invalid
4867 options or missing option arguments are encountered. If the
4868 variable OPTERR is set to 0, no error messages will be dis‐
4869 played, even if the first character of optstring is not a colon.
4870
4871 If an invalid option is seen, getopts places ? into name and, if
4872 not silent, prints an error message and unsets OPTARG. If
4873 getopts is silent, the option character found is placed in
4874 OPTARG and no diagnostic message is printed.
4875
4876 If a required argument is not found, and getopts is not silent,
4877 a question mark (?) is placed in name, OPTARG is unset, and a
4878 diagnostic message is printed. If getopts is silent, then a
4879 colon (:) is placed in name and OPTARG is set to the option
4880 character found.
4881
4882 getopts returns true if an option, specified or unspecified, is
4883 found. It returns false if the end of options is encountered or
4884 an error occurs.
4885
4886 hash [-lr] [-p filename] [-dt] [name]
4887 Each time hash is invoked, the full pathname of the command name
4888 is determined by searching the directories in $PATH and remem‐
4889 bered. Any previously-remembered pathname is discarded. If the
4890 -p option is supplied, no path search is performed, and filename
4891 is used as the full filename of the command. The -r option
4892 causes the shell to forget all remembered locations. The -d
4893 option causes the shell to forget the remembered location of
4894 each name. If the -t option is supplied, the full pathname to
4895 which each name corresponds is printed. If multiple name argu‐
4896 ments are supplied with -t, the name is printed before the
4897 hashed full pathname. The -l option causes output to be dis‐
4898 played in a format that may be reused as input. If no arguments
4899 are given, or if only -l is supplied, information about remem‐
4900 bered commands is printed. The return status is true unless a
4901 name is not found or an invalid option is supplied.
4902
4903 help [-dms] [pattern]
4904 Display helpful information about builtin commands. If pattern
4905 is specified, help gives detailed help on all commands matching
4906 pattern; otherwise help for all the builtins and shell control
4907 structures is printed.
4908 -d Display a short description of each pattern
4909 -m Display the description of each pattern in a manpage-like
4910 format
4911 -s Display only a short usage synopsis for each pattern
4912
4913 The return status is 0 unless no command matches pattern.
4914
4915 history [n]
4916 history -c
4917 history -d offset
4918 history -d start-end
4919 history -anrw [filename]
4920 history -p arg [arg ...]
4921 history -s arg [arg ...]
4922 With no options, display the command history list with line num‐
4923 bers. Lines listed with a * have been modified. An argument of
4924 n lists only the last n lines. If the shell variable HISTTIME‐
4925 FORMAT is set and not null, it is used as a format string for
4926 strftime(3) to display the time stamp associated with each dis‐
4927 played history entry. No intervening blank is printed between
4928 the formatted time stamp and the history line. If filename is
4929 supplied, it is used as the name of the history file; if not,
4930 the value of HISTFILE is used. Options, if supplied, have the
4931 following meanings:
4932 -c Clear the history list by deleting all the entries.
4933 -d offset
4934 Delete the history entry at position offset. If offset
4935 is negative, it is interpreted as relative to one greater
4936 than the last history position, so negative indices count
4937 back from the end of the history, and an index of -1
4938 refers to the current history -d command.
4939 -d start-end
4940 Delete the history entries between positions start and
4941 end, inclusive. Positive and negative values for start
4942 and end are interpreted as described above.
4943 -a Append the ``new'' history lines to the history file.
4944 These are history lines entered since the beginning of
4945 the current bash session, but not already appended to the
4946 history file.
4947 -n Read the history lines not already read from the history
4948 file into the current history list. These are lines
4949 appended to the history file since the beginning of the
4950 current bash session.
4951 -r Read the contents of the history file and append them to
4952 the current history list.
4953 -w Write the current history list to the history file, over‐
4954 writing the history file's contents.
4955 -p Perform history substitution on the following args and
4956 display the result on the standard output. Does not
4957 store the results in the history list. Each arg must be
4958 quoted to disable normal history expansion.
4959 -s Store the args in the history list as a single entry.
4960 The last command in the history list is removed before
4961 the args are added.
4962
4963 If the HISTTIMEFORMAT variable is set, the time stamp informa‐
4964 tion associated with each history entry is written to the his‐
4965 tory file, marked with the history comment character. When the
4966 history file is read, lines beginning with the history comment
4967 character followed immediately by a digit are interpreted as
4968 timestamps for the following history entry. The return value is
4969 0 unless an invalid option is encountered, an error occurs while
4970 reading or writing the history file, an invalid offset is sup‐
4971 plied as an argument to -d, or the history expansion supplied as
4972 an argument to -p fails.
4973
4974 jobs [-lnprs] [ jobspec ... ]
4975 jobs -x command [ args ... ]
4976 The first form lists the active jobs. The options have the fol‐
4977 lowing meanings:
4978 -l List process IDs in addition to the normal information.
4979 -n Display information only about jobs that have changed
4980 status since the user was last notified of their status.
4981 -p List only the process ID of the job's process group
4982 leader.
4983 -r Display only running jobs.
4984 -s Display only stopped jobs.
4985
4986 If jobspec is given, output is restricted to information about
4987 that job. The return status is 0 unless an invalid option is
4988 encountered or an invalid jobspec is supplied.
4989
4990 If the -x option is supplied, jobs replaces any jobspec found in
4991 command or args with the corresponding process group ID, and
4992 executes command passing it args, returning its exit status.
4993
4994 kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
4995 kill -l|-L [sigspec | exit_status]
4996 Send the signal named by sigspec or signum to the processes
4997 named by pid or jobspec. sigspec is either a case-insensitive
4998 signal name such as SIGKILL (with or without the SIG prefix) or
4999 a signal number; signum is a signal number. If sigspec is not
5000 present, then SIGTERM is assumed. An argument of -l lists the
5001 signal names. If any arguments are supplied when -l is given,
5002 the names of the signals corresponding to the arguments are
5003 listed, and the return status is 0. The exit_status argument to
5004 -l is a number specifying either a signal number or the exit
5005 status of a process terminated by a signal. The -L option is
5006 equivalent to -l. kill returns true if at least one signal was
5007 successfully sent, or false if an error occurs or an invalid
5008 option is encountered.
5009
5010 let arg [arg ...]
5011 Each arg is an arithmetic expression to be evaluated (see ARITH‐
5012 METIC EVALUATION above). If the last arg evaluates to 0, let
5013 returns 1; 0 is returned otherwise.
5014
5015 local [option] [name[=value] ... | - ]
5016 For each argument, a local variable named name is created, and
5017 assigned value. The option can be any of the options accepted
5018 by declare. When local is used within a function, it causes the
5019 variable name to have a visible scope restricted to that func‐
5020 tion and its children. If name is -, the set of shell options
5021 is made local to the function in which local is invoked: shell
5022 options changed using the set builtin inside the function are
5023 restored to their original values when the function returns.
5024 With no operands, local writes a list of local variables to the
5025 standard output. It is an error to use local when not within a
5026 function. The return status is 0 unless local is used outside a
5027 function, an invalid name is supplied, or name is a readonly
5028 variable.
5029
5030 logout Exit a login shell.
5031
5032 mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C
5033 callback] [-c quantum] [array]
5034 readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C
5035 callback] [-c quantum] [array]
5036 Read lines from the standard input into the indexed array vari‐
5037 able array, or from file descriptor fd if the -u option is sup‐
5038 plied. The variable MAPFILE is the default array. Options, if
5039 supplied, have the following meanings:
5040 -d The first character of delim is used to terminate each
5041 input line, rather than newline. If delim is the empty
5042 string, mapfile will terminate a line when it reads a NUL
5043 character.
5044 -n Copy at most count lines. If count is 0, all lines are
5045 copied.
5046 -O Begin assigning to array at index origin. The default
5047 index is 0.
5048 -s Discard the first count lines read.
5049 -t Remove a trailing delim (default newline) from each line
5050 read.
5051 -u Read lines from file descriptor fd instead of the stan‐
5052 dard input.
5053 -C Evaluate callback each time quantum lines are read. The
5054 -c option specifies quantum.
5055 -c Specify the number of lines read between each call to
5056 callback.
5057
5058 If -C is specified without -c, the default quantum is 5000.
5059 When callback is evaluated, it is supplied the index of the next
5060 array element to be assigned and the line to be assigned to that
5061 element as additional arguments. callback is evaluated after
5062 the line is read but before the array element is assigned.
5063
5064 If not supplied with an explicit origin, mapfile will clear
5065 array before assigning to it.
5066
5067 mapfile returns successfully unless an invalid option or option
5068 argument is supplied, array is invalid or unassignable, or if
5069 array is not an indexed array.
5070
5071 popd [-n] [+n] [-n]
5072 Removes entries from the directory stack. With no arguments,
5073 removes the top directory from the stack, and performs a cd to
5074 the new top directory. Arguments, if supplied, have the follow‐
5075 ing meanings:
5076 -n Suppresses the normal change of directory when removing
5077 directories from the stack, so that only the stack is
5078 manipulated.
5079 +n Removes the nth entry counting from the left of the list
5080 shown by dirs, starting with zero. For example: ``popd
5081 +0'' removes the first directory, ``popd +1'' the second.
5082 -n Removes the nth entry counting from the right of the list
5083 shown by dirs, starting with zero. For example: ``popd
5084 -0'' removes the last directory, ``popd -1'' the next to
5085 last.
5086
5087 If the popd command is successful, a dirs is performed as well,
5088 and the return status is 0. popd returns false if an invalid
5089 option is encountered, the directory stack is empty, a non-exis‐
5090 tent directory stack entry is specified, or the directory change
5091 fails.
5092
5093 printf [-v var] format [arguments]
5094 Write the formatted arguments to the standard output under the
5095 control of the format. The -v option causes the output to be
5096 assigned to the variable var rather than being printed to the
5097 standard output.
5098
5099 The format is a character string which contains three types of
5100 objects: plain characters, which are simply copied to standard
5101 output, character escape sequences, which are converted and
5102 copied to the standard output, and format specifications, each
5103 of which causes printing of the next successive argument. In
5104 addition to the standard printf(1) format specifications, printf
5105 interprets the following extensions:
5106 %b causes printf to expand backslash escape sequences in the
5107 corresponding argument in the same way as echo -e.
5108 %q causes printf to output the corresponding argument in a
5109 format that can be reused as shell input.
5110 %(datefmt)T
5111 causes printf to output the date-time string resulting
5112 from using datefmt as a format string for strftime(3).
5113 The corresponding argument is an integer representing the
5114 number of seconds since the epoch. Two special argument
5115 values may be used: -1 represents the current time, and
5116 -2 represents the time the shell was invoked. If no
5117 argument is specified, conversion behaves as if -1 had
5118 been given. This is an exception to the usual printf
5119 behavior.
5120
5121 Arguments to non-string format specifiers are treated as C con‐
5122 stants, except that a leading plus or minus sign is allowed, and
5123 if the leading character is a single or double quote, the value
5124 is the ASCII value of the following character.
5125
5126 The format is reused as necessary to consume all of the argu‐
5127 ments. If the format requires more arguments than are supplied,
5128 the extra format specifications behave as if a zero value or
5129 null string, as appropriate, had been supplied. The return
5130 value is zero on success, non-zero on failure.
5131
5132 pushd [-n] [+n] [-n]
5133 pushd [-n] [dir]
5134 Adds a directory to the top of the directory stack, or rotates
5135 the stack, making the new top of the stack the current working
5136 directory. With no arguments, pushd exchanges the top two
5137 directories and returns 0, unless the directory stack is empty.
5138 Arguments, if supplied, have the following meanings:
5139 -n Suppresses the normal change of directory when rotating
5140 or adding directories to the stack, so that only the
5141 stack is manipulated.
5142 +n Rotates the stack so that the nth directory (counting
5143 from the left of the list shown by dirs, starting with
5144 zero) is at the top.
5145 -n Rotates the stack so that the nth directory (counting
5146 from the right of the list shown by dirs, starting with
5147 zero) is at the top.
5148 dir Adds dir to the directory stack at the top, making it the
5149 new current working directory as if it had been supplied
5150 as the argument to the cd builtin.
5151
5152 If the pushd command is successful, a dirs is performed as well.
5153 If the first form is used, pushd returns 0 unless the cd to dir
5154 fails. With the second form, pushd returns 0 unless the direc‐
5155 tory stack is empty, a non-existent directory stack element is
5156 specified, or the directory change to the specified new current
5157 directory fails.
5158
5159 pwd [-LP]
5160 Print the absolute pathname of the current working directory.
5161 The pathname printed contains no symbolic links if the -P option
5162 is supplied or the -o physical option to the set builtin command
5163 is enabled. If the -L option is used, the pathname printed may
5164 contain symbolic links. The return status is 0 unless an error
5165 occurs while reading the name of the current directory or an
5166 invalid option is supplied.
5167
5168 read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p
5169 prompt] [-t timeout] [-u fd] [name ...]
5170 One line is read from the standard input, or from the file
5171 descriptor fd supplied as an argument to the -u option, split
5172 into words as described above under Word Splitting, and the
5173 first word is assigned to the first name, the second word to the
5174 second name, and so on. If there are more words than names, the
5175 remaining words and their intervening delimiters are assigned to
5176 the last name. If there are fewer words read from the input
5177 stream than names, the remaining names are assigned empty val‐
5178 ues. The characters in IFS are used to split the line into
5179 words using the same rules the shell uses for expansion
5180 (described above under Word Splitting). The backslash character
5181 (\) may be used to remove any special meaning for the next char‐
5182 acter read and for line continuation. Options, if supplied,
5183 have the following meanings:
5184 -a aname
5185 The words are assigned to sequential indices of the array
5186 variable aname, starting at 0. aname is unset before any
5187 new values are assigned. Other name arguments are
5188 ignored.
5189 -d delim
5190 The first character of delim is used to terminate the
5191 input line, rather than newline. If delim is the empty
5192 string, read will terminate a line when it reads a NUL
5193 character.
5194 -e If the standard input is coming from a terminal, readline
5195 (see READLINE above) is used to obtain the line. Read‐
5196 line uses the current (or default, if line editing was
5197 not previously active) editing settings, but uses Read‐
5198 line's default filename completion.
5199 -i text
5200 If readline is being used to read the line, text is
5201 placed into the editing buffer before editing begins.
5202 -n nchars
5203 read returns after reading nchars characters rather than
5204 waiting for a complete line of input, but honors a delim‐
5205 iter if fewer than nchars characters are read before the
5206 delimiter.
5207 -N nchars
5208 read returns after reading exactly nchars characters
5209 rather than waiting for a complete line of input, unless
5210 EOF is encountered or read times out. Delimiter charac‐
5211 ters encountered in the input are not treated specially
5212 and do not cause read to return until nchars characters
5213 are read. The result is not split on the characters in
5214 IFS; the intent is that the variable is assigned exactly
5215 the characters read (with the exception of backslash; see
5216 the -r option below).
5217 -p prompt
5218 Display prompt on standard error, without a trailing new‐
5219 line, before attempting to read any input. The prompt is
5220 displayed only if input is coming from a terminal.
5221 -r Backslash does not act as an escape character. The back‐
5222 slash is considered to be part of the line. In particu‐
5223 lar, a backslash-newline pair may not then be used as a
5224 line continuation.
5225 -s Silent mode. If input is coming from a terminal, charac‐
5226 ters are not echoed.
5227 -t timeout
5228 Cause read to time out and return failure if a complete
5229 line of input (or a specified number of characters) is
5230 not read within timeout seconds. timeout may be a deci‐
5231 mal number with a fractional portion following the deci‐
5232 mal point. This option is only effective if read is
5233 reading input from a terminal, pipe, or other special
5234 file; it has no effect when reading from regular files.
5235 If read times out, read saves any partial input read into
5236 the specified variable name. If timeout is 0, read
5237 returns immediately, without trying to read any data.
5238 The exit status is 0 if input is available on the speci‐
5239 fied file descriptor, non-zero otherwise. The exit sta‐
5240 tus is greater than 128 if the timeout is exceeded.
5241 -u fd Read input from file descriptor fd.
5242
5243 If no names are supplied, the line read is assigned to the vari‐
5244 able REPLY. The exit status is zero, unless end-of-file is
5245 encountered, read times out (in which case the status is greater
5246 than 128), a variable assignment error (such as assigning to a
5247 readonly variable) occurs, or an invalid file descriptor is sup‐
5248 plied as the argument to -u.
5249
5250 readonly [-aAf] [-p] [name[=word] ...]
5251 The given names are marked readonly; the values of these names
5252 may not be changed by subsequent assignment. If the -f option
5253 is supplied, the functions corresponding to the names are so
5254 marked. The -a option restricts the variables to indexed
5255 arrays; the -A option restricts the variables to associative
5256 arrays. If both options are supplied, -A takes precedence. If
5257 no name arguments are given, or if the -p option is supplied, a
5258 list of all readonly names is printed. The other options may be
5259 used to restrict the output to a subset of the set of readonly
5260 names. The -p option causes output to be displayed in a format
5261 that may be reused as input. If a variable name is followed by
5262 =word, the value of the variable is set to word. The return
5263 status is 0 unless an invalid option is encountered, one of the
5264 names is not a valid shell variable name, or -f is supplied with
5265 a name that is not a function.
5266
5267 return [n]
5268 Causes a function to stop executing and return the value speci‐
5269 fied by n to its caller. If n is omitted, the return status is
5270 that of the last command executed in the function body. If
5271 return is executed by a trap handler, the last command used to
5272 determine the status is the last command executed before the
5273 trap handler. If return is executed during a DEBUG trap, the
5274 last command used to determine the status is the last command
5275 executed by the trap handler before return was invoked. If
5276 return is used outside a function, but during execution of a
5277 script by the . (source) command, it causes the shell to stop
5278 executing that script and return either n or the exit status of
5279 the last command executed within the script as the exit status
5280 of the script. If n is supplied, the return value is its least
5281 significant 8 bits. The return status is non-zero if return is
5282 supplied a non-numeric argument, or is used outside a function
5283 and not during execution of a script by . or source. Any com‐
5284 mand associated with the RETURN trap is executed before execu‐
5285 tion resumes after the function or script.
5286
5287 set [--abefhkmnptuvxBCEHPT] [-o option-name] [arg ...]
5288 set [+abefhkmnptuvxBCEHPT] [+o option-name] [arg ...]
5289 Without options, the name and value of each shell variable are
5290 displayed in a format that can be reused as input for setting or
5291 resetting the currently-set variables. Read-only variables can‐
5292 not be reset. In posix mode, only shell variables are listed.
5293 The output is sorted according to the current locale. When
5294 options are specified, they set or unset shell attributes. Any
5295 arguments remaining after option processing are treated as val‐
5296 ues for the positional parameters and are assigned, in order, to
5297 $1, $2, ... $n. Options, if specified, have the following
5298 meanings:
5299 -a Each variable or function that is created or modified is
5300 given the export attribute and marked for export to the
5301 environment of subsequent commands.
5302 -b Report the status of terminated background jobs immedi‐
5303 ately, rather than before the next primary prompt. This
5304 is effective only when job control is enabled.
5305 -e Exit immediately if a pipeline (which may consist of a
5306 single simple command), a list, or a compound command
5307 (see SHELL GRAMMAR above), exits with a non-zero status.
5308 The shell does not exit if the command that fails is
5309 part of the command list immediately following a while
5310 or until keyword, part of the test following the if or
5311 elif reserved words, part of any command executed in a
5312 && or || list except the command following the final &&
5313 or ||, any command in a pipeline but the last, or if the
5314 command's return value is being inverted with !. If a
5315 compound command other than a subshell returns a non-
5316 zero status because a command failed while -e was being
5317 ignored, the shell does not exit. A trap on ERR, if
5318 set, is executed before the shell exits. This option
5319 applies to the shell environment and each subshell envi‐
5320 ronment separately (see COMMAND EXECUTION ENVIRONMENT
5321 above), and may cause subshells to exit before executing
5322 all the commands in the subshell.
5323
5324 If a compound command or shell function executes in a
5325 context where -e is being ignored, none of the commands
5326 executed within the compound command or function body
5327 will be affected by the -e setting, even if -e is set
5328 and a command returns a failure status. If a compound
5329 command or shell function sets -e while executing in a
5330 context where -e is ignored, that setting will not have
5331 any effect until the compound command or the command
5332 containing the function call completes.
5333 -f Disable pathname expansion.
5334 -h Remember the location of commands as they are looked up
5335 for execution. This is enabled by default.
5336 -k All arguments in the form of assignment statements are
5337 placed in the environment for a command, not just those
5338 that precede the command name.
5339 -m Monitor mode. Job control is enabled. This option is
5340 on by default for interactive shells on systems that
5341 support it (see JOB CONTROL above). All processes run
5342 in a separate process group. When a background job com‐
5343 pletes, the shell prints a line containing its exit sta‐
5344 tus.
5345 -n Read commands but do not execute them. This may be used
5346 to check a shell script for syntax errors. This is
5347 ignored by interactive shells.
5348 -o option-name
5349 The option-name can be one of the following:
5350 allexport
5351 Same as -a.
5352 braceexpand
5353 Same as -B.
5354 emacs Use an emacs-style command line editing inter‐
5355 face. This is enabled by default when the shell
5356 is interactive, unless the shell is started with
5357 the --noediting option. This also affects the
5358 editing interface used for read -e.
5359 errexit Same as -e.
5360 errtrace
5361 Same as -E.
5362 functrace
5363 Same as -T.
5364 hashall Same as -h.
5365 histexpand
5366 Same as -H.
5367 history Enable command history, as described above under
5368 HISTORY. This option is on by default in inter‐
5369 active shells.
5370 ignoreeof
5371 The effect is as if the shell command
5372 ``IGNOREEOF=10'' had been executed (see Shell
5373 Variables above).
5374 keyword Same as -k.
5375 monitor Same as -m.
5376 noclobber
5377 Same as -C.
5378 noexec Same as -n.
5379 noglob Same as -f.
5380 nolog Currently ignored.
5381 notify Same as -b.
5382 nounset Same as -u.
5383 onecmd Same as -t.
5384 physical
5385 Same as -P.
5386 pipefail
5387 If set, the return value of a pipeline is the
5388 value of the last (rightmost) command to exit
5389 with a non-zero status, or zero if all commands
5390 in the pipeline exit successfully. This option
5391 is disabled by default.
5392 posix Change the behavior of bash where the default
5393 operation differs from the POSIX standard to
5394 match the standard (posix mode). See SEE ALSO
5395 below for a reference to a document that details
5396 how posix mode affects bash's behavior.
5397 privileged
5398 Same as -p.
5399 verbose Same as -v.
5400 vi Use a vi-style command line editing interface.
5401 This also affects the editing interface used for
5402 read -e.
5403 xtrace Same as -x.
5404 If -o is supplied with no option-name, the values of the
5405 current options are printed. If +o is supplied with no
5406 option-name, a series of set commands to recreate the
5407 current option settings is displayed on the standard
5408 output.
5409 -p Turn on privileged mode. In this mode, the $ENV and
5410 $BASH_ENV files are not processed, shell functions are
5411 not inherited from the environment, and the SHELLOPTS,
5412 BASHOPTS, CDPATH, and GLOBIGNORE variables, if they
5413 appear in the environment, are ignored. If the shell is
5414 started with the effective user (group) id not equal to
5415 the real user (group) id, and the -p option is not sup‐
5416 plied, these actions are taken and the effective user id
5417 is set to the real user id. If the -p option is sup‐
5418 plied at startup, the effective user id is not reset.
5419 Turning this option off causes the effective user and
5420 group ids to be set to the real user and group ids.
5421 -t Exit after reading and executing one command.
5422 -u Treat unset variables and parameters other than the spe‐
5423 cial parameters "@" and "*" as an error when performing
5424 parameter expansion. If expansion is attempted on an
5425 unset variable or parameter, the shell prints an error
5426 message, and, if not interactive, exits with a non-zero
5427 status.
5428 -v Print shell input lines as they are read.
5429 -x After expanding each simple command, for command, case
5430 command, select command, or arithmetic for command, dis‐
5431 play the expanded value of PS4, followed by the command
5432 and its expanded arguments or associated word list.
5433 -B The shell performs brace expansion (see Brace Expansion
5434 above). This is on by default.
5435 -C If set, bash does not overwrite an existing file with
5436 the >, >&, and <> redirection operators. This may be
5437 overridden when creating output files by using the redi‐
5438 rection operator >| instead of >.
5439 -E If set, any trap on ERR is inherited by shell functions,
5440 command substitutions, and commands executed in a sub‐
5441 shell environment. The ERR trap is normally not inher‐
5442 ited in such cases.
5443 -H Enable ! style history substitution. This option is on
5444 by default when the shell is interactive.
5445 -P If set, the shell does not resolve symbolic links when
5446 executing commands such as cd that change the current
5447 working directory. It uses the physical directory
5448 structure instead. By default, bash follows the logical
5449 chain of directories when performing commands which
5450 change the current directory.
5451 -T If set, any traps on DEBUG and RETURN are inherited by
5452 shell functions, command substitutions, and commands
5453 executed in a subshell environment. The DEBUG and
5454 RETURN traps are normally not inherited in such cases.
5455 -- If no arguments follow this option, then the positional
5456 parameters are unset. Otherwise, the positional parame‐
5457 ters are set to the args, even if some of them begin
5458 with a -.
5459 - Signal the end of options, cause all remaining args to
5460 be assigned to the positional parameters. The -x and -v
5461 options are turned off. If there are no args, the posi‐
5462 tional parameters remain unchanged.
5463
5464 The options are off by default unless otherwise noted. Using +
5465 rather than - causes these options to be turned off. The
5466 options can also be specified as arguments to an invocation of
5467 the shell. The current set of options may be found in $-. The
5468 return status is always true unless an invalid option is encoun‐
5469 tered.
5470
5471 shift [n]
5472 The positional parameters from n+1 ... are renamed to $1 ....
5473 Parameters represented by the numbers $# down to $#-n+1 are
5474 unset. n must be a non-negative number less than or equal to
5475 $#. If n is 0, no parameters are changed. If n is not given,
5476 it is assumed to be 1. If n is greater than $#, the positional
5477 parameters are not changed. The return status is greater than
5478 zero if n is greater than $# or less than zero; otherwise 0.
5479
5480 shopt [-pqsu] [-o] [optname ...]
5481 Toggle the values of settings controlling optional shell behav‐
5482 ior. The settings can be either those listed below, or, if the
5483 -o option is used, those available with the -o option to the set
5484 builtin command. With no options, or with the -p option, a list
5485 of all settable options is displayed, with an indication of
5486 whether or not each is set; if optnames are supplied, the output
5487 is restricted to those options. The -p option causes output to
5488 be displayed in a form that may be reused as input. Other
5489 options have the following meanings:
5490 -s Enable (set) each optname.
5491 -u Disable (unset) each optname.
5492 -q Suppresses normal output (quiet mode); the return status
5493 indicates whether the optname is set or unset. If multi‐
5494 ple optname arguments are given with -q, the return sta‐
5495 tus is zero if all optnames are enabled; non-zero other‐
5496 wise.
5497 -o Restricts the values of optname to be those defined for
5498 the -o option to the set builtin.
5499
5500 If either -s or -u is used with no optname arguments, shopt
5501 shows only those options which are set or unset, respectively.
5502 Unless otherwise noted, the shopt options are disabled (unset)
5503 by default.
5504
5505 The return status when listing options is zero if all optnames
5506 are enabled, non-zero otherwise. When setting or unsetting
5507 options, the return status is zero unless an optname is not a
5508 valid shell option.
5509
5510 The list of shopt options is:
5511
5512 assoc_expand_once
5513 If set, the shell suppresses multiple evaluation of
5514 associative array subscripts during arithmetic expres‐
5515 sion evaluation, while executing builtins that can per‐
5516 form variable assignments, and while executing builtins
5517 that perform array dereferencing.
5518 autocd If set, a command name that is the name of a directory
5519 is executed as if it were the argument to the cd com‐
5520 mand. This option is only used by interactive shells.
5521 cdable_vars
5522 If set, an argument to the cd builtin command that is
5523 not a directory is assumed to be the name of a variable
5524 whose value is the directory to change to.
5525 cdspell If set, minor errors in the spelling of a directory com‐
5526 ponent in a cd command will be corrected. The errors
5527 checked for are transposed characters, a missing charac‐
5528 ter, and one character too many. If a correction is
5529 found, the corrected filename is printed, and the com‐
5530 mand proceeds. This option is only used by interactive
5531 shells.
5532 checkhash
5533 If set, bash checks that a command found in the hash ta‐
5534 ble exists before trying to execute it. If a hashed
5535 command no longer exists, a normal path search is per‐
5536 formed.
5537 checkjobs
5538 If set, bash lists the status of any stopped and running
5539 jobs before exiting an interactive shell. If any jobs
5540 are running, this causes the exit to be deferred until a
5541 second exit is attempted without an intervening command
5542 (see JOB CONTROL above). The shell always postpones
5543 exiting if any jobs are stopped.
5544 checkwinsize
5545 If set, bash checks the window size after each external
5546 (non-builtin) command and, if necessary, updates the
5547 values of LINES and COLUMNS. This option is enabled by
5548 default.
5549 cmdhist If set, bash attempts to save all lines of a multiple-
5550 line command in the same history entry. This allows
5551 easy re-editing of multi-line commands. This option is
5552 enabled by default, but only has an effect if command
5553 history is enabled, as described above under HISTORY.
5554 compat31
5555 If set, bash changes its behavior to that of version 3.1
5556 with respect to quoted arguments to the [[ conditional
5557 command's =~ operator and locale-specific string compar‐
5558 ison when using the [[ conditional command's < and >
5559 operators. Bash versions prior to bash-4.1 use ASCII
5560 collation and strcmp(3); bash-4.1 and later use the cur‐
5561 rent locale's collation sequence and strcoll(3).
5562 compat32
5563 If set, bash changes its behavior to that of version 3.2
5564 with respect to locale-specific string comparison when
5565 using the [[ conditional command's < and > operators
5566 (see previous item) and the effect of interrupting a
5567 command list. Bash versions 3.2 and earlier continue
5568 with the next command in the list after one terminates
5569 due to an interrupt.
5570 compat40
5571 If set, bash changes its behavior to that of version 4.0
5572 with respect to locale-specific string comparison when
5573 using the [[ conditional command's < and > operators
5574 (see description of compat31) and the effect of inter‐
5575 rupting a command list. Bash versions 4.0 and later
5576 interrupt the list as if the shell received the inter‐
5577 rupt; previous versions continue with the next command
5578 in the list.
5579 compat41
5580 If set, bash, when in posix mode, treats a single quote
5581 in a double-quoted parameter expansion as a special
5582 character. The single quotes must match (an even num‐
5583 ber) and the characters between the single quotes are
5584 considered quoted. This is the behavior of posix mode
5585 through version 4.1. The default bash behavior remains
5586 as in previous versions.
5587 compat42
5588 If set, bash does not process the replacement string in
5589 the pattern substitution word expansion using quote
5590 removal.
5591 compat43
5592 If set, bash does not print a warning message if an
5593 attempt is made to use a quoted compound array assign‐
5594 ment as an argument to declare, makes word expansion
5595 errors non-fatal errors that cause the current command
5596 to fail (the default behavior is to make them fatal
5597 errors that cause the shell to exit), and does not reset
5598 the loop state when a shell function is executed (this
5599 allows break or continue in a shell function to affect
5600 loops in the caller's context).
5601 compat44
5602 If set, bash saves the positional parameters to
5603 BASH_ARGV and BASH_ARGC before they are used, regardless
5604 of whether or not extended debugging mode is enabled.
5605 complete_fullquote
5606 If set, bash quotes all shell metacharacters in file‐
5607 names and directory names when performing completion.
5608 If not set, bash removes metacharacters such as the dol‐
5609 lar sign from the set of characters that will be quoted
5610 in completed filenames when these metacharacters appear
5611 in shell variable references in words to be completed.
5612 This means that dollar signs in variable names that
5613 expand to directories will not be quoted; however, any
5614 dollar signs appearing in filenames will not be quoted,
5615 either. This is active only when bash is using back‐
5616 slashes to quote completed filenames. This variable is
5617 set by default, which is the default bash behavior in
5618 versions through 4.2.
5619 direxpand
5620 If set, bash replaces directory names with the results
5621 of word expansion when performing filename completion.
5622 This changes the contents of the readline editing buf‐
5623 fer. If not set, bash attempts to preserve what the
5624 user typed.
5625 dirspell
5626 If set, bash attempts spelling correction on directory
5627 names during word completion if the directory name ini‐
5628 tially supplied does not exist.
5629 dotglob If set, bash includes filenames beginning with a `.' in
5630 the results of pathname expansion. The filenames ``.''
5631 and ``..'' must always be matched explicitly, even if
5632 dotglob is set.
5633 execfail
5634 If set, a non-interactive shell will not exit if it can‐
5635 not execute the file specified as an argument to the
5636 exec builtin command. An interactive shell does not
5637 exit if exec fails.
5638 expand_aliases
5639 If set, aliases are expanded as described above under
5640 ALIASES. This option is enabled by default for interac‐
5641 tive shells.
5642 extdebug
5643 If set at shell invocation, arrange to execute the
5644 debugger profile before the shell starts, identical to
5645 the --debugger option. If set after invocation, behav‐
5646 ior intended for use by debuggers is enabled:
5647 1. The -F option to the declare builtin displays the
5648 source file name and line number corresponding to
5649 each function name supplied as an argument.
5650 2. If the command run by the DEBUG trap returns a
5651 non-zero value, the next command is skipped and
5652 not executed.
5653 3. If the command run by the DEBUG trap returns a
5654 value of 2, and the shell is executing in a sub‐
5655 routine (a shell function or a shell script exe‐
5656 cuted by the . or source builtins), the shell
5657 simulates a call to return.
5658 4. BASH_ARGC and BASH_ARGV are updated as described
5659 in their descriptions above.
5660 5. Function tracing is enabled: command substitu‐
5661 tion, shell functions, and subshells invoked with
5662 ( command ) inherit the DEBUG and RETURN traps.
5663 6. Error tracing is enabled: command substitution,
5664 shell functions, and subshells invoked with (
5665 command ) inherit the ERR trap.
5666 extglob If set, the extended pattern matching features described
5667 above under Pathname Expansion are enabled.
5668 extquote
5669 If set, $'string' and $"string" quoting is performed
5670 within ${parameter} expansions enclosed in double
5671 quotes. This option is enabled by default.
5672 failglob
5673 If set, patterns which fail to match filenames during
5674 pathname expansion result in an expansion error.
5675 force_fignore
5676 If set, the suffixes specified by the FIGNORE shell
5677 variable cause words to be ignored when performing word
5678 completion even if the ignored words are the only possi‐
5679 ble completions. See SHELL VARIABLES above for a
5680 description of FIGNORE. This option is enabled by
5681 default.
5682 globasciiranges
5683 If set, range expressions used in pattern matching
5684 bracket expressions (see Pattern Matching above) behave
5685 as if in the traditional C locale when performing com‐
5686 parisons. That is, the current locale's collating
5687 sequence is not taken into account, so b will not col‐
5688 late between A and B, and upper-case and lower-case
5689 ASCII characters will collate together.
5690 globstar
5691 If set, the pattern ** used in a pathname expansion con‐
5692 text will match all files and zero or more directories
5693 and subdirectories. If the pattern is followed by a /,
5694 only directories and subdirectories match.
5695 gnu_errfmt
5696 If set, shell error messages are written in the standard
5697 GNU error message format.
5698 histappend
5699 If set, the history list is appended to the file named
5700 by the value of the HISTFILE variable when the shell
5701 exits, rather than overwriting the file.
5702 histreedit
5703 If set, and readline is being used, a user is given the
5704 opportunity to re-edit a failed history substitution.
5705 histverify
5706 If set, and readline is being used, the results of his‐
5707 tory substitution are not immediately passed to the
5708 shell parser. Instead, the resulting line is loaded
5709 into the readline editing buffer, allowing further modi‐
5710 fication.
5711 hostcomplete
5712 If set, and readline is being used, bash will attempt to
5713 perform hostname completion when a word containing a @
5714 is being completed (see Completing under READLINE
5715 above). This is enabled by default.
5716 huponexit
5717 If set, bash will send SIGHUP to all jobs when an inter‐
5718 active login shell exits.
5719 inherit_errexit
5720 If set, command substitution inherits the value of the
5721 errexit option, instead of unsetting it in the subshell
5722 environment. This option is enabled when posix mode is
5723 enabled.
5724 interactive_comments
5725 If set, allow a word beginning with # to cause that word
5726 and all remaining characters on that line to be ignored
5727 in an interactive shell (see COMMENTS above). This
5728 option is enabled by default.
5729 lastpipe
5730 If set, and job control is not active, the shell runs
5731 the last command of a pipeline not executed in the back‐
5732 ground in the current shell environment.
5733 lithist If set, and the cmdhist option is enabled, multi-line
5734 commands are saved to the history with embedded newlines
5735 rather than using semicolon separators where possible.
5736 localvar_inherit
5737 If set, local variables inherit the value and attributes
5738 of a variable of the same name that exists at a previous
5739 scope before any new value is assigned. The nameref
5740 attribute is not inherited.
5741 localvar_unset
5742 If set, calling unset on local variables in previous
5743 function scopes marks them so subsequent lookups find
5744 them unset until that function returns. This is identi‐
5745 cal to the behavior of unsetting local variables at the
5746 current function scope.
5747 login_shell
5748 The shell sets this option if it is started as a login
5749 shell (see INVOCATION above). The value may not be
5750 changed.
5751 mailwarn
5752 If set, and a file that bash is checking for mail has
5753 been accessed since the last time it was checked, the
5754 message ``The mail in mailfile has been read'' is dis‐
5755 played.
5756 no_empty_cmd_completion
5757 If set, and readline is being used, bash will not
5758 attempt to search the PATH for possible completions when
5759 completion is attempted on an empty line.
5760 nocaseglob
5761 If set, bash matches filenames in a case-insensitive
5762 fashion when performing pathname expansion (see Pathname
5763 Expansion above).
5764 nocasematch
5765 If set, bash matches patterns in a case-insensitive
5766 fashion when performing matching while executing case or
5767 [[ conditional commands, when performing pattern substi‐
5768 tution word expansions, or when filtering possible com‐
5769 pletions as part of programmable completion.
5770 nullglob
5771 If set, bash allows patterns which match no files (see
5772 Pathname Expansion above) to expand to a null string,
5773 rather than themselves.
5774 progcomp
5775 If set, the programmable completion facilities (see Pro‐
5776 grammable Completion above) are enabled. This option is
5777 enabled by default.
5778 progcomp_alias
5779 If set, and programmable completion is enabled, bash
5780 treats a command name that doesn't have any completions
5781 as a possible alias and attempts alias expansion. If it
5782 has an alias, bash attempts programmable completion
5783 using the command word resulting from the expanded
5784 alias.
5785 promptvars
5786 If set, prompt strings undergo parameter expansion, com‐
5787 mand substitution, arithmetic expansion, and quote
5788 removal after being expanded as described in PROMPTING
5789 above. This option is enabled by default.
5790 restricted_shell
5791 The shell sets this option if it is started in
5792 restricted mode (see RESTRICTED SHELL below). The value
5793 may not be changed. This is not reset when the startup
5794 files are executed, allowing the startup files to dis‐
5795 cover whether or not a shell is restricted.
5796 shift_verbose
5797 If set, the shift builtin prints an error message when
5798 the shift count exceeds the number of positional parame‐
5799 ters.
5800 sourcepath
5801 If set, the source (.) builtin uses the value of PATH to
5802 find the directory containing the file supplied as an
5803 argument. This option is enabled by default.
5804 xpg_echo
5805 If set, the echo builtin expands backslash-escape
5806 sequences by default.
5807
5808 suspend [-f]
5809 Suspend the execution of this shell until it receives a SIGCONT
5810 signal. A login shell cannot be suspended; the -f option can be
5811 used to override this and force the suspension. The return sta‐
5812 tus is 0 unless the shell is a login shell and -f is not sup‐
5813 plied, or if job control is not enabled.
5814
5815 test expr
5816 [ expr ]
5817 Return a status of 0 (true) or 1 (false) depending on the evalu‐
5818 ation of the conditional expression expr. Each operator and op‐
5819 erand must be a separate argument. Expressions are composed of
5820 the primaries described above under CONDITIONAL EXPRESSIONS.
5821 test does not accept any options, nor does it accept and ignore
5822 an argument of -- as signifying the end of options.
5823
5824 Expressions may be combined using the following operators,
5825 listed in decreasing order of precedence. The evaluation
5826 depends on the number of arguments; see below. Operator prece‐
5827 dence is used when there are five or more arguments.
5828 ! expr True if expr is false.
5829 ( expr )
5830 Returns the value of expr. This may be used to override
5831 the normal precedence of operators.
5832 expr1 -a expr2
5833 True if both expr1 and expr2 are true.
5834 expr1 -o expr2
5835 True if either expr1 or expr2 is true.
5836
5837 test and [ evaluate conditional expressions using a set of rules
5838 based on the number of arguments.
5839
5840 0 arguments
5841 The expression is false.
5842 1 argument
5843 The expression is true if and only if the argument is not
5844 null.
5845 2 arguments
5846 If the first argument is !, the expression is true if and
5847 only if the second argument is null. If the first argu‐
5848 ment is one of the unary conditional operators listed
5849 above under CONDITIONAL EXPRESSIONS, the expression is
5850 true if the unary test is true. If the first argument is
5851 not a valid unary conditional operator, the expression is
5852 false.
5853 3 arguments
5854 The following conditions are applied in the order listed.
5855 If the second argument is one of the binary conditional
5856 operators listed above under CONDITIONAL EXPRESSIONS, the
5857 result of the expression is the result of the binary test
5858 using the first and third arguments as operands. The -a
5859 and -o operators are considered binary operators when
5860 there are three arguments. If the first argument is !,
5861 the value is the negation of the two-argument test using
5862 the second and third arguments. If the first argument is
5863 exactly ( and the third argument is exactly ), the result
5864 is the one-argument test of the second argument. Other‐
5865 wise, the expression is false.
5866 4 arguments
5867 If the first argument is !, the result is the negation of
5868 the three-argument expression composed of the remaining
5869 arguments. Otherwise, the expression is parsed and eval‐
5870 uated according to precedence using the rules listed
5871 above.
5872 5 or more arguments
5873 The expression is parsed and evaluated according to
5874 precedence using the rules listed above.
5875
5876 When used with test or [, the < and > operators sort lexico‐
5877 graphically using ASCII ordering.
5878
5879 times Print the accumulated user and system times for the shell and
5880 for processes run from the shell. The return status is 0.
5881
5882 trap [-lp] [[arg] sigspec ...]
5883 The command arg is to be read and executed when the shell
5884 receives signal(s) sigspec. If arg is absent (and there is a
5885 single sigspec) or -, each specified signal is reset to its
5886 original disposition (the value it had upon entrance to the
5887 shell). If arg is the null string the signal specified by each
5888 sigspec is ignored by the shell and by the commands it invokes.
5889 If arg is not present and -p has been supplied, then the trap
5890 commands associated with each sigspec are displayed. If no
5891 arguments are supplied or if only -p is given, trap prints the
5892 list of commands associated with each signal. The -l option
5893 causes the shell to print a list of signal names and their cor‐
5894 responding numbers. Each sigspec is either a signal name
5895 defined in <signal.h>, or a signal number. Signal names are
5896 case insensitive and the SIG prefix is optional.
5897
5898 If a sigspec is EXIT (0) the command arg is executed on exit
5899 from the shell. If a sigspec is DEBUG, the command arg is exe‐
5900 cuted before every simple command, for command, case command,
5901 select command, every arithmetic for command, and before the
5902 first command executes in a shell function (see SHELL GRAMMAR
5903 above). Refer to the description of the extdebug option to the
5904 shopt builtin for details of its effect on the DEBUG trap. If a
5905 sigspec is RETURN, the command arg is executed each time a shell
5906 function or a script executed with the . or source builtins fin‐
5907 ishes executing.
5908
5909 If a sigspec is ERR, the command arg is executed whenever a
5910 pipeline (which may consist of a single simple command), a list,
5911 or a compound command returns a non-zero exit status, subject to
5912 the following conditions. The ERR trap is not executed if the
5913 failed command is part of the command list immediately following
5914 a while or until keyword, part of the test in an if statement,
5915 part of a command executed in a && or || list except the command
5916 following the final && or ||, any command in a pipeline but the
5917 last, or if the command's return value is being inverted using
5918 !. These are the same conditions obeyed by the errexit (-e)
5919 option.
5920
5921 Signals ignored upon entry to the shell cannot be trapped, reset
5922 or listed. Trapped signals that are not being ignored are reset
5923 to their original values in a subshell or subshell environment
5924 when one is created. The return status is false if any sigspec
5925 is invalid; otherwise trap returns true.
5926
5927 type [-aftpP] name [name ...]
5928 With no options, indicate how each name would be interpreted if
5929 used as a command name. If the -t option is used, type prints a
5930 string which is one of alias, keyword, function, builtin, or
5931 file if name is an alias, shell reserved word, function,
5932 builtin, or disk file, respectively. If the name is not found,
5933 then nothing is printed, and an exit status of false is
5934 returned. If the -p option is used, type either returns the
5935 name of the disk file that would be executed if name were speci‐
5936 fied as a command name, or nothing if ``type -t name'' would not
5937 return file. The -P option forces a PATH search for each name,
5938 even if ``type -t name'' would not return file. If a command is
5939 hashed, -p and -P print the hashed value, which is not necessar‐
5940 ily the file that appears first in PATH. If the -a option is
5941 used, type prints all of the places that contain an executable
5942 named name. This includes aliases and functions, if and only if
5943 the -p option is not also used. The table of hashed commands is
5944 not consulted when using -a. The -f option suppresses shell
5945 function lookup, as with the command builtin. type returns true
5946 if all of the arguments are found, false if any are not found.
5947
5948 ulimit [-HSabcdefiklmnpqrstuvxPT [limit]]
5949 Provides control over the resources available to the shell and
5950 to processes started by it, on systems that allow such control.
5951 The -H and -S options specify that the hard or soft limit is set
5952 for the given resource. A hard limit cannot be increased by a
5953 non-root user once it is set; a soft limit may be increased up
5954 to the value of the hard limit. If neither -H nor -S is speci‐
5955 fied, both the soft and hard limits are set. The value of limit
5956 can be a number in the unit specified for the resource or one of
5957 the special values hard, soft, or unlimited, which stand for the
5958 current hard limit, the current soft limit, and no limit,
5959 respectively. If limit is omitted, the current value of the
5960 soft limit of the resource is printed, unless the -H option is
5961 given. When more than one resource is specified, the limit name
5962 and unit are printed before the value. Other options are inter‐
5963 preted as follows:
5964 -a All current limits are reported
5965 -b The maximum socket buffer size
5966 -c The maximum size of core files created
5967 -d The maximum size of a process's data segment
5968 -e The maximum scheduling priority ("nice")
5969 -f The maximum size of files written by the shell and its
5970 children
5971 -i The maximum number of pending signals
5972 -k The maximum number of kqueues that may be allocated
5973 -l The maximum size that may be locked into memory
5974 -m The maximum resident set size (many systems do not honor
5975 this limit)
5976 -n The maximum number of open file descriptors (most systems
5977 do not allow this value to be set)
5978 -p The pipe size in 512-byte blocks (this may not be set)
5979 -q The maximum number of bytes in POSIX message queues
5980 -r The maximum real-time scheduling priority
5981 -s The maximum stack size
5982 -t The maximum amount of cpu time in seconds
5983 -u The maximum number of processes available to a single
5984 user
5985 -v The maximum amount of virtual memory available to the
5986 shell and, on some systems, to its children
5987 -x The maximum number of file locks
5988 -P The maximum number of pseudoterminals
5989 -T The maximum number of threads
5990
5991 If limit is given, and the -a option is not used, limit is the
5992 new value of the specified resource. If no option is given,
5993 then -f is assumed. Values are in 1024-byte increments, except
5994 for -t, which is in seconds; -p, which is in units of 512-byte
5995 blocks; -P, -T, -b, -k, -n, and -u, which are unscaled values;
5996 and, when in posix mode, -c and -f, which are in 512-byte incre‐
5997 ments. The return status is 0 unless an invalid option or argu‐
5998 ment is supplied, or an error occurs while setting a new limit.
5999 In POSIX Mode 512-byte blocks are used for the `-c' and `-f'
6000 options.
6001
6002 umask [-p] [-S] [mode]
6003 The user file-creation mask is set to mode. If mode begins with
6004 a digit, it is interpreted as an octal number; otherwise it is
6005 interpreted as a symbolic mode mask similar to that accepted by
6006 chmod(1). If mode is omitted, the current value of the mask is
6007 printed. The -S option causes the mask to be printed in sym‐
6008 bolic form; the default output is an octal number. If the -p
6009 option is supplied, and mode is omitted, the output is in a form
6010 that may be reused as input. The return status is 0 if the mode
6011 was successfully changed or if no mode argument was supplied,
6012 and false otherwise.
6013
6014 unalias [-a] [name ...]
6015 Remove each name from the list of defined aliases. If -a is
6016 supplied, all alias definitions are removed. The return value
6017 is true unless a supplied name is not a defined alias.
6018
6019 unset [-fv] [-n] [name ...]
6020 For each name, remove the corresponding variable or function.
6021 If the -v option is given, each name refers to a shell variable,
6022 and that variable is removed. Read-only variables may not be
6023 unset. If -f is specified, each name refers to a shell func‐
6024 tion, and the function definition is removed. If the -n option
6025 is supplied, and name is a variable with the nameref attribute,
6026 name will be unset rather than the variable it references. -n
6027 has no effect if the -f option is supplied. If no options are
6028 supplied, each name refers to a variable; if there is no vari‐
6029 able by that name, any function with that name is unset. Each
6030 unset variable or function is removed from the environment
6031 passed to subsequent commands. If any of COMP_WORDBREAKS, RAN‐
6032 DOM, SECONDS, LINENO, HISTCMD, FUNCNAME, GROUPS, or DIRSTACK are
6033 unset, they lose their special properties, even if they are sub‐
6034 sequently reset. The exit status is true unless a name is read‐
6035 only.
6036
6037 wait [-fn] [id ...]
6038 Wait for each specified child process and return its termination
6039 status. Each id may be a process ID or a job specification; if
6040 a job spec is given, all processes in that job's pipeline are
6041 waited for. If id is not given, all currently active child pro‐
6042 cesses are waited for, and the return status is zero. If the -n
6043 option is supplied, wait waits for any job to terminate and
6044 returns its exit status. If the -f option is supplied, and job
6045 control is enabled, wait forces id to terminate before returning
6046 its status, instead of returning when it changes status. If id
6047 specifies a non-existent process or job, the return status is
6048 127. Otherwise, the return status is the exit status of the
6049 last process or job waited for.
6050
6052 If bash is started with the name rbash, or the -r option is supplied at
6053 invocation, the shell becomes restricted. A restricted shell is used
6054 to set up an environment more controlled than the standard shell. It
6055 behaves identically to bash with the exception that the following are
6056 disallowed or not performed:
6057
6058 · changing directories with cd
6059
6060 · setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV
6061
6062 · specifying command names containing /
6063
6064 · specifying a filename containing a / as an argument to the .
6065 builtin command
6066
6067 · specifying a filename containing a slash as an argument to the
6068 -p option to the hash builtin command
6069
6070 · importing function definitions from the shell environment at
6071 startup
6072
6073 · parsing the value of SHELLOPTS from the shell environment at
6074 startup
6075
6076 · redirecting output using the >, >|, <>, >&, &>, and >> redirect‐
6077 ion operators
6078
6079 · using the exec builtin command to replace the shell with another
6080 command
6081
6082 · adding or deleting builtin commands with the -f and -d options
6083 to the enable builtin command
6084
6085 · using the enable builtin command to enable disabled shell
6086 builtins
6087
6088 · specifying the -p option to the command builtin command
6089
6090 · turning off restricted mode with set +r or set +o restricted.
6091
6092 These restrictions are enforced after any startup files are read.
6093
6094 When a command that is found to be a shell script is executed (see COM‐
6095 MAND EXECUTION above), rbash turns off any restrictions in the shell
6096 spawned to execute the script.
6097
6099 Bash Reference Manual, Brian Fox and Chet Ramey
6100 The Gnu Readline Library, Brian Fox and Chet Ramey
6101 The Gnu History Library, Brian Fox and Chet Ramey
6102 Portable Operating System Interface (POSIX) Part 2: Shell and Utili‐
6103 ties, IEEE --
6104 http://pubs.opengroup.org/onlinepubs/9699919799/
6105 http://tiswww.case.edu/~chet/bash/POSIX -- a description of posix mode
6106 sh(1), ksh(1), csh(1)
6107 emacs(1), vi(1)
6108 readline(3)
6109
6111 /bin/bash
6112 The bash executable
6113 /etc/profile
6114 The systemwide initialization file, executed for login shells
6115 /etc/bash.bash_logout
6116 The systemwide login shell cleanup file, executed when a login
6117 shell exits
6118 ~/.bash_profile
6119 The personal initialization file, executed for login shells
6120 ~/.bashrc
6121 The individual per-interactive-shell startup file
6122 ~/.bash_logout
6123 The individual login shell cleanup file, executed when a login
6124 shell exits
6125 ~/.inputrc
6126 Individual readline initialization file
6127
6129 Brian Fox, Free Software Foundation
6130 bfox@gnu.org
6131
6132 Chet Ramey, Case Western Reserve University
6133 chet.ramey@case.edu
6134
6136 If you find a bug in bash, you should report it. But first, you should
6137 make sure that it really is a bug, and that it appears in the latest
6138 version of bash. The latest version is always available from
6139 ftp://ftp.gnu.org/pub/gnu/bash/.
6140
6141 Once you have determined that a bug actually exists, use the bashbug
6142 command to submit a bug report. If you have a fix, you are encouraged
6143 to mail that as well! Suggestions and `philosophical' bug reports may
6144 be mailed to bug-bash@gnu.org or posted to the Usenet newsgroup
6145 gnu.bash.bug.
6146
6147 ALL bug reports should include:
6148
6149 The version number of bash
6150 The hardware and operating system
6151 The compiler used to compile
6152 A description of the bug behaviour
6153 A short script or `recipe' which exercises the bug
6154
6155 bashbug inserts the first three items automatically into the template
6156 it provides for filing a bug report.
6157
6158 Comments and bug reports concerning this manual page should be directed
6159 to chet.ramey@case.edu.
6160
6162 It's too big and too slow.
6163
6164 There are some subtle differences between bash and traditional versions
6165 of sh, mostly because of the POSIX specification.
6166
6167 Aliases are confusing in some uses.
6168
6169 Shell builtin commands and functions are not stoppable/restartable.
6170
6171 Compound commands and command sequences of the form `a ; b ; c' are not
6172 handled gracefully when process suspension is attempted. When a
6173 process is stopped, the shell immediately executes the next command in
6174 the sequence. It suffices to place the sequence of commands between
6175 parentheses to force it into a subshell, which may be stopped as a
6176 unit.
6177
6178 Array variables may not (yet) be exported.
6179
6180 There may be only one active coprocess at a time.
6181
6182
6183
6184GNU Bash 5.0 2018 December 7 BASH(1)