Linux: bash builtin commands(fedora38-GNU Bash 5.2)
1. bash builtin commands(fedora38-GNU Bash 5.2)
1 BASH_BUILTINS(1) General Commands Manual BASH_BUILTINS(1)
2
3 NAME
4 :, ., [, alias, bg, bind, break, builtin, caller, cd, command, compgen, complete, compopt, continue, declare, dirs, disown, echo,
5 enable, eval, exec, exit, export, false, fc, fg, getopts, hash, help, history, jobs, kill, let, local, logout, mapfile, popd,
6 printf, pushd, pwd, read, readarray, readonly, return, set, shift, shopt, source, suspend, test, times, trap, true, type, typeset,
7 ulimit, umask, unalias, unset, wait - bash built-in commands, see bash(1)
8
9 BASH BUILTIN COMMANDS
10 Unless otherwise noted, each builtin command documented in this section as accepting options preceded by - accepts -- to signify the
11 end of the options. The :, true, false, and test/[ builtins do not accept options and do not treat -- specially. The exit, logout,
12 return, break, continue, let, and shift builtins accept and process arguments beginning with - without requiring --. Other builtins
13 that accept arguments but are not specified as accepting options interpret arguments beginning with - as invalid options and require
14 -- to prevent this interpretation.
15 : [arguments]
16 No effect; the command does nothing beyond expanding arguments and performing any specified redirections. The return status
17 is zero.
18
19 . filename [arguments]
20 source filename [arguments]
21 Read and execute commands from filename in the current shell environment and return the exit status of the last command exe‐
22 cuted from filename. If filename does not contain a slash, filenames in PATH are used to find the directory containing file‐
23 name, but filename does not need to be executable. The file searched for in PATH need not be executable. When bash is not
24 in posix mode, it searches the current directory if no file is found in PATH. If the sourcepath option to the shopt builtin
25 command is turned off, the PATH is not searched. If any arguments are supplied, they become the positional parameters when
26 filename is executed. Otherwise the positional parameters are unchanged. If the -T option is enabled, . inherits any trap
27 on DEBUG; if it is not, any DEBUG trap string is saved and restored around the call to ., and . unsets the DEBUG trap while
28 it executes. If -T is not set, and the sourced file changes the DEBUG trap, the new value is retained when . completes. The
29 return status is the status of the last command exited within the script (0 if no commands are executed), and false if file‐
30 name is not found or cannot be read.
31
32 alias [-p] [name[=value] ...]
33 Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output.
34 When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the
35 next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no
36 value is supplied, the name and value of the alias is printed. Alias returns true unless a name is given for which no alias
37 has been defined.
38
39 bg [jobspec ...]
40 Resume each suspended job jobspec in the background, as if it had been started with &. If jobspec is not present, the
41 shell's notion of the current job is used. bg jobspec returns 0 unless run when job control is disabled or, when run with
42 job control enabled, any specified jobspec was not found or was started without job control.
43
44 bind [-m keymap] [-lpsvPSVX]
45 bind [-m keymap] [-q function] [-u function] [-r keyseq]
46 bind [-m keymap] -f filename
47 bind [-m keymap] -x keyseq:shell-command
48 bind [-m keymap] keyseq:function-name
49 bind [-m keymap] keyseq:readline-command
50 bind readline-command-line
51 Display current readline key and function bindings, bind a key sequence to a readline function or macro, or set a readline
52 variable. Each non-option argument is a command as it would appear in a readline initialization file such as .inputrc, but
53 each binding or command must be passed as a separate argument; e.g., '"\C-x\C-r": re-read-init-file'. Options, if supplied,
54 have the following meanings:
55 -m keymap
56 Use keymap as the keymap to be affected by the subsequent bindings. Acceptable keymap names are emacs, emacs-stan‐
57 dard, emacs-meta, emacs-ctlx, vi, vi-move, vi-command, and vi-insert. vi is equivalent to vi-command (vi-move is also
58 a synonym); emacs is equivalent to emacs-standard.
59 -l List the names of all readline functions.
60 -p Display readline function names and bindings in such a way that they can be re-read.
61 -P List current readline function names and bindings.
62 -s Display readline key sequences bound to macros and the strings they output in such a way that they can be re-read.
63 -S Display readline key sequences bound to macros and the strings they output.
64 -v Display readline variable names and values in such a way that they can be re-read.
65 -V List current readline variable names and values.
66 -f filename
67 Read key bindings from filename.
68 -q function
69 Query about which keys invoke the named function.
70 -u function
71 Unbind all keys bound to the named function.
72 -r keyseq
73 Remove any current binding for keyseq.
74 -x keyseq:shell-command
75 Cause shell-command to be executed whenever keyseq is entered. When shell-command is executed, the shell sets the
76 READLINE_LINE variable to the contents of the readline line buffer and the READLINE_POINT and READLINE_MARK variables
77 to the current location of the insertion point and the saved insertion point (the mark), respectively. The shell as‐
78 signs any numeric argument the user supplied to the READLINE_ARGUMENT variable. If there was no argument, that vari‐
79 able is not set. If the executed command changes the value of any of READLINE_LINE, READLINE_POINT, or READLINE_MARK,
80 those new values will be reflected in the editing state.
81 -X List all key sequences bound to shell commands and the associated commands in a format that can be reused as input.
82
83 The return value is 0 unless an unrecognized option is given or an error occurred.
84
85 break [n]
86 Exit from within a for, while, until, or select loop. If n is specified, break n levels. n must be ≥ 1. If n is greater
87 than the number of enclosing loops, all enclosing loops are exited. The return value is 0 unless n is not greater than or
88 equal to 1.
89
90 builtin shell-builtin [arguments]
91 Execute the specified shell builtin, passing it arguments, and return its exit status. This is useful when defining a func‐
92 tion whose name is the same as a shell builtin, retaining the functionality of the builtin within the function. The cd
93 builtin is commonly redefined this way. The return status is false if shell-builtin is not a shell builtin command.
94
95 caller [expr]
96 Returns the context of any active subroutine call (a shell function or a script executed with the . or source builtins).
97 Without expr, caller displays the line number and source filename of the current subroutine call. If a non-negative integer
98 is supplied as expr, caller displays the line number, subroutine name, and source file corresponding to that position in the
99 current execution call stack. This extra information may be used, for example, to print a stack trace. The current frame is
100 frame 0. The return value is 0 unless the shell is not executing a subroutine call or expr does not correspond to a valid
101 position in the call stack.
102
103 cd [-L|[-P [-e]] [-@]] [dir]
104 Change the current directory to dir. if dir is not supplied, the value of the HOME shell variable is the default. The vari‐
105 able CDPATH defines the search path for the directory containing dir: each directory name in CDPATH is searched for dir. Al‐
106 ternative directory names in CDPATH are separated by a colon (:). A null directory name in CDPATH is the same as the current
107 directory, i.e., ``.''. If dir begins with a slash (/), then CDPATH is not used. The -P option causes cd to use the physi‐
108 cal directory structure by resolving symbolic links while traversing dir and before processing instances of .. in dir (see
109 also the -P option to the set builtin command); the -L option forces symbolic links to be followed by resolving the link af‐
110 ter processing instances of .. in dir. If .. appears in dir, it is processed by removing the immediately previous pathname
111 component from dir, back to a slash or the beginning of dir. If the -e option is supplied with -P, and the current working
112 directory cannot be successfully determined after a successful directory change, cd will return an unsuccessful status. On
113 systems that support it, the -@ option presents the extended attributes associated with a file as a directory. An argument
114 of - is converted to $OLDPWD before the directory change is attempted. If a non-empty directory name from CDPATH is used, or
115 if - is the first argument, and the directory change is successful, the absolute pathname of the new working directory is
116 written to the standard output. If the directory change is successful, cd sets the value of the PWD environment variable to
117 the new directory name, and sets the OLDPWD environment variable to the value of the current working directory before the
118 change. The return value is true if the directory was successfully changed; false otherwise.
119
120 command [-pVv] command [arg ...]
121 Run command with args suppressing the normal shell function lookup. Only builtin commands or commands found in the PATH are
122 executed. If the -p option is given, the search for command is performed using a default value for PATH that is guaranteed
123 to find all of the standard utilities. If either the -V or -v option is supplied, a description of command is printed. The
124 -v option causes a single word indicating the command or filename used to invoke command to be displayed; the -V option pro‐
125 duces a more verbose description. If the -V or -v option is supplied, the exit status is 0 if command was found, and 1 if
126 not. If neither option is supplied and an error occurred or command cannot be found, the exit status is 127. Otherwise, the
127 exit status of the command builtin is the exit status of command.
128
129 compgen [option] [word]
130 Generate possible completion matches for word according to the options, which may be any option accepted by the complete
131 builtin with the exception of -p and -r, and write the matches to the standard output. When using the -F or -C options, the
132 various shell variables set by the programmable completion facilities, while available, will not have useful values.
133
134 The matches will be generated in the same way as if the programmable completion code had generated them directly from a com‐
135 pletion specification with the same flags. If word is specified, only those completions matching word will be displayed.
136
137 The return value is true unless an invalid option is supplied, or no matches were generated.
138
139 complete [-abcdefgjksuv] [-o comp-option] [-DEI] [-A action] [-G globpat] [-W wordlist]
140 [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] name [name ...]
141 complete -pr [-DEI] [name ...]
142 Specify how arguments to each name should be completed. If the -p option is supplied, or if no options are supplied, exist‐
143 ing completion specifications are printed in a way that allows them to be reused as input. The -r option removes a comple‐
144 tion specification for each name, or, if no names are supplied, all completion specifications. The -D option indicates that
145 other supplied options and actions should apply to the ``default'' command completion; that is, completion attempted on a
146 command for which no completion has previously been defined. The -E option indicates that other supplied options and actions
147 should apply to ``empty'' command completion; that is, completion attempted on a blank line. The -I option indicates that
148 other supplied options and actions should apply to completion on the initial non-assignment word on the line, or after a com‐
149 mand delimiter such as ; or |, which is usually command name completion. If multiple options are supplied, the -D option
150 takes precedence over -E, and both take precedence over -I. If any of -D, -E, or -I are supplied, any other name arguments
151 are ignored; these completions only apply to the case specified by the option.
152
153 The process of applying these completion specifications when word completion is attempted is described in bash(1).
154
155 Other options, if specified, have the following meanings. The arguments to the -G, -W, and -X options (and, if necessary,
156 the -P and -S options) should be quoted to protect them from expansion before the complete builtin is invoked.
157 -o comp-option
158 The comp-option controls several aspects of the compspec's behavior beyond the simple generation of completions.
159 comp-option may be one of:
160 bashdefault
161 Perform the rest of the default bash completions if the compspec generates no matches.
162 default Use readline's default filename completion if the compspec generates no matches.
163 dirnames
164 Perform directory name completion if the compspec generates no matches.
165 filenames
166 Tell readline that the compspec generates filenames, so it can perform any filename-specific processing (like
167 adding a slash to directory names, quoting special characters, or suppressing trailing spaces). Intended to
168 be used with shell functions.
169 noquote Tell readline not to quote the completed words if they are filenames (quoting filenames is the default).
170 nosort Tell readline not to sort the list of possible completions alphabetically.
171 nospace Tell readline not to append a space (the default) to words completed at the end of the line.
172 plusdirs
173 After any matches defined by the compspec are generated, directory name completion is attempted and any
174 matches are added to the results of the other actions.
175 -A action
176 The action may be one of the following to generate a list of possible completions:
177 alias Alias names. May also be specified as -a.
178 arrayvar
179 Array variable names.
180 binding Readline key binding names.
181 builtin Names of shell builtin commands. May also be specified as -b.
182 command Command names. May also be specified as -c.
183 directory
184 Directory names. May also be specified as -d.
185 disabled
186 Names of disabled shell builtins.
187 enabled Names of enabled shell builtins.
188 export Names of exported shell variables. May also be specified as -e.
189 file File names. May also be specified as -f.
190 function
191 Names of shell functions.
192 group Group names. May also be specified as -g.
193 helptopic
194 Help topics as accepted by the help builtin.
195 hostname
196 Hostnames, as taken from the file specified by the HOSTFILE shell variable.
197 job Job names, if job control is active. May also be specified as -j.
198 keyword Shell reserved words. May also be specified as -k.
199 running Names of running jobs, if job control is active.
200 service Service names. May also be specified as -s.
201 setopt Valid arguments for the -o option to the set builtin.
202 shopt Shell option names as accepted by the shopt builtin.
203 signal Signal names.
204 stopped Names of stopped jobs, if job control is active.
205 user User names. May also be specified as -u.
206 variable
207 Names of all shell variables. May also be specified as -v.
208 -C command
209 command is executed in a subshell environment, and its output is used as the possible completions. Arguments are
210 passed as with the -F option.
211 -F function
212 The shell function function is executed in the current shell environment. When the function is executed, the first
213 argument ($1) is the name of the command whose arguments are being completed, the second argument ($2) is the word
214 being completed, and the third argument ($3) is the word preceding the word being completed on the current command
215 line. When it finishes, the possible completions are retrieved from the value of the COMPREPLY array variable.
216 -G globpat
217 The pathname expansion pattern globpat is expanded to generate the possible completions.
218 -P prefix
219 prefix is added at the beginning of each possible completion after all other options have been applied.
220 -S suffix
221 suffix is appended to each possible completion after all other options have been applied.
222 -W wordlist
223 The wordlist is split using the characters in the IFS special variable as delimiters, and each resultant word is ex‐
224 panded. Shell quoting is honored within wordlist, in order to provide a mechanism for the words to contain shell
225 metacharacters or characters in the value of IFS. The possible completions are the members of the resultant list
226 which match the word being completed.
227 -X filterpat
228 filterpat is a pattern as used for pathname expansion. It is applied to the list of possible completions generated
229 by the preceding options and arguments, and each completion matching filterpat is removed from the list. A leading !
230 in filterpat negates the pattern; in this case, any completion not matching filterpat is removed.
231
232 The return value is true unless an invalid option is supplied, an option other than -p or -r is supplied without a name argu‐
233 ment, an attempt is made to remove a completion specification for a name for which no specification exists, or an error oc‐
234 curs adding a completion specification.
235
236 compopt [-o option] [-DEI] [+o option] [name]
237 Modify completion options for each name according to the options, or for the currently-executing completion if no names are
238 supplied. If no options are given, display the completion options for each name or the current completion. The possible
239 values of option are those valid for the complete builtin described above. The -D option indicates that other supplied op‐
240 tions should apply to the ``default'' command completion; that is, completion attempted on a command for which no completion
241 has previously been defined. The -E option indicates that other supplied options should apply to ``empty'' command comple‐
242 tion; that is, completion attempted on a blank line. The -I option indicates that other supplied options should apply to
243 completion on the initial non-assignment word on the line, or after a command delimiter such as ; or |, which is usually com‐
244 mand name completion.
245
246 The return value is true unless an invalid option is supplied, an attempt is made to modify the options for a name for which
247 no completion specification exists, or an output error occurs.
248
249 continue [n]
250 Resume the next iteration of the enclosing for, while, until, or select loop. If n is specified, resume at the nth enclosing
251 loop. n must be ≥ 1. If n is greater than the number of enclosing loops, the last enclosing loop (the ``top-level'' loop)
252 is resumed. The return value is 0 unless n is not greater than or equal to 1.
253
254 declare [-aAfFgiIlnrtux] [-p] [name[=value] ...]
255 typeset [-aAfFgiIlnrtux] [-p] [name[=value] ...]
256 Declare variables and/or give them attributes. If no names are given then display the values of variables. The -p option
257 will display the attributes and values of each name. When -p is used with name arguments, additional options, other than -f
258 and -F, are ignored. When -p is supplied without name arguments, it will display the attributes and values of all variables
259 having the attributes specified by the additional options. If no other options are supplied with -p, declare will display
260 the attributes and values of all shell variables. The -f option will restrict the display to shell functions. The -F option
261 inhibits the display of function definitions; only the function name and attributes are printed. If the extdebug shell op‐
262 tion is enabled using shopt, the source file name and line number where each name is defined are displayed as well. The -F
263 option implies -f. The -g option forces variables to be created or modified at the global scope, even when declare is exe‐
264 cuted in a shell function. It is ignored in all other cases. The -I option causes local variables to inherit the attributes
265 (except the nameref attribute) and value of any existing variable with the same name at a surrounding scope. If there is no
266 existing variable, the local variable is initially unset. The following options can be used to restrict output to variables
267 with the specified attribute or to give variables attributes:
268 -a Each name is an indexed array variable (see Arrays in bash(1)).
269 -A Each name is an associative array variable (see Arrays in bash(1)).
270 -f Use function names only.
271 -i The variable is treated as an integer; arithmetic evaluation (see ARITHMETIC EVALUATION in bash(1)) is performed when
272 the variable is assigned a value.
273 -l When the variable is assigned a value, all upper-case characters are converted to lower-case. The upper-case attri‐
274 bute is disabled.
275 -n Give each name the nameref attribute, making it a name reference to another variable. That other variable is defined
276 by the value of name. All references, assignments, and attribute modifications to name, except those using or chang‐
277 ing the -n attribute itself, are performed on the variable referenced by name's value. The nameref attribute cannot
278 be applied to array variables.
279 -r Make names readonly. These names cannot then be assigned values by subsequent assignment statements or unset.
280 -t Give each name the trace attribute. Traced functions inherit the DEBUG and RETURN traps from the calling shell. The
281 trace attribute has no special meaning for variables.
282 -u When the variable is assigned a value, all lower-case characters are converted to upper-case. The lower-case attri‐
283 bute is disabled.
284 -x Mark names for export to subsequent commands via the environment.
285
286 Using `+' instead of `-' turns off the attribute instead, with the exceptions that +a and +A may not be used to destroy array
287 variables and +r will not remove the readonly attribute. When used in a function, declare and typeset make each name local,
288 as with the local command, unless the -g option is supplied. If a variable name is followed by =value, the value of the
289 variable is set to value. When using -a or -A and the compound assignment syntax to create array variables, additional at‐
290 tributes do not take effect until subsequent assignments. The return value is 0 unless an invalid option is encountered, an
291 attempt is made to define a function using ``-f foo=bar'', an attempt is made to assign a value to a readonly variable, an
292 attempt is made to assign a value to an array variable without using the compound assignment syntax (see Arrays in bash(1)),
293 one of the names is not a valid shell variable name, an attempt is made to turn off readonly status for a readonly variable,
294 an attempt is made to turn off array status for an array variable, or an attempt is made to display a non-existent function
295 with -f.
296
297 dirs [-clpv] [+n] [-n]
298 Without options, displays the list of currently remembered directories. The default display is on a single line with direc‐
299 tory names separated by spaces. Directories are added to the list with the pushd command; the popd command removes entries
300 from the list. The current directory is always the first directory in the stack.
301 -c Clears the directory stack by deleting all of the entries.
302 -l Produces a listing using full pathnames; the default listing format uses a tilde to denote the home directory.
303 -p Print the directory stack with one entry per line.
304 -v Print the directory stack with one entry per line, prefixing each entry with its index in the stack.
305 +n Displays the nth entry counting from the left of the list shown by dirs when invoked without options, starting with
306 zero.
307 -n Displays the nth entry counting from the right of the list shown by dirs when invoked without options, starting with
308 zero.
309
310 The return value is 0 unless an invalid option is supplied or n indexes beyond the end of the directory stack.
311
312 disown [-ar] [-h] [jobspec ... | pid ... ]
313 Without options, remove each jobspec from the table of active jobs. If jobspec is not present, and neither the -a nor the -r
314 option is supplied, the current job is used. If the -h option is given, each jobspec is not removed from the table, but is
315 marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is supplied, the -a option means
316 to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value
317 is 0 unless a jobspec does not specify a valid job.
318
319 echo [-neE] [arg ...]
320 Output the args, separated by spaces, followed by a newline. The return status is 0 unless a write error occurs. If -n is
321 specified, the trailing newline is suppressed. If the -e option is given, interpretation of the following backslash-escaped
322 characters is enabled. The -E option disables the interpretation of these escape characters, even on systems where they are
323 interpreted by default. The xpg_echo shell option may be used to dynamically determine whether or not echo expands these es‐
324 cape characters by default. echo does not interpret -- to mean the end of options. echo interprets the following escape se‐
325 quences:
326 \a alert (bell)
327 \b backspace
328 \c suppress further output
329 \e
330 \E an escape character
331 \f form feed
332 \n new line
333 \r carriage return
334 \t horizontal tab
335 \v vertical tab
336 \\ backslash
337 \0nnn the eight-bit character whose value is the octal value nnn (zero to three octal digits)
338 \xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
339 \uHHHH the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHH (one to four hex digits)
340 \UHHHHHHHH
341 the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value HHHHHHHH (one to eight hex digits)
342
343 enable [-a] [-dnps] [-f filename] [name ...]
344 Enable and disable builtin shell commands. Disabling a builtin allows a disk command which has the same name as a shell
345 builtin to be executed without specifying a full pathname, even though the shell normally searches for builtins before disk
346 commands. If -n is used, each name is disabled; otherwise, names are enabled. For example, to use the test binary found via
347 the PATH instead of the shell builtin version, run ``enable -n test''. The -f option means to load the new builtin command
348 name from shared object filename, on systems that support dynamic loading. Bash will use the value of the BASH_LOAD‐
349 ABLES_PATH variable as a colon-separated list of directories in which to search for filename. The default is system-depen‐
350 dent. The -d option will delete a builtin previously loaded with -f. If no name arguments are given, or if the -p option is
351 supplied, a list of shell builtins is printed. With no other option arguments, the list consists of all enabled shell
352 builtins. If -n is supplied, only disabled builtins are printed. If -a is supplied, the list printed includes all builtins,
353 with an indication of whether or not each is enabled. If -s is supplied, the output is restricted to the POSIX special
354 builtins. If no options are supplied and a name is not a shell builtin, enable will attempt to load name from a shared ob‐
355 ject named name, as if the command were ``enable -f name name . The return value is 0 unless a name is not a shell builtin
356 or there is an error loading a new builtin from a shared object.
357
358 eval [arg ...]
359 The args are read and concatenated together into a single command. This command is then read and executed by the shell, and
360 its exit status is returned as the value of eval. If there are no args, or only null arguments, eval returns 0.
361
362 exec [-cl] [-a name] [command [arguments]]
363 If command is specified, it replaces the shell. No new process is created. The arguments become the arguments to command.
364 If the -l option is supplied, the shell places a dash at the beginning of the zeroth argument passed to command. This is
365 what login(1) does. The -c option causes command to be executed with an empty environment. If -a is supplied, the shell
366 passes name as the zeroth argument to the executed command. If command cannot be executed for some reason, a non-interactive
367 shell exits, unless the execfail shell option is enabled. In that case, it returns failure. An interactive shell returns
368 failure if the file cannot be executed. A subshell exits unconditionally if exec fails. If command is not specified, any
369 redirections take effect in the current shell, and the return status is 0. If there is a redirection error, the return sta‐
370 tus is 1.
371
372 exit [n]
373 Cause the shell to exit with a status of n. If n is omitted, the exit status is that of the last command executed. A trap
374 on EXIT is executed before the shell terminates.
375
376 export [-fn] [name[=word]] ...
377 export -p
378 The supplied names are marked for automatic export to the environment of subsequently executed commands. If the -f option is
379 given, the names refer to functions. If no names are given, or if the -p option is supplied, a list of names of all exported
380 variables is printed. The -n option causes the export property to be removed from each name. If a variable name is followed
381 by =word, the value of the variable is set to word. export returns an exit status of 0 unless an invalid option is encoun‐
382 tered, one of the names is not a valid shell variable name, or -f is supplied with a name that is not a function.
383
384 fc [-e ename] [-lnr] [first] [last]
385 fc -s [pat=rep] [cmd]
386 The first form selects a range of commands from first to last from the history list and displays or edits and re-executes
387 them. First and last may be specified as a string (to locate the last command beginning with that string) or as a number (an
388 index into the history list, where a negative number is used as an offset from the current command number). When listing, a
389 first or last of 0 is equivalent to -1 and -0 is equivalent to the current command (usually the fc command); otherwise 0 is
390 equivalent to -1 and -0 is invalid. If last is not specified, it is set to the current command for listing (so that ``fc -l
391 -10'' prints the last 10 commands) and to first otherwise. If first is not specified, it is set to the previous command for
392 editing and -16 for listing.
393
394 The -n option suppresses the command numbers when listing. The -r option reverses the order of the commands. If the -l op‐
395 tion is given, the commands are listed on standard output. Otherwise, the editor given by ename is invoked on a file con‐
396 taining those commands. If ename is not given, the value of the FCEDIT variable is used, and the value of EDITOR if FCEDIT
397 is not set. If neither variable is set, vi is used. When editing is complete, the edited commands are echoed and executed.
398
399 In the second form, command is re-executed after each instance of pat is replaced by rep. Command is interpreted the same as
400 first above. A useful alias to use with this is ``r="fc -s"'', so that typing ``r cc'' runs the last command beginning with
401 ``cc'' and typing ``r'' re-executes the last command.
402
403 If the first form is used, the return value is 0 unless an invalid option is encountered or first or last specify history
404 lines out of range. If the -e option is supplied, the return value is the value of the last command executed or failure if
405 an error occurs with the temporary file of commands. If the second form is used, the return status is that of the command
406 re-executed, unless cmd does not specify a valid history line, in which case fc returns failure.
407
408 fg [jobspec]
409 Resume jobspec in the foreground, and make it the current job. If jobspec is not present, the shell's notion of the current
410 job is used. The return value is that of the command placed into the foreground, or failure if run when job control is dis‐
411 abled or, when run with job control enabled, if jobspec does not specify a valid job or jobspec specifies a job that was
412 started without job control.
413
414 getopts optstring name [arg ...]
415 getopts is used by shell procedures to parse positional parameters. optstring contains the option characters to be recog‐
416 nized; if a character is followed by a colon, the option is expected to have an argument, which should be separated from it
417 by white space. The colon and question mark characters may not be used as option characters. Each time it is invoked,
418 getopts places the next option in the shell variable name, initializing name if it does not exist, and the index of the next
419 argument to be processed into the variable OPTIND. OPTIND is initialized to 1 each time the shell or a shell script is in‐
420 voked. When an option requires an argument, getopts places that argument into the variable OPTARG. The shell does not reset
421 OPTIND automatically; it must be manually reset between multiple calls to getopts within the same shell invocation if a new
422 set of parameters is to be used.
423
424 When the end of options is encountered, getopts exits with a return value greater than zero. OPTIND is set to the index of
425 the first non-option argument, and name is set to ?.
426
427 getopts normally parses the positional parameters, but if more arguments are supplied as arg values, getopts parses those in‐
428 stead.
429
430 getopts can report errors in two ways. If the first character of optstring is a colon, silent error reporting is used. In
431 normal operation, diagnostic messages are printed when invalid options or missing option arguments are encountered. If the
432 variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon.
433
434 If an invalid option is seen, getopts places ? into name and, if not silent, prints an error message and unsets OPTARG. If
435 getopts is silent, the option character found is placed in OPTARG and no diagnostic message is printed.
436
437 If a required argument is not found, and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a
438 diagnostic message is printed. If getopts is silent, then a colon (:) is placed in name and OPTARG is set to the option
439 character found.
440
441 getopts returns true if an option, specified or unspecified, is found. It returns false if the end of options is encountered
442 or an error occurs.
443
444 hash [-lr] [-p filename] [-dt] [name]
445 Each time hash is invoked, the full pathname of the command name is determined by searching the directories in $PATH and re‐
446 membered. Any previously-remembered pathname is discarded. If the -p option is supplied, no path search is performed, and
447 filename is used as the full filename of the command. The -r option causes the shell to forget all remembered locations.
448 The -d option causes the shell to forget the remembered location of each name. If the -t option is supplied, the full path‐
449 name to which each name corresponds is printed. If multiple name arguments are supplied with -t, the name is printed before
450 the hashed full pathname. The -l option causes output to be displayed in a format that may be reused as input. If no argu‐
451 ments are given, or if only -l is supplied, information about remembered commands is printed. The return status is true un‐
452 less a name is not found or an invalid option is supplied.
453
454 help [-dms] [pattern]
455 Display helpful information about builtin commands. If pattern is specified, help gives detailed help on all commands match‐
456 ing pattern; otherwise help for all the builtins and shell control structures is printed.
457 -d Display a short description of each pattern
458 -m Display the description of each pattern in a manpage-like format
459 -s Display only a short usage synopsis for each pattern
460
461 The return status is 0 unless no command matches pattern.
462
463 history [n]
464 history -c
465 history -d offset
466 history -d start-end
467 history -anrw [filename]
468 history -p arg [arg ...]
469 history -s arg [arg ...]
470 With no options, display the command history list with line numbers. Lines listed with a * have been modified. An argument
471 of n lists only the last n lines. If the shell variable HISTTIMEFORMAT is set and not null, it is used as a format string
472 for strftime(3) to display the time stamp associated with each displayed history entry. No intervening blank is printed be‐
473 tween the formatted time stamp and the history line. If filename is supplied, it is used as the name of the history file; if
474 not, the value of HISTFILE is used. Options, if supplied, have the following meanings:
475 -c Clear the history list by deleting all the entries.
476 -d offset
477 Delete the history entry at position offset. If offset is negative, it is interpreted as relative to one greater than
478 the last history position, so negative indices count back from the end of the history, and an index of -1 refers to
479 the current history -d command.
480 -d start-end
481 Delete the range of history entries between positions start and end, inclusive. Positive and negative values for
482 start and end are interpreted as described above.
483 -a Append the ``new'' history lines to the history file. These are history lines entered since the beginning of the cur‐
484 rent bash session, but not already appended to the history file.
485 -n Read the history lines not already read from the history file into the current history list. These are lines appended
486 to the history file since the beginning of the current bash session.
487 -r Read the contents of the history file and append them to the current history list.
488 -w Write the current history list to the history file, overwriting the history file's contents.
489 -p Perform history substitution on the following args and display the result on the standard output. Does not store the
490 results in the history list. Each arg must be quoted to disable normal history expansion.
491 -s Store the args in the history list as a single entry. The last command in the history list is removed before the args
492 are added.
493
494 If the HISTTIMEFORMAT variable is set, the time stamp information associated with each history entry is written to the his‐
495 tory file, marked with the history comment character. When the history file is read, lines beginning with the history com‐
496 ment character followed immediately by a digit are interpreted as timestamps for the following history entry. The return
497 value is 0 unless an invalid option is encountered, an error occurs while reading or writing the history file, an invalid
498 offset or range is supplied as an argument to -d, or the history expansion supplied as an argument to -p fails.
499
500 jobs [-lnprs] [ jobspec ... ]
501 jobs -x command [ args ... ]
502 The first form lists the active jobs. The options have the following meanings:
503 -l List process IDs in addition to the normal information.
504 -n Display information only about jobs that have changed status since the user was last notified of their status.
505 -p List only the process ID of the job's process group leader.
506 -r Display only running jobs.
507 -s Display only stopped jobs.
508
509 If jobspec is given, output is restricted to information about that job. The return status is 0 unless an invalid option is
510 encountered or an invalid jobspec is supplied.
511
512 If the -x option is supplied, jobs replaces any jobspec found in command or args with the corresponding process group ID, and
513 executes command passing it args, returning its exit status.
514
515 kill [-s sigspec | -n signum | -sigspec] [pid | jobspec] ...
516 kill -l|-L [sigspec | exit_status]
517 Send the signal named by sigspec or signum to the processes named by pid or jobspec. sigspec is either a case-insensitive
518 signal name such as SIGKILL (with or without the SIG prefix) or a signal number; signum is a signal number. If sigspec is
519 not present, then SIGTERM is assumed. An argument of -l lists the signal names. If any arguments are supplied when -l is
520 given, the names of the signals corresponding to the arguments are listed, and the return status is 0. The exit_status argu‐
521 ment to -l is a number specifying either a signal number or the exit status of a process terminated by a signal. The -L op‐
522 tion is equivalent to -l. kill returns true if at least one signal was successfully sent, or false if an error occurs or an
523 invalid option is encountered.
524
525 let arg [arg ...]
526 Each arg is an arithmetic expression to be evaluated (see ARITHMETIC EVALUATION in bash(1)). If the last arg evaluates to 0,
527 let returns 1; 0 is returned otherwise.
528
529 local [option] [name[=value] ... | - ]
530 For each argument, a local variable named name is created, and assigned value. The option can be any of the options accepted
531 by declare. When local is used within a function, it causes the variable name to have a visible scope restricted to that
532 function and its children. If name is -, the set of shell options is made local to the function in which local is invoked:
533 shell options changed using the set builtin inside the function are restored to their original values when the function re‐
534 turns. The restore is effected as if a series of set commands were executed to restore the values that were in place before
535 the function. With no operands, local writes a list of local variables to the standard output. It is an error to use local
536 when not within a function. The return status is 0 unless local is used outside a function, an invalid name is supplied, or
537 name is a readonly variable.
538
539 logout Exit a login shell.
540
541 mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
542 readarray [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
543 Read lines from the standard input into the indexed array variable array, or from file descriptor fd if the -u option is sup‐
544 plied. The variable MAPFILE is the default array. Options, if supplied, have the following meanings:
545 -d The first character of delim is used to terminate each input line, rather than newline. If delim is the empty string,
546 mapfile will terminate a line when it reads a NUL character.
547 -n Copy at most count lines. If count is 0, all lines are copied.
548 -O Begin assigning to array at index origin. The default index is 0.
549 -s Discard the first count lines read.
550 -t Remove a trailing delim (default newline) from each line read.
551 -u Read lines from file descriptor fd instead of the standard input.
552 -C Evaluate callback each time quantum lines are read. The -c option specifies quantum.
553 -c Specify the number of lines read between each call to callback.
554
555 If -C is specified without -c, the default quantum is 5000. When callback is evaluated, it is supplied the index of the next
556 array element to be assigned and the line to be assigned to that element as additional arguments. callback is evaluated af‐
557 ter the line is read but before the array element is assigned.
558
559 If not supplied with an explicit origin, mapfile will clear array before assigning to it.
560
561 mapfile returns successfully unless an invalid option or option argument is supplied, array is invalid or unassignable, or if
562 array is not an indexed array.
563
564 popd [-n] [+n] [-n]
565 Removes entries from the directory stack. The elements are numbered from 0 starting at the first directory listed by dirs.
566 With no arguments, popd removes the top directory from the stack, and changes to the new top directory. Arguments, if sup‐
567 plied, have the following meanings:
568 -n Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipu‐
569 lated.
570 +n Removes the nth entry counting from the left of the list shown by dirs, starting with zero, from the stack. For exam‐
571 ple: ``popd +0'' removes the first directory, ``popd +1'' the second.
572 -n Removes the nth entry counting from the right of the list shown by dirs, starting with zero. For example: ``popd -0''
573 removes the last directory, ``popd -1'' the next to last.
574
575 If the top element of the directory stack is modified, and the -n option was not supplied, popd uses the cd builtin to change
576 to the directory at the top of the stack. If the cd fails, popd returns a non-zero value.
577
578 Otherwise, popd returns false if an invalid option is encountered, the directory stack is empty, or a non-existent directory
579 stack entry is specified.
580
581 If the popd command is successful, bash runs dirs to show the final contents of the directory stack, and the return status is
582 0.
583
584 printf [-v var] format [arguments]
585 Write the formatted arguments to the standard output under the control of the format. The -v option causes the output to be
586 assigned to the variable var rather than being printed to the standard output.
587
588 The format is a character string which contains three types of objects: plain characters, which are simply copied to standard
589 output, character escape sequences, which are converted and copied to the standard output, and format specifications, each of
590 which causes printing of the next successive argument. In addition to the standard printf(1) format specifications, printf
591 interprets the following extensions:
592 %b causes printf to expand backslash escape sequences in the corresponding argument in the same way as echo -e.
593 %q causes printf to output the corresponding argument in a format that can be reused as shell input.
594 %Q like %q, but applies any supplied precision to the argument before quoting it.
595 %(datefmt)T
596 causes printf to output the date-time string resulting from using datefmt as a format string for strftime(3). The
597 corresponding argument is an integer representing the number of seconds since the epoch. Two special argument values
598 may be used: -1 represents the current time, and -2 represents the time the shell was invoked. If no argument is
599 specified, conversion behaves as if -1 had been given. This is an exception to the usual printf behavior.
600
601 The %b, %q, and %T directives all use the field width and precision arguments from the format specification and write that
602 many bytes from (or use that wide a field for) the expanded argument, which usually contains more characters than the origi‐
603 nal.
604
605 Arguments to non-string format specifiers are treated as C constants, except that a leading plus or minus sign is allowed,
606 and if the leading character is a single or double quote, the value is the ASCII value of the following character.
607
608 The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied,
609 the extra format specifications behave as if a zero value or null string, as appropriate, had been supplied. The return
610 value is zero on success, non-zero on failure.
611
612 pushd [-n] [+n] [-n]
613 pushd [-n] [dir]
614 Adds a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working
615 directory. With no arguments, pushd exchanges the top two elements of the directory stack. Arguments, if supplied, have the
616 following meanings:
617 -n Suppresses the normal change of directory when rotating or adding directories to the stack, so that only the stack is
618 manipulated.
619 +n Rotates the stack so that the nth directory (counting from the left of the list shown by dirs, starting with zero) is
620 at the top.
621 -n Rotates the stack so that the nth directory (counting from the right of the list shown by dirs, starting with zero) is
622 at the top.
623 dir Adds dir to the directory stack at the top
624
625 After the stack has been modified, if the -n option was not supplied, pushd uses the cd builtin to change to the directory at
626 the top of the stack. If the cd fails, pushd returns a non-zero value.
627
628 Otherwise, if no arguments are supplied, pushd returns 0 unless the directory stack is empty. When rotating the directory
629 stack, pushd returns 0 unless the directory stack is empty or a non-existent directory stack element is specified.
630
631 If the pushd command is successful, bash runs dirs to show the final contents of the directory stack.
632
633 pwd [-LP]
634 Print the absolute pathname of the current working directory. The pathname printed contains no symbolic links if the -P op‐
635 tion is supplied or the -o physical option to the set builtin command is enabled. If the -L option is used, the pathname
636 printed may contain symbolic links. The return status is 0 unless an error occurs while reading the name of the current di‐
637 rectory or an invalid option is supplied.
638
639 read [-ers] [-a aname] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
640 One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, split into
641 words as described in bash(1) under Word Splitting, and the first word is assigned to the first name, the second word to the
642 second name, and so on. If there are more words than names, the remaining words and their intervening delimiters are as‐
643 signed to the last name. If there are fewer words read from the input stream than names, the remaining names are assigned
644 empty values. The characters in IFS are used to split the line into words using the same rules the shell uses for expansion
645 (described in bash(1) under Word Splitting). The backslash character (\) may be used to remove any special meaning for the
646 next character read and for line continuation. Options, if supplied, have the following meanings:
647 -a aname
648 The words are assigned to sequential indices of the array variable aname, starting at 0. aname is unset before any
649 new values are assigned. Other name arguments are ignored.
650 -d delim
651 The first character of delim is used to terminate the input line, rather than newline. If delim is the empty string,
652 read will terminate a line when it reads a NUL character.
653 -e If the standard input is coming from a terminal, readline (see READLINE in bash(1)) is used to obtain the line. Read‐
654 line uses the current (or default, if line editing was not previously active) editing settings, but uses readline's
655 default filename completion.
656 -i text
657 If readline is being used to read the line, text is placed into the editing buffer before editing begins.
658 -n nchars
659 read returns after reading nchars characters rather than waiting for a complete line of input, but honors a delimiter
660 if fewer than nchars characters are read before the delimiter.
661 -N nchars
662 read returns after reading exactly nchars characters rather than waiting for a complete line of input, unless EOF is
663 encountered or read times out. Delimiter characters encountered in the input are not treated specially and do not
664 cause read to return until nchars characters are read. The result is not split on the characters in IFS; the intent
665 is that the variable is assigned exactly the characters read (with the exception of backslash; see the -r option be‐
666 low).
667 -p prompt
668 Display prompt on standard error, without a trailing newline, before attempting to read any input. The prompt is dis‐
669 played only if input is coming from a terminal.
670 -r Backslash does not act as an escape character. The backslash is considered to be part of the line. In particular, a
671 backslash-newline pair may not then be used as a line continuation.
672 -s Silent mode. If input is coming from a terminal, characters are not echoed.
673 -t timeout
674 Cause read to time out and return failure if a complete line of input (or a specified number of characters) is not
675 read within timeout seconds. timeout may be a decimal number with a fractional portion following the decimal point.
676 This option is only effective if read is reading input from a terminal, pipe, or other special file; it has no effect
677 when reading from regular files. If read times out, read saves any partial input read into the specified variable
678 name. If timeout is 0, read returns immediately, without trying to read any data. The exit status is 0 if input is
679 available on the specified file descriptor, or the read will return EOF, non-zero otherwise. The exit status is
680 greater than 128 if the timeout is exceeded.
681 -u fd Read input from file descriptor fd.
682
683 If no names are supplied, the line read, without the ending delimiter but otherwise unmodified, is assigned to the variable
684 REPLY. The exit status is zero, unless end-of-file is encountered, read times out (in which case the status is greater than
685 128), a variable assignment error (such as assigning to a readonly variable) occurs, or an invalid file descriptor is sup‐
686 plied as the argument to -u.
687
688 readonly [-aAf] [-p] [name[=word] ...]
689 The given names are marked readonly; the values of these names may not be changed by subsequent assignment. If the -f option
690 is supplied, the functions corresponding to the names are so marked. The -a option restricts the variables to indexed ar‐
691 rays; the -A option restricts the variables to associative arrays. If both options are supplied, -A takes precedence. If no
692 name arguments are given, or if the -p option is supplied, a list of all readonly names is printed. The other options may be
693 used to restrict the output to a subset of the set of readonly names. The -p option causes output to be displayed in a for‐
694 mat that may be reused as input. If a variable name is followed by =word, the value of the variable is set to word. The re‐
695 turn status is 0 unless an invalid option is encountered, one of the names is not a valid shell variable name, or -f is sup‐
696 plied with a name that is not a function.
697
698 return [n]
699 Causes a function to stop executing and return the value specified by n to its caller. If n is omitted, the return status is
700 that of the last command executed in the function body. If return is executed by a trap handler, the last command used to
701 determine the status is the last command executed before the trap handler. If return is executed during a DEBUG trap, the
702 last command used to determine the status is the last command executed by the trap handler before return was invoked. If re‐
703 turn is used outside a function, but during execution of a script by the . (source) command, it causes the shell to stop ex‐
704 ecuting that script and return either n or the exit status of the last command executed within the script as the exit status
705 of the script. If n is supplied, the return value is its least significant 8 bits. The return status is non-zero if return
706 is supplied a non-numeric argument, or is used outside a function and not during execution of a script by . or source. Any
707 command associated with the RETURN trap is executed before execution resumes after the function or script.
708
709 set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
710 set [+abefhkmnptuvxBCEHPT] [+o option-name] [--] [-] [arg ...]
711 Without options, display the name and value of each shell variable in a format that can be reused as input for setting or re‐
712 setting the currently-set variables. Read-only variables cannot be reset. In posix mode, only shell variables are listed.
713 The output is sorted according to the current locale. When options are specified, they set or unset shell attributes. Any
714 arguments remaining after option processing are treated as values for the positional parameters and are assigned, in order,
715 to $1, $2, ... $n. Options, if specified, have the following meanings:
716 -a Each variable or function that is created or modified is given the export attribute and marked for export to the en‐
717 vironment of subsequent commands.
718 -b Report the status of terminated background jobs immediately, rather than before the next primary prompt. This is ef‐
719 fective only when job control is enabled.
720 -e Exit immediately if a pipeline (which may consist of a single simple command), a list, or a compound command (see
721 SHELL GRAMMAR in bash(1)), exits with a non-zero status. The shell does not exit if the command that fails is part
722 of the command list immediately following a while or until keyword, part of the test following the if or elif re‐
723 served words, part of any command executed in a && or || list except the command following the final && or ||, any
724 command in a pipeline but the last, or if the command's return value is being inverted with !. If a compound command
725 other than a subshell returns a non-zero status because a command failed while -e was being ignored, the shell does
726 not exit. A trap on ERR, if set, is executed before the shell exits. This option applies to the shell environment
727 and each subshell environment separately (see COMMAND EXECUTION ENVIRONMENT in bash(1)), and may cause subshells to
728 exit before executing all the commands in the subshell.
729
730 If a compound command or shell function executes in a context where -e is being ignored, none of the commands exe‐
731 cuted within the compound command or function body will be affected by the -e setting, even if -e is set and a com‐
732 mand returns a failure status. If a compound command or shell function sets -e while executing in a context where -e
733 is ignored, that setting will not have any effect until the compound command or the command containing the function
734 call completes.
735 -f Disable pathname expansion.
736 -h Remember the location of commands as they are looked up for execution. This is enabled by default.
737 -k All arguments in the form of assignment statements are placed in the environment for a command, not just those that
738 precede the command name.
739 -m Monitor mode. Job control is enabled. This option is on by default for interactive shells on systems that support
740 it (see JOB CONTROL in bash(1)). All processes run in a separate process group. When a background job completes,
741 the shell prints a line containing its exit status.
742 -n Read commands but do not execute them. This may be used to check a shell script for syntax errors. This is ignored
743 by interactive shells.
744 -o option-name
745 The option-name can be one of the following:
746 allexport
747 Same as -a.
748 braceexpand
749 Same as -B.
750 emacs Use an emacs-style command line editing interface. This is enabled by default when the shell is interactive,
751 unless the shell is started with the --noediting option. This also affects the editing interface used for
752 read -e.
753 errexit Same as -e.
754 errtrace
755 Same as -E.
756 functrace
757 Same as -T.
758 hashall Same as -h.
759 histexpand
760 Same as -H.
761 history Enable command history, as described in bash(1) under HISTORY. This option is on by default in interactive
762 shells.
763 ignoreeof
764 The effect is as if the shell command ``IGNOREEOF=10'' had been executed (see Shell Variables in bash(1)).
765 keyword Same as -k.
766 monitor Same as -m.
767 noclobber
768 Same as -C.
769 noexec Same as -n.
770 noglob Same as -f.
771 nolog Currently ignored.
772 notify Same as -b.
773 nounset Same as -u.
774 onecmd Same as -t.
775 physical
776 Same as -P.
777 pipefail
778 If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero
779 status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.
780 posix Change the behavior of bash where the default operation differs from the POSIX standard to match the standard
781 (posix mode). See SEE ALSO in bash(1) for a reference to a document that details how posix mode affects
782 bash's behavior.
783 privileged
784 Same as -p.
785 verbose Same as -v.
786 vi Use a vi-style command line editing interface. This also affects the editing interface used for read -e.
787 xtrace Same as -x.
788 If -o is supplied with no option-name, the values of the current options are printed. If +o is supplied with no op‐
789 tion-name, a series of set commands to recreate the current option settings is displayed on the standard output.
790 -p Turn on privileged mode. In this mode, the $ENV and $BASH_ENV files are not processed, shell functions are not in‐
791 herited from the environment, and the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if they appear in the
792 environment, are ignored. If the shell is started with the effective user (group) id not equal to the real user
793 (group) id, and the -p option is not supplied, these actions are taken and the effective user id is set to the real
794 user id. If the -p option is supplied at startup, the effective user id is not reset. Turning this option off
795 causes the effective user and group ids to be set to the real user and group ids.
796 -r Enable restricted shell mode. This option cannot be unset once it has been set.
797 -t Exit after reading and executing one command.
798 -u Treat unset variables and parameters other than the special parameters "@" and "*", or array variables subscripted
799 with "@" or "*", as an error when performing parameter expansion. If expansion is attempted on an unset variable or
800 parameter, the shell prints an error message, and, if not interactive, exits with a non-zero status.
801 -v Print shell input lines as they are read.
802 -x After expanding each simple command, for command, case command, select command, or arithmetic for command, display
803 the expanded value of PS4, followed by the command and its expanded arguments or associated word list.
804 -B The shell performs brace expansion (see Brace Expansion in bash(1)). This is on by default.
805 -C If set, bash does not overwrite an existing file with the >, >&, and <> redirection operators. This may be overrid‐
806 den when creating output files by using the redirection operator >| instead of >.
807 -E If set, any trap on ERR is inherited by shell functions, command substitutions, and commands executed in a subshell
808 environment. The ERR trap is normally not inherited in such cases.
809 -H Enable ! style history substitution. This option is on by default when the shell is interactive.
810 -P If set, the shell does not resolve symbolic links when executing commands such as cd that change the current working
811 directory. It uses the physical directory structure instead. By default, bash follows the logical chain of directo‐
812 ries when performing commands which change the current directory.
813 -T If set, any traps on DEBUG and RETURN are inherited by shell functions, command substitutions, and commands executed
814 in a subshell environment. The DEBUG and RETURN traps are normally not inherited in such cases.
815 -- If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters
816 are set to the args, even if some of them begin with a -.
817 - Signal the end of options, cause all remaining args to be assigned to the positional parameters. The -x and -v op‐
818 tions are turned off. If there are no args, the positional parameters remain unchanged.
819
820 The options are off by default unless otherwise noted. Using + rather than - causes these options to be turned off. The op‐
821 tions can also be specified as arguments to an invocation of the shell. The current set of options may be found in $-. The
822 return status is always true unless an invalid option is encountered.
823
824 shift [n]
825 The positional parameters from n+1 ... are renamed to $1 .... Parameters represented by the numbers $# down to $#-n+1 are
826 unset. n must be a non-negative number less than or equal to $#. If n is 0, no parameters are changed. If n is not given,
827 it is assumed to be 1. If n is greater than $#, the positional parameters are not changed. The return status is greater
828 than zero if n is greater than $# or less than zero; otherwise 0.
829
830 shopt [-pqsu] [-o] [optname ...]
831 Toggle the values of settings controlling optional shell behavior. The settings can be either those listed below, or, if the
832 -o option is used, those available with the -o option to the set builtin command. With no options, or with the -p option, a
833 list of all settable options is displayed, with an indication of whether or not each is set; if optnames are supplied, the
834 output is restricted to those options. The -p option causes output to be displayed in a form that may be reused as input.
835 Other options have the following meanings:
836 -s Enable (set) each optname.
837 -u Disable (unset) each optname.
838 -q Suppresses normal output (quiet mode); the return status indicates whether the optname is set or unset. If multiple
839 optname arguments are given with -q, the return status is zero if all optnames are enabled; non-zero otherwise.
840 -o Restricts the values of optname to be those defined for the -o option to the set builtin.
841
842 If either -s or -u is used with no optname arguments, shopt shows only those options which are set or unset, respectively.
843 Unless otherwise noted, the shopt options are disabled (unset) by default.
844
845 The return status when listing options is zero if all optnames are enabled, non-zero otherwise. When setting or unsetting
846 options, the return status is zero unless an optname is not a valid shell option.
847
848 The list of shopt options is:
849
850 assoc_expand_once
851 If set, the shell suppresses multiple evaluation of associative array subscripts during arithmetic expression evalua‐
852 tion, while executing builtins that can perform variable assignments, and while executing builtins that perform array
853 dereferencing.
854 autocd If set, a command name that is the name of a directory is executed as if it were the argument to the cd command.
855 This option is only used by interactive shells.
856 cdable_vars
857 If set, an argument to the cd builtin command that is not a directory is assumed to be the name of a variable whose
858 value is the directory to change to.
859 cdspell If set, minor errors in the spelling of a directory component in a cd command will be corrected. The errors checked
860 for are transposed characters, a missing character, and one character too many. If a correction is found, the cor‐
861 rected filename is printed, and the command proceeds. This option is only used by interactive shells.
862 checkhash
863 If set, bash checks that a command found in the hash table exists before trying to execute it. If a hashed command
864 no longer exists, a normal path search is performed.
865 checkjobs
866 If set, bash lists the status of any stopped and running jobs before exiting an interactive shell. If any jobs are
867 running, this causes the exit to be deferred until a second exit is attempted without an intervening command (see JOB
868 CONTROL in bash(1)). The shell always postpones exiting if any jobs are stopped.
869 checkwinsize
870 If set, bash checks the window size after each external (non-builtin) command and, if necessary, updates the values
871 of LINES and COLUMNS. This option is enabled by default.
872 cmdhist If set, bash attempts to save all lines of a multiple-line command in the same history entry. This allows easy re-
873 editing of multi-line commands. This option is enabled by default, but only has an effect if command history is en‐
874 abled, as described in bash(1) under HISTORY.
875 compat31
876 compat32
877 compat40
878 compat41
879 compat42
880 compat43
881 compat44
882 compat50
883 These control aspects of the shell's compatibility mode (see SHELL COMPATIBILITY MODE in bash(1)).
884
885 complete_fullquote
886 If set, bash quotes all shell metacharacters in filenames and directory names when performing completion. If not
887 set, bash removes metacharacters such as the dollar sign from the set of characters that will be quoted in completed
888 filenames when these metacharacters appear in shell variable references in words to be completed. This means that
889 dollar signs in variable names that expand to directories will not be quoted; however, any dollar signs appearing in
890 filenames will not be quoted, either. This is active only when bash is using backslashes to quote completed file‐
891 names. This variable is set by default, which is the default bash behavior in versions through 4.2.
892
893 direxpand
894 If set, bash replaces directory names with the results of word expansion when performing filename completion. This
895 changes the contents of the readline editing buffer. If not set, bash attempts to preserve what the user typed.
896
897 dirspell
898 If set, bash attempts spelling correction on directory names during word completion if the directory name initially
899 supplied does not exist.
900
901 dotglob If set, bash includes filenames beginning with a `.' in the results of pathname expansion. The filenames ``.'' and
902 ``..'' must always be matched explicitly, even if dotglob is set.
903
904 execfail
905 If set, a non-interactive shell will not exit if it cannot execute the file specified as an argument to the exec
906 builtin command. An interactive shell does not exit if exec fails.
907
908 expand_aliases
909 If set, aliases are expanded as described in bash(1) under ALIASES. This option is enabled by default for interac‐
910 tive shells.
911
912 extdebug
913 If set at shell invocation, or in a shell startup file, arrange to execute the debugger profile before the shell
914 starts, identical to the --debugger option. If set after invocation, behavior intended for use by debuggers is en‐
915 abled:
916
917 1. The -F option to the declare builtin displays the source file name and line number corresponding to each func‐
918 tion name supplied as an argument.
919
920 2. If the command run by the DEBUG trap returns a non-zero value, the next command is skipped and not executed.
921
922 3. If the command run by the DEBUG trap returns a value of 2, and the shell is executing in a subroutine (a shell
923 function or a shell script executed by the . or source builtins), the shell simulates a call to return.
924
925 4. BASH_ARGC and BASH_ARGV are updated as described in their descriptions in bash(1)).
926
927 5. Function tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) in‐
928 herit the DEBUG and RETURN traps.
929
930 6. Error tracing is enabled: command substitution, shell functions, and subshells invoked with ( command ) in‐
931 herit the ERR trap.
932
933 extglob If set, the extended pattern matching features described in bash(1) under Pathname Expansion are enabled.
934
935 extquote
936 If set, $'string' and $"string" quoting is performed within ${parameter} expansions enclosed in double quotes. This
937 option is enabled by default.
938
939 failglob
940 If set, patterns which fail to match filenames during pathname expansion result in an expansion error.
941
942 force_fignore
943 If set, the suffixes specified by the FIGNORE shell variable cause words to be ignored when performing word comple‐
944 tion even if the ignored words are the only possible completions. See SHELL VARIABLES in bash(1) for a description
945 of FIGNORE. This option is enabled by default.
946
947 globasciiranges
948 If set, range expressions used in pattern matching bracket expressions (see Pattern Matching in bash(1)) behave as if
949 in the traditional C locale when performing comparisons. That is, the current locale's collating sequence is not
950 taken into account, so b will not collate between A and B, and upper-case and lower-case ASCII characters will col‐
951 late together.
952
953 globskipdots
954 If set, pathname expansion will never match the filenames ``.'' and ``..'', even if the pattern begins with a ``.''.
955 This option is enabled by default.
956
957 globstar
958 If set, the pattern ** used in a pathname expansion context will match all files and zero or more directories and
959 subdirectories. If the pattern is followed by a /, only directories and subdirectories match.
960
961 gnu_errfmt
962 If set, shell error messages are written in the standard GNU error message format.
963
964 histappend
965 If set, the history list is appended to the file named by the value of the HISTFILE variable when the shell exits,
966 rather than overwriting the file.
967
968 histreedit
969 If set, and readline is being used, a user is given the opportunity to re-edit a failed history substitution.
970
971 histverify
972 If set, and readline is being used, the results of history substitution are not immediately passed to the shell
973 parser. Instead, the resulting line is loaded into the readline editing buffer, allowing further modification.
974
975 hostcomplete
976 If set, and readline is being used, bash will attempt to perform hostname completion when a word containing a @ is
977 being completed (see Completing under READLINE in bash(1)). This is enabled by default.
978
979 huponexit
980 If set, bash will send SIGHUP to all jobs when an interactive login shell exits.
981
982 inherit_errexit
983 If set, command substitution inherits the value of the errexit option, instead of unsetting it in the subshell envi‐
984 ronment. This option is enabled when posix mode is enabled.
985
986 interactive_comments
987 If set, allow a word beginning with # to cause that word and all remaining characters on that line to be ignored in
988 an interactive shell (see COMMENTS in bash(1)). This option is enabled by default.
989
990 lastpipe
991 If set, and job control is not active, the shell runs the last command of a pipeline not executed in the background
992 in the current shell environment.
993
994 lithist If set, and the cmdhist option is enabled, multi-line commands are saved to the history with embedded newlines rather
995 than using semicolon separators where possible.
996
997 localvar_inherit
998 If set, local variables inherit the value and attributes of a variable of the same name that exists at a previous
999 scope before any new value is assigned. The nameref attribute is not inherited.
1000
1001 localvar_unset
1002 If set, calling unset on local variables in previous function scopes marks them so subsequent lookups find them unset
1003 until that function returns. This is identical to the behavior of unsetting local variables at the current function
1004 scope.
1005
1006 login_shell
1007 The shell sets this option if it is started as a login shell (see INVOCATION in bash(1)). The value may not be
1008 changed.
1009
1010 mailwarn
1011 If set, and a file that bash is checking for mail has been accessed since the last time it was checked, the message
1012 ``The mail in mailfile has been read'' is displayed.
1013
1014 no_empty_cmd_completion
1015 If set, and readline is being used, bash will not attempt to search the PATH for possible completions when completion
1016 is attempted on an empty line.
1017
1018 nocaseglob
1019 If set, bash matches filenames in a case-insensitive fashion when performing pathname expansion (see Pathname Expan‐
1020 sion in bash(1)).
1021
1022 nocasematch
1023 If set, bash matches patterns in a case-insensitive fashion when performing matching while executing case or [[ con‐
1024 ditional commands, when performing pattern substitution word expansions, or when filtering possible completions as
1025 part of programmable completion.
1026
1027 noexpand_translation
1028 If set, bash encloses the translated results of $"..." quoting in single quotes instead of double quotes. If the
1029 string is not translated, this has no effect.
1030
1031 nullglob
1032 If set, bash allows patterns which match no files (see Pathname Expansion in bash(1)) to expand to a null string,
1033 rather than themselves.
1034
1035 patsub_replacement
1036 If set, bash expands occurrences of & in the replacement string of pattern substitution to the text matched by the
1037 pattern, as described under Parameter Expansion in bash(1). This option is enabled by default.
1038
1039 progcomp
1040 If set, the programmable completion facilities (see Programmable Completion in bash(1)) are enabled. This option is
1041 enabled by default.
1042
1043 progcomp_alias
1044 If set, and programmable completion is enabled, bash treats a command name that doesn't have any completions as a
1045 possible alias and attempts alias expansion. If it has an alias, bash attempts programmable completion using the com‐
1046 mand word resulting from the expanded alias.
1047
1048 promptvars
1049 If set, prompt strings undergo parameter expansion, command substitution, arithmetic expansion, and quote removal af‐
1050 ter being expanded as described in PROMPTING in bash(1). This option is enabled by default.
1051
1052 restricted_shell
1053 The shell sets this option if it is started in restricted mode (see RESTRICTED SHELL in bash(1)). The value may not
1054 be changed. This is not reset when the startup files are executed, allowing the startup files to discover whether or
1055 not a shell is restricted.
1056
1057 shift_verbose
1058 If set, the shift builtin prints an error message when the shift count exceeds the number of positional parameters.
1059
1060 sourcepath
1061 If set, the . (source) builtin uses the value of PATH to find the directory containing the file supplied as an argu‐
1062 ment. This option is enabled by default.
1063
1064 varredir_close
1065 If set, the shell automatically closes file descriptors assigned using the {varname} redirection syntax (see REDI‐
1066 RECTION in bash(1)) instead of leaving them open when the command completes.
1067
1068 syslog_history
1069 If set, command history is logged to syslog.
1070
1071 xpg_echo
1072 If set, the echo builtin expands backslash-escape sequences by default.
1073
1074 suspend [-f]
1075 Suspend the execution of this shell until it receives a SIGCONT signal. A login shell, or a shell without job control en‐
1076 abled, cannot be suspended; the -f option can be used to override this and force the suspension. The return status is 0 un‐
1077 less the shell is a login shell or job control is not enabled and -f is not supplied.
1078
1079 test expr
1080 [ expr ]
1081 Return a status of 0 (true) or 1 (false) depending on the evaluation of the conditional expression expr. Each operator and
1082 operand must be a separate argument. Expressions are composed of the primaries described in bash(1) under CONDITIONAL EX‐
1083 PRESSIONS. test does not accept any options, nor does it accept and ignore an argument of -- as signifying the end of op‐
1084 tions.
1085
1086 Expressions may be combined using the following operators, listed in decreasing order of precedence. The evaluation depends
1087 on the number of arguments; see below. Operator precedence is used when there are five or more arguments.
1088 ! expr True if expr is false.
1089 ( expr )
1090 Returns the value of expr. This may be used to override the normal precedence of operators.
1091 expr1 -a expr2
1092 True if both expr1 and expr2 are true.
1093 expr1 -o expr2
1094 True if either expr1 or expr2 is true.
1095
1096 test and [ evaluate conditional expressions using a set of rules based on the number of arguments.
1097
1098 0 arguments
1099 The expression is false.
1100 1 argument
1101 The expression is true if and only if the argument is not null.
1102 2 arguments
1103 If the first argument is !, the expression is true if and only if the second argument is null. If the first argument
1104 is one of the unary conditional operators listed in bash(1) under CONDITIONAL EXPRESSIONS, the expression is true if
1105 the unary test is true. If the first argument is not a valid unary conditional operator, the expression is false.
1106 3 arguments
1107 The following conditions are applied in the order listed. If the second argument is one of the binary conditional op‐
1108 erators listed in bash(1) under CONDITIONAL EXPRESSIONS, the result of the expression is the result of the binary test
1109 using the first and third arguments as operands. The -a and -o operators are considered binary operators when there
1110 are three arguments. If the first argument is !, the value is the negation of the two-argument test using the second
1111 and third arguments. If the first argument is exactly ( and the third argument is exactly ), the result is the one-
1112 argument test of the second argument. Otherwise, the expression is false.
1113 4 arguments
1114 The following conditions are applied in the order listed. If the first argument is !, the result is the negation of
1115 the three-argument expression composed of the remaining arguments. the two-argument test using the second and third
1116 arguments. If the first argument is exactly ( and the fourth argument is exactly ), the result is the two-argument
1117 test of the second and third arguments. Otherwise, the expression is parsed and evaluated according to precedence us‐
1118 ing the rules listed above.
1119 5 or more arguments
1120 The expression is parsed and evaluated according to precedence using the rules listed above.
1121
1122 When used with test or [, the < and > operators sort lexicographically using ASCII ordering.
1123
1124 times Print the accumulated user and system times for the shell and for processes run from the shell. The return status is 0.
1125
1126 trap [-lp] [[arg] sigspec ...]
1127 The command arg is to be read and executed when the shell receives signal(s) sigspec. If arg is absent (and there is a sin‐
1128 gle sigspec) or -, each specified signal is reset to its original disposition (the value it had upon entrance to the shell).
1129 If arg is the null string the signal specified by each sigspec is ignored by the shell and by the commands it invokes. If
1130 arg is not present and -p has been supplied, then the trap commands associated with each sigspec are displayed. If no argu‐
1131 ments are supplied or if only -p is given, trap prints the list of commands associated with each signal. The -l option
1132 causes the shell to print a list of signal names and their corresponding numbers. Each sigspec is either a signal name de‐
1133 fined in <signal.h>, or a signal number. Signal names are case insensitive and the SIG prefix is optional.
1134
1135 If a sigspec is EXIT (0) the command arg is executed on exit from the shell. If a sigspec is DEBUG, the command arg is exe‐
1136 cuted before every simple command, for command, case command, select command, every arithmetic for command, and before the
1137 first command executes in a shell function (see SHELL GRAMMAR in bash(1)). Refer to the description of the extdebug option
1138 to the shopt builtin for details of its effect on the DEBUG trap. If a sigspec is RETURN, the command arg is executed each
1139 time a shell function or a script executed with the . or source builtins finishes executing.
1140
1141 If a sigspec is ERR, the command arg is executed whenever a pipeline (which may consist of a single simple command), a list,
1142 or a compound command returns a non-zero exit status, subject to the following conditions. The ERR trap is not executed if
1143 the failed command is part of the command list immediately following a while or until keyword, part of the test in an if
1144 statement, part of a command executed in a && or || list except the command following the final && or ||, any command in a
1145 pipeline but the last, or if the command's return value is being inverted using !. These are the same conditions obeyed by
1146 the errexit (-e) option.
1147
1148 Signals ignored upon entry to the shell cannot be trapped, reset or listed. Trapped signals that are not being ignored are
1149 reset to their original values in a subshell or subshell environment when one is created. The return status is false if any
1150 sigspec is invalid; otherwise trap returns true.
1151
1152 type [-aftpP] name [name ...]
1153 With no options, indicate how each name would be interpreted if used as a command name. If the -t option is used, type
1154 prints a string which is one of alias, keyword, function, builtin, or file if name is an alias, shell reserved word, func‐
1155 tion, builtin, or disk file, respectively. If the name is not found, then nothing is printed, and an exit status of false is
1156 returned. If the -p option is used, type either returns the name of the disk file that would be executed if name were speci‐
1157 fied as a command name, or nothing if ``type -t name'' would not return file. The -P option forces a PATH search for each
1158 name, even if ``type -t name'' would not return file. If a command is hashed, -p and -P print the hashed value, which is not
1159 necessarily the file that appears first in PATH. If the -a option is used, type prints all of the places that contain an ex‐
1160 ecutable named name. This includes aliases and functions, if and only if the -p option is not also used. The table of
1161 hashed commands is not consulted when using -a. The -f option suppresses shell function lookup, as with the command builtin.
1162 type returns true if all of the arguments are found, false if any are not found.
1163
1164 ulimit [-HS] -a
1165 ulimit [-HS] [-bcdefiklmnpqrstuvxPRT [limit]]
1166 Provides control over the resources available to the shell and to processes started by it, on systems that allow such con‐
1167 trol. The -H and -S options specify that the hard or soft limit is set for the given resource. A hard limit cannot be in‐
1168 creased by a non-root user once it is set; a soft limit may be increased up to the value of the hard limit. If neither -H
1169 nor -S is specified, both the soft and hard limits are set. The value of limit can be a number in the unit specified for the
1170 resource or one of the special values hard, soft, or unlimited, which stand for the current hard limit, the current soft
1171 limit, and no limit, respectively. If limit is omitted, the current value of the soft limit of the resource is printed, un‐
1172 less the -H option is given. When more than one resource is specified, the limit name and unit, if appropriate, are printed
1173 before the value. Other options are interpreted as follows:
1174 -a All current limits are reported; no limits are set
1175 -b The maximum socket buffer size
1176 -c The maximum size of core files created
1177 -d The maximum size of a process's data segment
1178 -e The maximum scheduling priority ("nice")
1179 -f The maximum size of files written by the shell and its children
1180 -i The maximum number of pending signals
1181 -k The maximum number of kqueues that may be allocated
1182 -l The maximum size that may be locked into memory
1183 -m The maximum resident set size (many systems do not honor this limit)
1184 -n The maximum number of open file descriptors (most systems do not allow this value to be set)
1185 -p The pipe size in 512-byte blocks (this may not be set)
1186 -q The maximum number of bytes in POSIX message queues
1187 -r The maximum real-time scheduling priority
1188 -s The maximum stack size
1189 -t The maximum amount of cpu time in seconds
1190 -u The maximum number of processes available to a single user
1191 -v The maximum amount of virtual memory available to the shell and, on some systems, to its children
1192 -x The maximum number of file locks
1193 -P The maximum number of pseudoterminals
1194 -R The maximum time a real-time process can run before blocking, in microseconds
1195 -T The maximum number of threads
1196
1197 If limit is given, and the -a option is not used, limit is the new value of the specified resource. If no option is given,
1198 then -f is assumed. Values are in 1024-byte increments, except for -t, which is in seconds; -R, which is in microseconds;
1199 -p, which is in units of 512-byte blocks; -P, -T, -b, -k, -n, and -u, which are unscaled values; and, when in posix mode, -c
1200 and -f, which are in 512-byte increments. The return status is 0 unless an invalid option or argument is supplied, or an er‐
1201 ror occurs while setting a new limit. In POSIX Mode 512-byte blocks are used for the `-c' and `-f' options.
1202
1203 umask [-p] [-S] [mode]
1204 The user file-creation mask is set to mode. If mode begins with a digit, it is interpreted as an octal number; otherwise it
1205 is interpreted as a symbolic mode mask similar to that accepted by chmod(1). If mode is omitted, the current value of the
1206 mask is printed. The -S option causes the mask to be printed in symbolic form; the default output is an octal number. If
1207 the -p option is supplied, and mode is omitted, the output is in a form that may be reused as input. The return status is 0
1208 if the mode was successfully changed or if no mode argument was supplied, and false otherwise.
1209
1210 unalias [-a] [name ...]
1211 Remove each name from the list of defined aliases. If -a is supplied, all alias definitions are removed. The return value
1212 is true unless a supplied name is not a defined alias.
1213
1214 unset [-fv] [-n] [name ...]
1215 For each name, remove the corresponding variable or function. If the -v option is given, each name refers to a shell vari‐
1216 able, and that variable is removed. Read-only variables may not be unset. If -f is specified, each name refers to a shell
1217 function, and the function definition is removed. If the -n option is supplied, and name is a variable with the nameref at‐
1218 tribute, name will be unset rather than the variable it references. -n has no effect if the -f option is supplied. If no
1219 options are supplied, each name refers to a variable; if there is no variable by that name, a function with that name, if
1220 any, is unset. Each unset variable or function is removed from the environment passed to subsequent commands. If any of
1221 BASH_ALIASES, BASH_ARGV0, BASH_CMDS, BASH_COMMAND, BASH_SUBSHELL, BASHPID, COMP_WORDBREAKS, DIRSTACK, EPOCHREALTIME,
1222 EPOCHSECONDS, FUNCNAME, GROUPS, HISTCMD, LINENO, RANDOM, SECONDS, or SRANDOM are unset, they lose their special properties,
1223 even if they are subsequently reset. The exit status is true unless a name is readonly or may not be unset.
1224
1225 wait [-fn] [-p varname] [id ...]
1226 Wait for each specified child process and return its termination status. Each id may be a process ID or a job specification;
1227 if a job spec is given, all processes in that job's pipeline are waited for. If id is not given, wait waits for all running
1228 background jobs and the last-executed process substitution, if its process id is the same as $!, and the return status is
1229 zero. If the -n option is supplied, wait waits for a single job from the list of ids or, if no ids are supplied, any job, to
1230 complete and returns its exit status. If none of the supplied arguments is a child of the shell, or if no arguments are sup‐
1231 plied and the shell has no unwaited-for children, the exit status is 127. If the -p option is supplied, the process or job
1232 identifier of the job for which the exit status is returned is assigned to the variable varname named by the option argument.
1233 The variable will be unset initially, before any assignment. This is useful only when the -n option is supplied. Supplying
1234 the -f option, when job control is enabled, forces wait to wait for id to terminate before returning its status, instead of
1235 returning when it changes status. If id specifies a non-existent process or job, the return status is 127. If wait is in‐
1236 terrupted by a signal, the return status will be greater than 128, as described under SIGNALS in bash(1). Otherwise, the re‐
1237 turn status is the exit status of the last process or job waited for.
1238
1239 SHELL COMPATIBILITY MODE
1240 Bash-4.0 introduced the concept of a shell compatibility level, specified as a set of options to the shopt builtin ( compat31, com‐
1241 pat32, compat40, compat41, and so on). There is only one current compatibility level -- each option is mutually exclusive. The
1242 compatibility level is intended to allow users to select behavior from previous versions that is incompatible with newer versions
1243 while they migrate scripts to use current features and behavior. It's intended to be a temporary solution.
1244
1245 This section does not mention behavior that is standard for a particular version (e.g., setting compat32 means that quoting the rhs
1246 of the regexp matching operator quotes special regexp characters in the word, which is default behavior in bash-3.2 and subsequent
1247 versions).
1248
1249 If a user enables, say, compat32, it may affect the behavior of other compatibility levels up to and including the current compati‐
1250 bility level. The idea is that each compatibility level controls behavior that changed in that version of bash, but that behavior
1251 may have been present in earlier versions. For instance, the change to use locale-based comparisons with the [[ command came in
1252 bash-4.1, and earlier versions used ASCII-based comparisons, so enabling compat32 will enable ASCII-based comparisons as well. That
1253 granularity may not be sufficient for all uses, and as a result users should employ compatibility levels carefully. Read the docu‐
1254 mentation for a particular feature to find out the current behavior.
1255
1256 Bash-4.3 introduced a new shell variable: BASH_COMPAT. The value assigned to this variable (a decimal version number like 4.2, or
1257 an integer corresponding to the compatNN option, like 42) determines the compatibility level.
1258
1259 Starting with bash-4.4, Bash has begun deprecating older compatibility levels. Eventually, the options will be removed in favor of
1260 BASH_COMPAT.
1261
1262 Bash-5.0 is the final version for which there will be an individual shopt option for the previous version. Users should use
1263 BASH_COMPAT on bash-5.0 and later versions.
1264
1265 The following table describes the behavior changes controlled by each compatibility level setting. The compatNN tag is used as
1266 shorthand for setting the compatibility level to NN using one of the following mechanisms. For versions prior to bash-5.0, the com‐
1267 patibility level may be set using the corresponding compatNN shopt option. For bash-4.3 and later versions, the BASH_COMPAT vari‐
1268 able is preferred, and it is required for bash-5.1 and later versions.
1269
1270 compat31
1271 • quoting the rhs of the [[ command's regexp matching operator (=~) has no special effect
1272
1273 compat32
1274 • interrupting a command list such as "a ; b ; c" causes the execution of the next command in the list (in bash-4.0 and
1275 later versions, the shell acts as if it received the interrupt, so interrupting one command in a list aborts the exe‐
1276 cution of the entire list)
1277
1278 compat40
1279 • the < and > operators to the [[ command do not consider the current locale when comparing strings; they use ASCII or‐
1280 dering. Bash versions prior to bash-4.1 use ASCII collation and strcmp(3); bash-4.1 and later use the current lo‐
1281 cale's collation sequence and strcoll(3).
1282
1283 compat41
1284 • in posix mode, time may be followed by options and still be recognized as a reserved word (this is POSIX interpreta‐
1285 tion 267)
1286 • in posix mode, the parser requires that an even number of single quotes occur in the word portion of a double-quoted
1287 parameter expansion and treats them specially, so that characters within the single quotes are considered quoted (this
1288 is POSIX interpretation 221)
1289
1290 compat42
1291 • the replacement string in double-quoted pattern substitution does not undergo quote removal, as it does in versions
1292 after bash-4.2
1293 • in posix mode, single quotes are considered special when expanding the word portion of a double-quoted parameter ex‐
1294 pansion and can be used to quote a closing brace or other special character (this is part of POSIX interpretation
1295 221); in later versions, single quotes are not special within double-quoted word expansions
1296
1297 compat43
1298 • the shell does not print a warning message if an attempt is made to use a quoted compound assignment as an argument to
1299 declare (e.g., declare -a foo='(1 2)'). Later versions warn that this usage is deprecated
1300 • word expansion errors are considered non-fatal errors that cause the current command to fail, even in posix mode (the
1301 default behavior is to make them fatal errors that cause the shell to exit)
1302 • when executing a shell function, the loop state (while/until/etc.) is not reset, so break or continue in that func‐
1303 tion will break or continue loops in the calling context. Bash-4.4 and later reset the loop state to prevent this
1304
1305 compat44
1306 • the shell sets up the values used by BASH_ARGV and BASH_ARGC so they can expand to the shell's positional parameters
1307 even if extended debugging mode is not enabled
1308 • a subshell inherits loops from its parent context, so break or continue will cause the subshell to exit. Bash-5.0 and
1309 later reset the loop state to prevent the exit
1310 • variable assignments preceding builtins like export and readonly that set attributes continue to affect variables with
1311 the same name in the calling environment even if the shell is not in posix mode
1312
1313 compat50
1314 • Bash-5.1 changed the way $RANDOM is generated to introduce slightly more randomness. If the shell compatibility level
1315 is set to 50 or lower, it reverts to the method from bash-5.0 and previous versions, so seeding the random number gen‐
1316 erator by assigning a value to RANDOM will produce the same sequence as in bash-5.0
1317 • If the command hash table is empty, bash versions prior to bash-5.1 printed an informational message to that effect,
1318 even when producing output that can be reused as input. Bash-5.1 suppresses that message when the -l option is sup‐
1319 plied.
1320
1321 compat51
1322 • The unset builtin treats attempts to unset array subscripts @ and * differently depending on whether the array is in‐
1323 dexed or associative, and differently than in previous versions.
1324
1325 SEE ALSO
1326 bash(1), sh(1)
1327
1328 GNU Bash 5.2 2021 November 22 BASH_BUILTINS(1)
2.reference
2.1 [wit@fedora null]$ man exec
本文由 lnlidawei 原创、整理、转载,本文来自于【博客园】; 整理和转载的文章的版权归属于【原创作者】; 转载或引用时请【保留文章的来源信息】:https://www.cnblogs.com/lnlidawei/p/17690634.html