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