]>
Commit | Line | Data |
---|---|---|
d3ad40de | 1 | .\" |
726f6388 JA |
2 | .\" MAN PAGE COMMENTS to |
3 | .\" | |
4 | .\" Chet Ramey | |
726f6388 | 5 | .\" Case Western Reserve University |
e225d5a9 | 6 | .\" chet@po.cwru.edu |
726f6388 | 7 | .\" |
b28ff8c9 | 8 | .\" Last Change: Sun Sep 25 22:01:16 EDT 2011 |
726f6388 JA |
9 | .\" |
10 | .\" bash_builtins, strip all but Built-Ins section | |
11 | .if \n(zZ=1 .ig zZ | |
bb70624e | 12 | .if \n(zY=1 .ig zY |
b28ff8c9 | 13 | .TH BASH 1 "2011 September 25" "GNU Bash 4.2" |
726f6388 JA |
14 | .\" |
15 | .\" There's some problem with having a `@' | |
16 | .\" in a tagged paragraph with the BSD man macros. | |
17 | .\" It has to do with `@' appearing in the }1 macro. | |
18 | .\" This is a problem on 4.3 BSD and Ultrix, but Sun | |
19 | .\" appears to have fixed it. | |
20 | .\" If you're seeing the characters | |
21 | .\" `@u-3p' appearing before the lines reading | |
22 | .\" `possible-hostname-completions | |
23 | .\" and `complete-hostname' down in READLINE, | |
24 | .\" then uncomment this redefinition. | |
25 | .\" | |
26 | .de }1 | |
27 | .ds ]X \&\\*(]B\\ | |
28 | .nr )E 0 | |
29 | .if !"\\$1"" .nr )I \\$1n | |
30 | .}f | |
31 | .ll \\n(LLu | |
32 | .in \\n()Ru+\\n(INu+\\n()Iu | |
33 | .ti \\n(INu | |
34 | .ie !\\n()Iu+\\n()Ru-\w\a\\*(]X\au-3p \{\\*(]X | |
35 | .br\} | |
36 | .el \\*(]X\h\a|\\n()Iu+\\n()Ru\a\c | |
37 | .}f | |
38 | .. | |
39 | .\" | |
40 | .\" File Name macro. This used to be `.PN', for Path Name, | |
41 | .\" but Sun doesn't seem to like that very much. | |
42 | .\" | |
43 | .de FN | |
44 | \fI\|\\$1\|\fP | |
45 | .. | |
46 | .SH NAME | |
ccc6cda3 | 47 | bash \- GNU Bourne-Again SHell |
726f6388 JA |
48 | .SH SYNOPSIS |
49 | .B bash | |
50 | [options] | |
51 | [file] | |
52 | .SH COPYRIGHT | |
deeba0d2 CR |
53 | .if n Bash is Copyright (C) 1989-2011 by the Free Software Foundation, Inc. |
54 | .if t Bash is Copyright \(co 1989-2011 by the Free Software Foundation, Inc. | |
726f6388 JA |
55 | .SH DESCRIPTION |
56 | .B Bash | |
ccc6cda3 | 57 | is an \fBsh\fR-compatible command language interpreter that |
726f6388 JA |
58 | executes commands read from the standard input or from a file. |
59 | .B Bash | |
60 | also incorporates useful features from the \fIKorn\fP and \fIC\fP | |
61 | shells (\fBksh\fP and \fBcsh\fP). | |
62 | .PP | |
63 | .B Bash | |
ac18b312 CR |
64 | is intended to be a conformant implementation of the |
65 | Shell and Utilities portion of the IEEE POSIX specification | |
66 | (IEEE Standard 1003.1). | |
7790f917 CR |
67 | .B Bash |
68 | can be configured to be POSIX-conformant by default. | |
726f6388 | 69 | .SH OPTIONS |
3d8cce26 CR |
70 | All of the single-character shell options documented in the |
71 | description of the \fBset\fR builtin command can be used as options | |
72 | when the shell is invoked. | |
73 | In addition, \fBbash\fR | |
cce855bc | 74 | interprets the following options when it is invoked: |
726f6388 JA |
75 | .PP |
76 | .PD 0 | |
77 | .TP 10 | |
78 | .BI \-c "\| string\^" | |
ccc6cda3 | 79 | If the |
726f6388 | 80 | .B \-c |
cce855bc | 81 | option is present, then commands are read from |
726f6388 JA |
82 | .IR string . |
83 | If there are arguments after the | |
84 | .IR string , | |
85 | they are assigned to the positional parameters, starting with | |
86 | .BR $0 . | |
87 | .TP | |
7117c2d2 JA |
88 | .B \-i |
89 | If the | |
90 | .B \-i | |
91 | option is present, the shell is | |
92 | .IR interactive . | |
93 | .TP | |
94 | .B \-l | |
95 | Make | |
96 | .B bash | |
97 | act as if it had been invoked as a login shell (see | |
98 | .SM | |
99 | .B INVOCATION | |
100 | below). | |
101 | .TP | |
ccc6cda3 JA |
102 | .B \-r |
103 | If the | |
104 | .B \-r | |
cce855bc | 105 | option is present, the shell becomes |
ccc6cda3 JA |
106 | .I restricted |
107 | (see | |
108 | .SM | |
109 | .B "RESTRICTED SHELL" | |
110 | below). | |
111 | .TP | |
726f6388 JA |
112 | .B \-s |
113 | If the | |
114 | .B \-s | |
cce855bc | 115 | option is present, or if no arguments remain after option |
726f6388 JA |
116 | processing, then commands are read from the standard input. |
117 | This option allows the positional parameters to be set | |
118 | when invoking an interactive shell. | |
119 | .TP | |
ccc6cda3 JA |
120 | .B \-D |
121 | A list of all double-quoted strings preceded by \fB$\fP | |
22e63b05 | 122 | is printed on the standard output. |
ccc6cda3 JA |
123 | These are the strings that |
124 | are subject to language translation when the current locale | |
28ef6c31 | 125 | is not \fBC\fP or \fBPOSIX\fP. |
ccc6cda3 JA |
126 | This implies the \fB\-n\fP option; no commands will be executed. |
127 | .TP | |
f73dda09 JA |
128 | .B [\-+]O [\fIshopt_option\fP] |
129 | \fIshopt_option\fP is one of the shell options accepted by the | |
130 | \fBshopt\fP builtin (see | |
131 | .SM | |
132 | .B SHELL BUILTIN COMMANDS | |
133 | below). | |
134 | If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option; | |
135 | \fB+O\fP unsets it. | |
136 | If \fIshopt_option\fP is not supplied, the names and values of the shell | |
137 | options accepted by \fBshopt\fP are printed on the standard output. | |
138 | If the invocation option is \fB+O\fP, the output is displayed in a format | |
139 | that may be reused as input. | |
140 | .TP | |
ccc6cda3 JA |
141 | .B \-\- |
142 | A | |
143 | .B \-\- | |
726f6388 JA |
144 | signals the end of options and disables further option processing. |
145 | Any arguments after the | |
726f6388 | 146 | .B \-\- |
ccc6cda3 JA |
147 | are treated as filenames and arguments. An argument of |
148 | .B \- | |
149 | is equivalent to \fB\-\-\fP. | |
726f6388 JA |
150 | .PD |
151 | .PP | |
152 | .B Bash | |
ccc6cda3 JA |
153 | also interprets a number of multi-character options. |
154 | These options must appear on the command line before the | |
7117c2d2 | 155 | single-character options to be recognized. |
726f6388 JA |
156 | .PP |
157 | .PD 0 | |
726f6388 | 158 | .TP |
d3a24ed2 CR |
159 | .B \-\-debugger |
160 | Arrange for the debugger profile to be executed before the shell | |
2206f89a CR |
161 | starts. |
162 | Turns on extended debugging mode (see the description of the | |
d3a24ed2 CR |
163 | .B extdebug |
164 | option to the | |
165 | .B shopt | |
d3a24ed2 CR |
166 | builtin below). |
167 | .TP | |
cce855bc JA |
168 | .B \-\-dump\-po\-strings |
169 | Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP | |
170 | \fBpo\fP (portable object) file format. | |
171 | .TP | |
ccc6cda3 JA |
172 | .B \-\-dump\-strings |
173 | Equivalent to \fB\-D\fP. | |
174 | .TP | |
175 | .B \-\-help | |
176 | Display a usage message on standard output and exit successfully. | |
177 | .TP | |
28ef6c31 | 178 | \fB\-\-init\-file\fP \fIfile\fP |
7117c2d2 | 179 | .PD 0 |
28ef6c31 JA |
180 | .TP |
181 | \fB\-\-rcfile\fP \fIfile\fP | |
182 | .PD | |
183 | Execute commands from | |
184 | .I file | |
185 | instead of the standard personal initialization file | |
186 | .I ~/.bashrc | |
187 | if the shell is interactive (see | |
188 | .SM | |
189 | .B INVOCATION | |
190 | below). | |
191 | .TP | |
ccc6cda3 | 192 | .B \-\-login |
7117c2d2 | 193 | Equivalent to \fB\-l\fP. |
ccc6cda3 JA |
194 | .TP |
195 | .B \-\-noediting | |
196 | Do not use the GNU | |
197 | .B readline | |
bb70624e | 198 | library to read command lines when the shell is interactive. |
ccc6cda3 JA |
199 | .TP |
200 | .B \-\-noprofile | |
201 | Do not read either the system-wide startup file | |
726f6388 JA |
202 | .FN /etc/profile |
203 | or any of the personal initialization files | |
204 | .IR ~/.bash_profile , | |
205 | .IR ~/.bash_login , | |
206 | or | |
207 | .IR ~/.profile . | |
208 | By default, | |
209 | .B bash | |
ccc6cda3 | 210 | reads these files when it is invoked as a login shell (see |
726f6388 JA |
211 | .SM |
212 | .B INVOCATION | |
213 | below). | |
214 | .TP | |
ccc6cda3 JA |
215 | .B \-\-norc |
216 | Do not read and execute the personal initialization file | |
217 | .I ~/.bashrc | |
218 | if the shell is interactive. | |
219 | This option is on by default if the shell is invoked as | |
220 | .BR sh . | |
221 | .TP | |
222 | .B \-\-posix | |
223 | Change the behavior of \fBbash\fP where the default operation differs | |
ac18b312 | 224 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 | 225 | .TP |
ccc6cda3 JA |
226 | .B \-\-restricted |
227 | The shell becomes restricted (see | |
228 | .SM | |
229 | .B "RESTRICTED SHELL" | |
726f6388 JA |
230 | below). |
231 | .TP | |
ccc6cda3 JA |
232 | .B \-\-verbose |
233 | Equivalent to \fB\-v\fP. | |
726f6388 | 234 | .TP |
ccc6cda3 JA |
235 | .B \-\-version |
236 | Show version information for this instance of | |
237 | .B bash | |
238 | on the standard output and exit successfully. | |
726f6388 JA |
239 | .PD |
240 | .SH ARGUMENTS | |
241 | If arguments remain after option processing, and neither the | |
242 | .B \-c | |
243 | nor the | |
244 | .B \-s | |
245 | option has been supplied, the first argument is assumed to | |
ccc6cda3 JA |
246 | be the name of a file containing shell commands. |
247 | If | |
726f6388 JA |
248 | .B bash |
249 | is invoked in this fashion, | |
250 | .B $0 | |
251 | is set to the name of the file, and the positional parameters | |
252 | are set to the remaining arguments. | |
253 | .B Bash | |
254 | reads and executes commands from this file, then exits. | |
ccc6cda3 JA |
255 | \fBBash\fP's exit status is the exit status of the last command |
256 | executed in the script. | |
257 | If no commands are executed, the exit status is 0. | |
f73dda09 JA |
258 | An attempt is first made to open the file in the current directory, and, |
259 | if no file is found, then the shell searches the directories in | |
260 | .SM | |
261 | .B PATH | |
262 | for the script. | |
ccc6cda3 JA |
263 | .SH INVOCATION |
264 | A \fIlogin shell\fP is one whose first character of argument zero is a | |
265 | .BR \- , | |
266 | or one started with the | |
267 | .B \-\-login | |
268 | option. | |
269 | .PP | |
bb70624e JA |
270 | An \fIinteractive\fP shell is one started without non-option arguments |
271 | and without the | |
272 | .B \-c | |
273 | option | |
da5b17cd | 274 | whose standard input and error are |
ccc6cda3 JA |
275 | both connected to terminals (as determined by |
276 | .IR isatty (3)), | |
277 | or one started with the | |
278 | .B \-i | |
279 | option. | |
280 | .SM | |
281 | .B PS1 | |
282 | is set and | |
283 | .B $\- | |
284 | includes | |
285 | .B i | |
286 | if | |
287 | .B bash | |
288 | is interactive, | |
289 | allowing a shell script or a startup file to test this state. | |
290 | .PP | |
291 | The following paragraphs describe how | |
292 | .B bash | |
293 | executes its startup files. | |
294 | If any of the files exist but cannot be read, | |
295 | .B bash | |
296 | reports an error. | |
b28ff8c9 | 297 | Tildes are expanded in filenames as described below under |
ccc6cda3 JA |
298 | .B "Tilde Expansion" |
299 | in the | |
300 | .SM | |
301 | .B EXPANSION | |
302 | section. | |
303 | .PP | |
304 | When | |
305 | .B bash | |
b72432fd JA |
306 | is invoked as an interactive login shell, or as a non-interactive shell |
307 | with the \fB\-\-login\fP option, it first reads and | |
d166f048 JA |
308 | executes commands from the file \fI/etc/profile\fP, if that |
309 | file exists. | |
ccc6cda3 JA |
310 | After reading that file, it looks for \fI~/.bash_profile\fP, |
311 | \fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads | |
312 | and executes commands from the first one that exists and is readable. | |
313 | The | |
314 | .B \-\-noprofile | |
315 | option may be used when the shell is started to inhibit this behavior. | |
316 | .PP | |
317 | When a login shell exits, | |
318 | .B bash | |
319 | reads and executes commands from the file \fI~/.bash_logout\fP, if it | |
320 | exists. | |
321 | .PP | |
322 | When an interactive shell that is not a login shell is started, | |
323 | .B bash | |
324 | reads and executes commands from \fI~/.bashrc\fP, if that file exists. | |
325 | This may be inhibited by using the | |
326 | .B \-\-norc | |
327 | option. | |
328 | The \fB\-\-rcfile\fP \fIfile\fP option will force | |
329 | .B bash | |
330 | to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP. | |
331 | .PP | |
332 | When | |
333 | .B bash | |
334 | is started non-interactively, to run a shell script, for example, it | |
335 | looks for the variable | |
336 | .SM | |
337 | .B BASH_ENV | |
338 | in the environment, expands its value if it appears there, and uses the | |
339 | expanded value as the name of a file to read and execute. | |
340 | .B Bash | |
341 | behaves as if the following command were executed: | |
342 | .sp .5 | |
343 | .RS | |
28ef6c31 JA |
344 | .if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP |
345 | .if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
ccc6cda3 JA |
346 | .RE |
347 | .sp .5 | |
348 | but the value of the | |
349 | .SM | |
350 | .B PATH | |
b28ff8c9 | 351 | variable is not used to search for the filename. |
ccc6cda3 JA |
352 | .PP |
353 | If | |
354 | .B bash | |
355 | is invoked with the name | |
356 | .BR sh , | |
357 | it tries to mimic the startup behavior of historical versions of | |
358 | .B sh | |
359 | as closely as possible, | |
360 | while conforming to the POSIX standard as well. | |
b72432fd JA |
361 | When invoked as an interactive login shell, or a non-interactive |
362 | shell with the \fB\-\-login\fP option, it first attempts to | |
cce855bc | 363 | read and execute commands from |
ccc6cda3 JA |
364 | .I /etc/profile |
365 | and | |
366 | .IR ~/.profile , | |
367 | in that order. | |
368 | The | |
369 | .B \-\-noprofile | |
370 | option may be used to inhibit this behavior. | |
371 | When invoked as an interactive shell with the name | |
372 | .BR sh , | |
373 | .B bash | |
374 | looks for the variable | |
375 | .SM | |
376 | .BR ENV , | |
377 | expands its value if it is defined, and uses the | |
378 | expanded value as the name of a file to read and execute. | |
379 | Since a shell invoked as | |
380 | .B sh | |
381 | does not attempt to read and execute commands from any other startup | |
382 | files, the | |
383 | .B \-\-rcfile | |
384 | option has no effect. | |
385 | A non-interactive shell invoked with the name | |
386 | .B sh | |
b72432fd | 387 | does not attempt to read any other startup files. |
ccc6cda3 JA |
388 | When invoked as |
389 | .BR sh , | |
390 | .B bash | |
391 | enters | |
392 | .I posix | |
393 | mode after the startup files are read. | |
394 | .PP | |
395 | When | |
396 | .B bash | |
397 | is started in | |
398 | .I posix | |
399 | mode, as with the | |
400 | .B \-\-posix | |
401 | command line option, it follows the POSIX standard for startup files. | |
cce855bc | 402 | In this mode, interactive shells expand the |
ccc6cda3 JA |
403 | .SM |
404 | .B ENV | |
cce855bc | 405 | variable and commands are read and executed from the file |
ccc6cda3 JA |
406 | whose name is the expanded value. |
407 | No other startup files are read. | |
ccc6cda3 JA |
408 | .PP |
409 | .B Bash | |
866961ad | 410 | attempts to determine when it is being run with its standard input |
dc60d4e0 | 411 | connected to a network connection, as when executed by the remote shell |
866961ad | 412 | daemon, usually \fIrshd\fP, or the secure shell daemon \fIsshd\fP. |
ccc6cda3 JA |
413 | If |
414 | .B bash | |
866961ad | 415 | determines it is being run in this fashion, it reads and executes |
ccc6cda3 JA |
416 | commands from \fI~/.bashrc\fP, if that file exists and is readable. |
417 | It will not do this if invoked as \fBsh\fP. | |
418 | The | |
419 | .B \-\-norc | |
420 | option may be used to inhibit this behavior, and the | |
421 | .B \-\-rcfile | |
422 | option may be used to force another file to be read, but | |
423 | \fIrshd\fP does not generally invoke the shell with those options | |
424 | or allow them to be specified. | |
b72432fd JA |
425 | .PP |
426 | If the shell is started with the effective user (group) id not equal to the | |
427 | real user (group) id, and the \fB\-p\fP option is not supplied, no startup | |
f73dda09 JA |
428 | files are read, shell functions are not inherited from the environment, the |
429 | .SM | |
691aebcb | 430 | .BR SHELLOPTS , |
984a1947 | 431 | .SM |
691aebcb | 432 | .BR BASHOPTS , |
984a1947 | 433 | .SM |
691aebcb CR |
434 | .BR CDPATH , |
435 | and | |
984a1947 | 436 | .SM |
691aebcb CR |
437 | .B GLOBIGNORE |
438 | variables, if they appear in the environment, are ignored, | |
b72432fd JA |
439 | and the effective user id is set to the real user id. |
440 | If the \fB\-p\fP option is supplied at invocation, the startup behavior is | |
441 | the same, but the effective user id is not reset. | |
726f6388 | 442 | .SH DEFINITIONS |
ccc6cda3 JA |
443 | .PP |
444 | The following definitions are used throughout the rest of this | |
445 | document. | |
726f6388 JA |
446 | .PD 0 |
447 | .TP | |
448 | .B blank | |
449 | A space or tab. | |
450 | .TP | |
451 | .B word | |
452 | A sequence of characters considered as a single unit by the shell. | |
453 | Also known as a | |
454 | .BR token . | |
455 | .TP | |
456 | .B name | |
457 | A | |
458 | .I word | |
459 | consisting only of alphanumeric characters and underscores, and | |
460 | beginning with an alphabetic character or an underscore. Also | |
461 | referred to as an | |
462 | .BR identifier . | |
463 | .TP | |
464 | .B metacharacter | |
465 | A character that, when unquoted, separates words. One of the following: | |
466 | .br | |
467 | .RS | |
468 | .PP | |
469 | .if t \fB| & ; ( ) < > space tab\fP | |
470 | .if n \fB| & ; ( ) < > space tab\fP | |
471 | .RE | |
472 | .PP | |
473 | .TP | |
474 | .B control operator | |
475 | A \fItoken\fP that performs a control function. It is one of the following | |
476 | symbols: | |
477 | .RS | |
478 | .PP | |
adc6cff5 | 479 | .if t \fB|| & && ; ;; ( ) | |& <newline>\fP |
8943768b | 480 | .if n \fB|| & && ; ;; ( ) | |& <newline>\fP |
726f6388 JA |
481 | .RE |
482 | .PD | |
483 | .SH "RESERVED WORDS" | |
484 | \fIReserved words\fP are words that have a special meaning to the shell. | |
485 | The following words are recognized as reserved when unquoted and either | |
486 | the first word of a simple command (see | |
487 | .SM | |
488 | .B SHELL GRAMMAR | |
489 | below) or the third word of a | |
490 | .B case | |
491 | or | |
492 | .B for | |
493 | command: | |
494 | .if t .RS | |
495 | .PP | |
496 | .B | |
cce855bc JA |
497 | .if n ! case do done elif else esac fi for function if in select then until while { } time [[ ]] |
498 | .if t ! case do done elif else esac fi for function if in select then until while { } time [[ ]] | |
726f6388 | 499 | .if t .RE |
726f6388 JA |
500 | .SH "SHELL GRAMMAR" |
501 | .SS Simple Commands | |
502 | .PP | |
503 | A \fIsimple command\fP is a sequence of optional variable assignments | |
ccc6cda3 | 504 | followed by \fBblank\fP-separated words and redirections, and |
726f6388 | 505 | terminated by a \fIcontrol operator\fP. The first word |
f73dda09 JA |
506 | specifies the command to be executed, and is passed as argument zero. |
507 | The remaining words are passed as arguments to the invoked command. | |
726f6388 JA |
508 | .PP |
509 | The return value of a \fIsimple command\fP is its exit status, or | |
510 | 128+\fIn\^\fP if the command is terminated by signal | |
511 | .IR n . | |
512 | .SS Pipelines | |
513 | .PP | |
514 | A \fIpipeline\fP is a sequence of one or more commands separated by | |
8943768b CR |
515 | one of the control operators |
516 | .B | | |
517 | or \fB|&\fP. | |
726f6388 JA |
518 | The format for a pipeline is: |
519 | .RS | |
520 | .PP | |
8943768b | 521 | [\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ] |
726f6388 JA |
522 | .RE |
523 | .PP | |
524 | The standard output of | |
525 | .I command | |
f73dda09 | 526 | is connected via a pipe to the standard input of |
726f6388 JA |
527 | .IR command2 . |
528 | This connection is performed before any redirections specified by the | |
529 | command (see | |
530 | .SM | |
531 | .B REDIRECTION | |
532 | below). | |
c920c360 CR |
533 | If \fB|&\fP is used, \fIcommand\fP's standard output and standard error |
534 | are connected to | |
535 | \fIcommand2\fP's standard input through the pipe; | |
536 | it is shorthand for \fB2>&1 |\fP. | |
537 | This implicit redirection of the standard error is | |
538 | performed after any redirections specified by the command. | |
726f6388 | 539 | .PP |
d3a24ed2 CR |
540 | The return status of a pipeline is the exit status of the last |
541 | command, unless the \fBpipefail\fP option is enabled. | |
542 | If \fBpipefail\fP is enabled, the pipeline's return status is the | |
543 | value of the last (rightmost) command to exit with a non-zero status, | |
544 | or zero if all commands exit successfully. | |
726f6388 JA |
545 | If the reserved word |
546 | .B ! | |
d3a24ed2 CR |
547 | precedes a pipeline, the exit status of that pipeline is the logical |
548 | negation of the exit status as described above. | |
ccc6cda3 | 549 | The shell waits for all commands in the pipeline to |
726f6388 JA |
550 | terminate before returning a value. |
551 | .PP | |
ccc6cda3 JA |
552 | If the |
553 | .B time | |
554 | reserved word precedes a pipeline, the elapsed as well as user and | |
555 | system time consumed by its execution are reported when the pipeline | |
556 | terminates. | |
557 | The \fB\-p\fP option changes the output format to that specified by POSIX. | |
7d92f73f CR |
558 | When the shell is in \fIposix mode\fP, it does not recognize |
559 | \fBtime\fP as a reserved word if the next token begins with a `-'. | |
ccc6cda3 JA |
560 | The |
561 | .SM | |
562 | .B TIMEFORMAT | |
563 | variable may be set to a format string that specifies how the timing | |
564 | information should be displayed; see the description of | |
565 | .SM | |
566 | .B TIMEFORMAT | |
567 | under | |
568 | .B "Shell Variables" | |
569 | below. | |
570 | .PP | |
6faad625 CR |
571 | When the shell is in \fIposix mode\fP, \fBtime\fP |
572 | may be followed by a newline. In this case, the shell displays the | |
573 | total user and system time consumed by the shell and its children. | |
574 | The | |
575 | .SM | |
576 | .B TIMEFORMAT | |
577 | variable may be used to specify the format of | |
578 | the time information. | |
579 | .PP | |
726f6388 JA |
580 | Each command in a pipeline is executed as a separate process (i.e., in a |
581 | subshell). | |
582 | .SS Lists | |
583 | .PP | |
584 | A \fIlist\fP is a sequence of one or more pipelines separated by one | |
585 | of the operators | |
586 | .BR ; , | |
587 | .BR & , | |
588 | .BR && , | |
589 | or | |
adc6cff5 | 590 | .BR || , |
ccc6cda3 | 591 | and optionally terminated by one of |
726f6388 JA |
592 | .BR ; , |
593 | .BR & , | |
594 | or | |
595 | .BR <newline> . | |
596 | .PP | |
597 | Of these list operators, | |
598 | .B && | |
599 | and | |
adc6cff5 | 600 | .B || |
726f6388 JA |
601 | have equal precedence, followed by |
602 | .B ; | |
603 | and | |
b1a26c01 | 604 | .BR & , |
726f6388 JA |
605 | which have equal precedence. |
606 | .PP | |
7117c2d2 JA |
607 | A sequence of one or more newlines may appear in a \fIlist\fP instead |
608 | of a semicolon to delimit commands. | |
609 | .PP | |
726f6388 JA |
610 | If a command is terminated by the control operator |
611 | .BR & , | |
612 | the shell executes the command in the \fIbackground\fP | |
613 | in a subshell. The shell does not wait for the command to | |
614 | finish, and the return status is 0. Commands separated by a | |
615 | .B ; | |
616 | are executed sequentially; the shell waits for each | |
617 | command to terminate in turn. The return status is the | |
618 | exit status of the last command executed. | |
619 | .PP | |
6fbe7620 | 620 | AND and OR lists are sequences of one of more pipelines separated by the |
adc6cff5 | 621 | \fB&&\fP and \fB||\fP control operators, respectively. |
6fbe7620 | 622 | AND and OR lists are executed with left associativity. |
726f6388 JA |
623 | An AND list has the form |
624 | .RS | |
625 | .PP | |
bb70624e | 626 | \fIcommand1\fP \fB&&\fP \fIcommand2\fP |
726f6388 JA |
627 | .RE |
628 | .PP | |
629 | .I command2 | |
630 | is executed if, and only if, | |
bb70624e | 631 | .I command1 |
726f6388 JA |
632 | returns an exit status of zero. |
633 | .PP | |
634 | An OR list has the form | |
635 | .RS | |
636 | .PP | |
adc6cff5 | 637 | \fIcommand1\fP \fB||\fP \fIcommand2\fP |
726f6388 JA |
638 | .PP |
639 | .RE | |
640 | .PP | |
641 | .I command2 | |
642 | is executed if and only if | |
bb70624e | 643 | .I command1 |
6fbe7620 CR |
644 | returns a non-zero exit status. |
645 | The return status of | |
726f6388 JA |
646 | AND and OR lists is the exit status of the last command |
647 | executed in the list. | |
648 | .SS Compound Commands | |
649 | .PP | |
f4f5e1c2 CR |
650 | A \fIcompound command\fP is one of the following. |
651 | In most cases a \fIlist\fP in a command's description may be separated from | |
652 | the rest of the command by one or more newlines, and may be followed by a | |
653 | newline in place of a semicolon. | |
726f6388 JA |
654 | .TP |
655 | (\fIlist\fP) | |
d3a24ed2 CR |
656 | \fIlist\fP is executed in a subshell environment (see |
657 | .SM | |
658 | \fBCOMMAND EXECUTION ENVIRONMENT\fP | |
659 | below). | |
660 | Variable assignments and builtin | |
726f6388 JA |
661 | commands that affect the shell's environment do not remain in effect |
662 | after the command completes. The return status is the exit status of | |
663 | \fIlist\fP. | |
664 | .TP | |
665 | { \fIlist\fP; } | |
ccc6cda3 JA |
666 | \fIlist\fP is simply executed in the current shell environment. |
667 | \fIlist\fP must be terminated with a newline or semicolon. | |
668 | This is known as a \fIgroup command\fP. | |
669 | The return status is the exit status of | |
726f6388 | 670 | \fIlist\fP. |
d3a24ed2 | 671 | Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and |
f73dda09 JA |
672 | \fB}\fP are \fIreserved words\fP and must occur where a reserved |
673 | word is permitted to be recognized. Since they do not cause a word | |
641d8f00 CR |
674 | break, they must be separated from \fIlist\fP by whitespace or another |
675 | shell metacharacter. | |
726f6388 | 676 | .TP |
ccc6cda3 JA |
677 | ((\fIexpression\fP)) |
678 | The \fIexpression\fP is evaluated according to the rules described | |
679 | below under | |
680 | .SM | |
681 | .BR "ARITHMETIC EVALUATION" . | |
682 | If the value of the expression is non-zero, the return status is 0; | |
683 | otherwise the return status is 1. This is exactly equivalent to | |
684 | \fBlet "\fIexpression\fP"\fR. | |
685 | .TP | |
cce855bc JA |
686 | \fB[[\fP \fIexpression\fP \fB]]\fP |
687 | Return a status of 0 or 1 depending on the evaluation of | |
688 | the conditional expression \fIexpression\fP. | |
689 | Expressions are composed of the primaries described below under | |
690 | .SM | |
691 | .BR "CONDITIONAL EXPRESSIONS" . | |
692 | Word splitting and pathname expansion are not performed on the words | |
15825757 CR |
693 | between the \fB[[\fP and \fB]]\fP; tilde expansion, |
694 | parameter and variable expansion, | |
695 | arithmetic expansion, command substitution, process | |
cce855bc | 696 | substitution, and quote removal are performed. |
d3a24ed2 CR |
697 | Conditional operators such as \fB\-f\fP must be unquoted to be recognized |
698 | as primaries. | |
cce855bc JA |
699 | .if t .sp 0.5 |
700 | .if n .sp 1 | |
54a1fa7c | 701 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
a8fd3f3e CR |
702 | lexicographically using the current locale. |
703 | .if t .sp 0.5 | |
704 | .if n .sp 1 | |
cce855bc JA |
705 | When the \fB==\fP and \fB!=\fP operators are used, the string to the |
706 | right of the operator is considered a pattern and matched according | |
707 | to the rules described below under \fBPattern Matching\fP. | |
2206f89a CR |
708 | If the shell option |
709 | .B nocasematch | |
710 | is enabled, the match is performed without regard to the case | |
711 | of alphabetic characters. | |
dc8fbaf9 CR |
712 | The return value is 0 if the string matches (\fB==\fP) or does not match |
713 | (\fB!=\fP) the pattern, and 1 otherwise. | |
e192f341 CR |
714 | Any part of the pattern may be quoted to force the quoted portion |
715 | to be matched as a string. | |
cce855bc JA |
716 | .if t .sp 0.5 |
717 | .if n .sp 1 | |
d3a24ed2 CR |
718 | An additional binary operator, \fB=~\fP, is available, with the same |
719 | precedence as \fB==\fP and \fB!=\fP. | |
720 | When it is used, the string to the right of the operator is considered | |
721 | an extended regular expression and matched accordingly (as in \fIregex\fP(3)). | |
d7f49990 CR |
722 | The return value is 0 if the string matches |
723 | the pattern, and 1 otherwise. | |
d3a24ed2 CR |
724 | If the regular expression is syntactically incorrect, the conditional |
725 | expression's return value is 2. | |
726 | If the shell option | |
2206f89a | 727 | .B nocasematch |
d3a24ed2 CR |
728 | is enabled, the match is performed without regard to the case |
729 | of alphabetic characters. | |
e192f341 CR |
730 | Any part of the pattern may be quoted to force the quoted portion |
731 | to be matched as a string. | |
d3a24ed2 | 732 | Substrings matched by parenthesized subexpressions within the regular |
984a1947 CR |
733 | expression are saved in the array variable |
734 | .SM | |
735 | .BR BASH_REMATCH . | |
736 | The element of | |
737 | .SM | |
738 | .B BASH_REMATCH | |
739 | with index 0 is the portion of the string | |
d3a24ed2 | 740 | matching the entire regular expression. |
984a1947 CR |
741 | The element of |
742 | .SM | |
743 | .B BASH_REMATCH | |
744 | with index \fIn\fP is the portion of the | |
d3a24ed2 CR |
745 | string matching the \fIn\fPth parenthesized subexpression. |
746 | .if t .sp 0.5 | |
747 | .if n .sp 1 | |
cce855bc JA |
748 | Expressions may be combined using the following operators, listed |
749 | in decreasing order of precedence: | |
750 | .if t .sp 0.5 | |
751 | .if n .sp 1 | |
752 | .RS | |
753 | .PD 0 | |
754 | .TP | |
755 | .B ( \fIexpression\fP ) | |
756 | Returns the value of \fIexpression\fP. | |
757 | This may be used to override the normal precedence of operators. | |
758 | .TP | |
759 | .B ! \fIexpression\fP | |
760 | True if | |
761 | .I expression | |
762 | is false. | |
763 | .TP | |
764 | \fIexpression1\fP \fB&&\fP \fIexpression2\fP | |
765 | True if both | |
766 | .I expression1 | |
767 | and | |
768 | .I expression2 | |
769 | are true. | |
770 | .TP | |
adc6cff5 | 771 | \fIexpression1\fP \fB||\fP \fIexpression2\fP |
cce855bc JA |
772 | True if either |
773 | .I expression1 | |
774 | or | |
775 | .I expression2 | |
776 | is true. | |
777 | .PD | |
cce855bc | 778 | .LP |
adc6cff5 | 779 | The \fB&&\fP and \fB||\fP |
7117c2d2 | 780 | operators do not evaluate \fIexpression2\fP if the value of |
cce855bc JA |
781 | \fIexpression1\fP is sufficient to determine the return value of |
782 | the entire conditional expression. | |
f73dda09 | 783 | .RE |
cce855bc | 784 | .TP |
0d8616ff | 785 | \fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 | 786 | The list of words following \fBin\fP is expanded, generating a list |
bb70624e JA |
787 | of items. |
788 | The variable \fIname\fP is set to each element of this list | |
789 | in turn, and \fIlist\fP is executed each time. | |
790 | If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes | |
791 | \fIlist\fP once for each positional parameter that is set (see | |
726f6388 JA |
792 | .SM |
793 | .B PARAMETERS | |
794 | below). | |
cce855bc JA |
795 | The return status is the exit status of the last command that executes. |
796 | If the expansion of the items following \fBin\fP results in an empty | |
797 | list, no commands are executed, and the return status is 0. | |
726f6388 | 798 | .TP |
bb70624e JA |
799 | \fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
800 | First, the arithmetic expression \fIexpr1\fP is evaluated according | |
801 | to the rules described below under | |
802 | .SM | |
803 | .BR "ARITHMETIC EVALUATION" . | |
804 | The arithmetic expression \fIexpr2\fP is then evaluated repeatedly | |
805 | until it evaluates to zero. | |
806 | Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is | |
807 | executed and the arithmetic expression \fIexpr3\fP is evaluated. | |
808 | If any expression is omitted, it behaves as if it evaluates to 1. | |
809 | The return value is the exit status of the last command in \fIlist\fP | |
810 | that is executed, or false if any of the expressions is invalid. | |
811 | .TP | |
b72432fd | 812 | \fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP |
726f6388 JA |
813 | The list of words following \fBin\fP is expanded, generating a list |
814 | of items. The set of expanded words is printed on the standard | |
815 | error, each preceded by a number. If the \fBin\fP | |
816 | \fIword\fP is omitted, the positional parameters are printed (see | |
817 | .SM | |
818 | .B PARAMETERS | |
819 | below). The | |
984a1947 | 820 | .SM |
726f6388 JA |
821 | .B PS3 |
822 | prompt is then displayed and a line read from the standard input. | |
ccc6cda3 | 823 | If the line consists of a number corresponding to one of |
726f6388 JA |
824 | the displayed words, then the value of |
825 | .I name | |
826 | is set to that word. If the line is empty, the words and prompt | |
827 | are displayed again. If EOF is read, the command completes. Any | |
828 | other value read causes | |
829 | .I name | |
830 | to be set to null. The line read is saved in the variable | |
984a1947 | 831 | .SM |
726f6388 JA |
832 | .BR REPLY . |
833 | The | |
834 | .I list | |
835 | is executed after each selection until a | |
836 | .B break | |
726f6388 JA |
837 | command is executed. |
838 | The exit status of | |
839 | .B select | |
840 | is the exit status of the last command executed in | |
841 | .IR list , | |
842 | or zero if no commands were executed. | |
843 | .TP | |
bb70624e | 844 | \fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \ |
726f6388 JA |
845 | ... ) \fIlist\fP ;; ] ... \fBesac\fP |
846 | A \fBcase\fP command first expands \fIword\fP, and tries to match | |
847 | it against each \fIpattern\fP in turn, using the same matching rules | |
848 | as for pathname expansion (see | |
849 | .B Pathname Expansion | |
2206f89a | 850 | below). |
dc8fbaf9 | 851 | The \fIword\fP is expanded using tilde |
d3ad40de | 852 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 CR |
853 | command substitution, process substitution and quote removal. |
854 | Each \fIpattern\fP examined is expanded using tilde | |
d3ad40de | 855 | expansion, parameter and variable expansion, arithmetic substitution, |
dc8fbaf9 | 856 | command substitution, and process substitution. |
2206f89a CR |
857 | If the shell option |
858 | .B nocasematch | |
859 | is enabled, the match is performed without regard to the case | |
860 | of alphabetic characters. | |
8943768b CR |
861 | When a match is found, the corresponding \fIlist\fP is executed. |
862 | If the \fB;;\fP operator is used, no subsequent matches are attempted after | |
863 | the first pattern match. | |
864 | Using \fB;&\fP in place of \fB;;\fP causes execution to continue with | |
865 | the \fIlist\fP associated with the next set of patterns. | |
866 | Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next | |
867 | pattern list in the statement, if any, and execute any associated \fIlist\fP | |
868 | on a successful match. | |
869 | The exit status is zero if no | |
ccc6cda3 | 870 | pattern matches. Otherwise, it is the exit status of the |
726f6388 JA |
871 | last command executed in \fIlist\fP. |
872 | .TP | |
ccc6cda3 JA |
873 | \fBif\fP \fIlist\fP; \fBthen\fP \fIlist;\fP \ |
874 | [ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \ | |
875 | [ \fBelse\fP \fIlist\fP; ] \fBfi\fP | |
726f6388 JA |
876 | The |
877 | .B if | |
878 | .I list | |
879 | is executed. If its exit status is zero, the | |
880 | \fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP | |
881 | \fIlist\fP is executed in turn, and if its exit status is zero, | |
882 | the corresponding \fBthen\fP \fIlist\fP is executed and the | |
883 | command completes. Otherwise, the \fBelse\fP \fIlist\fP is | |
884 | executed, if present. The exit status is the exit status of the | |
885 | last command executed, or zero if no condition tested true. | |
886 | .TP | |
89c77bc7 | 887 | \fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
7117c2d2 | 888 | .PD 0 |
726f6388 | 889 | .TP |
89c77bc7 | 890 | \fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP |
726f6388 | 891 | .PD |
89c77bc7 CR |
892 | The \fBwhile\fP command continuously executes the list |
893 | \fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns | |
726f6388 JA |
894 | an exit status of zero. The \fBuntil\fP command is identical |
895 | to the \fBwhile\fP command, except that the test is negated; | |
89c77bc7 | 896 | .I list-2 |
726f6388 | 897 | is executed as long as the last command in |
89c77bc7 | 898 | .I list-1 |
ccc6cda3 | 899 | returns a non-zero exit status. |
726f6388 JA |
900 | The exit status of the \fBwhile\fP and \fBuntil\fP commands |
901 | is the exit status | |
89c77bc7 | 902 | of the last command executed in \fIlist-2\fP, or zero if |
726f6388 | 903 | none was executed. |
09767ff0 CR |
904 | .SS Coprocesses |
905 | .PP | |
906 | A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved | |
907 | word. | |
908 | A coprocess is executed asynchronously in a subshell, as if the command | |
909 | had been terminated with the \fB&\fP control operator, with a two-way pipe | |
910 | established between the executing shell and the coprocess. | |
911 | .PP | |
912 | The format for a coprocess is: | |
913 | .RS | |
914 | .PP | |
915 | \fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP] | |
916 | .RE | |
917 | .PP | |
918 | This creates a coprocess named \fINAME\fP. | |
f6da9f85 | 919 | If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP. |
e141c35a CR |
920 | \fINAME\fP must not be supplied if \fIcommand\fP is a \fIsimple |
921 | command\fP (see above); otherwise, it is interpreted as the first word | |
922 | of the simple command. | |
b28ff8c9 | 923 | When the coprocess is executed, the shell creates an array variable (see |
09767ff0 CR |
924 | .B Arrays |
925 | below) named \fINAME\fP in the context of the executing shell. | |
926 | The standard output of | |
927 | .I command | |
928 | is connected via a pipe to a file descriptor in the executing shell, | |
929 | and that file descriptor is assigned to \fINAME\fP[0]. | |
930 | The standard input of | |
931 | .I command | |
932 | is connected via a pipe to a file descriptor in the executing shell, | |
933 | and that file descriptor is assigned to \fINAME\fP[1]. | |
934 | This pipe is established before any redirections specified by the | |
935 | command (see | |
936 | .SM | |
937 | .B REDIRECTION | |
938 | below). | |
939 | The file descriptors can be utilized as arguments to shell commands | |
940 | and redirections using standard word expansions. | |
dc60d4e0 | 941 | The process ID of the shell spawned to execute the coprocess is |
30915f17 CR |
942 | available as the value of the variable \fINAME\fP_PID. |
943 | The \fBwait\fP | |
944 | builtin command may be used to wait for the coprocess to terminate. | |
09767ff0 CR |
945 | .PP |
946 | The return status of a coprocess is the exit status of \fIcommand\fP. | |
d3a24ed2 CR |
947 | .SS Shell Function Definitions |
948 | .PP | |
949 | A shell function is an object that is called like a simple command and | |
950 | executes a compound command with a new set of positional parameters. | |
951 | Shell functions are declared as follows: | |
952 | .TP | |
9ec5ed66 CR |
953 | \fIname\fP () \fIcompound\-command\fP [\fIredirection\fP] |
954 | .PD 0 | |
955 | .TP | |
956 | \fBfunction\fP \fIname\fP [()] \fIcompound\-command\fP [\fIredirection\fP] | |
957 | .PD | |
d3a24ed2 CR |
958 | This defines a function named \fIname\fP. |
959 | The reserved word \fBfunction\fP is optional. | |
960 | If the \fBfunction\fP reserved word is supplied, the parentheses are optional. | |
961 | The \fIbody\fP of the function is the compound command | |
962 | .I compound\-command | |
963 | (see \fBCompound Commands\fP above). | |
964 | That command is usually a \fIlist\fP of commands between { and }, but | |
965 | may be any command listed under \fBCompound Commands\fP above. | |
966 | \fIcompound\-command\fP is executed whenever \fIname\fP is specified as the | |
967 | name of a simple command. | |
b28ff8c9 CR |
968 | When in \fIposix mode\fP, \fIname\fP may not be the name of one of the |
969 | POSIX \fIspecial builtins\fP. | |
d3a24ed2 CR |
970 | Any redirections (see |
971 | .SM | |
972 | .B REDIRECTION | |
973 | below) specified when a function is defined are performed | |
974 | when the function is executed. | |
975 | The exit status of a function definition is zero unless a syntax error | |
976 | occurs or a readonly function with the same name already exists. | |
977 | When executed, the exit status of a function is the exit status of the | |
978 | last command executed in the body. (See | |
726f6388 JA |
979 | .SM |
980 | .B FUNCTIONS | |
981 | below.) | |
982 | .SH COMMENTS | |
ccc6cda3 JA |
983 | In a non-interactive shell, or an interactive shell in which the |
984 | .B interactive_comments | |
985 | option to the | |
986 | .B shopt | |
987 | builtin is enabled (see | |
988 | .SM | |
989 | .B "SHELL BUILTIN COMMANDS" | |
990 | below), a word beginning with | |
726f6388 JA |
991 | .B # |
992 | causes that word and all remaining characters on that line to | |
993 | be ignored. An interactive shell without the | |
ccc6cda3 | 994 | .B interactive_comments |
ccc6cda3 JA |
995 | option enabled does not allow comments. The |
996 | .B interactive_comments | |
997 | option is on by default in interactive shells. | |
726f6388 JA |
998 | .SH QUOTING |
999 | \fIQuoting\fP is used to remove the special meaning of certain | |
1000 | characters or words to the shell. Quoting can be used to | |
1001 | disable special treatment for special characters, to prevent | |
1002 | reserved words from being recognized as such, and to prevent | |
1003 | parameter expansion. | |
1004 | .PP | |
1005 | Each of the \fImetacharacters\fP listed above under | |
1006 | .SM | |
1007 | .B DEFINITIONS | |
bb70624e JA |
1008 | has special meaning to the shell and must be quoted if it is to |
1009 | represent itself. | |
1010 | .PP | |
5c96a638 CR |
1011 | When the command history expansion facilities are being used |
1012 | (see | |
1013 | .SM | |
1014 | .B HISTORY EXPANSION | |
1015 | below), the | |
bb70624e JA |
1016 | \fIhistory expansion\fP character, usually \fB!\fP, must be quoted |
1017 | to prevent history expansion. | |
1018 | .PP | |
1019 | There are three quoting mechanisms: the | |
726f6388 JA |
1020 | .IR "escape character" , |
1021 | single quotes, and double quotes. | |
1022 | .PP | |
1023 | A non-quoted backslash (\fB\e\fP) is the | |
1024 | .IR "escape character" . | |
1025 | It preserves the literal value of the next character that follows, | |
1026 | with the exception of <newline>. If a \fB\e\fP<newline> pair | |
cce855bc JA |
1027 | appears, and the backslash is not itself quoted, the \fB\e\fP<newline> |
1028 | is treated as a line continuation (that is, it is removed from the | |
1029 | input stream and effectively ignored). | |
726f6388 JA |
1030 | .PP |
1031 | Enclosing characters in single quotes preserves the literal value | |
1032 | of each character within the quotes. A single quote may not occur | |
1033 | between single quotes, even when preceded by a backslash. | |
1034 | .PP | |
1035 | Enclosing characters in double quotes preserves the literal value | |
1036 | of all characters within the quotes, with the exception of | |
1037 | .BR $ , | |
3d4e09aa | 1038 | .BR \` , |
5c96a638 CR |
1039 | .BR \e , |
1040 | and, when history expansion is enabled, | |
1041 | .BR ! . | |
726f6388 JA |
1042 | The characters |
1043 | .B $ | |
1044 | and | |
3d4e09aa | 1045 | .B \` |
726f6388 JA |
1046 | retain their special meaning within double quotes. The backslash |
1047 | retains its special meaning only when followed by one of the following | |
1048 | characters: | |
1049 | .BR $ , | |
3d4e09aa | 1050 | .BR \` , |
726f6388 JA |
1051 | \^\fB"\fP\^, |
1052 | .BR \e , | |
1053 | or | |
1054 | .BR <newline> . | |
1055 | A double quote may be quoted within double quotes by preceding it with | |
1056 | a backslash. | |
5c96a638 CR |
1057 | If enabled, history expansion will be performed unless an |
1058 | .B ! | |
1059 | appearing in double quotes is escaped using a backslash. | |
1060 | The backslash preceding the | |
1061 | .B ! | |
1062 | is not removed. | |
726f6388 JA |
1063 | .PP |
1064 | The special parameters | |
1065 | .B * | |
1066 | and | |
1067 | .B @ | |
1068 | have special meaning when in double | |
1069 | quotes (see | |
1070 | .SM | |
1071 | .B PARAMETERS | |
1072 | below). | |
ccc6cda3 | 1073 | .PP |
20587658 | 1074 | Words of the form \fB$\fP\(aq\fIstring\fP\(aq are treated specially. The |
ccc6cda3 | 1075 | word expands to \fIstring\fP, with backslash-escaped characters replaced |
f75912ae | 1076 | as specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
1077 | present, are decoded as follows: |
1078 | .RS | |
1079 | .PD 0 | |
1080 | .TP | |
1081 | .B \ea | |
1082 | alert (bell) | |
1083 | .TP | |
1084 | .B \eb | |
1085 | backspace | |
1086 | .TP | |
1087 | .B \ee | |
a3143574 CR |
1088 | .TP |
1089 | .B \eE | |
ccc6cda3 JA |
1090 | an escape character |
1091 | .TP | |
1092 | .B \ef | |
1093 | form feed | |
1094 | .TP | |
1095 | .B \en | |
1096 | new line | |
1097 | .TP | |
1098 | .B \er | |
1099 | carriage return | |
1100 | .TP | |
1101 | .B \et | |
1102 | horizontal tab | |
1103 | .TP | |
1104 | .B \ev | |
1105 | vertical tab | |
1106 | .TP | |
1107 | .B \e\e | |
1108 | backslash | |
bb70624e | 1109 | .TP |
20587658 | 1110 | .B \e\(aq |
bb70624e | 1111 | single quote |
a3143574 CR |
1112 | .TP |
1113 | .B \e\(dq | |
1114 | double quote | |
ccc6cda3 JA |
1115 | .TP |
1116 | .B \e\fInnn\fP | |
f73dda09 | 1117 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
1118 | (one to three digits) |
1119 | .TP | |
f73dda09 JA |
1120 | .B \ex\fIHH\fP |
1121 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
1122 | (one or two hex digits) | |
7117c2d2 | 1123 | .TP |
eb0b2ad8 CR |
1124 | .B \eu\fIHHHH\fP |
1125 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1126 | \fIHHHH\fP (one to four hex digits) | |
1127 | .TP | |
1128 | .B \eU\fIHHHHHHHH\fP | |
1129 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
1130 | \fIHHHHHHHH\fP (one to eight hex digits) | |
1131 | .TP | |
7117c2d2 JA |
1132 | .B \ec\fIx\fP |
1133 | a control-\fIx\fP character | |
ccc6cda3 JA |
1134 | .PD |
1135 | .RE | |
1136 | .LP | |
bb70624e | 1137 | The expanded result is single-quoted, as if the dollar sign had |
ccc6cda3 JA |
1138 | not been present. |
1139 | .PP | |
08e72d7a CR |
1140 | A double-quoted string preceded by a dollar sign (\fB$\fP\(dq\fIstring\fP\(dq) |
1141 | will cause the string to be translated according to the current locale. | |
ccc6cda3 JA |
1142 | If the current locale is \fBC\fP or \fBPOSIX\fP, the dollar sign |
1143 | is ignored. | |
1144 | If the string is translated and replaced, the replacement is | |
1145 | double-quoted. | |
726f6388 JA |
1146 | .SH PARAMETERS |
1147 | A | |
1148 | .I parameter | |
ccc6cda3 JA |
1149 | is an entity that stores values. |
1150 | It can be a | |
726f6388 JA |
1151 | .IR name , |
1152 | a number, or one of the special characters listed below under | |
1153 | .BR "Special Parameters" . | |
d3a24ed2 | 1154 | A |
726f6388 JA |
1155 | .I variable |
1156 | is a parameter denoted by a | |
1157 | .IR name . | |
f73dda09 JA |
1158 | A variable has a \fIvalue\fP and zero or more \fIattributes\fP. |
1159 | Attributes are assigned using the | |
1160 | .B declare | |
1161 | builtin command (see | |
1162 | .B declare | |
1163 | below in | |
1164 | .SM | |
1165 | .BR "SHELL BUILTIN COMMANDS" ). | |
726f6388 JA |
1166 | .PP |
1167 | A parameter is set if it has been assigned a value. The null string is | |
1168 | a valid value. Once a variable is set, it may be unset only by using | |
1169 | the | |
1170 | .B unset | |
1171 | builtin command (see | |
1172 | .SM | |
1173 | .B SHELL BUILTIN COMMANDS | |
1174 | below). | |
1175 | .PP | |
1176 | A | |
1177 | .I variable | |
1178 | may be assigned to by a statement of the form | |
1179 | .RS | |
1180 | .PP | |
1181 | \fIname\fP=[\fIvalue\fP] | |
1182 | .RE | |
1183 | .PP | |
1184 | If | |
1185 | .I value | |
1186 | is not given, the variable is assigned the null string. All | |
1187 | .I values | |
bb70624e JA |
1188 | undergo tilde expansion, parameter and variable expansion, |
1189 | command substitution, arithmetic expansion, and quote | |
ccc6cda3 JA |
1190 | removal (see |
1191 | .SM | |
1192 | .B EXPANSION | |
1193 | below). If the variable has its | |
cce855bc | 1194 | .B integer |
f73dda09 | 1195 | attribute set, then |
726f6388 | 1196 | .I value |
d3a24ed2 | 1197 | is evaluated as an arithmetic expression even if the $((...)) expansion is |
cce855bc | 1198 | not used (see |
ccc6cda3 JA |
1199 | .B "Arithmetic Expansion" |
1200 | below). | |
1201 | Word splitting is not performed, with the exception | |
726f6388 JA |
1202 | of \fB"$@"\fP as explained below under |
1203 | .BR "Special Parameters" . | |
1204 | Pathname expansion is not performed. | |
f73dda09 | 1205 | Assignment statements may also appear as arguments to the |
5e13499c | 1206 | .BR alias , |
f73dda09 JA |
1207 | .BR declare , |
1208 | .BR typeset , | |
1209 | .BR export , | |
1210 | .BR readonly , | |
1211 | and | |
1212 | .B local | |
1213 | builtin commands. | |
19baff85 CR |
1214 | When in \fIposix mode\fP, these builtins may appear in a command after |
1215 | one or more instances of the \fBcommand\fP builtin and retain these | |
1216 | assignment statement properties. | |
d11b8b46 CR |
1217 | .PP |
1218 | In the context where an assignment statement is assigning a value | |
1219 | to a shell variable or array index, the += operator can be used to | |
1220 | append to or add to the variable's previous value. | |
dc60d4e0 | 1221 | When += is applied to a variable for which the \fIinteger\fP attribute has been |
d11b8b46 CR |
1222 | set, \fIvalue\fP is evaluated as an arithmetic expression and added to the |
1223 | variable's current value, which is also evaluated. | |
1224 | When += is applied to an array variable using compound assignment (see | |
1225 | .B Arrays | |
1226 | below), the | |
1227 | variable's value is not unset (as it is when using =), and new values are | |
fdf670ea CR |
1228 | appended to the array beginning at one greater than the array's maximum index |
1229 | (for indexed arrays) or added as additional key\-value pairs in an | |
1230 | associative array. | |
d11b8b46 CR |
1231 | When applied to a string-valued variable, \fIvalue\fP is expanded and |
1232 | appended to the variable's value. | |
726f6388 JA |
1233 | .SS Positional Parameters |
1234 | .PP | |
1235 | A | |
1236 | .I positional parameter | |
1237 | is a parameter denoted by one or more | |
1238 | digits, other than the single digit 0. Positional parameters are | |
1239 | assigned from the shell's arguments when it is invoked, | |
1240 | and may be reassigned using the | |
1241 | .B set | |
1242 | builtin command. Positional parameters may not be assigned to | |
1243 | with assignment statements. The positional parameters are | |
1244 | temporarily replaced when a shell function is executed (see | |
1245 | .SM | |
1246 | .B FUNCTIONS | |
1247 | below). | |
1248 | .PP | |
1249 | When a positional parameter consisting of more than a single | |
1250 | digit is expanded, it must be enclosed in braces (see | |
1251 | .SM | |
1252 | .B EXPANSION | |
1253 | below). | |
1254 | .SS Special Parameters | |
1255 | .PP | |
1256 | The shell treats several parameters specially. These parameters may | |
1257 | only be referenced; assignment to them is not allowed. | |
1258 | .PD 0 | |
1259 | .TP | |
1260 | .B * | |
1261 | Expands to the positional parameters, starting from one. When the | |
1262 | expansion occurs within double quotes, it expands to a single word | |
1263 | with the value of each parameter separated by the first character | |
1264 | of the | |
1265 | .SM | |
1266 | .B IFS | |
cce855bc JA |
1267 | special variable. That is, "\fB$*\fP" is equivalent |
1268 | to "\fB$1\fP\fIc\fP\fB$2\fP\fIc\fP\fB...\fP", where | |
726f6388 JA |
1269 | .I c |
1270 | is the first character of the value of the | |
1271 | .SM | |
1272 | .B IFS | |
1273 | variable. If | |
1274 | .SM | |
1275 | .B IFS | |
d166f048 JA |
1276 | is unset, the parameters are separated by spaces. |
1277 | If | |
1278 | .SM | |
1279 | .B IFS | |
1280 | is null, the parameters are joined without intervening separators. | |
726f6388 JA |
1281 | .TP |
1282 | .B @ | |
1283 | Expands to the positional parameters, starting from one. When the | |
cce855bc JA |
1284 | expansion occurs within double quotes, each parameter expands to a |
1285 | separate word. That is, "\fB$@\fP" is equivalent to | |
1286 | "\fB$1\fP" "\fB$2\fP" ... | |
be7d8f2d CR |
1287 | If the double-quoted expansion occurs within a word, the expansion of |
1288 | the first parameter is joined with the beginning part of the original | |
1289 | word, and the expansion of the last parameter is joined with the last | |
1290 | part of the original word. | |
cce855bc | 1291 | When there are no positional parameters, "\fB$@\fP" and |
726f6388 JA |
1292 | .B $@ |
1293 | expand to nothing (i.e., they are removed). | |
1294 | .TP | |
1295 | .B # | |
1296 | Expands to the number of positional parameters in decimal. | |
1297 | .TP | |
1298 | .B ? | |
e882163b | 1299 | Expands to the exit status of the most recently executed foreground |
726f6388 JA |
1300 | pipeline. |
1301 | .TP | |
1302 | .B \- | |
1303 | Expands to the current option flags as specified upon invocation, | |
1304 | by the | |
1305 | .B set | |
1306 | builtin command, or those set by the shell itself | |
1307 | (such as the | |
1308 | .B \-i | |
cce855bc | 1309 | option). |
726f6388 JA |
1310 | .TP |
1311 | .B $ | |
1312 | Expands to the process ID of the shell. In a () subshell, it | |
1313 | expands to the process ID of the current shell, not the | |
1314 | subshell. | |
1315 | .TP | |
1316 | .B ! | |
1317 | Expands to the process ID of the most recently executed background | |
1318 | (asynchronous) command. | |
1319 | .TP | |
1320 | .B 0 | |
1321 | Expands to the name of the shell or shell script. This is set at | |
1322 | shell initialization. If | |
1323 | .B bash | |
1324 | is invoked with a file of commands, | |
1325 | .B $0 | |
1326 | is set to the name of that file. If | |
1327 | .B bash | |
1328 | is started with the | |
1329 | .B \-c | |
1330 | option, then | |
1331 | .B $0 | |
1332 | is set to the first argument after the string to be | |
1333 | executed, if one is present. Otherwise, it is set | |
b28ff8c9 | 1334 | to the filename used to invoke |
726f6388 JA |
1335 | .BR bash , |
1336 | as given by argument zero. | |
1337 | .TP | |
1338 | .B _ | |
cc87ba64 CR |
1339 | At shell startup, set to the absolute pathname used to invoke the |
1340 | shell or shell script being executed as passed in the environment | |
1341 | or argument list. | |
ccc6cda3 JA |
1342 | Subsequently, expands to the last argument to the previous command, |
1343 | after expansion. | |
cc87ba64 CR |
1344 | Also set to the full pathname used to invoke each command executed |
1345 | and placed in the environment exported to that command. | |
ccc6cda3 JA |
1346 | When checking mail, this parameter holds the name of the mail file |
1347 | currently being checked. | |
726f6388 JA |
1348 | .PD |
1349 | .SS Shell Variables | |
1350 | .PP | |
1351 | The following variables are set by the shell: | |
1352 | .PP | |
1353 | .PD 0 | |
1354 | .TP | |
726f6388 | 1355 | .B BASH |
b28ff8c9 | 1356 | Expands to the full filename used to invoke this instance of |
726f6388 JA |
1357 | .BR bash . |
1358 | .TP | |
691aebcb CR |
1359 | .B BASHOPTS |
1360 | A colon-separated list of enabled shell options. Each word in | |
1361 | the list is a valid argument for the | |
1362 | .B \-s | |
1363 | option to the | |
1364 | .B shopt | |
1365 | builtin command (see | |
1366 | .SM | |
1367 | .B "SHELL BUILTIN COMMANDS" | |
1368 | below). The options appearing in | |
1369 | .SM | |
1370 | .B BASHOPTS | |
1371 | are those reported as | |
1372 | .I on | |
1373 | by \fBshopt\fP. | |
1374 | If this variable is in the environment when | |
1375 | .B bash | |
1376 | starts up, each shell option in the list will be enabled before | |
1377 | reading any startup files. | |
1378 | This variable is read-only. | |
1379 | .TP | |
d3ad40de | 1380 | .B BASHPID |
dc60d4e0 | 1381 | Expands to the process ID of the current \fBbash\fP process. |
d3ad40de | 1382 | This differs from \fB$$\fP under certain circumstances, such as subshells |
29d25b54 | 1383 | that do not require \fBbash\fP to be re-initialized. |
d3ad40de | 1384 | .TP |
fdf670ea CR |
1385 | .B BASH_ALIASES |
1386 | An associative array variable whose members correspond to the internal | |
5cdaaf76 | 1387 | list of aliases as maintained by the \fBalias\fP builtin. |
fdf670ea CR |
1388 | Elements added to this array appear in the alias list; unsetting array |
1389 | elements cause aliases to be removed from the alias list. | |
1390 | .TP | |
d3a24ed2 CR |
1391 | .B BASH_ARGC |
1392 | An array variable whose values are the number of parameters in each | |
29d25b54 | 1393 | frame of the current \fBbash\fP execution call stack. |
2206f89a | 1394 | The number of |
d3a24ed2 | 1395 | parameters to the current subroutine (shell function or script executed |
2206f89a CR |
1396 | with \fB.\fP or \fBsource\fP) is at the top of the stack. |
1397 | When a subroutine is executed, the number of parameters passed is pushed onto | |
984a1947 CR |
1398 | .SM |
1399 | .BR BASH_ARGC . | |
1400 | The shell sets | |
1401 | .SM | |
1402 | .B BASH_ARGC | |
1403 | only when in extended debugging mode (see the description of the | |
2206f89a CR |
1404 | .B extdebug |
1405 | option to the | |
1406 | .B shopt | |
1407 | builtin below) | |
d3a24ed2 CR |
1408 | .TP |
1409 | .B BASH_ARGV | |
29d25b54 | 1410 | An array variable containing all of the parameters in the current \fBbash\fP |
d3a24ed2 CR |
1411 | execution call stack. The final parameter of the last subroutine call |
1412 | is at the top of the stack; the first parameter of the initial call is | |
1413 | at the bottom. When a subroutine is executed, the parameters supplied | |
984a1947 CR |
1414 | are pushed onto |
1415 | .SM | |
1416 | .BR BASH_ARGV . | |
1417 | The shell sets | |
1418 | .SM | |
1419 | .B BASH_ARGV | |
1420 | only when in extended debugging mode | |
2206f89a CR |
1421 | (see the description of the |
1422 | .B extdebug | |
1423 | option to the | |
1424 | .B shopt | |
1425 | builtin below) | |
d3a24ed2 | 1426 | .TP |
fdf670ea CR |
1427 | .B BASH_CMDS |
1428 | An associative array variable whose members correspond to the internal | |
1429 | hash table of commands as maintained by the \fBhash\fP builtin. | |
1430 | Elements added to this array appear in the hash table; unsetting array | |
1431 | elements cause commands to be removed from the hash table. | |
1432 | .TP | |
d3a24ed2 CR |
1433 | .B BASH_COMMAND |
1434 | The command currently being executed or about to be executed, unless the | |
1435 | shell is executing a command as the result of a trap, | |
1436 | in which case it is the command executing at the time of the trap. | |
1437 | .TP | |
1438 | .B BASH_EXECUTION_STRING | |
1439 | The command argument to the \fB\-c\fP invocation option. | |
1440 | .TP | |
1441 | .B BASH_LINENO | |
1442 | An array variable whose members are the line numbers in source files | |
7d92f73f | 1443 | where each corresponding member of |
984a1947 | 1444 | .SM |
7d92f73f CR |
1445 | .B FUNCNAME |
1446 | was invoked. | |
d3a24ed2 | 1447 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP is the line number in the source |
7d92f73f CR |
1448 | file (\fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP) where |
1449 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called | |
3d4e09aa CR |
1450 | (or \fB${BASH_LINENO[\fP\fI$i-1\fP\fB]}\fP if referenced within another |
1451 | shell function). | |
984a1947 CR |
1452 | Use |
1453 | .SM | |
1454 | .B LINENO | |
1455 | to obtain the current line number. | |
d3a24ed2 CR |
1456 | .TP |
1457 | .B BASH_REMATCH | |
1458 | An array variable whose members are assigned by the \fB=~\fP binary | |
1459 | operator to the \fB[[\fP conditional command. | |
1460 | The element with index 0 is the portion of the string | |
1461 | matching the entire regular expression. | |
1462 | The element with index \fIn\fP is the portion of the | |
1463 | string matching the \fIn\fPth parenthesized subexpression. | |
1464 | This variable is read-only. | |
1465 | .TP | |
1466 | .B BASH_SOURCE | |
7d92f73f CR |
1467 | An array variable whose members are the source filenames |
1468 | where the corresponding shell function names in the | |
984a1947 CR |
1469 | .SM |
1470 | .B FUNCNAME | |
7d92f73f CR |
1471 | array variable are defined. |
1472 | The shell function | |
1473 | \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP is defined in the file | |
1474 | \fB${BASH_SOURCE[\fP\fI$i\fP\fB]}\fP and called from | |
1475 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP. | |
d3a24ed2 CR |
1476 | .TP |
1477 | .B BASH_SUBSHELL | |
c1854f2d CR |
1478 | Incremented by one within each subshell or subshell environment when |
1479 | the shell begins executing in that environment. | |
d3a24ed2 CR |
1480 | The initial value is 0. |
1481 | .TP | |
ccc6cda3 | 1482 | .B BASH_VERSINFO |
cce855bc JA |
1483 | A readonly array variable whose members hold version information for |
1484 | this instance of | |
ccc6cda3 JA |
1485 | .BR bash . |
1486 | The values assigned to the array members are as follows: | |
1487 | .sp .5 | |
1488 | .RS | |
ccc6cda3 JA |
1489 | .TP 24 |
1490 | .B BASH_VERSINFO[\fR0\fP] | |
1491 | The major version number (the \fIrelease\fP). | |
1492 | .TP | |
1493 | .B BASH_VERSINFO[\fR1\fP] | |
1494 | The minor version number (the \fIversion\fP). | |
1495 | .TP | |
1496 | .B BASH_VERSINFO[\fR2\fP] | |
1497 | The patch level. | |
1498 | .TP | |
1499 | .B BASH_VERSINFO[\fR3\fP] | |
1500 | The build version. | |
1501 | .TP | |
1502 | .B BASH_VERSINFO[\fR4\fP] | |
1503 | The release status (e.g., \fIbeta1\fP). | |
1504 | .TP | |
1505 | .B BASH_VERSINFO[\fR5\fP] | |
984a1947 CR |
1506 | The value of |
1507 | .SM | |
1508 | .BR MACHTYPE . | |
ccc6cda3 JA |
1509 | .RE |
1510 | .TP | |
f73dda09 JA |
1511 | .B BASH_VERSION |
1512 | Expands to a string describing the version of this instance of | |
1513 | .BR bash . | |
726f6388 | 1514 | .TP |
f73dda09 JA |
1515 | .B COMP_CWORD |
1516 | An index into \fB${COMP_WORDS}\fP of the word containing the current | |
1517 | cursor position. | |
1518 | This variable is available only in shell functions invoked by the | |
1519 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1520 | below). | |
1521 | .TP | |
d3ad40de CR |
1522 | .B COMP_KEY |
1523 | The key (or final key of a key sequence) used to invoke the current | |
1524 | completion function. | |
1525 | .TP | |
f73dda09 JA |
1526 | .B COMP_LINE |
1527 | The current command line. | |
1528 | This variable is available only in shell functions and external | |
1529 | commands invoked by the | |
1530 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1531 | below). | |
1532 | .TP | |
1533 | .B COMP_POINT | |
1534 | The index of the current cursor position relative to the beginning of | |
1535 | the current command. | |
1536 | If the current cursor position is at the end of the current command, | |
1537 | the value of this variable is equal to \fB${#COMP_LINE}\fP. | |
1538 | This variable is available only in shell functions and external | |
1539 | commands invoked by the | |
1540 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1541 | below). | |
1542 | .TP | |
d3ad40de CR |
1543 | .B COMP_TYPE |
1544 | Set to an integer value corresponding to the type of completion attempted | |
1545 | that caused a completion function to be called: | |
1546 | \fITAB\fP, for normal completion, | |
1547 | \fI?\fP, for listing completions after successive tabs, | |
1548 | \fI!\fP, for listing alternatives on partial word completion, | |
1549 | \fI@\fP, to list completions if the word is not unmodified, | |
1550 | or | |
1551 | \fI%\fP, for menu completion. | |
1552 | This variable is available only in shell functions and external | |
1553 | commands invoked by the | |
1554 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1555 | below). | |
1556 | .TP | |
d3a24ed2 | 1557 | .B COMP_WORDBREAKS |
db31fb26 | 1558 | The set of characters that the \fBreadline\fP library treats as word |
d3a24ed2 CR |
1559 | separators when performing word completion. |
1560 | If | |
1561 | .SM | |
1562 | .B COMP_WORDBREAKS | |
1563 | is unset, it loses its special properties, even if it is | |
1564 | subsequently reset. | |
1565 | .TP | |
f73dda09 JA |
1566 | .B COMP_WORDS |
1567 | An array variable (see \fBArrays\fP below) consisting of the individual | |
1568 | words in the current command line. | |
db31fb26 | 1569 | The line is split into words as \fBreadline\fP would split it, using |
984a1947 CR |
1570 | .SM |
1571 | .B COMP_WORDBREAKS | |
1572 | as described above. | |
f73dda09 JA |
1573 | This variable is available only in shell functions invoked by the |
1574 | programmable completion facilities (see \fBProgrammable Completion\fP | |
1575 | below). | |
1576 | .TP | |
5cdaaf76 CR |
1577 | .B COPROC |
1578 | An array variable (see \fBArrays\fP below) created to hold the file descriptors | |
1579 | for output from and input to an unnamed coprocess (see \fBCoprocesses\fP | |
1580 | above). | |
1581 | .TP | |
f73dda09 JA |
1582 | .B DIRSTACK |
1583 | An array variable (see | |
1584 | .B Arrays | |
1585 | below) containing the current contents of the directory stack. | |
1586 | Directories appear in the stack in the order they are displayed by the | |
1587 | .B dirs | |
1588 | builtin. | |
1589 | Assigning to members of this array variable may be used to modify | |
1590 | directories already in the stack, but the | |
1591 | .B pushd | |
1592 | and | |
1593 | .B popd | |
1594 | builtins must be used to add and remove directories. | |
1595 | Assignment to this variable will not change the current directory. | |
726f6388 JA |
1596 | If |
1597 | .SM | |
f73dda09 | 1598 | .B DIRSTACK |
726f6388 JA |
1599 | is unset, it loses its special properties, even if it is |
1600 | subsequently reset. | |
1601 | .TP | |
f73dda09 JA |
1602 | .B EUID |
1603 | Expands to the effective user ID of the current user, initialized at | |
1604 | shell startup. This variable is readonly. | |
1605 | .TP | |
1606 | .B FUNCNAME | |
d3a24ed2 CR |
1607 | An array variable containing the names of all shell functions |
1608 | currently in the execution call stack. | |
1609 | The element with index 0 is the name of any currently-executing | |
1610 | shell function. | |
7d92f73f | 1611 | The bottom-most element (the one with the highest index) is |
d3ad40de CR |
1612 | .if t \f(CW"main"\fP. |
1613 | .if n "main". | |
f73dda09 JA |
1614 | This variable exists only when a shell function is executing. |
1615 | Assignments to | |
726f6388 | 1616 | .SM |
f73dda09 JA |
1617 | .B FUNCNAME |
1618 | have no effect and return an error status. | |
726f6388 JA |
1619 | If |
1620 | .SM | |
f73dda09 | 1621 | .B FUNCNAME |
726f6388 JA |
1622 | is unset, it loses its special properties, even if it is |
1623 | subsequently reset. | |
7d92f73f CR |
1624 | .if t .sp 0.5 |
1625 | .if n .sp 1 | |
1626 | This variable can be used with \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP. | |
1627 | Each element of \fBFUNCNAME\fP has corresponding elements in | |
1628 | \fBBASH_LINENO\fP and \fBBASH_SOURCE\fP to describe the call stack. | |
1629 | For instance, \fB${FUNCNAME[\fP\fI$i\fP\fB]}\fP was called from the file | |
1630 | \fB${BASH_SOURCE[\fP\fI$i+1\fP\fB]}\fP at line number | |
1631 | \fB${BASH_LINENO[\fP\fI$i\fP\fB]}\fP. | |
1632 | The \fBcaller\fP builtin displays the current call stack using this | |
1633 | information. | |
726f6388 | 1634 | .TP |
f73dda09 JA |
1635 | .B GROUPS |
1636 | An array variable containing the list of groups of which the current | |
1637 | user is a member. | |
1638 | Assignments to | |
1639 | .SM | |
1640 | .B GROUPS | |
1641 | have no effect and return an error status. | |
726f6388 JA |
1642 | If |
1643 | .SM | |
f73dda09 | 1644 | .B GROUPS |
726f6388 JA |
1645 | is unset, it loses its special properties, even if it is |
1646 | subsequently reset. | |
1647 | .TP | |
1648 | .B HISTCMD | |
1649 | The history number, or index in the history list, of the current | |
ccc6cda3 JA |
1650 | command. |
1651 | If | |
726f6388 JA |
1652 | .SM |
1653 | .B HISTCMD | |
1654 | is unset, it loses its special properties, even if it is | |
1655 | subsequently reset. | |
1656 | .TP | |
f73dda09 JA |
1657 | .B HOSTNAME |
1658 | Automatically set to the name of the current host. | |
bb70624e | 1659 | .TP |
f73dda09 JA |
1660 | .B HOSTTYPE |
1661 | Automatically set to a string that uniquely | |
1662 | describes the type of machine on which | |
1663 | .B bash | |
1664 | is executing. | |
1665 | The default is system-dependent. | |
1666 | .TP | |
1667 | .B LINENO | |
1668 | Each time this parameter is referenced, the shell substitutes | |
1669 | a decimal number representing the current sequential line number | |
1670 | (starting with 1) within a script or function. When not in a | |
1671 | script or function, the value substituted is not guaranteed to | |
1672 | be meaningful. | |
ccc6cda3 JA |
1673 | If |
1674 | .SM | |
f73dda09 | 1675 | .B LINENO |
ccc6cda3 JA |
1676 | is unset, it loses its special properties, even if it is |
1677 | subsequently reset. | |
1678 | .TP | |
f73dda09 JA |
1679 | .B MACHTYPE |
1680 | Automatically set to a string that fully describes the system | |
1681 | type on which | |
1682 | .B bash | |
1683 | is executing, in the standard GNU \fIcpu-company-system\fP format. | |
1684 | The default is system-dependent. | |
1685 | .TP | |
5cdaaf76 CR |
1686 | .B MAPFILE |
1687 | An array variable (see \fBArrays\fP below) created to hold the text | |
1688 | read by the \fBmapfile\fP builtin when no variable name is supplied. | |
1689 | .TP | |
f73dda09 JA |
1690 | .B OLDPWD |
1691 | The previous working directory as set by the | |
1692 | .B cd | |
1693 | command. | |
ccc6cda3 | 1694 | .TP |
726f6388 JA |
1695 | .B OPTARG |
1696 | The value of the last option argument processed by the | |
1697 | .B getopts | |
1698 | builtin command (see | |
1699 | .SM | |
1700 | .B SHELL BUILTIN COMMANDS | |
1701 | below). | |
1702 | .TP | |
1703 | .B OPTIND | |
1704 | The index of the next argument to be processed by the | |
1705 | .B getopts | |
1706 | builtin command (see | |
1707 | .SM | |
1708 | .B SHELL BUILTIN COMMANDS | |
1709 | below). | |
1710 | .TP | |
726f6388 JA |
1711 | .B OSTYPE |
1712 | Automatically set to a string that | |
1713 | describes the operating system on which | |
1714 | .B bash | |
ccc6cda3 JA |
1715 | is executing. |
1716 | The default is system-dependent. | |
1717 | .TP | |
f73dda09 JA |
1718 | .B PIPESTATUS |
1719 | An array variable (see | |
1720 | .B Arrays | |
1721 | below) containing a list of exit status values from the processes | |
1722 | in the most-recently-executed foreground pipeline (which may | |
1723 | contain only a single command). | |
ccc6cda3 | 1724 | .TP |
f73dda09 JA |
1725 | .B PPID |
1726 | The process ID of the shell's parent. This variable is readonly. | |
1727 | .TP | |
1728 | .B PWD | |
1729 | The current working directory as set by the | |
1730 | .B cd | |
1731 | command. | |
1732 | .TP | |
1733 | .B RANDOM | |
1734 | Each time this parameter is referenced, a random integer between | |
1735 | 0 and 32767 is | |
1736 | generated. The sequence of random numbers may be initialized by assigning | |
1737 | a value to | |
1738 | .SM | |
1739 | .BR RANDOM . | |
1740 | If | |
1741 | .SM | |
1742 | .B RANDOM | |
1743 | is unset, it loses its special properties, even if it is | |
1744 | subsequently reset. | |
1745 | .TP | |
5cdaaf76 CR |
1746 | .B READLINE_LINE |
1747 | The contents of the | |
1748 | .B readline | |
1749 | line buffer, for use with | |
1750 | .if t \f(CWbind -x\fP | |
1751 | .if n "bind -x" | |
1752 | (see | |
1753 | .SM | |
1754 | .B "SHELL BUILTIN COMMANDS" | |
1755 | below). | |
1756 | .TP | |
1757 | .B READLINE_POINT | |
1758 | The position of the insertion point in the | |
1759 | .B readline | |
1760 | line buffer, for use with | |
1761 | .if t \f(CWbind -x\fP | |
1762 | .if n "bind -x" | |
1763 | (see | |
1764 | .SM | |
1765 | .B "SHELL BUILTIN COMMANDS" | |
1766 | below). | |
1767 | .TP | |
f73dda09 JA |
1768 | .B REPLY |
1769 | Set to the line of input read by the | |
1770 | .B read | |
1771 | builtin command when no arguments are supplied. | |
1772 | .TP | |
1773 | .B SECONDS | |
1774 | Each time this parameter is | |
1775 | referenced, the number of seconds since shell invocation is returned. If a | |
1776 | value is assigned to | |
1777 | .SM | |
1778 | .BR SECONDS , | |
1779 | the value returned upon subsequent | |
1780 | references is | |
1781 | the number of seconds since the assignment plus the value assigned. | |
1782 | If | |
1783 | .SM | |
1784 | .B SECONDS | |
1785 | is unset, it loses its special properties, even if it is | |
1786 | subsequently reset. | |
1787 | .TP | |
1788 | .B SHELLOPTS | |
1789 | A colon-separated list of enabled shell options. Each word in | |
1790 | the list is a valid argument for the | |
1791 | .B \-o | |
1792 | option to the | |
1793 | .B set | |
1794 | builtin command (see | |
1795 | .SM | |
1796 | .B "SHELL BUILTIN COMMANDS" | |
1797 | below). The options appearing in | |
ccc6cda3 JA |
1798 | .SM |
1799 | .B SHELLOPTS | |
1800 | are those reported as | |
1801 | .I on | |
1802 | by \fBset \-o\fP. | |
1803 | If this variable is in the environment when | |
1804 | .B bash | |
1805 | starts up, each shell option in the list will be enabled before | |
1806 | reading any startup files. | |
1807 | This variable is read-only. | |
bb70624e | 1808 | .TP |
f73dda09 JA |
1809 | .B SHLVL |
1810 | Incremented by one each time an instance of | |
1811 | .B bash | |
1812 | is started. | |
bb70624e | 1813 | .TP |
f73dda09 JA |
1814 | .B UID |
1815 | Expands to the user ID of the current user, initialized at shell startup. | |
1816 | This variable is readonly. | |
726f6388 JA |
1817 | .PD |
1818 | .PP | |
1819 | The following variables are used by the shell. In some cases, | |
1820 | .B bash | |
1821 | assigns a default value to a variable; these cases are noted | |
1822 | below. | |
1823 | .PP | |
1824 | .PD 0 | |
1825 | .TP | |
d166f048 | 1826 | .B BASH_ENV |
726f6388 JA |
1827 | If this parameter is set when \fBbash\fP is executing a shell script, |
1828 | its value is interpreted as a filename containing commands to | |
1829 | initialize the shell, as in | |
cce855bc | 1830 | .IR ~/.bashrc . |
726f6388 JA |
1831 | The value of |
1832 | .SM | |
d166f048 | 1833 | .B BASH_ENV |
726f6388 | 1834 | is subjected to parameter expansion, command substitution, and arithmetic |
b28ff8c9 | 1835 | expansion before being interpreted as a filename. |
726f6388 JA |
1836 | .SM |
1837 | .B PATH | |
b28ff8c9 | 1838 | is not used to search for the resultant filename. |
726f6388 | 1839 | .TP |
8f714a7c CR |
1840 | .B BASH_XTRACEFD |
1841 | If set to an integer corresponding to a valid file descriptor, \fBbash\fP | |
1842 | will write the trace output generated when | |
1843 | .if t \f(CWset -x\fP | |
1844 | .if n \fIset -x\fP | |
1845 | is enabled to that file descriptor. | |
984a1947 CR |
1846 | The file descriptor is closed when |
1847 | .SM | |
1848 | .B BASH_XTRACEFD | |
1849 | is unset or assigned a new value. | |
1850 | Unsetting | |
1851 | .SM | |
1852 | .B BASH_XTRACEFD | |
1853 | or assigning it the empty string causes the | |
8f714a7c | 1854 | trace output to be sent to the standard error. |
984a1947 CR |
1855 | Note that setting |
1856 | .SM | |
1857 | .B BASH_XTRACEFD | |
1858 | to 2 (the standard error file | |
8f714a7c CR |
1859 | descriptor) and then unsetting it will result in the standard error |
1860 | being closed. | |
1861 | .TP | |
5cdaaf76 CR |
1862 | .B CDPATH |
1863 | The search path for the | |
1864 | .B cd | |
1865 | command. | |
1866 | This is a colon-separated list of directories in which the shell looks | |
1867 | for destination directories specified by the | |
1868 | .B cd | |
1869 | command. | |
1870 | A sample value is | |
1871 | .if t \f(CW".:~:/usr"\fP. | |
1872 | .if n ".:~:/usr". | |
1873 | .TP | |
f73dda09 | 1874 | .B COLUMNS |
54a1fa7c | 1875 | Used by the \fBselect\fP compound command to determine the terminal width |
276cb932 CR |
1876 | when printing selection lists. Automatically set in an interactive shell |
1877 | upon receipt of a | |
9c7f20c7 CR |
1878 | .SM |
1879 | .BR SIGWINCH . | |
726f6388 | 1880 | .TP |
f73dda09 JA |
1881 | .B COMPREPLY |
1882 | An array variable from which \fBbash\fP reads the possible completions | |
1883 | generated by a shell function invoked by the programmable completion | |
1884 | facility (see \fBProgrammable Completion\fP below). | |
726f6388 | 1885 | .TP |
d3a24ed2 CR |
1886 | .B EMACS |
1887 | If \fBbash\fP finds this variable in the environment when the shell starts | |
1888 | with value | |
1889 | .if t \f(CWt\fP, | |
1890 | .if n "t", | |
5f8cde23 | 1891 | it assumes that the shell is running in an Emacs shell buffer and disables |
d3a24ed2 CR |
1892 | line editing. |
1893 | .TP | |
5cdaaf76 CR |
1894 | .B ENV |
1895 | Similar to | |
1896 | .SM | |
1897 | .BR BASH_ENV ; | |
1898 | used when the shell is invoked in POSIX mode. | |
1899 | .TP | |
f73dda09 JA |
1900 | .B FCEDIT |
1901 | The default editor for the | |
1902 | .B fc | |
1903 | builtin command. | |
726f6388 | 1904 | .TP |
f73dda09 JA |
1905 | .B FIGNORE |
1906 | A colon-separated list of suffixes to ignore when performing | |
1907 | filename completion (see | |
726f6388 | 1908 | .SM |
f73dda09 JA |
1909 | .B READLINE |
1910 | below). | |
1911 | A filename whose suffix matches one of the entries in | |
726f6388 | 1912 | .SM |
f73dda09 JA |
1913 | .B FIGNORE |
1914 | is excluded from the list of matched filenames. | |
7117c2d2 JA |
1915 | A sample value is |
1916 | .if t \f(CW".o:~"\fP. | |
1917 | .if n ".o:~". | |
ccc6cda3 | 1918 | .TP |
6faad625 CR |
1919 | .B FUNCNEST |
1920 | If set to a numeric value greater than 0, defines a maximum function | |
1921 | nesting level. Function invocations that exceed this nesting level | |
1922 | will cause the current command to abort. | |
1923 | .TP | |
f73dda09 JA |
1924 | .B GLOBIGNORE |
1925 | A colon-separated list of patterns defining the set of filenames to | |
1926 | be ignored by pathname expansion. | |
1927 | If a filename matched by a pathname expansion pattern also matches one | |
1928 | of the patterns in | |
726f6388 | 1929 | .SM |
f73dda09 JA |
1930 | .BR GLOBIGNORE , |
1931 | it is removed from the list of matches. | |
1932 | .TP | |
1933 | .B HISTCONTROL | |
d3a24ed2 CR |
1934 | A colon-separated list of values controlling how commands are saved on |
1935 | the history list. | |
1936 | If the list of values includes | |
f73dda09 JA |
1937 | .IR ignorespace , |
1938 | lines which begin with a | |
1939 | .B space | |
d3a24ed2 CR |
1940 | character are not saved in the history list. |
1941 | A value of | |
1942 | .I ignoredups | |
1943 | causes lines matching the previous history entry to not be saved. | |
f73dda09 JA |
1944 | A value of |
1945 | .I ignoreboth | |
d3a24ed2 CR |
1946 | is shorthand for \fIignorespace\fP and \fIignoredups\fP. |
1947 | A value of | |
1948 | .IR erasedups | |
1949 | causes all previous lines matching the current line to be removed from | |
1950 | the history list before that line is saved. | |
1951 | Any value not in the above list is ignored. | |
984a1947 CR |
1952 | If |
1953 | .SM | |
1954 | .B HISTCONTROL | |
1955 | is unset, or does not include a valid value, | |
d3a24ed2 CR |
1956 | all lines read by the shell parser are saved on the history list, |
1957 | subject to the value of | |
984a1947 | 1958 | .SM |
f73dda09 JA |
1959 | .BR HISTIGNORE . |
1960 | The second and subsequent lines of a multi-line compound command are | |
1961 | not tested, and are added to the history regardless of the value of | |
984a1947 | 1962 | .SM |
f73dda09 | 1963 | .BR HISTCONTROL . |
726f6388 JA |
1964 | .TP |
1965 | .B HISTFILE | |
ccc6cda3 | 1966 | The name of the file in which command history is saved (see |
726f6388 JA |
1967 | .SM |
1968 | .B HISTORY | |
ccc6cda3 | 1969 | below). The default value is \fI~/.bash_history\fP. If unset, the |
726f6388 JA |
1970 | command history is not saved when an interactive shell exits. |
1971 | .TP | |
1972 | .B HISTFILESIZE | |
1973 | The maximum number of lines contained in the history file. When this | |
1974 | variable is assigned a value, the history file is truncated, if | |
d3ad40de CR |
1975 | necessary, by removing the oldest entries, |
1976 | to contain no more than that number of lines. The default | |
ccc6cda3 JA |
1977 | value is 500. The history file is also truncated to this size after |
1978 | writing it when an interactive shell exits. | |
726f6388 | 1979 | .TP |
f73dda09 JA |
1980 | .B HISTIGNORE |
1981 | A colon-separated list of patterns used to decide which command lines | |
1982 | should be saved on the history list. Each pattern is anchored at the | |
1983 | beginning of the line and must match the complete line (no implicit | |
1984 | `\fB*\fP' is appended). Each pattern is tested against the line | |
1985 | after the checks specified by | |
984a1947 | 1986 | .SM |
f73dda09 JA |
1987 | .B HISTCONTROL |
1988 | are applied. | |
1989 | In addition to the normal shell pattern matching characters, `\fB&\fP' | |
1990 | matches the previous history line. `\fB&\fP' may be escaped using a | |
1991 | backslash; the backslash is removed before attempting a match. | |
1992 | The second and subsequent lines of a multi-line compound command are | |
1993 | not tested, and are added to the history regardless of the value of | |
984a1947 | 1994 | .SM |
f73dda09 JA |
1995 | .BR HISTIGNORE . |
1996 | .TP | |
1997 | .B HISTSIZE | |
1998 | The number of commands to remember in the command history (see | |
1999 | .SM | |
2000 | .B HISTORY | |
2001 | below). The default value is 500. | |
2002 | .TP | |
d3a24ed2 CR |
2003 | .B HISTTIMEFORMAT |
2004 | If this variable is set and not null, its value is used as a format string | |
2005 | for \fIstrftime\fP(3) to print the time stamp associated with each history | |
2006 | entry displayed by the \fBhistory\fP builtin. | |
2007 | If this variable is set, time stamps are written to the history file so | |
2008 | they may be preserved across shell sessions. | |
d3ad40de CR |
2009 | This uses the history comment character to distinguish timestamps from |
2010 | other history lines. | |
d3a24ed2 | 2011 | .TP |
f73dda09 JA |
2012 | .B HOME |
2013 | The home directory of the current user; the default argument for the | |
2014 | \fBcd\fP builtin command. | |
2015 | The value of this variable is also used when performing tilde expansion. | |
2016 | .TP | |
2017 | .B HOSTFILE | |
2018 | Contains the name of a file in the same format as | |
2019 | .FN /etc/hosts | |
2020 | that should be read when the shell needs to complete a | |
2021 | hostname. | |
2022 | The list of possible hostname completions may be changed while the | |
2023 | shell is running; | |
2024 | the next time hostname completion is attempted after the | |
2025 | value is changed, | |
726f6388 | 2026 | .B bash |
f73dda09 JA |
2027 | adds the contents of the new file to the existing list. |
2028 | If | |
726f6388 | 2029 | .SM |
f73dda09 | 2030 | .B HOSTFILE |
9dd88db7 CR |
2031 | is set, but has no value, or does not name a readable file, |
2032 | \fBbash\fP attempts to read | |
f73dda09 JA |
2033 | .FN /etc/hosts |
2034 | to obtain the list of possible hostname completions. | |
2035 | When | |
726f6388 | 2036 | .SM |
f73dda09 JA |
2037 | .B HOSTFILE |
2038 | is unset, the hostname list is cleared. | |
2039 | .TP | |
2040 | .B IFS | |
2041 | The | |
2042 | .I Internal Field Separator | |
2043 | that is used | |
2044 | for word splitting after expansion and to | |
2045 | split lines into words with the | |
2046 | .B read | |
2047 | builtin command. The default value is | |
2048 | ``<space><tab><newline>''. | |
2049 | .TP | |
2050 | .B IGNOREEOF | |
2051 | Controls the | |
2052 | action of an interactive shell on receipt of an | |
2053 | .SM | |
2054 | .B EOF | |
2055 | character as the sole input. If set, the value is the number of | |
2056 | consecutive | |
2057 | .SM | |
2058 | .B EOF | |
2059 | characters which must be | |
2060 | typed as the first characters on an input line before | |
2061 | .B bash | |
2062 | exits. If the variable exists but does not have a numeric value, or | |
2063 | has no value, the default value is 10. If it does not exist, | |
2064 | .SM | |
2065 | .B EOF | |
2066 | signifies the end of input to the shell. | |
2067 | .TP | |
2068 | .B INPUTRC | |
2069 | The filename for the | |
2070 | .B readline | |
2071 | startup file, overriding the default of | |
2072 | .FN ~/.inputrc | |
2073 | (see | |
2074 | .SM | |
2075 | .B READLINE | |
2076 | below). | |
726f6388 | 2077 | .TP |
ccc6cda3 JA |
2078 | .B LANG |
2079 | Used to determine the locale category for any category not specifically | |
2080 | selected with a variable starting with \fBLC_\fP. | |
2081 | .TP | |
2082 | .B LC_ALL | |
984a1947 CR |
2083 | This variable overrides the value of |
2084 | .SM | |
2085 | .B LANG | |
2086 | and any other | |
ccc6cda3 JA |
2087 | \fBLC_\fP variable specifying a locale category. |
2088 | .TP | |
2089 | .B LC_COLLATE | |
2090 | This variable determines the collation order used when sorting the | |
cce855bc JA |
2091 | results of pathname expansion, and determines the behavior of range |
2092 | expressions, equivalence classes, and collating sequences within | |
2093 | pathname expansion and pattern matching. | |
2094 | .TP | |
2095 | .B LC_CTYPE | |
2096 | This variable determines the interpretation of characters and the | |
2097 | behavior of character classes within pathname expansion and pattern | |
2098 | matching. | |
ccc6cda3 JA |
2099 | .TP |
2100 | .B LC_MESSAGES | |
2101 | This variable determines the locale used to translate double-quoted | |
2102 | strings preceded by a \fB$\fP. | |
2103 | .TP | |
bb70624e JA |
2104 | .B LC_NUMERIC |
2105 | This variable determines the locale category used for number formatting. | |
2106 | .TP | |
28ef6c31 | 2107 | .B LINES |
54a1fa7c | 2108 | Used by the \fBselect\fP compound command to determine the column length |
276cb932 CR |
2109 | for printing selection lists. Automatically set by an interactive shell |
2110 | upon receipt of a | |
984a1947 CR |
2111 | .SM |
2112 | .BR SIGWINCH . | |
28ef6c31 | 2113 | .TP |
f73dda09 | 2114 | .B MAIL |
9ec5ed66 | 2115 | If this parameter is set to a file or directory name and the |
726f6388 | 2116 | .SM |
f73dda09 JA |
2117 | .B MAILPATH |
2118 | variable is not set, | |
726f6388 | 2119 | .B bash |
9ec5ed66 CR |
2120 | informs the user of the arrival of mail in the specified file or |
2121 | Maildir-format directory. | |
726f6388 | 2122 | .TP |
f73dda09 JA |
2123 | .B MAILCHECK |
2124 | Specifies how | |
2125 | often (in seconds) | |
2126 | .B bash | |
2127 | checks for mail. The default is 60 seconds. When it is time to check | |
2128 | for mail, the shell does so before displaying the primary prompt. | |
2129 | If this variable is unset, or set to a value that is not a number | |
2130 | greater than or equal to zero, the shell disables mail checking. | |
726f6388 | 2131 | .TP |
f73dda09 | 2132 | .B MAILPATH |
b28ff8c9 | 2133 | A colon-separated list of filenames to be checked for mail. |
f73dda09 | 2134 | The message to be printed when mail arrives in a particular file |
b28ff8c9 | 2135 | may be specified by separating the filename from the message with a `?'. |
f73dda09 JA |
2136 | When used in the text of the message, \fB$_\fP expands to the name of |
2137 | the current mailfile. | |
2138 | Example: | |
2139 | .RS | |
2140 | .PP | |
20587658 | 2141 | \fBMAILPATH\fP=\(aq/var/mail/bfox?"You have mail":~/shell\-mail?"$_ has mail!"\(aq |
f73dda09 JA |
2142 | .PP |
2143 | .B Bash | |
2144 | supplies a default value for this variable, but the location of the user | |
2145 | mail files that it uses is system dependent (e.g., /var/mail/\fB$USER\fP). | |
2146 | .RE | |
726f6388 | 2147 | .TP |
f73dda09 JA |
2148 | .B OPTERR |
2149 | If set to the value 1, | |
2150 | .B bash | |
2151 | displays error messages generated by the | |
2152 | .B getopts | |
2153 | builtin command (see | |
726f6388 | 2154 | .SM |
f73dda09 | 2155 | .B SHELL BUILTIN COMMANDS |
ccc6cda3 | 2156 | below). |
726f6388 | 2157 | .SM |
f73dda09 JA |
2158 | .B OPTERR |
2159 | is initialized to 1 each time the shell is invoked or a shell | |
2160 | script is executed. | |
ccc6cda3 | 2161 | .TP |
f73dda09 JA |
2162 | .B PATH |
2163 | The search path for commands. It | |
2164 | is a colon-separated list of directories in which | |
2165 | the shell looks for commands (see | |
ccc6cda3 | 2166 | .SM |
f73dda09 | 2167 | .B COMMAND EXECUTION |
d3a24ed2 | 2168 | below). |
984a1947 CR |
2169 | A zero-length (null) directory name in the value of |
2170 | .SM | |
2171 | .B PATH | |
2172 | indicates the current directory. | |
d3a24ed2 CR |
2173 | A null directory name may appear as two adjacent colons, or as an initial |
2174 | or trailing colon. | |
2175 | The default path is system-dependent, | |
f73dda09 JA |
2176 | and is set by the administrator who installs |
2177 | .BR bash . | |
2178 | A common value is | |
f6da9f85 CR |
2179 | .if t \f(CW/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin\fP. |
2180 | .if n ``/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin''. | |
726f6388 | 2181 | .TP |
f73dda09 JA |
2182 | .B POSIXLY_CORRECT |
2183 | If this variable is in the environment when \fBbash\fP starts, the shell | |
2184 | enters \fIposix mode\fP before reading the startup files, as if the | |
2185 | .B \-\-posix | |
2186 | invocation option had been supplied. If it is set while the shell is | |
2187 | running, \fBbash\fP enables \fIposix mode\fP, as if the command | |
2188 | .if t \f(CWset -o posix\fP | |
2189 | .if n \fIset -o posix\fP | |
2190 | had been executed. | |
726f6388 | 2191 | .TP |
f73dda09 JA |
2192 | .B PROMPT_COMMAND |
2193 | If set, the value is executed as a command prior to issuing each primary | |
2194 | prompt. | |
ccc6cda3 | 2195 | .TP |
ed35cb4a CR |
2196 | .B PROMPT_DIRTRIM |
2197 | If set to a number greater than zero, the value is used as the number of | |
d0ca3503 | 2198 | trailing directory components to retain when expanding the \fB\ew\fP and |
ed35cb4a CR |
2199 | \fB\eW\fP prompt string escapes (see |
2200 | .SM | |
2201 | .B PROMPTING | |
2202 | below). Characters removed are replaced with an ellipsis. | |
2203 | .TP | |
f73dda09 JA |
2204 | .B PS1 |
2205 | The value of this parameter is expanded (see | |
2206 | .SM | |
2207 | .B PROMPTING | |
2208 | below) and used as the primary prompt string. The default value is | |
2209 | ``\fB\es\-\ev\e$ \fP''. | |
726f6388 | 2210 | .TP |
f73dda09 JA |
2211 | .B PS2 |
2212 | The value of this parameter is expanded as with | |
984a1947 | 2213 | .SM |
f73dda09 JA |
2214 | .B PS1 |
2215 | and used as the secondary prompt string. The default is | |
2216 | ``\fB> \fP''. | |
2217 | .TP | |
2218 | .B PS3 | |
2219 | The value of this parameter is used as the prompt for the | |
2220 | .B select | |
2221 | command (see | |
726f6388 | 2222 | .SM |
f73dda09 JA |
2223 | .B SHELL GRAMMAR |
2224 | above). | |
726f6388 | 2225 | .TP |
f73dda09 JA |
2226 | .B PS4 |
2227 | The value of this parameter is expanded as with | |
984a1947 | 2228 | .SM |
f73dda09 JA |
2229 | .B PS1 |
2230 | and the value is printed before each command | |
726f6388 | 2231 | .B bash |
f73dda09 | 2232 | displays during an execution trace. The first character of |
bb70624e | 2233 | .SM |
f73dda09 JA |
2234 | .B PS4 |
2235 | is replicated multiple times, as necessary, to indicate multiple | |
2236 | levels of indirection. The default is ``\fB+ \fP''. | |
2237 | .TP | |
61deeb13 CR |
2238 | .B SHELL |
2239 | The full pathname to the shell is kept in this environment variable. | |
2240 | If it is not set when the shell starts, | |
2241 | .B bash | |
2242 | assigns to it the full pathname of the current user's login shell. | |
2243 | .TP | |
f73dda09 JA |
2244 | .B TIMEFORMAT |
2245 | The value of this parameter is used as a format string specifying | |
2246 | how the timing information for pipelines prefixed with the | |
2247 | .B time | |
2248 | reserved word should be displayed. | |
2249 | The \fB%\fP character introduces an escape sequence that is | |
2250 | expanded to a time value or other information. | |
2251 | The escape sequences and their meanings are as follows; the | |
2252 | braces denote optional portions. | |
2253 | .sp .5 | |
2254 | .RS | |
2255 | .PD 0 | |
2256 | .TP 10 | |
2257 | .B %% | |
2258 | A literal \fB%\fP. | |
2259 | .TP | |
2260 | .B %[\fIp\fP][l]R | |
2261 | The elapsed time in seconds. | |
2262 | .TP | |
2263 | .B %[\fIp\fP][l]U | |
2264 | The number of CPU seconds spent in user mode. | |
2265 | .TP | |
2266 | .B %[\fIp\fP][l]S | |
2267 | The number of CPU seconds spent in system mode. | |
2268 | .TP | |
2269 | .B %P | |
2270 | The CPU percentage, computed as (%U + %S) / %R. | |
2271 | .PD | |
2272 | .RE | |
2273 | .IP | |
2274 | The optional \fIp\fP is a digit specifying the \fIprecision\fP, | |
2275 | the number of fractional digits after a decimal point. | |
2276 | A value of 0 causes no decimal point or fraction to be output. | |
2277 | At most three places after the decimal point may be specified; | |
2278 | values of \fIp\fP greater than 3 are changed to 3. | |
2279 | If \fIp\fP is not specified, the value 3 is used. | |
2280 | .IP | |
2281 | The optional \fBl\fP specifies a longer format, including | |
2282 | minutes, of the form \fIMM\fPm\fISS\fP.\fIFF\fPs. | |
2283 | The value of \fIp\fP determines whether or not the fraction is | |
2284 | included. | |
2285 | .IP | |
2286 | If this variable is not set, \fBbash\fP acts as if it had the | |
20587658 | 2287 | value \fB$\(aq\enreal\et%3lR\enuser\et%3lU\ensys\t%3lS\(aq\fP. |
f73dda09 JA |
2288 | If the value is null, no timing information is displayed. |
2289 | A trailing newline is added when the format string is displayed. | |
54a1fa7c | 2290 | .PD 0 |
f73dda09 JA |
2291 | .TP |
2292 | .B TMOUT | |
984a1947 CR |
2293 | If set to a value greater than zero, |
2294 | .SM | |
2295 | .B TMOUT | |
2296 | is treated as the | |
7117c2d2 JA |
2297 | default timeout for the \fBread\fP builtin. |
2298 | The \fBselect\fP command terminates if input does not arrive | |
984a1947 CR |
2299 | after |
2300 | .SM | |
2301 | .B TMOUT | |
2302 | seconds when input is coming from a terminal. | |
7117c2d2 | 2303 | In an interactive shell, the value is interpreted as the |
f73dda09 JA |
2304 | number of seconds to wait for input after issuing the primary prompt. |
2305 | .B Bash | |
2306 | terminates after waiting for that number of seconds if input does | |
2307 | not arrive. | |
726f6388 | 2308 | .TP |
1569c106 | 2309 | .B TMPDIR |
5f8cde23 CR |
2310 | If set, \fBbash\fP uses its value as the name of a directory in which |
2311 | \fBbash\fP creates temporary files for the shell's use. | |
1569c106 | 2312 | .TP |
726f6388 JA |
2313 | .B auto_resume |
2314 | This variable controls how the shell interacts with the user and | |
2315 | job control. If this variable is set, single word simple | |
2316 | commands without redirections are treated as candidates for resumption | |
2317 | of an existing stopped job. There is no ambiguity allowed; if there is | |
2318 | more than one job beginning with the string typed, the job most recently | |
2319 | accessed is selected. The | |
2320 | .I name | |
2321 | of a stopped job, in this context, is the command line used to | |
2322 | start it. | |
2323 | If set to the value | |
2324 | .IR exact , | |
2325 | the string supplied must match the name of a stopped job exactly; | |
2326 | if set to | |
2327 | .IR substring , | |
2328 | the string supplied needs to match a substring of the name of a | |
2329 | stopped job. The | |
2330 | .I substring | |
2331 | value provides functionality analogous to the | |
2332 | .B %? | |
ccc6cda3 | 2333 | job identifier (see |
726f6388 JA |
2334 | .SM |
2335 | .B JOB CONTROL | |
2336 | below). If set to any other value, the supplied string must | |
2337 | be a prefix of a stopped job's name; this provides functionality | |
22e63b05 | 2338 | analogous to the \fB%\fP\fIstring\fP job identifier. |
bb70624e | 2339 | .TP |
f73dda09 JA |
2340 | .B histchars |
2341 | The two or three characters which control history expansion | |
2342 | and tokenization (see | |
2343 | .SM | |
2344 | .B HISTORY EXPANSION | |
2345 | below). The first character is the \fIhistory expansion\fP character, | |
2346 | the character which signals the start of a history | |
2347 | expansion, normally `\fB!\fP'. | |
2348 | The second character is the \fIquick substitution\fP | |
2349 | character, which is used as shorthand for re-running the previous | |
2350 | command entered, substituting one string for another in the command. | |
2351 | The default is `\fB^\fP'. | |
2352 | The optional third character is the character | |
2353 | which indicates that the remainder of the line is a comment when found | |
2354 | as the first character of a word, normally `\fB#\fP'. The history | |
2355 | comment character causes history substitution to be skipped for the | |
2356 | remaining words on the line. It does not necessarily cause the shell | |
2357 | parser to treat the rest of the line as a comment. | |
726f6388 | 2358 | .PD |
ccc6cda3 JA |
2359 | .SS Arrays |
2360 | .B Bash | |
fdf670ea | 2361 | provides one-dimensional indexed and associative array variables. |
09767ff0 | 2362 | Any variable may be used as an indexed array; the |
ccc6cda3 | 2363 | .B declare |
fdf670ea CR |
2364 | builtin will explicitly declare an array. |
2365 | There is no maximum | |
ccc6cda3 | 2366 | limit on the size of an array, nor any requirement that members |
fdf670ea CR |
2367 | be indexed or assigned contiguously. |
2368 | Indexed arrays are referenced using integers (including arithmetic | |
09767ff0 CR |
2369 | expressions) and are zero-based; associative arrays are referenced |
2370 | using arbitrary strings. | |
ccc6cda3 | 2371 | .PP |
fdf670ea CR |
2372 | An indexed array is created automatically if any variable is assigned to |
2373 | using the syntax \fIname\fP[\fIsubscript\fP]=\fIvalue\fP. The | |
ccc6cda3 | 2374 | .I subscript |
67362c60 | 2375 | is treated as an arithmetic expression that must evaluate to a number. |
67362c60 | 2376 | To explicitly declare an indexed array, use |
ccc6cda3 JA |
2377 | .B declare \-a \fIname\fP |
2378 | (see | |
2379 | .SM | |
2380 | .B SHELL BUILTIN COMMANDS | |
2381 | below). | |
2382 | .B declare \-a \fIname\fP[\fIsubscript\fP] | |
09767ff0 CR |
2383 | is also accepted; the \fIsubscript\fP is ignored. |
2384 | .PP | |
2385 | Associative arrays are created using | |
2386 | .BR "declare \-A \fIname\fP" . | |
2387 | .PP | |
2388 | Attributes may be | |
ccc6cda3 JA |
2389 | specified for an array variable using the |
2390 | .B declare | |
2391 | and | |
2392 | .B readonly | |
2393 | builtins. Each attribute applies to all members of an array. | |
2394 | .PP | |
2395 | Arrays are assigned to using compound assignments of the form | |
2396 | \fIname\fP=\fB(\fPvalue\fI1\fP ... value\fIn\fP\fB)\fP, where each | |
09767ff0 | 2397 | \fIvalue\fP is of the form [\fIsubscript\fP]=\fIstring\fP. |
b28ff8c9 | 2398 | Indexed array assignments do not require anything but \fIstring\fP. |
09767ff0 CR |
2399 | When assigning to indexed arrays, if the optional brackets and subscript |
2400 | are supplied, that index is assigned to; | |
ccc6cda3 JA |
2401 | otherwise the index of the element assigned is the last index assigned |
2402 | to by the statement plus one. Indexing starts at zero. | |
fdf670ea CR |
2403 | .PP |
2404 | When assigning to an associative array, the subscript is required. | |
2405 | .PP | |
ccc6cda3 JA |
2406 | This syntax is also accepted by the |
2407 | .B declare | |
2408 | builtin. Individual array elements may be assigned to using the | |
2409 | \fIname\fP[\fIsubscript\fP]=\fIvalue\fP syntax introduced above. | |
2410 | .PP | |
2411 | Any element of an array may be referenced using | |
2412 | ${\fIname\fP[\fIsubscript\fP]}. The braces are required to avoid | |
2413 | conflicts with pathname expansion. If | |
2414 | \fIsubscript\fP is \fB@\fP or \fB*\fP, the word expands to | |
2415 | all members of \fIname\fP. These subscripts differ only when the | |
2416 | word appears within double quotes. If the word is double-quoted, | |
2417 | ${\fIname\fP[*]} expands to a single | |
2418 | word with the value of each array member separated by the first | |
2419 | character of the | |
2420 | .SM | |
2421 | .B IFS | |
2422 | special variable, and ${\fIname\fP[@]} expands each element of | |
2423 | \fIname\fP to a separate word. When there are no array members, | |
be7d8f2d CR |
2424 | ${\fIname\fP[@]} expands to nothing. |
2425 | If the double-quoted expansion occurs within a word, the expansion of | |
2426 | the first parameter is joined with the beginning part of the original | |
2427 | word, and the expansion of the last parameter is joined with the last | |
2428 | part of the original word. | |
2429 | This is analogous to the expansion | |
ccc6cda3 JA |
2430 | of the special parameters \fB*\fP and \fB@\fP (see |
2431 | .B Special Parameters | |
2432 | above). ${#\fIname\fP[\fIsubscript\fP]} expands to the length of | |
2433 | ${\fIname\fP[\fIsubscript\fP]}. If \fIsubscript\fP is \fB*\fP or | |
2434 | \fB@\fP, the expansion is the number of elements in the array. | |
2435 | Referencing an array variable without a subscript is equivalent to | |
fdf670ea | 2436 | referencing the array with a subscript of 0. |
d9e1f41e CR |
2437 | If the |
2438 | .I subscript | |
2439 | used to reference an element of an indexed array | |
2440 | evaluates to a number less than zero, it is used as | |
2441 | an offset from one greater than the array's maximum index (so a subcript | |
2442 | of -1 refers to the last element of the array). | |
ccc6cda3 | 2443 | .PP |
94a5513e CR |
2444 | An array variable is considered set if a subscript has been assigned a |
2445 | value. The null string is a valid value. | |
2446 | .PP | |
ccc6cda3 JA |
2447 | The |
2448 | .B unset | |
bb70624e | 2449 | builtin is used to destroy arrays. \fBunset\fP \fIname\fP[\fIsubscript\fP] |
ccc6cda3 | 2450 | destroys the array element at index \fIsubscript\fP. |
d0ca3503 CR |
2451 | Care must be taken to avoid unwanted side effects caused by pathname |
2452 | expansion. | |
ccc6cda3 JA |
2453 | \fBunset\fP \fIname\fP, where \fIname\fP is an array, or |
2454 | \fBunset\fP \fIname\fP[\fIsubscript\fP], where | |
2455 | \fIsubscript\fP is \fB*\fP or \fB@\fP, removes the entire array. | |
2456 | .PP | |
2457 | The | |
2458 | .BR declare , | |
2459 | .BR local , | |
2460 | and | |
2461 | .B readonly | |
2462 | builtins each accept a | |
2463 | .B \-a | |
fdf670ea CR |
2464 | option to specify an indexed array and a |
2465 | .B \-A | |
2466 | option to specify an associative array. | |
54a1fa7c CR |
2467 | If both options are supplied, |
2468 | .B \-A | |
2469 | takes precedence. | |
fdf670ea | 2470 | The |
ccc6cda3 JA |
2471 | .B read |
2472 | builtin accepts a | |
2473 | .B \-a | |
2474 | option to assign a list of words read from the standard input | |
2475 | to an array. The | |
2476 | .B set | |
2477 | and | |
2478 | .B declare | |
2479 | builtins display array values in a way that allows them to be | |
2480 | reused as assignments. | |
726f6388 JA |
2481 | .SH EXPANSION |
2482 | Expansion is performed on the command line after it has been split into | |
2483 | words. There are seven kinds of expansion performed: | |
2484 | .IR "brace expansion" , | |
2485 | .IR "tilde expansion" , | |
2486 | .IR "parameter and variable expansion" , | |
2487 | .IR "command substitution" , | |
2488 | .IR "arithmetic expansion" , | |
2489 | .IR "word splitting" , | |
2490 | and | |
2491 | .IR "pathname expansion" . | |
2492 | .PP | |
2493 | The order of expansions is: brace expansion, tilde expansion, | |
ccc6cda3 JA |
2494 | parameter, variable and arithmetic expansion and |
2495 | command substitution | |
2496 | (done in a left-to-right fashion), word splitting, and pathname | |
726f6388 JA |
2497 | expansion. |
2498 | .PP | |
2499 | On systems that can support it, there is an additional expansion | |
2500 | available: \fIprocess substitution\fP. | |
2501 | .PP | |
2502 | Only brace expansion, word splitting, and pathname expansion | |
2503 | can change the number of words of the expansion; other expansions | |
2504 | expand a single word to a single word. | |
ccc6cda3 | 2505 | The only exceptions to this are the expansions of |
cce855bc | 2506 | "\fB$@\fP" and "\fB${\fP\fIname\fP\fB[@]}\fP" |
ccc6cda3 | 2507 | as explained above (see |
726f6388 JA |
2508 | .SM |
2509 | .BR PARAMETERS ). | |
2510 | .SS Brace Expansion | |
2511 | .PP | |
2512 | .I "Brace expansion" | |
2513 | is a mechanism by which arbitrary strings | |
2514 | may be generated. This mechanism is similar to | |
2515 | \fIpathname expansion\fP, but the filenames generated | |
2516 | need not exist. Patterns to be brace expanded take | |
2517 | the form of an optional | |
2518 | .IR preamble , | |
d3a24ed2 CR |
2519 | followed by either a series of comma-separated strings or |
2520 | a sequence expression between a pair of braces, followed by | |
2521 | an optional | |
cce855bc | 2522 | .IR postscript . |
ccc6cda3 | 2523 | The preamble is prefixed to each string contained |
cce855bc | 2524 | within the braces, and the postscript is then appended |
726f6388 JA |
2525 | to each resulting string, expanding left to right. |
2526 | .PP | |
2527 | Brace expansions may be nested. The results of each expanded | |
2528 | string are not sorted; left to right order is preserved. | |
2529 | For example, a\fB{\fPd,c,b\fB}\fPe expands into `ade ace abe'. | |
2530 | .PP | |
8943768b | 2531 | A sequence expression takes the form |
36211029 | 2532 | \fB{\fP\fIx\fP\fB..\fP\fIy\fP\fB[..\fP\fIincr\fP\fB]}\fP, |
8943768b CR |
2533 | where \fIx\fP and \fIy\fP are either integers or single characters, |
2534 | and \fIincr\fP, an optional increment, is an integer. | |
d3a24ed2 CR |
2535 | When integers are supplied, the expression expands to each number between |
2536 | \fIx\fP and \fIy\fP, inclusive. | |
8943768b CR |
2537 | Supplied integers may be prefixed with \fI0\fP to force each term to have the |
2538 | same width. When either \fIx\fP or \fPy\fP begins with a zero, the shell | |
2539 | attempts to force all generated terms to contain the same number of digits, | |
2540 | zero-padding where necessary. | |
d3a24ed2 CR |
2541 | When characters are supplied, the expression expands to each character |
2542 | lexicographically between \fIx\fP and \fIy\fP, inclusive. Note that | |
2543 | both \fIx\fP and \fIy\fP must be of the same type. | |
8943768b CR |
2544 | When the increment is supplied, it is used as the difference between |
2545 | each term. The default increment is 1 or -1 as appropriate. | |
d3a24ed2 | 2546 | .PP |
726f6388 JA |
2547 | Brace expansion is performed before any other expansions, |
2548 | and any characters special to other expansions are preserved | |
2549 | in the result. It is strictly textual. | |
2550 | .B Bash | |
2551 | does not apply any syntactic interpretation to the context of the | |
2552 | expansion or the text between the braces. | |
2553 | .PP | |
2554 | A correctly-formed brace expansion must contain unquoted opening | |
d3a24ed2 CR |
2555 | and closing braces, and at least one unquoted comma or a valid |
2556 | sequence expression. | |
726f6388 | 2557 | Any incorrectly formed brace expansion is left unchanged. |
ccc6cda3 JA |
2558 | A \fB{\fP or \fB,\fP may be quoted with a backslash to prevent its |
2559 | being considered part of a brace expression. | |
bb70624e JA |
2560 | To avoid conflicts with parameter expansion, the string \fB${\fP |
2561 | is not considered eligible for brace expansion. | |
726f6388 JA |
2562 | .PP |
2563 | This construct is typically used as shorthand when the common | |
2564 | prefix of the strings to be generated is longer than in the | |
2565 | above example: | |
2566 | .RS | |
2567 | .PP | |
2568 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
2569 | .RE | |
2570 | or | |
2571 | .RS | |
2572 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
2573 | .RE | |
2574 | .PP | |
2575 | Brace expansion introduces a slight incompatibility with | |
ccc6cda3 JA |
2576 | historical versions of |
2577 | .BR sh . | |
726f6388 JA |
2578 | .B sh |
2579 | does not treat opening or closing braces specially when they | |
2580 | appear as part of a word, and preserves them in the output. | |
2581 | .B Bash | |
2582 | removes braces from words as a consequence of brace | |
2583 | expansion. For example, a word entered to | |
2584 | .B sh | |
2585 | as \fIfile{1,2}\fP | |
2586 | appears identically in the output. The same word is | |
2587 | output as | |
2588 | .I file1 file2 | |
2589 | after expansion by | |
2590 | .BR bash . | |
2591 | If strict compatibility with | |
2592 | .B sh | |
2593 | is desired, start | |
2594 | .B bash | |
2595 | with the | |
ccc6cda3 JA |
2596 | .B +B |
2597 | option or disable brace expansion with the | |
2598 | .B +B | |
726f6388 JA |
2599 | option to the |
2600 | .B set | |
2601 | command (see | |
2602 | .SM | |
2603 | .B SHELL BUILTIN COMMANDS | |
2604 | below). | |
2605 | .SS Tilde Expansion | |
2606 | .PP | |
cce855bc JA |
2607 | If a word begins with an unquoted tilde character (`\fB~\fP'), all of |
2608 | the characters preceding the first unquoted slash (or all characters, | |
2609 | if there is no unquoted slash) are considered a \fItilde-prefix\fP. | |
2610 | If none of the characters in the tilde-prefix are quoted, the | |
2611 | characters in the tilde-prefix following the tilde are treated as a | |
2612 | possible \fIlogin name\fP. | |
2613 | If this login name is the null string, the tilde is replaced with the | |
2614 | value of the shell parameter | |
726f6388 JA |
2615 | .SM |
2616 | .BR HOME . | |
2617 | If | |
2618 | .SM | |
2619 | .B HOME | |
cce855bc JA |
2620 | is unset, the home directory of the user executing the shell is |
2621 | substituted instead. | |
2622 | Otherwise, the tilde-prefix is replaced with the home directory | |
2623 | associated with the specified login name. | |
726f6388 | 2624 | .PP |
cce855bc | 2625 | If the tilde-prefix is a `~+', the value of the shell variable |
726f6388 JA |
2626 | .SM |
2627 | .B PWD | |
cce855bc JA |
2628 | replaces the tilde-prefix. |
2629 | If the tilde-prefix is a `~\-', the value of the shell variable | |
2630 | .SM | |
2631 | .BR OLDPWD , | |
2632 | if it is set, is substituted. | |
2633 | If the characters following the tilde in the tilde-prefix consist | |
2634 | of a number \fIN\fP, optionally prefixed | |
2635 | by a `+' or a `\-', the tilde-prefix is replaced with the corresponding | |
2636 | element from the directory stack, as it would be displayed by the | |
2637 | .B dirs | |
2638 | builtin invoked with the tilde-prefix as an argument. | |
2639 | If the characters following the tilde in the tilde-prefix consist of a | |
2640 | number without a leading `+' or `\-', `+' is assumed. | |
2641 | .PP | |
2642 | If the login name is invalid, or the tilde expansion fails, the word | |
2643 | is unchanged. | |
726f6388 | 2644 | .PP |
cce855bc JA |
2645 | Each variable assignment is checked for unquoted tilde-prefixes immediately |
2646 | following a | |
726f6388 | 2647 | .B : |
43df7bbb | 2648 | or the first |
726f6388 | 2649 | .BR = . |
cce855bc | 2650 | In these cases, tilde expansion is also performed. |
b28ff8c9 | 2651 | Consequently, one may use filenames with tildes in assignments to |
726f6388 JA |
2652 | .SM |
2653 | .BR PATH , | |
2654 | .SM | |
2655 | .BR MAILPATH , | |
2656 | and | |
2657 | .SM | |
2658 | .BR CDPATH , | |
2659 | and the shell assigns the expanded value. | |
2660 | .SS Parameter Expansion | |
2661 | .PP | |
2662 | The `\fB$\fP' character introduces parameter expansion, | |
2663 | command substitution, or arithmetic expansion. The parameter name | |
2664 | or symbol to be expanded may be enclosed in braces, which | |
2665 | are optional but serve to protect the variable to be expanded from | |
2666 | characters immediately following it which could be | |
2667 | interpreted as part of the name. | |
2668 | .PP | |
cce855bc JA |
2669 | When braces are used, the matching ending brace is the first `\fB}\fP' |
2670 | not escaped by a backslash or within a quoted string, and not within an | |
f75912ae | 2671 | embedded arithmetic expansion, command substitution, or parameter |
cce855bc JA |
2672 | expansion. |
2673 | .PP | |
726f6388 JA |
2674 | .PD 0 |
2675 | .TP | |
2676 | ${\fIparameter\fP} | |
2677 | The value of \fIparameter\fP is substituted. The braces are required | |
2678 | when | |
2679 | .I parameter | |
2680 | is a positional parameter with more than one digit, | |
2681 | or when | |
2682 | .I parameter | |
2683 | is followed by a character which is not to be | |
2684 | interpreted as part of its name. | |
2685 | .PD | |
2686 | .PP | |
08e72d7a | 2687 | If the first character of \fIparameter\fP is an exclamation point (\fB!\fP), |
ccc6cda3 JA |
2688 | a level of variable indirection is introduced. |
2689 | \fBBash\fP uses the value of the variable formed from the rest of | |
2690 | \fIparameter\fP as the name of the variable; this variable is then | |
bb70624e | 2691 | expanded and that value is used in the rest of the substitution, rather |
ccc6cda3 JA |
2692 | than the value of \fIparameter\fP itself. |
2693 | This is known as \fIindirect expansion\fP. | |
54a1fa7c | 2694 | The exceptions to this are the expansions of ${\fB!\fP\fIprefix\fP\fB*\fP} and |
d3a24ed2 CR |
2695 | ${\fB!\fP\fIname\fP[\fI@\fP]} described below. |
2696 | The exclamation point must immediately follow the left brace in order to | |
2697 | introduce indirection. | |
ccc6cda3 | 2698 | .PP |
726f6388 JA |
2699 | In each of the cases below, \fIword\fP is subject to tilde expansion, |
2700 | parameter expansion, command substitution, and arithmetic expansion. | |
e141c35a CR |
2701 | .PP |
2702 | When not performing substring expansion, using the forms documented below, | |
2703 | \fBbash\fP tests for a parameter that is unset or null. Omitting the colon | |
2704 | results in a test only for a parameter that is unset. | |
726f6388 JA |
2705 | .PP |
2706 | .PD 0 | |
2707 | .TP | |
2708 | ${\fIparameter\fP\fB:\-\fP\fIword\fP} | |
2709 | \fBUse Default Values\fP. If | |
2710 | .I parameter | |
2711 | is unset or null, the expansion of | |
2712 | .I word | |
2713 | is substituted. Otherwise, the value of | |
2714 | .I parameter | |
2715 | is substituted. | |
2716 | .TP | |
2717 | ${\fIparameter\fP\fB:=\fP\fIword\fP} | |
2718 | \fBAssign Default Values\fP. | |
2719 | If | |
2720 | .I parameter | |
2721 | is unset or null, the expansion of | |
2722 | .I word | |
2723 | is assigned to | |
2724 | .IR parameter . | |
2725 | The value of | |
2726 | .I parameter | |
2727 | is then substituted. Positional parameters and special parameters may | |
2728 | not be assigned to in this way. | |
2729 | .TP | |
2730 | ${\fIparameter\fP\fB:?\fP\fIword\fP} | |
2731 | \fBDisplay Error if Null or Unset\fP. | |
2732 | If | |
2733 | .I parameter | |
2734 | is null or unset, the expansion of \fIword\fP (or a message to that effect | |
2735 | if | |
2736 | .I word | |
2737 | is not present) is written to the standard error and the shell, if it | |
2738 | is not interactive, exits. Otherwise, the value of \fIparameter\fP is | |
2739 | substituted. | |
2740 | .TP | |
2741 | ${\fIparameter\fP\fB:+\fP\fIword\fP} | |
2742 | \fBUse Alternate Value\fP. | |
2743 | If | |
2744 | .I parameter | |
2745 | is null or unset, nothing is substituted, otherwise the expansion of | |
2746 | .I word | |
2747 | is substituted. | |
2748 | .TP | |
ccc6cda3 | 2749 | ${\fIparameter\fP\fB:\fP\fIoffset\fP} |
7117c2d2 | 2750 | .PD 0 |
ccc6cda3 JA |
2751 | .TP |
2752 | ${\fIparameter\fP\fB:\fP\fIoffset\fP\fB:\fP\fIlength\fP} | |
2753 | .PD | |
dc60d4e0 | 2754 | \fBSubstring Expansion\fP. |
bb70624e JA |
2755 | Expands to up to \fIlength\fP characters of \fIparameter\fP |
2756 | starting at the character specified by \fIoffset\fP. | |
ccc6cda3 | 2757 | If \fIlength\fP is omitted, expands to the substring of |
bb70624e | 2758 | \fIparameter\fP starting at the character specified by \fIoffset\fP. |
ccc6cda3 JA |
2759 | \fIlength\fP and \fIoffset\fP are arithmetic expressions (see |
2760 | .SM | |
2761 | .B | |
2762 | ARITHMETIC EVALUATION | |
2763 | below). | |
ccc6cda3 JA |
2764 | If \fIoffset\fP evaluates to a number less than zero, the value |
2765 | is used as an offset from the end of the value of \fIparameter\fP. | |
67362c60 CR |
2766 | If \fIlength\fP evaluates to a number less than zero, and \fIparameter\fP |
2767 | is not \fB@\fP and not an indexed or associative array, it is interpreted | |
2768 | as an offset from the end of the value of \fIparameter\fP rather than | |
2769 | a number of characters, and the expansion is the characters between the | |
2770 | two offsets. | |
ccc6cda3 JA |
2771 | If \fIparameter\fP is \fB@\fP, the result is \fIlength\fP positional |
2772 | parameters beginning at \fIoffset\fP. | |
09767ff0 | 2773 | If \fIparameter\fP is an indexed array name subscripted by @ or *, |
ccc6cda3 JA |
2774 | the result is the \fIlength\fP |
2775 | members of the array beginning with ${\fIparameter\fP[\fIoffset\fP]}. | |
ec2199bd CR |
2776 | A negative \fIoffset\fP is taken relative to one greater than the maximum |
2777 | index of the specified array. | |
09767ff0 CR |
2778 | Substring expansion applied to an associative array produces undefined |
2779 | results. | |
ec2199bd CR |
2780 | Note that a negative offset must be separated from the colon by at least |
2781 | one space to avoid being confused with the :- expansion. | |
cce855bc | 2782 | Substring indexing is zero-based unless the positional parameters |
d3ad40de CR |
2783 | are used, in which case the indexing starts at 1 by default. |
2784 | If \fIoffset\fP is 0, and the positional parameters are used, \fB$0\fP is | |
2785 | prefixed to the list. | |
ccc6cda3 | 2786 | .TP |
bb70624e | 2787 | ${\fB!\fP\fIprefix\fP\fB*\fP} |
d3a24ed2 CR |
2788 | .PD 0 |
2789 | .TP | |
2790 | ${\fB!\fP\fIprefix\fP\fB@\fP} | |
2791 | .PD | |
dc60d4e0 | 2792 | \fBNames matching prefix\fP. |
bb70624e JA |
2793 | Expands to the names of variables whose names begin with \fIprefix\fP, |
2794 | separated by the first character of the | |
2795 | .SM | |
2796 | .B IFS | |
2797 | special variable. | |
d3ad40de CR |
2798 | When \fI@\fP is used and the expansion appears within double quotes, each |
2799 | variable name expands to a separate word. | |
bb70624e | 2800 | .TP |
d3a24ed2 CR |
2801 | ${\fB!\fP\fIname\fP[\fI@\fP]} |
2802 | .PD 0 | |
2803 | .TP | |
2804 | ${\fB!\fP\fIname\fP[\fI*\fP]} | |
2805 | .PD | |
dc60d4e0 | 2806 | \fBList of array keys\fP. |
d3a24ed2 CR |
2807 | If \fIname\fP is an array variable, expands to the list of array indices |
2808 | (keys) assigned in \fIname\fP. | |
2809 | If \fIname\fP is not an array, expands to 0 if \fIname\fP is set and null | |
2810 | otherwise. | |
2811 | When \fI@\fP is used and the expansion appears within double quotes, each | |
2812 | key expands to a separate word. | |
2813 | .TP | |
726f6388 | 2814 | ${\fB#\fP\fIparameter\fP} |
dc60d4e0 | 2815 | \fBParameter length\fP. |
726f6388 | 2816 | The length in characters of the value of \fIparameter\fP is substituted. |
ccc6cda3 JA |
2817 | If |
2818 | .I parameter | |
2819 | is | |
726f6388 JA |
2820 | .B * |
2821 | or | |
2822 | .BR @ , | |
cce855bc | 2823 | the value substituted is the number of positional parameters. |
ccc6cda3 JA |
2824 | If |
2825 | .I parameter | |
2826 | is an array name subscripted by | |
726f6388 | 2827 | .B * |
ccc6cda3 JA |
2828 | or |
2829 | .BR @ , | |
cce855bc | 2830 | the value substituted is the number of elements in the array. |
726f6388 | 2831 | .TP |
726f6388 | 2832 | ${\fIparameter\fP\fB#\fP\fIword\fP} |
7117c2d2 | 2833 | .PD 0 |
726f6388 JA |
2834 | .TP |
2835 | ${\fIparameter\fP\fB##\fP\fIword\fP} | |
2836 | .PD | |
dc60d4e0 | 2837 | \fBRemove matching prefix pattern\fP. |
726f6388 JA |
2838 | The |
2839 | .I word | |
2840 | is expanded to produce a pattern just as in pathname | |
2841 | expansion. If the pattern matches the beginning of | |
2842 | the value of | |
2843 | .IR parameter , | |
cce855bc | 2844 | then the result of the expansion is the expanded value of |
726f6388 | 2845 | .I parameter |
ccc6cda3 JA |
2846 | with the shortest matching pattern (the ``\fB#\fP'' case) or the |
2847 | longest matching pattern (the ``\fB##\fP'' case) deleted. | |
2848 | If | |
2849 | .I parameter | |
2850 | is | |
2851 | .B @ | |
2852 | or | |
2853 | .BR * , | |
2854 | the pattern removal operation is applied to each positional | |
2855 | parameter in turn, and the expansion is the resultant list. | |
2856 | If | |
2857 | .I parameter | |
2858 | is an array variable subscripted with | |
2859 | .B @ | |
2860 | or | |
2861 | .BR * , | |
2862 | the pattern removal operation is applied to each member of the | |
2863 | array in turn, and the expansion is the resultant list. | |
726f6388 | 2864 | .TP |
726f6388 | 2865 | ${\fIparameter\fP\fB%\fP\fIword\fP} |
7117c2d2 | 2866 | .PD 0 |
726f6388 JA |
2867 | .TP |
2868 | ${\fIparameter\fP\fB%%\fP\fIword\fP} | |
2869 | .PD | |
dc60d4e0 | 2870 | \fBRemove matching suffix pattern\fP. |
726f6388 | 2871 | The \fIword\fP is expanded to produce a pattern just as in |
ccc6cda3 | 2872 | pathname expansion. |
cce855bc | 2873 | If the pattern matches a trailing portion of the expanded value of |
726f6388 | 2874 | .IR parameter , |
cce855bc | 2875 | then the result of the expansion is the expanded value of |
726f6388 | 2876 | .I parameter |
ccc6cda3 JA |
2877 | with the shortest matching pattern (the ``\fB%\fP'' case) or the |
2878 | longest matching pattern (the ``\fB%%\fP'' case) deleted. | |
2879 | If | |
2880 | .I parameter | |
2881 | is | |
2882 | .B @ | |
2883 | or | |
2884 | .BR * , | |
2885 | the pattern removal operation is applied to each positional | |
2886 | parameter in turn, and the expansion is the resultant list. | |
2887 | If | |
2888 | .I parameter | |
2889 | is an array variable subscripted with | |
2890 | .B @ | |
2891 | or | |
2892 | .BR * , | |
2893 | the pattern removal operation is applied to each member of the | |
2894 | array in turn, and the expansion is the resultant list. | |
2895 | .TP | |
ccc6cda3 | 2896 | ${\fIparameter\fP\fB/\fP\fIpattern\fP\fB/\fP\fIstring\fP} |
dc60d4e0 | 2897 | \fBPattern substitution\fP. |
ccc6cda3 JA |
2898 | The \fIpattern\fP is expanded to produce a pattern just as in |
2899 | pathname expansion. | |
2900 | \fIParameter\fP is expanded and the longest match of \fIpattern\fP | |
2901 | against its value is replaced with \fIstring\fP. | |
e6598ba4 | 2902 | If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are |
dc8fbaf9 | 2903 | replaced with \fIstring\fP. Normally only the first match is replaced. |
ccc6cda3 | 2904 | If \fIpattern\fP begins with \fB#\fP, it must match at the beginning |
b72432fd | 2905 | of the expanded value of \fIparameter\fP. |
ccc6cda3 | 2906 | If \fIpattern\fP begins with \fB%\fP, it must match at the end |
b72432fd | 2907 | of the expanded value of \fIparameter\fP. |
ccc6cda3 JA |
2908 | If \fIstring\fP is null, matches of \fIpattern\fP are deleted |
2909 | and the \fB/\fP following \fIpattern\fP may be omitted. | |
2910 | If | |
2911 | .I parameter | |
2912 | is | |
2913 | .B @ | |
2914 | or | |
2915 | .BR * , | |
2916 | the substitution operation is applied to each positional | |
2917 | parameter in turn, and the expansion is the resultant list. | |
2918 | If | |
2919 | .I parameter | |
2920 | is an array variable subscripted with | |
2921 | .B @ | |
2922 | or | |
2923 | .BR * , | |
2924 | the substitution operation is applied to each member of the | |
2925 | array in turn, and the expansion is the resultant list. | |
09767ff0 CR |
2926 | .TP |
2927 | ${\fIparameter\fP\fB^\fP\fIpattern\fP} | |
2928 | .PD 0 | |
2929 | .TP | |
2930 | ${\fIparameter\fP\fB^^\fP\fIpattern\fP} | |
2931 | .TP | |
2932 | ${\fIparameter\fP\fB,\fP\fIpattern\fP} | |
2933 | .TP | |
2934 | ${\fIparameter\fP\fB,,\fP\fIpattern\fP} | |
2935 | .PD | |
dc60d4e0 | 2936 | \fBCase modification\fP. |
09767ff0 CR |
2937 | This expansion modifies the case of alphabetic characters in \fIparameter\fP. |
2938 | The \fIpattern\fP is expanded to produce a pattern just as in | |
2939 | pathname expansion. | |
2940 | The \fB^\fP operator converts lowercase letters matching \fIpattern\fP | |
2941 | to uppercase; the \fB,\fP operator converts matching uppercase letters | |
2942 | to lowercase. | |
2943 | The \fB^^\fP and \fB,,\fP expansions convert each matched character in the | |
2944 | expanded value; the \fB^\fP and \fB,\fP expansions match and convert only | |
5cdaaf76 | 2945 | the first character in the expanded value. |
09767ff0 CR |
2946 | If \fIpattern\fP is omitted, it is treated like a \fB?\fP, which matches |
2947 | every character. | |
2948 | If | |
2949 | .I parameter | |
2950 | is | |
2951 | .B @ | |
2952 | or | |
2953 | .BR * , | |
2954 | the case modification operation is applied to each positional | |
2955 | parameter in turn, and the expansion is the resultant list. | |
2956 | If | |
2957 | .I parameter | |
2958 | is an array variable subscripted with | |
2959 | .B @ | |
2960 | or | |
2961 | .BR * , | |
2962 | the case modification operation is applied to each member of the | |
2963 | array in turn, and the expansion is the resultant list. | |
726f6388 JA |
2964 | .SS Command Substitution |
2965 | .PP | |
cce855bc | 2966 | \fICommand substitution\fP allows the output of a command to replace |
726f6388 | 2967 | the command name. There are two forms: |
726f6388 JA |
2968 | .RS |
2969 | .PP | |
2970 | \fB$(\fP\fIcommand\fP\|\fB)\fP | |
2971 | .RE | |
2972 | or | |
2973 | .RS | |
3d4e09aa | 2974 | \fB\`\fP\fIcommand\fP\fB\`\fP |
726f6388 JA |
2975 | .RE |
2976 | .PP | |
ccc6cda3 | 2977 | .B Bash |
726f6388 JA |
2978 | performs the expansion by executing \fIcommand\fP and |
2979 | replacing the command substitution with the standard output of the | |
2980 | command, with any trailing newlines deleted. | |
cce855bc JA |
2981 | Embedded newlines are not deleted, but they may be removed during |
2982 | word splitting. | |
2983 | The command substitution \fB$(cat \fIfile\fP)\fR can be replaced by | |
2984 | the equivalent but faster \fB$(< \fIfile\fP)\fR. | |
726f6388 | 2985 | .PP |
ccc6cda3 | 2986 | When the old-style backquote form of substitution is used, |
726f6388 JA |
2987 | backslash retains its literal meaning except when followed by |
2988 | .BR $ , | |
3d4e09aa | 2989 | .BR \` , |
726f6388 JA |
2990 | or |
2991 | .BR \e . | |
cce855bc JA |
2992 | The first backquote not preceded by a backslash terminates the |
2993 | command substitution. | |
726f6388 JA |
2994 | When using the $(\^\fIcommand\fP\|) form, all characters between the |
2995 | parentheses make up the command; none are treated specially. | |
2996 | .PP | |
cce855bc | 2997 | Command substitutions may be nested. To nest when using the backquoted form, |
726f6388 JA |
2998 | escape the inner backquotes with backslashes. |
2999 | .PP | |
3000 | If the substitution appears within double quotes, word splitting and | |
3001 | pathname expansion are not performed on the results. | |
3002 | .SS Arithmetic Expansion | |
3003 | .PP | |
3004 | Arithmetic expansion allows the evaluation of an arithmetic expression | |
ccc6cda3 | 3005 | and the substitution of the result. The format for arithmetic expansion is: |
726f6388 JA |
3006 | .RS |
3007 | .PP | |
726f6388 JA |
3008 | \fB$((\fP\fIexpression\fP\fB))\fP |
3009 | .RE | |
3010 | .PP | |
3011 | The | |
3012 | .I expression | |
3013 | is treated as if it were within double quotes, but a double quote | |
ccc6cda3 JA |
3014 | inside the parentheses is not treated specially. |
3015 | All tokens in the expression undergo parameter expansion, string | |
3016 | expansion, command substitution, and quote removal. | |
d3a24ed2 | 3017 | Arithmetic expansions may be nested. |
726f6388 JA |
3018 | .PP |
3019 | The evaluation is performed according to the rules listed below under | |
3020 | .SM | |
3021 | .BR "ARITHMETIC EVALUATION" . | |
3022 | If | |
3023 | .I expression | |
3024 | is invalid, | |
3025 | .B bash | |
3026 | prints a message indicating failure and no substitution occurs. | |
3027 | .SS Process Substitution | |
3028 | .PP | |
3029 | \fIProcess substitution\fP is supported on systems that support named | |
3030 | pipes (\fIFIFOs\fP) or the \fB/dev/fd\fP method of naming open files. | |
3031 | It takes the form of | |
3032 | \fB<(\fP\fIlist\^\fP\fB)\fP | |
3033 | or | |
3034 | \fB>(\fP\fIlist\^\fP\fB)\fP. | |
3035 | The process \fIlist\fP is run with its input or output connected to a | |
3036 | \fIFIFO\fP or some file in \fB/dev/fd\fP. The name of this file is | |
3037 | passed as an argument to the current command as the result of the | |
3038 | expansion. If the \fB>(\fP\fIlist\^\fP\fB)\fP form is used, writing to | |
3039 | the file will provide input for \fIlist\fP. If the | |
3040 | \fB<(\fP\fIlist\^\fP\fB)\fP form is used, the file passed as an | |
3041 | argument should be read to obtain the output of \fIlist\fP. | |
3042 | .PP | |
bb70624e | 3043 | When available, process substitution is performed |
ccc6cda3 JA |
3044 | simultaneously with parameter and variable expansion, |
3045 | command substitution, | |
3046 | and arithmetic expansion. | |
726f6388 JA |
3047 | .SS Word Splitting |
3048 | .PP | |
3049 | The shell scans the results of | |
3050 | parameter expansion, | |
3051 | command substitution, | |
3052 | and | |
3053 | arithmetic expansion | |
3054 | that did not occur within double quotes for | |
3055 | .IR "word splitting" . | |
3056 | .PP | |
3057 | The shell treats each character of | |
3058 | .SM | |
3059 | .B IFS | |
3060 | as a delimiter, and splits the results of the other | |
ccc6cda3 | 3061 | expansions into words on these characters. If |
726f6388 JA |
3062 | .SM |
3063 | .B IFS | |
ccc6cda3 JA |
3064 | is unset, or its |
3065 | value is exactly | |
726f6388 JA |
3066 | .BR <space><tab><newline> , |
3067 | the default, then | |
d3ad40de CR |
3068 | sequences of |
3069 | .BR <space> , | |
3070 | .BR <tab> , | |
3071 | and | |
3072 | .B <newline> | |
3073 | at the beginning and end of the results of the previous | |
3074 | expansions are ignored, and | |
726f6388 JA |
3075 | any sequence of |
3076 | .SM | |
3077 | .B IFS | |
d3ad40de CR |
3078 | characters not at the beginning or end serves to delimit words. |
3079 | If | |
726f6388 JA |
3080 | .SM |
3081 | .B IFS | |
3082 | has a value other than the default, then sequences of | |
3083 | the whitespace characters | |
3084 | .B space | |
3085 | and | |
3086 | .B tab | |
3087 | are ignored at the beginning and end of the | |
3088 | word, as long as the whitespace character is in the | |
3089 | value of | |
3090 | .SM | |
3091 | .BR IFS | |
3092 | (an | |
3093 | .SM | |
3094 | .B IFS | |
3095 | whitespace character). | |
3096 | Any character in | |
3097 | .SM | |
3098 | .B IFS | |
3099 | that is not | |
3100 | .SM | |
3101 | .B IFS | |
3102 | whitespace, along with any adjacent | |
3103 | .SM | |
3104 | .B IFS | |
3105 | whitespace characters, delimits a field. | |
3106 | A sequence of | |
3107 | .SM | |
3108 | .B IFS | |
3109 | whitespace characters is also treated as a delimiter. | |
3110 | If the value of | |
3111 | .SM | |
3112 | .B IFS | |
3113 | is null, no word splitting occurs. | |
726f6388 | 3114 | .PP |
20587658 | 3115 | Explicit null arguments (\^\f3"\^"\fP or \^\f3\(aq\^\(aq\fP\^) are retained. |
ccc6cda3 | 3116 | Unquoted implicit null arguments, resulting from the expansion of |
bb70624e | 3117 | parameters that have no values, are removed. |
ccc6cda3 JA |
3118 | If a parameter with no value is expanded within double quotes, a |
3119 | null argument results and is retained. | |
726f6388 JA |
3120 | .PP |
3121 | Note that if no expansion occurs, no splitting | |
3122 | is performed. | |
3123 | .SS Pathname Expansion | |
3124 | .PP | |
3125 | After word splitting, | |
3126 | unless the | |
3127 | .B \-f | |
3128 | option has been set, | |
3129 | .B bash | |
ccc6cda3 | 3130 | scans each word for the characters |
726f6388 JA |
3131 | .BR * , |
3132 | .BR ? , | |
3133 | and | |
3134 | .BR [ . | |
3135 | If one of these characters appears, then the word is | |
3136 | regarded as a | |
3137 | .IR pattern , | |
3138 | and replaced with an alphabetically sorted list of | |
b28ff8c9 | 3139 | filenames matching the pattern |
bfd181e7 CR |
3140 | (see |
3141 | .SM | |
3142 | .B "Pattern Matching" | |
3143 | below). | |
b28ff8c9 | 3144 | If no matching filenames are found, |
ccc6cda3 JA |
3145 | and the shell option |
3146 | .B nullglob | |
57a3f689 | 3147 | is not enabled, the word is left unchanged. |
cce855bc JA |
3148 | If the |
3149 | .B nullglob | |
3150 | option is set, and no matches are found, | |
726f6388 | 3151 | the word is removed. |
d3a24ed2 CR |
3152 | If the |
3153 | .B failglob | |
3154 | shell option is set, and no matches are found, an error message | |
3155 | is printed and the command is not executed. | |
cce855bc JA |
3156 | If the shell option |
3157 | .B nocaseglob | |
3158 | is enabled, the match is performed without regard to the case | |
3159 | of alphabetic characters. | |
ccc6cda3 | 3160 | When a pattern is used for pathname expansion, |
726f6388 JA |
3161 | the character |
3162 | .B ``.'' | |
3163 | at the start of a name or immediately following a slash | |
ccc6cda3 JA |
3164 | must be matched explicitly, unless the shell option |
3165 | .B dotglob | |
3166 | is set. | |
cce855bc JA |
3167 | When matching a pathname, the slash character must always be |
3168 | matched explicitly. | |
ccc6cda3 | 3169 | In other cases, the |
726f6388 JA |
3170 | .B ``.'' |
3171 | character is not treated specially. | |
ccc6cda3 JA |
3172 | See the description of |
3173 | .B shopt | |
3174 | below under | |
3175 | .SM | |
3176 | .B SHELL BUILTIN COMMANDS | |
3177 | for a description of the | |
cce855bc JA |
3178 | .BR nocaseglob , |
3179 | .BR nullglob , | |
d3a24ed2 | 3180 | .BR failglob , |
ccc6cda3 JA |
3181 | and |
3182 | .B dotglob | |
3183 | shell options. | |
3184 | .PP | |
3185 | The | |
3186 | .SM | |
3187 | .B GLOBIGNORE | |
b28ff8c9 | 3188 | shell variable may be used to restrict the set of filenames matching a |
ccc6cda3 JA |
3189 | .IR pattern . |
3190 | If | |
3191 | .SM | |
3192 | .B GLOBIGNORE | |
b28ff8c9 | 3193 | is set, each matching filename that also matches one of the patterns in |
ccc6cda3 JA |
3194 | .SM |
3195 | .B GLOBIGNORE | |
3196 | is removed from the list of matches. | |
b28ff8c9 | 3197 | The filenames |
ccc6cda3 JA |
3198 | .B ``.'' |
3199 | and | |
3200 | .B ``..'' | |
d3a24ed2 | 3201 | are always ignored when |
ccc6cda3 JA |
3202 | .SM |
3203 | .B GLOBIGNORE | |
d3a24ed2 | 3204 | is set and not null. However, setting |
ccc6cda3 JA |
3205 | .SM |
3206 | .B GLOBIGNORE | |
d3a24ed2 | 3207 | to a non-null value has the effect of enabling the |
ccc6cda3 | 3208 | .B dotglob |
b28ff8c9 | 3209 | shell option, so all other filenames beginning with a |
ccc6cda3 JA |
3210 | .B ``.'' |
3211 | will match. | |
b28ff8c9 | 3212 | To get the old behavior of ignoring filenames beginning with a |
ccc6cda3 JA |
3213 | .BR ``.'' , |
3214 | make | |
3215 | .B ``.*'' | |
3216 | one of the patterns in | |
3217 | .SM | |
3218 | .BR GLOBIGNORE . | |
3219 | The | |
3220 | .B dotglob | |
3221 | option is disabled when | |
3222 | .SM | |
3223 | .B GLOBIGNORE | |
3224 | is unset. | |
726f6388 | 3225 | .PP |
cce855bc JA |
3226 | \fBPattern Matching\fP |
3227 | .PP | |
3228 | Any character that appears in a pattern, other than the special pattern | |
3229 | characters described below, matches itself. The NUL character may not | |
d3a24ed2 CR |
3230 | occur in a pattern. A backslash escapes the following character; the |
3231 | escaping backslash is discarded when matching. | |
3232 | The special pattern characters must be quoted if | |
cce855bc JA |
3233 | they are to be matched literally. |
3234 | .PP | |
726f6388 JA |
3235 | The special pattern characters have the following meanings: |
3236 | .PP | |
3237 | .PD 0 | |
89c77bc7 | 3238 | .RS |
726f6388 JA |
3239 | .TP |
3240 | .B * | |
3241 | Matches any string, including the null string. | |
4ac1ff98 | 3242 | When the \fBglobstar\fP shell option is enabled, and \fB*\fP is used in |
d0ca3503 | 3243 | a pathname expansion context, two adjacent \fB*\fPs used as a single |
4ac1ff98 CR |
3244 | pattern will match all files and zero or more directories and |
3245 | subdirectories. | |
3246 | If followed by a \fB/\fP, two adjacent \fB*\fPs will match only directories | |
3247 | and subdirectories. | |
726f6388 JA |
3248 | .TP |
3249 | .B ? | |
3250 | Matches any single character. | |
3251 | .TP | |
3252 | .B [...] | |
3253 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
3254 | separated by a hyphen denotes a |
3255 | \fIrange expression\fP; | |
3256 | any character that sorts between those two characters, inclusive, | |
3257 | using the current locale's collating sequence and character set, | |
726f6388 JA |
3258 | is matched. If the first character following the |
3259 | .B [ | |
3260 | is a | |
3261 | .B ! | |
3262 | or a | |
3263 | .B ^ | |
ccc6cda3 | 3264 | then any character not enclosed is matched. |
28ef6c31 | 3265 | The sorting order of characters in range expressions is determined by |
3443670e | 3266 | the current locale and the values of the |
984a1947 CR |
3267 | .SM |
3268 | .B LC_COLLATE | |
3443670e CR |
3269 | or |
3270 | .SM | |
3271 | .B LC_ALL | |
3272 | shell variables, if set. | |
3273 | To obtain the traditional interpretation of range expressions, where | |
3274 | .B [a\-d] | |
3275 | is equivalent to | |
3276 | .BR [abcd] , | |
3277 | set value of the | |
3278 | .B LC_ALL | |
3279 | shell variable to | |
74d0116b CR |
3280 | .BR C , |
3281 | or enable the | |
3282 | .B globasciiranges | |
3283 | shell option. | |
ccc6cda3 | 3284 | A |
726f6388 | 3285 | .B \- |
726f6388 JA |
3286 | may be matched by including it as the first or last character |
3287 | in the set. | |
ccc6cda3 JA |
3288 | A |
3289 | .B ] | |
3290 | may be matched by including it as the first character | |
3291 | in the set. | |
cce855bc JA |
3292 | .br |
3293 | .if t .sp 0.5 | |
3294 | .if n .sp 1 | |
3295 | Within | |
3296 | .B [ | |
3297 | and | |
3298 | .BR ] , | |
3299 | \fIcharacter classes\fP can be specified using the syntax | |
3300 | \fB[:\fP\fIclass\fP\fB:]\fP, where \fIclass\fP is one of the | |
ac18b312 | 3301 | following classes defined in the POSIX standard: |
cce855bc JA |
3302 | .PP |
3303 | .RS | |
3304 | .B | |
7117c2d2 JA |
3305 | .if n alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit |
3306 | .if t alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit | |
cce855bc JA |
3307 | .br |
3308 | A character class matches any character belonging to that class. | |
7117c2d2 | 3309 | The \fBword\fP character class matches letters, digits, and the character _. |
cce855bc JA |
3310 | .br |
3311 | .if t .sp 0.5 | |
3312 | .if n .sp 1 | |
3313 | Within | |
3314 | .B [ | |
3315 | and | |
3316 | .BR ] , | |
3317 | an \fIequivalence class\fP can be specified using the syntax | |
3318 | \fB[=\fP\fIc\fP\fB=]\fP, which matches all characters with the | |
3319 | same collation weight (as defined by the current locale) as | |
3320 | the character \fIc\fP. | |
3321 | .br | |
3322 | .if t .sp 0.5 | |
3323 | .if n .sp 1 | |
3324 | Within | |
3325 | .B [ | |
3326 | and | |
3327 | .BR ] , | |
3328 | the syntax \fB[.\fP\fIsymbol\fP\fB.]\fP matches the collating symbol | |
3329 | \fIsymbol\fP. | |
3330 | .RE | |
89c77bc7 | 3331 | .RE |
cce855bc JA |
3332 | .PD |
3333 | .PP | |
3334 | If the \fBextglob\fP shell option is enabled using the \fBshopt\fP | |
3335 | builtin, several extended pattern matching operators are recognized. | |
bb70624e | 3336 | In the following description, a \fIpattern-list\fP is a list of one |
cce855bc JA |
3337 | or more patterns separated by a \fB|\fP. |
3338 | Composite patterns may be formed using one or more of the following | |
3339 | sub-patterns: | |
3340 | .sp 1 | |
3341 | .PD 0 | |
3342 | .RS | |
3343 | .TP | |
3344 | \fB?(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3345 | Matches zero or one occurrence of the given patterns | |
3346 | .TP | |
3347 | \fB*(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3348 | Matches zero or more occurrences of the given patterns | |
3349 | .TP | |
3350 | \fB+(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3351 | Matches one or more occurrences of the given patterns | |
3352 | .TP | |
3353 | \fB@(\fP\^\fIpattern-list\^\fP\fB)\fP | |
43df7bbb | 3354 | Matches one of the given patterns |
cce855bc JA |
3355 | .TP |
3356 | \fB!(\fP\^\fIpattern-list\^\fP\fB)\fP | |
3357 | Matches anything except one of the given patterns | |
3358 | .RE | |
726f6388 JA |
3359 | .PD |
3360 | .SS Quote Removal | |
3361 | .PP | |
3362 | After the preceding expansions, all unquoted occurrences of the | |
3363 | characters | |
3364 | .BR \e , | |
20587658 | 3365 | .BR \(aq , |
ccc6cda3 JA |
3366 | and \^\f3"\fP\^ that did not result from one of the above |
3367 | expansions are removed. | |
726f6388 JA |
3368 | .SH REDIRECTION |
3369 | Before a command is executed, its input and output | |
3370 | may be | |
3371 | .I redirected | |
3372 | using a special notation interpreted by the shell. | |
3373 | Redirection may also be used to open and close files for the | |
3374 | current shell execution environment. The following redirection | |
3375 | operators may precede or appear anywhere within a | |
3376 | .I simple command | |
3377 | or may follow a | |
3378 | .IR command . | |
3379 | Redirections are processed in the order they appear, from | |
3380 | left to right. | |
3381 | .PP | |
a8fd3f3e CR |
3382 | Each redirection that may be preceded by a file descriptor number |
3383 | may instead be preceded by a word of the form {\fIvarname\fP}. | |
3384 | In this case, for each redirection operator except | |
3385 | >&- and <&-, the shell will allocate a file descriptor greater | |
19baff85 CR |
3386 | than or equal to 10 and assign it to \fIvarname\fP. |
3387 | If >&- or <&- is preceded | |
a8fd3f3e CR |
3388 | by {\fIvarname\fP}, the value of \fIvarname\fP defines the file |
3389 | descriptor to close. | |
3390 | .PP | |
726f6388 JA |
3391 | In the following descriptions, if the file descriptor number is |
3392 | omitted, and the first character of the redirection operator is | |
3393 | .BR < , | |
3394 | the redirection refers to the standard input (file descriptor | |
3395 | 0). If the first character of the redirection operator is | |
3396 | .BR > , | |
3397 | the redirection refers to the standard output (file descriptor | |
3398 | 1). | |
3399 | .PP | |
cce855bc | 3400 | The word following the redirection operator in the following |
7610e0c5 CR |
3401 | descriptions, unless otherwise noted, is subjected to |
3402 | brace expansion, tilde expansion, parameter and variable expansion, | |
3403 | command substitution, arithmetic expansion, quote removal, | |
3404 | pathname expansion, and word splitting. | |
cce855bc | 3405 | If it expands to more than one word, |
726f6388 JA |
3406 | .B bash |
3407 | reports an error. | |
3408 | .PP | |
3409 | Note that the order of redirections is significant. For example, | |
3410 | the command | |
3411 | .RS | |
3412 | .PP | |
3413 | ls \fB>\fP dirlist 2\fB>&\fP1 | |
3414 | .RE | |
3415 | .PP | |
3416 | directs both standard output and standard error to the file | |
3417 | .IR dirlist , | |
3418 | while the command | |
3419 | .RS | |
3420 | .PP | |
3421 | ls 2\fB>&\fP1 \fB>\fP dirlist | |
3422 | .RE | |
3423 | .PP | |
3424 | directs only the standard output to file | |
3425 | .IR dirlist , | |
db31fb26 | 3426 | because the standard error was duplicated from the standard output |
726f6388 JA |
3427 | before the standard output was redirected to |
3428 | .IR dirlist . | |
cce855bc | 3429 | .PP |
bb70624e JA |
3430 | \fBBash\fP handles several filenames specially when they are used in |
3431 | redirections, as described in the following table: | |
3432 | .RS | |
3433 | .PP | |
3434 | .PD 0 | |
3435 | .TP | |
3436 | .B /dev/fd/\fIfd\fP | |
3437 | If \fIfd\fP is a valid integer, file descriptor \fIfd\fP is duplicated. | |
3438 | .TP | |
3439 | .B /dev/stdin | |
3440 | File descriptor 0 is duplicated. | |
3441 | .TP | |
3442 | .B /dev/stdout | |
3443 | File descriptor 1 is duplicated. | |
3444 | .TP | |
3445 | .B /dev/stderr | |
3446 | File descriptor 2 is duplicated. | |
3447 | .TP | |
3448 | .B /dev/tcp/\fIhost\fP/\fIport\fP | |
3449 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3450 | is an integer port number or service name, \fBbash\fP attempts to open |
3451 | a TCP connection to the corresponding socket. | |
bb70624e JA |
3452 | .TP |
3453 | .B /dev/udp/\fIhost\fP/\fIport\fP | |
3454 | If \fIhost\fP is a valid hostname or Internet address, and \fIport\fP | |
f73dda09 JA |
3455 | is an integer port number or service name, \fBbash\fP attempts to open |
3456 | a UDP connection to the corresponding socket. | |
bb70624e JA |
3457 | .PD |
3458 | .RE | |
3459 | .PP | |
cce855bc | 3460 | A failure to open or create a file causes the redirection to fail. |
cac4cdbf CR |
3461 | .PP |
3462 | Redirections using file descriptors greater than 9 should be used with | |
3463 | care, as they may conflict with file descriptors the shell uses | |
3464 | internally. | |
726f6388 JA |
3465 | .SS Redirecting Input |
3466 | .PP | |
3467 | Redirection of input causes the file whose name results from | |
3468 | the expansion of | |
3469 | .I word | |
3470 | to be opened for reading on file descriptor | |
3471 | .IR n , | |
3472 | or the standard input (file descriptor 0) if | |
3473 | .I n | |
3474 | is not specified. | |
3475 | .PP | |
3476 | The general format for redirecting input is: | |
3477 | .RS | |
3478 | .PP | |
3479 | [\fIn\fP]\fB<\fP\fIword\fP | |
3480 | .RE | |
3481 | .SS Redirecting Output | |
3482 | .PP | |
3483 | Redirection of output causes the file whose name results from | |
3484 | the expansion of | |
3485 | .I word | |
3486 | to be opened for writing on file descriptor | |
3487 | .IR n , | |
3488 | or the standard output (file descriptor 1) if | |
3489 | .I n | |
3490 | is not specified. If the file does not exist it is created; | |
3491 | if it does exist it is truncated to zero size. | |
3492 | .PP | |
3493 | The general format for redirecting output is: | |
3494 | .RS | |
3495 | .PP | |
3496 | [\fIn\fP]\fB>\fP\fIword\fP | |
3497 | .RE | |
3498 | .PP | |
3499 | If the redirection operator is | |
ccc6cda3 JA |
3500 | .BR > , |
3501 | and the | |
cce855bc | 3502 | .B noclobber |
ccc6cda3 JA |
3503 | option to the |
3504 | .B set | |
bb70624e | 3505 | builtin has been enabled, the redirection will fail if the file |
cce855bc JA |
3506 | whose name results from the expansion of \fIword\fP exists and is |
3507 | a regular file. | |
ccc6cda3 | 3508 | If the redirection operator is |
726f6388 | 3509 | .BR >| , |
cce855bc JA |
3510 | or the redirection operator is |
3511 | .B > | |
3512 | and the | |
3513 | .B noclobber | |
726f6388 JA |
3514 | option to the |
3515 | .B set | |
cce855bc | 3516 | builtin command is not enabled, the redirection is attempted even |
ccc6cda3 | 3517 | if the file named by \fIword\fP exists. |
726f6388 JA |
3518 | .SS Appending Redirected Output |
3519 | .PP | |
3520 | Redirection of output in this fashion | |
3521 | causes the file whose name results from | |
3522 | the expansion of | |
3523 | .I word | |
3524 | to be opened for appending on file descriptor | |
3525 | .IR n , | |
3526 | or the standard output (file descriptor 1) if | |
3527 | .I n | |
3528 | is not specified. If the file does not exist it is created. | |
3529 | .PP | |
3530 | The general format for appending output is: | |
3531 | .RS | |
3532 | .PP | |
3533 | [\fIn\fP]\fB>>\fP\fIword\fP | |
3534 | .RE | |
3535 | .PP | |
3536 | .SS Redirecting Standard Output and Standard Error | |
3537 | .PP | |
8943768b | 3538 | This construct allows both the |
726f6388 JA |
3539 | standard output (file descriptor 1) and |
3540 | the standard error output (file descriptor 2) | |
3541 | to be redirected to the file whose name is the | |
3542 | expansion of | |
8943768b | 3543 | .IR word . |
726f6388 JA |
3544 | .PP |
3545 | There are two formats for redirecting standard output and | |
3546 | standard error: | |
3547 | .RS | |
3548 | .PP | |
3549 | \fB&>\fP\fIword\fP | |
3550 | .RE | |
3551 | and | |
3552 | .RS | |
3553 | \fB>&\fP\fIword\fP | |
3554 | .RE | |
3555 | .PP | |
3556 | Of the two forms, the first is preferred. | |
3557 | This is semantically equivalent to | |
3558 | .RS | |
3559 | .PP | |
3560 | \fB>\fP\fIword\fP 2\fB>&\fP1 | |
3561 | .RE | |
8943768b | 3562 | .PP |
f6da9f85 | 3563 | (see \fBDuplicating File Descriptors\fP below). |
8943768b CR |
3564 | .SS Appending Standard Output and Standard Error |
3565 | .PP | |
3566 | This construct allows both the | |
3567 | standard output (file descriptor 1) and | |
3568 | the standard error output (file descriptor 2) | |
3569 | to be appended to the file whose name is the | |
3570 | expansion of | |
3571 | .IR word . | |
3572 | .PP | |
3573 | The format for appending standard output and standard error is: | |
3574 | .RS | |
3575 | .PP | |
3576 | \fB&>>\fP\fIword\fP | |
3577 | .RE | |
3578 | .PP | |
3579 | This is semantically equivalent to | |
3580 | .RS | |
3581 | .PP | |
3582 | \fB>>\fP\fIword\fP 2\fB>&\fP1 | |
3583 | .RE | |
f6da9f85 CR |
3584 | .PP |
3585 | (see \fBDuplicating File Descriptors\fP below). | |
726f6388 JA |
3586 | .SS Here Documents |
3587 | .PP | |
3588 | This type of redirection instructs the shell to read input from the | |
3589 | current source until a line containing only | |
626d0694 | 3590 | .I delimiter |
726f6388 JA |
3591 | (with no trailing blanks) |
3592 | is seen. All of | |
3593 | the lines read up to that point are then used as the standard | |
3594 | input for a command. | |
3595 | .PP | |
7117c2d2 | 3596 | The format of here-documents is: |
726f6388 JA |
3597 | .RS |
3598 | .PP | |
3599 | .nf | |
3600 | \fB<<\fP[\fB\-\fP]\fIword\fP | |
f73dda09 | 3601 | \fIhere-document\fP |
726f6388 JA |
3602 | \fIdelimiter\fP |
3603 | .fi | |
3604 | .RE | |
3605 | .PP | |
7610e0c5 CR |
3606 | No parameter and variable expansion, command substitution, |
3607 | arithmetic expansion, or pathname expansion is performed on | |
726f6388 JA |
3608 | .IR word . |
3609 | If any characters in | |
3610 | .I word | |
3611 | are quoted, the | |
3612 | .I delimiter | |
3613 | is the result of quote removal on | |
3614 | .IR word , | |
cce855bc JA |
3615 | and the lines in the here-document are not expanded. |
3616 | If \fIword\fP is unquoted, | |
726f6388 JA |
3617 | all lines of the here-document are subjected to parameter expansion, |
3618 | command substitution, and arithmetic expansion. In the latter | |
bb70624e | 3619 | case, the character sequence |
726f6388 JA |
3620 | .B \e<newline> |
3621 | is ignored, and | |
3622 | .B \e | |
3623 | must be used to quote the characters | |
3624 | .BR \e , | |
3625 | .BR $ , | |
3626 | and | |
3d4e09aa | 3627 | .BR \` . |
726f6388 JA |
3628 | .PP |
3629 | If the redirection operator is | |
3630 | .BR <<\- , | |
3631 | then all leading tab characters are stripped from input lines and the | |
3632 | line containing | |
3633 | .IR delimiter . | |
3634 | This allows | |
3635 | here-documents within shell scripts to be indented in a | |
3636 | natural fashion. | |
7117c2d2 JA |
3637 | .SS "Here Strings" |
3638 | A variant of here documents, the format is: | |
3639 | .RS | |
3640 | .PP | |
3641 | .nf | |
3642 | \fB<<<\fP\fIword\fP | |
3643 | .fi | |
3644 | .RE | |
3645 | .PP | |
7610e0c5 CR |
3646 | The \fIword\fP undergoes |
3647 | brace expansion, tilde expansion, parameter and variable expansion, | |
3648 | command substitution, arithmetic expansion, and quote removal. | |
3649 | Pathname expansion word splitting are not performed. | |
3650 | The result is supplied as a single string to the command on its | |
3651 | standard input. | |
726f6388 JA |
3652 | .SS "Duplicating File Descriptors" |
3653 | .PP | |
3654 | The redirection operator | |
3655 | .RS | |
3656 | .PP | |
3657 | [\fIn\fP]\fB<&\fP\fIword\fP | |
3658 | .RE | |
3659 | .PP | |
3660 | is used to duplicate input file descriptors. | |
3661 | If | |
3662 | .I word | |
3663 | expands to one or more digits, the file descriptor denoted by | |
3664 | .I n | |
cce855bc JA |
3665 | is made to be a copy of that file descriptor. |
3666 | If the digits in | |
3667 | .I word | |
3668 | do not specify a file descriptor open for input, a redirection error occurs. | |
3669 | If | |
726f6388 JA |
3670 | .I word |
3671 | evaluates to | |
3672 | .BR \- , | |
3673 | file descriptor | |
3674 | .I n | |
3675 | is closed. If | |
3676 | .I n | |
3677 | is not specified, the standard input (file descriptor 0) is used. | |
3678 | .PP | |
3679 | The operator | |
3680 | .RS | |
3681 | .PP | |
3682 | [\fIn\fP]\fB>&\fP\fIword\fP | |
3683 | .RE | |
3684 | .PP | |
3685 | is used similarly to duplicate output file descriptors. If | |
3686 | .I n | |
3687 | is not specified, the standard output (file descriptor 1) is used. | |
cce855bc JA |
3688 | If the digits in |
3689 | .I word | |
3690 | do not specify a file descriptor open for output, a redirection error occurs. | |
726f6388 JA |
3691 | As a special case, if \fIn\fP is omitted, and \fIword\fP does not |
3692 | expand to one or more digits, the standard output and standard | |
3693 | error are redirected as described previously. | |
7117c2d2 JA |
3694 | .SS "Moving File Descriptors" |
3695 | .PP | |
3696 | The redirection operator | |
3697 | .RS | |
3698 | .PP | |
3699 | [\fIn\fP]\fB<&\fP\fIdigit\fP\fB\-\fP | |
3700 | .RE | |
3701 | .PP | |
3702 | moves the file descriptor \fIdigit\fP to file descriptor | |
3703 | .IR n , | |
3704 | or the standard input (file descriptor 0) if \fIn\fP is not specified. | |
3705 | \fIdigit\fP is closed after being duplicated to \fIn\fP. | |
3706 | .PP | |
3707 | Similarly, the redirection operator | |
3708 | .RS | |
3709 | .PP | |
3710 | [\fIn\fP]\fB>&\fP\fIdigit\fP\fB\-\fP | |
3711 | .RE | |
3712 | .PP | |
3713 | moves the file descriptor \fIdigit\fP to file descriptor | |
3714 | .IR n , | |
3715 | or the standard output (file descriptor 1) if \fIn\fP is not specified. | |
726f6388 JA |
3716 | .SS "Opening File Descriptors for Reading and Writing" |
3717 | .PP | |
3718 | The redirection operator | |
3719 | .RS | |
3720 | .PP | |
3721 | [\fIn\fP]\fB<>\fP\fIword\fP | |
3722 | .RE | |
3723 | .PP | |
3724 | causes the file whose name is the expansion of | |
3725 | .I word | |
3726 | to be opened for both reading and writing on file descriptor | |
3727 | .IR n , | |
ccc6cda3 | 3728 | or on file descriptor 0 if |
726f6388 JA |
3729 | .I n |
3730 | is not specified. If the file does not exist, it is created. | |
726f6388 | 3731 | .SH ALIASES |
bb70624e | 3732 | \fIAliases\fP allow a string to be substituted for a word when it is used |
cce855bc | 3733 | as the first word of a simple command. |
bb70624e | 3734 | The shell maintains a list of aliases that may be set and unset with the |
726f6388 JA |
3735 | .B alias |
3736 | and | |
3737 | .B unalias | |
3738 | builtin commands (see | |
3739 | .SM | |
3740 | .B SHELL BUILTIN COMMANDS | |
3741 | below). | |
de8913bd | 3742 | The first word of each simple command, if unquoted, |
726f6388 JA |
3743 | is checked to see if it has an |
3744 | alias. If so, that word is replaced by the text of the alias. | |
3d4e09aa | 3745 | The characters \fB/\fP, \fB$\fP, \fB\`\fP, and \fB=\fP and |
de8913bd CR |
3746 | any of the shell \fImetacharacters\fP or quoting characters |
3747 | listed above may not appear in an alias name. | |
3748 | The replacement text may contain any valid shell input, | |
3749 | including shell metacharacters. | |
3750 | The first word of the replacement text is tested | |
726f6388 | 3751 | for aliases, but a word that is identical to an alias being expanded |
de8913bd CR |
3752 | is not expanded a second time. |
3753 | This means that one may alias | |
726f6388 JA |
3754 | .B ls |
3755 | to | |
3756 | .BR "ls \-F" , | |
3757 | for instance, and | |
3758 | .B bash | |
3759 | does not try to recursively expand the replacement text. | |
3760 | If the last character of the alias value is a | |
3761 | .IR blank , | |
3762 | then the next command | |
3763 | word following the alias is also checked for alias expansion. | |
3764 | .PP | |
3765 | Aliases are created and listed with the | |
3766 | .B alias | |
3767 | command, and removed with the | |
3768 | .B unalias | |
3769 | command. | |
3770 | .PP | |
ccc6cda3 | 3771 | There is no mechanism for using arguments in the replacement text. |
bb70624e JA |
3772 | If arguments are needed, a shell function should be used (see |
3773 | .SM | |
3774 | .B FUNCTIONS | |
3775 | below). | |
726f6388 | 3776 | .PP |
ccc6cda3 JA |
3777 | Aliases are not expanded when the shell is not interactive, unless |
3778 | the | |
3779 | .B expand_aliases | |
3780 | shell option is set using | |
3781 | .B shopt | |
3782 | (see the description of | |
3783 | .B shopt | |
3784 | under | |
3785 | .SM | |
3786 | \fBSHELL BUILTIN COMMANDS\fP | |
3787 | below). | |
726f6388 JA |
3788 | .PP |
3789 | The rules concerning the definition and use of aliases are | |
3790 | somewhat confusing. | |
3791 | .B Bash | |
3792 | always reads at least one complete line | |
3793 | of input before executing any | |
3794 | of the commands on that line. Aliases are expanded when a | |
3795 | command is read, not when it is executed. Therefore, an | |
3796 | alias definition appearing on the same line as another | |
3797 | command does not take effect until the next line of input is read. | |
ccc6cda3 | 3798 | The commands following the alias definition |
726f6388 JA |
3799 | on that line are not affected by the new alias. |
3800 | This behavior is also an issue when functions are executed. | |
cce855bc | 3801 | Aliases are expanded when a function definition is read, |
726f6388 JA |
3802 | not when the function is executed, because a function definition |
3803 | is itself a compound command. As a consequence, aliases | |
3804 | defined in a function are not available until after that | |
3805 | function is executed. To be safe, always put | |
3806 | alias definitions on a separate line, and do not use | |
3807 | .B alias | |
3808 | in compound commands. | |
3809 | .PP | |
cce855bc | 3810 | For almost every purpose, aliases are superseded by |
726f6388 | 3811 | shell functions. |
ccc6cda3 JA |
3812 | .SH FUNCTIONS |
3813 | A shell function, defined as described above under | |
3814 | .SM | |
3815 | .BR "SHELL GRAMMAR" , | |
3816 | stores a series of commands for later execution. | |
bb70624e JA |
3817 | When the name of a shell function is used as a simple command name, |
3818 | the list of commands associated with that function name is executed. | |
ccc6cda3 JA |
3819 | Functions are executed in the context of the |
3820 | current shell; no new process is created to interpret | |
3821 | them (contrast this with the execution of a shell script). | |
3822 | When a function is executed, the arguments to the | |
3823 | function become the positional parameters | |
bb70624e JA |
3824 | during its execution. |
3825 | The special parameter | |
ccc6cda3 | 3826 | .B # |
dc60d4e0 | 3827 | is updated to reflect the change. Special parameter \fB0\fP |
bb70624e | 3828 | is unchanged. |
d3a24ed2 | 3829 | The first element of the |
bb70624e JA |
3830 | .SM |
3831 | .B FUNCNAME | |
3832 | variable is set to the name of the function while the function | |
3833 | is executing. | |
4301bca7 | 3834 | .PP |
bb70624e | 3835 | All other aspects of the shell execution |
ccc6cda3 | 3836 | environment are identical between a function and its caller |
4301bca7 | 3837 | with these exceptions: the |
ccc6cda3 JA |
3838 | .SM |
3839 | .B DEBUG | |
76a8d78d CR |
3840 | and |
3841 | .B RETURN | |
3842 | traps (see the description of the | |
ccc6cda3 JA |
3843 | .B trap |
3844 | builtin under | |
3845 | .SM | |
3846 | .B SHELL BUILTIN COMMANDS | |
76a8d78d | 3847 | below) are not inherited unless the function has been given the |
7117c2d2 JA |
3848 | \fBtrace\fP attribute (see the description of the |
3849 | .SM | |
3850 | .B declare | |
d3a24ed2 CR |
3851 | builtin below) or the |
3852 | \fB\-o functrace\fP shell option has been enabled with | |
3853 | the \fBset\fP builtin | |
4301bca7 CR |
3854 | (in which case all functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps), |
3855 | and the | |
3856 | .SM | |
3857 | .B ERR | |
3858 | trap is not inherited unless the \fB\-o errtrace\fP shell option has | |
3859 | been enabled. | |
726f6388 | 3860 | .PP |
ccc6cda3 JA |
3861 | Variables local to the function may be declared with the |
3862 | .B local | |
3863 | builtin command. Ordinarily, variables and their values | |
3864 | are shared between the function and its caller. | |
726f6388 | 3865 | .PP |
6faad625 CR |
3866 | The \fBFUNCNEST\fP variable, if set to a numeric value greater |
3867 | than 0, defines a maximum function nesting level. Function | |
3868 | invocations that exceed the limit cause the entire command to | |
3869 | abort. | |
3870 | .PP | |
ccc6cda3 JA |
3871 | If the builtin command |
3872 | .B return | |
3873 | is executed in a function, the function completes and | |
3874 | execution resumes with the next command after the function | |
d3a24ed2 CR |
3875 | call. |
3876 | Any command associated with the \fBRETURN\fP trap is executed | |
3877 | before execution resumes. | |
3878 | When a function completes, the values of the | |
ccc6cda3 JA |
3879 | positional parameters and the special parameter |
3880 | .B # | |
cce855bc | 3881 | are restored to the values they had prior to the function's |
ccc6cda3 | 3882 | execution. |
726f6388 | 3883 | .PP |
ccc6cda3 JA |
3884 | Function names and definitions may be listed with the |
3885 | .B \-f | |
726f6388 | 3886 | option to the |
ccc6cda3 JA |
3887 | .B declare |
3888 | or | |
3889 | .B typeset | |
3890 | builtin commands. The | |
3891 | .B \-F | |
3892 | option to | |
3893 | .B declare | |
3894 | or | |
3895 | .B typeset | |
d3a24ed2 CR |
3896 | will list the function names only |
3897 | (and optionally the source file and line number, if the \fBextdebug\fP | |
3898 | shell option is enabled). | |
ccc6cda3 JA |
3899 | Functions may be exported so that subshells |
3900 | automatically have them defined with the | |
3901 | .B \-f | |
3902 | option to the | |
3903 | .B export | |
3904 | builtin. | |
11a6f9a9 CR |
3905 | A function definition may be deleted using the \fB\-f\fP option to |
3906 | the | |
3907 | .B unset | |
3908 | builtin. | |
d3a24ed2 CR |
3909 | Note that shell functions and variables with the same name may result |
3910 | in multiple identically-named entries in the environment passed to the | |
3911 | shell's children. | |
3912 | Care should be taken in cases where this may cause a problem. | |
726f6388 | 3913 | .PP |
7d92f73f CR |
3914 | Functions may be recursive. |
3915 | The \fBFUNCNEST\fP variable may be used to limit the depth of the | |
3916 | function call stack and restrict the number of function invocations. | |
3917 | By default, no limit is imposed on the number of recursive calls. | |
cce855bc JA |
3918 | .SH "ARITHMETIC EVALUATION" |
3919 | The shell allows arithmetic expressions to be evaluated, under | |
d3a24ed2 CR |
3920 | certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin |
3921 | commands and \fBArithmetic Expansion\fP). | |
7117c2d2 | 3922 | Evaluation is done in fixed-width integers with no check for overflow, |
cce855bc | 3923 | though division by 0 is trapped and flagged as an error. |
d3a24ed2 CR |
3924 | The operators and their precedence, associativity, and values |
3925 | are the same as in the C language. | |
cce855bc JA |
3926 | The following list of operators is grouped into levels of |
3927 | equal-precedence operators. | |
3928 | The levels are listed in order of decreasing precedence. | |
726f6388 | 3929 | .PP |
cce855bc JA |
3930 | .PD 0 |
3931 | .TP | |
bb70624e JA |
3932 | .B \fIid\fP++ \fIid\fP\-\- |
3933 | variable post-increment and post-decrement | |
3934 | .TP | |
3935 | .B ++\fIid\fP \-\-\fIid\fP | |
3936 | variable pre-increment and pre-decrement | |
3937 | .TP | |
cce855bc JA |
3938 | .B \- + |
3939 | unary minus and plus | |
3940 | .TP | |
3941 | .B ! ~ | |
3942 | logical and bitwise negation | |
3943 | .TP | |
3944 | .B ** | |
3945 | exponentiation | |
3946 | .TP | |
3947 | .B * / % | |
3948 | multiplication, division, remainder | |
3949 | .TP | |
3950 | .B + \- | |
3951 | addition, subtraction | |
3952 | .TP | |
3953 | .B << >> | |
3954 | left and right bitwise shifts | |
3955 | .TP | |
3956 | .B <= >= < > | |
3957 | comparison | |
3958 | .TP | |
3959 | .B == != | |
3960 | equality and inequality | |
3961 | .TP | |
3962 | .B & | |
3963 | bitwise AND | |
3964 | .TP | |
3965 | .B ^ | |
3966 | bitwise exclusive OR | |
3967 | .TP | |
3968 | .B | | |
3969 | bitwise OR | |
3970 | .TP | |
3971 | .B && | |
3972 | logical AND | |
3973 | .TP | |
3974 | .B || | |
3975 | logical OR | |
3976 | .TP | |
3977 | .B \fIexpr\fP?\fIexpr\fP:\fIexpr\fP | |
d3a24ed2 | 3978 | conditional operator |
cce855bc JA |
3979 | .TP |
3980 | .B = *= /= %= += \-= <<= >>= &= ^= |= | |
3981 | assignment | |
bb70624e JA |
3982 | .TP |
3983 | .B \fIexpr1\fP , \fIexpr2\fP | |
3984 | comma | |
cce855bc | 3985 | .PD |
ccc6cda3 | 3986 | .PP |
cce855bc | 3987 | Shell variables are allowed as operands; parameter expansion is |
bb70624e JA |
3988 | performed before the expression is evaluated. |
3989 | Within an expression, shell variables may also be referenced by name | |
3990 | without using the parameter expansion syntax. | |
d3a24ed2 CR |
3991 | A shell variable that is null or unset evaluates to 0 when referenced |
3992 | by name without using the parameter expansion syntax. | |
bb70624e | 3993 | The value of a variable is evaluated as an arithmetic expression |
d3a24ed2 CR |
3994 | when it is referenced, or when a variable which has been given the |
3995 | \fIinteger\fP attribute using \fBdeclare -i\fP is assigned a value. | |
3996 | A null value evaluates to 0. | |
dc60d4e0 | 3997 | A shell variable need not have its \fIinteger\fP attribute |
cce855bc | 3998 | turned on to be used in an expression. |
ccc6cda3 | 3999 | .PP |
cce855bc JA |
4000 | Constants with a leading 0 are interpreted as octal numbers. |
4001 | A leading 0x or 0X denotes hexadecimal. | |
1b13a290 | 4002 | Otherwise, numbers take the form [\fIbase#\fP]n, where the optional \fIbase\fP |
cce855bc JA |
4003 | is a decimal number between 2 and 64 representing the arithmetic |
4004 | base, and \fIn\fP is a number in that base. | |
bb70624e | 4005 | If \fIbase#\fP is omitted, then base 10 is used. |
cce855bc | 4006 | The digits greater than 9 are represented by the lowercase letters, |
f73dda09 | 4007 | the uppercase letters, @, and _, in that order. |
cce855bc | 4008 | If \fIbase\fP is less than or equal to 36, lowercase and uppercase |
f75912ae | 4009 | letters may be used interchangeably to represent numbers between 10 |
cce855bc | 4010 | and 35. |
ccc6cda3 | 4011 | .PP |
cce855bc JA |
4012 | Operators are evaluated in order of precedence. Sub-expressions in |
4013 | parentheses are evaluated first and may override the precedence | |
4014 | rules above. | |
4015 | .SH "CONDITIONAL EXPRESSIONS" | |
4016 | Conditional expressions are used by the \fB[[\fP compound command and | |
4017 | the \fBtest\fP and \fB[\fP builtin commands to test file attributes | |
4018 | and perform string and arithmetic comparisons. | |
4019 | Expressions are formed from the following unary or binary primaries. | |
4020 | If any \fIfile\fP argument to one of the primaries is of the form | |
bb70624e JA |
4021 | \fI/dev/fd/n\fP, then file descriptor \fIn\fP is checked. |
4022 | If the \fIfile\fP argument to one of the primaries is one of | |
4023 | \fI/dev/stdin\fP, \fI/dev/stdout\fP, or \fI/dev/stderr\fP, file | |
4024 | descriptor 0, 1, or 2, respectively, is checked. | |
be7d8f2d CR |
4025 | .PP |
4026 | Unless otherwise specified, primaries that operate on files follow symbolic | |
4027 | links and operate on the target of the link, rather than the link itself. | |
6bf8a8a7 CR |
4028 | .if t .sp 0.5 |
4029 | .if n .sp 1 | |
54a1fa7c | 4030 | When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort |
6bf8a8a7 | 4031 | lexicographically using the current locale. |
54a1fa7c | 4032 | The \fBtest\fP command sorts using ASCII ordering. |
cce855bc JA |
4033 | .sp 1 |
4034 | .PD 0 | |
4035 | .TP | |
4036 | .B \-a \fIfile\fP | |
4037 | True if \fIfile\fP exists. | |
4038 | .TP | |
4039 | .B \-b \fIfile\fP | |
4040 | True if \fIfile\fP exists and is a block special file. | |
4041 | .TP | |
4042 | .B \-c \fIfile\fP | |
4043 | True if \fIfile\fP exists and is a character special file. | |
4044 | .TP | |
4045 | .B \-d \fIfile\fP | |
4046 | True if \fIfile\fP exists and is a directory. | |
4047 | .TP | |
4048 | .B \-e \fIfile\fP | |
4049 | True if \fIfile\fP exists. | |
4050 | .TP | |
4051 | .B \-f \fIfile\fP | |
4052 | True if \fIfile\fP exists and is a regular file. | |
4053 | .TP | |
4054 | .B \-g \fIfile\fP | |
4055 | True if \fIfile\fP exists and is set-group-id. | |
4056 | .TP | |
b72432fd JA |
4057 | .B \-h \fIfile\fP |
4058 | True if \fIfile\fP exists and is a symbolic link. | |
4059 | .TP | |
cce855bc JA |
4060 | .B \-k \fIfile\fP |
4061 | True if \fIfile\fP exists and its ``sticky'' bit is set. | |
4062 | .TP | |
4063 | .B \-p \fIfile\fP | |
4064 | True if \fIfile\fP exists and is a named pipe (FIFO). | |
4065 | .TP | |
4066 | .B \-r \fIfile\fP | |
4067 | True if \fIfile\fP exists and is readable. | |
4068 | .TP | |
4069 | .B \-s \fIfile\fP | |
4070 | True if \fIfile\fP exists and has a size greater than zero. | |
4071 | .TP | |
4072 | .B \-t \fIfd\fP | |
4073 | True if file descriptor | |
4074 | .I fd | |
4075 | is open and refers to a terminal. | |
4076 | .TP | |
4077 | .B \-u \fIfile\fP | |
4078 | True if \fIfile\fP exists and its set-user-id bit is set. | |
4079 | .TP | |
4080 | .B \-w \fIfile\fP | |
4081 | True if \fIfile\fP exists and is writable. | |
4082 | .TP | |
4083 | .B \-x \fIfile\fP | |
4084 | True if \fIfile\fP exists and is executable. | |
4085 | .TP | |
cce855bc JA |
4086 | .B \-G \fIfile\fP |
4087 | True if \fIfile\fP exists and is owned by the effective group id. | |
4088 | .TP | |
4089 | .B \-L \fIfile\fP | |
4090 | True if \fIfile\fP exists and is a symbolic link. | |
4091 | .TP | |
5cdaaf76 CR |
4092 | .B \-N \fIfile\fP |
4093 | True if \fIfile\fP exists and has been modified since it was last read. | |
4094 | .TP | |
4095 | .B \-O \fIfile\fP | |
4096 | True if \fIfile\fP exists and is owned by the effective user id. | |
4097 | .TP | |
cce855bc JA |
4098 | .B \-S \fIfile\fP |
4099 | True if \fIfile\fP exists and is a socket. | |
4100 | .TP | |
5cdaaf76 CR |
4101 | \fIfile1\fP \fB\-ef\fP \fIfile2\fP |
4102 | True if \fIfile1\fP and \fIfile2\fP refer to the same device and | |
4103 | inode numbers. | |
cce855bc JA |
4104 | .TP |
4105 | \fIfile1\fP \-\fBnt\fP \fIfile2\fP | |
7117c2d2 JA |
4106 | True if \fIfile1\fP is newer (according to modification date) than \fIfile2\fP, |
4107 | or if \fIfile1\fP exists and \fPfile2\fP does not. | |
cce855bc JA |
4108 | .TP |
4109 | \fIfile1\fP \-\fBot\fP \fIfile2\fP | |
7117c2d2 JA |
4110 | True if \fIfile1\fP is older than \fIfile2\fP, or if \fIfile2\fP exists |
4111 | and \fIfile1\fP does not. | |
cce855bc | 4112 | .TP |
cce855bc | 4113 | .B \-o \fIoptname\fP |
6faad625 | 4114 | True if the shell option |
cce855bc JA |
4115 | .I optname |
4116 | is enabled. | |
4117 | See the list of options under the description of the | |
4118 | .B \-o | |
4119 | option to the | |
4120 | .B set | |
4121 | builtin below. | |
4122 | .TP | |
6faad625 CR |
4123 | .B \-v \fIvarname\fP |
4124 | True if the shell variable | |
4125 | .I varname | |
4126 | is set (has been assigned a value). | |
4127 | .TP | |
cce855bc JA |
4128 | .B \-z \fIstring\fP |
4129 | True if the length of \fIstring\fP is zero. | |
4130 | .TP | |
cce855bc | 4131 | \fIstring\fP |
f085a21f CR |
4132 | .PD 0 |
4133 | .TP | |
4134 | .B \-n \fIstring\fP | |
4135 | .PD | |
cce855bc JA |
4136 | True if the length of |
4137 | .I string | |
4138 | is non-zero. | |
4139 | .TP | |
4140 | \fIstring1\fP \fB==\fP \fIstring2\fP | |
a3143574 CR |
4141 | .PD 0 |
4142 | .TP | |
4143 | \fIstring1\fP \fB=\fP \fIstring2\fP | |
4144 | .PD | |
4145 | True if the strings are equal. \fB=\fP should be used | |
4146 | with the \fBtest\fP command for POSIX conformance. | |
cce855bc JA |
4147 | .TP |
4148 | \fIstring1\fP \fB!=\fP \fIstring2\fP | |
4149 | True if the strings are not equal. | |
4150 | .TP | |
4151 | \fIstring1\fP \fB<\fP \fIstring2\fP | |
0d8616ff | 4152 | True if \fIstring1\fP sorts before \fIstring2\fP lexicographically. |
cce855bc JA |
4153 | .TP |
4154 | \fIstring1\fP \fB>\fP \fIstring2\fP | |
0d8616ff | 4155 | True if \fIstring1\fP sorts after \fIstring2\fP lexicographically. |
cce855bc JA |
4156 | .TP |
4157 | .I \fIarg1\fP \fBOP\fP \fIarg2\fP | |
4158 | .SM | |
4159 | .B OP | |
4160 | is one of | |
4161 | .BR \-eq , | |
4162 | .BR \-ne , | |
4163 | .BR \-lt , | |
4164 | .BR \-le , | |
4165 | .BR \-gt , | |
4166 | or | |
4167 | .BR \-ge . | |
4168 | These arithmetic binary operators return true if \fIarg1\fP | |
4169 | is equal to, not equal to, less than, less than or equal to, | |
4170 | greater than, or greater than or equal to \fIarg2\fP, respectively. | |
4171 | .I Arg1 | |
4172 | and | |
4173 | .I arg2 | |
4174 | may be positive or negative integers. | |
4175 | .PD | |
4176 | .SH "SIMPLE COMMAND EXPANSION" | |
4177 | When a simple command is executed, the shell performs the following | |
4178 | expansions, assignments, and redirections, from left to right. | |
4179 | .IP 1. | |
4180 | The words that the parser has marked as variable assignments (those | |
4181 | preceding the command name) and redirections are saved for later | |
4182 | processing. | |
4183 | .IP 2. | |
4184 | The words that are not variable assignments or redirections are | |
4185 | expanded. If any words remain after expansion, the first word | |
4186 | is taken to be the name of the command and the remaining words are | |
4187 | the arguments. | |
4188 | .IP 3. | |
4189 | Redirections are performed as described above under | |
4190 | .SM | |
4191 | .BR REDIRECTION . | |
4192 | .IP 4. | |
4193 | The text after the \fB=\fP in each variable assignment undergoes tilde | |
4194 | expansion, parameter expansion, command substitution, arithmetic expansion, | |
4195 | and quote removal before being assigned to the variable. | |
4196 | .PP | |
4197 | If no command name results, the variable assignments affect the current | |
4198 | shell environment. Otherwise, the variables are added to the environment | |
4199 | of the executed command and do not affect the current shell environment. | |
4200 | If any of the assignments attempts to assign a value to a readonly variable, | |
4201 | an error occurs, and the command exits with a non-zero status. | |
4202 | .PP | |
4203 | If no command name results, redirections are performed, but do not | |
4204 | affect the current shell environment. A redirection error causes the | |
4205 | command to exit with a non-zero status. | |
4206 | .PP | |
4207 | If there is a command name left after expansion, execution proceeds as | |
4208 | described below. Otherwise, the command exits. If one of the expansions | |
4209 | contained a command substitution, the exit status of the command is | |
4210 | the exit status of the last command substitution performed. If there | |
4211 | were no command substitutions, the command exits with a status of zero. | |
4212 | .SH "COMMAND EXECUTION" | |
4213 | After a command has been split into words, if it results in a | |
4214 | simple command and an optional list of arguments, the following | |
4215 | actions are taken. | |
4216 | .PP | |
4217 | If the command name contains no slashes, the shell attempts to | |
4218 | locate it. If there exists a shell function by that name, that | |
4219 | function is invoked as described above in | |
4220 | .SM | |
4221 | .BR FUNCTIONS . | |
4222 | If the name does not match a function, the shell searches for | |
4223 | it in the list of shell builtins. If a match is found, that | |
4224 | builtin is invoked. | |
4225 | .PP | |
4226 | If the name is neither a shell function nor a builtin, | |
4227 | and contains no slashes, | |
4228 | .B bash | |
4229 | searches each element of the | |
4230 | .SM | |
4231 | .B PATH | |
4232 | for a directory containing an executable file by that name. | |
4233 | .B Bash | |
bb70624e | 4234 | uses a hash table to remember the full pathnames of executable |
cce855bc JA |
4235 | files (see |
4236 | .B hash | |
4237 | under | |
4238 | .SM | |
4239 | .B "SHELL BUILTIN COMMANDS" | |
4240 | below). | |
4241 | A full search of the directories in | |
4242 | .SM | |
4243 | .B PATH | |
4244 | is performed only if the command is not found in the hash table. | |
245a493c CR |
4245 | If the search is unsuccessful, the shell searches for a defined shell |
4246 | function named \fBcommand_not_found_handle\fP. | |
4247 | If that function exists, it is invoked with the original command and | |
4248 | the original command's arguments as its arguments, and the function's | |
4249 | exit status becomes the exit status of the shell. | |
4250 | If that function is not defined, the shell prints an error | |
cce855bc JA |
4251 | message and returns an exit status of 127. |
4252 | .PP | |
4253 | If the search is successful, or if the command name contains | |
4254 | one or more slashes, the shell executes the named program in a | |
4255 | separate execution environment. | |
4256 | Argument 0 is set to the name given, and the remaining arguments | |
4257 | to the command are set to the arguments given, if any. | |
4258 | .PP | |
4259 | If this execution fails because the file is not in executable | |
4260 | format, and the file is not a directory, it is assumed to be | |
4261 | a \fIshell script\fP, a file | |
4262 | containing shell commands. A subshell is spawned to execute | |
4263 | it. This subshell reinitializes itself, so | |
4264 | that the effect is as if a new shell had been invoked | |
4265 | to handle the script, with the exception that the locations of | |
4266 | commands remembered by the parent (see | |
4267 | .B hash | |
4268 | below under | |
4269 | .SM | |
4270 | \fBSHELL BUILTIN COMMANDS\fP) | |
4271 | are retained by the child. | |
4272 | .PP | |
4273 | If the program is a file beginning with | |
4274 | .BR #! , | |
4275 | the remainder of the first line specifies an interpreter | |
4276 | for the program. The shell executes the | |
4277 | specified interpreter on operating systems that do not | |
4278 | handle this executable format themselves. The arguments to the | |
4279 | interpreter consist of a single optional argument following the | |
4280 | interpreter name on the first line of the program, followed | |
4281 | by the name of the program, followed by the command | |
4282 | arguments, if any. | |
4283 | .SH COMMAND EXECUTION ENVIRONMENT | |
4284 | The shell has an \fIexecution environment\fP, which consists of the | |
4285 | following: | |
cce855bc JA |
4286 | .IP \(bu |
4287 | open files inherited by the shell at invocation, as modified by | |
4288 | redirections supplied to the \fBexec\fP builtin | |
4289 | .IP \(bu | |
4290 | the current working directory as set by \fBcd\fP, \fBpushd\fP, or | |
4291 | \fBpopd\fP, or inherited by the shell at invocation | |
4292 | .IP \(bu | |
4293 | the file creation mode mask as set by \fBumask\fP or inherited from | |
4294 | the shell's parent | |
4295 | .IP \(bu | |
4296 | current traps set by \fBtrap\fP | |
4297 | .IP \(bu | |
4298 | shell parameters that are set by variable assignment or with \fBset\fP | |
4299 | or inherited from the shell's parent in the environment | |
4300 | .IP \(bu | |
4301 | shell functions defined during execution or inherited from the shell's | |
4302 | parent in the environment | |
4303 | .IP \(bu | |
4304 | options enabled at invocation (either by default or with command-line | |
4305 | arguments) or by \fBset\fP | |
4306 | .IP \(bu | |
4307 | options enabled by \fBshopt\fP | |
4308 | .IP \(bu | |
4309 | shell aliases defined with \fBalias\fP | |
4310 | .IP \(bu | |
4311 | various process IDs, including those of background jobs, the value | |
984a1947 CR |
4312 | of \fB$$\fP, and the value of |
4313 | .SM | |
4314 | .B PPID | |
cce855bc JA |
4315 | .PP |
4316 | When a simple command other than a builtin or shell function | |
4317 | is to be executed, it | |
4318 | is invoked in a separate execution environment that consists of | |
4319 | the following. Unless otherwise noted, the values are inherited | |
4320 | from the shell. | |
984a1947 | 4321 | .if n .sp 1 |
cce855bc JA |
4322 | .IP \(bu |
4323 | the shell's open files, plus any modifications and additions specified | |
4324 | by redirections to the command | |
4325 | .IP \(bu | |
4326 | the current working directory | |
4327 | .IP \(bu | |
4328 | the file creation mode mask | |
4329 | .IP \(bu | |
d3a24ed2 CR |
4330 | shell variables and functions marked for export, along with variables |
4331 | exported for the command, passed in the environment | |
cce855bc | 4332 | .IP \(bu |
d3a24ed2 CR |
4333 | traps caught by the shell are reset to the values inherited from the |
4334 | shell's parent, and traps ignored by the shell are ignored | |
cce855bc JA |
4335 | .PP |
4336 | A command invoked in this separate environment cannot affect the | |
4337 | shell's execution environment. | |
4338 | .PP | |
d3a24ed2 CR |
4339 | Command substitution, commands grouped with parentheses, |
4340 | and asynchronous commands are invoked in a | |
cce855bc JA |
4341 | subshell environment that is a duplicate of the shell environment, |
4342 | except that traps caught by the shell are reset to the values | |
4343 | that the shell inherited from its parent at invocation. Builtin | |
4344 | commands that are invoked as part of a pipeline are also executed in a | |
4345 | subshell environment. Changes made to the subshell environment | |
4346 | cannot affect the shell's execution environment. | |
f73dda09 | 4347 | .PP |
012bac39 | 4348 | Subshells spawned to execute command substitutions inherit the value of |
dc60d4e0 CR |
4349 | the \fB\-e\fP option from the parent shell. When not in \fIposix\fP mode, |
4350 | \fBbash\fP clears the \fB\-e\fP option in such subshells. | |
012bac39 | 4351 | .PP |
f73dda09 JA |
4352 | If a command is followed by a \fB&\fP and job control is not active, the |
4353 | default standard input for the command is the empty file \fI/dev/null\fP. | |
4354 | Otherwise, the invoked command inherits the file descriptors of the calling | |
4355 | shell as modified by redirections. | |
cce855bc JA |
4356 | .SH ENVIRONMENT |
4357 | When a program is invoked it is given an array of strings | |
4358 | called the | |
4359 | .IR environment . | |
4360 | This is a list of | |
4361 | \fIname\fP\-\fIvalue\fP pairs, of the form | |
4362 | .IR "name\fR=\fPvalue" . | |
4363 | .PP | |
bb70624e JA |
4364 | The shell provides several ways to manipulate the environment. |
4365 | On invocation, the shell scans its own environment and | |
cce855bc JA |
4366 | creates a parameter for each name found, automatically marking |
4367 | it for | |
4368 | .I export | |
4369 | to child processes. Executed commands inherit the environment. | |
4370 | The | |
4371 | .B export | |
4372 | and | |
4373 | .B declare \-x | |
4374 | commands allow parameters and functions to be added to and | |
4375 | deleted from the environment. If the value of a parameter | |
4376 | in the environment is modified, the new value becomes part | |
4377 | of the environment, replacing the old. The environment | |
4378 | inherited by any executed command consists of the shell's | |
4379 | initial environment, whose values may be modified in the shell, | |
4380 | less any pairs removed by the | |
4381 | .B unset | |
4382 | command, plus any additions via the | |
4383 | .B export | |
4384 | and | |
4385 | .B declare \-x | |
4386 | commands. | |
4387 | .PP | |
4388 | The environment for any | |
4389 | .I simple command | |
4390 | or function may be augmented temporarily by prefixing it with | |
4391 | parameter assignments, as described above in | |
4392 | .SM | |
4393 | .BR PARAMETERS . | |
4394 | These assignment statements affect only the environment seen | |
4395 | by that command. | |
4396 | .PP | |
4397 | If the | |
4398 | .B \-k | |
4399 | option is set (see the | |
4400 | .B set | |
4401 | builtin command below), then | |
4402 | .I all | |
4403 | parameter assignments are placed in the environment for a command, | |
4404 | not just those that precede the command name. | |
4405 | .PP | |
4406 | When | |
4407 | .B bash | |
4408 | invokes an external command, the variable | |
4409 | .B _ | |
b28ff8c9 | 4410 | is set to the full filename of the command and passed to that |
ccc6cda3 JA |
4411 | command in its environment. |
4412 | .SH "EXIT STATUS" | |
35ee8ea0 CR |
4413 | .PP |
4414 | The exit status of an executed command is the value returned by the | |
4415 | \fIwaitpid\fP system call or equivalent function. Exit statuses | |
4416 | fall between 0 and 255, though, as explained below, the shell may | |
4417 | use values above 125 specially. Exit statuses from shell builtins and | |
4418 | compound commands are also limited to this range. Under certain | |
4419 | circumstances, the shell will use special values to indicate specific | |
4420 | failure modes. | |
4421 | .PP | |
cce855bc | 4422 | For the shell's purposes, a command which exits with a |
ccc6cda3 JA |
4423 | zero exit status has succeeded. An exit status of zero |
4424 | indicates success. A non-zero exit status indicates failure. | |
bb70624e JA |
4425 | When a command terminates on a fatal signal \fIN\fP, \fBbash\fP uses |
4426 | the value of 128+\fIN\fP as the exit status. | |
ccc6cda3 JA |
4427 | .PP |
4428 | If a command is not found, the child process created to | |
4429 | execute it returns a status of 127. If a command is found | |
4430 | but is not executable, the return status is 126. | |
4431 | .PP | |
cce855bc JA |
4432 | If a command fails because of an error during expansion or redirection, |
4433 | the exit status is greater than zero. | |
4434 | .PP | |
ccc6cda3 JA |
4435 | Shell builtin commands return a status of 0 (\fItrue\fP) if |
4436 | successful, and non-zero (\fIfalse\fP) if an error occurs | |
4437 | while they execute. | |
4438 | All builtins return an exit status of 2 to indicate incorrect usage. | |
4439 | .PP | |
4440 | \fBBash\fP itself returns the exit status of the last command | |
4441 | executed, unless a syntax error occurs, in which case it exits | |
4442 | with a non-zero value. See also the \fBexit\fP builtin | |
4443 | command below. | |
4444 | .SH SIGNALS | |
cce855bc | 4445 | When \fBbash\fP is interactive, in the absence of any traps, it ignores |
ccc6cda3 JA |
4446 | .SM |
4447 | .B SIGTERM | |
4448 | (so that \fBkill 0\fP does not kill an interactive shell), | |
4449 | and | |
4450 | .SM | |
4451 | .B SIGINT | |
4452 | is caught and handled (so that the \fBwait\fP builtin is interruptible). | |
4453 | In all cases, \fBbash\fP ignores | |
4454 | .SM | |
4455 | .BR SIGQUIT . | |
4456 | If job control is in effect, | |
4457 | .B bash | |
4458 | ignores | |
4459 | .SM | |
4460 | .BR SIGTTIN , | |
4461 | .SM | |
4462 | .BR SIGTTOU , | |
4463 | and | |
4464 | .SM | |
4465 | .BR SIGTSTP . | |
4466 | .PP | |
5e13499c | 4467 | Non-builtin commands run by \fBbash\fP have signal handlers |
cce855bc JA |
4468 | set to the values inherited by the shell from its parent. |
4469 | When job control is not in effect, asynchronous commands | |
ccc6cda3 JA |
4470 | ignore |
4471 | .SM | |
4472 | .B SIGINT | |
4473 | and | |
4474 | .SM | |
cce855bc | 4475 | .B SIGQUIT |
5e13499c | 4476 | in addition to these inherited handlers. |
ccc6cda3 JA |
4477 | Commands run as a result of command substitution ignore the |
4478 | keyboard-generated job control signals | |
4479 | .SM | |
4480 | .BR SIGTTIN , | |
4481 | .SM | |
4482 | .BR SIGTTOU , | |
4483 | and | |
4484 | .SM | |
4485 | .BR SIGTSTP . | |
4486 | .PP | |
4487 | The shell exits by default upon receipt of a | |
4488 | .SM | |
4489 | .BR SIGHUP . | |
f73dda09 | 4490 | Before exiting, an interactive shell resends the |
ccc6cda3 JA |
4491 | .SM |
4492 | .B SIGHUP | |
cce855bc JA |
4493 | to all jobs, running or stopped. |
4494 | Stopped jobs are sent | |
4495 | .SM | |
4496 | .B SIGCONT | |
4497 | to ensure that they receive the | |
4498 | .SM | |
4499 | .BR SIGHUP . | |
4500 | To prevent the shell from | |
4501 | sending the signal to a particular job, it should be removed from the | |
ccc6cda3 JA |
4502 | jobs table with the |
4503 | .B disown | |
4504 | builtin (see | |
4505 | .SM | |
4506 | .B "SHELL BUILTIN COMMANDS" | |
cce855bc JA |
4507 | below) or marked |
4508 | to not receive | |
ccc6cda3 | 4509 | .SM |
cce855bc JA |
4510 | .B SIGHUP |
4511 | using | |
4512 | .BR "disown \-h" . | |
4513 | .PP | |
4514 | If the | |
4515 | .B huponexit | |
4516 | shell option has been set with | |
4517 | .BR shopt , | |
4518 | .B bash | |
4519 | sends a | |
4520 | .SM | |
4521 | .B SIGHUP | |
4522 | to all jobs when an interactive login shell exits. | |
4523 | .PP | |
b66cc816 | 4524 | If \fBbash\fP is waiting for a command to complete and receives a signal |
5e13499c CR |
4525 | for which a trap has been set, the trap will not be executed until |
4526 | the command completes. | |
cce855bc JA |
4527 | When \fBbash\fP is waiting for an asynchronous command via the \fBwait\fP |
4528 | builtin, the reception of a signal for which a trap has been set will | |
4529 | cause the \fBwait\fP builtin to return immediately with an exit status | |
4530 | greater than 128, immediately after which the trap is executed. | |
ccc6cda3 JA |
4531 | .SH "JOB CONTROL" |
4532 | .I Job control | |
4533 | refers to the ability to selectively stop (\fIsuspend\fP) | |
4534 | the execution of processes and continue (\fIresume\fP) | |
4535 | their execution at a later point. A user typically employs | |
4536 | this facility via an interactive interface supplied jointly | |
602bb739 | 4537 | by the operating system kernel's terminal driver and |
ccc6cda3 JA |
4538 | .BR bash . |
4539 | .PP | |
4540 | The shell associates a | |
4541 | .I job | |
4542 | with each pipeline. It keeps a table of currently executing | |
4543 | jobs, which may be listed with the | |
4544 | .B jobs | |
4545 | command. When | |
4546 | .B bash | |
4547 | starts a job asynchronously (in the | |
4548 | .IR background ), | |
4549 | it prints a line that looks like: | |
4550 | .RS | |
4551 | .PP | |
4552 | [1] 25647 | |
4553 | .RE | |
4554 | .PP | |
4555 | indicating that this job is job number 1 and that the process ID | |
4556 | of the last process in the pipeline associated with this job is 25647. | |
4557 | All of the processes in a single pipeline are members of the same job. | |
4558 | .B Bash | |
4559 | uses the | |
4560 | .I job | |
4561 | abstraction as the basis for job control. | |
4562 | .PP | |
4563 | To facilitate the implementation of the user interface to job | |
bb70624e | 4564 | control, the operating system maintains the notion of a \fIcurrent terminal |
ccc6cda3 JA |
4565 | process group ID\fP. Members of this process group (processes whose |
4566 | process group ID is equal to the current terminal process group ID) | |
4567 | receive keyboard-generated signals such as | |
4568 | .SM | |
4569 | .BR SIGINT . | |
4570 | These processes are said to be in the | |
4571 | .IR foreground . | |
4572 | .I Background | |
4573 | processes are those whose process group ID differs from the terminal's; | |
4574 | such processes are immune to keyboard-generated signals. | |
602bb739 CR |
4575 | Only foreground processes are allowed to read from or, if the |
4576 | user so specifies with \f(CWstty tostop\fP, write to the | |
4577 | terminal. | |
4578 | Background processes which attempt to read from (write to when | |
4579 | \f(CWstty tostop\fP is in effect) the | |
ccc6cda3 JA |
4580 | terminal are sent a |
4581 | .SM | |
4582 | .B SIGTTIN (SIGTTOU) | |
602bb739 | 4583 | signal by the kernel's terminal driver, |
ccc6cda3 JA |
4584 | which, unless caught, suspends the process. |
4585 | .PP | |
4586 | If the operating system on which | |
4587 | .B bash | |
4588 | is running supports | |
4589 | job control, | |
4590 | .B bash | |
bb70624e | 4591 | contains facilities to use it. |
ccc6cda3 JA |
4592 | Typing the |
4593 | .I suspend | |
4594 | character (typically | |
4595 | .BR ^Z , | |
4596 | Control-Z) while a process is running | |
bb70624e | 4597 | causes that process to be stopped and returns control to |
ccc6cda3 JA |
4598 | .BR bash . |
4599 | Typing the | |
4600 | .I "delayed suspend" | |
4601 | character (typically | |
4602 | .BR ^Y , | |
4603 | Control-Y) causes the process to be stopped when it | |
4604 | attempts to read input from the terminal, and control to | |
4605 | be returned to | |
4606 | .BR bash . | |
cce855bc | 4607 | The user may then manipulate the state of this job, using the |
ccc6cda3 JA |
4608 | .B bg |
4609 | command to continue it in the background, the | |
4610 | .B fg | |
4611 | command to continue it in the foreground, or | |
4612 | the | |
4613 | .B kill | |
4614 | command to kill it. A \fB^Z\fP takes effect immediately, | |
4615 | and has the additional side effect of causing pending output | |
4616 | and typeahead to be discarded. | |
4617 | .PP | |
4618 | There are a number of ways to refer to a job in the shell. | |
4619 | The character | |
4620 | .B % | |
8e1a6eaa | 4621 | introduces a job specification (\fIjobspec\fP). Job number |
ccc6cda3 JA |
4622 | .I n |
4623 | may be referred to as | |
4624 | .BR %n . | |
4625 | A job may also be referred to using a prefix of the name used to | |
4626 | start it, or using a substring that appears in its command line. | |
4627 | For example, | |
4628 | .B %ce | |
4629 | refers to a stopped | |
4630 | .B ce | |
4631 | job. If a prefix matches more than one job, | |
4632 | .B bash | |
4633 | reports an error. Using | |
4634 | .BR %?ce , | |
4635 | on the other hand, refers to any job containing the string | |
4636 | .B ce | |
4637 | in its command line. If the substring matches more than one job, | |
4638 | .B bash | |
4639 | reports an error. The symbols | |
4640 | .B %% | |
4641 | and | |
4642 | .B %+ | |
4643 | refer to the shell's notion of the | |
4644 | .IR "current job" , | |
4645 | which is the last job stopped while it was in | |
cce855bc | 4646 | the foreground or started in the background. |
ccc6cda3 JA |
4647 | The |
4648 | .I "previous job" | |
4649 | may be referenced using | |
4650 | .BR %\- . | |
e33f2203 CR |
4651 | If there is only a single job, \fB%+\fP and \fB%\-\fP can both be used |
4652 | to refer to that job. | |
ccc6cda3 JA |
4653 | In output pertaining to jobs (e.g., the output of the |
4654 | .B jobs | |
4655 | command), the current job is always flagged with a | |
4656 | .BR + , | |
4657 | and the previous job with a | |
4658 | .BR \- . | |
43df7bbb CR |
4659 | A single % (with no accompanying job specification) also refers to the |
4660 | current job. | |
726f6388 | 4661 | .PP |
ccc6cda3 JA |
4662 | Simply naming a job can be used to bring it into the |
4663 | foreground: | |
4664 | .B %1 | |
4665 | is a synonym for | |
4666 | \fB``fg %1''\fP, | |
4667 | bringing job 1 from the background into the foreground. | |
4668 | Similarly, | |
4669 | .B ``%1 &'' | |
4670 | resumes job 1 in the background, equivalent to | |
4671 | \fB``bg %1''\fP. | |
726f6388 | 4672 | .PP |
ccc6cda3 JA |
4673 | The shell learns immediately whenever a job changes state. |
4674 | Normally, | |
4675 | .B bash | |
4676 | waits until it is about to print a prompt before reporting | |
4677 | changes in a job's status so as to not interrupt | |
4678 | any other output. If the | |
4679 | .B \-b | |
4680 | option to the | |
726f6388 | 4681 | .B set |
ccc6cda3 | 4682 | builtin command |
cce855bc | 4683 | is enabled, |
726f6388 | 4684 | .B bash |
ccc6cda3 | 4685 | reports such changes immediately. |
f73dda09 JA |
4686 | Any trap on |
4687 | .SM | |
4688 | .B SIGCHLD | |
4689 | is executed for each child that exits. | |
726f6388 | 4690 | .PP |
ccc6cda3 JA |
4691 | If an attempt to exit |
4692 | .B bash | |
d3ad40de CR |
4693 | is made while jobs are stopped (or, if the \fBcheckjobs\fP shell option has |
4694 | been enabled using the \fBshopt\fP builtin, running), the shell prints a | |
4695 | warning message, and, if the \fBcheckjobs\fP option is enabled, lists the | |
4696 | jobs and their statuses. | |
4697 | The | |
ccc6cda3 | 4698 | .B jobs |
d3ad40de | 4699 | command may then be used to inspect their status. |
ccc6cda3 | 4700 | If a second attempt to exit is made without an intervening command, |
d3ad40de | 4701 | the shell does not print another warning, and any stopped |
ccc6cda3 | 4702 | jobs are terminated. |
726f6388 JA |
4703 | .SH PROMPTING |
4704 | When executing interactively, | |
4705 | .B bash | |
4706 | displays the primary prompt | |
4707 | .SM | |
4708 | .B PS1 | |
4709 | when it is ready to read a command, and the secondary prompt | |
4710 | .SM | |
4711 | .B PS2 | |
4712 | when it needs more input to complete a command. | |
4713 | .B Bash | |
4714 | allows these prompt strings to be customized by inserting a number of | |
4715 | backslash-escaped special characters that are decoded as follows: | |
4716 | .RS | |
4717 | .PD 0 | |
4718 | .TP | |
ccc6cda3 JA |
4719 | .B \ea |
4720 | an ASCII bell character (07) | |
726f6388 JA |
4721 | .TP |
4722 | .B \ed | |
4723 | the date in "Weekday Month Date" format (e.g., "Tue May 26") | |
4724 | .TP | |
7117c2d2 JA |
4725 | .B \eD{\fIformat\fP} |
4726 | the \fIformat\fP is passed to \fIstrftime\fP(3) and the result is inserted | |
4727 | into the prompt string; an empty \fIformat\fP results in a locale-specific | |
4728 | time representation. The braces are required | |
4729 | .TP | |
ccc6cda3 JA |
4730 | .B \ee |
4731 | an ASCII escape character (033) | |
4732 | .TP | |
4733 | .B \eh | |
4734 | the hostname up to the first `.' | |
4735 | .TP | |
4736 | .B \eH | |
4737 | the hostname | |
4738 | .TP | |
bb70624e JA |
4739 | .B \ej |
4740 | the number of jobs currently managed by the shell | |
4741 | .TP | |
4742 | .B \el | |
4743 | the basename of the shell's terminal device name | |
4744 | .TP | |
726f6388 JA |
4745 | .B \en |
4746 | newline | |
4747 | .TP | |
cce855bc JA |
4748 | .B \er |
4749 | carriage return | |
4750 | .TP | |
726f6388 JA |
4751 | .B \es |
4752 | the name of the shell, the basename of | |
4753 | .B $0 | |
4754 | (the portion following the final slash) | |
4755 | .TP | |
ccc6cda3 JA |
4756 | .B \et |
4757 | the current time in 24-hour HH:MM:SS format | |
726f6388 | 4758 | .TP |
ccc6cda3 JA |
4759 | .B \eT |
4760 | the current time in 12-hour HH:MM:SS format | |
4761 | .TP | |
4762 | .B \e@ | |
4763 | the current time in 12-hour am/pm format | |
726f6388 | 4764 | .TP |
f73dda09 JA |
4765 | .B \eA |
4766 | the current time in 24-hour HH:MM format | |
4767 | .TP | |
726f6388 JA |
4768 | .B \eu |
4769 | the username of the current user | |
4770 | .TP | |
ccc6cda3 JA |
4771 | .B \ev |
4772 | the version of \fBbash\fP (e.g., 2.00) | |
726f6388 | 4773 | .TP |
ccc6cda3 | 4774 | .B \eV |
a5e25162 | 4775 | the release of \fBbash\fP, version + patch level (e.g., 2.00.0) |
ccc6cda3 JA |
4776 | .TP |
4777 | .B \ew | |
984a1947 CR |
4778 | the current working directory, with |
4779 | .SM | |
4780 | .B $HOME | |
4781 | abbreviated with a tilde | |
4782 | (uses the value of the | |
4783 | .SM | |
4784 | .B PROMPT_DIRTRIM | |
4785 | variable) | |
ccc6cda3 JA |
4786 | .TP |
4787 | .B \eW | |
984a1947 CR |
4788 | the basename of the current working directory, with |
4789 | .SM | |
4790 | .B $HOME | |
12d937f9 | 4791 | abbreviated with a tilde |
726f6388 JA |
4792 | .TP |
4793 | .B \e! | |
4794 | the history number of this command | |
4795 | .TP | |
ccc6cda3 JA |
4796 | .B \e# |
4797 | the command number of this command | |
4798 | .TP | |
726f6388 JA |
4799 | .B \e$ |
4800 | if the effective UID is 0, a | |
4801 | .BR # , | |
4802 | otherwise a | |
4803 | .B $ | |
4804 | .TP | |
ccc6cda3 JA |
4805 | .B \e\fInnn\fP |
4806 | the character corresponding to the octal number \fInnn\fP | |
726f6388 JA |
4807 | .TP |
4808 | .B \e\e | |
4809 | a backslash | |
4810 | .TP | |
4811 | .B \e[ | |
4812 | begin a sequence of non-printing characters, which could be used to | |
4813 | embed a terminal control sequence into the prompt | |
4814 | .TP | |
4815 | .B \e] | |
4816 | end a sequence of non-printing characters | |
4817 | .PD | |
4818 | .RE | |
4819 | .PP | |
4820 | The command number and the history number are usually different: | |
4821 | the history number of a command is its position in the history | |
4822 | list, which may include commands restored from the history file | |
4823 | (see | |
4824 | .SM | |
4825 | .B HISTORY | |
4826 | below), while the command number is the position in the sequence | |
4827 | of commands executed during the current shell session. | |
4828 | After the string is decoded, it is expanded via | |
bb70624e JA |
4829 | parameter expansion, command substitution, arithmetic |
4830 | expansion, and quote removal, subject to the value of the | |
ccc6cda3 JA |
4831 | .B promptvars |
4832 | shell option (see the description of the | |
4833 | .B shopt | |
4834 | command under | |
4835 | .SM | |
4836 | .B "SHELL BUILTIN COMMANDS" | |
4837 | below). | |
726f6388 JA |
4838 | .SH READLINE |
4839 | This is the library that handles reading input when using an interactive | |
4840 | shell, unless the | |
d166f048 | 4841 | .B \-\-noediting |
ccc6cda3 | 4842 | option is given at shell invocation. |
14e8b2a7 CR |
4843 | Line editing is also used when using the \fB\-e\fP option to the |
4844 | \fBread\fP builtin. | |
dc60d4e0 | 4845 | By default, the line editing commands are similar to those of Emacs. |
726f6388 | 4846 | A vi-style line editing interface is also available. |
14e8b2a7 CR |
4847 | Line editing can be enabled at any time using the |
4848 | .B \-o emacs | |
ccc6cda3 | 4849 | or |
14e8b2a7 | 4850 | .B \-o vi |
ccc6cda3 JA |
4851 | options to the |
4852 | .B set | |
4853 | builtin (see | |
4854 | .SM | |
4855 | .B SHELL BUILTIN COMMANDS | |
4856 | below). | |
14e8b2a7 CR |
4857 | To turn off line editing after the shell is running, use the |
4858 | .B +o emacs | |
4859 | or | |
4860 | .B +o vi | |
4861 | options to the | |
4862 | .B set | |
4863 | builtin. | |
ccc6cda3 | 4864 | .SS "Readline Notation" |
726f6388 | 4865 | .PP |
dc60d4e0 | 4866 | In this section, the Emacs-style notation is used to denote |
726f6388 JA |
4867 | keystrokes. Control keys are denoted by C\-\fIkey\fR, e.g., C\-n |
4868 | means Control\-N. Similarly, | |
4869 | .I meta | |
4870 | keys are denoted by M\-\fIkey\fR, so M\-x means Meta\-X. (On keyboards | |
4871 | without a | |
4872 | .I meta | |
4873 | key, M\-\fIx\fP means ESC \fIx\fP, i.e., press the Escape key | |
4874 | then the | |
4875 | .I x | |
4876 | key. This makes ESC the \fImeta prefix\fP. | |
4877 | The combination M\-C\-\fIx\fP means ESC\-Control\-\fIx\fP, | |
4878 | or press the Escape key | |
4879 | then hold the Control key while pressing the | |
4880 | .I x | |
4881 | key.) | |
4882 | .PP | |
ccc6cda3 JA |
4883 | Readline commands may be given numeric |
4884 | .IR arguments , | |
4885 | which normally act as a repeat count. | |
4886 | Sometimes, however, it is the sign of the argument that is significant. | |
4887 | Passing a negative argument to a command that acts in the forward | |
4888 | direction (e.g., \fBkill\-line\fP) causes that command to act in a | |
4889 | backward direction. | |
4890 | Commands whose behavior with arguments deviates from this are noted | |
4891 | below. | |
4892 | .PP | |
4893 | When a command is described as \fIkilling\fP text, the text | |
4894 | deleted is saved for possible future retrieval | |
4895 | (\fIyanking\fP). The killed text is saved in a | |
4896 | \fIkill ring\fP. Consecutive kills cause the text to be | |
4897 | accumulated into one unit, which can be yanked all at once. | |
4898 | Commands which do not kill text separate the chunks of text | |
4899 | on the kill ring. | |
4900 | .SS "Readline Initialization" | |
4901 | .PP | |
4902 | Readline is customized by putting commands in an initialization | |
4903 | file (the \fIinputrc\fP file). | |
4904 | The name of this file is taken from the value of the | |
726f6388 | 4905 | .SM |
ccc6cda3 JA |
4906 | .B INPUTRC |
4907 | variable. If that variable is unset, the default is | |
726f6388 | 4908 | .IR ~/.inputrc . |
ccc6cda3 JA |
4909 | When a program which uses the readline library starts up, the |
4910 | initialization file is read, and the key bindings and variables | |
4911 | are set. | |
4912 | There are only a few basic constructs allowed in the | |
4913 | readline initialization file. | |
4914 | Blank lines are ignored. | |
4915 | Lines beginning with a \fB#\fP are comments. | |
4916 | Lines beginning with a \fB$\fP indicate conditional constructs. | |
4917 | Other lines denote key bindings and variable settings. | |
4918 | .PP | |
4919 | The default key-bindings may be changed with an | |
4920 | .I inputrc | |
4921 | file. | |
726f6388 JA |
4922 | Other programs that use this library may add their own commands |
4923 | and bindings. | |
4924 | .PP | |
4925 | For example, placing | |
4926 | .RS | |
4927 | .PP | |
4928 | M\-Control\-u: universal\-argument | |
4929 | .RE | |
4930 | or | |
4931 | .RS | |
4932 | C\-Meta\-u: universal\-argument | |
4933 | .RE | |
4934 | into the | |
ccc6cda3 | 4935 | .I inputrc |
726f6388 JA |
4936 | would make M\-C\-u execute the readline command |
4937 | .IR universal\-argument . | |
4938 | .PP | |
4939 | The following symbolic character names are recognized: | |
4940 | .IR RUBOUT , | |
4941 | .IR DEL , | |
4942 | .IR ESC , | |
4943 | .IR LFD , | |
4944 | .IR NEWLINE , | |
4945 | .IR RET , | |
4946 | .IR RETURN , | |
4947 | .IR SPC , | |
4948 | .IR SPACE , | |
4949 | and | |
4950 | .IR TAB . | |
bb70624e | 4951 | .PP |
726f6388 JA |
4952 | In addition to command names, readline allows keys to be bound |
4953 | to a string that is inserted when the key is pressed (a \fImacro\fP). | |
ccc6cda3 | 4954 | .SS "Readline Key Bindings" |
726f6388 JA |
4955 | .PP |
4956 | The syntax for controlling key bindings in the | |
cce855bc | 4957 | .I inputrc |
726f6388 JA |
4958 | file is simple. All that is required is the name of the |
4959 | command or the text of a macro and a key sequence to which | |
4960 | it should be bound. The name may be specified in one of two ways: | |
ccc6cda3 | 4961 | as a symbolic key name, possibly with \fIMeta\-\fP or \fIControl\-\fP |
726f6388 | 4962 | prefixes, or as a key sequence. |
28ef6c31 | 4963 | .PP |
cce855bc | 4964 | When using the form \fBkeyname\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4965 | .I keyname |
4966 | is the name of a key spelled out in English. For example: | |
4967 | .sp | |
4968 | .RS | |
4969 | Control-u: universal\-argument | |
4970 | .br | |
4971 | Meta-Rubout: backward-kill-word | |
4972 | .br | |
ccc6cda3 | 4973 | Control-o: "> output" |
726f6388 JA |
4974 | .RE |
4975 | .LP | |
4976 | In the above example, | |
ccc6cda3 | 4977 | .I C\-u |
726f6388 JA |
4978 | is bound to the function |
4979 | .BR universal\-argument , | |
ccc6cda3 | 4980 | .I M\-DEL |
726f6388 JA |
4981 | is bound to the function |
4982 | .BR backward\-kill\-word , | |
4983 | and | |
ccc6cda3 | 4984 | .I C\-o |
726f6388 JA |
4985 | is bound to run the macro |
4986 | expressed on the right hand side (that is, to insert the text | |
28ef6c31 JA |
4987 | .if t \f(CW> output\fP |
4988 | .if n ``> output'' | |
726f6388 JA |
4989 | into the line). |
4990 | .PP | |
cce855bc | 4991 | In the second form, \fB"keyseq"\fP:\^\fIfunction\-name\fP or \fImacro\fP, |
726f6388 JA |
4992 | .B keyseq |
4993 | differs from | |
4994 | .B keyname | |
4995 | above in that strings denoting | |
4996 | an entire key sequence may be specified by placing the sequence | |
4997 | within double quotes. Some GNU Emacs style key escapes can be | |
28ef6c31 JA |
4998 | used, as in the following example, but the symbolic character names |
4999 | are not recognized. | |
726f6388 JA |
5000 | .sp |
5001 | .RS | |
ccc6cda3 | 5002 | "\eC\-u": universal\-argument |
726f6388 | 5003 | .br |
ccc6cda3 | 5004 | "\eC\-x\eC\-r": re\-read\-init\-file |
726f6388 JA |
5005 | .br |
5006 | "\ee[11~": "Function Key 1" | |
5007 | .RE | |
5008 | .PP | |
5009 | In this example, | |
ccc6cda3 | 5010 | .I C\-u |
726f6388 JA |
5011 | is again bound to the function |
5012 | .BR universal\-argument . | |
ccc6cda3 | 5013 | .I "C\-x C\-r" |
726f6388 JA |
5014 | is bound to the function |
5015 | .BR re\-read\-init\-file , | |
5016 | and | |
5017 | .I "ESC [ 1 1 ~" | |
5018 | is bound to insert the text | |
28ef6c31 JA |
5019 | .if t \f(CWFunction Key 1\fP. |
5020 | .if n ``Function Key 1''. | |
5021 | .PP | |
cce855bc | 5022 | The full set of GNU Emacs style escape sequences is |
726f6388 | 5023 | .RS |
cce855bc | 5024 | .PD 0 |
726f6388 JA |
5025 | .TP |
5026 | .B \eC\- | |
5027 | control prefix | |
5028 | .TP | |
ccc6cda3 | 5029 | .B \eM\- |
726f6388 JA |
5030 | meta prefix |
5031 | .TP | |
5032 | .B \ee | |
5033 | an escape character | |
5034 | .TP | |
5035 | .B \e\e | |
5036 | backslash | |
5037 | .TP | |
5038 | .B \e" | |
5039 | literal " | |
5040 | .TP | |
20587658 CR |
5041 | .B \e\(aq |
5042 | literal \(aq | |
726f6388 | 5043 | .RE |
cce855bc JA |
5044 | .PD |
5045 | .PP | |
5046 | In addition to the GNU Emacs style escape sequences, a second | |
5047 | set of backslash escapes is available: | |
5048 | .RS | |
5049 | .PD 0 | |
5050 | .TP | |
5051 | .B \ea | |
5052 | alert (bell) | |
5053 | .TP | |
5054 | .B \eb | |
5055 | backspace | |
5056 | .TP | |
5057 | .B \ed | |
5058 | delete | |
5059 | .TP | |
5060 | .B \ef | |
5061 | form feed | |
5062 | .TP | |
5063 | .B \en | |
5064 | newline | |
5065 | .TP | |
5066 | .B \er | |
5067 | carriage return | |
5068 | .TP | |
5069 | .B \et | |
5070 | horizontal tab | |
5071 | .TP | |
5072 | .B \ev | |
5073 | vertical tab | |
5074 | .TP | |
5075 | .B \e\fInnn\fP | |
f73dda09 | 5076 | the eight-bit character whose value is the octal value \fInnn\fP |
cce855bc JA |
5077 | (one to three digits) |
5078 | .TP | |
f73dda09 JA |
5079 | .B \ex\fIHH\fP |
5080 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
5081 | (one or two hex digits) | |
cce855bc JA |
5082 | .RE |
5083 | .PD | |
726f6388 | 5084 | .PP |
cce855bc JA |
5085 | When entering the text of a macro, single or double quotes must |
5086 | be used to indicate a macro definition. | |
5087 | Unquoted text is assumed to be a function name. | |
5088 | In the macro body, the backslash escapes described above are expanded. | |
5089 | Backslash will quote any other character in the macro text, | |
20587658 | 5090 | including " and \(aq. |
726f6388 JA |
5091 | .PP |
5092 | .B Bash | |
5093 | allows the current readline key bindings to be displayed or modified | |
5094 | with the | |
5095 | .B bind | |
5096 | builtin command. The editing mode may be switched during interactive | |
5097 | use by using the | |
5098 | .B \-o | |
5099 | option to the | |
5100 | .B set | |
5101 | builtin command (see | |
5102 | .SM | |
5103 | .B SHELL BUILTIN COMMANDS | |
5104 | below). | |
ccc6cda3 | 5105 | .SS "Readline Variables" |
726f6388 JA |
5106 | .PP |
5107 | Readline has variables that can be used to further customize its | |
5108 | behavior. A variable may be set in the | |
5109 | .I inputrc | |
5110 | file with a statement of the form | |
5111 | .RS | |
5112 | .PP | |
5113 | \fBset\fP \fIvariable\-name\fP \fIvalue\fP | |
5114 | .RE | |
5115 | .PP | |
5116 | Except where noted, readline variables can take the values | |
5117 | .B On | |
5118 | or | |
ff247e74 CR |
5119 | .B Off |
5120 | (without regard to case). | |
5121 | Unrecognized variable names are ignored. | |
5122 | When a variable value is read, empty or null values, "on" (case-insensitive), | |
5123 | and "1" are equivalent to \fBOn\fP. All other values are equivalent to | |
5124 | \fBOff\fP. | |
726f6388 JA |
5125 | The variables and their default values are: |
5126 | .PP | |
5127 | .PD 0 | |
5128 | .TP | |
726f6388 JA |
5129 | .B bell\-style (audible) |
5130 | Controls what happens when readline wants to ring the terminal bell. | |
5131 | If set to \fBnone\fP, readline never rings the bell. If set to | |
5132 | \fBvisible\fP, readline uses a visible bell if one is available. | |
5133 | If set to \fBaudible\fP, readline attempts to ring the terminal's bell. | |
5134 | .TP | |
453f278a CR |
5135 | .B bind\-tty\-special\-chars (On) |
5136 | If set to \fBOn\fP, readline attempts to bind the control characters | |
5137 | treated specially by the kernel's terminal driver to their readline | |
5138 | equivalents. | |
5139 | .TP | |
726f6388 | 5140 | .B comment\-begin (``#'') |
bb70624e | 5141 | The string that is inserted when the readline |
ccc6cda3 | 5142 | .B insert\-comment |
726f6388 | 5143 | command is executed. |
ccc6cda3 JA |
5144 | This command is bound to |
5145 | .B M\-# | |
5146 | in emacs mode and to | |
5147 | .B # | |
5148 | in vi command mode. | |
726f6388 | 5149 | .TP |
cce855bc JA |
5150 | .B completion\-ignore\-case (Off) |
5151 | If set to \fBOn\fP, readline performs filename matching and completion | |
5152 | in a case\-insensitive fashion. | |
5153 | .TP | |
f13513ff CR |
5154 | .B completion\-prefix\-display\-length (0) |
5155 | The length in characters of the common prefix of a list of possible | |
5156 | completions that is displayed without modification. When set to a | |
5157 | value greater than zero, common prefixes longer than this value are | |
5158 | replaced with an ellipsis when displaying possible completions. | |
5159 | .TP | |
726f6388 JA |
5160 | .B completion\-query\-items (100) |
5161 | This determines when the user is queried about viewing | |
5162 | the number of possible completions | |
5163 | generated by the \fBpossible\-completions\fP command. | |
5164 | It may be set to any integer value greater than or equal to | |
5165 | zero. If the number of possible completions is greater than | |
5166 | or equal to the value of this variable, the user is asked whether | |
5167 | or not he wishes to view them; otherwise they are simply listed | |
5168 | on the terminal. | |
5169 | .TP | |
ccc6cda3 JA |
5170 | .B convert\-meta (On) |
5171 | If set to \fBOn\fP, readline will convert characters with the | |
5172 | eighth bit set to an ASCII key sequence | |
bb70624e | 5173 | by stripping the eighth bit and prefixing an |
ccc6cda3 JA |
5174 | escape character (in effect, using escape as the \fImeta prefix\fP). |
5175 | .TP | |
5176 | .B disable\-completion (Off) | |
5177 | If set to \fBOn\fP, readline will inhibit word completion. Completion | |
5178 | characters will be inserted into the line as if they had been | |
5179 | mapped to \fBself-insert\fP. | |
5180 | .TP | |
5181 | .B editing\-mode (emacs) | |
5182 | Controls whether readline begins with a set of key bindings similar | |
dc60d4e0 | 5183 | to \fIEmacs\fP or \fIvi\fP. |
ccc6cda3 JA |
5184 | .B editing\-mode |
5185 | can be set to either | |
5186 | .B emacs | |
5187 | or | |
5188 | .BR vi . | |
5189 | .TP | |
824dfe68 CR |
5190 | .B echo\-control\-characters (On) |
5191 | When set to \fBOn\fP, on operating systems that indicate they support it, | |
5192 | readline echoes a character corresponding to a signal generated from the | |
5193 | keyboard. | |
5194 | .TP | |
ccc6cda3 JA |
5195 | .B enable\-keypad (Off) |
5196 | When set to \fBOn\fP, readline will try to enable the application | |
5197 | keypad when it is called. Some systems need this to enable the | |
5198 | arrow keys. | |
5199 | .TP | |
08e72d7a CR |
5200 | .B enable\-meta\-key (On) |
5201 | When set to \fBOn\fP, readline will try to enable any meta modifier | |
5202 | key the terminal claims to support when it is called. On many terminals, | |
5203 | the meta key is used to send eight-bit characters. | |
5204 | .TP | |
ccc6cda3 | 5205 | .B expand\-tilde (Off) |
dc60d4e0 | 5206 | If set to \fBOn\fP, tilde expansion is performed when readline |
ccc6cda3 JA |
5207 | attempts word completion. |
5208 | .TP | |
cdb32d45 | 5209 | .B history\-preserve\-point (Off) |
dc60d4e0 | 5210 | If set to \fBOn\fP, the history code attempts to place point at the |
f75912ae | 5211 | same location on each history line retrieved with \fBprevious-history\fP |
f73dda09 JA |
5212 | or \fBnext-history\fP. |
5213 | .TP | |
1d0e1a34 CR |
5214 | .B history\-size (0) |
5215 | Set the maximum number of history entries saved in the history list. If | |
5216 | set to zero, the number of entries in the history list is not limited. | |
5217 | .TP | |
ccc6cda3 JA |
5218 | .B horizontal\-scroll\-mode (Off) |
5219 | When set to \fBOn\fP, makes readline use a single line for display, | |
5220 | scrolling the input horizontally on a single screen line when it | |
5221 | becomes longer than the screen width rather than wrapping to a new line. | |
5222 | .TP | |
5223 | .B input\-meta (Off) | |
5224 | If set to \fBOn\fP, readline will enable eight-bit input (that is, | |
5225 | it will not strip the high bit from the characters it reads), | |
5226 | regardless of what the terminal claims it can support. The name | |
5227 | .B meta\-flag | |
5228 | is a synonym for this variable. | |
5229 | .TP | |
b72432fd JA |
5230 | .B isearch\-terminators (``C\-[C\-J'') |
5231 | The string of characters that should terminate an incremental | |
5232 | search without subsequently executing the character as a command. | |
5233 | If this variable has not been given a value, the characters | |
5234 | \fIESC\fP and \fIC\-J\fP will terminate an incremental search. | |
5235 | .TP | |
726f6388 | 5236 | .B keymap (emacs) |
cce855bc | 5237 | Set the current readline keymap. The set of valid keymap names is |
ccc6cda3 JA |
5238 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
5239 | vi\-command\fP, and | |
5240 | .IR vi\-insert . | |
5241 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
5242 | equivalent to \fIemacs\-standard\fP. The default value is | |
726f6388 JA |
5243 | .IR emacs ; |
5244 | the value of | |
5245 | .B editing\-mode | |
5246 | also affects the default keymap. | |
5247 | .TP | |
ccc6cda3 JA |
5248 | .B mark\-directories (On) |
5249 | If set to \fBOn\fP, completed directory names have a slash | |
5250 | appended. | |
5251 | .TP | |
5252 | .B mark\-modified\-lines (Off) | |
5253 | If set to \fBOn\fP, history lines that have been modified are displayed | |
5254 | with a preceding asterisk (\fB*\fP). | |
5255 | .TP | |
7117c2d2 JA |
5256 | .B mark\-symlinked\-directories (Off) |
5257 | If set to \fBOn\fP, completed names which are symbolic links to directories | |
5258 | have a slash appended (subject to the value of | |
5259 | \fBmark\-directories\fP). | |
5260 | .TP | |
f73dda09 JA |
5261 | .B match\-hidden\-files (On) |
5262 | This variable, when set to \fBOn\fP, causes readline to match files whose | |
5263 | names begin with a `.' (hidden files) when performing filename | |
112ff2a6 CR |
5264 | completion. |
5265 | If set to \fBOff\fP, the leading `.' must be | |
f73dda09 JA |
5266 | supplied by the user in the filename to be completed. |
5267 | .TP | |
d7c725b5 CR |
5268 | .B menu\-complete\-display\-prefix (Off) |
5269 | If set to \fBOn\fP, menu completion displays the common prefix of the | |
5270 | list of possible completions (which may be empty) before cycling through | |
5271 | the list. | |
5272 | .TP | |
ccc6cda3 JA |
5273 | .B output\-meta (Off) |
5274 | If set to \fBOn\fP, readline will display characters with the | |
5275 | eighth bit set directly rather than as a meta-prefixed escape | |
5276 | sequence. | |
5277 | .TP | |
7117c2d2 JA |
5278 | .B page\-completions (On) |
5279 | If set to \fBOn\fP, readline uses an internal \fImore\fP-like pager | |
5280 | to display a screenful of possible completions at a time. | |
5281 | .TP | |
cce855bc JA |
5282 | .B print\-completions\-horizontally (Off) |
5283 | If set to \fBOn\fP, readline will display completions with matches | |
5284 | sorted horizontally in alphabetical order, rather than down the screen. | |
f13513ff CR |
5285 | .TP |
5286 | .B revert\-all\-at\-newline (Off) | |
dc60d4e0 | 5287 | If set to \fBOn\fP, readline will undo all changes to history lines |
f13513ff CR |
5288 | before returning when \fBaccept\-line\fP is executed. By default, |
5289 | history lines may be modified and retain individual undo lists across | |
5290 | calls to \fBreadline\fP. | |
cce855bc | 5291 | .TP |
726f6388 JA |
5292 | .B show\-all\-if\-ambiguous (Off) |
5293 | This alters the default behavior of the completion functions. If | |
5294 | set to | |
dc60d4e0 | 5295 | .BR On , |
726f6388 JA |
5296 | words which have more than one possible completion cause the |
5297 | matches to be listed immediately instead of ringing the bell. | |
5298 | .TP | |
d3a24ed2 CR |
5299 | .B show\-all\-if\-unmodified (Off) |
5300 | This alters the default behavior of the completion functions in | |
5301 | a fashion similar to \fBshow\-all\-if\-ambiguous\fP. | |
5302 | If set to | |
dc60d4e0 | 5303 | .BR On , |
d3a24ed2 CR |
5304 | words which have more than one possible completion without any |
5305 | possible partial completion (the possible completions don't share | |
5306 | a common prefix) cause the matches to be listed immediately instead | |
5307 | of ringing the bell. | |
5308 | .TP | |
8f714a7c CR |
5309 | .B skip\-completed\-text (Off) |
5310 | If set to \fBOn\fP, this alters the default completion behavior when | |
5311 | inserting a single match into the line. It's only active when | |
5312 | performing completion in the middle of a word. If enabled, readline | |
5313 | does not insert characters from the completion that match characters | |
5314 | after point in the word being completed, so portions of the word | |
5315 | following the cursor are not duplicated. | |
5316 | .TP | |
ccc6cda3 JA |
5317 | .B visible\-stats (Off) |
5318 | If set to \fBOn\fP, a character denoting a file's type as reported | |
5319 | by \fIstat\fP(2) is appended to the filename when listing possible | |
5320 | completions. | |
726f6388 | 5321 | .PD |
ccc6cda3 | 5322 | .SS "Readline Conditional Constructs" |
726f6388 JA |
5323 | .PP |
5324 | Readline implements a facility similar in spirit to the conditional | |
5325 | compilation features of the C preprocessor which allows key | |
5326 | bindings and variable settings to be performed as the result | |
cce855bc | 5327 | of tests. There are four parser directives used. |
726f6388 JA |
5328 | .IP \fB$if\fP |
5329 | The | |
5330 | .B $if | |
5331 | construct allows bindings to be made based on the | |
5332 | editing mode, the terminal being used, or the application using | |
5333 | readline. The text of the test extends to the end of the line; | |
5334 | no characters are required to isolate it. | |
5335 | .RS | |
5336 | .IP \fBmode\fP | |
5337 | The \fBmode=\fP form of the \fB$if\fP directive is used to test | |
5338 | whether readline is in emacs or vi mode. | |
5339 | This may be used in conjunction | |
5340 | with the \fBset keymap\fP command, for instance, to set bindings in | |
ccc6cda3 | 5341 | the \fIemacs\-standard\fP and \fIemacs\-ctlx\fP keymaps only if |
726f6388 JA |
5342 | readline is starting out in emacs mode. |
5343 | .IP \fBterm\fP | |
5344 | The \fBterm=\fP form may be used to include terminal-specific | |
5345 | key bindings, perhaps to bind the key sequences output by the | |
5346 | terminal's function keys. The word on the right side of the | |
5347 | .B = | |
cce855bc | 5348 | is tested against the both full name of the terminal and the portion |
726f6388 JA |
5349 | of the terminal name before the first \fB\-\fP. This allows |
5350 | .I sun | |
5351 | to match both | |
5352 | .I sun | |
5353 | and | |
5354 | .IR sun\-cmd , | |
5355 | for instance. | |
5356 | .IP \fBapplication\fP | |
5357 | The \fBapplication\fP construct is used to include | |
ccc6cda3 | 5358 | application-specific settings. Each program using the readline |
726f6388 JA |
5359 | library sets the \fIapplication name\fP, and an initialization |
5360 | file can test for a particular value. | |
5361 | This could be used to bind key sequences to functions useful for | |
5362 | a specific program. For instance, the following command adds a | |
dc60d4e0 | 5363 | key sequence that quotes the current or previous word in \fBbash\fP: |
cce855bc | 5364 | .sp 1 |
726f6388 JA |
5365 | .RS |
5366 | .nf | |
5367 | \fB$if\fP Bash | |
5368 | # Quote the current or previous word | |
ccc6cda3 | 5369 | "\eC\-xq": "\eeb\e"\eef\e"" |
726f6388 JA |
5370 | \fB$endif\fP |
5371 | .fi | |
5372 | .RE | |
5373 | .RE | |
5374 | .IP \fB$endif\fP | |
cce855bc | 5375 | This command, as seen in the previous example, terminates an |
726f6388 JA |
5376 | \fB$if\fP command. |
5377 | .IP \fB$else\fP | |
5378 | Commands in this branch of the \fB$if\fP directive are executed if | |
5379 | the test fails. | |
cce855bc JA |
5380 | .IP \fB$include\fP |
5381 | This directive takes a single filename as an argument and reads commands | |
5382 | and bindings from that file. For example, the following directive | |
5383 | would read \fI/etc/inputrc\fP: | |
5384 | .sp 1 | |
5385 | .RS | |
5386 | .nf | |
5387 | \fB$include\fP \^ \fI/etc/inputrc\fP | |
5388 | .fi | |
5389 | .RE | |
ccc6cda3 | 5390 | .SS Searching |
726f6388 | 5391 | .PP |
ccc6cda3 JA |
5392 | Readline provides commands for searching through the command history |
5393 | (see | |
5394 | .SM | |
5395 | .B HISTORY | |
5396 | below) for lines containing a specified string. | |
5397 | There are two search modes: | |
5398 | .I incremental | |
5399 | and | |
5400 | .IR non-incremental . | |
5401 | .PP | |
5402 | Incremental searches begin before the user has finished typing the | |
5403 | search string. | |
5404 | As each character of the search string is typed, readline displays | |
5405 | the next entry from the history matching the string typed so far. | |
5406 | An incremental search requires only as many characters as needed to | |
5407 | find the desired history entry. | |
bb70624e | 5408 | The characters present in the value of the \fBisearch-terminators\fP |
b72432fd JA |
5409 | variable are used to terminate an incremental search. |
5410 | If that variable has not been assigned a value the Escape and | |
5411 | Control-J characters will terminate an incremental search. | |
ccc6cda3 JA |
5412 | Control-G will abort an incremental search and restore the original |
5413 | line. | |
5414 | When the search is terminated, the history entry containing the | |
5415 | search string becomes the current line. | |
bb70624e | 5416 | .PP |
ccc6cda3 JA |
5417 | To find other matching entries in the history list, type Control-S or |
5418 | Control-R as appropriate. | |
5419 | This will search backward or forward in the history for the next | |
5420 | entry matching the search string typed so far. | |
5421 | Any other key sequence bound to a readline command will terminate | |
5422 | the search and execute that command. | |
5423 | For instance, a \fInewline\fP will terminate the search and accept | |
5424 | the line, thereby executing the command from the history list. | |
5425 | .PP | |
f73dda09 JA |
5426 | Readline remembers the last incremental search string. If two |
5427 | Control-Rs are typed without any intervening characters defining a | |
5428 | new search string, any remembered search string is used. | |
5429 | .PP | |
ccc6cda3 JA |
5430 | Non-incremental searches read the entire search string before starting |
5431 | to search for matching history lines. The search string may be | |
cce855bc | 5432 | typed by the user or be part of the contents of the current line. |
ccc6cda3 | 5433 | .SS "Readline Command Names" |
726f6388 JA |
5434 | .PP |
5435 | The following is a list of the names of the commands and the default | |
5436 | key sequences to which they are bound. | |
ccc6cda3 | 5437 | Command names without an accompanying key sequence are unbound by default. |
bb70624e JA |
5438 | In the following descriptions, \fIpoint\fP refers to the current cursor |
5439 | position, and \fImark\fP refers to a cursor position saved by the | |
5440 | \fBset\-mark\fP command. | |
5441 | The text between the point and mark is referred to as the \fIregion\fP. | |
726f6388 JA |
5442 | .SS Commands for Moving |
5443 | .PP | |
5444 | .PD 0 | |
5445 | .TP | |
5446 | .B beginning\-of\-line (C\-a) | |
5447 | Move to the start of the current line. | |
5448 | .TP | |
5449 | .B end\-of\-line (C\-e) | |
5450 | Move to the end of the line. | |
5451 | .TP | |
5452 | .B forward\-char (C\-f) | |
5453 | Move forward a character. | |
5454 | .TP | |
5455 | .B backward\-char (C\-b) | |
5456 | Move back a character. | |
5457 | .TP | |
5458 | .B forward\-word (M\-f) | |
5459 | Move forward to the end of the next word. Words are composed of | |
5460 | alphanumeric characters (letters and digits). | |
5461 | .TP | |
5462 | .B backward\-word (M\-b) | |
8c2fef19 CR |
5463 | Move back to the start of the current or previous word. |
5464 | Words are composed of alphanumeric characters (letters and digits). | |
5465 | .TP | |
5466 | .B shell\-forward\-word | |
5467 | Move forward to the end of the next word. | |
5468 | Words are delimited by non-quoted shell metacharacters. | |
5469 | .TP | |
5470 | .B shell\-backward\-word | |
5471 | Move back to the start of the current or previous word. | |
5472 | Words are delimited by non-quoted shell metacharacters. | |
726f6388 JA |
5473 | .TP |
5474 | .B clear\-screen (C\-l) | |
5475 | Clear the screen leaving the current line at the top of the screen. | |
5476 | With an argument, refresh the current line without clearing the | |
5477 | screen. | |
5478 | .TP | |
5479 | .B redraw\-current\-line | |
ccc6cda3 | 5480 | Refresh the current line. |
726f6388 JA |
5481 | .PD |
5482 | .SS Commands for Manipulating the History | |
5483 | .PP | |
5484 | .PD 0 | |
5485 | .TP | |
5486 | .B accept\-line (Newline, Return) | |
5487 | Accept the line regardless of where the cursor is. If this line is | |
ccc6cda3 | 5488 | non-empty, add it to the history list according to the state of the |
726f6388 JA |
5489 | .SM |
5490 | .B HISTCONTROL | |
5491 | variable. If the line is a modified history | |
5492 | line, then restore the history line to its original state. | |
5493 | .TP | |
5494 | .B previous\-history (C\-p) | |
5495 | Fetch the previous command from the history list, moving back in | |
5496 | the list. | |
5497 | .TP | |
5498 | .B next\-history (C\-n) | |
5499 | Fetch the next command from the history list, moving forward in the | |
5500 | list. | |
5501 | .TP | |
5502 | .B beginning\-of\-history (M\-<) | |
5503 | Move to the first line in the history. | |
5504 | .TP | |
5505 | .B end\-of\-history (M\->) | |
5506 | Move to the end of the input history, i.e., the line currently being | |
5507 | entered. | |
5508 | .TP | |
5509 | .B reverse\-search\-history (C\-r) | |
5510 | Search backward starting at the current line and moving `up' through | |
5511 | the history as necessary. This is an incremental search. | |
5512 | .TP | |
5513 | .B forward\-search\-history (C\-s) | |
5514 | Search forward starting at the current line and moving `down' through | |
5515 | the history as necessary. This is an incremental search. | |
5516 | .TP | |
5517 | .B non\-incremental\-reverse\-search\-history (M\-p) | |
5518 | Search backward through the history starting at the current line | |
ccc6cda3 | 5519 | using a non-incremental search for a string supplied by the user. |
726f6388 JA |
5520 | .TP |
5521 | .B non\-incremental\-forward\-search\-history (M\-n) | |
ccc6cda3 | 5522 | Search forward through the history using a non-incremental search for |
726f6388 JA |
5523 | a string supplied by the user. |
5524 | .TP | |
5525 | .B history\-search\-forward | |
5526 | Search forward through the history for the string of characters | |
bb70624e | 5527 | between the start of the current line and the point. |
ccc6cda3 | 5528 | This is a non-incremental search. |
726f6388 JA |
5529 | .TP |
5530 | .B history\-search\-backward | |
5531 | Search backward through the history for the string of characters | |
ccc6cda3 JA |
5532 | between the start of the current line and the point. |
5533 | This is a non-incremental search. | |
726f6388 JA |
5534 | .TP |
5535 | .B yank\-nth\-arg (M\-C\-y) | |
5536 | Insert the first argument to the previous command (usually | |
28ef6c31 JA |
5537 | the second word on the previous line) at point. |
5538 | With an argument | |
726f6388 JA |
5539 | .IR n , |
5540 | insert the \fIn\fPth word from the previous command (the words | |
5541 | in the previous command begin with word 0). A negative argument | |
5542 | inserts the \fIn\fPth word from the end of the previous command. | |
eb2bb562 CR |
5543 | Once the argument \fIn\fP is computed, the argument is extracted |
5544 | as if the "!\fIn\fP" history expansion had been specified. | |
726f6388 JA |
5545 | .TP |
5546 | .B | |
5547 | yank\-last\-arg (M\-.\^, M\-_\^) | |
ccc6cda3 | 5548 | Insert the last argument to the previous command (the last word of |
adc6cff5 CR |
5549 | the previous history entry). |
5550 | With a numeric argument, behave exactly like \fByank\-nth\-arg\fP. | |
cce855bc | 5551 | Successive calls to \fByank\-last\-arg\fP move back through the history |
adc6cff5 CR |
5552 | list, inserting the last word (or the word specified by the argument to |
5553 | the first call) of each line in turn. | |
5554 | Any numeric argument supplied to these successive calls determines | |
5555 | the direction to move through the history. A negative argument switches | |
5556 | the direction through the history (back or forward). | |
eb2bb562 CR |
5557 | The history expansion facilities are used to extract the last argument, |
5558 | as if the "!$" history expansion had been specified. | |
726f6388 JA |
5559 | .TP |
5560 | .B shell\-expand\-line (M\-C\-e) | |
cce855bc | 5561 | Expand the line as the shell does. This |
726f6388 JA |
5562 | performs alias and history expansion as well as all of the shell |
5563 | word expansions. See | |
5564 | .SM | |
5565 | .B HISTORY EXPANSION | |
5566 | below for a description of history expansion. | |
5567 | .TP | |
5568 | .B history\-expand\-line (M\-^) | |
d166f048 JA |
5569 | Perform history expansion on the current line. |
5570 | See | |
726f6388 JA |
5571 | .SM |
5572 | .B HISTORY EXPANSION | |
5573 | below for a description of history expansion. | |
5574 | .TP | |
cce855bc JA |
5575 | .B magic\-space |
5576 | Perform history expansion on the current line and insert a space. | |
5577 | See | |
5578 | .SM | |
5579 | .B HISTORY EXPANSION | |
5580 | below for a description of history expansion. | |
5581 | .TP | |
d166f048 JA |
5582 | .B alias\-expand\-line |
5583 | Perform alias expansion on the current line. | |
5584 | See | |
5585 | .SM | |
5586 | .B ALIASES | |
5587 | above for a description of alias expansion. | |
5588 | .TP | |
5589 | .B history\-and\-alias\-expand\-line | |
5590 | Perform history and alias expansion on the current line. | |
5591 | .TP | |
726f6388 JA |
5592 | .B insert\-last\-argument (M\-.\^, M\-_\^) |
5593 | A synonym for \fByank\-last\-arg\fP. | |
5594 | .TP | |
ccc6cda3 | 5595 | .B operate\-and\-get\-next (C\-o) |
726f6388 JA |
5596 | Accept the current line for execution and fetch the next line |
5597 | relative to the current line from the history for editing. Any | |
5598 | argument is ignored. | |
7117c2d2 JA |
5599 | .TP |
5600 | .B edit\-and\-execute\-command (C\-xC\-e) | |
5601 | Invoke an editor on the current command line, and execute the result as shell | |
5602 | commands. | |
5603 | \fBBash\fP attempts to invoke | |
5604 | .SM | |
dd4f3dd8 | 5605 | .BR $VISUAL , |
7117c2d2 JA |
5606 | .SM |
5607 | .BR $EDITOR , | |
5608 | and \fIemacs\fP as the editor, in that order. | |
726f6388 JA |
5609 | .PD |
5610 | .SS Commands for Changing Text | |
5611 | .PP | |
5612 | .PD 0 | |
5613 | .TP | |
5614 | .B delete\-char (C\-d) | |
28ef6c31 | 5615 | Delete the character at point. If point is at the |
726f6388 | 5616 | beginning of the line, there are no characters in the line, and |
cce855bc | 5617 | the last character typed was not bound to \fBdelete\-char\fP, |
726f6388 JA |
5618 | then return |
5619 | .SM | |
5620 | .BR EOF . | |
5621 | .TP | |
5622 | .B backward\-delete\-char (Rubout) | |
5623 | Delete the character behind the cursor. When given a numeric argument, | |
ccc6cda3 | 5624 | save the deleted text on the kill ring. |
726f6388 | 5625 | .TP |
b72432fd JA |
5626 | .B forward\-backward\-delete\-char |
5627 | Delete the character under the cursor, unless the cursor is at the | |
5628 | end of the line, in which case the character behind the cursor is | |
f73dda09 | 5629 | deleted. |
b72432fd | 5630 | .TP |
726f6388 | 5631 | .B quoted\-insert (C\-q, C\-v) |
cce855bc | 5632 | Add the next character typed to the line verbatim. This is |
726f6388 JA |
5633 | how to insert characters like \fBC\-q\fP, for example. |
5634 | .TP | |
ccc6cda3 | 5635 | .B tab\-insert (C\-v TAB) |
726f6388 JA |
5636 | Insert a tab character. |
5637 | .TP | |
5638 | .B self\-insert (a,\ b,\ A,\ 1,\ !,\ ...) | |
5639 | Insert the character typed. | |
5640 | .TP | |
5641 | .B transpose\-chars (C\-t) | |
28ef6c31 JA |
5642 | Drag the character before point forward over the character at point, |
5643 | moving point forward as well. | |
5644 | If point is at the end of the line, then this transposes | |
5645 | the two characters before point. | |
bb70624e | 5646 | Negative arguments have no effect. |
726f6388 JA |
5647 | .TP |
5648 | .B transpose\-words (M\-t) | |
bb70624e | 5649 | Drag the word before point past the word after point, |
28ef6c31 | 5650 | moving point over that word as well. |
f73dda09 JA |
5651 | If point is at the end of the line, this transposes |
5652 | the last two words on the line. | |
726f6388 JA |
5653 | .TP |
5654 | .B upcase\-word (M\-u) | |
5655 | Uppercase the current (or following) word. With a negative argument, | |
cce855bc | 5656 | uppercase the previous word, but do not move point. |
726f6388 JA |
5657 | .TP |
5658 | .B downcase\-word (M\-l) | |
5659 | Lowercase the current (or following) word. With a negative argument, | |
cce855bc | 5660 | lowercase the previous word, but do not move point. |
726f6388 JA |
5661 | .TP |
5662 | .B capitalize\-word (M\-c) | |
5663 | Capitalize the current (or following) word. With a negative argument, | |
cce855bc | 5664 | capitalize the previous word, but do not move point. |
7117c2d2 JA |
5665 | .TP |
5666 | .B overwrite\-mode | |
5667 | Toggle overwrite mode. With an explicit positive numeric argument, | |
5668 | switches to overwrite mode. With an explicit non-positive numeric | |
5669 | argument, switches to insert mode. This command affects only | |
5670 | \fBemacs\fP mode; \fBvi\fP mode does overwrite differently. | |
5671 | Each call to \fIreadline()\fP starts in insert mode. | |
5672 | In overwrite mode, characters bound to \fBself\-insert\fP replace | |
5673 | the text at point rather than pushing the text to the right. | |
5674 | Characters bound to \fBbackward\-delete\-char\fP replace the character | |
5675 | before point with a space. By default, this command is unbound. | |
726f6388 JA |
5676 | .PD |
5677 | .SS Killing and Yanking | |
5678 | .PP | |
5679 | .PD 0 | |
5680 | .TP | |
5681 | .B kill\-line (C\-k) | |
bb70624e | 5682 | Kill the text from point to the end of the line. |
726f6388 | 5683 | .TP |
ccc6cda3 | 5684 | .B backward\-kill\-line (C\-x Rubout) |
726f6388 JA |
5685 | Kill backward to the beginning of the line. |
5686 | .TP | |
5687 | .B unix\-line\-discard (C\-u) | |
5688 | Kill backward from point to the beginning of the line. | |
cce855bc | 5689 | The killed text is saved on the kill-ring. |
bb70624e | 5690 | .\" There is no real difference between this and backward-kill-line |
726f6388 JA |
5691 | .TP |
5692 | .B kill\-whole\-line | |
bb70624e | 5693 | Kill all characters on the current line, no matter where point is. |
726f6388 JA |
5694 | .TP |
5695 | .B kill\-word (M\-d) | |
bb70624e JA |
5696 | Kill from point to the end of the current word, or if between |
5697 | words, to the end of the next word. | |
5698 | Word boundaries are the same as those used by \fBforward\-word\fP. | |
726f6388 JA |
5699 | .TP |
5700 | .B backward\-kill\-word (M\-Rubout) | |
bb70624e JA |
5701 | Kill the word behind point. |
5702 | Word boundaries are the same as those used by \fBbackward\-word\fP. | |
726f6388 | 5703 | .TP |
8c2fef19 CR |
5704 | .B shell\-kill\-word (M\-d) |
5705 | Kill from point to the end of the current word, or if between | |
5706 | words, to the end of the next word. | |
5707 | Word boundaries are the same as those used by \fBshell\-forward\-word\fP. | |
5708 | .TP | |
5709 | .B shell\-backward\-kill\-word (M\-Rubout) | |
5710 | Kill the word behind point. | |
5711 | Word boundaries are the same as those used by \fBshell\-backward\-word\fP. | |
5712 | .TP | |
726f6388 | 5713 | .B unix\-word\-rubout (C\-w) |
bb70624e | 5714 | Kill the word behind point, using white space as a word boundary. |
bb70624e | 5715 | The killed text is saved on the kill-ring. |
113d85a4 CR |
5716 | .TP |
5717 | .B unix\-filename\-rubout | |
5718 | Kill the word behind point, using white space and the slash character | |
5719 | as the word boundaries. | |
5720 | The killed text is saved on the kill-ring. | |
ccc6cda3 JA |
5721 | .TP |
5722 | .B delete\-horizontal\-space (M\-\e) | |
5723 | Delete all spaces and tabs around point. | |
5724 | .TP | |
5725 | .B kill\-region | |
bb70624e | 5726 | Kill the text in the current region. |
ccc6cda3 JA |
5727 | .TP |
5728 | .B copy\-region\-as\-kill | |
5729 | Copy the text in the region to the kill buffer. | |
726f6388 | 5730 | .TP |
ccc6cda3 JA |
5731 | .B copy\-backward\-word |
5732 | Copy the word before point to the kill buffer. | |
cce855bc | 5733 | The word boundaries are the same as \fBbackward\-word\fP. |
ccc6cda3 JA |
5734 | .TP |
5735 | .B copy\-forward\-word | |
5736 | Copy the word following point to the kill buffer. | |
cce855bc | 5737 | The word boundaries are the same as \fBforward\-word\fP. |
726f6388 JA |
5738 | .TP |
5739 | .B yank (C\-y) | |
28ef6c31 | 5740 | Yank the top of the kill ring into the buffer at point. |
726f6388 JA |
5741 | .TP |
5742 | .B yank\-pop (M\-y) | |
ccc6cda3 | 5743 | Rotate the kill ring, and yank the new top. Only works following |
726f6388 JA |
5744 | .B yank |
5745 | or | |
5746 | .BR yank\-pop . | |
5747 | .PD | |
5748 | .SS Numeric Arguments | |
5749 | .PP | |
5750 | .PD 0 | |
5751 | .TP | |
5752 | .B digit\-argument (M\-0, M\-1, ..., M\-\-) | |
5753 | Add this digit to the argument already accumulating, or start a new | |
5754 | argument. M\-\- starts a negative argument. | |
5755 | .TP | |
5756 | .B universal\-argument | |
d166f048 JA |
5757 | This is another way to specify an argument. |
5758 | If this command is followed by one or more digits, optionally with a | |
5759 | leading minus sign, those digits define the argument. | |
5760 | If the command is followed by digits, executing | |
5761 | .B universal\-argument | |
5762 | again ends the numeric argument, but is otherwise ignored. | |
5763 | As a special case, if this command is immediately followed by a | |
5764 | character that is neither a digit or minus sign, the argument count | |
5765 | for the next command is multiplied by four. | |
726f6388 | 5766 | The argument count is initially one, so executing this function the |
d166f048 JA |
5767 | first time makes the argument count four, a second time makes the |
5768 | argument count sixteen, and so on. | |
726f6388 JA |
5769 | .PD |
5770 | .SS Completing | |
5771 | .PP | |
5772 | .PD 0 | |
5773 | .TP | |
5774 | .B complete (TAB) | |
5775 | Attempt to perform completion on the text before point. | |
5776 | .B Bash | |
5777 | attempts completion treating the text as a variable (if the | |
5778 | text begins with \fB$\fP), username (if the text begins with | |
5779 | \fB~\fP), hostname (if the text begins with \fB@\fP), or | |
5780 | command (including aliases and functions) in turn. If none | |
5781 | of these produces a match, filename completion is attempted. | |
5782 | .TP | |
ccc6cda3 | 5783 | .B possible\-completions (M\-?) |
726f6388 JA |
5784 | List the possible completions of the text before point. |
5785 | .TP | |
ccc6cda3 | 5786 | .B insert\-completions (M\-*) |
726f6388 JA |
5787 | Insert all completions of the text before point |
5788 | that would have been generated by | |
ccc6cda3 | 5789 | \fBpossible\-completions\fP. |
726f6388 | 5790 | .TP |
cce855bc JA |
5791 | .B menu\-complete |
5792 | Similar to \fBcomplete\fP, but replaces the word to be completed | |
5793 | with a single match from the list of possible completions. | |
5794 | Repeated execution of \fBmenu\-complete\fP steps through the list | |
5795 | of possible completions, inserting each match in turn. | |
28ef6c31 | 5796 | At the end of the list of completions, the bell is rung |
f73dda09 | 5797 | (subject to the setting of \fBbell\-style\fP) |
28ef6c31 | 5798 | and the original text is restored. |
cce855bc JA |
5799 | An argument of \fIn\fP moves \fIn\fP positions forward in the list |
5800 | of matches; a negative argument may be used to move backward | |
5801 | through the list. | |
5802 | This command is intended to be bound to \fBTAB\fP, but is unbound | |
5803 | by default. | |
5804 | .TP | |
dc60d4e0 | 5805 | .B menu\-complete\-backward |
9dd88db7 CR |
5806 | Identical to \fBmenu\-complete\fP, but moves backward through the list |
5807 | of possible completions, as if \fBmenu\-complete\fP had been given a | |
5808 | negative argument. This command is unbound by default. | |
5809 | .TP | |
b72432fd JA |
5810 | .B delete\-char\-or\-list |
5811 | Deletes the character under the cursor if not at the beginning or | |
bb70624e | 5812 | end of the line (like \fBdelete\-char\fP). |
b72432fd | 5813 | If at the end of the line, behaves identically to |
bb70624e | 5814 | \fBpossible\-completions\fP. |
b72432fd JA |
5815 | This command is unbound by default. |
5816 | .TP | |
726f6388 JA |
5817 | .B complete\-filename (M\-/) |
5818 | Attempt filename completion on the text before point. | |
5819 | .TP | |
5820 | .B possible\-filename\-completions (C\-x /) | |
5821 | List the possible completions of the text before point, | |
5822 | treating it as a filename. | |
5823 | .TP | |
5824 | .B complete\-username (M\-~) | |
5825 | Attempt completion on the text before point, treating | |
5826 | it as a username. | |
5827 | .TP | |
5828 | .B possible\-username\-completions (C\-x ~) | |
5829 | List the possible completions of the text before point, | |
5830 | treating it as a username. | |
5831 | .TP | |
5832 | .B complete\-variable (M\-$) | |
5833 | Attempt completion on the text before point, treating | |
5834 | it as a shell variable. | |
5835 | .TP | |
5836 | .B possible\-variable\-completions (C\-x $) | |
5837 | List the possible completions of the text before point, | |
5838 | treating it as a shell variable. | |
5839 | .TP | |
5840 | .B complete\-hostname (M\-@) | |
5841 | Attempt completion on the text before point, treating | |
5842 | it as a hostname. | |
5843 | .TP | |
5844 | .B possible\-hostname\-completions (C\-x @) | |
5845 | List the possible completions of the text before point, | |
5846 | treating it as a hostname. | |
5847 | .TP | |
5848 | .B complete\-command (M\-!) | |
5849 | Attempt completion on the text before point, treating | |
5850 | it as a command name. Command completion attempts to | |
5851 | match the text against aliases, reserved words, shell | |
cce855bc | 5852 | functions, shell builtins, and finally executable filenames, |
726f6388 JA |
5853 | in that order. |
5854 | .TP | |
5855 | .B possible\-command\-completions (C\-x !) | |
5856 | List the possible completions of the text before point, | |
5857 | treating it as a command name. | |
5858 | .TP | |
ccc6cda3 | 5859 | .B dynamic\-complete\-history (M\-TAB) |
726f6388 JA |
5860 | Attempt completion on the text before point, comparing |
5861 | the text against lines from the history list for possible | |
5862 | completion matches. | |
5863 | .TP | |
8943768b CR |
5864 | .B dabbrev\-expand |
5865 | Attempt menu completion on the text before point, comparing | |
5866 | the text against lines from the history list for possible | |
5867 | completion matches. | |
5868 | .TP | |
726f6388 | 5869 | .B complete\-into\-braces (M\-{) |
bb70624e | 5870 | Perform filename completion and insert the list of possible completions |
726f6388 JA |
5871 | enclosed within braces so the list is available to the shell (see |
5872 | .B Brace Expansion | |
5873 | above). | |
5874 | .PD | |
5875 | .SS Keyboard Macros | |
5876 | .PP | |
5877 | .PD 0 | |
5878 | .TP | |
ccc6cda3 | 5879 | .B start\-kbd\-macro (C\-x (\^) |
726f6388 JA |
5880 | Begin saving the characters typed into the current keyboard macro. |
5881 | .TP | |
ccc6cda3 | 5882 | .B end\-kbd\-macro (C\-x )\^) |
726f6388 | 5883 | Stop saving the characters typed into the current keyboard macro |
ccc6cda3 | 5884 | and store the definition. |
726f6388 | 5885 | .TP |
ccc6cda3 | 5886 | .B call\-last\-kbd\-macro (C\-x e) |
726f6388 JA |
5887 | Re-execute the last keyboard macro defined, by making the characters |
5888 | in the macro appear as if typed at the keyboard. | |
5889 | .PD | |
5890 | .SS Miscellaneous | |
5891 | .PP | |
5892 | .PD 0 | |
5893 | .TP | |
5894 | .B re\-read\-init\-file (C\-x C\-r) | |
ccc6cda3 | 5895 | Read in the contents of the \fIinputrc\fP file, and incorporate |
726f6388 JA |
5896 | any bindings or variable assignments found there. |
5897 | .TP | |
5898 | .B abort (C\-g) | |
5899 | Abort the current editing command and | |
5900 | ring the terminal's bell (subject to the setting of | |
5901 | .BR bell\-style ). | |
5902 | .TP | |
ccc6cda3 JA |
5903 | .B do\-uppercase\-version (M\-a, M\-b, M\-\fIx\fP, ...) |
5904 | If the metafied character \fIx\fP is lowercase, run the command | |
5905 | that is bound to the corresponding uppercase character. | |
726f6388 JA |
5906 | .TP |
5907 | .B prefix\-meta (ESC) | |
5908 | Metafy the next character typed. | |
5909 | .SM | |
5910 | .B ESC | |
5911 | .B f | |
5912 | is equivalent to | |
5913 | .BR Meta\-f . | |
5914 | .TP | |
5915 | .B undo (C\-_, C\-x C\-u) | |
5916 | Incremental undo, separately remembered for each line. | |
5917 | .TP | |
5918 | .B revert\-line (M\-r) | |
cce855bc | 5919 | Undo all changes made to this line. This is like executing the |
726f6388 JA |
5920 | .B undo |
5921 | command enough times to return the line to its initial state. | |
5922 | .TP | |
b72432fd | 5923 | .B tilde\-expand (M\-&) |
726f6388 JA |
5924 | Perform tilde expansion on the current word. |
5925 | .TP | |
ccc6cda3 | 5926 | .B set\-mark (C\-@, M\-<space>) |
28ef6c31 | 5927 | Set the mark to the point. If a |
ccc6cda3 JA |
5928 | numeric argument is supplied, the mark is set to that position. |
5929 | .TP | |
5930 | .B exchange\-point\-and\-mark (C\-x C\-x) | |
5931 | Swap the point with the mark. The current cursor position is set to | |
5932 | the saved position, and the old cursor position is saved as the mark. | |
5933 | .TP | |
5934 | .B character\-search (C\-]) | |
5935 | A character is read and point is moved to the next occurrence of that | |
5936 | character. A negative count searches for previous occurrences. | |
5937 | .TP | |
5938 | .B character\-search\-backward (M\-C\-]) | |
5939 | A character is read and point is moved to the previous occurrence of that | |
5940 | character. A negative count searches for subsequent occurrences. | |
5941 | .TP | |
dc60d4e0 | 5942 | .B skip\-csi\-sequence |
691aebcb CR |
5943 | Read enough characters to consume a multi-key sequence such as those |
5944 | defined for keys like Home and End. Such sequences begin with a | |
5945 | Control Sequence Indicator (CSI), usually ESC\-[. If this sequence is | |
5946 | bound to "\e[", keys producing such sequences will have no effect | |
5947 | unless explicitly bound to a readline command, instead of inserting | |
5948 | stray characters into the editing buffer. This is unbound by default, | |
5949 | but usually bound to ESC\-[. | |
5950 | .TP | |
ccc6cda3 | 5951 | .B insert\-comment (M\-#) |
7117c2d2 | 5952 | Without a numeric argument, the value of the readline |
ccc6cda3 | 5953 | .B comment\-begin |
7117c2d2 JA |
5954 | variable is inserted at the beginning of the current line. |
5955 | If a numeric argument is supplied, this command acts as a toggle: if | |
5956 | the characters at the beginning of the line do not match the value | |
5957 | of \fBcomment\-begin\fP, the value is inserted, otherwise | |
db31fb26 | 5958 | the characters in \fBcomment\-begin\fP are deleted from the beginning of |
7117c2d2 JA |
5959 | the line. |
5960 | In either case, the line is accepted as if a newline had been typed. | |
5961 | The default value of | |
bb70624e | 5962 | \fBcomment\-begin\fP causes this command to make the current line |
ccc6cda3 | 5963 | a shell comment. |
7117c2d2 JA |
5964 | If a numeric argument causes the comment character to be removed, the line |
5965 | will be executed by the shell. | |
5966 | .TP | |
5967 | .B glob\-complete\-word (M\-g) | |
5968 | The word before point is treated as a pattern for pathname expansion, | |
5969 | with an asterisk implicitly appended. This pattern is used to | |
b28ff8c9 | 5970 | generate a list of matching filenames for possible completions. |
ccc6cda3 JA |
5971 | .TP |
5972 | .B glob\-expand\-word (C\-x *) | |
5973 | The word before point is treated as a pattern for pathname expansion, | |
b28ff8c9 | 5974 | and the list of matching filenames is inserted, replacing the word. |
7117c2d2 JA |
5975 | If a numeric argument is supplied, an asterisk is appended before |
5976 | pathname expansion. | |
ccc6cda3 JA |
5977 | .TP |
5978 | .B glob\-list\-expansions (C\-x g) | |
5979 | The list of expansions that would have been generated by | |
5980 | .B glob\-expand\-word | |
5981 | is displayed, and the line is redrawn. | |
7117c2d2 JA |
5982 | If a numeric argument is supplied, an asterisk is appended before |
5983 | pathname expansion. | |
ccc6cda3 | 5984 | .TP |
726f6388 JA |
5985 | .B dump\-functions |
5986 | Print all of the functions and their key bindings to the | |
5987 | readline output stream. If a numeric argument is supplied, | |
5988 | the output is formatted in such a way that it can be made part | |
5989 | of an \fIinputrc\fP file. | |
5990 | .TP | |
ccc6cda3 JA |
5991 | .B dump\-variables |
5992 | Print all of the settable readline variables and their values to the | |
5993 | readline output stream. If a numeric argument is supplied, | |
5994 | the output is formatted in such a way that it can be made part | |
5995 | of an \fIinputrc\fP file. | |
5996 | .TP | |
5997 | .B dump\-macros | |
5998 | Print all of the readline key sequences bound to macros and the | |
22e63b05 | 5999 | strings they output. If a numeric argument is supplied, |
ccc6cda3 JA |
6000 | the output is formatted in such a way that it can be made part |
6001 | of an \fIinputrc\fP file. | |
6002 | .TP | |
726f6388 JA |
6003 | .B display\-shell\-version (C\-x C\-v) |
6004 | Display version information about the current instance of | |
6005 | .BR bash . | |
6006 | .PD | |
bb70624e JA |
6007 | .SS Programmable Completion |
6008 | .PP | |
6009 | When word completion is attempted for an argument to a command for | |
6010 | which a completion specification (a \fIcompspec\fP) has been defined | |
6011 | using the \fBcomplete\fP builtin (see | |
6012 | .SM | |
6013 | .B "SHELL BUILTIN COMMANDS" | |
6014 | below), the programmable completion facilities are invoked. | |
6015 | .PP | |
6016 | First, the command name is identified. | |
3eb2d94a CR |
6017 | If the command word is the empty string (completion attempted at the |
6018 | beginning of an empty line), any compspec defined with | |
6019 | the \fB\-E\fP option to \fBcomplete\fP is used. | |
bb70624e JA |
6020 | If a compspec has been defined for that command, the |
6021 | compspec is used to generate the list of possible completions for the word. | |
6022 | If the command word is a full pathname, a compspec for the full | |
6023 | pathname is searched for first. | |
6024 | If no compspec is found for the full pathname, an attempt is made to | |
6025 | find a compspec for the portion following the final slash. | |
dc60d4e0 | 6026 | If those searches do not result in a compspec, any compspec defined with |
3eb2d94a | 6027 | the \fB\-D\fP option to \fBcomplete\fP is used as the default. |
bb70624e JA |
6028 | .PP |
6029 | Once a compspec has been found, it is used to generate the list of | |
6030 | matching words. | |
6031 | If a compspec is not found, the default \fBbash\fP completion as | |
6032 | described above under \fBCompleting\fP is performed. | |
6033 | .PP | |
6034 | First, the actions specified by the compspec are used. | |
6035 | Only matches which are prefixed by the word being completed are | |
6036 | returned. | |
6037 | When the | |
6038 | .B \-f | |
6039 | or | |
6040 | .B \-d | |
6041 | option is used for filename or directory name completion, the shell | |
6042 | variable | |
6043 | .SM | |
6044 | .B FIGNORE | |
6045 | is used to filter the matches. | |
6046 | .PP | |
d0ca3503 | 6047 | Any completions specified by a pathname expansion pattern to the |
bb70624e JA |
6048 | \fB\-G\fP option are generated next. |
6049 | The words generated by the pattern need not match the word | |
6050 | being completed. | |
6051 | The | |
6052 | .SM | |
6053 | .B GLOBIGNORE | |
6054 | shell variable is not used to filter the matches, but the | |
6055 | .SM | |
6056 | .B FIGNORE | |
6057 | variable is used. | |
6058 | .PP | |
6059 | Next, the string specified as the argument to the \fB\-W\fP option | |
6060 | is considered. | |
6061 | The string is first split using the characters in the | |
6062 | .SM | |
6063 | .B IFS | |
6064 | special variable as delimiters. | |
6065 | Shell quoting is honored. | |
6066 | Each word is then expanded using | |
6067 | brace expansion, tilde expansion, parameter and variable expansion, | |
6e70dbff | 6068 | command substitution, and arithmetic expansion, |
bb70624e JA |
6069 | as described above under |
6070 | .SM | |
6071 | .BR EXPANSION . | |
6072 | The results are split using the rules described above under | |
6073 | \fBWord Splitting\fP. | |
6074 | The results of the expansion are prefix-matched against the word being | |
6075 | completed, and the matching words become the possible completions. | |
6076 | .PP | |
6077 | After these matches have been generated, any shell function or command | |
6078 | specified with the \fB\-F\fP and \fB\-C\fP options is invoked. | |
6079 | When the command or function is invoked, the | |
6080 | .SM | |
d3ad40de CR |
6081 | .BR COMP_LINE , |
6082 | .SM | |
6083 | .BR COMP_POINT , | |
6084 | .SM | |
6085 | .BR COMP_KEY , | |
bb70624e JA |
6086 | and |
6087 | .SM | |
d3ad40de | 6088 | .B COMP_TYPE |
bb70624e JA |
6089 | variables are assigned values as described above under |
6090 | \fBShell Variables\fP. | |
6091 | If a shell function is being invoked, the | |
6092 | .SM | |
6093 | .B COMP_WORDS | |
6094 | and | |
6095 | .SM | |
6096 | .B COMP_CWORD | |
6097 | variables are also set. | |
6098 | When the function or command is invoked, the first argument is the | |
6099 | name of the command whose arguments are being completed, the | |
6100 | second argument is the word being completed, and the third argument | |
6101 | is the word preceding the word being completed on the current command line. | |
6102 | No filtering of the generated completions against the word being completed | |
6103 | is performed; the function or command has complete freedom in generating | |
6104 | the matches. | |
6105 | .PP | |
6106 | Any function specified with \fB\-F\fP is invoked first. | |
6107 | The function may use any of the shell facilities, including the | |
6108 | \fBcompgen\fP builtin described below, to generate the matches. | |
6109 | It must put the possible completions in the | |
6110 | .SM | |
6111 | .B COMPREPLY | |
6112 | array variable. | |
6113 | .PP | |
6114 | Next, any command specified with the \fB\-C\fP option is invoked | |
6115 | in an environment equivalent to command substitution. | |
6116 | It should print a list of completions, one per line, to the | |
6117 | standard output. | |
6118 | Backslash may be used to escape a newline, if necessary. | |
6119 | .PP | |
6120 | After all of the possible completions are generated, any filter | |
6121 | specified with the \fB\-X\fP option is applied to the list. | |
6122 | The filter is a pattern as used for pathname expansion; a \fB&\fP | |
6123 | in the pattern is replaced with the text of the word being completed. | |
6124 | A literal \fB&\fP may be escaped with a backslash; the backslash | |
6125 | is removed before attempting a match. | |
6126 | Any completion that matches the pattern will be removed from the list. | |
6127 | A leading \fB!\fP negates the pattern; in this case any completion | |
6128 | not matching the pattern will be removed. | |
6129 | .PP | |
6130 | Finally, any prefix and suffix specified with the \fB\-P\fP and \fB\-S\fP | |
6131 | options are added to each member of the completion list, and the result is | |
6132 | returned to the readline completion code as the list of possible | |
6133 | completions. | |
6134 | .PP | |
28ef6c31 JA |
6135 | If the previously-applied actions do not generate any matches, and the |
6136 | \fB\-o dirnames\fP option was supplied to \fBcomplete\fP when the | |
6137 | compspec was defined, directory name completion is attempted. | |
6138 | .PP | |
d3a24ed2 CR |
6139 | If the \fB\-o plusdirs\fP option was supplied to \fBcomplete\fP when the |
6140 | compspec was defined, directory name completion is attempted and any | |
6141 | matches are added to the results of the other actions. | |
6142 | .PP | |
28ef6c31 JA |
6143 | By default, if a compspec is found, whatever it generates is returned |
6144 | to the completion code as the full set of possible completions. | |
bb70624e JA |
6145 | The default \fBbash\fP completions are not attempted, and the readline |
6146 | default of filename completion is disabled. | |
d3a24ed2 CR |
6147 | If the \fB\-o bashdefault\fP option was supplied to \fBcomplete\fP when |
6148 | the compspec was defined, the \fBbash\fP default completions are attempted | |
28ef6c31 | 6149 | if the compspec generates no matches. |
d3a24ed2 CR |
6150 | If the \fB\-o default\fP option was supplied to \fBcomplete\fP when the |
6151 | compspec was defined, readline's default completion will be performed | |
6152 | if the compspec (and, if attempted, the default \fBbash\fP completions) | |
6153 | generate no matches. | |
7117c2d2 JA |
6154 | .PP |
6155 | When a compspec indicates that directory name completion is desired, | |
6156 | the programmable completion functions force readline to append a slash | |
6157 | to completed names which are symbolic links to directories, subject to | |
6158 | the value of the \fBmark\-directories\fP readline variable, regardless | |
6159 | of the setting of the \fBmark-symlinked\-directories\fP readline variable. | |
3eb2d94a CR |
6160 | .PP |
6161 | There is some support for dynamically modifying completions. This is | |
6162 | most useful when used in combination with a default completion specified | |
6163 | with \fBcomplete -D\fP. | |
6164 | It's possible for shell functions executed as completion | |
6165 | handlers to indicate that completion should be retried by returning an | |
6166 | exit status of 124. If a shell function returns 124, and changes | |
6167 | the compspec associated with the command on which completion is being | |
6168 | attempted (supplied as the first argument when the function is executed), | |
6169 | programmable completion restarts from the beginning, with an | |
3d8cce26 | 6170 | attempt to find a new compspec for that command. This allows a set of |
3eb2d94a CR |
6171 | completions to be built dynamically as completion is attempted, rather than |
6172 | being loaded all at once. | |
6173 | .PP | |
6174 | For instance, assuming that there is a library of compspecs, each kept in a | |
6175 | file corresponding to the name of the command, the following default | |
6176 | completion function would load completions dynamically: | |
6177 | .PP | |
6178 | \f(CW_completion_loader() | |
6179 | .br | |
6180 | { | |
6181 | .br | |
6182 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
6183 | .br | |
6184 | } | |
6185 | .br | |
6186 | complete -D -F _completion_loader | |
6187 | .br | |
6188 | \fP | |
726f6388 | 6189 | .SH HISTORY |
ccc6cda3 | 6190 | When the |
d166f048 | 6191 | .B \-o history |
ccc6cda3 JA |
6192 | option to the |
6193 | .B set | |
6194 | builtin is enabled, the shell provides access to the | |
6195 | \fIcommand history\fP, | |
bb70624e | 6196 | the list of commands previously typed. |
984a1947 CR |
6197 | The value of the |
6198 | .SM | |
6199 | .B HISTSIZE | |
6200 | variable is used as the | |
bb70624e JA |
6201 | number of commands to save in a history list. |
6202 | The text of the last | |
726f6388 JA |
6203 | .SM |
6204 | .B HISTSIZE | |
bb70624e | 6205 | commands (default 500) is saved. The shell |
726f6388 JA |
6206 | stores each command in the history list prior to parameter and |
6207 | variable expansion (see | |
6208 | .SM | |
6209 | .B EXPANSION | |
6210 | above) but after history expansion is performed, subject to the | |
6211 | values of the shell variables | |
ccc6cda3 JA |
6212 | .SM |
6213 | .B HISTIGNORE | |
726f6388 JA |
6214 | and |
6215 | .SM | |
6216 | .BR HISTCONTROL . | |
bb70624e | 6217 | .PP |
726f6388 JA |
6218 | On startup, the history is initialized from the file named by |
6219 | the variable | |
6220 | .SM | |
6221 | .B HISTFILE | |
6222 | (default \fI~/.bash_history\fP). | |
bb70624e | 6223 | The file named by the value of |
726f6388 JA |
6224 | .SM |
6225 | .B HISTFILE | |
6226 | is truncated, if necessary, to contain no more than | |
bb70624e | 6227 | the number of lines specified by the value of |
726f6388 | 6228 | .SM |
bb70624e | 6229 | .BR HISTFILESIZE . |
d3ad40de CR |
6230 | When the history file is read, |
6231 | lines beginning with the history comment character followed immediately | |
6232 | by a digit are interpreted as timestamps for the preceding history line. | |
6233 | These timestamps are optionally displayed depending on the value of the | |
6234 | .SM | |
6235 | .B HISTTIMEFORMAT | |
6236 | variable. | |
ccc6cda3 JA |
6237 | When an interactive shell exits, the last |
6238 | .SM | |
bb70624e | 6239 | .B $HISTSIZE |
ccc6cda3 JA |
6240 | lines are copied from the history list to |
6241 | .SM | |
bb70624e | 6242 | .BR $HISTFILE . |
ccc6cda3 JA |
6243 | If the |
6244 | .B histappend | |
6245 | shell option is enabled | |
6246 | (see the description of | |
6247 | .B shopt | |
6248 | under | |
6249 | .SM | |
6250 | .B "SHELL BUILTIN COMMANDS" | |
6251 | below), the lines are appended to the history file, | |
6252 | otherwise the history file is overwritten. | |
6253 | If | |
6254 | .SM | |
6255 | .B HISTFILE | |
6256 | is unset, or if the history file is unwritable, the history is | |
d3ad40de CR |
6257 | not saved. |
6258 | If the | |
6259 | .SM | |
984a1947 | 6260 | .B HISTTIMEFORMAT |
d3ad40de CR |
6261 | variable is set, time stamps are written to the history file, marked |
6262 | with the history comment character, so | |
6263 | they may be preserved across shell sessions. | |
6264 | This uses the history comment character to distinguish timestamps from | |
6265 | other history lines. | |
6266 | After saving the history, the history file is truncated | |
ccc6cda3 JA |
6267 | to contain no more than |
6268 | .SM | |
6269 | .B HISTFILESIZE | |
6270 | lines. If | |
6271 | .SM | |
6272 | .B HISTFILESIZE | |
6273 | is not set, no truncation is performed. | |
6274 | .PP | |
726f6388 JA |
6275 | The builtin command |
6276 | .B fc | |
6277 | (see | |
6278 | .SM | |
6279 | .B SHELL BUILTIN COMMANDS | |
6280 | below) may be used to list or edit and re-execute a portion of | |
6281 | the history list. | |
6282 | The | |
6283 | .B history | |
bb70624e | 6284 | builtin may be used to display or modify the history list and |
ccc6cda3 | 6285 | manipulate the history file. |
bb70624e | 6286 | When using command-line editing, search commands |
726f6388 | 6287 | are available in each editing mode that provide access to the |
ccc6cda3 JA |
6288 | history list. |
6289 | .PP | |
6290 | The shell allows control over which commands are saved on the history | |
6291 | list. The | |
726f6388 | 6292 | .SM |
ccc6cda3 JA |
6293 | .B HISTCONTROL |
6294 | and | |
726f6388 | 6295 | .SM |
ccc6cda3 JA |
6296 | .B HISTIGNORE |
6297 | variables may be set to cause the shell to save only a subset of the | |
6298 | commands entered. | |
6299 | The | |
6300 | .B cmdhist | |
6301 | shell option, if enabled, causes the shell to attempt to save each | |
6302 | line of a multi-line command in the same history entry, adding | |
6303 | semicolons where necessary to preserve syntactic correctness. | |
6304 | The | |
6305 | .B lithist | |
6306 | shell option causes the shell to save the command with embedded newlines | |
6307 | instead of semicolons. See the description of the | |
6308 | .B shopt | |
6309 | builtin below under | |
6310 | .SM | |
6311 | .B "SHELL BUILTIN COMMANDS" | |
6312 | for information on setting and unsetting shell options. | |
726f6388 JA |
6313 | .SH "HISTORY EXPANSION" |
6314 | .PP | |
6315 | The shell supports a history expansion feature that | |
6316 | is similar to the history expansion in | |
6317 | .BR csh. | |
6318 | This section describes what syntax features are available. This | |
6319 | feature is enabled by default for interactive shells, and can be | |
6320 | disabled using the | |
6321 | .B \+H | |
6322 | option to the | |
6323 | .B set | |
6324 | builtin command (see | |
6325 | .SM | |
6326 | .B SHELL BUILTIN COMMANDS | |
ccc6cda3 JA |
6327 | below). Non-interactive shells do not perform history expansion |
6328 | by default. | |
6329 | .PP | |
6330 | History expansions introduce words from the history list into | |
6331 | the input stream, making it easy to repeat commands, insert the | |
6332 | arguments to a previous command into the current input line, or | |
6333 | fix errors in previous commands quickly. | |
726f6388 JA |
6334 | .PP |
6335 | History expansion is performed immediately after a complete line | |
6336 | is read, before the shell breaks it into words. | |
ccc6cda3 | 6337 | It takes place in two parts. |
cce855bc | 6338 | The first is to determine which line from the history list |
ccc6cda3 JA |
6339 | to use during substitution. |
6340 | The second is to select portions of that line for inclusion into | |
6341 | the current one. | |
cce855bc | 6342 | The line selected from the history is the \fIevent\fP, |
ccc6cda3 JA |
6343 | and the portions of that line that are acted upon are \fIwords\fP. |
6344 | Various \fImodifiers\fP are available to manipulate the selected words. | |
6345 | The line is broken into words in the same fashion as when reading input, | |
6346 | so that several \fImetacharacter\fP-separated words surrounded by | |
cce855bc | 6347 | quotes are considered one word. |
ccc6cda3 JA |
6348 | History expansions are introduced by the appearance of the |
6349 | history expansion character, which is \^\fB!\fP\^ by default. | |
6350 | Only backslash (\^\fB\e\fP\^) and single quotes can quote | |
6351 | the history expansion character. | |
6352 | .PP | |
d3a24ed2 CR |
6353 | Several characters inhibit history expansion if found immediately |
6354 | following the history expansion character, even if it is unquoted: | |
6355 | space, tab, newline, carriage return, and \fB=\fP. | |
6356 | If the \fBextglob\fP shell option is enabled, \fB(\fP will also | |
6357 | inhibit expansion. | |
6358 | .PP | |
ccc6cda3 JA |
6359 | Several shell options settable with the |
6360 | .B shopt | |
6361 | builtin may be used to tailor the behavior of history expansion. | |
6362 | If the | |
6363 | .B histverify | |
6364 | shell option is enabled (see the description of the | |
6365 | .B shopt | |
984a1947 | 6366 | builtin below), and |
ccc6cda3 JA |
6367 | .B readline |
6368 | is being used, history substitutions are not immediately passed to | |
6369 | the shell parser. | |
6370 | Instead, the expanded line is reloaded into the | |
6371 | .B readline | |
6372 | editing buffer for further modification. | |
6373 | If | |
6374 | .B readline | |
6375 | is being used, and the | |
6376 | .B histreedit | |
6377 | shell option is enabled, a failed history substitution will be reloaded | |
6378 | into the | |
6379 | .B readline | |
6380 | editing buffer for correction. | |
6381 | The | |
6382 | .B \-p | |
6383 | option to the | |
6384 | .B history | |
6385 | builtin command may be used to see what a history expansion will | |
6386 | do before using it. | |
6387 | The | |
6388 | .B \-s | |
6389 | option to the | |
6390 | .B history | |
6391 | builtin may be used to add commands to the end of the history list | |
6392 | without actually executing them, so that they are available for | |
6393 | subsequent recall. | |
726f6388 JA |
6394 | .PP |
6395 | The shell allows control of the various characters used by the | |
6396 | history expansion mechanism (see the description of | |
6397 | .B histchars | |
6398 | above under | |
6399 | .BR "Shell Variables" ). | |
d3ad40de CR |
6400 | The shell uses |
6401 | the history comment character to mark history timestamps when | |
6402 | writing the history file. | |
726f6388 JA |
6403 | .SS Event Designators |
6404 | .PP | |
6405 | An event designator is a reference to a command line entry in the | |
6406 | history list. | |
5f8cde23 CR |
6407 | Unless the reference is absolute, events are relative to the current |
6408 | position in the history list. | |
726f6388 JA |
6409 | .PP |
6410 | .PD 0 | |
6411 | .TP | |
6412 | .B ! | |
6413 | Start a history substitution, except when followed by a | |
6414 | .BR blank , | |
d3a24ed2 CR |
6415 | newline, carriage return, = |
6416 | or ( (when the \fBextglob\fP shell option is enabled using | |
6417 | the \fBshopt\fP builtin). | |
726f6388 | 6418 | .TP |
726f6388 JA |
6419 | .B !\fIn\fR |
6420 | Refer to command line | |
6421 | .IR n . | |
6422 | .TP | |
6423 | .B !\-\fIn\fR | |
5f8cde23 | 6424 | Refer to the current command minus |
726f6388 JA |
6425 | .IR n . |
6426 | .TP | |
ccc6cda3 JA |
6427 | .B !! |
6428 | Refer to the previous command. This is a synonym for `!\-1'. | |
6429 | .TP | |
726f6388 | 6430 | .B !\fIstring\fR |
5f8cde23 CR |
6431 | Refer to the most recent command preceding the current position in the |
6432 | history list starting with | |
726f6388 JA |
6433 | .IR string . |
6434 | .TP | |
6435 | .B !?\fIstring\fR\fB[?]\fR | |
5f8cde23 CR |
6436 | Refer to the most recent command preceding the current postition in the |
6437 | history list containing | |
726f6388 | 6438 | .IR string . |
ccc6cda3 JA |
6439 | The trailing \fB?\fP may be omitted if |
6440 | .I string | |
6441 | is followed immediately by a newline. | |
726f6388 JA |
6442 | .TP |
6443 | .B \d\s+2^\s-2\u\fIstring1\fP\d\s+2^\s-2\u\fIstring2\fP\d\s+2^\s-2\u | |
5f8cde23 | 6444 | Quick substitution. Repeat the previous command, replacing |
726f6388 JA |
6445 | .I string1 |
6446 | with | |
6447 | .IR string2 . | |
6448 | Equivalent to | |
6449 | ``!!:s/\fIstring1\fP/\fIstring2\fP/'' | |
6450 | (see \fBModifiers\fP below). | |
6451 | .TP | |
6452 | .B !# | |
6453 | The entire command line typed so far. | |
6454 | .PD | |
6455 | .SS Word Designators | |
6456 | .PP | |
ccc6cda3 | 6457 | Word designators are used to select desired words from the event. |
726f6388 JA |
6458 | A |
6459 | .B : | |
ccc6cda3 | 6460 | separates the event specification from the word designator. |
cce855bc | 6461 | It may be omitted if the word designator begins with a |
726f6388 JA |
6462 | .BR ^ , |
6463 | .BR $ , | |
6464 | .BR * , | |
ccc6cda3 | 6465 | .BR \- , |
726f6388 JA |
6466 | or |
6467 | .BR % . | |
6468 | Words are numbered from the beginning of the line, | |
ccc6cda3 JA |
6469 | with the first word being denoted by 0 (zero). |
6470 | Words are inserted into the current line separated by single spaces. | |
726f6388 JA |
6471 | .PP |
6472 | .PD 0 | |
6473 | .TP | |
6474 | .B 0 (zero) | |
6475 | The zeroth word. For the shell, this is the command | |
6476 | word. | |
6477 | .TP | |
6478 | .I n | |
6479 | The \fIn\fRth word. | |
6480 | .TP | |
6481 | .B ^ | |
6482 | The first argument. That is, word 1. | |
6483 | .TP | |
6484 | .B $ | |
6485 | The last argument. | |
6486 | .TP | |
6487 | .B % | |
6488 | The word matched by the most recent `?\fIstring\fR?' search. | |
6489 | .TP | |
6490 | .I x\fB\-\fPy | |
6491 | A range of words; `\-\fIy\fR' abbreviates `0\-\fIy\fR'. | |
6492 | .TP | |
6493 | .B * | |
6494 | All of the words but the zeroth. This is a synonym | |
6495 | for `\fI1\-$\fP'. It is not an error to use | |
6496 | .B * | |
6497 | if there is just one | |
6498 | word in the event; the empty string is returned in that case. | |
6499 | .TP | |
6500 | .B x* | |
6501 | Abbreviates \fIx\-$\fP. | |
6502 | .TP | |
6503 | .B x\- | |
6504 | Abbreviates \fIx\-$\fP like \fBx*\fP, but omits the last word. | |
6505 | .PD | |
ccc6cda3 JA |
6506 | .PP |
6507 | If a word designator is supplied without an event specification, the | |
6508 | previous command is used as the event. | |
726f6388 JA |
6509 | .SS Modifiers |
6510 | .PP | |
ccc6cda3 JA |
6511 | After the optional word designator, there may appear a sequence of |
6512 | one or more of the following modifiers, each preceded by a `:'. | |
726f6388 JA |
6513 | .PP |
6514 | .PD 0 | |
6515 | .PP | |
6516 | .TP | |
6517 | .B h | |
b28ff8c9 | 6518 | Remove a trailing filename component, leaving only the head. |
ccc6cda3 JA |
6519 | .TP |
6520 | .B t | |
b28ff8c9 | 6521 | Remove all leading filename components, leaving the tail. |
726f6388 JA |
6522 | .TP |
6523 | .B r | |
6524 | Remove a trailing suffix of the form \fI.xxx\fP, leaving the | |
6525 | basename. | |
6526 | .TP | |
6527 | .B e | |
6528 | Remove all but the trailing suffix. | |
6529 | .TP | |
726f6388 JA |
6530 | .B p |
6531 | Print the new command but do not execute it. | |
6532 | .TP | |
6533 | .B q | |
6534 | Quote the substituted words, escaping further substitutions. | |
6535 | .TP | |
cce855bc JA |
6536 | .B x |
6537 | Quote the substituted words as with | |
6538 | .BR q , | |
6539 | but break into words at | |
6540 | .B blanks | |
6541 | and newlines. | |
726f6388 | 6542 | .TP |
cce855bc JA |
6543 | .B s/\fIold\fP/\fInew\fP/ |
6544 | Substitute | |
6545 | .I new | |
6546 | for the first occurrence of | |
6547 | .I old | |
6548 | in the event line. Any delimiter can be used in place of /. The | |
6549 | final delimiter is optional if it is the last character of the | |
6550 | event line. The delimiter may be quoted in | |
6551 | .I old | |
6552 | and | |
6553 | .I new | |
6554 | with a single backslash. If & appears in | |
6555 | .IR new , | |
6556 | it is replaced by | |
6557 | .IR old . | |
6558 | A single backslash will quote the &. If | |
6559 | .I old | |
6560 | is null, it is set to the last | |
6561 | .I old | |
6562 | substituted, or, if no previous history substitutions took place, | |
6563 | the last | |
6564 | .I string | |
6565 | in a | |
6566 | .B !?\fIstring\fR\fB[?]\fR | |
6567 | search. | |
ccc6cda3 | 6568 | .TP |
cce855bc JA |
6569 | .B & |
6570 | Repeat the previous substitution. | |
6571 | .TP | |
6572 | .B g | |
6573 | Cause changes to be applied over the entire event line. This is | |
6574 | used in conjunction with `\fB:s\fP' (e.g., `\fB:gs/\fIold\fP/\fInew\fP/\fR') | |
6575 | or `\fB:&\fP'. If used with | |
6576 | `\fB:s\fP', any delimiter can be used | |
6577 | in place of /, and the final delimiter is optional | |
6578 | if it is the last character of the event line. | |
d3a24ed2 CR |
6579 | An \fBa\fP may be used as a synonym for \fBg\fP. |
6580 | .TP | |
6581 | .B G | |
6582 | Apply the following `\fBs\fP' modifier once to each word in the event line. | |
726f6388 | 6583 | .PD |
726f6388 JA |
6584 | .SH "SHELL BUILTIN COMMANDS" |
6585 | .\" start of bash_builtins | |
6586 | .zZ | |
ccc6cda3 JA |
6587 | .PP |
6588 | Unless otherwise noted, each builtin command documented in this | |
6589 | section as accepting options preceded by | |
6590 | .B \- | |
6591 | accepts | |
6592 | .B \-\- | |
6593 | to signify the end of the options. | |
6932f7f5 CR |
6594 | The \fB:\fP, \fBtrue\fP, \fBfalse\fP, and \fBtest\fP builtins |
6595 | do not accept options and do not treat \fB\-\-\fP specially. | |
6596 | The \fBexit\fP, \fBlogout\fP, \fBbreak\fP, \fBcontinue\fP, \fBlet\fP, | |
6597 | and \fBshift\fP builtins accept and process arguments beginning with | |
6598 | \fB\-\fP without requiring \fB\-\-\fP. | |
6599 | Other builtins that accept arguments but are not specified as accepting | |
6600 | options interpret arguments beginning with \fB\-\fP as invalid options and | |
6601 | require \fB\-\-\fP to prevent this interpretation. | |
ccc6cda3 | 6602 | .sp .5 |
726f6388 JA |
6603 | .PD 0 |
6604 | .TP | |
6605 | \fB:\fP [\fIarguments\fP] | |
6606 | .PD | |
6607 | No effect; the command does nothing beyond expanding | |
6608 | .I arguments | |
6609 | and performing any specified | |
6610 | redirections. A zero exit code is returned. | |
6611 | .TP | |
726f6388 | 6612 | \fB .\| \fP \fIfilename\fP [\fIarguments\fP] |
7117c2d2 | 6613 | .PD 0 |
726f6388 JA |
6614 | .TP |
6615 | \fBsource\fP \fIfilename\fP [\fIarguments\fP] | |
6616 | .PD | |
6617 | Read and execute commands from | |
6618 | .I filename | |
6619 | in the current | |
6620 | shell environment and return the exit status of the last command | |
6621 | executed from | |
6622 | .IR filename . | |
6623 | If | |
6624 | .I filename | |
b28ff8c9 | 6625 | does not contain a slash, filenames in |
726f6388 JA |
6626 | .SM |
6627 | .B PATH | |
6628 | are used to find the directory containing | |
6629 | .IR filename . | |
6630 | The file searched for in | |
6631 | .SM | |
6632 | .B PATH | |
28ef6c31 JA |
6633 | need not be executable. |
6634 | When \fBbash\fP is not in \fIposix mode\fP, the current directory is | |
726f6388 JA |
6635 | searched if no file is found in |
6636 | .SM | |
6637 | .BR PATH . | |
ccc6cda3 JA |
6638 | If the |
6639 | .B sourcepath | |
6640 | option to the | |
6641 | .B shopt | |
6642 | builtin command is turned off, the | |
6643 | .SM | |
6644 | .B PATH | |
6645 | is not searched. | |
726f6388 | 6646 | If any \fIarguments\fP are supplied, they become the positional |
ccc6cda3 | 6647 | parameters when \fIfilename\fP is executed. Otherwise the positional |
726f6388 JA |
6648 | parameters are unchanged. |
6649 | The return status is the status of the last command exited within | |
6650 | the script (0 if no commands are executed), and false if | |
6651 | .I filename | |
cce855bc | 6652 | is not found or cannot be read. |
726f6388 | 6653 | .TP |
ccc6cda3 JA |
6654 | \fBalias\fP [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
6655 | \fBAlias\fP with no arguments or with the | |
6656 | .B \-p | |
6657 | option prints the list of aliases in the form | |
6658 | \fBalias\fP \fIname\fP=\fIvalue\fP on standard output. | |
6659 | When arguments are supplied, an alias is defined for | |
6660 | each \fIname\fP whose \fIvalue\fP is given. | |
6661 | A trailing space in \fIvalue\fP causes the next word to be | |
6662 | checked for alias substitution when the alias is expanded. | |
6663 | For each \fIname\fP in the argument list for which no \fIvalue\fP | |
6664 | is supplied, the name and value of the alias is printed. | |
6665 | \fBAlias\fP returns true unless a \fIname\fP is given for which | |
6666 | no alias has been defined. | |
726f6388 | 6667 | .TP |
de3341d1 CR |
6668 | \fBbg\fP [\fIjobspec\fP ...] |
6669 | Resume each suspended job \fIjobspec\fP in the background, as if it | |
cce855bc | 6670 | had been started with |
726f6388 | 6671 | .BR & . |
d3ad40de CR |
6672 | If |
6673 | .I jobspec | |
6674 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
726f6388 JA |
6675 | .B bg |
6676 | .I jobspec | |
6677 | returns 0 unless run when job control is disabled or, when run with | |
ff247e74 CR |
6678 | job control enabled, any specified \fIjobspec\fP was not found |
6679 | or was started without job control. | |
726f6388 | 6680 | .TP |
cce855bc | 6681 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-lpsvPSV\fP] |
7117c2d2 | 6682 | .PD 0 |
cce855bc JA |
6683 | .TP |
6684 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] [\fB\-q\fP \fIfunction\fP] [\fB\-u\fP \fIfunction\fP] [\fB\-r\fP \fIkeyseq\fP] | |
726f6388 | 6685 | .TP |
ccc6cda3 | 6686 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-f\fP \fIfilename\fP |
726f6388 | 6687 | .TP |
bb70624e JA |
6688 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fB\-x\fP \fIkeyseq\fP:\fIshell\-command\fP |
6689 | .TP | |
ccc6cda3 | 6690 | \fBbind\fP [\fB\-m\fP \fIkeymap\fP] \fIkeyseq\fP:\fIfunction\-name\fP |
7117c2d2 JA |
6691 | .TP |
6692 | \fBbind\fP \fIreadline\-command\fP | |
726f6388 JA |
6693 | .PD |
6694 | Display current | |
6695 | .B readline | |
7117c2d2 | 6696 | key and function bindings, bind a key sequence to a |
726f6388 | 6697 | .B readline |
7117c2d2 JA |
6698 | function or macro, or set a |
6699 | .B readline | |
6700 | variable. | |
6701 | Each non-option argument is a command as it would appear in | |
726f6388 | 6702 | .IR .inputrc , |
7117c2d2 JA |
6703 | but each binding or command must be passed as a separate argument; |
6704 | e.g., '"\eC\-x\eC\-r": re\-read\-init\-file'. | |
6705 | Options, if supplied, have the following meanings: | |
726f6388 JA |
6706 | .RS |
6707 | .PD 0 | |
6708 | .TP | |
6709 | .B \-m \fIkeymap\fP | |
6710 | Use | |
6711 | .I keymap | |
6712 | as the keymap to be affected by the subsequent bindings. | |
6713 | Acceptable | |
6714 | .I keymap | |
6715 | names are | |
ccc6cda3 | 6716 | \fIemacs, emacs\-standard, emacs\-meta, emacs\-ctlx, vi, |
28ef6c31 | 6717 | vi\-move, vi\-command\fP, and |
ccc6cda3 JA |
6718 | .IR vi\-insert . |
6719 | \fIvi\fP is equivalent to \fIvi\-command\fP; \fIemacs\fP is | |
6720 | equivalent to \fIemacs\-standard\fP. | |
726f6388 JA |
6721 | .TP |
6722 | .B \-l | |
ccc6cda3 JA |
6723 | List the names of all \fBreadline\fP functions. |
6724 | .TP | |
6725 | .B \-p | |
6726 | Display \fBreadline\fP function names and bindings in such a way | |
6727 | that they can be re-read. | |
6728 | .TP | |
6729 | .B \-P | |
6730 | List current \fBreadline\fP function names and bindings. | |
726f6388 | 6731 | .TP |
ccc6cda3 JA |
6732 | .B \-s |
6733 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6734 | they output in such a way that they can be re-read. | |
6735 | .TP | |
6736 | .B \-S | |
6737 | Display \fBreadline\fP key sequences bound to macros and the strings | |
6738 | they output. | |
726f6388 | 6739 | .TP |
d3ad40de CR |
6740 | .B \-v |
6741 | Display \fBreadline\fP variable names and values in such a way that they | |
6742 | can be re-read. | |
6743 | .TP | |
6744 | .B \-V | |
6745 | List current \fBreadline\fP variable names and values. | |
6746 | .TP | |
726f6388 | 6747 | .B \-f \fIfilename\fP |
ccc6cda3 | 6748 | Read key bindings from \fIfilename\fP. |
726f6388 JA |
6749 | .TP |
6750 | .B \-q \fIfunction\fP | |
ccc6cda3 JA |
6751 | Query about which keys invoke the named \fIfunction\fP. |
6752 | .TP | |
cce855bc JA |
6753 | .B \-u \fIfunction\fP |
6754 | Unbind all keys bound to the named \fIfunction\fP. | |
6755 | .TP | |
ccc6cda3 JA |
6756 | .B \-r \fIkeyseq\fP |
6757 | Remove any current binding for \fIkeyseq\fP. | |
bb70624e JA |
6758 | .TP |
6759 | .B \-x \fIkeyseq\fP:\fIshell\-command\fP | |
6760 | Cause \fIshell\-command\fP to be executed whenever \fIkeyseq\fP is | |
6761 | entered. | |
8943768b | 6762 | When \fIshell\-command\fP is executed, the shell sets the |
984a1947 | 6763 | .SM |
8943768b CR |
6764 | .B READLINE_LINE |
6765 | variable to the contents of the \fBreadline\fP line buffer and the | |
984a1947 | 6766 | .SM |
8943768b CR |
6767 | .B READLINE_POINT |
6768 | variable to the current location of the insertion point. | |
6769 | If the executed command changes the value of | |
984a1947 | 6770 | .SM |
8943768b CR |
6771 | .B READLINE_LINE |
6772 | or | |
984a1947 | 6773 | .SM |
8943768b CR |
6774 | .BR READLINE_POINT , |
6775 | those new values will be reflected in the editing state. | |
726f6388 JA |
6776 | .PD |
6777 | .PP | |
6778 | The return value is 0 unless an unrecognized option is given or an | |
6779 | error occurred. | |
6780 | .RE | |
6781 | .TP | |
6782 | \fBbreak\fP [\fIn\fP] | |
6783 | Exit from within a | |
6784 | .BR for , | |
6785 | .BR while , | |
ccc6cda3 | 6786 | .BR until , |
726f6388 | 6787 | or |
ccc6cda3 | 6788 | .B select |
726f6388 JA |
6789 | loop. If \fIn\fP is specified, break \fIn\fP levels. |
6790 | .I n | |
6791 | must be \(>= 1. If | |
6792 | .I n | |
6793 | is greater than the number of enclosing loops, all enclosing loops | |
33fe8777 CR |
6794 | are exited. |
6795 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 JA |
6796 | .TP |
6797 | \fBbuiltin\fP \fIshell\-builtin\fP [\fIarguments\fP] | |
6798 | Execute the specified shell builtin, passing it | |
6799 | .IR arguments , | |
6800 | and return its exit status. | |
cce855bc | 6801 | This is useful when defining a |
726f6388 | 6802 | function whose name is the same as a shell builtin, |
cce855bc JA |
6803 | retaining the functionality of the builtin within the function. |
6804 | The \fBcd\fP builtin is commonly redefined this way. | |
6805 | The return status is false if | |
726f6388 JA |
6806 | .I shell\-builtin |
6807 | is not a shell builtin command. | |
6808 | .TP | |
6a8fd0ed CR |
6809 | \fBcaller\fP [\fIexpr\fP] |
6810 | Returns the context of any active subroutine call (a shell function or | |
5cdaaf76 | 6811 | a script executed with the \fB.\fP or \fBsource\fP builtins). |
6a8fd0ed CR |
6812 | Without \fIexpr\fP, \fBcaller\fP displays the line number and source |
6813 | filename of the current subroutine call. | |
6814 | If a non-negative integer is supplied as \fIexpr\fP, \fBcaller\fP | |
6815 | displays the line number, subroutine name, and source file corresponding | |
6816 | to that position in the current execution call stack. This extra | |
6817 | information may be used, for example, to print a stack trace. The | |
6818 | current frame is frame 0. | |
6819 | The return value is 0 unless the shell is not executing a subroutine | |
6820 | call or \fIexpr\fP does not correspond to a valid position in the | |
6821 | call stack. | |
6822 | .TP | |
220537f2 | 6823 | \fBcd\fP [\fB\-L\fP|[\fB\-P\fP [\fB\-e\fP]]] [\fIdir\fP] |
726f6388 JA |
6824 | Change the current directory to \fIdir\fP. The variable |
6825 | .SM | |
6826 | .B HOME | |
6827 | is the | |
6828 | default | |
6829 | .IR dir . | |
6830 | The variable | |
6831 | .SM | |
6832 | .B CDPATH | |
ccc6cda3 | 6833 | defines the search path for the directory containing |
726f6388 | 6834 | .IR dir . |
ccc6cda3 JA |
6835 | Alternative directory names in |
6836 | .SM | |
6837 | .B CDPATH | |
6838 | are separated by a colon (:). A null directory name in | |
726f6388 JA |
6839 | .SM |
6840 | .B CDPATH | |
ccc6cda3 | 6841 | is the same as the current directory, i.e., ``\fB.\fP''. If |
726f6388 JA |
6842 | .I dir |
6843 | begins with a slash (/), | |
6844 | then | |
6845 | .SM | |
6846 | .B CDPATH | |
ccc6cda3 JA |
6847 | is not used. The |
6848 | .B \-P | |
6849 | option says to use the physical directory structure instead of | |
6850 | following symbolic links (see also the | |
6851 | .B \-P | |
6852 | option to the | |
6853 | .B set | |
6854 | builtin command); the | |
6855 | .B \-L | |
220537f2 CR |
6856 | option forces symbolic links to be followed. |
6857 | If the | |
6858 | .B \-e | |
6859 | option is supplied with | |
6860 | .BR \-P , | |
6861 | and the current working directory cannot be successfully determined | |
6862 | after a successful directory change, \fBcd\fP will return an unsuccessful | |
6863 | status. | |
6864 | An argument of | |
726f6388 | 6865 | .B \- |
19baff85 | 6866 | is converted to |
726f6388 | 6867 | .SM |
19baff85 CR |
6868 | .B $OLDPWD |
6869 | before the directory change is attempted. | |
984a1947 CR |
6870 | If a non-empty directory name from |
6871 | .SM | |
6872 | .B CDPATH | |
6873 | is used, or if | |
d3a24ed2 CR |
6874 | \fB\-\fP is the first argument, and the directory change is |
6875 | successful, the absolute pathname of the new working directory is | |
6876 | written to the standard output. | |
726f6388 JA |
6877 | The return value is true if the directory was successfully changed; |
6878 | false otherwise. | |
6879 | .TP | |
ccc6cda3 | 6880 | \fBcommand\fP [\fB\-pVv\fP] \fIcommand\fP [\fIarg\fP ...] |
726f6388 JA |
6881 | Run |
6882 | .I command | |
6883 | with | |
6884 | .I args | |
6885 | suppressing the normal shell function lookup. Only builtin | |
6886 | commands or commands found in the | |
6887 | .SM | |
6888 | .B PATH | |
6889 | are executed. If the | |
6890 | .B \-p | |
6891 | option is given, the search for | |
6892 | .I command | |
6893 | is performed using a default value for | |
984a1947 | 6894 | .SM |
726f6388 JA |
6895 | .B PATH |
6896 | that is guaranteed to find all of the standard utilities. | |
6897 | If either the | |
6898 | .B \-V | |
6899 | or | |
6900 | .B \-v | |
6901 | option is supplied, a description of | |
6902 | .I command | |
6903 | is printed. The | |
6904 | .B \-v | |
b28ff8c9 | 6905 | option causes a single word indicating the command or filename |
726f6388 JA |
6906 | used to invoke |
6907 | .I command | |
cce855bc | 6908 | to be displayed; the |
726f6388 JA |
6909 | .B \-V |
6910 | option produces a more verbose description. | |
726f6388 JA |
6911 | If the |
6912 | .B \-V | |
6913 | or | |
6914 | .B \-v | |
6915 | option is supplied, the exit status is 0 if | |
6916 | .I command | |
6917 | was found, and 1 if not. If neither option is supplied and | |
6918 | an error occurred or | |
6919 | .I command | |
6920 | cannot be found, the exit status is 127. Otherwise, the exit status of the | |
6921 | .B command | |
6922 | builtin is the exit status of | |
6923 | .IR command . | |
6924 | .TP | |
bb70624e JA |
6925 | \fBcompgen\fP [\fIoption\fP] [\fIword\fP] |
6926 | Generate possible completion matches for \fIword\fP according to | |
6927 | the \fIoption\fPs, which may be any option accepted by the | |
6928 | .B complete | |
6929 | builtin with the exception of \fB\-p\fP and \fB\-r\fP, and write | |
6930 | the matches to the standard output. | |
6931 | When using the \fB\-F\fP or \fB\-C\fP options, the various shell variables | |
6932 | set by the programmable completion facilities, while available, will not | |
6933 | have useful values. | |
6934 | .sp 1 | |
6935 | The matches will be generated in the same way as if the programmable | |
6936 | completion code had generated them directly from a completion specification | |
6937 | with the same flags. | |
6938 | If \fIword\fP is specified, only those completions matching \fIword\fP | |
6939 | will be displayed. | |
6940 | .sp 1 | |
6941 | The return value is true unless an invalid option is supplied, or no | |
6942 | matches were generated. | |
6943 | .TP | |
3eb2d94a | 6944 | \fBcomplete\fP [\fB\-abcdefgjksuv\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-DE\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] |
bb70624e | 6945 | .br |
d3ad40de | 6946 | [\fB\-X\fP \fIfilterpat\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] \fIname\fP [\fIname ...\fP] |
7117c2d2 | 6947 | .PD 0 |
bb70624e | 6948 | .TP |
3eb2d94a | 6949 | \fBcomplete\fP \fB\-pr\fP [\fB\-DE\fP] [\fIname\fP ...] |
bb70624e JA |
6950 | .PD |
6951 | Specify how arguments to each \fIname\fP should be completed. | |
6952 | If the \fB\-p\fP option is supplied, or if no options are supplied, | |
6953 | existing completion specifications are printed in a way that allows | |
6954 | them to be reused as input. | |
6955 | The \fB\-r\fP option removes a completion specification for | |
6956 | each \fIname\fP, or, if no \fIname\fPs are supplied, all | |
6957 | completion specifications. | |
3eb2d94a CR |
6958 | The \fB\-D\fP option indicates that the remaining options and actions should |
6959 | apply to the ``default'' command completion; that is, completion attempted | |
6960 | on a command for which no completion has previously been defined. | |
6a8fd0ed CR |
6961 | The \fB\-E\fP option indicates that the remaining options and actions should |
6962 | apply to ``empty'' command completion; that is, completion attempted on a | |
6963 | blank line. | |
bb70624e JA |
6964 | .sp 1 |
6965 | The process of applying these completion specifications when word completion | |
6966 | is attempted is described above under \fBProgrammable Completion\fP. | |
6967 | .sp 1 | |
6968 | Other options, if specified, have the following meanings. | |
6969 | The arguments to the \fB\-G\fP, \fB\-W\fP, and \fB\-X\fP options | |
6970 | (and, if necessary, the \fB\-P\fP and \fB\-S\fP options) | |
6971 | should be quoted to protect them from expansion before the | |
6972 | .B complete | |
6973 | builtin is invoked. | |
6974 | .RS | |
6975 | .PD 0 | |
6976 | .TP 8 | |
28ef6c31 JA |
6977 | \fB\-o\fP \fIcomp-option\fP |
6978 | The \fIcomp-option\fP controls several aspects of the compspec's behavior | |
6979 | beyond the simple generation of completions. | |
6980 | \fIcomp-option\fP may be one of: | |
6981 | .RS | |
6982 | .TP 8 | |
d3a24ed2 CR |
6983 | .B bashdefault |
6984 | Perform the rest of the default \fBbash\fP completions if the compspec | |
6985 | generates no matches. | |
6986 | .TP 8 | |
28ef6c31 | 6987 | .B default |
7117c2d2 JA |
6988 | Use readline's default filename completion if the compspec generates |
6989 | no matches. | |
28ef6c31 JA |
6990 | .TP 8 |
6991 | .B dirnames | |
6992 | Perform directory name completion if the compspec generates no matches. | |
6993 | .TP 8 | |
6994 | .B filenames | |
6995 | Tell readline that the compspec generates filenames, so it can perform any | |
e77a3058 CR |
6996 | filename\-specific processing (like adding a slash to directory names, |
6997 | quoting special characters, or suppressing trailing spaces). | |
6998 | Intended to be used with shell functions. | |
7117c2d2 JA |
6999 | .TP 8 |
7000 | .B nospace | |
7001 | Tell readline not to append a space (the default) to words completed at | |
7002 | the end of the line. | |
301e2142 CR |
7003 | .TP 8 |
7004 | .B plusdirs | |
7005 | After any matches defined by the compspec are generated, | |
7006 | directory name completion is attempted and any | |
7007 | matches are added to the results of the other actions. | |
28ef6c31 JA |
7008 | .RE |
7009 | .TP 8 | |
bb70624e JA |
7010 | \fB\-A\fP \fIaction\fP |
7011 | The \fIaction\fP may be one of the following to generate a list of possible | |
7012 | completions: | |
7013 | .RS | |
7014 | .TP 8 | |
7015 | .B alias | |
7016 | Alias names. May also be specified as \fB\-a\fP. | |
7017 | .TP 8 | |
7018 | .B arrayvar | |
7019 | Array variable names. | |
7020 | .TP 8 | |
7021 | .B binding | |
7022 | \fBReadline\fP key binding names. | |
7023 | .TP 8 | |
7024 | .B builtin | |
7025 | Names of shell builtin commands. May also be specified as \fB\-b\fP. | |
7026 | .TP 8 | |
7027 | .B command | |
7028 | Command names. May also be specified as \fB\-c\fP. | |
7029 | .TP 8 | |
7030 | .B directory | |
7031 | Directory names. May also be specified as \fB\-d\fP. | |
7032 | .TP 8 | |
7033 | .B disabled | |
7034 | Names of disabled shell builtins. | |
7035 | .TP 8 | |
7036 | .B enabled | |
7037 | Names of enabled shell builtins. | |
7038 | .TP 8 | |
7039 | .B export | |
7040 | Names of exported shell variables. May also be specified as \fB\-e\fP. | |
7041 | .TP 8 | |
7042 | .B file | |
7043 | File names. May also be specified as \fB\-f\fP. | |
7044 | .TP 8 | |
7045 | .B function | |
7046 | Names of shell functions. | |
7047 | .TP 8 | |
f73dda09 JA |
7048 | .B group |
7049 | Group names. May also be specified as \fB\-g\fP. | |
7050 | .TP 8 | |
bb70624e JA |
7051 | .B helptopic |
7052 | Help topics as accepted by the \fBhelp\fP builtin. | |
7053 | .TP 8 | |
7054 | .B hostname | |
7055 | Hostnames, as taken from the file specified by the | |
7056 | .SM | |
7057 | .B HOSTFILE | |
7058 | shell variable. | |
7059 | .TP 8 | |
7060 | .B job | |
7061 | Job names, if job control is active. May also be specified as \fB\-j\fP. | |
7062 | .TP 8 | |
7063 | .B keyword | |
7064 | Shell reserved words. May also be specified as \fB\-k\fP. | |
7065 | .TP 8 | |
7066 | .B running | |
7067 | Names of running jobs, if job control is active. | |
7068 | .TP 8 | |
7117c2d2 JA |
7069 | .B service |
7070 | Service names. May also be specified as \fB\-s\fP. | |
7071 | .TP 8 | |
bb70624e JA |
7072 | .B setopt |
7073 | Valid arguments for the \fB\-o\fP option to the \fBset\fP builtin. | |
7074 | .TP 8 | |
7075 | .B shopt | |
7076 | Shell option names as accepted by the \fBshopt\fP builtin. | |
7077 | .TP 8 | |
7078 | .B signal | |
7079 | Signal names. | |
7080 | .TP 8 | |
7081 | .B stopped | |
7082 | Names of stopped jobs, if job control is active. | |
7083 | .TP 8 | |
7084 | .B user | |
7085 | User names. May also be specified as \fB\-u\fP. | |
7086 | .TP 8 | |
7087 | .B variable | |
7088 | Names of all shell variables. May also be specified as \fB\-v\fP. | |
7089 | .RE | |
7090 | .TP 8 | |
bb70624e JA |
7091 | \fB\-C\fP \fIcommand\fP |
7092 | \fIcommand\fP is executed in a subshell environment, and its output is | |
7093 | used as the possible completions. | |
7094 | .TP 8 | |
7095 | \fB\-F\fP \fIfunction\fP | |
7096 | The shell function \fIfunction\fP is executed in the current shell | |
7097 | environment. | |
7098 | When it finishes, the possible completions are retrieved from the value | |
7099 | of the | |
7100 | .SM | |
7101 | .B COMPREPLY | |
7102 | array variable. | |
7103 | .TP 8 | |
5cdaaf76 CR |
7104 | \fB\-G\fP \fIglobpat\fP |
7105 | The pathname expansion pattern \fIglobpat\fP is expanded to generate | |
7106 | the possible completions. | |
bb70624e JA |
7107 | .TP 8 |
7108 | \fB\-P\fP \fIprefix\fP | |
7109 | \fIprefix\fP is added at the beginning of each possible completion | |
7110 | after all other options have been applied. | |
7111 | .TP 8 | |
7112 | \fB\-S\fP \fIsuffix\fP | |
7113 | \fIsuffix\fP is appended to each possible completion | |
7114 | after all other options have been applied. | |
5cdaaf76 CR |
7115 | .TP 8 |
7116 | \fB\-W\fP \fIwordlist\fP | |
7117 | The \fIwordlist\fP is split using the characters in the | |
7118 | .SM | |
7119 | .B IFS | |
7120 | special variable as delimiters, and each resultant word is expanded. | |
7121 | The possible completions are the members of the resultant list which | |
7122 | match the word being completed. | |
7123 | .TP 8 | |
7124 | \fB\-X\fP \fIfilterpat\fP | |
7125 | \fIfilterpat\fP is a pattern as used for pathname expansion. | |
7126 | It is applied to the list of possible completions generated by the | |
7127 | preceding options and arguments, and each completion matching | |
7128 | \fIfilterpat\fP is removed from the list. | |
7129 | A leading \fB!\fP in \fIfilterpat\fP negates the pattern; in this | |
7130 | case, any completion not matching \fIfilterpat\fP is removed. | |
bb70624e JA |
7131 | .PD |
7132 | .PP | |
7133 | The return value is true unless an invalid option is supplied, an option | |
7134 | other than \fB\-p\fP or \fB\-r\fP is supplied without a \fIname\fP | |
7135 | argument, an attempt is made to remove a completion specification for | |
7136 | a \fIname\fP for which no specification exists, or | |
7137 | an error occurs adding a completion specification. | |
7138 | .RE | |
7139 | .TP | |
3eb2d94a | 7140 | \fBcompopt\fP [\fB\-o\fP \fIoption\fP] [\fB\-DE\fP] [\fB+o\fP \fIoption\fP] [\fIname\fP] |
6fbe7620 CR |
7141 | Modify completion options for each \fIname\fP according to the |
7142 | \fIoption\fPs, or for the | |
5cdaaf76 | 7143 | currently-executing completion if no \fIname\fPs are supplied. |
6fbe7620 CR |
7144 | If no \fIoption\fPs are given, display the completion options for each |
7145 | \fIname\fP or the current completion. | |
7146 | The possible values of \fIoption\fP are those valid for the \fBcomplete\fP | |
7147 | builtin described above. | |
3eb2d94a CR |
7148 | The \fB\-D\fP option indicates that the remaining options should |
7149 | apply to the ``default'' command completion; that is, completion attempted | |
7150 | on a command for which no completion has previously been defined. | |
7151 | The \fB\-E\fP option indicates that the remaining options should | |
7152 | apply to ``empty'' command completion; that is, completion attempted on a | |
7153 | blank line. | |
9c7f20c7 | 7154 | .sp 1 |
6fbe7620 CR |
7155 | The return value is true unless an invalid option is supplied, an attempt |
7156 | is made to modify the options for a \fIname\fP for which no completion | |
7157 | specification exists, or an output error occurs. | |
7158 | .TP | |
726f6388 JA |
7159 | \fBcontinue\fP [\fIn\fP] |
7160 | Resume the next iteration of the enclosing | |
7161 | .BR for , | |
7162 | .BR while , | |
ccc6cda3 | 7163 | .BR until , |
726f6388 | 7164 | or |
ccc6cda3 | 7165 | .B select |
726f6388 JA |
7166 | loop. |
7167 | If | |
7168 | .I n | |
7169 | is specified, resume at the \fIn\fPth enclosing loop. | |
7170 | .I n | |
7171 | must be \(>= 1. If | |
7172 | .I n | |
7173 | is greater than the number of enclosing loops, the last enclosing loop | |
33fe8777 CR |
7174 | (the ``top-level'' loop) is resumed. |
7175 | The return value is 0 unless \fIn\fP is not greater than or equal to 1. | |
726f6388 | 7176 | .TP |
6faad625 | 7177 | \fBdeclare\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7178 | .PD 0 |
726f6388 | 7179 | .TP |
6faad625 | 7180 | \fBtypeset\fP [\fB\-aAfFgilrtux\fP] [\fB\-p\fP] [\fIname\fP[=\fIvalue\fP] ...] |
726f6388 | 7181 | .PD |
ccc6cda3 JA |
7182 | Declare variables and/or give them attributes. |
7183 | If no \fIname\fPs are given then display the values of variables. | |
7184 | The | |
7185 | .B \-p | |
7186 | option will display the attributes and values of each | |
7187 | .IR name . | |
7188 | When | |
7189 | .B \-p | |
6fbe7620 CR |
7190 | is used with \fIname\fP arguments, additional options are ignored. |
7191 | When | |
7192 | .B \-p | |
7193 | is supplied without \fIname\fP arguments, it will display the attributes | |
7194 | and values of all variables having the attributes specified by the | |
7195 | additional options. | |
7196 | If no other options are supplied with \fB\-p\fP, \fBdeclare\fP will display | |
7197 | the attributes and values of all shell variables. The \fB\-f\fP option | |
7198 | will restrict the display to shell functions. | |
ccc6cda3 JA |
7199 | The |
7200 | .B \-F | |
7201 | option inhibits the display of function definitions; only the | |
7202 | function name and attributes are printed. | |
d3a24ed2 CR |
7203 | If the \fBextdebug\fP shell option is enabled using \fBshopt\fP, |
7204 | the source file name and line number where the function is defined | |
7205 | are displayed as well. The | |
ccc6cda3 JA |
7206 | .B \-F |
7207 | option implies | |
7208 | .BR \-f . | |
6faad625 CR |
7209 | The |
7210 | .B \-g | |
7211 | option forces variables to be created or modified at the global scope, | |
7212 | even when \fBdeclare\fP is executed in a shell function. | |
7213 | It is ignored in all other cases. | |
ccc6cda3 JA |
7214 | The following options can |
7215 | be used to restrict output to variables with the specified attribute or | |
7216 | to give variables attributes: | |
726f6388 JA |
7217 | .RS |
7218 | .PD 0 | |
7219 | .TP | |
ccc6cda3 | 7220 | .B \-a |
fdf670ea CR |
7221 | Each \fIname\fP is an indexed array variable (see |
7222 | .B Arrays | |
7223 | above). | |
7224 | .TP | |
7225 | .B \-A | |
7226 | Each \fIname\fP is an associative array variable (see | |
ccc6cda3 JA |
7227 | .B Arrays |
7228 | above). | |
7229 | .TP | |
726f6388 | 7230 | .B \-f |
ccc6cda3 JA |
7231 | Use function names only. |
7232 | .TP | |
7233 | .B \-i | |
7234 | The variable is treated as an integer; arithmetic evaluation (see | |
7235 | .SM | |
984a1947 CR |
7236 | .B "ARITHMETIC EVALUATION" |
7237 | above) is performed when the variable is assigned a value. | |
726f6388 | 7238 | .TP |
09767ff0 CR |
7239 | .B \-l |
7240 | When the variable is assigned a value, all upper-case characters are | |
7241 | converted to lower-case. | |
7242 | The upper-case attribute is disabled. | |
7243 | .TP | |
726f6388 JA |
7244 | .B \-r |
7245 | Make \fIname\fPs readonly. These names cannot then be assigned values | |
cce855bc | 7246 | by subsequent assignment statements or unset. |
726f6388 | 7247 | .TP |
7117c2d2 JA |
7248 | .B \-t |
7249 | Give each \fIname\fP the \fItrace\fP attribute. | |
76a8d78d CR |
7250 | Traced functions inherit the \fBDEBUG\fP and \fBRETURN\fP traps from |
7251 | the calling shell. | |
7117c2d2 JA |
7252 | The trace attribute has no special meaning for variables. |
7253 | .TP | |
09767ff0 CR |
7254 | .B \-u |
7255 | When the variable is assigned a value, all lower-case characters are | |
7256 | converted to upper-case. | |
7257 | The lower-case attribute is disabled. | |
7258 | .TP | |
726f6388 JA |
7259 | .B \-x |
7260 | Mark \fIname\fPs for export to subsequent commands via the environment. | |
726f6388 JA |
7261 | .PD |
7262 | .PP | |
7263 | Using `+' instead of `\-' | |
d3ad40de CR |
7264 | turns off the attribute instead, |
7265 | with the exceptions that \fB+a\fP | |
984a1947 | 7266 | may not be used to destroy an array variable and \fB+r\fP will not |
d3ad40de | 7267 | remove the readonly attribute. |
b28ff8c9 CR |
7268 | When used in a function, |
7269 | .B declare | |
7270 | and | |
7271 | .B typeset | |
7272 | make each | |
54a1fa7c | 7273 | \fIname\fP local, as with the |
726f6388 | 7274 | .B local |
6faad625 | 7275 | command, |
b28ff8c9 | 7276 | unless the \fB\-g\fP option is supplied. |
d3a24ed2 CR |
7277 | If a variable name is followed by =\fIvalue\fP, the value of |
7278 | the variable is set to \fIvalue\fP. | |
7279 | The return value is 0 unless an invalid option is encountered, | |
bb70624e JA |
7280 | an attempt is made to define a function using |
7281 | .if n ``\-f foo=bar'', | |
7282 | .if t \f(CW\-f foo=bar\fP, | |
ccc6cda3 JA |
7283 | an attempt is made to assign a value to a readonly variable, |
7284 | an attempt is made to assign a value to an array variable without | |
7285 | using the compound assignment syntax (see | |
7286 | .B Arrays | |
cce855bc | 7287 | above), one of the \fInames\fP is not a valid shell variable name, |
726f6388 | 7288 | an attempt is made to turn off readonly status for a readonly variable, |
ccc6cda3 | 7289 | an attempt is made to turn off array status for an array variable, |
bb70624e | 7290 | or an attempt is made to display a non-existent function with \fB\-f\fP. |
726f6388 JA |
7291 | .RE |
7292 | .TP | |
b28ff8c9 | 7293 | .B dirs [\fB\-clpv\fP] [+\fIn\fP] [\-\fIn\fP] |
ccc6cda3 JA |
7294 | Without options, displays the list of currently remembered directories. |
7295 | The default display is on a single line with directory names separated | |
7296 | by spaces. | |
7297 | Directories are added to the list with the | |
726f6388 JA |
7298 | .B pushd |
7299 | command; the | |
7300 | .B popd | |
ccc6cda3 | 7301 | command removes entries from the list. |
726f6388 JA |
7302 | .RS |
7303 | .PD 0 | |
7304 | .TP | |
ccc6cda3 JA |
7305 | .B \-c |
7306 | Clears the directory stack by deleting all of the entries. | |
7307 | .TP | |
726f6388 | 7308 | .B \-l |
b28ff8c9 CR |
7309 | Produces a listing using full pathnames; |
7310 | the default listing format uses a tilde to denote the home directory. | |
ccc6cda3 JA |
7311 | .TP |
7312 | .B \-p | |
7313 | Print the directory stack with one entry per line. | |
7314 | .TP | |
7315 | .B \-v | |
7316 | Print the directory stack with one entry per line, | |
7317 | prefixing each entry with its index in the stack. | |
b28ff8c9 CR |
7318 | .TP |
7319 | \fB+\fP\fIn\fP | |
7320 | Displays the \fIn\fPth entry counting from the left of the list | |
7321 | shown by | |
7322 | .B dirs | |
7323 | when invoked without options, starting with zero. | |
7324 | .TP | |
7325 | \fB\-\fP\fIn\fP | |
7326 | Displays the \fIn\fPth entry counting from the right of the list | |
7327 | shown by | |
7328 | .B dirs | |
7329 | when invoked without options, starting with zero. | |
726f6388 JA |
7330 | .PD |
7331 | .PP | |
7332 | The return value is 0 unless an | |
cce855bc | 7333 | invalid option is supplied or \fIn\fP indexes beyond the end |
726f6388 JA |
7334 | of the directory stack. |
7335 | .RE | |
7336 | .TP | |
cce855bc | 7337 | \fBdisown\fP [\fB\-ar\fP] [\fB\-h\fP] [\fIjobspec\fP ...] |
b28ff8c9 | 7338 | Without options, remove each |
ccc6cda3 | 7339 | .I jobspec |
b28ff8c9 | 7340 | from the table of active jobs. |
d3ad40de CR |
7341 | If |
7342 | .I jobspec | |
984a1947 | 7343 | is not present, and neither \fB\-a\fP nor \fB\-r\fP is supplied, |
d3ad40de | 7344 | the shell's notion of the \fIcurrent job\fP is used. |
cce855bc JA |
7345 | If the \fB\-h\fP option is given, each |
7346 | .I jobspec | |
7347 | is not removed from the table, but is marked so that | |
ccc6cda3 JA |
7348 | .SM |
7349 | .B SIGHUP | |
7350 | is not sent to the job if the shell receives a | |
7351 | .SM | |
7352 | .BR SIGHUP . | |
7353 | If no | |
7354 | .I jobspec | |
cce855bc JA |
7355 | is present, and neither the |
7356 | .B \-a | |
7357 | nor the | |
7358 | .B \-r | |
7359 | option is supplied, the \fIcurrent job\fP is used. | |
7360 | If no | |
7361 | .I jobspec | |
7362 | is supplied, the | |
7363 | .B \-a | |
7364 | option means to remove or mark all jobs; the | |
7365 | .B \-r | |
7366 | option without a | |
7367 | .I jobspec | |
7368 | argument restricts operation to running jobs. | |
7369 | The return value is 0 unless a | |
ccc6cda3 JA |
7370 | .I jobspec |
7371 | does not specify a valid job. | |
7372 | .TP | |
726f6388 | 7373 | \fBecho\fP [\fB\-neE\fP] [\fIarg\fP ...] |
ccc6cda3 | 7374 | Output the \fIarg\fPs, separated by spaces, followed by a newline. |
f6da9f85 | 7375 | The return status is 0 unless a write error occurs. |
ccc6cda3 | 7376 | If \fB\-n\fP is specified, the trailing newline is |
726f6388 JA |
7377 | suppressed. If the \fB\-e\fP option is given, interpretation of |
7378 | the following backslash-escaped characters is enabled. The | |
7379 | .B \-E | |
7380 | option disables the interpretation of these escape characters, | |
7381 | even on systems where they are interpreted by default. | |
28ef6c31 | 7382 | The \fBxpg_echo\fP shell option may be used to |
bb70624e JA |
7383 | dynamically determine whether or not \fBecho\fP expands these |
7384 | escape characters by default. | |
ccc6cda3 | 7385 | .B echo |
3ffb039a | 7386 | does not interpret \fB\-\-\fP to mean the end of options. |
ccc6cda3 JA |
7387 | .B echo |
7388 | interprets the following escape sequences: | |
726f6388 JA |
7389 | .RS |
7390 | .PD 0 | |
7391 | .TP | |
7392 | .B \ea | |
7393 | alert (bell) | |
7394 | .TP | |
7395 | .B \eb | |
7396 | backspace | |
7397 | .TP | |
7398 | .B \ec | |
2e4498b3 | 7399 | suppress further output |
726f6388 | 7400 | .TP |
ccc6cda3 | 7401 | .B \ee |
9ec5ed66 CR |
7402 | .TP |
7403 | .B \eE | |
ccc6cda3 JA |
7404 | an escape character |
7405 | .TP | |
726f6388 JA |
7406 | .B \ef |
7407 | form feed | |
7408 | .TP | |
7409 | .B \en | |
7410 | new line | |
7411 | .TP | |
7412 | .B \er | |
7413 | carriage return | |
7414 | .TP | |
7415 | .B \et | |
7416 | horizontal tab | |
7417 | .TP | |
7418 | .B \ev | |
7419 | vertical tab | |
7420 | .TP | |
7421 | .B \e\e | |
7422 | backslash | |
7423 | .TP | |
7117c2d2 JA |
7424 | .B \e0\fInnn\fP |
7425 | the eight-bit character whose value is the octal value \fInnn\fP | |
7426 | (zero to three octal digits) | |
7427 | .TP | |
f73dda09 JA |
7428 | .B \ex\fIHH\fP |
7429 | the eight-bit character whose value is the hexadecimal value \fIHH\fP | |
7430 | (one or two hex digits) | |
eb0b2ad8 CR |
7431 | .TP |
7432 | .B \eu\fIHHHH\fP | |
7433 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7434 | \fIHHHH\fP (one to four hex digits) | |
7435 | .TP | |
7436 | .B \eU\fIHHHHHHHH\fP | |
7437 | the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value | |
7438 | \fIHHHHHHHH\fP (one to eight hex digits) | |
726f6388 JA |
7439 | .PD |
7440 | .RE | |
7441 | .TP | |
d3ad40de | 7442 | \fBenable\fP [\fB\-a\fP] [\fB\-dnps\fP] [\fB\-f\fP \fIfilename\fP] [\fIname\fP ...] |
cce855bc JA |
7443 | Enable and disable builtin shell commands. |
7444 | Disabling a builtin allows a disk command which has the same name | |
bb70624e | 7445 | as a shell builtin to be executed without specifying a full pathname, |
cce855bc | 7446 | even though the shell normally searches for builtins before disk commands. |
726f6388 JA |
7447 | If \fB\-n\fP is used, each \fIname\fP |
7448 | is disabled; otherwise, | |
7449 | \fInames\fP are enabled. For example, to use the | |
7450 | .B test | |
7451 | binary found via the | |
7452 | .SM | |
7453 | .B PATH | |
ccc6cda3 | 7454 | instead of the shell builtin version, run |
28ef6c31 JA |
7455 | .if t \f(CWenable -n test\fP. |
7456 | .if n ``enable -n test''. | |
ccc6cda3 JA |
7457 | The |
7458 | .B \-f | |
7459 | option means to load the new builtin command | |
7460 | .I name | |
7461 | from shared object | |
7462 | .IR filename , | |
7463 | on systems that support dynamic loading. The | |
7464 | .B \-d | |
7465 | option will delete a builtin previously loaded with | |
7466 | .BR \-f . | |
7467 | If no \fIname\fP arguments are given, or if the | |
7468 | .B \-p | |
7469 | option is supplied, a list of shell builtins is printed. | |
7470 | With no other option arguments, the list consists of all enabled | |
7471 | shell builtins. | |
7472 | If \fB\-n\fP is supplied, only disabled builtins are printed. | |
7473 | If \fB\-a\fP is supplied, the list printed includes all builtins, with an | |
726f6388 | 7474 | indication of whether or not each is enabled. |
ccc6cda3 JA |
7475 | If \fB\-s\fP is supplied, the output is restricted to the POSIX |
7476 | \fIspecial\fP builtins. | |
726f6388 JA |
7477 | The return value is 0 unless a |
7478 | .I name | |
bb70624e | 7479 | is not a shell builtin or there is an error loading a new builtin |
ccc6cda3 | 7480 | from a shared object. |
726f6388 JA |
7481 | .TP |
7482 | \fBeval\fP [\fIarg\fP ...] | |
7483 | The \fIarg\fPs are read and concatenated together into a single | |
7484 | command. This command is then read and executed by the shell, and | |
ccc6cda3 JA |
7485 | its exit status is returned as the value of |
7486 | .BR eval . | |
7487 | If there are no | |
726f6388 JA |
7488 | .IR args , |
7489 | or only null arguments, | |
7490 | .B eval | |
ccc6cda3 | 7491 | returns 0. |
726f6388 | 7492 | .TP |
cce855bc | 7493 | \fBexec\fP [\fB\-cl\fP] [\fB\-a\fP \fIname\fP] [\fIcommand\fP [\fIarguments\fP]] |
726f6388 JA |
7494 | If |
7495 | .I command | |
7496 | is specified, it replaces the shell. | |
7497 | No new process is created. The | |
7498 | .I arguments | |
7499 | become the arguments to \fIcommand\fP. | |
ccc6cda3 JA |
7500 | If the |
7501 | .B \-l | |
7502 | option is supplied, | |
d3ad40de | 7503 | the shell places a dash at the beginning of the zeroth argument passed to |
726f6388 | 7504 | .IR command . |
ccc6cda3 JA |
7505 | This is what |
7506 | .IR login (1) | |
7507 | does. The | |
7508 | .B \-c | |
7509 | option causes | |
7510 | .I command | |
7511 | to be executed with an empty environment. If | |
7512 | .B \-a | |
7513 | is supplied, the shell passes | |
7514 | .I name | |
b28ff8c9 CR |
7515 | as the zeroth argument to the executed command. |
7516 | If | |
ccc6cda3 | 7517 | .I command |
726f6388 | 7518 | cannot be executed for some reason, a non-interactive shell exits, |
b28ff8c9 | 7519 | unless the |
ccc6cda3 | 7520 | .B execfail |
b28ff8c9 CR |
7521 | shell option |
7522 | is enabled. In that case, it returns failure. | |
ccc6cda3 | 7523 | An interactive shell returns failure if the file cannot be executed. |
726f6388 JA |
7524 | If |
7525 | .I command | |
7526 | is not specified, any redirections take effect in the current shell, | |
cce855bc JA |
7527 | and the return status is 0. If there is a redirection error, the |
7528 | return status is 1. | |
726f6388 JA |
7529 | .TP |
7530 | \fBexit\fP [\fIn\fP] | |
7531 | Cause the shell to exit | |
7532 | with a status of \fIn\fP. If | |
7533 | .I n | |
7534 | is omitted, the exit status | |
7535 | is that of the last command executed. | |
7536 | A trap on | |
7537 | .SM | |
7538 | .B EXIT | |
7539 | is executed before the shell terminates. | |
7540 | .TP | |
ccc6cda3 | 7541 | \fBexport\fP [\fB\-fn\fP\^] [\fIname\fP[=\fIword\fP]] ... |
7117c2d2 | 7542 | .PD 0 |
726f6388 JA |
7543 | .TP |
7544 | .B export \-p | |
7545 | .PD | |
7546 | The supplied | |
7547 | .I names | |
7548 | are marked for automatic export to the environment of | |
7549 | subsequently executed commands. If the | |
7550 | .B \-f | |
7551 | option is given, | |
7552 | the | |
7553 | .I names | |
7554 | refer to functions. | |
7555 | If no | |
7556 | .I names | |
7557 | are given, or if the | |
7558 | .B \-p | |
7559 | option is supplied, a list | |
b28ff8c9 | 7560 | of names of all exported variables is printed. |
726f6388 JA |
7561 | The |
7562 | .B \-n | |
5e13499c CR |
7563 | option causes the export property to be removed from each |
7564 | \fIname\fP. | |
d3a24ed2 CR |
7565 | If a variable name is followed by =\fIword\fP, the value of |
7566 | the variable is set to \fIword\fP. | |
726f6388 | 7567 | .B export |
cce855bc | 7568 | returns an exit status of 0 unless an invalid option is |
726f6388 | 7569 | encountered, |
cce855bc | 7570 | one of the \fInames\fP is not a valid shell variable name, or |
726f6388 JA |
7571 | .B \-f |
7572 | is supplied with a | |
7573 | .I name | |
7574 | that is not a function. | |
7575 | .TP | |
d3ad40de | 7576 | \fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP] |
7117c2d2 | 7577 | .PD 0 |
726f6388 JA |
7578 | .TP |
7579 | \fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP] | |
7580 | .PD | |
b28ff8c9 | 7581 | The first form selects a range of commands from |
726f6388 JA |
7582 | .I first |
7583 | to | |
7584 | .I last | |
b28ff8c9 | 7585 | from the history list and displays or edits and re-executes them. |
726f6388 JA |
7586 | .I First |
7587 | and | |
7588 | .I last | |
7589 | may be specified as a string (to locate the last command beginning | |
7590 | with that string) or as a number (an index into the history list, | |
7591 | where a negative number is used as an offset from the current | |
7592 | command number). If | |
7593 | .I last | |
7594 | is not specified it is set to | |
7595 | the current command for listing (so that | |
bb70624e JA |
7596 | .if n ``fc \-l \-10'' |
7597 | .if t \f(CWfc \-l \-10\fP | |
726f6388 JA |
7598 | prints the last 10 commands) and to |
7599 | .I first | |
7600 | otherwise. | |
7601 | If | |
7602 | .I first | |
7603 | is not specified it is set to the previous | |
7604 | command for editing and \-16 for listing. | |
7605 | .sp 1 | |
7606 | The | |
7607 | .B \-n | |
cce855bc | 7608 | option suppresses |
726f6388 JA |
7609 | the command numbers when listing. The |
7610 | .B \-r | |
cce855bc | 7611 | option reverses the order of |
726f6388 JA |
7612 | the commands. If the |
7613 | .B \-l | |
cce855bc | 7614 | option is given, |
726f6388 JA |
7615 | the commands are listed on |
7616 | standard output. Otherwise, the editor given by | |
7617 | .I ename | |
7618 | is invoked | |
7619 | on a file containing those commands. If | |
7620 | .I ename | |
7621 | is not given, the | |
7622 | value of the | |
7623 | .SM | |
7624 | .B FCEDIT | |
7625 | variable is used, and | |
7626 | the value of | |
7627 | .SM | |
7628 | .B EDITOR | |
7629 | if | |
7630 | .SM | |
7631 | .B FCEDIT | |
7632 | is not set. If neither variable is set, | |
7633 | .FN vi | |
7634 | is used. When editing is complete, the edited commands are | |
7635 | echoed and executed. | |
7636 | .sp 1 | |
7637 | In the second form, \fIcommand\fP is re-executed after each instance | |
7638 | of \fIpat\fP is replaced by \fIrep\fP. | |
b28ff8c9 | 7639 | \fICommand\fP is intepreted the same as \fIfirst\fP above. |
ccc6cda3 | 7640 | A useful alias to use with this is |
d3a24ed2 | 7641 | .if n ``r="fc -s"'', |
ccc6cda3 JA |
7642 | .if t \f(CWr='fc \-s'\fP, |
7643 | so that typing | |
7644 | .if n ``r cc'' | |
7645 | .if t \f(CWr cc\fP | |
7646 | runs the last command beginning with | |
7647 | .if n ``cc'' | |
7648 | .if t \f(CWcc\fP | |
7649 | and typing | |
7650 | .if n ``r'' | |
7651 | .if t \f(CWr\fP | |
726f6388 JA |
7652 | re-executes the last command. |
7653 | .sp 1 | |
cce855bc | 7654 | If the first form is used, the return value is 0 unless an invalid |
726f6388 JA |
7655 | option is encountered or |
7656 | .I first | |
7657 | or | |
7658 | .I last | |
7659 | specify history lines out of range. | |
7660 | If the | |
7661 | .B \-e | |
7662 | option is supplied, the return value is the value of the last | |
7663 | command executed or failure if an error occurs with the temporary | |
7664 | file of commands. If the second form is used, the return status | |
7665 | is that of the command re-executed, unless | |
7666 | .I cmd | |
7667 | does not specify a valid history line, in which case | |
7668 | .B fc | |
7669 | returns failure. | |
7670 | .TP | |
7671 | \fBfg\fP [\fIjobspec\fP] | |
cce855bc | 7672 | Resume |
726f6388 | 7673 | .I jobspec |
cce855bc JA |
7674 | in the foreground, and make it the current job. |
7675 | If | |
726f6388 JA |
7676 | .I jobspec |
7677 | is not present, the shell's notion of the \fIcurrent job\fP is used. | |
7678 | The return value is that of the command placed into the foreground, | |
7679 | or failure if run when job control is disabled or, when run with | |
7680 | job control enabled, if | |
7681 | .I jobspec | |
7682 | does not specify a valid job or | |
7683 | .I jobspec | |
7684 | specifies a job that was started without job control. | |
7685 | .TP | |
7686 | \fBgetopts\fP \fIoptstring\fP \fIname\fP [\fIargs\fP] | |
7687 | .B getopts | |
7688 | is used by shell procedures to parse positional parameters. | |
7689 | .I optstring | |
bb70624e | 7690 | contains the option characters to be recognized; if a character |
726f6388 JA |
7691 | is followed by a colon, the option is expected to have an |
7692 | argument, which should be separated from it by white space. | |
bb70624e JA |
7693 | The colon and question mark characters may not be used as |
7694 | option characters. | |
726f6388 JA |
7695 | Each time it is invoked, |
7696 | .B getopts | |
7697 | places the next option in the shell variable | |
7698 | .IR name , | |
7699 | initializing | |
7700 | .I name | |
7701 | if it does not exist, | |
7702 | and the index of the next argument to be processed into the | |
7703 | variable | |
7704 | .SM | |
7705 | .BR OPTIND . | |
7706 | .SM | |
7707 | .B OPTIND | |
7708 | is initialized to 1 each time the shell or a shell script | |
7709 | is invoked. When an option requires an argument, | |
7710 | .B getopts | |
7711 | places that argument into the variable | |
7712 | .SM | |
7713 | .BR OPTARG . | |
7714 | The shell does not reset | |
7715 | .SM | |
7716 | .B OPTIND | |
7717 | automatically; it must be manually reset between multiple | |
7718 | calls to | |
7719 | .B getopts | |
7720 | within the same shell invocation if a new set of parameters | |
7721 | is to be used. | |
7722 | .sp 1 | |
cce855bc JA |
7723 | When the end of options is encountered, \fBgetopts\fP exits with a |
7724 | return value greater than zero. | |
984a1947 CR |
7725 | .SM |
7726 | .B OPTIND | |
7727 | is set to the index of the first non-option argument, | |
dc60d4e0 | 7728 | and \fIname\fP is set to ?. |
cce855bc JA |
7729 | .sp 1 |
7730 | .B getopts | |
7731 | normally parses the positional parameters, but if more arguments are | |
7732 | given in | |
7733 | .IR args , | |
7734 | .B getopts | |
7735 | parses those instead. | |
7736 | .sp 1 | |
726f6388 JA |
7737 | .B getopts |
7738 | can report errors in two ways. If the first character of | |
7739 | .I optstring | |
7740 | is a colon, | |
7741 | .I silent | |
b28ff8c9 | 7742 | error reporting is used. In normal operation, diagnostic messages |
cce855bc | 7743 | are printed when invalid options or missing option arguments are |
726f6388 JA |
7744 | encountered. |
7745 | If the variable | |
7746 | .SM | |
7747 | .B OPTERR | |
cce855bc | 7748 | is set to 0, no error messages will be displayed, even if the first |
726f6388 JA |
7749 | character of |
7750 | .I optstring | |
7751 | is not a colon. | |
7752 | .sp 1 | |
cce855bc | 7753 | If an invalid option is seen, |
726f6388 JA |
7754 | .B getopts |
7755 | places ? into | |
7756 | .I name | |
7757 | and, if not silent, | |
7758 | prints an error message and unsets | |
7759 | .SM | |
7760 | .BR OPTARG . | |
7761 | If | |
7762 | .B getopts | |
7763 | is silent, | |
7764 | the option character found is placed in | |
7765 | .SM | |
7766 | .B OPTARG | |
7767 | and no diagnostic message is printed. | |
7768 | .sp 1 | |
7769 | If a required argument is not found, and | |
7770 | .B getopts | |
7771 | is not silent, | |
7772 | a question mark (\^\fB?\fP\^) is placed in | |
7773 | .IR name , | |
f73dda09 | 7774 | .SM |
726f6388 JA |
7775 | .B OPTARG |
7776 | is unset, and a diagnostic message is printed. | |
7777 | If | |
7778 | .B getopts | |
7779 | is silent, then a colon (\^\fB:\fP\^) is placed in | |
7780 | .I name | |
7781 | and | |
7782 | .SM | |
7783 | .B OPTARG | |
7784 | is set to the option character found. | |
7785 | .sp 1 | |
7786 | .B getopts | |
726f6388 JA |
7787 | returns true if an option, specified or unspecified, is found. |
7788 | It returns false if the end of options is encountered or an | |
7789 | error occurs. | |
7790 | .TP | |
7117c2d2 | 7791 | \fBhash\fP [\fB\-lr\fP] [\fB\-p\fP \fIfilename\fP] [\fB\-dt\fP] [\fIname\fP] |
4691dc6b CR |
7792 | Each time \fBhash\fP is invoked, |
7793 | the full pathname of the command | |
7794 | .I name | |
7795 | is determined by searching | |
ccc6cda3 JA |
7796 | the directories in |
7797 | .B $PATH | |
4691dc6b | 7798 | and remembered. Any previously-remembered pathname is discarded. |
ccc6cda3 JA |
7799 | If the |
7800 | .B \-p | |
7801 | option is supplied, no path search is performed, and | |
7802 | .I filename | |
b28ff8c9 | 7803 | is used as the full filename of the command. |
ccc6cda3 | 7804 | The |
726f6388 JA |
7805 | .B \-r |
7806 | option causes the shell to forget all | |
f73dda09 | 7807 | remembered locations. |
7117c2d2 JA |
7808 | The |
7809 | .B \-d | |
7810 | option causes the shell to forget the remembered location of each \fIname\fP. | |
f73dda09 JA |
7811 | If the |
7812 | .B \-t | |
7813 | option is supplied, the full pathname to which each \fIname\fP corresponds | |
7814 | is printed. If multiple \fIname\fP arguments are supplied with \fB\-t\fP, | |
7815 | the \fIname\fP is printed before the hashed full pathname. | |
7117c2d2 JA |
7816 | The |
7817 | .B \-l | |
7818 | option causes output to be displayed in a format that may be reused as input. | |
7819 | If no arguments are given, or if only \fB\-l\fP is supplied, | |
7820 | information about remembered commands is printed. | |
ccc6cda3 | 7821 | The return status is true unless a |
726f6388 | 7822 | .I name |
cce855bc | 7823 | is not found or an invalid option is supplied. |
726f6388 | 7824 | .TP |
6a8fd0ed | 7825 | \fBhelp\fP [\fB\-dms\fP] [\fIpattern\fP] |
726f6388 JA |
7826 | Display helpful information about builtin commands. If |
7827 | .I pattern | |
7828 | is specified, | |
7829 | .B help | |
7830 | gives detailed help on all commands matching | |
7831 | .IR pattern ; | |
ccc6cda3 | 7832 | otherwise help for all the builtins and shell control structures |
bb70624e | 7833 | is printed. |
6a8fd0ed CR |
7834 | .RS |
7835 | .PD 0 | |
7836 | .TP | |
7837 | .B \-d | |
7838 | Display a short description of each \fIpattern\fP | |
7839 | .TP | |
6932f7f5 | 7840 | .B \-m |
6a8fd0ed CR |
7841 | Display the description of each \fIpattern\fP in a manpage-like format |
7842 | .TP | |
7843 | .B \-s | |
7844 | Display only a short usage synopsis for each \fIpattern\fP | |
7845 | .PD | |
54a1fa7c | 7846 | .PP |
bb70624e | 7847 | The return status is 0 unless no command matches |
726f6388 | 7848 | .IR pattern . |
54a1fa7c | 7849 | .RE |
726f6388 | 7850 | .TP |
bb70624e | 7851 | \fBhistory [\fIn\fP] |
7117c2d2 | 7852 | .PD 0 |
bb70624e JA |
7853 | .TP |
7854 | \fBhistory\fP \fB\-c\fP | |
7855 | .TP | |
7856 | \fBhistory \-d\fP \fIoffset\fP | |
ccc6cda3 JA |
7857 | .TP |
7858 | \fBhistory\fP \fB\-anrw\fP [\fIfilename\fP] | |
726f6388 | 7859 | .TP |
ccc6cda3 JA |
7860 | \fBhistory\fP \fB\-p\fP \fIarg\fP [\fIarg ...\fP] |
7861 | .TP | |
7862 | \fBhistory\fP \fB\-s\fP \fIarg\fP [\fIarg ...\fP] | |
726f6388 JA |
7863 | .PD |
7864 | With no options, display the command | |
7865 | history list with line numbers. Lines listed | |
7866 | with a | |
7867 | .B * | |
7868 | have been modified. An argument of | |
7869 | .I n | |
7870 | lists only the last | |
7871 | .I n | |
d3a24ed2 | 7872 | lines. |
984a1947 CR |
7873 | If the shell variable |
7874 | .SM | |
7875 | .B HISTTIMEFORMAT | |
7876 | is set and not null, | |
d3a24ed2 CR |
7877 | it is used as a format string for \fIstrftime\fP(3) to display |
7878 | the time stamp associated with each displayed history entry. | |
7879 | No intervening blank is printed between the formatted time stamp | |
7880 | and the history line. | |
7881 | If \fIfilename\fP is supplied, it is used as the | |
726f6388 JA |
7882 | name of the history file; if not, the value of |
7883 | .SM | |
7884 | .B HISTFILE | |
7885 | is used. Options, if supplied, have the following meanings: | |
7886 | .RS | |
7887 | .PD 0 | |
7888 | .TP | |
bb70624e JA |
7889 | .B \-c |
7890 | Clear the history list by deleting all the entries. | |
7891 | .TP | |
7892 | \fB\-d\fP \fIoffset\fP | |
7893 | Delete the history entry at position \fIoffset\fP. | |
7894 | .TP | |
726f6388 JA |
7895 | .B \-a |
7896 | Append the ``new'' history lines (history lines entered since the | |
ccc6cda3 | 7897 | beginning of the current \fBbash\fP session) to the history file. |
726f6388 JA |
7898 | .TP |
7899 | .B \-n | |
7900 | Read the history lines not already read from the history | |
7901 | file into the current history list. These are lines | |
7902 | appended to the history file since the beginning of the | |
7903 | current \fBbash\fP session. | |
7904 | .TP | |
7905 | .B \-r | |
7906 | Read the contents of the history file | |
b28ff8c9 | 7907 | and append them to the current history list. |
726f6388 JA |
7908 | .TP |
7909 | .B \-w | |
b28ff8c9 | 7910 | Write the current history list to the history file, overwriting the |
726f6388 | 7911 | history file's contents. |
ccc6cda3 | 7912 | .TP |
ccc6cda3 JA |
7913 | .B \-p |
7914 | Perform history substitution on the following \fIargs\fP and display | |
7915 | the result on the standard output. | |
7916 | Does not store the results in the history list. | |
7917 | Each \fIarg\fP must be quoted to disable normal history expansion. | |
7918 | .TP | |
7919 | .B \-s | |
7920 | Store the | |
7921 | .I args | |
7922 | in the history list as a single entry. The last command in the | |
7923 | history list is removed before the | |
7924 | .I args | |
7925 | are added. | |
726f6388 JA |
7926 | .PD |
7927 | .PP | |
984a1947 CR |
7928 | If the |
7929 | .SM | |
7930 | .B HISTTIMEFORMAT | |
7931 | variable is set, the time stamp information | |
d3ad40de CR |
7932 | associated with each history entry is written to the history file, |
7933 | marked with the history comment character. | |
7934 | When the history file is read, lines beginning with the history | |
7935 | comment character followed immediately by a digit are interpreted | |
7936 | as timestamps for the previous history line. | |
bb70624e JA |
7937 | The return value is 0 unless an invalid option is encountered, an |
7938 | error occurs while reading or writing the history file, an invalid | |
7939 | \fIoffset\fP is supplied as an argument to \fB\-d\fP, or the | |
7940 | history expansion supplied as an argument to \fB\-p\fP fails. | |
726f6388 JA |
7941 | .RE |
7942 | .TP | |
ccc6cda3 | 7943 | \fBjobs\fP [\fB\-lnprs\fP] [ \fIjobspec\fP ... ] |
7117c2d2 | 7944 | .PD 0 |
726f6388 JA |
7945 | .TP |
7946 | \fBjobs\fP \fB\-x\fP \fIcommand\fP [ \fIargs\fP ... ] | |
7947 | .PD | |
ccc6cda3 JA |
7948 | The first form lists the active jobs. The options have the following |
7949 | meanings: | |
7950 | .RS | |
7951 | .PD 0 | |
7952 | .TP | |
726f6388 | 7953 | .B \-l |
ccc6cda3 JA |
7954 | List process IDs |
7955 | in addition to the normal information. | |
7956 | .TP | |
726f6388 | 7957 | .B \-n |
ccc6cda3 JA |
7958 | Display information only about jobs that have changed status since |
7959 | the user was last notified of their status. | |
7960 | .TP | |
5cdaaf76 CR |
7961 | .B \-p |
7962 | List only the process ID of the job's process group | |
7963 | leader. | |
7964 | .TP | |
ccc6cda3 | 7965 | .B \-r |
b28ff8c9 | 7966 | Display only running jobs. |
ccc6cda3 JA |
7967 | .TP |
7968 | .B \-s | |
b28ff8c9 | 7969 | Display only stopped jobs. |
ccc6cda3 JA |
7970 | .PD |
7971 | .PP | |
7972 | If | |
726f6388 JA |
7973 | .I jobspec |
7974 | is given, output is restricted to information about that job. | |
cce855bc JA |
7975 | The return status is 0 unless an invalid option is encountered |
7976 | or an invalid | |
726f6388 JA |
7977 | .I jobspec |
7978 | is supplied. | |
ccc6cda3 | 7979 | .PP |
726f6388 JA |
7980 | If the |
7981 | .B \-x | |
7982 | option is supplied, | |
7983 | .B jobs | |
7984 | replaces any | |
7985 | .I jobspec | |
7986 | found in | |
7987 | .I command | |
7988 | or | |
7989 | .I args | |
7990 | with the corresponding process group ID, and executes | |
7991 | .I command | |
7992 | passing it | |
7993 | .IR args , | |
7994 | returning its exit status. | |
ccc6cda3 | 7995 | .RE |
726f6388 | 7996 | .TP |
ccc6cda3 | 7997 | \fBkill\fP [\fB\-s\fP \fIsigspec\fP | \fB\-n\fP \fIsignum\fP | \fB\-\fP\fIsigspec\fP] [\fIpid\fP | \fIjobspec\fP] ... |
7117c2d2 | 7998 | .PD 0 |
726f6388 | 7999 | .TP |
cce855bc | 8000 | \fBkill\fP \fB\-l\fP [\fIsigspec\fP | \fIexit_status\fP] |
726f6388 JA |
8001 | .PD |
8002 | Send the signal named by | |
8003 | .I sigspec | |
ccc6cda3 JA |
8004 | or |
8005 | .I signum | |
726f6388 JA |
8006 | to the processes named by |
8007 | .I pid | |
8008 | or | |
8009 | .IR jobspec . | |
8010 | .I sigspec | |
61deeb13 | 8011 | is either a case-insensitive signal name such as |
726f6388 JA |
8012 | .SM |
8013 | .B SIGKILL | |
61deeb13 | 8014 | (with or without the |
726f6388 JA |
8015 | .SM |
8016 | .B SIG | |
61deeb13 CR |
8017 | prefix) or a signal number; |
8018 | .I signum | |
8019 | is a signal number. | |
726f6388 JA |
8020 | If |
8021 | .I sigspec | |
8022 | is not present, then | |
8023 | .SM | |
8024 | .B SIGTERM | |
cce855bc JA |
8025 | is assumed. |
8026 | An argument of | |
726f6388 | 8027 | .B \-l |
cce855bc JA |
8028 | lists the signal names. |
8029 | If any arguments are supplied when | |
726f6388 | 8030 | .B \-l |
cce855bc JA |
8031 | is given, the names of the signals corresponding to the arguments are |
8032 | listed, and the return status is 0. | |
8033 | The \fIexit_status\fP argument to | |
ccc6cda3 | 8034 | .B \-l |
cce855bc JA |
8035 | is a number specifying either a signal number or the exit status of |
8036 | a process terminated by a signal. | |
726f6388 JA |
8037 | .B kill |
8038 | returns true if at least one signal was successfully sent, or false | |
cce855bc | 8039 | if an error occurs or an invalid option is encountered. |
726f6388 JA |
8040 | .TP |
8041 | \fBlet\fP \fIarg\fP [\fIarg\fP ...] | |
8042 | Each | |
8043 | .I arg | |
8044 | is an arithmetic expression to be evaluated (see | |
8045 | .SM | |
984a1947 CR |
8046 | .B "ARITHMETIC EVALUATION" |
8047 | above). | |
726f6388 JA |
8048 | If the last |
8049 | .I arg | |
8050 | evaluates to 0, | |
8051 | .B let | |
8052 | returns 1; 0 is returned otherwise. | |
8053 | .TP | |
bb70624e | 8054 | \fBlocal\fP [\fIoption\fP] [\fIname\fP[=\fIvalue\fP] ...] |
cce855bc JA |
8055 | For each argument, a local variable named |
8056 | .I name | |
8057 | is created, and assigned | |
726f6388 | 8058 | .IR value . |
bb70624e | 8059 | The \fIoption\fP can be any of the options accepted by \fBdeclare\fP. |
726f6388 JA |
8060 | When |
8061 | .B local | |
8062 | is used within a function, it causes the variable | |
8063 | .I name | |
8064 | to have a visible scope restricted to that function and its children. | |
8065 | With no operands, | |
8066 | .B local | |
8067 | writes a list of local variables to the standard output. It is | |
8068 | an error to use | |
8069 | .B local | |
8070 | when not within a function. The return status is 0 unless | |
8071 | .B local | |
bb70624e | 8072 | is used outside a function, an invalid |
726f6388 | 8073 | .I name |
bb70624e JA |
8074 | is supplied, or |
8075 | \fIname\fP is a readonly variable. | |
726f6388 JA |
8076 | .TP |
8077 | .B logout | |
8078 | Exit a login shell. | |
8079 | .TP | |
09767ff0 | 8080 | \fBmapfile\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] |
e141c35a CR |
8081 | .PD 0 |
8082 | .TP | |
8083 | \fBreadarray\fP [\fB\-n\fP \fIcount\fP] [\fB\-O\fP \fIorigin\fP] [\fB\-s\fP \fIcount\fP] [\fB\-t\fP] [\fB\-u\fP \fIfd\fP] [\fB\-C\fP \fIcallback\fP] [\fB\-c\fP \fIquantum\fP] [\fIarray\fP] | |
8084 | .PD | |
e1e48bba | 8085 | Read lines from the standard input into the indexed array variable |
6a8fd0ed CR |
8086 | .IR array , |
8087 | or from file descriptor | |
8088 | .IR fd | |
8089 | if the | |
8090 | .B \-u | |
8091 | option is supplied. | |
984a1947 CR |
8092 | The variable |
8093 | .SM | |
8094 | .B MAPFILE | |
8095 | is the default \fIarray\fP. | |
6a8fd0ed CR |
8096 | Options, if supplied, have the following meanings: |
8097 | .RS | |
8098 | .PD 0 | |
8099 | .TP | |
8100 | .B \-n | |
8101 | Copy at most | |
8102 | .I count | |
8103 | lines. If \fIcount\fP is 0, all lines are copied. | |
8104 | .TP | |
8105 | .B \-O | |
8106 | Begin assigning to | |
8107 | .I array | |
8108 | at index | |
8109 | .IR origin . | |
8110 | The default index is 0. | |
8111 | .TP | |
8112 | .B \-s | |
8113 | Discard the first \fIcount\fP lines read. | |
8114 | .TP | |
8115 | .B \-t | |
984a1947 | 8116 | Remove a trailing newline from each line read. |
6a8fd0ed CR |
8117 | .TP |
8118 | .B \-u | |
8119 | Read lines from file descriptor \fIfd\fP instead of the standard input. | |
8120 | .TP | |
8121 | .B \-C | |
8122 | Evaluate | |
8123 | .I callback | |
8124 | each time \fIquantum\fP lines are read. The \fB\-c\fP option specifies | |
8125 | .IR quantum . | |
8126 | .TP | |
8127 | .B \-c | |
8128 | Specify the number of lines read between each call to | |
8129 | .IR callback . | |
8130 | .PD | |
8131 | .PP | |
8132 | If | |
8133 | .B \-C | |
8134 | is specified without | |
8135 | .BR \-c , | |
8136 | the default quantum is 5000. | |
e141c35a | 8137 | When \fIcallback\fP is evaluated, it is supplied the index of the next |
6faad625 CR |
8138 | array element to be assigned and the line to be assigned to that element |
8139 | as additional arguments. | |
e141c35a CR |
8140 | \fIcallback\fP is evaluated after the line is read but before the |
8141 | array element is assigned. | |
6a8fd0ed CR |
8142 | .PP |
8143 | If not supplied with an explicit origin, \fBmapfile\fP will clear \fIarray\fP | |
8144 | before assigning to it. | |
8145 | .PP | |
8146 | \fBmapfile\fP returns successfully unless an invalid option or option | |
e1e48bba CR |
8147 | argument is supplied, \fIarray\fP is invalid or unassignable, or if |
8148 | \fIarray\fP is not an indexed array. | |
6a8fd0ed CR |
8149 | .RE |
8150 | .TP | |
ccc6cda3 | 8151 | \fBpopd\fP [\-\fBn\fP] [+\fIn\fP] [\-\fIn\fP] |
726f6388 JA |
8152 | Removes entries from the directory stack. With no arguments, |
8153 | removes the top directory from the stack, and performs a | |
8154 | .B cd | |
8155 | to the new top directory. | |
ccc6cda3 | 8156 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8157 | .RS |
8158 | .PD 0 | |
8159 | .TP | |
d3ad40de CR |
8160 | .B \-n |
8161 | Suppresses the normal change of directory when removing directories | |
8162 | from the stack, so that only the stack is manipulated. | |
8163 | .TP | |
ccc6cda3 JA |
8164 | \fB+\fP\fIn\fP |
8165 | Removes the \fIn\fPth entry counting from the left of the list | |
726f6388 JA |
8166 | shown by |
8167 | .BR dirs , | |
bb70624e JA |
8168 | starting with zero. For example: |
8169 | .if n ``popd +0'' | |
8170 | .if t \f(CWpopd +0\fP | |
8171 | removes the first directory, | |
8172 | .if n ``popd +1'' | |
8173 | .if t \f(CWpopd +1\fP | |
8174 | the second. | |
726f6388 | 8175 | .TP |
ccc6cda3 JA |
8176 | \fB\-\fP\fIn\fP |
8177 | Removes the \fIn\fPth entry counting from the right of the list | |
726f6388 JA |
8178 | shown by |
8179 | .BR dirs , | |
bb70624e JA |
8180 | starting with zero. For example: |
8181 | .if n ``popd -0'' | |
8182 | .if t \f(CWpopd -0\fP | |
8183 | removes the last directory, | |
8184 | .if n ``popd -1'' | |
8185 | .if t \f(CWpopd -1\fP | |
8186 | the next to last. | |
726f6388 JA |
8187 | .PD |
8188 | .PP | |
8189 | If the | |
8190 | .B popd | |
8191 | command is successful, a | |
8192 | .B dirs | |
8193 | is performed as well, and the return status is 0. | |
8194 | .B popd | |
cce855bc | 8195 | returns false if an invalid option is encountered, the directory stack |
726f6388 JA |
8196 | is empty, a non-existent directory stack entry is specified, or the |
8197 | directory change fails. | |
8198 | .RE | |
8199 | .TP | |
3ee6b87d | 8200 | \fBprintf\fP [\fB\-v\fP \fIvar\fP] \fIformat\fP [\fIarguments\fP] |
cce855bc JA |
8201 | Write the formatted \fIarguments\fP to the standard output under the |
8202 | control of the \fIformat\fP. | |
6faad625 CR |
8203 | The \fB\-v\fP option causes the output to be assigned to the variable |
8204 | \fIvar\fP rather than being printed to the standard output. | |
8205 | .sp 1 | |
cce855bc JA |
8206 | The \fIformat\fP is a character string which contains three types of objects: |
8207 | plain characters, which are simply copied to standard output, character | |
8208 | escape sequences, which are converted and copied to the standard output, and | |
8209 | format specifications, each of which causes printing of the next successive | |
8210 | \fIargument\fP. | |
6faad625 CR |
8211 | In addition to the standard \fIprintf\fP(1) format specifications, |
8212 | \fBprintf\fP interprets the following extensions: | |
8213 | .RS | |
8214 | .PD 0 | |
8215 | .TP | |
8216 | .B %b | |
8217 | causes | |
cce855bc | 8218 | \fBprintf\fP to expand backslash escape sequences in the corresponding |
5e13499c | 8219 | \fIargument\fP (except that \fB\ec\fP terminates output, backslashes in |
20587658 | 8220 | \fB\e\(aq\fP, \fB\e"\fP, and \fB\e?\fP are not removed, and octal escapes |
6faad625 CR |
8221 | beginning with \fB\e0\fP may contain up to four digits). |
8222 | .TP | |
8223 | .B %q | |
8224 | causes \fBprintf\fP to output the corresponding | |
cce855bc | 8225 | \fIargument\fP in a format that can be reused as shell input. |
6faad625 CR |
8226 | .TP |
8227 | .B %(\fIdatefmt\fP)T | |
8228 | causes \fBprintf\fP to output the date-time string resulting from using | |
8229 | \fIdatefmt\fP as a format string for \fIstrftime\fP(3). The corresponding | |
8230 | \fIargument\fP is an integer representing the number of seconds since the | |
8231 | epoch. Two special argument values may be used: -1 represents the current | |
8232 | time, and -2 represents the time the shell was invoked. | |
8233 | .PD | |
8234 | .PP | |
112ff2a6 CR |
8235 | Arguments to non-string format specifiers are treated as C constants, |
8236 | except that a leading plus or minus sign is allowed, and if the leading | |
8237 | character is a single or double quote, the value is the ASCII value of | |
8238 | the following character. | |
6faad625 | 8239 | .PP |
cce855bc JA |
8240 | The \fIformat\fP is reused as necessary to consume all of the \fIarguments\fP. |
8241 | If the \fIformat\fP requires more \fIarguments\fP than are supplied, the | |
8242 | extra format specifications behave as if a zero value or null string, as | |
6faad625 CR |
8243 | appropriate, had been supplied. |
8244 | The return value is zero on success, non-zero on failure. | |
8245 | .RE | |
cce855bc | 8246 | .TP |
d3ad40de | 8247 | \fBpushd\fP [\fB\-n\fP] [+\fIn\fP] [\-\fIn\fP] |
7117c2d2 | 8248 | .PD 0 |
726f6388 | 8249 | .TP |
d3ad40de | 8250 | \fBpushd\fP [\fB\-n\fP] [\fIdir\fP] |
726f6388 JA |
8251 | .PD |
8252 | Adds a directory to the top of the directory stack, or rotates | |
8253 | the stack, making the new top of the stack the current working | |
8254 | directory. With no arguments, exchanges the top two directories | |
8255 | and returns 0, unless the directory stack is empty. | |
ccc6cda3 | 8256 | Arguments, if supplied, have the following meanings: |
726f6388 JA |
8257 | .RS |
8258 | .PD 0 | |
8259 | .TP | |
d3ad40de CR |
8260 | .B \-n |
8261 | Suppresses the normal change of directory when adding directories | |
8262 | to the stack, so that only the stack is manipulated. | |
8263 | .TP | |
ccc6cda3 | 8264 | \fB+\fP\fIn\fP |
726f6388 JA |
8265 | Rotates the stack so that the \fIn\fPth directory |
8266 | (counting from the left of the list shown by | |
d166f048 JA |
8267 | .BR dirs , |
8268 | starting with zero) | |
726f6388 JA |
8269 | is at the top. |
8270 | .TP | |
ccc6cda3 | 8271 | \fB\-\fP\fIn\fP |
726f6388 | 8272 | Rotates the stack so that the \fIn\fPth directory |
d166f048 JA |
8273 | (counting from the right of the list shown by |
8274 | .BR dirs , | |
8275 | starting with zero) is at the top. | |
726f6388 | 8276 | .TP |
bb70624e | 8277 | .I dir |
ccc6cda3 | 8278 | Adds |
726f6388 JA |
8279 | .I dir |
8280 | to the directory stack at the top, making it the | |
19baff85 CR |
8281 | new current working directory as if it had been supplied as the argument |
8282 | to the \fBcd\fP builtin. | |
726f6388 JA |
8283 | .PD |
8284 | .PP | |
8285 | If the | |
8286 | .B pushd | |
8287 | command is successful, a | |
8288 | .B dirs | |
8289 | is performed as well. | |
8290 | If the first form is used, | |
8291 | .B pushd | |
8292 | returns 0 unless the cd to | |
8293 | .I dir | |
8294 | fails. With the second form, | |
8295 | .B pushd | |
8296 | returns 0 unless the directory stack is empty, | |
ccc6cda3 | 8297 | a non-existent directory stack element is specified, |
726f6388 JA |
8298 | or the directory change to the specified new current directory |
8299 | fails. | |
8300 | .RE | |
8301 | .TP | |
ccc6cda3 | 8302 | \fBpwd\fP [\fB\-LP\fP] |
bb70624e JA |
8303 | Print the absolute pathname of the current working directory. |
8304 | The pathname printed contains no symbolic links if the | |
726f6388 | 8305 | .B \-P |
ccc6cda3 JA |
8306 | option is supplied or the |
8307 | .B \-o physical | |
726f6388 JA |
8308 | option to the |
8309 | .B set | |
ccc6cda3 JA |
8310 | builtin command is enabled. |
8311 | If the | |
8312 | .B \-L | |
bb70624e | 8313 | option is used, the pathname printed may contain symbolic links. |
ccc6cda3 | 8314 | The return status is 0 unless an error occurs while |
cce855bc JA |
8315 | reading the name of the current directory or an |
8316 | invalid option is supplied. | |
726f6388 | 8317 | .TP |
08e72d7a | 8318 | \fBread\fP [\fB\-ers\fP] [\fB\-a\fP \fIaname\fP] [\fB\-d\fP \fIdelim\fP] [\fB\-i\fP \fItext\fP] [\fB\-n\fP \fInchars\fP] [\fB\-N\fP \fInchars\fP] [\fB\-p\fP \fIprompt\fP] [\fB\-t\fP \fItimeout\fP] [\fB\-u\fP \fIfd\fP] [\fIname\fP ...] |
7117c2d2 JA |
8319 | One line is read from the standard input, or from the file descriptor |
8320 | \fIfd\fP supplied as an argument to the \fB\-u\fP option, and the first word | |
726f6388 JA |
8321 | is assigned to the first |
8322 | .IR name , | |
8323 | the second word to the second | |
8324 | .IR name , | |
cce855bc JA |
8325 | and so on, with leftover words and their intervening separators assigned |
8326 | to the last | |
726f6388 | 8327 | .IR name . |
7117c2d2 | 8328 | If there are fewer words read from the input stream than names, |
cce855bc JA |
8329 | the remaining names are assigned empty values. |
8330 | The characters in | |
726f6388 JA |
8331 | .SM |
8332 | .B IFS | |
cce855bc | 8333 | are used to split the line into words. |
b72432fd JA |
8334 | The backslash character (\fB\e\fP) may be used to remove any special |
8335 | meaning for the next character read and for line continuation. | |
cce855bc | 8336 | Options, if supplied, have the following meanings: |
ccc6cda3 JA |
8337 | .RS |
8338 | .PD 0 | |
8339 | .TP | |
bb70624e | 8340 | .B \-a \fIaname\fP |
ccc6cda3 JA |
8341 | The words are assigned to sequential indices |
8342 | of the array variable | |
8343 | .IR aname , | |
8344 | starting at 0. | |
8345 | .I aname | |
8346 | is unset before any new values are assigned. | |
cce855bc | 8347 | Other \fIname\fP arguments are ignored. |
ccc6cda3 | 8348 | .TP |
bb70624e JA |
8349 | .B \-d \fIdelim\fP |
8350 | The first character of \fIdelim\fP is used to terminate the input line, | |
8351 | rather than newline. | |
8352 | .TP | |
ccc6cda3 JA |
8353 | .B \-e |
8354 | If the standard input | |
8355 | is coming from a terminal, | |
8356 | .B readline | |
8357 | (see | |
8358 | .SM | |
8359 | .B READLINE | |
8360 | above) is used to obtain the line. | |
14e8b2a7 CR |
8361 | Readline uses the current (or default, if line editing was not previously |
8362 | active) editing settings. | |
bb70624e | 8363 | .TP |
1d0e1a34 CR |
8364 | .B \-i \fItext\fP |
8365 | If | |
8366 | .B readline | |
8367 | is being used to read the line, \fItext\fP is placed into the editing | |
8368 | buffer before editing begins. | |
8369 | .TP | |
bb70624e JA |
8370 | .B \-n \fInchars\fP |
8371 | \fBread\fP returns after reading \fInchars\fP characters rather than | |
08e72d7a CR |
8372 | waiting for a complete line of input, but honor a delimiter if fewer |
8373 | than \fInchars\fP characters are read before the delimiter. | |
8374 | .TP | |
8375 | .B \-N \fInchars\fP | |
8376 | \fBread\fP returns after reading exactly \fInchars\fP characters rather | |
8377 | than waiting for a complete line of input, unless EOF is encountered or | |
a3143574 CR |
8378 | \fBread\fP times out. |
8379 | Delimiter characters encountered in the input are | |
8380 | not treated specially and do not cause \fBread\fP to return until | |
8381 | \fInchars\fP characters are read. | |
bb70624e JA |
8382 | .TP |
8383 | .B \-p \fIprompt\fP | |
f73dda09 | 8384 | Display \fIprompt\fP on standard error, without a |
bb70624e JA |
8385 | trailing newline, before attempting to read any input. The prompt |
8386 | is displayed only if input is coming from a terminal. | |
8387 | .TP | |
8388 | .B \-r | |
8389 | Backslash does not act as an escape character. | |
8390 | The backslash is considered to be part of the line. | |
8391 | In particular, a backslash-newline pair may not be used as a line | |
8392 | continuation. | |
8393 | .TP | |
8394 | .B \-s | |
8395 | Silent mode. If input is coming from a terminal, characters are | |
8396 | not echoed. | |
8397 | .TP | |
8398 | .B \-t \fItimeout\fP | |
8399 | Cause \fBread\fP to time out and return failure if a complete line of | |
8400 | input is not read within \fItimeout\fP seconds. | |
4ac1ff98 CR |
8401 | \fItimeout\fP may be a decimal number with a fractional portion following |
8402 | the decimal point. | |
e33f2203 CR |
8403 | This option is only effective if \fBread\fP is reading input from a |
8404 | terminal, pipe, or other special file; it has no effect when reading | |
8405 | from regular files. | |
b13b8a87 CR |
8406 | If \fItimeout\fP is 0, \fBread\fP returns immediately, without trying to |
8407 | read any data. The exit statis is 0 if input is available on | |
8408 | the specified file descriptor, non-zero otherwise. | |
e33f2203 | 8409 | The exit status is greater than 128 if the timeout is exceeded. |
7117c2d2 | 8410 | .TP |
0f445e6c | 8411 | .B \-u \fIfd\fP |
7117c2d2 | 8412 | Read input from file descriptor \fIfd\fP. |
ccc6cda3 JA |
8413 | .PD |
8414 | .PP | |
8415 | If no | |
726f6388 JA |
8416 | .I names |
8417 | are supplied, the line read is assigned to the variable | |
8418 | .SM | |
8419 | .BR REPLY . | |
7117c2d2 | 8420 | The return code is zero, unless end-of-file is encountered, \fBread\fP |
09767ff0 CR |
8421 | times out (in which case the return code is greater than 128), or an |
8422 | invalid file descriptor is supplied as the argument to \fB\-u\fP. | |
ccc6cda3 | 8423 | .RE |
726f6388 | 8424 | .TP |
54a1fa7c | 8425 | \fBreadonly\fP [\fB\-aAf\fP] [\fB\-p\fP] [\fIname\fP[=\fIword\fP] ...] |
726f6388 JA |
8426 | .PD |
8427 | The given | |
ccc6cda3 JA |
8428 | \fInames\fP are marked readonly; the values of these |
8429 | .I names | |
726f6388 JA |
8430 | may not be changed by subsequent assignment. |
8431 | If the | |
8432 | .B \-f | |
8433 | option is supplied, the functions corresponding to the | |
8434 | \fInames\fP are so | |
ccc6cda3 JA |
8435 | marked. |
8436 | The | |
8437 | .B \-a | |
fdf670ea CR |
8438 | option restricts the variables to indexed arrays; the |
8439 | .B \-A | |
8440 | option restricts the variables to associative arrays. | |
54a1fa7c CR |
8441 | If both options are supplied, |
8442 | .B \-A | |
8443 | takes precedence. | |
ccc6cda3 JA |
8444 | If no |
8445 | .I name | |
8446 | arguments are given, or if the | |
726f6388 | 8447 | .B \-p |
ccc6cda3 | 8448 | option is supplied, a list of all readonly names is printed. |
54a1fa7c CR |
8449 | The other options may be used to restrict the output to a subset of |
8450 | the set of readonly names. | |
cce855bc JA |
8451 | The |
8452 | .B \-p | |
bb70624e JA |
8453 | option causes output to be displayed in a format that |
8454 | may be reused as input. | |
d3a24ed2 CR |
8455 | If a variable name is followed by =\fIword\fP, the value of |
8456 | the variable is set to \fIword\fP. | |
cce855bc | 8457 | The return status is 0 unless an invalid option is encountered, |
ccc6cda3 JA |
8458 | one of the |
8459 | .I names | |
cce855bc | 8460 | is not a valid shell variable name, or |
726f6388 JA |
8461 | .B \-f |
8462 | is supplied with a | |
8463 | .I name | |
8464 | that is not a function. | |
8465 | .TP | |
8466 | \fBreturn\fP [\fIn\fP] | |
b28ff8c9 CR |
8467 | Causes a function to stop executing and return the value specified by |
8468 | .I n | |
8469 | to its caller. | |
726f6388 JA |
8470 | If |
8471 | .I n | |
8472 | is omitted, the return status is that of the last command | |
b28ff8c9 CR |
8473 | executed in the function body. If |
8474 | .B return | |
8475 | is used outside a function, | |
726f6388 JA |
8476 | but during execution of a script by the |
8477 | .B . | |
8478 | (\fBsource\fP) command, it causes the shell to stop executing | |
8479 | that script and return either | |
8480 | .I n | |
8481 | or the exit status of the last command executed within the | |
b28ff8c9 CR |
8482 | script as the exit status of the script. |
8483 | The return status is non-zero if | |
8484 | .B return | |
8485 | is used outside a | |
8486 | function and not during execution of a script by \fB.\fP\^ or \fBsource\fP. | |
d3a24ed2 CR |
8487 | Any command associated with the \fBRETURN\fP trap is executed |
8488 | before execution resumes after the function or script. | |
726f6388 | 8489 | .TP |
dc60d4e0 | 8490 | \fBset\fP [\fB\-\-abefhkmnptuvxBCEHPT\fP] [\fB\-o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de CR |
8491 | .PD 0 |
8492 | .TP | |
dc60d4e0 | 8493 | \fBset\fP [\fB+abefhkmnptuvxBCEHPT\fP] [\fB+o\fP \fIoption\-name\fP] [\fIarg\fP ...] |
d3ad40de | 8494 | .PD |
ccc6cda3 | 8495 | Without options, the name and value of each shell variable are displayed |
54cdd75a CR |
8496 | in a format that can be reused as input |
8497 | for setting or resetting the currently-set variables. | |
8498 | Read-only variables cannot be reset. | |
8499 | In \fIposix mode\fP, only shell variables are listed. | |
cce855bc | 8500 | The output is sorted according to the current locale. |
ccc6cda3 | 8501 | When options are specified, they set or unset shell attributes. |
626d0694 | 8502 | Any arguments remaining after option processing are treated |
ccc6cda3 JA |
8503 | as values for the positional parameters and are assigned, in order, to |
8504 | .BR $1 , | |
8505 | .BR $2 , | |
8506 | .B ... | |
8507 | .BR $\fIn\fP . | |
8508 | Options, if specified, have the following meanings: | |
726f6388 JA |
8509 | .RS |
8510 | .PD 0 | |
8511 | .TP 8 | |
8512 | .B \-a | |
5e13499c CR |
8513 | Automatically mark variables and functions which are modified or |
8514 | created for export to the environment of subsequent commands. | |
726f6388 JA |
8515 | .TP 8 |
8516 | .B \-b | |
ccc6cda3 JA |
8517 | Report the status of terminated background jobs |
8518 | immediately, rather than before the next primary prompt. This is | |
8519 | effective only when job control is enabled. | |
726f6388 JA |
8520 | .TP 8 |
8521 | .B \-e | |
15825757 CR |
8522 | Exit immediately if a |
8523 | \fIpipeline\fP (which may consist of a single \fIsimple command\fP), | |
8524 | a \fIlist\fP, | |
8525 | or a \fIcompound command\fP | |
8526 | (see | |
726f6388 JA |
8527 | .SM |
8528 | .B SHELL GRAMMAR | |
15825757 | 8529 | above), exits with a non-zero status. |
d3a24ed2 CR |
8530 | The shell does not exit if the |
8531 | command that fails is part of the command list immediately following a | |
8532 | .B while | |
726f6388 | 8533 | or |
d3a24ed2 CR |
8534 | .B until |
8535 | keyword, | |
4b9cc222 | 8536 | part of the test following the |
d3ad40de | 8537 | .B if |
4b9cc222 CR |
8538 | or |
8539 | .B elif | |
8540 | reserved words, part of any command executed in a | |
726f6388 JA |
8541 | .B && |
8542 | or | |
adc6cff5 CR |
8543 | .B || |
8544 | list except the command following the final \fB&&\fP or \fB||\fP, | |
d3ad40de CR |
8545 | any command in a pipeline but the last, |
8546 | or if the command's return value is | |
a05a1337 | 8547 | being inverted with |
726f6388 | 8548 | .BR ! . |
15825757 CR |
8549 | If a compound command other than a subshell |
8550 | returns a non-zero status because a command failed | |
8551 | while \fB\-e\fP was being ignored, the shell does not exit. | |
f73dda09 | 8552 | A trap on \fBERR\fP, if set, is executed before the shell exits. |
a05a1337 CR |
8553 | This option applies to the shell environment and each subshell environment |
8554 | separately (see | |
984a1947 | 8555 | .SM |
a05a1337 CR |
8556 | .B "COMMAND EXECUTION ENVIRONMENT" |
8557 | above), and may cause | |
8558 | subshells to exit before executing all the commands in the subshell. | |
726f6388 JA |
8559 | .TP 8 |
8560 | .B \-f | |
8561 | Disable pathname expansion. | |
8562 | .TP 8 | |
8563 | .B \-h | |
ccc6cda3 | 8564 | Remember the location of commands as they are looked up for execution. |
cce855bc | 8565 | This is enabled by default. |
726f6388 JA |
8566 | .TP 8 |
8567 | .B \-k | |
ccc6cda3 JA |
8568 | All arguments in the form of assignment statements |
8569 | are placed in the environment for a command, not just | |
8570 | those that precede the command name. | |
726f6388 JA |
8571 | .TP 8 |
8572 | .B \-m | |
cce855bc | 8573 | Monitor mode. Job control is enabled. This option is on |
726f6388 JA |
8574 | by default for interactive shells on systems that support |
8575 | it (see | |
8576 | .SM | |
8577 | .B JOB CONTROL | |
f6da9f85 CR |
8578 | above). |
8579 | All processes run in a separate process group. | |
8580 | When a background job completes, the shell prints a line | |
8581 | containing its exit status. | |
726f6388 JA |
8582 | .TP 8 |
8583 | .B \-n | |
8584 | Read commands but do not execute them. This may be used to | |
ccc6cda3 | 8585 | check a shell script for syntax errors. This is ignored by |
726f6388 JA |
8586 | interactive shells. |
8587 | .TP 8 | |
ccc6cda3 JA |
8588 | .B \-o \fIoption\-name\fP |
8589 | The \fIoption\-name\fP can be one of the following: | |
726f6388 JA |
8590 | .RS |
8591 | .TP 8 | |
8592 | .B allexport | |
8593 | Same as | |
8594 | .BR \-a . | |
8595 | .TP 8 | |
8596 | .B braceexpand | |
ccc6cda3 JA |
8597 | Same as |
8598 | .BR \-B . | |
726f6388 JA |
8599 | .TP 8 |
8600 | .B emacs | |
8601 | Use an emacs-style command line editing interface. This is enabled | |
8602 | by default when the shell is interactive, unless the shell is started | |
8603 | with the | |
ccc6cda3 | 8604 | .B \-\-noediting |
726f6388 | 8605 | option. |
10a4e415 | 8606 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 | 8607 | .TP 8 |
a3143574 CR |
8608 | .B errexit |
8609 | Same as | |
8610 | .BR \-e . | |
8611 | .TP 8 | |
d3a24ed2 CR |
8612 | .B errtrace |
8613 | Same as | |
8614 | .BR \-E . | |
8615 | .TP 8 | |
8616 | .B functrace | |
8617 | Same as | |
8618 | .BR \-T . | |
8619 | .TP 8 | |
ccc6cda3 JA |
8620 | .B hashall |
8621 | Same as | |
8622 | .BR \-h . | |
8623 | .TP 8 | |
726f6388 JA |
8624 | .B histexpand |
8625 | Same as | |
8626 | .BR \-H . | |
8627 | .TP 8 | |
ccc6cda3 JA |
8628 | .B history |
8629 | Enable command history, as described above under | |
8630 | .SM | |
8631 | .BR HISTORY . | |
8632 | This option is on by default in interactive shells. | |
8633 | .TP 8 | |
726f6388 | 8634 | .B ignoreeof |
28ef6c31 JA |
8635 | The effect is as if the shell command |
8636 | .if t \f(CWIGNOREEOF=10\fP | |
8637 | .if n ``IGNOREEOF=10'' | |
8638 | had been executed | |
726f6388 JA |
8639 | (see |
8640 | .B Shell Variables | |
8641 | above). | |
8642 | .TP 8 | |
ccc6cda3 JA |
8643 | .B keyword |
8644 | Same as | |
8645 | .BR \-k . | |
726f6388 JA |
8646 | .TP 8 |
8647 | .B monitor | |
8648 | Same as | |
8649 | .BR \-m . | |
8650 | .TP 8 | |
8651 | .B noclobber | |
8652 | Same as | |
8653 | .BR \-C . | |
8654 | .TP 8 | |
8655 | .B noexec | |
8656 | Same as | |
8657 | .BR \-n . | |
8658 | .TP 8 | |
8659 | .B noglob | |
8660 | Same as | |
8661 | .BR \-f . | |
57a3f689 | 8662 | .TP 8 |
f73dda09 JA |
8663 | .B nolog |
8664 | Currently ignored. | |
726f6388 | 8665 | .TP 8 |
726f6388 JA |
8666 | .B notify |
8667 | Same as | |
8668 | .BR \-b . | |
8669 | .TP 8 | |
8670 | .B nounset | |
8671 | Same as | |
8672 | .BR \-u . | |
8673 | .TP 8 | |
ccc6cda3 JA |
8674 | .B onecmd |
8675 | Same as | |
8676 | .BR \-t . | |
8677 | .TP 8 | |
726f6388 JA |
8678 | .B physical |
8679 | Same as | |
8680 | .BR \-P . | |
8681 | .TP 8 | |
d3a24ed2 CR |
8682 | .B pipefail |
8683 | If set, the return value of a pipeline is the value of the last | |
8684 | (rightmost) command to exit with a non-zero status, or zero if all | |
8685 | commands in the pipeline exit successfully. | |
8686 | This option is disabled by default. | |
8687 | .TP 8 | |
726f6388 | 8688 | .B posix |
ccc6cda3 JA |
8689 | Change the behavior of |
8690 | .B bash | |
8691 | where the default operation differs | |
ac18b312 | 8692 | from the POSIX standard to match the standard (\fIposix mode\fP). |
726f6388 JA |
8693 | .TP 8 |
8694 | .B privileged | |
8695 | Same as | |
8696 | .BR \-p . | |
8697 | .TP 8 | |
8698 | .B verbose | |
8699 | Same as | |
8700 | .BR \-v . | |
8701 | .TP 8 | |
8702 | .B vi | |
8703 | Use a vi-style command line editing interface. | |
10a4e415 | 8704 | This also affects the editing interface used for \fBread \-e\fP. |
726f6388 JA |
8705 | .TP 8 |
8706 | .B xtrace | |
8707 | Same as | |
8708 | .BR \-x . | |
ccc6cda3 | 8709 | .sp .5 |
726f6388 | 8710 | .PP |
ccc6cda3 JA |
8711 | If |
8712 | .B \-o | |
8713 | is supplied with no \fIoption\-name\fP, the values of the current options are | |
726f6388 | 8714 | printed. |
ccc6cda3 JA |
8715 | If |
8716 | .B +o | |
8717 | is supplied with no \fIoption\-name\fP, a series of | |
8718 | .B set | |
8719 | commands to recreate the current option settings is displayed on | |
8720 | the standard output. | |
726f6388 JA |
8721 | .RE |
8722 | .TP 8 | |
8723 | .B \-p | |
8724 | Turn on | |
8725 | .I privileged | |
8726 | mode. In this mode, the | |
bb70624e | 8727 | .SM |
726f6388 | 8728 | .B $ENV |
b72432fd | 8729 | and |
bb70624e | 8730 | .SM |
b72432fd JA |
8731 | .B $BASH_ENV |
8732 | files are not processed, shell functions are not inherited from the | |
bb70624e JA |
8733 | environment, and the |
8734 | .SM | |
e77a3058 | 8735 | .BR SHELLOPTS , |
984a1947 | 8736 | .SM |
691aebcb | 8737 | .BR BASHOPTS , |
984a1947 | 8738 | .SM |
e77a3058 CR |
8739 | .BR CDPATH , |
8740 | and | |
984a1947 | 8741 | .SM |
e77a3058 CR |
8742 | .B GLOBIGNORE |
8743 | variables, if they appear in the environment, are ignored. | |
b72432fd JA |
8744 | If the shell is started with the effective user (group) id not equal to the |
8745 | real user (group) id, and the \fB\-p\fP option is not supplied, these actions | |
8746 | are taken and the effective user id is set to the real user id. | |
8747 | If the \fB\-p\fP option is supplied at startup, the effective user id is | |
8748 | not reset. | |
cce855bc | 8749 | Turning this option off causes the effective user |
726f6388 JA |
8750 | and group ids to be set to the real user and group ids. |
8751 | .TP 8 | |
8752 | .B \-t | |
8753 | Exit after reading and executing one command. | |
8754 | .TP 8 | |
8755 | .B \-u | |
2c471a92 CR |
8756 | Treat unset variables and parameters other than the special |
8757 | parameters "@" and "*" as an error when performing | |
726f6388 | 8758 | parameter expansion. If expansion is attempted on an |
2c471a92 | 8759 | unset variable or parameter, the shell prints an error message, and, |
ccc6cda3 | 8760 | if not interactive, exits with a non-zero status. |
726f6388 JA |
8761 | .TP 8 |
8762 | .B \-v | |
8763 | Print shell input lines as they are read. | |
8764 | .TP 8 | |
8765 | .B \-x | |
ccc6cda3 | 8766 | After expanding each \fIsimple command\fP, |
d3a24ed2 CR |
8767 | \fBfor\fP command, \fBcase\fP command, \fBselect\fP command, or |
8768 | arithmetic \fBfor\fP command, display the expanded value of | |
726f6388 JA |
8769 | .SM |
8770 | .BR PS4 , | |
d3a24ed2 CR |
8771 | followed by the command and its expanded arguments |
8772 | or associated word list. | |
726f6388 | 8773 | .TP 8 |
ccc6cda3 JA |
8774 | .B \-B |
8775 | The shell performs brace expansion (see | |
8776 | .B Brace Expansion | |
8777 | above). This is on by default. | |
726f6388 JA |
8778 | .TP 8 |
8779 | .B \-C | |
ccc6cda3 JA |
8780 | If set, |
8781 | .B bash | |
8782 | does not overwrite an existing file with the | |
8783 | .BR > , | |
8784 | .BR >& , | |
8785 | and | |
8786 | .B <> | |
8787 | redirection operators. This may be overridden when | |
8788 | creating output files by using the redirection operator | |
8789 | .B >| | |
8790 | instead of | |
8791 | .BR > . | |
726f6388 | 8792 | .TP 8 |
d3a24ed2 CR |
8793 | .B \-E |
8794 | If set, any trap on \fBERR\fP is inherited by shell functions, command | |
8795 | substitutions, and commands executed in a subshell environment. | |
8796 | The \fBERR\fP trap is normally not inherited in such cases. | |
8797 | .TP 8 | |
726f6388 JA |
8798 | .B \-H |
8799 | Enable | |
8800 | .B ! | |
cce855bc | 8801 | style history substitution. This option is on by |
726f6388 JA |
8802 | default when the shell is interactive. |
8803 | .TP 8 | |
8804 | .B \-P | |
ccc6cda3 JA |
8805 | If set, the shell does not follow symbolic links when executing |
8806 | commands such as | |
726f6388 | 8807 | .B cd |
ccc6cda3 JA |
8808 | that change the current working directory. It uses the |
8809 | physical directory structure instead. By default, | |
8810 | .B bash | |
8811 | follows the logical chain of directories when performing commands | |
8812 | which change the current directory. | |
726f6388 | 8813 | .TP 8 |
d3a24ed2 | 8814 | .B \-T |
76a8d78d CR |
8815 | If set, any traps on \fBDEBUG\fP and \fBRETURN\fP are inherited by shell |
8816 | functions, command substitutions, and commands executed in a | |
8817 | subshell environment. | |
8818 | The \fBDEBUG\fP and \fBRETURN\fP traps are normally not inherited | |
8819 | in such cases. | |
d3a24ed2 | 8820 | .TP 8 |
726f6388 | 8821 | .B \-\- |
cce855bc | 8822 | If no arguments follow this option, then the positional parameters are |
726f6388 JA |
8823 | unset. Otherwise, the positional parameters are set to the |
8824 | \fIarg\fPs, even if some of them begin with a | |
8825 | .BR \- . | |
8826 | .TP 8 | |
8827 | .B \- | |
8828 | Signal the end of options, cause all remaining \fIarg\fPs to be | |
8829 | assigned to the positional parameters. The | |
8830 | .B \-x | |
8831 | and | |
8832 | .B \-v | |
8833 | options are turned off. | |
8834 | If there are no \fIarg\fPs, | |
8835 | the positional parameters remain unchanged. | |
8836 | .PD | |
8837 | .PP | |
cce855bc JA |
8838 | The options are off by default unless otherwise noted. |
8839 | Using + rather than \- causes these options to be turned off. | |
8840 | The options can also be specified as arguments to an invocation of | |
8841 | the shell. | |
8842 | The current set of options may be found in | |
726f6388 | 8843 | .BR $\- . |
cce855bc | 8844 | The return status is always true unless an invalid option is encountered. |
726f6388 JA |
8845 | .RE |
8846 | .TP | |
8847 | \fBshift\fP [\fIn\fP] | |
8848 | The positional parameters from \fIn\fP+1 ... are renamed to | |
8849 | .B $1 | |
8850 | .B .... | |
8851 | Parameters represented by the numbers \fB$#\fP | |
8852 | down to \fB$#\fP\-\fIn\fP+1 are unset. | |
ccc6cda3 JA |
8853 | .I n |
8854 | must be a non-negative number less than or equal to \fB$#\fP. | |
726f6388 JA |
8855 | If |
8856 | .I n | |
8857 | is 0, no parameters are changed. | |
8858 | If | |
8859 | .I n | |
8860 | is not given, it is assumed to be 1. | |
726f6388 JA |
8861 | If |
8862 | .I n | |
8863 | is greater than \fB$#\fP, the positional parameters are not changed. | |
ccc6cda3 | 8864 | The return status is greater than zero if |
726f6388 JA |
8865 | .I n |
8866 | is greater than | |
8867 | .B $# | |
ccc6cda3 JA |
8868 | or less than zero; otherwise 0. |
8869 | .TP | |
8870 | \fBshopt\fP [\fB\-pqsu\fP] [\fB\-o\fP] [\fIoptname\fP ...] | |
8871 | Toggle the values of variables controlling optional shell behavior. | |
8872 | With no options, or with the | |
8873 | .B \-p | |
8874 | option, a list of all settable options is displayed, with | |
cce855bc JA |
8875 | an indication of whether or not each is set. |
8876 | The \fB\-p\fP option causes output to be displayed in a form that | |
8877 | may be reused as input. | |
8878 | Other options have the following meanings: | |
ccc6cda3 JA |
8879 | .RS |
8880 | .PD 0 | |
8881 | .TP | |
8882 | .B \-s | |
8883 | Enable (set) each \fIoptname\fP. | |
8884 | .TP | |
8885 | .B \-u | |
8886 | Disable (unset) each \fIoptname\fP. | |
8887 | .TP | |
8888 | .B \-q | |
8889 | Suppresses normal output (quiet mode); the return status indicates | |
8890 | whether the \fIoptname\fP is set or unset. | |
8891 | If multiple \fIoptname\fP arguments are given with | |
8892 | .BR \-q , | |
8893 | the return status is zero if all \fIoptnames\fP are enabled; non-zero | |
8894 | otherwise. | |
8895 | .TP | |
8896 | .B \-o | |
8897 | Restricts the values of \fIoptname\fP to be those defined for the | |
8898 | .B \-o | |
8899 | option to the | |
8900 | .B set | |
8901 | builtin. | |
8902 | .PD | |
8903 | .PP | |
8904 | If either | |
8905 | .B \-s | |
8906 | or | |
8907 | .B \-u | |
b28ff8c9 CR |
8908 | is used with no \fIoptname\fP arguments, |
8909 | .B shopt | |
8910 | shows only those options which are set or unset, respectively. | |
ccc6cda3 JA |
8911 | Unless otherwise noted, the \fBshopt\fP options are disabled (unset) |
8912 | by default. | |
8913 | .PP | |
8914 | The return status when listing options is zero if all \fIoptnames\fP | |
8915 | are enabled, non-zero otherwise. When setting or unsetting options, | |
cce855bc | 8916 | the return status is zero unless an \fIoptname\fP is not a valid shell |
ccc6cda3 JA |
8917 | option. |
8918 | .PP | |
8919 | The list of \fBshopt\fP options is: | |
8920 | .if t .sp .5v | |
8921 | .if n .sp 1v | |
8922 | .PD 0 | |
8923 | .TP 8 | |
d3ad40de CR |
8924 | .B autocd |
8925 | If set, a command name that is the name of a directory is executed as if | |
8926 | it were the argument to the \fBcd\fP command. | |
8927 | This option is only used by interactive shells. | |
8928 | .TP 8 | |
ccc6cda3 JA |
8929 | .B cdable_vars |
8930 | If set, an argument to the | |
8931 | .B cd | |
8932 | builtin command that | |
8933 | is not a directory is assumed to be the name of a variable whose | |
8934 | value is the directory to change to. | |
8935 | .TP 8 | |
8936 | .B cdspell | |
8937 | If set, minor errors in the spelling of a directory component in a | |
8938 | .B cd | |
8939 | command will be corrected. | |
8940 | The errors checked for are transposed characters, | |
8941 | a missing character, and one character too many. | |
b28ff8c9 | 8942 | If a correction is found, the corrected filename is printed, |
ccc6cda3 | 8943 | and the command proceeds. |
d166f048 | 8944 | This option is only used by interactive shells. |
ccc6cda3 JA |
8945 | .TP 8 |
8946 | .B checkhash | |
8947 | If set, \fBbash\fP checks that a command found in the hash | |
8948 | table exists before trying to execute it. If a hashed command no | |
8949 | longer exists, a normal path search is performed. | |
8950 | .TP 8 | |
d3ad40de | 8951 | .B checkjobs |
29d25b54 | 8952 | If set, \fBbash\fP lists the status of any stopped and running jobs before |
d3ad40de CR |
8953 | exiting an interactive shell. If any jobs are running, this causes |
8954 | the exit to be deferred until a second exit is attempted without an | |
984a1947 CR |
8955 | intervening command (see |
8956 | .SM | |
8957 | .B "JOB CONTROL" | |
8958 | above). The shell always | |
d3ad40de CR |
8959 | postpones exiting if any jobs are stopped. |
8960 | .TP 8 | |
ccc6cda3 | 8961 | .B checkwinsize |
51f7ea36 | 8962 | If set, \fBbash\fP checks the window size after each command |
ccc6cda3 JA |
8963 | and, if necessary, updates the values of |
8964 | .SM | |
8965 | .B LINES | |
8966 | and | |
8967 | .SM | |
8968 | .BR COLUMNS . | |
8969 | .TP 8 | |
8970 | .B cmdhist | |
8971 | If set, | |
8972 | .B bash | |
8973 | attempts to save all lines of a multiple-line | |
8974 | command in the same history entry. This allows | |
8975 | easy re-editing of multi-line commands. | |
8976 | .TP 8 | |
35ee8ea0 CR |
8977 | .B compat31 |
8978 | If set, | |
8979 | .B bash | |
8980 | changes its behavior to that of version 3.1 with respect to quoted | |
54a1fa7c | 8981 | arguments to the \fB[[\fP conditional command's \fB=~\fP operator. |
35ee8ea0 | 8982 | .TP 8 |
cd0ef727 CR |
8983 | .B compat32 |
8984 | If set, | |
8985 | .B bash | |
8986 | changes its behavior to that of version 3.2 with respect to locale-specific | |
54a1fa7c CR |
8987 | string comparison when using the \fB[[\fP |
8988 | conditional command's \fB<\fP and \fB>\fP operators. | |
8989 | Bash versions prior to bash-4.1 use ASCII collation and | |
8990 | .IR strcmp (3); | |
8991 | bash-4.1 and later | |
8992 | use the current locale's collation sequence and | |
8993 | .IR strcoll (3). | |
cd0ef727 CR |
8994 | .TP 8 |
8995 | .B compat40 | |
8996 | If set, | |
8997 | .B bash | |
8998 | changes its behavior to that of version 4.0 with respect to locale-specific | |
54a1fa7c CR |
8999 | string comparison when using the \fB[[\fP |
9000 | conditional command's \fB<\fP and \fB>\fP operators (see previous item) | |
9001 | and the effect of interrupting a command list. | |
cd0ef727 | 9002 | .TP 8 |
67362c60 | 9003 | .B compat41 |
67362c60 CR |
9004 | If set, |
9005 | .BR bash , | |
9006 | when in posix mode, treats a single quote in a double-quoted | |
9007 | parameter expansion as a special character. The single quotes must match | |
9008 | (an even number) and the characters between the single quotes are considered | |
9009 | quoted. This is the behavior of posix mode through version 4.1. | |
9010 | The default bash behavior remains as in previous versions. | |
9011 | .TP 8 | |
ddef12ff CR |
9012 | .B complete_fullquote |
9013 | If set, | |
9014 | .B bash | |
9015 | quotes all shell metacharacters in filenames and directory names when | |
9016 | performing completion. | |
9017 | If not set, | |
9018 | .B bash | |
9019 | removes metacharacters such as the dollar sign from the set of | |
9020 | characters that will be quoted in completed filenames | |
9021 | when these metacharacters appear in shell variable references in words to be | |
9022 | completed. | |
9023 | This means that dollar signs in variable names that expand to directories | |
9024 | will not be quoted; | |
9025 | however, any dollar signs appearing in filenames will not be quoted, either. | |
9026 | This is active only when bash is using backslashes to quote completed | |
9027 | filenames. | |
9028 | This variable is set by default, which is the default bash behavior in | |
9029 | versions through 4.2. | |
9030 | .TP 8 | |
74d0116b CR |
9031 | .B direxpand |
9032 | If set, | |
9033 | .B bash | |
9034 | replaces directory names with the results of word expansion when performing | |
9035 | filename completion. This changes the contents of the readline editing | |
9036 | buffer. | |
9037 | If not set, | |
9038 | .B bash | |
9039 | attempts to preserve what the user typed. | |
9040 | .TP 8 | |
4ac1ff98 CR |
9041 | .B dirspell |
9042 | If set, | |
9043 | .B bash | |
9044 | attempts spelling correction on directory names during word completion | |
9045 | if the directory name initially supplied does not exist. | |
9046 | .TP 8 | |
ccc6cda3 JA |
9047 | .B dotglob |
9048 | If set, | |
9049 | .B bash | |
9050 | includes filenames beginning with a `.' in the results of pathname | |
9051 | expansion. | |
9052 | .TP 8 | |
9053 | .B execfail | |
9054 | If set, a non-interactive shell will not exit if | |
9055 | it cannot execute the file specified as an argument to the | |
9056 | .B exec | |
9057 | builtin command. An interactive shell does not exit if | |
9058 | .B exec | |
9059 | fails. | |
9060 | .TP 8 | |
9061 | .B expand_aliases | |
9062 | If set, aliases are expanded as described above under | |
9063 | .SM | |
9064 | .BR ALIASES . | |
9065 | This option is enabled by default for interactive shells. | |
9066 | .TP 8 | |
d3a24ed2 CR |
9067 | .B extdebug |
9068 | If set, behavior intended for use by debuggers is enabled: | |
9069 | .RS | |
9070 | .TP | |
9071 | .B 1. | |
9072 | The \fB\-F\fP option to the \fBdeclare\fP builtin displays the source | |
9073 | file name and line number corresponding to each function name supplied | |
9074 | as an argument. | |
9075 | .TP | |
9076 | .B 2. | |
9077 | If the command run by the \fBDEBUG\fP trap returns a non-zero value, the | |
9078 | next command is skipped and not executed. | |
9079 | .TP | |
9080 | .B 3. | |
9081 | If the command run by the \fBDEBUG\fP trap returns a value of 2, and the | |
9082 | shell is executing in a subroutine (a shell function or a shell script | |
9083 | executed by the \fB.\fP or \fBsource\fP builtins), a call to | |
9084 | \fBreturn\fP is simulated. | |
2206f89a CR |
9085 | .TP |
9086 | .B 4. | |
984a1947 CR |
9087 | .SM |
9088 | .B BASH_ARGC | |
9089 | and | |
9090 | .SM | |
9091 | .B BASH_ARGV | |
9092 | are updated as described in their descriptions above. | |
2206f89a CR |
9093 | .TP |
9094 | .B 5. | |
9095 | Function tracing is enabled: command substitution, shell functions, and | |
9096 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
9097 | \fBDEBUG\fP and \fBRETURN\fP traps. | |
9098 | .TP | |
9099 | .B 6. | |
9100 | Error tracing is enabled: command substitution, shell functions, and | |
9101 | subshells invoked with \fB(\fP \fIcommand\fP \fB)\fP inherit the | |
5cdaaf76 | 9102 | \fBERR\fP trap. |
d3a24ed2 CR |
9103 | .RE |
9104 | .TP 8 | |
cce855bc JA |
9105 | .B extglob |
9106 | If set, the extended pattern matching features described above under | |
9107 | \fBPathname Expansion\fP are enabled. | |
9108 | .TP 8 | |
d3a24ed2 | 9109 | .B extquote |
20587658 | 9110 | If set, \fB$\fP\(aq\fIstring\fP\(aq and \fB$\fP"\fIstring\fP" quoting is |
d3a24ed2 CR |
9111 | performed within \fB${\fP\fIparameter\fP\fB}\fP expansions |
9112 | enclosed in double quotes. This option is enabled by default. | |
9113 | .TP 8 | |
9114 | .B failglob | |
9115 | If set, patterns which fail to match filenames during pathname expansion | |
9116 | result in an expansion error. | |
9117 | .TP 8 | |
9118 | .B force_fignore | |
984a1947 CR |
9119 | If set, the suffixes specified by the |
9120 | .SM | |
9121 | .B FIGNORE | |
9122 | shell variable | |
d3a24ed2 CR |
9123 | cause words to be ignored when performing word completion even if |
9124 | the ignored words are the only possible completions. | |
9125 | See | |
9126 | .SM | |
9127 | \fBSHELL VARIABLES\fP | |
984a1947 CR |
9128 | above for a description of |
9129 | .SM | |
9130 | .BR FIGNORE . | |
d3a24ed2 CR |
9131 | This option is enabled by default. |
9132 | .TP 8 | |
74d0116b CR |
9133 | .B globasciiranges |
9134 | If set, range expressions used in pattern matching (see | |
9135 | .SM | |
9136 | .B Pattern Matching | |
9137 | above) behave as if in the traditional C locale when performing | |
9138 | comparisons. That is, the current locale's collating sequence | |
9139 | is not taken into account, so | |
9140 | .B b | |
9141 | will not collate between | |
9142 | .B A | |
9143 | and | |
9144 | .BR B , | |
9145 | and upper-case and lower-case ASCII characters will collate together. | |
9146 | .TP 8 | |
4ac1ff98 | 9147 | .B globstar |
d0ca3503 | 9148 | If set, the pattern \fB**\fP used in a pathname expansion context will |
54a1fa7c | 9149 | match all files and zero or more directories and subdirectories. |
4ac1ff98 CR |
9150 | If the pattern is followed by a \fB/\fP, only directories and |
9151 | subdirectories match. | |
9152 | .TP 8 | |
d3a24ed2 CR |
9153 | .B gnu_errfmt |
9154 | If set, shell error messages are written in the standard GNU error | |
9155 | message format. | |
9156 | .TP 8 | |
ccc6cda3 JA |
9157 | .B histappend |
9158 | If set, the history list is appended to the file named by the value | |
9159 | of the | |
984a1947 | 9160 | .SM |
ccc6cda3 JA |
9161 | .B HISTFILE |
9162 | variable when the shell exits, rather than overwriting the file. | |
9163 | .TP 8 | |
9164 | .B histreedit | |
9165 | If set, and | |
9166 | .B readline | |
9167 | is being used, a user is given the opportunity to re-edit a | |
9168 | failed history substitution. | |
9169 | .TP 8 | |
9170 | .B histverify | |
9171 | If set, and | |
9172 | .B readline | |
9173 | is being used, the results of history substitution are not immediately | |
9174 | passed to the shell parser. Instead, the resulting line is loaded into | |
9175 | the \fBreadline\fP editing buffer, allowing further modification. | |
9176 | .TP 8 | |
9177 | .B hostcomplete | |
9178 | If set, and | |
9179 | .B readline | |
cce855bc JA |
9180 | is being used, \fBbash\fP will attempt to perform hostname completion when a |
9181 | word containing a \fB@\fP is being completed (see | |
ccc6cda3 JA |
9182 | .B Completing |
9183 | under | |
9184 | .SM | |
9185 | .B READLINE | |
9186 | above). | |
9187 | This is enabled by default. | |
9188 | .TP 8 | |
cce855bc JA |
9189 | .B huponexit |
9190 | If set, \fBbash\fP will send | |
9191 | .SM | |
9192 | .B SIGHUP | |
9193 | to all jobs when an interactive login shell exits. | |
9194 | .TP 8 | |
ccc6cda3 JA |
9195 | .B interactive_comments |
9196 | If set, allow a word beginning with | |
9197 | .B # | |
9198 | to cause that word and all remaining characters on that | |
9199 | line to be ignored in an interactive shell (see | |
9200 | .SM | |
9201 | .B COMMENTS | |
9202 | above). This option is enabled by default. | |
9203 | .TP 8 | |
7d92f73f CR |
9204 | .B lastpipe |
9205 | If set, and job control is not active, the shell runs the last command of | |
9206 | a pipeline not executed in the background in the current shell environment. | |
9207 | .TP 8 | |
ccc6cda3 JA |
9208 | .B lithist |
9209 | If set, and the | |
9210 | .B cmdhist | |
9211 | option is enabled, multi-line commands are saved to the history with | |
9212 | embedded newlines rather than using semicolon separators where possible. | |
9213 | .TP 8 | |
f73dda09 JA |
9214 | .B login_shell |
9215 | The shell sets this option if it is started as a login shell (see | |
9216 | .SM | |
9217 | .B "INVOCATION" | |
9218 | above). | |
9219 | The value may not be changed. | |
9220 | .TP 8 | |
ccc6cda3 JA |
9221 | .B mailwarn |
9222 | If set, and a file that \fBbash\fP is checking for mail has been | |
9223 | accessed since the last time it was checked, the message ``The mail in | |
9224 | \fImailfile\fP has been read'' is displayed. | |
9225 | .TP 8 | |
bb70624e JA |
9226 | .B no_empty_cmd_completion |
9227 | If set, and | |
9228 | .B readline | |
9229 | is being used, | |
9230 | .B bash | |
984a1947 CR |
9231 | will not attempt to search the |
9232 | .SM | |
9233 | .B PATH | |
9234 | for possible completions when | |
bb70624e JA |
9235 | completion is attempted on an empty line. |
9236 | .TP 8 | |
cce855bc JA |
9237 | .B nocaseglob |
9238 | If set, | |
9239 | .B bash | |
9240 | matches filenames in a case\-insensitive fashion when performing pathname | |
9241 | expansion (see | |
9242 | .B Pathname Expansion | |
9243 | above). | |
9244 | .TP 8 | |
2206f89a CR |
9245 | .B nocasematch |
9246 | If set, | |
9247 | .B bash | |
9248 | matches patterns in a case\-insensitive fashion when performing matching | |
9249 | while executing \fBcase\fP or \fB[[\fP conditional commands. | |
9250 | .TP 8 | |
ccc6cda3 JA |
9251 | .B nullglob |
9252 | If set, | |
9253 | .B bash | |
9254 | allows patterns which match no | |
9255 | files (see | |
9256 | .B Pathname Expansion | |
9257 | above) | |
9258 | to expand to a null string, rather than themselves. | |
9259 | .TP 8 | |
bb70624e JA |
9260 | .B progcomp |
9261 | If set, the programmable completion facilities (see | |
9262 | \fBProgrammable Completion\fP above) are enabled. | |
9263 | This option is enabled by default. | |
9264 | .TP 8 | |
ccc6cda3 | 9265 | .B promptvars |
d3a24ed2 CR |
9266 | If set, prompt strings undergo |
9267 | parameter expansion, command substitution, arithmetic | |
9268 | expansion, and quote removal after being expanded as described in | |
ccc6cda3 JA |
9269 | .SM |
9270 | .B PROMPTING | |
9271 | above. This option is enabled by default. | |
9272 | .TP 8 | |
b72432fd JA |
9273 | .B restricted_shell |
9274 | The shell sets this option if it is started in restricted mode (see | |
9275 | .SM | |
9276 | .B "RESTRICTED SHELL" | |
9277 | below). | |
9278 | The value may not be changed. | |
9279 | This is not reset when the startup files are executed, allowing | |
9280 | the startup files to discover whether or not a shell is restricted. | |
9281 | .TP 8 | |
ccc6cda3 JA |
9282 | .B shift_verbose |
9283 | If set, the | |
9284 | .B shift | |
9285 | builtin prints an error message when the shift count exceeds the | |
9286 | number of positional parameters. | |
9287 | .TP 8 | |
9288 | .B sourcepath | |
9289 | If set, the | |
9290 | \fBsource\fP (\fB.\fP) builtin uses the value of | |
9291 | .SM | |
9292 | .B PATH | |
9293 | to find the directory containing the file supplied as an argument. | |
cce855bc | 9294 | This option is enabled by default. |
bb70624e JA |
9295 | .TP 8 |
9296 | .B xpg_echo | |
9297 | If set, the \fBecho\fP builtin expands backslash-escape sequences | |
9298 | by default. | |
ccc6cda3 | 9299 | .RE |
54a1fa7c | 9300 | .PD |
726f6388 JA |
9301 | .TP |
9302 | \fBsuspend\fP [\fB\-f\fP] | |
9303 | Suspend the execution of this shell until it receives a | |
9304 | .SM | |
9305 | .B SIGCONT | |
09767ff0 | 9306 | signal. A login shell cannot be suspended; the |
726f6388 | 9307 | .B \-f |
09767ff0 CR |
9308 | option can be used to override this and force the suspension. |
9309 | The return status is 0 unless the shell is a login shell and | |
726f6388 JA |
9310 | .B \-f |
9311 | is not supplied, or if job control is not enabled. | |
9312 | .TP | |
726f6388 | 9313 | \fBtest\fP \fIexpr\fP |
7117c2d2 | 9314 | .PD 0 |
726f6388 JA |
9315 | .TP |
9316 | \fB[\fP \fIexpr\fP \fB]\fP | |
b28ff8c9 | 9317 | Return a status of 0 (true) or 1 (false) depending on |
726f6388 JA |
9318 | the evaluation of the conditional expression |
9319 | .IR expr . | |
cce855bc JA |
9320 | Each operator and operand must be a separate argument. |
9321 | Expressions are composed of the primaries described above under | |
9322 | .SM | |
9323 | .BR "CONDITIONAL EXPRESSIONS" . | |
3ffb039a CR |
9324 | \fBtest\fP does not accept any options, nor does it accept and ignore |
9325 | an argument of \fB\-\-\fP as signifying the end of options. | |
cce855bc JA |
9326 | .if t .sp 0.5 |
9327 | .if n .sp 1 | |
9328 | Expressions may be combined using the following operators, listed | |
9329 | in decreasing order of precedence. | |
641d8f00 | 9330 | The evaluation depends on the number of arguments; see below. |
06dff54a | 9331 | Operator precedence is used when there are five or more arguments. |
726f6388 JA |
9332 | .RS |
9333 | .PD 0 | |
9334 | .TP | |
726f6388 JA |
9335 | .B ! \fIexpr\fP |
9336 | True if | |
9337 | .I expr | |
9338 | is false. | |
9339 | .TP | |
cce855bc JA |
9340 | .B ( \fIexpr\fP ) |
9341 | Returns the value of \fIexpr\fP. | |
9342 | This may be used to override the normal precedence of operators. | |
9343 | .TP | |
726f6388 JA |
9344 | \fIexpr1\fP \-\fBa\fP \fIexpr2\fP |
9345 | True if both | |
9346 | .I expr1 | |
cce855bc | 9347 | and |
726f6388 JA |
9348 | .I expr2 |
9349 | are true. | |
9350 | .TP | |
9351 | \fIexpr1\fP \-\fBo\fP \fIexpr2\fP | |
9352 | True if either | |
9353 | .I expr1 | |
cce855bc | 9354 | or |
726f6388 JA |
9355 | .I expr2 |
9356 | is true. | |
cce855bc JA |
9357 | .PD |
9358 | .PP | |
9359 | \fBtest\fP and \fB[\fP evaluate conditional | |
9360 | expressions using a set of rules based on the number of arguments. | |
9361 | .if t .sp 0.5 | |
9362 | .if n .sp 1 | |
9363 | .PD 0 | |
726f6388 | 9364 | .TP |
cce855bc JA |
9365 | 0 arguments |
9366 | The expression is false. | |
9367 | .TP | |
9368 | 1 argument | |
9369 | The expression is true if and only if the argument is not null. | |
9370 | .TP | |
9371 | 2 arguments | |
9372 | If the first argument is \fB!\fP, the expression is true if and | |
9373 | only if the second argument is null. | |
9374 | If the first argument is one of the unary conditional operators listed above | |
9375 | under | |
726f6388 | 9376 | .SM |
cce855bc JA |
9377 | .BR "CONDITIONAL EXPRESSIONS" , |
9378 | the expression is true if the unary test is true. | |
9379 | If the first argument is not a valid unary conditional operator, the expression | |
9380 | is false. | |
9381 | .TP | |
9382 | 3 arguments | |
adc6cff5 | 9383 | The following conditions are applied in the order listed. |
cce855bc JA |
9384 | If the second argument is one of the binary conditional operators listed above |
9385 | under | |
9386 | .SM | |
9387 | .BR "CONDITIONAL EXPRESSIONS" , | |
9388 | the result of the expression is the result of the binary test using | |
9389 | the first and third arguments as operands. | |
641d8f00 CR |
9390 | The \fB\-a\fP and \fB\-o\fP operators are considered binary operators |
9391 | when there are three arguments. | |
cce855bc JA |
9392 | If the first argument is \fB!\fP, the value is the negation of |
9393 | the two-argument test using the second and third arguments. | |
9394 | If the first argument is exactly \fB(\fP and the third argument is | |
9395 | exactly \fB)\fP, the result is the one-argument test of the second | |
9396 | argument. | |
9397 | Otherwise, the expression is false. | |
cce855bc JA |
9398 | .TP |
9399 | 4 arguments | |
9400 | If the first argument is \fB!\fP, the result is the negation of | |
9401 | the three-argument expression composed of the remaining arguments. | |
9402 | Otherwise, the expression is parsed and evaluated according to | |
9403 | precedence using the rules listed above. | |
9404 | .TP | |
9405 | 5 or more arguments | |
9406 | The expression is parsed and evaluated according to precedence | |
9407 | using the rules listed above. | |
54a1fa7c CR |
9408 | .if t .sp 0.5 |
9409 | .if n .sp 1 | |
9410 | .LP | |
9411 | When used with \fBtest\fP or \fB[\fP, the \fB<\fP and \fB>\fP operators | |
9412 | sort lexicographically using ASCII ordering. | |
726f6388 | 9413 | .RE |
cce855bc | 9414 | .PD |
726f6388 JA |
9415 | .TP |
9416 | .B times | |
9417 | Print the accumulated user and system times for the shell and | |
9418 | for processes run from the shell. The return status is 0. | |
9419 | .TP | |
61deeb13 | 9420 | \fBtrap\fP [\fB\-lp\fP] [[\fIarg\fP] \fIsigspec\fP ...] |
726f6388 JA |
9421 | The command |
9422 | .I arg | |
9423 | is to be read and executed when the shell receives | |
9424 | signal(s) | |
9425 | .IR sigspec . | |
9426 | If | |
9427 | .I arg | |
61deeb13 | 9428 | is absent (and there is a single \fIsigspec\fP) or |
726f6388 | 9429 | .BR \- , |
61deeb13 CR |
9430 | each specified signal is |
9431 | reset to its original disposition (the value it had | |
d166f048 JA |
9432 | upon entrance to the shell). |
9433 | If | |
726f6388 | 9434 | .I arg |
d166f048 JA |
9435 | is the null string the signal specified by each |
9436 | .I sigspec | |
9437 | is ignored by the shell and by the commands it invokes. | |
ccc6cda3 JA |
9438 | If |
9439 | .I arg | |
bb70624e | 9440 | is not present and |
ccc6cda3 | 9441 | .B \-p |
bb70624e | 9442 | has been supplied, then the trap commands associated with each |
ccc6cda3 | 9443 | .I sigspec |
bb70624e JA |
9444 | are displayed. |
9445 | If no arguments are supplied or if only | |
ccc6cda3 JA |
9446 | .B \-p |
9447 | is given, | |
9448 | .B trap | |
61deeb13 | 9449 | prints the list of commands associated with each signal. |
d3a24ed2 CR |
9450 | The |
9451 | .B \-l | |
9452 | option causes the shell to print a list of signal names and | |
9453 | their corresponding numbers. | |
d166f048 | 9454 | Each |
726f6388 JA |
9455 | .I sigspec |
9456 | is either | |
d166f048 | 9457 | a signal name defined in <\fIsignal.h\fP>, or a signal number. |
9c7f20c7 CR |
9458 | Signal names are case insensitive and the |
9459 | .SM | |
9460 | .B SIG | |
9461 | prefix is optional. | |
4301bca7 CR |
9462 | .if t .sp 0.5 |
9463 | .if n .sp 1 | |
d166f048 | 9464 | If a |
726f6388 JA |
9465 | .I sigspec |
9466 | is | |
9467 | .SM | |
9468 | .B EXIT | |
9469 | (0) the command | |
9470 | .I arg | |
f73dda09 JA |
9471 | is executed on exit from the shell. |
9472 | If a | |
ccc6cda3 JA |
9473 | .I sigspec |
9474 | is | |
9475 | .SM | |
9476 | .BR DEBUG , | |
9477 | the command | |
9478 | .I arg | |
d3a24ed2 CR |
9479 | is executed before every \fIsimple command\fP, \fIfor\fP command, |
9480 | \fIcase\fP command, \fIselect\fP command, every arithmetic \fIfor\fP | |
9481 | command, and before the first command executes in a shell function (see | |
ccc6cda3 JA |
9482 | .SM |
9483 | .B SHELL GRAMMAR | |
9484 | above). | |
40b074c6 | 9485 | Refer to the description of the \fBextdebug\fP option to the |
d3a24ed2 | 9486 | \fBshopt\fP builtin for details of its effect on the \fBDEBUG\fP trap. |
f73dda09 JA |
9487 | If a |
9488 | .I sigspec | |
9489 | is | |
9490 | .SM | |
4301bca7 CR |
9491 | .BR RETURN , |
9492 | the command | |
9493 | .I arg | |
e05be32d CR |
9494 | is executed each time a shell function or a script executed with |
9495 | the \fB.\fP or \fBsource\fP builtins finishes executing. | |
4301bca7 CR |
9496 | .if t .sp 0.5 |
9497 | .if n .sp 1 | |
9498 | If a | |
9499 | .I sigspec | |
9500 | is | |
9501 | .SM | |
f73dda09 JA |
9502 | .BR ERR , |
9503 | the command | |
9504 | .I arg | |
5e13499c CR |
9505 | is executed whenever a simple command has a non\-zero exit status, |
9506 | subject to the following conditions. | |
f73dda09 JA |
9507 | The |
9508 | .SM | |
d3a24ed2 CR |
9509 | .B ERR |
9510 | trap is not executed if the failed | |
9511 | command is part of the command list immediately following a | |
9512 | .B while | |
f73dda09 | 9513 | or |
d3a24ed2 CR |
9514 | .B until |
9515 | keyword, | |
9516 | part of the test in an | |
f73dda09 | 9517 | .I if |
9d85af6d | 9518 | statement, part of a command executed in a |
f73dda09 JA |
9519 | .B && |
9520 | or | |
adc6cff5 | 9521 | .B || |
f73dda09 JA |
9522 | list, or if the command's return value is |
9523 | being inverted via | |
9524 | .BR ! . | |
5e13499c | 9525 | These are the same conditions obeyed by the \fBerrexit\fP option. |
4301bca7 CR |
9526 | .if t .sp 0.5 |
9527 | .if n .sp 1 | |
726f6388 | 9528 | Signals ignored upon entry to the shell cannot be trapped or reset. |
d3ad40de | 9529 | Trapped signals that are not being ignored are reset to their original |
4301bca7 | 9530 | values in a subshell or subshell environment when one is created. |
d166f048 | 9531 | The return status is false if any |
ccc6cda3 JA |
9532 | .I sigspec |
9533 | is invalid; otherwise | |
726f6388 JA |
9534 | .B trap |
9535 | returns true. | |
9536 | .TP | |
7117c2d2 | 9537 | \fBtype\fP [\fB\-aftpP\fP] \fIname\fP [\fIname\fP ...] |
726f6388 JA |
9538 | With no options, |
9539 | indicate how each | |
9540 | .I name | |
9541 | would be interpreted if used as a command name. | |
9542 | If the | |
cce855bc JA |
9543 | .B \-t |
9544 | option is used, | |
726f6388 | 9545 | .B type |
ccc6cda3 | 9546 | prints a string which is one of |
726f6388 JA |
9547 | .IR alias , |
9548 | .IR keyword , | |
9549 | .IR function , | |
9550 | .IR builtin , | |
9551 | or | |
9552 | .I file | |
9553 | if | |
9554 | .I name | |
9555 | is an alias, shell reserved word, function, builtin, or disk file, | |
ccc6cda3 JA |
9556 | respectively. |
9557 | If the | |
9558 | .I name | |
9559 | is not found, then nothing is printed, and an exit status of false | |
9560 | is returned. | |
726f6388 | 9561 | If the |
cce855bc JA |
9562 | .B \-p |
9563 | option is used, | |
726f6388 JA |
9564 | .B type |
9565 | either returns the name of the disk file | |
9566 | that would be executed if | |
9567 | .I name | |
9568 | were specified as a command name, | |
28ef6c31 JA |
9569 | or nothing if |
9570 | .if t \f(CWtype -t name\fP | |
9571 | .if n ``type -t name'' | |
726f6388 JA |
9572 | would not return |
9573 | .IR file . | |
7117c2d2 JA |
9574 | The |
9575 | .B \-P | |
9576 | option forces a | |
9577 | .SM | |
9578 | .B PATH | |
9579 | search for each \fIname\fP, even if | |
9580 | .if t \f(CWtype -t name\fP | |
9581 | .if n ``type -t name'' | |
9582 | would not return | |
9583 | .IR file . | |
726f6388 | 9584 | If a command is hashed, |
cce855bc | 9585 | .B \-p |
7117c2d2 JA |
9586 | and |
9587 | .B \-P | |
b28ff8c9 | 9588 | print the hashed value, which is not necessarily the file that appears |
726f6388 JA |
9589 | first in |
9590 | .SM | |
9591 | .BR PATH . | |
9592 | If the | |
cce855bc JA |
9593 | .B \-a |
9594 | option is used, | |
726f6388 JA |
9595 | .B type |
9596 | prints all of the places that contain | |
9597 | an executable named | |
9598 | .IR name . | |
9599 | This includes aliases and functions, | |
9600 | if and only if the | |
cce855bc JA |
9601 | .B \-p |
9602 | option is not also used. | |
726f6388 JA |
9603 | The table of hashed commands is not consulted |
9604 | when using | |
cce855bc | 9605 | .BR \-a . |
7117c2d2 JA |
9606 | The |
9607 | .B \-f | |
9608 | option suppresses shell function lookup, as with the \fBcommand\fP builtin. | |
726f6388 | 9609 | .B type |
6a8fd0ed CR |
9610 | returns true if all of the arguments are found, false if |
9611 | any are not found. | |
726f6388 | 9612 | .TP |
6fbe7620 | 9613 | \fBulimit\fP [\fB\-HSTabcdefilmnpqrstuvx\fP [\fIlimit\fP]] |
ccc6cda3 | 9614 | Provides control over the resources available to the shell and to |
f73dda09 | 9615 | processes started by it, on systems that allow such control. |
ccc6cda3 | 9616 | The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is |
79e6c7dc CR |
9617 | set for the given resource. |
9618 | A hard limit cannot be increased by a non-root user once it is set; | |
9619 | a soft limit may be increased up to the value of the hard limit. | |
ccc6cda3 JA |
9620 | If neither \fB\-H\fP nor \fB\-S\fP is specified, both the soft and hard |
9621 | limits are set. | |
f73dda09 JA |
9622 | The value of |
9623 | .I limit | |
9624 | can be a number in the unit specified for the resource | |
9625 | or one of the special values | |
9626 | .BR hard , | |
9627 | .BR soft , | |
9628 | or | |
9629 | .BR unlimited , | |
9630 | which stand for the current hard limit, the current soft limit, and | |
9631 | no limit, respectively. | |
ccc6cda3 | 9632 | If |
726f6388 JA |
9633 | .I limit |
9634 | is omitted, the current value of the soft limit of the resource is | |
ccc6cda3 JA |
9635 | printed, unless the \fB\-H\fP option is given. When more than one |
9636 | resource is specified, the limit name and unit are printed before the value. | |
726f6388 JA |
9637 | Other options are interpreted as follows: |
9638 | .RS | |
9639 | .PD 0 | |
9640 | .TP | |
9641 | .B \-a | |
ccc6cda3 | 9642 | All current limits are reported |
726f6388 | 9643 | .TP |
6fbe7620 CR |
9644 | .B \-b |
9645 | The maximum socket buffer size | |
9646 | .TP | |
726f6388 | 9647 | .B \-c |
ccc6cda3 | 9648 | The maximum size of core files created |
726f6388 JA |
9649 | .TP |
9650 | .B \-d | |
ccc6cda3 | 9651 | The maximum size of a process's data segment |
726f6388 | 9652 | .TP |
dc8fbaf9 CR |
9653 | .B \-e |
9654 | The maximum scheduling priority ("nice") | |
9655 | .TP | |
726f6388 | 9656 | .B \-f |
d3ad40de | 9657 | The maximum size of files written by the shell and its children |
726f6388 | 9658 | .TP |
af12dacd CR |
9659 | .B \-i |
9660 | The maximum number of pending signals | |
9661 | .TP | |
ccc6cda3 JA |
9662 | .B \-l |
9663 | The maximum size that may be locked into memory | |
726f6388 | 9664 | .TP |
ccc6cda3 | 9665 | .B \-m |
db31fb26 | 9666 | The maximum resident set size (many systems do not honor this limit) |
726f6388 | 9667 | .TP |
ccc6cda3 JA |
9668 | .B \-n |
9669 | The maximum number of open file descriptors (most systems do not | |
9670 | allow this value to be set) | |
726f6388 JA |
9671 | .TP |
9672 | .B \-p | |
ccc6cda3 | 9673 | The pipe size in 512-byte blocks (this may not be set) |
726f6388 | 9674 | .TP |
af12dacd CR |
9675 | .B \-q |
9676 | The maximum number of bytes in POSIX message queues | |
9677 | .TP | |
dc8fbaf9 CR |
9678 | .B \-r |
9679 | The maximum real-time scheduling priority | |
9680 | .TP | |
ccc6cda3 JA |
9681 | .B \-s |
9682 | The maximum stack size | |
9683 | .TP | |
9684 | .B \-t | |
9685 | The maximum amount of cpu time in seconds | |
726f6388 JA |
9686 | .TP |
9687 | .B \-u | |
ccc6cda3 | 9688 | The maximum number of processes available to a single user |
726f6388 JA |
9689 | .TP |
9690 | .B \-v | |
68dfe178 CR |
9691 | The maximum amount of virtual memory available to the shell and, on |
9692 | some systems, to its children | |
af12dacd CR |
9693 | .TP |
9694 | .B \-x | |
9695 | The maximum number of file locks | |
6fbe7620 CR |
9696 | .TP |
9697 | .B \-T | |
9698 | The maximum number of threads | |
726f6388 JA |
9699 | .PD |
9700 | .PP | |
ccc6cda3 | 9701 | If |
726f6388 | 9702 | .I limit |
b28ff8c9 | 9703 | is given, and the |
726f6388 | 9704 | .B \-a |
b28ff8c9 CR |
9705 | option is not used, |
9706 | \fIlimit\fP is the new value of the specified resource. | |
726f6388 JA |
9707 | If no option is given, then |
9708 | .B \-f | |
9709 | is assumed. Values are in 1024-byte increments, except for | |
9710 | .BR \-t , | |
b28ff8c9 | 9711 | which is in seconds; |
726f6388 | 9712 | .BR \-p , |
b28ff8c9 | 9713 | which is in units of 512-byte blocks; |
726f6388 | 9714 | and |
6fbe7620 CR |
9715 | .BR \-T , |
9716 | .BR \-b , | |
9717 | .BR \-n , | |
726f6388 JA |
9718 | and |
9719 | .BR \-u , | |
f73dda09 JA |
9720 | which are unscaled values. |
9721 | The return status is 0 unless an invalid option or argument is supplied, | |
9722 | or an error occurs while setting a new limit. | |
726f6388 JA |
9723 | .RE |
9724 | .TP | |
cce855bc | 9725 | \fBumask\fP [\fB\-p\fP] [\fB\-S\fP] [\fImode\fP] |
726f6388 JA |
9726 | The user file-creation mask is set to |
9727 | .IR mode . | |
9728 | If | |
9729 | .I mode | |
9730 | begins with a digit, it | |
9731 | is interpreted as an octal number; otherwise | |
9732 | it is interpreted as a symbolic mode mask similar | |
9733 | to that accepted by | |
9734 | .IR chmod (1). | |
9735 | If | |
9736 | .I mode | |
bb70624e | 9737 | is omitted, the current value of the mask is printed. |
ccc6cda3 | 9738 | The |
726f6388 JA |
9739 | .B \-S |
9740 | option causes the mask to be printed in symbolic form; the | |
9741 | default output is an octal number. | |
cce855bc JA |
9742 | If the |
9743 | .B \-p | |
9744 | option is supplied, and | |
9745 | .I mode | |
9746 | is omitted, the output is in a form that may be reused as input. | |
ccc6cda3 | 9747 | The return status is 0 if the mode was successfully changed or if |
726f6388 JA |
9748 | no \fImode\fP argument was supplied, and false otherwise. |
9749 | .TP | |
9750 | \fBunalias\fP [\-\fBa\fP] [\fIname\fP ...] | |
bb70624e | 9751 | Remove each \fIname\fP from the list of defined aliases. If |
726f6388 JA |
9752 | .B \-a |
9753 | is supplied, all alias definitions are removed. The return | |
9754 | value is true unless a supplied | |
9755 | .I name | |
9756 | is not a defined alias. | |
9757 | .TP | |
9758 | \fBunset\fP [\-\fBfv\fP] [\fIname\fP ...] | |
9759 | For each | |
9760 | .IR name , | |
ccc6cda3 | 9761 | remove the corresponding variable or function. |
276cb932 | 9762 | If the |
ccc6cda3 JA |
9763 | .B \-v |
9764 | option is given, each | |
9765 | .I name | |
276cb932 | 9766 | refers to a shell variable, and that variable is removed. |
ccc6cda3 JA |
9767 | Read-only variables may not be unset. |
9768 | If | |
726f6388 | 9769 | .B \-f |
f75912ae | 9770 | is specified, each |
ccc6cda3 JA |
9771 | .I name |
9772 | refers to a shell function, and the function definition | |
9773 | is removed. | |
276cb932 CR |
9774 | If no options are supplied, each \fIname\fP refers to a variable; if |
9775 | there is no variable by that name, any function with that name is | |
9776 | unset. | |
ccc6cda3 JA |
9777 | Each unset variable or function is removed from the environment |
9778 | passed to subsequent commands. | |
9779 | If any of | |
726f6388 | 9780 | .SM |
984a1947 CR |
9781 | .BR COMP_WORDBREAKS , |
9782 | .SM | |
726f6388 JA |
9783 | .BR RANDOM , |
9784 | .SM | |
9785 | .BR SECONDS , | |
9786 | .SM | |
9787 | .BR LINENO , | |
ccc6cda3 JA |
9788 | .SM |
9789 | .BR HISTCMD , | |
bb70624e JA |
9790 | .SM |
9791 | .BR FUNCNAME , | |
9792 | .SM | |
9793 | .BR GROUPS , | |
726f6388 JA |
9794 | or |
9795 | .SM | |
ccc6cda3 | 9796 | .B DIRSTACK |
726f6388 JA |
9797 | are unset, they lose their special properties, even if they are |
9798 | subsequently reset. The exit status is true unless a | |
9799 | .I name | |
d3a24ed2 | 9800 | is readonly. |
726f6388 | 9801 | .TP |
d90269dd CR |
9802 | \fBwait\fP [\fIn ...\fP] |
9803 | Wait for each specified process and return its termination status. | |
9804 | Each | |
726f6388 JA |
9805 | .I n |
9806 | may be a process | |
9807 | ID or a job specification; if a job spec is given, all processes | |
9808 | in that job's pipeline are waited for. If | |
9809 | .I n | |
9810 | is not given, all currently active child processes | |
9811 | are waited for, and the return status is zero. If | |
9812 | .I n | |
ccc6cda3 | 9813 | specifies a non-existent process or job, the return status is |
726f6388 JA |
9814 | 127. Otherwise, the return status is the exit status of the last |
9815 | process or job waited for. | |
9816 | .\" bash_builtins | |
9817 | .if \n(zZ=1 .ig zZ | |
ccc6cda3 | 9818 | .SH "RESTRICTED SHELL" |
bb70624e JA |
9819 | .\" rbash.1 |
9820 | .zY | |
726f6388 | 9821 | .PP |
ccc6cda3 | 9822 | If |
726f6388 | 9823 | .B bash |
ccc6cda3 JA |
9824 | is started with the name |
9825 | .BR rbash , | |
9826 | or the | |
9827 | .B \-r | |
9828 | option is supplied at invocation, | |
9829 | the shell becomes restricted. | |
9830 | A restricted shell is used to | |
9831 | set up an environment more controlled than the standard shell. | |
9832 | It behaves identically to | |
9833 | .B bash | |
cce855bc | 9834 | with the exception that the following are disallowed or not performed: |
ccc6cda3 JA |
9835 | .IP \(bu |
9836 | changing directories with \fBcd\fP | |
9837 | .IP \(bu | |
9838 | setting or unsetting the values of | |
984a1947 | 9839 | .SM |
b72432fd | 9840 | .BR SHELL , |
984a1947 | 9841 | .SM |
b72432fd | 9842 | .BR PATH , |
984a1947 | 9843 | .SM |
b72432fd | 9844 | .BR ENV , |
ccc6cda3 | 9845 | or |
984a1947 | 9846 | .SM |
b72432fd | 9847 | .B BASH_ENV |
ccc6cda3 JA |
9848 | .IP \(bu |
9849 | specifying command names containing | |
9850 | .B / | |
9851 | .IP \(bu | |
b28ff8c9 | 9852 | specifying a filename containing a |
ccc6cda3 JA |
9853 | .B / |
9854 | as an argument to the | |
9855 | .B . | |
9856 | builtin command | |
9857 | .IP \(bu | |
dc60d4e0 | 9858 | specifying a filename containing a slash as an argument to the |
bb70624e JA |
9859 | .B \-p |
9860 | option to the | |
9861 | .B hash | |
9862 | builtin command | |
9863 | .IP \(bu | |
ccc6cda3 JA |
9864 | importing function definitions from the shell environment at startup |
9865 | .IP \(bu | |
984a1947 CR |
9866 | parsing the value of |
9867 | .SM | |
9868 | .B SHELLOPTS | |
9869 | from the shell environment at startup | |
cce855bc | 9870 | .IP \(bu |
ccc6cda3 JA |
9871 | redirecting output using the >, >|, <>, >&, &>, and >> redirection operators |
9872 | .IP \(bu | |
9873 | using the | |
9874 | .B exec | |
9875 | builtin command to replace the shell with another command | |
9876 | .IP \(bu | |
9877 | adding or deleting builtin commands with the | |
9878 | .B \-f | |
726f6388 | 9879 | and |
ccc6cda3 JA |
9880 | .B \-d |
9881 | options to the | |
9882 | .B enable | |
9883 | builtin command | |
9884 | .IP \(bu | |
dc60d4e0 | 9885 | using the \fBenable\fP builtin command to enable disabled shell builtins |
7117c2d2 | 9886 | .IP \(bu |
ccc6cda3 JA |
9887 | specifying the |
9888 | .B \-p | |
9889 | option to the | |
9890 | .B command | |
9891 | builtin command | |
9892 | .IP \(bu | |
9893 | turning off restricted mode with | |
cce855bc | 9894 | \fBset +r\fP or \fBset +o restricted\fP. |
726f6388 | 9895 | .PP |
ccc6cda3 JA |
9896 | These restrictions are enforced after any startup files are read. |
9897 | .PP | |
61deeb13 CR |
9898 | .ie \n(zY=1 When a command that is found to be a shell script is executed, |
9899 | .el \{ When a command that is found to be a shell script is executed | |
9900 | (see | |
ccc6cda3 JA |
9901 | .SM |
9902 | .B "COMMAND EXECUTION" | |
9903 | above), | |
61deeb13 | 9904 | \} |
ccc6cda3 JA |
9905 | .B rbash |
9906 | turns off any restrictions in the shell spawned to execute the | |
9907 | script. | |
bb70624e JA |
9908 | .\" end of rbash.1 |
9909 | .if \n(zY=1 .ig zY | |
726f6388 JA |
9910 | .SH "SEE ALSO" |
9911 | .PD 0 | |
9912 | .TP | |
bb70624e | 9913 | \fIBash Reference Manual\fP, Brian Fox and Chet Ramey |
726f6388 JA |
9914 | .TP |
9915 | \fIThe Gnu Readline Library\fP, Brian Fox and Chet Ramey | |
9916 | .TP | |
9917 | \fIThe Gnu History Library\fP, Brian Fox and Chet Ramey | |
9918 | .TP | |
726f6388 JA |
9919 | \fIPortable Operating System Interface (POSIX) Part 2: Shell and Utilities\fP, IEEE |
9920 | .TP | |
9921 | \fIsh\fP(1), \fIksh\fP(1), \fIcsh\fP(1) | |
9922 | .TP | |
9923 | \fIemacs\fP(1), \fIvi\fP(1) | |
9924 | .TP | |
9925 | \fIreadline\fP(3) | |
9926 | .PD | |
9927 | .SH FILES | |
9928 | .PD 0 | |
9929 | .TP | |
9930 | .FN /bin/bash | |
9931 | The \fBbash\fP executable | |
9932 | .TP | |
9933 | .FN /etc/profile | |
9934 | The systemwide initialization file, executed for login shells | |
9935 | .TP | |
9936 | .FN ~/.bash_profile | |
9937 | The personal initialization file, executed for login shells | |
9938 | .TP | |
9939 | .FN ~/.bashrc | |
9940 | The individual per-interactive-shell startup file | |
9941 | .TP | |
b72432fd JA |
9942 | .FN ~/.bash_logout |
9943 | The individual login shell cleanup file, executed when a login shell exits | |
9944 | .TP | |
726f6388 JA |
9945 | .FN ~/.inputrc |
9946 | Individual \fIreadline\fP initialization file | |
9947 | .PD | |
9948 | .SH AUTHORS | |
ccc6cda3 | 9949 | Brian Fox, Free Software Foundation |
726f6388 | 9950 | .br |
bb70624e | 9951 | bfox@gnu.org |
726f6388 JA |
9952 | .PP |
9953 | Chet Ramey, Case Western Reserve University | |
9954 | .br | |
db31fb26 | 9955 | chet.ramey@case.edu |
726f6388 JA |
9956 | .SH BUG REPORTS |
9957 | If you find a bug in | |
9958 | .B bash, | |
9959 | you should report it. But first, you should | |
9960 | make sure that it really is a bug, and that it appears in the latest | |
9961 | version of | |
d3a24ed2 CR |
9962 | .BR bash . |
9963 | The latest version is always available from | |
9c7f20c7 | 9964 | \fIftp://ftp.gnu.org/pub/gnu/bash/\fP. |
726f6388 JA |
9965 | .PP |
9966 | Once you have determined that a bug actually exists, use the | |
9967 | .I bashbug | |
9968 | command to submit a bug report. | |
d166f048 | 9969 | If you have a fix, you are encouraged to mail that as well! |
726f6388 | 9970 | Suggestions and `philosophical' bug reports may be mailed |
cce855bc | 9971 | to \fIbug-bash@gnu.org\fP or posted to the Usenet |
726f6388 JA |
9972 | newsgroup |
9973 | .BR gnu.bash.bug . | |
9974 | .PP | |
9975 | ALL bug reports should include: | |
9976 | .PP | |
9977 | .PD 0 | |
9978 | .TP 20 | |
9979 | The version number of \fBbash\fR | |
9980 | .TP | |
9981 | The hardware and operating system | |
9982 | .TP | |
9983 | The compiler used to compile | |
9984 | .TP | |
9985 | A description of the bug behaviour | |
9986 | .TP | |
9987 | A short script or `recipe' which exercises the bug | |
9988 | .PD | |
9989 | .PP | |
9990 | .I bashbug | |
9991 | inserts the first three items automatically into the template | |
9992 | it provides for filing a bug report. | |
9993 | .PP | |
9994 | Comments and bug reports concerning | |
9995 | this manual page should be directed to | |
54a1fa7c | 9996 | .IR chet.ramey@case.edu . |
726f6388 JA |
9997 | .SH BUGS |
9998 | .PP | |
9999 | It's too big and too slow. | |
10000 | .PP | |
10001 | There are some subtle differences between | |
10002 | .B bash | |
10003 | and traditional versions of | |
10004 | .BR sh , | |
10005 | mostly because of the | |
10006 | .SM | |
10007 | .B POSIX | |
10008 | specification. | |
10009 | .PP | |
10010 | Aliases are confusing in some uses. | |
ccc6cda3 JA |
10011 | .PP |
10012 | Shell builtin commands and functions are not stoppable/restartable. | |
10013 | .PP | |
10014 | Compound commands and command sequences of the form `a ; b ; c' | |
10015 | are not handled gracefully when process suspension is attempted. | |
10016 | When a process is stopped, the shell immediately executes the next | |
10017 | command in the sequence. | |
10018 | It suffices to place the sequence of commands between | |
10019 | parentheses to force it into a subshell, which may be stopped as | |
10020 | a unit. | |
10021 | .PP | |
ccc6cda3 | 10022 | Array variables may not (yet) be exported. |
09767ff0 CR |
10023 | .PP |
10024 | There may be only one active coprocess at a time. | |
726f6388 | 10025 | .zZ |
bb70624e | 10026 | .zY |