]>
Commit | Line | Data |
---|---|---|
28ef6c31 JA |
1 | This is bashref.info, produced by makeinfo version 4.0 from |
2 | /usr/homes/chet/src/bash/src/doc/bashref.texi. | |
e8ce775d JA |
3 | |
4 | INFO-DIR-SECTION Utilities | |
5 | START-INFO-DIR-ENTRY | |
cce855bc | 6 | * Bash: (bash). The GNU Bourne-Again SHell. |
e8ce775d | 7 | END-INFO-DIR-ENTRY |
ccc6cda3 JA |
8 | |
9 | This text is a brief description of the features that are present in | |
10 | the Bash shell. | |
11 | ||
28ef6c31 | 12 | This is Edition 2.5, last updated 28 Mar 2001, |
ccc6cda3 | 13 | of `The GNU Bash Reference Manual', |
28ef6c31 | 14 | for `Bash', Version 2.05. |
ccc6cda3 | 15 | |
b72432fd | 16 | Copyright (C) 1991-1999 Free Software Foundation, Inc. |
ccc6cda3 JA |
17 | |
18 | Permission is granted to make and distribute verbatim copies of | |
19 | this manual provided the copyright notice and this permission notice | |
20 | are preserved on all copies. | |
21 | ||
22 | Permission is granted to copy and distribute modified versions of this | |
23 | manual under the conditions for verbatim copying, provided that the entire | |
24 | resulting derived work is distributed under the terms of a permission | |
25 | notice identical to this one. | |
26 | ||
27 | Permission is granted to copy and distribute translations of this manual | |
28 | into another language, under the above conditions for modified versions, | |
29 | except that this permission notice may be stated in a translation approved | |
cce855bc | 30 | by the Free Software Foundation. |
ccc6cda3 JA |
31 | |
32 | \1f | |
33 | File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) | |
34 | ||
35 | Bash Features | |
36 | ************* | |
37 | ||
38 | This text is a brief description of the features that are present in | |
39 | the Bash shell. | |
40 | ||
28ef6c31 JA |
41 | This is Edition 2.5, last updated 28 Mar 2001, of `The GNU Bash |
42 | Reference Manual', for `Bash', Version 2.05. | |
ccc6cda3 JA |
43 | |
44 | Copyright (C) 1991, 1993, 1996 Free Software Foundation, Inc. | |
45 | ||
46 | Bash contains features that appear in other popular shells, and some | |
47 | features that only appear in Bash. Some of the shells that Bash has | |
48 | borrowed concepts from are the Bourne Shell (`sh'), the Korn Shell | |
49 | (`ksh'), and the C-shell (`csh' and its successor, `tcsh'). The | |
50 | following menu breaks the features up into categories based upon which | |
51 | one of these other shells inspired the feature. | |
52 | ||
53 | This manual is meant as a brief introduction to features found in | |
54 | Bash. The Bash manual page should be used as the definitive reference | |
55 | on shell behavior. | |
56 | ||
57 | * Menu: | |
58 | ||
59 | * Introduction:: An introduction to the shell. | |
60 | ||
61 | * Definitions:: Some definitions used in the rest of this | |
62 | manual. | |
63 | ||
64 | * Basic Shell Features:: The shell "building blocks". | |
65 | ||
bb70624e JA |
66 | * Shell Builtin Commands:: Commands that are a part of the shell. |
67 | ||
68 | * Shell Variables:: Variables used or set by Bash. | |
ccc6cda3 | 69 | |
ccc6cda3 JA |
70 | * Bash Features:: Features found only in Bash. |
71 | ||
72 | * Job Control:: A chapter describing what job control is | |
73 | and how Bash allows you to use it. | |
74 | ||
75 | * Using History Interactively:: Chapter dealing with history expansion | |
76 | rules. | |
77 | ||
78 | * Command Line Editing:: Chapter describing the command line | |
79 | editing features. | |
80 | ||
81 | * Installing Bash:: How to build and install Bash on your system. | |
82 | ||
83 | * Reporting Bugs:: How to report bugs in Bash. | |
84 | ||
bb70624e JA |
85 | * Major Differences From The Bourne Shell:: A terse list of the differences |
86 | between Bash and historical | |
87 | versions of /bin/sh. | |
88 | ||
ccc6cda3 JA |
89 | * Builtin Index:: Index of Bash builtin commands. |
90 | ||
91 | * Reserved Word Index:: Index of Bash reserved words. | |
92 | ||
93 | * Variable Index:: Quick reference helps you find the | |
94 | variable you want. | |
95 | ||
96 | * Function Index:: Index of bindable Readline functions. | |
97 | ||
98 | * Concept Index:: General index for concepts described in | |
99 | this manual. | |
100 | ||
101 | \1f | |
102 | File: bashref.info, Node: Introduction, Next: Definitions, Prev: Top, Up: Top | |
103 | ||
104 | Introduction | |
105 | ************ | |
106 | ||
107 | * Menu: | |
108 | ||
109 | * What is Bash?:: A short description of Bash. | |
110 | ||
111 | * What is a shell?:: A brief introduction to shells. | |
112 | ||
113 | \1f | |
114 | File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction | |
115 | ||
116 | What is Bash? | |
117 | ============= | |
118 | ||
bb70624e JA |
119 | Bash is the shell, or command language interpreter, for the GNU |
120 | operating system. The name is an acronym for the `Bourne-Again SHell', | |
121 | a pun on Stephen Bourne, the author of the direct ancestor of the | |
122 | current Unix shell `/bin/sh', which appeared in the Seventh Edition | |
123 | Bell Labs Research version of Unix. | |
ccc6cda3 | 124 | |
bb70624e JA |
125 | Bash is largely compatible with `sh' and incorporates useful |
126 | features from the Korn shell `ksh' and the C shell `csh'. It is | |
127 | intended to be a conformant implementation of the IEEE POSIX Shell and | |
128 | Tools specification (IEEE Working Group 1003.2). It offers functional | |
ccc6cda3 JA |
129 | improvements over `sh' for both interactive and programming use. |
130 | ||
bb70624e JA |
131 | While the GNU operating system provides other shells, including a |
132 | version of `csh', Bash is the default shell. Like other GNU software, | |
133 | Bash is quite portable. It currently runs on nearly every version of | |
134 | Unix and a few other operating systems - independently-supported ports | |
135 | exist for MS-DOS, OS/2, Windows 95/98, and Windows NT. | |
ccc6cda3 JA |
136 | |
137 | \1f | |
138 | File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction | |
139 | ||
140 | What is a shell? | |
141 | ================ | |
142 | ||
143 | At its base, a shell is simply a macro processor that executes | |
144 | commands. A Unix shell is both a command interpreter, which provides | |
bb70624e | 145 | the user interface to the rich set of GNU utilities, and a programming |
cce855bc JA |
146 | language, allowing these utilitites to be combined. Files containing |
147 | commands can be created, and become commands themselves. These new | |
bb70624e | 148 | commands have the same status as system commands in directories such as |
cce855bc | 149 | `/bin', allowing users or groups to establish custom environments. |
ccc6cda3 | 150 | |
bb70624e | 151 | A shell allows execution of GNU commands, both synchronously and |
cce855bc JA |
152 | asynchronously. The shell waits for synchronous commands to complete |
153 | before accepting more input; asynchronous commands continue to execute | |
154 | in parallel with the shell while it reads and executes additional | |
155 | commands. The "redirection" constructs permit fine-grained control of | |
bb70624e JA |
156 | the input and output of those commands. Moreover, the shell allows |
157 | control over the contents of commands' environments. Shells may be | |
158 | used interactively or non-interactively: they accept input typed from | |
159 | the keyboard or from a file. | |
160 | ||
161 | Shells also provide a small set of built-in commands ("builtins") | |
162 | implementing functionality impossible or inconvenient to obtain via | |
163 | separate utilities. For example, `cd', `break', `continue', and | |
164 | `exec') cannot be implemented outside of the shell because they | |
165 | directly manipulate the shell itself. The `history', `getopts', | |
166 | `kill', or `pwd' builtins, among others, could be implemented in | |
167 | separate utilities, but they are more convenient to use as builtin | |
168 | commands. All of the shell builtins are described in subsequent | |
169 | sections. | |
ccc6cda3 JA |
170 | |
171 | While executing commands is essential, most of the power (and | |
172 | complexity) of shells is due to their embedded programming languages. | |
173 | Like any high-level language, the shell provides variables, flow | |
174 | control constructs, quoting, and functions. | |
175 | ||
bb70624e JA |
176 | Shells offer features geared specifically for interactive use rather |
177 | than to augment the programming language. These interactive features | |
178 | include job control, command line editing, history and aliases. Each | |
179 | of these features is described in this manual. | |
ccc6cda3 JA |
180 | |
181 | \1f | |
182 | File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top | |
183 | ||
184 | Definitions | |
185 | *********** | |
186 | ||
187 | These definitions are used throughout the remainder of this manual. | |
188 | ||
189 | `POSIX' | |
190 | A family of open system standards based on Unix. Bash is | |
191 | concerned with POSIX 1003.2, the Shell and Tools Standard. | |
192 | ||
193 | `blank' | |
194 | A space or tab character. | |
195 | ||
196 | `builtin' | |
197 | A command that is implemented internally by the shell itself, | |
198 | rather than by an executable program somewhere in the file system. | |
199 | ||
200 | `control operator' | |
201 | A `word' that performs a control function. It is a `newline' or | |
202 | one of the following: `||', `&&', `&', `;', `;;', `|', `(', or `)'. | |
203 | ||
204 | `exit status' | |
205 | The value returned by a command to its caller. | |
206 | ||
207 | `field' | |
208 | A unit of text that is the result of one of the shell expansions. | |
209 | After expansion, when executing a command, the resulting fields | |
210 | are used as the command name and arguments. | |
211 | ||
212 | `filename' | |
213 | A string of characters used to identify a file. | |
214 | ||
215 | `job' | |
216 | A set of processes comprising a pipeline, and any processes | |
217 | descended from it, that are all in the same process group. | |
218 | ||
219 | `job control' | |
d166f048 JA |
220 | A mechanism by which users can selectively stop (suspend) and |
221 | restart (resume) execution of processes. | |
ccc6cda3 JA |
222 | |
223 | `metacharacter' | |
224 | A character that, when unquoted, separates words. A metacharacter | |
225 | is a `blank' or one of the following characters: `|', `&', `;', | |
226 | `(', `)', `<', or `>'. | |
227 | ||
228 | `name' | |
229 | A `word' consisting solely of letters, numbers, and underscores, | |
230 | and beginning with a letter or underscore. `Name's are used as | |
231 | shell variable and function names. Also referred to as an | |
232 | `identifier'. | |
233 | ||
234 | `operator' | |
235 | A `control operator' or a `redirection operator'. *Note | |
236 | Redirections::, for a list of redirection operators. | |
237 | ||
238 | `process group' | |
239 | A collection of related processes each having the same process | |
240 | group ID. | |
241 | ||
242 | `process group ID' | |
243 | A unique identifer that represents a `process group' during its | |
244 | lifetime. | |
245 | ||
246 | `reserved word' | |
247 | A `word' that has a special meaning to the shell. Most reserved | |
248 | words introduce shell flow control constructs, such as `for' and | |
249 | `while'. | |
250 | ||
251 | `return status' | |
252 | A synonym for `exit status'. | |
253 | ||
254 | `signal' | |
bb70624e | 255 | A mechanism by which a process may be notified by the kernel of an |
ccc6cda3 JA |
256 | event occurring in the system. |
257 | ||
258 | `special builtin' | |
259 | A shell builtin command that has been classified as special by the | |
bb70624e | 260 | POSIX 1003.2 standard. |
ccc6cda3 JA |
261 | |
262 | `token' | |
263 | A sequence of characters considered a single unit by the shell. | |
264 | It is either a `word' or an `operator'. | |
265 | ||
266 | `word' | |
267 | A `token' that is not an `operator'. | |
268 | ||
269 | \1f | |
bb70624e | 270 | File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top |
ccc6cda3 JA |
271 | |
272 | Basic Shell Features | |
273 | ******************** | |
274 | ||
275 | Bash is an acronym for `Bourne-Again SHell'. The Bourne shell is | |
276 | the traditional Unix shell originally written by Stephen Bourne. All | |
277 | of the Bourne shell builtin commands are available in Bash, and the | |
278 | rules for evaluation and quoting are taken from the POSIX 1003.2 | |
279 | specification for the `standard' Unix shell. | |
280 | ||
cce855bc | 281 | This chapter briefly summarizes the shell's `building blocks': |
ccc6cda3 JA |
282 | commands, control structures, shell functions, shell parameters, shell |
283 | expansions, redirections, which are a way to direct input and output | |
284 | from and to named files, and how the shell executes commands. | |
285 | ||
286 | * Menu: | |
287 | ||
288 | * Shell Syntax:: What your input means to the shell. | |
cce855bc | 289 | * Shell Commands:: The types of commands you can use. |
ccc6cda3 JA |
290 | * Shell Functions:: Grouping commands by name. |
291 | * Shell Parameters:: Special shell variables. | |
292 | * Shell Expansions:: How Bash expands variables and the various | |
293 | expansions available. | |
294 | * Redirections:: A way to control where input and output go. | |
295 | * Executing Commands:: What happens when you run a command. | |
296 | * Shell Scripts:: Executing files of shell commands. | |
297 | ||
298 | \1f | |
cce855bc | 299 | File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features |
ccc6cda3 JA |
300 | |
301 | Shell Syntax | |
302 | ============ | |
303 | ||
304 | * Menu: | |
305 | ||
306 | * Shell Operation:: The basic operation of the shell. | |
307 | ||
308 | * Quoting:: How to remove the special meaning from characters. | |
309 | ||
310 | * Comments:: How to specify comments. | |
311 | ||
bb70624e JA |
312 | When the shell reads input, it proceeds through a sequence of |
313 | operations. If the input indicates the beginning of a comment, the | |
314 | shell ignores the comment symbol (`#'), and the rest of that line. | |
315 | ||
316 | Otherwise, roughly speaking, the shell reads its input and divides | |
317 | the input into words and operators, employing the quoting rules to | |
318 | select which meanings to assign various words and characters. | |
319 | ||
320 | The shell then parses these tokens into commands and other | |
321 | constructs, removes the special meaning of certain words or characters, | |
322 | expands others, redirects input and output as needed, executes the | |
323 | specified command, waits for the command's exit status, and makes that | |
324 | exit status available for further inspection or processing. | |
325 | ||
ccc6cda3 JA |
326 | \1f |
327 | File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax | |
328 | ||
329 | Shell Operation | |
330 | --------------- | |
331 | ||
332 | The following is a brief description of the shell's operation when it | |
333 | reads and executes a command. Basically, the shell does the following: | |
334 | ||
28ef6c31 | 335 | 1. Reads its input from a file (*note Shell Scripts::), from a string |
ccc6cda3 | 336 | supplied as an argument to the `-c' invocation option (*note |
28ef6c31 | 337 | Invoking Bash::), or from the user's terminal. |
ccc6cda3 JA |
338 | |
339 | 2. Breaks the input into words and operators, obeying the quoting | |
cce855bc | 340 | rules described in *Note Quoting::. These tokens are separated by |
ccc6cda3 | 341 | `metacharacters'. Alias expansion is performed by this step |
28ef6c31 | 342 | (*note Aliases::). |
ccc6cda3 | 343 | |
cce855bc | 344 | 3. Parses the tokens into simple and compound commands (*note Shell |
28ef6c31 | 345 | Commands::). |
ccc6cda3 | 346 | |
28ef6c31 | 347 | 4. Performs the various shell expansions (*note Shell Expansions::), |
ccc6cda3 | 348 | breaking the expanded tokens into lists of filenames (*note |
28ef6c31 | 349 | Filename Expansion::) and commands and arguments. |
ccc6cda3 | 350 | |
28ef6c31 | 351 | 5. Performs any necessary redirections (*note Redirections::) and |
ccc6cda3 JA |
352 | removes the redirection operators and their operands from the |
353 | argument list. | |
354 | ||
28ef6c31 | 355 | 6. Executes the command (*note Executing Commands::). |
ccc6cda3 JA |
356 | |
357 | 7. Optionally waits for the command to complete and collects its exit | |
28ef6c31 | 358 | status (*note Exit Status::). |
ccc6cda3 JA |
359 | |
360 | ||
361 | \1f | |
362 | File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax | |
363 | ||
364 | Quoting | |
365 | ------- | |
366 | ||
367 | * Menu: | |
368 | ||
369 | * Escape Character:: How to remove the special meaning from a single | |
370 | character. | |
371 | * Single Quotes:: How to inhibit all interpretation of a sequence | |
372 | of characters. | |
373 | * Double Quotes:: How to suppress most of the interpretation of a | |
374 | sequence of characters. | |
375 | * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings. | |
376 | ||
377 | * Locale Translation:: How to translate strings into different languages. | |
378 | ||
379 | Quoting is used to remove the special meaning of certain characters | |
380 | or words to the shell. Quoting can be used to disable special | |
381 | treatment for special characters, to prevent reserved words from being | |
382 | recognized as such, and to prevent parameter expansion. | |
383 | ||
28ef6c31 | 384 | Each of the shell metacharacters (*note Definitions::) has special |
cce855bc | 385 | meaning to the shell and must be quoted if it is to represent itself. |
bb70624e JA |
386 | When the command history expansion facilities are being used, the |
387 | HISTORY EXPANSION character, usually `!', must be quoted to prevent | |
28ef6c31 | 388 | history expansion. *Note Bash History Facilities::, for more details |
bb70624e JA |
389 | concerning history expansion. There are three quoting mechanisms: the |
390 | ESCAPE CHARACTER, single quotes, and double quotes. | |
ccc6cda3 JA |
391 | |
392 | \1f | |
393 | File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting | |
394 | ||
395 | Escape Character | |
396 | ................ | |
397 | ||
398 | A non-quoted backslash `\' is the Bash escape character. It | |
399 | preserves the literal value of the next character that follows, with | |
400 | the exception of `newline'. If a `\newline' pair appears, and the | |
cce855bc JA |
401 | backslash itself is not quoted, the `\newline' is treated as a line |
402 | continuation (that is, it is removed from the input stream and | |
403 | effectively ignored). | |
ccc6cda3 JA |
404 | |
405 | \1f | |
406 | File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting | |
407 | ||
408 | Single Quotes | |
409 | ............. | |
410 | ||
bb70624e JA |
411 | Enclosing characters in single quotes (`'') preserves the literal |
412 | value of each character within the quotes. A single quote may not occur | |
413 | between single quotes, even when preceded by a backslash. | |
ccc6cda3 JA |
414 | |
415 | \1f | |
416 | File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting | |
417 | ||
418 | Double Quotes | |
419 | ............. | |
420 | ||
bb70624e JA |
421 | Enclosing characters in double quotes (`"') preserves the literal |
422 | value of all characters within the quotes, with the exception of `$', | |
423 | ``', and `\'. The characters `$' and ``' retain their special meaning | |
28ef6c31 JA |
424 | within double quotes (*note Shell Expansions::). The backslash retains |
425 | its special meaning only when followed by one of the following | |
bb70624e JA |
426 | characters: `$', ``', `"', `\', or `newline'. Within double quotes, |
427 | backslashes that are followed by one of these characters are removed. | |
428 | Backslashes preceding characters without a special meaning are left | |
429 | unmodified. A double quote may be quoted within double quotes by | |
430 | preceding it with a backslash. | |
ccc6cda3 JA |
431 | |
432 | The special parameters `*' and `@' have special meaning when in | |
28ef6c31 | 433 | double quotes (*note Shell Parameter Expansion::). |
ccc6cda3 JA |
434 | |
435 | \1f | |
436 | File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting | |
437 | ||
438 | ANSI-C Quoting | |
439 | .............. | |
440 | ||
441 | Words of the form `$'STRING'' are treated specially. The word | |
442 | expands to STRING, with backslash-escaped characters replaced as | |
28ef6c31 | 443 | specified by the ANSI C standard. Backslash escape sequences, if |
ccc6cda3 JA |
444 | present, are decoded as follows: |
445 | ||
446 | `\a' | |
447 | alert (bell) | |
448 | ||
449 | `\b' | |
450 | backspace | |
451 | ||
452 | `\e' | |
453 | an escape character (not ANSI C) | |
454 | ||
455 | `\f' | |
456 | form feed | |
457 | ||
458 | `\n' | |
459 | newline | |
460 | ||
461 | `\r' | |
462 | carriage return | |
463 | ||
464 | `\t' | |
465 | horizontal tab | |
466 | ||
467 | `\v' | |
468 | vertical tab | |
469 | ||
470 | `\\' | |
471 | backslash | |
472 | ||
bb70624e JA |
473 | `\'' |
474 | single quote | |
475 | ||
ccc6cda3 | 476 | `\NNN' |
cce855bc JA |
477 | the character whose `ASCII' code is the octal value NNN (one to |
478 | three digits) | |
479 | ||
480 | `\xNNN' | |
481 | the character whose `ASCII' code is the hexadecimal value NNN (one | |
482 | to three digits) | |
ccc6cda3 | 483 | |
bb70624e JA |
484 | The expanded result is single-quoted, as if the dollar sign had not |
485 | been present. | |
ccc6cda3 JA |
486 | |
487 | \1f | |
488 | File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting | |
489 | ||
490 | Locale-Specific Translation | |
491 | ........................... | |
492 | ||
493 | A double-quoted string preceded by a dollar sign (`$') will cause | |
494 | the string to be translated according to the current locale. If the | |
495 | current locale is `C' or `POSIX', the dollar sign is ignored. If the | |
496 | string is translated and replaced, the replacement is double-quoted. | |
497 | ||
28ef6c31 JA |
498 | Some systems use the message catalog selected by the `LC_MESSAGES' |
499 | shell variable. Others create the name of the message catalog from the | |
500 | value of the `TEXTDOMAIN' shell variable, possibly adding a suffix of | |
501 | `.mo'. If you use the `TEXTDOMAIN' variable, you may need to set the | |
502 | `TEXTDOMAINDIR' variable to the location of the message catalog files. | |
503 | ||
ccc6cda3 JA |
504 | \1f |
505 | File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax | |
506 | ||
507 | Comments | |
508 | -------- | |
509 | ||
510 | In a non-interactive shell, or an interactive shell in which the | |
511 | `interactive_comments' option to the `shopt' builtin is enabled (*note | |
28ef6c31 | 512 | Bash Builtins::), a word beginning with `#' causes that word and all |
ccc6cda3 JA |
513 | remaining characters on that line to be ignored. An interactive shell |
514 | without the `interactive_comments' option enabled does not allow | |
515 | comments. The `interactive_comments' option is on by default in | |
bb70624e JA |
516 | interactive shells. *Note Interactive Shells::, for a description of |
517 | what makes a shell interactive. | |
cce855bc JA |
518 | |
519 | \1f | |
520 | File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features | |
521 | ||
522 | Shell Commands | |
523 | ============== | |
524 | ||
bb70624e JA |
525 | A simple shell command such as `echo a b c' consists of the command |
526 | itself followed by arguments, separated by spaces. | |
527 | ||
528 | More complex shell commands are composed of simple commands arranged | |
529 | together in a variety of ways: in a pipeline in which the output of one | |
530 | command becomes the input of a second, in a loop or conditional | |
531 | construct, or in some other grouping. | |
532 | ||
cce855bc JA |
533 | * Menu: |
534 | ||
535 | * Simple Commands:: The most common type of command. | |
536 | * Pipelines:: Connecting the input and output of several | |
537 | commands. | |
538 | * Lists:: How to execute commands sequentially. | |
539 | * Looping Constructs:: Shell commands for iterative action. | |
540 | * Conditional Constructs:: Shell commands for conditional execution. | |
541 | * Command Grouping:: Ways to group commands. | |
ccc6cda3 JA |
542 | |
543 | \1f | |
cce855bc | 544 | File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands |
ccc6cda3 JA |
545 | |
546 | Simple Commands | |
cce855bc | 547 | --------------- |
ccc6cda3 | 548 | |
cce855bc | 549 | A simple command is the kind of command encountered most often. |
ccc6cda3 | 550 | It's just a sequence of words separated by `blank's, terminated by one |
28ef6c31 JA |
551 | of the shell's control operators (*note Definitions::). The first word |
552 | generally specifies a command to be executed, with the rest of the | |
bb70624e | 553 | words being that command's arguments. |
ccc6cda3 | 554 | |
28ef6c31 | 555 | The return status (*note Exit Status::) of a simple command is its |
bb70624e JA |
556 | exit status as provided by the POSIX 1003.1 `waitpid' function, or |
557 | 128+N if the command was terminated by signal N. | |
ccc6cda3 JA |
558 | |
559 | \1f | |
cce855bc | 560 | File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands |
ccc6cda3 JA |
561 | |
562 | Pipelines | |
cce855bc | 563 | --------- |
ccc6cda3 JA |
564 | |
565 | A `pipeline' is a sequence of simple commands separated by `|'. | |
566 | ||
567 | The format for a pipeline is | |
568 | [`time' [`-p']] [`!'] COMMAND1 [`|' COMMAND2 ...] | |
569 | ||
570 | The output of each command in the pipeline is connected to the input of | |
571 | the next command. That is, each command reads the previous command's | |
572 | output. | |
573 | ||
574 | The reserved word `time' causes timing statistics to be printed for | |
cce855bc JA |
575 | the pipeline once it finishes. The statistics currently consist of |
576 | elapsed (wall-clock) time and user and system time consumed by the | |
577 | command's execution. The `-p' option changes the output format to that | |
578 | specified by POSIX. The `TIMEFORMAT' variable may be set to a format | |
579 | string that specifies how the timing information should be displayed. | |
580 | *Note Bash Variables::, for a description of the available formats. | |
581 | The use of `time' as a reserved word permits the timing of shell | |
582 | builtins, shell functions, and pipelines. An external `time' command | |
583 | cannot time these easily. | |
584 | ||
28ef6c31 | 585 | If the pipeline is not executed asynchronously (*note Lists::), the |
cce855bc | 586 | shell waits for all commands in the pipeline to complete. |
ccc6cda3 | 587 | |
cce855bc | 588 | Each command in a pipeline is executed in its own subshell (*note |
28ef6c31 JA |
589 | Command Execution Environment::). The exit status of a pipeline is the |
590 | exit status of the last command in the pipeline. If the reserved word | |
591 | `!' precedes the pipeline, the exit status is the logical negation of | |
592 | the exit status of the last command. | |
ccc6cda3 JA |
593 | |
594 | \1f | |
cce855bc | 595 | File: bashref.info, Node: Lists, Next: Looping Constructs, Prev: Pipelines, Up: Shell Commands |
ccc6cda3 JA |
596 | |
597 | Lists of Commands | |
cce855bc | 598 | ----------------- |
ccc6cda3 JA |
599 | |
600 | A `list' is a sequence of one or more pipelines separated by one of | |
601 | the operators `;', `&', `&&', or `||', and optionally terminated by one | |
602 | of `;', `&', or a `newline'. | |
603 | ||
604 | Of these list operators, `&&' and `||' have equal precedence, | |
605 | followed by `;' and `&', which have equal precedence. | |
606 | ||
607 | If a command is terminated by the control operator `&', the shell | |
cce855bc JA |
608 | executes the command asynchronously in a subshell. This is known as |
609 | executing the command in the BACKGROUND. The shell does not wait for | |
bb70624e | 610 | the command to finish, and the return status is 0 (true). When job |
28ef6c31 | 611 | control is not active (*note Job Control::), the standard input for |
bb70624e JA |
612 | asynchronous commands, in the absence of any explicit redirections, is |
613 | redirected from `/dev/null'. | |
cce855bc JA |
614 | |
615 | Commands separated by a `;' are executed sequentially; the shell | |
616 | waits for each command to terminate in turn. The return status is the | |
617 | exit status of the last command executed. | |
ccc6cda3 JA |
618 | |
619 | The control operators `&&' and `||' denote AND lists and OR lists, | |
620 | respectively. An AND list has the form | |
bb70624e | 621 | COMMAND1 && COMMAND2 |
ccc6cda3 | 622 | |
bb70624e JA |
623 | COMMAND2 is executed if, and only if, COMMAND1 returns an exit status |
624 | of zero. | |
ccc6cda3 JA |
625 | |
626 | An OR list has the form | |
bb70624e | 627 | COMMAND1 || COMMAND2 |
ccc6cda3 | 628 | |
bb70624e | 629 | COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit |
ccc6cda3 JA |
630 | status. |
631 | ||
632 | The return status of AND and OR lists is the exit status of the last | |
633 | command executed in the list. | |
634 | ||
635 | \1f | |
cce855bc | 636 | File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Prev: Lists, Up: Shell Commands |
ccc6cda3 JA |
637 | |
638 | Looping Constructs | |
cce855bc | 639 | ------------------ |
ccc6cda3 JA |
640 | |
641 | Bash supports the following looping constructs. | |
642 | ||
bb70624e | 643 | Note that wherever a `;' appears in the description of a command's |
cce855bc JA |
644 | syntax, it may be replaced with one or more newlines. |
645 | ||
ccc6cda3 JA |
646 | `until' |
647 | The syntax of the `until' command is: | |
648 | until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
cce855bc JA |
649 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
650 | status which is not zero. The return status is the exit status of | |
651 | the last command executed in CONSEQUENT-COMMANDS, or zero if none | |
652 | was executed. | |
ccc6cda3 JA |
653 | |
654 | `while' | |
655 | The syntax of the `while' command is: | |
656 | while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
657 | ||
cce855bc JA |
658 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
659 | status of zero. The return status is the exit status of the last | |
660 | command executed in CONSEQUENT-COMMANDS, or zero if none was | |
661 | executed. | |
ccc6cda3 JA |
662 | |
663 | `for' | |
664 | The syntax of the `for' command is: | |
665 | ||
666 | for NAME [in WORDS ...]; do COMMANDS; done | |
cce855bc JA |
667 | Expand WORDS, and execute COMMANDS once for each member in the |
668 | resultant list, with NAME bound to the current member. If `in | |
bb70624e JA |
669 | WORDS' is not present, the `for' command executes the COMMANDS |
670 | once for each positional parameter that is set, as if `in "$@"' | |
28ef6c31 | 671 | had been specified (*note Special Parameters::). The return |
bb70624e JA |
672 | status is the exit status of the last command that executes. If |
673 | there are no items in the expansion of WORDS, no commands are | |
674 | executed, and the return status is zero. | |
675 | ||
676 | An alternate form of the `for' command is also supported: | |
677 | ||
678 | for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done | |
679 | First, the arithmetic expression EXPR1 is evaluated according to | |
28ef6c31 | 680 | the rules described below (*note Shell Arithmetic::). The |
bb70624e JA |
681 | arithmetic expression EXPR2 is then evaluated repeatedly until it |
682 | evaluates to zero. Each time EXPR2 evaluates to a non-zero value, | |
683 | COMMANDS are executed and the arithmetic expression EXPR3 is | |
684 | evaluated. If any expression is omitted, it behaves as if it | |
685 | evaluates to 1. The return value is the exit status of the last | |
686 | command in LIST that is executed, or false if any of the | |
687 | expressions is invalid. | |
ccc6cda3 | 688 | |
28ef6c31 | 689 | The `break' and `continue' builtins (*note Bourne Shell Builtins::) |
ccc6cda3 JA |
690 | may be used to control loop execution. |
691 | ||
692 | \1f | |
cce855bc | 693 | File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Shell Commands |
ccc6cda3 JA |
694 | |
695 | Conditional Constructs | |
cce855bc | 696 | ---------------------- |
ccc6cda3 JA |
697 | |
698 | `if' | |
699 | The syntax of the `if' command is: | |
700 | ||
701 | if TEST-COMMANDS; then | |
702 | CONSEQUENT-COMMANDS; | |
703 | [elif MORE-TEST-COMMANDS; then | |
704 | MORE-CONSEQUENTS;] | |
705 | [else ALTERNATE-CONSEQUENTS;] | |
706 | fi | |
707 | ||
cce855bc JA |
708 | The TEST-COMMANDS list is executed, and if its return status is |
709 | zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS | |
710 | returns a non-zero status, each `elif' list is executed in turn, | |
711 | and if its exit status is zero, the corresponding MORE-CONSEQUENTS | |
712 | is executed and the command completes. If `else | |
713 | ALTERNATE-CONSEQUENTS' is present, and the final command in the | |
714 | final `if' or `elif' clause has a non-zero exit status, then | |
715 | ALTERNATE-CONSEQUENTS is executed. The return status is the exit | |
716 | status of the last command executed, or zero if no condition | |
717 | tested true. | |
ccc6cda3 JA |
718 | |
719 | `case' | |
720 | The syntax of the `case' command is: | |
721 | ||
cce855bc | 722 | `case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac' |
ccc6cda3 | 723 | |
cce855bc JA |
724 | `case' will selectively execute the COMMAND-LIST corresponding to |
725 | the first PATTERN that matches WORD. The `|' is used to separate | |
726 | multiple patterns, and the `)' operator terminates a pattern list. | |
727 | A list of patterns and an associated command-list is known as a | |
728 | CLAUSE. Each clause must be terminated with `;;'. The WORD | |
729 | undergoes tilde expansion, parameter expansion, command | |
730 | substitution, arithmetic expansion, and quote removal before | |
731 | matching is attempted. Each PATTERN undergoes tilde expansion, | |
732 | parameter expansion, command substitution, and arithmetic | |
733 | expansion. | |
734 | ||
735 | There may be an arbitrary number of `case' clauses, each terminated | |
736 | by a `;;'. The first pattern that matches determines the | |
737 | command-list that is executed. | |
ccc6cda3 JA |
738 | |
739 | Here is an example using `case' in a script that could be used to | |
740 | describe one interesting feature of an animal: | |
741 | ||
742 | echo -n "Enter the name of an animal: " | |
743 | read ANIMAL | |
744 | echo -n "The $ANIMAL has " | |
745 | case $ANIMAL in | |
746 | horse | dog | cat) echo -n "four";; | |
747 | man | kangaroo ) echo -n "two";; | |
748 | *) echo -n "an unknown number of";; | |
749 | esac | |
750 | echo " legs." | |
751 | ||
cce855bc JA |
752 | The return status is zero if no PATTERN is matched. Otherwise, the |
753 | return status is the exit status of the COMMAND-LIST executed. | |
754 | ||
755 | `select' | |
756 | The `select' construct allows the easy generation of menus. It | |
757 | has almost the same syntax as the `for' command: | |
758 | ||
759 | select NAME [in WORDS ...]; do COMMANDS; done | |
760 | ||
761 | The list of words following `in' is expanded, generating a list of | |
762 | items. The set of expanded words is printed on the standard error | |
763 | output stream, each preceded by a number. If the `in WORDS' is | |
764 | omitted, the positional parameters are printed, as if `in "$@"' | |
765 | had been specifed. The `PS3' prompt is then displayed and a line | |
766 | is read from the standard input. If the line consists of a number | |
767 | corresponding to one of the displayed words, then the value of | |
768 | NAME is set to that word. If the line is empty, the words and | |
769 | prompt are displayed again. If `EOF' is read, the `select' | |
770 | command completes. Any other value read causes NAME to be set to | |
771 | null. The line read is saved in the variable `REPLY'. | |
772 | ||
773 | The COMMANDS are executed after each selection until a `break' or | |
774 | `return' command is executed, at which point the `select' command | |
775 | completes. | |
776 | ||
777 | Here is an example that allows the user to pick a filename from the | |
778 | current directory, and displays the name and index of the file | |
779 | selected. | |
780 | ||
781 | select fname in *; | |
782 | do | |
783 | echo you picked $fname \($REPLY\) | |
784 | break; | |
785 | done | |
786 | ||
ccc6cda3 JA |
787 | `((...))' |
788 | (( EXPRESSION )) | |
789 | ||
cce855bc | 790 | The arithmetic EXPRESSION is evaluated according to the rules |
28ef6c31 | 791 | described below (*note Shell Arithmetic::). If the value of the |
cce855bc JA |
792 | expression is non-zero, the return status is 0; otherwise the |
793 | return status is 1. This is exactly equivalent to | |
ccc6cda3 JA |
794 | let "EXPRESSION" |
795 | ||
cce855bc JA |
796 | *Note Bash Builtins::, for a full description of the `let' builtin. |
797 | ||
798 | `[[...]]' | |
799 | [[ EXPRESSION ]] | |
800 | ||
801 | Return a status of 0 or 1 depending on the evaluation of the | |
802 | conditional expression EXPRESSION. Expressions are composed of | |
803 | the primaries described below in *Note Bash Conditional | |
804 | Expressions::. Word splitting and filename expansion are not | |
805 | performed on the words between the `[[' and `]]'; tilde expansion, | |
806 | parameter and variable expansion, arithmetic expansion, command | |
807 | substitution, process substitution, and quote removal are | |
808 | performed. | |
809 | ||
810 | When the `==' and `!=' operators are used, the string to the right | |
811 | of the operator is considered a pattern and matched according to | |
812 | the rules described below in *Note Pattern Matching::. The return | |
813 | value is 0 if the string matches or does not match the pattern, | |
814 | respectively, and 1 otherwise. Any part of the pattern may be | |
815 | quoted to force it to be matched as a string. | |
816 | ||
817 | Expressions may be combined using the following operators, listed | |
818 | in decreasing order of precedence: | |
819 | ||
820 | `( EXPRESSION )' | |
821 | Returns the value of EXPRESSION. This may be used to | |
822 | override the normal precedence of operators. | |
823 | ||
824 | `! EXPRESSION' | |
825 | True if EXPRESSION is false. | |
826 | ||
827 | `EXPRESSION1 && EXPRESSION2' | |
828 | True if both EXPRESSION1 and EXPRESSION2 are true. | |
829 | ||
830 | `EXPRESSION1 || EXPRESSION2' | |
831 | True if either EXPRESSION1 or EXPRESSION2 is true. | |
832 | ||
bb70624e JA |
833 | The `&&' and `||' commands do not execute EXPRESSION2 if the value |
834 | of EXPRESSION1 is sufficient to determine the return value of the | |
cce855bc | 835 | entire conditional expression. |
ccc6cda3 JA |
836 | |
837 | \1f | |
cce855bc | 838 | File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Shell Commands |
ccc6cda3 JA |
839 | |
840 | Grouping Commands | |
cce855bc | 841 | ----------------- |
ccc6cda3 JA |
842 | |
843 | Bash provides two ways to group a list of commands to be executed as | |
844 | a unit. When commands are grouped, redirections may be applied to the | |
845 | entire command list. For example, the output of all the commands in | |
846 | the list may be redirected to a single stream. | |
847 | ||
848 | `()' | |
849 | ( LIST ) | |
850 | ||
851 | Placing a list of commands between parentheses causes a subshell | |
cce855bc JA |
852 | to be created, and each of the commands in LIST to be executed in |
853 | that subshell. Since the LIST is executed in a subshell, variable | |
ccc6cda3 JA |
854 | assignments do not remain in effect after the subshell completes. |
855 | ||
856 | `{}' | |
857 | { LIST; } | |
858 | ||
859 | Placing a list of commands between curly braces causes the list to | |
860 | be executed in the current shell context. No subshell is created. | |
cce855bc | 861 | The semicolon (or newline) following LIST is required. |
ccc6cda3 JA |
862 | |
863 | In addition to the creation of a subshell, there is a subtle | |
864 | difference between these two constructs due to historical reasons. The | |
865 | braces are `reserved words', so they must be separated from the LIST by | |
866 | `blank's. The parentheses are `operators', and are recognized as | |
d166f048 JA |
867 | separate tokens by the shell even if they are not separated from the |
868 | LIST by whitespace. | |
ccc6cda3 JA |
869 | |
870 | The exit status of both of these constructs is the exit status of | |
871 | LIST. | |
872 | ||
873 | \1f | |
cce855bc | 874 | File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features |
ccc6cda3 JA |
875 | |
876 | Shell Functions | |
877 | =============== | |
878 | ||
879 | Shell functions are a way to group commands for later execution | |
880 | using a single name for the group. They are executed just like a | |
bb70624e JA |
881 | "regular" command. When the name of a shell function is used as a |
882 | simple command name, the list of commands associated with that function | |
883 | name is executed. Shell functions are executed in the current shell | |
ccc6cda3 JA |
884 | context; no new process is created to interpret them. |
885 | ||
886 | Functions are declared using this syntax: | |
887 | [ `function' ] NAME () { COMMAND-LIST; } | |
888 | ||
889 | This defines a shell function named NAME. The reserved word | |
cce855bc JA |
890 | `function' is optional. If the `function' reserved word is supplied, |
891 | the parentheses are optional. The BODY of the function is the | |
892 | COMMAND-LIST between { and }. This list is executed whenever NAME is | |
893 | specified as the name of a command. The exit status of a function is | |
894 | the exit status of the last command executed in the body. | |
ccc6cda3 | 895 | |
bb70624e JA |
896 | Note that for historical reasons, the curly braces that surround the |
897 | body of the function must be separated from the body by `blank's or | |
898 | newlines. This is because the braces are reserved words and are only | |
899 | recognized as such when they are separated by whitespace. Also, the | |
900 | COMMAND-LIST must be terminated with a semicolon or a newline. | |
901 | ||
ccc6cda3 JA |
902 | When a function is executed, the arguments to the function become |
903 | the positional parameters during its execution (*note Positional | |
28ef6c31 | 904 | Parameters::). The special parameter `#' that expands to the number of |
ccc6cda3 | 905 | positional parameters is updated to reflect the change. Positional |
bb70624e JA |
906 | parameter `0' is unchanged. The `FUNCNAME' variable is set to the name |
907 | of the function while the function is executing. | |
ccc6cda3 JA |
908 | |
909 | If the builtin command `return' is executed in a function, the | |
910 | function completes and execution resumes with the next command after | |
911 | the function call. When a function completes, the values of the | |
912 | positional parameters and the special parameter `#' are restored to the | |
cce855bc JA |
913 | values they had prior to the function's execution. If a numeric |
914 | argument is given to `return', that is the function's return status; | |
915 | otherwise the functions's return status is the exit status of the last | |
916 | command executed before the `return'. | |
ccc6cda3 JA |
917 | |
918 | Variables local to the function may be declared with the `local' | |
919 | builtin. These variables are visible only to the function and the | |
920 | commands it invokes. | |
921 | ||
922 | Functions may be recursive. No limit is placed on the number of | |
923 | recursive calls. | |
924 | ||
925 | \1f | |
926 | File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features | |
927 | ||
928 | Shell Parameters | |
929 | ================ | |
930 | ||
931 | * Menu: | |
932 | ||
933 | * Positional Parameters:: The shell's command-line arguments. | |
934 | * Special Parameters:: Parameters with special meanings. | |
935 | ||
936 | A PARAMETER is an entity that stores values. It can be a `name', a | |
937 | number, or one of the special characters listed below. For the shell's | |
938 | purposes, a VARIABLE is a parameter denoted by a `name'. | |
939 | ||
940 | A parameter is set if it has been assigned a value. The null string | |
941 | is a valid value. Once a variable is set, it may be unset only by using | |
942 | the `unset' builtin command. | |
943 | ||
944 | A variable may be assigned to by a statement of the form | |
945 | NAME=[VALUE] | |
946 | ||
947 | If VALUE is not given, the variable is assigned the null string. All | |
948 | VALUEs undergo tilde expansion, parameter and variable expansion, | |
949 | command substitution, arithmetic expansion, and quote removal (detailed | |
cce855bc | 950 | below). If the variable has its `integer' attribute set (see the |
ccc6cda3 | 951 | description of the `declare' builtin in *Note Bash Builtins::), then |
cce855bc | 952 | VALUE is subject to arithmetic expansion even if the `$((...))' |
28ef6c31 | 953 | expansion is not used (*note Arithmetic Expansion::). Word splitting |
cce855bc JA |
954 | is not performed, with the exception of `"$@"' as explained below. |
955 | Filename expansion is not performed. | |
ccc6cda3 JA |
956 | |
957 | \1f | |
958 | File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters | |
959 | ||
960 | Positional Parameters | |
961 | --------------------- | |
962 | ||
963 | A POSITIONAL PARAMETER is a parameter denoted by one or more digits, | |
964 | other than the single digit `0'. Positional parameters are assigned | |
965 | from the shell's arguments when it is invoked, and may be reassigned | |
cce855bc | 966 | using the `set' builtin command. Positional parameter `N' may be |
bb70624e JA |
967 | referenced as `${N}', or as `$N' when `N' consists of a single digit. |
968 | Positional parameters may not be assigned to with assignment statements. | |
969 | The `set' and `shift' builtins are used to set and unset them (*note | |
28ef6c31 JA |
970 | Shell Builtin Commands::). The positional parameters are temporarily |
971 | replaced when a shell function is executed (*note Shell Functions::). | |
ccc6cda3 JA |
972 | |
973 | When a positional parameter consisting of more than a single digit | |
974 | is expanded, it must be enclosed in braces. | |
975 | ||
976 | \1f | |
977 | File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters | |
978 | ||
979 | Special Parameters | |
980 | ------------------ | |
981 | ||
982 | The shell treats several parameters specially. These parameters may | |
983 | only be referenced; assignment to them is not allowed. | |
984 | ||
985 | `*' | |
986 | Expands to the positional parameters, starting from one. When the | |
987 | expansion occurs within double quotes, it expands to a single word | |
988 | with the value of each parameter separated by the first character | |
989 | of the `IFS' special variable. That is, `"$*"' is equivalent to | |
990 | `"$1C$2C..."', where C is the first character of the value of the | |
d166f048 JA |
991 | `IFS' variable. If `IFS' is unset, the parameters are separated |
992 | by spaces. If `IFS' is null, the parameters are joined without | |
993 | intervening separators. | |
ccc6cda3 JA |
994 | |
995 | `@' | |
996 | Expands to the positional parameters, starting from one. When the | |
cce855bc | 997 | expansion occurs within double quotes, each parameter expands to a |
ccc6cda3 JA |
998 | separate word. That is, `"$@"' is equivalent to `"$1" "$2" ...'. |
999 | When there are no positional parameters, `"$@"' and `$@' expand to | |
1000 | nothing (i.e., they are removed). | |
1001 | ||
1002 | `#' | |
1003 | Expands to the number of positional parameters in decimal. | |
1004 | ||
1005 | `?' | |
1006 | Expands to the exit status of the most recently executed foreground | |
1007 | pipeline. | |
1008 | ||
1009 | `-' | |
bb70624e JA |
1010 | (A hyphen.) Expands to the current option flags as specified upon |
1011 | invocation, by the `set' builtin command, or those set by the | |
1012 | shell itself (such as the `-i' option). | |
ccc6cda3 JA |
1013 | |
1014 | `$' | |
1015 | Expands to the process ID of the shell. In a `()' subshell, it | |
cce855bc | 1016 | expands to the process ID of the invoking shell, not the subshell. |
ccc6cda3 JA |
1017 | |
1018 | `!' | |
1019 | Expands to the process ID of the most recently executed background | |
1020 | (asynchronous) command. | |
1021 | ||
1022 | `0' | |
1023 | Expands to the name of the shell or shell script. This is set at | |
cce855bc | 1024 | shell initialization. If Bash is invoked with a file of commands |
28ef6c31 JA |
1025 | (*note Shell Scripts::), `$0' is set to the name of that file. If |
1026 | Bash is started with the `-c' option (*note Invoking Bash::), then | |
1027 | `$0' is set to the first argument after the string to be executed, | |
1028 | if one is present. Otherwise, it is set to the filename used to | |
1029 | invoke Bash, as given by argument zero. | |
ccc6cda3 JA |
1030 | |
1031 | `_' | |
bb70624e JA |
1032 | (An underscore.) At shell startup, set to the absolute filename |
1033 | of the shell or shell script being executed as passed in the | |
1034 | argument list. Subsequently, expands to the last argument to the | |
1035 | previous command, after expansion. Also set to the full pathname | |
1036 | of each command executed and placed in the environment exported to | |
1037 | that command. When checking mail, this parameter holds the name | |
1038 | of the mail file. | |
ccc6cda3 JA |
1039 | |
1040 | \1f | |
1041 | File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features | |
1042 | ||
1043 | Shell Expansions | |
1044 | ================ | |
1045 | ||
1046 | Expansion is performed on the command line after it has been split | |
1047 | into `token's. There are seven kinds of expansion performed: | |
1048 | * brace expansion | |
1049 | ||
1050 | * tilde expansion | |
1051 | ||
1052 | * parameter and variable expansion | |
1053 | ||
1054 | * command substitution | |
1055 | ||
1056 | * arithmetic expansion | |
1057 | ||
1058 | * word splitting | |
1059 | ||
1060 | * filename expansion | |
1061 | ||
1062 | * Menu: | |
1063 | ||
cce855bc JA |
1064 | * Brace Expansion:: Expansion of expressions within braces. |
1065 | * Tilde Expansion:: Expansion of the ~ character. | |
ccc6cda3 JA |
1066 | * Shell Parameter Expansion:: How Bash expands variables to their values. |
1067 | * Command Substitution:: Using the output of a command as an argument. | |
cce855bc | 1068 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. |
ccc6cda3 JA |
1069 | * Process Substitution:: A way to write and read to and from a |
1070 | command. | |
1071 | * Word Splitting:: How the results of expansion are split into separate | |
1072 | arguments. | |
1073 | * Filename Expansion:: A shorthand for specifying filenames matching patterns. | |
1074 | * Quote Removal:: How and when quote characters are removed from | |
1075 | words. | |
1076 | ||
ccc6cda3 JA |
1077 | The order of expansions is: brace expansion, tilde expansion, |
1078 | parameter, variable, and arithmetic expansion and command substitution | |
1079 | (done in a left-to-right fashion), word splitting, and filename | |
1080 | expansion. | |
1081 | ||
1082 | On systems that can support it, there is an additional expansion | |
1083 | available: PROCESS SUBSTITUTION. This is performed at the same time as | |
cce855bc | 1084 | parameter, variable, and arithmetic expansion and command substitution. |
ccc6cda3 JA |
1085 | |
1086 | Only brace expansion, word splitting, and filename expansion can | |
1087 | change the number of words of the expansion; other expansions expand a | |
1088 | single word to a single word. The only exceptions to this are the | |
28ef6c31 JA |
1089 | expansions of `"$@"' (*note Special Parameters::) and `"${NAME[@]}"' |
1090 | (*note Arrays::). | |
ccc6cda3 | 1091 | |
28ef6c31 | 1092 | After all expansions, `quote removal' (*note Quote Removal::) is |
ccc6cda3 JA |
1093 | performed. |
1094 | ||
1095 | \1f | |
cce855bc JA |
1096 | File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions |
1097 | ||
1098 | Brace Expansion | |
1099 | --------------- | |
1100 | ||
1101 | Brace expansion is a mechanism by which arbitrary strings may be | |
1102 | generated. This mechanism is similar to FILENAME EXPANSION (*note | |
28ef6c31 | 1103 | Filename Expansion::), but the file names generated need not exist. |
cce855bc JA |
1104 | Patterns to be brace expanded take the form of an optional PREAMBLE, |
1105 | followed by a series of comma-separated strings between a pair of | |
bb70624e | 1106 | braces, followed by an optional POSTSCRIPT. The preamble is prefixed |
cce855bc JA |
1107 | to each string contained within the braces, and the postscript is then |
1108 | appended to each resulting string, expanding left to right. | |
1109 | ||
1110 | Brace expansions may be nested. The results of each expanded string | |
1111 | are not sorted; left to right order is preserved. For example, | |
1112 | bash$ echo a{d,c,b}e | |
1113 | ade ace abe | |
1114 | ||
1115 | Brace expansion is performed before any other expansions, and any | |
1116 | characters special to other expansions are preserved in the result. It | |
1117 | is strictly textual. Bash does not apply any syntactic interpretation | |
bb70624e JA |
1118 | to the context of the expansion or the text between the braces. To |
1119 | avoid conflicts with parameter expansion, the string `${' is not | |
1120 | considered eligible for brace expansion. | |
cce855bc JA |
1121 | |
1122 | A correctly-formed brace expansion must contain unquoted opening and | |
1123 | closing braces, and at least one unquoted comma. Any incorrectly | |
1124 | formed brace expansion is left unchanged. | |
1125 | ||
1126 | This construct is typically used as shorthand when the common prefix | |
1127 | of the strings to be generated is longer than in the above example: | |
1128 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
1129 | or | |
1130 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
1131 | ||
1132 | \1f | |
1133 | File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions | |
1134 | ||
1135 | Tilde Expansion | |
1136 | --------------- | |
1137 | ||
1138 | If a word begins with an unquoted tilde character (`~'), all of the | |
1139 | characters up to the first unquoted slash (or all characters, if there | |
1140 | is no unquoted slash) are considered a TILDE-PREFIX. If none of the | |
1141 | characters in the tilde-prefix are quoted, the characters in the | |
1142 | tilde-prefix following the tilde are treated as a possible LOGIN NAME. | |
1143 | If this login name is the null string, the tilde is replaced with the | |
1144 | value of the `HOME' shell variable. If `HOME' is unset, the home | |
1145 | directory of the user executing the shell is substituted instead. | |
1146 | Otherwise, the tilde-prefix is replaced with the home directory | |
1147 | associated with the specified login name. | |
1148 | ||
1149 | If the tilde-prefix is `~+', the value of the shell variable `PWD' | |
1150 | replaces the tilde-prefix. If the tilde-prefix is `~-', the value of | |
1151 | the shell variable `OLDPWD', if it is set, is substituted. | |
1152 | ||
1153 | If the characters following the tilde in the tilde-prefix consist of | |
1154 | a number N, optionally prefixed by a `+' or a `-', the tilde-prefix is | |
1155 | replaced with the corresponding element from the directory stack, as it | |
1156 | would be displayed by the `dirs' builtin invoked with the characters | |
1157 | following tilde in the tilde-prefix as an argument (*note The Directory | |
28ef6c31 | 1158 | Stack::). If the tilde-prefix, sans the tilde, consists of a number |
cce855bc JA |
1159 | without a leading `+' or `-', `+' is assumed. |
1160 | ||
1161 | If the login name is invalid, or the tilde expansion fails, the word | |
1162 | is left unchanged. | |
1163 | ||
1164 | Each variable assignment is checked for unquoted tilde-prefixes | |
1165 | immediately following a `:' or `='. In these cases, tilde expansion is | |
1166 | also performed. Consequently, one may use file names with tildes in | |
1167 | assignments to `PATH', `MAILPATH', and `CDPATH', and the shell assigns | |
1168 | the expanded value. | |
1169 | ||
1170 | The following table shows how Bash treats unquoted tilde-prefixes: | |
1171 | ||
1172 | `~' | |
1173 | The value of `$HOME' | |
1174 | ||
1175 | `~/foo' | |
1176 | `$HOME/foo' | |
1177 | ||
1178 | `~fred/foo' | |
1179 | The subdirectory `foo' of the home directory of the user `fred' | |
1180 | ||
1181 | `~+/foo' | |
1182 | `$PWD/foo' | |
1183 | ||
1184 | `~-/foo' | |
1185 | `${OLDPWD-'~-'}/foo' | |
1186 | ||
1187 | `~N' | |
1188 | The string that would be displayed by `dirs +N' | |
1189 | ||
1190 | `~+N' | |
1191 | The string that would be displayed by `dirs +N' | |
1192 | ||
1193 | `~-N' | |
1194 | The string that would be displayed by `dirs -N' | |
1195 | ||
1196 | \1f | |
1197 | File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions | |
ccc6cda3 JA |
1198 | |
1199 | Shell Parameter Expansion | |
1200 | ------------------------- | |
1201 | ||
1202 | The `$' character introduces parameter expansion, command | |
1203 | substitution, or arithmetic expansion. The parameter name or symbol to | |
1204 | be expanded may be enclosed in braces, which are optional but serve to | |
1205 | protect the variable to be expanded from characters immediately | |
1206 | following it which could be interpreted as part of the name. | |
1207 | ||
cce855bc JA |
1208 | When braces are used, the matching ending brace is the first `}' not |
1209 | escaped by a backslash or within a quoted string, and not within an | |
1210 | embedded arithmetic expansion, command substitution, or parameter | |
1211 | expansion. | |
1212 | ||
ccc6cda3 JA |
1213 | The basic form of parameter expansion is ${PARAMETER}. The value of |
1214 | PARAMETER is substituted. The braces are required when PARAMETER is a | |
1215 | positional parameter with more than one digit, or when PARAMETER is | |
1216 | followed by a character that is not to be interpreted as part of its | |
1217 | name. | |
1218 | ||
1219 | If the first character of PARAMETER is an exclamation point, a level | |
1220 | of variable indirection is introduced. Bash uses the value of the | |
1221 | variable formed from the rest of PARAMETER as the name of the variable; | |
d166f048 JA |
1222 | this variable is then expanded and that value is used in the rest of |
1223 | the substitution, rather than the value of PARAMETER itself. This is | |
bb70624e JA |
1224 | known as `indirect expansion'. The exception to this is the expansion |
1225 | of ${!PREFIX*} described below. | |
ccc6cda3 JA |
1226 | |
1227 | In each of the cases below, WORD is subject to tilde expansion, | |
1228 | parameter expansion, command substitution, and arithmetic expansion. | |
bb70624e JA |
1229 | |
1230 | When not performing substring expansion, Bash tests for a parameter | |
ccc6cda3 | 1231 | that is unset or null; omitting the colon results in a test only for a |
bb70624e JA |
1232 | parameter that is unset. Put another way, if the colon is included, |
1233 | the operator tests for both existence and that the value is not null; | |
1234 | if the colon is omitted, the operator tests only for existence. | |
ccc6cda3 JA |
1235 | |
1236 | `${PARAMETER:-WORD}' | |
1237 | If PARAMETER is unset or null, the expansion of WORD is | |
1238 | substituted. Otherwise, the value of PARAMETER is substituted. | |
1239 | ||
1240 | `${PARAMETER:=WORD}' | |
1241 | If PARAMETER is unset or null, the expansion of WORD is assigned | |
1242 | to PARAMETER. The value of PARAMETER is then substituted. | |
1243 | Positional parameters and special parameters may not be assigned | |
1244 | to in this way. | |
1245 | ||
1246 | `${PARAMETER:?WORD}' | |
1247 | If PARAMETER is null or unset, the expansion of WORD (or a message | |
1248 | to that effect if WORD is not present) is written to the standard | |
1249 | error and the shell, if it is not interactive, exits. Otherwise, | |
1250 | the value of PARAMETER is substituted. | |
1251 | ||
1252 | `${PARAMETER:+WORD}' | |
1253 | If PARAMETER is null or unset, nothing is substituted, otherwise | |
1254 | the expansion of WORD is substituted. | |
1255 | ||
1256 | `${PARAMETER:OFFSET}' | |
1257 | `${PARAMETER:OFFSET:LENGTH}' | |
bb70624e | 1258 | Expands to up to LENGTH characters of PARAMETER starting at the |
cce855bc | 1259 | character specified by OFFSET. If LENGTH is omitted, expands to |
bb70624e | 1260 | the substring of PARAMETER starting at the character specified by |
cce855bc | 1261 | OFFSET. LENGTH and OFFSET are arithmetic expressions (*note Shell |
28ef6c31 | 1262 | Arithmetic::). This is referred to as Substring Expansion. |
ccc6cda3 JA |
1263 | |
1264 | LENGTH must evaluate to a number greater than or equal to zero. | |
1265 | If OFFSET evaluates to a number less than zero, the value is used | |
1266 | as an offset from the end of the value of PARAMETER. If PARAMETER | |
1267 | is `@', the result is LENGTH positional parameters beginning at | |
1268 | OFFSET. If PARAMETER is an array name indexed by `@' or `*', the | |
1269 | result is the LENGTH members of the array beginning with | |
cce855bc JA |
1270 | `${PARAMETER[OFFSET]}'. Substring indexing is zero-based unless |
1271 | the positional parameters are used, in which case the indexing | |
1272 | starts at 1. | |
ccc6cda3 | 1273 | |
bb70624e JA |
1274 | `${!PREFIX*}' |
1275 | Expands to the names of variables whose names begin with PREFIX, | |
1276 | separated by the first character of the `IFS' special variable. | |
1277 | ||
ccc6cda3 | 1278 | `${#PARAMETER}' |
cce855bc JA |
1279 | The length in characters of the expanded value of PARAMETER is |
1280 | substituted. If PARAMETER is `*' or `@', the value substituted is | |
1281 | the number of positional parameters. If PARAMETER is an array | |
1282 | name subscripted by `*' or `@', the value substituted is the | |
1283 | number of elements in the array. | |
ccc6cda3 JA |
1284 | |
1285 | `${PARAMETER#WORD}' | |
1286 | `${PARAMETER##WORD}' | |
1287 | The WORD is expanded to produce a pattern just as in filename | |
28ef6c31 | 1288 | expansion (*note Filename Expansion::). If the pattern matches |
cce855bc JA |
1289 | the beginning of the expanded value of PARAMETER, then the result |
1290 | of the expansion is the expanded value of PARAMETER with the | |
1291 | shortest matching pattern (the `#' case) or the longest matching | |
1292 | pattern (the `##' case) deleted. If PARAMETER is `@' or `*', the | |
1293 | pattern removal operation is applied to each positional parameter | |
1294 | in turn, and the expansion is the resultant list. If PARAMETER is | |
1295 | an array variable subscripted with `@' or `*', the pattern removal | |
1296 | operation is applied to each member of the array in turn, and the | |
1297 | expansion is the resultant list. | |
ccc6cda3 JA |
1298 | |
1299 | `${PARAMETER%WORD}' | |
1300 | `${PARAMETER%%WORD}' | |
1301 | The WORD is expanded to produce a pattern just as in filename | |
cce855bc JA |
1302 | expansion. If the pattern matches a trailing portion of the |
1303 | expanded value of PARAMETER, then the result of the expansion is | |
1304 | the value of PARAMETER with the shortest matching pattern (the `%' | |
1305 | case) or the longest matching pattern (the `%%' case) deleted. If | |
1306 | PARAMETER is `@' or `*', the pattern removal operation is applied | |
1307 | to each positional parameter in turn, and the expansion is the | |
1308 | resultant list. If PARAMETER is an array variable subscripted | |
1309 | with `@' or `*', the pattern removal operation is applied to each | |
1310 | member of the array in turn, and the expansion is the resultant | |
1311 | list. | |
ccc6cda3 JA |
1312 | |
1313 | `${PARAMETER/PATTERN/STRING}' | |
1314 | `${PARAMETER//PATTERN/STRING}' | |
1315 | The PATTERN is expanded to produce a pattern just as in filename | |
1316 | expansion. PARAMETER is expanded and the longest match of PATTERN | |
1317 | against its value is replaced with STRING. In the first form, | |
1318 | only the first match is replaced. The second form causes all | |
1319 | matches of PATTERN to be replaced with STRING. If PATTERN begins | |
b72432fd JA |
1320 | with `#', it must match at the beginning of the expanded value of |
1321 | PARAMETER. If PATTERN begins with `%', it must match at the end | |
1322 | of the expanded value of PARAMETER. If STRING is null, matches of | |
1323 | PATTERN are deleted and the `/' following PATTERN may be omitted. | |
1324 | If PARAMETER is `@' or `*', the substitution operation is applied | |
1325 | to each positional parameter in turn, and the expansion is the | |
1326 | resultant list. If PARAMETER is an array variable subscripted | |
1327 | with `@' or `*', the substitution operation is applied to each | |
1328 | member of the array in turn, and the expansion is the resultant | |
1329 | list. | |
ccc6cda3 JA |
1330 | |
1331 | \1f | |
cce855bc | 1332 | File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions |
ccc6cda3 JA |
1333 | |
1334 | Command Substitution | |
1335 | -------------------- | |
1336 | ||
1337 | Command substitution allows the output of a command to replace the | |
bb70624e JA |
1338 | command itself. Command substitution occurs when a command is enclosed |
1339 | as follows: | |
ccc6cda3 JA |
1340 | $(COMMAND) |
1341 | ||
1342 | or | |
1343 | `COMMAND` | |
1344 | ||
1345 | Bash performs the expansion by executing COMMAND and replacing the | |
1346 | command substitution with the standard output of the command, with any | |
cce855bc JA |
1347 | trailing newlines deleted. Embedded newlines are not deleted, but they |
1348 | may be removed during word splitting. The command substitution `$(cat | |
1349 | FILE)' can be replaced by the equivalent but faster `$(< FILE)'. | |
ccc6cda3 JA |
1350 | |
1351 | When the old-style backquote form of substitution is used, backslash | |
1352 | retains its literal meaning except when followed by `$', ``', or `\'. | |
cce855bc JA |
1353 | The first backquote not preceded by a backslash terminates the command |
1354 | substitution. When using the `$(COMMAND)' form, all characters between | |
1355 | the parentheses make up the command; none are treated specially. | |
ccc6cda3 | 1356 | |
cce855bc JA |
1357 | Command substitutions may be nested. To nest when using the |
1358 | backquoted form, escape the inner backquotes with backslashes. | |
ccc6cda3 JA |
1359 | |
1360 | If the substitution appears within double quotes, word splitting and | |
1361 | filename expansion are not performed on the results. | |
1362 | ||
1363 | \1f | |
cce855bc JA |
1364 | File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions |
1365 | ||
1366 | Arithmetic Expansion | |
1367 | -------------------- | |
1368 | ||
1369 | Arithmetic expansion allows the evaluation of an arithmetic | |
1370 | expression and the substitution of the result. The format for | |
1371 | arithmetic expansion is: | |
1372 | ||
1373 | $(( EXPRESSION )) | |
1374 | ||
1375 | The expression is treated as if it were within double quotes, but a | |
1376 | double quote inside the parentheses is not treated specially. All | |
1377 | tokens in the expression undergo parameter expansion, command | |
1378 | substitution, and quote removal. Arithmetic substitutions may be | |
1379 | nested. | |
1380 | ||
1381 | The evaluation is performed according to the rules listed below | |
28ef6c31 | 1382 | (*note Shell Arithmetic::). If the expression is invalid, Bash prints |
cce855bc JA |
1383 | a message indicating failure to the standard error and no substitution |
1384 | occurs. | |
1385 | ||
1386 | \1f | |
1387 | File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions | |
ccc6cda3 JA |
1388 | |
1389 | Process Substitution | |
1390 | -------------------- | |
1391 | ||
1392 | Process substitution is supported on systems that support named | |
1393 | pipes (FIFOs) or the `/dev/fd' method of naming open files. It takes | |
1394 | the form of | |
1395 | <(LIST) | |
1396 | ||
1397 | or | |
1398 | >(LIST) | |
1399 | ||
1400 | The process LIST is run with its input or output connected to a FIFO or | |
1401 | some file in `/dev/fd'. The name of this file is passed as an argument | |
1402 | to the current command as the result of the expansion. If the | |
1403 | `>(LIST)' form is used, writing to the file will provide input for | |
1404 | LIST. If the `<(LIST)' form is used, the file passed as an argument | |
bb70624e JA |
1405 | should be read to obtain the output of LIST. Note that no space may |
1406 | appear between the `<' or `>' and the left parenthesis, otherwise the | |
1407 | construct would be interpreted as a redirection. | |
ccc6cda3 | 1408 | |
cce855bc JA |
1409 | When available, process substitution is performed simultaneously with |
1410 | parameter and variable expansion, command substitution, and arithmetic | |
1411 | expansion. | |
ccc6cda3 JA |
1412 | |
1413 | \1f | |
1414 | File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions | |
1415 | ||
1416 | Word Splitting | |
1417 | -------------- | |
1418 | ||
1419 | The shell scans the results of parameter expansion, command | |
1420 | substitution, and arithmetic expansion that did not occur within double | |
1421 | quotes for word splitting. | |
1422 | ||
1423 | The shell treats each character of `$IFS' as a delimiter, and splits | |
1424 | the results of the other expansions into words on these characters. If | |
1425 | `IFS' is unset, or its value is exactly `<space><tab><newline>', the | |
1426 | default, then any sequence of `IFS' characters serves to delimit words. | |
1427 | If `IFS' has a value other than the default, then sequences of the | |
1428 | whitespace characters `space' and `tab' are ignored at the beginning | |
1429 | and end of the word, as long as the whitespace character is in the | |
1430 | value of `IFS' (an `IFS' whitespace character). Any character in `IFS' | |
1431 | that is not `IFS' whitespace, along with any adjacent `IFS' whitespace | |
1432 | characters, delimits a field. A sequence of `IFS' whitespace | |
1433 | characters is also treated as a delimiter. If the value of `IFS' is | |
1434 | null, no word splitting occurs. | |
1435 | ||
1436 | Explicit null arguments (`""' or `''') are retained. Unquoted | |
bb70624e | 1437 | implicit null arguments, resulting from the expansion of parameters |
ccc6cda3 JA |
1438 | that have no values, are removed. If a parameter with no value is |
1439 | expanded within double quotes, a null argument results and is retained. | |
1440 | ||
1441 | Note that if no expansion occurs, no splitting is performed. | |
1442 | ||
1443 | \1f | |
1444 | File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions | |
1445 | ||
1446 | Filename Expansion | |
1447 | ------------------ | |
1448 | ||
cce855bc JA |
1449 | * Menu: |
1450 | ||
1451 | * Pattern Matching:: How the shell matches patterns. | |
1452 | ||
ccc6cda3 | 1453 | After word splitting, unless the `-f' option has been set (*note The |
28ef6c31 | 1454 | Set Builtin::), Bash scans each word for the characters `*', `?', and |
bb70624e JA |
1455 | `['. If one of these characters appears, then the word is regarded as |
1456 | a PATTERN, and replaced with an alphabetically sorted list of file | |
ccc6cda3 | 1457 | names matching the pattern. If no matching file names are found, and |
cce855bc JA |
1458 | the shell option `nullglob' is disabled, the word is left unchanged. |
1459 | If the `nullglob' option is set, and no matches are found, the word is | |
1460 | removed. If the shell option `nocaseglob' is enabled, the match is | |
1461 | performed without regard to the case of alphabetic characters. | |
1462 | ||
28ef6c31 JA |
1463 | When a pattern is used for filename generation, the character `.' at |
1464 | the start of a filename or immediately following a slash must be | |
cce855bc JA |
1465 | matched explicitly, unless the shell option `dotglob' is set. When |
1466 | matching a file name, the slash character must always be matched | |
1467 | explicitly. In other cases, the `.' character is not treated specially. | |
1468 | ||
1469 | See the description of `shopt' in *Note Bash Builtins::, for a | |
1470 | description of the `nocaseglob', `nullglob', and `dotglob' options. | |
ccc6cda3 JA |
1471 | |
1472 | The `GLOBIGNORE' shell variable may be used to restrict the set of | |
cce855bc | 1473 | filenames matching a pattern. If `GLOBIGNORE' is set, each matching |
ccc6cda3 | 1474 | filename that also matches one of the patterns in `GLOBIGNORE' is |
28ef6c31 | 1475 | removed from the list of matches. The filenames `.' and `..' are |
cce855bc | 1476 | always ignored, even when `GLOBIGNORE' is set. However, setting |
ccc6cda3 JA |
1477 | `GLOBIGNORE' has the effect of enabling the `dotglob' shell option, so |
1478 | all other filenames beginning with a `.' will match. To get the old | |
1479 | behavior of ignoring filenames beginning with a `.', make `.*' one of | |
1480 | the patterns in `GLOBIGNORE'. The `dotglob' option is disabled when | |
1481 | `GLOBIGNORE' is unset. | |
1482 | ||
cce855bc JA |
1483 | \1f |
1484 | File: bashref.info, Node: Pattern Matching, Up: Filename Expansion | |
1485 | ||
1486 | Pattern Matching | |
1487 | ................ | |
1488 | ||
1489 | Any character that appears in a pattern, other than the special | |
1490 | pattern characters described below, matches itself. The NUL character | |
1491 | may not occur in a pattern. The special pattern characters must be | |
1492 | quoted if they are to be matched literally. | |
1493 | ||
ccc6cda3 JA |
1494 | The special pattern characters have the following meanings: |
1495 | `*' | |
1496 | Matches any string, including the null string. | |
1497 | ||
1498 | `?' | |
1499 | Matches any single character. | |
1500 | ||
1501 | `[...]' | |
1502 | Matches any one of the enclosed characters. A pair of characters | |
28ef6c31 JA |
1503 | separated by a hyphen denotes a RANGE EXPRESSION; any character |
1504 | that sorts between those two characters, inclusive, using the | |
1505 | current locale's collating sequence and character set, is matched. | |
1506 | If the first character following the `[' is a `!' or a `^' then | |
1507 | any character not enclosed is matched. A `-' may be matched by | |
1508 | including it as the first or last character in the set. A `]' may | |
1509 | be matched by including it as the first character in the set. The | |
1510 | sorting order of characters in range expressions is determined by | |
1511 | the current locale and the value of the `LC_COLLATE' shell | |
1512 | variable, if set. | |
1513 | ||
1514 | For example, in the default C locale, `[a-dx-z]' is equivalent to | |
1515 | `[abcdxyz]'. Many locales sort characters in dictionary order, | |
1516 | and in these locales `[a-dx-z]' is typically not equivalent to | |
1517 | `[abcdxyz]'; it might be equivalent to `[aBbCcDdxXyYz]', for | |
1518 | example. To obtain the traditional interpretation of ranges in | |
1519 | bracket expressions, you can force the use of the C locale by | |
1520 | setting the `LC_COLLATE' or `LC_ALL' environment variable to the | |
1521 | value `C'. | |
ccc6cda3 | 1522 | |
cce855bc JA |
1523 | Within `[' and `]', CHARACTER CLASSES can be specified using the |
1524 | syntax `[:'CLASS`:]', where CLASS is one of the following classes | |
bb70624e | 1525 | defined in the POSIX 1003.2 standard: |
cce855bc JA |
1526 | alnum alpha ascii blank cntrl digit graph lower |
1527 | print punct space upper xdigit | |
1528 | ||
1529 | A character class matches any character belonging to that class. | |
1530 | ||
1531 | Within `[' and `]', an EQUIVALENCE CLASS can be specified using | |
1532 | the syntax `[='C`=]', which matches all characters with the same | |
1533 | collation weight (as defined by the current locale) as the | |
1534 | character C. | |
1535 | ||
28ef6c31 | 1536 | Within `[' and `]', the syntax `[.'SYMBOL`.]' matches the |
cce855bc JA |
1537 | collating symbol SYMBOL. |
1538 | ||
1539 | If the `extglob' shell option is enabled using the `shopt' builtin, | |
1540 | several extended pattern matching operators are recognized. In the | |
1541 | following description, a PATTERN-LIST is a list of one or more patterns | |
1542 | separated by a `|'. Composite patterns may be formed using one or more | |
1543 | of the following sub-patterns: | |
1544 | ||
1545 | `?(PATTERN-LIST)' | |
1546 | Matches zero or one occurrence of the given patterns. | |
1547 | ||
1548 | `*(PATTERN-LIST)' | |
1549 | Matches zero or more occurrences of the given patterns. | |
1550 | ||
1551 | `+(PATTERN-LIST)' | |
1552 | Matches one or more occurrences of the given patterns. | |
1553 | ||
1554 | `@(PATTERN-LIST)' | |
1555 | Matches exactly one of the given patterns. | |
1556 | ||
1557 | `!(PATTERN-LIST)' | |
1558 | Matches anything except one of the given patterns. | |
1559 | ||
ccc6cda3 JA |
1560 | \1f |
1561 | File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions | |
1562 | ||
1563 | Quote Removal | |
1564 | ------------- | |
1565 | ||
1566 | After the preceding expansions, all unquoted occurrences of the | |
1567 | characters `\', `'', and `"' that did not result from one of the above | |
1568 | expansions are removed. | |
1569 | ||
1570 | \1f | |
1571 | File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features | |
1572 | ||
1573 | Redirections | |
1574 | ============ | |
1575 | ||
1576 | Before a command is executed, its input and output may be REDIRECTED | |
1577 | using a special notation interpreted by the shell. Redirection may | |
1578 | also be used to open and close files for the current shell execution | |
1579 | environment. The following redirection operators may precede or appear | |
1580 | anywhere within a simple command or may follow a command. Redirections | |
1581 | are processed in the order they appear, from left to right. | |
1582 | ||
1583 | In the following descriptions, if the file descriptor number is | |
1584 | omitted, and the first character of the redirection operator is `<', | |
1585 | the redirection refers to the standard input (file descriptor 0). If | |
1586 | the first character of the redirection operator is `>', the redirection | |
1587 | refers to the standard output (file descriptor 1). | |
1588 | ||
cce855bc JA |
1589 | The word following the redirection operator in the following |
1590 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
1591 | tilde expansion, parameter expansion, command substitution, arithmetic | |
bb70624e JA |
1592 | expansion, quote removal, filename expansion, and word splitting. If |
1593 | it expands to more than one word, Bash reports an error. | |
ccc6cda3 JA |
1594 | |
1595 | Note that the order of redirections is significant. For example, | |
1596 | the command | |
1597 | ls > DIRLIST 2>&1 | |
1598 | ||
bb70624e JA |
1599 | directs both standard output (file descriptor 1) and standard error |
1600 | (file descriptor 2) to the file DIRLIST, while the command | |
ccc6cda3 JA |
1601 | ls 2>&1 > DIRLIST |
1602 | ||
1603 | directs only the standard output to file DIRLIST, because the standard | |
1604 | error was duplicated as standard output before the standard output was | |
1605 | redirected to DIRLIST. | |
1606 | ||
bb70624e JA |
1607 | Bash handles several filenames specially when they are used in |
1608 | redirections, as described in the following table: | |
1609 | ||
1610 | `/dev/fd/FD' | |
1611 | If FD is a valid integer, file descriptor FD is duplicated. | |
1612 | ||
1613 | `/dev/stdin' | |
1614 | File descriptor 0 is duplicated. | |
1615 | ||
1616 | `/dev/stdout' | |
1617 | File descriptor 1 is duplicated. | |
1618 | ||
1619 | `/dev/stderr' | |
1620 | File descriptor 2 is duplicated. | |
1621 | ||
1622 | `/dev/tcp/HOST/PORT' | |
1623 | If HOST is a valid hostname or Internet address, and PORT is an | |
1624 | integer port number, Bash attempts to open a TCP connection to the | |
1625 | corresponding socket. | |
1626 | ||
1627 | `/dev/udp/HOST/PORT' | |
1628 | If HOST is a valid hostname or Internet address, and PORT is an | |
1629 | integer port number, Bash attempts to open a UDP connection to the | |
1630 | corresponding socket. | |
1631 | ||
cce855bc JA |
1632 | A failure to open or create a file causes the redirection to fail. |
1633 | ||
ccc6cda3 JA |
1634 | Redirecting Input |
1635 | ----------------- | |
1636 | ||
1637 | Redirection of input causes the file whose name results from the | |
1638 | expansion of WORD to be opened for reading on file descriptor `n', or | |
1639 | the standard input (file descriptor 0) if `n' is not specified. | |
1640 | ||
1641 | The general format for redirecting input is: | |
1642 | [n]<WORD | |
1643 | ||
1644 | Redirecting Output | |
1645 | ------------------ | |
1646 | ||
1647 | Redirection of output causes the file whose name results from the | |
1648 | expansion of WORD to be opened for writing on file descriptor `n', or | |
1649 | the standard output (file descriptor 1) if `n' is not specified. If | |
1650 | the file does not exist it is created; if it does exist it is truncated | |
1651 | to zero size. | |
1652 | ||
1653 | The general format for redirecting output is: | |
1654 | [n]>[|]WORD | |
1655 | ||
cce855bc JA |
1656 | If the redirection operator is `>', and the `noclobber' option to |
1657 | the `set' builtin has been enabled, the redirection will fail if the | |
bb70624e | 1658 | file whose name results from the expansion of WORD exists and is a |
cce855bc JA |
1659 | regular file. If the redirection operator is `>|', or the redirection |
1660 | operator is `>' and the `noclobber' option is not enabled, the | |
1661 | redirection is attempted even if the file named by WORD exists. | |
ccc6cda3 JA |
1662 | |
1663 | Appending Redirected Output | |
1664 | --------------------------- | |
1665 | ||
1666 | Redirection of output in this fashion causes the file whose name | |
1667 | results from the expansion of WORD to be opened for appending on file | |
1668 | descriptor `n', or the standard output (file descriptor 1) if `n' is | |
1669 | not specified. If the file does not exist it is created. | |
1670 | ||
1671 | The general format for appending output is: | |
1672 | [n]>>WORD | |
1673 | ||
1674 | Redirecting Standard Output and Standard Error | |
1675 | ---------------------------------------------- | |
1676 | ||
1677 | Bash allows both the standard output (file descriptor 1) and the | |
1678 | standard error output (file descriptor 2) to be redirected to the file | |
1679 | whose name is the expansion of WORD with this construct. | |
1680 | ||
1681 | There are two formats for redirecting standard output and standard | |
1682 | error: | |
1683 | &>WORD | |
1684 | ||
1685 | and | |
1686 | >&WORD | |
1687 | ||
1688 | Of the two forms, the first is preferred. This is semantically | |
1689 | equivalent to | |
1690 | >WORD 2>&1 | |
1691 | ||
1692 | Here Documents | |
1693 | -------------- | |
1694 | ||
1695 | This type of redirection instructs the shell to read input from the | |
1696 | current source until a line containing only WORD (with no trailing | |
1697 | blanks) is seen. All of the lines read up to that point are then used | |
1698 | as the standard input for a command. | |
1699 | ||
1700 | The format of here-documents is as follows: | |
1701 | <<[-]WORD | |
1702 | HERE-DOCUMENT | |
1703 | DELIMITER | |
1704 | ||
bb70624e JA |
1705 | No parameter expansion, command substitution, arithmetic expansion, |
1706 | or filename expansion is performed on WORD. If any characters in WORD | |
ccc6cda3 | 1707 | are quoted, the DELIMITER is the result of quote removal on WORD, and |
cce855bc JA |
1708 | the lines in the here-document are not expanded. If WORD is unquoted, |
1709 | all lines of the here-document are subjected to parameter expansion, | |
1710 | command substitution, and arithmetic expansion. In the latter case, | |
bb70624e JA |
1711 | the character sequence `\newline' is ignored, and `\' must be used to |
1712 | quote the characters `\', `$', and ``'. | |
ccc6cda3 JA |
1713 | |
1714 | If the redirection operator is `<<-', then all leading tab | |
1715 | characters are stripped from input lines and the line containing | |
1716 | DELIMITER. This allows here-documents within shell scripts to be | |
1717 | indented in a natural fashion. | |
1718 | ||
1719 | Duplicating File Descriptors | |
1720 | ---------------------------- | |
1721 | ||
1722 | The redirection operator | |
1723 | [n]<&WORD | |
1724 | ||
1725 | is used to duplicate input file descriptors. If WORD expands to one or | |
1726 | more digits, the file descriptor denoted by `n' is made to be a copy of | |
cce855bc JA |
1727 | that file descriptor. If the digits in WORD do not specify a file |
1728 | descriptor open for input, a redirection error occurs. If WORD | |
1729 | evaluates to `-', file descriptor `n' is closed. If `n' is not | |
1730 | specified, the standard input (file descriptor 0) is used. | |
ccc6cda3 JA |
1731 | |
1732 | The operator | |
1733 | [n]>&WORD | |
1734 | ||
1735 | is used similarly to duplicate output file descriptors. If `n' is not | |
cce855bc JA |
1736 | specified, the standard output (file descriptor 1) is used. If the |
1737 | digits in WORD do not specify a file descriptor open for output, a | |
1738 | redirection error occurs. As a special case, if `n' is omitted, and | |
1739 | WORD does not expand to one or more digits, the standard output and | |
1740 | standard error are redirected as described previously. | |
ccc6cda3 JA |
1741 | |
1742 | Opening File Descriptors for Reading and Writing | |
1743 | ------------------------------------------------ | |
1744 | ||
1745 | The redirection operator | |
1746 | [n]<>WORD | |
1747 | ||
1748 | causes the file whose name is the expansion of WORD to be opened for | |
1749 | both reading and writing on file descriptor `n', or on file descriptor | |
1750 | 0 if `n' is not specified. If the file does not exist, it is created. | |
1751 | ||
1752 | \1f | |
1753 | File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features | |
1754 | ||
1755 | Executing Commands | |
1756 | ================== | |
1757 | ||
1758 | * Menu: | |
1759 | ||
cce855bc JA |
1760 | * Simple Command Expansion:: How Bash expands simple commands before |
1761 | executing them. | |
1762 | ||
ccc6cda3 JA |
1763 | * Command Search and Execution:: How Bash finds commands and runs them. |
1764 | ||
cce855bc JA |
1765 | * Command Execution Environment:: The environment in which Bash |
1766 | executes commands that are not | |
1767 | shell builtins. | |
1768 | ||
ccc6cda3 JA |
1769 | * Environment:: The environment given to a command. |
1770 | ||
1771 | * Exit Status:: The status returned by commands and how Bash | |
1772 | interprets it. | |
1773 | ||
1774 | * Signals:: What happens when Bash or a command it runs | |
1775 | receives a signal. | |
1776 | ||
1777 | \1f | |
cce855bc JA |
1778 | File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands |
1779 | ||
1780 | Simple Command Expansion | |
1781 | ------------------------ | |
1782 | ||
1783 | When a simple command is executed, the shell performs the following | |
1784 | expansions, assignments, and redirections, from left to right. | |
1785 | ||
1786 | 1. The words that the parser has marked as variable assignments (those | |
1787 | preceding the command name) and redirections are saved for later | |
1788 | processing. | |
1789 | ||
1790 | 2. The words that are not variable assignments or redirections are | |
28ef6c31 | 1791 | expanded (*note Shell Expansions::). If any words remain after |
cce855bc JA |
1792 | expansion, the first word is taken to be the name of the command |
1793 | and the remaining words are the arguments. | |
1794 | ||
1795 | 3. Redirections are performed as described above (*note | |
28ef6c31 | 1796 | Redirections::). |
cce855bc JA |
1797 | |
1798 | 4. The text after the `=' in each variable assignment undergoes tilde | |
1799 | expansion, parameter expansion, command substitution, arithmetic | |
1800 | expansion, and quote removal before being assigned to the variable. | |
1801 | ||
1802 | If no command name results, the variable assignments affect the | |
1803 | current shell environment. Otherwise, the variables are added to the | |
1804 | environment of the executed command and do not affect the current shell | |
1805 | environment. If any of the assignments attempts to assign a value to a | |
1806 | readonly variable, an error occurs, and the command exits with a | |
1807 | non-zero status. | |
1808 | ||
1809 | If no command name results, redirections are performed, but do not | |
1810 | affect the current shell environment. A redirection error causes the | |
1811 | command to exit with a non-zero status. | |
1812 | ||
1813 | If there is a command name left after expansion, execution proceeds | |
1814 | as described below. Otherwise, the command exits. If one of the | |
1815 | expansions contained a command substitution, the exit status of the | |
1816 | command is the exit status of the last command substitution performed. | |
1817 | If there were no command substitutions, the command exits with a status | |
1818 | of zero. | |
1819 | ||
1820 | \1f | |
1821 | File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands | |
ccc6cda3 JA |
1822 | |
1823 | Command Search and Execution | |
1824 | ---------------------------- | |
1825 | ||
1826 | After a command has been split into words, if it results in a simple | |
1827 | command and an optional list of arguments, the following actions are | |
1828 | taken. | |
1829 | ||
1830 | 1. If the command name contains no slashes, the shell attempts to | |
1831 | locate it. If there exists a shell function by that name, that | |
bb70624e | 1832 | function is invoked as described in *Note Shell Functions::. |
ccc6cda3 JA |
1833 | |
1834 | 2. If the name does not match a function, the shell searches for it | |
1835 | in the list of shell builtins. If a match is found, that builtin | |
1836 | is invoked. | |
1837 | ||
1838 | 3. If the name is neither a shell function nor a builtin, and | |
1839 | contains no slashes, Bash searches each element of `$PATH' for a | |
1840 | directory containing an executable file by that name. Bash uses a | |
cce855bc JA |
1841 | hash table to remember the full pathnames of executable files to |
1842 | avoid multiple `PATH' searches (see the description of `hash' in | |
1843 | *Note Bourne Shell Builtins::). A full search of the directories | |
ccc6cda3 JA |
1844 | in `$PATH' is performed only if the command is not found in the |
1845 | hash table. If the search is unsuccessful, the shell prints an | |
cce855bc | 1846 | error message and returns an exit status of 127. |
ccc6cda3 JA |
1847 | |
1848 | 4. If the search is successful, or if the command name contains one | |
cce855bc JA |
1849 | or more slashes, the shell executes the named program in a |
1850 | separate execution environment. Argument 0 is set to the name | |
1851 | given, and the remaining arguments to the command are set to the | |
1852 | arguments supplied, if any. | |
ccc6cda3 JA |
1853 | |
1854 | 5. If this execution fails because the file is not in executable | |
cce855bc JA |
1855 | format, and the file is not a directory, it is assumed to be a |
1856 | SHELL SCRIPT and the shell executes it as described in *Note Shell | |
1857 | Scripts::. | |
1858 | ||
1859 | 6. If the command was not begun asynchronously, the shell waits for | |
1860 | the command to complete and collects its exit status. | |
1861 | ||
1862 | ||
1863 | \1f | |
1864 | File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands | |
1865 | ||
1866 | Command Execution Environment | |
1867 | ----------------------------- | |
1868 | ||
1869 | The shell has an EXECUTION ENVIRONMENT, which consists of the | |
1870 | following: | |
1871 | ||
1872 | * open files inherited by the shell at invocation, as modified by | |
1873 | redirections supplied to the `exec' builtin | |
1874 | ||
1875 | * the current working directory as set by `cd', `pushd', or `popd', | |
1876 | or inherited by the shell at invocation | |
1877 | ||
1878 | * the file creation mode mask as set by `umask' or inherited from | |
1879 | the shell's parent | |
1880 | ||
1881 | * current traps set by `trap' | |
1882 | ||
1883 | * shell parameters that are set by variable assignment or with `set' | |
1884 | or inherited from the shell's parent in the environment | |
1885 | ||
1886 | * shell functions defined during execution or inherited from the | |
1887 | shell's parent in the environment | |
1888 | ||
1889 | * options enabled at invocation (either by default or with | |
1890 | command-line arguments) or by `set' | |
1891 | ||
1892 | * options enabled by `shopt' | |
1893 | ||
28ef6c31 | 1894 | * shell aliases defined with `alias' (*note Aliases::) |
cce855bc JA |
1895 | |
1896 | * various process IDs, including those of background jobs (*note | |
28ef6c31 JA |
1897 | Lists::), the value of `$$', and the value of `$PPID' |
1898 | ||
cce855bc JA |
1899 | |
1900 | When a simple command other than a builtin or shell function is to | |
1901 | be executed, it is invoked in a separate execution environment that | |
1902 | consists of the following. Unless otherwise noted, the values are | |
1903 | inherited from the shell. | |
1904 | ||
1905 | * the shell's open files, plus any modifications and additions | |
1906 | specified by redirections to the command | |
1907 | ||
1908 | * the current working directory | |
1909 | ||
1910 | * the file creation mode mask | |
1911 | ||
1912 | * shell variables marked for export, along with variables exported | |
28ef6c31 | 1913 | for the command, passed in the environment (*note Environment::) |
cce855bc JA |
1914 | |
1915 | * traps caught by the shell are reset to the values inherited from | |
1916 | the shell's parent, and traps ignored by the shell are ignored | |
1917 | ||
28ef6c31 | 1918 | |
cce855bc JA |
1919 | A command invoked in this separate environment cannot affect the |
1920 | shell's execution environment. | |
1921 | ||
1922 | Command substitution and asynchronous commands are invoked in a | |
1923 | subshell environment that is a duplicate of the shell environment, | |
1924 | except that traps caught by the shell are reset to the values that the | |
1925 | shell inherited from its parent at invocation. Builtin commands that | |
1926 | are invoked as part of a pipeline are also executed in a subshell | |
1927 | environment. Changes made to the subshell environment cannot affect | |
1928 | the shell's execution environment. | |
ccc6cda3 JA |
1929 | |
1930 | \1f | |
cce855bc | 1931 | File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands |
ccc6cda3 JA |
1932 | |
1933 | Environment | |
1934 | ----------- | |
1935 | ||
1936 | When a program is invoked it is given an array of strings called the | |
1937 | ENVIRONMENT. This is a list of name-value pairs, of the form | |
1938 | `name=value'. | |
1939 | ||
bb70624e | 1940 | Bash provides several ways to manipulate the environment. On |
ccc6cda3 JA |
1941 | invocation, the shell scans its own environment and creates a parameter |
1942 | for each name found, automatically marking it for EXPORT to child | |
1943 | processes. Executed commands inherit the environment. The `export' | |
1944 | and `declare -x' commands allow parameters and functions to be added to | |
1945 | and deleted from the environment. If the value of a parameter in the | |
1946 | environment is modified, the new value becomes part of the environment, | |
1947 | replacing the old. The environment inherited by any executed command | |
1948 | consists of the shell's initial environment, whose values may be | |
cce855bc JA |
1949 | modified in the shell, less any pairs removed by the `unset' and |
1950 | `export -n' commands, plus any additions via the `export' and `declare | |
1951 | -x' commands. | |
ccc6cda3 JA |
1952 | |
1953 | The environment for any simple command or function may be augmented | |
1954 | temporarily by prefixing it with parameter assignments, as described in | |
1955 | *Note Shell Parameters::. These assignment statements affect only the | |
1956 | environment seen by that command. | |
1957 | ||
28ef6c31 | 1958 | If the `-k' option is set (*note The Set Builtin::), then all |
ccc6cda3 JA |
1959 | parameter assignments are placed in the environment for a command, not |
1960 | just those that precede the command name. | |
1961 | ||
1962 | When Bash invokes an external command, the variable `$_' is set to | |
1963 | the full path name of the command and passed to that command in its | |
1964 | environment. | |
1965 | ||
1966 | \1f | |
1967 | File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands | |
1968 | ||
1969 | Exit Status | |
1970 | ----------- | |
1971 | ||
cce855bc JA |
1972 | For the shell's purposes, a command which exits with a zero exit |
1973 | status has succeeded. A non-zero exit status indicates failure. This | |
1974 | seemingly counter-intuitive scheme is used so there is one well-defined | |
1975 | way to indicate success and a variety of ways to indicate various | |
1976 | failure modes. When a command terminates on a fatal signal whose | |
1977 | number is N, Bash uses the value 128+N as the exit status. | |
ccc6cda3 JA |
1978 | |
1979 | If a command is not found, the child process created to execute it | |
1980 | returns a status of 127. If a command is found but is not executable, | |
1981 | the return status is 126. | |
1982 | ||
cce855bc JA |
1983 | If a command fails because of an error during expansion or |
1984 | redirection, the exit status is greater than zero. | |
1985 | ||
ccc6cda3 | 1986 | The exit status is used by the Bash conditional commands (*note |
28ef6c31 JA |
1987 | Conditional Constructs::) and some of the list constructs (*note |
1988 | Lists::). | |
ccc6cda3 JA |
1989 | |
1990 | All of the Bash builtins return an exit status of zero if they | |
1991 | succeed and a non-zero status on failure, so they may be used by the | |
cce855bc JA |
1992 | conditional and list constructs. All builtins return an exit status of |
1993 | 2 to indicate incorrect usage. | |
ccc6cda3 JA |
1994 | |
1995 | \1f | |
1996 | File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands | |
1997 | ||
1998 | Signals | |
1999 | ------- | |
2000 | ||
cce855bc JA |
2001 | When Bash is interactive, in the absence of any traps, it ignores |
2002 | `SIGTERM' (so that `kill 0' does not kill an interactive shell), and | |
2003 | `SIGINT' is caught and handled (so that the `wait' builtin is | |
2004 | interruptible). When Bash receives a `SIGINT', it breaks out of any | |
2005 | executing loops. In all cases, Bash ignores `SIGQUIT'. If job control | |
28ef6c31 | 2006 | is in effect (*note Job Control::), Bash ignores `SIGTTIN', `SIGTTOU', |
cce855bc | 2007 | and `SIGTSTP'. |
ccc6cda3 | 2008 | |
cce855bc | 2009 | Commands started by Bash have signal handlers set to the values |
ccc6cda3 | 2010 | inherited by the shell from its parent. When job control is not in |
cce855bc JA |
2011 | effect, asynchronous commands ignore `SIGINT' and `SIGQUIT' as well. |
2012 | Commands run as a result of command substitution ignore the | |
2013 | keyboard-generated job control signals `SIGTTIN', `SIGTTOU', and | |
ccc6cda3 JA |
2014 | `SIGTSTP'. |
2015 | ||
2016 | The shell exits by default upon receipt of a `SIGHUP'. Before | |
cce855bc JA |
2017 | exiting, it resends the `SIGHUP' to all jobs, running or stopped. |
2018 | Stopped jobs are sent `SIGCONT' to ensure that they receive the | |
2019 | `SIGHUP'. To prevent the shell from sending the `SIGHUP' signal to a | |
2020 | particular job, it should be removed from the jobs table with the | |
28ef6c31 | 2021 | `disown' builtin (*note Job Control Builtins::) or marked to not |
cce855bc JA |
2022 | receive `SIGHUP' using `disown -h'. |
2023 | ||
2024 | If the `huponexit' shell option has been set with `shopt' (*note | |
28ef6c31 JA |
2025 | Bash Builtins::), Bash sends a `SIGHUP' to all jobs when an interactive |
2026 | login shell exits. | |
cce855bc JA |
2027 | |
2028 | When Bash receives a signal for which a trap has been set while | |
2029 | waiting for a command to complete, the trap will not be executed until | |
2030 | the command completes. When Bash is waiting for an asynchronous | |
2031 | command via the `wait' builtin, the reception of a signal for which a | |
2032 | trap has been set will cause the `wait' builtin to return immediately | |
2033 | with an exit status greater than 128, immediately after which the trap | |
2034 | is executed. | |
ccc6cda3 JA |
2035 | |
2036 | \1f | |
2037 | File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features | |
2038 | ||
2039 | Shell Scripts | |
2040 | ============= | |
2041 | ||
2042 | A shell script is a text file containing shell commands. When such | |
2043 | a file is used as the first non-option argument when invoking Bash, and | |
28ef6c31 | 2044 | neither the `-c' nor `-s' option is supplied (*note Invoking Bash::), |
ccc6cda3 JA |
2045 | Bash reads and executes commands from the file, then exits. This mode |
2046 | of operation creates a non-interactive shell. When Bash runs a shell | |
2047 | script, it sets the special parameter `0' to the name of the file, | |
2048 | rather than the name of the shell, and the positional parameters are | |
2049 | set to the remaining arguments, if any are given. If no additional | |
2050 | arguments are supplied, the positional parameters are unset. | |
2051 | ||
2052 | A shell script may be made executable by using the `chmod' command | |
2053 | to turn on the execute bit. When Bash finds such a file while | |
2054 | searching the `$PATH' for a command, it spawns a subshell to execute | |
2055 | it. In other words, executing | |
2056 | filename ARGUMENTS | |
2057 | ||
2058 | is equivalent to executing | |
2059 | bash filename ARGUMENTS | |
2060 | ||
2061 | if `filename' is an executable shell script. This subshell | |
2062 | reinitializes itself, so that the effect is as if a new shell had been | |
cce855bc JA |
2063 | invoked to interpret the script, with the exception that the locations |
2064 | of commands remembered by the parent (see the description of `hash' in | |
2065 | *Note Bourne Shell Builtins::) are retained by the child. | |
ccc6cda3 | 2066 | |
bb70624e JA |
2067 | Most versions of Unix make this a part of the operating system's |
2068 | command execution mechanism. If the first line of a script begins with | |
2069 | the two characters `#!', the remainder of the line specifies an | |
2070 | interpreter for the program. Thus, you can specify Bash, `awk', Perl, | |
2071 | or some other interpreter and write the rest of the script file in that | |
2072 | language. | |
2073 | ||
2074 | The arguments to the interpreter consist of a single optional | |
2075 | argument following the interpreter name on the first line of the script | |
2076 | file, followed by the name of the script file, followed by the rest of | |
2077 | the arguments. Bash will perform this action on operating systems that | |
2078 | do not handle it themselves. Note that some older versions of Unix | |
2079 | limit the interpreter name and argument to a maximum of 32 characters. | |
2080 | ||
2081 | Bash scripts often begin with `#! /bin/bash' (assuming that Bash has | |
2082 | been installed in `/bin'), since this ensures that Bash will be used to | |
2083 | interpret the script, even if it is executed under another shell. | |
ccc6cda3 JA |
2084 | |
2085 | \1f | |
bb70624e | 2086 | File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top |
ccc6cda3 | 2087 | |
bb70624e JA |
2088 | Shell Builtin Commands |
2089 | ********************** | |
ccc6cda3 JA |
2090 | |
2091 | * Menu: | |
2092 | ||
2093 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
2094 | Shell. | |
bb70624e JA |
2095 | * Bash Builtins:: Table of builtins specific to Bash. |
2096 | * The Set Builtin:: This builtin is so overloaded it | |
2097 | deserves its own section. | |
2098 | * Special Builtins:: Builtin commands classified specially by | |
2099 | POSIX.2. | |
2100 | ||
2101 | Builtin commands are contained within the shell itself. When the | |
2102 | name of a builtin command is used as the first word of a simple command | |
28ef6c31 | 2103 | (*note Simple Commands::), the shell executes the command directly, |
bb70624e JA |
2104 | without invoking another program. Builtin commands are necessary to |
2105 | implement functionality impossible or inconvenient to obtain with | |
2106 | separate utilities. | |
ccc6cda3 | 2107 | |
bb70624e JA |
2108 | This section briefly the builtins which Bash inherits from the |
2109 | Bourne Shell, as well as the builtin commands which are unique to or | |
2110 | have been extended in Bash. | |
2111 | ||
2112 | Several builtin commands are described in other chapters: builtin | |
2113 | commands which provide the Bash interface to the job control facilities | |
28ef6c31 JA |
2114 | (*note Job Control Builtins::), the directory stack (*note Directory |
2115 | Stack Builtins::), the command history (*note Bash History Builtins::), | |
2116 | and the programmable completion facilities (*note Programmable | |
2117 | Completion Builtins::). | |
bb70624e JA |
2118 | |
2119 | Many of the builtins have been extended by POSIX or Bash. | |
ccc6cda3 JA |
2120 | |
2121 | \1f | |
bb70624e | 2122 | File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 JA |
2123 | |
2124 | Bourne Shell Builtins | |
2125 | ===================== | |
2126 | ||
2127 | The following shell builtin commands are inherited from the Bourne | |
2128 | Shell. These commands are implemented as specified by the POSIX 1003.2 | |
2129 | standard. | |
2130 | ||
bb70624e | 2131 | `: (a colon)' |
ccc6cda3 JA |
2132 | : [ARGUMENTS] |
2133 | Do nothing beyond expanding ARGUMENTS and performing redirections. | |
cce855bc | 2134 | The return status is zero. |
ccc6cda3 | 2135 | |
bb70624e | 2136 | `. (a period)' |
b72432fd | 2137 | . FILENAME [ARGUMENTS] |
ccc6cda3 | 2138 | Read and execute commands from the FILENAME argument in the |
cce855bc | 2139 | current shell context. If FILENAME does not contain a slash, the |
28ef6c31 JA |
2140 | `PATH' variable is used to find FILENAME. When Bash is not in |
2141 | POSIX mode, the current directory is searched if FILENAME is not | |
2142 | found in `$PATH'. If any ARGUMENTS are supplied, they become the | |
2143 | positional parameters when FILENAME is executed. Otherwise the | |
2144 | positional parameters are unchanged. The return status is the | |
2145 | exit status of the last command executed, or zero if no commands | |
2146 | are executed. If FILENAME is not found, or cannot be read, the | |
2147 | return status is non-zero. This builtin is equivalent to `source'. | |
ccc6cda3 JA |
2148 | |
2149 | `break' | |
2150 | break [N] | |
2151 | Exit from a `for', `while', `until', or `select' loop. If N is | |
cce855bc JA |
2152 | supplied, the Nth enclosing loop is exited. N must be greater |
2153 | than or equal to 1. The return status is zero unless N is not | |
2154 | greater than or equal to 1. | |
ccc6cda3 JA |
2155 | |
2156 | `cd' | |
2157 | cd [-LP] [DIRECTORY] | |
2158 | Change the current working directory to DIRECTORY. If DIRECTORY | |
2159 | is not given, the value of the `HOME' shell variable is used. If | |
2160 | the shell variable `CDPATH' exists, it is used as a search path. | |
2161 | If DIRECTORY begins with a slash, `CDPATH' is not used. The `-P' | |
cce855bc JA |
2162 | option means to not follow symbolic links; symbolic links are |
2163 | followed by default or with the `-L' option. If DIRECTORY is `-', | |
2164 | it is equivalent to `$OLDPWD'. The return status is zero if the | |
2165 | directory is successfully changed, non-zero otherwise. | |
ccc6cda3 JA |
2166 | |
2167 | `continue' | |
2168 | continue [N] | |
2169 | Resume the next iteration of an enclosing `for', `while', `until', | |
2170 | or `select' loop. If N is supplied, the execution of the Nth | |
cce855bc JA |
2171 | enclosing loop is resumed. N must be greater than or equal to 1. |
2172 | The return status is zero unless N is not greater than or equal to | |
2173 | 1. | |
ccc6cda3 JA |
2174 | |
2175 | `eval' | |
2176 | eval [ARGUMENTS] | |
2177 | The arguments are concatenated together into a single command, | |
cce855bc JA |
2178 | which is then read and executed, and its exit status returned as |
2179 | the exit status of `eval'. If there are no arguments or only | |
2180 | empty arguments, the return status is zero. | |
ccc6cda3 JA |
2181 | |
2182 | `exec' | |
cce855bc JA |
2183 | exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] |
2184 | If COMMAND is supplied, it replaces the shell without creating a | |
2185 | new process. If the `-l' option is supplied, the shell places a | |
bb70624e JA |
2186 | dash at the beginning of the zeroth arg passed to COMMAND. This |
2187 | is what the `login' program does. The `-c' option causes COMMAND | |
2188 | to be executed with an empty environment. If `-a' is supplied, | |
2189 | the shell passes NAME as the zeroth argument to COMMAND. If no | |
cce855bc JA |
2190 | COMMAND is specified, redirections may be used to affect the |
2191 | current shell environment. If there are no redirection errors, the | |
2192 | return status is zero; otherwise the return status is non-zero. | |
ccc6cda3 JA |
2193 | |
2194 | `exit' | |
2195 | exit [N] | |
bb70624e JA |
2196 | Exit the shell, returning a status of N to the shell's parent. If |
2197 | N is omitted, the exit status is that of the last command executed. | |
cce855bc | 2198 | Any trap on `EXIT' is executed before the shell terminates. |
ccc6cda3 JA |
2199 | |
2200 | `export' | |
2201 | export [-fn] [-p] [NAME[=VALUE]] | |
2202 | Mark each NAME to be passed to child processes in the environment. | |
2203 | If the `-f' option is supplied, the NAMEs refer to shell | |
cce855bc JA |
2204 | functions; otherwise the names refer to shell variables. The `-n' |
2205 | option means to no longer mark each NAME for export. If no NAMES | |
2206 | are supplied, or if the `-p' option is given, a list of exported | |
2207 | names is displayed. The `-p' option displays output in a form | |
2208 | that may be reused as input. The return status is zero unless an | |
2209 | invalid option is supplied, one of the names is not a valid shell | |
2210 | variable name, or `-f' is supplied with a name that is not a shell | |
2211 | function. | |
ccc6cda3 JA |
2212 | |
2213 | `getopts' | |
2214 | getopts OPTSTRING NAME [ARGS] | |
2215 | `getopts' is used by shell scripts to parse positional parameters. | |
bb70624e JA |
2216 | OPTSTRING contains the option characters to be recognized; if a |
2217 | character is followed by a colon, the option is expected to have an | |
2218 | argument, which should be separated from it by white space. The | |
2219 | colon (`:') and question mark (`?') may not be used as option | |
2220 | characters. Each time it is invoked, `getopts' places the next | |
2221 | option in the shell variable NAME, initializing NAME if it does | |
2222 | not exist, and the index of the next argument to be processed into | |
2223 | the variable `OPTIND'. `OPTIND' is initialized to 1 each time the | |
2224 | shell or a shell script is invoked. When an option requires an | |
2225 | argument, `getopts' places that argument into the variable | |
2226 | `OPTARG'. The shell does not reset `OPTIND' automatically; it | |
2227 | must be manually reset between multiple calls to `getopts' within | |
2228 | the same shell invocation if a new set of parameters is to be used. | |
ccc6cda3 | 2229 | |
cce855bc JA |
2230 | When the end of options is encountered, `getopts' exits with a |
2231 | return value greater than zero. `OPTIND' is set to the index of | |
2232 | the first non-option argument, and `name' is set to `?'. | |
2233 | ||
2234 | `getopts' normally parses the positional parameters, but if more | |
2235 | arguments are given in ARGS, `getopts' parses those instead. | |
2236 | ||
ccc6cda3 JA |
2237 | `getopts' can report errors in two ways. If the first character of |
2238 | OPTSTRING is a colon, SILENT error reporting is used. In normal | |
cce855bc | 2239 | operation diagnostic messages are printed when invalid options or |
ccc6cda3 | 2240 | missing option arguments are encountered. If the variable `OPTERR' |
cce855bc | 2241 | is set to 0, no error messages will be displayed, even if the first |
ccc6cda3 JA |
2242 | character of `optstring' is not a colon. |
2243 | ||
cce855bc | 2244 | If an invalid option is seen, `getopts' places `?' into NAME and, |
ccc6cda3 JA |
2245 | if not silent, prints an error message and unsets `OPTARG'. If |
2246 | `getopts' is silent, the option character found is placed in | |
2247 | `OPTARG' and no diagnostic message is printed. | |
2248 | ||
2249 | If a required argument is not found, and `getopts' is not silent, | |
2250 | a question mark (`?') is placed in NAME, `OPTARG' is unset, and a | |
2251 | diagnostic message is printed. If `getopts' is silent, then a | |
2252 | colon (`:') is placed in NAME and `OPTARG' is set to the option | |
2253 | character found. | |
2254 | ||
ccc6cda3 JA |
2255 | `hash' |
2256 | hash [-r] [-p FILENAME] [NAME] | |
cce855bc JA |
2257 | Remember the full pathnames of commands specified as NAME |
2258 | arguments, so they need not be searched for on subsequent | |
2259 | invocations. The commands are found by searching through the | |
2260 | directories listed in `$PATH'. The `-p' option inhibits the path | |
2261 | search, and FILENAME is used as the location of NAME. The `-r' | |
2262 | option causes the shell to forget all remembered locations. If no | |
2263 | arguments are given, information about remembered commands is | |
2264 | printed. The return status is zero unless a NAME is not found or | |
2265 | an invalid option is supplied. | |
ccc6cda3 JA |
2266 | |
2267 | `pwd' | |
2268 | pwd [-LP] | |
bb70624e JA |
2269 | Print the absolute pathname of the current working directory. If |
2270 | the `-P' option is supplied, the pathname printed will not contain | |
2271 | symbolic links. If the `-L' option is supplied, the pathname | |
2272 | printed may contain symbolic links. The return status is zero | |
2273 | unless an error is encountered while determining the name of the | |
2274 | current directory or an invalid option is supplied. | |
ccc6cda3 JA |
2275 | |
2276 | `readonly' | |
2277 | readonly [-apf] [NAME] ... | |
cce855bc JA |
2278 | Mark each NAME as readonly. The values of these names may not be |
2279 | changed by subsequent assignment. If the `-f' option is supplied, | |
2280 | each NAME refers to a shell function. The `-a' option means each | |
2281 | NAME refers to an array variable. If no NAME arguments are given, | |
2282 | or if the `-p' option is supplied, a list of all readonly names is | |
2283 | printed. The `-p' option causes output to be displayed in a | |
2284 | format that may be reused as input. The return status is zero | |
2285 | unless an invalid option is supplied, one of the NAME arguments is | |
2286 | not a valid shell variable or function name, or the `-f' option is | |
2287 | supplied with a name that is not a shell function. | |
ccc6cda3 JA |
2288 | |
2289 | `return' | |
2290 | return [N] | |
bb70624e JA |
2291 | Cause a shell function to exit with the return value N. If N is |
2292 | not supplied, the return value is the exit status of the last | |
2293 | command executed in the function. This may also be used to | |
2294 | terminate execution of a script being executed with the `.' (or | |
2295 | `source') builtin, returning either N or the exit status of the | |
cce855bc JA |
2296 | last command executed within the script as the exit status of the |
2297 | script. The return status is false if `return' is used outside a | |
bb70624e JA |
2298 | function and not during the execution of a script by `.' or |
2299 | `source'. | |
ccc6cda3 JA |
2300 | |
2301 | `shift' | |
2302 | shift [N] | |
cce855bc JA |
2303 | Shift the positional parameters to the left by N. The positional |
2304 | parameters from N+1 ... `$#' are renamed to `$1' ... `$#'-N+1. | |
2305 | Parameters represented by the numbers `$#' to N+1 are unset. N | |
2306 | must be a non-negative number less than or equal to `$#'. If N is | |
2307 | zero or greater than `$#', the positional parameters are not | |
bb70624e JA |
2308 | changed. If N is not supplied, it is assumed to be 1. The return |
2309 | status is zero unless N is greater than `$#' or less than zero, | |
2310 | non-zero otherwise. | |
ccc6cda3 JA |
2311 | |
2312 | `test' | |
2313 | `[' | |
cce855bc JA |
2314 | Evaluate a conditional expression EXPR. Each operator and operand |
2315 | must be a separate argument. Expressions are composed of the | |
2316 | primaries described below in *Note Bash Conditional Expressions::. | |
2317 | ||
bb70624e JA |
2318 | When the `[' form is used, the last argument to the command must |
2319 | be a `]'. | |
2320 | ||
cce855bc JA |
2321 | Expressions may be combined using the following operators, listed |
2322 | in decreasing order of precedence. | |
2323 | ||
2324 | `! EXPR' | |
2325 | True if EXPR is false. | |
2326 | ||
2327 | `( EXPR )' | |
2328 | Returns the value of EXPR. This may be used to override the | |
2329 | normal precedence of operators. | |
2330 | ||
2331 | `EXPR1 -a EXPR2' | |
2332 | True if both EXPR1 and EXPR2 are true. | |
2333 | ||
2334 | `EXPR1 -o EXPR2' | |
2335 | True if either EXPR1 or EXPR2 is true. | |
2336 | ||
2337 | The `test' and `[' builtins evaluate conditional expressions using | |
2338 | a set of rules based on the number of arguments. | |
2339 | ||
2340 | 0 arguments | |
2341 | The expression is false. | |
2342 | ||
2343 | 1 argument | |
2344 | The expression is true if and only if the argument is not | |
2345 | null. | |
2346 | ||
2347 | 2 arguments | |
2348 | If the first argument is `!', the expression is true if and | |
2349 | only if the second argument is null. If the first argument | |
2350 | is one of the unary conditional operators (*note Bash | |
28ef6c31 | 2351 | Conditional Expressions::), the expression is true if the |
cce855bc JA |
2352 | unary test is true. If the first argument is not a valid |
2353 | unary operator, the expression is false. | |
2354 | ||
2355 | 3 arguments | |
2356 | If the second argument is one of the binary conditional | |
28ef6c31 | 2357 | operators (*note Bash Conditional Expressions::), the result |
cce855bc JA |
2358 | of the expression is the result of the binary test using the |
2359 | first and third arguments as operands. If the first argument | |
2360 | is `!', the value is the negation of the two-argument test | |
2361 | using the second and third arguments. If the first argument | |
2362 | is exactly `(' and the third argument is exactly `)', the | |
2363 | result is the one-argument test of the second argument. | |
2364 | Otherwise, the expression is false. The `-a' and `-o' | |
2365 | operators are considered binary operators in this case. | |
2366 | ||
2367 | 4 arguments | |
2368 | If the first argument is `!', the result is the negation of | |
2369 | the three-argument expression composed of the remaining | |
2370 | arguments. Otherwise, the expression is parsed and evaluated | |
2371 | according to precedence using the rules listed above. | |
2372 | ||
2373 | 5 or more arguments | |
2374 | The expression is parsed and evaluated according to precedence | |
2375 | using the rules listed above. | |
ccc6cda3 JA |
2376 | |
2377 | `times' | |
2378 | times | |
2379 | Print out the user and system times used by the shell and its | |
cce855bc | 2380 | children. The return status is zero. |
ccc6cda3 JA |
2381 | |
2382 | `trap' | |
d166f048 | 2383 | trap [-lp] [ARG] [SIGSPEC ...] |
ccc6cda3 JA |
2384 | The commands in ARG are to be read and executed when the shell |
2385 | receives signal SIGSPEC. If ARG is absent or equal to `-', all | |
2386 | specified signals are reset to the values they had when the shell | |
d166f048 JA |
2387 | was started. If ARG is the null string, then the signal specified |
2388 | by each SIGSPEC is ignored by the shell and commands it invokes. | |
bb70624e JA |
2389 | If ARG is not present and `-p' has been supplied, the shell |
2390 | displays the trap commands associated with each SIGSPEC. If no | |
2391 | arguments are supplied, or only `-p' is given, `trap' prints the | |
2392 | list of commands associated with each signal number in a form that | |
2393 | may be reused as shell input. Each SIGSPEC is either a signal | |
2394 | name such as `SIGINT' (with or without the `SIG' prefix) or a | |
2395 | signal number. If a SIGSPEC is `0' or `EXIT', ARG is executed | |
2396 | when the shell exits. If a SIGSPEC is `DEBUG', the command ARG is | |
2397 | executed after every simple command. The `-l' option causes the | |
2398 | shell to print a list of signal names and their corresponding | |
2399 | numbers. | |
ccc6cda3 JA |
2400 | |
2401 | Signals ignored upon entry to the shell cannot be trapped or reset. | |
2402 | Trapped signals are reset to their original values in a child | |
2403 | process when it is created. | |
2404 | ||
cce855bc JA |
2405 | The return status is zero unless a SIGSPEC does not specify a |
2406 | valid signal. | |
2407 | ||
ccc6cda3 | 2408 | `umask' |
cce855bc | 2409 | umask [-p] [-S] [MODE] |
ccc6cda3 JA |
2410 | Set the shell process's file creation mask to MODE. If MODE |
2411 | begins with a digit, it is interpreted as an octal number; if not, | |
2412 | it is interpreted as a symbolic mode mask similar to that accepted | |
2413 | by the `chmod' command. If MODE is omitted, the current value of | |
2414 | the mask is printed. If the `-S' option is supplied without a | |
cce855bc JA |
2415 | MODE argument, the mask is printed in a symbolic format. If the |
2416 | `-p' option is supplied, and MODE is omitted, the output is in a | |
2417 | form that may be reused as input. The return status is zero if | |
2418 | the mode is successfully changed or if no MODE argument is | |
2419 | supplied, and non-zero otherwise. | |
ccc6cda3 | 2420 | |
bb70624e JA |
2421 | Note that when the mode is interpreted as an octal number, each |
2422 | number of the umask is subtracted from `7'. Thus, a umask of `022' | |
2423 | results in permissions of `755'. | |
2424 | ||
ccc6cda3 JA |
2425 | `unset' |
2426 | unset [-fv] [NAME] | |
2427 | Each variable or function NAME is removed. If no options are | |
2428 | supplied, or the `-v' option is given, each NAME refers to a shell | |
2429 | variable. If the `-f' option is given, the NAMEs refer to shell | |
cce855bc JA |
2430 | functions, and the function definition is removed. Readonly |
2431 | variables and functions may not be unset. The return status is | |
2432 | zero unless a NAME does not exist or is readonly. | |
ccc6cda3 JA |
2433 | |
2434 | \1f | |
bb70624e | 2435 | File: bashref.info, Node: Bash Builtins, Next: The Set Builtin, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 2436 | |
bb70624e JA |
2437 | Bash Builtin Commands |
2438 | ===================== | |
ccc6cda3 | 2439 | |
bb70624e JA |
2440 | This section describes builtin commands which are unique to or have |
2441 | been extended in Bash. Some of these commands are specified in the | |
2442 | POSIX 1003.2 standard. | |
ccc6cda3 | 2443 | |
bb70624e JA |
2444 | `alias' |
2445 | alias [`-p'] [NAME[=VALUE] ...] | |
ccc6cda3 | 2446 | |
bb70624e JA |
2447 | Without arguments or with the `-p' option, `alias' prints the list |
2448 | of aliases on the standard output in a form that allows them to be | |
2449 | reused as input. If arguments are supplied, an alias is defined | |
2450 | for each NAME whose VALUE is given. If no VALUE is given, the name | |
2451 | and value of the alias is printed. Aliases are described in *Note | |
2452 | Aliases::. | |
ccc6cda3 | 2453 | |
bb70624e JA |
2454 | `bind' |
2455 | bind [-m KEYMAP] [-lpsvPSV] | |
2456 | bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ] | |
2457 | bind [-m KEYMAP] -f FILENAME | |
2458 | bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND | |
2459 | bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME | |
ccc6cda3 | 2460 | |
28ef6c31 | 2461 | Display current Readline (*note Command Line Editing::) key and |
bb70624e JA |
2462 | function bindings, or bind a key sequence to a Readline function |
2463 | or macro. The binding syntax accepted is identical to that of a | |
28ef6c31 | 2464 | Readline initialization file (*note Readline Init File::), but |
bb70624e JA |
2465 | each binding must be passed as a separate argument: e.g., |
2466 | `"\C-x\C-r":re-read-init-file'. Options, if supplied, have the | |
2467 | following meanings: | |
ccc6cda3 | 2468 | |
bb70624e JA |
2469 | `-m KEYMAP' |
2470 | Use KEYMAP as the keymap to be affected by the subsequent | |
2471 | bindings. Acceptable KEYMAP names are `emacs', | |
28ef6c31 | 2472 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
bb70624e JA |
2473 | `vi-command', and `vi-insert'. `vi' is equivalent to |
2474 | `vi-command'; `emacs' is equivalent to `emacs-standard'. | |
cce855bc | 2475 | |
bb70624e JA |
2476 | `-l' |
2477 | List the names of all Readline functions. | |
cce855bc | 2478 | |
bb70624e JA |
2479 | `-p' |
2480 | Display Readline function names and bindings in such a way | |
2481 | that they can be used as input or in a Readline | |
2482 | initialization file. | |
cce855bc | 2483 | |
bb70624e JA |
2484 | `-P' |
2485 | List current Readline function names and bindings. | |
cce855bc | 2486 | |
bb70624e JA |
2487 | `-v' |
2488 | Display Readline variable names and values in such a way that | |
2489 | they can be used as input or in a Readline initialization | |
2490 | file. | |
ccc6cda3 | 2491 | |
bb70624e JA |
2492 | `-V' |
2493 | List current Readline variable names and values. | |
ccc6cda3 | 2494 | |
bb70624e JA |
2495 | `-s' |
2496 | Display Readline key sequences bound to macros and the | |
2497 | strings they output in such a way that they can be used as | |
2498 | input or in a Readline initialization file. | |
ccc6cda3 | 2499 | |
bb70624e JA |
2500 | `-S' |
2501 | Display Readline key sequences bound to macros and the | |
2502 | strings they output. | |
ccc6cda3 | 2503 | |
bb70624e JA |
2504 | `-f FILENAME' |
2505 | Read key bindings from FILENAME. | |
ccc6cda3 | 2506 | |
bb70624e JA |
2507 | `-q FUNCTION' |
2508 | Query about which keys invoke the named FUNCTION. | |
ccc6cda3 | 2509 | |
bb70624e JA |
2510 | `-u FUNCTION' |
2511 | Unbind all keys bound to the named FUNCTION. | |
ccc6cda3 | 2512 | |
bb70624e JA |
2513 | `-r KEYSEQ' |
2514 | Remove any current binding for KEYSEQ. | |
ccc6cda3 | 2515 | |
bb70624e JA |
2516 | `-x KEYSEQ:SHELL-COMMAND' |
2517 | Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered. | |
ccc6cda3 | 2518 | |
bb70624e JA |
2519 | The return status is zero unless an invalid option is supplied or |
2520 | an error occurs. | |
ccc6cda3 | 2521 | |
bb70624e JA |
2522 | `builtin' |
2523 | builtin [SHELL-BUILTIN [ARGS]] | |
2524 | Run a shell builtin, passing it ARGS, and return its exit status. | |
2525 | This is useful when defining a shell function with the same name | |
2526 | as a shell builtin, retaining the functionality of the builtin | |
2527 | within the function. The return status is non-zero if | |
2528 | SHELL-BUILTIN is not a shell builtin command. | |
ccc6cda3 | 2529 | |
bb70624e JA |
2530 | `command' |
2531 | command [-pVv] COMMAND [ARGUMENTS ...] | |
2532 | Runs COMMAND with ARGUMENTS ignoring any shell function named | |
2533 | COMMAND. Only shell builtin commands or commands found by | |
2534 | searching the `PATH' are executed. If there is a shell function | |
2535 | named `ls', running `command ls' within the function will execute | |
2536 | the external command `ls' instead of calling the function | |
2537 | recursively. The `-p' option means to use a default value for | |
28ef6c31 | 2538 | `PATH' that is guaranteed to find all of the standard utilities. |
bb70624e JA |
2539 | The return status in this case is 127 if COMMAND cannot be found |
2540 | or an error occurred, and the exit status of COMMAND otherwise. | |
ccc6cda3 | 2541 | |
bb70624e JA |
2542 | If either the `-V' or `-v' option is supplied, a description of |
2543 | COMMAND is printed. The `-v' option causes a single word | |
2544 | indicating the command or file name used to invoke COMMAND to be | |
2545 | displayed; the `-V' option produces a more verbose description. | |
2546 | In this case, the return status is zero if COMMAND is found, and | |
2547 | non-zero if not. | |
ccc6cda3 | 2548 | |
bb70624e JA |
2549 | `declare' |
2550 | declare [-afFrxi] [-p] [NAME[=VALUE]] | |
ccc6cda3 | 2551 | |
bb70624e JA |
2552 | Declare variables and give them attributes. If no NAMEs are |
2553 | given, then display the values of variables instead. | |
ccc6cda3 | 2554 | |
bb70624e JA |
2555 | The `-p' option will display the attributes and values of each |
2556 | NAME. When `-p' is used, additional options are ignored. The | |
2557 | `-F' option inhibits the display of function definitions; only the | |
2558 | function name and attributes are printed. `-F' implies `-f'. The | |
2559 | following options can be used to restrict output to variables with | |
2560 | the specified attributes or to give variables attributes: | |
ccc6cda3 | 2561 | |
bb70624e | 2562 | `-a' |
28ef6c31 | 2563 | Each NAME is an array variable (*note Arrays::). |
ccc6cda3 | 2564 | |
bb70624e JA |
2565 | `-f' |
2566 | Use function names only. | |
ccc6cda3 | 2567 | |
bb70624e JA |
2568 | `-i' |
2569 | The variable is to be treated as an integer; arithmetic | |
28ef6c31 | 2570 | evaluation (*note Shell Arithmetic::) is performed when the |
bb70624e | 2571 | variable is assigned a value. |
ccc6cda3 | 2572 | |
bb70624e JA |
2573 | `-r' |
2574 | Make NAMEs readonly. These names cannot then be assigned | |
2575 | values by subsequent assignment statements or unset. | |
ccc6cda3 | 2576 | |
bb70624e JA |
2577 | `-x' |
2578 | Mark each NAME for export to subsequent commands via the | |
2579 | environment. | |
ccc6cda3 | 2580 | |
bb70624e JA |
2581 | Using `+' instead of `-' turns off the attribute instead. When |
2582 | used in a function, `declare' makes each NAME local, as with the | |
2583 | `local' command. | |
ccc6cda3 | 2584 | |
bb70624e JA |
2585 | The return status is zero unless an invalid option is encountered, |
2586 | an attempt is made to define a function using `-f foo=bar', an | |
2587 | attempt is made to assign a value to a readonly variable, an | |
2588 | attempt is made to assign a value to an array variable without | |
28ef6c31 | 2589 | using the compound assignment syntax (*note Arrays::), one of the |
bb70624e JA |
2590 | NAMES is not a valid shell variable name, an attempt is made to |
2591 | turn off readonly status for a readonly variable, an attempt is | |
2592 | made to turn off array status for an array variable, or an attempt | |
2593 | is made to display a non-existent function with `-f'. | |
ccc6cda3 | 2594 | |
bb70624e JA |
2595 | `echo' |
2596 | echo [-neE] [ARG ...] | |
2597 | Output the ARGs, separated by spaces, terminated with a newline. | |
2598 | The return status is always 0. If `-n' is specified, the trailing | |
2599 | newline is suppressed. If the `-e' option is given, | |
2600 | interpretation of the following backslash-escaped characters is | |
2601 | enabled. The `-E' option disables the interpretation of these | |
2602 | escape characters, even on systems where they are interpreted by | |
2603 | default. The `xpg_echo' shell option may be used to dynamically | |
2604 | determine whether or not `echo' expands these escape characters by | |
2605 | default. `echo' interprets the following escape sequences: | |
2606 | `\a' | |
2607 | alert (bell) | |
ccc6cda3 | 2608 | |
bb70624e JA |
2609 | `\b' |
2610 | backspace | |
ccc6cda3 | 2611 | |
bb70624e JA |
2612 | `\c' |
2613 | suppress trailing newline | |
ccc6cda3 | 2614 | |
bb70624e JA |
2615 | `\e' |
2616 | escape | |
ccc6cda3 | 2617 | |
bb70624e JA |
2618 | `\f' |
2619 | form feed | |
ccc6cda3 | 2620 | |
bb70624e JA |
2621 | `\n' |
2622 | new line | |
ccc6cda3 | 2623 | |
bb70624e JA |
2624 | `\r' |
2625 | carriage return | |
ccc6cda3 | 2626 | |
bb70624e JA |
2627 | `\t' |
2628 | horizontal tab | |
ccc6cda3 | 2629 | |
bb70624e JA |
2630 | `\v' |
2631 | vertical tab | |
ccc6cda3 | 2632 | |
bb70624e JA |
2633 | `\\' |
2634 | backslash | |
ccc6cda3 | 2635 | |
bb70624e JA |
2636 | `\NNN' |
2637 | the character whose `ASCII' code is the octal value NNN (one | |
2638 | to three digits) | |
ccc6cda3 | 2639 | |
bb70624e JA |
2640 | `\xNNN' |
2641 | the character whose `ASCII' code is the hexadecimal value NNN | |
2642 | (one to three digits) | |
ccc6cda3 | 2643 | |
bb70624e JA |
2644 | `enable' |
2645 | enable [-n] [-p] [-f FILENAME] [-ads] [NAME ...] | |
2646 | Enable and disable builtin shell commands. Disabling a builtin | |
2647 | allows a disk command which has the same name as a shell builtin | |
2648 | to be executed without specifying a full pathname, even though the | |
2649 | shell normally searches for builtins before disk commands. If | |
2650 | `-n' is used, the NAMEs become disabled. Otherwise NAMEs are | |
2651 | enabled. For example, to use the `test' binary found via `$PATH' | |
2652 | instead of the shell builtin version, type `enable -n test'. | |
ccc6cda3 | 2653 | |
bb70624e JA |
2654 | If the `-p' option is supplied, or no NAME arguments appear, a |
2655 | list of shell builtins is printed. With no other arguments, the | |
2656 | list consists of all enabled shell builtins. The `-a' option | |
2657 | means to list each builtin with an indication of whether or not it | |
2658 | is enabled. | |
ccc6cda3 | 2659 | |
bb70624e JA |
2660 | The `-f' option means to load the new builtin command NAME from |
2661 | shared object FILENAME, on systems that support dynamic loading. | |
2662 | The `-d' option will delete a builtin loaded with `-f'. | |
ccc6cda3 | 2663 | |
bb70624e JA |
2664 | If there are no options, a list of the shell builtins is displayed. |
2665 | The `-s' option restricts `enable' to the POSIX special builtins. | |
2666 | If `-s' is used with `-f', the new builtin becomes a special | |
28ef6c31 | 2667 | builtin (*note Special Builtins::). |
ccc6cda3 | 2668 | |
bb70624e JA |
2669 | The return status is zero unless a NAME is not a shell builtin or |
2670 | there is an error loading a new builtin from a shared object. | |
ccc6cda3 | 2671 | |
bb70624e JA |
2672 | `help' |
2673 | help [-s] [PATTERN] | |
2674 | Display helpful information about builtin commands. If PATTERN is | |
2675 | specified, `help' gives detailed help on all commands matching | |
2676 | PATTERN, otherwise a list of the builtins is printed. The `-s' | |
2677 | option restricts the information displayed to a short usage | |
2678 | synopsis. The return status is zero unless no command matches | |
2679 | PATTERN. | |
ccc6cda3 | 2680 | |
bb70624e JA |
2681 | `let' |
2682 | let EXPRESSION [EXPRESSION] | |
2683 | The `let' builtin allows arithmetic to be performed on shell | |
2684 | variables. Each EXPRESSION is evaluated according to the rules | |
2685 | given below in *Note Shell Arithmetic::. If the last EXPRESSION | |
2686 | evaluates to 0, `let' returns 1; otherwise 0 is returned. | |
ccc6cda3 | 2687 | |
bb70624e JA |
2688 | `local' |
2689 | local [OPTION] NAME[=VALUE] | |
2690 | For each argument, a local variable named NAME is created, and | |
2691 | assigned VALUE. The OPTION can be any of the options accepted by | |
2692 | `declare'. `local' can only be used within a function; it makes | |
2693 | the variable NAME have a visible scope restricted to that function | |
2694 | and its children. The return status is zero unless `local' is | |
2695 | used outside a function, an invalid NAME is supplied, or NAME is a | |
2696 | readonly variable. | |
ccc6cda3 | 2697 | |
bb70624e JA |
2698 | `logout' |
2699 | logout [N] | |
2700 | Exit a login shell, returning a status of N to the shell's parent. | |
ccc6cda3 | 2701 | |
bb70624e JA |
2702 | `printf' |
2703 | `printf' FORMAT [ARGUMENTS] | |
2704 | Write the formatted ARGUMENTS to the standard output under the | |
2705 | control of the FORMAT. The FORMAT is a character string which | |
2706 | contains three types of objects: plain characters, which are | |
2707 | simply copied to standard output, character escape sequences, | |
2708 | which are converted and copied to the standard output, and format | |
2709 | specifications, each of which causes printing of the next | |
2710 | successive ARGUMENT. In addition to the standard `printf(1)' | |
2711 | formats, `%b' causes `printf' to expand backslash escape sequences | |
2712 | in the corresponding ARGUMENT, and `%q' causes `printf' to output | |
2713 | the corresponding ARGUMENT in a format that can be reused as shell | |
2714 | input. | |
ccc6cda3 | 2715 | |
bb70624e JA |
2716 | The FORMAT is reused as necessary to consume all of the ARGUMENTS. |
2717 | If the FORMAT requires more ARGUMENTS than are supplied, the extra | |
2718 | format specifications behave as if a zero value or null string, as | |
2719 | appropriate, had been supplied. The return value is zero on | |
2720 | success, non-zero on failure. | |
ccc6cda3 | 2721 | |
bb70624e JA |
2722 | `read' |
2723 | read [-ers] [-a ANAME] [-p PROMPT] [-t TIMEOUT] [-n NCHARS] [-d DELIM] [NAME ...] | |
2724 | One line is read from the standard input, and the first word is | |
2725 | assigned to the first NAME, the second word to the second NAME, | |
2726 | and so on, with leftover words and their intervening separators | |
2727 | assigned to the last NAME. If there are fewer words read from the | |
2728 | standard input than names, the remaining names are assigned empty | |
2729 | values. The characters in the value of the `IFS' variable are | |
2730 | used to split the line into words. The backslash character `\' | |
2731 | may be used to remove any special meaning for the next character | |
2732 | read and for line continuation. If no names are supplied, the | |
2733 | line read is assigned to the variable `REPLY'. The return code is | |
2734 | zero, unless end-of-file is encountered or `read' times out. | |
2735 | Options, if supplied, have the following meanings: | |
ccc6cda3 | 2736 | |
bb70624e JA |
2737 | `-a ANAME' |
2738 | The words are assigned to sequential indices of the array | |
2739 | variable ANAME, starting at 0. All elements are removed from | |
2740 | ANAME before the assignment. Other NAME arguments are | |
2741 | ignored. | |
ccc6cda3 | 2742 | |
bb70624e JA |
2743 | `-d DELIM' |
2744 | The first character of DELIM is used to terminate the input | |
2745 | line, rather than newline. | |
ccc6cda3 | 2746 | |
bb70624e | 2747 | `-e' |
28ef6c31 JA |
2748 | Readline (*note Command Line Editing::) is used to obtain the |
2749 | line. | |
ccc6cda3 | 2750 | |
bb70624e JA |
2751 | `-n NCHARS' |
2752 | `read' returns after reading NCHARS characters rather than | |
2753 | waiting for a complete line of input. | |
cce855bc | 2754 | |
bb70624e JA |
2755 | `-p PROMPT' |
2756 | Display PROMPT, without a trailing newline, before attempting | |
2757 | to read any input. The prompt is displayed only if input is | |
2758 | coming from a terminal. | |
ccc6cda3 | 2759 | |
bb70624e JA |
2760 | `-r' |
2761 | If this option is given, backslash does not act as an escape | |
2762 | character. The backslash is considered to be part of the | |
2763 | line. In particular, a backslash-newline pair may not be | |
2764 | used as a line continuation. | |
ccc6cda3 | 2765 | |
bb70624e JA |
2766 | `-s' |
2767 | Silent mode. If input is coming from a terminal, characters | |
2768 | are not echoed. | |
cce855bc | 2769 | |
bb70624e JA |
2770 | `-t TIMEOUT' |
2771 | Cause `read' to time out and return failure if a complete | |
2772 | line of input is not read within TIMEOUT seconds. This | |
2773 | option has no effect if `read' is not reading input from the | |
2774 | terminal or a pipe. | |
cce855bc | 2775 | |
bb70624e JA |
2776 | `shopt' |
2777 | shopt [-pqsu] [-o] [OPTNAME ...] | |
2778 | Toggle the values of variables controlling optional shell behavior. | |
2779 | With no options, or with the `-p' option, a list of all settable | |
2780 | options is displayed, with an indication of whether or not each is | |
2781 | set. The `-p' option causes output to be displayed in a form that | |
2782 | may be reused as input. Other options have the following meanings: | |
cce855bc | 2783 | |
bb70624e JA |
2784 | `-s' |
2785 | Enable (set) each OPTNAME. | |
ccc6cda3 | 2786 | |
bb70624e JA |
2787 | `-u' |
2788 | Disable (unset) each OPTNAME. | |
ccc6cda3 | 2789 | |
bb70624e JA |
2790 | `-q' |
2791 | Suppresses normal output; the return status indicates whether | |
2792 | the OPTNAME is set or unset. If multiple OPTNAME arguments | |
2793 | are given with `-q', the return status is zero if all | |
2794 | OPTNAMES are enabled; non-zero otherwise. | |
ccc6cda3 | 2795 | |
bb70624e JA |
2796 | `-o' |
2797 | Restricts the values of OPTNAME to be those defined for the | |
28ef6c31 | 2798 | `-o' option to the `set' builtin (*note The Set Builtin::). |
ccc6cda3 | 2799 | |
bb70624e JA |
2800 | If either `-s' or `-u' is used with no OPTNAME arguments, the |
2801 | display is limited to those options which are set or unset, | |
2802 | respectively. | |
ccc6cda3 | 2803 | |
bb70624e JA |
2804 | Unless otherwise noted, the `shopt' options are disabled (off) by |
2805 | default. | |
ccc6cda3 | 2806 | |
bb70624e JA |
2807 | The return status when listing options is zero if all OPTNAMES are |
2808 | enabled, non-zero otherwise. When setting or unsetting options, | |
2809 | the return status is zero unless an OPTNAME is not a valid shell | |
2810 | option. | |
ccc6cda3 | 2811 | |
bb70624e JA |
2812 | The list of `shopt' options is: |
2813 | `cdable_vars' | |
2814 | If this is set, an argument to the `cd' builtin command that | |
2815 | is not a directory is assumed to be the name of a variable | |
2816 | whose value is the directory to change to. | |
ccc6cda3 | 2817 | |
bb70624e JA |
2818 | `cdspell' |
2819 | If set, minor errors in the spelling of a directory component | |
2820 | in a `cd' command will be corrected. The errors checked for | |
2821 | are transposed characters, a missing character, and a | |
2822 | character too many. If a correction is found, the corrected | |
2823 | path is printed, and the command proceeds. This option is | |
2824 | only used by interactive shells. | |
ccc6cda3 | 2825 | |
bb70624e JA |
2826 | `checkhash' |
2827 | If this is set, Bash checks that a command found in the hash | |
2828 | table exists before trying to execute it. If a hashed | |
2829 | command no longer exists, a normal path search is performed. | |
ccc6cda3 | 2830 | |
bb70624e JA |
2831 | `checkwinsize' |
2832 | If set, Bash checks the window size after each command and, | |
2833 | if necessary, updates the values of `LINES' and `COLUMNS'. | |
ccc6cda3 | 2834 | |
bb70624e JA |
2835 | `cmdhist' |
2836 | If set, Bash attempts to save all lines of a multiple-line | |
2837 | command in the same history entry. This allows easy | |
2838 | re-editing of multi-line commands. | |
cce855bc | 2839 | |
bb70624e JA |
2840 | `dotglob' |
2841 | If set, Bash includes filenames beginning with a `.' in the | |
2842 | results of filename expansion. | |
cce855bc | 2843 | |
bb70624e JA |
2844 | `execfail' |
2845 | If this is set, a non-interactive shell will not exit if it | |
2846 | cannot execute the file specified as an argument to the `exec' | |
2847 | builtin command. An interactive shell does not exit if `exec' | |
2848 | fails. | |
ccc6cda3 | 2849 | |
bb70624e JA |
2850 | `expand_aliases' |
2851 | If set, aliases are expanded as described below under Aliases, | |
2852 | *Note Aliases::. This option is enabled by default for | |
2853 | interactive shells. | |
ccc6cda3 | 2854 | |
bb70624e JA |
2855 | `extglob' |
2856 | If set, the extended pattern matching features described above | |
28ef6c31 | 2857 | (*note Pattern Matching::) are enabled. |
ccc6cda3 | 2858 | |
bb70624e JA |
2859 | `histappend' |
2860 | If set, the history list is appended to the file named by the | |
2861 | value of the `HISTFILE' variable when the shell exits, rather | |
2862 | than overwriting the file. | |
ccc6cda3 | 2863 | |
bb70624e JA |
2864 | `histreedit' |
2865 | If set, and Readline is being used, a user is given the | |
2866 | opportunity to re-edit a failed history substitution. | |
ccc6cda3 | 2867 | |
bb70624e JA |
2868 | `histverify' |
2869 | If set, and Readline is being used, the results of history | |
2870 | substitution are not immediately passed to the shell parser. | |
2871 | Instead, the resulting line is loaded into the Readline | |
2872 | editing buffer, allowing further modification. | |
ccc6cda3 | 2873 | |
bb70624e JA |
2874 | `hostcomplete' |
2875 | If set, and Readline is being used, Bash will attempt to | |
2876 | perform hostname completion when a word containing a `@' is | |
28ef6c31 | 2877 | being completed (*note Commands For Completion::). This |
bb70624e | 2878 | option is enabled by default. |
ccc6cda3 | 2879 | |
bb70624e JA |
2880 | `huponexit' |
2881 | If set, Bash will send `SIGHUP' to all jobs when an | |
28ef6c31 | 2882 | interactive login shell exits (*note Signals::). |
ccc6cda3 | 2883 | |
bb70624e JA |
2884 | `interactive_comments' |
2885 | Allow a word beginning with `#' to cause that word and all | |
2886 | remaining characters on that line to be ignored in an | |
2887 | interactive shell. This option is enabled by default. | |
ccc6cda3 | 2888 | |
bb70624e JA |
2889 | `lithist' |
2890 | If enabled, and the `cmdhist' option is enabled, multi-line | |
2891 | commands are saved to the history with embedded newlines | |
2892 | rather than using semicolon separators where possible. | |
ccc6cda3 | 2893 | |
bb70624e JA |
2894 | `mailwarn' |
2895 | If set, and a file that Bash is checking for mail has been | |
2896 | accessed since the last time it was checked, the message | |
2897 | `"The mail in MAILFILE has been read"' is displayed. | |
ccc6cda3 | 2898 | |
bb70624e JA |
2899 | `no_empty_cmd_completion' |
2900 | If set, and Readline is being used, Bash will not attempt to | |
2901 | search the `PATH' for possible completions when completion is | |
2902 | attempted on an empty line. | |
ccc6cda3 | 2903 | |
bb70624e JA |
2904 | `nocaseglob' |
2905 | If set, Bash matches filenames in a case-insensitive fashion | |
2906 | when performing filename expansion. | |
ccc6cda3 | 2907 | |
bb70624e JA |
2908 | `nullglob' |
2909 | If set, Bash allows filename patterns which match no files to | |
2910 | expand to a null string, rather than themselves. | |
ccc6cda3 | 2911 | |
bb70624e JA |
2912 | `progcomp' |
2913 | If set, the programmable completion facilities (*note | |
28ef6c31 | 2914 | Programmable Completion::) are enabled. This option is |
bb70624e | 2915 | enabled by default. |
ccc6cda3 | 2916 | |
bb70624e JA |
2917 | `promptvars' |
2918 | If set, prompt strings undergo variable and parameter | |
28ef6c31 | 2919 | expansion after being expanded (*note Printing a Prompt::). |
bb70624e | 2920 | This option is enabled by default. |
ccc6cda3 | 2921 | |
bb70624e JA |
2922 | `restricted_shell' |
2923 | The shell sets this option if it is started in restricted mode | |
28ef6c31 JA |
2924 | (*note The Restricted Shell::). The value may not be changed. |
2925 | This is not reset when the startup files are executed, | |
2926 | allowing the startup files to discover whether or not a shell | |
2927 | is restricted. | |
ccc6cda3 | 2928 | |
bb70624e JA |
2929 | `shift_verbose' |
2930 | If this is set, the `shift' builtin prints an error message | |
2931 | when the shift count exceeds the number of positional | |
2932 | parameters. | |
ccc6cda3 | 2933 | |
bb70624e JA |
2934 | `sourcepath' |
2935 | If set, the `source' builtin uses the value of `PATH' to find | |
2936 | the directory containing the file supplied as an argument. | |
2937 | This option is enabled by default. | |
ccc6cda3 | 2938 | |
bb70624e JA |
2939 | `xpg_echo' |
2940 | If set, the `echo' builtin expands backslash-escape sequences | |
2941 | by default. | |
ccc6cda3 | 2942 | |
bb70624e JA |
2943 | The return status when listing options is zero if all OPTNAMES are |
2944 | enabled, non-zero otherwise. When setting or unsetting options, | |
2945 | the return status is zero unless an OPTNAME is not a valid shell | |
2946 | option. | |
ccc6cda3 | 2947 | |
bb70624e JA |
2948 | `source' |
2949 | source FILENAME | |
28ef6c31 | 2950 | A synonym for `.' (*note Bourne Shell Builtins::). |
ccc6cda3 | 2951 | |
bb70624e JA |
2952 | `type' |
2953 | type [-atp] [NAME ...] | |
2954 | For each NAME, indicate how it would be interpreted if used as a | |
2955 | command name. | |
cce855bc | 2956 | |
bb70624e JA |
2957 | If the `-t' option is used, `type' prints a single word which is |
2958 | one of `alias', `function', `builtin', `file' or `keyword', if | |
2959 | NAME is an alias, shell function, shell builtin, disk file, or | |
2960 | shell reserved word, respectively. If the NAME is not found, then | |
2961 | nothing is printed, and `type' returns a failure status. | |
ccc6cda3 | 2962 | |
bb70624e JA |
2963 | If the `-p' option is used, `type' either returns the name of the |
2964 | disk file that would be executed, or nothing if `-t' would not | |
2965 | return `file'. | |
ccc6cda3 | 2966 | |
bb70624e JA |
2967 | If the `-a' option is used, `type' returns all of the places that |
2968 | contain an executable named FILE. This includes aliases and | |
2969 | functions, if and only if the `-p' option is not also used. | |
ccc6cda3 | 2970 | |
bb70624e JA |
2971 | The return status is zero if any of the NAMES are found, non-zero |
2972 | if none are found. | |
ccc6cda3 | 2973 | |
bb70624e JA |
2974 | `typeset' |
2975 | typeset [-afFrxi] [-p] [NAME[=VALUE]] | |
2976 | The `typeset' command is supplied for compatibility with the Korn | |
2977 | shell; however, it has been deprecated in favor of the `declare' | |
2978 | builtin command. | |
ccc6cda3 | 2979 | |
bb70624e JA |
2980 | `ulimit' |
2981 | ulimit [-acdflmnpstuvSH] [LIMIT] | |
2982 | `ulimit' provides control over the resources available to processes | |
2983 | started by the shell, on systems that allow such control. If an | |
2984 | option is given, it is interpreted as follows: | |
2985 | `-S' | |
2986 | Change and report the soft limit associated with a resource. | |
ccc6cda3 | 2987 | |
bb70624e JA |
2988 | `-H' |
2989 | Change and report the hard limit associated with a resource. | |
ccc6cda3 | 2990 | |
bb70624e JA |
2991 | `-a' |
2992 | All current limits are reported. | |
ccc6cda3 | 2993 | |
bb70624e JA |
2994 | `-c' |
2995 | The maximum size of core files created. | |
ccc6cda3 | 2996 | |
bb70624e JA |
2997 | `-d' |
2998 | The maximum size of a process's data segment. | |
ccc6cda3 | 2999 | |
bb70624e JA |
3000 | `-f' |
3001 | The maximum size of files created by the shell. | |
ccc6cda3 | 3002 | |
bb70624e JA |
3003 | `-l' |
3004 | The maximum size that may be locked into memory. | |
ccc6cda3 | 3005 | |
bb70624e JA |
3006 | `-m' |
3007 | The maximum resident set size. | |
ccc6cda3 | 3008 | |
bb70624e JA |
3009 | `-n' |
3010 | The maximum number of open file descriptors. | |
ccc6cda3 | 3011 | |
bb70624e JA |
3012 | `-p' |
3013 | The pipe buffer size. | |
ccc6cda3 | 3014 | |
bb70624e JA |
3015 | `-s' |
3016 | The maximum stack size. | |
ccc6cda3 | 3017 | |
bb70624e JA |
3018 | `-t' |
3019 | The maximum amount of cpu time in seconds. | |
ccc6cda3 | 3020 | |
bb70624e JA |
3021 | `-u' |
3022 | The maximum number of processes available to a single user. | |
cce855bc | 3023 | |
bb70624e JA |
3024 | `-v' |
3025 | The maximum amount of virtual memory available to the process. | |
ccc6cda3 | 3026 | |
bb70624e JA |
3027 | If LIMIT is given, it is the new value of the specified resource. |
3028 | Otherwise, the current value of the soft limit for the specified | |
3029 | resource is printed, unless the `-H' option is supplied. When | |
3030 | setting new limits, if neither `-H' nor `-S' is supplied, both the | |
3031 | hard and soft limits are set. If no option is given, then `-f' is | |
3032 | assumed. Values are in 1024-byte increments, except for `-t', | |
3033 | which is in seconds, `-p', which is in units of 512-byte blocks, | |
3034 | and `-n' and `-u', which are unscaled values. | |
ccc6cda3 | 3035 | |
bb70624e JA |
3036 | The return status is zero unless an invalid option is supplied, a |
3037 | non-numeric argument other than `unlimited' is supplied as a | |
3038 | LIMIT, or an error occurs while setting a new limit. | |
ccc6cda3 | 3039 | |
bb70624e JA |
3040 | `unalias' |
3041 | unalias [-a] [NAME ... ] | |
ccc6cda3 | 3042 | |
bb70624e JA |
3043 | Remove each NAME from the list of aliases. If `-a' is supplied, |
3044 | all aliases are removed. Aliases are described in *Note Aliases::. | |
ccc6cda3 | 3045 | |
bb70624e JA |
3046 | \1f |
3047 | File: bashref.info, Node: The Set Builtin, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands | |
ccc6cda3 | 3048 | |
bb70624e JA |
3049 | The Set Builtin |
3050 | =============== | |
ccc6cda3 | 3051 | |
bb70624e | 3052 | This builtin is so complicated that it deserves its own section. |
ccc6cda3 | 3053 | |
bb70624e JA |
3054 | `set' |
3055 | set [--abefhkmnptuvxBCHP] [-o OPTION] [ARGUMENT ...] | |
ccc6cda3 | 3056 | |
bb70624e JA |
3057 | If no options or arguments are supplied, `set' displays the names |
3058 | and values of all shell variables and functions, sorted according | |
3059 | to the current locale, in a format that may be reused as input. | |
ccc6cda3 | 3060 | |
bb70624e JA |
3061 | When options are supplied, they set or unset shell attributes. |
3062 | Options, if specified, have the following meanings: | |
ccc6cda3 | 3063 | |
bb70624e | 3064 | `-a' |
28ef6c31 JA |
3065 | Mark variables and function which are modified or created for |
3066 | export to the environment of subsequent commands. | |
ccc6cda3 | 3067 | |
bb70624e JA |
3068 | `-b' |
3069 | Cause the status of terminated background jobs to be reported | |
3070 | immediately, rather than before printing the next primary | |
3071 | prompt. | |
ccc6cda3 | 3072 | |
bb70624e JA |
3073 | `-e' |
3074 | Exit immediately if a simple command (*note Simple | |
28ef6c31 | 3075 | Commands::) exits with a non-zero status, unless the command |
bb70624e JA |
3076 | that fails is part of an `until' or `while' loop, part of an |
3077 | `if' statement, part of a `&&' or `||' list, or if the | |
3078 | command's return status is being inverted using `!'. | |
ccc6cda3 | 3079 | |
bb70624e JA |
3080 | `-f' |
3081 | Disable file name generation (globbing). | |
ccc6cda3 | 3082 | |
bb70624e JA |
3083 | `-h' |
3084 | Locate and remember (hash) commands as they are looked up for | |
3085 | execution. This option is enabled by default. | |
ccc6cda3 | 3086 | |
bb70624e JA |
3087 | `-k' |
3088 | All arguments in the form of assignment statements are placed | |
3089 | in the environment for a command, not just those that precede | |
3090 | the command name. | |
ccc6cda3 | 3091 | |
bb70624e | 3092 | `-m' |
28ef6c31 | 3093 | Job control is enabled (*note Job Control::). |
b72432fd | 3094 | |
bb70624e JA |
3095 | `-n' |
3096 | Read commands but do not execute them; this may be used to | |
3097 | check a script for syntax errors. This option is ignored by | |
3098 | interactive shells. | |
ccc6cda3 | 3099 | |
bb70624e JA |
3100 | `-o OPTION-NAME' |
3101 | Set the option corresponding to OPTION-NAME: | |
ccc6cda3 | 3102 | |
bb70624e JA |
3103 | `allexport' |
3104 | Same as `-a'. | |
ccc6cda3 | 3105 | |
bb70624e JA |
3106 | `braceexpand' |
3107 | Same as `-B'. | |
ccc6cda3 | 3108 | |
bb70624e JA |
3109 | `emacs' |
3110 | Use an `emacs'-style line editing interface (*note | |
28ef6c31 | 3111 | Command Line Editing::). |
ccc6cda3 | 3112 | |
bb70624e JA |
3113 | `errexit' |
3114 | Same as `-e'. | |
d166f048 | 3115 | |
bb70624e JA |
3116 | `hashall' |
3117 | Same as `-h'. | |
d166f048 | 3118 | |
bb70624e JA |
3119 | `histexpand' |
3120 | Same as `-H'. | |
ccc6cda3 | 3121 | |
bb70624e JA |
3122 | `history' |
3123 | Enable command history, as described in *Note Bash | |
3124 | History Facilities::. This option is on by default in | |
3125 | interactive shells. | |
ccc6cda3 | 3126 | |
bb70624e JA |
3127 | `ignoreeof' |
3128 | An interactive shell will not exit upon reading EOF. | |
ccc6cda3 | 3129 | |
bb70624e JA |
3130 | `keyword' |
3131 | Same as `-k'. | |
ccc6cda3 | 3132 | |
bb70624e JA |
3133 | `monitor' |
3134 | Same as `-m'. | |
ccc6cda3 | 3135 | |
bb70624e JA |
3136 | `noclobber' |
3137 | Same as `-C'. | |
ccc6cda3 | 3138 | |
bb70624e JA |
3139 | `noexec' |
3140 | Same as `-n'. | |
ccc6cda3 | 3141 | |
bb70624e JA |
3142 | `noglob' |
3143 | Same as `-f'. | |
ccc6cda3 | 3144 | |
bb70624e JA |
3145 | `notify' |
3146 | Same as `-b'. | |
ccc6cda3 | 3147 | |
bb70624e JA |
3148 | `nounset' |
3149 | Same as `-u'. | |
ccc6cda3 | 3150 | |
bb70624e JA |
3151 | `onecmd' |
3152 | Same as `-t'. | |
ccc6cda3 | 3153 | |
bb70624e JA |
3154 | `physical' |
3155 | Same as `-P'. | |
ccc6cda3 | 3156 | |
bb70624e JA |
3157 | `posix' |
3158 | Change the behavior of Bash where the default operation | |
3159 | differs from the POSIX 1003.2 standard to match the | |
28ef6c31 JA |
3160 | standard (*note Bash POSIX Mode::). This is intended to |
3161 | make Bash behave as a strict superset of that standard. | |
ccc6cda3 | 3162 | |
bb70624e JA |
3163 | `privileged' |
3164 | Same as `-p'. | |
ccc6cda3 | 3165 | |
bb70624e JA |
3166 | `verbose' |
3167 | Same as `-v'. | |
cce855bc | 3168 | |
bb70624e JA |
3169 | `vi' |
3170 | Use a `vi'-style line editing interface. | |
ccc6cda3 | 3171 | |
bb70624e JA |
3172 | `xtrace' |
3173 | Same as `-x'. | |
cce855bc | 3174 | |
bb70624e JA |
3175 | `-p' |
3176 | Turn on privileged mode. In this mode, the `$BASH_ENV' and | |
3177 | `$ENV' files are not processed, shell functions are not | |
3178 | inherited from the environment, and the `SHELLOPTS' variable, | |
3179 | if it appears in the environment, is ignored. If the shell | |
3180 | is started with the effective user (group) id not equal to the | |
3181 | real user (group) id, and the `-p' option is not supplied, | |
3182 | these actions are taken and the effective user id is set to | |
3183 | the real user id. If the `-p' option is supplied at startup, | |
3184 | the effective user id is not reset. Turning this option off | |
3185 | causes the effective user and group ids to be set to the real | |
3186 | user and group ids. | |
ccc6cda3 | 3187 | |
bb70624e JA |
3188 | `-t' |
3189 | Exit after reading and executing one command. | |
ccc6cda3 | 3190 | |
bb70624e JA |
3191 | `-u' |
3192 | Treat unset variables as an error when performing parameter | |
3193 | expansion. An error message will be written to the standard | |
3194 | error, and a non-interactive shell will exit. | |
ccc6cda3 | 3195 | |
bb70624e JA |
3196 | `-v' |
3197 | Print shell input lines as they are read. | |
ccc6cda3 | 3198 | |
bb70624e JA |
3199 | `-x' |
3200 | Print a trace of simple commands and their arguments after | |
3201 | they are expanded and before they are executed. | |
ccc6cda3 | 3202 | |
bb70624e JA |
3203 | `-B' |
3204 | The shell will perform brace expansion (*note Brace | |
28ef6c31 | 3205 | Expansion::). This option is on by default. |
ccc6cda3 | 3206 | |
bb70624e JA |
3207 | `-C' |
3208 | Prevent output redirection using `>', `>&', and `<>' from | |
3209 | overwriting existing files. | |
ccc6cda3 | 3210 | |
bb70624e JA |
3211 | `-H' |
3212 | Enable `!' style history substitution (*note History | |
28ef6c31 JA |
3213 | Interaction::). This option is on by default for interactive |
3214 | shells. | |
ccc6cda3 | 3215 | |
bb70624e JA |
3216 | `-P' |
3217 | If set, do not follow symbolic links when performing commands | |
3218 | such as `cd' which change the current directory. The | |
3219 | physical directory is used instead. By default, Bash follows | |
3220 | the logical chain of directories when performing commands | |
3221 | which change the current directory. | |
ccc6cda3 | 3222 | |
bb70624e JA |
3223 | For example, if `/usr/sys' is a symbolic link to |
3224 | `/usr/local/sys' then: | |
3225 | $ cd /usr/sys; echo $PWD | |
3226 | /usr/sys | |
3227 | $ cd ..; pwd | |
3228 | /usr | |
ccc6cda3 | 3229 | |
bb70624e JA |
3230 | If `set -P' is on, then: |
3231 | $ cd /usr/sys; echo $PWD | |
3232 | /usr/local/sys | |
3233 | $ cd ..; pwd | |
3234 | /usr/local | |
ccc6cda3 | 3235 | |
bb70624e JA |
3236 | `--' |
3237 | If no arguments follow this option, then the positional | |
3238 | parameters are unset. Otherwise, the positional parameters | |
3239 | are set to the ARGUMENTS, even if some of them begin with a | |
3240 | `-'. | |
ccc6cda3 | 3241 | |
bb70624e JA |
3242 | `-' |
3243 | Signal the end of options, cause all remaining ARGUMENTS to | |
3244 | be assigned to the positional parameters. The `-x' and `-v' | |
3245 | options are turned off. If there are no arguments, the | |
3246 | positional parameters remain unchanged. | |
ccc6cda3 | 3247 | |
bb70624e JA |
3248 | Using `+' rather than `-' causes these options to be turned off. |
3249 | The options can also be used upon invocation of the shell. The | |
3250 | current set of options may be found in `$-'. | |
cce855bc | 3251 | |
bb70624e JA |
3252 | The remaining N ARGUMENTS are positional parameters and are |
3253 | assigned, in order, to `$1', `$2', ... `$N'. The special | |
3254 | parameter `#' is set to N. | |
ccc6cda3 | 3255 | |
bb70624e JA |
3256 | The return status is always zero unless an invalid option is |
3257 | supplied. | |
ccc6cda3 | 3258 | |
bb70624e JA |
3259 | \1f |
3260 | File: bashref.info, Node: Special Builtins, Prev: The Set Builtin, Up: Shell Builtin Commands | |
ccc6cda3 | 3261 | |
bb70624e JA |
3262 | Special Builtins |
3263 | ================ | |
ccc6cda3 | 3264 | |
bb70624e | 3265 | For historical reasons, the POSIX 1003.2 standard has classified |
28ef6c31 | 3266 | several builtin commands as _special_. When Bash is executing in POSIX |
bb70624e JA |
3267 | mode, the special builtins differ from other builtin commands in three |
3268 | respects: | |
ccc6cda3 | 3269 | |
bb70624e JA |
3270 | 1. Special builtins are found before shell functions during command |
3271 | lookup. | |
ccc6cda3 | 3272 | |
bb70624e JA |
3273 | 2. If a special builtin returns an error status, a non-interactive |
3274 | shell exits. | |
ccc6cda3 | 3275 | |
bb70624e JA |
3276 | 3. Assignment statements preceding the command stay in effect in the |
3277 | shell environment after the command completes. | |
ccc6cda3 | 3278 | |
bb70624e JA |
3279 | When Bash is not executing in POSIX mode, these builtins behave no |
3280 | differently than the rest of the Bash builtin commands. The Bash POSIX | |
3281 | mode is described in *Note Bash POSIX Mode::. | |
ccc6cda3 | 3282 | |
bb70624e JA |
3283 | These are the POSIX special builtins: |
3284 | break : . continue eval exec exit export readonly return set | |
3285 | shift trap unset | |
ccc6cda3 | 3286 | |
bb70624e JA |
3287 | \1f |
3288 | File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top | |
cce855bc | 3289 | |
bb70624e JA |
3290 | Shell Variables |
3291 | *************** | |
ccc6cda3 | 3292 | |
bb70624e | 3293 | * Menu: |
ccc6cda3 | 3294 | |
bb70624e JA |
3295 | * Bourne Shell Variables:: Variables which Bash uses in the same way |
3296 | as the Bourne Shell. | |
3297 | * Bash Variables:: List of variables that exist in Bash. | |
ccc6cda3 | 3298 | |
bb70624e JA |
3299 | This chapter describes the shell variables that Bash uses. Bash |
3300 | automatically assigns default values to a number of variables. | |
cce855bc | 3301 | |
bb70624e JA |
3302 | \1f |
3303 | File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables | |
ccc6cda3 | 3304 | |
bb70624e JA |
3305 | Bourne Shell Variables |
3306 | ====================== | |
cce855bc | 3307 | |
bb70624e JA |
3308 | Bash uses certain shell variables in the same way as the Bourne |
3309 | shell. In some cases, Bash assigns a default value to the variable. | |
cce855bc | 3310 | |
bb70624e JA |
3311 | `CDPATH' |
3312 | A colon-separated list of directories used as a search path for | |
3313 | the `cd' builtin command. | |
ccc6cda3 | 3314 | |
bb70624e JA |
3315 | `HOME' |
3316 | The current user's home directory; the default for the `cd' builtin | |
3317 | command. The value of this variable is also used by tilde | |
28ef6c31 | 3318 | expansion (*note Tilde Expansion::). |
ccc6cda3 | 3319 | |
bb70624e JA |
3320 | `IFS' |
3321 | A list of characters that separate fields; used when the shell | |
3322 | splits words as part of expansion. | |
ccc6cda3 | 3323 | |
bb70624e JA |
3324 | `MAIL' |
3325 | If this parameter is set to a filename and the `MAILPATH' variable | |
3326 | is not set, Bash informs the user of the arrival of mail in the | |
3327 | specified file. | |
cce855bc | 3328 | |
bb70624e JA |
3329 | `MAILPATH' |
3330 | A colon-separated list of filenames which the shell periodically | |
3331 | checks for new mail. Each list entry can specify the message that | |
3332 | is printed when new mail arrives in the mail file by separating | |
3333 | the file name from the message with a `?'. When used in the text | |
3334 | of the message, `$_' expands to the name of the current mail file. | |
cce855bc | 3335 | |
bb70624e JA |
3336 | `OPTARG' |
3337 | The value of the last option argument processed by the `getopts' | |
3338 | builtin. | |
ccc6cda3 | 3339 | |
bb70624e JA |
3340 | `OPTIND' |
3341 | The index of the last option argument processed by the `getopts' | |
3342 | builtin. | |
ccc6cda3 | 3343 | |
bb70624e JA |
3344 | `PATH' |
3345 | A colon-separated list of directories in which the shell looks for | |
3346 | commands. | |
ccc6cda3 | 3347 | |
bb70624e JA |
3348 | `PS1' |
3349 | The primary prompt string. The default value is `\s-\v\$ '. | |
3350 | *Note Printing a Prompt::, for the complete list of escape | |
3351 | sequences that are expanded before `PS1' is displayed. | |
ccc6cda3 | 3352 | |
bb70624e JA |
3353 | `PS2' |
3354 | The secondary prompt string. The default value is `> '. | |
ccc6cda3 | 3355 | |
bb70624e JA |
3356 | \1f |
3357 | File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables | |
ccc6cda3 | 3358 | |
bb70624e JA |
3359 | Bash Variables |
3360 | ============== | |
ccc6cda3 | 3361 | |
bb70624e JA |
3362 | These variables are set or used by Bash, but other shells do not |
3363 | normally treat them specially. | |
ccc6cda3 | 3364 | |
bb70624e JA |
3365 | A few variables used by Bash are described in different chapters: |
3366 | variables for controlling the job control facilities (*note Job Control | |
28ef6c31 | 3367 | Variables::). |
ccc6cda3 | 3368 | |
bb70624e JA |
3369 | `BASH' |
3370 | The full pathname used to execute the current instance of Bash. | |
ccc6cda3 | 3371 | |
bb70624e JA |
3372 | `BASH_ENV' |
3373 | If this variable is set when Bash is invoked to execute a shell | |
3374 | script, its value is expanded and used as the name of a startup | |
3375 | file to read before executing the script. *Note Bash Startup | |
3376 | Files::. | |
ccc6cda3 | 3377 | |
bb70624e JA |
3378 | `BASH_VERSION' |
3379 | The version number of the current instance of Bash. | |
ccc6cda3 | 3380 | |
bb70624e | 3381 | `BASH_VERSINFO' |
28ef6c31 | 3382 | A readonly array variable (*note Arrays::) whose members hold |
bb70624e JA |
3383 | version information for this instance of Bash. The values |
3384 | assigned to the array members are as follows: | |
ccc6cda3 | 3385 | |
bb70624e JA |
3386 | `BASH_VERSINFO[0]' |
3387 | The major version number (the RELEASE). | |
ccc6cda3 | 3388 | |
bb70624e JA |
3389 | `BASH_VERSINFO[1]' |
3390 | The minor version number (the VERSION). | |
ccc6cda3 | 3391 | |
bb70624e JA |
3392 | `BASH_VERSINFO[2]' |
3393 | The patch level. | |
ccc6cda3 | 3394 | |
bb70624e JA |
3395 | `BASH_VERSINFO[3]' |
3396 | The build version. | |
ccc6cda3 | 3397 | |
bb70624e JA |
3398 | `BASH_VERSINFO[4]' |
3399 | The release status (e.g., BETA1). | |
ccc6cda3 | 3400 | |
bb70624e JA |
3401 | `BASH_VERSINFO[5]' |
3402 | The value of `MACHTYPE'. | |
ccc6cda3 | 3403 | |
bb70624e JA |
3404 | `COMP_WORDS' |
3405 | An array variable consisting of the individual words in the | |
3406 | current command line. This variable is available only in shell | |
3407 | functions invoked by the programmable completion facilities (*note | |
28ef6c31 | 3408 | Programmable Completion::). |
bb70624e JA |
3409 | |
3410 | `COMP_CWORD' | |
3411 | An index into `${COMP_WORDS}' of the word containing the current | |
3412 | cursor position. This variable is available only in shell | |
3413 | functions invoked by the programmable completion facilities (*note | |
28ef6c31 | 3414 | Programmable Completion::). |
bb70624e JA |
3415 | |
3416 | `COMP_LINE' | |
3417 | The current command line. This variable is available only in | |
3418 | shell functions and external commands invoked by the programmable | |
28ef6c31 | 3419 | completion facilities (*note Programmable Completion::). |
bb70624e JA |
3420 | |
3421 | `COMP_POINT' | |
3422 | The index of the current cursor position relative to the beginning | |
3423 | of the current command. If the current cursor position is at the | |
3424 | end of the current command, the value of this variable is equal to | |
3425 | `${#COMP_LINE}'. This variable is available only in shell | |
3426 | functions and external commands invoked by the programmable | |
28ef6c31 | 3427 | completion facilities (*note Programmable Completion::). |
bb70624e JA |
3428 | |
3429 | `COMPREPLY' | |
3430 | An array variable from which Bash reads the possible completions | |
3431 | generated by a shell function invoked by the programmable | |
28ef6c31 | 3432 | completion facility (*note Programmable Completion::). |
ccc6cda3 | 3433 | |
bb70624e JA |
3434 | `DIRSTACK' |
3435 | An array variable containing the current contents of the directory | |
3436 | stack. Directories appear in the stack in the order they are | |
3437 | displayed by the `dirs' builtin. Assigning to members of this | |
3438 | array variable may be used to modify directories already in the | |
3439 | stack, but the `pushd' and `popd' builtins must be used to add and | |
3440 | remove directories. Assignment to this variable will not change | |
3441 | the current directory. If `DIRSTACK' is unset, it loses its | |
3442 | special properties, even if it is subsequently reset. | |
cce855bc | 3443 | |
bb70624e JA |
3444 | `EUID' |
3445 | The numeric effective user id of the current user. This variable | |
3446 | is readonly. | |
cce855bc | 3447 | |
bb70624e JA |
3448 | `FCEDIT' |
3449 | The editor used as a default by the `-e' option to the `fc' | |
3450 | builtin command. | |
ccc6cda3 | 3451 | |
bb70624e JA |
3452 | `FIGNORE' |
3453 | A colon-separated list of suffixes to ignore when performing | |
3454 | filename completion. A file name whose suffix matches one of the | |
3455 | entries in `FIGNORE' is excluded from the list of matched file | |
3456 | names. A sample value is `.o:~' | |
ccc6cda3 | 3457 | |
bb70624e JA |
3458 | `GLOBIGNORE' |
3459 | A colon-separated list of patterns defining the set of filenames to | |
3460 | be ignored by filename expansion. If a filename matched by a | |
3461 | filename expansion pattern also matches one of the patterns in | |
3462 | `GLOBIGNORE', it is removed from the list of matches. | |
ccc6cda3 | 3463 | |
bb70624e JA |
3464 | `GROUPS' |
3465 | An array variable containing the list of groups of which the | |
3466 | current user is a member. Assignments to `GROUPS' have no effect | |
28ef6c31 | 3467 | and return an error status. If `GROUPS' is unset, it loses its |
bb70624e | 3468 | special properties, even if it is subsequently reset. |
ccc6cda3 | 3469 | |
bb70624e JA |
3470 | `histchars' |
3471 | Up to three characters which control history expansion, quick | |
28ef6c31 JA |
3472 | substitution, and tokenization (*note History Interaction::). The |
3473 | first character is the HISTORY EXPANSION character, that is, the | |
3474 | character which signifies the start of a history expansion, | |
bb70624e JA |
3475 | normally `!'. The second character is the character which |
3476 | signifies `quick substitution' when seen as the first character on | |
3477 | a line, normally `^'. The optional third character is the | |
3478 | character which indicates that the remainder of the line is a | |
3479 | comment when found as the first character of a word, usually `#'. | |
3480 | The history comment character causes history substitution to be | |
3481 | skipped for the remaining words on the line. It does not | |
3482 | necessarily cause the shell parser to treat the rest of the line | |
3483 | as a comment. | |
cce855bc | 3484 | |
bb70624e JA |
3485 | `HISTCMD' |
3486 | The history number, or index in the history list, of the current | |
3487 | command. If `HISTCMD' is unset, it loses its special properties, | |
3488 | even if it is subsequently reset. | |
ccc6cda3 | 3489 | |
bb70624e JA |
3490 | `FUNCNAME' |
3491 | The name of any currently-executing shell function. This variable | |
3492 | exists only when a shell function is executing. Assignments to | |
28ef6c31 | 3493 | `FUNCNAME' have no effect and return an error status. If |
bb70624e JA |
3494 | `FUNCNAME' is unset, it loses its special properties, even if it |
3495 | is subsequently reset. | |
ccc6cda3 | 3496 | |
bb70624e JA |
3497 | `HISTCONTROL' |
3498 | A value of `ignorespace' means to not enter lines which begin with | |
3499 | a space or tab into the history list. A value of `ignoredups' | |
3500 | means to not enter lines which match the last entered line. A | |
3501 | value of `ignoreboth' combines the two options. Unset, or set to | |
3502 | any other value than those above, means to save all lines on the | |
3503 | history list. The second and subsequent lines of a multi-line | |
3504 | compound command are not tested, and are added to the history | |
3505 | regardless of the value of `HISTCONTROL'. | |
ccc6cda3 | 3506 | |
bb70624e JA |
3507 | `HISTIGNORE' |
3508 | A colon-separated list of patterns used to decide which command | |
3509 | lines should be saved on the history list. Each pattern is | |
3510 | anchored at the beginning of the line and must match the complete | |
3511 | line (no implicit `*' is appended). Each pattern is tested | |
3512 | against the line after the checks specified by `HISTCONTROL' are | |
3513 | applied. In addition to the normal shell pattern matching | |
3514 | characters, `&' matches the previous history line. `&' may be | |
3515 | escaped using a backslash; the backslash is removed before | |
3516 | attempting a match. The second and subsequent lines of a | |
3517 | multi-line compound command are not tested, and are added to the | |
3518 | history regardless of the value of `HISTIGNORE'. | |
cce855bc | 3519 | |
bb70624e JA |
3520 | `HISTIGNORE' subsumes the function of `HISTCONTROL'. A pattern of |
3521 | `&' is identical to `ignoredups', and a pattern of `[ ]*' is | |
3522 | identical to `ignorespace'. Combining these two patterns, | |
3523 | separating them with a colon, provides the functionality of | |
3524 | `ignoreboth'. | |
ccc6cda3 | 3525 | |
bb70624e JA |
3526 | `HISTFILE' |
3527 | The name of the file to which the command history is saved. The | |
3528 | default value is `~/.bash_history'. | |
ccc6cda3 | 3529 | |
bb70624e JA |
3530 | `HISTSIZE' |
3531 | The maximum number of commands to remember on the history list. | |
3532 | The default value is 500. | |
b72432fd | 3533 | |
bb70624e JA |
3534 | `HISTFILESIZE' |
3535 | The maximum number of lines contained in the history file. When | |
3536 | this variable is assigned a value, the history file is truncated, | |
3537 | if necessary, to contain no more than that number of lines. The | |
3538 | history file is also truncated to this size after writing it when | |
3539 | an interactive shell exits. The default value is 500. | |
ccc6cda3 | 3540 | |
bb70624e JA |
3541 | `HOSTFILE' |
3542 | Contains the name of a file in the same format as `/etc/hosts' that | |
3543 | should be read when the shell needs to complete a hostname. The | |
3544 | list of possible hostname completions may be changed while the | |
3545 | shell is running; the next time hostname completion is attempted | |
3546 | after the value is changed, Bash adds the contents of the new file | |
3547 | to the existing list. If `HOSTFILE' is set, but has no value, | |
3548 | Bash attempts to read `/etc/hosts' to obtain the list of possible | |
3549 | hostname completions. When `HOSTFILE' is unset, the hostname list | |
3550 | is cleared. | |
cce855bc | 3551 | |
bb70624e JA |
3552 | `HOSTNAME' |
3553 | The name of the current host. | |
cce855bc | 3554 | |
bb70624e JA |
3555 | `HOSTTYPE' |
3556 | A string describing the machine Bash is running on. | |
ccc6cda3 | 3557 | |
bb70624e JA |
3558 | `IGNOREEOF' |
3559 | Controls the action of the shell on receipt of an `EOF' character | |
3560 | as the sole input. If set, the value denotes the number of | |
3561 | consecutive `EOF' characters that can be read as the first | |
3562 | character on an input line before the shell will exit. If the | |
3563 | variable exists but does not have a numeric value (or has no | |
3564 | value) then the default is 10. If the variable does not exist, | |
3565 | then `EOF' signifies the end of input to the shell. This is only | |
3566 | in effect for interactive shells. | |
ccc6cda3 | 3567 | |
bb70624e JA |
3568 | `INPUTRC' |
3569 | The name of the Readline initialization file, overriding the | |
3570 | default of `~/.inputrc'. | |
ccc6cda3 | 3571 | |
bb70624e JA |
3572 | `LANG' |
3573 | Used to determine the locale category for any category not | |
3574 | specifically selected with a variable starting with `LC_'. | |
ccc6cda3 | 3575 | |
bb70624e JA |
3576 | `LC_ALL' |
3577 | This variable overrides the value of `LANG' and any other `LC_' | |
3578 | variable specifying a locale category. | |
cce855bc | 3579 | |
bb70624e JA |
3580 | `LC_COLLATE' |
3581 | This variable determines the collation order used when sorting the | |
3582 | results of filename expansion, and determines the behavior of | |
3583 | range expressions, equivalence classes, and collating sequences | |
3584 | within filename expansion and pattern matching (*note Filename | |
28ef6c31 | 3585 | Expansion::). |
ccc6cda3 | 3586 | |
bb70624e JA |
3587 | `LC_CTYPE' |
3588 | This variable determines the interpretation of characters and the | |
3589 | behavior of character classes within filename expansion and pattern | |
28ef6c31 | 3590 | matching (*note Filename Expansion::). |
ccc6cda3 | 3591 | |
bb70624e JA |
3592 | `LC_MESSAGES' |
3593 | This variable determines the locale used to translate double-quoted | |
28ef6c31 | 3594 | strings preceded by a `$' (*note Locale Translation::). |
ccc6cda3 | 3595 | |
bb70624e JA |
3596 | `LC_NUMERIC' |
3597 | This variable determines the locale category used for number | |
3598 | formatting. | |
ccc6cda3 | 3599 | |
28ef6c31 JA |
3600 | `LINES' |
3601 | Used by the `select' builtin command to determine the column length | |
3602 | for printing selection lists. Automatically set upon receipt of a | |
3603 | `SIGWINCH'. | |
3604 | ||
3605 | `COLUMNS' | |
3606 | Used by the `select' builtin command to determine the terminal | |
3607 | width when printing selection lists. Automatically set upon | |
3608 | receipt of a `SIGWINCH'. | |
3609 | ||
bb70624e JA |
3610 | `LINENO' |
3611 | The line number in the script or shell function currently | |
3612 | executing. | |
ccc6cda3 | 3613 | |
bb70624e JA |
3614 | `MACHTYPE' |
3615 | A string that fully describes the system type on which Bash is | |
3616 | executing, in the standard GNU CPU-COMPANY-SYSTEM format. | |
ccc6cda3 | 3617 | |
bb70624e JA |
3618 | `MAILCHECK' |
3619 | How often (in seconds) that the shell should check for mail in the | |
28ef6c31 JA |
3620 | files specified in the `MAILPATH' or `MAIL' variables. The |
3621 | default is 60 seconds. When it is time to check for mail, the | |
3622 | shell does so before displaying the primary prompt. If this | |
3623 | variable is unset, or set to a value that is not a number greater | |
3624 | than or equal to zero, the shell disables mail checking. | |
ccc6cda3 | 3625 | |
bb70624e JA |
3626 | `OLDPWD' |
3627 | The previous working directory as set by the `cd' builtin. | |
ccc6cda3 | 3628 | |
bb70624e JA |
3629 | `OPTERR' |
3630 | If set to the value 1, Bash displays error messages generated by | |
3631 | the `getopts' builtin command. | |
ccc6cda3 | 3632 | |
bb70624e JA |
3633 | `OSTYPE' |
3634 | A string describing the operating system Bash is running on. | |
ccc6cda3 | 3635 | |
bb70624e | 3636 | `PIPESTATUS' |
28ef6c31 | 3637 | An array variable (*note Arrays::) containing a list of exit |
bb70624e JA |
3638 | status values from the processes in the most-recently-executed |
3639 | foreground pipeline (which may contain only a single command). | |
ccc6cda3 | 3640 | |
bb70624e JA |
3641 | `PPID' |
3642 | The process ID of the shell's parent process. This variable is | |
3643 | readonly. | |
ccc6cda3 | 3644 | |
bb70624e JA |
3645 | `PROMPT_COMMAND' |
3646 | If set, the value is interpreted as a command to execute before | |
3647 | the printing of each primary prompt (`$PS1'). | |
ccc6cda3 | 3648 | |
bb70624e JA |
3649 | `PS3' |
3650 | The value of this variable is used as the prompt for the `select' | |
3651 | command. If this variable is not set, the `select' command | |
3652 | prompts with `#? ' | |
ccc6cda3 | 3653 | |
bb70624e JA |
3654 | `PS4' |
3655 | The value is the prompt printed before the command line is echoed | |
28ef6c31 | 3656 | when the `-x' option is set (*note The Set Builtin::). The first |
bb70624e JA |
3657 | character of `PS4' is replicated multiple times, as necessary, to |
3658 | indicate multiple levels of indirection. The default is `+ '. | |
ccc6cda3 | 3659 | |
bb70624e JA |
3660 | `PWD' |
3661 | The current working directory as set by the `cd' builtin. | |
ccc6cda3 | 3662 | |
bb70624e JA |
3663 | `RANDOM' |
3664 | Each time this parameter is referenced, a random integer between 0 | |
3665 | and 32767 is generated. Assigning a value to this variable seeds | |
3666 | the random number generator. | |
cce855bc | 3667 | |
bb70624e JA |
3668 | `REPLY' |
3669 | The default variable for the `read' builtin. | |
ccc6cda3 | 3670 | |
bb70624e JA |
3671 | `SECONDS' |
3672 | This variable expands to the number of seconds since the shell was | |
3673 | started. Assignment to this variable resets the count to the | |
3674 | value assigned, and the expanded value becomes the value assigned | |
3675 | plus the number of seconds since the assignment. | |
ccc6cda3 | 3676 | |
bb70624e JA |
3677 | `SHELLOPTS' |
3678 | A colon-separated list of enabled shell options. Each word in the | |
3679 | list is a valid argument for the `-o' option to the `set' builtin | |
28ef6c31 | 3680 | command (*note The Set Builtin::). The options appearing in |
bb70624e JA |
3681 | `SHELLOPTS' are those reported as `on' by `set -o'. If this |
3682 | variable is in the environment when Bash starts up, each shell | |
3683 | option in the list will be enabled before reading any startup | |
3684 | files. This variable is readonly. | |
ccc6cda3 | 3685 | |
bb70624e JA |
3686 | `SHLVL' |
3687 | Incremented by one each time a new instance of Bash is started. | |
3688 | This is intended to be a count of how deeply your Bash shells are | |
3689 | nested. | |
cce855bc | 3690 | |
bb70624e JA |
3691 | `TIMEFORMAT' |
3692 | The value of this parameter is used as a format string specifying | |
3693 | how the timing information for pipelines prefixed with the `time' | |
3694 | reserved word should be displayed. The `%' character introduces an | |
3695 | escape sequence that is expanded to a time value or other | |
3696 | information. The escape sequences and their meanings are as | |
3697 | follows; the braces denote optional portions. | |
cce855bc | 3698 | |
bb70624e JA |
3699 | `%%' |
3700 | A literal `%'. | |
ccc6cda3 | 3701 | |
bb70624e JA |
3702 | `%[P][l]R' |
3703 | The elapsed time in seconds. | |
ccc6cda3 | 3704 | |
bb70624e JA |
3705 | `%[P][l]U' |
3706 | The number of CPU seconds spent in user mode. | |
ccc6cda3 | 3707 | |
bb70624e JA |
3708 | `%[P][l]S' |
3709 | The number of CPU seconds spent in system mode. | |
ccc6cda3 | 3710 | |
bb70624e JA |
3711 | `%P' |
3712 | The CPU percentage, computed as (%U + %S) / %R. | |
ccc6cda3 | 3713 | |
bb70624e JA |
3714 | The optional P is a digit specifying the precision, the number of |
3715 | fractional digits after a decimal point. A value of 0 causes no | |
3716 | decimal point or fraction to be output. At most three places | |
3717 | after the decimal point may be specified; values of P greater than | |
3718 | 3 are changed to 3. If P is not specified, the value 3 is used. | |
ccc6cda3 | 3719 | |
bb70624e JA |
3720 | The optional `l' specifies a longer format, including minutes, of |
3721 | the form MMmSS.FFs. The value of P determines whether or not the | |
3722 | fraction is included. | |
ccc6cda3 | 3723 | |
bb70624e JA |
3724 | If this variable is not set, Bash acts as if it had the value |
3725 | `$'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'' | |
3726 | If the value is null, no timing information is displayed. A | |
3727 | trailing newline is added when the format string is displayed. | |
ccc6cda3 | 3728 | |
bb70624e JA |
3729 | `TMOUT' |
3730 | If set to a value greater than zero, the value is interpreted as | |
3731 | the number of seconds to wait for input after issuing the primary | |
3732 | prompt when the shell is interactive. Bash terminates after that | |
3733 | number of seconds if input does not arrive. | |
ccc6cda3 | 3734 | |
bb70624e JA |
3735 | `UID' |
3736 | The numeric real user id of the current user. This variable is | |
3737 | readonly. | |
ccc6cda3 | 3738 | |
bb70624e JA |
3739 | \1f |
3740 | File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top | |
ccc6cda3 | 3741 | |
bb70624e JA |
3742 | Bash Features |
3743 | ************* | |
ccc6cda3 | 3744 | |
bb70624e | 3745 | This section describes features unique to Bash. |
ccc6cda3 | 3746 | |
bb70624e | 3747 | * Menu: |
ccc6cda3 | 3748 | |
bb70624e JA |
3749 | * Invoking Bash:: Command line options that you can give |
3750 | to Bash. | |
3751 | * Bash Startup Files:: When and how Bash executes scripts. | |
3752 | * Interactive Shells:: What an interactive shell is. | |
3753 | * Bash Conditional Expressions:: Primitives used in composing expressions for | |
3754 | the `test' builtin. | |
3755 | * Shell Arithmetic:: Arithmetic on shell variables. | |
3756 | * Aliases:: Substituting one command for another. | |
3757 | * Arrays:: Array Variables. | |
3758 | * The Directory Stack:: History of visited directories. | |
3759 | * Printing a Prompt:: Controlling the PS1 string. | |
3760 | * The Restricted Shell:: A more controlled mode of shell execution. | |
3761 | * Bash POSIX Mode:: Making Bash behave more closely to what | |
3762 | the POSIX standard specifies. | |
ccc6cda3 | 3763 | |
bb70624e JA |
3764 | \1f |
3765 | File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features | |
ccc6cda3 | 3766 | |
bb70624e JA |
3767 | Invoking Bash |
3768 | ============= | |
ccc6cda3 | 3769 | |
bb70624e JA |
3770 | bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...] |
3771 | bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] -c STRING [ARGUMENT ...] | |
3772 | bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [ARGUMENT ...] | |
ccc6cda3 | 3773 | |
bb70624e | 3774 | In addition to the single-character shell command-line options |
28ef6c31 | 3775 | (*note The Set Builtin::), there are several multi-character options |
bb70624e JA |
3776 | that you can use. These options must appear on the command line before |
3777 | the single-character options in order for them to be recognized. | |
ccc6cda3 | 3778 | |
bb70624e JA |
3779 | `--dump-po-strings' |
3780 | A list of all double-quoted strings preceded by `$' is printed on | |
3781 | the standard ouput in the GNU `gettext' PO (portable object) file | |
3782 | format. Equivalent to `-D' except for the output format. | |
ccc6cda3 | 3783 | |
bb70624e JA |
3784 | `--dump-strings' |
3785 | Equivalent to `-D'. | |
ccc6cda3 | 3786 | |
bb70624e JA |
3787 | `--help' |
3788 | Display a usage message on standard output and exit sucessfully. | |
ccc6cda3 | 3789 | |
28ef6c31 JA |
3790 | `--init-file FILENAME' |
3791 | `--rcfile FILENAME' | |
3792 | Execute commands from FILENAME (instead of `~/.bashrc') in an | |
3793 | interactive shell. | |
3794 | ||
bb70624e | 3795 | `--login' |
28ef6c31 JA |
3796 | Make this shell act as if it had been directly invoked by login. |
3797 | When the shell is interactive, this is equivalent to starting a | |
3798 | login shell with `exec -l bash'. When the shell is not | |
3799 | interactive, the login shell startup files will be executed. | |
3800 | `exec bash --login' will replace the current shell with a Bash | |
3801 | login shell. *Note Bash Startup Files::, for a description of the | |
3802 | special behavior of a login shell. | |
ccc6cda3 | 3803 | |
bb70624e | 3804 | `--noediting' |
28ef6c31 | 3805 | Do not use the GNU Readline library (*note Command Line Editing::) |
bb70624e | 3806 | to read command lines when the shell is interactive. |
ccc6cda3 | 3807 | |
bb70624e JA |
3808 | `--noprofile' |
3809 | Don't load the system-wide startup file `/etc/profile' or any of | |
3810 | the personal initialization files `~/.bash_profile', | |
3811 | `~/.bash_login', or `~/.profile' when Bash is invoked as a login | |
3812 | shell. | |
ccc6cda3 | 3813 | |
bb70624e JA |
3814 | `--norc' |
3815 | Don't read the `~/.bashrc' initialization file in an interactive | |
3816 | shell. This is on by default if the shell is invoked as `sh'. | |
ccc6cda3 | 3817 | |
bb70624e JA |
3818 | `--posix' |
3819 | Change the behavior of Bash where the default operation differs | |
3820 | from the POSIX 1003.2 standard to match the standard. This is | |
3821 | intended to make Bash behave as a strict superset of that | |
3822 | standard. *Note Bash POSIX Mode::, for a description of the Bash | |
3823 | POSIX mode. | |
ccc6cda3 | 3824 | |
bb70624e | 3825 | `--restricted' |
28ef6c31 | 3826 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 3827 | |
bb70624e JA |
3828 | `--verbose' |
3829 | Equivalent to `-v'. Print shell input lines as they're read. | |
ccc6cda3 | 3830 | |
bb70624e JA |
3831 | `--version' |
3832 | Show version information for this instance of Bash on the standard | |
3833 | output and exit successfully. | |
ccc6cda3 | 3834 | |
bb70624e JA |
3835 | There are several single-character options that may be supplied at |
3836 | invocation which are not available with the `set' builtin. | |
ccc6cda3 | 3837 | |
bb70624e JA |
3838 | `-c STRING' |
3839 | Read and execute commands from STRING after processing the | |
3840 | options, then exit. Any remaining arguments are assigned to the | |
3841 | positional parameters, starting with `$0'. | |
ccc6cda3 | 3842 | |
bb70624e JA |
3843 | `-i' |
3844 | Force the shell to run interactively. Interactive shells are | |
3845 | described in *Note Interactive Shells::. | |
ccc6cda3 | 3846 | |
bb70624e | 3847 | `-r' |
28ef6c31 | 3848 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 3849 | |
bb70624e JA |
3850 | `-s' |
3851 | If this option is present, or if no arguments remain after option | |
3852 | processing, then commands are read from the standard input. This | |
3853 | option allows the positional parameters to be set when invoking an | |
3854 | interactive shell. | |
ccc6cda3 | 3855 | |
bb70624e JA |
3856 | `-D' |
3857 | A list of all double-quoted strings preceded by `$' is printed on | |
3858 | the standard ouput. These are the strings that are subject to | |
3859 | language translation when the current locale is not `C' or `POSIX' | |
28ef6c31 | 3860 | (*note Locale Translation::). This implies the `-n' option; no |
bb70624e | 3861 | commands will be executed. |
ccc6cda3 | 3862 | |
bb70624e JA |
3863 | `--' |
3864 | A `--' signals the end of options and disables further option | |
3865 | processing. Any arguments after the `--' are treated as filenames | |
3866 | and arguments. | |
ccc6cda3 | 3867 | |
28ef6c31 | 3868 | An _interactive_ shell is one started without non-option arguments, |
bb70624e JA |
3869 | unless `-s' is specified, without specifying the `-c' option, and whose |
3870 | input and output are both connected to terminals (as determined by | |
3871 | `isatty(3)'), or one started with the `-i' option. *Note Interactive | |
28ef6c31 | 3872 | Shells::, for more information. |
ccc6cda3 | 3873 | |
bb70624e JA |
3874 | If arguments remain after option processing, and neither the `-c' |
3875 | nor the `-s' option has been supplied, the first argument is assumed to | |
28ef6c31 JA |
3876 | be the name of a file containing shell commands (*note Shell Scripts::). |
3877 | When Bash is invoked in this fashion, `$0' is set to the name of the | |
3878 | file, and the positional parameters are set to the remaining arguments. | |
3879 | Bash reads and executes commands from this file, then exits. Bash's | |
3880 | exit status is the exit status of the last command executed in the | |
3881 | script. If no commands are executed, the exit status is 0. | |
ccc6cda3 | 3882 | |
bb70624e JA |
3883 | \1f |
3884 | File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features | |
ccc6cda3 | 3885 | |
bb70624e JA |
3886 | Bash Startup Files |
3887 | ================== | |
ccc6cda3 | 3888 | |
bb70624e JA |
3889 | This section describs how Bash executes its startup files. If any |
3890 | of the files exist but cannot be read, Bash reports an error. Tildes | |
3891 | are expanded in file names as described above under Tilde Expansion | |
28ef6c31 | 3892 | (*note Tilde Expansion::). |
ccc6cda3 | 3893 | |
bb70624e | 3894 | Interactive shells are described in *Note Interactive Shells::. |
ccc6cda3 | 3895 | |
bb70624e JA |
3896 | Invoked as an interactive login shell, or with `--login' |
3897 | ........................................................ | |
cce855bc | 3898 | |
bb70624e JA |
3899 | When Bash is invoked as an interactive login shell, or as a |
3900 | non-interactive shell with the `--login' option, it first reads and | |
3901 | executes commands from the file `/etc/profile', if that file exists. | |
3902 | After reading that file, it looks for `~/.bash_profile', | |
3903 | `~/.bash_login', and `~/.profile', in that order, and reads and | |
3904 | executes commands from the first one that exists and is readable. The | |
3905 | `--noprofile' option may be used when the shell is started to inhibit | |
3906 | this behavior. | |
ccc6cda3 | 3907 | |
bb70624e JA |
3908 | When a login shell exits, Bash reads and executes commands from the |
3909 | file `~/.bash_logout', if it exists. | |
ccc6cda3 | 3910 | |
bb70624e JA |
3911 | Invoked as an interactive non-login shell |
3912 | ......................................... | |
ccc6cda3 | 3913 | |
bb70624e JA |
3914 | When an interactive shell that is not a login shell is started, Bash |
3915 | reads and executes commands from `~/.bashrc', if that file exists. | |
3916 | This may be inhibited by using the `--norc' option. The `--rcfile | |
3917 | FILE' option will force Bash to read and execute commands from FILE | |
3918 | instead of `~/.bashrc'. | |
ccc6cda3 | 3919 | |
bb70624e JA |
3920 | So, typically, your `~/.bash_profile' contains the line |
3921 | `if [ -f ~/.bashrc ]; then . ~/.bashrc; fi' | |
cce855bc | 3922 | |
bb70624e | 3923 | after (or before) any login-specific initializations. |
ccc6cda3 | 3924 | |
bb70624e JA |
3925 | Invoked non-interactively |
3926 | ......................... | |
ccc6cda3 | 3927 | |
bb70624e JA |
3928 | When Bash is started non-interactively, to run a shell script, for |
3929 | example, it looks for the variable `BASH_ENV' in the environment, | |
3930 | expands its value if it appears there, and uses the expanded value as | |
3931 | the name of a file to read and execute. Bash behaves as if the | |
3932 | following command were executed: | |
3933 | `if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi' | |
ccc6cda3 | 3934 | |
bb70624e JA |
3935 | but the value of the `PATH' variable is not used to search for the file |
3936 | name. | |
ccc6cda3 | 3937 | |
28ef6c31 JA |
3938 | As noted above, if a non-interactive shell is invoked with the |
3939 | `--login' option, Bash attempts to read and execute commands from the | |
3940 | login shell startup files. | |
3941 | ||
bb70624e JA |
3942 | Invoked with name `sh' |
3943 | ...................... | |
ccc6cda3 | 3944 | |
bb70624e JA |
3945 | If Bash is invoked with the name `sh', it tries to mimic the startup |
3946 | behavior of historical versions of `sh' as closely as possible, while | |
3947 | conforming to the POSIX standard as well. | |
ccc6cda3 | 3948 | |
bb70624e JA |
3949 | When invoked as an interactive login shell, or as a non-interactive |
3950 | shell with the `--login' option, it first attempts to read and execute | |
3951 | commands from `/etc/profile' and `~/.profile', in that order. The | |
3952 | `--noprofile' option may be used to inhibit this behavior. When | |
3953 | invoked as an interactive shell with the name `sh', Bash looks for the | |
3954 | variable `ENV', expands its value if it is defined, and uses the | |
3955 | expanded value as the name of a file to read and execute. Since a | |
3956 | shell invoked as `sh' does not attempt to read and execute commands | |
3957 | from any other startup files, the `--rcfile' option has no effect. A | |
3958 | non-interactive shell invoked with the name `sh' does not attempt to | |
3959 | read any other startup files. | |
ccc6cda3 | 3960 | |
bb70624e JA |
3961 | When invoked as `sh', Bash enters POSIX mode after the startup files |
3962 | are read. | |
b72432fd | 3963 | |
bb70624e JA |
3964 | Invoked in POSIX mode |
3965 | ..................... | |
ccc6cda3 | 3966 | |
bb70624e JA |
3967 | When Bash is started in POSIX mode, as with the `--posix' command |
3968 | line option, it follows the POSIX standard for startup files. In this | |
3969 | mode, interactive shells expand the `ENV' variable and commands are | |
3970 | read and executed from the file whose name is the expanded value. No | |
3971 | other startup files are read. | |
ccc6cda3 | 3972 | |
bb70624e JA |
3973 | Invoked by remote shell daemon |
3974 | .............................. | |
ccc6cda3 | 3975 | |
bb70624e JA |
3976 | Bash attempts to determine when it is being run by the remote shell |
3977 | daemon, usually `rshd'. If Bash determines it is being run by rshd, it | |
3978 | reads and executes commands from `~/.bashrc', if that file exists and | |
3979 | is readable. It will not do this if invoked as `sh'. The `--norc' | |
3980 | option may be used to inhibit this behavior, and the `--rcfile' option | |
3981 | may be used to force another file to be read, but `rshd' does not | |
3982 | generally invoke the shell with those options or allow them to be | |
3983 | specified. | |
ccc6cda3 | 3984 | |
bb70624e JA |
3985 | Invoked with unequal effective and real UID/GIDs |
3986 | ................................................ | |
3987 | ||
3988 | If Bash is started with the effective user (group) id not equal to | |
3989 | the real user (group) id, and the `-p' option is not supplied, no | |
3990 | startup files are read, shell functions are not inherited from the | |
3991 | environment, the `SHELLOPTS' variable, if it appears in the | |
3992 | environment, is ignored, and the effective user id is set to the real | |
3993 | user id. If the `-p' option is supplied at invocation, the startup | |
3994 | behavior is the same, but the effective user id is not reset. | |
3995 | ||
3996 | \1f | |
3997 | File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features | |
3998 | ||
3999 | Interactive Shells | |
4000 | ================== | |
4001 | ||
4002 | * Menu: | |
4003 | ||
4004 | * What is an Interactive Shell?:: What determines whether a shell is Interactive. | |
4005 | * Is this Shell Interactive?:: How to tell if a shell is interactive. | |
4006 | * Interactive Shell Behavior:: What changes in a interactive shell? | |
4007 | ||
4008 | \1f | |
4009 | File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells | |
4010 | ||
4011 | What is an Interactive Shell? | |
4012 | ----------------------------- | |
4013 | ||
4014 | An interactive shell is one started without non-option arguments, | |
4015 | unless `-s' is specified, without specifiying the `-c' option, and | |
4016 | whose input and output are both connected to terminals (as determined | |
4017 | by `isatty(3)'), or one started with the `-i' option. | |
4018 | ||
4019 | An interactive shell generally reads from and writes to a user's | |
4020 | terminal. | |
4021 | ||
4022 | The `-s' invocation option may be used to set the positional | |
4023 | parameters when an interactive shell is started. | |
4024 | ||
4025 | \1f | |
4026 | File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells | |
4027 | ||
4028 | Is this Shell Interactive? | |
4029 | -------------------------- | |
4030 | ||
4031 | To determine within a startup script whether or not Bash is running | |
4032 | interactively, test the value of the `-' special parameter. It | |
4033 | contains `i' when the shell is interactive. For example: | |
4034 | ||
4035 | case "$-" in | |
4036 | *i*) echo This shell is interactive ;; | |
4037 | *) echo This shell is not interactive ;; | |
4038 | esac | |
4039 | ||
28ef6c31 JA |
4040 | Alternatively, startup scripts may examine the variable `PS1'; it is |
4041 | unset in non-interactive shells, and set in interactive shells. Thus: | |
bb70624e JA |
4042 | |
4043 | if [ -z "$PS1" ]; then | |
4044 | echo This shell is not interactive | |
4045 | else | |
4046 | echo This shell is interactive | |
4047 | fi | |
4048 | ||
4049 | \1f | |
4050 | File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells | |
4051 | ||
4052 | Interactive Shell Behavior | |
4053 | -------------------------- | |
4054 | ||
4055 | When the shell is running interactively, it changes its behavior in | |
4056 | several ways. | |
4057 | ||
4058 | 1. Startup files are read and executed as described in *Note Bash | |
4059 | Startup Files::. | |
4060 | ||
28ef6c31 | 4061 | 2. Job Control (*note Job Control::) is enabled by default. When job |
bb70624e JA |
4062 | control is in effect, Bash ignores the keyboard-generated job |
4063 | control signals `SIGTTIN', `SIGTTOU', and `SIGTSTP'. | |
4064 | ||
28ef6c31 JA |
4065 | 3. Bash expands and displays `PS1' before reading the first line of a |
4066 | command, and expands and displays `PS2' before reading the second | |
4067 | and subsequent lines of a multi-line command. | |
bb70624e JA |
4068 | |
4069 | 4. Bash executes the value of the `PROMPT_COMMAND' variable as a | |
4070 | command before printing the primary prompt, `$PS1' (*note Bash | |
28ef6c31 | 4071 | Variables::). |
bb70624e | 4072 | |
28ef6c31 | 4073 | 5. Readline (*note Command Line Editing::) is used to read commands |
bb70624e JA |
4074 | from the user's terminal. |
4075 | ||
4076 | 6. Bash inspects the value of the `ignoreeof' option to `set -o' | |
4077 | instead of exiting immediately when it receives an `EOF' on its | |
28ef6c31 | 4078 | standard input when reading a command (*note The Set Builtin::). |
bb70624e | 4079 | |
28ef6c31 JA |
4080 | 7. Command history (*note Bash History Facilities::) and history |
4081 | expansion (*note History Interaction::) are enabled by default. | |
bb70624e JA |
4082 | Bash will save the command history to the file named by `$HISTFILE' |
4083 | when an interactive shell exits. | |
4084 | ||
28ef6c31 | 4085 | 8. Alias expansion (*note Aliases::) is performed by default. |
bb70624e JA |
4086 | |
4087 | 9. In the absence of any traps, Bash ignores `SIGTERM' (*note | |
28ef6c31 | 4088 | Signals::). |
bb70624e JA |
4089 | |
4090 | 10. In the absence of any traps, `SIGINT' is caught and handled | |
28ef6c31 | 4091 | ((*note Signals::). `SIGINT' will interrupt some shell builtins. |
bb70624e JA |
4092 | |
4093 | 11. An interactive login shell sends a `SIGHUP' to all jobs on exit if | |
28ef6c31 | 4094 | the `hupoxexit' shell option has been enabled (*note Signals::). |
bb70624e JA |
4095 | |
4096 | 12. The `-n' invocation option is ignored, and `set -n' has no effect | |
28ef6c31 | 4097 | (*note The Set Builtin::). |
bb70624e JA |
4098 | |
4099 | 13. Bash will check for mail periodically, depending on the values of | |
4100 | the `MAIL', `MAILPATH', and `MAILCHECK' shell variables (*note | |
28ef6c31 | 4101 | Bash Variables::). |
bb70624e JA |
4102 | |
4103 | 14. Expansion errors due to references to unbound shell variables after | |
4104 | `set -u' has been enabled will not cause the shell to exit (*note | |
28ef6c31 | 4105 | The Set Builtin::). |
bb70624e JA |
4106 | |
4107 | 15. The shell will not exit on expansion errors caused by VAR being | |
4108 | unset or null in `${VAR:?WORD}' expansions (*note Shell Parameter | |
28ef6c31 | 4109 | Expansion::). |
bb70624e JA |
4110 | |
4111 | 16. Redirection errors encountered by shell builtins will not cause the | |
4112 | shell to exit. | |
4113 | ||
4114 | 17. When running in POSIX mode, a special builtin returning an error | |
28ef6c31 | 4115 | status will not cause the shell to exit (*note Bash POSIX Mode::). |
bb70624e JA |
4116 | |
4117 | 18. A failed `exec' will not cause the shell to exit (*note Bourne | |
28ef6c31 | 4118 | Shell Builtins::). |
bb70624e JA |
4119 | |
4120 | 19. Parser syntax errors will not cause the shell to exit. | |
4121 | ||
4122 | 20. Simple spelling correction for directory arguments to the `cd' | |
4123 | builtin is enabled by default (see the description of the `cdspell' | |
4124 | option to the `shopt' builtin in *Note Bash Builtins::). | |
4125 | ||
4126 | 21. The shell will check the value of the `TMOUT' variable and exit if | |
4127 | a command is not read within the specified number of seconds after | |
28ef6c31 | 4128 | printing `$PS1' (*note Bash Variables::). |
bb70624e JA |
4129 | |
4130 | ||
4131 | \1f | |
4132 | File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features | |
4133 | ||
4134 | Bash Conditional Expressions | |
4135 | ============================ | |
4136 | ||
4137 | Conditional expressions are used by the `[[' compound command and | |
4138 | the `test' and `[' builtin commands. | |
4139 | ||
4140 | Expressions may be unary or binary. Unary expressions are often | |
4141 | used to examine the status of a file. There are string operators and | |
4142 | numeric comparison operators as well. If the FILE argument to one of | |
4143 | the primaries is of the form `/dev/fd/N', then file descriptor N is | |
4144 | checked. If the FILE argument to one of the primaries is one of | |
4145 | `/dev/stdin', `/dev/stdout', or `/dev/stderr', file descriptor 0, 1, or | |
4146 | 2, respectively, is checked. | |
4147 | ||
4148 | `-a FILE' | |
4149 | True if FILE exists. | |
4150 | ||
4151 | `-b FILE' | |
4152 | True if FILE exists and is a block special file. | |
4153 | ||
4154 | `-c FILE' | |
4155 | True if FILE exists and is a character special file. | |
4156 | ||
4157 | `-d FILE' | |
4158 | True if FILE exists and is a directory. | |
4159 | ||
4160 | `-e FILE' | |
4161 | True if FILE exists. | |
4162 | ||
4163 | `-f FILE' | |
4164 | True if FILE exists and is a regular file. | |
4165 | ||
4166 | `-g FILE' | |
4167 | True if FILE exists and its set-group-id bit is set. | |
4168 | ||
4169 | `-h FILE' | |
4170 | True if FILE exists and is a symbolic link. | |
4171 | ||
4172 | `-k FILE' | |
4173 | True if FILE exists and its "sticky" bit is set. | |
4174 | ||
4175 | `-p FILE' | |
4176 | True if FILE exists and is a named pipe (FIFO). | |
4177 | ||
4178 | `-r FILE' | |
4179 | True if FILE exists and is readable. | |
4180 | ||
4181 | `-s FILE' | |
4182 | True if FILE exists and has a size greater than zero. | |
4183 | ||
4184 | `-t FD' | |
4185 | True if file descriptor FD is open and refers to a terminal. | |
ccc6cda3 JA |
4186 | |
4187 | `-u FILE' | |
4188 | True if FILE exists and its set-user-id bit is set. | |
4189 | ||
4190 | `-w FILE' | |
4191 | True if FILE exists and is writable. | |
4192 | ||
4193 | `-x FILE' | |
4194 | True if FILE exists and is executable. | |
4195 | ||
4196 | `-O FILE' | |
4197 | True if FILE exists and is owned by the effective user id. | |
4198 | ||
4199 | `-G FILE' | |
4200 | True if FILE exists and is owned by the effective group id. | |
4201 | ||
cce855bc JA |
4202 | `-L FILE' |
4203 | True if FILE exists and is a symbolic link. | |
4204 | ||
4205 | `-S FILE' | |
4206 | True if FILE exists and is a socket. | |
4207 | ||
4208 | `-N FILE' | |
4209 | True if FILE exists and has been modified since it was last read. | |
4210 | ||
ccc6cda3 JA |
4211 | `FILE1 -nt FILE2' |
4212 | True if FILE1 is newer (according to modification date) than FILE2. | |
4213 | ||
4214 | `FILE1 -ot FILE2' | |
4215 | True if FILE1 is older than FILE2. | |
4216 | ||
4217 | `FILE1 -ef FILE2' | |
4218 | True if FILE1 and FILE2 have the same device and inode numbers. | |
4219 | ||
4220 | `-o OPTNAME' | |
4221 | True if shell option OPTNAME is enabled. The list of options | |
4222 | appears in the description of the `-o' option to the `set' builtin | |
28ef6c31 | 4223 | (*note The Set Builtin::). |
ccc6cda3 JA |
4224 | |
4225 | `-z STRING' | |
4226 | True if the length of STRING is zero. | |
4227 | ||
4228 | `-n STRING' | |
4229 | `STRING' | |
4230 | True if the length of STRING is non-zero. | |
4231 | ||
cce855bc JA |
4232 | `STRING1 == STRING2' |
4233 | True if the strings are equal. `=' may be used in place of `=='. | |
ccc6cda3 JA |
4234 | |
4235 | `STRING1 != STRING2' | |
4236 | True if the strings are not equal. | |
4237 | ||
4238 | `STRING1 < STRING2' | |
cce855bc JA |
4239 | True if STRING1 sorts before STRING2 lexicographically in the |
4240 | current locale. | |
ccc6cda3 JA |
4241 | |
4242 | `STRING1 > STRING2' | |
cce855bc JA |
4243 | True if STRING1 sorts after STRING2 lexicographically in the |
4244 | current locale. | |
ccc6cda3 JA |
4245 | |
4246 | `ARG1 OP ARG2' | |
4247 | `OP' is one of `-eq', `-ne', `-lt', `-le', `-gt', or `-ge'. These | |
4248 | arithmetic binary operators return true if ARG1 is equal to, not | |
4249 | equal to, less than, less than or equal to, greater than, or | |
4250 | greater than or equal to ARG2, respectively. ARG1 and ARG2 may be | |
4251 | positive or negative integers. | |
4252 | ||
ccc6cda3 | 4253 | \1f |
bb70624e | 4254 | File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features |
ccc6cda3 | 4255 | |
bb70624e JA |
4256 | Shell Arithmetic |
4257 | ================ | |
ccc6cda3 | 4258 | |
bb70624e JA |
4259 | The shell allows arithmetic expressions to be evaluated, as one of |
4260 | the shell expansions or by the `let' builtin. | |
ccc6cda3 | 4261 | |
bb70624e JA |
4262 | Evaluation is done in long integers with no check for overflow, |
4263 | though division by 0 is trapped and flagged as an error. The operators | |
4264 | and their precedence and associativity are the same as in the C | |
4265 | language. The following list of operators is grouped into levels of | |
4266 | equal-precedence operators. The levels are listed in order of | |
4267 | decreasing precedence. | |
cce855bc | 4268 | |
bb70624e JA |
4269 | `ID++ ID--' |
4270 | variable post-increment and post-decrement | |
d166f048 | 4271 | |
bb70624e JA |
4272 | `++ID --ID' |
4273 | variable pre-increment and pre-decrement | |
ccc6cda3 | 4274 | |
bb70624e JA |
4275 | `- +' |
4276 | unary minus and plus | |
ccc6cda3 | 4277 | |
bb70624e JA |
4278 | `! ~' |
4279 | logical and bitwise negation | |
ccc6cda3 | 4280 | |
bb70624e JA |
4281 | `**' |
4282 | exponentiation | |
ccc6cda3 | 4283 | |
bb70624e JA |
4284 | `* / %' |
4285 | multiplication, division, remainder | |
ccc6cda3 | 4286 | |
bb70624e JA |
4287 | `+ -' |
4288 | addition, subtraction | |
ccc6cda3 | 4289 | |
bb70624e JA |
4290 | `<< >>' |
4291 | left and right bitwise shifts | |
cce855bc | 4292 | |
bb70624e JA |
4293 | `<= >= < >' |
4294 | comparison | |
cce855bc | 4295 | |
bb70624e JA |
4296 | `== !=' |
4297 | equality and inequality | |
cce855bc | 4298 | |
bb70624e JA |
4299 | `&' |
4300 | bitwise AND | |
cce855bc | 4301 | |
bb70624e JA |
4302 | `^' |
4303 | bitwise exclusive OR | |
cce855bc | 4304 | |
bb70624e JA |
4305 | `|' |
4306 | bitwise OR | |
cce855bc | 4307 | |
bb70624e JA |
4308 | `&&' |
4309 | logical AND | |
ccc6cda3 | 4310 | |
bb70624e JA |
4311 | `||' |
4312 | logical OR | |
ccc6cda3 | 4313 | |
bb70624e JA |
4314 | `expr ? expr : expr' |
4315 | conditional evaluation | |
cce855bc | 4316 | |
bb70624e JA |
4317 | `= *= /= %= += -= <<= >>= &= ^= |=' |
4318 | assignment | |
ccc6cda3 | 4319 | |
bb70624e JA |
4320 | `expr1 , expr2' |
4321 | comma | |
ccc6cda3 | 4322 | |
bb70624e JA |
4323 | Shell variables are allowed as operands; parameter expansion is |
4324 | performed before the expression is evaluated. Within an expression, | |
4325 | shell variables may also be referenced by name without using the | |
4326 | parameter expansion syntax. The value of a variable is evaluated as an | |
4327 | arithmetic expression when it is referenced. A shell variable need not | |
4328 | have its integer attribute turned on to be used in an expression. | |
ccc6cda3 | 4329 | |
bb70624e JA |
4330 | Constants with a leading 0 are interpreted as octal numbers. A |
4331 | leading `0x' or `0X' denotes hexadecimal. Otherwise, numbers take the | |
4332 | form [BASE`#']N, where BASE is a decimal number between 2 and 64 | |
4333 | representing the arithmetic base, and N is a number in that base. If | |
4334 | BASE`#' is omitted, then base 10 is used. The digits greater than 9 | |
4335 | are represented by the lowercase letters, the uppercase letters, `_', | |
4336 | and `@', in that order. If BASE is less than or equal to 36, lowercase | |
4337 | and uppercase letters may be used interchangably to represent numbers | |
4338 | between 10 and 35. | |
ccc6cda3 | 4339 | |
bb70624e JA |
4340 | Operators are evaluated in order of precedence. Sub-expressions in |
4341 | parentheses are evaluated first and may override the precedence rules | |
4342 | above. | |
ccc6cda3 | 4343 | |
bb70624e JA |
4344 | \1f |
4345 | File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features | |
ccc6cda3 | 4346 | |
bb70624e JA |
4347 | Aliases |
4348 | ======= | |
ccc6cda3 | 4349 | |
bb70624e | 4350 | ALIASES allow a string to be substituted for a word when it is used |
cce855bc | 4351 | as the first word of a simple command. The shell maintains a list of |
bb70624e | 4352 | aliases that may be set and unset with the `alias' and `unalias' |
cce855bc JA |
4353 | builtin commands. |
4354 | ||
4355 | The first word of each simple command, if unquoted, is checked to see | |
4356 | if it has an alias. If so, that word is replaced by the text of the | |
4357 | alias. The alias name and the replacement text may contain any valid | |
4358 | shell input, including shell metacharacters, with the exception that | |
4359 | the alias name may not contain `='. The first word of the replacement | |
4360 | text is tested for aliases, but a word that is identical to an alias | |
4361 | being expanded is not expanded a second time. This means that one may | |
4362 | alias `ls' to `"ls -F"', for instance, and Bash does not try to | |
4363 | recursively expand the replacement text. If the last character of the | |
4364 | alias value is a space or tab character, then the next command word | |
4365 | following the alias is also checked for alias expansion. | |
4366 | ||
4367 | Aliases are created and listed with the `alias' command, and removed | |
4368 | with the `unalias' command. | |
4369 | ||
4370 | There is no mechanism for using arguments in the replacement text, | |
4371 | as in `csh'. If arguments are needed, a shell function should be used | |
28ef6c31 | 4372 | (*note Shell Functions::). |
cce855bc JA |
4373 | |
4374 | Aliases are not expanded when the shell is not interactive, unless | |
4375 | the `expand_aliases' shell option is set using `shopt' (*note Bash | |
28ef6c31 | 4376 | Builtins::). |
ccc6cda3 | 4377 | |
cce855bc JA |
4378 | The rules concerning the definition and use of aliases are somewhat |
4379 | confusing. Bash always reads at least one complete line of input | |
4380 | before executing any of the commands on that line. Aliases are | |
4381 | expanded when a command is read, not when it is executed. Therefore, an | |
4382 | alias definition appearing on the same line as another command does not | |
4383 | take effect until the next line of input is read. The commands | |
4384 | following the alias definition on that line are not affected by the new | |
4385 | alias. This behavior is also an issue when functions are executed. | |
4386 | Aliases are expanded when a function definition is read, not when the | |
4387 | function is executed, because a function definition is itself a | |
4388 | compound command. As a consequence, aliases defined in a function are | |
4389 | not available until after that function is executed. To be safe, | |
4390 | always put alias definitions on a separate line, and do not use `alias' | |
4391 | in compound commands. | |
ccc6cda3 | 4392 | |
bb70624e | 4393 | For almost every purpose, shell functions are preferred over aliases. |
ccc6cda3 JA |
4394 | |
4395 | \1f | |
cce855bc | 4396 | File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features |
ccc6cda3 JA |
4397 | |
4398 | Arrays | |
4399 | ====== | |
4400 | ||
4401 | Bash provides one-dimensional array variables. Any variable may be | |
4402 | used as an array; the `declare' builtin will explicitly declare an | |
4403 | array. There is no maximum limit on the size of an array, nor any | |
4404 | requirement that members be indexed or assigned contiguously. Arrays | |
4405 | are zero-based. | |
4406 | ||
4407 | An array is created automatically if any variable is assigned to | |
4408 | using the syntax | |
4409 | name[SUBSCRIPT]=VALUE | |
4410 | ||
4411 | The SUBSCRIPT is treated as an arithmetic expression that must evaluate | |
4412 | to a number greater than or equal to zero. To explicitly declare an | |
4413 | array, use | |
4414 | declare -a NAME | |
4415 | ||
4416 | The syntax | |
4417 | declare -a NAME[SUBSCRIPT] | |
4418 | ||
4419 | is also accepted; the SUBSCRIPT is ignored. Attributes may be | |
4420 | specified for an array variable using the `declare' and `readonly' | |
4421 | builtins. Each attribute applies to all members of an array. | |
4422 | ||
4423 | Arrays are assigned to using compound assignments of the form | |
4424 | name=(value1 ... valueN) | |
4425 | ||
4426 | where each VALUE is of the form `[[SUBSCRIPT]=]'STRING. If the | |
4427 | optional subscript is supplied, that index is assigned to; otherwise | |
4428 | the index of the element assigned is the last index assigned to by the | |
4429 | statement plus one. Indexing starts at zero. This syntax is also | |
4430 | accepted by the `declare' builtin. Individual array elements may be | |
4431 | assigned to using the `name['SUBSCRIPT`]='VALUE syntax introduced above. | |
4432 | ||
4433 | Any element of an array may be referenced using | |
4434 | `${name['SUBSCRIPT`]}'. The braces are required to avoid conflicts | |
4435 | with the shell's filename expansion operators. If the SUBSCRIPT is `@' | |
4436 | or `*', the word expands to all members of the array NAME. These | |
4437 | subscripts differ only when the word appears within double quotes. If | |
4438 | the word is double-quoted, `${name[*]}' expands to a single word with | |
4439 | the value of each array member separated by the first character of the | |
4440 | `IFS' variable, and `${name[@]}' expands each element of NAME to a | |
4441 | separate word. When there are no array members, `${name[@]}' expands | |
4442 | to nothing. This is analogous to the expansion of the special | |
4443 | parameters `@' and `*'. `${#name['SUBSCRIPT`]}' expands to the length | |
4444 | of `${name['SUBSCRIPT`]}'. If SUBSCRIPT is `@' or `*', the expansion | |
4445 | is the number of elements in the array. Referencing an array variable | |
4446 | without a subscript is equivalent to referencing element zero. | |
4447 | ||
4448 | The `unset' builtin is used to destroy arrays. `unset' | |
bb70624e JA |
4449 | NAME[SUBSCRIPT] destroys the array element at index SUBSCRIPT. `unset' |
4450 | NAME, where NAME is an array, removes the entire array. A subscript of | |
4451 | `*' or `@' also removes the entire array. | |
ccc6cda3 JA |
4452 | |
4453 | The `declare', `local', and `readonly' builtins each accept a `-a' | |
4454 | option to specify an array. The `read' builtin accepts a `-a' option | |
4455 | to assign a list of words read from the standard input to an array, and | |
4456 | can read values from the standard input into individual array elements. | |
4457 | The `set' and `declare' builtins display array values in a way that | |
4458 | allows them to be reused as input. | |
4459 | ||
4460 | \1f | |
cce855bc JA |
4461 | File: bashref.info, Node: The Directory Stack, Next: Printing a Prompt, Prev: Arrays, Up: Bash Features |
4462 | ||
4463 | The Directory Stack | |
4464 | =================== | |
4465 | ||
bb70624e JA |
4466 | * Menu: |
4467 | ||
4468 | * Directory Stack Builtins:: Bash builtin commands to manipulate | |
4469 | the directory stack. | |
4470 | ||
4471 | The directory stack is a list of recently-visited directories. The | |
cce855bc JA |
4472 | `pushd' builtin adds directories to the stack as it changes the current |
4473 | directory, and the `popd' builtin removes specified directories from | |
4474 | the stack and changes the current directory to the directory removed. | |
4475 | The `dirs' builtin displays the contents of the directory stack. | |
4476 | ||
4477 | The contents of the directory stack are also visible as the value of | |
4478 | the `DIRSTACK' shell variable. | |
4479 | ||
bb70624e JA |
4480 | \1f |
4481 | File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack | |
4482 | ||
4483 | Directory Stack Builtins | |
4484 | ------------------------ | |
4485 | ||
cce855bc | 4486 | `dirs' |
bb70624e | 4487 | dirs [+N | -N] [-clpv] |
cce855bc JA |
4488 | Display the list of currently remembered directories. Directories |
4489 | are added to the list with the `pushd' command; the `popd' command | |
4490 | removes directories from the list. | |
4491 | `+N' | |
4492 | Displays the Nth directory (counting from the left of the | |
4493 | list printed by `dirs' when invoked without options), starting | |
4494 | with zero. | |
4495 | ||
4496 | `-N' | |
4497 | Displays the Nth directory (counting from the right of the | |
4498 | list printed by `dirs' when invoked without options), starting | |
4499 | with zero. | |
4500 | ||
4501 | `-c' | |
4502 | Clears the directory stack by deleting all of the elements. | |
4503 | ||
4504 | `-l' | |
4505 | Produces a longer listing; the default listing format uses a | |
4506 | tilde to denote the home directory. | |
4507 | ||
4508 | `-p' | |
4509 | Causes `dirs' to print the directory stack with one entry per | |
4510 | line. | |
4511 | ||
4512 | `-v' | |
4513 | Causes `dirs' to print the directory stack with one entry per | |
4514 | line, prefixing each entry with its index in the stack. | |
4515 | ||
4516 | `popd' | |
4517 | popd [+N | -N] [-n] | |
4518 | ||
4519 | Remove the top entry from the directory stack, and `cd' to the new | |
4520 | top directory. When no arguments are given, `popd' removes the | |
4521 | top directory from the stack and performs a `cd' to the new top | |
4522 | directory. The elements are numbered from 0 starting at the first | |
4523 | directory listed with `dirs'; i.e., `popd' is equivalent to `popd | |
4524 | +0'. | |
4525 | `+N' | |
4526 | Removes the Nth directory (counting from the left of the list | |
4527 | printed by `dirs'), starting with zero. | |
4528 | ||
4529 | `-N' | |
4530 | Removes the Nth directory (counting from the right of the | |
4531 | list printed by `dirs'), starting with zero. | |
4532 | ||
4533 | `-n' | |
4534 | Suppresses the normal change of directory when removing | |
4535 | directories from the stack, so that only the stack is | |
4536 | manipulated. | |
4537 | ||
4538 | `pushd' | |
4539 | pushd [DIR | +N | -N] [-n] | |
4540 | ||
4541 | Save the current directory on the top of the directory stack and | |
4542 | then `cd' to DIR. With no arguments, `pushd' exchanges the top | |
4543 | two directories. | |
4544 | ||
4545 | `+N' | |
4546 | Brings the Nth directory (counting from the left of the list | |
4547 | printed by `dirs', starting with zero) to the top of the list | |
4548 | by rotating the stack. | |
4549 | ||
4550 | `-N' | |
4551 | Brings the Nth directory (counting from the right of the list | |
4552 | printed by `dirs', starting with zero) to the top of the list | |
4553 | by rotating the stack. | |
4554 | ||
4555 | `-n' | |
4556 | Suppresses the normal change of directory when adding | |
4557 | directories to the stack, so that only the stack is | |
4558 | manipulated. | |
4559 | ||
4560 | `DIR' | |
4561 | Makes the current working directory be the top of the stack, | |
4562 | and then executes the equivalent of ``cd' DIR'. `cd's to DIR. | |
4563 | ||
4564 | \1f | |
4565 | File: bashref.info, Node: Printing a Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features | |
ccc6cda3 JA |
4566 | |
4567 | Controlling the Prompt | |
4568 | ====================== | |
4569 | ||
4570 | The value of the variable `PROMPT_COMMAND' is examined just before | |
bb70624e JA |
4571 | Bash prints each primary prompt. If `PROMPT_COMMAND' is set and has a |
4572 | non-null value, then the value is executed just as if it had been typed | |
4573 | on the command line. | |
ccc6cda3 JA |
4574 | |
4575 | In addition, the following table describes the special characters | |
4576 | which can appear in the prompt variables: | |
4577 | ||
4578 | `\a' | |
cce855bc | 4579 | A bell character. |
ccc6cda3 JA |
4580 | |
4581 | `\d' | |
cce855bc | 4582 | The date, in "Weekday Month Date" format (e.g., "Tue May 26"). |
ccc6cda3 JA |
4583 | |
4584 | `\e' | |
cce855bc | 4585 | An escape character. |
ccc6cda3 JA |
4586 | |
4587 | `\h' | |
cce855bc | 4588 | The hostname, up to the first `.'. |
ccc6cda3 JA |
4589 | |
4590 | `\H' | |
cce855bc | 4591 | The hostname. |
ccc6cda3 | 4592 | |
bb70624e JA |
4593 | `\j' |
4594 | The number of jobs currently managed by the shell. | |
4595 | ||
4596 | `\l' | |
4597 | The basename of the shell's terminal device name. | |
4598 | ||
ccc6cda3 | 4599 | `\n' |
cce855bc JA |
4600 | A newline. |
4601 | ||
4602 | `\r' | |
4603 | A carriage return. | |
ccc6cda3 JA |
4604 | |
4605 | `\s' | |
cce855bc | 4606 | The name of the shell, the basename of `$0' (the portion following |
ccc6cda3 JA |
4607 | the final slash). |
4608 | ||
4609 | `\t' | |
cce855bc | 4610 | The time, in 24-hour HH:MM:SS format. |
ccc6cda3 JA |
4611 | |
4612 | `\T' | |
cce855bc | 4613 | The time, in 12-hour HH:MM:SS format. |
ccc6cda3 JA |
4614 | |
4615 | `\@' | |
cce855bc JA |
4616 | The time, in 12-hour am/pm format. |
4617 | ||
4618 | `\u' | |
4619 | The username of the current user. | |
ccc6cda3 JA |
4620 | |
4621 | `\v' | |
cce855bc | 4622 | The version of Bash (e.g., 2.00) |
ccc6cda3 JA |
4623 | |
4624 | `\V' | |
cce855bc | 4625 | The release of Bash, version + patchlevel (e.g., 2.00.0) |
ccc6cda3 JA |
4626 | |
4627 | `\w' | |
cce855bc | 4628 | The current working directory. |
ccc6cda3 JA |
4629 | |
4630 | `\W' | |
cce855bc | 4631 | The basename of `$PWD'. |
ccc6cda3 JA |
4632 | |
4633 | `\!' | |
cce855bc | 4634 | The history number of this command. |
ccc6cda3 JA |
4635 | |
4636 | `\#' | |
cce855bc | 4637 | The command number of this command. |
ccc6cda3 JA |
4638 | |
4639 | `\$' | |
cce855bc | 4640 | If the effective uid is 0, `#', otherwise `$'. |
ccc6cda3 | 4641 | |
cce855bc JA |
4642 | `\NNN' |
4643 | The character whose ASCII code is the octal value NNN. | |
ccc6cda3 JA |
4644 | |
4645 | `\\' | |
cce855bc | 4646 | A backslash. |
ccc6cda3 JA |
4647 | |
4648 | `\[' | |
cce855bc | 4649 | Begin a sequence of non-printing characters. This could be used to |
ccc6cda3 JA |
4650 | embed a terminal control sequence into the prompt. |
4651 | ||
4652 | `\]' | |
cce855bc | 4653 | End a sequence of non-printing characters. |
ccc6cda3 | 4654 | |
bb70624e JA |
4655 | The command number and the history number are usually different: the |
4656 | history number of a command is its position in the history list, which | |
4657 | may include commands restored from the history file (*note Bash History | |
28ef6c31 JA |
4658 | Facilities::), while the command number is the position in the sequence |
4659 | of commands executed during the current shell session. | |
bb70624e JA |
4660 | |
4661 | After the string is decoded, it is expanded via parameter expansion, | |
4662 | command substitution, arithmetic expansion, and quote removal, subject | |
28ef6c31 | 4663 | to the value of the `promptvars' shell option (*note Bash Builtins::). |
bb70624e | 4664 | |
ccc6cda3 JA |
4665 | \1f |
4666 | File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Printing a Prompt, Up: Bash Features | |
4667 | ||
4668 | The Restricted Shell | |
4669 | ==================== | |
4670 | ||
4671 | If Bash is started with the name `rbash', or the `--restricted' | |
4672 | option is supplied at invocation, the shell becomes restricted. A | |
4673 | restricted shell is used to set up an environment more controlled than | |
4674 | the standard shell. A restricted shell behaves identically to `bash' | |
4675 | with the exception that the following are disallowed: | |
4676 | * Changing directories with the `cd' builtin. | |
4677 | ||
b72432fd JA |
4678 | * Setting or unsetting the values of the `SHELL', `PATH', `ENV', or |
4679 | `BASH_ENV' variables. | |
ccc6cda3 JA |
4680 | |
4681 | * Specifying command names containing slashes. | |
4682 | ||
4683 | * Specifying a filename containing a slash as an argument to the `.' | |
4684 | builtin command. | |
4685 | ||
bb70624e JA |
4686 | * Specifying a filename containing a slash as an argument to the `-p' |
4687 | option to the `hash' builtin command. | |
4688 | ||
ccc6cda3 JA |
4689 | * Importing function definitions from the shell environment at |
4690 | startup. | |
4691 | ||
cce855bc JA |
4692 | * Parsing the value of `SHELLOPTS' from the shell environment at |
4693 | startup. | |
4694 | ||
ccc6cda3 JA |
4695 | * Redirecting output using the `>', `>|', `<>', `>&', `&>', and `>>' |
4696 | redirection operators. | |
4697 | ||
4698 | * Using the `exec' builtin to replace the shell with another command. | |
4699 | ||
4700 | * Adding or deleting builtin commands with the `-f' and `-d' options | |
4701 | to the `enable' builtin. | |
4702 | ||
4703 | * Specifying the `-p' option to the `command' builtin. | |
4704 | ||
cce855bc | 4705 | * Turning off restricted mode with `set +r' or `set +o restricted'. |
ccc6cda3 JA |
4706 | |
4707 | \1f | |
4708 | File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features | |
4709 | ||
4710 | Bash POSIX Mode | |
4711 | =============== | |
4712 | ||
4713 | Starting Bash with the `--posix' command-line option or executing | |
4714 | `set -o posix' while Bash is running will cause Bash to conform more | |
bb70624e JA |
4715 | closely to the POSIX 1003.2 standard by changing the behavior to match |
4716 | that specified by POSIX in areas where the Bash default differs. | |
ccc6cda3 JA |
4717 | |
4718 | The following list is what's changed when `POSIX mode' is in effect: | |
4719 | ||
4720 | 1. When a command in the hash table no longer exists, Bash will | |
4721 | re-search `$PATH' to find the new location. This is also | |
4722 | available with `shopt -s checkhash'. | |
4723 | ||
28ef6c31 JA |
4724 | 2. The message printed by the job control code and builtins when a job |
4725 | exits with a non-zero status is `Done(status)'. | |
ccc6cda3 JA |
4726 | |
4727 | 3. The message printed by the job control code and builtins when a job | |
28ef6c31 JA |
4728 | is stopped is `Stopped(SIGNAME)', where SIGNAME is, for example, |
4729 | `SIGTSTP'. | |
ccc6cda3 JA |
4730 | |
4731 | 4. Reserved words may not be aliased. | |
4732 | ||
bb70624e | 4733 | 5. The POSIX 1003.2 `PS1' and `PS2' expansions of `!' to the history |
ccc6cda3 | 4734 | number and `!!' to `!' are enabled, and parameter expansion is |
cce855bc JA |
4735 | performed on the values of `PS1' and `PS2' regardless of the |
4736 | setting of the `promptvars' option. | |
ccc6cda3 | 4737 | |
cce855bc JA |
4738 | 6. Interactive comments are enabled by default. (Bash has them on by |
4739 | default anyway.) | |
ccc6cda3 | 4740 | |
bb70624e JA |
4741 | 7. The POSIX 1003.2 startup files are executed (`$ENV') rather than |
4742 | the normal Bash files. | |
ccc6cda3 JA |
4743 | |
4744 | 8. Tilde expansion is only performed on assignments preceding a | |
4745 | command name, rather than on all assignment statements on the line. | |
4746 | ||
4747 | 9. The default history file is `~/.sh_history' (this is the default | |
4748 | value of `$HISTFILE'). | |
4749 | ||
4750 | 10. The output of `kill -l' prints all the signal names on a single | |
4751 | line, separated by spaces. | |
4752 | ||
4753 | 11. Non-interactive shells exit if FILENAME in `.' FILENAME is not | |
4754 | found. | |
4755 | ||
cce855bc JA |
4756 | 12. Non-interactive shells exit if a syntax error in an arithmetic |
4757 | expansion results in an invalid expression. | |
4758 | ||
4759 | 13. Redirection operators do not perform filename expansion on the word | |
ccc6cda3 JA |
4760 | in the redirection unless the shell is interactive. |
4761 | ||
bb70624e JA |
4762 | 14. Redirection operators do not perform word splitting on the word in |
4763 | the redirection. | |
4764 | ||
4765 | 15. Function names must be valid shell `name's. That is, they may not | |
ccc6cda3 | 4766 | contain characters other than letters, digits, and underscores, and |
cce855bc | 4767 | may not start with a digit. Declaring a function with an invalid |
ccc6cda3 JA |
4768 | name causes a fatal syntax error in non-interactive shells. |
4769 | ||
bb70624e JA |
4770 | 16. POSIX 1003.2 `special' builtins are found before shell functions |
4771 | during command lookup. | |
ccc6cda3 | 4772 | |
bb70624e | 4773 | 17. If a POSIX 1003.2 special builtin returns an error status, a |
ccc6cda3 JA |
4774 | non-interactive shell exits. The fatal errors are those listed in |
4775 | the POSIX.2 standard, and include things like passing incorrect | |
4776 | options, redirection errors, variable assignment errors for | |
4777 | assignments preceding the command name, and so on. | |
4778 | ||
bb70624e | 4779 | 18. If the `cd' builtin finds a directory to change to using |
ccc6cda3 JA |
4780 | `$CDPATH', the value it assigns to the `PWD' variable does not |
4781 | contain any symbolic links, as if `cd -P' had been executed. | |
4782 | ||
28ef6c31 | 4783 | 19. If `CDPATH' is set, the `cd' builtin will not implicitly append |
cce855bc JA |
4784 | the current directory to it. This means that `cd' will fail if no |
4785 | valid directory name can be constructed from any of the entries in | |
4786 | `$CDPATH', even if the a directory with the same name as the name | |
4787 | given as an argument to `cd' exists in the current directory. | |
4788 | ||
bb70624e | 4789 | 20. A non-interactive shell exits with an error status if a variable |
ccc6cda3 JA |
4790 | assignment error occurs when no command name follows the assignment |
4791 | statements. A variable assignment error occurs, for example, when | |
cce855bc | 4792 | trying to assign a value to a readonly variable. |
ccc6cda3 | 4793 | |
bb70624e | 4794 | 21. A non-interactive shell exits with an error status if the iteration |
ccc6cda3 | 4795 | variable in a `for' statement or the selection variable in a |
cce855bc | 4796 | `select' statement is a readonly variable. |
ccc6cda3 | 4797 | |
bb70624e | 4798 | 22. Process substitution is not available. |
ccc6cda3 | 4799 | |
bb70624e JA |
4800 | 23. Assignment statements preceding POSIX 1003.2 special builtins |
4801 | persist in the shell environment after the builtin completes. | |
ccc6cda3 | 4802 | |
28ef6c31 JA |
4803 | 24. Assignment statements preceding shell function calls persist in the |
4804 | shell environment after the function returns, as if a POSIX | |
4805 | special builtin command had been executed. | |
4806 | ||
4807 | 25. The `export' and `readonly' builtin commands display their output | |
bb70624e | 4808 | in the format required by POSIX 1003.2. |
d166f048 | 4809 | |
28ef6c31 JA |
4810 | 26. The `trap' builtin displays signal names without the leading `SIG'. |
4811 | ||
4812 | 27. The `.' and `source' builtins do not search the current directory | |
4813 | for the filename argument if it is not found by searching `PATH'. | |
4814 | ||
4815 | 28. Subshells spawned to execute command substitutions inherit the | |
4816 | value of the `-e' option from the parent shell. When not in POSIX | |
4817 | mode, Bash clears the `-e' option in such subshells. | |
4818 | ||
4819 | 29. Alias expansion is always enabled, even in non-interactive shells. | |
4820 | ||
4821 | 30. When the `set' builtin is invoked without options, it does not | |
4822 | display shell function names and definitions. | |
4823 | ||
ccc6cda3 | 4824 | |
bb70624e | 4825 | There is other POSIX 1003.2 behavior that Bash does not implement. |
ccc6cda3 JA |
4826 | Specifically: |
4827 | ||
4828 | 1. Assignment statements affect the execution environment of all | |
4829 | builtins, not just special ones. | |
4830 | ||
28ef6c31 JA |
4831 | 2. When a subshell is created to execute a shell script with execute |
4832 | permission, but without a leading `#!', Bash sets `$0' to the full | |
4833 | pathname of the script as found by searching `$PATH', rather than | |
4834 | the command as typed by the user. | |
4835 | ||
4836 | 3. When using `.' to source a shell script found in `$PATH', bash | |
4837 | checks execute permission bits rather than read permission bits, | |
4838 | just as if it were searching for a command. | |
4839 | ||
4840 | ||
ccc6cda3 JA |
4841 | \1f |
4842 | File: bashref.info, Node: Job Control, Next: Using History Interactively, Prev: Bash Features, Up: Top | |
4843 | ||
4844 | Job Control | |
4845 | *********** | |
4846 | ||
cce855bc | 4847 | This chapter discusses what job control is, how it works, and how |
ccc6cda3 JA |
4848 | Bash allows you to access its facilities. |
4849 | ||
4850 | * Menu: | |
4851 | ||
4852 | * Job Control Basics:: How job control works. | |
4853 | * Job Control Builtins:: Bash builtin commands used to interact | |
4854 | with job control. | |
4855 | * Job Control Variables:: Variables Bash uses to customize job | |
4856 | control. | |
4857 | ||
4858 | \1f | |
4859 | File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control | |
4860 | ||
4861 | Job Control Basics | |
4862 | ================== | |
4863 | ||
4864 | Job control refers to the ability to selectively stop (suspend) the | |
4865 | execution of processes and continue (resume) their execution at a later | |
4866 | point. A user typically employs this facility via an interactive | |
4867 | interface supplied jointly by the system's terminal driver and Bash. | |
4868 | ||
4869 | The shell associates a JOB with each pipeline. It keeps a table of | |
4870 | currently executing jobs, which may be listed with the `jobs' command. | |
cce855bc | 4871 | When Bash starts a job asynchronously, it prints a line that looks like: |
ccc6cda3 JA |
4872 | [1] 25647 |
4873 | ||
4874 | indicating that this job is job number 1 and that the process ID of the | |
4875 | last process in the pipeline associated with this job is 25647. All of | |
4876 | the processes in a single pipeline are members of the same job. Bash | |
4877 | uses the JOB abstraction as the basis for job control. | |
4878 | ||
4879 | To facilitate the implementation of the user interface to job | |
bb70624e JA |
4880 | control, the operating system maintains the notion of a current terminal |
4881 | process group ID. Members of this process group (processes whose | |
4882 | process group ID is equal to the current terminal process group ID) | |
4883 | receive keyboard-generated signals such as `SIGINT'. These processes | |
4884 | are said to be in the foreground. Background processes are those whose | |
4885 | process group ID differs from the terminal's; such processes are immune | |
4886 | to keyboard-generated signals. Only foreground processes are allowed | |
4887 | to read from or write to the terminal. Background processes which | |
4888 | attempt to read from (write to) the terminal are sent a `SIGTTIN' | |
4889 | (`SIGTTOU') signal by the terminal driver, which, unless caught, | |
4890 | suspends the process. | |
ccc6cda3 JA |
4891 | |
4892 | If the operating system on which Bash is running supports job | |
cce855bc JA |
4893 | control, Bash contains facilities to use it. Typing the SUSPEND |
4894 | character (typically `^Z', Control-Z) while a process is running causes | |
4895 | that process to be stopped and returns control to Bash. Typing the | |
4896 | DELAYED SUSPEND character (typically `^Y', Control-Y) causes the | |
4897 | process to be stopped when it attempts to read input from the terminal, | |
4898 | and control to be returned to Bash. The user then manipulates the | |
4899 | state of this job, using the `bg' command to continue it in the | |
4900 | background, the `fg' command to continue it in the foreground, or the | |
4901 | `kill' command to kill it. A `^Z' takes effect immediately, and has | |
4902 | the additional side effect of causing pending output and typeahead to | |
4903 | be discarded. | |
ccc6cda3 JA |
4904 | |
4905 | There are a number of ways to refer to a job in the shell. The | |
bb70624e JA |
4906 | character `%' introduces a job name. |
4907 | ||
4908 | Job number `n' may be referred to as `%n'. The symbols `%%' and | |
4909 | `%+' refer to the shell's notion of the current job, which is the last | |
4910 | job stopped while it was in the foreground or started in the | |
4911 | background. The previous job may be referenced using `%-'. In output | |
4912 | pertaining to jobs (e.g., the output of the `jobs' command), the | |
4913 | current job is always flagged with a `+', and the previous job with a | |
4914 | `-'. | |
4915 | ||
4916 | A job may also be referred to using a prefix of the name used to | |
4917 | start it, or using a substring that appears in its command line. For | |
4918 | example, `%ce' refers to a stopped `ce' job. Using `%?ce', on the other | |
4919 | hand, refers to any job containing the string `ce' in its command line. | |
4920 | If the prefix or substring matches more than one job, Bash reports an | |
4921 | error. | |
ccc6cda3 JA |
4922 | |
4923 | Simply naming a job can be used to bring it into the foreground: | |
4924 | `%1' is a synonym for `fg %1', bringing job 1 from the background into | |
4925 | the foreground. Similarly, `%1 &' resumes job 1 in the background, | |
4926 | equivalent to `bg %1' | |
4927 | ||
4928 | The shell learns immediately whenever a job changes state. | |
4929 | Normally, Bash waits until it is about to print a prompt before | |
4930 | reporting changes in a job's status so as to not interrupt any other | |
cce855bc | 4931 | output. If the the `-b' option to the `set' builtin is enabled, Bash |
28ef6c31 | 4932 | reports such changes immediately (*note The Set Builtin::). |
ccc6cda3 | 4933 | |
cce855bc JA |
4934 | If an attempt to exit Bash is while jobs are stopped, the shell |
4935 | prints a message warning that there are stopped jobs. The `jobs' | |
4936 | command may then be used to inspect their status. If a second attempt | |
4937 | to exit is made without an intervening command, Bash does not print | |
4938 | another warning, and the stopped jobs are terminated. | |
ccc6cda3 JA |
4939 | |
4940 | \1f | |
4941 | File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control | |
4942 | ||
4943 | Job Control Builtins | |
4944 | ==================== | |
4945 | ||
4946 | `bg' | |
4947 | bg [JOBSPEC] | |
cce855bc JA |
4948 | Resume the suspended job JOBSPEC in the background, as if it had |
4949 | been started with `&'. If JOBSPEC is not supplied, the current | |
4950 | job is used. The return status is zero unless it is run when job | |
4951 | control is not enabled, or, when run with job control enabled, if | |
4952 | JOBSPEC was not found or JOBSPEC specifies a job that was started | |
4953 | without job control. | |
ccc6cda3 JA |
4954 | |
4955 | `fg' | |
4956 | fg [JOBSPEC] | |
cce855bc JA |
4957 | Resume the job JOBSPEC in the foreground and make it the current |
4958 | job. If JOBSPEC is not supplied, the current job is used. The | |
4959 | return status is that of the command placed into the foreground, | |
4960 | or non-zero if run when job control is disabled or, when run with | |
4961 | job control enabled, JOBSPEC does not specify a valid job or | |
4962 | JOBSPEC specifies a job that was started without job control. | |
ccc6cda3 JA |
4963 | |
4964 | `jobs' | |
bb70624e | 4965 | jobs [-lnprs] [JOBSPEC] |
cce855bc | 4966 | jobs -x COMMAND [ARGUMENTS] |
ccc6cda3 JA |
4967 | |
4968 | The first form lists the active jobs. The options have the | |
4969 | following meanings: | |
4970 | ||
4971 | `-l' | |
cce855bc | 4972 | List process IDs in addition to the normal information. |
ccc6cda3 JA |
4973 | |
4974 | `-n' | |
4975 | Display information only about jobs that have changed status | |
cce855bc | 4976 | since the user was last notified of their status. |
ccc6cda3 JA |
4977 | |
4978 | `-p' | |
4979 | List only the process ID of the job's process group leader. | |
4980 | ||
4981 | `-r' | |
4982 | Restrict output to running jobs. | |
4983 | ||
4984 | `-s' | |
4985 | Restrict output to stopped jobs. | |
4986 | ||
4987 | If JOBSPEC is given, output is restricted to information about | |
4988 | that job. If JOBSPEC is not supplied, the status of all jobs is | |
4989 | listed. | |
4990 | ||
4991 | If the `-x' option is supplied, `jobs' replaces any JOBSPEC found | |
4992 | in COMMAND or ARGUMENTS with the corresponding process group ID, | |
4993 | and executes COMMAND, passing it ARGUMENTs, returning its exit | |
4994 | status. | |
4995 | ||
4996 | `kill' | |
cce855bc JA |
4997 | kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID |
4998 | kill -l [EXIT_STATUS] | |
ccc6cda3 | 4999 | Send a signal specified by SIGSPEC or SIGNUM to the process named |
cce855bc JA |
5000 | by job specification JOBSPEC or process ID PID. SIGSPEC is either |
5001 | a signal name such as `SIGINT' (with or without the `SIG' prefix) | |
5002 | or a signal number; SIGNUM is a signal number. If SIGSPEC and | |
5003 | SIGNUM are not present, `SIGTERM' is used. The `-l' option lists | |
5004 | the signal names. If any arguments are supplied when `-l' is | |
5005 | given, the names of the signals corresponding to the arguments are | |
5006 | listed, and the return status is zero. EXIT_STATUS is a number | |
5007 | specifying a signal number or the exit status of a process | |
5008 | terminated by a signal. The return status is zero if at least one | |
5009 | signal was successfully sent, or non-zero if an error occurs or an | |
5010 | invalid option is encountered. | |
ccc6cda3 JA |
5011 | |
5012 | `wait' | |
bb70624e | 5013 | wait [JOBSPEC or PID] |
ccc6cda3 | 5014 | Wait until the child process specified by process ID PID or job |
cce855bc JA |
5015 | specification JOBSPEC exits and return the exit status of the last |
5016 | command waited for. If a job spec is given, all processes in the | |
5017 | job are waited for. If no arguments are given, all currently | |
5018 | active child processes are waited for, and the return status is | |
5019 | zero. If neither JOBSPEC nor PID specifies an active child process | |
5020 | of the shell, the return status is 127. | |
ccc6cda3 JA |
5021 | |
5022 | `disown' | |
cce855bc | 5023 | disown [-ar] [-h] [JOBSPEC ...] |
ccc6cda3 JA |
5024 | Without options, each JOBSPEC is removed from the table of active |
5025 | jobs. If the `-h' option is given, the job is not removed from | |
5026 | the table, but is marked so that `SIGHUP' is not sent to the job | |
cce855bc JA |
5027 | if the shell receives a `SIGHUP'. If JOBSPEC is not present, and |
5028 | neither the `-a' nor `-r' option is supplied, the current job is | |
5029 | used. If no JOBSPEC is supplied, the `-a' option means to remove | |
5030 | or mark all jobs; the `-r' option without a JOBSPEC argument | |
5031 | restricts operation to running jobs. | |
ccc6cda3 JA |
5032 | |
5033 | `suspend' | |
5034 | suspend [-f] | |
5035 | Suspend the execution of this shell until it receives a `SIGCONT' | |
5036 | signal. The `-f' option means to suspend even if the shell is a | |
5037 | login shell. | |
5038 | ||
5039 | When job control is not active, the `kill' and `wait' builtins do | |
5040 | not accept JOBSPEC arguments. They must be supplied process IDs. | |
5041 | ||
5042 | \1f | |
5043 | File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control | |
5044 | ||
5045 | Job Control Variables | |
5046 | ===================== | |
5047 | ||
5048 | `auto_resume' | |
5049 | This variable controls how the shell interacts with the user and | |
5050 | job control. If this variable exists then single word simple | |
cce855bc JA |
5051 | commands without redirections are treated as candidates for |
5052 | resumption of an existing job. There is no ambiguity allowed; if | |
5053 | there is more than one job beginning with the string typed, then | |
5054 | the most recently accessed job will be selected. The name of a | |
5055 | stopped job, in this context, is the command line used to start | |
5056 | it. If this variable is set to the value `exact', the string | |
5057 | supplied must match the name of a stopped job exactly; if set to | |
ccc6cda3 JA |
5058 | `substring', the string supplied needs to match a substring of the |
5059 | name of a stopped job. The `substring' value provides | |
5060 | functionality analogous to the `%?' job ID (*note Job Control | |
28ef6c31 JA |
5061 | Basics::). If set to any other value, the supplied string must be |
5062 | a prefix of a stopped job's name; this provides functionality | |
ccc6cda3 JA |
5063 | analogous to the `%' job ID. |
5064 | ||
5065 | \1f | |
bb70624e | 5066 | File: bashref.info, Node: Command Line Editing, Next: Installing Bash, Prev: Using History Interactively, Up: Top |
ccc6cda3 | 5067 | |
bb70624e JA |
5068 | Command Line Editing |
5069 | ******************** | |
ccc6cda3 | 5070 | |
bb70624e JA |
5071 | This chapter describes the basic features of the GNU command line |
5072 | editing interface. Command line editing is provided by the Readline | |
5073 | library, which is used by several different programs, including Bash. | |
ccc6cda3 JA |
5074 | |
5075 | * Menu: | |
5076 | ||
bb70624e JA |
5077 | * Introduction and Notation:: Notation used in this text. |
5078 | * Readline Interaction:: The minimum set of commands for editing a line. | |
5079 | * Readline Init File:: Customizing Readline from a user's view. | |
5080 | * Bindable Readline Commands:: A description of most of the Readline commands | |
5081 | available for binding | |
5082 | * Readline vi Mode:: A short description of how to make Readline | |
5083 | behave like the vi editor. | |
5084 | ||
5085 | * Programmable Completion:: How to specify the possible completions for | |
5086 | a specific command. | |
5087 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
5088 | complete arguments for a particular command. | |
ccc6cda3 JA |
5089 | |
5090 | \1f | |
bb70624e | 5091 | File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing |
ccc6cda3 | 5092 | |
bb70624e JA |
5093 | Introduction to Line Editing |
5094 | ============================ | |
ccc6cda3 | 5095 | |
bb70624e JA |
5096 | The following paragraphs describe the notation used to represent |
5097 | keystrokes. | |
ccc6cda3 | 5098 | |
28ef6c31 | 5099 | The text `C-k' is read as `Control-K' and describes the character |
bb70624e | 5100 | produced when the <k> key is pressed while the Control key is depressed. |
ccc6cda3 | 5101 | |
28ef6c31 | 5102 | The text `M-k' is read as `Meta-K' and describes the character |
bb70624e JA |
5103 | produced when the Meta key (if you have one) is depressed, and the <k> |
5104 | key is pressed. The Meta key is labeled <ALT> on many keyboards. On | |
5105 | keyboards with two keys labeled <ALT> (usually to either side of the | |
5106 | space bar), the <ALT> on the left side is generally set to work as a | |
5107 | Meta key. The <ALT> key on the right may also be configured to work as | |
5108 | a Meta key or may be configured as some other modifier, such as a | |
5109 | Compose key for typing accented characters. | |
5110 | ||
5111 | If you do not have a Meta or <ALT> key, or another key working as a | |
5112 | Meta key, the identical keystroke can be generated by typing <ESC> | |
28ef6c31 JA |
5113 | _first_, and then typing <k>. Either process is known as "metafying" |
5114 | the <k> key. | |
bb70624e | 5115 | |
28ef6c31 JA |
5116 | The text `M-C-k' is read as `Meta-Control-k' and describes the |
5117 | character produced by "metafying" `C-k'. | |
bb70624e JA |
5118 | |
5119 | In addition, several keys have their own names. Specifically, | |
5120 | <DEL>, <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves | |
28ef6c31 JA |
5121 | when seen in this text, or in an init file (*note Readline Init File::). |
5122 | If your keyboard lacks a <LFD> key, typing <C-j> will produce the | |
5123 | desired character. The <RET> key may be labeled <Return> or <Enter> on | |
5124 | some keyboards. | |
ccc6cda3 JA |
5125 | |
5126 | \1f | |
bb70624e | 5127 | File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing |
cce855bc | 5128 | |
bb70624e JA |
5129 | Readline Interaction |
5130 | ==================== | |
cce855bc | 5131 | |
bb70624e JA |
5132 | Often during an interactive session you type in a long line of text, |
5133 | only to notice that the first word on the line is misspelled. The | |
5134 | Readline library gives you a set of commands for manipulating the text | |
5135 | as you type it in, allowing you to just fix your typo, and not forcing | |
5136 | you to retype the majority of the line. Using these editing commands, | |
5137 | you move the cursor to the place that needs correction, and delete or | |
5138 | insert the text of the corrections. Then, when you are satisfied with | |
28ef6c31 JA |
5139 | the line, you simply press <RET>. You do not have to be at the end of |
5140 | the line to press <RET>; the entire line is accepted regardless of the | |
5141 | location of the cursor within the line. | |
cce855bc | 5142 | |
bb70624e | 5143 | * Menu: |
cce855bc | 5144 | |
bb70624e JA |
5145 | * Readline Bare Essentials:: The least you need to know about Readline. |
5146 | * Readline Movement Commands:: Moving about the input line. | |
5147 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
5148 | * Readline Arguments:: Giving numeric arguments to commands. | |
5149 | * Searching:: Searching through previous lines. | |
cce855bc | 5150 | |
bb70624e JA |
5151 | \1f |
5152 | File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction | |
cce855bc | 5153 | |
bb70624e JA |
5154 | Readline Bare Essentials |
5155 | ------------------------ | |
cce855bc | 5156 | |
bb70624e JA |
5157 | In order to enter characters into the line, simply type them. The |
5158 | typed character appears where the cursor was, and then the cursor moves | |
5159 | one space to the right. If you mistype a character, you can use your | |
5160 | erase character to back up and delete the mistyped character. | |
cce855bc | 5161 | |
bb70624e JA |
5162 | Sometimes you may mistype a character, and not notice the error |
5163 | until you have typed several other characters. In that case, you can | |
28ef6c31 JA |
5164 | type `C-b' to move the cursor to the left, and then correct your |
5165 | mistake. Afterwards, you can move the cursor to the right with `C-f'. | |
cce855bc | 5166 | |
bb70624e JA |
5167 | When you add text in the middle of a line, you will notice that |
5168 | characters to the right of the cursor are `pushed over' to make room | |
5169 | for the text that you have inserted. Likewise, when you delete text | |
5170 | behind the cursor, characters to the right of the cursor are `pulled | |
5171 | back' to fill in the blank space created by the removal of the text. A | |
5172 | list of the bare essentials for editing the text of an input line | |
5173 | follows. | |
cce855bc | 5174 | |
28ef6c31 | 5175 | `C-b' |
bb70624e | 5176 | Move back one character. |
cce855bc | 5177 | |
28ef6c31 | 5178 | `C-f' |
bb70624e | 5179 | Move forward one character. |
cce855bc | 5180 | |
bb70624e JA |
5181 | <DEL> or <Backspace> |
5182 | Delete the character to the left of the cursor. | |
cce855bc | 5183 | |
28ef6c31 | 5184 | `C-d' |
bb70624e | 5185 | Delete the character underneath the cursor. |
cce855bc | 5186 | |
bb70624e JA |
5187 | Printing characters |
5188 | Insert the character into the line at the cursor. | |
cce855bc | 5189 | |
28ef6c31 | 5190 | `C-_' or `C-x C-u' |
bb70624e JA |
5191 | Undo the last editing command. You can undo all the way back to an |
5192 | empty line. | |
cce855bc | 5193 | |
bb70624e JA |
5194 | (Depending on your configuration, the <Backspace> key be set to delete |
5195 | the character to the left of the cursor and the <DEL> key set to delete | |
28ef6c31 | 5196 | the character underneath the cursor, like `C-d', rather than the |
bb70624e | 5197 | character to the left of the cursor.) |
cce855bc JA |
5198 | |
5199 | \1f | |
bb70624e | 5200 | File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction |
ccc6cda3 | 5201 | |
bb70624e JA |
5202 | Readline Movement Commands |
5203 | -------------------------- | |
ccc6cda3 | 5204 | |
bb70624e JA |
5205 | The above table describes the most basic keystrokes that you need in |
5206 | order to do editing of the input line. For your convenience, many | |
28ef6c31 | 5207 | other commands have been added in addition to `C-b', `C-f', `C-d', and |
bb70624e | 5208 | <DEL>. Here are some commands for moving more rapidly about the line. |
ccc6cda3 | 5209 | |
28ef6c31 | 5210 | `C-a' |
bb70624e | 5211 | Move to the start of the line. |
ccc6cda3 | 5212 | |
28ef6c31 | 5213 | `C-e' |
bb70624e | 5214 | Move to the end of the line. |
ccc6cda3 | 5215 | |
28ef6c31 | 5216 | `M-f' |
bb70624e JA |
5217 | Move forward a word, where a word is composed of letters and |
5218 | digits. | |
ccc6cda3 | 5219 | |
28ef6c31 | 5220 | `M-b' |
bb70624e | 5221 | Move backward a word. |
ccc6cda3 | 5222 | |
28ef6c31 | 5223 | `C-l' |
bb70624e | 5224 | Clear the screen, reprinting the current line at the top. |
ccc6cda3 | 5225 | |
28ef6c31 | 5226 | Notice how `C-f' moves forward a character, while `M-f' moves |
bb70624e JA |
5227 | forward a word. It is a loose convention that control keystrokes |
5228 | operate on characters while meta keystrokes operate on words. | |
ccc6cda3 JA |
5229 | |
5230 | \1f | |
bb70624e | 5231 | File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction |
ccc6cda3 | 5232 | |
bb70624e JA |
5233 | Readline Killing Commands |
5234 | ------------------------- | |
ccc6cda3 | 5235 | |
bb70624e JA |
5236 | "Killing" text means to delete the text from the line, but to save |
5237 | it away for later use, usually by "yanking" (re-inserting) it back into | |
5238 | the line. (`Cut' and `paste' are more recent jargon for `kill' and | |
5239 | `yank'.) | |
ccc6cda3 | 5240 | |
bb70624e JA |
5241 | If the description for a command says that it `kills' text, then you |
5242 | can be sure that you can get the text back in a different (or the same) | |
5243 | place later. | |
ccc6cda3 | 5244 | |
bb70624e JA |
5245 | When you use a kill command, the text is saved in a "kill-ring". |
5246 | Any number of consecutive kills save all of the killed text together, so | |
5247 | that when you yank it back, you get it all. The kill ring is not line | |
5248 | specific; the text that you killed on a previously typed line is | |
5249 | available to be yanked back later, when you are typing another line. | |
ccc6cda3 | 5250 | |
bb70624e | 5251 | Here is the list of commands for killing text. |
ccc6cda3 | 5252 | |
28ef6c31 | 5253 | `C-k' |
bb70624e JA |
5254 | Kill the text from the current cursor position to the end of the |
5255 | line. | |
ccc6cda3 | 5256 | |
28ef6c31 | 5257 | `M-d' |
bb70624e JA |
5258 | Kill from the cursor to the end of the current word, or, if between |
5259 | words, to the end of the next word. Word boundaries are the same | |
28ef6c31 | 5260 | as those used by `M-f'. |
ccc6cda3 | 5261 | |
28ef6c31 | 5262 | `M-<DEL>' |
bb70624e JA |
5263 | Kill from the cursor the start of the previous word, or, if between |
5264 | words, to the start of the previous word. Word boundaries are the | |
28ef6c31 | 5265 | same as those used by `M-b'. |
ccc6cda3 | 5266 | |
28ef6c31 | 5267 | `C-w' |
ccc6cda3 | 5268 | Kill from the cursor to the previous whitespace. This is |
28ef6c31 | 5269 | different than `M-<DEL>' because the word boundaries differ. |
ccc6cda3 | 5270 | |
cce855bc JA |
5271 | Here is how to "yank" the text back into the line. Yanking means to |
5272 | copy the most-recently-killed text from the kill buffer. | |
ccc6cda3 | 5273 | |
28ef6c31 | 5274 | `C-y' |
ccc6cda3 JA |
5275 | Yank the most recently killed text back into the buffer at the |
5276 | cursor. | |
5277 | ||
28ef6c31 | 5278 | `M-y' |
ccc6cda3 | 5279 | Rotate the kill-ring, and yank the new top. You can only do this |
28ef6c31 | 5280 | if the prior command is `C-y' or `M-y'. |
ccc6cda3 JA |
5281 | |
5282 | \1f | |
5283 | File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction | |
5284 | ||
5285 | Readline Arguments | |
5286 | ------------------ | |
5287 | ||
5288 | You can pass numeric arguments to Readline commands. Sometimes the | |
5289 | argument acts as a repeat count, other times it is the sign of the | |
5290 | argument that is significant. If you pass a negative argument to a | |
5291 | command which normally acts in a forward direction, that command will | |
5292 | act in a backward direction. For example, to kill text back to the | |
5293 | start of the line, you might type `M-- C-k'. | |
5294 | ||
5295 | The general way to pass numeric arguments to a command is to type | |
cce855bc | 5296 | meta digits before the command. If the first `digit' typed is a minus |
bb70624e | 5297 | sign (`-'), then the sign of the argument will be negative. Once you |
cce855bc JA |
5298 | have typed one meta digit to get the argument started, you can type the |
5299 | remainder of the digits, and then the command. For example, to give | |
28ef6c31 JA |
5300 | the `C-d' command an argument of 10, you could type `M-1 0 C-d', which |
5301 | will delete the next ten characters on the input line. | |
ccc6cda3 JA |
5302 | |
5303 | \1f | |
5304 | File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction | |
5305 | ||
5306 | Searching for Commands in the History | |
5307 | ------------------------------------- | |
5308 | ||
5309 | Readline provides commands for searching through the command history | |
28ef6c31 JA |
5310 | (*note Bash History Facilities::) for lines containing a specified |
5311 | string. There are two search modes: "incremental" and | |
5312 | "non-incremental". | |
ccc6cda3 JA |
5313 | |
5314 | Incremental searches begin before the user has finished typing the | |
5315 | search string. As each character of the search string is typed, | |
cce855bc | 5316 | Readline displays the next entry from the history matching the string |
ccc6cda3 | 5317 | typed so far. An incremental search requires only as many characters |
bb70624e | 5318 | as needed to find the desired history entry. To search backward in the |
28ef6c31 | 5319 | history for a particular string, type `C-r'. Typing `C-s' searches |
bb70624e JA |
5320 | forward through the history. The characters present in the value of |
5321 | the `isearch-terminators' variable are used to terminate an incremental | |
5322 | search. If that variable has not been assigned a value, the <ESC> and | |
28ef6c31 | 5323 | `C-J' characters will terminate an incremental search. `C-g' will |
bb70624e JA |
5324 | abort an incremental search and restore the original line. When the |
5325 | search is terminated, the history entry containing the search string | |
5326 | becomes the current line. | |
5327 | ||
28ef6c31 JA |
5328 | To find other matching entries in the history list, type `C-r' or |
5329 | `C-s' as appropriate. This will search backward or forward in the | |
bb70624e JA |
5330 | history for the next entry matching the search string typed so far. |
5331 | Any other key sequence bound to a Readline command will terminate the | |
5332 | search and execute that command. For instance, a <RET> will terminate | |
5333 | the search and accept the line, thereby executing the command from the | |
28ef6c31 JA |
5334 | history list. A movement command will terminate the search, make the |
5335 | last line found the current line, and begin editing. | |
ccc6cda3 JA |
5336 | |
5337 | Non-incremental searches read the entire search string before | |
5338 | starting to search for matching history lines. The search string may be | |
cce855bc | 5339 | typed by the user or be part of the contents of the current line. |
ccc6cda3 JA |
5340 | |
5341 | \1f | |
5342 | File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing | |
5343 | ||
5344 | Readline Init File | |
5345 | ================== | |
5346 | ||
bb70624e | 5347 | Although the Readline library comes with a set of Emacs-like |
cce855bc JA |
5348 | keybindings installed by default, it is possible to use a different set |
5349 | of keybindings. Any user can customize programs that use Readline by | |
bb70624e JA |
5350 | putting commands in an "inputrc" file, conventionally in his home |
5351 | directory. The name of this file is taken from the value of the shell | |
5352 | variable `INPUTRC'. If that variable is unset, the default is | |
5353 | `~/.inputrc'. | |
ccc6cda3 JA |
5354 | |
5355 | When a program which uses the Readline library starts up, the init | |
5356 | file is read, and the key bindings are set. | |
5357 | ||
5358 | In addition, the `C-x C-r' command re-reads this init file, thus | |
5359 | incorporating any changes that you might have made to it. | |
5360 | ||
5361 | * Menu: | |
5362 | ||
5363 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
5364 | ||
5365 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
5366 | ||
5367 | * Sample Init File:: An example inputrc file. | |
5368 | ||
5369 | \1f | |
5370 | File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File | |
5371 | ||
5372 | Readline Init File Syntax | |
5373 | ------------------------- | |
5374 | ||
5375 | There are only a few basic constructs allowed in the Readline init | |
5376 | file. Blank lines are ignored. Lines beginning with a `#' are | |
5377 | comments. Lines beginning with a `$' indicate conditional constructs | |
28ef6c31 | 5378 | (*note Conditional Init Constructs::). Other lines denote variable |
ccc6cda3 JA |
5379 | settings and key bindings. |
5380 | ||
5381 | Variable Settings | |
cce855bc JA |
5382 | You can modify the run-time behavior of Readline by altering the |
5383 | values of variables in Readline using the `set' command within the | |
28ef6c31 JA |
5384 | init file. The syntax is simple: |
5385 | ||
5386 | set VARIABLE VALUE | |
5387 | ||
5388 | Here, for example, is how to change from the default Emacs-like | |
5389 | key binding to use `vi' line editing commands: | |
ccc6cda3 JA |
5390 | |
5391 | set editing-mode vi | |
5392 | ||
28ef6c31 JA |
5393 | Variable names and values, where appropriate, are recognized |
5394 | without regard to case. | |
5395 | ||
bb70624e JA |
5396 | The `bind -V' command lists the current Readline variable names |
5397 | and values. *Note Bash Builtins::. | |
5398 | ||
cce855bc JA |
5399 | A great deal of run-time behavior is changeable with the following |
5400 | variables. | |
ccc6cda3 JA |
5401 | |
5402 | `bell-style' | |
5403 | Controls what happens when Readline wants to ring the | |
5404 | terminal bell. If set to `none', Readline never rings the | |
5405 | bell. If set to `visible', Readline uses a visible bell if | |
5406 | one is available. If set to `audible' (the default), | |
5407 | Readline attempts to ring the terminal's bell. | |
5408 | ||
5409 | `comment-begin' | |
5410 | The string to insert at the beginning of the line when the | |
5411 | `insert-comment' command is executed. The default value is | |
5412 | `"#"'. | |
5413 | ||
cce855bc JA |
5414 | `completion-ignore-case' |
5415 | If set to `on', Readline performs filename matching and | |
5416 | completion in a case-insensitive fashion. The default value | |
5417 | is `off'. | |
5418 | ||
ccc6cda3 JA |
5419 | `completion-query-items' |
5420 | The number of possible completions that determines when the | |
5421 | user is asked whether he wants to see the list of | |
5422 | possibilities. If the number of possible completions is | |
5423 | greater than this value, Readline will ask the user whether | |
5424 | or not he wishes to view them; otherwise, they are simply | |
28ef6c31 JA |
5425 | listed. This variable must be set to an integer value |
5426 | greater than or equal to 0. The default limit is `100'. | |
ccc6cda3 JA |
5427 | |
5428 | `convert-meta' | |
5429 | If set to `on', Readline will convert characters with the | |
cce855bc | 5430 | eighth bit set to an ASCII key sequence by stripping the |
bb70624e | 5431 | eighth bit and prefixing an <ESC> character, converting them |
cce855bc | 5432 | to a meta-prefixed key sequence. The default value is `on'. |
ccc6cda3 JA |
5433 | |
5434 | `disable-completion' | |
cce855bc | 5435 | If set to `On', Readline will inhibit word completion. |
ccc6cda3 JA |
5436 | Completion characters will be inserted into the line as if |
5437 | they had been mapped to `self-insert'. The default is `off'. | |
5438 | ||
5439 | `editing-mode' | |
cce855bc JA |
5440 | The `editing-mode' variable controls which default set of key |
5441 | bindings is used. By default, Readline starts up in Emacs | |
5442 | editing mode, where the keystrokes are most similar to Emacs. | |
5443 | This variable can be set to either `emacs' or `vi'. | |
ccc6cda3 JA |
5444 | |
5445 | `enable-keypad' | |
cce855bc | 5446 | When set to `on', Readline will try to enable the application |
ccc6cda3 JA |
5447 | keypad when it is called. Some systems need this to enable |
5448 | the arrow keys. The default is `off'. | |
5449 | ||
5450 | `expand-tilde' | |
5451 | If set to `on', tilde expansion is performed when Readline | |
5452 | attempts word completion. The default is `off'. | |
5453 | ||
5454 | `horizontal-scroll-mode' | |
5455 | This variable can be set to either `on' or `off'. Setting it | |
cce855bc | 5456 | to `on' means that the text of the lines being edited will |
ccc6cda3 JA |
5457 | scroll horizontally on a single screen line when they are |
5458 | longer than the width of the screen, instead of wrapping onto | |
5459 | a new screen line. By default, this variable is set to `off'. | |
5460 | ||
b72432fd JA |
5461 | `input-meta' |
5462 | If set to `on', Readline will enable eight-bit input (it will | |
28ef6c31 | 5463 | not clear the eighth bit in the characters it reads), |
b72432fd JA |
5464 | regardless of what the terminal claims it can support. The |
5465 | default value is `off'. The name `meta-flag' is a synonym | |
5466 | for this variable. | |
5467 | ||
5468 | `isearch-terminators' | |
5469 | The string of characters that should terminate an incremental | |
5470 | search without subsequently executing the character as a | |
28ef6c31 JA |
5471 | command (*note Searching::). If this variable has not been |
5472 | given a value, the characters <ESC> and `C-J' will terminate | |
b72432fd JA |
5473 | an incremental search. |
5474 | ||
ccc6cda3 JA |
5475 | `keymap' |
5476 | Sets Readline's idea of the current keymap for key binding | |
5477 | commands. Acceptable `keymap' names are `emacs', | |
28ef6c31 | 5478 | `emacs-standard', `emacs-meta', `emacs-ctlx', `vi', `vi-move', |
ccc6cda3 JA |
5479 | `vi-command', and `vi-insert'. `vi' is equivalent to |
5480 | `vi-command'; `emacs' is equivalent to `emacs-standard'. The | |
5481 | default value is `emacs'. The value of the `editing-mode' | |
5482 | variable also affects the default keymap. | |
5483 | ||
5484 | `mark-directories' | |
5485 | If set to `on', completed directory names have a slash | |
5486 | appended. The default is `on'. | |
5487 | ||
5488 | `mark-modified-lines' | |
cce855bc JA |
5489 | This variable, when set to `on', causes Readline to display an |
5490 | asterisk (`*') at the start of history lines which have been | |
5491 | modified. This variable is `off' by default. | |
ccc6cda3 | 5492 | |
ccc6cda3 JA |
5493 | `output-meta' |
5494 | If set to `on', Readline will display characters with the | |
5495 | eighth bit set directly rather than as a meta-prefixed escape | |
5496 | sequence. The default is `off'. | |
5497 | ||
cce855bc JA |
5498 | `print-completions-horizontally' |
5499 | If set to `on', Readline will display completions with matches | |
5500 | sorted horizontally in alphabetical order, rather than down | |
5501 | the screen. The default is `off'. | |
5502 | ||
ccc6cda3 JA |
5503 | `show-all-if-ambiguous' |
5504 | This alters the default behavior of the completion functions. | |
5505 | If set to `on', words which have more than one possible | |
5506 | completion cause the matches to be listed immediately instead | |
5507 | of ringing the bell. The default value is `off'. | |
5508 | ||
5509 | `visible-stats' | |
5510 | If set to `on', a character denoting a file's type is | |
5511 | appended to the filename when listing possible completions. | |
5512 | The default is `off'. | |
5513 | ||
5514 | Key Bindings | |
5515 | The syntax for controlling key bindings in the init file is | |
bb70624e | 5516 | simple. First you need to find the name of the command that you |
cce855bc JA |
5517 | want to change. The following sections contain tables of the |
5518 | command name, the default keybinding, if any, and a short | |
5519 | description of what the command does. | |
ccc6cda3 | 5520 | |
28ef6c31 JA |
5521 | Once you know the name of the command, simply place on a line in |
5522 | the init file the name of the key you wish to bind the command to, | |
5523 | a colon, and then the name of the command. The name of the key | |
5524 | can be expressed in different ways, depending on what you find most | |
5525 | comfortable. | |
5526 | ||
5527 | In addition to command names, readline allows keys to be bound to | |
5528 | a string that is inserted when the key is pressed (a MACRO). | |
ccc6cda3 | 5529 | |
bb70624e JA |
5530 | The `bind -p' command displays Readline function names and |
5531 | bindings in a format that can put directly into an initialization | |
5532 | file. *Note Bash Builtins::. | |
5533 | ||
ccc6cda3 JA |
5534 | KEYNAME: FUNCTION-NAME or MACRO |
5535 | KEYNAME is the name of a key spelled out in English. For | |
5536 | example: | |
5537 | Control-u: universal-argument | |
5538 | Meta-Rubout: backward-kill-word | |
5539 | Control-o: "> output" | |
5540 | ||
28ef6c31 JA |
5541 | In the above example, `C-u' is bound to the function |
5542 | `universal-argument', `M-DEL' is bound to the function | |
5543 | `backward-kill-word', and `C-o' is bound to run the macro | |
ccc6cda3 JA |
5544 | expressed on the right hand side (that is, to insert the text |
5545 | `> output' into the line). | |
5546 | ||
28ef6c31 JA |
5547 | A number of symbolic character names are recognized while |
5548 | processing this key binding syntax: DEL, ESC, ESCAPE, LFD, | |
5549 | NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB. | |
5550 | ||
ccc6cda3 JA |
5551 | "KEYSEQ": FUNCTION-NAME or MACRO |
5552 | KEYSEQ differs from KEYNAME above in that strings denoting an | |
5553 | entire key sequence can be specified, by placing the key | |
5554 | sequence in double quotes. Some GNU Emacs style key escapes | |
5555 | can be used, as in the following example, but the special | |
5556 | character names are not recognized. | |
5557 | ||
5558 | "\C-u": universal-argument | |
5559 | "\C-x\C-r": re-read-init-file | |
5560 | "\e[11~": "Function Key 1" | |
5561 | ||
28ef6c31 | 5562 | In the above example, `C-u' is again bound to the function |
ccc6cda3 | 5563 | `universal-argument' (just as it was in the first example), |
28ef6c31 JA |
5564 | `C-x C-r' is bound to the function `re-read-init-file', and |
5565 | `<ESC> <[> <1> <1> <~>' is bound to insert the text `Function | |
5566 | Key 1'. | |
cce855bc JA |
5567 | |
5568 | The following GNU Emacs style escape sequences are available when | |
5569 | specifying key sequences: | |
5570 | ||
5571 | `\C-' | |
5572 | control prefix | |
5573 | ||
5574 | `\M-' | |
5575 | meta prefix | |
5576 | ||
5577 | `\e' | |
5578 | an escape character | |
5579 | ||
5580 | `\\' | |
5581 | backslash | |
5582 | ||
5583 | `\"' | |
bb70624e | 5584 | <">, a double quotation mark |
cce855bc JA |
5585 | |
5586 | `\'' | |
bb70624e | 5587 | <'>, a single quote or apostrophe |
cce855bc JA |
5588 | |
5589 | In addition to the GNU Emacs style escape sequences, a second set | |
5590 | of backslash escapes is available: | |
ccc6cda3 | 5591 | |
cce855bc JA |
5592 | `\a' |
5593 | alert (bell) | |
5594 | ||
5595 | `\b' | |
5596 | backspace | |
5597 | ||
5598 | `\d' | |
5599 | delete | |
5600 | ||
5601 | `\f' | |
5602 | form feed | |
5603 | ||
5604 | `\n' | |
5605 | newline | |
ccc6cda3 | 5606 | |
cce855bc JA |
5607 | `\r' |
5608 | carriage return | |
ccc6cda3 | 5609 | |
cce855bc JA |
5610 | `\t' |
5611 | horizontal tab | |
ccc6cda3 | 5612 | |
cce855bc JA |
5613 | `\v' |
5614 | vertical tab | |
ccc6cda3 | 5615 | |
cce855bc | 5616 | `\NNN' |
28ef6c31 JA |
5617 | the character whose ASCII code is the octal value NNN (one to |
5618 | three digits) | |
ccc6cda3 | 5619 | |
cce855bc | 5620 | `\xNNN' |
28ef6c31 | 5621 | the character whose ASCII code is the hexadecimal value NNN |
cce855bc | 5622 | (one to three digits) |
ccc6cda3 | 5623 | |
cce855bc JA |
5624 | When entering the text of a macro, single or double quotes must be |
5625 | used to indicate a macro definition. Unquoted text is assumed to | |
5626 | be a function name. In the macro body, the backslash escapes | |
5627 | described above are expanded. Backslash will quote any other | |
5628 | character in the macro text, including `"' and `''. For example, | |
5629 | the following binding will make `C-x \' insert a single `\' into | |
5630 | the line: | |
5631 | "\C-x\\": "\\" | |
ccc6cda3 JA |
5632 | |
5633 | \1f | |
5634 | File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File | |
5635 | ||
5636 | Conditional Init Constructs | |
5637 | --------------------------- | |
5638 | ||
5639 | Readline implements a facility similar in spirit to the conditional | |
5640 | compilation features of the C preprocessor which allows key bindings | |
5641 | and variable settings to be performed as the result of tests. There | |
cce855bc | 5642 | are four parser directives used. |
ccc6cda3 JA |
5643 | |
5644 | `$if' | |
5645 | The `$if' construct allows bindings to be made based on the | |
5646 | editing mode, the terminal being used, or the application using | |
5647 | Readline. The text of the test extends to the end of the line; no | |
5648 | characters are required to isolate it. | |
5649 | ||
5650 | `mode' | |
5651 | The `mode=' form of the `$if' directive is used to test | |
5652 | whether Readline is in `emacs' or `vi' mode. This may be | |
5653 | used in conjunction with the `set keymap' command, for | |
5654 | instance, to set bindings in the `emacs-standard' and | |
5655 | `emacs-ctlx' keymaps only if Readline is starting out in | |
5656 | `emacs' mode. | |
5657 | ||
5658 | `term' | |
5659 | The `term=' form may be used to include terminal-specific key | |
5660 | bindings, perhaps to bind the key sequences output by the | |
5661 | terminal's function keys. The word on the right side of the | |
cce855bc JA |
5662 | `=' is tested against both the full name of the terminal and |
5663 | the portion of the terminal name before the first `-'. This | |
ccc6cda3 JA |
5664 | allows `sun' to match both `sun' and `sun-cmd', for instance. |
5665 | ||
5666 | `application' | |
5667 | The APPLICATION construct is used to include | |
5668 | application-specific settings. Each program using the | |
5669 | Readline library sets the APPLICATION NAME, and you can test | |
28ef6c31 JA |
5670 | for a particular value. This could be used to bind key |
5671 | sequences to functions useful for a specific program. For | |
5672 | instance, the following command adds a key sequence that | |
5673 | quotes the current or previous word in Bash: | |
ccc6cda3 JA |
5674 | $if Bash |
5675 | # Quote the current or previous word | |
5676 | "\C-xq": "\eb\"\ef\"" | |
5677 | $endif | |
5678 | ||
5679 | `$endif' | |
cce855bc JA |
5680 | This command, as seen in the previous example, terminates an `$if' |
5681 | command. | |
ccc6cda3 JA |
5682 | |
5683 | `$else' | |
5684 | Commands in this branch of the `$if' directive are executed if the | |
5685 | test fails. | |
5686 | ||
cce855bc JA |
5687 | `$include' |
5688 | This directive takes a single filename as an argument and reads | |
28ef6c31 JA |
5689 | commands and bindings from that file. For example, the following |
5690 | directive reads from `/etc/inputrc': | |
cce855bc JA |
5691 | $include /etc/inputrc |
5692 | ||
ccc6cda3 JA |
5693 | \1f |
5694 | File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File | |
5695 | ||
5696 | Sample Init File | |
5697 | ---------------- | |
5698 | ||
28ef6c31 | 5699 | Here is an example of an INPUTRC file. This illustrates key |
ccc6cda3 JA |
5700 | binding, variable assignment, and conditional syntax. |
5701 | ||
5702 | ||
5703 | # This file controls the behaviour of line input editing for | |
5704 | # programs that use the Gnu Readline library. Existing programs | |
5705 | # include FTP, Bash, and Gdb. | |
5706 | # | |
5707 | # You can re-read the inputrc file with C-x C-r. | |
5708 | # Lines beginning with '#' are comments. | |
cce855bc JA |
5709 | # |
5710 | # First, include any systemwide bindings and variable assignments from | |
5711 | # /etc/Inputrc | |
5712 | $include /etc/Inputrc | |
5713 | ||
ccc6cda3 JA |
5714 | # |
5715 | # Set various bindings for emacs mode. | |
5716 | ||
5717 | set editing-mode emacs | |
5718 | ||
5719 | $if mode=emacs | |
5720 | ||
5721 | Meta-Control-h: backward-kill-word Text after the function name is ignored | |
5722 | ||
5723 | # | |
5724 | # Arrow keys in keypad mode | |
5725 | # | |
d166f048 JA |
5726 | #"\M-OD": backward-char |
5727 | #"\M-OC": forward-char | |
5728 | #"\M-OA": previous-history | |
5729 | #"\M-OB": next-history | |
ccc6cda3 JA |
5730 | # |
5731 | # Arrow keys in ANSI mode | |
5732 | # | |
d166f048 JA |
5733 | "\M-[D": backward-char |
5734 | "\M-[C": forward-char | |
5735 | "\M-[A": previous-history | |
5736 | "\M-[B": next-history | |
ccc6cda3 JA |
5737 | # |
5738 | # Arrow keys in 8 bit keypad mode | |
5739 | # | |
d166f048 JA |
5740 | #"\M-\C-OD": backward-char |
5741 | #"\M-\C-OC": forward-char | |
5742 | #"\M-\C-OA": previous-history | |
5743 | #"\M-\C-OB": next-history | |
ccc6cda3 JA |
5744 | # |
5745 | # Arrow keys in 8 bit ANSI mode | |
5746 | # | |
d166f048 JA |
5747 | #"\M-\C-[D": backward-char |
5748 | #"\M-\C-[C": forward-char | |
5749 | #"\M-\C-[A": previous-history | |
5750 | #"\M-\C-[B": next-history | |
ccc6cda3 JA |
5751 | |
5752 | C-q: quoted-insert | |
5753 | ||
5754 | $endif | |
5755 | ||
5756 | # An old-style binding. This happens to be the default. | |
5757 | TAB: complete | |
5758 | ||
5759 | # Macros that are convenient for shell interaction | |
5760 | $if Bash | |
5761 | # edit the path | |
5762 | "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f" | |
5763 | # prepare to type a quoted word -- insert open and close double quotes | |
5764 | # and move to just after the open quote | |
5765 | "\C-x\"": "\"\"\C-b" | |
5766 | # insert a backslash (testing backslash escapes in sequences and macros) | |
5767 | "\C-x\\": "\\" | |
5768 | # Quote the current or previous word | |
5769 | "\C-xq": "\eb\"\ef\"" | |
5770 | # Add a binding to refresh the line, which is unbound | |
5771 | "\C-xr": redraw-current-line | |
5772 | # Edit variable on current line. | |
5773 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
5774 | $endif | |
5775 | ||
5776 | # use a visible bell if one is available | |
5777 | set bell-style visible | |
5778 | ||
5779 | # don't strip characters to 7 bits when reading | |
5780 | set input-meta on | |
5781 | ||
5782 | # allow iso-latin1 characters to be inserted rather than converted to | |
5783 | # prefix-meta sequences | |
5784 | set convert-meta off | |
5785 | ||
5786 | # display characters with the eighth bit set directly rather than | |
5787 | # as meta-prefixed characters | |
5788 | set output-meta on | |
5789 | ||
5790 | # if there are more than 150 possible completions for a word, ask the | |
5791 | # user if he wants to see all of them | |
5792 | set completion-query-items 150 | |
5793 | ||
5794 | # For FTP | |
5795 | $if Ftp | |
5796 | "\C-xg": "get \M-?" | |
5797 | "\C-xt": "put \M-?" | |
5798 | "\M-.": yank-last-arg | |
5799 | $endif | |
5800 | ||
5801 | \1f | |
bb70624e JA |
5802 | File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing |
5803 | ||
5804 | Bindable Readline Commands | |
5805 | ========================== | |
5806 | ||
5807 | * Menu: | |
5808 | ||
5809 | * Commands For Moving:: Moving about the line. | |
5810 | * Commands For History:: Getting at previous lines. | |
5811 | * Commands For Text:: Commands for changing text. | |
5812 | * Commands For Killing:: Commands for killing and yanking. | |
5813 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
5814 | * Commands For Completion:: Getting Readline to do the typing for you. | |
5815 | * Keyboard Macros:: Saving and re-executing typed characters | |
5816 | * Miscellaneous Commands:: Other miscellaneous commands. | |
5817 | ||
5818 | This section describes Readline commands that may be bound to key | |
5819 | sequences. You can list your key bindings by executing `bind -P' or, | |
5820 | for a more terse format, suitable for an INPUTRC file, `bind -p'. | |
28ef6c31 JA |
5821 | (*Note Bash Builtins::.) Command names without an accompanying key |
5822 | sequence are unbound by default. | |
bb70624e | 5823 | |
28ef6c31 JA |
5824 | In the following descriptions, "point" refers to the current cursor |
5825 | position, and "mark" refers to a cursor position saved by the | |
bb70624e | 5826 | `set-mark' command. The text between the point and mark is referred to |
28ef6c31 | 5827 | as the "region". |
bb70624e JA |
5828 | |
5829 | \1f | |
5830 | File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands | |
5831 | ||
5832 | Commands For Moving | |
5833 | ------------------- | |
5834 | ||
5835 | `beginning-of-line (C-a)' | |
5836 | Move to the start of the current line. | |
5837 | ||
5838 | `end-of-line (C-e)' | |
5839 | Move to the end of the line. | |
5840 | ||
5841 | `forward-char (C-f)' | |
5842 | Move forward a character. | |
5843 | ||
5844 | `backward-char (C-b)' | |
5845 | Move back a character. | |
5846 | ||
5847 | `forward-word (M-f)' | |
5848 | Move forward to the end of the next word. Words are composed of | |
5849 | letters and digits. | |
5850 | ||
5851 | `backward-word (M-b)' | |
5852 | Move back to the start of the current or previous word. Words are | |
5853 | composed of letters and digits. | |
5854 | ||
5855 | `clear-screen (C-l)' | |
5856 | Clear the screen and redraw the current line, leaving the current | |
5857 | line at the top of the screen. | |
5858 | ||
5859 | `redraw-current-line ()' | |
5860 | Refresh the current line. By default, this is unbound. | |
5861 | ||
5862 | \1f | |
5863 | File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands | |
5864 | ||
5865 | Commands For Manipulating The History | |
5866 | ------------------------------------- | |
5867 | ||
28ef6c31 | 5868 | `accept-line (Newline or Return)' |
bb70624e JA |
5869 | Accept the line regardless of where the cursor is. If this line is |
5870 | non-empty, add it to the history list according to the setting of | |
28ef6c31 JA |
5871 | the `HISTCONTROL' and `HISTIGNORE' variables. If this line is a |
5872 | modified history line, then restore the history line to its | |
5873 | original state. | |
bb70624e JA |
5874 | |
5875 | `previous-history (C-p)' | |
28ef6c31 JA |
5876 | Move `back' through the history list, fetching the previous |
5877 | command. | |
bb70624e JA |
5878 | |
5879 | `next-history (C-n)' | |
28ef6c31 | 5880 | Move `forward' through the history list, fetching the next command. |
bb70624e JA |
5881 | |
5882 | `beginning-of-history (M-<)' | |
5883 | Move to the first line in the history. | |
5884 | ||
5885 | `end-of-history (M->)' | |
5886 | Move to the end of the input history, i.e., the line currently | |
5887 | being entered. | |
5888 | ||
5889 | `reverse-search-history (C-r)' | |
5890 | Search backward starting at the current line and moving `up' | |
5891 | through the history as necessary. This is an incremental search. | |
5892 | ||
5893 | `forward-search-history (C-s)' | |
5894 | Search forward starting at the current line and moving `down' | |
5895 | through the the history as necessary. This is an incremental | |
5896 | search. | |
5897 | ||
5898 | `non-incremental-reverse-search-history (M-p)' | |
5899 | Search backward starting at the current line and moving `up' | |
5900 | through the history as necessary using a non-incremental search | |
5901 | for a string supplied by the user. | |
5902 | ||
5903 | `non-incremental-forward-search-history (M-n)' | |
5904 | Search forward starting at the current line and moving `down' | |
5905 | through the the history as necessary using a non-incremental search | |
5906 | for a string supplied by the user. | |
5907 | ||
5908 | `history-search-forward ()' | |
5909 | Search forward through the history for the string of characters | |
5910 | between the start of the current line and the point. This is a | |
5911 | non-incremental search. By default, this command is unbound. | |
5912 | ||
5913 | `history-search-backward ()' | |
5914 | Search backward through the history for the string of characters | |
5915 | between the start of the current line and the point. This is a | |
5916 | non-incremental search. By default, this command is unbound. | |
5917 | ||
5918 | `yank-nth-arg (M-C-y)' | |
5919 | Insert the first argument to the previous command (usually the | |
28ef6c31 JA |
5920 | second word on the previous line) at point. With an argument N, |
5921 | insert the Nth word from the previous command (the words in the | |
5922 | previous command begin with word 0). A negative argument inserts | |
5923 | the Nth word from the end of the previous command. | |
bb70624e | 5924 | |
28ef6c31 | 5925 | `yank-last-arg (M-. or M-_)' |
bb70624e JA |
5926 | Insert last argument to the previous command (the last word of the |
5927 | previous history entry). With an argument, behave exactly like | |
5928 | `yank-nth-arg'. Successive calls to `yank-last-arg' move back | |
5929 | through the history list, inserting the last argument of each line | |
5930 | in turn. | |
5931 | ||
5932 | \1f | |
5933 | File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands | |
5934 | ||
5935 | Commands For Changing Text | |
5936 | -------------------------- | |
5937 | ||
5938 | `delete-char (C-d)' | |
28ef6c31 JA |
5939 | Delete the character at point. If point is at the beginning of |
5940 | the line, there are no characters in the line, and the last | |
5941 | character typed was not bound to `delete-char', then return EOF. | |
bb70624e JA |
5942 | |
5943 | `backward-delete-char (Rubout)' | |
5944 | Delete the character behind the cursor. A numeric argument means | |
5945 | to kill the characters instead of deleting them. | |
5946 | ||
5947 | `forward-backward-delete-char ()' | |
5948 | Delete the character under the cursor, unless the cursor is at the | |
5949 | end of the line, in which case the character behind the cursor is | |
5950 | deleted. By default, this is not bound to a key. | |
5951 | ||
28ef6c31 | 5952 | `quoted-insert (C-q or C-v)' |
bb70624e | 5953 | Add the next character typed to the line verbatim. This is how to |
28ef6c31 | 5954 | insert key sequences like `C-q', for example. |
bb70624e JA |
5955 | |
5956 | `self-insert (a, b, A, 1, !, ...)' | |
5957 | Insert yourself. | |
5958 | ||
5959 | `transpose-chars (C-t)' | |
5960 | Drag the character before the cursor forward over the character at | |
5961 | the cursor, moving the cursor forward as well. If the insertion | |
5962 | point is at the end of the line, then this transposes the last two | |
5963 | characters of the line. Negative arguments have no effect. | |
5964 | ||
5965 | `transpose-words (M-t)' | |
5966 | Drag the word before point past the word after point, moving point | |
5967 | past that word as well. | |
5968 | ||
5969 | `upcase-word (M-u)' | |
5970 | Uppercase the current (or following) word. With a negative | |
5971 | argument, uppercase the previous word, but do not move the cursor. | |
5972 | ||
5973 | `downcase-word (M-l)' | |
5974 | Lowercase the current (or following) word. With a negative | |
5975 | argument, lowercase the previous word, but do not move the cursor. | |
5976 | ||
5977 | `capitalize-word (M-c)' | |
5978 | Capitalize the current (or following) word. With a negative | |
5979 | argument, capitalize the previous word, but do not move the cursor. | |
5980 | ||
5981 | \1f | |
5982 | File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands | |
5983 | ||
5984 | Killing And Yanking | |
5985 | ------------------- | |
5986 | ||
5987 | `kill-line (C-k)' | |
5988 | Kill the text from point to the end of the line. | |
5989 | ||
5990 | `backward-kill-line (C-x Rubout)' | |
5991 | Kill backward to the beginning of the line. | |
5992 | ||
5993 | `unix-line-discard (C-u)' | |
5994 | Kill backward from the cursor to the beginning of the current line. | |
5995 | ||
5996 | `kill-whole-line ()' | |
28ef6c31 JA |
5997 | Kill all characters on the current line, no matter where point is. |
5998 | By default, this is unbound. | |
bb70624e JA |
5999 | |
6000 | `kill-word (M-d)' | |
6001 | Kill from point to the end of the current word, or if between | |
6002 | words, to the end of the next word. Word boundaries are the same | |
6003 | as `forward-word'. | |
6004 | ||
28ef6c31 | 6005 | `backward-kill-word (M-<DEL>)' |
bb70624e JA |
6006 | Kill the word behind point. Word boundaries are the same as |
6007 | `backward-word'. | |
6008 | ||
6009 | `unix-word-rubout (C-w)' | |
6010 | Kill the word behind point, using white space as a word boundary. | |
6011 | The killed text is saved on the kill-ring. | |
6012 | ||
6013 | `delete-horizontal-space ()' | |
6014 | Delete all spaces and tabs around point. By default, this is | |
6015 | unbound. | |
6016 | ||
6017 | `kill-region ()' | |
6018 | Kill the text in the current region. By default, this command is | |
6019 | unbound. | |
6020 | ||
6021 | `copy-region-as-kill ()' | |
6022 | Copy the text in the region to the kill buffer, so it can be yanked | |
6023 | right away. By default, this command is unbound. | |
6024 | ||
6025 | `copy-backward-word ()' | |
6026 | Copy the word before point to the kill buffer. The word | |
6027 | boundaries are the same as `backward-word'. By default, this | |
6028 | command is unbound. | |
6029 | ||
6030 | `copy-forward-word ()' | |
6031 | Copy the word following point to the kill buffer. The word | |
6032 | boundaries are the same as `forward-word'. By default, this | |
6033 | command is unbound. | |
6034 | ||
6035 | `yank (C-y)' | |
28ef6c31 | 6036 | Yank the top of the kill ring into the buffer at point. |
bb70624e JA |
6037 | |
6038 | `yank-pop (M-y)' | |
6039 | Rotate the kill-ring, and yank the new top. You can only do this | |
28ef6c31 | 6040 | if the prior command is `yank' or `yank-pop'. |
bb70624e JA |
6041 | |
6042 | \1f | |
6043 | File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands | |
6044 | ||
6045 | Specifying Numeric Arguments | |
6046 | ---------------------------- | |
6047 | ||
6048 | `digit-argument (M-0, M-1, ... M--)' | |
6049 | Add this digit to the argument already accumulating, or start a new | |
28ef6c31 | 6050 | argument. `M--' starts a negative argument. |
bb70624e JA |
6051 | |
6052 | `universal-argument ()' | |
6053 | This is another way to specify an argument. If this command is | |
6054 | followed by one or more digits, optionally with a leading minus | |
6055 | sign, those digits define the argument. If the command is | |
6056 | followed by digits, executing `universal-argument' again ends the | |
6057 | numeric argument, but is otherwise ignored. As a special case, if | |
6058 | this command is immediately followed by a character that is | |
6059 | neither a digit or minus sign, the argument count for the next | |
6060 | command is multiplied by four. The argument count is initially | |
6061 | one, so executing this function the first time makes the argument | |
6062 | count four, a second time makes the argument count sixteen, and so | |
6063 | on. By default, this is not bound to a key. | |
6064 | ||
6065 | \1f | |
6066 | File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands | |
6067 | ||
6068 | Letting Readline Type For You | |
6069 | ----------------------------- | |
6070 | ||
28ef6c31 JA |
6071 | `complete (<TAB>)' |
6072 | Attempt to perform completion on the text before point. The | |
6073 | actual completion performed is application-specific. Bash | |
6074 | attempts completion treating the text as a variable (if the text | |
6075 | begins with `$'), username (if the text begins with `~'), hostname | |
6076 | (if the text begins with `@'), or command (including aliases and | |
6077 | functions) in turn. If none of these produces a match, filename | |
6078 | completion is attempted. | |
bb70624e JA |
6079 | |
6080 | `possible-completions (M-?)' | |
28ef6c31 | 6081 | List the possible completions of the text before point. |
bb70624e JA |
6082 | |
6083 | `insert-completions (M-*)' | |
6084 | Insert all completions of the text before point that would have | |
6085 | been generated by `possible-completions'. | |
6086 | ||
6087 | `menu-complete ()' | |
6088 | Similar to `complete', but replaces the word to be completed with | |
6089 | a single match from the list of possible completions. Repeated | |
6090 | execution of `menu-complete' steps through the list of possible | |
6091 | completions, inserting each match in turn. At the end of the list | |
28ef6c31 JA |
6092 | of completions, the bell is rung (subject to the setting of |
6093 | `bell-style') and the original text is restored. An argument of N | |
6094 | moves N positions forward in the list of matches; a negative | |
6095 | argument may be used to move backward through the list. This | |
6096 | command is intended to be bound to <TAB>, but is unbound by | |
bb70624e JA |
6097 | default. |
6098 | ||
6099 | `delete-char-or-list ()' | |
6100 | Deletes the character under the cursor if not at the beginning or | |
6101 | end of the line (like `delete-char'). If at the end of the line, | |
6102 | behaves identically to `possible-completions'. This command is | |
6103 | unbound by default. | |
6104 | ||
6105 | `complete-filename (M-/)' | |
6106 | Attempt filename completion on the text before point. | |
6107 | ||
6108 | `possible-filename-completions (C-x /)' | |
6109 | List the possible completions of the text before point, treating | |
6110 | it as a filename. | |
6111 | ||
6112 | `complete-username (M-~)' | |
6113 | Attempt completion on the text before point, treating it as a | |
6114 | username. | |
6115 | ||
6116 | `possible-username-completions (C-x ~)' | |
6117 | List the possible completions of the text before point, treating | |
6118 | it as a username. | |
6119 | ||
6120 | `complete-variable (M-$)' | |
6121 | Attempt completion on the text before point, treating it as a | |
6122 | shell variable. | |
6123 | ||
6124 | `possible-variable-completions (C-x $)' | |
6125 | List the possible completions of the text before point, treating | |
6126 | it as a shell variable. | |
6127 | ||
6128 | `complete-hostname (M-@)' | |
6129 | Attempt completion on the text before point, treating it as a | |
6130 | hostname. | |
6131 | ||
6132 | `possible-hostname-completions (C-x @)' | |
6133 | List the possible completions of the text before point, treating | |
6134 | it as a hostname. | |
6135 | ||
6136 | `complete-command (M-!)' | |
6137 | Attempt completion on the text before point, treating it as a | |
6138 | command name. Command completion attempts to match the text | |
6139 | against aliases, reserved words, shell functions, shell builtins, | |
6140 | and finally executable filenames, in that order. | |
6141 | ||
6142 | `possible-command-completions (C-x !)' | |
6143 | List the possible completions of the text before point, treating | |
6144 | it as a command name. | |
6145 | ||
28ef6c31 | 6146 | `dynamic-complete-history (M-<TAB>)' |
bb70624e JA |
6147 | Attempt completion on the text before point, comparing the text |
6148 | against lines from the history list for possible completion | |
6149 | matches. | |
6150 | ||
6151 | `complete-into-braces (M-{)' | |
6152 | Perform filename completion and insert the list of possible | |
6153 | completions enclosed within braces so the list is available to the | |
28ef6c31 | 6154 | shell (*note Brace Expansion::). |
bb70624e JA |
6155 | |
6156 | \1f | |
6157 | File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands | |
6158 | ||
6159 | Keyboard Macros | |
6160 | --------------- | |
6161 | ||
6162 | `start-kbd-macro (C-x ()' | |
6163 | Begin saving the characters typed into the current keyboard macro. | |
6164 | ||
6165 | `end-kbd-macro (C-x ))' | |
6166 | Stop saving the characters typed into the current keyboard macro | |
6167 | and save the definition. | |
6168 | ||
6169 | `call-last-kbd-macro (C-x e)' | |
6170 | Re-execute the last keyboard macro defined, by making the | |
6171 | characters in the macro appear as if typed at the keyboard. | |
6172 | ||
6173 | \1f | |
6174 | File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands | |
6175 | ||
6176 | Some Miscellaneous Commands | |
6177 | --------------------------- | |
6178 | ||
6179 | `re-read-init-file (C-x C-r)' | |
6180 | Read in the contents of the INPUTRC file, and incorporate any | |
6181 | bindings or variable assignments found there. | |
6182 | ||
6183 | `abort (C-g)' | |
6184 | Abort the current editing command and ring the terminal's bell | |
6185 | (subject to the setting of `bell-style'). | |
6186 | ||
6187 | `do-uppercase-version (M-a, M-b, M-X, ...)' | |
6188 | If the metafied character X is lowercase, run the command that is | |
6189 | bound to the corresponding uppercase character. | |
6190 | ||
28ef6c31 JA |
6191 | `prefix-meta (<ESC>)' |
6192 | Metafy the next character typed. This is for keyboards without a | |
6193 | meta key. Typing `<ESC> f' is equivalent to typing `M-f'. | |
bb70624e | 6194 | |
28ef6c31 | 6195 | `undo (C-_ or C-x C-u)' |
bb70624e JA |
6196 | Incremental undo, separately remembered for each line. |
6197 | ||
6198 | `revert-line (M-r)' | |
6199 | Undo all changes made to this line. This is like executing the | |
6200 | `undo' command enough times to get back to the beginning. | |
6201 | ||
6202 | `tilde-expand (M-&)' | |
6203 | Perform tilde expansion on the current word. | |
6204 | ||
6205 | `set-mark (C-@)' | |
28ef6c31 JA |
6206 | Set the mark to the point. If a numeric argument is supplied, the |
6207 | mark is set to that position. | |
bb70624e JA |
6208 | |
6209 | `exchange-point-and-mark (C-x C-x)' | |
6210 | Swap the point with the mark. The current cursor position is set | |
6211 | to the saved position, and the old cursor position is saved as the | |
6212 | mark. | |
6213 | ||
6214 | `character-search (C-])' | |
6215 | A character is read and point is moved to the next occurrence of | |
6216 | that character. A negative count searches for previous | |
6217 | occurrences. | |
6218 | ||
6219 | `character-search-backward (M-C-])' | |
6220 | A character is read and point is moved to the previous occurrence | |
6221 | of that character. A negative count searches for subsequent | |
6222 | occurrences. | |
6223 | ||
6224 | `insert-comment (M-#)' | |
6225 | The value of the `comment-begin' variable is inserted at the | |
6226 | beginning of the current line, and the line is accepted as if a | |
6227 | newline had been typed. The default value of `comment-begin' | |
6228 | causes this command to make the current line a shell comment. | |
6229 | ||
6230 | `dump-functions ()' | |
6231 | Print all of the functions and their key bindings to the Readline | |
6232 | output stream. If a numeric argument is supplied, the output is | |
6233 | formatted in such a way that it can be made part of an INPUTRC | |
6234 | file. This command is unbound by default. | |
6235 | ||
6236 | `dump-variables ()' | |
6237 | Print all of the settable variables and their values to the | |
6238 | Readline output stream. If a numeric argument is supplied, the | |
6239 | output is formatted in such a way that it can be made part of an | |
6240 | INPUTRC file. This command is unbound by default. | |
6241 | ||
6242 | `dump-macros ()' | |
6243 | Print all of the Readline key sequences bound to macros and the | |
28ef6c31 JA |
6244 | strings they output. If a numeric argument is supplied, the |
6245 | output is formatted in such a way that it can be made part of an | |
6246 | INPUTRC file. This command is unbound by default. | |
bb70624e JA |
6247 | |
6248 | `glob-expand-word (C-x *)' | |
6249 | The word before point is treated as a pattern for pathname | |
6250 | expansion, and the list of matching file names is inserted, | |
6251 | replacing the word. | |
6252 | ||
6253 | `glob-list-expansions (C-x g)' | |
6254 | The list of expansions that would have been generated by | |
6255 | `glob-expand-word' is displayed, and the line is redrawn. | |
6256 | ||
6257 | `display-shell-version (C-x C-v)' | |
6258 | Display version information about the current instance of Bash. | |
6259 | ||
6260 | `shell-expand-line (M-C-e)' | |
6261 | Expand the line as the shell does. This performs alias and | |
6262 | history expansion as well as all of the shell word expansions | |
28ef6c31 | 6263 | (*note Shell Expansions::). |
bb70624e JA |
6264 | |
6265 | `history-expand-line (M-^)' | |
6266 | Perform history expansion on the current line. | |
6267 | ||
6268 | `magic-space ()' | |
6269 | Perform history expansion on the current line and insert a space | |
28ef6c31 | 6270 | (*note History Interaction::). |
bb70624e JA |
6271 | |
6272 | `alias-expand-line ()' | |
28ef6c31 | 6273 | Perform alias expansion on the current line (*note Aliases::). |
bb70624e JA |
6274 | |
6275 | `history-and-alias-expand-line ()' | |
6276 | Perform history and alias expansion on the current line. | |
6277 | ||
28ef6c31 | 6278 | `insert-last-argument (M-. or M-_)' |
bb70624e JA |
6279 | A synonym for `yank-last-arg'. |
6280 | ||
6281 | `operate-and-get-next (C-o)' | |
6282 | Accept the current line for execution and fetch the next line | |
6283 | relative to the current line from the history for editing. Any | |
6284 | argument is ignored. | |
6285 | ||
6286 | `emacs-editing-mode (C-e)' | |
6287 | When in `vi' editing mode, this causes a switch back to `emacs' | |
6288 | editing mode, as if the command `set -o emacs' had been executed. | |
6289 | ||
6290 | \1f | |
6291 | File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing | |
6292 | ||
6293 | Readline vi Mode | |
6294 | ================ | |
6295 | ||
6296 | While the Readline library does not have a full set of `vi' editing | |
6297 | functions, it does contain enough to allow simple editing of the line. | |
6298 | The Readline `vi' mode behaves as specified in the POSIX 1003.2 | |
6299 | standard. | |
6300 | ||
6301 | In order to switch interactively between `emacs' and `vi' editing | |
6302 | modes, use the `set -o emacs' and `set -o vi' commands (*note The Set | |
28ef6c31 | 6303 | Builtin::). The Readline default is `emacs' mode. |
bb70624e JA |
6304 | |
6305 | When you enter a line in `vi' mode, you are already placed in | |
6306 | `insertion' mode, as if you had typed an `i'. Pressing <ESC> switches | |
6307 | you into `command' mode, where you can edit the text of the line with | |
6308 | the standard `vi' movement keys, move to previous history lines with | |
6309 | `k' and subsequent lines with `j', and so forth. | |
6310 | ||
6311 | \1f | |
6312 | File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing | |
6313 | ||
6314 | Programmable Completion | |
6315 | ======================= | |
6316 | ||
6317 | When word completion is attempted for an argument to a command for | |
6318 | which a completion specification (a COMPSPEC) has been defined using | |
28ef6c31 | 6319 | the `complete' builtin (*note Programmable Completion Builtins::), the |
bb70624e JA |
6320 | programmable completion facilities are invoked. |
6321 | ||
6322 | First, the command name is identified. If a compspec has been | |
6323 | defined for that command, the compspec is used to generate the list of | |
6324 | possible completions for the word. If the command word is a full | |
6325 | pathname, a compspec for the full pathname is searched for first. If | |
6326 | no compspec is found for the full pathname, an attempt is made to find | |
6327 | a compspec for the portion following the final slash. | |
6328 | ||
6329 | Once a compspec has been found, it is used to generate the list of | |
6330 | matching words. If a compspec is not found, the default Bash completion | |
28ef6c31 | 6331 | described above (*note Commands For Completion::) is performed. |
bb70624e JA |
6332 | |
6333 | First, the actions specified by the compspec are used. Only matches | |
6334 | which are prefixed by the word being completed are returned. When the | |
6335 | `-f' or `-d' option is used for filename or directory name completion, | |
6336 | the shell variable `FIGNORE' is used to filter the matches. *Note Bash | |
6337 | Variables::, for a description of `FIGNORE'. | |
6338 | ||
6339 | Any completions specified by a filename expansion pattern to the | |
6340 | `-G' option are generated next. The words generated by the pattern | |
6341 | need not match the word being completed. The `GLOBIGNORE' shell | |
6342 | variable is not used to filter the matches, but the `FIGNORE' shell | |
6343 | variable is used. | |
6344 | ||
6345 | Next, the string specified as the argument to the `-W' option is | |
6346 | considered. The string is first split using the characters in the `IFS' | |
6347 | special variable as delimiters. Shell quoting is honored. Each word | |
6348 | is then expanded using brace expansion, tilde expansion, parameter and | |
6349 | variable expansion, command substitution, arithmetic expansion, and | |
28ef6c31 JA |
6350 | pathname expansion, as described above (*note Shell Expansions::). The |
6351 | results are split using the rules described above (*note Word | |
6352 | Splitting::). The results of the expansion are prefix-matched against | |
bb70624e JA |
6353 | the word being completed, and the matching words become the possible |
6354 | completions. | |
6355 | ||
6356 | After these matches have been generated, any shell function or | |
6357 | command specified with the `-F' and `-C' options is invoked. When the | |
6358 | command or function is invoked, the `COMP_LINE' and `COMP_POINT' | |
6359 | variables are assigned values as described above (*note Bash | |
28ef6c31 | 6360 | Variables::). If a shell function is being invoked, the `COMP_WORDS' |
bb70624e JA |
6361 | and `COMP_CWORD' variables are also set. When the function or command |
6362 | is invoked, the first argument is the name of the command whose | |
6363 | arguments are being completed, the second argument is the word being | |
6364 | completed, and the third argument is the word preceding the word being | |
6365 | completed on the current command line. No filtering of the generated | |
6366 | completions against the word being completed is performed; the function | |
6367 | or command has complete freedom in generating the matches. | |
6368 | ||
6369 | Any function specified with `-F' is invoked first. The function may | |
6370 | use any of the shell facilities, including the `compgen' builtin | |
28ef6c31 JA |
6371 | described below (*note Programmable Completion Builtins::), to generate |
6372 | the matches. It must put the possible completions in the `COMPREPLY' | |
6373 | array variable. | |
bb70624e JA |
6374 | |
6375 | Next, any command specified with the `-C' option is invoked in an | |
6376 | environment equivalent to command substitution. It should print a list | |
6377 | of completions, one per line, to the standard output. Backslash may be | |
6378 | used to escape a newline, if necessary. | |
6379 | ||
6380 | After all of the possible completions are generated, any filter | |
6381 | specified with the `-X' option is applied to the list. The filter is a | |
6382 | pattern as used for pathname expansion; a `&' in the pattern is | |
6383 | replaced with the text of the word being completed. A literal `&' may | |
6384 | be escaped with a backslash; the backslash is removed before attempting | |
6385 | a match. Any completion that matches the pattern will be removed from | |
6386 | the list. A leading `!' negates the pattern; in this case any | |
6387 | completion not matching the pattern will be removed. | |
6388 | ||
6389 | Finally, any prefix and suffix specified with the `-P' and `-S' | |
6390 | options are added to each member of the completion list, and the result | |
6391 | is returned to the Readline completion code as the list of possible | |
6392 | completions. | |
6393 | ||
28ef6c31 JA |
6394 | If the previously-applied actions do not generate any matches, and |
6395 | the `-o dirnames' option was supplied to `complete' when the compspec | |
6396 | was defined, directory name completion is attempted. | |
6397 | ||
6398 | By default, if a compspec is found, whatever it generates is | |
6399 | returned to the completion code as the full set of possible completions. | |
6400 | The default Bash completions are not attempted, and the Readline default | |
6401 | of filename completion is disabled. If the `-o default' option was | |
6402 | supplied to `complete' when the compspec was defined, Readline's | |
6403 | default completion will be performed if the compspec generates no | |
6404 | matches. | |
bb70624e JA |
6405 | |
6406 | \1f | |
6407 | File: bashref.info, Node: Programmable Completion Builtins, Prev: Programmable Completion, Up: Command Line Editing | |
6408 | ||
6409 | Programmable Completion Builtins | |
6410 | ================================ | |
6411 | ||
6412 | Two builtin commands are available to manipulate the programmable | |
6413 | completion facilities. | |
6414 | ||
6415 | `compgen' | |
6416 | `compgen [OPTION] [WORD]' | |
6417 | ||
6418 | Generate possible completion matches for WORD according to the | |
6419 | OPTIONs, which may be any option accepted by the `complete' | |
6420 | builtin with the exception of `-p' and `-r', and write the matches | |
6421 | to the standard output. When using the `-F' or `-C' options, the | |
6422 | various shell variables set by the programmable completion | |
6423 | facilities, while available, will not have useful values. | |
6424 | ||
6425 | The matches will be generated in the same way as if the | |
6426 | programmable completion code had generated them directly from a | |
6427 | completion specification with the same flags. If WORD is | |
6428 | specified, only those completions matching WORD will be displayed. | |
6429 | ||
6430 | The return value is true unless an invalid option is supplied, or | |
6431 | no matches were generated. | |
6432 | ||
6433 | `complete' | |
28ef6c31 | 6434 | `complete [-abcdefjkvu] [-o COMP-OPTION] [-A ACTION] [-G GLOBPAT] [-W WORDLIST] |
bb70624e JA |
6435 | [-P PREFIX] [-S SUFFIX] [-X FILTERPAT] [-F FUNCTION] |
6436 | [-C COMMAND] NAME [NAME ...]' | |
6437 | `complete -pr [NAME ...]' | |
6438 | ||
6439 | Specify how arguments to each NAME should be completed. If the | |
6440 | `-p' option is supplied, or if no options are supplied, existing | |
6441 | completion specifications are printed in a way that allows them to | |
6442 | be reused as input. The `-r' option removes a completion | |
6443 | specification for each NAME, or, if no NAMEs are supplied, all | |
6444 | completion specifications. | |
6445 | ||
6446 | The process of applying these completion specifications when word | |
6447 | completion is attempted is described above (*note Programmable | |
28ef6c31 | 6448 | Completion::). |
bb70624e JA |
6449 | |
6450 | Other options, if specified, have the following meanings. The | |
6451 | arguments to the `-G', `-W', and `-X' options (and, if necessary, | |
6452 | the `-P' and `-S' options) should be quoted to protect them from | |
6453 | expansion before the `complete' builtin is invoked. | |
6454 | ||
28ef6c31 JA |
6455 | `-o COMP-OPTION' |
6456 | The COMP-OPTION controls several aspects of the compspec's | |
6457 | behavior beyond the simple generation of completions. | |
6458 | COMP-OPTION may be one of: | |
6459 | ||
6460 | `default' | |
6461 | Use readline's default completion if the compspec | |
6462 | generates no matches. | |
6463 | ||
6464 | `dirnames' | |
6465 | Perform directory name completion if the compspec | |
6466 | generates no matches. | |
6467 | ||
6468 | `filenames' | |
6469 | Tell Readline that the compspec generates filenames, so | |
6470 | it can perform any filename\-specific processing (like | |
6471 | adding a slash to directory names or suppressing | |
6472 | trailing spaces). This option is intended to be used | |
6473 | with shell functions specified with `-F'. | |
6474 | ||
bb70624e JA |
6475 | `-A ACTION' |
6476 | The ACTION may be one of the following to generate a list of | |
6477 | possible completions: | |
6478 | ||
6479 | `alias' | |
6480 | Alias names. May also be specified as `-a'. | |
6481 | ||
6482 | `arrayvar' | |
6483 | Array variable names. | |
6484 | ||
6485 | `binding' | |
6486 | Readline key binding names (*note Bindable Readline | |
28ef6c31 | 6487 | Commands::). |
bb70624e JA |
6488 | |
6489 | `builtin' | |
6490 | Names of shell builtin commands. May also be specified | |
6491 | as `-b'. | |
6492 | ||
6493 | `command' | |
6494 | Command names. May also be specified as `-c'. | |
6495 | ||
6496 | `directory' | |
6497 | Directory names. May also be specified as `-d'. | |
6498 | ||
6499 | `disabled' | |
6500 | Names of disabled shell builtins. | |
6501 | ||
6502 | `enabled' | |
6503 | Names of enabled shell builtins. | |
6504 | ||
6505 | `export' | |
6506 | Names of exported shell variables. May also be | |
6507 | specified as `-e'. | |
6508 | ||
6509 | `file' | |
6510 | File names. May also be specified as `-f'. | |
6511 | ||
6512 | `function' | |
6513 | Names of shell functions. | |
6514 | ||
6515 | `helptopic' | |
6516 | Help topics as accepted by the `help' builtin (*note | |
28ef6c31 | 6517 | Bash Builtins::). |
bb70624e JA |
6518 | |
6519 | `hostname' | |
6520 | Hostnames, as taken from the file specified by the | |
28ef6c31 | 6521 | `HOSTFILE' shell variable (*note Bash Variables::). |
bb70624e JA |
6522 | |
6523 | `job' | |
6524 | Job names, if job control is active. May also be | |
6525 | specified as `-j'. | |
6526 | ||
6527 | `keyword' | |
6528 | Shell reserved words. May also be specified as `-k'. | |
6529 | ||
6530 | `running' | |
6531 | Names of running jobs, if job control is active. | |
6532 | ||
6533 | `setopt' | |
6534 | Valid arguments for the `-o' option to the `set' builtin | |
28ef6c31 | 6535 | (*note The Set Builtin::). |
bb70624e JA |
6536 | |
6537 | `shopt' | |
6538 | Shell option names as accepted by the `shopt' builtin | |
28ef6c31 | 6539 | (*note Bash Builtins::). |
bb70624e JA |
6540 | |
6541 | `signal' | |
6542 | Signal names. | |
6543 | ||
6544 | `stopped' | |
6545 | Names of stopped jobs, if job control is active. | |
6546 | ||
6547 | `user' | |
6548 | User names. May also be specified as `-u'. | |
6549 | ||
6550 | `variable' | |
6551 | Names of all shell variables. May also be specified as | |
6552 | `-v'. | |
6553 | ||
6554 | `-G GLOBPAT' | |
6555 | The filename expansion pattern GLOBPAT is expanded to generate | |
6556 | the possible completions. | |
6557 | ||
6558 | `-W WORDLIST' | |
6559 | The WORDLIST is split using the characters in the `IFS' | |
6560 | special variable as delimiters, and each resultant word is | |
6561 | expanded. The possible completions are the members of the | |
6562 | resultant list which match the word being completed. | |
6563 | ||
6564 | `-C COMMAND' | |
6565 | COMMAND is executed in a subshell environment, and its output | |
6566 | is used as the possible completions. | |
6567 | ||
6568 | `-F FUNCTION' | |
6569 | The shell function FUNCTION is executed in the current shell | |
6570 | environment. When it finishes, the possible completions are | |
6571 | retrieved from the value of the `COMPREPLY' array variable. | |
6572 | ||
6573 | `-X FILTERPAT' | |
6574 | FILTERPAT is a pattern as used for filename expansion. It is | |
6575 | applied to the list of possible completions generated by the | |
6576 | preceding options and arguments, and each completion matching | |
6577 | FILTERPAT is removed from the list. A leading `!' in | |
6578 | FILTERPAT negates the pattern; in this case, any completion | |
6579 | not matching FILTERPAT is removed. | |
6580 | ||
6581 | `-P PREFIX' | |
6582 | PREFIX is added at the beginning of each possible completion | |
6583 | after all other options have been applied. | |
6584 | ||
6585 | `-S SUFFIX' | |
6586 | SUFFIX is appended to each possible completion after all | |
6587 | other options have been applied. | |
6588 | ||
6589 | The return value is true unless an invalid option is supplied, an | |
6590 | option other than `-p' or `-r' is supplied without a NAME | |
6591 | argument, an attempt is made to remove a completion specification | |
6592 | for a NAME for which no specification exists, or an error occurs | |
6593 | adding a completion specification. | |
6594 | ||
6595 | \1f | |
6596 | File: bashref.info, Node: Using History Interactively, Next: Command Line Editing, Prev: Job Control, Up: Top | |
6597 | ||
6598 | Using History Interactively | |
6599 | *************************** | |
6600 | ||
6601 | This chapter describes how to use the GNU History Library | |
6602 | interactively, from a user's standpoint. It should be considered a | |
6603 | user's guide. For information on using the GNU History Library in | |
6604 | other programs, see the GNU Readline Library Manual. | |
6605 | ||
6606 | * Menu: | |
6607 | ||
6608 | * Bash History Facilities:: How Bash lets you manipulate your command | |
6609 | history. | |
6610 | * Bash History Builtins:: The Bash builtin commands that manipulate | |
6611 | the command history. | |
6612 | * History Interaction:: What it feels like using History as a user. | |
6613 | ||
6614 | \1f | |
6615 | File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively | |
6616 | ||
6617 | Bash History Facilities | |
6618 | ======================= | |
6619 | ||
6620 | When the `-o history' option to the `set' builtin is enabled (*note | |
28ef6c31 | 6621 | The Set Builtin::), the shell provides access to the "command history", |
bb70624e JA |
6622 | the list of commands previously typed. The value of the `HISTSIZE' |
6623 | shell variable is used as the number of commands to save in a history | |
6624 | list. The text of the last `$HISTSIZE' commands (default 500) is saved. | |
6625 | The shell stores each command in the history list prior to parameter | |
6626 | and variable expansion but after history expansion is performed, | |
6627 | subject to the values of the shell variables `HISTIGNORE' and | |
6628 | `HISTCONTROL'. | |
6629 | ||
6630 | When the shell starts up, the history is initialized from the file | |
6631 | named by the `HISTFILE' variable (default `~/.bash_history'). The file | |
6632 | named by the value of `HISTFILE' is truncated, if necessary, to contain | |
6633 | no more than the number of lines specified by the value of the | |
6634 | `HISTFILESIZE' variable. When an interactive shell exits, the last | |
6635 | `$HISTSIZE' lines are copied from the history list to the file named by | |
6636 | `$HISTFILE'. If the `histappend' shell option is set (*note Bash | |
28ef6c31 | 6637 | Builtins::), the lines are appended to the history file, otherwise the |
bb70624e JA |
6638 | history file is overwritten. If `HISTFILE' is unset, or if the history |
6639 | file is unwritable, the history is not saved. After saving the | |
6640 | history, the history file is truncated to contain no more than | |
6641 | `$HISTFILESIZE' lines. If `HISTFILESIZE' is not set, no truncation is | |
6642 | performed. | |
6643 | ||
6644 | The builtin command `fc' may be used to list or edit and re-execute | |
6645 | a portion of the history list. The `history' builtin may be used to | |
6646 | display or modify the history list and manipulate the history file. | |
6647 | When using command-line editing, search commands are available in each | |
6648 | editing mode that provide access to the history list (*note Commands | |
28ef6c31 | 6649 | For History::). |
bb70624e JA |
6650 | |
6651 | The shell allows control over which commands are saved on the history | |
6652 | list. The `HISTCONTROL' and `HISTIGNORE' variables may be set to cause | |
6653 | the shell to save only a subset of the commands entered. The `cmdhist' | |
6654 | shell option, if enabled, causes the shell to attempt to save each line | |
6655 | of a multi-line command in the same history entry, adding semicolons | |
6656 | where necessary to preserve syntactic correctness. The `lithist' shell | |
6657 | option causes the shell to save the command with embedded newlines | |
6658 | instead of semicolons. The `shopt' builtin is used to set these | |
6659 | options. *Note Bash Builtins::, for a description of `shopt'. | |
6660 | ||
6661 | \1f | |
6662 | File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively | |
6663 | ||
6664 | Bash History Builtins | |
6665 | ===================== | |
6666 | ||
6667 | Bash provides two builtin commands which manipulate the history list | |
6668 | and history file. | |
6669 | ||
6670 | `fc' | |
6671 | `fc [-e ENAME] [-nlr] [FIRST] [LAST]' | |
6672 | `fc -s [PAT=REP] [COMMAND]' | |
6673 | ||
6674 | Fix Command. In the first form, a range of commands from FIRST to | |
6675 | LAST is selected from the history list. Both FIRST and LAST may | |
6676 | be specified as a string (to locate the most recent command | |
6677 | beginning with that string) or as a number (an index into the | |
6678 | history list, where a negative number is used as an offset from the | |
6679 | current command number). If LAST is not specified it is set to | |
6680 | FIRST. If FIRST is not specified it is set to the previous | |
6681 | command for editing and -16 for listing. If the `-l' flag is | |
6682 | given, the commands are listed on standard output. The `-n' flag | |
6683 | suppresses the command numbers when listing. The `-r' flag | |
6684 | reverses the order of the listing. Otherwise, the editor given by | |
6685 | ENAME is invoked on a file containing those commands. If ENAME is | |
6686 | not given, the value of the following variable expansion is used: | |
6687 | `${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the | |
6688 | `FCEDIT' variable if set, or the value of the `EDITOR' variable if | |
6689 | that is set, or `vi' if neither is set. When editing is complete, | |
6690 | the edited commands are echoed and executed. | |
6691 | ||
6692 | In the second form, COMMAND is re-executed after each instance of | |
6693 | PAT in the selected command is replaced by REP. | |
6694 | ||
6695 | A useful alias to use with the `fc' command is `r='fc -s'', so | |
6696 | that typing `r cc' runs the last command beginning with `cc' and | |
28ef6c31 | 6697 | typing `r' re-executes the last command (*note Aliases::). |
bb70624e JA |
6698 | |
6699 | `history' | |
6700 | history [N] | |
6701 | history -c | |
6702 | history -d OFFSET | |
6703 | history [-anrw] [FILENAME] | |
6704 | history -ps ARG | |
6705 | ||
6706 | With no options, display the history list with line numbers. | |
28ef6c31 JA |
6707 | Lines prefixed with a `*' have been modified. An argument of N |
6708 | lists only the last N lines. Options, if supplied, have the | |
bb70624e JA |
6709 | following meanings: |
6710 | ||
6711 | `-c' | |
6712 | Clear the history list. This may be combined with the other | |
6713 | options to replace the history list completely. | |
6714 | ||
6715 | `-d OFFSET' | |
6716 | Delete the history entry at position OFFSET. OFFSET should | |
6717 | be specified as it appears when the history is displayed. | |
6718 | ||
6719 | `-a' | |
6720 | Append the new history lines (history lines entered since the | |
6721 | beginning of the current Bash session) to the history file. | |
6722 | ||
6723 | `-n' | |
6724 | Append the history lines not already read from the history | |
6725 | file to the current history list. These are lines appended | |
6726 | to the history file since the beginning of the current Bash | |
6727 | session. | |
6728 | ||
6729 | `-r' | |
6730 | Read the current history file and append its contents to the | |
6731 | history list. | |
6732 | ||
6733 | `-w' | |
6734 | Write out the current history to the history file. | |
6735 | ||
6736 | `-p' | |
6737 | Perform history substitution on the ARGs and display the | |
6738 | result on the standard output, without storing the results in | |
6739 | the history list. | |
6740 | ||
6741 | `-s' | |
6742 | The ARGs are added to the end of the history list as a single | |
6743 | entry. | |
6744 | ||
6745 | When any of the `-w', `-r', `-a', or `-n' options is used, if | |
6746 | FILENAME is given, then it is used as the history file. If not, | |
6747 | then the value of the `HISTFILE' variable is used. | |
6748 | ||
6749 | \1f | |
6750 | File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively | |
ccc6cda3 | 6751 | |
bb70624e JA |
6752 | History Expansion |
6753 | ================= | |
ccc6cda3 | 6754 | |
bb70624e JA |
6755 | The History library provides a history expansion feature that is |
6756 | similar to the history expansion provided by `csh'. This section | |
6757 | describes the syntax used to manipulate the history information. | |
ccc6cda3 | 6758 | |
bb70624e JA |
6759 | History expansions introduce words from the history list into the |
6760 | input stream, making it easy to repeat commands, insert the arguments | |
6761 | to a previous command into the current input line, or fix errors in | |
6762 | previous commands quickly. | |
ccc6cda3 | 6763 | |
bb70624e JA |
6764 | History expansion takes place in two parts. The first is to |
6765 | determine which line from the history list should be used during | |
6766 | substitution. The second is to select portions of that line for | |
6767 | inclusion into the current one. The line selected from the history is | |
6768 | called the "event", and the portions of that line that are acted upon | |
6769 | are called "words". Various "modifiers" are available to manipulate | |
6770 | the selected words. The line is broken into words in the same fashion | |
6771 | that Bash does, so that several words surrounded by quotes are | |
6772 | considered one word. History expansions are introduced by the | |
6773 | appearance of the history expansion character, which is `!' by default. | |
6774 | Only `\' and `'' may be used to escape the history expansion character. | |
6775 | ||
6776 | Several shell options settable with the `shopt' builtin (*note Bash | |
28ef6c31 | 6777 | Builtins::) may be used to tailor the behavior of history expansion. |
bb70624e JA |
6778 | If the `histverify' shell option is enabled, and Readline is being |
6779 | used, history substitutions are not immediately passed to the shell | |
6780 | parser. Instead, the expanded line is reloaded into the Readline | |
6781 | editing buffer for further modification. If Readline is being used, | |
6782 | and the `histreedit' shell option is enabled, a failed history | |
6783 | expansion will be reloaded into the Readline editing buffer for | |
6784 | correction. The `-p' option to the `history' builtin command may be | |
6785 | used to see what a history expansion will do before using it. The `-s' | |
6786 | option to the `history' builtin may be used to add commands to the end | |
6787 | of the history list without actually executing them, so that they are | |
6788 | available for subsequent recall. This is most useful in conjunction | |
6789 | with Readline. | |
6790 | ||
6791 | The shell allows control of the various characters used by the | |
6792 | history expansion mechanism with the `histchars' variable. | |
6793 | ||
6794 | * Menu: | |
6795 | ||
6796 | * Event Designators:: How to specify which history line to use. | |
6797 | * Word Designators:: Specifying which words are of interest. | |
6798 | * Modifiers:: Modifying the results of substitution. | |
ccc6cda3 JA |
6799 | |
6800 | \1f | |
bb70624e | 6801 | File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction |
ccc6cda3 | 6802 | |
bb70624e JA |
6803 | Event Designators |
6804 | ----------------- | |
ccc6cda3 | 6805 | |
bb70624e JA |
6806 | An event designator is a reference to a command line entry in the |
6807 | history list. | |
ccc6cda3 | 6808 | |
bb70624e JA |
6809 | `!' |
6810 | Start a history substitution, except when followed by a space, tab, | |
6811 | the end of the line, `=' or `('. | |
ccc6cda3 | 6812 | |
bb70624e JA |
6813 | `!N' |
6814 | Refer to command line N. | |
ccc6cda3 | 6815 | |
bb70624e JA |
6816 | `!-N' |
6817 | Refer to the command N lines back. | |
ccc6cda3 | 6818 | |
bb70624e JA |
6819 | `!!' |
6820 | Refer to the previous command. This is a synonym for `!-1'. | |
ccc6cda3 | 6821 | |
bb70624e JA |
6822 | `!STRING' |
6823 | Refer to the most recent command starting with STRING. | |
ccc6cda3 | 6824 | |
bb70624e JA |
6825 | `!?STRING[?]' |
6826 | Refer to the most recent command containing STRING. The trailing | |
6827 | `?' may be omitted if the STRING is followed immediately by a | |
6828 | newline. | |
ccc6cda3 | 6829 | |
bb70624e JA |
6830 | `^STRING1^STRING2^' |
6831 | Quick Substitution. Repeat the last command, replacing STRING1 | |
6832 | with STRING2. Equivalent to `!!:s/STRING1/STRING2/'. | |
6833 | ||
6834 | `!#' | |
6835 | The entire command line typed so far. | |
ccc6cda3 JA |
6836 | |
6837 | \1f | |
bb70624e | 6838 | File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction |
ccc6cda3 | 6839 | |
bb70624e JA |
6840 | Word Designators |
6841 | ---------------- | |
ccc6cda3 | 6842 | |
bb70624e JA |
6843 | Word designators are used to select desired words from the event. A |
6844 | `:' separates the event specification from the word designator. It may | |
6845 | be omitted if the word designator begins with a `^', `$', `*', `-', or | |
6846 | `%'. Words are numbered from the beginning of the line, with the first | |
6847 | word being denoted by 0 (zero). Words are inserted into the current | |
6848 | line separated by single spaces. | |
ccc6cda3 | 6849 | |
bb70624e | 6850 | For example, |
ccc6cda3 | 6851 | |
bb70624e JA |
6852 | `!!' |
6853 | designates the preceding command. When you type this, the | |
6854 | preceding command is repeated in toto. | |
ccc6cda3 | 6855 | |
bb70624e JA |
6856 | `!!:$' |
6857 | designates the last argument of the preceding command. This may be | |
6858 | shortened to `!$'. | |
ccc6cda3 | 6859 | |
bb70624e JA |
6860 | `!fi:2' |
6861 | designates the second argument of the most recent command starting | |
6862 | with the letters `fi'. | |
ccc6cda3 | 6863 | |
bb70624e | 6864 | Here are the word designators: |
ccc6cda3 | 6865 | |
bb70624e JA |
6866 | `0 (zero)' |
6867 | The `0'th word. For many applications, this is the command word. | |
ccc6cda3 | 6868 | |
bb70624e JA |
6869 | `N' |
6870 | The Nth word. | |
ccc6cda3 | 6871 | |
bb70624e JA |
6872 | `^' |
6873 | The first argument; that is, word 1. | |
ccc6cda3 | 6874 | |
bb70624e JA |
6875 | `$' |
6876 | The last argument. | |
ccc6cda3 | 6877 | |
bb70624e JA |
6878 | `%' |
6879 | The word matched by the most recent `?STRING?' search. | |
ccc6cda3 | 6880 | |
bb70624e JA |
6881 | `X-Y' |
6882 | A range of words; `-Y' abbreviates `0-Y'. | |
ccc6cda3 | 6883 | |
bb70624e JA |
6884 | `*' |
6885 | All of the words, except the `0'th. This is a synonym for `1-$'. | |
6886 | It is not an error to use `*' if there is just one word in the | |
6887 | event; the empty string is returned in that case. | |
6888 | ||
6889 | `X*' | |
6890 | Abbreviates `X-$' | |
6891 | ||
6892 | `X-' | |
6893 | Abbreviates `X-$' like `X*', but omits the last word. | |
6894 | ||
6895 | If a word designator is supplied without an event specification, the | |
6896 | previous command is used as the event. | |
ccc6cda3 JA |
6897 | |
6898 | \1f | |
bb70624e | 6899 | File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction |
ccc6cda3 | 6900 | |
bb70624e JA |
6901 | Modifiers |
6902 | --------- | |
ccc6cda3 | 6903 | |
bb70624e JA |
6904 | After the optional word designator, you can add a sequence of one or |
6905 | more of the following modifiers, each preceded by a `:'. | |
ccc6cda3 | 6906 | |
bb70624e JA |
6907 | `h' |
6908 | Remove a trailing pathname component, leaving only the head. | |
ccc6cda3 | 6909 | |
bb70624e JA |
6910 | `t' |
6911 | Remove all leading pathname components, leaving the tail. | |
6912 | ||
6913 | `r' | |
6914 | Remove a trailing suffix of the form `.SUFFIX', leaving the | |
6915 | basename. | |
6916 | ||
6917 | `e' | |
6918 | Remove all but the trailing suffix. | |
6919 | ||
6920 | `p' | |
6921 | Print the new command but do not execute it. | |
6922 | ||
6923 | `q' | |
6924 | Quote the substituted words, escaping further substitutions. | |
6925 | ||
6926 | `x' | |
6927 | Quote the substituted words as with `q', but break into words at | |
6928 | spaces, tabs, and newlines. | |
6929 | ||
6930 | `s/OLD/NEW/' | |
6931 | Substitute NEW for the first occurrence of OLD in the event line. | |
6932 | Any delimiter may be used in place of `/'. The delimiter may be | |
6933 | quoted in OLD and NEW with a single backslash. If `&' appears in | |
6934 | NEW, it is replaced by OLD. A single backslash will quote the | |
6935 | `&'. The final delimiter is optional if it is the last character | |
6936 | on the input line. | |
6937 | ||
6938 | `&' | |
6939 | Repeat the previous substitution. | |
6940 | ||
6941 | `g' | |
6942 | Cause changes to be applied over the entire event line. Used in | |
6943 | conjunction with `s', as in `gs/OLD/NEW/', or with `&'. | |
6944 | ||
6945 | \1f | |
6946 | File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Command Line Editing, Up: Top | |
6947 | ||
6948 | Installing Bash | |
6949 | *************** | |
b72432fd | 6950 | |
bb70624e JA |
6951 | This chapter provides basic instructions for installing Bash on the |
6952 | various supported platforms. The distribution supports the GNU | |
6953 | operating systems, nearly every version of Unix, and several non-Unix | |
6954 | systems such as BeOS and Interix. Other independent ports exist for | |
6955 | MS-DOS, OS/2, Windows 95/98, and Windows NT. | |
ccc6cda3 | 6956 | |
bb70624e | 6957 | * Menu: |
ccc6cda3 | 6958 | |
bb70624e | 6959 | * Basic Installation:: Installation instructions. |
ccc6cda3 | 6960 | |
bb70624e JA |
6961 | * Compilers and Options:: How to set special options for various |
6962 | systems. | |
ccc6cda3 | 6963 | |
bb70624e JA |
6964 | * Compiling For Multiple Architectures:: How to compile Bash for more |
6965 | than one kind of system from | |
6966 | the same source tree. | |
ccc6cda3 | 6967 | |
bb70624e | 6968 | * Installation Names:: How to set the various paths used by the installation. |
ccc6cda3 | 6969 | |
bb70624e | 6970 | * Specifying the System Type:: How to configure Bash for a particular system. |
ccc6cda3 | 6971 | |
bb70624e JA |
6972 | * Sharing Defaults:: How to share default configuration values among GNU |
6973 | programs. | |
ccc6cda3 | 6974 | |
bb70624e | 6975 | * Operation Controls:: Options recognized by the configuration program. |
ccc6cda3 | 6976 | |
bb70624e JA |
6977 | * Optional Features:: How to enable and disable optional features when |
6978 | building Bash. | |
ccc6cda3 | 6979 | |
bb70624e JA |
6980 | \1f |
6981 | File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 6982 | |
bb70624e JA |
6983 | Basic Installation |
6984 | ================== | |
ccc6cda3 | 6985 | |
bb70624e | 6986 | These are installation instructions for Bash. |
ccc6cda3 | 6987 | |
bb70624e | 6988 | The simplest way to compile Bash is: |
ccc6cda3 | 6989 | |
bb70624e JA |
6990 | 1. `cd' to the directory containing the source code and type |
6991 | `./configure' to configure Bash for your system. If you're using | |
6992 | `csh' on an old version of System V, you might need to type `sh | |
6993 | ./configure' instead to prevent `csh' from trying to execute | |
6994 | `configure' itself. | |
ccc6cda3 | 6995 | |
bb70624e JA |
6996 | Running `configure' takes some time. While running, it prints |
6997 | messages telling which features it is checking for. | |
ccc6cda3 | 6998 | |
bb70624e JA |
6999 | 2. Type `make' to compile Bash and build the `bashbug' bug reporting |
7000 | script. | |
ccc6cda3 | 7001 | |
bb70624e | 7002 | 3. Optionally, type `make tests' to run the Bash test suite. |
ccc6cda3 | 7003 | |
bb70624e JA |
7004 | 4. Type `make install' to install `bash' and `bashbug'. This will |
7005 | also install the manual pages and Info file. | |
ccc6cda3 | 7006 | |
ccc6cda3 | 7007 | |
bb70624e JA |
7008 | The `configure' shell script attempts to guess correct values for |
7009 | various system-dependent variables used during compilation. It uses | |
7010 | those values to create a `Makefile' in each directory of the package | |
7011 | (the top directory, the `builtins', `doc', and `support' directories, | |
7012 | each directory under `lib', and several others). It also creates a | |
7013 | `config.h' file containing system-dependent definitions. Finally, it | |
7014 | creates a shell script named `config.status' that you can run in the | |
7015 | future to recreate the current configuration, a file `config.cache' | |
7016 | that saves the results of its tests to speed up reconfiguring, and a | |
7017 | file `config.log' containing compiler output (useful mainly for | |
7018 | debugging `configure'). If at some point `config.cache' contains | |
7019 | results you don't want to keep, you may remove or edit it. | |
ccc6cda3 | 7020 | |
bb70624e JA |
7021 | To find out more about the options and arguments that the |
7022 | `configure' script understands, type | |
ccc6cda3 | 7023 | |
bb70624e | 7024 | bash-2.04$ ./configure --help |
ccc6cda3 | 7025 | |
bb70624e | 7026 | at the Bash prompt in your Bash source directory. |
ccc6cda3 | 7027 | |
bb70624e JA |
7028 | If you need to do unusual things to compile Bash, please try to |
7029 | figure out how `configure' could check whether or not to do them, and | |
7030 | mail diffs or instructions to <bash-maintainers@gnu.org> so they can be | |
7031 | considered for the next release. | |
ccc6cda3 | 7032 | |
bb70624e JA |
7033 | The file `configure.in' is used to create `configure' by a program |
7034 | called Autoconf. You only need `configure.in' if you want to change it | |
7035 | or regenerate `configure' using a newer version of Autoconf. If you do | |
7036 | this, make sure you are using Autoconf version 2.10 or newer. | |
ccc6cda3 | 7037 | |
bb70624e JA |
7038 | If you need to change `configure.in' or regenerate `configure', you |
7039 | will need to create two files: `_distribution' and `_patchlevel'. | |
7040 | `_distribution' should contain the major and minor version numbers of | |
7041 | the Bash distribution, for example `2.01'. `_patchlevel' should | |
7042 | contain the patch level of the Bash distribution, `0' for example. The | |
7043 | script `support/mkconffiles' has been provided to automate the creation | |
7044 | of these files. | |
ccc6cda3 | 7045 | |
bb70624e JA |
7046 | You can remove the program binaries and object files from the source |
7047 | code directory by typing `make clean'. To also remove the files that | |
7048 | `configure' created (so you can compile Bash for a different kind of | |
7049 | computer), type `make distclean'. | |
ccc6cda3 | 7050 | |
bb70624e JA |
7051 | \1f |
7052 | File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash | |
ccc6cda3 | 7053 | |
bb70624e JA |
7054 | Compilers and Options |
7055 | ===================== | |
ccc6cda3 | 7056 | |
bb70624e JA |
7057 | Some systems require unusual options for compilation or linking that |
7058 | the `configure' script does not know about. You can give `configure' | |
7059 | initial values for variables by setting them in the environment. Using | |
7060 | a Bourne-compatible shell, you can do that on the command line like | |
7061 | this: | |
ccc6cda3 | 7062 | |
bb70624e | 7063 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure |
ccc6cda3 | 7064 | |
bb70624e | 7065 | On systems that have the `env' program, you can do it like this: |
cce855bc | 7066 | |
bb70624e | 7067 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure |
b72432fd | 7068 | |
bb70624e | 7069 | The configuration process uses GCC to build Bash if it is available. |
ccc6cda3 | 7070 | |
bb70624e JA |
7071 | \1f |
7072 | File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 7073 | |
bb70624e JA |
7074 | Compiling For Multiple Architectures |
7075 | ==================================== | |
ccc6cda3 | 7076 | |
bb70624e JA |
7077 | You can compile Bash for more than one kind of computer at the same |
7078 | time, by placing the object files for each architecture in their own | |
7079 | directory. To do this, you must use a version of `make' that supports | |
7080 | the `VPATH' variable, such as GNU `make'. `cd' to the directory where | |
7081 | you want the object files and executables to go and run the `configure' | |
7082 | script from the source directory. You may need to supply the | |
7083 | `--srcdir=PATH' argument to tell `configure' where the source files | |
7084 | are. `configure' automatically checks for the source code in the | |
7085 | directory that `configure' is in and in `..'. | |
ccc6cda3 | 7086 | |
bb70624e JA |
7087 | If you have to use a `make' that does not supports the `VPATH' |
7088 | variable, you can compile Bash for one architecture at a time in the | |
7089 | source code directory. After you have installed Bash for one | |
7090 | architecture, use `make distclean' before reconfiguring for another | |
7091 | architecture. | |
ccc6cda3 | 7092 | |
bb70624e JA |
7093 | Alternatively, if your system supports symbolic links, you can use |
7094 | the `support/mkclone' script to create a build tree which has symbolic | |
7095 | links back to each file in the source directory. Here's an example | |
7096 | that creates a build directory in the current directory from a source | |
7097 | directory `/usr/gnu/src/bash-2.0': | |
ccc6cda3 | 7098 | |
bb70624e | 7099 | bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 . |
ccc6cda3 | 7100 | |
bb70624e JA |
7101 | The `mkclone' script requires Bash, so you must have already built Bash |
7102 | for at least one architecture before you can create build directories | |
7103 | for other architectures. | |
ccc6cda3 | 7104 | |
bb70624e JA |
7105 | \1f |
7106 | File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash | |
ccc6cda3 | 7107 | |
bb70624e JA |
7108 | Installation Names |
7109 | ================== | |
ccc6cda3 | 7110 | |
bb70624e JA |
7111 | By default, `make install' will install into `/usr/local/bin', |
7112 | `/usr/local/man', etc. You can specify an installation prefix other | |
7113 | than `/usr/local' by giving `configure' the option `--prefix=PATH'. | |
ccc6cda3 | 7114 | |
bb70624e JA |
7115 | You can specify separate installation prefixes for |
7116 | architecture-specific files and architecture-independent files. If you | |
7117 | give `configure' the option `--exec-prefix=PATH', `make install' will | |
7118 | use PATH as the prefix for installing programs and libraries. | |
7119 | Documentation and other data files will still use the regular prefix. | |
ccc6cda3 JA |
7120 | |
7121 | \1f | |
bb70624e | 7122 | File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash |
ccc6cda3 | 7123 | |
bb70624e JA |
7124 | Specifying the System Type |
7125 | ========================== | |
ccc6cda3 | 7126 | |
bb70624e JA |
7127 | There may be some features `configure' can not figure out |
7128 | automatically, but needs to determine by the type of host Bash will run | |
7129 | on. Usually `configure' can figure that out, but if it prints a | |
7130 | message saying it can not guess the host type, give it the | |
7131 | `--host=TYPE' option. `TYPE' can either be a short name for the system | |
7132 | type, such as `sun4', or a canonical name with three fields: | |
7133 | `CPU-COMPANY-SYSTEM' (e.g., `sparc-sun-sunos4.1.2'). | |
ccc6cda3 | 7134 | |
bb70624e JA |
7135 | See the file `support/config.sub' for the possible values of each |
7136 | field. | |
ccc6cda3 | 7137 | |
bb70624e JA |
7138 | \1f |
7139 | File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash | |
7140 | ||
7141 | Sharing Defaults | |
7142 | ================ | |
7143 | ||
7144 | If you want to set default values for `configure' scripts to share, | |
7145 | you can create a site shell script called `config.site' that gives | |
7146 | default values for variables like `CC', `cache_file', and `prefix'. | |
7147 | `configure' looks for `PREFIX/share/config.site' if it exists, then | |
7148 | `PREFIX/etc/config.site' if it exists. Or, you can set the | |
7149 | `CONFIG_SITE' environment variable to the location of the site script. | |
7150 | A warning: the Bash `configure' looks for a site script, but not all | |
7151 | `configure' scripts do. | |
ccc6cda3 JA |
7152 | |
7153 | \1f | |
bb70624e | 7154 | File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash |
ccc6cda3 | 7155 | |
bb70624e JA |
7156 | Operation Controls |
7157 | ================== | |
ccc6cda3 | 7158 | |
bb70624e JA |
7159 | `configure' recognizes the following options to control how it |
7160 | operates. | |
ccc6cda3 | 7161 | |
bb70624e JA |
7162 | `--cache-file=FILE' |
7163 | Use and save the results of the tests in FILE instead of | |
7164 | `./config.cache'. Set FILE to `/dev/null' to disable caching, for | |
7165 | debugging `configure'. | |
ccc6cda3 | 7166 | |
bb70624e JA |
7167 | `--help' |
7168 | Print a summary of the options to `configure', and exit. | |
ccc6cda3 | 7169 | |
bb70624e JA |
7170 | `--quiet' |
7171 | `--silent' | |
7172 | `-q' | |
7173 | Do not print messages saying which checks are being made. | |
ccc6cda3 | 7174 | |
bb70624e JA |
7175 | `--srcdir=DIR' |
7176 | Look for the Bash source code in directory DIR. Usually | |
7177 | `configure' can determine that directory automatically. | |
ccc6cda3 | 7178 | |
bb70624e JA |
7179 | `--version' |
7180 | Print the version of Autoconf used to generate the `configure' | |
7181 | script, and exit. | |
ccc6cda3 | 7182 | |
bb70624e JA |
7183 | `configure' also accepts some other, not widely used, boilerplate |
7184 | options. `configure --help' prints the complete list. | |
ccc6cda3 | 7185 | |
bb70624e JA |
7186 | \1f |
7187 | File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash | |
ccc6cda3 | 7188 | |
bb70624e JA |
7189 | Optional Features |
7190 | ================= | |
ccc6cda3 | 7191 | |
bb70624e JA |
7192 | The Bash `configure' has a number of `--enable-FEATURE' options, |
7193 | where FEATURE indicates an optional part of Bash. There are also | |
7194 | several `--with-PACKAGE' options, where PACKAGE is something like | |
7195 | `bash-malloc' or `purify'. To turn off the default use of a package, | |
7196 | use `--without-PACKAGE'. To configure Bash without a feature that is | |
7197 | enabled by default, use `--disable-FEATURE'. | |
ccc6cda3 | 7198 | |
bb70624e JA |
7199 | Here is a complete list of the `--enable-' and `--with-' options |
7200 | that the Bash `configure' recognizes. | |
ccc6cda3 | 7201 | |
bb70624e JA |
7202 | `--with-afs' |
7203 | Define if you are using the Andrew File System from Transarc. | |
ccc6cda3 | 7204 | |
bb70624e JA |
7205 | `--with-bash-malloc' |
7206 | Use the Bash version of `malloc' in `lib/malloc/malloc.c'. This | |
7207 | is not the same `malloc' that appears in GNU libc, but an older | |
7208 | version derived from the 4.2 BSD `malloc'. This `malloc' is very | |
7209 | fast, but wastes some space on each allocation. This option is | |
7210 | enabled by default. The `NOTES' file contains a list of systems | |
7211 | for which this should be turned off, and `configure' disables this | |
7212 | option automatically for a number of systems. | |
ccc6cda3 | 7213 | |
bb70624e JA |
7214 | `--with-curses' |
7215 | Use the curses library instead of the termcap library. This should | |
7216 | be supplied if your system has an inadequate or incomplete termcap | |
7217 | database. | |
ccc6cda3 | 7218 | |
bb70624e JA |
7219 | `--with-glibc-malloc' |
7220 | Use the GNU libc version of `malloc' in `lib/malloc/gmalloc.c'. | |
7221 | This is not the version of `malloc' that appears in glibc version | |
7222 | 2, but a modified version of the `malloc' from glibc version 1. | |
7223 | This is somewhat slower than the default `malloc', but wastes less | |
7224 | space on a per-allocation basis, and will return memory to the | |
7225 | operating system under certain circumstances. | |
ccc6cda3 | 7226 | |
bb70624e JA |
7227 | `--with-gnu-malloc' |
7228 | A synonym for `--with-bash-malloc'. | |
ccc6cda3 | 7229 | |
bb70624e JA |
7230 | `--with-installed-readline' |
7231 | Define this to make Bash link with a locally-installed version of | |
7232 | Readline rather than the version in `lib/readline'. This works | |
7233 | only with Readline 4.1 and later versions. | |
ccc6cda3 | 7234 | |
bb70624e JA |
7235 | `--with-purify' |
7236 | Define this to use the Purify memory allocation checker from | |
7237 | Rational Software. | |
ccc6cda3 | 7238 | |
bb70624e JA |
7239 | `--enable-minimal-config' |
7240 | This produces a shell with minimal features, close to the | |
7241 | historical Bourne shell. | |
ccc6cda3 | 7242 | |
bb70624e JA |
7243 | There are several `--enable-' options that alter how Bash is |
7244 | compiled and linked, rather than changing run-time features. | |
ccc6cda3 | 7245 | |
bb70624e JA |
7246 | `--enable-profiling' |
7247 | This builds a Bash binary that produces profiling information to be | |
7248 | processed by `gprof' each time it is executed. | |
cce855bc | 7249 | |
bb70624e JA |
7250 | `--enable-static-link' |
7251 | This causes Bash to be linked statically, if `gcc' is being used. | |
7252 | This could be used to build a version to use as root's shell. | |
d166f048 | 7253 | |
bb70624e JA |
7254 | The `minimal-config' option can be used to disable all of the |
7255 | following options, but it is processed first, so individual options may | |
7256 | be enabled using `enable-FEATURE'. | |
d166f048 | 7257 | |
bb70624e JA |
7258 | All of the following options except for `disabled-builtins' and |
7259 | `xpg-echo-default' are enabled by default, unless the operating system | |
7260 | does not provide the necessary support. | |
ccc6cda3 | 7261 | |
bb70624e JA |
7262 | `--enable-alias' |
7263 | Allow alias expansion and include the `alias' and `unalias' | |
28ef6c31 | 7264 | builtins (*note Aliases::). |
ccc6cda3 | 7265 | |
bb70624e JA |
7266 | `--enable-arith-for-command' |
7267 | Include support for the alternate form of the `for' command that | |
7268 | behaves like the C language `for' statement (*note Looping | |
28ef6c31 | 7269 | Constructs::). |
ccc6cda3 | 7270 | |
bb70624e JA |
7271 | `--enable-array-variables' |
7272 | Include support for one-dimensional array shell variables (*note | |
28ef6c31 | 7273 | Arrays::). |
ccc6cda3 | 7274 | |
bb70624e JA |
7275 | `--enable-bang-history' |
7276 | Include support for `csh'-like history substitution (*note History | |
28ef6c31 | 7277 | Interaction::). |
ccc6cda3 | 7278 | |
bb70624e JA |
7279 | `--enable-brace-expansion' |
7280 | Include `csh'-like brace expansion ( `b{a,b}c' ==> `bac bbc' ). | |
7281 | See *Note Brace Expansion::, for a complete description. | |
ccc6cda3 | 7282 | |
bb70624e JA |
7283 | `--enable-command-timing' |
7284 | Include support for recognizing `time' as a reserved word and for | |
7285 | displaying timing statistics for the pipeline following `time' | |
28ef6c31 | 7286 | (*note Pipelines::). This allows pipelines as well as shell |
bb70624e | 7287 | builtins and functions to be timed. |
ccc6cda3 | 7288 | |
bb70624e JA |
7289 | `--enable-cond-command' |
7290 | Include support for the `[[' conditional command (*note | |
28ef6c31 | 7291 | Conditional Constructs::). |
ccc6cda3 | 7292 | |
bb70624e JA |
7293 | `--enable-directory-stack' |
7294 | Include support for a `csh'-like directory stack and the `pushd', | |
28ef6c31 | 7295 | `popd', and `dirs' builtins (*note The Directory Stack::). |
ccc6cda3 | 7296 | |
bb70624e JA |
7297 | `--enable-disabled-builtins' |
7298 | Allow builtin commands to be invoked via `builtin xxx' even after | |
7299 | `xxx' has been disabled using `enable -n xxx'. See *Note Bash | |
7300 | Builtins::, for details of the `builtin' and `enable' builtin | |
7301 | commands. | |
ccc6cda3 | 7302 | |
bb70624e JA |
7303 | `--enable-dparen-arithmetic' |
7304 | Include support for the `((...))' command (*note Conditional | |
28ef6c31 | 7305 | Constructs::). |
ccc6cda3 | 7306 | |
bb70624e JA |
7307 | `--enable-extended-glob' |
7308 | Include support for the extended pattern matching features | |
7309 | described above under *Note Pattern Matching::. | |
ccc6cda3 | 7310 | |
bb70624e JA |
7311 | `--enable-help-builtin' |
7312 | Include the `help' builtin, which displays help on shell builtins | |
28ef6c31 | 7313 | and variables (*note Bash Builtins::). |
ccc6cda3 | 7314 | |
bb70624e JA |
7315 | `--enable-history' |
7316 | Include command history and the `fc' and `history' builtin | |
28ef6c31 | 7317 | commands (*note Bash History Facilities::). |
ccc6cda3 | 7318 | |
bb70624e | 7319 | `--enable-job-control' |
28ef6c31 | 7320 | This enables the job control features (*note Job Control::), if |
bb70624e | 7321 | the operating system supports them. |
ccc6cda3 | 7322 | |
bb70624e JA |
7323 | `--enable-net-redirections' |
7324 | This enables the special handling of filenames of the form | |
7325 | `/dev/tcp/HOST/PORT' and `/dev/udp/HOST/PORT' when used in | |
28ef6c31 | 7326 | redirections (*note Redirections::). |
ccc6cda3 | 7327 | |
bb70624e | 7328 | `--enable-process-substitution' |
28ef6c31 JA |
7329 | This enables process substitution (*note Process Substitution::) if |
7330 | the operating system provides the necessary support. | |
ccc6cda3 | 7331 | |
bb70624e JA |
7332 | `--enable-prompt-string-decoding' |
7333 | Turn on the interpretation of a number of backslash-escaped | |
7334 | characters in the `$PS1', `$PS2', `$PS3', and `$PS4' prompt | |
7335 | strings. See *Note Printing a Prompt::, for a complete list of | |
7336 | prompt string escape sequences. | |
ccc6cda3 | 7337 | |
bb70624e JA |
7338 | `--enable-progcomp' |
7339 | Enable the programmable completion facilities (*note Programmable | |
28ef6c31 | 7340 | Completion::). If Readline is not enabled, this option has no |
bb70624e | 7341 | effect. |
ccc6cda3 | 7342 | |
bb70624e JA |
7343 | `--enable-readline' |
7344 | Include support for command-line editing and history with the Bash | |
28ef6c31 | 7345 | version of the Readline library (*note Command Line Editing::). |
ccc6cda3 | 7346 | |
bb70624e JA |
7347 | `--enable-restricted' |
7348 | Include support for a "restricted shell". If this is enabled, | |
7349 | Bash, when called as `rbash', enters a restricted mode. See *Note | |
7350 | The Restricted Shell::, for a description of restricted mode. | |
ccc6cda3 | 7351 | |
bb70624e JA |
7352 | `--enable-select' |
7353 | Include the `select' builtin, which allows the generation of simple | |
28ef6c31 | 7354 | menus (*note Conditional Constructs::). |
ccc6cda3 | 7355 | |
bb70624e JA |
7356 | `--enable-usg-echo-default' |
7357 | A synonym for `--enable-xpg-echo-default'. | |
ccc6cda3 | 7358 | |
bb70624e JA |
7359 | `--enable-xpg-echo-default' |
7360 | Make the `echo' builtin expand backslash-escaped characters by | |
7361 | default, without requiring the `-e' option. This sets the default | |
7362 | value of the `xpg_echo' shell option to `on', which makes the Bash | |
7363 | `echo' behave more like the version specified in the Single Unix | |
7364 | Specification, version 2. *Note Bash Builtins::, for a | |
7365 | description of the escape sequences that `echo' recognizes. | |
ccc6cda3 | 7366 | |
bb70624e JA |
7367 | The file `config-top.h' contains C Preprocessor `#define' statements |
7368 | for options which are not settable from `configure'. Some of these are | |
7369 | not meant to be changed; beware of the consequences if you do. Read | |
7370 | the comments associated with each definition for more information about | |
7371 | its effect. | |
ccc6cda3 | 7372 | |
bb70624e JA |
7373 | \1f |
7374 | File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top | |
d166f048 | 7375 | |
bb70624e JA |
7376 | Reporting Bugs |
7377 | ************** | |
ccc6cda3 | 7378 | |
bb70624e JA |
7379 | Please report all bugs you find in Bash. But first, you should make |
7380 | sure that it really is a bug, and that it appears in the latest version | |
7381 | of Bash that you have. | |
ccc6cda3 | 7382 | |
bb70624e JA |
7383 | Once you have determined that a bug actually exists, use the |
7384 | `bashbug' command to submit a bug report. If you have a fix, you are | |
7385 | encouraged to mail that as well! Suggestions and `philosophical' bug | |
7386 | reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet | |
7387 | newsgroup `gnu.bash.bug'. | |
ccc6cda3 | 7388 | |
bb70624e JA |
7389 | All bug reports should include: |
7390 | * The version number of Bash. | |
ccc6cda3 | 7391 | |
bb70624e | 7392 | * The hardware and operating system. |
ccc6cda3 | 7393 | |
bb70624e | 7394 | * The compiler used to compile Bash. |
ccc6cda3 | 7395 | |
bb70624e | 7396 | * A description of the bug behaviour. |
ccc6cda3 | 7397 | |
bb70624e JA |
7398 | * A short script or `recipe' which exercises the bug and may be used |
7399 | to reproduce it. | |
ccc6cda3 | 7400 | |
bb70624e JA |
7401 | `bashbug' inserts the first three items automatically into the template |
7402 | it provides for filing a bug report. | |
7403 | ||
7404 | Please send all reports concerning this manual to <chet@po.CWRU.Edu>. | |
ccc6cda3 JA |
7405 | |
7406 | \1f | |
bb70624e | 7407 | File: bashref.info, Node: Major Differences From The Bourne Shell, Next: Builtin Index, Prev: Reporting Bugs, Up: Top |
ccc6cda3 | 7408 | |
bb70624e JA |
7409 | Major Differences From The Bourne Shell |
7410 | *************************************** | |
ccc6cda3 | 7411 | |
bb70624e JA |
7412 | Bash implements essentially the same grammar, parameter and variable |
7413 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the | |
7414 | POSIX 1003.2 standard as the specification of how these features are to | |
7415 | be implemented. There are some differences between the traditional | |
7416 | Bourne shell and Bash; this section quickly details the differences of | |
7417 | significance. A number of these differences are explained in greater | |
7418 | depth in previous sections. This section uses the version of `sh' | |
28ef6c31 | 7419 | included in SVR4.2 as the baseline reference. |
ccc6cda3 | 7420 | |
bb70624e | 7421 | * Bash is POSIX-conformant, even where the POSIX specification |
28ef6c31 | 7422 | differs from traditional `sh' behavior (*note Bash POSIX Mode::). |
ccc6cda3 | 7423 | |
bb70624e | 7424 | * Bash has multi-character invocation options (*note Invoking |
28ef6c31 | 7425 | Bash::). |
ccc6cda3 | 7426 | |
28ef6c31 | 7427 | * Bash has command-line editing (*note Command Line Editing::) and |
bb70624e | 7428 | the `bind' builtin. |
ccc6cda3 | 7429 | |
bb70624e | 7430 | * Bash provides a programmable word completion mechanism (*note |
28ef6c31 | 7431 | Programmable Completion::), and two builtin commands, `complete' |
bb70624e | 7432 | and `compgen', to manipulate it. |
ccc6cda3 | 7433 | |
28ef6c31 | 7434 | * Bash has command history (*note Bash History Facilities::) and the |
bb70624e | 7435 | `history' and `fc' builtins to manipulate it. |
ccc6cda3 | 7436 | |
bb70624e | 7437 | * Bash implements `csh'-like history expansion (*note History |
28ef6c31 | 7438 | Interaction::). |
ccc6cda3 | 7439 | |
28ef6c31 | 7440 | * Bash has one-dimensional array variables (*note Arrays::), and the |
bb70624e JA |
7441 | appropriate variable expansions and assignment syntax to use them. |
7442 | Several of the Bash builtins take options to act on arrays. Bash | |
7443 | provides a number of built-in array variables. | |
ccc6cda3 | 7444 | |
bb70624e JA |
7445 | * The `$'...'' quoting syntax, which expands ANSI-C |
7446 | backslash-escaped characters in the text between the single quotes, | |
28ef6c31 | 7447 | is supported (*note ANSI-C Quoting::). |
ccc6cda3 | 7448 | |
bb70624e JA |
7449 | * Bash supports the `$"..."' quoting syntax to do locale-specific |
7450 | translation of the characters between the double quotes. The | |
7451 | `-D', `--dump-strings', and `--dump-po-strings' invocation options | |
7452 | list the translatable strings found in a script (*note Locale | |
28ef6c31 | 7453 | Translation::). |
ccc6cda3 | 7454 | |
bb70624e | 7455 | * Bash implements the `!' keyword to negate the return value of a |
28ef6c31 | 7456 | pipeline (*note Pipelines::). Very useful when an `if' statement |
bb70624e | 7457 | needs to act only if a test fails. |
ccc6cda3 | 7458 | |
bb70624e | 7459 | * Bash has the `time' reserved word and command timing (*note |
28ef6c31 | 7460 | Pipelines::). The display of the timing statistics may be |
bb70624e | 7461 | controlled with the `TIMEFORMAT' variable. |
ccc6cda3 | 7462 | |
bb70624e JA |
7463 | * Bash implements the `for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic |
7464 | for command, similar to the C language (*note Looping | |
28ef6c31 | 7465 | Constructs::). |
ccc6cda3 | 7466 | |
bb70624e | 7467 | * Bash includes the `select' compound command, which allows the |
28ef6c31 | 7468 | generation of simple menus (*note Conditional Constructs::). |
ccc6cda3 | 7469 | |
bb70624e | 7470 | * Bash includes the `[[' compound command, which makes conditional |
28ef6c31 | 7471 | testing part of the shell grammar (*note Conditional Constructs::). |
ccc6cda3 | 7472 | |
28ef6c31 JA |
7473 | * Bash includes brace expansion (*note Brace Expansion::) and tilde |
7474 | expansion (*note Tilde Expansion::). | |
ccc6cda3 | 7475 | |
bb70624e | 7476 | * Bash implements command aliases and the `alias' and `unalias' |
28ef6c31 | 7477 | builtins (*note Aliases::). |
ccc6cda3 | 7478 | |
bb70624e | 7479 | * Bash provides shell arithmetic, the `((' compound command (*note |
28ef6c31 JA |
7480 | Conditional Constructs::), and arithmetic expansion (*note Shell |
7481 | Arithmetic::). | |
ccc6cda3 | 7482 | |
bb70624e JA |
7483 | * Variables present in the shell's initial environment are |
7484 | automatically exported to child processes. The Bourne shell does | |
7485 | not normally do this unless the variables are explicitly marked | |
7486 | using the `export' command. | |
ccc6cda3 | 7487 | |
bb70624e JA |
7488 | * Bash includes the POSIX pattern removal `%', `#', `%%' and `##' |
7489 | expansions to remove leading or trailing substrings from variable | |
28ef6c31 | 7490 | values (*note Shell Parameter Expansion::). |
ccc6cda3 | 7491 | |
bb70624e | 7492 | * The expansion `${#xx}', which returns the length of `${xx}', is |
28ef6c31 | 7493 | supported (*note Shell Parameter Expansion::). |
ccc6cda3 | 7494 | |
bb70624e JA |
7495 | * The expansion `${var:'OFFSET`[:'LENGTH`]}', which expands to the |
7496 | substring of `var''s value of length LENGTH, beginning at OFFSET, | |
28ef6c31 | 7497 | is present (*note Shell Parameter Expansion::). |
ccc6cda3 | 7498 | |
bb70624e JA |
7499 | * The expansion `${var/[/]'PATTERN`[/'REPLACEMENT`]}', which matches |
7500 | PATTERN and replaces it with REPLACEMENT in the value of `var', is | |
28ef6c31 | 7501 | available (*note Shell Parameter Expansion::). |
ccc6cda3 | 7502 | |
bb70624e JA |
7503 | * The expansion `${!PREFIX}*' expansion, which expands to the names |
7504 | of all shell variables whose names begin with PREFIX, is available | |
28ef6c31 | 7505 | (*note Shell Parameter Expansion::). |
ccc6cda3 | 7506 | |
bb70624e | 7507 | * Bash has INDIRECT variable expansion using `${!word}' (*note Shell |
28ef6c31 | 7508 | Parameter Expansion::). |
ccc6cda3 | 7509 | |
bb70624e | 7510 | * Bash can expand positional parameters beyond `$9' using `${NUM}'. |
ccc6cda3 | 7511 | |
bb70624e | 7512 | * The POSIX `$()' form of command substitution is implemented (*note |
28ef6c31 | 7513 | Command Substitution::), and preferred to the Bourne shell's ```' |
bb70624e | 7514 | (which is also implemented for backwards compatibility). |
ccc6cda3 | 7515 | |
28ef6c31 | 7516 | * Bash has process substitution (*note Process Substitution::). |
ccc6cda3 | 7517 | |
bb70624e JA |
7518 | * Bash automatically assigns variables that provide information |
7519 | about the current user (`UID', `EUID', and `GROUPS'), the current | |
7520 | host (`HOSTTYPE', `OSTYPE', `MACHTYPE', and `HOSTNAME'), and the | |
7521 | instance of Bash that is running (`BASH', `BASH_VERSION', and | |
7522 | `BASH_VERSINFO'). *Note Bash Variables::, for details. | |
ccc6cda3 | 7523 | |
bb70624e | 7524 | * The `IFS' variable is used to split only the results of expansion, |
28ef6c31 | 7525 | not all words (*note Word Splitting::). This closes a |
bb70624e | 7526 | longstanding shell security hole. |
ccc6cda3 | 7527 | |
bb70624e JA |
7528 | * Bash implements the full set of POSIX 1003.2 filename expansion |
7529 | operators, including CHARACTER CLASSES, EQUIVALENCE CLASSES, and | |
28ef6c31 | 7530 | COLLATING SYMBOLS (*note Filename Expansion::). |
ccc6cda3 | 7531 | |
bb70624e | 7532 | * Bash implements extended pattern matching features when the |
28ef6c31 | 7533 | `extglob' shell option is enabled (*note Pattern Matching::). |
ccc6cda3 | 7534 | |
bb70624e JA |
7535 | * It is possible to have a variable and a function with the same |
7536 | name; `sh' does not separate the two name spaces. | |
ccc6cda3 | 7537 | |
bb70624e JA |
7538 | * Bash functions are permitted to have local variables using the |
7539 | `local' builtin, and thus useful recursive functions may be written | |
28ef6c31 | 7540 | (*note Bash Builtins::). |
ccc6cda3 | 7541 | |
bb70624e | 7542 | * Variable assignments preceding commands affect only that command, |
28ef6c31 | 7543 | even builtins and functions (*note Environment::). In `sh', all |
bb70624e JA |
7544 | variable assignments preceding commands are global unless the |
7545 | command is executed from the file system. | |
ccc6cda3 | 7546 | |
bb70624e | 7547 | * Bash performs filename expansion on filenames specified as operands |
28ef6c31 | 7548 | to input and output redirection operators (*note Redirections::). |
ccc6cda3 | 7549 | |
bb70624e JA |
7550 | * Bash contains the `<>' redirection operator, allowing a file to be |
7551 | opened for both reading and writing, and the `&>' redirection | |
7552 | operator, for directing standard output and standard error to the | |
28ef6c31 | 7553 | same file (*note Redirections::). |
d166f048 | 7554 | |
bb70624e | 7555 | * Bash treats a number of filenames specially when they are used in |
28ef6c31 | 7556 | redirection operators (*note Redirections::). |
ccc6cda3 | 7557 | |
bb70624e | 7558 | * Bash can open network connections to arbitrary machines and |
28ef6c31 | 7559 | services with the redirection operators (*note Redirections::). |
ccc6cda3 | 7560 | |
bb70624e | 7561 | * The `noclobber' option is available to avoid overwriting existing |
28ef6c31 JA |
7562 | files with output redirection (*note The Set Builtin::). The `>|' |
7563 | redirection operator may be used to override `noclobber'. | |
ccc6cda3 | 7564 | |
28ef6c31 JA |
7565 | * The Bash `cd' and `pwd' builtins (*note Bourne Shell Builtins::) |
7566 | each take `-L' and `-P' options to switch between logical and | |
bb70624e | 7567 | physical modes. |
b72432fd | 7568 | |
bb70624e JA |
7569 | * Bash allows a function to override a builtin with the same name, |
7570 | and provides access to that builtin's functionality within the | |
7571 | function via the `builtin' and `command' builtins (*note Bash | |
28ef6c31 | 7572 | Builtins::). |
ccc6cda3 | 7573 | |
bb70624e | 7574 | * The `command' builtin allows selective disabling of functions when |
28ef6c31 | 7575 | command lookup is performed (*note Bash Builtins::). |
ccc6cda3 | 7576 | |
bb70624e | 7577 | * Individual builtins may be enabled or disabled using the `enable' |
28ef6c31 | 7578 | builtin (*note Bash Builtins::). |
cce855bc | 7579 | |
bb70624e JA |
7580 | * The Bash `exec' builtin takes additional options that allow users |
7581 | to control the contents of the environment passed to the executed | |
7582 | command, and what the zeroth argument to the command is to be | |
28ef6c31 | 7583 | (*note Bourne Shell Builtins::). |
cce855bc | 7584 | |
bb70624e | 7585 | * Shell functions may be exported to children via the environment |
28ef6c31 | 7586 | using `export -f' (*note Shell Functions::). |
cce855bc | 7587 | |
bb70624e JA |
7588 | * The Bash `export', `readonly', and `declare' builtins can take a |
7589 | `-f' option to act on shell functions, a `-p' option to display | |
7590 | variables with various attributes set in a format that can be used | |
7591 | as shell input, a `-n' option to remove various variable | |
7592 | attributes, and `name=value' arguments to set variable attributes | |
7593 | and values simultaneously. | |
ccc6cda3 | 7594 | |
bb70624e JA |
7595 | * The Bash `hash' builtin allows a name to be associated with an |
7596 | arbitrary filename, even when that filename cannot be found by | |
7597 | searching the `$PATH', using `hash -p' (*note Bourne Shell | |
28ef6c31 | 7598 | Builtins::). |
ccc6cda3 | 7599 | |
bb70624e | 7600 | * Bash includes a `help' builtin for quick reference to shell |
28ef6c31 | 7601 | facilities (*note Bash Builtins::). |
ccc6cda3 | 7602 | |
bb70624e | 7603 | * The `printf' builtin is available to display formatted output |
28ef6c31 | 7604 | (*note Bash Builtins::). |
ccc6cda3 | 7605 | |
28ef6c31 | 7606 | * The Bash `read' builtin (*note Bash Builtins::) will read a line |
bb70624e JA |
7607 | ending in `\' with the `-r' option, and will use the `REPLY' |
7608 | variable as a default if no non-option arguments are supplied. | |
7609 | The Bash `read' builtin also accepts a prompt string with the `-p' | |
7610 | option and will use Readline to obtain the line when given the | |
7611 | `-e' option. The `read' builtin also has additional options to | |
7612 | control input: the `-s' option will turn off echoing of input | |
7613 | characters as they are read, the `-t' option will allow `read' to | |
7614 | time out if input does not arrive within a specified number of | |
7615 | seconds, the `-n' option will allow reading only a specified | |
7616 | number of characters rather than a full line, and the `-d' option | |
7617 | will read until a particular character rather than newline. | |
ccc6cda3 | 7618 | |
bb70624e JA |
7619 | * The `return' builtin may be used to abort execution of scripts |
7620 | executed with the `.' or `source' builtins (*note Bourne Shell | |
28ef6c31 | 7621 | Builtins::). |
d166f048 | 7622 | |
bb70624e | 7623 | * Bash includes the `shopt' builtin, for finer control of shell |
28ef6c31 | 7624 | optional capabilities (*note Bash Builtins::). |
d166f048 | 7625 | |
bb70624e | 7626 | * Bash has much more optional behavior controllable with the `set' |
28ef6c31 | 7627 | builtin (*note The Set Builtin::). |
cce855bc | 7628 | |
28ef6c31 | 7629 | * The `test' builtin (*note Bourne Shell Builtins::) is slightly |
bb70624e JA |
7630 | different, as it implements the POSIX algorithm, which specifies |
7631 | the behavior based on the number of arguments. | |
ccc6cda3 | 7632 | |
28ef6c31 | 7633 | * The `trap' builtin (*note Bourne Shell Builtins::) allows a |
bb70624e JA |
7634 | `DEBUG' pseudo-signal specification, similar to `EXIT'. Commands |
7635 | specified with a `DEBUG' trap are executed after every simple | |
7636 | command. The `DEBUG' trap is not inherited by shell functions. | |
d166f048 | 7637 | |
bb70624e | 7638 | * The Bash `type' builtin is more extensive and gives more |
28ef6c31 | 7639 | information about the names it finds (*note Bash Builtins::). |
cce855bc | 7640 | |
bb70624e JA |
7641 | * The Bash `umask' builtin permits a `-p' option to cause the output |
7642 | to be displayed in the form of a `umask' command that may be | |
28ef6c31 | 7643 | reused as input (*note Bourne Shell Builtins::). |
d166f048 | 7644 | |
bb70624e JA |
7645 | * Bash implements a `csh'-like directory stack, and provides the |
7646 | `pushd', `popd', and `dirs' builtins to manipulate it (*note The | |
28ef6c31 | 7647 | Directory Stack::). Bash also makes the directory stack visible |
bb70624e | 7648 | as the value of the `DIRSTACK' shell variable. |
d166f048 | 7649 | |
bb70624e | 7650 | * Bash interprets special backslash-escaped characters in the prompt |
28ef6c31 | 7651 | strings when interactive (*note Printing a Prompt::). |
d166f048 | 7652 | |
bb70624e | 7653 | * The Bash restricted mode is more useful (*note The Restricted |
28ef6c31 | 7654 | Shell::); the SVR4.2 shell restricted mode is too limited. |
ccc6cda3 | 7655 | |
bb70624e | 7656 | * The `disown' builtin can remove a job from the internal shell job |
28ef6c31 | 7657 | table (*note Job Control Builtins::) or suppress the sending of |
bb70624e | 7658 | `SIGHUP' to a job when the shell exits as the result of a `SIGHUP'. |
ccc6cda3 | 7659 | |
bb70624e JA |
7660 | * The SVR4.2 shell has two privilege-related builtins (`mldmode' and |
7661 | `priv') not present in Bash. | |
ccc6cda3 | 7662 | |
bb70624e | 7663 | * Bash does not have the `stop' or `newgrp' builtins. |
d166f048 | 7664 | |
bb70624e JA |
7665 | * Bash does not use the `SHACCT' variable or perform shell |
7666 | accounting. | |
d166f048 | 7667 | |
bb70624e | 7668 | * The SVR4.2 `sh' uses a `TIMEOUT' variable like Bash uses `TMOUT'. |
ccc6cda3 | 7669 | |
28ef6c31 | 7670 | |
bb70624e | 7671 | More features unique to Bash may be found in *Note Bash Features::. |
ccc6cda3 | 7672 | |
bb70624e JA |
7673 | Implementation Differences From The SVR4.2 Shell |
7674 | ================================================ | |
ccc6cda3 | 7675 | |
bb70624e JA |
7676 | Since Bash is a completely new implementation, it does not suffer |
7677 | from many of the limitations of the SVR4.2 shell. For instance: | |
ccc6cda3 | 7678 | |
bb70624e JA |
7679 | * Bash does not fork a subshell when redirecting into or out of a |
7680 | shell control structure such as an `if' or `while' statement. | |
ccc6cda3 | 7681 | |
bb70624e JA |
7682 | * Bash does not allow unbalanced quotes. The SVR4.2 shell will |
7683 | silently insert a needed closing quote at `EOF' under certain | |
7684 | circumstances. This can be the cause of some hard-to-find errors. | |
ccc6cda3 | 7685 | |
bb70624e JA |
7686 | * The SVR4.2 shell uses a baroque memory management scheme based on |
7687 | trapping `SIGSEGV'. If the shell is started from a process with | |
7688 | `SIGSEGV' blocked (e.g., by using the `system()' C library | |
7689 | function call), it misbehaves badly. | |
ccc6cda3 | 7690 | |
bb70624e JA |
7691 | * In a questionable attempt at security, the SVR4.2 shell, when |
7692 | invoked without the `-p' option, will alter its real and effective | |
7693 | UID and GID if they are less than some magic threshold value, | |
7694 | commonly 100. This can lead to unexpected results. | |
ccc6cda3 | 7695 | |
bb70624e JA |
7696 | * The SVR4.2 shell does not allow users to trap `SIGSEGV', |
7697 | `SIGALRM', or `SIGCHLD'. | |
ccc6cda3 | 7698 | |
bb70624e JA |
7699 | * The SVR4.2 shell does not allow the `IFS', `MAILCHECK', `PATH', |
7700 | `PS1', or `PS2' variables to be unset. | |
ccc6cda3 | 7701 | |
bb70624e | 7702 | * The SVR4.2 shell treats `^' as the undocumented equivalent of `|'. |
ccc6cda3 | 7703 | |
bb70624e JA |
7704 | * Bash allows multiple option arguments when it is invoked (`-x -v'); |
7705 | the SVR4.2 shell allows only one option argument (`-xv'). In | |
7706 | fact, some versions of the shell dump core if the second argument | |
7707 | begins with a `-'. | |
ccc6cda3 | 7708 | |
bb70624e JA |
7709 | * The SVR4.2 shell exits a script if any builtin fails; Bash exits a |
7710 | script only if one of the POSIX 1003.2 special builtins fails, and | |
7711 | only for certain failures, as enumerated in the POSIX 1003.2 | |
7712 | standard. | |
ccc6cda3 | 7713 | |
bb70624e JA |
7714 | * The SVR4.2 shell behaves differently when invoked as `jsh' (it |
7715 | turns on job control). | |
ccc6cda3 JA |
7716 | |
7717 | \1f | |
bb70624e | 7718 | File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Prev: Major Differences From The Bourne Shell, Up: Top |
ccc6cda3 JA |
7719 | |
7720 | Index of Shell Builtin Commands | |
7721 | ******************************* | |
7722 | ||
7723 | * Menu: | |
7724 | ||
e8ce775d JA |
7725 | * .: Bourne Shell Builtins. |
7726 | * :: Bourne Shell Builtins. | |
7727 | * [: Bourne Shell Builtins. | |
bb70624e | 7728 | * alias: Bash Builtins. |
e8ce775d JA |
7729 | * bg: Job Control Builtins. |
7730 | * bind: Bash Builtins. | |
7731 | * break: Bourne Shell Builtins. | |
7732 | * builtin: Bash Builtins. | |
7733 | * cd: Bourne Shell Builtins. | |
7734 | * command: Bash Builtins. | |
bb70624e JA |
7735 | * compgen: Programmable Completion Builtins. |
7736 | * complete: Programmable Completion Builtins. | |
e8ce775d JA |
7737 | * continue: Bourne Shell Builtins. |
7738 | * declare: Bash Builtins. | |
bb70624e | 7739 | * dirs: Directory Stack Builtins. |
e8ce775d JA |
7740 | * disown: Job Control Builtins. |
7741 | * echo: Bash Builtins. | |
7742 | * enable: Bash Builtins. | |
7743 | * eval: Bourne Shell Builtins. | |
7744 | * exec: Bourne Shell Builtins. | |
7745 | * exit: Bourne Shell Builtins. | |
7746 | * export: Bourne Shell Builtins. | |
cce855bc | 7747 | * fc: Bash History Builtins. |
e8ce775d JA |
7748 | * fg: Job Control Builtins. |
7749 | * getopts: Bourne Shell Builtins. | |
7750 | * hash: Bourne Shell Builtins. | |
7751 | * help: Bash Builtins. | |
cce855bc | 7752 | * history: Bash History Builtins. |
e8ce775d JA |
7753 | * jobs: Job Control Builtins. |
7754 | * kill: Job Control Builtins. | |
cce855bc | 7755 | * let: Bash Builtins. |
e8ce775d | 7756 | * local: Bash Builtins. |
cce855bc | 7757 | * logout: Bash Builtins. |
bb70624e | 7758 | * popd: Directory Stack Builtins. |
cce855bc | 7759 | * printf: Bash Builtins. |
bb70624e | 7760 | * pushd: Directory Stack Builtins. |
e8ce775d JA |
7761 | * pwd: Bourne Shell Builtins. |
7762 | * read: Bash Builtins. | |
7763 | * readonly: Bourne Shell Builtins. | |
7764 | * return: Bourne Shell Builtins. | |
7765 | * set: The Set Builtin. | |
7766 | * shift: Bourne Shell Builtins. | |
7767 | * shopt: Bash Builtins. | |
cce855bc | 7768 | * source: Bash Builtins. |
e8ce775d JA |
7769 | * suspend: Job Control Builtins. |
7770 | * test: Bourne Shell Builtins. | |
7771 | * times: Bourne Shell Builtins. | |
7772 | * trap: Bourne Shell Builtins. | |
7773 | * type: Bash Builtins. | |
cce855bc | 7774 | * typeset: Bash Builtins. |
e8ce775d JA |
7775 | * ulimit: Bash Builtins. |
7776 | * umask: Bourne Shell Builtins. | |
bb70624e | 7777 | * unalias: Bash Builtins. |
e8ce775d JA |
7778 | * unset: Bourne Shell Builtins. |
7779 | * wait: Job Control Builtins. | |
ccc6cda3 JA |
7780 | |
7781 | \1f | |
7782 | File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Top | |
7783 | ||
bb70624e JA |
7784 | Index of Shell Reserved Words |
7785 | ***************************** | |
ccc6cda3 JA |
7786 | |
7787 | * Menu: | |
7788 | ||
e8ce775d | 7789 | * !: Pipelines. |
cce855bc JA |
7790 | * [[: Conditional Constructs. |
7791 | * ]]: Conditional Constructs. | |
e8ce775d JA |
7792 | * case: Conditional Constructs. |
7793 | * do: Looping Constructs. | |
7794 | * done: Looping Constructs. | |
7795 | * elif: Conditional Constructs. | |
7796 | * else: Conditional Constructs. | |
7797 | * esac: Conditional Constructs. | |
7798 | * fi: Conditional Constructs. | |
7799 | * for: Looping Constructs. | |
7800 | * function: Shell Functions. | |
7801 | * if: Conditional Constructs. | |
7802 | * in: Conditional Constructs. | |
cce855bc | 7803 | * select: Conditional Constructs. |
e8ce775d JA |
7804 | * then: Conditional Constructs. |
7805 | * time: Pipelines. | |
7806 | * until: Looping Constructs. | |
7807 | * while: Looping Constructs. | |
7808 | * {: Command Grouping. | |
7809 | * }: Command Grouping. | |
ccc6cda3 JA |
7810 | |
7811 | \1f | |
7812 | File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Top | |
7813 | ||
7814 | Parameter and Variable Index | |
7815 | **************************** | |
7816 | ||
7817 | * Menu: | |
7818 | ||
e8ce775d JA |
7819 | * !: Special Parameters. |
7820 | * #: Special Parameters. | |
7821 | * $: Special Parameters. | |
7822 | * *: Special Parameters. | |
7823 | * -: Special Parameters. | |
7824 | * 0: Special Parameters. | |
7825 | * ?: Special Parameters. | |
7826 | * @: Special Parameters. | |
7827 | * _: Special Parameters. | |
7828 | * auto_resume: Job Control Variables. | |
7829 | * BASH: Bash Variables. | |
7830 | * BASH_ENV: Bash Variables. | |
7831 | * BASH_VERSINFO: Bash Variables. | |
7832 | * BASH_VERSION: Bash Variables. | |
7833 | * bell-style: Readline Init File Syntax. | |
7834 | * CDPATH: Bourne Shell Variables. | |
28ef6c31 | 7835 | * COLUMNS: Bash Variables. |
e8ce775d | 7836 | * comment-begin: Readline Init File Syntax. |
bb70624e JA |
7837 | * COMP_CWORD: Bash Variables. |
7838 | * COMP_LINE: Bash Variables. | |
7839 | * COMP_POINT: Bash Variables. | |
7840 | * COMP_WORDS: Bash Variables. | |
e8ce775d | 7841 | * completion-query-items: Readline Init File Syntax. |
bb70624e | 7842 | * COMPREPLY: Bash Variables. |
e8ce775d JA |
7843 | * convert-meta: Readline Init File Syntax. |
7844 | * DIRSTACK: Bash Variables. | |
7845 | * disable-completion: Readline Init File Syntax. | |
7846 | * editing-mode: Readline Init File Syntax. | |
7847 | * enable-keypad: Readline Init File Syntax. | |
7848 | * EUID: Bash Variables. | |
7849 | * expand-tilde: Readline Init File Syntax. | |
cce855bc | 7850 | * FCEDIT: Bash Variables. |
e8ce775d | 7851 | * FIGNORE: Bash Variables. |
bb70624e | 7852 | * FUNCNAME: Bash Variables. |
e8ce775d JA |
7853 | * GLOBIGNORE: Bash Variables. |
7854 | * GROUPS: Bash Variables. | |
7855 | * histchars: Bash Variables. | |
7856 | * HISTCMD: Bash Variables. | |
7857 | * HISTCONTROL: Bash Variables. | |
7858 | * HISTFILE: Bash Variables. | |
7859 | * HISTFILESIZE: Bash Variables. | |
7860 | * HISTIGNORE: Bash Variables. | |
7861 | * HISTSIZE: Bash Variables. | |
7862 | * HOME: Bourne Shell Variables. | |
7863 | * horizontal-scroll-mode: Readline Init File Syntax. | |
7864 | * HOSTFILE: Bash Variables. | |
7865 | * HOSTNAME: Bash Variables. | |
7866 | * HOSTTYPE: Bash Variables. | |
7867 | * IFS: Bourne Shell Variables. | |
cce855bc | 7868 | * IGNOREEOF: Bash Variables. |
e8ce775d JA |
7869 | * input-meta: Readline Init File Syntax. |
7870 | * INPUTRC: Bash Variables. | |
b72432fd | 7871 | * isearch-terminators: Readline Init File Syntax. |
e8ce775d JA |
7872 | * keymap: Readline Init File Syntax. |
7873 | * LANG: Bash Variables. | |
7874 | * LC_ALL: Bash Variables. | |
7875 | * LC_COLLATE: Bash Variables. | |
cce855bc | 7876 | * LC_CTYPE: Bash Variables. |
e8ce775d | 7877 | * LC_MESSAGES: Bash Variables. |
bb70624e | 7878 | * LC_NUMERIC: Bash Variables. |
cce855bc | 7879 | * LINENO: Bash Variables. |
28ef6c31 | 7880 | * LINES: Bash Variables. |
e8ce775d JA |
7881 | * MACHTYPE: Bash Variables. |
7882 | * MAIL: Bourne Shell Variables. | |
7883 | * MAILCHECK: Bash Variables. | |
7884 | * MAILPATH: Bourne Shell Variables. | |
7885 | * mark-modified-lines: Readline Init File Syntax. | |
7886 | * meta-flag: Readline Init File Syntax. | |
cce855bc | 7887 | * OLDPWD: Bash Variables. |
e8ce775d JA |
7888 | * OPTARG: Bourne Shell Variables. |
7889 | * OPTERR: Bash Variables. | |
7890 | * OPTIND: Bourne Shell Variables. | |
7891 | * OSTYPE: Bash Variables. | |
7892 | * output-meta: Readline Init File Syntax. | |
7893 | * PATH: Bourne Shell Variables. | |
7894 | * PIPESTATUS: Bash Variables. | |
7895 | * PPID: Bash Variables. | |
7896 | * PROMPT_COMMAND: Bash Variables. | |
7897 | * PS1: Bourne Shell Variables. | |
7898 | * PS2: Bourne Shell Variables. | |
cce855bc JA |
7899 | * PS3: Bash Variables. |
7900 | * PS4: Bash Variables. | |
7901 | * PWD: Bash Variables. | |
7902 | * RANDOM: Bash Variables. | |
7903 | * REPLY: Bash Variables. | |
7904 | * SECONDS: Bash Variables. | |
e8ce775d JA |
7905 | * SHELLOPTS: Bash Variables. |
7906 | * SHLVL: Bash Variables. | |
7907 | * show-all-if-ambiguous: Readline Init File Syntax. | |
7908 | * TIMEFORMAT: Bash Variables. | |
cce855bc | 7909 | * TMOUT: Bash Variables. |
e8ce775d JA |
7910 | * UID: Bash Variables. |
7911 | * visible-stats: Readline Init File Syntax. | |
ccc6cda3 JA |
7912 | |
7913 | \1f | |
7914 | File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Top | |
7915 | ||
7916 | Function Index | |
7917 | ************** | |
7918 | ||
7919 | * Menu: | |
7920 | ||
e8ce775d | 7921 | * abort (C-g): Miscellaneous Commands. |
28ef6c31 | 7922 | * accept-line (Newline or Return): Commands For History. |
e8ce775d JA |
7923 | * backward-char (C-b): Commands For Moving. |
7924 | * backward-delete-char (Rubout): Commands For Text. | |
7925 | * backward-kill-line (C-x Rubout): Commands For Killing. | |
28ef6c31 | 7926 | * backward-kill-word (M-<DEL>): Commands For Killing. |
e8ce775d JA |
7927 | * backward-word (M-b): Commands For Moving. |
7928 | * beginning-of-history (M-<): Commands For History. | |
7929 | * beginning-of-line (C-a): Commands For Moving. | |
7930 | * call-last-kbd-macro (C-x e): Keyboard Macros. | |
7931 | * capitalize-word (M-c): Commands For Text. | |
7932 | * character-search (C-]): Miscellaneous Commands. | |
7933 | * character-search-backward (M-C-]): Miscellaneous Commands. | |
7934 | * clear-screen (C-l): Commands For Moving. | |
28ef6c31 | 7935 | * complete (<TAB>): Commands For Completion. |
e8ce775d JA |
7936 | * copy-backward-word (): Commands For Killing. |
7937 | * copy-forward-word (): Commands For Killing. | |
7938 | * copy-region-as-kill (): Commands For Killing. | |
7939 | * delete-char (C-d): Commands For Text. | |
b72432fd | 7940 | * delete-char-or-list (): Commands For Completion. |
e8ce775d JA |
7941 | * delete-horizontal-space (): Commands For Killing. |
7942 | * digit-argument (M-0, M-1, ... M--): Numeric Arguments. | |
ccc6cda3 | 7943 | * do-uppercase-version (M-a, M-b, M-X, ...): Miscellaneous Commands. |
e8ce775d JA |
7944 | * downcase-word (M-l): Commands For Text. |
7945 | * dump-functions (): Miscellaneous Commands. | |
7946 | * dump-macros (): Miscellaneous Commands. | |
7947 | * dump-variables (): Miscellaneous Commands. | |
7948 | * end-kbd-macro (C-x )): Keyboard Macros. | |
7949 | * end-of-history (M->): Commands For History. | |
7950 | * end-of-line (C-e): Commands For Moving. | |
7951 | * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. | |
b72432fd | 7952 | * forward-backward-delete-char (): Commands For Text. |
e8ce775d JA |
7953 | * forward-char (C-f): Commands For Moving. |
7954 | * forward-search-history (C-s): Commands For History. | |
7955 | * forward-word (M-f): Commands For Moving. | |
7956 | * history-search-backward (): Commands For History. | |
7957 | * history-search-forward (): Commands For History. | |
7958 | * insert-comment (M-#): Miscellaneous Commands. | |
7959 | * insert-completions (M-*): Commands For Completion. | |
7960 | * kill-line (C-k): Commands For Killing. | |
7961 | * kill-region (): Commands For Killing. | |
7962 | * kill-whole-line (): Commands For Killing. | |
7963 | * kill-word (M-d): Commands For Killing. | |
cce855bc | 7964 | * menu-complete (): Commands For Completion. |
e8ce775d | 7965 | * next-history (C-n): Commands For History. |
ccc6cda3 JA |
7966 | * non-incremental-forward-search-history (M-n): Commands For History. |
7967 | * non-incremental-reverse-search-history (M-p): Commands For History. | |
e8ce775d | 7968 | * possible-completions (M-?): Commands For Completion. |
28ef6c31 | 7969 | * prefix-meta (<ESC>): Miscellaneous Commands. |
e8ce775d | 7970 | * previous-history (C-p): Commands For History. |
28ef6c31 | 7971 | * quoted-insert (C-q or C-v): Commands For Text. |
e8ce775d JA |
7972 | * re-read-init-file (C-x C-r): Miscellaneous Commands. |
7973 | * redraw-current-line (): Commands For Moving. | |
7974 | * reverse-search-history (C-r): Commands For History. | |
7975 | * revert-line (M-r): Miscellaneous Commands. | |
7976 | * self-insert (a, b, A, 1, !, ...): Commands For Text. | |
7977 | * set-mark (C-@): Miscellaneous Commands. | |
7978 | * start-kbd-macro (C-x (): Keyboard Macros. | |
e8ce775d JA |
7979 | * transpose-chars (C-t): Commands For Text. |
7980 | * transpose-words (M-t): Commands For Text. | |
28ef6c31 | 7981 | * undo (C-_ or C-x C-u): Miscellaneous Commands. |
e8ce775d JA |
7982 | * universal-argument (): Numeric Arguments. |
7983 | * unix-line-discard (C-u): Commands For Killing. | |
7984 | * unix-word-rubout (C-w): Commands For Killing. | |
7985 | * upcase-word (M-u): Commands For Text. | |
7986 | * yank (C-y): Commands For Killing. | |
28ef6c31 | 7987 | * yank-last-arg (M-. or M-_): Commands For History. |
e8ce775d JA |
7988 | * yank-nth-arg (M-C-y): Commands For History. |
7989 | * yank-pop (M-y): Commands For Killing. | |
ccc6cda3 JA |
7990 | |
7991 | \1f | |
7992 | File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Top | |
7993 | ||
7994 | Concept Index | |
7995 | ************* | |
7996 | ||
7997 | * Menu: | |
7998 | ||
e8ce775d | 7999 | * alias expansion: Aliases. |
cce855bc | 8000 | * arithmetic evaluation: Shell Arithmetic. |
e8ce775d JA |
8001 | * arithmetic expansion: Arithmetic Expansion. |
8002 | * arithmetic, shell: Shell Arithmetic. | |
8003 | * arrays: Arrays. | |
8004 | * background: Job Control Basics. | |
8005 | * Bash configuration: Basic Installation. | |
8006 | * Bash installation: Basic Installation. | |
8007 | * Bourne shell: Basic Shell Features. | |
8008 | * brace expansion: Brace Expansion. | |
8009 | * builtin: Definitions. | |
8010 | * command editing: Readline Bare Essentials. | |
8011 | * command execution: Command Search and Execution. | |
cce855bc | 8012 | * command expansion: Simple Command Expansion. |
e8ce775d JA |
8013 | * command history: Bash History Facilities. |
8014 | * command search: Command Search and Execution. | |
8015 | * command substitution: Command Substitution. | |
8016 | * command timing: Pipelines. | |
8017 | * commands, conditional: Conditional Constructs. | |
8018 | * commands, grouping: Command Grouping. | |
8019 | * commands, lists: Lists. | |
8020 | * commands, looping: Looping Constructs. | |
8021 | * commands, pipelines: Pipelines. | |
cce855bc | 8022 | * commands, shell: Shell Commands. |
e8ce775d JA |
8023 | * commands, simple: Simple Commands. |
8024 | * comments, shell: Comments. | |
bb70624e | 8025 | * completion builtins: Programmable Completion Builtins. |
e8ce775d JA |
8026 | * configuration: Basic Installation. |
8027 | * control operator: Definitions. | |
cce855bc | 8028 | * directory stack: The Directory Stack. |
e8ce775d JA |
8029 | * editing command lines: Readline Bare Essentials. |
8030 | * environment: Environment. | |
cce855bc | 8031 | * evaluation, arithmetic: Shell Arithmetic. |
e8ce775d | 8032 | * event designators: Event Designators. |
cce855bc | 8033 | * execution environment: Command Execution Environment. |
28ef6c31 JA |
8034 | * exit status <1>: Definitions. |
8035 | * exit status: Exit Status. | |
e8ce775d JA |
8036 | * expansion: Shell Expansions. |
8037 | * expansion, arithmetic: Arithmetic Expansion. | |
8038 | * expansion, brace: Brace Expansion. | |
8039 | * expansion, filename: Filename Expansion. | |
8040 | * expansion, parameter: Shell Parameter Expansion. | |
8041 | * expansion, pathname: Filename Expansion. | |
8042 | * expansion, tilde: Tilde Expansion. | |
cce855bc | 8043 | * expressions, arithmetic: Shell Arithmetic. |
e8ce775d JA |
8044 | * expressions, conditional: Bash Conditional Expressions. |
8045 | * field: Definitions. | |
8046 | * filename: Definitions. | |
8047 | * filename expansion: Filename Expansion. | |
8048 | * foreground: Job Control Basics. | |
8049 | * functions, shell: Shell Functions. | |
cce855bc | 8050 | * history builtins: Bash History Builtins. |
e8ce775d JA |
8051 | * history events: Event Designators. |
8052 | * history expansion: History Interaction. | |
8053 | * history list: Bash History Facilities. | |
bb70624e | 8054 | * History, how to use: Programmable Completion Builtins. |
e8ce775d JA |
8055 | * identifier: Definitions. |
8056 | * initialization file, readline: Readline Init File. | |
8057 | * installation: Basic Installation. | |
8058 | * interaction, readline: Readline Interaction. | |
bb70624e | 8059 | * interactive shell <1>: Interactive Shells. |
e8ce775d JA |
8060 | * interactive shell: Invoking Bash. |
8061 | * job: Definitions. | |
28ef6c31 JA |
8062 | * job control <1>: Definitions. |
8063 | * job control: Job Control Basics. | |
e8ce775d JA |
8064 | * kill ring: Readline Killing Commands. |
8065 | * killing text: Readline Killing Commands. | |
8066 | * localization: Locale Translation. | |
cce855bc | 8067 | * matching, pattern: Pattern Matching. |
e8ce775d JA |
8068 | * metacharacter: Definitions. |
8069 | * name: Definitions. | |
8070 | * notation, readline: Readline Bare Essentials. | |
8071 | * operator, shell: Definitions. | |
8072 | * parameter expansion: Shell Parameter Expansion. | |
8073 | * parameters: Shell Parameters. | |
8074 | * parameters, positional: Positional Parameters. | |
8075 | * parameters, special: Special Parameters. | |
8076 | * pathname expansion: Filename Expansion. | |
cce855bc | 8077 | * pattern matching: Pattern Matching. |
e8ce775d JA |
8078 | * pipeline: Pipelines. |
8079 | * POSIX: Definitions. | |
8080 | * POSIX Mode: Bash POSIX Mode. | |
8081 | * process group: Definitions. | |
8082 | * process group ID: Definitions. | |
8083 | * process substitution: Process Substitution. | |
bb70624e | 8084 | * programmable completion: Programmable Completion. |
e8ce775d JA |
8085 | * prompting: Printing a Prompt. |
8086 | * quoting: Quoting. | |
8087 | * quoting, ANSI: ANSI-C Quoting. | |
bb70624e | 8088 | * Readline, how to use: Job Control Variables. |
e8ce775d JA |
8089 | * redirection: Redirections. |
8090 | * reserved word: Definitions. | |
8091 | * restricted shell: The Restricted Shell. | |
8092 | * return status: Definitions. | |
cce855bc | 8093 | * shell arithmetic: Shell Arithmetic. |
e8ce775d JA |
8094 | * shell function: Shell Functions. |
8095 | * shell script: Shell Scripts. | |
8096 | * shell variable: Shell Parameters. | |
bb70624e | 8097 | * shell, interactive: Interactive Shells. |
e8ce775d JA |
8098 | * signal: Definitions. |
8099 | * signal handling: Signals. | |
28ef6c31 JA |
8100 | * special builtin <1>: Definitions. |
8101 | * special builtin: Special Builtins. | |
e8ce775d JA |
8102 | * startup files: Bash Startup Files. |
8103 | * suspending jobs: Job Control Basics. | |
8104 | * tilde expansion: Tilde Expansion. | |
8105 | * token: Definitions. | |
8106 | * variable, shell: Shell Parameters. | |
28ef6c31 | 8107 | * variables, readline: Readline Init File Syntax. |
e8ce775d JA |
8108 | * word: Definitions. |
8109 | * word splitting: Word Splitting. | |
8110 | * yanking text: Readline Killing Commands. | |
ccc6cda3 JA |
8111 | |
8112 | ||
8113 | \1f | |
8114 | Tag Table: | |
28ef6c31 JA |
8115 | Node: Top\7f1157 |
8116 | Node: Introduction\7f3286 | |
8117 | Node: What is Bash?\7f3511 | |
8118 | Node: What is a shell?\7f4612 | |
8119 | Node: Definitions\7f6846 | |
8120 | Node: Basic Shell Features\7f9512 | |
8121 | Node: Shell Syntax\7f10736 | |
8122 | Node: Shell Operation\7f11760 | |
8123 | Node: Quoting\7f13045 | |
8124 | Node: Escape Character\7f14304 | |
8125 | Node: Single Quotes\7f14776 | |
8126 | Node: Double Quotes\7f15111 | |
8127 | Node: ANSI-C Quoting\7f16012 | |
8128 | Node: Locale Translation\7f16915 | |
8129 | Node: Comments\7f17690 | |
8130 | Node: Shell Commands\7f18295 | |
8131 | Node: Simple Commands\7f19176 | |
8132 | Node: Pipelines\7f19797 | |
8133 | Node: Lists\7f21322 | |
8134 | Node: Looping Constructs\7f22835 | |
8135 | Node: Conditional Constructs\7f25279 | |
8136 | Node: Command Grouping\7f31220 | |
8137 | Node: Shell Functions\7f32597 | |
8138 | Node: Shell Parameters\7f35134 | |
8139 | Node: Positional Parameters\7f36459 | |
8140 | Node: Special Parameters\7f37350 | |
8141 | Node: Shell Expansions\7f40008 | |
8142 | Node: Brace Expansion\7f41928 | |
8143 | Node: Tilde Expansion\7f43597 | |
8144 | Node: Shell Parameter Expansion\7f45928 | |
8145 | Node: Command Substitution\7f52728 | |
8146 | Node: Arithmetic Expansion\7f54050 | |
8147 | Node: Process Substitution\7f54894 | |
8148 | Node: Word Splitting\7f55931 | |
8149 | Node: Filename Expansion\7f57383 | |
8150 | Node: Pattern Matching\7f59341 | |
8151 | Node: Quote Removal\7f62472 | |
8152 | Node: Redirections\7f62758 | |
8153 | Node: Executing Commands\7f69629 | |
8154 | Node: Simple Command Expansion\7f70296 | |
8155 | Node: Command Search and Execution\7f72217 | |
8156 | Node: Command Execution Environment\7f74214 | |
8157 | Node: Environment\7f76667 | |
8158 | Node: Exit Status\7f78318 | |
8159 | Node: Signals\7f79513 | |
8160 | Node: Shell Scripts\7f81405 | |
8161 | Node: Shell Builtin Commands\7f83788 | |
8162 | Node: Bourne Shell Builtins\7f85218 | |
8163 | Node: Bash Builtins\7f100145 | |
8164 | Node: The Set Builtin\7f124177 | |
8165 | Node: Special Builtins\7f131034 | |
8166 | Node: Shell Variables\7f132006 | |
8167 | Node: Bourne Shell Variables\7f132442 | |
8168 | Node: Bash Variables\7f134221 | |
8169 | Node: Bash Features\7f149565 | |
8170 | Node: Invoking Bash\7f150447 | |
8171 | Node: Bash Startup Files\7f155232 | |
8172 | Node: Interactive Shells\7f160102 | |
8173 | Node: What is an Interactive Shell?\7f160504 | |
8174 | Node: Is this Shell Interactive?\7f161139 | |
8175 | Node: Interactive Shell Behavior\7f161945 | |
8176 | Node: Bash Conditional Expressions\7f165212 | |
8177 | Node: Shell Arithmetic\7f168506 | |
8178 | Node: Aliases\7f170937 | |
8179 | Node: Arrays\7f173440 | |
8180 | Node: The Directory Stack\7f176460 | |
8181 | Node: Directory Stack Builtins\7f177166 | |
8182 | Node: Printing a Prompt\7f180044 | |
8183 | Node: The Restricted Shell\7f182414 | |
8184 | Node: Bash POSIX Mode\7f183892 | |
8185 | Node: Job Control\7f189520 | |
8186 | Node: Job Control Basics\7f189986 | |
8187 | Node: Job Control Builtins\7f194200 | |
8188 | Node: Job Control Variables\7f198495 | |
8189 | Node: Command Line Editing\7f199644 | |
8190 | Node: Introduction and Notation\7f200642 | |
8191 | Node: Readline Interaction\7f202259 | |
8192 | Node: Readline Bare Essentials\7f203445 | |
8193 | Node: Readline Movement Commands\7f205225 | |
8194 | Node: Readline Killing Commands\7f206181 | |
8195 | Node: Readline Arguments\7f208090 | |
8196 | Node: Searching\7f209125 | |
8197 | Node: Readline Init File\7f211115 | |
8198 | Node: Readline Init File Syntax\7f212169 | |
8199 | Node: Conditional Init Constructs\7f222372 | |
8200 | Node: Sample Init File\7f224896 | |
8201 | Node: Bindable Readline Commands\7f228065 | |
8202 | Node: Commands For Moving\7f229264 | |
8203 | Node: Commands For History\7f230112 | |
8204 | Node: Commands For Text\7f233000 | |
8205 | Node: Commands For Killing\7f234933 | |
8206 | Node: Numeric Arguments\7f236883 | |
8207 | Node: Commands For Completion\7f238010 | |
8208 | Node: Keyboard Macros\7f241590 | |
8209 | Node: Miscellaneous Commands\7f242148 | |
8210 | Node: Readline vi Mode\7f246510 | |
8211 | Node: Programmable Completion\7f247419 | |
8212 | Node: Programmable Completion Builtins\7f252467 | |
8213 | Node: Using History Interactively\7f259374 | |
8214 | Node: Bash History Facilities\7f260053 | |
8215 | Node: Bash History Builtins\7f262613 | |
8216 | Node: History Interaction\7f266179 | |
8217 | Node: Event Designators\7f268730 | |
8218 | Node: Word Designators\7f269657 | |
8219 | Node: Modifiers\7f271286 | |
8220 | Node: Installing Bash\7f272603 | |
8221 | Node: Basic Installation\7f273745 | |
8222 | Node: Compilers and Options\7f276863 | |
8223 | Node: Compiling For Multiple Architectures\7f277597 | |
8224 | Node: Installation Names\7f279254 | |
8225 | Node: Specifying the System Type\7f279977 | |
8226 | Node: Sharing Defaults\7f280684 | |
8227 | Node: Operation Controls\7f281349 | |
8228 | Node: Optional Features\7f282300 | |
8229 | Node: Reporting Bugs\7f289705 | |
8230 | Node: Major Differences From The Bourne Shell\7f290802 | |
8231 | Node: Builtin Index\7f304814 | |
8232 | Node: Reserved Word Index\7f308405 | |
8233 | Node: Variable Index\7f309881 | |
8234 | Node: Function Index\7f315667 | |
8235 | Node: Concept Index\7f320157 | |
ccc6cda3 JA |
8236 | \1f |
8237 | End Tag Table |