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