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