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 files ~/.bash_logout and /etc/bash.bash_logout, if the files 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 Several extended pattern matching operators are recognized. In the
1722 following description, a pattern-list is a list of one or more patterns
1723 separated by a |. Composite patterns may be formed using one or more
1724 of the following sub-patterns:
1725
1726 ?(pattern-list)
1727 Matches zero or one occurrence of the given patterns
1728 *(pattern-list)
1729 Matches zero or more occurrences of the given patterns
1730 +(pattern-list)
1731 Matches one or more occurrences of the given patterns
1732 @(pattern-list)
1733 Matches one of the given patterns
1734
1735 If the extglob shell option is enabled using the shopt builtin, follow‐
1736 ing pattern matching operator is recognized as well:
1737
1738 !(pattern-list)
1739 Matches anything except one of the given patterns
1740
1741 Quote Removal
1742 After the preceding expansions, all unquoted occurrences of the charac‐
1743 ters \, ', and " that did not result from one of the above expansions
1744 are removed.
1745
1747 Before a command is executed, its input and output may be redirected
1748 using a special notation interpreted by the shell. Redirection may
1749 also be used to open and close files for the current shell execution
1750 environment. The following redirection operators may precede or appear
1751 anywhere within a simple command or may follow a command. Redirections
1752 are processed in the order they appear, from left to right.
1753
1754 Each redirection that may be preceded by a file descriptor number may
1755 instead be preceded by a word of the form {varname}. In this case, for
1756 each redirection operator except >&- and <&-, the shell will allocate a
1757 file descriptor greater than 10 and assign it to varname. If >&- or
1758 <&- is preceded by {varname}, the value of varname defines the file
1759 descriptor to close.
1760
1761 In the following descriptions, if the file descriptor number is omit‐
1762 ted, and the first character of the redirection operator is <, the re‐
1763 direction refers to the standard input (file descriptor 0). If the
1764 first character of the redirection operator is >, the redirection
1765 refers to the standard output (file descriptor 1).
1766
1767 The word following the redirection operator in the following descrip‐
1768 tions, unless otherwise noted, is subjected to brace expansion, tilde
1769 expansion, parameter expansion, command substitution, arithmetic expan‐
1770 sion, quote removal, pathname expansion, and word splitting. If it
1771 expands to more than one word, bash reports an error.
1772
1773 Note that the order of redirections is significant. For example, the
1774 command
1775
1776 ls > dirlist 2>&1
1777
1778 directs both standard output and standard error to the file dirlist,
1779 while the command
1780
1781 ls 2>&1 > dirlist
1782
1783 directs only the standard output to file dirlist, because the standard
1784 error was duplicated from the standard output before the standard out‐
1785 put was redirected to dirlist.
1786
1787 Bash handles several filenames specially when they are used in redirec‐
1788 tions, as described in the following table:
1789
1790 /dev/fd/fd
1791 If fd is a valid integer, file descriptor fd is dupli‐
1792 cated.
1793 /dev/stdin
1794 File descriptor 0 is duplicated.
1795 /dev/stdout
1796 File descriptor 1 is duplicated.
1797 /dev/stderr
1798 File descriptor 2 is duplicated.
1799 /dev/tcp/host/port
1800 If host is a valid hostname or Internet address, and port
1801 is an integer port number or service name, bash attempts
1802 to open a TCP connection to the corresponding socket.
1803 /dev/udp/host/port
1804 If host is a valid hostname or Internet address, and port
1805 is an integer port number or service name, bash attempts
1806 to open a UDP connection to the corresponding socket.
1807
1808 A failure to open or create a file causes the redirection to fail.
1809
1810 Redirections using file descriptors greater than 9 should be used with
1811 care, as they may conflict with file descriptors the shell uses inter‐
1812 nally.
1813
1814 Redirecting Input
1815 Redirection of input causes the file whose name results from the expan‐
1816 sion of word to be opened for reading on file descriptor n, or the
1817 standard input (file descriptor 0) if n is not specified.
1818
1819 The general format for redirecting input is:
1820
1821 [n]<word
1822
1823 Redirecting Output
1824 Redirection of output causes the file whose name results from the
1825 expansion of word to be opened for writing on file descriptor n, or the
1826 standard output (file descriptor 1) if n is not specified. If the file
1827 does not exist it is created; if it does exist it is truncated to zero
1828 size.
1829
1830 The general format for redirecting output is:
1831
1832 [n]>word
1833
1834 If the redirection operator is >, and the noclobber option to the set
1835 builtin has been enabled, the redirection will fail if the file whose
1836 name results from the expansion of word exists and is a regular file.
1837 If the redirection operator is >|, or the redirection operator is > and
1838 the noclobber option to the set builtin command is not enabled, the re‐
1839 direction is attempted even if the file named by word exists.
1840
1841 Appending Redirected Output
1842 Redirection of output in this fashion causes the file whose name
1843 results from the expansion of word to be opened for appending on file
1844 descriptor n, or the standard output (file descriptor 1) if n is not
1845 specified. If the file does not exist it is created.
1846
1847 The general format for appending output is:
1848
1849 [n]>>word
1850
1851 Redirecting Standard Output and Standard Error
1852 This construct allows both the standard output (file descriptor 1) and
1853 the standard error output (file descriptor 2) to be redirected to the
1854 file whose name is the expansion of word.
1855
1856 There are two formats for redirecting standard output and standard
1857 error:
1858
1859 &>word
1860 and
1861 >&word
1862
1863 Of the two forms, the first is preferred. This is semantically equiva‐
1864 lent to
1865
1866 >word 2>&1
1867
1868 Appending Standard Output and Standard Error
1869 This construct allows both the standard output (file descriptor 1) and
1870 the standard error output (file descriptor 2) to be appended to the
1871 file whose name is the expansion of word.
1872
1873 The format for appending standard output and standard error is:
1874
1875 &>>word
1876
1877 This is semantically equivalent to
1878
1879 >>word 2>&1
1880
1881 Here Documents
1882 This type of redirection instructs the shell to read input from the
1883 current source until a line containing only delimiter (with no trailing
1884 blanks) is seen. All of the lines read up to that point are then used
1885 as the standard input for a command.
1886
1887 The format of here-documents is:
1888
1889 <<[-]word
1890 here-document
1891 delimiter
1892
1893 No parameter expansion, command substitution, arithmetic expansion, or
1894 pathname expansion is performed on word. If any characters in word are
1895 quoted, the delimiter is the result of quote removal on word, and the
1896 lines in the here-document are not expanded. If word is unquoted, all
1897 lines of the here-document are subjected to parameter expansion, com‐
1898 mand substitution, and arithmetic expansion. In the latter case, the
1899 character sequence \<newline> is ignored, and \ must be used to quote
1900 the characters \, $, and `.
1901
1902 If the redirection operator is <<-, then all leading tab characters are
1903 stripped from input lines and the line containing delimiter. This
1904 allows here-documents within shell scripts to be indented in a natural
1905 fashion.
1906
1907 Here Strings
1908 A variant of here documents, the format is:
1909
1910 <<<word
1911
1912 The word is expanded and supplied to the command on its standard input.
1913
1914 Duplicating File Descriptors
1915 The redirection operator
1916
1917 [n]<&word
1918
1919 is used to duplicate input file descriptors. If word expands to one or
1920 more digits, the file descriptor denoted by n is made to be a copy of
1921 that file descriptor. If the digits in word do not specify a file
1922 descriptor open for input, a redirection error occurs. If word evalu‐
1923 ates to -, file descriptor n is closed. If n is not specified, the
1924 standard input (file descriptor 0) is used.
1925
1926 The operator
1927
1928 [n]>&word
1929
1930 is used similarly to duplicate output file descriptors. If n is not
1931 specified, the standard output (file descriptor 1) is used. If the
1932 digits in word do not specify a file descriptor open for output, a re‐
1933 direction error occurs. As a special case, if n is omitted, and word
1934 does not expand to one or more digits, the standard output and standard
1935 error are redirected as described previously.
1936
1937 Moving File Descriptors
1938 The redirection operator
1939
1940 [n]<&digit-
1941
1942 moves the file descriptor digit to file descriptor n, or the standard
1943 input (file descriptor 0) if n is not specified. digit is closed after
1944 being duplicated to n.
1945
1946 Similarly, the redirection operator
1947
1948 [n]>&digit-
1949
1950 moves the file descriptor digit to file descriptor n, or the standard
1951 output (file descriptor 1) if n is not specified.
1952
1953 Opening File Descriptors for Reading and Writing
1954 The redirection operator
1955
1956 [n]<>word
1957
1958 causes the file whose name is the expansion of word to be opened for
1959 both reading and writing on file descriptor n, or on file descriptor 0
1960 if n is not specified. If the file does not exist, it is created.
1961
1963 Aliases allow a string to be substituted for a word when it is used as
1964 the first word of a simple command. The shell maintains a list of
1965 aliases that may be set and unset with the alias and unalias builtin
1966 commands (see SHELL BUILTIN COMMANDS below). The first word of each
1967 simple command, if unquoted, is checked to see if it has an alias. If
1968 so, that word is replaced by the text of the alias. The characters /,
1969 $, `, and = and any of the shell metacharacters or quoting characters
1970 listed above may not appear in an alias name. The replacement text may
1971 contain any valid shell input, including shell metacharacters. The
1972 first word of the replacement text is tested for aliases, but a word
1973 that is identical to an alias being expanded is not expanded a second
1974 time. This means that one may alias ls to ls -F, for instance, and
1975 bash does not try to recursively expand the replacement text. If the
1976 last character of the alias value is a blank, then the next command
1977 word following the alias is also checked for alias expansion.
1978
1979 Aliases are created and listed with the alias command, and removed with
1980 the unalias command.
1981
1982 There is no mechanism for using arguments in the replacement text. If
1983 arguments are needed, a shell function should be used (see FUNCTIONS
1984 below).
1985
1986 Aliases are not expanded when the shell is not interactive, unless the
1987 expand_aliases shell option is set using shopt (see the description of
1988 shopt under SHELL BUILTIN COMMANDS below).
1989
1990 The rules concerning the definition and use of aliases are somewhat
1991 confusing. Bash always reads at least one complete line of input
1992 before executing any of the commands on that line. Aliases are
1993 expanded when a command is read, not when it is executed. Therefore,
1994 an alias definition appearing on the same line as another command does
1995 not take effect until the next line of input is read. The commands
1996 following the alias definition on that line are not affected by the new
1997 alias. This behavior is also an issue when functions are executed.
1998 Aliases are expanded when a function definition is read, not when the
1999 function is executed, because a function definition is itself a com‐
2000 pound command. As a consequence, aliases defined in a function are not
2001 available until after that function is executed. To be safe, always
2002 put alias definitions on a separate line, and do not use alias in com‐
2003 pound commands.
2004
2005 For almost every purpose, aliases are superseded by shell functions.
2006
2008 A shell function, defined as described above under SHELL GRAMMAR,
2009 stores a series of commands for later execution. When the name of a
2010 shell function is used as a simple command name, the list of commands
2011 associated with that function name is executed. Functions are executed
2012 in the context of the current shell; no new process is created to
2013 interpret them (contrast this with the execution of a shell script).
2014 When a function is executed, the arguments to the function become the
2015 positional parameters during its execution. The special parameter # is
2016 updated to reflect the change. Special parameter 0 is unchanged. The
2017 first element of the FUNCNAME variable is set to the name of the func‐
2018 tion while the function is executing.
2019
2020 All other aspects of the shell execution environment are identical
2021 between a function and its caller with these exceptions: the DEBUG and
2022 RETURN traps (see the description of the trap builtin under SHELL
2023 BUILTIN COMMANDS below) are not inherited unless the function has been
2024 given the trace attribute (see the description of the declare builtin
2025 below) or the -o functrace shell option has been enabled with the set
2026 builtin (in which case all functions inherit the DEBUG and RETURN
2027 traps), and the ERR trap is not inherited unless the -o errtrace shell
2028 option has been enabled.
2029
2030 Variables local to the function may be declared with the local builtin
2031 command. Ordinarily, variables and their values are shared between the
2032 function and its caller.
2033
2034 If the builtin command return is executed in a function, the function
2035 completes and execution resumes with the next command after the func‐
2036 tion call. Any command associated with the RETURN trap is executed
2037 before execution resumes. When a function completes, the values of the
2038 positional parameters and the special parameter # are restored to the
2039 values they had prior to the function's execution.
2040
2041 Function names and definitions may be listed with the -f option to the
2042 declare or typeset builtin commands. The -F option to declare or type‐
2043 set will list the function names only (and optionally the source file
2044 and line number, if the extdebug shell option is enabled). Functions
2045 may be exported so that subshells automatically have them defined with
2046 the -f option to the export builtin. A function definition may be
2047 deleted using the -f option to the unset builtin. Note that shell
2048 functions and variables with the same name may result in multiple iden‐
2049 tically-named entries in the environment passed to the shell's chil‐
2050 dren. Care should be taken in cases where this may cause a problem.
2051
2052 Functions may be recursive. No limit is imposed on the number of
2053 recursive calls.
2054
2056 The shell allows arithmetic expressions to be evaluated, under certain
2057 circumstances (see the let and declare builtin commands and Arithmetic
2058 Expansion). Evaluation is done in fixed-width integers with no check
2059 for overflow, though division by 0 is trapped and flagged as an error.
2060 The operators and their precedence, associativity, and values are the
2061 same as in the C language. The following list of operators is grouped
2062 into levels of equal-precedence operators. The levels are listed in
2063 order of decreasing precedence.
2064
2065 id++ id--
2066 variable post-increment and post-decrement
2067 ++id --id
2068 variable pre-increment and pre-decrement
2069 - + unary minus and plus
2070 ! ~ logical and bitwise negation
2071 ** exponentiation
2072 * / % multiplication, division, remainder
2073 + - addition, subtraction
2074 << >> left and right bitwise shifts
2075 <= >= < >
2076 comparison
2077 == != equality and inequality
2078 & bitwise AND
2079 ^ bitwise exclusive OR
2080 | bitwise OR
2081 && logical AND
2082 || logical OR
2083 expr?expr:expr
2084 conditional operator
2085 = *= /= %= += -= <<= >>= &= ^= |=
2086 assignment
2087 expr1 , expr2
2088 comma
2089
2090 Shell variables are allowed as operands; parameter expansion is per‐
2091 formed before the expression is evaluated. Within an expression, shell
2092 variables may also be referenced by name without using the parameter
2093 expansion syntax. A shell variable that is null or unset evaluates to
2094 0 when referenced by name without using the parameter expansion syntax.
2095 The value of a variable is evaluated as an arithmetic expression when
2096 it is referenced, or when a variable which has been given the integer
2097 attribute using declare -i is assigned a value. A null value evaluates
2098 to 0. A shell variable need not have its integer attribute turned on
2099 to be used in an expression.
2100
2101 Constants with a leading 0 are interpreted as octal numbers. A leading
2102 0x or 0X denotes hexadecimal. Otherwise, numbers take the form
2103 [base#]n, where base is a decimal number between 2 and 64 representing
2104 the arithmetic base, and n is a number in that base. If base# is omit‐
2105 ted, then base 10 is used. The digits greater than 9 are represented
2106 by the lowercase letters, the uppercase letters, @, and _, in that
2107 order. If base is less than or equal to 36, lowercase and uppercase
2108 letters may be used interchangeably to represent numbers between 10 and
2109 35.
2110
2111 Operators are evaluated in order of precedence. Sub-expressions in
2112 parentheses are evaluated first and may override the precedence rules
2113 above.
2114
2116 Conditional expressions are used by the [[ compound command and the
2117 test and [ builtin commands to test file attributes and perform string
2118 and arithmetic comparisons. Expressions are formed from the following
2119 unary or binary primaries. If any file argument to one of the pri‐
2120 maries is of the form /dev/fd/n, then file descriptor n is checked. If
2121 the file argument to one of the primaries is one of /dev/stdin,
2122 /dev/stdout, or /dev/stderr, file descriptor 0, 1, or 2, respectively,
2123 is checked.
2124
2125 Unless otherwise specified, primaries that operate on files follow sym‐
2126 bolic links and operate on the target of the link, rather than the link
2127 itself.
2128
2129 When used with [[, The < and > operators sort lexicographically using
2130 the current locale.
2131
2132 -a file
2133 True if file exists.
2134 -b file
2135 True if file exists and is a block special file.
2136 -c file
2137 True if file exists and is a character special file.
2138 -d file
2139 True if file exists and is a directory.
2140 -e file
2141 True if file exists.
2142 -f file
2143 True if file exists and is a regular file.
2144 -g file
2145 True if file exists and is set-group-id.
2146 -h file
2147 True if file exists and is a symbolic link.
2148 -k file
2149 True if file exists and its ``sticky'' bit is set.
2150 -p file
2151 True if file exists and is a named pipe (FIFO).
2152 -r file
2153 True if file exists and is readable.
2154 -s file
2155 True if file exists and has a size greater than zero.
2156 -t fd True if file descriptor fd is open and refers to a terminal.
2157 -u file
2158 True if file exists and its set-user-id bit is set.
2159 -w file
2160 True if file exists and is writable.
2161 -x file
2162 True if file exists and is executable.
2163 -O file
2164 True if file exists and is owned by the effective user id.
2165 -G file
2166 True if file exists and is owned by the effective group id.
2167 -L file
2168 True if file exists and is a symbolic link.
2169 -S file
2170 True if file exists and is a socket.
2171 -N file
2172 True if file exists and has been modified since it was last
2173 read.
2174 file1 -nt file2
2175 True if file1 is newer (according to modification date) than
2176 file2, or if file1 exists and file2 does not.
2177 file1 -ot file2
2178 True if file1 is older than file2, or if file2 exists and file1
2179 does not.
2180 file1 -ef file2
2181 True if file1 and file2 refer to the same device and inode num‐
2182 bers.
2183 -o optname
2184 True if shell option optname is enabled. See the list of
2185 options under the description of the -o option to the set
2186 builtin below.
2187 -z string
2188 True if the length of string is zero.
2189 string
2190 -n string
2191 True if the length of string is non-zero.
2192
2193 string1 == string2
2194 string1 = string2
2195 True if the strings are equal. = should be used with the test
2196 command for POSIX conformance.
2197
2198 string1 != string2
2199 True if the strings are not equal.
2200
2201 string1 < string2
2202 True if string1 sorts before string2 lexicographically.
2203
2204 string1 > string2
2205 True if string1 sorts after string2 lexicographically.
2206
2207 arg1 OP arg2
2208 OP is one of -eq, -ne, -lt, -le, -gt, or -ge. These arithmetic
2209 binary operators return true if arg1 is equal to, not equal to,
2210 less than, less than or equal to, greater than, or greater than
2211 or equal to arg2, respectively. Arg1 and arg2 may be positive
2212 or negative integers.
2213
2215 When a simple command is executed, the shell performs the following
2216 expansions, assignments, and redirections, from left to right.
2217
2218 1. The words that the parser has marked as variable assignments
2219 (those preceding the command name) and redirections are saved
2220 for later processing.
2221
2222 2. The words that are not variable assignments or redirections are
2223 expanded. If any words remain after expansion, the first word
2224 is taken to be the name of the command and the remaining words
2225 are the arguments.
2226
2227 3. Redirections are performed as described above under REDIRECTION.
2228
2229 4. The text after the = in each variable assignment undergoes tilde
2230 expansion, parameter expansion, command substitution, arithmetic
2231 expansion, and quote removal before being assigned to the vari‐
2232 able.
2233
2234 If no command name results, the variable assignments affect the current
2235 shell environment. Otherwise, the variables are added to the environ‐
2236 ment of the executed command and do not affect the current shell envi‐
2237 ronment. If any of the assignments attempts to assign a value to a
2238 readonly variable, an error occurs, and the command exits with a non-
2239 zero status.
2240
2241 If no command name results, redirections are performed, but do not
2242 affect the current shell environment. A redirection error causes the
2243 command to exit with a non-zero status.
2244
2245 If there is a command name left after expansion, execution proceeds as
2246 described below. Otherwise, the command exits. If one of the expan‐
2247 sions contained a command substitution, the exit status of the command
2248 is the exit status of the last command substitution performed. If
2249 there were no command substitutions, the command exits with a status of
2250 zero.
2251
2253 After a command has been split into words, if it results in a simple
2254 command and an optional list of arguments, the following actions are
2255 taken.
2256
2257 If the command name contains no slashes, the shell attempts to locate
2258 it. If there exists a shell function by that name, that function is
2259 invoked as described above in FUNCTIONS. If the name does not match a
2260 function, the shell searches for it in the list of shell builtins. If
2261 a match is found, that builtin is invoked.
2262
2263 If the name is neither a shell function nor a builtin, and contains no
2264 slashes, bash searches each element of the PATH for a directory con‐
2265 taining an executable file by that name. Bash uses a hash table to
2266 remember the full pathnames of executable files (see hash under SHELL
2267 BUILTIN COMMANDS below). A full search of the directories in PATH is
2268 performed only if the command is not found in the hash table. If the
2269 search is unsuccessful, the shell searches for a defined shell function
2270 named command_not_found_handle. If that function exists, it is invoked
2271 with the original command and the original command's arguments as its
2272 arguments, and the function's exit status becomes the exit status of
2273 the shell. If that function is not defined, the shell prints an error
2274 message and returns an exit status of 127.
2275
2276 If the search is successful, or if the command name contains one or
2277 more slashes, the shell executes the named program in a separate execu‐
2278 tion environment. Argument 0 is set to the name given, and the remain‐
2279 ing arguments to the command are set to the arguments given, if any.
2280
2281 If this execution fails because the file is not in executable format,
2282 and the file is not a directory, it is assumed to be a shell script, a
2283 file containing shell commands. A subshell is spawned to execute it.
2284 This subshell reinitializes itself, so that the effect is as if a new
2285 shell had been invoked to handle the script, with the exception that
2286 the locations of commands remembered by the parent (see hash below
2287 under SHELL BUILTIN COMMANDS) are retained by the child.
2288
2289 If the program is a file beginning with #!, the remainder of the first
2290 line specifies an interpreter for the program. The shell executes the
2291 specified interpreter on operating systems that do not handle this exe‐
2292 cutable format themselves. The arguments to the interpreter consist of
2293 a single optional argument following the interpreter name on the first
2294 line of the program, followed by the name of the program, followed by
2295 the command arguments, if any.
2296
2298 The shell has an execution environment, which consists of the follow‐
2299 ing:
2300
2301
2302 · open files inherited by the shell at invocation, as modified by
2303 redirections supplied to the exec builtin
2304
2305 · the current working directory as set by cd, pushd, or popd, or
2306 inherited by the shell at invocation
2307
2308 · the file creation mode mask as set by umask or inherited from
2309 the shell's parent
2310
2311 · current traps set by trap
2312
2313 · shell parameters that are set by variable assignment or with set
2314 or inherited from the shell's parent in the environment
2315
2316 · shell functions defined during execution or inherited from the
2317 shell's parent in the environment
2318
2319 · options enabled at invocation (either by default or with com‐
2320 mand-line arguments) or by set
2321
2322 · options enabled by shopt
2323
2324 · shell aliases defined with alias
2325
2326 · various process IDs, including those of background jobs, the
2327 value of $$, and the value of PPID
2328
2329 When a simple command other than a builtin or shell function is to be
2330 executed, it is invoked in a separate execution environment that con‐
2331 sists of the following. Unless otherwise noted, the values are inher‐
2332 ited from the shell.
2333
2334
2335 · the shell's open files, plus any modifications and additions
2336 specified by redirections to the command
2337
2338 · the current working directory
2339
2340 · the file creation mode mask
2341
2342 · shell variables and functions marked for export, along with
2343 variables exported for the command, passed in the environment
2344
2345 · traps caught by the shell are reset to the values inherited from
2346 the shell's parent, and traps ignored by the shell are ignored
2347
2348 A command invoked in this separate environment cannot affect the
2349 shell's execution environment.
2350
2351 Command substitution, commands grouped with parentheses, and asynchro‐
2352 nous commands are invoked in a subshell environment that is a duplicate
2353 of the shell environment, except that traps caught by the shell are
2354 reset to the values that the shell inherited from its parent at invoca‐
2355 tion. Builtin commands that are invoked as part of a pipeline are also
2356 executed in a subshell environment. Changes made to the subshell envi‐
2357 ronment cannot affect the shell's execution environment.
2358
2359 Subshells spawned to execute command substitutions inherit the value of
2360 the -e option from the parent shell. When not in posix mode, Bash
2361 clears the -e option in such subshells.
2362
2363 If a command is followed by a & and job control is not active, the
2364 default standard input for the command is the empty file /dev/null.
2365 Otherwise, the invoked command inherits the file descriptors of the
2366 calling shell as modified by redirections.
2367
2369 When a program is invoked it is given an array of strings called the
2370 environment. This is a list of name-value pairs, of the form
2371 name=value.
2372
2373 The shell provides several ways to manipulate the environment. On
2374 invocation, the shell scans its own environment and creates a parameter
2375 for each name found, automatically marking it for export to child pro‐
2376 cesses. Executed commands inherit the environment. The export and
2377 declare -x commands allow parameters and functions to be added to and
2378 deleted from the environment. If the value of a parameter in the envi‐
2379 ronment is modified, the new value becomes part of the environment,
2380 replacing the old. The environment inherited by any executed command
2381 consists of the shell's initial environment, whose values may be modi‐
2382 fied in the shell, less any pairs removed by the unset command, plus
2383 any additions via the export and declare -x commands.
2384
2385 The environment for any simple command or function may be augmented
2386 temporarily by prefixing it with parameter assignments, as described
2387 above in PARAMETERS. These assignment statements affect only the envi‐
2388 ronment seen by that command.
2389
2390 If the -k option is set (see the set builtin command below), then all
2391 parameter assignments are placed in the environment for a command, not
2392 just those that precede the command name.
2393
2394 When bash invokes an external command, the variable _ is set to the
2395 full file name of the command and passed to that command in its envi‐
2396 ronment.
2397
2399 The exit status of an executed command is the value returned by the
2400 waitpid system call or equivalent function. Exit statuses fall between
2401 0 and 255, though, as explained below, the shell may use values above
2402 125 specially. Exit statuses from shell builtins and compound commands
2403 are also limited to this range. Under certain circumstances, the shell
2404 will use special values to indicate specific failure modes.
2405
2406 For the shell's purposes, a command which exits with a zero exit status
2407 has succeeded. An exit status of zero indicates success. A non-zero
2408 exit status indicates failure. When a command terminates on a fatal
2409 signal N, bash uses the value of 128+N as the exit status.
2410
2411 If a command is not found, the child process created to execute it
2412 returns a status of 127. If a command is found but is not executable,
2413 the return status is 126.
2414
2415 If a command fails because of an error during expansion or redirection,
2416 the exit status is greater than zero.
2417
2418 Shell builtin commands return a status of 0 (true) if successful, and
2419 non-zero (false) if an error occurs while they execute. All builtins
2420 return an exit status of 2 to indicate incorrect usage.
2421
2422 Bash itself returns the exit status of the last command executed,
2423 unless a syntax error occurs, in which case it exits with a non-zero
2424 value. See also the exit builtin command below.
2425
2427 When bash is interactive, in the absence of any traps, it ignores
2428 SIGTERM (so that kill 0 does not kill an interactive shell), and SIGINT
2429 is caught and handled (so that the wait builtin is interruptible). In
2430 all cases, bash ignores SIGQUIT. If job control is in effect, bash
2431 ignores SIGTTIN, SIGTTOU, and SIGTSTP.
2432
2433 Non-builtin commands run by bash have signal handlers set to the values
2434 inherited by the shell from its parent. When job control is not in
2435 effect, asynchronous commands ignore SIGINT and SIGQUIT in addition to
2436 these inherited handlers. Commands run as a result of command substi‐
2437 tution ignore the keyboard-generated job control signals SIGTTIN, SIGT‐
2438 TOU, and SIGTSTP.
2439
2440 The shell exits by default upon receipt of a SIGHUP. Before exiting,
2441 an interactive shell resends the SIGHUP to all jobs, running or
2442 stopped. Stopped jobs are sent SIGCONT to ensure that they receive the
2443 SIGHUP. To prevent the shell from sending the signal to a particular
2444 job, it should be removed from the jobs table with the disown builtin
2445 (see SHELL BUILTIN COMMANDS below) or marked to not receive SIGHUP
2446 using disown -h.
2447
2448 If the huponexit shell option has been set with shopt, bash sends a
2449 SIGHUP to all jobs when an interactive login shell exits.
2450
2451 If bash is waiting for a command to complete and receives a signal for
2452 which a trap has been set, the trap will not be executed until the com‐
2453 mand completes. When bash is waiting for an asynchronous command via
2454 the wait builtin, the reception of a signal for which a trap has been
2455 set will cause the wait builtin to return immediately with an exit sta‐
2456 tus greater than 128, immediately after which the trap is executed.
2457
2459 Job control refers to the ability to selectively stop (suspend) the
2460 execution of processes and continue (resume) their execution at a later
2461 point. A user typically employs this facility via an interactive
2462 interface supplied jointly by the operating system kernel's terminal
2463 driver and bash.
2464
2465 The shell associates a job with each pipeline. It keeps a table of
2466 currently executing jobs, which may be listed with the jobs command.
2467 When bash starts a job asynchronously (in the background), it prints a
2468 line that looks like:
2469
2470 [1] 25647
2471
2472 indicating that this job is job number 1 and that the process ID of the
2473 last process in the pipeline associated with this job is 25647. All of
2474 the processes in a single pipeline are members of the same job. Bash
2475 uses the job abstraction as the basis for job control.
2476
2477 To facilitate the implementation of the user interface to job control,
2478 the operating system maintains the notion of a current terminal process
2479 group ID. Members of this process group (processes whose process group
2480 ID is equal to the current terminal process group ID) receive keyboard-
2481 generated signals such as SIGINT. These processes are said to be in
2482 the foreground. Background processes are those whose process group ID
2483 differs from the terminal's; such processes are immune to keyboard-gen‐
2484 erated signals. Only foreground processes are allowed to read from or,
2485 if the user so specifies with stty tostop, write to the terminal.
2486 Background processes which attempt to read from (write to when stty
2487 tostop is in effect) the terminal are sent a SIGTTIN (SIGTTOU) signal
2488 by the kernel's terminal driver, which, unless caught, suspends the
2489 process.
2490
2491 If the operating system on which bash is running supports job control,
2492 bash contains facilities to use it. Typing the suspend character (typ‐
2493 ically ^Z, Control-Z) while a process is running causes that process to
2494 be stopped and returns control to bash. Typing the delayed suspend
2495 character (typically ^Y, Control-Y) causes the process to be stopped
2496 when it attempts to read input from the terminal, and control to be
2497 returned to bash. The user may then manipulate the state of this job,
2498 using the bg command to continue it in the background, the fg command
2499 to continue it in the foreground, or the kill command to kill it. A ^Z
2500 takes effect immediately, and has the additional side effect of causing
2501 pending output and typeahead to be discarded.
2502
2503 There are a number of ways to refer to a job in the shell. The charac‐
2504 ter % introduces a job specification (jobspec). Job number n may be
2505 referred to as %n. A job may also be referred to using a prefix of the
2506 name used to start it, or using a substring that appears in its command
2507 line. For example, %ce refers to a stopped ce job. If a prefix
2508 matches more than one job, bash reports an error. Using %?ce, on the
2509 other hand, refers to any job containing the string ce in its command
2510 line. If the substring matches more than one job, bash reports an
2511 error. The symbols %% and %+ refer to the shell's notion of the cur‐
2512 rent job, which is the last job stopped while it was in the foreground
2513 or started in the background. The previous job may be referenced using
2514 %-. If there is only a single job, %+ and %- can both be used to refer
2515 to that job. In output pertaining to jobs (e.g., the output of the
2516 jobs command), the current job is always flagged with a +, and the pre‐
2517 vious job with a -. A single % (with no accompanying job specifica‐
2518 tion) also refers to the current job.
2519
2520 Simply naming a job can be used to bring it into the foreground: %1 is
2521 a synonym for ``fg %1'', bringing job 1 from the background into the
2522 foreground. Similarly, ``%1 &'' resumes job 1 in the background,
2523 equivalent to ``bg %1''.
2524
2525 The shell learns immediately whenever a job changes state. Normally,
2526 bash waits until it is about to print a prompt before reporting changes
2527 in a job's status so as to not interrupt any other output. If the -b
2528 option to the set builtin command is enabled, bash reports such changes
2529 immediately. Any trap on SIGCHLD is executed for each child that
2530 exits.
2531
2532 If an attempt to exit bash is made while jobs are stopped (or, if the
2533 checkjobs shell option has been enabled using the shopt builtin, run‐
2534 ning), the shell prints a warning message, and, if the checkjobs option
2535 is enabled, lists the jobs and their statuses. The jobs command may
2536 then be used to inspect their status. If a second attempt to exit is
2537 made without an intervening command, the shell does not print another
2538 warning, and any stopped jobs are terminated.
2539
2541 When executing interactively, bash displays the primary prompt PS1 when
2542 it is ready to read a command, and the secondary prompt PS2 when it
2543 needs more input to complete a command. Bash allows these prompt
2544 strings to be customized by inserting a number of backslash-escaped
2545 special characters that are decoded as follows:
2546 \a an ASCII bell character (07)
2547 \d the date in "Weekday Month Date" format (e.g., "Tue May
2548 26")
2549 \D{format}
2550 the format is passed to strftime(3) and the result is
2551 inserted into the prompt string; an empty format results
2552 in a locale-specific time representation. The braces are
2553 required
2554 \e an ASCII escape character (033)
2555 \h the hostname up to the first `.'
2556 \H the hostname
2557 \j the number of jobs currently managed by the shell
2558 \l the basename of the shell's terminal device name
2559 \n newline
2560 \r carriage return
2561 \s the name of the shell, the basename of $0 (the portion
2562 following the final slash)
2563 \t the current time in 24-hour HH:MM:SS format
2564 \T the current time in 12-hour HH:MM:SS format
2565 \@ the current time in 12-hour am/pm format
2566 \A the current time in 24-hour HH:MM format
2567 \u the username of the current user
2568 \v the version of bash (e.g., 2.00)
2569 \V the release of bash, version + patch level (e.g., 2.00.0)
2570 \w the current working directory, with $HOME abbreviated
2571 with a tilde (uses the value of the PROMPT_DIRTRIM vari‐
2572 able)
2573 \W the basename of the current working directory, with $HOME
2574 abbreviated with a tilde
2575 \! the history number of this command
2576 \# the command number of this command
2577 \$ if the effective UID is 0, a #, otherwise a $
2578 \nnn the character corresponding to the octal number nnn
2579 \\ a backslash
2580 \[ begin a sequence of non-printing characters, which could
2581 be used to embed a terminal control sequence into the
2582 prompt
2583 \] end a sequence of non-printing characters
2584
2585 The command number and the history number are usually different: the
2586 history number of a command is its position in the history list, which
2587 may include commands restored from the history file (see HISTORY
2588 below), while the command number is the position in the sequence of
2589 commands executed during the current shell session. After the string
2590 is decoded, it is expanded via parameter expansion, command substitu‐
2591 tion, arithmetic expansion, and quote removal, subject to the value of
2592 the promptvars shell option (see the description of the shopt command
2593 under SHELL BUILTIN COMMANDS below).
2594
2596 This is the library that handles reading input when using an interac‐
2597 tive shell, unless the --noediting option is given at shell invocation.
2598 Line editing is also used when using the -e option to the read builtin.
2599 By default, the line editing commands are similar to those of emacs. A
2600 vi-style line editing interface is also available. Line editing can be
2601 enabled at any time using the -o emacs or -o vi options to the set
2602 builtin (see SHELL BUILTIN COMMANDS below). To turn off line editing
2603 after the shell is running, use the +o emacs or +o vi options to the
2604 set builtin.
2605
2606 Readline Notation
2607 In this section, the emacs-style notation is used to denote keystrokes.
2608 Control keys are denoted by C-key, e.g., C-n means Control-N. Simi‐
2609 larly, meta keys are denoted by M-key, so M-x means Meta-X. (On key‐
2610 boards without a meta key, M-x means ESC x, i.e., press the Escape key
2611 then the x key. This makes ESC the meta prefix. The combination M-C-x
2612 means ESC-Control-x, or press the Escape key then hold the Control key
2613 while pressing the x key.)
2614
2615 Readline commands may be given numeric arguments, which normally act as
2616 a repeat count. Sometimes, however, it is the sign of the argument
2617 that is significant. Passing a negative argument to a command that
2618 acts in the forward direction (e.g., kill-line) causes that command to
2619 act in a backward direction. Commands whose behavior with arguments
2620 deviates from this are noted below.
2621
2622 When a command is described as killing text, the text deleted is saved
2623 for possible future retrieval (yanking). The killed text is saved in a
2624 kill ring. Consecutive kills cause the text to be accumulated into one
2625 unit, which can be yanked all at once. Commands which do not kill text
2626 separate the chunks of text on the kill ring.
2627
2628 Readline Initialization
2629 Readline is customized by putting commands in an initialization file
2630 (the inputrc file). The name of this file is taken from the value of
2631 the INPUTRC variable. If that variable is unset, the default is
2632 ~/.inputrc. When a program which uses the readline library starts up,
2633 the initialization file is read, and the key bindings and variables are
2634 set. There are only a few basic constructs allowed in the readline
2635 initialization file. Blank lines are ignored. Lines beginning with a
2636 # are comments. Lines beginning with a $ indicate conditional con‐
2637 structs. Other lines denote key bindings and variable settings.
2638
2639 The default key-bindings may be changed with an inputrc file. Other
2640 programs that use this library may add their own commands and bindings.
2641
2642 For example, placing
2643
2644 M-Control-u: universal-argument
2645 or
2646 C-Meta-u: universal-argument
2647 into the inputrc would make M-C-u execute the readline command univer‐
2648 sal-argument.
2649
2650 The following symbolic character names are recognized: RUBOUT, DEL,
2651 ESC, LFD, NEWLINE, RET, RETURN, SPC, SPACE, and TAB.
2652
2653 In addition to command names, readline allows keys to be bound to a
2654 string that is inserted when the key is pressed (a macro).
2655
2656 Readline Key Bindings
2657 The syntax for controlling key bindings in the inputrc file is simple.
2658 All that is required is the name of the command or the text of a macro
2659 and a key sequence to which it should be bound. The name may be speci‐
2660 fied in one of two ways: as a symbolic key name, possibly with Meta- or
2661 Control- prefixes, or as a key sequence.
2662
2663 When using the form keyname:function-name or macro, keyname is the name
2664 of a key spelled out in English. For example:
2665
2666 Control-u: universal-argument
2667 Meta-Rubout: backward-kill-word
2668 Control-o: "> output"
2669
2670 In the above example, C-u is bound to the function universal-argument,
2671 M-DEL is bound to the function backward-kill-word, and C-o is bound to
2672 run the macro expressed on the right hand side (that is, to insert the
2673 text ``> output'' into the line).
2674
2675 In the second form, "keyseq":function-name or macro, keyseq differs
2676 from keyname above in that strings denoting an entire key sequence may
2677 be specified by placing the sequence within double quotes. Some GNU
2678 Emacs style key escapes can be used, as in the following example, but
2679 the symbolic character names are not recognized.
2680
2681 "\C-u": universal-argument
2682 "\C-x\C-r": re-read-init-file
2683 "\e[11~": "Function Key 1"
2684
2685 In this example, C-u is again bound to the function universal-argument.
2686 C-x C-r is bound to the function re-read-init-file, and ESC [ 1 1 ~ is
2687 bound to insert the text ``Function Key 1''.
2688
2689 The full set of GNU Emacs style escape sequences is
2690 \C- control prefix
2691 \M- meta prefix
2692 \e an escape character
2693 \\ backslash
2694 \" literal "
2695 \' literal '
2696
2697 In addition to the GNU Emacs style escape sequences, a second set of
2698 backslash escapes is available:
2699 \a alert (bell)
2700 \b backspace
2701 \d delete
2702 \f form feed
2703 \n newline
2704 \r carriage return
2705 \t horizontal tab
2706 \v vertical tab
2707 \nnn the eight-bit character whose value is the octal value
2708 nnn (one to three digits)
2709 \xHH the eight-bit character whose value is the hexadecimal
2710 value HH (one or two hex digits)
2711
2712 When entering the text of a macro, single or double quotes must be used
2713 to indicate a macro definition. Unquoted text is assumed to be a func‐
2714 tion name. In the macro body, the backslash escapes described above
2715 are expanded. Backslash will quote any other character in the macro
2716 text, including " and '.
2717
2718 Bash allows the current readline key bindings to be displayed or modi‐
2719 fied with the bind builtin command. The editing mode may be switched
2720 during interactive use by using the -o option to the set builtin com‐
2721 mand (see SHELL BUILTIN COMMANDS below).
2722
2723 Readline Variables
2724 Readline has variables that can be used to further customize its behav‐
2725 ior. A variable may be set in the inputrc file with a statement of the
2726 form
2727
2728 set variable-name value
2729
2730 Except where noted, readline variables can take the values On or Off
2731 (without regard to case). Unrecognized variable names are ignored.
2732 When a variable value is read, empty or null values, "on" (case-insen‐
2733 sitive), and "1" are equivalent to On. All other values are equivalent
2734 to Off. The variables and their default values are:
2735
2736 bell-style (audible)
2737 Controls what happens when readline wants to ring the terminal
2738 bell. If set to none, readline never rings the bell. If set to
2739 visible, readline uses a visible bell if one is available. If
2740 set to audible, readline attempts to ring the terminal's bell.
2741 bind-tty-special-chars (On)
2742 If set to On, readline attempts to bind the control characters
2743 treated specially by the kernel's terminal driver to their read‐
2744 line equivalents.
2745 comment-begin (``#'')
2746 The string that is inserted when the readline insert-comment
2747 command is executed. This command is bound to M-# in emacs mode
2748 and to # in vi command mode.
2749 completion-ignore-case (Off)
2750 If set to On, readline performs filename matching and completion
2751 in a case-insensitive fashion.
2752 completion-prefix-display-length (0)
2753 The length in characters of the common prefix of a list of pos‐
2754 sible completions that is displayed without modification. When
2755 set to a value greater than zero, common prefixes longer than
2756 this value are replaced with an ellipsis when displaying possi‐
2757 ble completions.
2758 completion-query-items (100)
2759 This determines when the user is queried about viewing the num‐
2760 ber of possible completions generated by the possible-comple‐
2761 tions command. It may be set to any integer value greater than
2762 or equal to zero. If the number of possible completions is
2763 greater than or equal to the value of this variable, the user is
2764 asked whether or not he wishes to view them; otherwise they are
2765 simply listed on the terminal.
2766 convert-meta (On)
2767 If set to On, readline will convert characters with the eighth
2768 bit set to an ASCII key sequence by stripping the eighth bit and
2769 prefixing an escape character (in effect, using escape as the
2770 meta prefix).
2771 disable-completion (Off)
2772 If set to On, readline will inhibit word completion. Completion
2773 characters will be inserted into the line as if they had been
2774 mapped to self-insert.
2775 editing-mode (emacs)
2776 Controls whether readline begins with a set of key bindings sim‐
2777 ilar to emacs or vi. editing-mode can be set to either emacs or
2778 vi.
2779 echo-control-characters (On)
2780 When set to On, on operating systems that indicate they support
2781 it, readline echoes a character corresponding to a signal gener‐
2782 ated from the keyboard.
2783 enable-keypad (Off)
2784 When set to On, readline will try to enable the application key‐
2785 pad when it is called. Some systems need this to enable the
2786 arrow keys.
2787 enable-meta-key (On)
2788 When set to On, readline will try to enable any meta modifier
2789 key the terminal claims to support when it is called. On many
2790 terminals, the meta key is used to send eight-bit characters.
2791 expand-tilde (Off)
2792 If set to on, tilde expansion is performed when readline
2793 attempts word completion.
2794 history-preserve-point (Off)
2795 If set to on, the history code attempts to place point at the
2796 same location on each history line retrieved with previous-his‐
2797 tory or next-history.
2798 history-size (0)
2799 Set the maximum number of history entries saved in the history
2800 list. If set to zero, the number of entries in the history list
2801 is not limited.
2802 horizontal-scroll-mode (Off)
2803 When set to On, makes readline use a single line for display,
2804 scrolling the input horizontally on a single screen line when it
2805 becomes longer than the screen width rather than wrapping to a
2806 new line.
2807 input-meta (Off)
2808 If set to On, readline will enable eight-bit input (that is, it
2809 will not strip the high bit from the characters it reads),
2810 regardless of what the terminal claims it can support. The name
2811 meta-flag is a synonym for this variable.
2812 isearch-terminators (``C-[C-J'')
2813 The string of characters that should terminate an incremental
2814 search without subsequently executing the character as a com‐
2815 mand. If this variable has not been given a value, the charac‐
2816 ters ESC and C-J will terminate an incremental search.
2817 keymap (emacs)
2818 Set the current readline keymap. The set of valid keymap names
2819 is emacs, emacs-standard, emacs-meta, emacs-ctlx, vi, vi-com‐
2820 mand, and vi-insert. vi is equivalent to vi-command; emacs is
2821 equivalent to emacs-standard. The default value is emacs; the
2822 value of editing-mode also affects the default keymap.
2823 mark-directories (On)
2824 If set to On, completed directory names have a slash appended.
2825 mark-modified-lines (Off)
2826 If set to On, history lines that have been modified are dis‐
2827 played with a preceding asterisk (*).
2828 mark-symlinked-directories (Off)
2829 If set to On, completed names which are symbolic links to direc‐
2830 tories have a slash appended (subject to the value of
2831 mark-directories).
2832 match-hidden-files (On)
2833 This variable, when set to On, causes readline to match files
2834 whose names begin with a `.' (hidden files) when performing
2835 filename completion, unless the leading `.' is supplied by the
2836 user in the filename to be completed.
2837 output-meta (Off)
2838 If set to On, readline will display characters with the eighth
2839 bit set directly rather than as a meta-prefixed escape sequence.
2840 page-completions (On)
2841 If set to On, readline uses an internal more-like pager to dis‐
2842 play a screenful of possible completions at a time.
2843 print-completions-horizontally (Off)
2844 If set to On, readline will display completions with matches
2845 sorted horizontally in alphabetical order, rather than down the
2846 screen.
2847 revert-all-at-newline (Off)
2848 If set to on, readline will undo all changes to history lines
2849 before returning when accept-line is executed. By default, his‐
2850 tory lines may be modified and retain individual undo lists
2851 across calls to readline.
2852 show-all-if-ambiguous (Off)
2853 This alters the default behavior of the completion functions.
2854 If set to on, words which have more than one possible completion
2855 cause the matches to be listed immediately instead of ringing
2856 the bell.
2857 show-all-if-unmodified (Off)
2858 This alters the default behavior of the completion functions in
2859 a fashion similar to show-all-if-ambiguous. If set to on, words
2860 which have more than one possible completion without any possi‐
2861 ble partial completion (the possible completions don't share a
2862 common prefix) cause the matches to be listed immediately
2863 instead of ringing the bell.
2864 skip-completed-text (Off)
2865 If set to On, this alters the default completion behavior when
2866 inserting a single match into the line. It's only active when
2867 performing completion in the middle of a word. If enabled,
2868 readline does not insert characters from the completion that
2869 match characters after point in the word being completed, so
2870 portions of the word following the cursor are not duplicated.
2871 visible-stats (Off)
2872 If set to On, a character denoting a file's type as reported by
2873 stat(2) is appended to the filename when listing possible com‐
2874 pletions.
2875
2876 Readline Conditional Constructs
2877 Readline implements a facility similar in spirit to the conditional
2878 compilation features of the C preprocessor which allows key bindings
2879 and variable settings to be performed as the result of tests. There
2880 are four parser directives used.
2881
2882 $if The $if construct allows bindings to be made based on the edit‐
2883 ing mode, the terminal being used, or the application using
2884 readline. The text of the test extends to the end of the line;
2885 no characters are required to isolate it.
2886
2887 mode The mode= form of the $if directive is used to test
2888 whether readline is in emacs or vi mode. This may be
2889 used in conjunction with the set keymap command, for
2890 instance, to set bindings in the emacs-standard and
2891 emacs-ctlx keymaps only if readline is starting out in
2892 emacs mode.
2893
2894 term The term= form may be used to include terminal-specific
2895 key bindings, perhaps to bind the key sequences output by
2896 the terminal's function keys. The word on the right side
2897 of the = is tested against the both full name of the ter‐
2898 minal and the portion of the terminal name before the
2899 first -. This allows sun to match both sun and sun-cmd,
2900 for instance.
2901
2902 application
2903 The application construct is used to include application-
2904 specific settings. Each program using the readline
2905 library sets the application name, and an initialization
2906 file can test for a particular value. This could be used
2907 to bind key sequences to functions useful for a specific
2908 program. For instance, the following command adds a key
2909 sequence that quotes the current or previous word in
2910 Bash:
2911
2912 $if Bash
2913 # Quote the current or previous word
2914 "\C-xq": "\eb\"\ef\""
2915 $endif
2916
2917 $endif This command, as seen in the previous example, terminates an $if
2918 command.
2919
2920 $else Commands in this branch of the $if directive are executed if the
2921 test fails.
2922
2923 $include
2924 This directive takes a single filename as an argument and reads
2925 commands and bindings from that file. For example, the follow‐
2926 ing directive would read /etc/inputrc:
2927
2928 $include /etc/inputrc
2929
2930 Searching
2931 Readline provides commands for searching through the command history
2932 (see HISTORY below) for lines containing a specified string. There are
2933 two search modes: incremental and non-incremental.
2934
2935 Incremental searches begin before the user has finished typing the
2936 search string. As each character of the search string is typed, read‐
2937 line displays the next entry from the history matching the string typed
2938 so far. An incremental search requires only as many characters as
2939 needed to find the desired history entry. The characters present in
2940 the value of the isearch-terminators variable are used to terminate an
2941 incremental search. If that variable has not been assigned a value the
2942 Escape and Control-J characters will terminate an incremental search.
2943 Control-G will abort an incremental search and restore the original
2944 line. When the search is terminated, the history entry containing the
2945 search string becomes the current line.
2946
2947 To find other matching entries in the history list, type Control-S or
2948 Control-R as appropriate. This will search backward or forward in the
2949 history for the next entry matching the search string typed so far.
2950 Any other key sequence bound to a readline command will terminate the
2951 search and execute that command. For instance, a newline will termi‐
2952 nate the search and accept the line, thereby executing the command from
2953 the history list.
2954
2955 Readline remembers the last incremental search string. If two Control-
2956 Rs are typed without any intervening characters defining a new search
2957 string, any remembered search string is used.
2958
2959 Non-incremental searches read the entire search string before starting
2960 to search for matching history lines. The search string may be typed
2961 by the user or be part of the contents of the current line.
2962
2963 Readline Command Names
2964 The following is a list of the names of the commands and the default
2965 key sequences to which they are bound. Command names without an accom‐
2966 panying key sequence are unbound by default. In the following descrip‐
2967 tions, point refers to the current cursor position, and mark refers to
2968 a cursor position saved by the set-mark command. The text between the
2969 point and mark is referred to as the region.
2970
2971 Commands for Moving
2972 beginning-of-line (C-a)
2973 Move to the start of the current line.
2974 end-of-line (C-e)
2975 Move to the end of the line.
2976 forward-char (C-f)
2977 Move forward a character.
2978 backward-char (C-b)
2979 Move back a character.
2980 forward-word (M-f)
2981 Move forward to the end of the next word. Words are composed of
2982 alphanumeric characters (letters and digits).
2983 backward-word (M-b)
2984 Move back to the start of the current or previous word. Words
2985 are composed of alphanumeric characters (letters and digits).
2986 shell-forward-word
2987 Move forward to the end of the next word. Words are delimited
2988 by non-quoted shell metacharacters.
2989 shell-backward-word
2990 Move back to the start of the current or previous word. Words
2991 are delimited by non-quoted shell metacharacters.
2992 clear-screen (C-l)
2993 Clear the screen leaving the current line at the top of the
2994 screen. With an argument, refresh the current line without
2995 clearing the screen.
2996 redraw-current-line
2997 Refresh the current line.
2998
2999 Commands for Manipulating the History
3000 accept-line (Newline, Return)
3001 Accept the line regardless of where the cursor is. If this line
3002 is non-empty, add it to the history list according to the state
3003 of the HISTCONTROL variable. If the line is a modified history
3004 line, then restore the history line to its original state.
3005 previous-history (C-p)
3006 Fetch the previous command from the history list, moving back in
3007 the list.
3008 next-history (C-n)
3009 Fetch the next command from the history list, moving forward in
3010 the list.
3011 beginning-of-history (M-<)
3012 Move to the first line in the history.
3013 end-of-history (M->)
3014 Move to the end of the input history, i.e., the line currently
3015 being entered.
3016 reverse-search-history (C-r)
3017 Search backward starting at the current line and moving `up'
3018 through the history as necessary. This is an incremental
3019 search.
3020 forward-search-history (C-s)
3021 Search forward starting at the current line and moving `down'
3022 through the history as necessary. This is an incremental
3023 search.
3024 non-incremental-reverse-search-history (M-p)
3025 Search backward through the history starting at the current line
3026 using a non-incremental search for a string supplied by the
3027 user.
3028 non-incremental-forward-search-history (M-n)
3029 Search forward through the history using a non-incremental
3030 search for a string supplied by the user.
3031 history-search-forward
3032 Search forward through the history for the string of characters
3033 between the start of the current line and the point. This is a
3034 non-incremental search.
3035 history-search-backward
3036 Search backward through the history for the string of characters
3037 between the start of the current line and the point. This is a
3038 non-incremental search.
3039 yank-nth-arg (M-C-y)
3040 Insert the first argument to the previous command (usually the
3041 second word on the previous line) at point. With an argument n,
3042 insert the nth word from the previous command (the words in the
3043 previous command begin with word 0). A negative argument
3044 inserts the nth word from the end of the previous command. Once
3045 the argument n is computed, the argument is extracted as if the
3046 "!n" history expansion had been specified.
3047 yank-last-arg (M-., M-_)
3048 Insert the last argument to the previous command (the last word
3049 of the previous history entry). With an argument, behave
3050 exactly like yank-nth-arg. Successive calls to yank-last-arg
3051 move back through the history list, inserting the last argument
3052 of each line in turn. The history expansion facilities are used
3053 to extract the last argument, as if the "!$" history expansion
3054 had been specified.
3055 shell-expand-line (M-C-e)
3056 Expand the line as the shell does. This performs alias and his‐
3057 tory expansion as well as all of the shell word expansions. See
3058 HISTORY EXPANSION below for a description of history expansion.
3059 history-expand-line (M-^)
3060 Perform history expansion on the current line. See HISTORY
3061 EXPANSION below for a description of history expansion.
3062 magic-space
3063 Perform history expansion on the current line and insert a
3064 space. See HISTORY EXPANSION below for a description of history
3065 expansion.
3066 alias-expand-line
3067 Perform alias expansion on the current line. See ALIASES above
3068 for a description of alias expansion.
3069 history-and-alias-expand-line
3070 Perform history and alias expansion on the current line.
3071 insert-last-argument (M-., M-_)
3072 A synonym for yank-last-arg.
3073 operate-and-get-next (C-o)
3074 Accept the current line for execution and fetch the next line
3075 relative to the current line from the history for editing. Any
3076 argument is ignored.
3077 edit-and-execute-command (C-xC-e)
3078 Invoke an editor on the current command line, and execute the
3079 result as shell commands. Bash attempts to invoke $VISUAL,
3080 $EDITOR, and emacs as the editor, in that order.
3081
3082 Commands for Changing Text
3083 delete-char (C-d)
3084 Delete the character at point. If point is at the beginning of
3085 the line, there are no characters in the line, and the last
3086 character typed was not bound to delete-char, then return EOF.
3087 backward-delete-char (Rubout)
3088 Delete the character behind the cursor. When given a numeric
3089 argument, save the deleted text on the kill ring.
3090 forward-backward-delete-char
3091 Delete the character under the cursor, unless the cursor is at
3092 the end of the line, in which case the character behind the cur‐
3093 sor is deleted.
3094 quoted-insert (C-q, C-v)
3095 Add the next character typed to the line verbatim. This is how
3096 to insert characters like C-q, for example.
3097 tab-insert (C-v TAB)
3098 Insert a tab character.
3099 self-insert (a, b, A, 1, !, ...)
3100 Insert the character typed.
3101 transpose-chars (C-t)
3102 Drag the character before point forward over the character at
3103 point, moving point forward as well. If point is at the end of
3104 the line, then this transposes the two characters before point.
3105 Negative arguments have no effect.
3106 transpose-words (M-t)
3107 Drag the word before point past the word after point, moving
3108 point over that word as well. If point is at the end of the
3109 line, this transposes the last two words on the line.
3110 upcase-word (M-u)
3111 Uppercase the current (or following) word. With a negative
3112 argument, uppercase the previous word, but do not move point.
3113 downcase-word (M-l)
3114 Lowercase the current (or following) word. With a negative
3115 argument, lowercase the previous word, but do not move point.
3116 capitalize-word (M-c)
3117 Capitalize the current (or following) word. With a negative
3118 argument, capitalize the previous word, but do not move point.
3119 overwrite-mode
3120 Toggle overwrite mode. With an explicit positive numeric argu‐
3121 ment, switches to overwrite mode. With an explicit non-positive
3122 numeric argument, switches to insert mode. This command affects
3123 only emacs mode; vi mode does overwrite differently. Each call
3124 to readline() starts in insert mode. In overwrite mode, charac‐
3125 ters bound to self-insert replace the text at point rather than
3126 pushing the text to the right. Characters bound to back‐
3127 ward-delete-char replace the character before point with a
3128 space. By default, this command is unbound.
3129
3130 Killing and Yanking
3131 kill-line (C-k)
3132 Kill the text from point to the end of the line.
3133 backward-kill-line (C-x Rubout)
3134 Kill backward to the beginning of the line.
3135 unix-line-discard (C-u)
3136 Kill backward from point to the beginning of the line. The
3137 killed text is saved on the kill-ring.
3138 kill-whole-line
3139 Kill all characters on the current line, no matter where point
3140 is.
3141 kill-word (M-d)
3142 Kill from point to the end of the current word, or if between
3143 words, to the end of the next word. Word boundaries are the
3144 same as those used by forward-word.
3145 backward-kill-word (M-Rubout)
3146 Kill the word behind point. Word boundaries are the same as
3147 those used by backward-word.
3148 shell-kill-word (M-d)
3149 Kill from point to the end of the current word, or if between
3150 words, to the end of the next word. Word boundaries are the
3151 same as those used by shell-forward-word.
3152 shell-backward-kill-word (M-Rubout)
3153 Kill the word behind point. Word boundaries are the same as
3154 those used by shell-backward-word.
3155 unix-word-rubout (C-w)
3156 Kill the word behind point, using white space as a word bound‐
3157 ary. The killed text is saved on the kill-ring.
3158 unix-filename-rubout
3159 Kill the word behind point, using white space and the slash
3160 character as the word boundaries. The killed text is saved on
3161 the kill-ring.
3162 delete-horizontal-space (M-\)
3163 Delete all spaces and tabs around point.
3164 kill-region
3165 Kill the text in the current region.
3166 copy-region-as-kill
3167 Copy the text in the region to the kill buffer.
3168 copy-backward-word
3169 Copy the word before point to the kill buffer. The word bound‐
3170 aries are the same as backward-word.
3171 copy-forward-word
3172 Copy the word following point to the kill buffer. The word
3173 boundaries are the same as forward-word.
3174 yank (C-y)
3175 Yank the top of the kill ring into the buffer at point.
3176 yank-pop (M-y)
3177 Rotate the kill ring, and yank the new top. Only works follow‐
3178 ing yank or yank-pop.
3179
3180 Numeric Arguments
3181 digit-argument (M-0, M-1, ..., M--)
3182 Add this digit to the argument already accumulating, or start a
3183 new argument. M-- starts a negative argument.
3184 universal-argument
3185 This is another way to specify an argument. If this command is
3186 followed by one or more digits, optionally with a leading minus
3187 sign, those digits define the argument. If the command is fol‐
3188 lowed by digits, executing universal-argument again ends the
3189 numeric argument, but is otherwise ignored. As a special case,
3190 if this command is immediately followed by a character that is
3191 neither a digit or minus sign, the argument count for the next
3192 command is multiplied by four. The argument count is initially
3193 one, so executing this function the first time makes the argu‐
3194 ment count four, a second time makes the argument count sixteen,
3195 and so on.
3196
3197 Completing
3198 complete (TAB)
3199 Attempt to perform completion on the text before point. Bash
3200 attempts completion treating the text as a variable (if the text
3201 begins with $), username (if the text begins with ~), hostname
3202 (if the text begins with @), or command (including aliases and
3203 functions) in turn. If none of these produces a match, filename
3204 completion is attempted.
3205 possible-completions (M-?)
3206 List the possible completions of the text before point.
3207 insert-completions (M-*)
3208 Insert all completions of the text before point that would have
3209 been generated by possible-completions.
3210 menu-complete
3211 Similar to complete, but replaces the word to be completed with
3212 a single match from the list of possible completions. Repeated
3213 execution of menu-complete steps through the list of possible
3214 completions, inserting each match in turn. At the end of the
3215 list of completions, the bell is rung (subject to the setting of
3216 bell-style) and the original text is restored. An argument of n
3217 moves n positions forward in the list of matches; a negative
3218 argument may be used to move backward through the list. This
3219 command is intended to be bound to TAB, but is unbound by
3220 default.c
3221 menu-complete-krd
3222 Identicwal to menu-complete, but moves backward through the list
3223 of possible completions, as if menu-complete had been given a
3224 negative argument. This command is unbound by default.
3225 delete-char-or-list
3226 Deletes the character under the cursor if not at the beginning
3227 or end of the line (like delete-char). If at the end of the
3228 line, behaves identically to possible-completions. This command
3229 is unbound by default.
3230 complete-filename (M-/)
3231 Attempt filename completion on the text before point.
3232 possible-filename-completions (C-x /)
3233 List the possible completions of the text before point, treating
3234 it as a filename.
3235 complete-username (M-~)
3236 Attempt completion on the text before point, treating it as a
3237 username.
3238 possible-username-completions (C-x ~)
3239 List the possible completions of the text before point, treating
3240 it as a username.
3241 complete-variable (M-$)
3242 Attempt completion on the text before point, treating it as a
3243 shell variable.
3244 possible-variable-completions (C-x $)
3245 List the possible completions of the text before point, treating
3246 it as a shell variable.
3247 complete-hostname (M-@)
3248 Attempt completion on the text before point, treating it as a
3249 hostname.
3250 possible-hostname-completions (C-x @)
3251 List the possible completions of the text before point, treating
3252 it as a hostname.
3253 complete-command (M-!)
3254 Attempt completion on the text before point, treating it as a
3255 command name. Command completion attempts to match the text
3256 against aliases, reserved words, shell functions, shell
3257 builtins, and finally executable filenames, in that order.
3258 possible-command-completions (C-x !)
3259 List the possible completions of the text before point, treating
3260 it as a command name.
3261 dynamic-complete-history (M-TAB)
3262 Attempt completion on the text before point, comparing the text
3263 against lines from the history list for possible completion
3264 matches.
3265 dabbrev-expand
3266 Attempt menu completion on the text before point, comparing the
3267 text against lines from the history list for possible completion
3268 matches.
3269 complete-into-braces (M-{)
3270 Perform filename completion and insert the list of possible com‐
3271 pletions enclosed within braces so the list is available to the
3272 shell (see Brace Expansion above).
3273
3274 Keyboard Macros
3275 start-kbd-macro (C-x ()
3276 Begin saving the characters typed into the current keyboard
3277 macro.
3278 end-kbd-macro (C-x ))
3279 Stop saving the characters typed into the current keyboard macro
3280 and store the definition.
3281 call-last-kbd-macro (C-x e)
3282 Re-execute the last keyboard macro defined, by making the char‐
3283 acters in the macro appear as if typed at the keyboard.
3284
3285 Miscellaneous
3286 re-read-init-file (C-x C-r)
3287 Read in the contents of the inputrc file, and incorporate any
3288 bindings or variable assignments found there.
3289 abort (C-g)
3290 Abort the current editing command and ring the terminal's bell
3291 (subject to the setting of bell-style).
3292 do-uppercase-version (M-a, M-b, M-x, ...)
3293 If the metafied character x is lowercase, run the command that
3294 is bound to the corresponding uppercase character.
3295 prefix-meta (ESC)
3296 Metafy the next character typed. ESC f is equivalent to Meta-f.
3297 undo (C-_, C-x C-u)
3298 Incremental undo, separately remembered for each line.
3299 revert-line (M-r)
3300 Undo all changes made to this line. This is like executing the
3301 undo command enough times to return the line to its initial
3302 state.
3303 tilde-expand (M-&)
3304 Perform tilde expansion on the current word.
3305 set-mark (C-@, M-<space>)
3306 Set the mark to the point. If a numeric argument is supplied,
3307 the mark is set to that position.
3308 exchange-point-and-mark (C-x C-x)
3309 Swap the point with the mark. The current cursor position is
3310 set to the saved position, and the old cursor position is saved
3311 as the mark.
3312 character-search (C-])
3313 A character is read and point is moved to the next occurrence of
3314 that character. A negative count searches for previous occur‐
3315 rences.
3316 character-search-backward (M-C-])
3317 A character is read and point is moved to the previous occur‐
3318 rence of that character. A negative count searches for subse‐
3319 quent occurrences.
3320 skip-csi-sequence ()
3321 Read enough characters to consume a multi-key sequence such as
3322 those defined for keys like Home and End. Such sequences begin
3323 with a Control Sequence Indicator (CSI), usually ESC-[. If this
3324 sequence is bound to "\[", keys producing such sequences will
3325 have no effect unless explicitly bound to a readline command,
3326 instead of inserting stray characters into the editing buffer.
3327 This is unbound by default, but usually bound to ESC-[.
3328 insert-comment (M-#)
3329 Without a numeric argument, the value of the readline com‐
3330 ment-begin variable is inserted at the beginning of the current
3331 line. If a numeric argument is supplied, this command acts as a
3332 toggle: if the characters at the beginning of the line do not
3333 match the value of comment-begin, the value is inserted, other‐
3334 wise the characters in comment-begin are deleted from the begin‐
3335 ning of the line. In either case, the line is accepted as if a
3336 newline had been typed. The default value of comment-begin
3337 causes this command to make the current line a shell comment.
3338 If a numeric argument causes the comment character to be
3339 removed, the line will be executed by the shell.
3340 glob-complete-word (M-g)
3341 The word before point is treated as a pattern for pathname
3342 expansion, with an asterisk implicitly appended. This pattern
3343 is used to generate a list of matching file names for possible
3344 completions.
3345 glob-expand-word (C-x *)
3346 The word before point is treated as a pattern for pathname
3347 expansion, and the list of matching file names is inserted,
3348 replacing the word. If a numeric argument is supplied, an
3349 asterisk is appended before pathname expansion.
3350 glob-list-expansions (C-x g)
3351 The list of expansions that would have been generated by
3352 glob-expand-word is displayed, and the line is redrawn. If a
3353 numeric argument is supplied, an asterisk is appended before
3354 pathname expansion.
3355 dump-functions
3356 Print all of the functions and their key bindings to the read‐
3357 line output stream. If a numeric argument is supplied, the out‐
3358 put is formatted in such a way that it can be made part of an
3359 inputrc file.
3360 dump-variables
3361 Print all of the settable readline variables and their values to
3362 the readline output stream. If a numeric argument is supplied,
3363 the output is formatted in such a way that it can be made part
3364 of an inputrc file.
3365 dump-macros
3366 Print all of the readline key sequences bound to macros and the
3367 strings they output. If a numeric argument is supplied, the
3368 output is formatted in such a way that it can be made part of an
3369 inputrc file.
3370 display-shell-version (C-x C-v)
3371 Display version information about the current instance of bash.
3372
3373 Programmable Completion
3374 When word completion is attempted for an argument to a command for
3375 which a completion specification (a compspec) has been defined using
3376 the complete builtin (see SHELL BUILTIN COMMANDS below), the program‐
3377 mable completion facilities are invoked.
3378
3379 First, the command name is identified. If the command word is the
3380 empty string (completion attempted at the beginning of an empty line),
3381 any compspec defined with the -E option to complete is used. If a
3382 compspec has been defined for that command, the compspec is used to
3383 generate the list of possible completions for the word. If the command
3384 word is a full pathname, a compspec for the full pathname is searched
3385 for first. If no compspec is found for the full pathname, an attempt
3386 is made to find a compspec for the portion following the final slash.
3387 If those searches to not result in a compspec, any compspec defined
3388 with the -D option to complete is used as the default.
3389
3390 Once a compspec has been found, it is used to generate the list of
3391 matching words. If a compspec is not found, the default bash comple‐
3392 tion as described above under Completing is performed.
3393
3394 First, the actions specified by the compspec are used. Only matches
3395 which are prefixed by the word being completed are returned. When the
3396 -f or -d option is used for filename or directory name completion, the
3397 shell variable FIGNORE is used to filter the matches.
3398
3399 Any completions specified by a pathname expansion pattern to the -G
3400 option are generated next. The words generated by the pattern need not
3401 match the word being completed. The GLOBIGNORE shell variable is not
3402 used to filter the matches, but the FIGNORE variable is used.
3403
3404 Next, the string specified as the argument to the -W option is consid‐
3405 ered. The string is first split using the characters in the IFS spe‐
3406 cial variable as delimiters. Shell quoting is honored. Each word is
3407 then expanded using brace expansion, tilde expansion, parameter and
3408 variable expansion, command substitution, and arithmetic expansion, as
3409 described above under EXPANSION. The results are split using the rules
3410 described above under Word Splitting. The results of the expansion are
3411 prefix-matched against the word being completed, and the matching words
3412 become the possible completions.
3413
3414 After these matches have been generated, any shell function or command
3415 specified with the -F and -C options is invoked. When the command or
3416 function is invoked, the COMP_LINE, COMP_POINT, COMP_KEY, and COMP_TYPE
3417 variables are assigned values as described above under Shell Variables.
3418 If a shell function is being invoked, the COMP_WORDS and COMP_CWORD
3419 variables are also set. When the function or command is invoked, the
3420 first argument is the name of the command whose arguments are being
3421 completed, the second argument is the word being completed, and the
3422 third argument is the word preceding the word being completed on the
3423 current command line. No filtering of the generated completions
3424 against the word being completed is performed; the function or command
3425 has complete freedom in generating the matches.
3426
3427 Any function specified with -F is invoked first. The function may use
3428 any of the shell facilities, including the compgen builtin described
3429 below, to generate the matches. It must put the possible completions
3430 in the COMPREPLY array variable.
3431
3432 Next, any command specified with the -C option is invoked in an envi‐
3433 ronment equivalent to command substitution. It should print a list of
3434 completions, one per line, to the standard output. Backslash may be
3435 used to escape a newline, if necessary.
3436
3437 After all of the possible completions are generated, any filter speci‐
3438 fied with the -X option is applied to the list. The filter is a pat‐
3439 tern as used for pathname expansion; a & in the pattern is replaced
3440 with the text of the word being completed. A literal & may be escaped
3441 with a backslash; the backslash is removed before attempting a match.
3442 Any completion that matches the pattern will be removed from the list.
3443 A leading ! negates the pattern; in this case any completion not match‐
3444 ing the pattern will be removed.
3445
3446 Finally, any prefix and suffix specified with the -P and -S options are
3447 added to each member of the completion list, and the result is returned
3448 to the readline completion code as the list of possible completions.
3449
3450 If the previously-applied actions do not generate any matches, and the
3451 -o dirnames option was supplied to complete when the compspec was
3452 defined, directory name completion is attempted.
3453
3454 If the -o plusdirs option was supplied to complete when the compspec
3455 was defined, directory name completion is attempted and any matches are
3456 added to the results of the other actions.
3457
3458 By default, if a compspec is found, whatever it generates is returned
3459 to the completion code as the full set of possible completions. The
3460 default bash completions are not attempted, and the readline default of
3461 filename completion is disabled. If the -o bashdefault option was sup‐
3462 plied to complete when the compspec was defined, the bash default com‐
3463 pletions are attempted if the compspec generates no matches. If the -o
3464 default option was supplied to complete when the compspec was defined,
3465 readline's default completion will be performed if the compspec (and,
3466 if attempted, the default bash completions) generate no matches.
3467
3468 When a compspec indicates that directory name completion is desired,
3469 the programmable completion functions force readline to append a slash
3470 to completed names which are symbolic links to directories, subject to
3471 the value of the mark-directories readline variable, regardless of the
3472 setting of the mark-symlinked-directories readline variable.
3473
3474 There is some support for dynamically modifying completions. This is
3475 most useful when used in combination with a default completion speci‐
3476 fied with complete -D. It's possible for shell functions executed as
3477 completion handlers to indicate that completion should be retried by
3478 returning an exit status of 124. If a shell function returns 124, and
3479 changes the compspec associated with the command on which completion is
3480 being attempted (supplied as the first argument when the function is
3481 executed), programmable completion restarts from the beginning, with an
3482 attempt to find a compspec for that command. This allows a set of com‐
3483 pletions to be built dynamically as completion is attempted, rather
3484 than being loaded all at once.
3485
3486 For instance, assuming that there is a library of compspecs, each kept
3487 in a file corresponding to the name of the command, the following
3488 default completion function would load completions dynamically:
3489
3490 _completion_loader()
3491 {
3492 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
3493 }
3494 complete -D -F _completion_loader
3495
3496
3498 When the -o history option to the set builtin is enabled, the shell
3499 provides access to the command history, the list of commands previously
3500 typed. The value of the HISTSIZE variable is used as the number of
3501 commands to save in a history list. The text of the last HISTSIZE com‐
3502 mands (default 500) is saved. The shell stores each command in the
3503 history list prior to parameter and variable expansion (see EXPANSION
3504 above) but after history expansion is performed, subject to the values
3505 of the shell variables HISTIGNORE and HISTCONTROL.
3506
3507 On startup, the history is initialized from the file named by the vari‐
3508 able HISTFILE (default ~/.bash_history). The file named by the value
3509 of HISTFILE is truncated, if necessary, to contain no more than the
3510 number of lines specified by the value of HISTFILESIZE. When the his‐
3511 tory file is read, lines beginning with the history comment character
3512 followed immediately by a digit are interpreted as timestamps for the
3513 preceding history line. These timestamps are optionally displayed
3514 depending on the value of the HISTTIMEFORMAT variable. When an inter‐
3515 active shell exits, the last $HISTSIZE lines are copied from the his‐
3516 tory list to $HISTFILE. If the histappend shell option is enabled (see
3517 the description of shopt under SHELL BUILTIN COMMANDS below), the lines
3518 are appended to the history file, otherwise the history file is over‐
3519 written. If HISTFILE is unset, or if the history file is unwritable,
3520 the history is not saved. If the HISTTIMEFORMAT variable is set, time
3521 stamps are written to the history file, marked with the history comment
3522 character, so they may be preserved across shell sessions. This uses
3523 the history comment character to distinguish timestamps from other his‐
3524 tory lines. After saving the history, the history file is truncated to
3525 contain no more than HISTFILESIZE lines. If HISTFILESIZE is not set,
3526 no truncation is performed.
3527
3528 The builtin command fc (see SHELL BUILTIN COMMANDS below) may be used
3529 to list or edit and re-execute a portion of the history list. The his‐
3530 tory builtin may be used to display or modify the history list and
3531 manipulate the history file. When using command-line editing, search
3532 commands are available in each editing mode that provide access to the
3533 history list.
3534
3535 The shell allows control over which commands are saved on the history
3536 list. The HISTCONTROL and HISTIGNORE variables may be set to cause the
3537 shell to save only a subset of the commands entered. The cmdhist shell
3538 option, if enabled, causes the shell to attempt to save each line of a
3539 multi-line command in the same history entry, adding semicolons where
3540 necessary to preserve syntactic correctness. The lithist shell option
3541 causes the shell to save the command with embedded newlines instead of
3542 semicolons. See the description of the shopt builtin below under SHELL
3543 BUILTIN COMMANDS for information on setting and unsetting shell
3544 options.
3545
3547 The shell supports a history expansion feature that is similar to the
3548 history expansion in csh. This section describes what syntax features
3549 are available. This feature is enabled by default for interactive
3550 shells, and can be disabled using the +H option to the set builtin com‐
3551 mand (see SHELL BUILTIN COMMANDS below). Non-interactive shells do not
3552 perform history expansion by default.
3553
3554 History expansions introduce words from the history list into the input
3555 stream, making it easy to repeat commands, insert the arguments to a
3556 previous command into the current input line, or fix errors in previous
3557 commands quickly.
3558
3559 History expansion is performed immediately after a complete line is
3560 read, before the shell breaks it into words. It takes place in two
3561 parts. The first is to determine which line from the history list to
3562 use during substitution. The second is to select portions of that line
3563 for inclusion into the current one. The line selected from the history
3564 is the event, and the portions of that line that are acted upon are
3565 words. Various modifiers are available to manipulate the selected
3566 words. The line is broken into words in the same fashion as when read‐
3567 ing input, so that several metacharacter-separated words surrounded by
3568 quotes are considered one word. History expansions are introduced by
3569 the appearance of the history expansion character, which is ! by
3570 default. Only backslash (\) and single quotes can quote the history
3571 expansion character.
3572
3573 Several characters inhibit history expansion if found immediately fol‐
3574 lowing the history expansion character, even if it is unquoted: space,
3575 tab, newline, carriage return, and =. If the extglob shell option is
3576 enabled, ( will also inhibit expansion.
3577
3578 Several shell options settable with the shopt builtin may be used to
3579 tailor the behavior of history expansion. If the histverify shell
3580 option is enabled (see the description of the shopt builtin below), and
3581 readline is being used, history substitutions are not immediately
3582 passed to the shell parser. Instead, the expanded line is reloaded
3583 into the readline editing buffer for further modification. If readline
3584 is being used, and the histreedit shell option is enabled, a failed
3585 history substitution will be reloaded into the readline editing buffer
3586 for correction. The -p option to the history builtin command may be
3587 used to see what a history expansion will do before using it. The -s
3588 option to the history builtin may be used to add commands to the end of
3589 the history list without actually executing them, so that they are
3590 available for subsequent recall.
3591
3592 The shell allows control of the various characters used by the history
3593 expansion mechanism (see the description of histchars above under Shell
3594 Variables). The shell uses the history comment character to mark his‐
3595 tory timestamps when writing the history file.
3596
3597 Event Designators
3598 An event designator is a reference to a command line entry in the his‐
3599 tory list.
3600
3601 ! Start a history substitution, except when followed by a blank,
3602 newline, carriage return, = or ( (when the extglob shell option
3603 is enabled using the shopt builtin).
3604 !n Refer to command line n.
3605 !-n Refer to the current command line minus n.
3606 !! Refer to the previous command. This is a synonym for `!-1'.
3607 !string
3608 Refer to the most recent command starting with string.
3609 !?string[?]
3610 Refer to the most recent command containing string. The trail‐
3611 ing ? may be omitted if string is followed immediately by a new‐
3612 line.
3613 ^string1^string2^
3614 Quick substitution. Repeat the last command, replacing string1
3615 with string2. Equivalent to ``!!:s/string1/string2/'' (see Mod‐
3616 ifiers below).
3617 !# The entire command line typed so far.
3618
3619 Word Designators
3620 Word designators are used to select desired words from the event. A :
3621 separates the event specification from the word designator. It may be
3622 omitted if the word designator begins with a ^, $, *, -, or %. Words
3623 are numbered from the beginning of the line, with the first word being
3624 denoted by 0 (zero). Words are inserted into the current line sepa‐
3625 rated by single spaces.
3626
3627 0 (zero)
3628 The zeroth word. For the shell, this is the command word.
3629 n The nth word.
3630 ^ The first argument. That is, word 1.
3631 $ The last argument.
3632 % The word matched by the most recent `?string?' search.
3633 x-y A range of words; `-y' abbreviates `0-y'.
3634 * All of the words but the zeroth. This is a synonym for `1-$'.
3635 It is not an error to use * if there is just one word in the
3636 event; the empty string is returned in that case.
3637 x* Abbreviates x-$.
3638 x- Abbreviates x-$ like x*, but omits the last word.
3639
3640 If a word designator is supplied without an event specification, the
3641 previous command is used as the event.
3642
3643 Modifiers
3644 After the optional word designator, there may appear a sequence of one
3645 or more of the following modifiers, each preceded by a `:'.
3646
3647 h Remove a trailing file name component, leaving only the head.
3648 t Remove all leading file name components, leaving the tail.
3649 r Remove a trailing suffix of the form .xxx, leaving the basename.
3650 e Remove all but the trailing suffix.
3651 p Print the new command but do not execute it.
3652 q Quote the substituted words, escaping further substitutions.
3653 x Quote the substituted words as with q, but break into words at
3654 blanks and newlines.
3655 s/old/new/
3656 Substitute new for the first occurrence of old in the event
3657 line. Any delimiter can be used in place of /. The final
3658 delimiter is optional if it is the last character of the event
3659 line. The delimiter may be quoted in old and new with a single
3660 backslash. If & appears in new, it is replaced by old. A sin‐
3661 gle backslash will quote the &. If old is null, it is set to
3662 the last old substituted, or, if no previous history substitu‐
3663 tions took place, the last string in a !?string[?] search.
3664 & Repeat the previous substitution.
3665 g Cause changes to be applied over the entire event line. This is
3666 used in conjunction with `:s' (e.g., `:gs/old/new/') or `:&'.
3667 If used with `:s', any delimiter can be used in place of /, and
3668 the final delimiter is optional if it is the last character of
3669 the event line. An a may be used as a synonym for g.
3670 G Apply the following `s' modifier once to each word in the event
3671 line.
3672
3674 Unless otherwise noted, each builtin command documented in this section
3675 as accepting options preceded by - accepts -- to signify the end of the
3676 options. The :, true, false, and test builtins do not accept options
3677 and do not treat -- specially. The exit, logout, break, continue, let,
3678 and shift builtins accept and process arguments beginning with - with‐
3679 out requiring --. Other builtins that accept arguments but are not
3680 specified as accepting options interpret arguments beginning with - as
3681 invalid options and require -- to prevent this interpretation.
3682 : [arguments]
3683 No effect; the command does nothing beyond expanding arguments
3684 and performing any specified redirections. A zero exit code is
3685 returned.
3686
3687 . filename [arguments]
3688 source filename [arguments]
3689 Read and execute commands from filename in the current shell
3690 environment and return the exit status of the last command exe‐
3691 cuted from filename. If filename does not contain a slash, file
3692 names in PATH are used to find the directory containing file‐
3693 name. The file searched for in PATH need not be executable.
3694 When bash is not in posix mode, the current directory is
3695 searched if no file is found in PATH. If the sourcepath option
3696 to the shopt builtin command is turned off, the PATH is not
3697 searched. If any arguments are supplied, they become the posi‐
3698 tional parameters when filename is executed. Otherwise the
3699 positional parameters are unchanged. The return status is the
3700 status of the last command exited within the script (0 if no
3701 commands are executed), and false if filename is not found or
3702 cannot be read.
3703
3704 alias [-p] [name[=value] ...]
3705 Alias with no arguments or with the -p option prints the list of
3706 aliases in the form alias name=value on standard output. When
3707 arguments are supplied, an alias is defined for each name whose
3708 value is given. A trailing space in value causes the next word
3709 to be checked for alias substitution when the alias is expanded.
3710 For each name in the argument list for which no value is sup‐
3711 plied, the name and value of the alias is printed. Alias
3712 returns true unless a name is given for which no alias has been
3713 defined.
3714
3715 bg [jobspec ...]
3716 Resume each suspended job jobspec in the background, as if it
3717 had been started with &. If jobspec is not present, the shell's
3718 notion of the current job is used. bg jobspec returns 0 unless
3719 run when job control is disabled or, when run with job control
3720 enabled, any specified jobspec was not found or was started
3721 without job control.
3722
3723 bind [-m keymap] [-lpsvPSV]
3724 bind [-m keymap] [-q function] [-u function] [-r keyseq]
3725 bind [-m keymap] -f filename
3726 bind [-m keymap] -x keyseq:shell-command
3727 bind [-m keymap] keyseq:function-name
3728 bind readline-command
3729 Display current readline key and function bindings, bind a key
3730 sequence to a readline function or macro, or set a readline
3731 variable. Each non-option argument is a command as it would
3732 appear in .inputrc, but each binding or command must be passed
3733 as a separate argument; e.g., '"\C-x\C-r": re-read-init-file'.
3734 Options, if supplied, have the following meanings:
3735 -m keymap
3736 Use keymap as the keymap to be affected by the subsequent
3737 bindings. Acceptable keymap names are emacs, emacs-stan‐
3738 dard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command,
3739 and vi-insert. vi is equivalent to vi-command; emacs is
3740 equivalent to emacs-standard.
3741 -l List the names of all readline functions.
3742 -p Display readline function names and bindings in such a
3743 way that they can be re-read.
3744 -P List current readline function names and bindings.
3745 -s Display readline key sequences bound to macros and the
3746 strings they output in such a way that they can be re-
3747 read.
3748 -S Display readline key sequences bound to macros and the
3749 strings they output.
3750 -v Display readline variable names and values in such a way
3751 that they can be re-read.
3752 -V List current readline variable names and values.
3753 -f filename
3754 Read key bindings from filename.
3755 -q function
3756 Query about which keys invoke the named function.
3757 -u function
3758 Unbind all keys bound to the named function.
3759 -r keyseq
3760 Remove any current binding for keyseq.
3761 -x keyseq:shell-command
3762 Cause shell-command to be executed whenever keyseq is
3763 entered. When shell-command is executed, the shell sets
3764 the READLINE_LINE variable to the contents of the read‐
3765 line line buffer and the READLINE_POINT variable to the
3766 current location of the insertion point. If the executed
3767 command changes the value of READLINE_LINE or READ‐
3768 LINE_POINT, those new values will be reflected in the
3769 editing state.
3770
3771 The return value is 0 unless an unrecognized option is given or
3772 an error occurred.
3773
3774 break [n]
3775 Exit from within a for, while, until, or select loop. If n is
3776 specified, break n levels. n must be ≥ 1. If n is greater than
3777 the number of enclosing loops, all enclosing loops are exited.
3778 The return value is non-zero when n is ≤ 0; Otherwise, break
3779 returns 0 value.
3780
3781 builtin shell-builtin [arguments]
3782 Execute the specified shell builtin, passing it arguments, and
3783 return its exit status. This is useful when defining a function
3784 whose name is the same as a shell builtin, retaining the func‐
3785 tionality of the builtin within the function. The cd builtin is
3786 commonly redefined this way. The return status is false if
3787 shell-builtin is not a shell builtin command.
3788
3789 caller [expr]
3790 Returns the context of any active subroutine call (a shell func‐
3791 tion or a script executed with the . or source builtins. With‐
3792 out expr, caller displays the line number and source filename of
3793 the current subroutine call. If a non-negative integer is sup‐
3794 plied as expr, caller displays the line number, subroutine name,
3795 and source file corresponding to that position in the current
3796 execution call stack. This extra information may be used, for
3797 example, to print a stack trace. The current frame is frame 0.
3798 The return value is 0 unless the shell is not executing a sub‐
3799 routine call or expr does not correspond to a valid position in
3800 the call stack.
3801
3802 cd [-L|-P] [dir]
3803 Change the current directory to dir. The variable HOME is the
3804 default dir. The variable CDPATH defines the search path for
3805 the directory containing dir. Alternative directory names in
3806 CDPATH are separated by a colon (:). A null directory name in
3807 CDPATH is the same as the current directory, i.e., ``.''. If
3808 dir begins with a slash (/), then CDPATH is not used. The -P
3809 option says to use the physical directory structure instead of
3810 following symbolic links (see also the -P option to the set
3811 builtin command); the -L option forces symbolic links to be fol‐
3812 lowed. An argument of - is equivalent to $OLDPWD. If a non-
3813 empty directory name from CDPATH is used, or if - is the first
3814 argument, and the directory change is successful, the absolute
3815 pathname of the new working directory is written to the standard
3816 output. The return value is true if the directory was success‐
3817 fully changed; false otherwise.
3818
3819 command [-pVv] command [arg ...]
3820 Run command with args suppressing the normal shell function
3821 lookup. Only builtin commands or commands found in the PATH are
3822 executed. If the -p option is given, the search for command is
3823 performed using a default value for PATH that is guaranteed to
3824 find all of the standard utilities. If either the -V or -v
3825 option is supplied, a description of command is printed. The -v
3826 option causes a single word indicating the command or file name
3827 used to invoke command to be displayed; the -V option produces a
3828 more verbose description. If the -V or -v option is supplied,
3829 the exit status is 0 if command was found, and 1 if not. If
3830 neither option is supplied and an error occurred or command can‐
3831 not be found, the exit status is 127. Otherwise, the exit sta‐
3832 tus of the command builtin is the exit status of command.
3833
3834 compgen [option] [word]
3835 Generate possible completion matches for word according to the
3836 options, which may be any option accepted by the complete
3837 builtin with the exception of -p and -r, and write the matches
3838 to the standard output. When using the -F or -C options, the
3839 various shell variables set by the programmable completion
3840 facilities, while available, will not have useful values.
3841
3842 The matches will be generated in the same way as if the program‐
3843 mable completion code had generated them directly from a comple‐
3844 tion specification with the same flags. If word is specified,
3845 only those completions matching word will be displayed.
3846
3847 The return value is true unless an invalid option is supplied,
3848 or no matches were generated.
3849
3850 complete [-abcdefgjksuv] [-o comp-option] [-DE] [-A action] [-G glob‐
3851 pat] [-W wordlist] [-F function] [-C command]
3852 [-X filterpat] [-P prefix] [-S suffix] name [name ...]
3853 complete -pr [-DE] [name ...]
3854 Specify how arguments to each name should be completed. If the
3855 -p option is supplied, or if no options are supplied, existing
3856 completion specifications are printed in a way that allows them
3857 to be reused as input. The -r option removes a completion spec‐
3858 ification for each name, or, if no names are supplied, all com‐
3859 pletion specifications. The -D option indicates that the
3860 remaining options and actions should apply to the ``default''
3861 command completion; that is, completion attempted on a command
3862 for which no completion has previously been defined. The -E
3863 option indicates that the remaining options and actions should
3864 apply to ``empty'' command completion; that is, completion
3865 attempted on a blank line.
3866
3867 The process of applying these completion specifications when
3868 word completion is attempted is described above under Program‐
3869 mable Completion.
3870
3871 Other options, if specified, have the following meanings. The
3872 arguments to the -G, -W, and -X options (and, if necessary, the
3873 -P and -S options) should be quoted to protect them from expan‐
3874 sion before the complete builtin is invoked.
3875 -o comp-option
3876 The comp-option controls several aspects of the comp‐
3877 spec's behavior beyond the simple generation of comple‐
3878 tions. comp-option may be one of:
3879 bashdefault
3880 Perform the rest of the default bash completions
3881 if the compspec generates no matches.
3882 default Use readline's default filename completion if
3883 the compspec generates no matches.
3884 dirnames
3885 Perform directory name completion if the comp‐
3886 spec generates no matches.
3887 filenames
3888 Tell readline that the compspec generates file‐
3889 names, so it can perform any filename-specific
3890 processing (like adding a slash to directory
3891 names, quoting special characters, or suppress‐
3892 ing trailing spaces). Intended to be used with
3893 shell functions.
3894 nospace Tell readline not to append a space (the
3895 default) to words completed at the end of the
3896 line.
3897 plusdirs
3898 After any matches defined by the compspec are
3899 generated, directory name completion is
3900 attempted and any matches are added to the
3901 results of the other actions.
3902 -A action
3903 The action may be one of the following to generate a
3904 list of possible completions:
3905 alias Alias names. May also be specified as -a.
3906 arrayvar
3907 Array variable names.
3908 binding Readline key binding names.
3909 builtin Names of shell builtin commands. May also be
3910 specified as -b.
3911 command Command names. May also be specified as -c.
3912 directory
3913 Directory names. May also be specified as -d.
3914 disabled
3915 Names of disabled shell builtins.
3916 enabled Names of enabled shell builtins.
3917 export Names of exported shell variables. May also be
3918 specified as -e.
3919 file File names. May also be specified as -f.
3920 function
3921 Names of shell functions.
3922 group Group names. May also be specified as -g.
3923 helptopic
3924 Help topics as accepted by the help builtin.
3925 hostname
3926 Hostnames, as taken from the file specified by
3927 the HOSTFILE shell variable.
3928 job Job names, if job control is active. May also
3929 be specified as -j.
3930 keyword Shell reserved words. May also be specified as
3931 -k.
3932 running Names of running jobs, if job control is active.
3933 service Service names. May also be specified as -s.
3934 setopt Valid arguments for the -o option to the set
3935 builtin.
3936 shopt Shell option names as accepted by the shopt
3937 builtin.
3938 signal Signal names.
3939 stopped Names of stopped jobs, if job control is active.
3940 user User names. May also be specified as -u.
3941 variable
3942 Names of all shell variables. May also be spec‐
3943 ified as -v.
3944 -G globpat
3945 The pathname expansion pattern globpat is expanded to
3946 generate the possible completions.
3947 -W wordlist
3948 The wordlist is split using the characters in the IFS
3949 special variable as delimiters, and each resultant word
3950 is expanded. The possible completions are the members
3951 of the resultant list which match the word being com‐
3952 pleted.
3953 -C command
3954 command is executed in a subshell environment, and its
3955 output is used as the possible completions.
3956 -F function
3957 The shell function function is executed in the current
3958 shell environment. When it finishes, the possible com‐
3959 pletions are retrieved from the value of the COMPREPLY
3960 array variable.
3961 -X filterpat
3962 filterpat is a pattern as used for pathname expansion.
3963 It is applied to the list of possible completions gener‐
3964 ated by the preceding options and arguments, and each
3965 completion matching filterpat is removed from the list.
3966 A leading ! in filterpat negates the pattern; in this
3967 case, any completion not matching filterpat is removed.
3968 -P prefix
3969 prefix is added at the beginning of each possible com‐
3970 pletion after all other options have been applied.
3971 -S suffix
3972 suffix is appended to each possible completion after all
3973 other options have been applied.
3974
3975 The return value is true unless an invalid option is supplied,
3976 an option other than -p or -r is supplied without a name argu‐
3977 ment, an attempt is made to remove a completion specification
3978 for a name for which no specification exists, or an error occurs
3979 adding a completion specification.
3980
3981 compopt [-o option] [-DE] [+o option] [name]
3982 Modify completion options for each name according to the
3983 options, or for the currently-execution completion if no names
3984 are supplied. If no options are given, display the completion
3985 options for each name or the current completion. The possible
3986 values of option are those valid for the complete builtin
3987 described above. The -D option indicates that the remaining
3988 options should apply to the ``default'' command completion; that
3989 is, completion attempted on a command for which no completion
3990 has previously been defined. The -E option indicates that the
3991 remaining options should apply to ``empty'' command completion;
3992 that is, completion attempted on a blank line.
3993
3994 The return value is true unless an invalid option is supplied, an
3995 attempt is made to modify the options for a name for which no comple‐
3996 tion specification exists, or an output error occurs.
3997
3998 continue [n]
3999 Resume the next iteration of the enclosing for, while, until, or
4000 select loop. If n is specified, resume at the nth enclosing
4001 loop. n must be ≥ 1. If n is greater than the number of
4002 enclosing loops, the last enclosing loop (the ``top-level''
4003 loop) is resumed. When continue is executed inside of loop, the
4004 return value is non-zero when n is ≤ 0; Otherwise, continue
4005 returns 0 value. When continue is executed outside of loop, the
4006 return value is 0.
4007
4008 declare [-aAfFilrtux] [-p] [name[=value] ...]
4009 typeset [-aAfFilrtux] [-p] [name[=value] ...]
4010 Declare variables and/or give them attributes. If no names are
4011 given then display the values of variables. The -p option will
4012 display the attributes and values of each name. When -p is used
4013 with name arguments, additional options are ignored. When -p is
4014 supplied without name arguments, it will display the attributes
4015 and values of all variables having the attributes specified by
4016 the additional options. If no other options are supplied with
4017 -p, declare will display the attributes and values of all shell
4018 variables. The -f option will restrict the display to shell
4019 functions. The -F option inhibits the display of function defi‐
4020 nitions; only the function name and attributes are printed. If
4021 the extdebug shell option is enabled using shopt, the source
4022 file name and line number where the function is defined are dis‐
4023 played as well. The -F option implies -f. The following
4024 options can be used to restrict output to variables with the
4025 specified attribute or to give variables attributes:
4026 -a Each name is an indexed array variable (see Arrays
4027 above).
4028 -A Each name is an associative array variable (see Arrays
4029 above).
4030 -f Use function names only.
4031 -i The variable is treated as an integer; arithmetic evalua‐
4032 tion (see ARITHMETIC EVALUATION above) is performed when
4033 the variable is assigned a value.
4034 -l When the variable is assigned a value, all upper-case
4035 characters are converted to lower-case. The upper-case
4036 attribute is disabled.
4037 -r Make names readonly. These names cannot then be assigned
4038 values by subsequent assignment statements or unset.
4039 -t Give each name the trace attribute. Traced functions
4040 inherit the DEBUG and RETURN traps from the calling
4041 shell. The trace attribute has no special meaning for
4042 variables.
4043 -u When the variable is assigned a value, all lower-case
4044 characters are converted to upper-case. The lower-case
4045 attribute is disabled.
4046 -x Mark names for export to subsequent commands via the
4047 environment.
4048
4049 Using `+' instead of `-' turns off the attribute instead, with
4050 the exceptions that +a may not be used to destroy an array vari‐
4051 able and +r will not remove the readonly attribute. When used
4052 in a function, makes each name local, as with the local command.
4053 If a variable name is followed by =value, the value of the vari‐
4054 able is set to value. The return value is 0 unless an invalid
4055 option is encountered, an attempt is made to define a function
4056 using ``-f foo=bar'', an attempt is made to assign a value to a
4057 readonly variable, an attempt is made to assign a value to an
4058 array variable without using the compound assignment syntax (see
4059 Arrays above), one of the names is not a valid shell variable
4060 name, an attempt is made to turn off readonly status for a read‐
4061 only variable, an attempt is made to turn off array status for
4062 an array variable, or an attempt is made to display a non-exis‐
4063 tent function with -f.
4064
4065 dirs [+n] [-n] [-cplv]
4066 Without options, displays the list of currently remembered
4067 directories. The default display is on a single line with
4068 directory names separated by spaces. Directories are added to
4069 the list with the pushd command; the popd command removes
4070 entries from the list.
4071 +n Displays the nth entry counting from the left of the list
4072 shown by dirs when invoked without options, starting with
4073 zero.
4074 -n Displays the nth entry counting from the right of the
4075 list shown by dirs when invoked without options, starting
4076 with zero.
4077 -c Clears the directory stack by deleting all of the
4078 entries.
4079 -l Produces a longer listing; the default listing format
4080 uses a tilde to denote the home directory.
4081 -p Print the directory stack with one entry per line.
4082 -v Print the directory stack with one entry per line, pre‐
4083 fixing each entry with its index in the stack.
4084
4085 The return value is 0 unless an invalid option is supplied or n
4086 indexes beyond the end of the directory stack.
4087
4088 disown [-ar] [-h] [jobspec ...]
4089 Without options, each jobspec is removed from the table of
4090 active jobs. If jobspec is not present, and neither -a nor -r
4091 is supplied, the shell's notion of the current job is used. If
4092 the -h option is given, each jobspec is not removed from the ta‐
4093 ble, but is marked so that SIGHUP is not sent to the job if the
4094 shell receives a SIGHUP. If no jobspec is present, and neither
4095 the -a nor the -r option is supplied, the current job is used.
4096 If no jobspec is supplied, the -a option means to remove or mark
4097 all jobs; the -r option without a jobspec argument restricts
4098 operation to running jobs. The return value is 0 unless a job‐
4099 spec does not specify a valid job.
4100
4101 echo [-neE] [arg ...]
4102 Output the args, separated by spaces, followed by a newline.
4103 The return status is always 0. If -n is specified, the trailing
4104 newline is suppressed. If the -e option is given, interpreta‐
4105 tion of the following backslash-escaped characters is enabled.
4106 The -E option disables the interpretation of these escape char‐
4107 acters, even on systems where they are interpreted by default.
4108 The xpg_echo shell option may be used to dynamically determine
4109 whether or not echo expands these escape characters by default.
4110 echo does not interpret -- to mean the end of options. echo
4111 interprets the following escape sequences:
4112 \a alert (bell)
4113 \b backspace
4114 \c suppress further output
4115 \e an escape character
4116 \f form feed
4117 \n new line
4118 \r carriage return
4119 \t horizontal tab
4120 \v vertical tab
4121 \\ backslash
4122 \0nnn the eight-bit character whose value is the octal value
4123 nnn (zero to three octal digits)
4124 \xHH the eight-bit character whose value is the hexadecimal
4125 value HH (one or two hex digits)
4126
4127 enable [-a] [-dnps] [-f filename] [name ...]
4128 Enable and disable builtin shell commands. Disabling a builtin
4129 allows a disk command which has the same name as a shell builtin
4130 to be executed without specifying a full pathname, even though
4131 the shell normally searches for builtins before disk commands.
4132 If -n is used, each name is disabled; otherwise, names are
4133 enabled. For example, to use the test binary found via the PATH
4134 instead of the shell builtin version, run ``enable -n test''.
4135 The -f option means to load the new builtin command name from
4136 shared object filename, on systems that support dynamic loading.
4137 The -d option will delete a builtin previously loaded with -f.
4138 If no name arguments are given, or if the -p option is supplied,
4139 a list of shell builtins is printed. With no other option argu‐
4140 ments, the list consists of all enabled shell builtins. If -n
4141 is supplied, only disabled builtins are printed. If -a is sup‐
4142 plied, the list printed includes all builtins, with an indica‐
4143 tion of whether or not each is enabled. If -s is supplied, the
4144 output is restricted to the POSIX special builtins. The return
4145 value is 0 unless a name is not a shell builtin or there is an
4146 error loading a new builtin from a shared object.
4147
4148 eval [arg ...]
4149 The args are read and concatenated together into a single com‐
4150 mand. This command is then read and executed by the shell, and
4151 its exit status is returned as the value of eval. If there are
4152 no args, or only null arguments, eval returns 0.
4153
4154 exec [-cl] [-a name] [command [arguments]]
4155 If command is specified, it replaces the shell. No new process
4156 is created. The arguments become the arguments to command. If
4157 the -l option is supplied, the shell places a dash at the begin‐
4158 ning of the zeroth argument passed to command. This is what
4159 login(1) does. The -c option causes command to be executed with
4160 an empty environment. If -a is supplied, the shell passes name
4161 as the zeroth argument to the executed command. If command can‐
4162 not be executed for some reason, a non-interactive shell exits,
4163 unless the shell option execfail is enabled, in which case it
4164 returns failure. An interactive shell returns failure if the
4165 file cannot be executed. If command is not specified, any redi‐
4166 rections take effect in the current shell, and the return status
4167 is 0. If there is a redirection error, the return status is 1.
4168
4169 exit [n]
4170 Cause the shell to exit with a status of n. If n is omitted,
4171 the exit status is that of the last command executed. A trap on
4172 EXIT is executed before the shell terminates.
4173
4174 export [-fn] [name[=word]] ...
4175 export -p
4176 The supplied names are marked for automatic export to the envi‐
4177 ronment of subsequently executed commands. If the -f option is
4178 given, the names refer to functions. If no names are given, or
4179 if the -p option is supplied, a list of all names that are
4180 exported in this shell is printed. The -n option causes the
4181 export property to be removed from each name. If a variable
4182 name is followed by =word, the value of the variable is set to
4183 word. export returns an exit status of 0 unless an invalid
4184 option is encountered, one of the names is not a valid shell
4185 variable name, or -f is supplied with a name that is not a func‐
4186 tion.
4187
4188 fc [-e ename] [-lnr] [first] [last]
4189 fc -s [pat=rep] [cmd]
4190 Fix Command. In the first form, a range of commands from first
4191 to last is selected from the history list. First and last may
4192 be specified as a string (to locate the last command beginning
4193 with that string) or as a number (an index into the history
4194 list, where a negative number is used as an offset from the cur‐
4195 rent command number). If last is not specified it is set to the
4196 current command for listing (so that ``fc -l -10'' prints the
4197 last 10 commands) and to first otherwise. If first is not spec‐
4198 ified it is set to the previous command for editing and -16 for
4199 listing.
4200
4201 The -n option suppresses the command numbers when listing. The
4202 -r option reverses the order of the commands. If the -l option
4203 is given, the commands are listed on standard output. Other‐
4204 wise, the editor given by ename is invoked on a file containing
4205 those commands. If ename is not given, the value of the FCEDIT
4206 variable is used, and the value of EDITOR if FCEDIT is not set.
4207 If neither variable is set, vi is used. When editing is com‐
4208 plete, the edited commands are echoed and executed.
4209
4210 In the second form, command is re-executed after each instance
4211 of pat is replaced by rep. A useful alias to use with this is
4212 ``r="fc -s"'', so that typing ``r cc'' runs the last command
4213 beginning with ``cc'' and typing ``r'' re-executes the last com‐
4214 mand.
4215
4216 If the first form is used, the return value is 0 unless an
4217 invalid option is encountered or first or last specify history
4218 lines out of range. If the -e option is supplied, the return
4219 value is the value of the last command executed or failure if an
4220 error occurs with the temporary file of commands. If the second
4221 form is used, the return status is that of the command re-exe‐
4222 cuted, unless cmd does not specify a valid history line, in
4223 which case fc returns failure.
4224
4225 fg [jobspec]
4226 Resume jobspec in the foreground, and make it the current job.
4227 If jobspec is not present, the shell's notion of the current job
4228 is used. The return value is that of the command placed into
4229 the foreground, or failure if run when job control is disabled
4230 or, when run with job control enabled, if jobspec does not spec‐
4231 ify a valid job or jobspec specifies a job that was started
4232 without job control.
4233
4234 getopts optstring name [args]
4235 getopts is used by shell procedures to parse positional parame‐
4236 ters. optstring contains the option characters to be recog‐
4237 nized; if a character is followed by a colon, the option is
4238 expected to have an argument, which should be separated from it
4239 by white space. The colon and question mark characters may not
4240 be used as option characters. Each time it is invoked, getopts
4241 places the next option in the shell variable name, initializing
4242 name if it does not exist, and the index of the next argument to
4243 be processed into the variable OPTIND. OPTIND is initialized to
4244 1 each time the shell or a shell script is invoked. When an
4245 option requires an argument, getopts places that argument into
4246 the variable OPTARG. The shell does not reset OPTIND automati‐
4247 cally; it must be manually reset between multiple calls to
4248 getopts within the same shell invocation if a new set of parame‐
4249 ters is to be used.
4250
4251 When the end of options is encountered, getopts exits with a
4252 return value greater than zero. OPTIND is set to the index of
4253 the first non-option argument, and name is set to ?.
4254
4255 getopts normally parses the positional parameters, but if more
4256 arguments are given in args, getopts parses those instead.
4257
4258 getopts can report errors in two ways. If the first character
4259 of optstring is a colon, silent error reporting is used. In
4260 normal operation diagnostic messages are printed when invalid
4261 options or missing option arguments are encountered. If the
4262 variable OPTERR is set to 0, no error messages will be dis‐
4263 played, even if the first character of optstring is not a colon.
4264
4265 If an invalid option is seen, getopts places ? into name and, if
4266 not silent, prints an error message and unsets OPTARG. If
4267 getopts is silent, the option character found is placed in
4268 OPTARG and no diagnostic message is printed.
4269
4270 If a required argument is not found, and getopts is not silent,
4271 a question mark (?) is placed in name, OPTARG is unset, and a
4272 diagnostic message is printed. If getopts is silent, then a
4273 colon (:) is placed in name and OPTARG is set to the option
4274 character found.
4275
4276 getopts returns true if an option, specified or unspecified, is
4277 found. It returns false if the end of options is encountered or
4278 an error occurs.
4279
4280 hash [-lr] [-p filename] [-dt] [name]
4281 For each name, the full file name of the command is determined
4282 by searching the directories in $PATH and remembered. If the -p
4283 option is supplied, no path search is performed, and filename is
4284 used as the full file name of the command. The -r option causes
4285 the shell to forget all remembered locations. The -d option
4286 causes the shell to forget the remembered location of each name.
4287 If the -t option is supplied, the full pathname to which each
4288 name corresponds is printed. If multiple name arguments are
4289 supplied with -t, the name is printed before the hashed full
4290 pathname. The -l option causes output to be displayed in a for‐
4291 mat that may be reused as input. If no arguments are given, or
4292 if only -l is supplied, information about remembered commands is
4293 printed. The return status is true unless a name is not found
4294 or an invalid option is supplied.
4295
4296 help [-dms] [pattern]
4297 Display helpful information about builtin commands. If pattern
4298 is specified, help gives detailed help on all commands matching
4299 pattern; otherwise help for all the builtins and shell control
4300 structures is printed.
4301 -d Display a short description of each pattern
4302 -m Display the description of each pattern in a manpage-like
4303 format
4304 -s Display only a short usage synopsis for each pattern
4305 The return status is 0 unless no command matches pattern.
4306
4307 history [n]
4308 history -c
4309 history -d offset
4310 history -anrw [filename]
4311 history -p arg [arg ...]
4312 history -s arg [arg ...]
4313 With no options, display the command history list with line num‐
4314 bers. Lines listed with a * have been modified. An argument of
4315 n lists only the last n lines. If the shell variable HISTTIME‐
4316 FORMAT is set and not null, it is used as a format string for
4317 strftime(3) to display the time stamp associated with each dis‐
4318 played history entry. No intervening blank is printed between
4319 the formatted time stamp and the history line. If filename is
4320 supplied, it is used as the name of the history file; if not,
4321 the value of HISTFILE is used. Options, if supplied, have the
4322 following meanings:
4323 -c Clear the history list by deleting all the entries.
4324 -d offset
4325 Delete the history entry at position offset.
4326 -a Append the ``new'' history lines (history lines entered
4327 since the beginning of the current bash session) to the
4328 history file.
4329 -n Read the history lines not already read from the history
4330 file into the current history list. These are lines
4331 appended to the history file since the beginning of the
4332 current bash session.
4333 -r Read the contents of the history file and use them as the
4334 current history.
4335 -w Write the current history to the history file, overwrit‐
4336 ing the history file's contents.
4337 -p Perform history substitution on the following args and
4338 display the result on the standard output. Does not
4339 store the results in the history list. Each arg must be
4340 quoted to disable normal history expansion.
4341 -s Store the args in the history list as a single entry.
4342 The last command in the history list is removed before
4343 the args are added.
4344
4345 If the HISTTIMEFORMAT variable is set, the time stamp informa‐
4346 tion associated with each history entry is written to the his‐
4347 tory file, marked with the history comment character. When the
4348 history file is read, lines beginning with the history comment
4349 character followed immediately by a digit are interpreted as
4350 timestamps for the previous history line. The return value is 0
4351 unless an invalid option is encountered, an error occurs while
4352 reading or writing the history file, an invalid offset is sup‐
4353 plied as an argument to -d, or the history expansion supplied as
4354 an argument to -p fails.
4355
4356 jobs [-lnprs] [ jobspec ... ]
4357 jobs -x command [ args ... ]
4358 The first form lists the active jobs. The options have the fol‐
4359 lowing meanings:
4360 -l List process IDs in addition to the normal information.
4361 -p List only the process ID of the job's process group
4362 leader.
4363 -n Display information only about jobs that have changed
4364 status since the user was last notified of their status.
4365 -r Restrict output to running jobs.
4366 -s Restrict output to stopped jobs.
4367
4368 If jobspec is given, output is restricted to information about
4369 that job. The return status is 0 unless an invalid option is
4370 encountered or an invalid jobspec is supplied.
4371
4372 If the -x option is supplied, jobs replaces any jobspec found in
4373 command or args with the corresponding process group ID, and
4374 executes command passing it args, returning its exit status.
4375
4376 kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
4377 kill -l [sigspec | exit_status]
4378 Send the signal named by sigspec or signum to the processes
4379 named by pid or jobspec. sigspec is either a case-insensitive
4380 signal name such as SIGKILL (with or without the SIG prefix) or
4381 a signal number; signum is a signal number. If sigspec is not
4382 present, then SIGTERM is assumed. An argument of -l lists the
4383 signal names. If any arguments are supplied when -l is given,
4384 the names of the signals corresponding to the arguments are
4385 listed, and the return status is 0. The exit_status argument to
4386 -l is a number specifying either a signal number or the exit
4387 status of a process terminated by a signal. kill returns true
4388 if at least one signal was successfully sent, or false if an
4389 error occurs or an invalid option is encountered.
4390
4391 let arg [arg ...]
4392 Each arg is an arithmetic expression to be evaluated (see ARITH‐
4393 METIC EVALUATION above). If the last arg evaluates to 0, let
4394 returns 1; 0 is returned otherwise.
4395
4396 local [option] [name[=value] ...]
4397 For each argument, a local variable named name is created, and
4398 assigned value. The option can be any of the options accepted
4399 by declare. When local is used within a function, it causes the
4400 variable name to have a visible scope restricted to that func‐
4401 tion and its children. With no operands, local writes a list of
4402 local variables to the standard output. It is an error to use
4403 local when not within a function. The return status is 0 unless
4404 local is used outside a function, an invalid name is supplied,
4405 or name is a readonly variable.
4406
4407 logout Exit a login shell.
4408
4409 mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback]
4410 [-c quantum] [array]
4411 readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback]
4412 [-c quantum] [array]
4413 Read lines from the standard input into the indexed array vari‐
4414 able array, or from file descriptor fd if the -u option is sup‐
4415 plied. The variable MAPFILE is the default array. Options, if
4416 supplied, have the following meanings:
4417 -n Copy at most count lines. If count is 0, all lines are
4418 copied.
4419 -O Begin assigning to array at index origin. The default
4420 index is 0.
4421 -s Discard the first count lines read.
4422 -t Remove a trailing newline from each line read.
4423 -u Read lines from file descriptor fd instead of the stan‐
4424 dard input.
4425 -C Evaluate callback each time quantum lines are read. The
4426 -c option specifies quantum.
4427 -c Specify the number of lines read between each call to
4428 callback.
4429
4430 If -C is specified without -c, the default quantum is 5000.
4431 When callback is evaluated, it is supplied the index of the next
4432 array element to be assigned as an additional argument. call‐
4433 back is evaluated after the line is read but before the array
4434 element is assigned.
4435
4436 If not supplied with an explicit origin, mapfile will clear
4437 array before assigning to it.
4438
4439 mapfile returns successfully unless an invalid option or option
4440 argument is supplied, array is invalid or unassignable, or if
4441 array is not an indexed array.
4442
4443 popd [-n] [+n] [-n]
4444 Removes entries from the directory stack. With no arguments,
4445 removes the top directory from the stack, and performs a cd to
4446 the new top directory. Arguments, if supplied, have the follow‐
4447 ing meanings:
4448 -n Suppresses the normal change of directory when removing
4449 directories from the stack, so that only the stack is
4450 manipulated.
4451 +n Removes the nth entry counting from the left of the list
4452 shown by dirs, starting with zero. For example: ``popd
4453 +0'' removes the first directory, ``popd +1'' the second.
4454 -n Removes the nth entry counting from the right of the list
4455 shown by dirs, starting with zero. For example: ``popd
4456 -0'' removes the last directory, ``popd -1'' the next to
4457 last.
4458
4459 If the popd command is successful, a dirs is performed as well,
4460 and the return status is 0. popd returns false if an invalid
4461 option is encountered, the directory stack is empty, a non-exis‐
4462 tent directory stack entry is specified, or the directory change
4463 fails.
4464
4465 printf [-v var] format [arguments]
4466 Write the formatted arguments to the standard output under the
4467 control of the format. The format is a character string which
4468 contains three types of objects: plain characters, which are
4469 simply copied to standard output, character escape sequences,
4470 which are converted and copied to the standard output, and for‐
4471 mat specifications, each of which causes printing of the next
4472 successive argument. In addition to the standard printf(1) for‐
4473 mats, %b causes printf to expand backslash escape sequences in
4474 the corresponding argument (except that \c terminates output,
4475 backslashes in \', \", and \? are not removed, and octal escapes
4476 beginning with \0 may contain up to four digits), and %q causes
4477 printf to output the corresponding argument in a format that can
4478 be reused as shell input.
4479
4480 The -v option causes the output to be assigned to the variable
4481 var rather than being printed to the standard output.
4482
4483 The format is reused as necessary to consume all of the argu‐
4484 ments. If the format requires more arguments than are supplied,
4485 the extra format specifications behave as if a zero value or
4486 null string, as appropriate, had been supplied. The return
4487 value is zero on success, non-zero on failure.
4488
4489 pushd [-n] [+n] [-n]
4490 pushd [-n] [dir]
4491 Adds a directory to the top of the directory stack, or rotates
4492 the stack, making the new top of the stack the current working
4493 directory. With no arguments, exchanges the top two directories
4494 and returns 0, unless the directory stack is empty. Arguments,
4495 if supplied, have the following meanings:
4496 -n Suppresses the normal change of directory when adding
4497 directories to the stack, so that only the stack is
4498 manipulated.
4499 +n Rotates the stack so that the nth directory (counting
4500 from the left of the list shown by dirs, starting with
4501 zero) is at the top.
4502 -n Rotates the stack so that the nth directory (counting
4503 from the right of the list shown by dirs, starting with
4504 zero) is at the top.
4505 dir Adds dir to the directory stack at the top, making it the
4506 new current working directory.
4507
4508 If the pushd command is successful, a dirs is performed as well.
4509 If the first form is used, pushd returns 0 unless the cd to dir
4510 fails. With the second form, pushd returns 0 unless the direc‐
4511 tory stack is empty, a non-existent directory stack element is
4512 specified, or the directory change to the specified new current
4513 directory fails.
4514
4515 pwd [-LP]
4516 Print the absolute pathname of the current working directory.
4517 The pathname printed contains no symbolic links if the -P option
4518 is supplied or the -o physical option to the set builtin command
4519 is enabled. If the -L option is used, the pathname printed may
4520 contain symbolic links. The return status is 0 unless an error
4521 occurs while reading the name of the current directory or an
4522 invalid option is supplied.
4523
4524 read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p
4525 prompt] [-t timeout] [-u fd] [name ...]
4526 One line is read from the standard input, or from the file
4527 descriptor fd supplied as an argument to the -u option, and the
4528 first word is assigned to the first name, the second word to the
4529 second name, and so on, with leftover words and their interven‐
4530 ing separators assigned to the last name. If there are fewer
4531 words read from the input stream than names, the remaining names
4532 are assigned empty values. The characters in IFS are used to
4533 split the line into words. The backslash character (\) may be
4534 used to remove any special meaning for the next character read
4535 and for line continuation. Options, if supplied, have the fol‐
4536 lowing meanings:
4537 -a aname
4538 The words are assigned to sequential indices of the array
4539 variable aname, starting at 0. aname is unset before any
4540 new values are assigned. Other name arguments are
4541 ignored.
4542 -d delim
4543 The first character of delim is used to terminate the
4544 input line, rather than newline.
4545 -e If the standard input is coming from a terminal, readline
4546 (see READLINE above) is used to obtain the line. Read‐
4547 line uses the current (or default, if line editing was
4548 not previously active) editing settings.
4549 -i text
4550 If readline is being used to read the line, text is
4551 placed into the editing buffer before editing begins.
4552 -n nchars
4553 read returns after reading nchars characters rather than
4554 waiting for a complete line of input, but honor a delim‐
4555 iter if fewer than nchars characters are read before the
4556 delimiter.
4557 -N nchars
4558 read returns after reading exactly nchars characters
4559 rather than waiting for a complete line of input, unless
4560 EOF is encountered or read times out. Delimiter charac‐
4561 ters encountered in the input are not treated specially
4562 and do not cause read to return until nchars characters
4563 are read.
4564 -p prompt
4565 Display prompt on standard error, without a trailing new‐
4566 line, before attempting to read any input. The prompt is
4567 displayed only if input is coming from a terminal.
4568 -r Backslash does not act as an escape character. The back‐
4569 slash is considered to be part of the line. In particu‐
4570 lar, a backslash-newline pair may not be used as a line
4571 continuation.
4572 -s Silent mode. If input is coming from a terminal, charac‐
4573 ters are not echoed.
4574 -t timeout
4575 Cause read to time out and return failure if a complete
4576 line of input is not read within timeout seconds. time‐
4577 out may be a decimal number with a fractional portion
4578 following the decimal point. This option is only effec‐
4579 tive if read is reading input from a terminal, pipe, or
4580 other special file; it has no effect when reading from
4581 regular files. If timeout is 0, read returns success if
4582 input is available on the specified file descriptor,
4583 failure otherwise. The exit status is greater than 128
4584 if the timeout is exceeded.
4585 -u fd Read input from file descriptor fd.
4586
4587 If no names are supplied, the line read is assigned to the vari‐
4588 able REPLY. The return code is zero, unless end-of-file is
4589 encountered, read times out (in which case the return code is
4590 greater than 128), or an invalid file descriptor is supplied as
4591 the argument to -u.
4592
4593 readonly [-aApf] [name[=word] ...]
4594 The given names are marked readonly; the values of these names
4595 may not be changed by subsequent assignment. If the -f option
4596 is supplied, the functions corresponding to the names are so
4597 marked. The -a option restricts the variables to indexed
4598 arrays; the -A option restricts the variables to associative
4599 arrays. If no name arguments are given, or if the -p option is
4600 supplied, a list of all readonly names is printed. The -p
4601 option causes output to be displayed in a format that may be
4602 reused as input. If a variable name is followed by =word, the
4603 value of the variable is set to word. The return status is 0
4604 unless an invalid option is encountered, one of the names is not
4605 a valid shell variable name, or -f is supplied with a name that
4606 is not a function.
4607
4608 return [n]
4609 Causes a function to exit with the return value specified by n.
4610 If n is omitted, the return status is that of the last command
4611 executed in the function body. If used outside a function, but
4612 during execution of a script by the . (source) command, it
4613 causes the shell to stop executing that script and return either
4614 n or the exit status of the last command executed within the
4615 script as the exit status of the script. If used outside a
4616 function and not during execution of a script by ., the return
4617 status is false. Any command associated with the RETURN trap is
4618 executed before execution resumes after the function or script.
4619
4620 set [--abefhkmnptuvxBCEHPT] [-o option] [arg ...]
4621 set [+abefhkmnptuvxBCEHPT] [+o option] [arg ...]
4622 Without options, the name and value of each shell variable are
4623 displayed in a format that can be reused as input for setting or
4624 resetting the currently-set variables. Read-only variables can‐
4625 not be reset. In posix mode, only shell variables are listed.
4626 The output is sorted according to the current locale. When
4627 options are specified, they set or unset shell attributes. Any
4628 arguments remaining after option processing are treated as val‐
4629 ues for the positional parameters and are assigned, in order, to
4630 $1, $2, ... $n. Options, if specified, have the following
4631 meanings:
4632 -a Automatically mark variables and functions which are
4633 modified or created for export to the environment of
4634 subsequent commands.
4635 -b Report the status of terminated background jobs immedi‐
4636 ately, rather than before the next primary prompt. This
4637 is effective only when job control is enabled.
4638 -e Exit immediately if a pipeline (which may consist of a
4639 single simple command), a subshell command enclosed in
4640 parentheses, or one of the commands executed as part of
4641 a command list enclosed by braces (see SHELL GRAMMAR
4642 above) exits with a non-zero status. The shell does not
4643 exit if the command that fails is part of the command
4644 list immediately following a while or until keyword,
4645 part of the test following the if or elif reserved
4646 words, part of any command executed in a && or ⎪⎪ list
4647 except the command following the final && or ⎪⎪, any
4648 command in a pipeline but the last, or if the command's
4649 return value is being inverted with !. A trap on ERR,
4650 if set, is executed before the shell exits. This option
4651 applies to the shell environment and each subshell envi‐
4652 ronment separately (see COMMAND EXECUTION ENVIRONMENT
4653 above), and may cause subshells to exit before executing
4654 all the commands in the subshell.
4655 -f Disable pathname expansion.
4656 -h Remember the location of commands as they are looked up
4657 for execution. This is enabled by default.
4658 -k All arguments in the form of assignment statements are
4659 placed in the environment for a command, not just those
4660 that precede the command name.
4661 -m Monitor mode. Job control is enabled. This option is
4662 on by default for interactive shells on systems that
4663 support it (see JOB CONTROL above). Background pro‐
4664 cesses run in a separate process group and a line con‐
4665 taining their exit status is printed upon their comple‐
4666 tion.
4667 -n Read commands but do not execute them. This may be used
4668 to check a shell script for syntax errors. This is
4669 ignored by interactive shells.
4670 -o option-name
4671 The option-name can be one of the following:
4672 allexport
4673 Same as -a.
4674 braceexpand
4675 Same as -B.
4676 emacs Use an emacs-style command line editing inter‐
4677 face. This is enabled by default when the shell
4678 is interactive, unless the shell is started with
4679 the --noediting option. This also affects the
4680 editing interface used for read -e.
4681 errexit Same as -e.
4682 errtrace
4683 Same as -E.
4684 functrace
4685 Same as -T.
4686 hashall Same as -h.
4687 histexpand
4688 Same as -H.
4689 history Enable command history, as described above under
4690 HISTORY. This option is on by default in inter‐
4691 active shells.
4692 ignoreeof
4693 The effect is as if the shell command
4694 ``IGNOREEOF=10'' had been executed (see Shell
4695 Variables above).
4696 keyword Same as -k.
4697 monitor Same as -m.
4698 noclobber
4699 Same as -C.
4700 noexec Same as -n.
4701 noglob Same as -f.
4702 nolog Currently ignored.
4703 notify Same as -b.
4704 nounset Same as -u.
4705 onecmd Same as -t.
4706 physical
4707 Same as -P.
4708 pipefail
4709 If set, the return value of a pipeline is the
4710 value of the last (rightmost) command to exit
4711 with a non-zero status, or zero if all commands
4712 in the pipeline exit successfully. This option
4713 is disabled by default.
4714 posix Change the behavior of bash where the default
4715 operation differs from the POSIX standard to
4716 match the standard (posix mode).
4717 privileged
4718 Same as -p.
4719 verbose Same as -v.
4720 vi Use a vi-style command line editing interface.
4721 This also affects the editing interface used for
4722 read -e.
4723 xtrace Same as -x.
4724 If -o is supplied with no option-name, the values of the
4725 current options are printed. If +o is supplied with no
4726 option-name, a series of set commands to recreate the
4727 current option settings is displayed on the standard
4728 output.
4729 -p Turn on privileged mode. In this mode, the $ENV and
4730 $BASH_ENV files are not processed, shell functions are
4731 not inherited from the environment, and the SHELLOPTS,
4732 BASHOPTS, CDPATH, and GLOBIGNORE variables, if they
4733 appear in the environment, are ignored. If the shell is
4734 started with the effective user (group) id not equal to
4735 the real user (group) id, and the -p option is not sup‐
4736 plied, these actions are taken and the effective user id
4737 is set to the real user id. If the -p option is sup‐
4738 plied at startup, the effective user id is not reset.
4739 Turning this option off causes the effective user and
4740 group ids to be set to the real user and group ids.
4741 -t Exit after reading and executing one command.
4742 -u Treat unset variables and parameters other than the spe‐
4743 cial parameters "@" and "*" as an error when performing
4744 parameter expansion. If expansion is attempted on an
4745 unset variable or parameter, the shell prints an error
4746 message, and, if not interactive, exits with a non-zero
4747 status.
4748 -v Print shell input lines as they are read.
4749 -x After expanding each simple command, for command, case
4750 command, select command, or arithmetic for command, dis‐
4751 play the expanded value of PS4, followed by the command
4752 and its expanded arguments or associated word list.
4753 -B The shell performs brace expansion (see Brace Expansion
4754 above). This is on by default.
4755 -C If set, bash does not overwrite an existing file with
4756 the >, >&, and <> redirection operators. This may be
4757 overridden when creating output files by using the redi‐
4758 rection operator >| instead of >.
4759 -E If set, any trap on ERR is inherited by shell functions,
4760 command substitutions, and commands executed in a sub‐
4761 shell environment. The ERR trap is normally not inher‐
4762 ited in such cases.
4763 -H Enable ! style history substitution. This option is on
4764 by default when the shell is interactive.
4765 -P If set, the shell does not follow symbolic links when
4766 executing commands such as cd that change the current
4767 working directory. It uses the physical directory
4768 structure instead. By default, bash follows the logical
4769 chain of directories when performing commands which
4770 change the current directory.
4771 -T If set, any traps on DEBUG and RETURN are inherited by
4772 shell functions, command substitutions, and commands
4773 executed in a subshell environment. The DEBUG and
4774 RETURN traps are normally not inherited in such cases.
4775 -- If no arguments follow this option, then the positional
4776 parameters are unset. Otherwise, the positional parame‐
4777 ters are set to the args, even if some of them begin
4778 with a -.
4779 - Signal the end of options, cause all remaining args to
4780 be assigned to the positional parameters. The -x and -v
4781 options are turned off. If there are no args, the posi‐
4782 tional parameters remain unchanged.
4783
4784 The options are off by default unless otherwise noted. Using +
4785 rather than - causes these options to be turned off. The
4786 options can also be specified as arguments to an invocation of
4787 the shell. The current set of options may be found in $-. The
4788 return status is always true unless an invalid option is encoun‐
4789 tered.
4790
4791 shift [n]
4792 The positional parameters from n+1 ... are renamed to $1 ....
4793 Parameters represented by the numbers $# down to $#-n+1 are
4794 unset. n must be a non-negative number less than or equal to
4795 $#. If n is 0, no parameters are changed. If n is not given,
4796 it is assumed to be 1. If n is greater than $#, the positional
4797 parameters are not changed. The return status is greater than
4798 zero if n is greater than $# or less than zero; otherwise 0.
4799
4800 shopt [-pqsu] [-o] [optname ...]
4801 Toggle the values of variables controlling optional shell behav‐
4802 ior. With no options, or with the -p option, a list of all set‐
4803 table options is displayed, with an indication of whether or not
4804 each is set. The -p option causes output to be displayed in a
4805 form that may be reused as input. Other options have the fol‐
4806 lowing meanings:
4807 -s Enable (set) each optname.
4808 -u Disable (unset) each optname.
4809 -q Suppresses normal output (quiet mode); the return status
4810 indicates whether the optname is set or unset. If multi‐
4811 ple optname arguments are given with -q, the return sta‐
4812 tus is zero if all optnames are enabled; non-zero other‐
4813 wise.
4814 -o Restricts the values of optname to be those defined for
4815 the -o option to the set builtin.
4816
4817 If either -s or -u is used with no optname arguments, the dis‐
4818 play is limited to those options which are set or unset, respec‐
4819 tively. Unless otherwise noted, the shopt options are disabled
4820 (unset) by default.
4821
4822 The return status when listing options is zero if all optnames
4823 are enabled, non-zero otherwise. When setting or unsetting
4824 options, the return status is zero unless an optname is not a
4825 valid shell option.
4826
4827 The list of shopt options is:
4828
4829 autocd If set, a command name that is the name of a directory
4830 is executed as if it were the argument to the cd com‐
4831 mand. This option is only used by interactive shells.
4832 cdable_vars
4833 If set, an argument to the cd builtin command that is
4834 not a directory is assumed to be the name of a variable
4835 whose value is the directory to change to.
4836 cdspell If set, minor errors in the spelling of a directory com‐
4837 ponent in a cd command will be corrected. The errors
4838 checked for are transposed characters, a missing charac‐
4839 ter, and one character too many. If a correction is
4840 found, the corrected file name is printed, and the com‐
4841 mand proceeds. This option is only used by interactive
4842 shells.
4843 checkhash
4844 If set, bash checks that a command found in the hash ta‐
4845 ble exists before trying to execute it. If a hashed
4846 command no longer exists, a normal path search is per‐
4847 formed.
4848 checkjobs
4849 If set, bash lists the status of any stopped and running
4850 jobs before exiting an interactive shell. If any jobs
4851 are running, this causes the exit to be deferred until a
4852 second exit is attempted without an intervening command
4853 (see JOB CONTROL above). The shell always postpones
4854 exiting if any jobs are stopped.
4855 checkwinsize
4856 If set, bash checks the window size after each command
4857 and, if necessary, updates the values of LINES and COL‐
4858 UMNS.
4859 cmdhist If set, bash attempts to save all lines of a multiple-
4860 line command in the same history entry. This allows
4861 easy re-editing of multi-line commands.
4862 compat31
4863 If set, bash changes its behavior to that of version 3.1
4864 with respect to quoted arguments to the conditional com‐
4865 mand's =~ operator.
4866 compat32
4867 If set, bash changes its behavior to that of version 3.2
4868 with respect to locale-specific string comparison when
4869 using the conditional command's < and > operators.
4870 compat40
4871 If set, bash changes its behavior to that of version 4.0
4872 with respect to locale-specific string comparison when
4873 using the conditional command's < and > operators and
4874 the effect of interrupting a command list.
4875 dirspell
4876 If set, bash attempts spelling correction on directory
4877 names during word completion if the directory name ini‐
4878 tially supplied does not exist.
4879 dotglob If set, bash includes filenames beginning with a `.' in
4880 the results of pathname expansion.
4881 execfail
4882 If set, a non-interactive shell will not exit if it can‐
4883 not execute the file specified as an argument to the
4884 exec builtin command. An interactive shell does not
4885 exit if exec fails.
4886 expand_aliases
4887 If set, aliases are expanded as described above under
4888 ALIASES. This option is enabled by default for interac‐
4889 tive shells.
4890 extdebug
4891 If set, behavior intended for use by debuggers is
4892 enabled:
4893 1. The -F option to the declare builtin displays the
4894 source file name and line number corresponding to
4895 each function name supplied as an argument.
4896 2. If the command run by the DEBUG trap returns a
4897 non-zero value, the next command is skipped and
4898 not executed.
4899 3. If the command run by the DEBUG trap returns a
4900 value of 2, and the shell is executing in a sub‐
4901 routine (a shell function or a shell script exe‐
4902 cuted by the . or source builtins), a call to
4903 return is simulated.
4904 4. BASH_ARGC and BASH_ARGV are updated as described
4905 in their descriptions above.
4906 5. Function tracing is enabled: command substitu‐
4907 tion, shell functions, and subshells invoked with
4908 ( command ) inherit the DEBUG and RETURN traps.
4909 6. Error tracing is enabled: command substitution,
4910 shell functions, and subshells invoked with (
4911 command ) inherit the ERROR trap.
4912 extglob If set, the extended pattern matching features described
4913 above under Pathname Expansion are enabled.
4914 extquote
4915 If set, $'string' and $"string" quoting is performed
4916 within ${parameter} expansions enclosed in double
4917 quotes. This option is enabled by default.
4918 failglob
4919 If set, patterns which fail to match filenames during
4920 pathname expansion result in an expansion error.
4921 force_fignore
4922 If set, the suffixes specified by the FIGNORE shell
4923 variable cause words to be ignored when performing word
4924 completion even if the ignored words are the only possi‐
4925 ble completions. See SHELL VARIABLES above for a
4926 description of FIGNORE. This option is enabled by
4927 default.
4928 globstar
4929 If set, the pattern ** used in a pathname expansion con‐
4930 text will match a files and zero or more directories and
4931 subdirectories. If the pattern is followed by a /, only
4932 directories and subdirectories match.
4933 gnu_errfmt
4934 If set, shell error messages are written in the standard
4935 GNU error message format.
4936 histappend
4937 If set, the history list is appended to the file named
4938 by the value of the HISTFILE variable when the shell
4939 exits, rather than overwriting the file.
4940 histreedit
4941 If set, and readline is being used, a user is given the
4942 opportunity to re-edit a failed history substitution.
4943 histverify
4944 If set, and readline is being used, the results of his‐
4945 tory substitution are not immediately passed to the
4946 shell parser. Instead, the resulting line is loaded
4947 into the readline editing buffer, allowing further modi‐
4948 fication.
4949 hostcomplete
4950 If set, and readline is being used, bash will attempt to
4951 perform hostname completion when a word containing a @
4952 is being completed (see Completing under READLINE
4953 above). This is enabled by default.
4954 huponexit
4955 If set, bash will send SIGHUP to all jobs when an inter‐
4956 active login shell exits.
4957 interactive_comments
4958 If set, allow a word beginning with # to cause that word
4959 and all remaining characters on that line to be ignored
4960 in an interactive shell (see COMMENTS above). This
4961 option is enabled by default.
4962 lithist If set, and the cmdhist option is enabled, multi-line
4963 commands are saved to the history with embedded newlines
4964 rather than using semicolon separators where possible.
4965 login_shell
4966 The shell sets this option if it is started as a login
4967 shell (see INVOCATION above). The value may not be
4968 changed.
4969 mailwarn
4970 If set, and a file that bash is checking for mail has
4971 been accessed since the last time it was checked, the
4972 message ``The mail in mailfile has been read'' is dis‐
4973 played.
4974 no_empty_cmd_completion
4975 If set, and readline is being used, bash will not
4976 attempt to search the PATH for possible completions when
4977 completion is attempted on an empty line.
4978 nocaseglob
4979 If set, bash matches filenames in a case-insensitive
4980 fashion when performing pathname expansion (see Pathname
4981 Expansion above).
4982 nocasematch
4983 If set, bash matches patterns in a case-insensitive
4984 fashion when performing matching while executing case or
4985 [[ conditional commands.
4986 nullglob
4987 If set, bash allows patterns which match no files (see
4988 Pathname Expansion above) to expand to a null string,
4989 rather than themselves.
4990 progcomp
4991 If set, the programmable completion facilities (see Pro‐
4992 grammable Completion above) are enabled. This option is
4993 enabled by default.
4994 promptvars
4995 If set, prompt strings undergo parameter expansion, com‐
4996 mand substitution, arithmetic expansion, and quote
4997 removal after being expanded as described in PROMPTING
4998 above. This option is enabled by default.
4999 restricted_shell
5000 The shell sets this option if it is started in
5001 restricted mode (see RESTRICTED SHELL below). The value
5002 may not be changed. This is not reset when the startup
5003 files are executed, allowing the startup files to dis‐
5004 cover whether or not a shell is restricted.
5005 shift_verbose
5006 If set, the shift builtin prints an error message when
5007 the shift count exceeds the number of positional parame‐
5008 ters.
5009 sourcepath
5010 If set, the source (.) builtin uses the value of PATH to
5011 find the directory containing the file supplied as an
5012 argument. This option is enabled by default.
5013 xpg_echo
5014 If set, the echo builtin expands backslash-escape
5015 sequences by default.
5016 suspend [-f]
5017 Suspend the execution of this shell until it receives a SIGCONT
5018 signal. When the suspended shell is a background process, it can
5019 be restarted by the fg command. For more information, read the
5020 JOB CONTROL section. The suspend command can not suspend the
5021 login shell. However, when -f option is specified, suspend com‐
5022 mand can suspend even login shell. The return status is 0
5023 unless the shell is a login shell and -f is not supplied, or if
5024 job control is not enabled.
5025 test expr
5026 [ expr ]
5027 Return a status of 0 or 1 depending on the evaluation of the
5028 conditional expression expr. Each operator and operand must be
5029 a separate argument. Expressions are composed of the primaries
5030 described above under CONDITIONAL EXPRESSIONS. test does not
5031 accept any options, nor does it accept and ignore an argument of
5032 -- as signifying the end of options.
5033
5034 Expressions may be combined using the following operators,
5035 listed in decreasing order of precedence. The evaluation
5036 depends on the number of arguments; see below.
5037 ! expr True if expr is false.
5038 ( expr )
5039 Returns the value of expr. This may be used to override
5040 the normal precedence of operators.
5041 expr1 -a expr2
5042 True if both expr1 and expr2 are true.
5043 expr1 -o expr2
5044 True if either expr1 or expr2 is true.
5045
5046 test and [ evaluate conditional expressions using a set of rules
5047 based on the number of arguments.
5048
5049 0 arguments
5050 The expression is false.
5051 1 argument
5052 The expression is true if and only if the argument is not
5053 null.
5054 2 arguments
5055 If the first argument is !, the expression is true if and
5056 only if the second argument is null. If the first argu‐
5057 ment is one of the unary conditional operators listed
5058 above under CONDITIONAL EXPRESSIONS, the expression is
5059 true if the unary test is true. If the first argument is
5060 not a valid unary conditional operator, the expression is
5061 false.
5062 3 arguments
5063 If the second argument is one of the binary conditional
5064 operators listed above under CONDITIONAL EXPRESSIONS, the
5065 result of the expression is the result of the binary test
5066 using the first and third arguments as operands. The -a
5067 and -o operators are considered binary operators when
5068 there are three arguments. If the first argument is !,
5069 the value is the negation of the two-argument test using
5070 the second and third arguments. If the first argument is
5071 exactly ( and the third argument is exactly ), the result
5072 is the one-argument test of the second argument. Other‐
5073 wise, the expression is false.
5074 4 arguments
5075 If the first argument is !, the result is the negation of
5076 the three-argument expression composed of the remaining
5077 arguments. Otherwise, the expression is parsed and eval‐
5078 uated according to precedence using the rules listed
5079 above.
5080 5 or more arguments
5081 The expression is parsed and evaluated according to
5082 precedence using the rules listed above.
5083
5084 times Print the accumulated user and system times for the shell and
5085 for processes run from the shell. The return status is 0.
5086
5087 trap [-lp] [[arg] sigspec ...]
5088 The command arg is to be read and executed when the shell
5089 receives signal(s) sigspec. If arg is absent (and there is a
5090 single sigspec) or -, each specified signal is reset to its
5091 original disposition (the value it had upon entrance to the
5092 shell). If arg is the null string the signal specified by each
5093 sigspec is ignored by the shell and by the commands it invokes.
5094 If arg is not present and -p has been supplied, then the trap
5095 commands associated with each sigspec are displayed. If no
5096 arguments are supplied or if only -p is given, trap prints the
5097 list of commands associated with each signal. The -l option
5098 causes the shell to print a list of signal names and their cor‐
5099 responding numbers. Each sigspec is either a signal name
5100 defined in <signal.h>, or a signal number. Signal names are
5101 case insensitive and the SIG prefix is optional.
5102
5103 If a sigspec is EXIT (0) the command arg is executed on exit
5104 from the shell. If a sigspec is DEBUG, the command arg is exe‐
5105 cuted before every simple command, for command, case command,
5106 select command, every arithmetic for command, and before the
5107 first command executes in a shell function (see SHELL GRAMMAR
5108 above). Refer to the description of the extdebug option to the
5109 shopt builtin for details of its effect on the DEBUG trap. If a
5110 sigspec is RETURN, the command arg is executed each time a shell
5111 function or a script executed with the . or source builtins fin‐
5112 ishes executing.
5113
5114 If a sigspec is ERR, the command arg is executed whenever a sim‐
5115 ple command has a non-zero exit status, subject to the following
5116 conditions. The ERR trap is not executed if the failed command
5117 is part of the command list immediately following a while or
5118 until keyword, part of the test in an if statement, part of a
5119 command executed in a && or ⎪⎪ list, or if the command's return
5120 value is being inverted via !. These are the same conditions
5121 obeyed by the errexit option.
5122
5123 Signals ignored upon entry to the shell cannot be trapped, reset
5124 or listed. Trapped signals that are not being ignored are reset
5125 to their original values in a subshell or subshell environment
5126 when one is created. The return status is false if any sigspec
5127 is invalid; otherwise trap returns true.
5128
5129 type [-aftpP] name [name ...]
5130 With no options, indicate how each name would be interpreted if
5131 used as a command name. If the -t option is used, type prints a
5132 string which is one of alias, keyword, function, builtin, or
5133 file if name is an alias, shell reserved word, function,
5134 builtin, or disk file, respectively. If the name is not found,
5135 then nothing is printed, and an exit status of false is
5136 returned. If the -p option is used, type either returns the
5137 name of the disk file that would be executed if name were speci‐
5138 fied as a command name, or nothing if ``type -t name'' would not
5139 return file. The -P option forces a PATH search for each name,
5140 even if ``type -t name'' would not return file. If a command is
5141 hashed, -p and -P print the hashed value, not necessarily the
5142 file that appears first in PATH. If the -a option is used, type
5143 prints all of the places that contain an executable named name.
5144 This includes aliases and functions, if and only if the -p
5145 option is not also used. The table of hashed commands is not
5146 consulted when using -a. The -f option suppresses shell func‐
5147 tion lookup, as with the command builtin. type returns true if
5148 all of the arguments are found, false if any are not found.
5149
5150 ulimit [-HSTabcdefilmnpqrstuvx [limit]]
5151 Provides control over the resources available to the shell and
5152 to processes started by it, on systems that allow such control.
5153 The -H and -S options specify that the hard or soft limit is set
5154 for the given resource. A hard limit cannot be increased by a
5155 non-root user once it is set; a soft limit may be increased up
5156 to the value of the hard limit. If neither -H nor -S is speci‐
5157 fied, both the soft and hard limits are set. The value of limit
5158 can be a number in the unit specified for the resource or one of
5159 the special values hard, soft, or unlimited, which stand for the
5160 current hard limit, the current soft limit, and no limit,
5161 respectively. If limit is omitted, the current value of the
5162 soft limit of the resource is printed, unless the -H option is
5163 given. When more than one resource is specified, the limit name
5164 and unit are printed before the value. Other options are inter‐
5165 preted as follows:
5166 -a All current limits are reported
5167 -b The maximum socket buffer size
5168 -c The maximum size of core files created
5169 -d The maximum size of a process's data segment
5170 -e The maximum scheduling priority ("nice")
5171 -f The maximum size of files written by the shell and its
5172 children
5173 -i The maximum number of pending signals
5174 -l The maximum size that may be locked into memory
5175 -m The maximum resident set size (many systems do not honor
5176 this limit)
5177 -n The maximum number of open file descriptors (most systems
5178 do not allow this value to be set)
5179 -p The pipe size in 512-byte blocks (this may not be set)
5180 -q The maximum number of bytes in POSIX message queues
5181 -r The maximum real-time scheduling priority
5182 -s The maximum stack size
5183 -t The maximum amount of cpu time in seconds
5184 -u The maximum number of processes available to a single
5185 user
5186 -v The maximum amount of virtual memory available to the
5187 shell
5188 -x The maximum number of file locks
5189 -T The maximum number of threads
5190
5191 If limit is given, it is the new value of the specified resource
5192 (the -a option is display only). If no option is given, then -f
5193 is assumed. Values are in 1024-byte increments, except for -t,
5194 which is in seconds, -p, which is in units of 512-byte blocks,
5195 and -T, -b, -n, and -u, which are unscaled values. The return
5196 status is 0 unless an invalid option or argument is supplied, or
5197 an error occurs while setting a new limit. In POSIX Mode
5198 512-byte blocks are used for the `-c' and `-f' options.
5199
5200 umask [-p] [-S] [mode]
5201 The user file-creation mask is set to mode. If mode begins with
5202 a digit, it is interpreted as an octal number; otherwise it is
5203 interpreted as a symbolic mode mask similar to that accepted by
5204 chmod(1). If mode is omitted, the current value of the mask is
5205 printed. The -S option causes the mask to be printed in sym‐
5206 bolic form; the default output is an octal number. If the -p
5207 option is supplied, and mode is omitted, the output is in a form
5208 that may be reused as input. The return status is 0 if the mode
5209 was successfully changed or if no mode argument was supplied,
5210 and false otherwise.
5211
5212 unalias [-a] [name ...]
5213 Remove each name from the list of defined aliases. If -a is
5214 supplied, all alias definitions are removed. The return value
5215 is true unless a supplied name is not a defined alias.
5216
5217 unset [-fv] [name ...]
5218 For each name, remove the corresponding variable or function.
5219 If no options are supplied, or the -v option is given, each name
5220 refers to a shell variable. Read-only variables may not be
5221 unset. If -f is specified, each name refers to a shell func‐
5222 tion, and the function definition is removed. Each unset vari‐
5223 able or function is removed from the environment passed to sub‐
5224 sequent commands. If any of COMP_WORDBREAKS, RANDOM, SECONDS,
5225 LINENO, HISTCMD, FUNCNAME, GROUPS, or DIRSTACK are unset, they
5226 lose their special properties, even if they are subsequently
5227 reset. The exit status is true unless a name is readonly.
5228
5229 wait [n ...]
5230 Wait for each specified process and return its termination sta‐
5231 tus. Each n may be a process ID or a job specification; if a
5232 job spec is given, all processes in that job's pipeline are
5233 waited for. If n is not given, all currently active child pro‐
5234 cesses are waited for, and the return status is zero. If n
5235 specifies a non-existent process or job, the return status is
5236 127. Otherwise, the return status is the exit status of the
5237 last process or job waited for.
5238
5240 If bash is started with the name rbash, or the -r option is supplied at
5241 invocation, the shell becomes restricted. A restricted shell is used
5242 to set up an environment more controlled than the standard shell. It
5243 behaves identically to bash with the exception that the following are
5244 disallowed or not performed:
5245
5246 · changing directories with cd
5247
5248 · setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV
5249
5250 · specifying command names containing /
5251
5252 · specifying a file name containing a / as an argument to the .
5253 builtin command
5254
5255 · Specifying a filename containing a slash as an argument to the
5256 -p option to the hash builtin command
5257
5258 · importing function definitions from the shell environment at
5259 startup
5260
5261 · parsing the value of SHELLOPTS from the shell environment at
5262 startup
5263
5264 · redirecting output using the >, >|, <>, >&, &>, and >> redirect‐
5265 ion operators
5266
5267 · using the exec builtin command to replace the shell with another
5268 command
5269
5270 · adding or deleting builtin commands with the -f and -d options
5271 to the enable builtin command
5272
5273 · Using the enable builtin command to enable disabled shell
5274 builtins
5275
5276 · specifying the -p option to the command builtin command
5277
5278 · turning off restricted mode with set +r or set +o restricted.
5279
5280 These restrictions are enforced after any startup files are read.
5281
5282 When a command that is found to be a shell script is executed (see COM‐
5283 MAND EXECUTION above), rbash turns off any restrictions in the shell
5284 spawned to execute the script.
5285
5287 Bash Reference Manual, Brian Fox and Chet Ramey
5288 The Gnu Readline Library, Brian Fox and Chet Ramey
5289 The Gnu History Library, Brian Fox and Chet Ramey
5290 Portable Operating System Interface (POSIX) Part 2: Shell and Utili‐
5291 ties, IEEE
5292 sh(1), ksh(1), csh(1)
5293 emacs(1), vi(1)
5294 readline(3)
5295
5297 /bin/bash
5298 The bash executable
5299 /etc/profile
5300 The systemwide initialization file, executed for login shells
5301 /etc/bash.bash_logout
5302 The systemwide login shell cleanup file, executed when a login
5303 shell exits
5304 ~/.bash_profile
5305 The personal initialization file, executed for login shells
5306 ~/.bashrc
5307 The individual per-interactive-shell startup file
5308 ~/.bash_logout
5309 The individual login shell cleanup file, executed when a login
5310 shell exits
5311 ~/.inputrc
5312 Individual readline initialization file
5313
5315 Brian Fox, Free Software Foundation
5316 bfox@gnu.org
5317
5318 Chet Ramey, Case Western Reserve University
5319 chet.ramey@case.edu
5320
5322 If you find a bug in bash, you should report it. But first, you should
5323 make sure that it really is a bug, and that it appears in the latest
5324 version of bash. The latest version is always available from
5325 ftp://ftp.gnu.org/pub/bash/.
5326
5327 Once you have determined that a bug actually exists, use the bashbug
5328 command (from the source package) to submit a bug report. If you have
5329 a fix, you are encouraged to mail that as well! Suggestions and
5330 `philosophical' bug reports may be mailed to bug-bash@gnu.org or posted
5331 to the Usenet newsgroup gnu.bash.bug.
5332
5333 ALL bug reports should include:
5334
5335 The version number of bash
5336 The hardware and operating system
5337 The compiler used to compile
5338 A description of the bug behaviour
5339 A short script or `recipe' which exercises the bug
5340
5341 Comments and bug reports concerning this manual page should be directed
5342 to chet@po.cwru.edu.
5343
5345 It's too big and too slow.
5346
5347 There are some subtle differences between bash and traditional versions
5348 of sh, mostly because of the POSIX specification.
5349
5350 Aliases are confusing in some uses.
5351
5352 Shell builtin commands and functions are not stoppable/restartable.
5353
5354 Compound commands and command sequences of the form `a ; b ; c' are not
5355 handled gracefully when process suspension is attempted. When a
5356 process is stopped, the shell immediately executes the next command in
5357 the sequence. It suffices to place the sequence of commands between
5358 parentheses to force it into a subshell, which may be stopped as a
5359 unit.
5360
5361 Array variables may not (yet) be exported.
5362
5363 There may be only one active coprocess at a time.
5364
5365
5366
5367GNU Bash-4.1 2009 December 29 BASH(1)