4 BASH(1) USER COMMANDS BASH(1)
9 bash - GNU Bourne-Again SHell
15 Bash is Copyright (C) 1989, 1991 by the Free Software Foun-
19 Bash is an sh-compatible command language interpreter that
20 executes commands read from the standard input or from a
21 file. Bash also incorporates useful features from the _
\bK_
\bo_
\br_
\bn
22 and _
\bC shells (ksh and csh).
24 Bash is ultimately intended to be a conformant implementa-
25 tion of the IEEE Posix Shell and Tools specification (IEEE
26 Working Group 1003.2).
29 In addition to the single-character shell options documented
30 in the description of the set builtin command, bash inter-
31 prets the following flags when it is invoked:
33 -c _
\bs_
\bt_
\br_
\bi_
\bn_
\bg If the -c flag is present, then commands are read
34 from _
\bs_
\bt_
\br_
\bi_
\bn_
\bg. If there are arguments after the
35 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg, they are assigned to the positional param-
36 eters, starting with $0.
37 -i If the -i flag is present, the shell is _
\bi_
\bn_
\bt_
\be_
\br_
\ba_
\bc_
\b-
39 -s If the -s flag is present, or if no arguments
40 remain after option processing, then commands are
41 read from the standard input. This option allows
42 the positional parameters to be set when invoking
44 - A single - signals the end of options and disables
45 further option processing. Any arguments after
46 the - are treated as filenames and arguments. An
47 argument of -- is equivalent to an argument of -.
49 Bash also interprets a number of multi-character options.
50 These options must appear on the command line before the
51 single-character options to be recognized.
53 -norc Do not read and execute the personal initializa-
54 tion file ~/._
\bb_
\ba_
\bs_
\bh_
\br_
\bc if the shell is interactive.
55 This option is on by default if the shell is
58 Do not read either the system-wide startup file
59 /_
\be_
\bt_
\bc/_
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be or any of the personal initialization
63 GNU Last change: 1995 May 5 1
70 BASH(1) USER COMMANDS BASH(1)
74 files ~/._
\bb_
\ba_
\bs_
\bh__
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be, ~/._
\bb_
\ba_
\bs_
\bh__
\bl_
\bo_
\bg_
\bi_
\bn, or ~/._
\bp_
\br_
\bo_
\b-
75 _
\bf_
\bi_
\bl_
\be. By default, bash normally reads these files
76 when it is invoked as a login shell (see INVOCA-
78 -rcfile _
\bf_
\bi_
\bl_
\be
79 Execute commands from _
\bf_
\bi_
\bl_
\be instead of the standard
80 personal initialization file ~/._
\bb_
\ba_
\bs_
\bh_
\br_
\bc, if the
81 shell is interactive (see INVOCATION below).
82 -version Show the version number of this instance of bash
84 -quiet Do not be verbose when starting up (do not show
85 the shell version or any other information). This
87 -login Make bash act as if it had been invoked as a login
90 Do not perform curly brace expansion (see Brace
93 Do not use the GNU _
\br_
\be_
\ba_
\bd_
\bl_
\bi_
\bn_
\be library to read com-
94 mand lines if interactive.
95 -posix Change the behavior of bash where the default
96 operation differs from the Posix 1003.2 standard
100 If arguments remain after option processing, and neither the
101 -c nor the -s option has been supplied, the first argument
102 is assumed to be the name of a file containing shell com-
103 mands. If bash is invoked in this fashion, $0 is set to the
104 name of the file, and the positional parameters are set to
105 the remaining arguments. Bash reads and executes commands
106 from this file, then exits. Bash's exit status is the exit
107 status of the last command executed in the script.
112 word A sequence of characters considered as a single unit by
113 the shell. Also known as a token.
114 name A _
\bw_
\bo_
\br_
\bd consisting only of alphanumeric characters and
115 underscores, and beginning with an alphabetic character
116 or an underscore. Also referred to as an identifier.
118 A character that, when unquoted, separates words. One
120 | & ; ( ) < > space tab
122 A _
\bt_
\bo_
\bk_
\be_
\bn that performs a control function. It is one of
123 the following symbols:
124 || & && ; ;; ( ) | <newline>
129 GNU Last change: 1995 May 5 2
136 BASH(1) USER COMMANDS BASH(1)
141 _
\bR_
\be_
\bs_
\be_
\br_
\bv_
\be_
\bd _
\bw_
\bo_
\br_
\bd_
\bs are words that have a special meaning to the
142 shell. The following words are recognized as reserved when
143 unquoted and either the first word of a simple command (see
144 SHELL GRAMMAR below) or the third word of a case or for com-
147 ! case do done elif else esac fi for function if in select
152 A _
\bs_
\bi_
\bm_
\bp_
\bl_
\be _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is a sequence of optional variable assign-
153 ments followed by _
\bb_
\bl_
\ba_
\bn_
\bk-separated words and redirections,
154 and terminated by a _
\bc_
\bo_
\bn_
\bt_
\br_
\bo_
\bl _
\bo_
\bp_
\be_
\br_
\ba_
\bt_
\bo_
\br. The first word speci-
155 fies the command to be executed. The remaining words are
156 passed as arguments to the invoked command.
158 The return value of a _
\bs_
\bi_
\bm_
\bp_
\bl_
\be _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is its exit status, or
159 128+_
\bn if the command is terminated by signal _
\bn.
162 A _
\bp_
\bi_
\bp_
\be_
\bl_
\bi_
\bn_
\be is a sequence of one or more commands separated
163 by the character |. The format for a pipeline is:
165 [ ! ] _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd [ | _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2 ... ]
167 The standard output of _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is connected to the standard
168 input of _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2. This connection is performed before any
169 redirections specified by the command (see REDIRECTION
172 If the reserved word ! precedes a pipeline, the exit status
173 of that pipeline is the logical NOT of the exit status of
174 the last command. Otherwise, the status of the pipeline is
175 the exit status of the last command. The shell waits for
176 all commands in the pipeline to terminate before returning a
179 Each command in a pipeline is executed as a separate process
180 (i.e., in a subshell).
183 A _
\bl_
\bi_
\bs_
\bt is a sequence of one or more pipelines separated by
184 one of the operators ;, &, &&, or ||, and terminated by one
185 of ;, &, or <newline>.
187 Of these list operators, && and || have equal precedence,
188 followed by ; and &, which have equal precedence.
190 If a command is terminated by the control operator &, the
191 shell executes the command in the _
\bb_
\ba_
\bc_
\bk_
\bg_
\br_
\bo_
\bu_
\bn_
\bd in a subshell.
195 GNU Last change: 1995 May 5 3
202 BASH(1) USER COMMANDS BASH(1)
206 The shell does not wait for the command to finish, and the
207 return status is 0. Commands separated by a ; are executed
208 sequentially; the shell waits for each command to terminate
209 in turn. The return status is the exit status of the last
212 The control operators && and || denote AND lists and OR
213 lists, respectively. An AND list has the form
215 _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd && _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2
217 _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2 is executed if, and only if, _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd returns an
220 An OR list has the form
222 _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd || _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2
224 _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\b2 is executed if and only if _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd returns a
225 non-zero exit status. The return status of AND and OR lists
226 is the exit status of the last command executed in the list.
229 A _
\bc_
\bo_
\bm_
\bp_
\bo_
\bu_
\bn_
\bd _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is one of the following:
232 _
\bl_
\bi_
\bs_
\bt is executed in a subshell. Variable assignments
233 and builtin commands that affect the shell's environ-
234 ment do not remain in effect after the command com-
235 pletes. The return status is the exit status of _
\bl_
\bi_
\bs_
\bt.
237 { _
\bl_
\bi_
\bs_
\bt; }
238 _
\bl_
\bi_
\bs_
\bt is simply executed in the current shell environ-
239 ment. This is known as a _
\bg_
\br_
\bo_
\bu_
\bp _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd. The return
240 status is the exit status of _
\bl_
\bi_
\bs_
\bt.
242 for _
\bn_
\ba_
\bm_
\be [ in _
\bw_
\bo_
\br_
\bd; ] do _
\bl_
\bi_
\bs_
\bt ; done
243 The list of words following in is expanded, generating
244 a list of items. The variable _
\bn_
\ba_
\bm_
\be is set to each ele-
245 ment of this list in turn, and _
\bl_
\bi_
\bs_
\bt is executed each
246 time. If the in _
\bw_
\bo_
\br_
\bd is omitted, the for command exe-
247 cutes _
\bl_
\bi_
\bs_
\bt once for each positional parameter that is
248 set (see PARAMETERS below).
250 select _
\bn_
\ba_
\bm_
\be [ in _
\bw_
\bo_
\br_
\bd; ] do _
\bl_
\bi_
\bs_
\bt ; done
251 The list of words following in is expanded, generating
252 a list of items. The set of expanded words is printed
253 on the standard error, each preceded by a number. If
254 the in _
\bw_
\bo_
\br_
\bd is omitted, the positional parameters are
255 printed (see PARAMETERS below). The PS3 prompt is then
256 displayed and a line read from the standard input. If
257 the line consists of the number corresponding to one of
261 GNU Last change: 1995 May 5 4
268 BASH(1) USER COMMANDS BASH(1)
272 the displayed words, then the value of _
\bn_
\ba_
\bm_
\be is set to
273 that word. If the line is empty, the words and prompt
274 are displayed again. If EOF is read, the command com-
275 pletes. Any other value read causes _
\bn_
\ba_
\bm_
\be to be set to
276 null. The line read is saved in the variable REPLY.
277 The _
\bl_
\bi_
\bs_
\bt is executed after each selection until a break
278 or return command is executed. The exit status of
279 select is the exit status of the last command executed
280 in _
\bl_
\bi_
\bs_
\bt, or zero if no commands were executed.
282 case _
\bw_
\bo_
\br_
\bd in [ _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn [ | _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn ] ... ) _
\bl_
\bi_
\bs_
\bt ;; ] ... esac
283 A case command first expands _
\bw_
\bo_
\br_
\bd, and tries to match
284 it against each _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn in turn, using the same match-
285 ing rules as for pathname expansion (see Pathname
286 Expansion below). When a match is found, the
287 corresponding _
\bl_
\bi_
\bs_
\bt is executed. After the first match,
288 no subsequent matches are attempted. The exit status
289 is zero if no patterns are matches. Otherwise, it is
290 the exit status of the last command executed in _
\bl_
\bi_
\bs_
\bt.
292 if _
\bl_
\bi_
\bs_
\bt then _
\bl_
\bi_
\bs_
\bt [ elif _
\bl_
\bi_
\bs_
\bt then _
\bl_
\bi_
\bs_
\bt ] ... [ else _
\bl_
\bi_
\bs_
\bt ] fi
293 The if _
\bl_
\bi_
\bs_
\bt is executed. If its exit status is zero,
294 the then _
\bl_
\bi_
\bs_
\bt is executed. Otherwise, each elif _
\bl_
\bi_
\bs_
\bt
295 is executed in turn, and if its exit status is zero,
296 the corresponding then _
\bl_
\bi_
\bs_
\bt is executed and the command
297 completes. Otherwise, the else _
\bl_
\bi_
\bs_
\bt is executed, if
298 present. The exit status is the exit status of the
299 last command executed, or zero if no condition tested
302 while _
\bl_
\bi_
\bs_
\bt do _
\bl_
\bi_
\bs_
\bt done
303 until _
\bl_
\bi_
\bs_
\bt do _
\bl_
\bi_
\bs_
\bt done
304 The while command continuously executes the do _
\bl_
\bi_
\bs_
\bt as
305 long as the last command in _
\bl_
\bi_
\bs_
\bt returns an exit status
306 of zero. The until command is identical to the while
307 command, except that the test is negated; the do _
\bl_
\bi_
\bs_
\bt
308 is executed as long as the last command in _
\bl_
\bi_
\bs_
\bt returns
309 a non-zero exit status. The exit status of the while
310 and until commands is the exit status of the last do
311 _
\bl_
\bi_
\bs_
\bt command executed, or zero if none was executed.
313 [ function ] _
\bn_
\ba_
\bm_
\be () { _
\bl_
\bi_
\bs_
\bt; }
314 This defines a function named _
\bn_
\ba_
\bm_
\be. The _
\bb_
\bo_
\bd_
\by of the
315 function is the _
\bl_
\bi_
\bs_
\bt of commands between { and }. This
316 list is executed whenever _
\bn_
\ba_
\bm_
\be is specified as the name
317 of a simple command. The exit status of a function is
318 the exit status of the last command executed in the
319 body. (See FUNCTIONS below.)
322 In a non-interactive shell, or an interactive shell in which
323 the -o interactive-comments option to the set builtin is
327 GNU Last change: 1995 May 5 5
334 BASH(1) USER COMMANDS BASH(1)
338 enabled, a word beginning with # causes that word and all
339 remaining characters on that line to be ignored. An
340 interactive shell without the -o interactive-comments option
341 enabled does not allow comments.
344 _
\bQ_
\bu_
\bo_
\bt_
\bi_
\bn_
\bg is used to remove the special meaning of certain
345 characters or words to the shell. Quoting can be used to
346 disable special treatment for special characters, to prevent
347 reserved words from being recognized as such, and to prevent
350 Each of the _
\bm_
\be_
\bt_
\ba_
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br_
\bs listed above under DEFINITIONS
351 has special meaning to the shell and must be quoted if they
352 are to represent themselves. There are three quoting
353 mechanisms: the _
\be_
\bs_
\bc_
\ba_
\bp_
\be _
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br, single quotes, and double
356 A non-quoted backslash (\) is the _
\be_
\bs_
\bc_
\ba_
\bp_
\be _
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br. It
357 preserves the literal value of the next character that fol-
358 lows, with the exception of <newline>. If a \<newline> pair
359 appears, and the backslash is not quoted, the \<newline> is
360 treated as a line continuation (that is, it is effectively
363 Enclosing characters in single quotes preserves the literal
364 value of each character within the quotes. A single quote
365 may not occur between single quotes, even when preceded by a
368 Enclosing characters in double quotes preserves the literal
369 value of all characters within the quotes, with the excep-
370 tion of $, `, and \. The characters $ and ` retain their
371 special meaning within double quotes. The backslash retains
372 its special meaning only when followed by one of the follow-
373 ing characters: $, `, ", \, or <newline>. A double quote
374 may be quoted within double quotes by preceding it with a
377 The special parameters * and @ have special meaning when in
378 double quotes (see PARAMETERS below).
381 A _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is an entity that stores values, somewhat like a
382 variable in a conventional programming language. It can be
383 a _
\bn_
\ba_
\bm_
\be, a number, or one of the special characters listed
384 below under Special Parameters. For the shell's purposes, a
385 _
\bv_
\ba_
\br_
\bi_
\ba_
\bb_
\bl_
\be is a parameter denoted by a _
\bn_
\ba_
\bm_
\be.
387 A parameter is set if it has been assigned a value. The
388 null string is a valid value. Once a variable is set, it
389 may be unset only by using the unset builtin command (see
393 GNU Last change: 1995 May 5 6
400 BASH(1) USER COMMANDS BASH(1)
404 SHELL BUILTIN COMMANDS below).
406 A _
\bv_
\ba_
\br_
\bi_
\ba_
\bb_
\bl_
\be may be assigned to by a statement of the form
408 _
\bn_
\ba_
\bm_
\be=[_
\bv_
\ba_
\bl_
\bu_
\be]
410 If _
\bv_
\ba_
\bl_
\bu_
\be is not given, the variable is assigned the null
411 string. All _
\bv_
\ba_
\bl_
\bu_
\be_
\bs undergo tilde expansion, parameter and
412 variable expansion, command substitution, arithmetic expan-
413 sion, and quote removal. If the variable has its -i attri-
414 bute set (see declare below in SHELL BUILTIN COMMANDS) then
415 _
\bv_
\ba_
\bl_
\bu_
\be is subject to arithmetic expansion even if the $[...]
416 syntax does not appear. Word splitting is not performed,
417 with the exception of "$@" as explained below under Special
418 Parameters. Pathname expansion is not performed.
420 Positional Parameters
421 A _
\bp_
\bo_
\bs_
\bi_
\bt_
\bi_
\bo_
\bn_
\ba_
\bl _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is a parameter denoted by one or more
422 digits, other than the single digit 0. Positional parame-
423 ters are assigned from the shell's arguments when it is
424 invoked, and may be reassigned using the set builtin com-
425 mand. Positional parameters may not be assigned to with
426 assignment statements. The positional parameters are tem-
427 porarily replaced when a shell function is executed (see
430 When a positional parameter consisting of more than a single
431 digit is expanded, it must be enclosed in braces (see EXPAN-
435 The shell treats several parameters specially. These param-
436 eters may only be referenced; assignment to them is not
438 * Expands to the positional parameters, starting from
439 one. When the expansion occurs within double quotes,
440 it expands to a single word with the value of each
441 parameter separated by the first character of the IFS
442 special variable. That is, ``$*'' is equivalent to
443 ``$1_
\bc$2_
\bc...'', where _
\bc is the first character of the
444 value of the IFS variable. If IFS is null or unset,
445 the parameters are separated by spaces.
446 @ Expands to the positional parameters, starting from
447 one. When the expansion occurs within double quotes,
448 each parameter expands as a separate word. That is, ``
449 $@'' is equivalent to ``$1'' ``$2'' ... When there are
450 no positional parameters, ``$@'' and $@ expand to noth-
451 ing (i.e., they are removed).
452 # Expands to the number of positional parameters in
454 ? Expands to the status of the most recently executed
459 GNU Last change: 1995 May 5 7
466 BASH(1) USER COMMANDS BASH(1)
470 - Expands to the current option flags as specified upon
471 invocation, by the set builtin command, or those set by
472 the shell itself (such as the -i flag).
473 $ Expands to the process ID of the shell. In a () sub-
474 shell, it expands to the process ID of the current
475 shell, not the subshell.
476 ! Expands to the process ID of the most recently executed
477 background (asynchronous) command.
478 0 Expands to the name of the shell or shell script. This
479 is set at shell initialization. If bash is invoked
480 with a file of commands, $0 is set to the name of that
481 file. If bash is started with the -c option, then $0
482 is set to the first argument after the string to be
483 executed, if one is present. Otherwise, it is set to
484 the pathname used to invoke bash, as given by argument
486 _ Expands to the last argument to the previous command,
487 after expansion. Also set to the full pathname of each
488 command executed and placed in the environment exported
492 The following variables are set by the shell:
494 PPID The process ID of the shell's parent.
495 PWD The current working directory as set by the cd command.
497 The previous working directory as set by the cd com-
500 Set to the line of input read by the read builtin com-
501 mand when no arguments are supplied.
502 UID Expands to the user ID of the current user, initialized
504 EUID Expands to the effective user ID of the current user,
505 initialized at shell startup.
506 BASH Expands to the full pathname used to invoke this
509 Expands to the version number of this instance of bash.
511 Incremented by one each time an instance of bash is
514 Each time this parameter is referenced, a random
515 integer is generated. The sequence of random numbers
516 may be initialized by assigning a value to RANDOM. If
517 RANDOM is unset, it loses its special properties, even
518 if it is subsequently reset.
520 Each time this parameter is referenced, the number of
521 seconds since shell invocation is returned. If a value
525 GNU Last change: 1995 May 5 8
532 BASH(1) USER COMMANDS BASH(1)
536 is assigned to SECONDS, the value returned upon subse-
537 quent references is the number of seconds since the
538 assignment plus the value assigned. If SECONDS is
539 unset, it loses its special properties, even if it is
542 Each time this parameter is referenced, the shell sub-
543 stitutes a decimal number representing the current
544 sequential line number (starting with 1) within a
545 script or function. When not in a script or function,
546 the value substituted is not guaranteed to be meaning-
547 ful. When in a function, the value is not the number
548 of the source line that the command appears on (that
549 information has been lost by the time the function is
550 executed), but is an approximation of the number of
551 _
\bs_
\bi_
\bm_
\bp_
\bl_
\be _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd_
\bs executed in the current function. If
552 LINENO is unset, it loses its special properties, even
553 if it is subsequently reset.
555 The history number, or index in the history list, of
556 the current command. If HISTCMD is unset, it loses its
557 special properties, even if it is subsequently reset.
559 The value of the last option argument processed by the
560 getopts builtin command (see SHELL BUILTIN COMMANDS
563 The index of the next argument to be processed by the
564 getopts builtin command (see SHELL BUILTIN COMMANDS
567 Automatically set to a string that uniquely describes
568 the type of machine on which bash is executing. The
569 default is system-dependent.
571 Automatically set to a string that describes the
572 operating system on which bash is executing. The
573 default is system-dependent.
575 The following variables are used by the shell. In some
576 cases, bash assigns a default value to a variable; these
577 cases are noted below.
579 IFS The _
\bI_
\bn_
\bt_
\be_
\br_
\bn_
\ba_
\bl _
\bF_
\bi_
\be_
\bl_
\bd _
\bS_
\be_
\bp_
\ba_
\br_
\ba_
\bt_
\bo_
\br that is used for word
580 splitting after expansion and to split lines into words
581 with the read builtin command. The default value is
582 ``<space><tab><newline>''.
583 PATH The search path for commands. It is a colon-separated
584 list of directories in which the shell looks for com-
585 mands (see COMMAND EXECUTION below). The default path
586 is system-dependent, and is set by the administrator
587 who installs bash. A common value is
591 GNU Last change: 1995 May 5 9
598 BASH(1) USER COMMANDS BASH(1)
602 ``/usr/gnu/bin:/usr/local/bin:/usr/ucb:/bin:/usr/bin:.''.
603 HOME The home directory of the current user; the default
604 argument for the cd builtin command.
606 The search path for the cd command. This is a colon-
607 separated list of directories in which the shell looks
608 for destination directories specified by the cd com-
609 mand. A sample value is ``.:~:/usr''.
610 ENV If this parameter is set when bash is executing a shell
611 script, its value is interpreted as a filename contain-
612 ing commands to initialize the shell, as in ._
\bb_
\ba_
\bs_
\bh_
\br_
\bc.
613 The value of ENV is subjected to parameter expansion,
614 command substitution, and arithmetic expansion before
615 being interpreted as a pathname. PATH is not used to
616 search for the resultant pathname.
617 MAIL If this parameter is set to a filename and the MAILPATH
618 variable is not set, bash informs the user of the
619 arrival of mail in the specified file.
621 Specifies how often (in seconds) bash checks for mail.
622 The default is 60 seconds. When it is time to check
623 for mail, the shell does so before prompting. If this
624 variable is unset, the shell disables mail checking.
626 A colon-separated list of pathnames to be checked for
627 mail. The message to be printed may be specified by
628 separating the pathname from the message with a `?'.
629 $_ stands for the name of the current mailfile. Exam-
631 MAILPATH='/usr/spool/mail/bfox?"You have
632 mail":~/shell-mail?"$_ has mail!"'
633 Bash supplies a default value for this variable, but
634 the location of the user mail files that it uses is
635 system dependent (e.g., /usr/spool/mail/$USER).
637 If set, and a file that bash is checking for mail has
638 been accessed since the last time it was checked, the
639 message ``The mail in _
\bm_
\ba_
\bi_
\bl_
\bf_
\bi_
\bl_
\be has been read'' is
641 PS1 The value of this parameter is expanded (see PROMPTING
642 below) and used as the primary prompt string. The
643 default value is ``bash\$ ''.
644 PS2 The value of this parameter is expanded and used as the
645 secondary prompt string. The default is ``> ''.
646 PS3 The value of this parameter is used as the prompt for
647 the _
\bs_
\be_
\bl_
\be_
\bc_
\bt command (see SHELL GRAMMAR above).
648 PS4 The value of this parameter is expanded and the value
649 is printed before each command bash displays during an
650 execution trace. The first character of PS4 is repli-
651 cated multiple times, as necessary, to indicate multi-
652 ple levels of indirection. The default is ``+ ''.
657 GNU Last change: 1995 May 5 10
664 BASH(1) USER COMMANDS BASH(1)
668 The number of commands to remember in the command his-
669 tory (see HISTORY below). The default value is 500.
671 The name of the file in which command history is saved.
672 (See HISTORY below.) The default value is
673 ~/._
\bb_
\ba_
\bs_
\bh__
\bh_
\bi_
\bs_
\bt_
\bo_
\br_
\by. If unset, the command history is not
674 saved when an interactive shell exits.
676 The maximum number of lines contained in the history
677 file. When this variable is assigned a value, the his-
678 tory file is truncated, if necessary, to contain no
679 more than that number of lines. The default value is
682 If set to the value 1, bash displays error messages
683 generated by the getopts builtin command (see SHELL
684 BUILTIN COMMANDS below). OPTERR is initialized to 1
685 each time the shell is invoked or a shell script is
688 If set, the value is executed as a command prior to
689 issuing each primary prompt.
691 Controls the action of the shell on receipt of an EOF
692 character as the sole input. If set, the value is the
693 number of consecutive EOF characters typed as the first
694 characters on an input line before bash exits. If the
695 variable exists but does not have a numeric value, or
696 has no value, the default value is 10. If it does not
697 exist, EOF signifies the end of input to the shell.
698 This is only in effect for interactive shells.
700 If set to a value greater than zero, the value is
701 interpreted as the number of seconds to wait for input
702 after issuing the primary prompt. Bash terminates
703 after waiting for that number of seconds if input does
706 The default editor for the fc builtin command.
708 A colon-separated list of suffixes to ignore when per-
709 forming filename completion (see READLINE below). A
710 filename whose suffix matches one of the entries in
711 FIGNORE is excluded from the list of matched filenames.
712 A sample value is ``.o:~''.
714 The filename for the readline startup file, overriding
715 the default of ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc (see READLINE below).
717 If set, bash reports terminated background jobs immedi-
718 ately, rather than waiting until before printing the
719 next primary prompt (see also the -b option to the set
723 GNU Last change: 1995 May 5 11
730 BASH(1) USER COMMANDS BASH(1)
737 If set to a value of _
\bi_
\bg_
\bn_
\bo_
\br_
\be_
\bs_
\bp_
\ba_
\bc_
\be, lines which begin
738 with a space character are not entered on the history
739 list. If set to a value of _
\bi_
\bg_
\bn_
\bo_
\br_
\be_
\bd_
\bu_
\bp_
\bs, lines matching
740 the last history line are not entered. A value of
741 _
\bi_
\bg_
\bn_
\bo_
\br_
\be_
\bb_
\bo_
\bt_
\bh combines the two options. If unset, or if
742 set to any other value than those above, all lines read
743 by the parser are saved on the history list.
745 command_oriented_history
746 If set, bash attempts to save all lines of a
747 multiple-line command in the same history entry. This
748 allows easy re-editing of multi-line commands.
751 If set, bash includes filenames beginning with a `.' in
752 the results of pathname expansion.
754 allow_null_glob_expansion
755 If set, bash allows pathname patterns which match no
756 files (see Pathname Expansion below) to expand to a
757 null string, rather than themselves.
760 The two or three characters which control history
761 expansion and tokenization (see HISTORY EXPANSION
762 below). The first character is the _
\bh_
\bi_
\bs_
\bt_
\bo_
\br_
\by _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn
763 _
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br, that is, the character which signals the
764 start of a history expansion, normally `!'. The second
765 character is the _
\bq_
\bu_
\bi_
\bc_
\bk _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn character, which is
766 used as shorthand for re-running the previous command
767 entered, substituting one string for another in the
768 command. The default is `^'. The optional third char-
769 acter is the character which signifies that the
770 remainder of the line is a comment, when found as the
771 first character of a word, normally `#'. The history
772 comment character causes history substitution to be
773 skipped for the remaining words on the line. It does
774 not necessarily cause the shell parser to treat the
775 rest of the line as a comment.
778 If set, the shell does not follow symbolic links when
779 executing commands that change the current working
780 directory. It uses the physical directory structure
781 instead. By default, bash follows the logical chain of
782 directories when performing commands which change the
783 current directory, such as cd. See also the descrip-
784 tion of the -P option to the set builtin ( SHELL BUIL-
789 GNU Last change: 1995 May 5 12
796 BASH(1) USER COMMANDS BASH(1)
800 hostname_completion_file
802 Contains the name of a file in the same format as
803 /_
\be_
\bt_
\bc/_
\bh_
\bo_
\bs_
\bt_
\bs that should be read when the shell needs to
804 complete a hostname. The file may be changed interac-
805 tively; the next time hostname completion is attempted
806 bash adds the contents of the new file to the already
810 If set, bash does not overwrite an existing file with
811 the >, >&, and <> redirection operators. This variable
812 may be overridden when creating output files by using
813 the redirection operator >| instead of > (see also the
814 -C option to the set builtin command).
817 This variable controls how the shell interacts with the
818 user and job control. If this variable is set, single
819 word simple commands without redirections are treated
820 as candidates for resumption of an existing stopped
821 job. There is no ambiguity allowed; if there is more
822 than one job beginning with the string typed, the job
823 most recently accessed is selected. The _
\bn_
\ba_
\bm_
\be of a
824 stopped job, in this context, is the command line used
825 to start it. If set to the value _
\be_
\bx_
\ba_
\bc_
\bt, the string
826 supplied must match the name of a stopped job exactly;
827 if set to _
\bs_
\bu_
\bb_
\bs_
\bt_
\br_
\bi_
\bn_
\bg, the string supplied needs to match
828 a substring of the name of a stopped job. The _
\bs_
\bu_
\bb_
\b-
829 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg value provides functionality analogous to the %?
830 job id (see JOB CONTROL below). If set to any other
831 value, the supplied string must be a prefix of a
832 stopped job's name; this provides functionality analo-
833 gous to the % job id.
835 no_exit_on_failed_exec
836 If this variable exists, a non-interactive shell will
837 not exit if it cannot execute the file specified in the
838 exec builtin command. An interactive shell does not
842 If this is set, an argument to the cd builtin command
843 that is not a directory is assumed to be the name of a
844 variable whose value is the directory to change to.
847 Expansion is performed on the command line after it has been
848 split into words. There are seven kinds of expansion per-
849 formed: _
\bb_
\br_
\ba_
\bc_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn, _
\bt_
\bi_
\bl_
\bd_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn, _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br _
\ba_
\bn_
\bd
850 _
\bv_
\ba_
\br_
\bi_
\ba_
\bb_
\bl_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn, _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn, _
\ba_
\br_
\bi_
\bt_
\bh_
\bm_
\be_
\bt_
\bi_
\bc _
\be_
\bx_
\bp_
\ba_
\bn_
\b-
851 _
\bs_
\bi_
\bo_
\bn, _
\bw_
\bo_
\br_
\bd _
\bs_
\bp_
\bl_
\bi_
\bt_
\bt_
\bi_
\bn_
\bg, and _
\bp_
\ba_
\bt_
\bh_
\bn_
\ba_
\bm_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn.
855 GNU Last change: 1995 May 5 13
862 BASH(1) USER COMMANDS BASH(1)
866 The order of expansions is: brace expansion, tilde expan-
867 sion, parameter, variable, command, and arithmetic substitu-
868 tion (done in a left-to-right fashion), word splitting, and
871 On systems that can support it, there is an additional
872 expansion available: _
\bp_
\br_
\bo_
\bc_
\be_
\bs_
\bs _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn.
874 Only brace expansion, word splitting, and pathname expansion
875 can change the number of words of the expansion; other
876 expansions expand a single word to a single word. The sin-
877 gle exception to this is the expansion of ``$@'' as
878 explained above (see PARAMETERS).
881 _
\bB_
\br_
\ba_
\bc_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn is a mechanism by which arbitrary strings
882 may be generated. This mechanism is similar to _
\bp_
\ba_
\bt_
\bh_
\bn_
\ba_
\bm_
\be
883 _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn, but the filenames generated need not exist. Pat-
884 terns to be brace expanded take the form of an optional
885 _
\bp_
\br_
\be_
\ba_
\bm_
\bb_
\bl_
\be, followed by a series of comma-separated strings
886 between a pair of braces, followed by an optional _
\bp_
\bo_
\bs_
\bt_
\ba_
\bm_
\bb_
\bl_
\be.
887 The preamble is prepended to each string contained within
888 the braces, and the postamble is then appended to each
889 resulting string, expanding left to right.
891 Brace expansions may be nested. The results of each
892 expanded string are not sorted; left to right order is
893 preserved. For example, a{d,c,b}e expands into `ade ace
896 Brace expansion is performed before any other expansions,
897 and any characters special to other expansions are preserved
898 in the result. It is strictly textual. Bash does not apply
899 any syntactic interpretation to the context of the expansion
900 or the text between the braces.
902 A correctly-formed brace expansion must contain unquoted
903 opening and closing braces, and at least one unquoted comma.
904 Any incorrectly formed brace expansion is left unchanged.
906 This construct is typically used as shorthand when the com-
907 mon prefix of the strings to be generated is longer than in
910 mkdir /usr/local/src/bash/{old,new,dist,bugs}
912 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
914 Brace expansion introduces a slight incompatibility with
915 traditional versions of sh, the Bourne shell. sh does not
916 treat opening or closing braces specially when they appear
917 as part of a word, and preserves them in the output. Bash
921 GNU Last change: 1995 May 5 14
928 BASH(1) USER COMMANDS BASH(1)
932 removes braces from words as a consequence of brace expan-
933 sion. For example, a word entered to sh as _
\bf_
\bi_
\bl_
\be{_
\b1,_
\b2}
934 appears identically in the output. The same word is output
935 as _
\bf_
\bi_
\bl_
\be_
\b1 _
\bf_
\bi_
\bl_
\be_
\b2 after expansion by bash. If strict compati-
936 bility with sh is desired, start bash with the -nobraceex-
937 pansion flag (see OPTIONS above) or disable brace expansion
938 with the +o braceexpand option to the set command (see SHELL
939 BUILTIN COMMANDS below).
942 If a word begins with a tilde character (`~'), all of the
943 characters preceding the first slash (or all characters, if
944 there is no slash) are treated as a possible _
\bl_
\bo_
\bg_
\bi_
\bn _
\bn_
\ba_
\bm_
\be. If
945 this _
\bl_
\bo_
\bg_
\bi_
\bn _
\bn_
\ba_
\bm_
\be is the null string, the tilde is replaced
946 with the value of the parameter HOME. If HOME is unset, the
947 home directory of the user executing the shell is substi-
950 If a `+' follows the tilde, the value of PWD replaces the
951 tilde and `+'. If a `-' follows, the value of OLDPWD is
952 substituted. If the value following the tilde is a valid
953 _
\bl_
\bo_
\bg_
\bi_
\bn _
\bn_
\ba_
\bm_
\be, the tilde and _
\bl_
\bo_
\bg_
\bi_
\bn _
\bn_
\ba_
\bm_
\be are replaced with the
954 home directory associated with that name. If the name is
955 invalid, or the tilde expansion fails, the word is
958 Each variable assignment is checked for unquoted instances
959 of tildes following a : or =. In these cases, tilde substi-
960 tution is also performed. Consequently, one may use path-
961 names with tildes in assignments to PATH, MAILPATH, and
962 CDPATH, and the shell assigns the expanded value.
965 The `$' character introduces parameter expansion, command
966 substitution, or arithmetic expansion. The parameter name
967 or symbol to be expanded may be enclosed in braces, which
968 are optional but serve to protect the variable to be
969 expanded from characters immediately following it which
970 could be interpreted as part of the name.
972 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br}
973 The value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is substituted. The braces are
974 required when _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is a positional parameter with
975 more than one digit, or when _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is followed by a
976 character which is not to be interpreted as part of its
979 In each of the cases below, _
\bw_
\bo_
\br_
\bd is subject to tilde expan-
980 sion, parameter expansion, command substitution, and arith-
981 metic expansion. Bash tests for a parameter that is unset
982 or null; omitting the colon results in a test only for a
983 parameter that is unset.
987 GNU Last change: 1995 May 5 15
994 BASH(1) USER COMMANDS BASH(1)
998 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br:-_
\bw_
\bo_
\br_
\bd}
999 Use Default Values. If _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is unset or null, the
1000 expansion of _
\bw_
\bo_
\br_
\bd is substituted. Otherwise, the value
1001 of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is substituted.
1002 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br:=_
\bw_
\bo_
\br_
\bd}
1003 Assign Default Values. If _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is unset or null,
1004 the expansion of _
\bw_
\bo_
\br_
\bd is assigned to _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br. The
1005 value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is then substituted. Positional
1006 parameters and special parameters may not be assigned
1008 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br:?_
\bw_
\bo_
\br_
\bd}
1009 Display Error if Null or Unset. If _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is null
1010 or unset, the expansion of _
\bw_
\bo_
\br_
\bd (or a message to that
1011 effect if _
\bw_
\bo_
\br_
\bd is not present) is written to the stan-
1012 dard error and the shell, if it is not interactive,
1013 exits. Otherwise, the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is substi-
1015 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br:+_
\bw_
\bo_
\br_
\bd}
1016 Use Alternate Value. If _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is null or unset,
1017 nothing is substituted, otherwise the expansion of _
\bw_
\bo_
\br_
\bd
1019 ${#_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br}
1020 The length in characters of the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is
1021 substituted. If _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br is * or @, the length sub-
1022 stituted is the length of * expanded within double
1024 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br#_
\bw_
\bo_
\br_
\bd}
1025 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br##_
\bw_
\bo_
\br_
\bd}
1026 The _
\bw_
\bo_
\br_
\bd is expanded to produce a pattern just as in
1027 pathname expansion. If the pattern matches the begin-
1028 ning of the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br, then the expansion is
1029 the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br with the shortest matching pat-
1030 tern deleted (the ``#'' case) or the longest matching
1031 pattern deleted (the ``##'' case).
1033 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br%_
\bw_
\bo_
\br_
\bd}
1034 ${_
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br%%_
\bw_
\bo_
\br_
\bd}
1035 The _
\bw_
\bo_
\br_
\bd is expanded to produce a pattern just as in
1036 pathname expansion. If the pattern matches a trailing
1037 portion of the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br, then the expansion
1038 is the value of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br with the shortest matching
1039 pattern deleted (the ``%'' case) or the longest match-
1040 ing pattern deleted (the ``%%'' case).
1042 Command Substitution
1043 _
\bC_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn allows the output of a command to
1044 replace the command name. There are two forms:
1046 $(_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd)
1048 `_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd`
1053 GNU Last change: 1995 May 5 16
1060 BASH(1) USER COMMANDS BASH(1)
1064 Bash performs the expansion by executing _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd and replac-
1065 ing the command substitution with the standard output of the
1066 command, with any trailing newlines deleted.
1068 When the old-style backquote form of substitution is used,
1069 backslash retains its literal meaning except when followed
1070 by $, `, or \. When using the $(_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd) form, all charac-
1071 ters between the parentheses make up the command; none are
1074 Command substitutions may be nested. To nest when using the
1075 old form, escape the inner backquotes with backslashes.
1077 If the substitution appears within double quotes, word
1078 splitting and pathname expansion are not performed on the
1081 Arithmetic Expansion
1082 Arithmetic expansion allows the evaluation of an arithmetic
1083 expression and the substitution of the result. There are
1084 two formats for arithmetic expansion:
1086 $[_
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn]
1088 $((_
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn))
1090 The _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn is treated as if it were within double
1091 quotes, but a double quote inside the braces or parentheses
1092 is not treated specially. All tokens in the expression
1093 undergo parameter expansion, command substitution, and quote
1094 removal. Arithmetic substitutions may be nested.
1096 The evaluation is performed according to the rules listed
1097 below under ARITHMETIC EVALUATION. If _
\be_
\bx_
\bp_
\br_
\be_
\bs_
\bs_
\bi_
\bo_
\bn is
1098 invalid, bash prints a message indicating failure and no
1099 substitution occurs.
1101 Process Substitution
1102 _
\bP_
\br_
\bo_
\bc_
\be_
\bs_
\bs _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn is supported on systems that support
1103 named pipes (_
\bF_
\bI_
\bF_
\bO_
\bs) or the /dev/fd method of naming open
1104 files. It takes the form of <(_
\bl_
\bi_
\bs_
\bt) or >(_
\bl_
\bi_
\bs_
\bt). The pro-
1105 cess _
\bl_
\bi_
\bs_
\bt is run with its input or output connected to a
1106 _
\bF_
\bI_
\bF_
\bO or some file in /dev/fd. The name of this file is
1107 passed as an argument to the current command as the result
1108 of the expansion. If the >(_
\bl_
\bi_
\bs_
\bt) form is used, writing to
1109 the file will provide input for _
\bl_
\bi_
\bs_
\bt. If the <(_
\bl_
\bi_
\bs_
\bt) form
1110 is used, the file passed as an argument should be read to
1111 obtain the output of _
\bl_
\bi_
\bs_
\bt.
1113 On systems that support it, _
\bp_
\br_
\bo_
\bc_
\be_
\bs_
\bs _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn is per-
1114 formed simultaneously with _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br _
\ba_
\bn_
\bd _
\bv_
\ba_
\br_
\bi_
\ba_
\bb_
\bl_
\be _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn,
1115 _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd _
\bs_
\bu_
\bb_
\bs_
\bt_
\bi_
\bt_
\bu_
\bt_
\bi_
\bo_
\bn, and _
\ba_
\br_
\bi_
\bt_
\bh_
\bm_
\be_
\bt_
\bi_
\bc _
\be_
\bx_
\bp_
\ba_
\bn_
\bs_
\bi_
\bo_
\bn.
1119 GNU Last change: 1995 May 5 17
1126 BASH(1) USER COMMANDS BASH(1)
1131 The shell scans the results of parameter expansion, command
1132 substitution, and arithmetic expansion that did not occur
1133 within double quotes for _
\bw_
\bo_
\br_
\bd _
\bs_
\bp_
\bl_
\bi_
\bt_
\bt_
\bi_
\bn_
\bg.
1135 The shell treats each character of IFS as a delimiter, and
1136 splits the results of the other expansions into words on
1137 these characters. If the value of IFS is exactly
1138 <space><tab><newline>, the default, then any sequence of IFS
1139 characters serves to delimit words. If IFS has a value
1140 other than the default, then sequences of the whitespace
1141 characters space and tab are ignored at the beginning and
1142 end of the word, as long as the whitespace character is in
1143 the value of IFS (an IFS whitespace character). Any charac-
1144 ter in IFS that is not IFS whitespace, along with any adja-
1145 cent IFS whitespace characters, delimits a field. A
1146 sequence of IFS whitespace characters is also treated as a
1147 delimiter. If the value of IFS is null, no word splitting
1148 occurs. IFS cannot be unset.
1150 Explicit null arguments ("" or '') are retained. Implicit
1151 null arguments, resulting from the expansion of _
\bp_
\ba_
\br_
\ba_
\bm_
\be_
\bt_
\be_
\br_
\bs
1152 that have no values, are removed.
1154 Note that if no expansion occurs, no splitting is performed.
1157 After word splitting, unless the -f option has been set,
1158 bash scans each _
\bw_
\bo_
\br_
\bd for the characters *, ?, and [. If one
1159 of these characters appears, then the word is regarded as a
1160 _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn, and replaced with an alphabetically sorted list of
1161 pathnames matching the pattern. If no matching pathnames
1162 are found, and the shell variable allow_null_glob_expansion
1163 is unset, the word is left unchanged. If the variable is
1164 set, and no matches are found, the word is removed. When a
1165 pattern is used for pathname generation, the character ``.''
1166 at the start of a name or immediately following a slash must
1167 be matched explicitly, unless the shell variable
1168 glob_dot_filenames is set. The slash character must always
1169 be matched explicitly. In other cases, the ``.'' character
1170 is not treated specially.
1172 The special pattern characters have the following meanings:
1174 * Matches any string, including the null string.
1175 ? Matches any single character.
1177 Matches any one of the enclosed characters. A pair of
1178 characters separated by a minus sign denotes a _
\br_
\ba_
\bn_
\bg_
\be;
1179 any character lexically between those two characters,
1180 inclusive, is matched. If the first character follow-
1181 ing the [ is a ! or a ^ then any character not enclosed
1185 GNU Last change: 1995 May 5 18
1192 BASH(1) USER COMMANDS BASH(1)
1196 is matched. A - or ] may be matched by including it as
1197 the first or last character in the set.
1200 After the preceding expansions, all unquoted occurrences of
1201 the characters \, `, and " are removed.
1204 Before a command is executed, its input and output may be
1205 _
\br_
\be_
\bd_
\bi_
\br_
\be_
\bc_
\bt_
\be_
\bd using a special notation interpreted by the
1206 shell. Redirection may also be used to open and close files
1207 for the current shell execution environment. The following
1208 redirection operators may precede or appear anywhere within
1209 a _
\bs_
\bi_
\bm_
\bp_
\bl_
\be _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd or may follow a _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd. Redirections are
1210 processed in the order they appear, from left to right.
1212 In the following descriptions, if the file descriptor number
1213 is omitted, and the first character of the redirection
1214 operator is <, the redirection refers to the standard input
1215 (file descriptor 0). If the first character of the redirec-
1216 tion operator is >, the redirection refers to the standard
1217 output (file descriptor 1).
1219 The word that follows the redirection operator in the fol-
1220 lowing descriptions is subjected to brace expansion, tilde
1221 expansion, parameter expansion, command substitution, arith-
1222 metic expansion, quote removal, and pathname expansion. If
1223 it expands to more than one word, bash reports an error.
1225 Note that the order of redirections is significant. For
1226 example, the command
1230 directs both standard output and standard error to the file
1231 _
\bd_
\bi_
\br_
\bl_
\bi_
\bs_
\bt, while the command
1235 directs only the standard output to file _
\bd_
\bi_
\br_
\bl_
\bi_
\bs_
\bt, because
1236 the standard error was duplicated as standard output before
1237 the standard output was redirected to _
\bd_
\bi_
\br_
\bl_
\bi_
\bs_
\bt.
1240 Redirection of input causes the file whose name results from
1241 the expansion of _
\bw_
\bo_
\br_
\bd to be opened for reading on file
1242 descriptor _
\bn, or the standard input (file descriptor 0) if _
\bn
1245 The general format for redirecting input is:
1251 GNU Last change: 1995 May 5 19
1258 BASH(1) USER COMMANDS BASH(1)
1262 [_
\bn]<_
\bw_
\bo_
\br_
\bd
1265 Redirection of output causes the file whose name results
1266 from the expansion of _
\bw_
\bo_
\br_
\bd to be opened for writing on file
1267 descriptor _
\bn, or the standard output (file descriptor 1) if
1268 _
\bn is not specified. If the file does not exist it is
1269 created; if it does exist it is truncated to zero size.
1271 The general format for redirecting output is:
1273 [_
\bn]>_
\bw_
\bo_
\br_
\bd
1275 If the redirection operator is >|, then the value of the -C
1276 option to the set builtin command is not tested, and file
1277 creation is attempted. (See also the description of
1278 noclobber under Shell Variables above.)
1280 Appending Redirected Output
1281 Redirection of output in this fashion causes the file whose
1282 name results from the expansion of _
\bw_
\bo_
\br_
\bd to be opened for
1283 appending on file descriptor _
\bn, or the standard output (file
1284 descriptor 1) if _
\bn is not specified. If the file does not
1285 exist it is created.
1287 The general format for appending output is:
1289 [_
\bn]>>_
\bw_
\bo_
\br_
\bd
1291 Redirecting Standard Output and Standard Error
1292 Bash allows both the standard output (file descriptor 1) and
1293 the standard error output (file descriptor 2) to be
1294 redirected to the file whose name is the expansion of _
\bw_
\bo_
\br_
\bd
1295 with this construct.
1297 There are two formats for redirecting standard output and
1304 Of the two forms, the first is preferred. This is semanti-
1307 >_
\bw_
\bo_
\br_
\bd 2>&1
1310 This type of redirection instructs the shell to read input
1311 from the current source until a line containing only _
\bw_
\bo_
\br_
\bd
1312 (with no trailing blanks) is seen. All of the lines read up
1313 to that point are then used as the standard input for a
1317 GNU Last change: 1995 May 5 20
1324 BASH(1) USER COMMANDS BASH(1)
1330 The format of here-documents is as follows:
1332 <<[-]_
\bw_
\bo_
\br_
\bd
1333 _
\bh_
\be_
\br_
\be-_
\bd_
\bo_
\bc_
\bu_
\bm_
\be_
\bn_
\bt
1334 _
\bd_
\be_
\bl_
\bi_
\bm_
\bi_
\bt_
\be_
\br
1336 No parameter expansion, command substitution, pathname
1337 expansion, or arithmetic expansion is performed on _
\bw_
\bo_
\br_
\bd. If
1338 any characters in _
\bw_
\bo_
\br_
\bd are quoted, the _
\bd_
\be_
\bl_
\bi_
\bm_
\bi_
\bt_
\be_
\br is the
1339 result of quote removal on _
\bw_
\bo_
\br_
\bd, and the lines in the here-
1340 document are not expanded. Otherwise, all lines of the
1341 here-document are subjected to parameter expansion, command
1342 substitution, and arithmetic expansion. In the latter case,
1343 the pair \<newline> is ignored, and \ must be used to quote
1344 the characters \, $, and `.
1346 If the redirection operator is <<-, then all leading tab
1347 characters are stripped from input lines and the line con-
1348 taining _
\bd_
\be_
\bl_
\bi_
\bm_
\bi_
\bt_
\be_
\br. This allows here-documents within shell
1349 scripts to be indented in a natural fashion.
1351 Duplicating File Descriptors
1352 The redirection operator
1354 [_
\bn]<&_
\bw_
\bo_
\br_
\bd
1356 is used to duplicate input file descriptors. If _
\bw_
\bo_
\br_
\bd
1357 expands to one or more digits, the file descriptor denoted
1358 by _
\bn is made to be a copy of that file descriptor. If _
\bw_
\bo_
\br_
\bd
1359 evaluates to -, file descriptor _
\bn is closed. If _
\bn is not
1360 specified, the standard input (file descriptor 0) is used.
1364 [_
\bn]>&_
\bw_
\bo_
\br_
\bd
1366 is used similarly to duplicate output file descriptors. If
1367 _
\bn is not specified, the standard output (file descriptor 1)
1368 is used. As a special case, if _
\bn is omitted, and _
\bw_
\bo_
\br_
\bd does
1369 not expand to one or more digits, the standard output and
1370 standard error are redirected as described previously.
1372 Opening File Descriptors for Reading and Writing
1373 The redirection operator
1375 [_
\bn]<>_
\bw_
\bo_
\br_
\bd
1377 causes the file whose name is the expansion of _
\bw_
\bo_
\br_
\bd to be
1378 opened for both reading and writing on file descriptor _
\bn, or
1379 as the standard input and standard output if _
\bn is not
1383 GNU Last change: 1995 May 5 21
1390 BASH(1) USER COMMANDS BASH(1)
1394 specified. If the file does not exist, it is created.
1397 A shell function, defined as described above under SHELL
1398 GRAMMAR, stores a series of commands for later execution.
1399 Functions are executed in the context of the current shell;
1400 no new process is created to interpret them (contrast this
1401 with the execution of a shell script). When a function is
1402 executed, the arguments to the function become the posi-
1403 tional parameters during its execution. The special parame-
1404 ter # is updated to reflect the change. Positional parame-
1407 Variables local to the function may be declared with the
1408 local builtin command. Ordinarily, variables and their
1409 values are shared between the function and its caller.
1411 If the builtin command return is executed in a function, the
1412 function completes and execution resumes with the next com-
1413 mand after the function call. When a function completes,
1414 the values of the positional parameters and the special
1415 parameter # are restored to the values they had prior to
1418 Function names and definitions may be listed with the -f
1419 option to the declare or typeset builtin commands. Func-
1420 tions may be exported so that subshells automatically have
1421 them defined with the -f option to the export builtin.
1423 Functions may be recursive. No limit is imposed on the
1424 number of recursive calls.
1427 The shell maintains a list of _
\ba_
\bl_
\bi_
\ba_
\bs_
\be_
\bs that may be set and
1428 unset with the alias and unalias builtin commands (see SHELL
1429 BUILTIN COMMANDS below). The first word of each command, if
1430 unquoted, is checked to see if it has an alias. If so, that
1431 word is replaced by the text of the alias. The alias name
1432 and the replacement text may contain any valid shell input,
1433 including the _
\bm_
\be_
\bt_
\ba_
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br_
\bs listed above, with the excep-
1434 tion that the alias name may not contain =. The first word
1435 of the replacement text is tested for aliases, but a word
1436 that is identical to an alias being expanded is not expanded
1437 a second time. This means that one may alias ls to ls -F,
1438 for instance, and bash does not try to recursively expand
1439 the replacement text. If the last character of the alias
1440 value is a _
\bb_
\bl_
\ba_
\bn_
\bk, then the next command word following the
1441 alias is also checked for alias expansion.
1443 Aliases are created and listed with the alias command, and
1444 removed with the unalias command.
1449 GNU Last change: 1995 May 5 22
1456 BASH(1) USER COMMANDS BASH(1)
1460 There is no mechanism for using arguments in the replacement
1461 text, as in csh. If arguments are needed, a shell function
1464 Aliases are not expanded when the shell is not interactive.
1466 The rules concerning the definition and use of aliases are
1467 somewhat confusing. Bash always reads at least one complete
1468 line of input before executing any of the commands on that
1469 line. Aliases are expanded when a command is read, not when
1470 it is executed. Therefore, an alias definition appearing on
1471 the same line as another command does not take effect until
1472 the next line of input is read. This means that the com-
1473 mands following the alias definition on that line are not
1474 affected by the new alias. This behavior is also an issue
1475 when functions are executed. Aliases are expanded when the
1476 function definition is read, not when the function is exe-
1477 cuted, because a function definition is itself a compound
1478 command. As a consequence, aliases defined in a function
1479 are not available until after that function is executed. To
1480 be safe, always put alias definitions on a separate line,
1481 and do not use alias in compound commands.
1483 Note that for almost every purpose, aliases are superseded
1487 _
\bJ_
\bo_
\bb _
\bc_
\bo_
\bn_
\bt_
\br_
\bo_
\bl refers to the ability to selectively stop
1488 (_
\bs_
\bu_
\bs_
\bp_
\be_
\bn_
\bd) the execution of processes and continue (_
\br_
\be_
\bs_
\bu_
\bm_
\be)
1489 their execution at a later point. A user typically employs
1490 this facility via an interactive interface supplied jointly
1491 by the system's terminal driver and bash.
1493 The shell associates a _
\bj_
\bo_
\bb with each pipeline. It keeps a
1494 table of currently executing jobs, which may be listed with
1495 the jobs command. When bash starts a job asynchronously (in
1496 the _
\bb_
\ba_
\bc_
\bk_
\bg_
\br_
\bo_
\bu_
\bn_
\bd), it prints a line that looks like:
1500 indicating that this job is job number 1 and that the pro-
1501 cess ID of the last process in the pipeline associated with
1502 this job is 25647. All of the processes in a single pipe-
1503 line are members of the same job. Bash uses the _
\bj_
\bo_
\bb
1504 abstraction as the basis for job control.
1506 To facilitate the implementation of the user interface to
1507 job control, the system maintains the notion of a _
\bc_
\bu_
\br_
\br_
\be_
\bn_
\bt
1508 _
\bt_
\be_
\br_
\bm_
\bi_
\bn_
\ba_
\bl _
\bp_
\br_
\bo_
\bc_
\be_
\bs_
\bs _
\bg_
\br_
\bo_
\bu_
\bp _
\bI_
\bD. Members of this process group
1509 (processes whose process group ID is equal to the current
1510 terminal process group ID) receive keyboard-generated sig-
1511 nals such as SIGINT. These processes are said to be in the
1515 GNU Last change: 1995 May 5 23
1522 BASH(1) USER COMMANDS BASH(1)
1526 _
\bf_
\bo_
\br_
\be_
\bg_
\br_
\bo_
\bu_
\bn_
\bd. _
\bB_
\ba_
\bc_
\bk_
\bg_
\br_
\bo_
\bu_
\bn_
\bd processes are those whose process
1527 group ID differs from the terminal's; such processes are
1528 immune to keyboard-generated signals. Only foreground
1529 processes are allowed to read from or write to the terminal.
1530 Background processes which attempt to read from (write to)
1531 the terminal are sent a SIGTTIN (SIGTTOU) signal by the ter-
1532 minal driver, which, unless caught, suspends the process.
1534 If the operating system on which bash is running supports
1535 job control, bash allows you to use it. Typing the _
\bs_
\bu_
\bs_
\bp_
\be_
\bn_
\bd
1536 character (typically ^Z, Control-Z) while a process is run-
1537 ning causes that process to be stopped and returns you to
1538 bash. Typing the _
\bd_
\be_
\bl_
\ba_
\by_
\be_
\bd _
\bs_
\bu_
\bs_
\bp_
\be_
\bn_
\bd character (typically ^Y,
1539 Control-Y) causes the process to be stopped when it attempts
1540 to read input from the terminal, and control to be returned
1541 to bash. You may then manipulate the state of this job,
1542 using the bg command to continue it in the background, the
1543 fg command to continue it in the foreground, or the kill
1544 command to kill it. A ^Z takes effect immediately, and has
1545 the additional side effect of causing pending output and
1546 typeahead to be discarded.
1548 There are a number of ways to refer to a job in the shell.
1549 The character % introduces a job name. Job number _
\bn may be
1550 referred to as %n. A job may also be referred to using a
1551 prefix of the name used to start it, or using a substring
1552 that appears in its command line. For example, %ce refers
1553 to a stopped ce job. If a prefix matches more than one job,
1554 bash reports an error. Using %?ce, on the other hand,
1555 refers to any job containing the string ce in its command
1556 line. If the substring matches more than one job, bash
1557 reports an error. The symbols %% and %+ refer to the
1558 shell's notion of the _
\bc_
\bu_
\br_
\br_
\be_
\bn_
\bt _
\bj_
\bo_
\bb, which is the last job
1559 stopped while it was in the foreground. The _
\bp_
\br_
\be_
\bv_
\bi_
\bo_
\bu_
\bs _
\bj_
\bo_
\bb
1560 may be referenced using %-. In output pertaining to jobs
1561 (e.g., the output of the jobs command), the current job is
1562 always flagged with a +, and the previous job with a -.
1564 Simply naming a job can be used to bring it into the fore-
1565 ground: %1 is a synonym for ``fg %1'', bringing job 1 from
1566 the background into the foreground. Similarly, ``%1 &''
1567 resumes job 1 in the background, equivalent to ``bg %1''.
1569 The shell learns immediately whenever a job changes state.
1570 Normally, bash waits until it is about to print a prompt
1571 before reporting changes in a job's status so as to not
1572 interrupt any other output. If the -b option to the set
1573 builtin command is set, bash reports such changes immedi-
1574 ately. (See also the description of notify variable under
1575 Shell Variables above.)
1581 GNU Last change: 1995 May 5 24
1588 BASH(1) USER COMMANDS BASH(1)
1592 If you attempt to exit bash while jobs are stopped, the
1593 shell prints a message warning you. You may then use the
1594 jobs command to inspect their status. If you do this, or
1595 try to exit again immediately, you are not warned again, and
1596 the stopped jobs are terminated.
1599 When bash is interactive, it ignores SIGTERM (so that kill 0
1600 does not kill an interactive shell), and SIGINT is caught
1601 and handled (so that the wait builtin is interruptible). In
1602 all cases, bash ignores SIGQUIT. If job control is in
1603 effect, bash ignores SIGTTIN, SIGTTOU, and SIGTSTP.
1605 Synchronous jobs started by bash have signals set to the
1606 values inherited by the shell from its parent. When job
1607 control is not in effect, background jobs (jobs started with
1608 &) ignore SIGINT and SIGQUIT. Commands run as a result of
1609 command substitution ignore the keyboard-generated job con-
1610 trol signals SIGTTIN, SIGTTOU, and SIGTSTP.
1613 After a command has been split into words, if it results in
1614 a simple command and an optional list of arguments, the fol-
1615 lowing actions are taken.
1617 If the command name contains no slashes, the shell attempts
1618 to locate it. If there exists a shell function by that
1619 name, that function is invoked as described above in FUNC-
1620 TIONS. If the name does not match a function, the shell
1621 searches for it in the list of shell builtins. If a match
1622 is found, that builtin is invoked.
1624 If the name is neither a shell function nor a builtin, and
1625 contains no slashes, bash searches each element of the PATH
1626 for a directory containing an executable file by that name.
1627 If the search is unsuccessful, the shell prints an error
1628 message and returns a nonzero exit status.
1630 If the search is successful, or if the command name contains
1631 one or more slashes, the shell executes the named program.
1632 Argument 0 is set to the name given, and the remaining argu-
1633 ments to the command are set to the arguments given, if any.
1635 If this execution fails because the file is not in execut-
1636 able format, and the file is not a directory, it is assumed
1637 to be a _
\bs_
\bh_
\be_
\bl_
\bl _
\bs_
\bc_
\br_
\bi_
\bp_
\bt, a file containing shell commands. A
1638 subshell is spawned to execute it. This subshell reinitial-
1639 izes itself, so that the effect is as if a new shell had
1640 been invoked to handle the script, with the exception that
1641 the locations of commands remembered by the parent (see hash
1642 below under SHELL BUILTIN COMMANDS) are retained by the
1647 GNU Last change: 1995 May 5 25
1654 BASH(1) USER COMMANDS BASH(1)
1658 If the program is a file beginning with #!, the remainder of
1659 the first line specifies an interpreter for the program.
1660 The shell executes the specified interpreter on operating
1661 systems that do not handle this executable format them-
1662 selves. The arguments to the interpreter consist of a sin-
1663 gle optional argument following the interpreter name on the
1664 first line of the program, followed by the name of the pro-
1665 gram, followed by the command arguments, if any.
1668 When a program is invoked it is given an array of strings
1669 called the _
\be_
\bn_
\bv_
\bi_
\br_
\bo_
\bn_
\bm_
\be_
\bn_
\bt. This is a list of _
\bn_
\ba_
\bm_
\be-_
\bv_
\ba_
\bl_
\bu_
\be pairs,
1670 of the form _
\bn_
\ba_
\bm_
\be=_
\bv_
\ba_
\bl_
\bu_
\be.
1672 The shell allows you to manipulate the environment in
1673 several ways. On invocation, the shell scans its own
1674 environment and creates a parameter for each name found,
1675 automatically marking it for _
\be_
\bx_
\bp_
\bo_
\br_
\bt to child processes.
1676 Executed commands inherit the environment. The export and
1677 declare -x commands allow parameters and functions to be
1678 added to and deleted from the environment. If the value of
1679 a parameter in the environment is modified, the new value
1680 becomes part of the environment, replacing the old. The
1681 environment inherited by any executed command consists of
1682 the shell's initial environment, whose values may be modi-
1683 fied in the shell, less any pairs removed by the unset com-
1684 mand, plus any additions via the export and declare -x com-
1687 The environment for any _
\bs_
\bi_
\bm_
\bp_
\bl_
\be _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd or function may be
1688 augmented temporarily by prefixing it with parameter assign-
1689 ments, as described above in PARAMETERS. These assignment
1690 statements affect only the environment seen by that command.
1692 If the -k flag is set (see the set builtin command below),
1693 then _
\ba_
\bl_
\bl parameter assignments are placed in the environment
1694 for a command, not just those that precede the command name.
1696 When bash invokes an external command, the variable _ is set
1697 to the full path name of the command and passed to that com-
1698 mand in its environment.
1701 For the purposes of the shell, a command which exits with a
1702 zero exit status has succeeded. An exit status of zero
1703 indicates success. A non-zero exit status indicates
1704 failure. When a command terminates on a fatal signal, bash
1705 uses the value of 128+signal as the exit status.
1707 If a command is not found, the child process created to exe-
1708 cute it returns a status of 127. If a command is found but
1709 is not executable, the return status is 126.
1713 GNU Last change: 1995 May 5 26
1720 BASH(1) USER COMMANDS BASH(1)
1724 Bash itself returns the exit status of the last command exe-
1725 cuted, unless a syntax error occurs, in which case it exits
1726 with a non-zero value. See also the exit builtin command
1730 When executing interactively, bash displays the primary
1731 prompt PS1 when it is ready to read a command, and the
1732 secondary prompt PS2 when it needs more input to complete a
1733 command. Bash allows these prompt strings to be customized
1734 by inserting a number of backslash-escaped special charac-
1735 ters that are decoded as follows:
1736 \t the current time in HH:MM:SS format
1737 \d the date in "Weekday Month Date" format (e.g.,
1740 \s the name of the shell, the basename of $0 (the
1741 portion following the final slash)
1742 \w the current working directory
1743 \W the basename of the current working directory
1744 \u the username of the current user
1746 \# the command number of this command
1747 \! the history number of this command
1748 \$ if the effective UID is 0, a #, otherwise a $
1749 \nnn the character corresponding to the octal number
1752 \[ begin a sequence of non-printing characters, which
1753 could be used to embed a terminal control sequence
1755 \] end a sequence of non-printing characters
1757 The command number and the history number are usually dif-
1758 ferent: the history number of a command is its position in
1759 the history list, which may include commands restored from
1760 the history file (see HISTORY below), while the command
1761 number is the position in the sequence of commands executed
1762 during the current shell session. After the string is
1763 decoded, it is expanded via parameter expansion, command
1764 substitution, arithmetic expansion, and word splitting.
1767 This is the library that handles reading input when using an
1768 interactive shell, unless the -nolineediting option is
1769 given. By default, the line editing commands are similar to
1770 those of emacs. A vi-style line editing interface is also
1773 In this section, the emacs-style notation is used to denote
1774 keystrokes. Control keys are denoted by C-_
\bk_
\be_
\by, e.g., C-n
1775 means Control-N. Similarly, _
\bm_
\be_
\bt_
\ba keys are denoted by M-_
\bk_
\be_
\by,
1779 GNU Last change: 1995 May 5 27
1786 BASH(1) USER COMMANDS BASH(1)
1790 so M-x means Meta-X. (On keyboards without a _
\bm_
\be_
\bt_
\ba key, M-_
\bx
1791 means ESC _
\bx, i.e., press the Escape key then the _
\bx key.
1792 This makes ESC the _
\bm_
\be_
\bt_
\ba _
\bp_
\br_
\be_
\bf_
\bi_
\bx. The combination M-C-_
\bx means
1793 ESC-Control-_
\bx, or press the Escape key then hold the Control
1794 key while pressing the _
\bx key.)
1796 The default key-bindings may be changed with an ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc
1797 file. The value of the shell variable INPUTRC, if set, is
1798 used instead of ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc. Other programs that use this
1799 library may add their own commands and bindings.
1801 For example, placing
1803 M-Control-u: universal-argument
1805 C-Meta-u: universal-argument
1806 into the ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc would make M-C-u execute the readline
1807 command _
\bu_
\bn_
\bi_
\bv_
\be_
\br_
\bs_
\ba_
\bl-_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt.
1809 The following symbolic character names are recognized:
1810 _
\bR_
\bU_
\bB_
\bO_
\bU_
\bT, _
\bD_
\bE_
\bL, _
\bE_
\bS_
\bC, _
\bL_
\bF_
\bD, _
\bN_
\bE_
\bW_
\bL_
\bI_
\bN_
\bE, _
\bR_
\bE_
\bT, _
\bR_
\bE_
\bT_
\bU_
\bR_
\bN, _
\bS_
\bP_
\bC, _
\bS_
\bP_
\bA_
\bC_
\bE, and
1811 _
\bT_
\bA_
\bB. In addition to command names, readline allows keys to
1812 be bound to a string that is inserted when the key is
1813 pressed (a _
\bm_
\ba_
\bc_
\br_
\bo).
1815 Readline is customized by putting commands in an initializa-
1816 tion file. The name of this file is taken from the value of
1817 the INPUTRC variable. If that variable is unset, the
1818 default is ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc. When a program which uses the read-
1819 line library starts up, the init file is read, and the key
1820 bindings and variables are set. There are only a few basic
1821 constructs allowed in the readline init file. Blank lines
1822 are ignored. Lines beginning with a # are comments. Lines
1823 beginning with a $ indicate conditional constructs. Other
1824 lines denote key bindings and variable settings.
1826 The syntax for controlling key bindings in the ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc
1827 file is simple. All that is required is the name of the
1828 command or the text of a macro and a key sequence to which
1829 it should be bound. The name may be specified in one of two
1830 ways: as a symbolic key name, possibly with _
\bM_
\be_
\bt_
\ba- or
1831 _
\bC_
\bo_
\bn_
\bt_
\br_
\bo_
\bl- prefixes, or as a key sequence. When using the
1832 form keyname:_
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be or _
\bm_
\ba_
\bc_
\br_
\bo, _
\bk_
\be_
\by_
\bn_
\ba_
\bm_
\be is the name of
1833 a key spelled out in English. For example:
1835 Control-u: universal-argument
1836 Meta-Rubout: backward-kill-word
1837 Control-o: ">&output"
1839 In the above example, _
\bC-_
\bu is bound to the function
1840 universal-argument, _
\bM-_
\bD_
\bE_
\bL is bound to the function
1841 backward-kill-word, and _
\bC-_
\bo is bound to run the macro
1845 GNU Last change: 1995 May 5 28
1852 BASH(1) USER COMMANDS BASH(1)
1856 expressed on the right hand side (that is, to insert the
1857 text >&_
\bo_
\bu_
\bt_
\bp_
\bu_
\bt into the line).
1859 In the second form, "keyseq":_
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be or _
\bm_
\ba_
\bc_
\br_
\bo, keyseq
1860 differs from keyname above in that strings denoting an
1861 entire key sequence may be specified by placing the sequence
1862 within double quotes. Some GNU Emacs style key escapes can
1863 be used, as in the following example.
1865 "\C-u": universal-argument
1866 "\C-x\C-r": re-read-init-file
1867 "\e[11~": "Function Key 1"
1869 In this example, _
\bC-_
\bu is again bound to the function
1870 universal-argument. _
\bC-_
\bx _
\bC-_
\br is bound to the function
1871 re-read-init-file, and _
\bE_
\bS_
\bC [ _
\b1 _
\b1 ~ is bound to insert the
1872 text Function Key 1. The full set of escape sequences is
1878 \e an escape character
1886 When entering the text of a macro, single or double quotes
1887 should be used to indicate a macro definition. Unquoted
1888 text is assumed to be a function name. Backslash will quote
1889 any character in the macro text, including " and '.
1891 Bash allows the current readline key bindings to be
1892 displayed or modified with the bind builtin command. The
1893 editing mode may be switched during interactive use by using
1894 the -o option to the set builtin command (see SHELL BUILTIN
1897 Readline has variables that can be used to further customize
1898 its behavior. A variable may be set in the _
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc file
1899 with a statement of the form
1901 set _
\bv_
\ba_
\br_
\bi_
\ba_
\bb_
\bl_
\be-_
\bn_
\ba_
\bm_
\be _
\bv_
\ba_
\bl_
\bu_
\be
1903 Except where noted, readline variables can take the values
1904 On or Off. The variables and their default values are:
1906 horizontal-scroll-mode (Off)
1907 When set to On, makes readline use a single line for
1911 GNU Last change: 1995 May 5 29
1918 BASH(1) USER COMMANDS BASH(1)
1922 display, scrolling the input horizontally on a single
1923 screen line when it becomes longer than the screen
1924 width rather than wrapping to a new line.
1925 editing-mode (emacs)
1926 Controls whether readline begins with a set of key
1927 bindings similar to _
\be_
\bm_
\ba_
\bc_
\bs or _
\bv_
\bi. editing-mode can be
1928 set to either emacs or vi.
1929 mark-modified-lines (Off)
1930 If set to On, history lines that have been modified are
1931 displayed with a preceding asterisk (*).
1932 bell-style (audible)
1933 Controls what happens when readline wants to ring the
1934 terminal bell. If set to none, readline never rings
1935 the bell. If set to visible, readline uses a visible
1936 bell if one is available. If set to audible, readline
1937 attempts to ring the terminal's bell.
1938 comment-begin (``#'')
1939 The string that is inserted in vi mode when the
1940 vi-comment command is executed.
1942 If set to On, readline will enable eight-bit input
1943 (that is, it will not strip the high bit from the char-
1944 acters it reads), regardless of what the terminal
1945 claims it can support.
1947 If set to On, readline will convert characters with the
1948 eighth bit set to an ASCII key sequence by stripping
1949 the eighth bit and prepending an escape character (in
1950 effect, using escape as the _
\bm_
\be_
\bt_
\ba _
\bp_
\br_
\be_
\bf_
\bi_
\bx).
1952 If set to On, readline will display characters with the
1953 eighth bit set directly rather than as a meta-prefixed
1955 completion-query-items (100)
1956 This determines when the user is queried about viewing
1957 the number of possible completions generated by the
1958 possible-completions command. It may be set to any
1959 integer value greater than or equal to zero. If the
1960 number of possible completions is greater than or equal
1961 to the value of this variable, the user is asked
1962 whether or not he wishes to view them; otherwise they
1963 are simply listed on the terminal.
1965 Set the current readline keymap. The set of legal key-
1966 map names is _
\be_
\bm_
\ba_
\bc_
\bs, _
\be_
\bm_
\ba_
\bc_
\bs-_
\bs_
\bt_
\ba_
\bn_
\bd_
\ba_
\br_
\bd, _
\be_
\bm_
\ba_
\bc_
\bs-_
\bm_
\be_
\bt_
\ba, _
\be_
\bm_
\ba_
\bc_
\bs-
1967 _
\bc_
\bt_
\bl_
\bx, _
\bv_
\bi, _
\bv_
\bi-_
\bm_
\bo_
\bv_
\be, _
\bv_
\bi-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd, and _
\bv_
\bi-_
\bi_
\bn_
\bs_
\be_
\br_
\bt. _
\bv_
\bi is
1968 equivalent to _
\bv_
\bi-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd; _
\be_
\bm_
\ba_
\bc_
\bs is equivalent to
1969 _
\be_
\bm_
\ba_
\bc_
\bs-_
\bs_
\bt_
\ba_
\bn_
\bd_
\ba_
\br_
\bd. The default value is _
\be_
\bm_
\ba_
\bc_
\bs; the value
1970 of editing-mode also affects the default keymap.
1971 show-all-if-ambiguous (Off)
1972 This alters the default behavior of the completion
1973 functions. If set to on, words which have more than
1977 GNU Last change: 1995 May 5 30
1984 BASH(1) USER COMMANDS BASH(1)
1988 one possible completion cause the matches to be listed
1989 immediately instead of ringing the bell.
1991 If set to on, tilde expansion is performed when read-
1992 line attempts word completion.
1994 Readline implements a facility similar in spirit to the con-
1995 ditional compilation features of the C preprocessor which
1996 allows key bindings and variable settings to be performed as
1997 the result of tests. There are three parser directives
2000 $if The $if construct allows bindings to be made based on
2001 the editing mode, the terminal being used, or the
2002 application using readline. The text of the test
2003 extends to the end of the line; no characters are
2004 required to isolate it.
2006 mode The mode= form of the $if directive is used to
2007 test whether readline is in emacs or vi mode.
2008 This may be used in conjunction with the set key-
2009 map command, for instance, to set bindings in the
2010 _
\be_
\bm_
\ba_
\bc_
\bs-_
\bs_
\bt_
\ba_
\bn_
\bd_
\ba_
\br_
\bd and _
\be_
\bm_
\ba_
\bc_
\bs-_
\bc_
\bt_
\bl_
\bx keymaps only if
2011 readline is starting out in emacs mode.
2013 term The term= form may be used to include terminal-
2014 specific key bindings, perhaps to bind the key
2015 sequences output by the terminal's function keys.
2016 The word on the right side of the = is tested
2017 against the full name of the terminal and the por-
2018 tion of the terminal name before the first -.
2019 This allows _
\bs_
\bu_
\bn to match both _
\bs_
\bu_
\bn and _
\bs_
\bu_
\bn-_
\bc_
\bm_
\bd, for
2023 The application construct is used to include
2024 application-specific settings. Each program using
2025 the readline library sets the _
\ba_
\bp_
\bp_
\bl_
\bi_
\bc_
\ba_
\bt_
\bi_
\bo_
\bn _
\bn_
\ba_
\bm_
\be,
2026 and an initialization file can test for a particu-
2027 lar value. This could be used to bind key
2028 sequences to functions useful for a specific pro-
2029 gram. For instance, the following command adds a
2030 key sequence that quotes the current or previous
2033 # Quote the current or previous word
2034 "\C-xq": "\eb\"\ef\""
2038 This command, as you saw in the previous example, ter-
2039 minates an $if command.
2043 GNU Last change: 1995 May 5 31
2050 BASH(1) USER COMMANDS BASH(1)
2055 Commands in this branch of the $if directive are exe-
2056 cuted if the test fails.
2058 Readline commands may be given numeric _
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs, which nor-
2059 mally act as a repeat count. Sometimes, however, it is the
2060 sign of the argument that is significant. Passing a nega-
2061 tive argument to a command that acts in the forward direc-
2062 tion (e.g., kill-line) causes that command to act in a back-
2063 ward direction. Commands whose behavior with arguments
2064 deviates from this are noted.
2066 When a command is described as _
\bk_
\bi_
\bl_
\bl_
\bi_
\bn_
\bg text, the text
2067 deleted is saved for possible future retrieval (_
\by_
\ba_
\bn_
\bk_
\bi_
\bn_
\bg).
2068 The killed text is saved in a _
\bk_
\bi_
\bl_
\bl-_
\br_
\bi_
\bn_
\bg. Consecutive kills
2069 cause the text to be accumulated into one unit, which can be
2070 yanked all at once. Commands which do not kill text separate
2071 the chunks of text on the kill-ring.
2073 The following is a list of the names of the commands and the
2074 default key sequences to which they are bound.
2077 beginning-of-line (C-a)
2078 Move to the start of the current line.
2080 Move to the end of the line.
2082 Move forward a character.
2084 Move back a character.
2086 Move forward to the end of the next word. Words are
2087 composed of alphanumeric characters (letters and
2090 Move back to the start of this, or the previous, word.
2091 Words are composed of alphanumeric characters (letters
2094 Clear the screen leaving the current line at the top of
2095 the screen. With an argument, refresh the current line
2096 without clearing the screen.
2098 Refresh the current line. By default, this is unbound.
2100 Commands for Manipulating the History
2101 accept-line (Newline, Return)
2102 Accept the line regardless of where the cursor is. If
2103 this line is non-empty, add it to the history list
2104 according to the state of the HISTCONTROL variable. If
2105 the line is a modified history line, then restore the
2109 GNU Last change: 1995 May 5 32
2116 BASH(1) USER COMMANDS BASH(1)
2120 history line to its original state.
2121 previous-history (C-p)
2122 Fetch the previous command from the history list, mov-
2123 ing back in the list.
2125 Fetch the next command from the history list, moving
2126 forward in the list.
2127 beginning-of-history (M-<)
2128 Move to the first line in the history.
2129 end-of-history (M->)
2130 Move to the end of the input history, i.e., the line
2131 currently being entered.
2132 reverse-search-history (C-r)
2133 Search backward starting at the current line and moving
2134 `up' through the history as necessary. This is an
2136 forward-search-history (C-s)
2137 Search forward starting at the current line and moving
2138 `down' through the history as necessary. This is an
2140 non-incremental-reverse-search-history (M-p)
2141 Search backward through the history starting at the
2142 current line using a non-incremental search for a
2143 string supplied by the user.
2144 non-incremental-forward-search-history (M-n)
2145 Search forward through the history using a
2146 non-incremental search for a string supplied by the
2148 history-search-forward
2149 Search forward through the history for the string of
2150 characters between the start of the current line and
2151 the current point. This is a non-incremental search.
2152 By default, this command is unbound.
2153 history-search-backward
2154 Search backward through the history for the string of
2155 characters between the start of the current line and
2156 the current point. This is a non-incremental search.
2157 By default, this command is unbound.
2158 yank-nth-arg (M-C-y)
2159 Insert the first argument to the previous command (usu-
2160 ally the second word on the previous line) at point
2161 (the current cursor position). With an argument _
\bn,
2162 insert the _
\bnth word from the previous command (the
2163 words in the previous command begin with word 0). A
2164 negative argument inserts the _
\bnth word from the end of
2165 the previous command.
2166 yank-last-arg (M-., M-_)
2167 Insert the last argument to the previous command (the
2168 last word on the previous line). With an argument,
2169 behave exactly like yank-nth-arg.
2170 shell-expand-line (M-C-e)
2171 Expand the line the way the shell does when it reads
2175 GNU Last change: 1995 May 5 33
2182 BASH(1) USER COMMANDS BASH(1)
2186 it. This performs alias and history expansion as well
2187 as all of the shell word expansions. See HISTORY
2188 EXPANSION below for a description of history expansion.
2189 history-expand-line (M-^)
2190 Perform history expansion on the current line. See
2191 HISTORY EXPANSION below for a description of history
2193 insert-last-argument (M-., M-_)
2194 A synonym for yank-last-arg.
2195 operate-and-get-next (C-o)
2196 Accept the current line for execution and fetch the
2197 next line relative to the current line from the history
2198 for editing. Any argument is ignored.
2200 Commands for Changing Text
2202 Delete the character under the cursor. If point is at
2203 the beginning of the line, there are no characters in
2204 the line, and the last character typed was not C-d,
2206 backward-delete-char (Rubout)
2207 Delete the character behind the cursor. When given a
2208 numeric argument, save the deleted text on the
2210 quoted-insert (C-q, C-v)
2211 Add the next character that you type to the line verba-
2212 tim. This is how to insert characters like C-q, for
2214 tab-insert (C-v TAB)
2215 Insert a tab character.
2216 self-insert (a, b, A, 1, !, ...)
2217 Insert the character typed.
2218 transpose-chars (C-t)
2219 Drag the character before point forward over the char-
2220 acter at point. Point moves forward as well. If point
2221 is at the end of the line, then transpose the two char-
2222 acters before point. Negative arguments don't work.
2223 transpose-words (M-t)
2224 Drag the word behind the cursor past the word in front
2225 of the cursor moving the cursor over that word as well.
2227 Uppercase the current (or following) word. With a
2228 negative argument, do the previous word, but do not
2231 Lowercase the current (or following) word. With a
2232 negative argument, do the previous word, but do not
2234 capitalize-word (M-c)
2235 Capitalize the current (or following) word. With a
2236 negative argument, do the previous word, but do not
2241 GNU Last change: 1995 May 5 34
2248 BASH(1) USER COMMANDS BASH(1)
2254 Kill the text from the current cursor position to the
2256 backward-kill-line (C-x C-Rubout)
2257 Kill backward to the beginning of the line.
2258 unix-line-discard (C-u)
2259 Kill backward from point to the beginning of the line.
2261 Kill all characters on the current line, no matter
2262 where the cursor is. By default, this is unbound.
2264 Kill from the cursor to the end of the current word, or
2265 if between words, to the end of the next word. Word
2266 boundaries are the same as those used by forward-word.
2267 backward-kill-word (M-Rubout)
2268 Kill the word behind the cursor. Word boundaries are
2269 the same as those used by backward-word.
2270 unix-word-rubout (C-w)
2271 Kill the word behind the cursor, using white space as a
2272 word boundary. The word boundaries are different from
2274 delete-horizontal-space
2275 Delete all spaces and tabs around point. By default,
2278 Yank the top of the kill ring into the buffer at the
2281 Rotate the kill-ring, and yank the new top. Only works
2282 following yank or yank-pop.
2285 digit-argument (M-0, M-1, ..., M--)
2286 Add this digit to the argument already accumulating, or
2287 start a new argument. M-- starts a negative argument.
2289 Each time this is executed, the argument count is mul-
2290 tiplied by four. The argument count is initially one,
2291 so executing this function the first time makes the
2292 argument count four. By default, this is not bound to
2297 Attempt to perform completion on the text before point.
2298 Bash attempts completion treating the text as a vari-
2299 able (if the text begins with $), username (if the text
2300 begins with ~), hostname (if the text begins with @),
2301 or command (including aliases and functions) in turn.
2302 If none of these produces a match, filename completion
2307 GNU Last change: 1995 May 5 35
2314 BASH(1) USER COMMANDS BASH(1)
2318 possible-completions (M-?)
2319 List the possible completions of the text before point.
2321 Insert all completions of the text before point that
2322 would have been generated by possible-completions. By
2323 default, this is not bound to a key.
2324 complete-filename (M-/)
2325 Attempt filename completion on the text before point.
2326 possible-filename-completions (C-x /)
2327 List the possible completions of the text before point,
2328 treating it as a filename.
2329 complete-username (M-~)
2330 Attempt completion on the text before point, treating
2332 possible-username-completions (C-x ~)
2333 List the possible completions of the text before point,
2334 treating it as a username.
2335 complete-variable (M-$)
2336 Attempt completion on the text before point, treating
2337 it as a shell variable.
2338 possible-variable-completions (C-x $)
2339 List the possible completions of the text before point,
2340 treating it as a shell variable.
2341 complete-hostname (M-@)
2342 Attempt completion on the text before point, treating
2344 possible-hostname-completions (C-x @)
2345 List the possible completions of the text before point,
2346 treating it as a hostname.
2347 complete-command (M-!)
2348 Attempt completion on the text before point, treating
2349 it as a command name. Command completion attempts to
2350 match the text against aliases, reserved words, shell
2351 functions, builtins, and finally executable filenames,
2353 possible-command-completions (C-x !)
2354 List the possible completions of the text before point,
2355 treating it as a command name.
2356 dynamic-complete-history (M-TAB)
2357 Attempt completion on the text before point, comparing
2358 the text against lines from the history list for possi-
2359 ble completion matches.
2360 complete-into-braces (M-{)
2361 Perform filename completion and return the list of pos-
2362 sible completions enclosed within braces so the list is
2363 available to the shell (see Brace Expansion above).
2366 start-kbd-macro (C-x ()
2367 Begin saving the characters typed into the current key-
2369 end-kbd-macro (C-x ))
2373 GNU Last change: 1995 May 5 36
2380 BASH(1) USER COMMANDS BASH(1)
2384 Stop saving the characters typed into the current key-
2385 board macro and save the definition.
2386 call-last-kbd-macro (C-x e)
2387 Re-execute the last keyboard macro defined, by making
2388 the characters in the macro appear as if typed at the
2392 re-read-init-file (C-x C-r)
2393 Read in the contents of your init file, and incorporate
2394 any bindings or variable assignments found there.
2396 Abort the current editing command and ring the
2397 terminal's bell (subject to the setting of bell-style).
2398 do-uppercase-version (M-a, M-b, ...)
2399 Run the command that is bound to the corresponding
2400 uppercase character.
2402 Metafy the next character typed. ESC f is equivalent
2405 Incremental undo, separately remembered for each line.
2407 Undo all changes made to this line. This is like typ-
2408 ing the undo command enough times to return the line to
2411 Perform tilde expansion on the current word.
2413 Print all of the functions and their key bindings to
2414 the readline output stream. If a numeric argument is
2415 supplied, the output is formatted in such a way that it
2416 can be made part of an _
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc file.
2417 display-shell-version (C-x C-v)
2418 Display version information about the current instance
2422 When interactive, the shell provides access to the _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd
2423 _
\bh_
\bi_
\bs_
\bt_
\bo_
\br_
\by, the list of commands previously typed. The text of
2424 the last HISTSIZE commands (default 500) is saved in a his-
2425 tory list. The shell stores each command in the history
2426 list prior to parameter and variable expansion (see EXPAN-
2427 SION above) but after history expansion is performed, sub-
2428 ject to the values of the shell variables
2429 command_oriented_history and HISTCONTROL. On startup, the
2430 history is initialized from the file named by the variable
2431 HISTFILE (default ~/._
\bb_
\ba_
\bs_
\bh__
\bh_
\bi_
\bs_
\bt_
\bo_
\br_
\by). HISTFILE is truncated,
2432 if necessary, to contain no more than HISTFILESIZE lines.
2433 The builtin command fc (see SHELL BUILTIN COMMANDS below)
2434 may be used to list or edit and re-execute a portion of the
2435 history list. The history builtin can be used to display
2439 GNU Last change: 1995 May 5 37
2446 BASH(1) USER COMMANDS BASH(1)
2450 the history list and manipulate the history file. When
2451 using the command-line editing, search commands are avail-
2452 able in each editing mode that provide access to the history
2453 list. When an interactive shell exits, the last HISTSIZE
2454 lines are copied from the history list to HISTFILE. If
2455 HISTFILE is unset, or if the history file is unwritable, the
2456 history is not saved.
2459 The shell supports a history expansion feature that is simi-
2460 lar to the history expansion in csh. This section describes
2461 what syntax features are available. This feature is enabled
2462 by default for interactive shells, and can be disabled using
2463 the +H option to the set builtin command (see SHELL BUILTIN
2464 COMMANDS below). Non-interactive shells do not perform his-
2467 History expansion is performed immediately after a complete
2468 line is read, before the shell breaks it into words. It
2469 takes place in two parts. The first is to determine which
2470 line from the previous history to use during substitution.
2471 The second is to select portions of that line for inclusion
2472 into the current one. The line selected from the previous
2473 history is the _
\be_
\bv_
\be_
\bn_
\bt, and the portions of that line that are
2474 acted upon are _
\bw_
\bo_
\br_
\bd_
\bs. The line is broken into words in the
2475 same fashion as when reading input, so that several
2476 _
\bm_
\be_
\bt_
\ba_
\bc_
\bh_
\ba_
\br_
\ba_
\bc_
\bt_
\be_
\br-separated words surrounded by quotes are con-
2477 sidered as one word. Only backslash (\) and single quotes
2478 can quote the history escape character, which is ! by
2481 The shell allows control of the various characters used by
2482 the history expansion mechanism (see the description of
2483 histchars above under Shell Variables).
2486 An event designator is a reference to a command line entry
2487 in the history list.
2489 ! Start a history substitution, except when followed by a
2490 blank, newline, = or (.
2491 !! Refer to the previous command. This is a synonym for
2493 !_
\bn Refer to command line _
\bn.
2494 !-_
\bn Refer to the current command line minus _
\bn.
2495 !_
\bs_
\bt_
\br_
\bi_
\bn_
\bg
2496 Refer to the most recent command starting with _
\bs_
\bt_
\br_
\bi_
\bn_
\bg.
2497 !?_
\bs_
\bt_
\br_
\bi_
\bn_
\bg[?]
2498 Refer to the most recent command containing _
\bs_
\bt_
\br_
\bi_
\bn_
\bg.
2499 \e9 ^
\e8_
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1
\e9^
\e8_
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2
\e9^
2500 \e8 Quick substitution. Repeat the last command, replacing
2501 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 with _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2. Equivalent to
2505 GNU Last change: 1995 May 5 38
2512 BASH(1) USER COMMANDS BASH(1)
2516 ``!!:s/_
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1/_
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2/'' (see Modifiers below).
2517 !# The entire command line typed so far.
2520 A : separates the event specification from the word designa-
2521 tor. It can be omitted if the word designator begins with a
2522 ^, $, *, or %. Words are numbered from the beginning of the
2523 line, with the first word being denoted by a 0 (zero).
2526 The zeroth word. For the shell, this is the command
2528 _
\bn The _
\bnth word.
2529 ^ The first argument. That is, word 1.
2530 $ The last argument.
2531 % The word matched by the most recent `?_
\bs_
\bt_
\br_
\bi_
\bn_
\bg?' search.
2532 _
\bx-_
\by A range of words; `-_
\by' abbreviates `0-_
\by'.
2533 * All of the words but the zeroth. This is a synonym for
2534 `_
\b1-$'. It is not an error to use * if there is just
2535 one word in the event; the empty string is returned in
2537 x* Abbreviates _
\bx-$.
2538 x- Abbreviates _
\bx-$ like x*, but omits the last word.
2541 After the optional word designator, you can add a sequence
2542 of one or more of the following modifiers, each preceded by
2545 h Remove a trailing pathname component, leaving only the
2547 r Remove a trailing suffix of the form ._
\bx_
\bx_
\bx, leaving the
2549 e Remove all but the trailing suffix.
2550 t Remove all leading pathname components, leaving the
2552 p Print the new command but do not execute it.
2553 q Quote the substituted words, escaping further substitu-
2555 x Quote the substituted words as with q, but break into
2556 words at blanks and newlines.
2557 s/_
\bo_
\bl_
\bd/_
\bn_
\be_
\bw/
2558 Substitute _
\bn_
\be_
\bw for the first occurrence of _
\bo_
\bl_
\bd in the
2559 event line. Any delimiter can be used in place of /.
2560 The final delimiter is optional if it is the last char-
2561 acter of the event line. The delimiter may be quoted
2562 in _
\bo_
\bl_
\bd and _
\bn_
\be_
\bw with a single backslash. If & appears
2563 in _
\bn_
\be_
\bw, it is replaced by _
\bo_
\bl_
\bd. A single backslash will
2565 & Repeat the previous substitution.
2566 g Cause changes to be applied over the entire event line.
2567 This is used in conjunction with `:s' (e.g.,
2571 GNU Last change: 1995 May 5 39
2578 BASH(1) USER COMMANDS BASH(1)
2582 `:gs/_
\bo_
\bl_
\bd/_
\bn_
\be_
\bw/') or `:&'. If used with `:s', any delim-
2583 iter can be used in place of /, and the final delimiter
2584 is optional if it is the last character of the event
2587 ARITHMETIC EVALUATION
2588 The shell allows arithmetic expressions to be evaluated,
2589 under certain circumstances (see the let builtin command and
2590 Arithmetic Expansion). Evaluation is done in long integers
2591 with no check for overflow, though division by 0 is trapped
2592 and flagged as an error. The following list of operators is
2593 grouped into levels of equal-precedence operators. The lev-
2594 els are listed in order of decreasing precedence.
2596 - + unary minus and plus
2597 ! ~ logical and bitwise negation
2599 multiplication, division, remainder
2600 + - addition, subtraction
2602 left and right bitwise shifts
2606 equality and inequality
2608 ^ bitwise exclusive OR
2615 Shell variables are allowed as operands; parameter expansion
2616 is performed before the expression is evaluated. The value
2617 of a parameter is coerced to a long integer within an
2618 expression. A shell variable need not have its integer
2619 attribute turned on to be used in an expression.
2621 Constants with a leading 0 are interpreted as octal numbers.
2622 A leading _
\b0_
\bx or _
\b0_
\bX denotes hexadecimal. Otherwise, numbers
2623 take the form [_
\bb_
\ba_
\bs_
\be#]n, where _
\bb_
\ba_
\bs_
\be is a decimal number
2624 between 2 and 36 representing the arithmetic base, and _
\bn is
2625 a number in that base. If _
\bb_
\ba_
\bs_
\be is omitted, then base 10 is
2628 Operators are evaluated in order of precedence. Sub-
2629 expressions in parentheses are evaluated first and may over-
2630 ride the precedence rules above.
2632 SHELL BUILTIN COMMANDS
2633 : [_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs]
2637 GNU Last change: 1995 May 5 40
2644 BASH(1) USER COMMANDS BASH(1)
2648 No effect; the command does nothing beyond expanding
2649 _
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs and performing any specified redirections. A
2650 zero exit code is returned.
2652 . _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be [_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs]
2653 source _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be [_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs]
2654 Read and execute commands from _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be in the current
2655 shell environment and return the exit status of the
2656 last command executed from _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be. If _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be does
2657 not contain a slash, pathnames in PATH are used to find
2658 the directory containing _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be. The file searched
2659 for in PATH need not be executable. The current direc-
2660 tory is searched if no file is found in PATH. If any
2661 _
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs are supplied, they become the positional
2662 parameters when _
\bf_
\bi_
\bl_
\be is executed. Otherwise the posi-
2663 tional parameters are unchanged. The return status is
2664 the status of the last command exited within the script
2665 (0 if no commands are executed), and false if _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be
2668 alias [_
\bn_
\ba_
\bm_
\be[=_
\bv_
\ba_
\bl_
\bu_
\be] ...]
2669 Alias with no arguments prints the list of aliases in
2670 the form _
\bn_
\ba_
\bm_
\be=_
\bv_
\ba_
\bl_
\bu_
\be on standard output. When arguments
2671 are supplied, an alias is defined for each _
\bn_
\ba_
\bm_
\be whose
2672 _
\bv_
\ba_
\bl_
\bu_
\be is given. A trailing space in _
\bv_
\ba_
\bl_
\bu_
\be causes the
2673 next word to be checked for alias substitution when the
2674 alias is expanded. For each _
\bn_
\ba_
\bm_
\be in the argument list
2675 for which no _
\bv_
\ba_
\bl_
\bu_
\be is supplied, the name and value of
2676 the alias is printed. Alias returns true unless a _
\bn_
\ba_
\bm_
\be
2677 is given for which no alias has been defined.
2679 bg [_
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc]
2680 Place _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc in the background, as if it had been
2681 started with &. If _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc is not present, the shell's
2682 notion of the _
\bc_
\bu_
\br_
\br_
\be_
\bn_
\bt _
\bj_
\bo_
\bb is used. bg _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc returns
2683 0 unless run when job control is disabled or, when run
2684 with job control enabled, if _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc was not found or
2685 started without job control.
2687 bind [-m _
\bk_
\be_
\by_
\bm_
\ba_
\bp] [-lvd] [-q _
\bn_
\ba_
\bm_
\be]
2688 bind [-m _
\bk_
\be_
\by_
\bm_
\ba_
\bp] -f _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be
2689 bind [-m _
\bk_
\be_
\by_
\bm_
\ba_
\bp] _
\bk_
\be_
\by_
\bs_
\be_
\bq:_
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be
2690 Display current readline key and function bindings, or
2691 bind a key sequence to a readline function or macro.
2692 The binding syntax accepted is identical to that of
2693 ._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc, but each binding must be passed as a separate
2694 argument; e.g., '"\C-x\C-r": re-read-init-file'.
2695 Options, if supplied, have the following meanings:
2696 -m _
\bk_
\be_
\by_
\bm_
\ba_
\bp
2697 Use _
\bk_
\be_
\by_
\bm_
\ba_
\bp as the keymap to be affected by the
2698 subsequent bindings. Acceptable _
\bk_
\be_
\by_
\bm_
\ba_
\bp names are
2699 _
\be_
\bm_
\ba_
\bc_
\bs, _
\be_
\bm_
\ba_
\bc_
\bs-_
\bs_
\bt_
\ba_
\bn_
\bd_
\ba_
\br_
\bd, _
\be_
\bm_
\ba_
\bc_
\bs-_
\bm_
\be_
\bt_
\ba, _
\be_
\bm_
\ba_
\bc_
\bs-_
\bc_
\bt_
\bl_
\bx, _
\bv_
\bi,
2703 GNU Last change: 1995 May 5 41
2710 BASH(1) USER COMMANDS BASH(1)
2714 _
\bv_
\bi-_
\bm_
\bo_
\bv_
\be, _
\bv_
\bi-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd, and _
\bv_
\bi-_
\bi_
\bn_
\bs_
\be_
\br_
\bt. _
\bv_
\bi is
2715 equivalent to _
\bv_
\bi-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd; _
\be_
\bm_
\ba_
\bc_
\bs is equivalent to
2716 _
\be_
\bm_
\ba_
\bc_
\bs-_
\bs_
\bt_
\ba_
\bn_
\bd_
\ba_
\br_
\bd.
2717 -l List the names of all readline functions
2718 -v List current function names and bindings
2719 -d Dump function names and bindings in such a way
2720 that they can be re-read
2721 -f _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be
2722 Read key bindings from _
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be
2723 -q _
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn
2724 Query about which keys invoke the named _
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn
2726 The return value is 0 unless an unrecognized option is
2727 given or an error occurred.
2730 Exit from within a for, while, or until loop. If _
\bn is
2731 specified, break _
\bn levels. _
\bn must be >
\b_ 1. If _
\bn is
2732 greater than the number of enclosing loops, all enclos-
2733 ing loops are exited. The return value is 0 unless the
2734 shell is not executing a loop when break is executed.
2736 builtin _
\bs_
\bh_
\be_
\bl_
\bl-_
\bb_
\bu_
\bi_
\bl_
\bt_
\bi_
\bn [_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs]
2737 Execute the specified shell builtin, passing it _
\ba_
\br_
\bg_
\bu_
\b-
2738 _
\bm_
\be_
\bn_
\bt_
\bs, and return its exit status. This is useful when
2739 you wish to define a function whose name is the same as
2740 a shell builtin, but need the functionality of the
2741 builtin within the function itself. The cd builtin is
2742 commonly redefined this way. The return status is
2743 false if _
\bs_
\bh_
\be_
\bl_
\bl-_
\bb_
\bu_
\bi_
\bl_
\bt_
\bi_
\bn is not a shell builtin command.
2746 Change the current directory to _
\bd_
\bi_
\br. The variable HOME
2747 is the default _
\bd_
\bi_
\br. The variable CDPATH defines the
2748 search path for the directory containing _
\bd_
\bi_
\br. Alterna-
2749 tive directory names are separated by a colon (:). A
2750 null directory name in CDPATH is the same as the
2751 current directory, i.e., ``.''. If _
\bd_
\bi_
\br begins with a
2752 slash (/), then CDPATH is not used. An argument of -
2753 is equivalent to $OLDPWD. The return value is true if
2754 the directory was successfully changed; false other-
2757 command [-pVv] _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd [_
\ba_
\br_
\bg ...]
2758 Run _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd with _
\ba_
\br_
\bg_
\bs suppressing the normal shell
2759 function lookup. Only builtin commands or commands
2760 found in the PATH are executed. If the -p option is
2761 given, the search for _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is performed using a
2762 default value for PATH that is guaranteed to find all
2763 of the standard utilities. If either the -V or -v
2764 option is supplied, a description of _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is
2765 printed. The -v option causes a single word indicating
2769 GNU Last change: 1995 May 5 42
2776 BASH(1) USER COMMANDS BASH(1)
2780 the command or pathname used to invoke _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd to be
2781 printed; the -V option produces a more verbose descrip-
2782 tion. An argument of -- disables option checking for
2783 the rest of the arguments. If the -V or -v option is
2784 supplied, the exit status is 0 if _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd was found,
2785 and 1 if not. If neither option is supplied and an
2786 error occurred or _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd cannot be found, the exit
2787 status is 127. Otherwise, the exit status of the com-
2788 mand builtin is the exit status of _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd.
2791 Resume the next iteration of the enclosing for, while,
2792 or until loop. If _
\bn is specified, resume at the _
\bnth
2793 enclosing loop. _
\bn must be >
\b_ 1. If _
\bn is greater than
2794 the number of enclosing loops, the last enclosing loop
2795 (the `top-level' loop) is resumed. The return value is
2796 0 unless the shell is not executing a loop when con-
2799 declare [-frxi] [_
\bn_
\ba_
\bm_
\be[=_
\bv_
\ba_
\bl_
\bu_
\be]]
2800 typeset [-frxi] [_
\bn_
\ba_
\bm_
\be[=_
\bv_
\ba_
\bl_
\bu_
\be]]
2801 Declare variables and/or give them attributes. If no
2802 _
\bn_
\ba_
\bm_
\bes are given, then display the values of variables
2803 instead. The options can be used to restrict output to
2804 variables with the specified attribute.
2805 -f Use function names only
2806 -r Make _
\bn_
\ba_
\bm_
\bes readonly. These names cannot then be
2807 assigned values by subsequent assignment state-
2809 -x Mark _
\bn_
\ba_
\bm_
\bes for export to subsequent commands via
2811 -i The variable is treated as an integer; arithmetic
2812 evaluation (see ARITHMETIC EVALUATION ) is per-
2813 formed when the variable is assigned a value.
2815 Using `+' instead of `-' turns off the attribute
2816 instead. When used in a function, makes _
\bn_
\ba_
\bm_
\bes local,
2817 as with the local command. The return value is 0
2818 unless an illegal option is encountered, an attempt is
2819 made to define a function using "-f foo=bar", one of
2820 the _
\bn_
\ba_
\bm_
\be_
\bs is not a legal shell variable name, an
2821 attempt is made to turn off readonly status for a
2822 readonly variable, or an attempt is made to display a
2823 non-existant function with -f.
2826 Display the list of currently remembered directories.
2827 Directories are added to the list with the pushd com-
2828 mand; the popd command moves back up through the list.
2829 +n displays the _
\bnth entry counting from the left of
2830 the list shown by dirs when invoked without
2831 options, starting with zero.
2835 GNU Last change: 1995 May 5 43
2842 BASH(1) USER COMMANDS BASH(1)
2846 -n displays the _
\bnth entry counting from the right of
2847 the list shown by dirs when invoked without
2848 options, starting with zero.
2849 -l produces a longer listing; the default listing
2850 format uses a tilde to denote the home directory.
2852 The return value is 0 unless an illegal option is sup-
2853 plied or _
\bn indexes beyond the end of the directory
2856 echo [-neE] [_
\ba_
\br_
\bg ...]
2857 Output the _
\ba_
\br_
\bgs, separated by spaces. The return
2858 status is always 0. If -n is specified, the trailing
2859 newline is suppressed. If the -e option is given,
2860 interpretation of the following backslash-escaped char-
2861 acters is enabled. The -E option disables the
2862 interpretation of these escape characters, even on sys-
2863 tems where they are interpreted by default.
2866 \c suppress trailing newline
2873 \nnn the character whose ASCII code is _
\bn_
\bn_
\bn (octal)
2875 enable [-n] [-all] [_
\bn_
\ba_
\bm_
\be ...]
2876 Enable and disable builtin shell commands. This allows
2877 the execution of a disk command which has the same name
2878 as a shell builtin without specifying a full pathname.
2879 If -n is used, each _
\bn_
\ba_
\bm_
\be is disabled; otherwise, _
\bn_
\ba_
\bm_
\be_
\bs
2880 are enabled. For example, to use the test binary found
2881 via the PATH instead of the shell builtin version, type
2882 ``enable -n test''. If no arguments are given, a list
2883 of all enabled shell builtins is printed. If only -n
2884 is supplied, a list of all disabled builtins is
2885 printed. If only -all is supplied, the list printed
2886 includes all builtins, with an indication of whether or
2887 not each is enabled. enable accepts -a as a synonym
2888 for -all. The return value is 0 unless a _
\bn_
\ba_
\bm_
\be is not a
2891 eval [_
\ba_
\br_
\bg ...]
2892 The _
\ba_
\br_
\bgs are read and concatenated together into a sin-
2893 gle command. This command is then read and executed by
2894 the shell, and its exit status is returned as the value
2895 of the eval command. If there are no _
\ba_
\br_
\bg_
\bs, or only
2896 null arguments, eval returns true.
2901 GNU Last change: 1995 May 5 44
2908 BASH(1) USER COMMANDS BASH(1)
2912 exec [[-] _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd [_
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs]]
2913 If _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is specified, it replaces the shell. No new
2914 process is created. The _
\ba_
\br_
\bg_
\bu_
\bm_
\be_
\bn_
\bt_
\bs become the arguments
2915 to _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd. If the first argument is -, the shell
2916 places a dash in the zeroth arg passed to _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd.
2917 This is what login does. If the file cannot be exe-
2918 cuted for some reason, a non-interactive shell exits,
2919 unless the shell variable no_exit_on_failed_exec
2920 exists, in which case it returns failure. An interac-
2921 tive shell returns failure if the file cannot be exe-
2922 cuted. If _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is not specified, any redirections
2923 take effect in the current shell, and the return status
2927 Cause the shell to exit with a status of _
\bn. If _
\bn is
2928 omitted, the exit status is that of the last command
2929 executed. A trap on EXIT is executed before the shell
2932 export [-nf] [_
\bn_
\ba_
\bm_
\be[=_
\bw_
\bo_
\br_
\bd]] ...
2934 The supplied _
\bn_
\ba_
\bm_
\be_
\bs are marked for automatic export to
2935 the environment of subsequently executed commands. If
2936 the -f option is given, the _
\bn_
\ba_
\bm_
\be_
\bs refer to functions.
2937 If no _
\bn_
\ba_
\bm_
\be_
\bs are given, or if the -p option is supplied,
2938 a list of all names that are exported in this shell is
2939 printed. The -n option causes the export property to
2940 be removed from the named variables. An argument of --
2941 disables option checking for the rest of the arguments.
2942 export returns an exit status of 0 unless an illegal
2943 option is encountered, one of the _
\bn_
\ba_
\bm_
\be_
\bs is not a legal
2944 shell variable name, or -f is supplied with a _
\bn_
\ba_
\bm_
\be that
2947 fc [-e _
\be_
\bn_
\ba_
\bm_
\be] [-nlr] [_
\bf_
\bi_
\br_
\bs_
\bt] [_
\bl_
\ba_
\bs_
\bt]
2948 fc -s [_
\bp_
\ba_
\bt=_
\br_
\be_
\bp] [_
\bc_
\bm_
\bd]
2949 Fix Command. In the first form, a range of commands
2950 from _
\bf_
\bi_
\br_
\bs_
\bt to _
\bl_
\ba_
\bs_
\bt is selected from the history list.
2951 _
\bF_
\bi_
\br_
\bs_
\bt and _
\bl_
\ba_
\bs_
\bt may be specified as a string (to locate
2952 the last command beginning with that string) or as a
2953 number (an index into the history list, where a nega-
2954 tive number is used as an offset from the current com-
2955 mand number). If _
\bl_
\ba_
\bs_
\bt is not specified it is set to
2956 the current command for listing (so that fc -l -10
2957 prints the last 10 commands) and to _
\bf_
\bi_
\br_
\bs_
\bt otherwise.
2958 If _
\bf_
\bi_
\br_
\bs_
\bt is not specified it is set to the previous
2959 command for editing and -16 for listing.
2961 The -n flag suppresses the command numbers when list-
2962 ing. The -r flag reverses the order of the commands.
2963 If the -l flag is given, the commands are listed on
2967 GNU Last change: 1995 May 5 45
2974 BASH(1) USER COMMANDS BASH(1)
2978 standard output. Otherwise, the editor given by _
\be_
\bn_
\ba_
\bm_
\be
2979 is invoked on a file containing those commands. If
2980 _
\be_
\bn_
\ba_
\bm_
\be is not given, the value of the FCEDIT variable is
2981 used, and the value of EDITOR if FCEDIT is not set. If
2982 neither variable is set, _
\bv_
\bi is used. When editing is
2983 complete, the edited commands are echoed and executed.
2985 In the second form, _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd is re-executed after each
2986 instance of _
\bp_
\ba_
\bt is replaced by _
\br_
\be_
\bp. A useful alias to
2987 use with this is ``r=fc -s'', so that typing ``r cc''
2988 runs the last command beginning with ``cc'' and typing
2989 ``r'' re-executes the last command.
2991 If the first form is used, the return value is 0 unless
2992 an illegal option is encountered or _
\bf_
\bi_
\br_
\bs_
\bt or _
\bl_
\ba_
\bs_
\bt
2993 specify history lines out of range. If the -e option
2994 is supplied, the return value is the value of the last
2995 command executed or failure if an error occurs with the
2996 temporary file of commands. If the second form is
2997 used, the return status is that of the command re-
2998 executed, unless _
\bc_
\bm_
\bd does not specify a valid history
2999 line, in which case fc returns failure.
3001 fg [_
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc]
3002 Place _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc in the foreground, and make it the
3003 current job. If _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc is not present, the shell's
3004 notion of the _
\bc_
\bu_
\br_
\br_
\be_
\bn_
\bt _
\bj_
\bo_
\bb is used. The return value is
3005 that of the command placed into the foreground, or
3006 failure if run when job control is disabled or, when
3007 run with job control enabled, if _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc does not
3008 specify a valid job or _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc specifies a job that was
3009 started without job control.
3011 getopts _
\bo_
\bp_
\bt_
\bs_
\bt_
\br_
\bi_
\bn_
\bg _
\bn_
\ba_
\bm_
\be [_
\ba_
\br_
\bg_
\bs]
3012 getopts is used by shell procedures to parse positional
3013 parameters. _
\bo_
\bp_
\bt_
\bs_
\bt_
\br_
\bi_
\bn_
\bg contains the option letters to
3014 be recognized; if a letter is followed by a colon, the
3015 option is expected to have an argument, which should be
3016 separated from it by white space. Each time it is
3017 invoked, getopts places the next option in the shell
3018 variable _
\bn_
\ba_
\bm_
\be, initializing _
\bn_
\ba_
\bm_
\be if it does not exist,
3019 and the index of the next argument to be processed into
3020 the variable OPTIND. OPTIND is initialized to 1 each
3021 time the shell or a shell script is invoked. When an
3022 option requires an argument, getopts places that argu-
3023 ment into the variable OPTARG. The shell does not
3024 reset OPTIND automatically; it must be manually reset
3025 between multiple calls to getopts within the same shell
3026 invocation if a new set of parameters is to be used.
3028 getopts can report errors in two ways. If the first
3029 character of _
\bo_
\bp_
\bt_
\bs_
\bt_
\br_
\bi_
\bn_
\bg is a colon, _
\bs_
\bi_
\bl_
\be_
\bn_
\bt error
3033 GNU Last change: 1995 May 5 46
3040 BASH(1) USER COMMANDS BASH(1)
3044 reporting is used. In normal operation diagnostic mes-
3045 sages are printed when illegal options or missing
3046 option arguments are encountered. If the variable
3047 OPTERR is set to 0, no error message will be displayed,
3048 even if the first character of _
\bo_
\bp_
\bt_
\bs_
\bt_
\br_
\bi_
\bn_
\bg is not a
3051 If an illegal option is seen, getopts places ? into
3052 _
\bn_
\ba_
\bm_
\be and, if not silent, prints an error message and
3053 unsets OPTARG. If getopts is silent, the option char-
3054 acter found is placed in OPTARG and no diagnostic mes-
3057 If a required argument is not found, and getopts is not
3058 silent, a question mark (?) is placed in _
\bn_
\ba_
\bm_
\be, OPTARG
3059 is unset, and a diagnostic message is printed. If
3060 getopts is silent, then a colon (:) is placed in _
\bn_
\ba_
\bm_
\be
3061 and OPTARG is set to the option character found.
3063 getopts normally parses the positional parameters, but
3064 if more arguments are given in _
\ba_
\br_
\bg_
\bs, getopts parses
3065 those instead. getopts returns true if an option,
3066 specified or unspecified, is found. It returns false
3067 if the end of options is encountered or an error
3070 hash [-r] [_
\bn_
\ba_
\bm_
\be]
3071 For each _
\bn_
\ba_
\bm_
\be, the full pathname of the command is
3072 determined and remembered. The -r option causes the
3073 shell to forget all remembered locations. If no argu-
3074 ments are given, information about remembered commands
3075 is printed. An argument of -- disables option checking
3076 for the rest of the arguments. The return status is
3077 true unless a _
\bn_
\ba_
\bm_
\be is not found or an illegal option is
3080 help [_
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn]
3081 Display helpful information about builtin commands. If
3082 _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn is specified, help gives detailed help on all
3083 commands matching _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn; otherwise a list of the
3084 builtins is printed. The return status is 0 unless no
3085 command matches _
\bp_
\ba_
\bt_
\bt_
\be_
\br_
\bn.
3088 history -rwan [_
\bf_
\bi_
\bl_
\be_
\bn_
\ba_
\bm_
\be]
3089 With no options, display the command history list with
3090 line numbers. Lines listed with a * have been modi-
3091 fied. An argument of _
\bn lists only the last _
\bn lines.
3092 If a non-option argument is supplied, it is used as the
3093 name of the history file; if not, the value of HISTFILE
3094 is used. Options, if supplied, have the following
3099 GNU Last change: 1995 May 5 47
3106 BASH(1) USER COMMANDS BASH(1)
3110 -a Append the ``new'' history lines (history lines
3111 entered since the beginning of the current bash
3112 session) to the history file
3113 -n Read the history lines not already read from the
3114 history file into the current history list. These
3115 are lines appended to the history file since the
3116 beginning of the current bash session.
3117 -r Read the contents of the history file and use them
3118 as the current history
3119 -w Write the current history to the history file,
3120 overwriting the history file's contents.
3122 The return value is 0 unless an illegal option is
3123 encountered or an error occurs while reading or writing
3126 jobs [-lnp] [ _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc ... ]
3127 jobs -x _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd [ _
\ba_
\br_
\bg_
\bs ... ]
3128 The first form lists the active jobs. The -l option
3129 lists process IDs in addition to the normal informa-
3130 tion; the -p option lists only the process ID of the
3131 job's process group leader. The -n option displays
3132 only jobs that have changed status since last notified.
3133 If _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc is given, output is restricted to informa-
3134 tion about that job. The return status is 0 unless an
3135 illegal option is encountered or an illegal _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc is
3138 If the -x option is supplied, jobs replaces any _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc
3139 found in _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd or _
\ba_
\br_
\bg_
\bs with the corresponding process
3140 group ID, and executes _
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd passing it _
\ba_
\br_
\bg_
\bs, return-
3141 ing its exit status.
3143 kill [-s sigspec | -sigspec] [_
\bp_
\bi_
\bd | _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc] ...
3144 kill -l [_
\bs_
\bi_
\bg_
\bn_
\bu_
\bm]
3145 Send the signal named by _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc to the processes named
3146 by _
\bp_
\bi_
\bd or _
\bj_
\bo_
\bb_
\bs_
\bp_
\be_
\bc. _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc is either a signal name
3147 such as SIGKILL or a signal number. If _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc is a
3148 signal name, the name is case insensitive and may be
3149 given with or without the SIG prefix. If _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc is
3150 not present, then SIGTERM is assumed. An argument of
3151 -l lists the signal names. If any arguments are sup-
3152 plied when -l is given, the names of the specified sig-
3153 nals are listed, and the return status is 0. An argu-
3154 ment of -- disables option checking for the rest of the
3155 arguments. kill returns true if at least one signal
3156 was successfully sent, or false if an error occurs or
3157 an illegal option is encountered.
3159 let _
\ba_
\br_
\bg [_
\ba_
\br_
\bg ...]
3160 Each _
\ba_
\br_
\bg is an arithmetic expression to be evaluated
3161 (see ARITHMETIC EVALUATION). If the last _
\ba_
\br_
\bg evaluates
3165 GNU Last change: 1995 May 5 48
3172 BASH(1) USER COMMANDS BASH(1)
3176 to 0, let returns 1; 0 is returned otherwise.
3178 local [_
\bn_
\ba_
\bm_
\be[=_
\bv_
\ba_
\bl_
\bu_
\be] ...]
3179 For each argument, create a local variable named _
\bn_
\ba_
\bm_
\be,
3180 and assign it _
\bv_
\ba_
\bl_
\bu_
\be. When local is used within a func-
3181 tion, it causes the variable _
\bn_
\ba_
\bm_
\be to have a visible
3182 scope restricted to that function and its children.
3183 With no operands, local writes a list of local vari-
3184 ables to the standard output. It is an error to use
3185 local when not within a function. The return status is
3186 0 unless local is used outside a function, or an ille-
3187 gal _
\bn_
\ba_
\bm_
\be is supplied.
3193 Removes entries from the directory stack. With no
3194 arguments, removes the top directory from the stack,
3195 and performs a cd to the new top directory.
3196 +n removes the _
\bnth entry counting from the left of
3197 the list shown by dirs, starting with zero. For
3198 example: ``popd +0'' removes the first directory,
3199 ``popd +1'' the second.
3200 -n removes the _
\bnth entry counting from the right of
3201 the list shown by dirs, starting with zero. For
3202 example: ``popd -0'' removes the last directory,
3203 ``popd -1'' the next to last.
3205 If the popd command is successful, a dirs is performed
3206 as well, and the return status is 0. popd returns
3207 false if an illegal option is encountered, the direc-
3208 tory stack is empty, a non-existent directory stack
3209 entry is specified, or the directory change fails.
3211 pushd [_
\bd_
\bi_
\br]
3213 Adds a directory to the top of the directory stack, or
3214 rotates the stack, making the new top of the stack the
3215 current working directory. With no arguments,
3216 exchanges the top two directories and returns 0, unless
3217 the directory stack is empty.
3218 +n Rotates the stack so that the _
\bnth directory
3219 (counting from the left of the list shown by dirs)
3221 -n Rotates the stack so that the _
\bnth directory
3222 (counting from the right) is at the top.
3223 dir adds _
\bd_
\bi_
\br to the directory stack at the top, making
3224 it the new current working directory.
3226 If the pushd command is successful, a dirs is performed
3227 as well. If the first form is used, pushd returns 0
3231 GNU Last change: 1995 May 5 49
3238 BASH(1) USER COMMANDS BASH(1)
3242 unless the cd to _
\bd_
\bi_
\br fails. With the second form,
3243 pushd returns 0 unless the directory stack is empty, a
3244 non-existant directory stack element is specified, or
3245 the directory change to the specified new current
3248 pwd Print the absolute pathname of the current working
3249 directory. The path printed contains no symbolic links
3250 if the -P option to the set builtin command is set.
3251 See also the description of nolinks under Shell Vari-
3252 ables above). The return status is 0 unless an error
3253 occurs while reading the pathname of the current direc-
3256 read [-r] [_
\bn_
\ba_
\bm_
\be ...]
3257 One line is read from the standard input, and the first
3258 word is assigned to the first _
\bn_
\ba_
\bm_
\be, the second word to
3259 the second _
\bn_
\ba_
\bm_
\be, and so on, with leftover words
3260 assigned to the last _
\bn_
\ba_
\bm_
\be. Only the characters in IFS
3261 are recognized as word delimiters. If no _
\bn_
\ba_
\bm_
\be_
\bs are
3262 supplied, the line read is assigned to the variable
3263 REPLY. The return code is zero, unless end-of-file is
3264 encountered. If the -r option is given, a backslash-
3265 newline pair is not ignored, and the backslash is con-
3266 sidered to be part of the line.
3268 readonly [-f] [_
\bn_
\ba_
\bm_
\be ...]
3270 The given _
\bn_
\ba_
\bm_
\be_
\bs are marked readonly and the values of
3271 these _
\bn_
\ba_
\bm_
\be_
\bs may not be changed by subsequent assign-
3272 ment. If the -f option is supplied, the functions
3273 corresponding to the _
\bn_
\ba_
\bm_
\be_
\bs are so marked. If no argu-
3274 ments are given, or if the -p option is supplied, a
3275 list of all readonly names is printed. An argument of
3276 -- disables option checking for the rest of the argu-
3277 ments. The return status is 0 unless an illegal option
3278 is encountered, one of the _
\bn_
\ba_
\bm_
\be_
\bs is not a legal shell
3279 variable name, or -f is supplied with a _
\bn_
\ba_
\bm_
\be that is
3283 Causes a function to exit with the return value speci-
3284 fied by _
\bn. If _
\bn is omitted, the return status is that
3285 of the last command executed in the function body. If
3286 used outside a function, but during execution of a
3287 script by the . (source) command, it causes the shell
3288 to stop executing that script and return either _
\bn or
3289 the exit status of the last command executed within the
3290 script as the exit status of the script. If used out-
3291 side a function and not during execution of a script by
3292 ., the return status is false.
3297 GNU Last change: 1995 May 5 50
3304 BASH(1) USER COMMANDS BASH(1)
3308 set [--abefhkmnptuvxldCHP] [-o _
\bo_
\bp_
\bt_
\bi_
\bo_
\bn] [_
\ba_
\br_
\bg ...]
3309 -a Automatically mark variables which are modified
3310 or created for export to the environment of
3311 subsequent commands.
3312 -b Cause the status of terminated background jobs
3313 to be reported immediately, rather than before
3314 the next primary prompt. (Also see notify
3315 under Shell Variables above).
3316 -e Exit immediately if a _
\bs_
\bi_
\bm_
\bp_
\bl_
\be-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd (see SHELL
3317 GRAMMAR above) exits with a non-zero status.
3318 The shell does not exit if the command that
3319 fails is part of an _
\bu_
\bn_
\bt_
\bi_
\bl or _
\bw_
\bh_
\bi_
\bl_
\be loop, part
3320 of an _
\bi_
\bf statement, part of a && or || list, or
3321 if the command's return value is being inverted
3323 -f Disable pathname expansion.
3324 -h Locate and remember function commands as func-
3325 tions are defined. Function commands are nor-
3326 mally looked up when the function is executed.
3327 -k All keyword arguments are placed in the
3328 environment for a command, not just those that
3329 precede the command name.
3330 -m Monitor mode. Job control is enabled. This
3331 flag is on by default for interactive shells on
3332 systems that support it (see JOB CONTROL
3333 above). Background processes run in a separate
3334 process group and a line containing their exit
3335 status is printed upon their completion.
3336 -n Read commands but do not execute them. This
3337 may be used to check a shell script for syntax
3338 errors. This is ignored for interactive
3340 -o _
\bo_
\bp_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be
3341 The _
\bo_
\bp_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be can be one of the following:
3345 The shell performs brace expansion (see
3346 Brace Expansion above). This is on by
3348 emacs Use an emacs-style command line editing
3349 interface. This is enabled by default
3350 when the shell is interactive, unless
3351 the shell is started with the -nol-
3357 The effect is as if the shell command
3358 `IGNOREEOF=10' had been executed (see
3359 Shell Variables above).
3363 GNU Last change: 1995 May 5 51
3370 BASH(1) USER COMMANDS BASH(1)
3374 interactive-comments
3375 Allow a word beginning with # to cause
3376 that word and all remaining characters
3377 on that line to be ignored in an
3378 interactive shell (see COMMENTS above).
3389 posix Change the behavior of bash where the
3390 default operation differs from the
3391 Posix 1003.2 standard to match the
3396 vi Use a vi-style command line editing
3399 If no _
\bo_
\bp_
\bt_
\bi_
\bo_
\bn-_
\bn_
\ba_
\bm_
\be is supplied, the values of
3400 the current options are printed.
3401 -p Turn on _
\bp_
\br_
\bi_
\bv_
\bi_
\bl_
\be_
\bg_
\be_
\bd mode. In this mode, the
3402 $ENV file is not processed, and shell functions
3403 are not inherited from the environment. This
3404 is enabled automatically on startup if the
3405 effective user (group) id is not equal to the
3406 real user (group) id. Turning this option off
3407 causes the effective user and group ids to be
3408 set to the real user and group ids.
3409 -t Exit after reading and executing one command.
3410 -u Treat unset variables as an error when perform-
3411 ing parameter expansion. If expansion is
3412 attempted on an unset variable, the shell
3413 prints an error message, and, if not interac-
3414 tive, exits with a non-zero status.
3415 -v Print shell input lines as they are read.
3416 -x After expanding each _
\bs_
\bi_
\bm_
\bp_
\bl_
\be-_
\bc_
\bo_
\bm_
\bm_
\ba_
\bn_
\bd, bash
3417 displays the expanded value of PS4, followed by
3418 the command and its expanded arguments.
3419 -l Save and restore the binding of _
\bn_
\ba_
\bm_
\be in a for
3420 _
\bn_
\ba_
\bm_
\be [in word] command (see SHELL GRAMMAR
3422 -d Disable the hashing of commands that are looked
3423 up for execution. Normally, commands are
3424 remembered in a hash table, and once found, do
3425 not have to be looked up again.
3429 GNU Last change: 1995 May 5 52
3436 BASH(1) USER COMMANDS BASH(1)
3440 -C The effect is as if the shell command
3441 `noclobber=' had been executed (see Shell Vari-
3443 -H Enable ! style history substitution. This flag
3444 is on by default when the shell is interactive.
3445 -P If set, do not follow symbolic links when per-
3446 forming commands such as cd which change the
3447 current directory. The physical directory is
3449 -- If no arguments follow this flag, then the
3450 positional parameters are unset. Otherwise,
3451 the positional parameters are set to the _
\ba_
\br_
\bgs,
3452 even if some of them begin with a -.
3453 - Signal the end of options, cause all remaining
3454 _
\ba_
\br_
\bgs to be assigned to the positional parame-
3455 ters. The -x and -v options are turned off.
3456 If there are no _
\ba_
\br_
\bgs, the positional parameters
3459 The flags are off by default unless otherwise noted.
3460 Using + rather than - causes these flags to be turned
3461 off. The flags can also be specified as options to an
3462 invocation of the shell. The current set of flags may
3463 be found in $-. After the option arguments are pro-
3464 cessed, the remaining _
\bn _
\ba_
\br_
\bgs are treated as values for
3465 the positional parameters and are assigned, in order,
3466 to $1, $2, ... $_
\bn. If no options or _
\ba_
\br_
\bgs are supplied,
3467 all shell variables are printed. The return status is
3468 always true unless an illegal option is encountered.
3471 The positional parameters from _
\bn+1 ... are renamed to
3472 $1 .... Parameters represented by the numbers $# down
3473 to $#-_
\bn+1 are unset. If _
\bn is 0, no parameters are
3474 changed. If _
\bn is not given, it is assumed to be 1. _
\bn
3475 must be a non-negative number less than or equal to $#.
3476 If _
\bn is greater than $#, the positional parameters are
3477 not changed. The return status is greater than 0 if _
\bn
3478 is greater than $# or less than 0; otherwise 0.
3481 Suspend the execution of this shell until it receives a
3482 SIGCONT signal. The -f option says not to complain if
3483 this is a login shell; just suspend anyway. The return
3484 status is 0 unless the shell is a login shell and -f is
3485 not supplied, or if job control is not enabled.
3487 test _
\be_
\bx_
\bp_
\br
3488 [ _
\be_
\bx_
\bp_
\br ]
3489 Return a status of 0 (true) or 1 (false) depending on
3490 the evaluation of the conditional expression _
\be_
\bx_
\bp_
\br.
3491 Expressions may be unary or binary. Unary expressions
3495 GNU Last change: 1995 May 5 53
3502 BASH(1) USER COMMANDS BASH(1)
3506 are often used to examine the status of a file. There
3507 are string operators and numeric comparison operators
3508 as well. Each operator and operand must be a separate
3509 argument. If _
\bf_
\bi_
\bl_
\be is of the form /dev/fd/_
\bn, then file
3510 descriptor _
\bn is checked.
3512 True if _
\bf_
\bi_
\bl_
\be exists and is block special.
3514 True if _
\bf_
\bi_
\bl_
\be exists and is character special.
3516 True if _
\bf_
\bi_
\bl_
\be exists and is a directory.
3518 True if _
\bf_
\bi_
\bl_
\be exists.
3520 True if _
\bf_
\bi_
\bl_
\be exists and is a regular file.
3522 True if _
\bf_
\bi_
\bl_
\be exists and is set-group-id.
3524 True if _
\bf_
\bi_
\bl_
\be has its ``sticky'' bit set.
3526 True if _
\bf_
\bi_
\bl_
\be exists and is a symbolic link.
3528 True if _
\bf_
\bi_
\bl_
\be exists and is a named pipe.
3530 True if _
\bf_
\bi_
\bl_
\be exists and is readable.
3532 True if _
\bf_
\bi_
\bl_
\be exists and has a size greater than
3535 True if _
\bf_
\bi_
\bl_
\be exists and is a socket.
3537 True if _
\bf_
\bd is opened on a terminal.
3539 True if _
\bf_
\bi_
\bl_
\be exists and its set-user-id bit is
3542 True if _
\bf_
\bi_
\bl_
\be exists and is writable.
3544 True if _
\bf_
\bi_
\bl_
\be exists and is executable.
3546 True if _
\bf_
\bi_
\bl_
\be exists and is owned by the effective
3549 True if _
\bf_
\bi_
\bl_
\be exists and is owned by the effective
3551 _
\bf_
\bi_
\bl_
\be_
\b1 -nt _
\bf_
\bi_
\bl_
\be_
\b2
3552 True if _
\bf_
\bi_
\bl_
\be_
\b1 is newer (according to modification
3553 date) than _
\bf_
\bi_
\bl_
\be_
\b2.
3554 _
\bf_
\bi_
\bl_
\be_
\b1 -ot _
\bf_
\bi_
\bl_
\be_
\b2
3555 True if _
\bf_
\bi_
\bl_
\be_
\b1 is older than file2.
3556 _
\bf_
\bi_
\bl_
\be_
\b1 -ef _
\bf_
\bi_
\bl_
\be
3557 True if _
\bf_
\bi_
\bl_
\be_
\b1 and _
\bf_
\bi_
\bl_
\be_
\b2 have the same device and
3561 GNU Last change: 1995 May 5 54
3568 BASH(1) USER COMMANDS BASH(1)
3573 -z _
\bs_
\bt_
\br_
\bi_
\bn_
\bg
3574 True if the length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is zero.
3575 -n _
\bs_
\bt_
\br_
\bi_
\bn_
\bg
3576 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg
3577 True if the length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg is non-zero.
3578 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 = _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2
3579 True if the strings are equal.
3580 _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b1 != _
\bs_
\bt_
\br_
\bi_
\bn_
\bg_
\b2
3581 True if the strings are not equal.
3583 True if _
\be_
\bx_
\bp_
\br is false.
3584 _
\be_
\bx_
\bp_
\br_
\b1 -a _
\be_
\bx_
\bp_
\br_
\b2
3585 True if both _
\be_
\bx_
\bp_
\br_
\b1 AND _
\be_
\bx_
\bp_
\br_
\b2 are true.
3586 _
\be_
\bx_
\bp_
\br_
\b1 -o _
\be_
\bx_
\bp_
\br_
\b2
3587 True if either _
\be_
\bx_
\bp_
\br_
\b1 OR _
\be_
\bx_
\bp_
\br_
\b2 is true.
3588 _
\ba_
\br_
\bg_
\b1 OP _
\ba_
\br_
\bg_
\b2
3589 OP is one of -eq, -ne, -lt, -le, -gt, or -ge.
3590 These arithmetic binary operators return true if
3591 _
\ba_
\br_
\bg_
\b1 is equal, not-equal, less-than, less-than-
3592 or-equal, greater-than, or greater-than-or-equal
3593 than _
\ba_
\br_
\bg_
\b2, respectively. _
\bA_
\br_
\bg_
\b1 and _
\ba_
\br_
\bg_
\b2 may be
3594 positive integers, negative integers, or the spe-
3595 cial expression -l _
\bs_
\bt_
\br_
\bi_
\bn_
\bg, which evaluates to the
3596 length of _
\bs_
\bt_
\br_
\bi_
\bn_
\bg.
3599 Print the accumulated user and system times for the
3600 shell and for processes run from the shell. The return
3603 trap [-l] [_
\ba_
\br_
\bg] [_
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc]
3604 The command _
\ba_
\br_
\bg is to be read and executed when the
3605 shell receives signal(s) _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc. If _
\ba_
\br_
\bg is absent or
3606 -, all specified signals are reset to their original
3607 values (the values they had upon entrance to the
3608 shell). If _
\ba_
\br_
\bg is the null string this signal is
3609 ignored by the shell and by the commands it invokes.
3610 _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc is either a signal name defined in <_
\bs_
\bi_
\bg_
\bn_
\ba_
\bl._
\bh>,
3611 or a signal number. If _
\bs_
\bi_
\bg_
\bs_
\bp_
\be_
\bc is EXIT (0) the command
3612 _
\ba_
\br_
\bg is executed on exit from the shell. With no argu-
3613 ments, trap prints the list of commands associated with
3614 each signal number. The -l option causes the shell to
3615 print a list of signal names and their corresponding
3616 numbers. An argument of -- disables option checking
3617 for the rest of the arguments. Signals ignored upon
3618 entry to the shell cannot be trapped or reset. Trapped
3619 signals are reset to their original values in a child
3620 process when it is created. The return status is false
3621 if either the trap name or number is invalid; otherwise
3627 GNU Last change: 1995 May 5 55
3634 BASH(1) USER COMMANDS BASH(1)
3638 type [-all] [-type | -path] _
\bn_
\ba_
\bm_
\be [_
\bn_
\ba_
\bm_
\be ...]
3639 With no options, indicate how each _
\bn_
\ba_
\bm_
\be would be inter-
3640 preted if used as a command name. If the -type flag is
3641 used, type prints a phrase which is one of _
\ba_
\bl_
\bi_
\ba_
\bs, _
\bk_
\be_
\by_
\b-
3642 _
\bw_
\bo_
\br_
\bd, _
\bf_
\bu_
\bn_
\bc_
\bt_
\bi_
\bo_
\bn, _
\bb_
\bu_
\bi_
\bl_
\bt_
\bi_
\bn, or _
\bf_
\bi_
\bl_
\be if _
\bn_
\ba_
\bm_
\be is an alias,
3643 shell reserved word, function, builtin, or disk file,
3644 respectively. If the name is not found, then nothing is
3645 printed, and an exit status of false is returned. If
3646 the -path flag is used, type either returns the name of
3647 the disk file that would be executed if _
\bn_
\ba_
\bm_
\be were
3648 specified as a command name, or nothing if -type would
3649 not return _
\bf_
\bi_
\bl_
\be. If a command is hashed, -path prints
3650 the hashed value, not necessarily the file that appears
3651 first in PATH. If the -all flag is used, type prints
3652 all of the places that contain an executable named
3653 _
\bn_
\ba_
\bm_
\be. This includes aliases and functions, if and only
3654 if the -path flag is not also used. The table of
3655 hashed commands is not consulted when using -all. type
3656 accepts -a, -t, and -p in place of -all, -type, and
3657 -path, respectively. An argument of -- disables option
3658 checking for the rest of the arguments. type returns
3659 true if any of the arguments are found, false if none
3662 ulimit [-SHacdfmstpnuv [_
\bl_
\bi_
\bm_
\bi_
\bt]]
3663 Ulimit provides control over the resources available to
3664 the shell and to processes started by it, on systems
3665 that allow such control. The value of _
\bl_
\bi_
\bm_
\bi_
\bt can be a
3666 number in the unit specified for the resource, or the
3667 value unlimited. The H and S options specify that the
3668 hard or soft limit is set for the given resource. A
3669 hard limit cannot be increased once it is set; a soft
3670 limit may be increased up to the value of the hard
3671 limit. If neither H nor S is specified, the command
3672 applies to the soft limit. If _
\bl_
\bi_
\bm_
\bi_
\bt is omitted, the
3673 current value of the soft limit of the resource is
3674 printed, unless the H option is given. When more than
3675 one resource is specified, the limit name and unit is
3676 printed before the value. Other options are inter-
3678 -a all current limits are reported
3679 -c the maximum size of core files created
3680 -d the maximum size of a process's data segment
3681 -f the maximum size of files created by the shell
3682 -m the maximum resident set size
3683 -s the maximum stack size
3684 -t the maximum amount of cpu time in seconds
3685 -p the pipe size in 512-byte blocks (this may not be
3687 -n the maximum number of open file descriptors (most
3688 systems do not allow this value to be set, only
3693 GNU Last change: 1995 May 5 56
3700 BASH(1) USER COMMANDS BASH(1)
3704 -u the maximum number of processes available to a
3706 -v The maximum amount of virtual memory available to
3709 An argument of -- disables option checking for the rest
3710 of the arguments. If _
\bl_
\bi_
\bm_
\bi_
\bt is given, it is the new
3711 value of the specified resource (the -a option is
3712 display only). If no option is given, then -f is
3713 assumed. Values are in 1024-byte increments, except
3714 for -t, which is in seconds, -p, which is in units of
3715 512-byte blocks, and -n and -u, which are unscaled
3716 values. The return status is 0 unless an illegal
3717 option is encountered, a non-numeric argument other
3718 than unlimited is supplied as _
\bl_
\bi_
\bm_
\bi_
\bt, or an error occurs
3719 while setting a new limit.
3721 umask [-S] [_
\bm_
\bo_
\bd_
\be]
3722 The user file-creation mask is set to _
\bm_
\bo_
\bd_
\be. If _
\bm_
\bo_
\bd_
\be
3723 begins with a digit, it is interpreted as an octal
3724 number; otherwise it is interpreted as a symbolic mode
3725 mask similar to that accepted by _
\bc_
\bh_
\bm_
\bo_
\bd(1). If _
\bm_
\bo_
\bd_
\be is
3726 omitted, or if the -S option is supplied, the current
3727 value of the mask is printed. The -S option causes the
3728 mask to be printed in symbolic form; the default output
3729 is an octal number. An argument of -- disables option
3730 checking for the rest of the arguments. The return
3731 status is 0 if the mode was successfully changed or if
3732 no _
\bm_
\bo_
\bd_
\be argument was supplied, and false otherwise.
3734 unalias [-a] [_
\bn_
\ba_
\bm_
\be ...]
3735 Remove _
\bn_
\ba_
\bm_
\bes from the list of defined aliases. If -a
3736 is supplied, all alias definitions are removed. The
3737 return value is true unless a supplied _
\bn_
\ba_
\bm_
\be is not a
3740 unset [-fv] [_
\bn_
\ba_
\bm_
\be ...]
3741 For each _
\bn_
\ba_
\bm_
\be, remove the corresponding variable or,
3742 given the -f option, function. An argument of -- dis-
3743 ables option checking for the rest of the arguments.
3744 Note that PATH, IFS, PPID, PS1, PS2, UID, and EUID can-
3745 not be unset. If any of RANDOM, SECONDS, LINENO, or
3746 HISTCMD are unset, they lose their special properties,
3747 even if they are subsequently reset. The exit status
3748 is true unless a _
\bn_
\ba_
\bm_
\be does not exist or is non-
3752 Wait for the specified process and return its termina-
3753 tion status. _
\bn may be a process ID or a job specifica-
3754 tion; if a job spec is given, all processes in that
3755 job's pipeline are waited for. If _
\bn is not given, all
3759 GNU Last change: 1995 May 5 57
3766 BASH(1) USER COMMANDS BASH(1)
3770 currently active child processes are waited for, and
3771 the return status is zero. If _
\bn specifies a non-
3772 existant process or job, the return status is 127.
3773 Otherwise, the return status is the exit status of the
3774 last process or job waited for.
3777 A _
\bl_
\bo_
\bg_
\bi_
\bn _
\bs_
\bh_
\be_
\bl_
\bl is one whose first character of argument zero
3778 is a -, or one started with the -login flag.
3780 An _
\bi_
\bn_
\bt_
\be_
\br_
\ba_
\bc_
\bt_
\bi_
\bv_
\be shell is one whose standard input and output
3781 are both connected to terminals (as determined by
3782 _
\bi_
\bs_
\ba_
\bt_
\bt_
\by(3)), or one started with the -i option. PS1 is set
3783 and $- includes i if bash is interactive, allowing a shell
3784 script or a startup file to test this state.
3787 On login (subject to the -noprofile option):
3788 if /_
\be_
\bt_
\bc/_
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be exists, source it.
3790 if ~/._
\bb_
\ba_
\bs_
\bh__
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be exists, source it,
3791 else if ~/._
\bb_
\ba_
\bs_
\bh__
\bl_
\bo_
\bg_
\bi_
\bn exists, source it,
3792 else if ~/._
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be exists, source it.
3795 if ~/._
\bb_
\ba_
\bs_
\bh__
\bl_
\bo_
\bg_
\bo_
\bu_
\bt exists, source it.
3797 Non-login interactive shells:
3798 On startup (subject to the -norc and -rcfile options):
3799 if ~/._
\bb_
\ba_
\bs_
\bh_
\br_
\bc exists, source it.
3801 Non-interactive shells:
3803 if the environment variable ENV is non-null, expand
3804 it and source the file it names, as if the command
3805 if [ "$ENV" ]; then . $ENV; fi
3806 had been executed, but do not use PATH to search
3807 for the pathname. When not started in Posix mode, bash
3808 looks for BASH_ENV before ENV.
3810 If Bash is invoked as sh, it tries to mimic the behavior of
3811 sh as closely as possible. For a login shell, it attempts
3812 to source only /_
\be_
\bt_
\bc/_
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be and ~/._
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be, in that order.
3813 The -noprofile option may still be used to disable this
3814 behavior. A shell invoked as sh does not attempt to source
3815 any other startup files.
3817 When bash is started in _
\bp_
\bo_
\bs_
\bi_
\bx mode, as with the -posix com-
3818 mand line option, it follows the Posix standard for startup
3819 files. In this mode, the ENV variable is expanded and that
3820 file sourced; no other startup files are read.
3825 GNU Last change: 1995 May 5 58
3832 BASH(1) USER COMMANDS BASH(1)
3837 _
\bB_
\ba_
\bs_
\bh _
\bF_
\be_
\ba_
\bt_
\bu_
\br_
\be_
\bs, Brian Fox and Chet Ramey
3838 _
\bT_
\bh_
\be _
\bG_
\bn_
\bu _
\bR_
\be_
\ba_
\bd_
\bl_
\bi_
\bn_
\be _
\bL_
\bi_
\bb_
\br_
\ba_
\br_
\by, Brian Fox and Chet Ramey
3839 _
\bT_
\bh_
\be _
\bG_
\bn_
\bu _
\bH_
\bi_
\bs_
\bt_
\bo_
\br_
\by _
\bL_
\bi_
\bb_
\br_
\ba_
\br_
\by, Brian Fox and Chet Ramey
3841 _
\bA _
\bS_
\by_
\bs_
\bt_
\be_
\bm _
\bV _
\bC_
\bo_
\bm_
\bp_
\ba_
\bt_
\bi_
\bb_
\bl_
\be _
\bI_
\bm_
\bp_
\bl_
\be_
\bm_
\be_
\bn_
\bt_
\ba_
\bt_
\bi_
\bo_
\bn _
\bo_
\bf _
\b4._
\b2_
\bB_
\bS_
\bD _
\bJ_
\bo_
\bb _
\bC_
\bo_
\bn_
\bt_
\br_
\bo_
\bl, David
3842 _
\bU_
\bt_
\bi_
\bl_
\bi_
\bt_
\bi_
\be_
\bs, IEEE
3843 _
\bP_
\bo_
\br_
\bt_
\ba_
\bb_
\bl_
\be _
\bO_
\bp_
\be_
\br_
\ba_
\bt_
\bi_
\bn_
\bg _
\bS_
\by_
\bs_
\bt_
\be_
\bm _
\bI_
\bn_
\bt_
\be_
\br_
\bf_
\ba_
\bc_
\be (_
\bP_
\bO_
\bS_
\bI_
\bX) _
\bP_
\ba_
\br_
\bt _
\b2: _
\bS_
\bh_
\be_
\bl_
\bl _
\ba_
\bn_
\bd
3844 _
\bs_
\bh(1), _
\bk_
\bs_
\bh(1), _
\bc_
\bs_
\bh(1)
3845 _
\be_
\bm_
\ba_
\bc_
\bs(1), _
\bv_
\bi(1)
3846 _
\br_
\be_
\ba_
\bd_
\bl_
\bi_
\bn_
\be(3)
3849 /_
\bb_
\bi_
\bn/_
\bb_
\ba_
\bs_
\bh
3851 /_
\be_
\bt_
\bc/_
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be
3852 The systemwide initialization file, executed for login
3854 ~/._
\bb_
\ba_
\bs_
\bh__
\bp_
\br_
\bo_
\bf_
\bi_
\bl_
\be
3855 The personal initialization file, executed for login
3857 ~/._
\bb_
\ba_
\bs_
\bh_
\br_
\bc
3858 The individual per-interactive-shell startup file
3859 ~/._
\bi_
\bn_
\bp_
\bu_
\bt_
\br_
\bc
3860 Individual _
\br_
\be_
\ba_
\bd_
\bl_
\bi_
\bn_
\be initialization file
3863 Brian Fox, Free Software Foundation (primary author)
3866 Chet Ramey, Case Western Reserve University
3870 If you find a bug in bash, you should report it. But first,
3871 you should make sure that it really is a bug, and that it
3872 appears in the latest version of bash that you have.
3874 Once you have determined that a bug actually exists, use the
3875 _
\bb_
\ba_
\bs_
\bh_
\bb_
\bu_
\bg command to submit a bug report. If you have a fix,
3876 you are welcome to mail that as well! Suggestions and `phi-
3877 losophical' bug reports may be mailed to _
\bb_
\bu_
\bg-
3878 _
\bb_
\ba_
\bs_
\bh@_
\bp_
\br_
\be_
\bp._
\ba_
\bi._
\bM_
\bI_
\bT._
\bE_
\bd_
\bu or posted to the Usenet newsgroup
3881 ALL bug reports should include:
3883 The version number of bash
3884 The hardware and operating system
3885 The compiler used to compile
3886 A description of the bug behaviour
3887 A short script or `recipe' which exercises the bug
3891 GNU Last change: 1995 May 5 59
3898 BASH(1) USER COMMANDS BASH(1)
3902 _
\bb_
\ba_
\bs_
\bh_
\bb_
\bu_
\bg inserts the first three items automatically into the
3903 template it provides for filing a bug report.
3905 Comments and bug reports concerning this manual page should
3906 be directed to _
\bc_
\bh_
\be_
\bt@_
\bi_
\bn_
\bs._
\bC_
\bW_
\bR_
\bU._
\bE_
\bd_
\bu.
3909 It's too big and too slow.
3911 There are some subtle differences between bash and tradi-
3912 tional versions of sh, mostly because of the POSIX specifi-
3915 Aliases are confusing in some uses.
3957 GNU Last change: 1995 May 5 60