]>
Commit | Line | Data |
---|---|---|
1 | This is bashref.info, produced by makeinfo version 7.2 from | |
2 | bashref.texi. | |
3 | ||
4 | This text is a brief description of the features that are present in the | |
5 | Bash shell (version 5.3, 18 May 2025). | |
6 | ||
7 | This is Edition 5.3, last updated 18 May 2025, of ‘The GNU Bash | |
8 | Reference Manual’, for ‘Bash’, Version 5.3. | |
9 | ||
10 | Copyright © 1988-2025 Free Software Foundation, Inc. | |
11 | ||
12 | Permission is granted to copy, distribute and/or modify this | |
13 | document under the terms of the GNU Free Documentation License, | |
14 | Version 1.3 or any later version published by the Free Software | |
15 | Foundation; with no Invariant Sections, no Front-Cover Texts, and | |
16 | no Back-Cover Texts. A copy of the license is included in the | |
17 | section entitled "GNU Free Documentation License". | |
18 | INFO-DIR-SECTION Basics | |
19 | START-INFO-DIR-ENTRY | |
20 | * Bash: (bash). The GNU Bourne-Again SHell. | |
21 | END-INFO-DIR-ENTRY | |
22 | ||
23 | \1f | |
24 | File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) | |
25 | ||
26 | Bash Features | |
27 | ************* | |
28 | ||
29 | This text is a brief description of the features that are present in the | |
30 | Bash shell (version 5.3, 18 May 2025). The Bash home page is | |
31 | <http://www.gnu.org/software/bash/>. | |
32 | ||
33 | This is Edition 5.3, last updated 18 May 2025, of ‘The GNU Bash | |
34 | Reference Manual’, for ‘Bash’, Version 5.3. | |
35 | ||
36 | Bash contains features that appear in other popular shells, and some | |
37 | features that only appear in Bash. Some of the shells that Bash has | |
38 | borrowed concepts from are the Bourne Shell (‘sh’), the Korn Shell | |
39 | (‘ksh’), and the C-shell (‘csh’ and its successor, ‘tcsh’). The | |
40 | following menu breaks the features up into categories, noting which | |
41 | features were inspired by other shells and which are specific to Bash. | |
42 | ||
43 | This manual is meant as a brief introduction to features found in | |
44 | Bash. The Bash manual page should be used as the definitive reference | |
45 | on shell behavior. | |
46 | ||
47 | * Menu: | |
48 | ||
49 | * Introduction:: An introduction to the shell. | |
50 | * Definitions:: Some definitions used in the rest of this | |
51 | manual. | |
52 | * Basic Shell Features:: The shell "building blocks". | |
53 | * Shell Builtin Commands:: Commands that are a part of the shell. | |
54 | * Shell Variables:: Variables used or set by Bash. | |
55 | * Bash Features:: Features found only in Bash. | |
56 | * Job Control:: What job control is and how Bash allows you | |
57 | to use it. | |
58 | * Command Line Editing:: Chapter describing the command line | |
59 | editing features. | |
60 | * Using History Interactively:: Command History Expansion | |
61 | * Installing Bash:: How to build and install Bash on your system. | |
62 | * Reporting Bugs:: How to report bugs in Bash. | |
63 | * Major Differences From The Bourne Shell:: A terse list of the differences | |
64 | between Bash and historical | |
65 | versions of /bin/sh. | |
66 | * GNU Free Documentation License:: Copying and sharing this documentation. | |
67 | * Indexes:: Various indexes for this manual. | |
68 | ||
69 | \1f | |
70 | File: bashref.info, Node: Introduction, Next: Definitions, Up: Top | |
71 | ||
72 | 1 Introduction | |
73 | ************** | |
74 | ||
75 | * Menu: | |
76 | ||
77 | * What is Bash?:: A short description of Bash. | |
78 | * What is a shell?:: A brief introduction to shells. | |
79 | ||
80 | \1f | |
81 | File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction | |
82 | ||
83 | 1.1 What is Bash? | |
84 | ================= | |
85 | ||
86 | Bash is the shell, or command language interpreter, for the GNU | |
87 | operating system. The name is an acronym for the ‘Bourne-Again SHell’, | |
88 | a pun on Stephen Bourne, the author of the direct ancestor of the | |
89 | current Unix shell ‘sh’, which appeared in the Seventh Edition Bell Labs | |
90 | Research version of Unix. | |
91 | ||
92 | Bash is largely compatible with ‘sh’ and incorporates useful features | |
93 | from the Korn shell ‘ksh’ and the C shell ‘csh’. It is intended to be a | |
94 | conformant implementation of the IEEE POSIX Shell and Tools portion of | |
95 | the IEEE POSIX specification (IEEE Standard 1003.1). It offers | |
96 | functional improvements over ‘sh’ for both interactive and programming | |
97 | use. | |
98 | ||
99 | While the GNU operating system provides other shells, including a | |
100 | version of ‘csh’, Bash is the default shell. Like other GNU software, | |
101 | Bash is quite portable. It currently runs on nearly every version of | |
102 | Unix and a few other operating systems − independently-supported ports | |
103 | exist for Windows and other platforms. | |
104 | ||
105 | \1f | |
106 | File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction | |
107 | ||
108 | 1.2 What is a shell? | |
109 | ==================== | |
110 | ||
111 | At its base, a shell is simply a macro processor that executes commands. | |
112 | The term macro processor means functionality where text and symbols are | |
113 | expanded to create larger expressions. | |
114 | ||
115 | A Unix shell is both a command interpreter and a programming | |
116 | language. As a command interpreter, the shell provides the user | |
117 | interface to the rich set of GNU utilities. The programming language | |
118 | features allow these utilities to be combined. Users can create files | |
119 | containing commands, and these become commands themselves. These new | |
120 | commands have the same status as system commands in directories such as | |
121 | ‘/bin’, allowing users or groups to establish custom environments to | |
122 | automate their common tasks. | |
123 | ||
124 | Shells may be used interactively or non-interactively. In | |
125 | interactive mode, they accept input typed from the keyboard. When | |
126 | executing non-interactively, shells execute commands read from a file or | |
127 | a string. | |
128 | ||
129 | A shell allows execution of GNU commands, both synchronously and | |
130 | asynchronously. The shell waits for synchronous commands to complete | |
131 | before accepting more input; asynchronous commands continue to execute | |
132 | in parallel with the shell while it reads and executes additional | |
133 | commands. The “redirection” constructs permit fine-grained control of | |
134 | the input and output of those commands. Moreover, the shell allows | |
135 | control over the contents of commands' environments. | |
136 | ||
137 | Shells also provide a small set of built-in commands (“builtins”) | |
138 | implementing functionality impossible or inconvenient to obtain via | |
139 | separate utilities. For example, ‘cd’, ‘break’, ‘continue’, and ‘exec’ | |
140 | cannot be implemented outside of the shell because they directly | |
141 | manipulate the shell itself. The ‘history’, ‘getopts’, ‘kill’, or ‘pwd’ | |
142 | builtins, among others, could be implemented in separate utilities, but | |
143 | they are more convenient to use as builtin commands. All of the shell | |
144 | builtins are described in subsequent sections. | |
145 | ||
146 | While executing commands is essential, most of the power (and | |
147 | complexity) of shells is due to their embedded programming languages. | |
148 | Like any high-level language, the shell provides variables, flow control | |
149 | constructs, quoting, and functions. | |
150 | ||
151 | Shells offer features geared specifically for interactive use rather | |
152 | than to augment the programming language. These interactive features | |
153 | include job control, command line editing, command history and aliases. | |
154 | This manual describes how Bash provides all of these features. | |
155 | ||
156 | \1f | |
157 | File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top | |
158 | ||
159 | 2 Definitions | |
160 | ************* | |
161 | ||
162 | These definitions are used throughout the remainder of this manual. | |
163 | ||
164 | ‘POSIX’ | |
165 | A family of open system standards based on Unix. Bash is primarily | |
166 | concerned with the Shell and Utilities portion of the POSIX 1003.1 | |
167 | standard. | |
168 | ||
169 | ‘blank’ | |
170 | A space or tab character. | |
171 | ||
172 | ‘whitespace’ | |
173 | A character belonging to the ‘space’ character class in the current | |
174 | locale, or for which ‘isspace()’ returns true. | |
175 | ||
176 | ‘builtin’ | |
177 | A command that is implemented internally by the shell itself, | |
178 | rather than by an executable program somewhere in the file system. | |
179 | ||
180 | ‘control operator’ | |
181 | A ‘token’ that performs a control function. It is a ‘newline’ or | |
182 | one of the following: ‘||’, ‘&&’, ‘&’, ‘;’, ‘;;’, ‘;&’, ‘;;&’, ‘|’, | |
183 | ‘|&’, ‘(’, or ‘)’. | |
184 | ||
185 | ‘exit status’ | |
186 | The value returned by a command to its caller. The value is | |
187 | restricted to eight bits, so the maximum value is 255. | |
188 | ||
189 | ‘field’ | |
190 | A unit of text that is the result of one of the shell expansions. | |
191 | After expansion, when executing a command, the resulting fields are | |
192 | used as the command name and arguments. | |
193 | ||
194 | ‘filename’ | |
195 | A string of characters used to identify a file. | |
196 | ||
197 | ‘job’ | |
198 | A set of processes comprising a pipeline, and any processes | |
199 | descended from it, that are all in the same process group. | |
200 | ||
201 | ‘job control’ | |
202 | A mechanism by which users can selectively stop (suspend) and | |
203 | restart (resume) execution of processes. | |
204 | ||
205 | ‘metacharacter’ | |
206 | A character that, when unquoted, separates words. A metacharacter | |
207 | is a ‘space’, ‘tab’, ‘newline’, or one of the following characters: | |
208 | ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’. | |
209 | ||
210 | ‘name’ | |
211 | A ‘word’ consisting solely of letters, numbers, and underscores, | |
212 | and beginning with a letter or underscore. ‘Name’s are used as | |
213 | shell variable and function names. Also referred to as an | |
214 | ‘identifier’. | |
215 | ||
216 | ‘operator’ | |
217 | A ‘control operator’ or a ‘redirection operator’. *Note | |
218 | Redirections::, for a list of redirection operators. Operators | |
219 | contain at least one unquoted ‘metacharacter’. | |
220 | ||
221 | ‘process group’ | |
222 | A collection of related processes each having the same process | |
223 | group ID. | |
224 | ||
225 | ‘process group ID’ | |
226 | A unique identifier that represents a ‘process group’ during its | |
227 | lifetime. | |
228 | ||
229 | ‘reserved word’ | |
230 | A ‘word’ that has a special meaning to the shell. Most reserved | |
231 | words introduce shell flow control constructs, such as ‘for’ and | |
232 | ‘while’. | |
233 | ||
234 | ‘return status’ | |
235 | A synonym for ‘exit status’. | |
236 | ||
237 | ‘signal’ | |
238 | A mechanism by which a process may be notified by the kernel of an | |
239 | event occurring in the system. | |
240 | ||
241 | ‘special builtin’ | |
242 | A shell builtin command that has been classified as special by the | |
243 | POSIX standard. | |
244 | ||
245 | ‘token’ | |
246 | A sequence of characters considered a single unit by the shell. It | |
247 | is either a ‘word’ or an ‘operator’. | |
248 | ||
249 | ‘word’ | |
250 | A sequence of characters treated as a unit by the shell. Words may | |
251 | not include unquoted ‘metacharacters’. | |
252 | ||
253 | \1f | |
254 | File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top | |
255 | ||
256 | 3 Basic Shell Features | |
257 | ********************** | |
258 | ||
259 | Bash is an acronym for ‘Bourne-Again SHell’. The Bourne shell is the | |
260 | traditional Unix shell originally written by Stephen Bourne. All of the | |
261 | Bourne shell builtin commands are available in Bash, and the rules for | |
262 | evaluation and quoting are taken from the POSIX specification for the | |
263 | 'standard' Unix shell. | |
264 | ||
265 | This chapter briefly summarizes the shell's 'building blocks': | |
266 | commands, control structures, shell functions, shell parameters, shell | |
267 | expansions, redirections, which are a way to direct input and output | |
268 | from and to named files, and how the shell executes commands. | |
269 | ||
270 | * Menu: | |
271 | ||
272 | * Shell Syntax:: What your input means to the shell. | |
273 | * Shell Commands:: The types of commands you can use. | |
274 | * Shell Functions:: Grouping commands by name. | |
275 | * Shell Parameters:: How the shell stores values. | |
276 | * Shell Expansions:: How Bash expands parameters and the various | |
277 | expansions available. | |
278 | * Redirections:: A way to control where input and output go. | |
279 | * Executing Commands:: What happens when you run a command. | |
280 | * Shell Scripts:: Executing files of shell commands. | |
281 | ||
282 | \1f | |
283 | File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features | |
284 | ||
285 | 3.1 Shell Syntax | |
286 | ================ | |
287 | ||
288 | * Menu: | |
289 | ||
290 | * Shell Operation:: The basic operation of the shell. | |
291 | * Quoting:: How to remove the special meaning from characters. | |
292 | * Comments:: How to specify comments. | |
293 | ||
294 | When the shell reads input, it proceeds through a sequence of | |
295 | operations. If the input indicates the beginning of a comment, the | |
296 | shell ignores the comment symbol (‘#’), and the rest of that line. | |
297 | ||
298 | Otherwise, roughly speaking, the shell reads its input and divides | |
299 | the input into words and operators, employing the quoting rules to | |
300 | select which meanings to assign various words and characters. | |
301 | ||
302 | The shell then parses these tokens into commands and other | |
303 | constructs, removes the special meaning of certain words or characters, | |
304 | expands others, redirects input and output as needed, executes the | |
305 | specified command, waits for the command's exit status, and makes that | |
306 | exit status available for further inspection or processing. | |
307 | ||
308 | \1f | |
309 | File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax | |
310 | ||
311 | 3.1.1 Shell Operation | |
312 | --------------------- | |
313 | ||
314 | The following is a brief description of the shell's operation when it | |
315 | reads and executes a command. Basically, the shell does the following: | |
316 | ||
317 | 1. Reads its input from a file (*note Shell Scripts::), from a string | |
318 | supplied as an argument to the ‘-c’ invocation option (*note | |
319 | Invoking Bash::), or from the user's terminal. | |
320 | ||
321 | 2. Breaks the input into words and operators, obeying the quoting | |
322 | rules described in *note Quoting::. These tokens are separated by | |
323 | ‘metacharacters’. This step performs alias expansion (*note | |
324 | Aliases::). | |
325 | ||
326 | 3. Parses the tokens into simple and compound commands (*note Shell | |
327 | Commands::). | |
328 | ||
329 | 4. Performs the various shell expansions (*note Shell Expansions::), | |
330 | breaking the expanded tokens into lists of filenames (*note | |
331 | Filename Expansion::) and commands and arguments. | |
332 | ||
333 | 5. Performs any necessary redirections (*note Redirections::) and | |
334 | removes the redirection operators and their operands from the | |
335 | argument list. | |
336 | ||
337 | 6. Executes the command (*note Executing Commands::). | |
338 | ||
339 | 7. Optionally waits for the command to complete and collects its exit | |
340 | status (*note Exit Status::). | |
341 | ||
342 | \1f | |
343 | File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax | |
344 | ||
345 | 3.1.2 Quoting | |
346 | ------------- | |
347 | ||
348 | * Menu: | |
349 | ||
350 | * Escape Character:: How to remove the special meaning from a single | |
351 | character. | |
352 | * Single Quotes:: How to inhibit all interpretation of a sequence | |
353 | of characters. | |
354 | * Double Quotes:: How to suppress most of the interpretation of a | |
355 | sequence of characters. | |
356 | * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings. | |
357 | * Locale Translation:: How to translate strings into different languages. | |
358 | ||
359 | Quoting is used to remove the special meaning of certain characters or | |
360 | words to the shell. Quoting can be used to disable special treatment | |
361 | for special characters, to prevent reserved words from being recognized | |
362 | as such, and to prevent parameter expansion. | |
363 | ||
364 | Each of the shell metacharacters (*note Definitions::) has special | |
365 | meaning to the shell and must be quoted if it is to represent itself. | |
366 | ||
367 | When the command history expansion facilities are being used (*note | |
368 | History Interaction::), the “history expansion” character, usually ‘!’, | |
369 | must be quoted to prevent history expansion. *Note Bash History | |
370 | Facilities::, for more details concerning history expansion. | |
371 | ||
372 | There are four quoting mechanisms: the “escape character”, single | |
373 | quotes, double quotes, and dollar-single quotes. | |
374 | ||
375 | \1f | |
376 | File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting | |
377 | ||
378 | 3.1.2.1 Escape Character | |
379 | ........................ | |
380 | ||
381 | A non-quoted backslash ‘\’ is the Bash escape character. It preserves | |
382 | the literal value of the next character that follows, removing any | |
383 | special meaning it has, with the exception of ‘newline’. If a | |
384 | ‘\newline’ pair appears, and the backslash itself is not quoted, the | |
385 | ‘\newline’ is treated as a line continuation (that is, it is removed | |
386 | from the input stream and effectively ignored). | |
387 | ||
388 | \1f | |
389 | File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting | |
390 | ||
391 | 3.1.2.2 Single Quotes | |
392 | ..................... | |
393 | ||
394 | Enclosing characters in single quotes (‘'’) preserves the literal value | |
395 | of each character within the quotes. A single quote may not occur | |
396 | between single quotes, even when preceded by a backslash. | |
397 | ||
398 | \1f | |
399 | File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting | |
400 | ||
401 | 3.1.2.3 Double Quotes | |
402 | ..................... | |
403 | ||
404 | Enclosing characters in double quotes (‘"’) preserves the literal value | |
405 | of all characters within the quotes, with the exception of ‘$’, ‘`’, | |
406 | ‘\’, and, when history expansion is enabled, ‘!’. When the shell is in | |
407 | POSIX mode (*note Bash POSIX Mode::), the ‘!’ has no special meaning | |
408 | within double quotes, even when history expansion is enabled. The | |
409 | characters ‘$’ and ‘`’ retain their special meaning within double quotes | |
410 | (*note Shell Expansions::). The backslash retains its special meaning | |
411 | only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, | |
412 | ‘\’, or ‘newline’. Within double quotes, backslashes that are followed | |
413 | by one of these characters are removed. Backslashes preceding | |
414 | characters without a special meaning are left unmodified. | |
415 | ||
416 | A double quote may be quoted within double quotes by preceding it | |
417 | with a backslash. If enabled, history expansion will be performed | |
418 | unless an ‘!’ appearing in double quotes is escaped using a backslash. | |
419 | The backslash preceding the ‘!’ is not removed. | |
420 | ||
421 | The special parameters ‘*’ and ‘@’ have special meaning when in | |
422 | double quotes (*note Shell Parameter Expansion::). | |
423 | ||
424 | \1f | |
425 | File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting | |
426 | ||
427 | 3.1.2.4 ANSI-C Quoting | |
428 | ...................... | |
429 | ||
430 | Character sequences of the form ‘$'STRING'’ are treated as a special | |
431 | kind of single quotes. The sequence expands to STRING, with | |
432 | backslash-escaped characters in STRING replaced as specified by the ANSI | |
433 | C standard. Backslash escape sequences, if present, are decoded as | |
434 | follows: | |
435 | ||
436 | ‘\a’ | |
437 | alert (bell) | |
438 | ‘\b’ | |
439 | backspace | |
440 | ‘\e’ | |
441 | ‘\E’ | |
442 | An escape character (not in ANSI C). | |
443 | ‘\f’ | |
444 | form feed | |
445 | ‘\n’ | |
446 | newline | |
447 | ‘\r’ | |
448 | carriage return | |
449 | ‘\t’ | |
450 | horizontal tab | |
451 | ‘\v’ | |
452 | vertical tab | |
453 | ‘\\’ | |
454 | backslash | |
455 | ‘\'’ | |
456 | single quote | |
457 | ‘\"’ | |
458 | double quote | |
459 | ‘\?’ | |
460 | question mark | |
461 | ‘\NNN’ | |
462 | The eight-bit character whose value is the octal value NNN (one to | |
463 | three octal digits). | |
464 | ‘\xHH’ | |
465 | The eight-bit character whose value is the hexadecimal value HH | |
466 | (one or two hex digits). | |
467 | ‘\uHHHH’ | |
468 | The Unicode (ISO/IEC 10646) character whose value is the | |
469 | hexadecimal value HHHH (one to four hex digits). | |
470 | ‘\UHHHHHHHH’ | |
471 | The Unicode (ISO/IEC 10646) character whose value is the | |
472 | hexadecimal value HHHHHHHH (one to eight hex digits). | |
473 | ‘\cX’ | |
474 | A control-X character. | |
475 | ||
476 | The expanded result is single-quoted, as if the dollar sign had not been | |
477 | present. | |
478 | ||
479 | \1f | |
480 | File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting | |
481 | ||
482 | 3.1.2.5 Locale-Specific Translation | |
483 | ................................... | |
484 | ||
485 | * Menu: | |
486 | ||
487 | * Creating Internationalized Scripts:: How to use translations and different | |
488 | languages in your scripts. | |
489 | ||
490 | Prefixing a double-quoted string with a dollar sign (‘$’), such as | |
491 | $"hello, world", causes the string to be translated according to the | |
492 | current locale. The ‘gettext’ infrastructure performs the lookup and | |
493 | translation, using the ‘LC_MESSAGES’, ‘TEXTDOMAINDIR’, and ‘TEXTDOMAIN’ | |
494 | shell variables, as explained below. See the gettext documentation for | |
495 | additional details not covered here. If the current locale is ‘C’ or | |
496 | ‘POSIX’, if there are no translations available, or if the string is not | |
497 | translated, the dollar sign is ignored, and the string is treated as | |
498 | double-quoted as described above. Since this is a form of double | |
499 | quoting, the string remains double-quoted by default, whether or not it | |
500 | is translated and replaced. If the ‘noexpand_translation’ option is | |
501 | enabled using the ‘shopt’ builtin (*note The Shopt Builtin::), | |
502 | translated strings are single-quoted instead of double-quoted. | |
503 | ||
504 | The rest of this section is a brief overview of how you use gettext | |
505 | to create translations for strings in a shell script named SCRIPTNAME. | |
506 | There are more details in the gettext documentation. | |
507 | ||
508 | \1f | |
509 | File: bashref.info, Node: Creating Internationalized Scripts, Up: Locale Translation | |
510 | ||
511 | Once you've marked the strings in your script that you want to translate | |
512 | using $"...", you create a gettext "template" file using the command | |
513 | ||
514 | bash --dump-po-strings SCRIPTNAME > DOMAIN.pot | |
515 | ||
516 | The DOMAIN is your “message domain”. It's just an arbitrary string | |
517 | that's used to identify the files gettext needs, like a package or | |
518 | script name. It needs to be unique among all the message domains on | |
519 | systems where you install the translations, so gettext knows which | |
520 | translations correspond to your script. You'll use the template file to | |
521 | create translations for each target language. The template file | |
522 | conventionally has the suffix ‘.pot’. | |
523 | ||
524 | You copy this template file to a separate file for each target | |
525 | language you want to support (called "PO" files, which use the suffix | |
526 | ‘.po’). PO files use various naming conventions, but when you are | |
527 | working to translate a template file into a particular language, you | |
528 | first copy the template file to a file whose name is the language you | |
529 | want to target, with the ‘.po’ suffix. For instance, the Spanish | |
530 | translations of your strings would be in a file named ‘es.po’, and to | |
531 | get started using a message domain named "example," you would run | |
532 | ||
533 | cp example.pot es.po | |
534 | ||
535 | Ultimately, PO files are often named DOMAIN.po and installed in | |
536 | directories that contain multiple translation files for a particular | |
537 | language. | |
538 | ||
539 | Whichever naming convention you choose, you will need to translate | |
540 | the strings in the PO files into the appropriate languages. This has to | |
541 | be done manually. | |
542 | ||
543 | When you have the translations and PO files complete, you'll use the | |
544 | gettext tools to produce what are called "MO" files, which are compiled | |
545 | versions of the PO files the gettext tools use to look up translations | |
546 | efficiently. MO files are also called "message catalog" files. You use | |
547 | the ‘msgfmt’ program to do this. For instance, if you had a file with | |
548 | Spanish translations, you could run | |
549 | ||
550 | msgfmt -o es.mo es.po | |
551 | ||
552 | to produce the corresponding MO file. | |
553 | ||
554 | Once you have the MO files, you decide where to install them and use | |
555 | the ‘TEXTDOMAINDIR’ shell variable to tell the gettext tools where they | |
556 | are. Make sure to use the same message domain to name the MO files as | |
557 | you did for the PO files when you install them. | |
558 | ||
559 | Your users will use the ‘LANG’ or ‘LC_MESSAGES’ shell variables to | |
560 | select the desired language. | |
561 | ||
562 | You set the ‘TEXTDOMAIN’ variable to the script's message domain. As | |
563 | above, you use the message domain to name your translation files. | |
564 | ||
565 | You, or possibly your users, set the ‘TEXTDOMAINDIR’ variable to the | |
566 | name of a directory where the message catalog files are stored. If you | |
567 | install the message files into the system's standard message catalog | |
568 | directory, you don't need to worry about this variable. | |
569 | ||
570 | The directory where the message catalog files are stored varies | |
571 | between systems. Some use the message catalog selected by the | |
572 | ‘LC_MESSAGES’ shell variable. Others create the name of the message | |
573 | catalog from the value of the ‘TEXTDOMAIN’ shell variable, possibly | |
574 | adding the ‘.mo’ suffix. If you use the ‘TEXTDOMAIN’ variable, you may | |
575 | need to set the ‘TEXTDOMAINDIR’ variable to the location of the message | |
576 | catalog files, as above. It's common to use both variables in this | |
577 | fashion: ‘$TEXTDOMAINDIR’/‘$LC_MESSAGES’/LC_MESSAGES/‘$TEXTDOMAIN’.mo. | |
578 | ||
579 | If you used that last convention, and you wanted to store the message | |
580 | catalog files with Spanish (es) and Esperanto (eo) translations into a | |
581 | local directory you use for custom translation files, you could run | |
582 | ||
583 | TEXTDOMAIN=example | |
584 | TEXTDOMAINDIR=/usr/local/share/locale | |
585 | ||
586 | cp es.mo ${TEXTDOMAINDIR}/es/LC_MESSAGES/${TEXTDOMAIN}.mo | |
587 | cp eo.mo ${TEXTDOMAINDIR}/eo/LC_MESSAGES/${TEXTDOMAIN}.mo | |
588 | ||
589 | When all of this is done, and the message catalog files containing | |
590 | the compiled translations are installed in the correct location, your | |
591 | users will be able to see translated strings in any of the supported | |
592 | languages by setting the ‘LANG’ or ‘LC_MESSAGES’ environment variables | |
593 | before running your script. | |
594 | ||
595 | \1f | |
596 | File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax | |
597 | ||
598 | 3.1.3 Comments | |
599 | -------------- | |
600 | ||
601 | In a non-interactive shell, or an interactive shell in which the | |
602 | ‘interactive_comments’ option to the ‘shopt’ builtin is enabled (*note | |
603 | The Shopt Builtin::), a word beginning with ‘#’ introduces a comment. A | |
604 | word begins at the beginning of a line, after unquoted whitespace, or | |
605 | after an operator. The comment causes that word and all remaining | |
606 | characters on that line to be ignored. An interactive shell without the | |
607 | ‘interactive_comments’ option enabled does not allow comments. The | |
608 | ‘interactive_comments’ option is enabled by default in interactive | |
609 | shells. *Note Interactive Shells::, for a description of what makes a | |
610 | shell interactive. | |
611 | ||
612 | \1f | |
613 | File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features | |
614 | ||
615 | 3.2 Shell Commands | |
616 | ================== | |
617 | ||
618 | A simple shell command such as ‘echo a b c’ consists of the command | |
619 | itself followed by arguments, separated by spaces. | |
620 | ||
621 | More complex shell commands are composed of simple commands arranged | |
622 | together in a variety of ways: in a pipeline in which the output of one | |
623 | command becomes the input of a second, in a loop or conditional | |
624 | construct, or in some other grouping. | |
625 | ||
626 | * Menu: | |
627 | ||
628 | * Reserved Words:: Words that have special meaning to the shell. | |
629 | * Simple Commands:: The most common type of command. | |
630 | * Pipelines:: Connecting the input and output of several | |
631 | commands. | |
632 | * Lists:: How to execute commands sequentially. | |
633 | * Compound Commands:: Shell commands for control flow. | |
634 | * Coprocesses:: Two-way communication between commands. | |
635 | * GNU Parallel:: Running commands in parallel. | |
636 | ||
637 | \1f | |
638 | File: bashref.info, Node: Reserved Words, Next: Simple Commands, Up: Shell Commands | |
639 | ||
640 | 3.2.1 Reserved Words | |
641 | -------------------- | |
642 | ||
643 | Reserved words are words that have special meaning to the shell. They | |
644 | are used to begin and end the shell's compound commands. | |
645 | ||
646 | The following words are recognized as reserved when unquoted and the | |
647 | first word of a command (see below for exceptions): | |
648 | ||
649 | ‘if’ ‘then’ ‘elif’ ‘else’ ‘fi’ ‘time’ | |
650 | ‘for’ ‘in’ ‘until’ ‘while’ ‘do’ ‘done’ | |
651 | ‘case’ ‘esac’ ‘coproc’‘select’‘function’ | |
652 | ‘{’ ‘}’ ‘[[’ ‘]]’ ‘!’ | |
653 | ||
654 | ‘in’ is recognized as a reserved word if it is the third word of a | |
655 | ‘case’ or ‘select’ command. ‘in’ and ‘do’ are recognized as reserved | |
656 | words if they are the third word in a ‘for’ command. | |
657 | ||
658 | \1f | |
659 | File: bashref.info, Node: Simple Commands, Next: Pipelines, Prev: Reserved Words, Up: Shell Commands | |
660 | ||
661 | 3.2.2 Simple Commands | |
662 | --------------------- | |
663 | ||
664 | A simple command is the kind of command that's executed most often. | |
665 | It's just a sequence of words separated by ‘blank’s, terminated by one | |
666 | of the shell's control operators (*note Definitions::). The first word | |
667 | generally specifies a command to be executed, with the rest of the words | |
668 | being that command's arguments. | |
669 | ||
670 | The return status (*note Exit Status::) of a simple command is its | |
671 | exit status as provided by the POSIX 1003.1 ‘waitpid’ function, or 128+N | |
672 | if the command was terminated by signal N. | |
673 | ||
674 | \1f | |
675 | File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands | |
676 | ||
677 | 3.2.3 Pipelines | |
678 | --------------- | |
679 | ||
680 | A ‘pipeline’ is a sequence of one or more commands separated by one of | |
681 | the control operators ‘|’ or ‘|&’. | |
682 | ||
683 | The format for a pipeline is | |
684 | [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ... | |
685 | ||
686 | The output of each command in the pipeline is connected via a pipe to | |
687 | the input of the next command. That is, each command reads the previous | |
688 | command's output. This connection is performed before any redirections | |
689 | specified by COMMAND1. | |
690 | ||
691 | If ‘|&’ is the pipeline operator, COMMAND1's standard error, in | |
692 | addition to its standard output, is connected to COMMAND2's standard | |
693 | input through the pipe; it is shorthand for ‘2>&1 |’. This implicit | |
694 | redirection of the standard error to the standard output is performed | |
695 | after any redirections specified by COMMAND1, consistent with that | |
696 | shorthand. | |
697 | ||
698 | If the reserved word ‘time’ precedes the pipeline, Bash prints timing | |
699 | statistics for the pipeline once it finishes. The statistics currently | |
700 | consist of elapsed (wall-clock) time and user and system time consumed | |
701 | by the command's execution. The ‘-p’ option changes the output format | |
702 | to that specified by POSIX. When the shell is in POSIX mode (*note Bash | |
703 | POSIX Mode::), it does not recognize ‘time’ as a reserved word if the | |
704 | next token begins with a ‘-’. The value of the ‘TIMEFORMAT’ variable is | |
705 | a format string that specifies how the timing information should be | |
706 | displayed. *Note Bash Variables::, for a description of the available | |
707 | formats. Providing ‘time’ as a reserved word permits the timing of | |
708 | shell builtins, shell functions, and pipelines. An external ‘time’ | |
709 | command cannot time these easily. | |
710 | ||
711 | When the shell is in POSIX mode (*note Bash POSIX Mode::), you can | |
712 | use ‘time’ by itself as a simple command. In this case, the shell | |
713 | displays the total user and system time consumed by the shell and its | |
714 | children. The ‘TIMEFORMAT’ variable specifies the format of the time | |
715 | information. | |
716 | ||
717 | If a pipeline is not executed asynchronously (*note Lists::), the | |
718 | shell waits for all commands in the pipeline to complete. | |
719 | ||
720 | Each command in a multi-command pipeline, where pipes are created, is | |
721 | executed in its own “subshell”, which is a separate process (*note | |
722 | Command Execution Environment::). If the ‘lastpipe’ option is enabled | |
723 | using the ‘shopt’ builtin (*note The Shopt Builtin::), and job control | |
724 | is not active, the last element of a pipeline may be run by the shell | |
725 | process. | |
726 | ||
727 | The exit status of a pipeline is the exit status of the last command | |
728 | in the pipeline, unless the ‘pipefail’ option is enabled (*note The Set | |
729 | Builtin::). If ‘pipefail’ is enabled, the pipeline's return status is | |
730 | the value of the last (rightmost) command to exit with a non-zero | |
731 | status, or zero if all commands exit successfully. If the reserved word | |
732 | ‘!’ precedes the pipeline, the exit status is the logical negation of | |
733 | the exit status as described above. If a pipeline is not executed | |
734 | asynchronously (*note Lists::), the shell waits for all commands in the | |
735 | pipeline to terminate before returning a value. The return status of an | |
736 | asynchronous pipeline is 0. | |
737 | ||
738 | \1f | |
739 | File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands | |
740 | ||
741 | 3.2.4 Lists of Commands | |
742 | ----------------------- | |
743 | ||
744 | A ‘list’ is a sequence of one or more pipelines separated by one of the | |
745 | operators ‘;’, ‘&’, ‘&&’, or ‘||’, and optionally terminated by one of | |
746 | ‘;’, ‘&’, or a ‘newline’. | |
747 | ||
748 | Of these list operators, ‘&&’ and ‘||’ have equal precedence, | |
749 | followed by ‘;’ and ‘&’, which have equal precedence. | |
750 | ||
751 | A sequence of one or more newlines may appear in a ‘list’ to delimit | |
752 | commands, equivalent to a semicolon. | |
753 | ||
754 | If a command is terminated by the control operator ‘&’, the shell | |
755 | executes the command asynchronously in a subshell. This is known as | |
756 | executing the command in the “background”, and these are referred to as | |
757 | “asynchronous” commands. The shell does not wait for the command to | |
758 | finish, and the return status is 0 (true). When job control is not | |
759 | active (*note Job Control::), the standard input for asynchronous | |
760 | commands, in the absence of any explicit redirections, is redirected | |
761 | from ‘/dev/null’. | |
762 | ||
763 | Commands separated by a ‘;’ are executed sequentially; the shell | |
764 | waits for each command to terminate in turn. The return status is the | |
765 | exit status of the last command executed. | |
766 | ||
767 | AND and OR lists are sequences of one or more pipelines separated by | |
768 | the control operators ‘&&’ and ‘||’, respectively. AND and OR lists are | |
769 | executed with left associativity. | |
770 | ||
771 | An AND list has the form | |
772 | COMMAND1 && COMMAND2 | |
773 | ||
774 | COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of | |
775 | zero (success). | |
776 | ||
777 | An OR list has the form | |
778 | COMMAND1 || COMMAND2 | |
779 | ||
780 | COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit | |
781 | status. | |
782 | ||
783 | The return status of AND and OR lists is the exit status of the last | |
784 | command executed in the list. | |
785 | ||
786 | \1f | |
787 | File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands | |
788 | ||
789 | 3.2.5 Compound Commands | |
790 | ----------------------- | |
791 | ||
792 | * Menu: | |
793 | ||
794 | * Looping Constructs:: Shell commands for iterative action. | |
795 | * Conditional Constructs:: Shell commands for conditional execution. | |
796 | * Command Grouping:: Ways to group commands. | |
797 | ||
798 | Compound commands are the shell programming language constructs. Each | |
799 | construct begins with a reserved word or control operator and is | |
800 | terminated by a corresponding reserved word or operator. Any | |
801 | redirections (*note Redirections::) associated with a compound command | |
802 | apply to all commands within that compound command unless explicitly | |
803 | overridden. | |
804 | ||
805 | In most cases a list of commands in a compound command's description | |
806 | may be separated from the rest of the command by one or more newlines, | |
807 | and may be followed by a newline in place of a semicolon. | |
808 | ||
809 | Bash provides looping constructs, conditional commands, and | |
810 | mechanisms to group commands and execute them as a unit. | |
811 | ||
812 | \1f | |
813 | File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands | |
814 | ||
815 | 3.2.5.1 Looping Constructs | |
816 | .......................... | |
817 | ||
818 | Bash supports the following looping constructs. | |
819 | ||
820 | Note that wherever a ‘;’ appears in the description of a command's | |
821 | syntax, it may be replaced with one or more newlines. | |
822 | ||
823 | ‘until’ | |
824 | The syntax of the ‘until’ command is: | |
825 | ||
826 | until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
827 | ||
828 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit | |
829 | status which is not zero. The return status is the exit status of | |
830 | the last command executed in CONSEQUENT-COMMANDS, or zero if none | |
831 | was executed. | |
832 | ||
833 | ‘while’ | |
834 | The syntax of the ‘while’ command is: | |
835 | ||
836 | while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done | |
837 | ||
838 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit | |
839 | status of zero. The return status is the exit status of the last | |
840 | command executed in CONSEQUENT-COMMANDS, or zero if none was | |
841 | executed. | |
842 | ||
843 | ‘for’ | |
844 | The syntax of the ‘for’ command is: | |
845 | ||
846 | for NAME [ [in WORDS ...] ; ] do COMMANDS; done | |
847 | ||
848 | Expand WORDS (*note Shell Expansions::), and then execute COMMANDS | |
849 | once for each word in the resultant list, with NAME bound to the | |
850 | current word. If ‘in WORDS’ is not present, the ‘for’ command | |
851 | executes the COMMANDS once for each positional parameter that is | |
852 | set, as if ‘in "$@"’ had been specified (*note Special | |
853 | Parameters::). | |
854 | ||
855 | The return status is the exit status of the last command that | |
856 | executes. If there are no items in the expansion of WORDS, no | |
857 | commands are executed, and the return status is zero. | |
858 | ||
859 | There is an alternate form of the ‘for’ command which is similar to | |
860 | the C language: | |
861 | ||
862 | for (( EXPR1 ; EXPR2 ; EXPR3 )) [;] do COMMANDS ; done | |
863 | ||
864 | First, evaluate the arithmetic expression EXPR1 according to the | |
865 | rules described below (*note Shell Arithmetic::). Then, repeatedly | |
866 | evaluate the arithmetic expression EXPR2 until it evaluates to | |
867 | zero. Each time EXPR2 evaluates to a non-zero value, execute | |
868 | COMMANDS and evaluate the arithmetic expression EXPR3. If any | |
869 | expression is omitted, it behaves as if it evaluates to 1. The | |
870 | return value is the exit status of the last command in COMMANDS | |
871 | that is executed, or non-zero if any of the expressions is invalid. | |
872 | ||
873 | Use the ‘break’ and ‘continue’ builtins (*note Bourne Shell | |
874 | Builtins::) to control loop execution. | |
875 | ||
876 | \1f | |
877 | File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands | |
878 | ||
879 | 3.2.5.2 Conditional Constructs | |
880 | .............................. | |
881 | ||
882 | ‘if’ | |
883 | The syntax of the ‘if’ command is: | |
884 | ||
885 | if TEST-COMMANDS; then | |
886 | CONSEQUENT-COMMANDS; | |
887 | [elif MORE-TEST-COMMANDS; then | |
888 | MORE-CONSEQUENTS;] | |
889 | [else ALTERNATE-CONSEQUENTS;] | |
890 | fi | |
891 | ||
892 | The TEST-COMMANDS list is executed, and if its return status is | |
893 | zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS | |
894 | returns a non-zero status, each ‘elif’ list is executed in turn, | |
895 | and if its exit status is zero, the corresponding MORE-CONSEQUENTS | |
896 | is executed and the command completes. If ‘else | |
897 | ALTERNATE-CONSEQUENTS’ is present, and the final command in the | |
898 | final ‘if’ or ‘elif’ clause has a non-zero exit status, then | |
899 | ALTERNATE-CONSEQUENTS is executed. The return status is the exit | |
900 | status of the last command executed, or zero if no condition tested | |
901 | true. | |
902 | ||
903 | ‘case’ | |
904 | The syntax of the ‘case’ command is: | |
905 | ||
906 | case WORD in | |
907 | [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... | |
908 | esac | |
909 | ||
910 | ‘case’ will selectively execute the COMMAND-LIST corresponding to | |
911 | the first PATTERN that matches WORD, proceeding from the first | |
912 | pattern to the last. The match is performed according to the rules | |
913 | described below in *note Pattern Matching::. If the ‘nocasematch’ | |
914 | shell option (see the description of ‘shopt’ in *note The Shopt | |
915 | Builtin::) is enabled, the match is performed without regard to the | |
916 | case of alphabetic characters. The ‘|’ is used to separate | |
917 | multiple patterns in a pattern list, and the ‘)’ operator | |
918 | terminates the pattern list. A pattern list and an associated | |
919 | COMMAND-LIST is known as a CLAUSE. | |
920 | ||
921 | Each clause must be terminated with ‘;;’, ‘;&’, or ‘;;&’. The WORD | |
922 | undergoes tilde expansion, parameter expansion, command | |
923 | substitution, process substitution, arithmetic expansion, and quote | |
924 | removal (*note Shell Parameter Expansion::) before the shell | |
925 | attempts to match the pattern. Each PATTERN undergoes tilde | |
926 | expansion, parameter expansion, command substitution, arithmetic | |
927 | expansion, process substitution, and quote removal. | |
928 | ||
929 | There may be an arbitrary number of ‘case’ clauses, each terminated | |
930 | by a ‘;;’, ‘;&’, or ‘;;&’. The first pattern that matches | |
931 | determines the command-list that is executed. It's a common idiom | |
932 | to use ‘*’ as the final pattern to define the default case, since | |
933 | that pattern will always match. | |
934 | ||
935 | Here is an example using ‘case’ in a script that could be used to | |
936 | describe one interesting feature of an animal: | |
937 | ||
938 | echo -n "Enter the name of an animal: " | |
939 | read ANIMAL | |
940 | echo -n "The $ANIMAL has " | |
941 | case $ANIMAL in | |
942 | horse | dog | cat) echo -n "four";; | |
943 | man | kangaroo ) echo -n "two";; | |
944 | *) echo -n "an unknown number of";; | |
945 | esac | |
946 | echo " legs." | |
947 | ||
948 | If the ‘;;’ operator is used, the ‘case’ command completes after | |
949 | the first pattern match. Using ‘;&’ in place of ‘;;’ causes | |
950 | execution to continue with the COMMAND-LIST associated with the | |
951 | next clause, if any. Using ‘;;&’ in place of ‘;;’ causes the shell | |
952 | to test the patterns in the next clause, if any, and execute any | |
953 | associated COMMAND-LIST if the match succeeds, continuing the case | |
954 | statement execution as if the pattern list had not matched. | |
955 | ||
956 | The return status is zero if no PATTERN matches. Otherwise, the | |
957 | return status is the exit status of the last COMMAND-LIST executed. | |
958 | ||
959 | ‘select’ | |
960 | ||
961 | The ‘select’ construct allows the easy generation of menus. It has | |
962 | almost the same syntax as the ‘for’ command: | |
963 | ||
964 | select NAME [in WORDS ...]; do COMMANDS; done | |
965 | ||
966 | First, expand the list of words following ‘in’, generating a list | |
967 | of items, and print the set of expanded words on the standard error | |
968 | stream, each preceded by a number. If the ‘in WORDS’ is omitted, | |
969 | print the positional parameters, as if ‘in "$@"’ had been | |
970 | specified. ‘select’ then displays the ‘PS3’ prompt and reads a | |
971 | line from the standard input. If the line consists of a number | |
972 | corresponding to one of the displayed words, then ‘select’ sets the | |
973 | value of NAME to that word. If the line is empty, ‘select’ | |
974 | displays the words and prompt again. If ‘EOF’ is read, ‘select’ | |
975 | completes and returns 1. Any other value read causes NAME to be | |
976 | set to null. The line read is saved in the variable ‘REPLY’. | |
977 | ||
978 | The COMMANDS are executed after each selection until a ‘break’ | |
979 | command is executed, at which point the ‘select’ command completes. | |
980 | ||
981 | Here is an example that allows the user to pick a filename from the | |
982 | current directory, and displays the name and index of the file | |
983 | selected. | |
984 | ||
985 | select fname in *; | |
986 | do | |
987 | echo you picked $fname \($REPLY\) | |
988 | break; | |
989 | done | |
990 | ||
991 | ‘((...))’ | |
992 | (( EXPRESSION )) | |
993 | ||
994 | The arithmetic EXPRESSION is evaluated according to the rules | |
995 | described below (*note Shell Arithmetic::). The EXPRESSION | |
996 | undergoes the same expansions as if it were within double quotes, | |
997 | but unescaped double quote characters in EXPRESSION are not treated | |
998 | specially and are removed. Since this can potentially result in | |
999 | empty strings, this command treats those as expressions that | |
1000 | evaluate to 0. If the value of the expression is non-zero, the | |
1001 | return status is 0; otherwise the return status is 1. | |
1002 | ||
1003 | ‘[[...]]’ | |
1004 | [[ EXPRESSION ]] | |
1005 | ||
1006 | Evaluate the conditional expression EXPRESSION and return a status | |
1007 | of zero (true) or non-zero (false). Expressions are composed of | |
1008 | the primaries described below in *note Bash Conditional | |
1009 | Expressions::. The words between the ‘[[’ and ‘]]’ do not undergo | |
1010 | word splitting and filename expansion. The shell performs tilde | |
1011 | expansion, parameter and variable expansion, arithmetic expansion, | |
1012 | command substitution, process substitution, and quote removal on | |
1013 | those words. Conditional operators such as ‘-f’ must be unquoted | |
1014 | to be recognized as primaries. | |
1015 | ||
1016 | When used with ‘[[’, the ‘<’ and ‘>’ operators sort | |
1017 | lexicographically using the current locale. | |
1018 | ||
1019 | When the ‘==’ and ‘!=’ operators are used, the string to the right | |
1020 | of the operator is considered a pattern and matched according to | |
1021 | the rules described below in *note Pattern Matching::, as if the | |
1022 | ‘extglob’ shell option were enabled. The ‘=’ operator is identical | |
1023 | to ‘==’. If the ‘nocasematch’ shell option (see the description of | |
1024 | ‘shopt’ in *note The Shopt Builtin::) is enabled, the match is | |
1025 | performed without regard to the case of alphabetic characters. The | |
1026 | return value is 0 if the string matches (‘==’) or does not match | |
1027 | (‘!=’) the pattern, and 1 otherwise. | |
1028 | ||
1029 | If you quote any part of the pattern, using any of the shell's | |
1030 | quoting mechanisms, the quoted portion is matched literally. This | |
1031 | means every character in the quoted portion matches itself, instead | |
1032 | of having any special pattern matching meaning. | |
1033 | ||
1034 | An additional binary operator, ‘=~’, is available, with the same | |
1035 | precedence as ‘==’ and ‘!=’. When you use ‘=~’, the string to the | |
1036 | right of the operator is considered a POSIX extended regular | |
1037 | expression pattern and matched accordingly (using the POSIX | |
1038 | ‘regcomp’ and ‘regexec’ interfaces usually described in regex(3)). | |
1039 | The return value is 0 if the string matches the pattern, and 1 if | |
1040 | it does not. If the regular expression is syntactically incorrect, | |
1041 | the conditional expression returns 2. If the ‘nocasematch’ shell | |
1042 | option (see the description of ‘shopt’ in *note The Shopt | |
1043 | Builtin::) is enabled, the match is performed without regard to the | |
1044 | case of alphabetic characters. | |
1045 | ||
1046 | You can quote any part of the pattern to force the quoted portion | |
1047 | to be matched literally instead of as a regular expression (see | |
1048 | above). If the pattern is stored in a shell variable, quoting the | |
1049 | variable expansion forces the entire pattern to be matched | |
1050 | literally. | |
1051 | ||
1052 | The match succeeds if the pattern matches any part of the string. | |
1053 | If you want to force the pattern to match the entire string, anchor | |
1054 | the pattern using the ‘^’ and ‘$’ regular expression operators. | |
1055 | ||
1056 | For example, the following will match a line (stored in the shell | |
1057 | variable ‘line’) if there is a sequence of characters anywhere in | |
1058 | the value consisting of any number, including zero, of characters | |
1059 | in the ‘space’ character class, immediately followed by zero or one | |
1060 | instances of ‘a’, then a ‘b’: | |
1061 | ||
1062 | [[ $line =~ [[:space:]]*(a)?b ]] | |
1063 | ||
1064 | That means values for ‘line’ like ‘aab’, ‘ aaaaaab’, ‘xaby’, and ‘ | |
1065 | ab’ will all match, as will a line containing a ‘b’ anywhere in its | |
1066 | value. | |
1067 | ||
1068 | If you want to match a character that's special to the regular | |
1069 | expression grammar (‘^$|[]()\.*+?’), it has to be quoted to remove | |
1070 | its special meaning. This means that in the pattern ‘xxx.txt’, the | |
1071 | ‘.’ matches any character in the string (its usual regular | |
1072 | expression meaning), but in the pattern ‘"xxx.txt"’, it can only | |
1073 | match a literal ‘.’. | |
1074 | ||
1075 | Likewise, if you want to include a character in your pattern that | |
1076 | has a special meaning to the regular expression grammar, you must | |
1077 | make sure it's not quoted. If you want to anchor a pattern at the | |
1078 | beginning or end of the string, for instance, you cannot quote the | |
1079 | ‘^’ or ‘$’ characters using any form of shell quoting. | |
1080 | ||
1081 | If you want to match ‘initial string’ at the start of a line, the | |
1082 | following will work: | |
1083 | [[ $line =~ ^"initial string" ]] | |
1084 | but this will not: | |
1085 | [[ $line =~ "^initial string" ]] | |
1086 | because in the second example the ‘^’ is quoted and doesn't have | |
1087 | its usual special meaning. | |
1088 | ||
1089 | It is sometimes difficult to specify a regular expression properly | |
1090 | without using quotes, or to keep track of the quoting used by | |
1091 | regular expressions while paying attention to shell quoting and the | |
1092 | shell's quote removal. Storing the regular expression in a shell | |
1093 | variable is often a useful way to avoid problems with quoting | |
1094 | characters that are special to the shell. For example, the | |
1095 | following is equivalent to the pattern used above: | |
1096 | ||
1097 | pattern='[[:space:]]*(a)?b' | |
1098 | [[ $line =~ $pattern ]] | |
1099 | ||
1100 | Shell programmers should take special care with backslashes, since | |
1101 | backslashes are used by both the shell and regular expressions to | |
1102 | remove the special meaning from the following character. This | |
1103 | means that after the shell's word expansions complete (*note Shell | |
1104 | Expansions::), any backslashes remaining in parts of the pattern | |
1105 | that were originally not quoted can remove the special meaning of | |
1106 | pattern characters. If any part of the pattern is quoted, the | |
1107 | shell does its best to ensure that the regular expression treats | |
1108 | those remaining backslashes as literal, if they appeared in a | |
1109 | quoted portion. | |
1110 | ||
1111 | The following two sets of commands are _not_ equivalent: | |
1112 | ||
1113 | pattern='\.' | |
1114 | ||
1115 | [[ . =~ $pattern ]] | |
1116 | [[ . =~ \. ]] | |
1117 | ||
1118 | [[ . =~ "$pattern" ]] | |
1119 | [[ . =~ '\.' ]] | |
1120 | ||
1121 | The first two matches will succeed, but the second two will not, | |
1122 | because in the second two the backslash will be part of the pattern | |
1123 | to be matched. In the first two examples, the pattern passed to | |
1124 | the regular expression parser is ‘\.’. The backslash removes the | |
1125 | special meaning from ‘.’, so the literal ‘.’ matches. In the | |
1126 | second two examples, the pattern passed to the regular expression | |
1127 | parser has the backslash quoted (e.g., ‘\\\.’), which will not | |
1128 | match the string, since it does not contain a backslash. If the | |
1129 | string in the first examples were anything other than ‘.’, say ‘a’, | |
1130 | the pattern would not match, because the quoted ‘.’ in the pattern | |
1131 | loses its special meaning of matching any single character. | |
1132 | ||
1133 | Bracket expressions in regular expressions can be sources of errors | |
1134 | as well, since characters that are normally special in regular | |
1135 | expressions lose their special meanings between brackets. However, | |
1136 | you can use bracket expressions to match special pattern characters | |
1137 | without quoting them, so they are sometimes useful for this | |
1138 | purpose. | |
1139 | ||
1140 | Though it might seem like a strange way to write it, the following | |
1141 | pattern will match a ‘.’ in the string: | |
1142 | ||
1143 | [[ . =~ [.] ]] | |
1144 | ||
1145 | The shell performs any word expansions before passing the pattern | |
1146 | to the regular expression functions, so you can assume that the | |
1147 | shell's quoting takes precedence. As noted above, the regular | |
1148 | expression parser will interpret any unquoted backslashes remaining | |
1149 | in the pattern after shell expansion according to its own rules. | |
1150 | The intention is to avoid making shell programmers quote things | |
1151 | twice as much as possible, so shell quoting should be sufficient to | |
1152 | quote special pattern characters where that's necessary. | |
1153 | ||
1154 | The array variable ‘BASH_REMATCH’ records which parts of the string | |
1155 | matched the pattern. The element of ‘BASH_REMATCH’ with index 0 | |
1156 | contains the portion of the string matching the entire regular | |
1157 | expression. Substrings matched by parenthesized subexpressions | |
1158 | within the regular expression are saved in the remaining | |
1159 | ‘BASH_REMATCH’ indices. The element of ‘BASH_REMATCH’ with index N | |
1160 | is the portion of the string matching the Nth parenthesized | |
1161 | subexpression. | |
1162 | ||
1163 | Bash sets ‘BASH_REMATCH’ in the global scope; declaring it as a | |
1164 | local variable will lead to unexpected results. | |
1165 | ||
1166 | Expressions may be combined using the following operators, listed | |
1167 | in decreasing order of precedence: | |
1168 | ||
1169 | ‘( EXPRESSION )’ | |
1170 | Returns the value of EXPRESSION. This may be used to override | |
1171 | the normal precedence of operators. | |
1172 | ||
1173 | ‘! EXPRESSION’ | |
1174 | True if EXPRESSION is false. | |
1175 | ||
1176 | ‘EXPRESSION1 && EXPRESSION2’ | |
1177 | True if both EXPRESSION1 and EXPRESSION2 are true. | |
1178 | ||
1179 | ‘EXPRESSION1 || EXPRESSION2’ | |
1180 | True if either EXPRESSION1 or EXPRESSION2 is true. | |
1181 | ||
1182 | The ‘&&’ and ‘||’ operators do not evaluate EXPRESSION2 if the | |
1183 | value of EXPRESSION1 is sufficient to determine the return value of | |
1184 | the entire conditional expression. | |
1185 | ||
1186 | \1f | |
1187 | File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands | |
1188 | ||
1189 | 3.2.5.3 Grouping Commands | |
1190 | ......................... | |
1191 | ||
1192 | Bash provides two ways to group a list of commands to be executed as a | |
1193 | unit. When commands are grouped, redirections may be applied to the | |
1194 | entire command list. For example, the output of all the commands in the | |
1195 | list may be redirected to a single stream. | |
1196 | ||
1197 | ‘()’ | |
1198 | ( LIST ) | |
1199 | ||
1200 | Placing a list of commands between parentheses forces the shell to | |
1201 | create a subshell (*note Command Execution Environment::), and each | |
1202 | of the commands in LIST is executed in that subshell environment. | |
1203 | Since the LIST is executed in a subshell, variable assignments do | |
1204 | not remain in effect after the subshell completes. | |
1205 | ||
1206 | ‘{}’ | |
1207 | { LIST; } | |
1208 | ||
1209 | Placing a list of commands between curly braces causes the list to | |
1210 | be executed in the current shell environment. No subshell is | |
1211 | created. The semicolon (or newline) following LIST is required. | |
1212 | ||
1213 | In addition to the creation of a subshell, there is a subtle | |
1214 | difference between these two constructs due to historical reasons. The | |
1215 | braces are reserved words, so they must be separated from the LIST by | |
1216 | ‘blank’s or other shell metacharacters. The parentheses are operators, | |
1217 | and are recognized as separate tokens by the shell even if they are not | |
1218 | separated from the LIST by whitespace. | |
1219 | ||
1220 | The exit status of both of these constructs is the exit status of | |
1221 | LIST. | |
1222 | ||
1223 | \1f | |
1224 | File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands | |
1225 | ||
1226 | 3.2.6 Coprocesses | |
1227 | ----------------- | |
1228 | ||
1229 | A ‘coprocess’ is a shell command preceded by the ‘coproc’ reserved word. | |
1230 | A coprocess is executed asynchronously in a subshell, as if the command | |
1231 | had been terminated with the ‘&’ control operator, with a two-way pipe | |
1232 | established between the executing shell and the coprocess. | |
1233 | ||
1234 | The syntax for a coprocess is: | |
1235 | ||
1236 | coproc [NAME] COMMAND [REDIRECTIONS] | |
1237 | ||
1238 | This creates a coprocess named NAME. COMMAND may be either a simple | |
1239 | command (*note Simple Commands::) or a compound command (*note Compound | |
1240 | Commands::). NAME is a shell variable name. If NAME is not supplied, | |
1241 | the default name is ‘COPROC’. | |
1242 | ||
1243 | The recommended form to use for a coprocess is | |
1244 | ||
1245 | coproc NAME { COMMAND; } | |
1246 | ||
1247 | This form is preferred because simple commands result in the coprocess | |
1248 | always being named ‘COPROC’, and it is simpler to use and more complete | |
1249 | than the other compound commands. | |
1250 | ||
1251 | There are other forms of coprocesses: | |
1252 | ||
1253 | coproc NAME COMPOUND-COMMAND | |
1254 | coproc COMPOUND-COMMAND | |
1255 | coproc SIMPLE-COMMAND | |
1256 | ||
1257 | If COMMAND is a compound command, NAME is optional. The word following | |
1258 | ‘coproc’ determines whether that word is interpreted as a variable name: | |
1259 | it is interpreted as NAME if it is not a reserved word that introduces a | |
1260 | compound command. If COMMAND is a simple command, NAME is not allowed; | |
1261 | this is to avoid confusion between NAME and the first word of the simple | |
1262 | command. | |
1263 | ||
1264 | When the coprocess is executed, the shell creates an array variable | |
1265 | (*note Arrays::) named NAME in the context of the executing shell. The | |
1266 | standard output of COMMAND is connected via a pipe to a file descriptor | |
1267 | in the executing shell, and that file descriptor is assigned to NAME[0]. | |
1268 | The standard input of COMMAND is connected via a pipe to a file | |
1269 | descriptor in the executing shell, and that file descriptor is assigned | |
1270 | to NAME[1]. This pipe is established before any redirections specified | |
1271 | by the command (*note Redirections::). The file descriptors can be | |
1272 | utilized as arguments to shell commands and redirections using standard | |
1273 | word expansions. Other than those created to execute command and | |
1274 | process substitutions, the file descriptors are not available in | |
1275 | subshells. | |
1276 | ||
1277 | The process ID of the shell spawned to execute the coprocess is | |
1278 | available as the value of the variable ‘NAME_PID’. The ‘wait’ builtin | |
1279 | may be used to wait for the coprocess to terminate. | |
1280 | ||
1281 | Since the coprocess is created as an asynchronous command, the | |
1282 | ‘coproc’ command always returns success. The return status of a | |
1283 | coprocess is the exit status of COMMAND. | |
1284 | ||
1285 | \1f | |
1286 | File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands | |
1287 | ||
1288 | 3.2.7 GNU Parallel | |
1289 | ------------------ | |
1290 | ||
1291 | There are ways to run commands in parallel that are not built into Bash. | |
1292 | GNU Parallel is a tool to do just that. | |
1293 | ||
1294 | GNU Parallel, as its name suggests, can be used to build and run | |
1295 | commands in parallel. You may run the same command with different | |
1296 | arguments, whether they are filenames, usernames, hostnames, or lines | |
1297 | read from files. GNU Parallel provides shorthand references to many of | |
1298 | the most common operations (input lines, various portions of the input | |
1299 | line, different ways to specify the input source, and so on). Parallel | |
1300 | can replace ‘xargs’ or feed commands from its input sources to several | |
1301 | different instances of Bash. | |
1302 | ||
1303 | For a complete description, refer to the GNU Parallel documentation, | |
1304 | which is available at | |
1305 | <https://www.gnu.org/software/parallel/parallel_tutorial.html>. | |
1306 | ||
1307 | \1f | |
1308 | File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features | |
1309 | ||
1310 | 3.3 Shell Functions | |
1311 | =================== | |
1312 | ||
1313 | Shell functions are a way to group commands for later execution using a | |
1314 | single name for the group. They are executed just like a "regular" | |
1315 | simple command. When the name of a shell function is used as a simple | |
1316 | command name, the shell executes the list of commands associated with | |
1317 | that function name. Shell functions are executed in the current shell | |
1318 | context; there is no new process created to interpret them. | |
1319 | ||
1320 | Functions are declared using this syntax: | |
1321 | FNAME () COMPOUND-COMMAND [ REDIRECTIONS ] | |
1322 | ||
1323 | or | |
1324 | ||
1325 | function FNAME [()] COMPOUND-COMMAND [ REDIRECTIONS ] | |
1326 | ||
1327 | This defines a shell function named FNAME. The reserved word | |
1328 | ‘function’ is optional. If the ‘function’ reserved word is supplied, | |
1329 | the parentheses are optional. The “body” of the function is the | |
1330 | compound command COMPOUND-COMMAND (*note Compound Commands::). That | |
1331 | command is usually a LIST enclosed between { and }, but may be any | |
1332 | compound command listed above. If the ‘function’ reserved word is used, | |
1333 | but the parentheses are not supplied, the braces are recommended. When | |
1334 | the shell is in POSIX mode (*note Bash POSIX Mode::), FNAME must be a | |
1335 | valid shell name and may not be the same as one of the special builtins | |
1336 | (*note Special Builtins::). When not in POSIX mode, a function name can | |
1337 | be any unquoted shell word that does not contain ‘$’. | |
1338 | ||
1339 | Any redirections (*note Redirections::) associated with the shell | |
1340 | function are performed when the function is executed. Function | |
1341 | definitions are deleted using the ‘-f’ option to the ‘unset’ builtin | |
1342 | (*note Bourne Shell Builtins::). | |
1343 | ||
1344 | The exit status of a function definition is zero unless a syntax | |
1345 | error occurs or a readonly function with the same name already exists. | |
1346 | When executed, the exit status of a function is the exit status of the | |
1347 | last command executed in the body. | |
1348 | ||
1349 | Note that for historical reasons, in the most common usage the curly | |
1350 | braces that surround the body of the function must be separated from the | |
1351 | body by ‘blank’s or newlines. This is because the braces are reserved | |
1352 | words and are only recognized as such when they are separated from the | |
1353 | command list by whitespace or another shell metacharacter. When using | |
1354 | the braces, the LIST must be terminated by a semicolon, a ‘&’, or a | |
1355 | newline. | |
1356 | ||
1357 | COMPOUND-COMMAND is executed whenever FNAME is specified as the name | |
1358 | of a simple command. Functions are executed in the context of the | |
1359 | calling shell; there is no new process created to interpret them | |
1360 | (contrast this with the execution of a shell script). | |
1361 | ||
1362 | When a function is executed, the arguments to the function become the | |
1363 | positional parameters during its execution (*note Positional | |
1364 | Parameters::). The special parameter ‘#’ that expands to the number of | |
1365 | positional parameters is updated to reflect the new set of positional | |
1366 | parameters. Special parameter ‘0’ is unchanged. The first element of | |
1367 | the ‘FUNCNAME’ variable is set to the name of the function while the | |
1368 | function is executing. | |
1369 | ||
1370 | All other aspects of the shell execution environment are identical | |
1371 | between a function and its caller with these exceptions: the ‘DEBUG’ and | |
1372 | ‘RETURN’ traps are not inherited unless the function has been given the | |
1373 | ‘trace’ attribute using the ‘declare’ builtin or the ‘-o functrace’ | |
1374 | option has been enabled with the ‘set’ builtin, (in which case all | |
1375 | functions inherit the ‘DEBUG’ and ‘RETURN’ traps), and the ‘ERR’ trap is | |
1376 | not inherited unless the ‘-o errtrace’ shell option has been enabled. | |
1377 | *Note Bourne Shell Builtins::, for the description of the ‘trap’ | |
1378 | builtin. | |
1379 | ||
1380 | The ‘FUNCNEST’ variable, if set to a numeric value greater than 0, | |
1381 | defines a maximum function nesting level. Function invocations that | |
1382 | exceed the limit cause the entire command to abort. | |
1383 | ||
1384 | If the builtin command ‘return’ is executed in a function, the | |
1385 | function completes and execution resumes with the next command after the | |
1386 | function call. Any command associated with the ‘RETURN’ trap is | |
1387 | executed before execution resumes. When a function completes, the | |
1388 | values of the positional parameters and the special parameter ‘#’ are | |
1389 | restored to the values they had prior to the function's execution. If | |
1390 | ‘return’ is supplied a numeric argument, that is the function's return | |
1391 | status; otherwise the function's return status is the exit status of the | |
1392 | last command executed before the ‘return’. | |
1393 | ||
1394 | Variables local to the function are declared with the ‘local’ builtin | |
1395 | (“local variables”). Ordinarily, variables and their values are shared | |
1396 | between a function and its caller. These variables are visible only to | |
1397 | the function and the commands it invokes. This is particularly | |
1398 | important when a shell function calls other functions. | |
1399 | ||
1400 | In the following description, the “current scope” is a currently- | |
1401 | executing function. Previous scopes consist of that function's caller | |
1402 | and so on, back to the "global" scope, where the shell is not executing | |
1403 | any shell function. A local variable at the current local scope is a | |
1404 | variable declared using the ‘local’ or ‘declare’ builtins in the | |
1405 | function that is currently executing. | |
1406 | ||
1407 | Local variables "shadow" variables with the same name declared at | |
1408 | previous scopes. For instance, a local variable declared in a function | |
1409 | hides variables with the same name declared at previous scopes, | |
1410 | including global variables: references and assignments refer to the | |
1411 | local variable, leaving the variables at previous scopes unmodified. | |
1412 | When the function returns, the global variable is once again visible. | |
1413 | ||
1414 | The shell uses “dynamic scoping” to control a variable's visibility | |
1415 | within functions. With dynamic scoping, visible variables and their | |
1416 | values are a result of the sequence of function calls that caused | |
1417 | execution to reach the current function. The value of a variable that a | |
1418 | function sees depends on its value within its caller, if any, whether | |
1419 | that caller is the global scope or another shell function. This is also | |
1420 | the value that a local variable declaration shadows, and the value that | |
1421 | is restored when the function returns. | |
1422 | ||
1423 | For example, if a variable ‘var’ is declared as local in function | |
1424 | ‘func1’, and ‘func1’ calls another function ‘func2’, references to ‘var’ | |
1425 | made from within ‘func2’ resolve to the local variable ‘var’ from | |
1426 | ‘func1’, shadowing any global variable named ‘var’. | |
1427 | ||
1428 | The following script demonstrates this behavior. When executed, the | |
1429 | script displays | |
1430 | ||
1431 | In func2, var = func1 local | |
1432 | ||
1433 | func1() | |
1434 | { | |
1435 | local var='func1 local' | |
1436 | func2 | |
1437 | } | |
1438 | ||
1439 | func2() | |
1440 | { | |
1441 | echo "In func2, var = $var" | |
1442 | } | |
1443 | ||
1444 | var=global | |
1445 | func1 | |
1446 | ||
1447 | The ‘unset’ builtin also acts using the same dynamic scope: if a | |
1448 | variable is local to the current scope, ‘unset’ unsets it; otherwise the | |
1449 | unset will refer to the variable found in any calling scope as described | |
1450 | above. If a variable at the current local scope is unset, it remains so | |
1451 | (appearing as unset) until it is reset in that scope or until the | |
1452 | function returns. Once the function returns, any instance of the | |
1453 | variable at a previous scope becomes visible. If the unset acts on a | |
1454 | variable at a previous scope, any instance of a variable with that name | |
1455 | that had been shadowed becomes visible (see below how the | |
1456 | ‘localvar_unset’ shell option changes this behavior). | |
1457 | ||
1458 | The ‘-f’ option to the ‘declare’ (‘typeset’) builtin command (*note | |
1459 | Bash Builtins::) lists function names and definitions. The ‘-F’ option | |
1460 | to ‘declare’ or ‘typeset’ lists the function names only (and optionally | |
1461 | the source file and line number, if the ‘extdebug’ shell option is | |
1462 | enabled). Functions may be exported so that child shell processes | |
1463 | (those created when executing a separate shell invocation) automatically | |
1464 | have them defined with the ‘-f’ option to the ‘export’ builtin (*note | |
1465 | Bourne Shell Builtins::). The ‘-f’ option to the ‘unset’ builtin (*note | |
1466 | Bourne Shell Builtins::) deletes a function definition. | |
1467 | ||
1468 | Functions may be recursive. The ‘FUNCNEST’ variable may be used to | |
1469 | limit the depth of the function call stack and restrict the number of | |
1470 | function invocations. By default, Bash places no limit on the number of | |
1471 | recursive calls. | |
1472 | ||
1473 | \1f | |
1474 | File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features | |
1475 | ||
1476 | 3.4 Shell Parameters | |
1477 | ==================== | |
1478 | ||
1479 | * Menu: | |
1480 | ||
1481 | * Positional Parameters:: The shell's command-line arguments. | |
1482 | * Special Parameters:: Parameters denoted by special characters. | |
1483 | ||
1484 | A “parameter” is an entity that stores values. It can be a ‘name’, a | |
1485 | number, or one of the special characters listed below. A “variable” is | |
1486 | a parameter denoted by a ‘name’. A variable has a ‘value’ and zero or | |
1487 | more ‘attributes’. Attributes are assigned using the ‘declare’ builtin | |
1488 | command (see the description of the ‘declare’ builtin in *note Bash | |
1489 | Builtins::). The ‘export’ and ‘readonly’ builtins assign specific | |
1490 | attributes. | |
1491 | ||
1492 | A parameter is set if it has been assigned a value. The null string | |
1493 | is a valid value. Once a variable is set, it may be unset only by using | |
1494 | the ‘unset’ builtin command. | |
1495 | ||
1496 | A variable is assigned to using a statement of the form | |
1497 | NAME=[VALUE] | |
1498 | If VALUE is not given, the variable is assigned the null string. All | |
1499 | VALUEs undergo tilde expansion, parameter and variable expansion, | |
1500 | command substitution, arithmetic expansion, and quote removal (*note | |
1501 | Shell Parameter Expansion::). If the variable has its ‘integer’ | |
1502 | attribute set, then VALUE is evaluated as an arithmetic expression even | |
1503 | if the ‘$((...))’ expansion is not used (*note Arithmetic Expansion::). | |
1504 | Word splitting and filename expansion are not performed. Assignment | |
1505 | statements may also appear as arguments to the ‘alias’, ‘declare’, | |
1506 | ‘typeset’, ‘export’, ‘readonly’, and ‘local’ builtin commands | |
1507 | (“declaration commands”). When in POSIX mode (*note Bash POSIX Mode::), | |
1508 | these builtins may appear in a command after one or more instances of | |
1509 | the ‘command’ builtin and retain these assignment statement properties. | |
1510 | For example, | |
1511 | command export var=value | |
1512 | ||
1513 | In the context where an assignment statement is assigning a value to | |
1514 | a shell variable or array index (*note Arrays::), the ‘+=’ operator | |
1515 | appends to or adds to the variable's previous value. This includes | |
1516 | arguments to declaration commands such as ‘declare’ that accept | |
1517 | assignment statements. When ‘+=’ is applied to a variable for which the | |
1518 | ‘integer’ attribute has been set, the variable's current value and VALUE | |
1519 | are each evaluated as arithmetic expressions, and the sum of the results | |
1520 | is assigned as the variable's value. The current value is usually an | |
1521 | integer constant, but may be an expression. When ‘+=’ is applied to an | |
1522 | array variable using compound assignment (*note Arrays::), the | |
1523 | variable's value is not unset (as it is when using ‘=’), and new values | |
1524 | are appended to the array beginning at one greater than the array's | |
1525 | maximum index (for indexed arrays), or added as additional key-value | |
1526 | pairs in an associative array. When applied to a string-valued | |
1527 | variable, VALUE is expanded and appended to the variable's value. | |
1528 | ||
1529 | A variable can be assigned the ‘nameref’ attribute using the ‘-n’ | |
1530 | option to the ‘declare’ or ‘local’ builtin commands (*note Bash | |
1531 | Builtins::) to create a “nameref”, or a reference to another variable. | |
1532 | This allows variables to be manipulated indirectly. Whenever the | |
1533 | nameref variable is referenced, assigned to, unset, or has its | |
1534 | attributes modified (other than using or changing the nameref attribute | |
1535 | itself), the operation is actually performed on the variable specified | |
1536 | by the nameref variable's value. A nameref is commonly used within | |
1537 | shell functions to refer to a variable whose name is passed as an | |
1538 | argument to the function. For instance, if a variable name is passed to | |
1539 | a shell function as its first argument, running | |
1540 | declare -n ref=$1 | |
1541 | inside the function creates a local nameref variable ‘ref’ whose value | |
1542 | is the variable name passed as the first argument. References and | |
1543 | assignments to ‘ref’, and changes to its attributes, are treated as | |
1544 | references, assignments, and attribute modifications to the variable | |
1545 | whose name was passed as ‘$1’. | |
1546 | ||
1547 | If the control variable in a ‘for’ loop has the nameref attribute, | |
1548 | the list of words can be a list of shell variables, and a name reference | |
1549 | is established for each word in the list, in turn, when the loop is | |
1550 | executed. Array variables cannot be given the nameref attribute. | |
1551 | However, nameref variables can reference array variables and subscripted | |
1552 | array variables. Namerefs can be unset using the ‘-n’ option to the | |
1553 | ‘unset’ builtin (*note Bourne Shell Builtins::). Otherwise, if ‘unset’ | |
1554 | is executed with the name of a nameref variable as an argument, the | |
1555 | variable referenced by the nameref variable is unset. | |
1556 | ||
1557 | When the shell starts, it reads its environment and creates a shell | |
1558 | variable from each environment variable that has a valid name, as | |
1559 | described below (*note Environment::). | |
1560 | ||
1561 | \1f | |
1562 | File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters | |
1563 | ||
1564 | 3.4.1 Positional Parameters | |
1565 | --------------------------- | |
1566 | ||
1567 | A “positional parameter” is a parameter denoted by one or more digits, | |
1568 | other than the single digit ‘0’. Positional parameters are assigned | |
1569 | from the shell's arguments when it is invoked, and may be reassigned | |
1570 | using the ‘set’ builtin command. Positional parameter ‘N’ may be | |
1571 | referenced as ‘${N}’, or as ‘$N’ when ‘N’ consists of a single digit. | |
1572 | Positional parameters may not be assigned to with assignment statements. | |
1573 | The ‘set’ and ‘shift’ builtins are used to set and unset them (*note | |
1574 | Shell Builtin Commands::). The positional parameters are temporarily | |
1575 | replaced when a shell function is executed (*note Shell Functions::). | |
1576 | ||
1577 | When a positional parameter consisting of more than a single digit is | |
1578 | expanded, it must be enclosed in braces. Without braces, a digit | |
1579 | following ‘$’ can only refer to one of the first nine positional | |
1580 | parameters ($1\-$9) or the special parameter $0 (see below). | |
1581 | ||
1582 | \1f | |
1583 | File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters | |
1584 | ||
1585 | 3.4.2 Special Parameters | |
1586 | ------------------------ | |
1587 | ||
1588 | The shell treats several parameters specially. These parameters may | |
1589 | only be referenced; assignment to them is not allowed. Special | |
1590 | parameters are denoted by one of the following characters. | |
1591 | ||
1592 | ‘*’ | |
1593 | ($*) Expands to the positional parameters, starting from one. When | |
1594 | the expansion is not within double quotes, each positional | |
1595 | parameter expands to a separate word. In contexts where word | |
1596 | expansions are performed, those words are subject to further word | |
1597 | splitting and filename expansion. When the expansion occurs within | |
1598 | double quotes, it expands to a single word with the value of each | |
1599 | parameter separated by the first character of the ‘IFS’ variable. | |
1600 | That is, ‘"$*"’ is equivalent to ‘"$1C$2C..."’, where C is the | |
1601 | first character of the value of the ‘IFS’ variable. If ‘IFS’ is | |
1602 | unset, the parameters are separated by spaces. If ‘IFS’ is null, | |
1603 | the parameters are joined without intervening separators. | |
1604 | ||
1605 | ‘@’ | |
1606 | ($@) Expands to the positional parameters, starting from one. In | |
1607 | contexts where word splitting is performed, this expands each | |
1608 | positional parameter to a separate word; if not within double | |
1609 | quotes, these words are subject to word splitting. In contexts | |
1610 | where word splitting is not performed, such as the value portion of | |
1611 | an assignment statement, this expands to a single word with each | |
1612 | positional parameter separated by a space. When the expansion | |
1613 | occurs within double quotes, and word splitting is performed, each | |
1614 | parameter expands to a separate word. That is, ‘"$@"’ is | |
1615 | equivalent to ‘"$1" "$2" ...’. If the double-quoted expansion | |
1616 | occurs within a word, the expansion of the first parameter is | |
1617 | joined with the expansion of the beginning part of the original | |
1618 | word, and the expansion of the last parameter is joined with the | |
1619 | expansion of the last part of the original word. When there are no | |
1620 | positional parameters, ‘"$@"’ and ‘$@’ expand to nothing (i.e., | |
1621 | they are removed). | |
1622 | ||
1623 | ‘#’ | |
1624 | ($#) Expands to the number of positional parameters in decimal. | |
1625 | ||
1626 | ‘?’ | |
1627 | ($?) Expands to the exit status of the most recently executed | |
1628 | command. | |
1629 | ||
1630 | ‘-’ | |
1631 | ($-, a hyphen.) Expands to the current option flags as specified | |
1632 | upon invocation, by the ‘set’ builtin command, or those set by the | |
1633 | shell itself (such as the ‘-i’ option). | |
1634 | ||
1635 | ‘$’ | |
1636 | ($$) Expands to the process ID of the shell. In a subshell, it | |
1637 | expands to the process ID of the invoking shell, not the subshell. | |
1638 | ||
1639 | ‘!’ | |
1640 | ($!) Expands to the process ID of the job most recently placed | |
1641 | into the background, whether executed as an asynchronous command or | |
1642 | using the ‘bg’ builtin (*note Job Control Builtins::). | |
1643 | ||
1644 | ‘0’ | |
1645 | ($0) Expands to the name of the shell or shell script. This is set | |
1646 | at shell initialization. If Bash is invoked with a file of | |
1647 | commands (*note Shell Scripts::), ‘$0’ is set to the name of that | |
1648 | file. If Bash is started with the ‘-c’ option (*note Invoking | |
1649 | Bash::), then ‘$0’ is set to the first argument after the string to | |
1650 | be executed, if one is present. Otherwise, it is set to the | |
1651 | filename used to invoke Bash, as given by argument zero. | |
1652 | ||
1653 | \1f | |
1654 | File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features | |
1655 | ||
1656 | 3.5 Shell Expansions | |
1657 | ==================== | |
1658 | ||
1659 | Expansion is performed on the command line after it has been split into | |
1660 | ‘token’s. Bash performs these expansions: | |
1661 | ||
1662 | • brace expansion | |
1663 | • tilde expansion | |
1664 | • parameter and variable expansion | |
1665 | • command substitution | |
1666 | • arithmetic expansion | |
1667 | • word splitting | |
1668 | • filename expansion | |
1669 | • quote removal | |
1670 | ||
1671 | * Menu: | |
1672 | ||
1673 | * Brace Expansion:: Expansion of expressions within braces. | |
1674 | * Tilde Expansion:: Expansion of the ~ character. | |
1675 | * Shell Parameter Expansion:: How Bash expands variables to their values. | |
1676 | * Command Substitution:: Using the output of a command as an argument. | |
1677 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. | |
1678 | * Process Substitution:: A way to write and read to and from a | |
1679 | command. | |
1680 | * Word Splitting:: How the results of expansion are split into separate | |
1681 | arguments. | |
1682 | * Filename Expansion:: A shorthand for specifying filenames matching patterns. | |
1683 | * Quote Removal:: How and when quote characters are removed from | |
1684 | words. | |
1685 | ||
1686 | The order of expansions is: brace expansion; tilde expansion, | |
1687 | parameter and variable expansion, arithmetic expansion, and command | |
1688 | substitution (done in a left-to-right fashion); word splitting; filename | |
1689 | expansion; and quote removal. | |
1690 | ||
1691 | On systems that can support it, there is an additional expansion | |
1692 | available: “process substitution”. This is performed at the same time | |
1693 | as tilde, parameter, variable, and arithmetic expansion and command | |
1694 | substitution. | |
1695 | ||
1696 | “Quote removal” is always performed last. It removes quote | |
1697 | characters present in the original word, not ones resulting from one of | |
1698 | the other expansions, unless they have been quoted themselves. *Note | |
1699 | Quote Removal:: for more details. | |
1700 | ||
1701 | Only brace expansion, word splitting, and filename expansion can | |
1702 | increase the number of words of the expansion; other expansions expand a | |
1703 | single word to a single word. The only exceptions to this are the | |
1704 | expansions of ‘"$@"’ and ‘$*’ (*note Special Parameters::), and | |
1705 | ‘"${NAME[@]}"’ and ‘${NAME[*]}’ (*note Arrays::). | |
1706 | ||
1707 | \1f | |
1708 | File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions | |
1709 | ||
1710 | 3.5.1 Brace Expansion | |
1711 | --------------------- | |
1712 | ||
1713 | Brace expansion is a mechanism to generate arbitrary strings sharing a | |
1714 | common prefix and suffix, either of which can be empty. This mechanism | |
1715 | is similar to “filename expansion” (*note Filename Expansion::), but the | |
1716 | filenames generated need not exist. Patterns to be brace expanded are | |
1717 | formed from an optional PREAMBLE, followed by either a series of | |
1718 | comma-separated strings or a sequence expression between a pair of | |
1719 | braces, followed by an optional POSTSCRIPT. The preamble is prefixed to | |
1720 | each string contained within the braces, and the postscript is then | |
1721 | appended to each resulting string, expanding left to right. | |
1722 | ||
1723 | Brace expansions may be nested. The results of each expanded string | |
1724 | are not sorted; brace expansion preserves left to right order. For | |
1725 | example, | |
1726 | bash$ echo a{d,c,b}e | |
1727 | ade ace abe | |
1728 | ||
1729 | A sequence expression takes the form ‘X..Y[..INCR]’, where X and Y | |
1730 | are either integers or letters, and INCR, an optional increment, is an | |
1731 | integer. When integers are supplied, the expression expands to each | |
1732 | number between X and Y, inclusive. If either X or Y begins with a zero, | |
1733 | each generated term will contain the same number of digits, zero-padding | |
1734 | where necessary. When letters are supplied, the expression expands to | |
1735 | each character lexicographically between X and Y, inclusive, using the C | |
1736 | locale. Note that both X and Y must be of the same type (integer or | |
1737 | letter). When the increment is supplied, it is used as the difference | |
1738 | between each term. The default increment is 1 or -1 as appropriate. | |
1739 | ||
1740 | Brace expansion is performed before any other expansions, and any | |
1741 | characters special to other expansions are preserved in the result. It | |
1742 | is strictly textual. Bash does not apply any syntactic interpretation | |
1743 | to the context of the expansion or the text between the braces. | |
1744 | ||
1745 | A correctly-formed brace expansion must contain unquoted opening and | |
1746 | closing braces, and at least one unquoted comma or a valid sequence | |
1747 | expression. Any incorrectly formed brace expansion is left unchanged. | |
1748 | ||
1749 | A ‘{’ or ‘,’ may be quoted with a backslash to prevent its being | |
1750 | considered part of a brace expression. To avoid conflicts with | |
1751 | parameter expansion, the string ‘${’ is not considered eligible for | |
1752 | brace expansion, and inhibits brace expansion until the closing ‘}’. | |
1753 | ||
1754 | This construct is typically used as shorthand when the common prefix | |
1755 | of the strings to be generated is longer than in the above example: | |
1756 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
1757 | or | |
1758 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
1759 | ||
1760 | Brace expansion introduces a slight incompatibility with historical | |
1761 | versions of ‘sh’. ‘sh’ does not treat opening or closing braces | |
1762 | specially when they appear as part of a word, and preserves them in the | |
1763 | output. Bash removes braces from words as a consequence of brace | |
1764 | expansion. For example, a word entered to ‘sh’ as ‘file{1,2}’ appears | |
1765 | identically in the output. Bash outputs that word as ‘file1 file2’ | |
1766 | after brace expansion. Start Bash with the ‘+B’ option or disable brace | |
1767 | expansion with the ‘+B’ option to the ‘set’ command (*note Shell Builtin | |
1768 | Commands::) for strict ‘sh’ compatibility. | |
1769 | ||
1770 | \1f | |
1771 | File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions | |
1772 | ||
1773 | 3.5.2 Tilde Expansion | |
1774 | --------------------- | |
1775 | ||
1776 | If a word begins with an unquoted tilde character (‘~’), all of the | |
1777 | characters up to the first unquoted slash (or all characters, if there | |
1778 | is no unquoted slash) are considered a “tilde-prefix”. If none of the | |
1779 | characters in the tilde-prefix are quoted, the characters in the | |
1780 | tilde-prefix following the tilde are treated as a possible “login name”. | |
1781 | If this login name is the null string, the tilde is replaced with the | |
1782 | value of the ‘HOME’ shell variable. If ‘HOME’ is unset, the tilde | |
1783 | expands to the home directory of the user executing the shell instead. | |
1784 | Otherwise, the tilde-prefix is replaced with the home directory | |
1785 | associated with the specified login name. | |
1786 | ||
1787 | If the tilde-prefix is ‘~+’, the value of the shell variable ‘PWD’ | |
1788 | replaces the tilde-prefix. If the tilde-prefix is ‘~-’, the shell | |
1789 | substitutes the value of the shell variable ‘OLDPWD’, if it is set. | |
1790 | ||
1791 | If the characters following the tilde in the tilde-prefix consist of | |
1792 | a number N, optionally prefixed by a ‘+’ or a ‘-’, the tilde-prefix is | |
1793 | replaced with the corresponding element from the directory stack, as it | |
1794 | would be displayed by the ‘dirs’ builtin invoked with the characters | |
1795 | following tilde in the tilde-prefix as an argument (*note The Directory | |
1796 | Stack::). If the tilde-prefix, sans the tilde, consists of a number | |
1797 | without a leading ‘+’ or ‘-’, tilde expansion assumes ‘+’. | |
1798 | ||
1799 | The results of tilde expansion are treated as if they were quoted, so | |
1800 | the replacement is not subject to word splitting and filename expansion. | |
1801 | ||
1802 | If the login name is invalid, or the tilde expansion fails, the | |
1803 | tilde-prefix is left unchanged. | |
1804 | ||
1805 | Bash checks each variable assignment for unquoted tilde-prefixes | |
1806 | immediately following a ‘:’ or the first ‘=’, and performs tilde | |
1807 | expansion in these cases. Consequently, one may use filenames with | |
1808 | tildes in assignments to ‘PATH’, ‘MAILPATH’, and ‘CDPATH’, and the shell | |
1809 | assigns the expanded value. | |
1810 | ||
1811 | The following table shows how Bash treats unquoted tilde-prefixes: | |
1812 | ||
1813 | ‘~’ | |
1814 | The value of ‘$HOME’. | |
1815 | ‘~/foo’ | |
1816 | ‘$HOME/foo’ | |
1817 | ||
1818 | ‘~fred/foo’ | |
1819 | The directory or file ‘foo’ in the home directory of the user | |
1820 | ‘fred’. | |
1821 | ||
1822 | ‘~+/foo’ | |
1823 | ‘$PWD/foo’ | |
1824 | ||
1825 | ‘~-/foo’ | |
1826 | ‘${OLDPWD-'~-'}/foo’ | |
1827 | ||
1828 | ‘~N’ | |
1829 | The string that would be displayed by ‘dirs +N’. | |
1830 | ||
1831 | ‘~+N’ | |
1832 | The string that would be displayed by ‘dirs +N’. | |
1833 | ||
1834 | ‘~-N’ | |
1835 | The string that would be displayed by ‘dirs -N’. | |
1836 | ||
1837 | Bash also performs tilde expansion on words satisfying the conditions | |
1838 | of variable assignments (*note Shell Parameters::) when they appear as | |
1839 | arguments to simple commands. Bash does not do this, except for the | |
1840 | declaration commands listed above, when in POSIX mode. | |
1841 | ||
1842 | \1f | |
1843 | File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions | |
1844 | ||
1845 | 3.5.3 Shell Parameter Expansion | |
1846 | ------------------------------- | |
1847 | ||
1848 | The ‘$’ character introduces parameter expansion, command substitution, | |
1849 | or arithmetic expansion. The parameter name or symbol to be expanded | |
1850 | may be enclosed in braces, which are optional but serve to protect the | |
1851 | variable to be expanded from characters immediately following it which | |
1852 | could be interpreted as part of the name. For example, if the first | |
1853 | positional parameter has the value ‘a’, then ‘${11}’ expands to the | |
1854 | value of the eleventh positional parameter, while ‘$11’ expands to ‘a1’. | |
1855 | ||
1856 | When braces are used, the matching ending brace is the first ‘}’ not | |
1857 | escaped by a backslash or within a quoted string, and not within an | |
1858 | embedded arithmetic expansion, command substitution, or parameter | |
1859 | expansion. | |
1860 | ||
1861 | The basic form of parameter expansion is ${PARAMETER}, which | |
1862 | substitutes the value of PARAMETER. The PARAMETER is a shell parameter | |
1863 | as described above (*note Shell Parameters::) or an array reference | |
1864 | (*note Arrays::). The braces are required when PARAMETER is a | |
1865 | positional parameter with more than one digit, or when PARAMETER is | |
1866 | followed by a character that is not to be interpreted as part of its | |
1867 | name. | |
1868 | ||
1869 | If the first character of PARAMETER is an exclamation point (!), and | |
1870 | PARAMETER is not a nameref, it introduces a level of indirection. Bash | |
1871 | uses the value formed by expanding the rest of PARAMETER as the new | |
1872 | PARAMETER; this new parameter is then expanded and that value is used in | |
1873 | the rest of the expansion, rather than the expansion of the original | |
1874 | PARAMETER. This is known as ‘indirect expansion’. The value is subject | |
1875 | to tilde expansion, parameter expansion, command substitution, and | |
1876 | arithmetic expansion. If PARAMETER is a nameref, this expands to the | |
1877 | name of the variable referenced by PARAMETER instead of performing the | |
1878 | complete indirect expansion, for compatibility. The exceptions to this | |
1879 | are the expansions of ${!PREFIX*} and ${!NAME[@]} described below. The | |
1880 | exclamation point must immediately follow the left brace in order to | |
1881 | introduce indirection. | |
1882 | ||
1883 | In each of the cases below, WORD is subject to tilde expansion, | |
1884 | parameter expansion, command substitution, and arithmetic expansion. | |
1885 | ||
1886 | When not performing substring expansion, using the forms described | |
1887 | below (e.g., ‘:-’), Bash tests for a parameter that is unset or null. | |
1888 | Omitting the colon results in a test only for a parameter that is unset. | |
1889 | Put another way, if the colon is included, the operator tests for both | |
1890 | PARAMETER's existence and that its value is not null; if the colon is | |
1891 | omitted, the operator tests only for existence. | |
1892 | ||
1893 | ‘${PARAMETER:−WORD}’ | |
1894 | If PARAMETER is unset or null, the expansion of WORD is | |
1895 | substituted. Otherwise, the value of PARAMETER is substituted. | |
1896 | ||
1897 | $ v=123 | |
1898 | $ echo ${v-unset} | |
1899 | 123 | |
1900 | $ echo ${v:-unset-or-null} | |
1901 | 123 | |
1902 | $ unset v | |
1903 | $ echo ${v-unset} | |
1904 | unset | |
1905 | $ v= | |
1906 | $ echo ${v-unset} | |
1907 | ||
1908 | $ echo ${v:-unset-or-null} | |
1909 | unset-or-null | |
1910 | ||
1911 | ‘${PARAMETER:=WORD}’ | |
1912 | If PARAMETER is unset or null, the expansion of WORD is assigned to | |
1913 | PARAMETER, and the result of the expansion is the final value of | |
1914 | PARAMETER. Positional parameters and special parameters may not be | |
1915 | assigned in this way. | |
1916 | ||
1917 | $ unset var | |
1918 | $ : ${var=DEFAULT} | |
1919 | $ echo $var | |
1920 | DEFAULT | |
1921 | $ var= | |
1922 | $ : ${var=DEFAULT} | |
1923 | $ echo $var | |
1924 | ||
1925 | $ var= | |
1926 | $ : ${var:=DEFAULT} | |
1927 | $ echo $var | |
1928 | DEFAULT | |
1929 | $ unset var | |
1930 | $ : ${var:=DEFAULT} | |
1931 | $ echo $var | |
1932 | DEFAULT | |
1933 | ||
1934 | ‘${PARAMETER:?WORD}’ | |
1935 | If PARAMETER is null or unset, the shell writes the expansion of | |
1936 | WORD (or a message to that effect if WORD is not present) to the | |
1937 | standard error and, if it is not interactive, exits with a non-zero | |
1938 | status. An interactive shell does not exit, but does not execute | |
1939 | the command associated with the expansion. Otherwise, the value of | |
1940 | PARAMETER is substituted. | |
1941 | ||
1942 | $ var= | |
1943 | $ : ${var:?var is unset or null} | |
1944 | bash: var: var is unset or null | |
1945 | $ echo ${var?var is unset} | |
1946 | ||
1947 | $ unset var | |
1948 | $ : ${var?var is unset} | |
1949 | bash: var: var is unset | |
1950 | $ : ${var:?var is unset or null} | |
1951 | bash: var: var is unset or null | |
1952 | $ var=123 | |
1953 | $ echo ${var:?var is unset or null} | |
1954 | 123 | |
1955 | ||
1956 | ‘${PARAMETER:+WORD}’ | |
1957 | If PARAMETER is null or unset, nothing is substituted, otherwise | |
1958 | the expansion of WORD is substituted. The value of PARAMETER is | |
1959 | not used. | |
1960 | ||
1961 | $ var=123 | |
1962 | $ echo ${var:+var is set and not null} | |
1963 | var is set and not null | |
1964 | $ echo ${var+var is set} | |
1965 | var is set | |
1966 | $ var= | |
1967 | $ echo ${var:+var is set and not null} | |
1968 | ||
1969 | $ echo ${var+var is set} | |
1970 | var is set | |
1971 | $ unset var | |
1972 | $ echo ${var+var is set} | |
1973 | ||
1974 | $ echo ${var:+var is set and not null} | |
1975 | ||
1976 | $ | |
1977 | ||
1978 | ‘${PARAMETER:OFFSET}’ | |
1979 | ‘${PARAMETER:OFFSET:LENGTH}’ | |
1980 | This is referred to as Substring Expansion. It expands to up to | |
1981 | LENGTH characters of the value of PARAMETER starting at the | |
1982 | character specified by OFFSET. If PARAMETER is ‘@’ or ‘*’, an | |
1983 | indexed array subscripted by ‘@’ or ‘*’, or an associative array | |
1984 | name, the results differ as described below. If :LENGTH is omitted | |
1985 | (the first form above), this expands to the substring of the value | |
1986 | of PARAMETER starting at the character specified by OFFSET and | |
1987 | extending to the end of the value. If OFFSET is omitted, it is | |
1988 | treated as 0. If LENGTH is omitted, but the colon after OFFSET is | |
1989 | present, it is treated as 0. LENGTH and OFFSET are arithmetic | |
1990 | expressions (*note Shell Arithmetic::). | |
1991 | ||
1992 | If OFFSET evaluates to a number less than zero, the value is used | |
1993 | as an offset in characters from the end of the value of PARAMETER. | |
1994 | If LENGTH evaluates to a number less than zero, it is interpreted | |
1995 | as an offset in characters from the end of the value of PARAMETER | |
1996 | rather than a number of characters, and the expansion is the | |
1997 | characters between OFFSET and that result. | |
1998 | ||
1999 | Note that a negative offset must be separated from the colon by at | |
2000 | least one space to avoid being confused with the ‘:-’ expansion. | |
2001 | ||
2002 | Here are some examples illustrating substring expansion on | |
2003 | parameters and subscripted arrays: | |
2004 | ||
2005 | $ string=01234567890abcdefgh | |
2006 | $ echo ${string:7} | |
2007 | 7890abcdefgh | |
2008 | $ echo ${string:7:0} | |
2009 | ||
2010 | $ echo ${string:7:2} | |
2011 | 78 | |
2012 | $ echo ${string:7:-2} | |
2013 | 7890abcdef | |
2014 | $ echo ${string: -7} | |
2015 | bcdefgh | |
2016 | $ echo ${string: -7:0} | |
2017 | ||
2018 | $ echo ${string: -7:2} | |
2019 | bc | |
2020 | $ echo ${string: -7:-2} | |
2021 | bcdef | |
2022 | $ set -- 01234567890abcdefgh | |
2023 | $ echo ${1:7} | |
2024 | 7890abcdefgh | |
2025 | $ echo ${1:7:0} | |
2026 | ||
2027 | $ echo ${1:7:2} | |
2028 | 78 | |
2029 | $ echo ${1:7:-2} | |
2030 | 7890abcdef | |
2031 | $ echo ${1: -7} | |
2032 | bcdefgh | |
2033 | $ echo ${1: -7:0} | |
2034 | ||
2035 | $ echo ${1: -7:2} | |
2036 | bc | |
2037 | $ echo ${1: -7:-2} | |
2038 | bcdef | |
2039 | $ array[0]=01234567890abcdefgh | |
2040 | $ echo ${array[0]:7} | |
2041 | 7890abcdefgh | |
2042 | $ echo ${array[0]:7:0} | |
2043 | ||
2044 | $ echo ${array[0]:7:2} | |
2045 | 78 | |
2046 | $ echo ${array[0]:7:-2} | |
2047 | 7890abcdef | |
2048 | $ echo ${array[0]: -7} | |
2049 | bcdefgh | |
2050 | $ echo ${array[0]: -7:0} | |
2051 | ||
2052 | $ echo ${array[0]: -7:2} | |
2053 | bc | |
2054 | $ echo ${array[0]: -7:-2} | |
2055 | bcdef | |
2056 | ||
2057 | If PARAMETER is ‘@’ or ‘*’, the result is LENGTH positional | |
2058 | parameters beginning at OFFSET. A negative OFFSET is taken | |
2059 | relative to one greater than the greatest positional parameter, so | |
2060 | an offset of -1 evaluates to the last positional parameter (or 0 if | |
2061 | there are no positional parameters). It is an expansion error if | |
2062 | LENGTH evaluates to a number less than zero. | |
2063 | ||
2064 | The following examples illustrate substring expansion using | |
2065 | positional parameters: | |
2066 | ||
2067 | $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
2068 | $ echo ${@:7} | |
2069 | 7 8 9 0 a b c d e f g h | |
2070 | $ echo ${@:7:0} | |
2071 | ||
2072 | $ echo ${@:7:2} | |
2073 | 7 8 | |
2074 | $ echo ${@:7:-2} | |
2075 | bash: -2: substring expression < 0 | |
2076 | $ echo ${@: -7:2} | |
2077 | b c | |
2078 | $ echo ${@:0} | |
2079 | ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
2080 | $ echo ${@:0:2} | |
2081 | ./bash 1 | |
2082 | $ echo ${@: -7:0} | |
2083 | ||
2084 | ||
2085 | If PARAMETER is an indexed array name subscripted by ‘@’ or ‘*’, | |
2086 | the result is the LENGTH members of the array beginning with | |
2087 | ‘${PARAMETER[OFFSET]}’. A negative OFFSET is taken relative to one | |
2088 | greater than the maximum index of the specified array. It is an | |
2089 | expansion error if LENGTH evaluates to a number less than zero. | |
2090 | ||
2091 | These examples show how you can use substring expansion with | |
2092 | indexed arrays: | |
2093 | ||
2094 | $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h) | |
2095 | $ echo ${array[@]:7} | |
2096 | 7 8 9 0 a b c d e f g h | |
2097 | $ echo ${array[@]:7:2} | |
2098 | 7 8 | |
2099 | $ echo ${array[@]: -7:2} | |
2100 | b c | |
2101 | $ echo ${array[@]: -7:-2} | |
2102 | bash: -2: substring expression < 0 | |
2103 | $ echo ${array[@]:0} | |
2104 | 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
2105 | $ echo ${array[@]:0:2} | |
2106 | 0 1 | |
2107 | $ echo ${array[@]: -7:0} | |
2108 | ||
2109 | ||
2110 | Substring expansion applied to an associative array produces | |
2111 | undefined results. | |
2112 | ||
2113 | Substring indexing is zero-based unless the positional parameters | |
2114 | are used, in which case the indexing starts at 1 by default. If | |
2115 | OFFSET is 0, and the positional parameters are used, ‘$0’ is | |
2116 | prefixed to the list. | |
2117 | ||
2118 | ‘${!PREFIX*}’ | |
2119 | ‘${!PREFIX@}’ | |
2120 | Expands to the names of variables whose names begin with PREFIX, | |
2121 | separated by the first character of the ‘IFS’ special variable. | |
2122 | When ‘@’ is used and the expansion appears within double quotes, | |
2123 | each variable name expands to a separate word. | |
2124 | ||
2125 | ‘${!NAME[@]}’ | |
2126 | ‘${!NAME[*]}’ | |
2127 | If NAME is an array variable, expands to the list of array indices | |
2128 | (keys) assigned in NAME. If NAME is not an array, expands to 0 if | |
2129 | NAME is set and null otherwise. When ‘@’ is used and the expansion | |
2130 | appears within double quotes, each key expands to a separate word. | |
2131 | ||
2132 | ‘${#PARAMETER}’ | |
2133 | Substitutes the length in characters of the value of PARAMETER. If | |
2134 | PARAMETER is ‘*’ or ‘@’, the value substituted is the number of | |
2135 | positional parameters. If PARAMETER is an array name subscripted | |
2136 | by ‘*’ or ‘@’, the value substituted is the number of elements in | |
2137 | the array. If PARAMETER is an indexed array name subscripted by a | |
2138 | negative number, that number is interpreted as relative to one | |
2139 | greater than the maximum index of PARAMETER, so negative indices | |
2140 | count back from the end of the array, and an index of -1 references | |
2141 | the last element. | |
2142 | ||
2143 | ‘${PARAMETER#WORD}’ | |
2144 | ‘${PARAMETER##WORD}’ | |
2145 | The WORD is expanded to produce a pattern and matched against the | |
2146 | expanded value of PARAMETER according to the rules described below | |
2147 | (*note Pattern Matching::). If the pattern matches the beginning | |
2148 | of the expanded value of PARAMETER, then the result of the | |
2149 | expansion is the expanded value of PARAMETER with the shortest | |
2150 | matching pattern (the ‘#’ case) or the longest matching pattern | |
2151 | (the ‘##’ case) deleted. If PARAMETER is ‘@’ or ‘*’, the pattern | |
2152 | removal operation is applied to each positional parameter in turn, | |
2153 | and the expansion is the resultant list. If PARAMETER is an array | |
2154 | variable subscripted with ‘@’ or ‘*’, the pattern removal operation | |
2155 | is applied to each member of the array in turn, and the expansion | |
2156 | is the resultant list. | |
2157 | ||
2158 | ‘${PARAMETER%WORD}’ | |
2159 | ‘${PARAMETER%%WORD}’ | |
2160 | The WORD is expanded to produce a pattern and matched against the | |
2161 | expanded value of PARAMETER according to the rules described below | |
2162 | (*note Pattern Matching::). If the pattern matches a trailing | |
2163 | portion of the expanded value of PARAMETER, then the result of the | |
2164 | expansion is the value of PARAMETER with the shortest matching | |
2165 | pattern (the ‘%’ case) or the longest matching pattern (the ‘%%’ | |
2166 | case) deleted. If PARAMETER is ‘@’ or ‘*’, the pattern removal | |
2167 | operation is applied to each positional parameter in turn, and the | |
2168 | expansion is the resultant list. If PARAMETER is an array variable | |
2169 | subscripted with ‘@’ or ‘*’, the pattern removal operation is | |
2170 | applied to each member of the array in turn, and the expansion is | |
2171 | the resultant list. | |
2172 | ||
2173 | ‘${PARAMETER/PATTERN/STRING}’ | |
2174 | ‘${PARAMETER//PATTERN/STRING}’ | |
2175 | ‘${PARAMETER/#PATTERN/STRING}’ | |
2176 | ‘${PARAMETER/%PATTERN/STRING}’ | |
2177 | The PATTERN is expanded to produce a pattern and matched against | |
2178 | the expanded value of PARAMETER as described below (*note Pattern | |
2179 | Matching::). The longest match of PATTERN in the expanded value is | |
2180 | replaced with STRING. STRING undergoes tilde expansion, parameter | |
2181 | and variable expansion, arithmetic expansion, command and process | |
2182 | substitution, and quote removal. | |
2183 | ||
2184 | In the first form above, only the first match is replaced. If | |
2185 | there are two slashes separating PARAMETER and PATTERN (the second | |
2186 | form above), all matches of PATTERN are replaced with STRING. If | |
2187 | PATTERN is preceded by ‘#’ (the third form above), it must match at | |
2188 | the beginning of the expanded value of PARAMETER. If PATTERN is | |
2189 | preceded by ‘%’ (the fourth form above), it must match at the end | |
2190 | of the expanded value of PARAMETER. | |
2191 | ||
2192 | If the expansion of STRING is null, matches of PATTERN are deleted | |
2193 | and the ‘/’ following PATTERN may be omitted. | |
2194 | ||
2195 | If the ‘patsub_replacement’ shell option is enabled using ‘shopt’ | |
2196 | (*note The Shopt Builtin::), any unquoted instances of ‘&’ in | |
2197 | STRING are replaced with the matching portion of PATTERN. This is | |
2198 | intended to duplicate a common ‘sed’ idiom. | |
2199 | ||
2200 | Quoting any part of STRING inhibits replacement in the expansion of | |
2201 | the quoted portion, including replacement strings stored in shell | |
2202 | variables. Backslash escapes ‘&’ in STRING; the backslash is | |
2203 | removed in order to permit a literal ‘&’ in the replacement string. | |
2204 | Users should take care if STRING is double-quoted to avoid unwanted | |
2205 | interactions between the backslash and double-quoting, since | |
2206 | backslash has special meaning within double quotes. Pattern | |
2207 | substitution performs the check for unquoted ‘&’ after expanding | |
2208 | STRING, so users should ensure to properly quote any occurrences of | |
2209 | ‘&’ they want to be taken literally in the replacement and ensure | |
2210 | any instances of ‘&’ they want to be replaced are unquoted. | |
2211 | ||
2212 | For instance, | |
2213 | ||
2214 | var=abcdef | |
2215 | rep='& ' | |
2216 | echo ${var/abc/& } | |
2217 | echo "${var/abc/& }" | |
2218 | echo ${var/abc/$rep} | |
2219 | echo "${var/abc/$rep}" | |
2220 | ||
2221 | will display four lines of "abc def", while | |
2222 | ||
2223 | var=abcdef | |
2224 | rep='& ' | |
2225 | echo ${var/abc/\& } | |
2226 | echo "${var/abc/\& }" | |
2227 | echo ${var/abc/"& "} | |
2228 | echo ${var/abc/"$rep"} | |
2229 | ||
2230 | will display four lines of "& def". Like the pattern removal | |
2231 | operators, double quotes surrounding the replacement string quote | |
2232 | the expanded characters, while double quotes enclosing the entire | |
2233 | parameter substitution do not, since the expansion is performed in | |
2234 | a context that doesn't take any enclosing double quotes into | |
2235 | account. | |
2236 | ||
2237 | Since backslash can escape ‘&’, it can also escape a backslash in | |
2238 | the replacement string. This means that ‘\\’ will insert a literal | |
2239 | backslash into the replacement, so these two ‘echo’ commands | |
2240 | ||
2241 | var=abcdef | |
2242 | rep='\\&xyz' | |
2243 | echo ${var/abc/\\&xyz} | |
2244 | echo ${var/abc/$rep} | |
2245 | ||
2246 | will both output ‘\abcxyzdef’. | |
2247 | ||
2248 | It should rarely be necessary to enclose only STRING in double | |
2249 | quotes. | |
2250 | ||
2251 | If the ‘nocasematch’ shell option (see the description of ‘shopt’ | |
2252 | in *note The Shopt Builtin::) is enabled, the match is performed | |
2253 | without regard to the case of alphabetic characters. | |
2254 | ||
2255 | If PARAMETER is ‘@’ or ‘*’, the substitution operation is applied | |
2256 | to each positional parameter in turn, and the expansion is the | |
2257 | resultant list. If PARAMETER is an array variable subscripted with | |
2258 | ‘@’ or ‘*’, the substitution operation is applied to each member of | |
2259 | the array in turn, and the expansion is the resultant list. | |
2260 | ||
2261 | ‘${PARAMETER^PATTERN}’ | |
2262 | ‘${PARAMETER^^PATTERN}’ | |
2263 | ‘${PARAMETER,PATTERN}’ | |
2264 | ‘${PARAMETER,,PATTERN}’ | |
2265 | This expansion modifies the case of alphabetic characters in | |
2266 | PARAMETER. First, the PATTERN is expanded to produce a pattern as | |
2267 | described below in *note Pattern Matching::. | |
2268 | ||
2269 | ‘Bash’ then examines characters in the expanded value of PARAMETER | |
2270 | against PATTERN as described below. If a character matches the | |
2271 | pattern, its case is converted. The pattern should not attempt to | |
2272 | match more than one character. | |
2273 | ||
2274 | Using ‘^’ converts lowercase letters matching PATTERN to uppercase; | |
2275 | ‘,’ converts matching uppercase letters to lowercase. The ‘^’ and | |
2276 | ‘,’ variants examine the first character in the expanded value and | |
2277 | convert its case if it matches PATTERN; the ‘^^’ and ‘,,’ variants | |
2278 | examine all characters in the expanded value and convert each one | |
2279 | that matches PATTERN. If PATTERN is omitted, it is treated like a | |
2280 | ‘?’, which matches every character. | |
2281 | ||
2282 | If PARAMETER is ‘@’ or ‘*’, the case modification operation is | |
2283 | applied to each positional parameter in turn, and the expansion is | |
2284 | the resultant list. If PARAMETER is an array variable subscripted | |
2285 | with ‘@’ or ‘*’, the case modification operation is applied to each | |
2286 | member of the array in turn, and the expansion is the resultant | |
2287 | list. | |
2288 | ||
2289 | ‘${PARAMETER@OPERATOR}’ | |
2290 | The expansion is either a transformation of the value of PARAMETER | |
2291 | or information about PARAMETER itself, depending on the value of | |
2292 | OPERATOR. Each OPERATOR is a single letter: | |
2293 | ||
2294 | ‘U’ | |
2295 | The expansion is a string that is the value of PARAMETER with | |
2296 | lowercase alphabetic characters converted to uppercase. | |
2297 | ‘u’ | |
2298 | The expansion is a string that is the value of PARAMETER with | |
2299 | the first character converted to uppercase, if it is | |
2300 | alphabetic. | |
2301 | ‘L’ | |
2302 | The expansion is a string that is the value of PARAMETER with | |
2303 | uppercase alphabetic characters converted to lowercase. | |
2304 | ‘Q’ | |
2305 | The expansion is a string that is the value of PARAMETER | |
2306 | quoted in a format that can be reused as input. | |
2307 | ‘E’ | |
2308 | The expansion is a string that is the value of PARAMETER with | |
2309 | backslash escape sequences expanded as with the ‘$'...'’ | |
2310 | quoting mechanism. | |
2311 | ‘P’ | |
2312 | The expansion is a string that is the result of expanding the | |
2313 | value of PARAMETER as if it were a prompt string (*note | |
2314 | Controlling the Prompt::). | |
2315 | ‘A’ | |
2316 | The expansion is a string in the form of an assignment | |
2317 | statement or ‘declare’ command that, if evaluated, recreates | |
2318 | PARAMETER with its attributes and value. | |
2319 | ‘K’ | |
2320 | Produces a possibly-quoted version of the value of PARAMETER, | |
2321 | except that it prints the values of indexed and associative | |
2322 | arrays as a sequence of quoted key-value pairs (*note | |
2323 | Arrays::). The keys and values are quoted in a format that | |
2324 | can be reused as input. | |
2325 | ‘a’ | |
2326 | The expansion is a string consisting of flag values | |
2327 | representing PARAMETER's attributes. | |
2328 | ‘k’ | |
2329 | Like the ‘K’ transformation, but expands the keys and values | |
2330 | of indexed and associative arrays to separate words after word | |
2331 | splitting. | |
2332 | ||
2333 | If PARAMETER is ‘@’ or ‘*’, the operation is applied to each | |
2334 | positional parameter in turn, and the expansion is the resultant | |
2335 | list. If PARAMETER is an array variable subscripted with ‘@’ or | |
2336 | ‘*’, the operation is applied to each member of the array in turn, | |
2337 | and the expansion is the resultant list. | |
2338 | ||
2339 | The result of the expansion is subject to word splitting and | |
2340 | filename expansion as described below. | |
2341 | ||
2342 | \1f | |
2343 | File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions | |
2344 | ||
2345 | 3.5.4 Command Substitution | |
2346 | -------------------------- | |
2347 | ||
2348 | Command substitution allows the output of a command to replace the | |
2349 | command itself. The standard form of command substitution occurs when a | |
2350 | command is enclosed as follows: | |
2351 | $(COMMAND) | |
2352 | or (deprecated) | |
2353 | `COMMAND`. | |
2354 | ||
2355 | Bash performs command substitution by executing COMMAND in a subshell | |
2356 | environment and replacing the command substitution with the standard | |
2357 | output of the command, with any trailing newlines deleted. Embedded | |
2358 | newlines are not deleted, but they may be removed during word splitting. | |
2359 | The command substitution ‘$(cat FILE)’ can be replaced by the equivalent | |
2360 | but faster ‘$(< FILE)’. | |
2361 | ||
2362 | With the old-style backquote form of substitution, backslash retains | |
2363 | its literal meaning except when followed by ‘$’, ‘`’, or ‘\’. The first | |
2364 | backquote not preceded by a backslash terminates the command | |
2365 | substitution. When using the ‘$(COMMAND)’ form, all characters between | |
2366 | the parentheses make up the command; none are treated specially. | |
2367 | ||
2368 | There is an alternate form of command substitution: | |
2369 | ||
2370 | ${C COMMAND; } | |
2371 | ||
2372 | which executes COMMAND in the current execution environment and captures | |
2373 | its output, again with trailing newlines removed. | |
2374 | ||
2375 | The character C following the open brace must be a space, tab, | |
2376 | newline, or ‘|’, and the close brace must be in a position where a | |
2377 | reserved word may appear (i.e., preceded by a command terminator such as | |
2378 | semicolon). Bash allows the close brace to be joined to the remaining | |
2379 | characters in the word without being followed by a shell metacharacter | |
2380 | as a reserved word would usually require. | |
2381 | ||
2382 | Any side effects of COMMAND take effect immediately in the current | |
2383 | execution environment and persist in the current environment after the | |
2384 | command completes (e.g., the ‘exit’ builtin exits the shell). | |
2385 | ||
2386 | This type of command substitution superficially resembles executing | |
2387 | an unnamed shell function: local variables are created as when a shell | |
2388 | function is executing, and the ‘return’ builtin forces COMMAND to | |
2389 | complete; however, the rest of the execution environment, including the | |
2390 | positional parameters, is shared with the caller. | |
2391 | ||
2392 | If the first character following the open brace is a ‘|’, the | |
2393 | construct expands to the value of the ‘REPLY’ shell variable after | |
2394 | COMMAND executes, without removing any trailing newlines, and the | |
2395 | standard output of COMMAND remains the same as in the calling shell. | |
2396 | Bash creates ‘REPLY’ as an initially-unset local variable when COMMAND | |
2397 | executes, and restores ‘REPLY’ to the value it had before the command | |
2398 | substitution after COMMAND completes, as with any local variable. | |
2399 | ||
2400 | For example, this construct expands to ‘12345’, and leaves the shell | |
2401 | variable ‘X’ unchanged in the current execution environment: | |
2402 | ||
2403 | ||
2404 | ${ local X=12345 ; echo $X; } | |
2405 | ||
2406 | (not declaring ‘X’ as local would modify its value in the current | |
2407 | environment, as with normal shell function execution), while this | |
2408 | construct does not require any output to expand to ‘12345’: | |
2409 | ||
2410 | ${| REPLY=12345; } | |
2411 | ||
2412 | and restores ‘REPLY’ to the value it had before the command | |
2413 | substitution. | |
2414 | ||
2415 | Command substitutions may be nested. To nest when using the | |
2416 | backquoted form, escape the inner backquotes with backslashes. | |
2417 | ||
2418 | If the substitution appears within double quotes, Bash does not | |
2419 | perform word splitting and filename expansion on the results. | |
2420 | ||
2421 | \1f | |
2422 | File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions | |
2423 | ||
2424 | 3.5.5 Arithmetic Expansion | |
2425 | -------------------------- | |
2426 | ||
2427 | Arithmetic expansion evaluates an arithmetic expression and substitutes | |
2428 | the result. The format for arithmetic expansion is: | |
2429 | ||
2430 | $(( EXPRESSION )) | |
2431 | ||
2432 | The EXPRESSION undergoes the same expansions as if it were within | |
2433 | double quotes, but unescaped double quote characters in EXPRESSION are | |
2434 | not treated specially and are removed. All tokens in the expression | |
2435 | undergo parameter and variable expansion, command substitution, and | |
2436 | quote removal. The result is treated as the arithmetic expression to be | |
2437 | evaluated. Since the way Bash handles double quotes can potentially | |
2438 | result in empty strings, arithmetic expansion treats those as | |
2439 | expressions that evaluate to 0. Arithmetic expansions may be nested. | |
2440 | ||
2441 | The evaluation is performed according to the rules listed below | |
2442 | (*note Shell Arithmetic::). If the expression is invalid, Bash prints a | |
2443 | message indicating failure to the standard error, does not perform the | |
2444 | substitution, and does not execute the command associated with the | |
2445 | expansion. | |
2446 | ||
2447 | \1f | |
2448 | File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions | |
2449 | ||
2450 | 3.5.6 Process Substitution | |
2451 | -------------------------- | |
2452 | ||
2453 | Process substitution allows a process's input or output to be referred | |
2454 | to using a filename. It takes the form of | |
2455 | <(LIST) | |
2456 | or | |
2457 | >(LIST) | |
2458 | The process LIST is run asynchronously, and its input or output appears | |
2459 | as a filename. This filename is passed as an argument to the current | |
2460 | command as the result of the expansion. | |
2461 | ||
2462 | If the ‘>(LIST)’ form is used, writing to the file provides input for | |
2463 | LIST. If the ‘<(LIST)’ form is used, reading the file obtains the | |
2464 | output of LIST. Note that no space may appear between the ‘<’ or ‘>’ | |
2465 | and the left parenthesis, otherwise the construct would be interpreted | |
2466 | as a redirection. | |
2467 | ||
2468 | Process substitution is supported on systems that support named pipes | |
2469 | (FIFOs) or the ‘/dev/fd’ method of naming open files. | |
2470 | ||
2471 | When available, process substitution is performed simultaneously with | |
2472 | parameter and variable expansion, command substitution, and arithmetic | |
2473 | expansion. | |
2474 | ||
2475 | \1f | |
2476 | File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions | |
2477 | ||
2478 | 3.5.7 Word Splitting | |
2479 | -------------------- | |
2480 | ||
2481 | The shell scans the results of parameter expansion, command | |
2482 | substitution, and arithmetic expansion that did not occur within double | |
2483 | quotes for word splitting. Words that were not expanded are not split. | |
2484 | ||
2485 | The shell treats each character of ‘$IFS’ as a delimiter, and splits | |
2486 | the results of the other expansions into fields using these characters | |
2487 | as field terminators. | |
2488 | ||
2489 | An “IFS whitespace” character is whitespace as defined above (*note | |
2490 | Definitions::) that appears in the value of ‘IFS’. Space, tab, and | |
2491 | newline are always considered IFS whitespace, even if they don't appear | |
2492 | in the locale's ‘space’ category. | |
2493 | ||
2494 | If ‘IFS’ is unset, word splitting behaves as if its value were | |
2495 | ‘<space><tab><newline>’, and treats these characters as IFS whitespace. | |
2496 | If the value of ‘IFS’ is null, no word splitting occurs, but implicit | |
2497 | null arguments (see below) are still removed. | |
2498 | ||
2499 | Word splitting begins by removing sequences of IFS whitespace | |
2500 | characters from the beginning and end of the results of the previous | |
2501 | expansions, then splits the remaining words. | |
2502 | ||
2503 | If the value of ‘IFS’ consists solely of IFS whitespace, any sequence | |
2504 | of IFS whitespace characters delimits a field, so a field consists of | |
2505 | characters that are not unquoted IFS whitespace, and null fields result | |
2506 | only from quoting. | |
2507 | ||
2508 | If ‘IFS’ contains a non-whitespace character, then any character in | |
2509 | the value of ‘IFS’ that is not IFS whitespace, along with any adjacent | |
2510 | IFS whitespace characters, delimits a field. This means that adjacent | |
2511 | non-IFS-whitespace delimiters produce a null field. A sequence of IFS | |
2512 | whitespace characters also delimits a field. | |
2513 | ||
2514 | Explicit null arguments (‘""’ or ‘''’) are retained and passed to | |
2515 | commands as empty strings. Unquoted implicit null arguments, resulting | |
2516 | from the expansion of parameters that have no values, are removed. | |
2517 | Expanding a parameter with no value within double quotes produces a null | |
2518 | field, which is retained and passed to a command as an empty string. | |
2519 | ||
2520 | When a quoted null argument appears as part of a word whose expansion | |
2521 | is non-null, word splitting removes the null argument portion, leaving | |
2522 | the non-null expansion. That is, the word ‘-d''’ becomes ‘-d’ after | |
2523 | word splitting and null argument removal. | |
2524 | ||
2525 | \1f | |
2526 | File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions | |
2527 | ||
2528 | 3.5.8 Filename Expansion | |
2529 | ------------------------ | |
2530 | ||
2531 | * Menu: | |
2532 | ||
2533 | * Pattern Matching:: How the shell matches patterns. | |
2534 | ||
2535 | After word splitting, unless the ‘-f’ option has been set (*note The Set | |
2536 | Builtin::), Bash scans each word for the characters ‘*’, ‘?’, and ‘[’. | |
2537 | If one of these characters appears, and is not quoted, then the word is | |
2538 | regarded as a PATTERN, and replaced with a sorted list of filenames | |
2539 | matching the pattern (*note Pattern Matching::), subject to the value of | |
2540 | the ‘GLOBSORT’ shell variable (*note Bash Variables::). | |
2541 | ||
2542 | If no matching filenames are found, and the shell option ‘nullglob’ | |
2543 | is disabled, the word is left unchanged. If the ‘nullglob’ option is | |
2544 | set, and no matches are found, the word is removed. If the ‘failglob’ | |
2545 | shell option is set, and no matches are found, Bash prints an error | |
2546 | message and does not execute the command. If the shell option | |
2547 | ‘nocaseglob’ is enabled, the match is performed without regard to the | |
2548 | case of alphabetic characters. | |
2549 | ||
2550 | When a pattern is used for filename expansion, the character ‘.’ at | |
2551 | the start of a filename or immediately following a slash must be matched | |
2552 | explicitly, unless the shell option ‘dotglob’ is set. In order to match | |
2553 | the filenames ‘.’ and ‘..’, the pattern must begin with ‘.’ (for | |
2554 | example, ‘.?’), even if ‘dotglob’ is set. If the ‘globskipdots’ shell | |
2555 | option is enabled, the filenames ‘.’ and ‘..’ never match, even if the | |
2556 | pattern begins with a ‘.’. When not matching filenames, the ‘.’ | |
2557 | character is not treated specially. | |
2558 | ||
2559 | When matching a filename, the slash character must always be matched | |
2560 | explicitly by a slash in the pattern, but in other matching contexts it | |
2561 | can be matched by a special pattern character as described below (*note | |
2562 | Pattern Matching::). | |
2563 | ||
2564 | See the description of ‘shopt’ in *note The Shopt Builtin::, for a | |
2565 | description of the ‘nocaseglob’, ‘nullglob’, ‘globskipdots’, ‘failglob’, | |
2566 | and ‘dotglob’ options. | |
2567 | ||
2568 | The ‘GLOBIGNORE’ shell variable may be used to restrict the set of | |
2569 | file names matching a pattern. If ‘GLOBIGNORE’ is set, each matching | |
2570 | file name that also matches one of the patterns in ‘GLOBIGNORE’ is | |
2571 | removed from the list of matches. If the ‘nocaseglob’ option is set, | |
2572 | the matching against the patterns in ‘GLOBIGNORE’ is performed without | |
2573 | regard to case. The filenames ‘.’ and ‘..’ are always ignored when | |
2574 | ‘GLOBIGNORE’ is set and not null. However, setting ‘GLOBIGNORE’ to a | |
2575 | non-null value has the effect of enabling the ‘dotglob’ shell option, so | |
2576 | all other filenames beginning with a ‘.’ match. To get the old behavior | |
2577 | of ignoring filenames beginning with a ‘.’, make ‘.*’ one of the | |
2578 | patterns in ‘GLOBIGNORE’. The ‘dotglob’ option is disabled when | |
2579 | ‘GLOBIGNORE’ is unset. The ‘GLOBIGNORE’ pattern matching honors the | |
2580 | setting of the ‘extglob’ shell option. | |
2581 | ||
2582 | The value of the ‘GLOBSORT’ shell variable controls how the results | |
2583 | of pathname expansion are sorted, as described below (*note Bash | |
2584 | Variables::). | |
2585 | ||
2586 | \1f | |
2587 | File: bashref.info, Node: Pattern Matching, Up: Filename Expansion | |
2588 | ||
2589 | 3.5.8.1 Pattern Matching | |
2590 | ........................ | |
2591 | ||
2592 | Any character that appears in a pattern, other than the special pattern | |
2593 | characters described below, matches itself. The NUL character may not | |
2594 | occur in a pattern. A backslash escapes the following character; the | |
2595 | escaping backslash is discarded when matching. The special pattern | |
2596 | characters must be quoted if they are to be matched literally. | |
2597 | ||
2598 | The special pattern characters have the following meanings: | |
2599 | ‘*’ | |
2600 | Matches any string, including the null string. When the ‘globstar’ | |
2601 | shell option is enabled, and ‘*’ is used in a filename expansion | |
2602 | context, two adjacent ‘*’s used as a single pattern match all files | |
2603 | and zero or more directories and subdirectories. If followed by a | |
2604 | ‘/’, two adjacent ‘*’s match only directories and subdirectories. | |
2605 | ‘?’ | |
2606 | Matches any single character. | |
2607 | ‘[...]’ | |
2608 | Matches any one of the characters enclosed between the brackets. | |
2609 | This is known as a “bracket expression” and matches a single | |
2610 | character. A pair of characters separated by a hyphen denotes a | |
2611 | “range expression”; any character that falls between those two | |
2612 | characters, inclusive, using the current locale's collating | |
2613 | sequence and character set, matches. If the first character | |
2614 | following the ‘[’ is a ‘!’ or a ‘^’ then any character not within | |
2615 | the range matches. To match a ‘−’, include it as the first or last | |
2616 | character in the set. To match a ‘]’, include it as the first | |
2617 | character in the set. | |
2618 | ||
2619 | The sorting order of characters in range expressions, and the | |
2620 | characters included in the range, are determined by the current | |
2621 | locale and the values of the ‘LC_COLLATE’ and ‘LC_ALL’ shell | |
2622 | variables, if set. | |
2623 | ||
2624 | For example, in the default C locale, ‘[a-dx-z]’ is equivalent to | |
2625 | ‘[abcdxyz]’. Many locales sort characters in dictionary order, and | |
2626 | in these locales ‘[a-dx-z]’ is typically not equivalent to | |
2627 | ‘[abcdxyz]’; it might be equivalent to ‘[aBbCcDdxYyZz]’, for | |
2628 | example. To obtain the traditional interpretation of ranges in | |
2629 | bracket expressions, you can force the use of the C locale by | |
2630 | setting the ‘LC_COLLATE’ or ‘LC_ALL’ environment variable to the | |
2631 | value ‘C’, or enable the ‘globasciiranges’ shell option. | |
2632 | ||
2633 | Within a bracket expression, “character classes” can be specified | |
2634 | using the syntax ‘[:’CLASS‘:]’, where CLASS is one of the following | |
2635 | classes defined in the POSIX standard: | |
2636 | alnum alpha ascii blank cntrl digit graph lower | |
2637 | print punct space upper word xdigit | |
2638 | A character class matches any character belonging to that class. | |
2639 | The ‘word’ character class matches letters, digits, and the | |
2640 | character ‘_’. | |
2641 | ||
2642 | For instance, the following pattern will match any character | |
2643 | belonging to the ‘space’ character class in the current locale, | |
2644 | then any upper case letter or ‘!’, a dot, and finally any lower | |
2645 | case letter or a hyphen. | |
2646 | ||
2647 | [[:space:]][[:upper:]!].[-[:lower:]] | |
2648 | ||
2649 | Within a bracket expression, an “equivalence class” can be | |
2650 | specified using the syntax ‘[=’C‘=]’, which matches all characters | |
2651 | with the same collation weight (as defined by the current locale) | |
2652 | as the character C. | |
2653 | ||
2654 | Within a bracket expression, the syntax ‘[.’SYMBOL‘.]’ matches the | |
2655 | collating symbol SYMBOL. | |
2656 | ||
2657 | If the ‘extglob’ shell option is enabled using the ‘shopt’ builtin, | |
2658 | the shell recognizes several extended pattern matching operators. In | |
2659 | the following description, a PATTERN-LIST is a list of one or more | |
2660 | patterns separated by a ‘|’. When matching filenames, the ‘dotglob’ | |
2661 | shell option determines the set of filenames that are tested, as | |
2662 | described above. Composite patterns may be formed using one or more of | |
2663 | the following sub-patterns: | |
2664 | ||
2665 | ‘?(PATTERN-LIST)’ | |
2666 | Matches zero or one occurrence of the given patterns. | |
2667 | ||
2668 | ‘*(PATTERN-LIST)’ | |
2669 | Matches zero or more occurrences of the given patterns. | |
2670 | ||
2671 | ‘+(PATTERN-LIST)’ | |
2672 | Matches one or more occurrences of the given patterns. | |
2673 | ||
2674 | ‘@(PATTERN-LIST)’ | |
2675 | Matches one of the given patterns. | |
2676 | ||
2677 | ‘!(PATTERN-LIST)’ | |
2678 | Matches anything except one of the given patterns. | |
2679 | ||
2680 | The ‘extglob’ option changes the behavior of the parser, since the | |
2681 | parentheses are normally treated as operators with syntactic meaning. | |
2682 | To ensure that extended matching patterns are parsed correctly, make | |
2683 | sure that ‘extglob’ is enabled before parsing constructs containing the | |
2684 | patterns, including shell functions and command substitutions. | |
2685 | ||
2686 | When matching filenames, the ‘dotglob’ shell option determines the | |
2687 | set of filenames that are tested: when ‘dotglob’ is enabled, the set of | |
2688 | filenames includes all files beginning with ‘.’, but the filenames ‘.’ | |
2689 | and ‘..’ must be matched by a pattern or sub-pattern that begins with a | |
2690 | dot; when it is disabled, the set does not include any filenames | |
2691 | beginning with ‘.’ unless the pattern or sub-pattern begins with a ‘.’. | |
2692 | If the ‘globskipdots’ shell option is enabled, the filenames ‘.’ and | |
2693 | ‘..’ never appear in the set. As above, ‘.’ only has a special meaning | |
2694 | when matching filenames. | |
2695 | ||
2696 | Complicated extended pattern matching against long strings is slow, | |
2697 | especially when the patterns contain alternations and the strings | |
2698 | contain multiple matches. Using separate matches against shorter | |
2699 | strings, or using arrays of strings instead of a single long string, may | |
2700 | be faster. | |
2701 | ||
2702 | \1f | |
2703 | File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions | |
2704 | ||
2705 | 3.5.9 Quote Removal | |
2706 | ------------------- | |
2707 | ||
2708 | After the preceding expansions, all unquoted occurrences of the | |
2709 | characters ‘\’, ‘'’, and ‘"’ that did not result from one of the above | |
2710 | expansions are removed. | |
2711 | ||
2712 | \1f | |
2713 | File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features | |
2714 | ||
2715 | 3.6 Redirections | |
2716 | ================ | |
2717 | ||
2718 | Before a command is executed, its input and output may be “redirected” | |
2719 | using a special notation interpreted by the shell. “Redirection” allows | |
2720 | commands' file handles to be duplicated, opened, closed, made to refer | |
2721 | to different files, and can change the files the command reads from and | |
2722 | writes to. When used with the ‘exec’ builtin, redirections modify file | |
2723 | handles in the current shell execution environment. The following | |
2724 | redirection operators may precede or appear anywhere within a simple | |
2725 | command or may follow a command. Redirections are processed in the | |
2726 | order they appear, from left to right. | |
2727 | ||
2728 | Each redirection that may be preceded by a file descriptor number may | |
2729 | instead be preceded by a word of the form {VARNAME}. In this case, for | |
2730 | each redirection operator except ‘>&-’ and ‘<&-’, the shell allocates a | |
2731 | file descriptor greater than or equal to 10 and assigns it to {VARNAME}. | |
2732 | If {VARNAME} precedes ‘>&-’ or ‘<&-’, the value of VARNAME defines the | |
2733 | file descriptor to close. If {VARNAME} is supplied, the redirection | |
2734 | persists beyond the scope of the command, which allows the shell | |
2735 | programmer to manage the file descriptor's lifetime manually without | |
2736 | using the ‘exec’ builtin. The ‘varredir_close’ shell option manages | |
2737 | this behavior (*note The Shopt Builtin::). | |
2738 | ||
2739 | In the following descriptions, if the file descriptor number is | |
2740 | omitted, and the first character of the redirection operator is ‘<’, the | |
2741 | redirection refers to the standard input (file descriptor 0). If the | |
2742 | first character of the redirection operator is ‘>’, the redirection | |
2743 | refers to the standard output (file descriptor 1). | |
2744 | ||
2745 | The WORD following the redirection operator in the following | |
2746 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
2747 | tilde expansion, parameter and variable expansion, command substitution, | |
2748 | arithmetic expansion, quote removal, filename expansion, and word | |
2749 | splitting. If it expands to more than one word, Bash reports an error. | |
2750 | ||
2751 | The order of redirections is significant. For example, the command | |
2752 | ls > DIRLIST 2>&1 | |
2753 | directs both standard output (file descriptor 1) and standard error | |
2754 | (file descriptor 2) to the file DIRLIST, while the command | |
2755 | ls 2>&1 > DIRLIST | |
2756 | directs only the standard output to file DIRLIST, because the standard | |
2757 | error was made a copy of the standard output before the standard output | |
2758 | was redirected to DIRLIST. | |
2759 | ||
2760 | Bash handles several filenames specially when they are used in | |
2761 | redirections, as described in the following table. If the operating | |
2762 | system on which Bash is running provides these special files, Bash uses | |
2763 | them; otherwise it emulates them internally with the behavior described | |
2764 | below. | |
2765 | ||
2766 | ‘/dev/fd/FD’ | |
2767 | If FD is a valid integer, duplicate file descriptor FD. | |
2768 | ||
2769 | ‘/dev/stdin’ | |
2770 | File descriptor 0 is duplicated. | |
2771 | ||
2772 | ‘/dev/stdout’ | |
2773 | File descriptor 1 is duplicated. | |
2774 | ||
2775 | ‘/dev/stderr’ | |
2776 | File descriptor 2 is duplicated. | |
2777 | ||
2778 | ‘/dev/tcp/HOST/PORT’ | |
2779 | If HOST is a valid hostname or Internet address, and PORT is an | |
2780 | integer port number or service name, Bash attempts to open the | |
2781 | corresponding TCP socket. | |
2782 | ||
2783 | ‘/dev/udp/HOST/PORT’ | |
2784 | If HOST is a valid hostname or Internet address, and PORT is an | |
2785 | integer port number or service name, Bash attempts to open the | |
2786 | corresponding UDP socket. | |
2787 | ||
2788 | A failure to open or create a file causes the redirection to fail. | |
2789 | ||
2790 | Redirections using file descriptors greater than 9 should be used | |
2791 | with care, as they may conflict with file descriptors the shell uses | |
2792 | internally. | |
2793 | ||
2794 | 3.6.1 Redirecting Input | |
2795 | ----------------------- | |
2796 | ||
2797 | Redirecting input opens the file whose name results from the expansion | |
2798 | of WORD for reading on file descriptor ‘n’, or the standard input (file | |
2799 | descriptor 0) if ‘n’ is not specified. | |
2800 | ||
2801 | The general format for redirecting input is: | |
2802 | [N]<WORD | |
2803 | ||
2804 | 3.6.2 Redirecting Output | |
2805 | ------------------------ | |
2806 | ||
2807 | Redirecting output opens the file whose name results from the expansion | |
2808 | of WORD for writing on file descriptor N, or the standard output (file | |
2809 | descriptor 1) if N is not specified. If the file does not exist it is | |
2810 | created; if it does exist it is truncated to zero size. | |
2811 | ||
2812 | The general format for redirecting output is: | |
2813 | [N]>[|]WORD | |
2814 | ||
2815 | If the redirection operator is ‘>’, and the ‘noclobber’ option to the | |
2816 | ‘set’ builtin command has been enabled, the redirection fails if the | |
2817 | file whose name results from the expansion of WORD exists and is a | |
2818 | regular file. If the redirection operator is ‘>|’, or the redirection | |
2819 | operator is ‘>’ and the ‘noclobber’ option to the ‘set’ builtin is not | |
2820 | enabled, Bash attempts the redirection even if the file named by WORD | |
2821 | exists. | |
2822 | ||
2823 | 3.6.3 Appending Redirected Output | |
2824 | --------------------------------- | |
2825 | ||
2826 | Redirecting output in this fashion opens the file whose name results | |
2827 | from the expansion of WORD for appending on file descriptor N, or the | |
2828 | standard output (file descriptor 1) if N is not specified. If the file | |
2829 | does not exist it is created. | |
2830 | ||
2831 | The general format for appending output is: | |
2832 | [N]>>WORD | |
2833 | ||
2834 | 3.6.4 Redirecting Standard Output and Standard Error | |
2835 | ---------------------------------------------------- | |
2836 | ||
2837 | This construct redirects both the standard output (file descriptor 1) | |
2838 | and the standard error output (file descriptor 2) to the file whose name | |
2839 | is the expansion of WORD. | |
2840 | ||
2841 | There are two formats for redirecting standard output and standard | |
2842 | error: | |
2843 | &>WORD | |
2844 | and | |
2845 | >&WORD | |
2846 | Of the two forms, the first is preferred. This is semantically | |
2847 | equivalent to | |
2848 | >WORD 2>&1 | |
2849 | When using the second form, WORD may not expand to a number or ‘-’. | |
2850 | If it does, other redirection operators apply (see Duplicating File | |
2851 | Descriptors below) for compatibility reasons. | |
2852 | ||
2853 | 3.6.5 Appending Standard Output and Standard Error | |
2854 | -------------------------------------------------- | |
2855 | ||
2856 | This construct appends both the standard output (file descriptor 1) and | |
2857 | the standard error output (file descriptor 2) to the file whose name is | |
2858 | the expansion of WORD. | |
2859 | ||
2860 | The format for appending standard output and standard error is: | |
2861 | &>>WORD | |
2862 | This is semantically equivalent to | |
2863 | >>WORD 2>&1 | |
2864 | (see Duplicating File Descriptors below). | |
2865 | ||
2866 | 3.6.6 Here Documents | |
2867 | -------------------- | |
2868 | ||
2869 | This type of redirection instructs the shell to read input from the | |
2870 | current source until it reads a line containing only DELIMITER (with no | |
2871 | trailing blanks). All of the lines read up to that point then become | |
2872 | the standard input (or file descriptor N if N is specified) for a | |
2873 | command. | |
2874 | ||
2875 | The format of here-documents is: | |
2876 | [N]<<[−]WORD | |
2877 | HERE-DOCUMENT | |
2878 | DELIMITER | |
2879 | ||
2880 | The shell does not perform parameter and variable expansion, command | |
2881 | substitution, arithmetic expansion, or filename expansion on WORD. | |
2882 | ||
2883 | If any part of WORD is quoted, the DELIMITER is the result of quote | |
2884 | removal on WORD, and the lines in the here-document are not expanded. | |
2885 | If WORD is unquoted, DELIMITER is WORD itself, and the here-document | |
2886 | text is treated similarly to a double-quoted string: all lines of the | |
2887 | here-document are subjected to parameter expansion, command | |
2888 | substitution, and arithmetic expansion, the character sequence | |
2889 | ‘\newline’ is treated literally, and ‘\’ must be used to quote the | |
2890 | characters ‘\’, ‘$’, and ‘`’; however, double quote characters have no | |
2891 | special meaning. | |
2892 | ||
2893 | If the redirection operator is ‘<<-’, the shell strips leading tab | |
2894 | characters are stripped from input lines and the line containing | |
2895 | DELIMITER. This allows here-documents within shell scripts to be | |
2896 | indented in a natural fashion. | |
2897 | ||
2898 | If the delimiter is not quoted, the ‘\<newline>’ sequence is treated | |
2899 | as a line continuation: the two lines are joined and the | |
2900 | backslash-newline is removed. This happens while reading the | |
2901 | here-document, before the check for the ending delimiter, so joined | |
2902 | lines can form the end delimiter. | |
2903 | ||
2904 | 3.6.7 Here Strings | |
2905 | ------------------ | |
2906 | ||
2907 | A variant of here documents, the format is: | |
2908 | [N]<<< WORD | |
2909 | ||
2910 | The WORD undergoes tilde expansion, parameter and variable expansion, | |
2911 | command substitution, arithmetic expansion, and quote removal. Filename | |
2912 | expansion and word splitting are not performed. The result is supplied | |
2913 | as a single string, with a newline appended, to the command on its | |
2914 | standard input (or file descriptor N if N is specified). | |
2915 | ||
2916 | 3.6.8 Duplicating File Descriptors | |
2917 | ---------------------------------- | |
2918 | ||
2919 | The redirection operator | |
2920 | [N]<&WORD | |
2921 | is used to duplicate input file descriptors. If WORD expands to one or | |
2922 | more digits, file descriptor N is made to be a copy of that file | |
2923 | descriptor. It is a redirection error if the digits in WORD do not | |
2924 | specify a file descriptor open for input. If WORD evaluates to ‘-’, | |
2925 | file descriptor N is closed. If N is not specified, this uses the | |
2926 | standard input (file descriptor 0). | |
2927 | ||
2928 | The operator | |
2929 | [N]>&WORD | |
2930 | is used similarly to duplicate output file descriptors. If N is not | |
2931 | specified, this uses the standard output (file descriptor 1). It is a | |
2932 | redirection error if the digits in WORD do not specify a file descriptor | |
2933 | open for output. If WORD evaluates to ‘-’, file descriptor N is closed. | |
2934 | As a special case, if N is omitted, and WORD does not expand to one or | |
2935 | more digits or ‘-’, this redirects the standard output and standard | |
2936 | error as described previously. | |
2937 | ||
2938 | 3.6.9 Moving File Descriptors | |
2939 | ----------------------------- | |
2940 | ||
2941 | The redirection operator | |
2942 | [N]<&DIGIT- | |
2943 | moves the file descriptor DIGIT to file descriptor N, or the standard | |
2944 | input (file descriptor 0) if N is not specified. DIGIT is closed after | |
2945 | being duplicated to N. | |
2946 | ||
2947 | Similarly, the redirection operator | |
2948 | [N]>&DIGIT- | |
2949 | moves the file descriptor DIGIT to file descriptor N, or the standard | |
2950 | output (file descriptor 1) if N is not specified. | |
2951 | ||
2952 | 3.6.10 Opening File Descriptors for Reading and Writing | |
2953 | ------------------------------------------------------- | |
2954 | ||
2955 | The redirection operator | |
2956 | [N]<>WORD | |
2957 | opens the file whose name is the expansion of WORD for both reading and | |
2958 | writing on file descriptor N, or on file descriptor 0 if N is not | |
2959 | specified. If the file does not exist, it is created. | |
2960 | ||
2961 | \1f | |
2962 | File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features | |
2963 | ||
2964 | 3.7 Executing Commands | |
2965 | ====================== | |
2966 | ||
2967 | * Menu: | |
2968 | ||
2969 | * Simple Command Expansion:: How Bash expands simple commands before | |
2970 | executing them. | |
2971 | * Command Search and Execution:: How Bash finds commands and runs them. | |
2972 | * Command Execution Environment:: The environment in which Bash | |
2973 | executes commands that are not | |
2974 | shell builtins. | |
2975 | * Environment:: The environment given to a command. | |
2976 | * Exit Status:: The status returned by commands and how Bash | |
2977 | interprets it. | |
2978 | * Signals:: What happens when Bash or a command it runs | |
2979 | receives a signal. | |
2980 | ||
2981 | \1f | |
2982 | File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands | |
2983 | ||
2984 | 3.7.1 Simple Command Expansion | |
2985 | ------------------------------ | |
2986 | ||
2987 | When the shell executes a simple command, it performs the following | |
2988 | expansions, assignments, and redirections, from left to right, in the | |
2989 | following order. | |
2990 | ||
2991 | 1. The words that the parser has marked as variable assignments (those | |
2992 | preceding the command name) and redirections are saved for later | |
2993 | processing. | |
2994 | ||
2995 | 2. The words that are not variable assignments or redirections are | |
2996 | expanded (*note Shell Expansions::). If any words remain after | |
2997 | expansion, the first word is taken to be the name of the command | |
2998 | and the remaining words are the arguments. | |
2999 | ||
3000 | 3. Redirections are performed as described above (*note | |
3001 | Redirections::). | |
3002 | ||
3003 | 4. The text after the ‘=’ in each variable assignment undergoes tilde | |
3004 | expansion, parameter expansion, command substitution, arithmetic | |
3005 | expansion, and quote removal before being assigned to the variable. | |
3006 | ||
3007 | If no command name results, the variable assignments affect the | |
3008 | current shell environment. In the case of such a command (one that | |
3009 | consists only of assignment statements and redirections), assignment | |
3010 | statements are performed before redirections. Otherwise, the variables | |
3011 | are added to the environment of the executed command and do not affect | |
3012 | the current shell environment. If any of the assignments attempts to | |
3013 | assign a value to a readonly variable, an error occurs, and the command | |
3014 | exits with a non-zero status. | |
3015 | ||
3016 | If no command name results, redirections are performed, but do not | |
3017 | affect the current shell environment. A redirection error causes the | |
3018 | command to exit with a non-zero status. | |
3019 | ||
3020 | If there is a command name left after expansion, execution proceeds | |
3021 | as described below. Otherwise, the command exits. If one of the | |
3022 | expansions contained a command substitution, the exit status of the | |
3023 | command is the exit status of the last command substitution performed. | |
3024 | If there were no command substitutions, the command exits with a zero | |
3025 | status. | |
3026 | ||
3027 | \1f | |
3028 | File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands | |
3029 | ||
3030 | 3.7.2 Command Search and Execution | |
3031 | ---------------------------------- | |
3032 | ||
3033 | After a command has been split into words, if it results in a simple | |
3034 | command and an optional list of arguments, the shell performs the | |
3035 | following actions. | |
3036 | ||
3037 | 1. If the command name contains no slashes, the shell attempts to | |
3038 | locate it. If there exists a shell function by that name, that | |
3039 | function is invoked as described in *note Shell Functions::. | |
3040 | ||
3041 | 2. If the name does not match a function, the shell searches for it in | |
3042 | the list of shell builtins. If a match is found, that builtin is | |
3043 | invoked. | |
3044 | ||
3045 | 3. If the name is neither a shell function nor a builtin, and contains | |
3046 | no slashes, Bash searches each element of ‘$PATH’ for a directory | |
3047 | containing an executable file by that name. Bash uses a hash table | |
3048 | to remember the full pathnames of executable files to avoid | |
3049 | multiple ‘PATH’ searches (see the description of ‘hash’ in *note | |
3050 | Bourne Shell Builtins::). Bash performs a full search of the | |
3051 | directories in ‘$PATH’ only if the command is not found in the hash | |
3052 | table. If the search is unsuccessful, the shell searches for a | |
3053 | defined shell function named ‘command_not_found_handle’. If that | |
3054 | function exists, it is invoked in a separate execution environment | |
3055 | with the original command and the original command's arguments as | |
3056 | its arguments, and the function's exit status becomes the exit | |
3057 | status of that subshell. If that function is not defined, the | |
3058 | shell prints an error message and returns an exit status of 127. | |
3059 | ||
3060 | 4. If the search is successful, or if the command name contains one or | |
3061 | more slashes, the shell executes the named program in a separate | |
3062 | execution environment. Argument 0 is set to the name given, and | |
3063 | the remaining arguments to the command are set to the arguments | |
3064 | supplied, if any. | |
3065 | ||
3066 | 5. If this execution fails because the file is not in executable | |
3067 | format, and the file is not a directory, it is assumed to be a | |
3068 | “shell script”, a file containing shell commands, and the shell | |
3069 | executes it as described in *note Shell Scripts::. | |
3070 | ||
3071 | 6. If the command was not begun asynchronously, the shell waits for | |
3072 | the command to complete and collects its exit status. | |
3073 | ||
3074 | \1f | |
3075 | File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands | |
3076 | ||
3077 | 3.7.3 Command Execution Environment | |
3078 | ----------------------------------- | |
3079 | ||
3080 | The shell has an “execution environment”, which consists of the | |
3081 | following: | |
3082 | ||
3083 | • Open files inherited by the shell at invocation, as modified by | |
3084 | redirections supplied to the ‘exec’ builtin. | |
3085 | ||
3086 | • The current working directory as set by ‘cd’, ‘pushd’, or ‘popd’, | |
3087 | or inherited by the shell at invocation. | |
3088 | ||
3089 | • The file creation mode mask as set by ‘umask’ or inherited from the | |
3090 | shell's parent. | |
3091 | ||
3092 | • Current traps set by ‘trap’. | |
3093 | ||
3094 | • Shell parameters that are set by variable assignment or with ‘set’ | |
3095 | or inherited from the shell's parent in the environment. | |
3096 | ||
3097 | • Shell functions defined during execution or inherited from the | |
3098 | shell's parent in the environment. | |
3099 | ||
3100 | • Options enabled at invocation (either by default or with | |
3101 | command-line arguments) or by ‘set’. | |
3102 | ||
3103 | • Options enabled by ‘shopt’ (*note The Shopt Builtin::). | |
3104 | ||
3105 | • Shell aliases defined with ‘alias’ (*note Aliases::). | |
3106 | ||
3107 | • Various process IDs, including those of background jobs (*note | |
3108 | Lists::), the value of ‘$$’, and the value of ‘$PPID’. | |
3109 | ||
3110 | When a simple command other than a builtin or shell function is to be | |
3111 | executed, it is invoked in a separate execution environment that | |
3112 | consists of the following. Unless otherwise noted, the values are | |
3113 | inherited from the shell. | |
3114 | ||
3115 | • The shell's open files, plus any modifications and additions | |
3116 | specified by redirections to the command. | |
3117 | ||
3118 | • The current working directory. | |
3119 | ||
3120 | • The file creation mode mask. | |
3121 | ||
3122 | • Shell variables and functions marked for export, along with | |
3123 | variables exported for the command, passed in the environment | |
3124 | (*note Environment::). | |
3125 | ||
3126 | • Traps caught by the shell are reset to the values inherited from | |
3127 | the shell's parent, and traps ignored by the shell are ignored. | |
3128 | ||
3129 | A command invoked in this separate environment cannot affect the | |
3130 | shell's execution environment. | |
3131 | ||
3132 | A “subshell” is a copy of the shell process. | |
3133 | ||
3134 | Command substitution, commands grouped with parentheses, and | |
3135 | asynchronous commands are invoked in a subshell environment that is a | |
3136 | duplicate of the shell environment, except that traps caught by the | |
3137 | shell are reset to the values that the shell inherited from its parent | |
3138 | at invocation. Builtin commands that are invoked as part of a pipeline, | |
3139 | except possibly in the last element depending on the value of the | |
3140 | ‘lastpipe’ shell option (*note The Shopt Builtin::), are also executed | |
3141 | in a subshell environment. Changes made to the subshell environment | |
3142 | cannot affect the shell's execution environment. | |
3143 | ||
3144 | When the shell is in POSIX mode, subshells spawned to execute command | |
3145 | substitutions inherit the value of the ‘-e’ option from the parent | |
3146 | shell. When not in POSIX mode, Bash clears the ‘-e’ option in such | |
3147 | subshells See the description of the ‘inherit_errexit’ shell option | |
3148 | (*note Bash Builtins::) for how to control this behavior when not in | |
3149 | POSIX mode. | |
3150 | ||
3151 | If a command is followed by a ‘&’ and job control is not active, the | |
3152 | default standard input for the command is the empty file ‘/dev/null’. | |
3153 | Otherwise, the invoked command inherits the file descriptors of the | |
3154 | calling shell as modified by redirections. | |
3155 | ||
3156 | \1f | |
3157 | File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands | |
3158 | ||
3159 | 3.7.4 Environment | |
3160 | ----------------- | |
3161 | ||
3162 | When a program is invoked it is given an array of strings called the | |
3163 | “environment”. This is a list of name-value pairs, of the form | |
3164 | ‘name=value’. | |
3165 | ||
3166 | Bash provides several ways to manipulate the environment. On | |
3167 | invocation, the shell scans its own environment and creates a parameter | |
3168 | for each name found, automatically marking it for ‘export’ to child | |
3169 | processes. Executed commands inherit the environment. The ‘export’, | |
3170 | ‘declare -x’, and ‘unset’ commands modify the environment by adding and | |
3171 | deleting parameters and functions. If the value of a parameter in the | |
3172 | environment is modified, the new value automatically becomes part of the | |
3173 | environment, replacing the old. The environment inherited by any | |
3174 | executed command consists of the shell's initial environment, whose | |
3175 | values may be modified in the shell, less any pairs removed by the | |
3176 | ‘unset’ and ‘export -n’ commands, plus any additions via the ‘export’ | |
3177 | and ‘declare -x’ commands. | |
3178 | ||
3179 | If any parameter assignment statements, as described in *note Shell | |
3180 | Parameters::, appear before a simple command, the variable assignments | |
3181 | are part of that command's environment for as long as it executes. | |
3182 | These assignment statements affect only the environment seen by that | |
3183 | command. If these assignments precede a call to a shell function, the | |
3184 | variables are local to the function and exported to that function's | |
3185 | children. | |
3186 | ||
3187 | If the ‘-k’ option is set (*note The Set Builtin::), then all | |
3188 | parameter assignments are placed in the environment for a command, not | |
3189 | just those that precede the command name. | |
3190 | ||
3191 | When Bash invokes an external command, the variable ‘$_’ is set to | |
3192 | the full pathname of the command and passed to that command in its | |
3193 | environment. | |
3194 | ||
3195 | \1f | |
3196 | File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands | |
3197 | ||
3198 | 3.7.5 Exit Status | |
3199 | ----------------- | |
3200 | ||
3201 | The exit status of an executed command is the value returned by the | |
3202 | ‘waitpid’ system call or equivalent function. Exit statuses fall | |
3203 | between 0 and 255, though, as explained below, the shell may use values | |
3204 | above 125 specially. Exit statuses from shell builtins and compound | |
3205 | commands are also limited to this range. Under certain circumstances, | |
3206 | the shell will use special values to indicate specific failure modes. | |
3207 | ||
3208 | For the shell's purposes, a command which exits with a zero exit | |
3209 | status has succeeded. So while an exit status of zero indicates | |
3210 | success, a non-zero exit status indicates failure. This seemingly | |
3211 | counter-intuitive scheme is used so there is one well-defined way to | |
3212 | indicate success and a variety of ways to indicate various failure | |
3213 | modes. | |
3214 | ||
3215 | When a command terminates on a fatal signal whose number is N, Bash | |
3216 | uses the value 128+N as the exit status. | |
3217 | ||
3218 | If a command is not found, the child process created to execute it | |
3219 | returns a status of 127. If a command is found but is not executable, | |
3220 | the return status is 126. | |
3221 | ||
3222 | If a command fails because of an error during expansion or | |
3223 | redirection, the exit status is greater than zero. | |
3224 | ||
3225 | The exit status is used by the Bash conditional commands (*note | |
3226 | Conditional Constructs::) and some of the list constructs (*note | |
3227 | Lists::). | |
3228 | ||
3229 | All of the Bash builtins return an exit status of zero if they | |
3230 | succeed and a non-zero status on failure, so they may be used by the | |
3231 | conditional and list constructs. All builtins return an exit status of | |
3232 | 2 to indicate incorrect usage, generally invalid options or missing | |
3233 | arguments. | |
3234 | ||
3235 | The exit status of the last command is available in the special | |
3236 | parameter $? (*note Special Parameters::). | |
3237 | ||
3238 | Bash itself returns the exit status of the last command executed, | |
3239 | unless a syntax error occurs, in which case it exits with a non-zero | |
3240 | value. See also the ‘exit’ builtin command (*note Bourne Shell | |
3241 | Builtins::. | |
3242 | ||
3243 | \1f | |
3244 | File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands | |
3245 | ||
3246 | 3.7.6 Signals | |
3247 | ------------- | |
3248 | ||
3249 | When Bash is interactive, in the absence of any traps, it ignores | |
3250 | ‘SIGTERM’ (so that ‘kill 0’ does not kill an interactive shell), and | |
3251 | catches and handles ‘SIGINT’ (so that the ‘wait’ builtin is | |
3252 | interruptible). When Bash receives a ‘SIGINT’, it breaks out of any | |
3253 | executing loops. In all cases, Bash ignores ‘SIGQUIT’. If job control | |
3254 | is in effect (*note Job Control::), Bash ignores ‘SIGTTIN’, ‘SIGTTOU’, | |
3255 | and ‘SIGTSTP’. | |
3256 | ||
3257 | The ‘trap’ builtin modifies the shell's signal handling, as described | |
3258 | below (*note Bourne Shell Builtins::. | |
3259 | ||
3260 | Non-builtin commands Bash executes have signal handlers set to the | |
3261 | values inherited by the shell from its parent, unless ‘trap’ sets them | |
3262 | to be ignored, in which case the child process will ignore them as well. | |
3263 | When job control is not in effect, asynchronous commands ignore ‘SIGINT’ | |
3264 | and ‘SIGQUIT’ in addition to these inherited handlers. Commands run as | |
3265 | a result of command substitution ignore the keyboard-generated job | |
3266 | control signals ‘SIGTTIN’, ‘SIGTTOU’, and ‘SIGTSTP’. | |
3267 | ||
3268 | The shell exits by default upon receipt of a ‘SIGHUP’. Before | |
3269 | exiting, an interactive shell resends the ‘SIGHUP’ to all jobs, running | |
3270 | or stopped. The shell sends ‘SIGCONT’ to stopped jobs to ensure that | |
3271 | they receive the ‘SIGHUP’ (*Note Job Control::, for more information | |
3272 | about running and stopped jobs). To prevent the shell from sending the | |
3273 | ‘SIGHUP’ signal to a particular job, remove it from the jobs table with | |
3274 | the ‘disown’ builtin (*note Job Control Builtins::) or mark it not to | |
3275 | receive ‘SIGHUP’ using ‘disown -h’. | |
3276 | ||
3277 | If the ‘huponexit’ shell option has been set using ‘shopt’ (*note The | |
3278 | Shopt Builtin::), Bash sends a ‘SIGHUP’ to all jobs when an interactive | |
3279 | login shell exits. | |
3280 | ||
3281 | If Bash is waiting for a command to complete and receives a signal | |
3282 | for which a trap has been set, it will not execute the trap until the | |
3283 | command completes. If Bash is waiting for an asynchronous command via | |
3284 | the ‘wait’ builtin, and it receives a signal for which a trap has been | |
3285 | set, the ‘wait’ builtin will return immediately with an exit status | |
3286 | greater than 128, immediately after which the shell executes the trap. | |
3287 | ||
3288 | When job control is not enabled, and Bash is waiting for a foreground | |
3289 | command to complete, the shell receives keyboard-generated signals such | |
3290 | as ‘SIGINT’ (usually generated by ‘^C’) that users commonly intend to | |
3291 | send to that command. This happens because the shell and the command | |
3292 | are in the same process group as the terminal, and ‘^C’ sends ‘SIGINT’ | |
3293 | to all processes in that process group. Since Bash does not enable job | |
3294 | control by default when the shell is not interactive, this scenario is | |
3295 | most common in non-interactive shells. | |
3296 | ||
3297 | When job control is enabled, and Bash is waiting for a foreground | |
3298 | command to complete, the shell does not receive keyboard-generated | |
3299 | signals, because it is not in the same process group as the terminal. | |
3300 | This scenario is most common in interactive shells, where Bash attempts | |
3301 | to enable job control by default. See *note Job Control::, for a more | |
3302 | in-depth discussion of process groups. | |
3303 | ||
3304 | When job control is not enabled, and Bash receives ‘SIGINT’ while | |
3305 | waiting for a foreground command, it waits until that foreground command | |
3306 | terminates and then decides what to do about the ‘SIGINT’: | |
3307 | ||
3308 | 1. If the command terminates due to the ‘SIGINT’, Bash concludes that | |
3309 | the user meant to send the ‘SIGINT’ to the shell as well, and acts | |
3310 | on the ‘SIGINT’ (e.g., by running a ‘SIGINT’ trap, exiting a | |
3311 | non-interactive shell, or returning to the top level to read a new | |
3312 | command). | |
3313 | ||
3314 | 2. If the command does not terminate due to ‘SIGINT’, the program | |
3315 | handled the ‘SIGINT’ itself and did not treat it as a fatal signal. | |
3316 | In that case, Bash does not treat ‘SIGINT’ as a fatal signal, | |
3317 | either, instead assuming that the ‘SIGINT’ was used as part of the | |
3318 | program's normal operation (e.g., ‘emacs’ uses it to abort editing | |
3319 | commands) or deliberately discarded. However, Bash will run any | |
3320 | trap set on ‘SIGINT’, as it does with any other trapped signal it | |
3321 | receives while it is waiting for the foreground command to | |
3322 | complete, for compatibility. | |
3323 | ||
3324 | When job control is enabled, Bash does not receive keyboard-generated | |
3325 | signals such as ‘SIGINT’ while it is waiting for a foreground command. | |
3326 | An interactive shell does not pay attention to the ‘SIGINT’, even if the | |
3327 | foreground command terminates as a result, other than noting its exit | |
3328 | status. If the shell is not interactive, and the foreground command | |
3329 | terminates due to the ‘SIGINT’, Bash pretends it received the ‘SIGINT’ | |
3330 | itself (scenario 1 above), for compatibility. | |
3331 | ||
3332 | \1f | |
3333 | File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features | |
3334 | ||
3335 | 3.8 Shell Scripts | |
3336 | ================= | |
3337 | ||
3338 | A shell script is a text file containing shell commands. When such a | |
3339 | file is used as the first non-option argument when invoking Bash, and | |
3340 | neither the ‘-c’ nor ‘-s’ option is supplied (*note Invoking Bash::), | |
3341 | Bash reads and executes commands from the file, then exits. This mode | |
3342 | of operation creates a non-interactive shell. If the filename does not | |
3343 | contain any slashes, the shell first searches for the file in the | |
3344 | current directory, and looks in the directories in ‘$PATH’ if not found | |
3345 | there. | |
3346 | ||
3347 | Bash tries to determine whether the file is a text file or a binary, | |
3348 | and will not execute files it determines to be binaries. | |
3349 | ||
3350 | When Bash runs a shell script, it sets the special parameter ‘0’ to | |
3351 | the name of the file, rather than the name of the shell, and the | |
3352 | positional parameters are set to the remaining arguments, if any are | |
3353 | given. If no additional arguments are supplied, the positional | |
3354 | parameters are unset. | |
3355 | ||
3356 | A shell script may be made executable by using the ‘chmod’ command to | |
3357 | turn on the execute bit. When Bash finds such a file while searching | |
3358 | the ‘$PATH’ for a command, it creates a new instance of itself to | |
3359 | execute it. In other words, executing | |
3360 | filename ARGUMENTS | |
3361 | is equivalent to executing | |
3362 | bash filename ARGUMENTS | |
3363 | ||
3364 | if ‘filename’ is an executable shell script. This subshell | |
3365 | reinitializes itself, so that the effect is as if a new shell had been | |
3366 | invoked to interpret the script, with the exception that the locations | |
3367 | of commands remembered by the parent (see the description of ‘hash’ in | |
3368 | *note Bourne Shell Builtins::) are retained by the child. | |
3369 | ||
3370 | The GNU operating system, and most versions of Unix, make this a part | |
3371 | of the operating system's command execution mechanism. If the first | |
3372 | line of a script begins with the two characters ‘#!’, the remainder of | |
3373 | the line specifies an interpreter for the program and, depending on the | |
3374 | operating system, one or more optional arguments for that interpreter. | |
3375 | Thus, you can specify Bash, ‘awk’, Perl, or some other interpreter and | |
3376 | write the rest of the script file in that language. | |
3377 | ||
3378 | The arguments to the interpreter consist of one or more optional | |
3379 | arguments following the interpreter name on the first line of the script | |
3380 | file, followed by the name of the script file, followed by the rest of | |
3381 | the arguments supplied to the script. The details of how the | |
3382 | interpreter line is split into an interpreter name and a set of | |
3383 | arguments vary across systems. Bash will perform this action on | |
3384 | operating systems that do not handle it themselves. Note that some | |
3385 | older versions of Unix limit the interpreter name and a single argument | |
3386 | to a maximum of 32 characters, so it's not portable to assume that using | |
3387 | more than one argument will work. | |
3388 | ||
3389 | Bash scripts often begin with ‘#! /bin/bash’ (assuming that Bash has | |
3390 | been installed in ‘/bin’), since this ensures that Bash will be used to | |
3391 | interpret the script, even if it is executed under another shell. It's | |
3392 | a common idiom to use ‘env’ to find ‘bash’ even if it's been installed | |
3393 | in another directory: ‘#!/usr/bin/env bash’ will find the first | |
3394 | occurrence of ‘bash’ in ‘$PATH’. | |
3395 | ||
3396 | \1f | |
3397 | File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top | |
3398 | ||
3399 | 4 Shell Builtin Commands | |
3400 | ************************ | |
3401 | ||
3402 | * Menu: | |
3403 | ||
3404 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
3405 | Shell. | |
3406 | * Bash Builtins:: Table of builtins specific to Bash. | |
3407 | * Modifying Shell Behavior:: Builtins to modify shell attributes and | |
3408 | optional behavior. | |
3409 | * Special Builtins:: Builtin commands classified specially by | |
3410 | POSIX. | |
3411 | ||
3412 | Builtin commands are contained within the shell itself. When the name | |
3413 | of a builtin command is used as the first word of a simple command | |
3414 | (*note Simple Commands::), the shell executes the command directly, | |
3415 | without invoking another program. Builtin commands are necessary to | |
3416 | implement functionality impossible or inconvenient to obtain with | |
3417 | separate utilities. | |
3418 | ||
3419 | This section briefly describes the builtins which Bash inherits from | |
3420 | the Bourne Shell, as well as the builtin commands which are unique to or | |
3421 | have been extended in Bash. | |
3422 | ||
3423 | Several builtin commands are described in other chapters: builtin | |
3424 | commands which provide the Bash interface to the job control facilities | |
3425 | (*note Job Control Builtins::), the directory stack (*note Directory | |
3426 | Stack Builtins::), the command history (*note Bash History Builtins::), | |
3427 | and the programmable completion facilities (*note Programmable | |
3428 | Completion Builtins::). | |
3429 | ||
3430 | Many of the builtins have been extended by POSIX or Bash. | |
3431 | ||
3432 | Unless otherwise noted, each builtin command documented as accepting | |
3433 | options preceded by ‘-’ accepts ‘--’ to signify the end of the options. | |
3434 | The ‘:’, ‘true’, ‘false’, and ‘test’/‘[’ builtins do not accept options | |
3435 | and do not treat ‘--’ specially. The ‘exit’, ‘logout’, ‘return’, | |
3436 | ‘break’, ‘continue’, ‘let’, and ‘shift’ builtins accept and process | |
3437 | arguments beginning with ‘-’ without requiring ‘--’. Other builtins | |
3438 | that accept arguments but are not specified as accepting options | |
3439 | interpret arguments beginning with ‘-’ as invalid options and require | |
3440 | ‘--’ to prevent this interpretation. | |
3441 | ||
3442 | \1f | |
3443 | File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands | |
3444 | ||
3445 | 4.1 Bourne Shell Builtins | |
3446 | ========================= | |
3447 | ||
3448 | The following shell builtin commands are inherited from the Bourne | |
3449 | Shell. These commands are implemented as specified by the POSIX | |
3450 | standard. | |
3451 | ||
3452 | ‘: (a colon)’ | |
3453 | : [ARGUMENTS] | |
3454 | ||
3455 | Do nothing beyond expanding ARGUMENTS and performing redirections. | |
3456 | The return status is zero. | |
3457 | ||
3458 | ‘. (a period)’ | |
3459 | . [-p PATH] FILENAME [ARGUMENTS] | |
3460 | ||
3461 | The ‘.’ command reads and execute commands from the FILENAME | |
3462 | argument in the current shell context. | |
3463 | ||
3464 | If FILENAME does not contain a slash, ‘.’ searches for it. If ‘-p’ | |
3465 | is supplied, ‘.’ treats PATH as a colon-separated list of | |
3466 | directories in which to find FILENAME; otherwise, ‘.’ uses the | |
3467 | directories in ‘PATH’ to find FILENAME. FILENAME does not need to | |
3468 | be executable. When Bash is not in POSIX mode, it searches the | |
3469 | current directory if FILENAME is not found in ‘$PATH’, but does not | |
3470 | search the current directory if ‘-p’ is supplied. If the | |
3471 | ‘sourcepath’ option (*note The Shopt Builtin::) is turned off, ‘.’ | |
3472 | does not search ‘PATH’. | |
3473 | ||
3474 | If any ARGUMENTS are supplied, they become the positional | |
3475 | parameters when FILENAME is executed. Otherwise the positional | |
3476 | parameters are unchanged. | |
3477 | ||
3478 | If the ‘-T’ option is enabled, ‘.’ inherits any trap on ‘DEBUG’; if | |
3479 | it is not, any ‘DEBUG’ trap string is saved and restored around the | |
3480 | call to ‘.’, and ‘.’ unsets the ‘DEBUG’ trap while it executes. If | |
3481 | ‘-T’ is not set, and the sourced file changes the ‘DEBUG’ trap, the | |
3482 | new value persists after ‘.’ completes. The return status is the | |
3483 | exit status of the last command executed from FILENAME, or zero if | |
3484 | no commands are executed. If FILENAME is not found, or cannot be | |
3485 | read, the return status is non-zero. This builtin is equivalent to | |
3486 | ‘source’. | |
3487 | ||
3488 | ‘break’ | |
3489 | break [N] | |
3490 | ||
3491 | Exit from a ‘for’, ‘while’, ‘until’, or ‘select’ loop. If N is | |
3492 | supplied, ‘break’ exits the Nth enclosing loop. N must be greater | |
3493 | than or equal to 1. The return status is zero unless N is not | |
3494 | greater than or equal to 1. | |
3495 | ||
3496 | ‘cd’ | |
3497 | cd [-L] [-@] [DIRECTORY] | |
3498 | cd -P [-e] [-@] [DIRECTORY] | |
3499 | ||
3500 | Change the current working directory to DIRECTORY. If DIRECTORY is | |
3501 | not supplied, the value of the ‘HOME’ shell variable is used as | |
3502 | DIRECTORY. If the shell variable ‘CDPATH’ exists, and DIRECTORY | |
3503 | does not begin with a slash, ‘cd’ uses it as a search path: ‘cd’ | |
3504 | searches each directory name in ‘CDPATH’ for DIRECTORY, with | |
3505 | alternative directory names in ‘CDPATH’ separated by a colon (‘:’). | |
3506 | A null directory name in ‘CDPATH’ means the same thing as the | |
3507 | current directory. | |
3508 | ||
3509 | The ‘-P’ option means not to follow symbolic links: symbolic links | |
3510 | are resolved while ‘cd’ is traversing DIRECTORY and before | |
3511 | processing an instance of ‘..’ in DIRECTORY. | |
3512 | ||
3513 | By default, or when the ‘-L’ option is supplied, symbolic links in | |
3514 | DIRECTORY are resolved after ‘cd’ processes an instance of ‘..’ in | |
3515 | DIRECTORY. | |
3516 | ||
3517 | If ‘..’ appears in DIRECTORY, ‘cd’ processes it by removing the | |
3518 | immediately preceding pathname component, back to a slash or the | |
3519 | beginning of DIRECTORY, and verifying that the portion of DIRECTORY | |
3520 | it has processed to that point is still a valid directory name | |
3521 | after removing the pathname component. If it is not a valid | |
3522 | directory name, ‘cd’ returns a non-zero status. | |
3523 | ||
3524 | If the ‘-e’ option is supplied with ‘-P’ and ‘cd’ cannot | |
3525 | successfully determine the current working directory after a | |
3526 | successful directory change, it returns a non-zero status. | |
3527 | ||
3528 | On systems that support it, the ‘-@’ option presents the extended | |
3529 | attributes associated with a file as a directory. | |
3530 | ||
3531 | If DIRECTORY is ‘-’, it is converted to ‘$OLDPWD’ before attempting | |
3532 | the directory change. | |
3533 | ||
3534 | If ‘cd’ uses a non-empty directory name from ‘CDPATH’, or if ‘-’ is | |
3535 | the first argument, and the directory change is successful, ‘cd’ | |
3536 | writes the absolute pathname of the new working directory to the | |
3537 | standard output. | |
3538 | ||
3539 | If the directory change is successful, ‘cd’ sets the value of the | |
3540 | ‘PWD’ environment variable to the new directory name, and sets the | |
3541 | ‘OLDPWD’ environment variable to the value of the current working | |
3542 | directory before the change. | |
3543 | ||
3544 | The return status is zero if the directory is successfully changed, | |
3545 | non-zero otherwise. | |
3546 | ||
3547 | ‘continue’ | |
3548 | continue [N] | |
3549 | ||
3550 | ‘continue’ resumes the next iteration of an enclosing ‘for’, | |
3551 | ‘while’, ‘until’, or ‘select’ loop. If N is supplied, Bash resumes | |
3552 | the execution of the Nth enclosing loop. N must be greater than or | |
3553 | equal to 1. The return status is zero unless N is not greater than | |
3554 | or equal to 1. | |
3555 | ||
3556 | ‘eval’ | |
3557 | eval [ARGUMENTS] | |
3558 | ||
3559 | The ARGUMENTS are concatenated together into a single command, | |
3560 | separated by spaces. Bash then reads and executes this command and | |
3561 | returns its exit status as the exit status of ‘eval’. If there are | |
3562 | no arguments or only empty arguments, the return status is zero. | |
3563 | ||
3564 | ‘exec’ | |
3565 | exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] | |
3566 | ||
3567 | If COMMAND is supplied, it replaces the shell without creating a | |
3568 | new process. COMMAND cannot be a shell builtin or function. The | |
3569 | ARGUMENTS become the arguments to COMMAND If the ‘-l’ option is | |
3570 | supplied, the shell places a dash at the beginning of the zeroth | |
3571 | argument passed to COMMAND. This is what the ‘login’ program does. | |
3572 | The ‘-c’ option causes COMMAND to be executed with an empty | |
3573 | environment. If ‘-a’ is supplied, the shell passes NAME as the | |
3574 | zeroth argument to COMMAND. | |
3575 | ||
3576 | If COMMAND cannot be executed for some reason, a non-interactive | |
3577 | shell exits, unless the ‘execfail’ shell option is enabled. In | |
3578 | that case, it returns a non-zero status. An interactive shell | |
3579 | returns a non-zero status if the file cannot be executed. A | |
3580 | subshell exits unconditionally if ‘exec’ fails. | |
3581 | ||
3582 | If COMMAND is not specified, redirections may be used to affect the | |
3583 | current shell environment. If there are no redirection errors, the | |
3584 | return status is zero; otherwise the return status is non-zero. | |
3585 | ||
3586 | ‘exit’ | |
3587 | exit [N] | |
3588 | ||
3589 | Exit the shell, returning a status of N to the shell's parent. If | |
3590 | N is omitted, the exit status is that of the last command executed. | |
3591 | Any trap on ‘EXIT’ is executed before the shell terminates. | |
3592 | ||
3593 | ‘export’ | |
3594 | export [-fn] [-p] [NAME[=VALUE]] | |
3595 | ||
3596 | Mark each NAME to be passed to subsequently executed commands in | |
3597 | the environment. If the ‘-f’ option is supplied, the NAMEs refer | |
3598 | to shell functions; otherwise the names refer to shell variables. | |
3599 | ||
3600 | The ‘-n’ option means to unexport each name: no longer mark it for | |
3601 | export. If no NAMEs are supplied, or if only the ‘-p’ option is | |
3602 | given, ‘export’ displays a list of names of all exported variables | |
3603 | on the standard output. Using ‘-p’ and ‘-f’ together displays | |
3604 | exported functions. The ‘-p’ option displays output in a form that | |
3605 | may be reused as input. | |
3606 | ||
3607 | ‘export’ allows the value of a variable to be set at the same time | |
3608 | it is exported or unexported by following the variable name with | |
3609 | =VALUE. This sets the value of the variable is to VALUE while | |
3610 | modifying the export attribute. | |
3611 | ||
3612 | The return status is zero unless an invalid option is supplied, one | |
3613 | of the names is not a valid shell variable name, or ‘-f’ is | |
3614 | supplied with a name that is not a shell function. | |
3615 | ||
3616 | ‘false’ | |
3617 | false | |
3618 | ||
3619 | Does nothing; returns a non-zero status. | |
3620 | ||
3621 | ‘getopts’ | |
3622 | getopts OPTSTRING NAME [ARG ...] | |
3623 | ||
3624 | ‘getopts’ is used by shell scripts or functions to parse positional | |
3625 | parameters and obtain options and their arguments. OPTSTRING | |
3626 | contains the option characters to be recognized; if a character is | |
3627 | followed by a colon, the option is expected to have an argument, | |
3628 | which should be separated from it by whitespace. The colon (‘:’) | |
3629 | and question mark (‘?’) may not be used as option characters. | |
3630 | ||
3631 | Each time it is invoked, ‘getopts’ places the next option in the | |
3632 | shell variable NAME, initializing NAME if it does not exist, and | |
3633 | the index of the next argument to be processed into the variable | |
3634 | ‘OPTIND’. ‘OPTIND’ is initialized to 1 each time the shell or a | |
3635 | shell script is invoked. When an option requires an argument, | |
3636 | ‘getopts’ places that argument into the variable ‘OPTARG’. | |
3637 | ||
3638 | The shell does not reset ‘OPTIND’ automatically; it must be | |
3639 | manually reset between multiple calls to ‘getopts’ within the same | |
3640 | shell invocation to use a new set of parameters. | |
3641 | ||
3642 | When it reaches the end of options, ‘getopts’ exits with a return | |
3643 | value greater than zero. ‘OPTIND’ is set to the index of the first | |
3644 | non-option argument, and NAME is set to ‘?’. | |
3645 | ||
3646 | ‘getopts’ normally parses the positional parameters, but if more | |
3647 | arguments are supplied as ARG values, ‘getopts’ parses those | |
3648 | instead. | |
3649 | ||
3650 | ‘getopts’ can report errors in two ways. If the first character of | |
3651 | OPTSTRING is a colon, ‘getopts’ uses _silent_ error reporting. In | |
3652 | normal operation, ‘getopts’ prints diagnostic messages when it | |
3653 | encounters invalid options or missing option arguments. If the | |
3654 | variable ‘OPTERR’ is set to 0, ‘getopts’ does not display any error | |
3655 | messages, even if the first character of ‘optstring’ is not a | |
3656 | colon. | |
3657 | ||
3658 | If ‘getopts’ detects an invalid option, it places ‘?’ into NAME | |
3659 | and, if not silent, prints an error message and unsets ‘OPTARG’. | |
3660 | If ‘getopts’ is silent, it assigns the option character found to | |
3661 | ‘OPTARG’ and does not print a diagnostic message. | |
3662 | ||
3663 | If a required argument is not found, and ‘getopts’ is not silent, | |
3664 | it sets the value of NAME to a question mark (‘?’), unsets | |
3665 | ‘OPTARG’, and prints a diagnostic message. If ‘getopts’ is silent, | |
3666 | it sets the value of NAME to a colon (‘:’), and sets ‘OPTARG’ to | |
3667 | the option character found. | |
3668 | ||
3669 | ‘getopts’ returns true if an option, specified or unspecified, is | |
3670 | found. It returns false when it encounters the end of options or | |
3671 | if an error occurs. | |
3672 | ||
3673 | ‘hash’ | |
3674 | hash [-r] [-p FILENAME] [-dt] [NAME] | |
3675 | ||
3676 | Each time ‘hash’ is invoked, it remembers the full filenames of the | |
3677 | commands specified as NAME arguments, so they need not be searched | |
3678 | for on subsequent invocations. The commands are found by searching | |
3679 | through the directories listed in ‘$PATH’. Any | |
3680 | previously-remembered filename associated with NAME is discarded. | |
3681 | The ‘-p’ option inhibits the path search, and ‘hash’ uses FILENAME | |
3682 | as the location of NAME. | |
3683 | ||
3684 | The ‘-r’ option causes the shell to forget all remembered | |
3685 | locations. Assigning to the ‘PATH’ variable also clears all hashed | |
3686 | filenames. The ‘-d’ option causes the shell to forget the | |
3687 | remembered location of each NAME. | |
3688 | ||
3689 | If the ‘-t’ option is supplied, ‘hash’ prints the full pathname | |
3690 | corresponding to each NAME. If multiple NAME arguments are | |
3691 | supplied with ‘-t’, ‘hash’ prints each NAME before the | |
3692 | corresponding hashed full path. The ‘-l’ option displays output in | |
3693 | a format that may be reused as input. | |
3694 | ||
3695 | If no arguments are given, or if only ‘-l’ is supplied, ‘hash’ | |
3696 | prints information about remembered commands. The ‘-t’, ‘-d’, and | |
3697 | ‘-p’ options (the options that act on the NAME arguments) are | |
3698 | mutually exclusive. Only one will be active. If more than one is | |
3699 | supplied, ‘-t’ has higher priority than ‘-p’, and both have higher | |
3700 | priority than ‘-d’. | |
3701 | ||
3702 | The return status is zero unless a NAME is not found or an invalid | |
3703 | option is supplied. | |
3704 | ||
3705 | ‘pwd’ | |
3706 | pwd [-LP] | |
3707 | ||
3708 | Print the absolute pathname of the current working directory. If | |
3709 | the ‘-P’ option is supplied, or the ‘-o physical’ option to the | |
3710 | ‘set’ builtin (*note The Set Builtin::) is enabled, the pathname | |
3711 | printed will not contain symbolic links. If the ‘-L’ option is | |
3712 | supplied, the pathname printed may contain symbolic links. The | |
3713 | return status is zero unless an error is encountered while | |
3714 | determining the name of the current directory or an invalid option | |
3715 | is supplied. | |
3716 | ||
3717 | ‘readonly’ | |
3718 | readonly [-aAf] [-p] [NAME[=VALUE]] ... | |
3719 | ||
3720 | Mark each NAME as readonly. The values of these names may not be | |
3721 | changed by subsequent assignment or unset. If the ‘-f’ option is | |
3722 | supplied, each NAME refers to a shell function. The ‘-a’ option | |
3723 | means each NAME refers to an indexed array variable; the ‘-A’ | |
3724 | option means each NAME refers to an associative array variable. If | |
3725 | both options are supplied, ‘-A’ takes precedence. If no NAME | |
3726 | arguments are supplied, or if the ‘-p’ option is supplied, print a | |
3727 | list of all readonly names. The other options may be used to | |
3728 | restrict the output to a subset of the set of readonly names. The | |
3729 | ‘-p’ option displays output in a format that may be reused as | |
3730 | input. | |
3731 | ||
3732 | ‘readonly’ allows the value of a variable to be set at the same | |
3733 | time the readonly attribute is changed by following the variable | |
3734 | name with =VALUE. This sets the value of the variable is to VALUE | |
3735 | while modifying the readonly attribute. | |
3736 | ||
3737 | The return status is zero unless an invalid option is supplied, one | |
3738 | of the NAME arguments is not a valid shell variable or function | |
3739 | name, or the ‘-f’ option is supplied with a name that is not a | |
3740 | shell function. | |
3741 | ||
3742 | ‘return’ | |
3743 | return [N] | |
3744 | ||
3745 | Stop executing a shell function or sourced file and return the | |
3746 | value N to its caller. If N is not supplied, the return value is | |
3747 | the exit status of the last command executed. If ‘return’ is | |
3748 | executed by a trap handler, the last command used to determine the | |
3749 | status is the last command executed before the trap handler. If | |
3750 | ‘return’ is executed during a ‘DEBUG’ trap, the last command used | |
3751 | to determine the status is the last command executed by the trap | |
3752 | handler before ‘return’ was invoked. | |
3753 | ||
3754 | When ‘return’ is used to terminate execution of a script being | |
3755 | executed with the ‘.’ (‘source’) builtin, it returns either N or | |
3756 | the exit status of the last command executed within the script as | |
3757 | the exit status of the script. If N is supplied, the return value | |
3758 | is its least significant 8 bits. | |
3759 | ||
3760 | Any command associated with the ‘RETURN’ trap is executed before | |
3761 | execution resumes after the function or script. | |
3762 | ||
3763 | The return status is non-zero if ‘return’ is supplied a non-numeric | |
3764 | argument or is used outside a function and not during the execution | |
3765 | of a script by ‘.’ or ‘source’. | |
3766 | ||
3767 | ‘shift’ | |
3768 | shift [N] | |
3769 | ||
3770 | Shift the positional parameters to the left by N: the positional | |
3771 | parameters from N+1 ... ‘$#’ are renamed to ‘$1’ ... ‘$#’-N. | |
3772 | Parameters represented by the numbers ‘$#’ down to ‘$#’-N+1 are | |
3773 | unset. N must be a non-negative number less than or equal to ‘$#’. | |
3774 | If N is not supplied, it is assumed to be 1. If N is zero or | |
3775 | greater than ‘$#’, the positional parameters are not changed. The | |
3776 | return status is zero unless N is greater than ‘$#’ or less than | |
3777 | zero, non-zero otherwise. | |
3778 | ||
3779 | ‘test’ | |
3780 | ‘[’ | |
3781 | test EXPR | |
3782 | ||
3783 | Evaluate a conditional expression EXPR and return a status of 0 | |
3784 | (true) or 1 (false). Each operator and operand must be a separate | |
3785 | argument. Expressions are composed of the primaries described | |
3786 | below in *note Bash Conditional Expressions::. ‘test’ does not | |
3787 | accept any options, nor does it accept and ignore an argument of | |
3788 | ‘--’ as signifying the end of options. When using the ‘[’ form, | |
3789 | the last argument to the command must be a ‘]’. | |
3790 | ||
3791 | Expressions may be combined using the following operators, listed | |
3792 | in decreasing order of precedence. The evaluation depends on the | |
3793 | number of arguments; see below. ‘test’ uses operator precedence | |
3794 | when there are five or more arguments. | |
3795 | ||
3796 | ‘! EXPR’ | |
3797 | True if EXPR is false. | |
3798 | ||
3799 | ‘( EXPR )’ | |
3800 | Returns the value of EXPR. This may be used to override | |
3801 | normal operator precedence. | |
3802 | ||
3803 | ‘EXPR1 -a EXPR2’ | |
3804 | True if both EXPR1 and EXPR2 are true. | |
3805 | ||
3806 | ‘EXPR1 -o EXPR2’ | |
3807 | True if either EXPR1 or EXPR2 is true. | |
3808 | ||
3809 | The ‘test’ and ‘[’ builtins evaluate conditional expressions using | |
3810 | a set of rules based on the number of arguments. | |
3811 | ||
3812 | 0 arguments | |
3813 | The expression is false. | |
3814 | ||
3815 | 1 argument | |
3816 | The expression is true if, and only if, the argument is not | |
3817 | null. | |
3818 | ||
3819 | 2 arguments | |
3820 | If the first argument is ‘!’, the expression is true if and | |
3821 | only if the second argument is null. If the first argument is | |
3822 | one of the unary conditional operators (*note Bash Conditional | |
3823 | Expressions::), the expression is true if the unary test is | |
3824 | true. If the first argument is not a valid unary operator, | |
3825 | the expression is false. | |
3826 | ||
3827 | 3 arguments | |
3828 | The following conditions are applied in the order listed. | |
3829 | ||
3830 | 1. If the second argument is one of the binary conditional | |
3831 | operators (*note Bash Conditional Expressions::), the | |
3832 | result of the expression is the result of the binary test | |
3833 | using the first and third arguments as operands. The | |
3834 | ‘-a’ and ‘-o’ operators are considered binary operators | |
3835 | when there are three arguments. | |
3836 | 2. If the first argument is ‘!’, the value is the negation | |
3837 | of the two-argument test using the second and third | |
3838 | arguments. | |
3839 | 3. If the first argument is exactly ‘(’ and the third | |
3840 | argument is exactly ‘)’, the result is the one-argument | |
3841 | test of the second argument. | |
3842 | 4. Otherwise, the expression is false. | |
3843 | ||
3844 | 4 arguments | |
3845 | The following conditions are applied in the order listed. | |
3846 | ||
3847 | 1. If the first argument is ‘!’, the result is the negation | |
3848 | of the three-argument expression composed of the | |
3849 | remaining arguments. | |
3850 | 2. If the first argument is exactly ‘(’ and the fourth | |
3851 | argument is exactly ‘)’, the result is the two-argument | |
3852 | test of the second and third arguments. | |
3853 | 3. Otherwise, the expression is parsed and evaluated | |
3854 | according to precedence using the rules listed above. | |
3855 | ||
3856 | 5 or more arguments | |
3857 | The expression is parsed and evaluated according to precedence | |
3858 | using the rules listed above. | |
3859 | ||
3860 | If the shell is in POSIX mode, or if the expression is part of the | |
3861 | ‘[[’ command, the ‘<’ and ‘>’ operators sort using the current | |
3862 | locale. If the shell is not in POSIX mode, the ‘test’ and ‘[’ | |
3863 | commands sort lexicographically using ASCII ordering. | |
3864 | ||
3865 | The historical operator-precedence parsing with 4 or more arguments | |
3866 | can lead to ambiguities when it encounters strings that look like | |
3867 | primaries. The POSIX standard has deprecated the ‘-a’ and ‘-o’ | |
3868 | primaries and enclosing expressions within parentheses. Scripts | |
3869 | should no longer use them. It's much more reliable to restrict | |
3870 | test invocations to a single primary, and to replace uses of ‘-a’ | |
3871 | and ‘-o’ with the shell's ‘&&’ and ‘||’ list operators. For | |
3872 | example, use | |
3873 | ||
3874 | test -n string1 && test -n string2 | |
3875 | ||
3876 | instead of | |
3877 | ||
3878 | test -n string1 -a -n string2 | |
3879 | ||
3880 | ‘times’ | |
3881 | times | |
3882 | ||
3883 | Print out the user and system times used by the shell and its | |
3884 | children. The return status is zero. | |
3885 | ||
3886 | ‘trap’ | |
3887 | trap [-lpP] [ACTION] [SIGSPEC ...] | |
3888 | ||
3889 | The ACTION is a command that is read and executed when the shell | |
3890 | receives any of the signals SIGSPEC. If ACTION is absent (and | |
3891 | there is a single SIGSPEC) or equal to ‘-’, each specified | |
3892 | SIGSPEC's disposition is reset to the value it had when the shell | |
3893 | was started. If ACTION is the null string, then the signal | |
3894 | specified by each SIGSPEC is ignored by the shell and commands it | |
3895 | invokes. | |
3896 | ||
3897 | If no arguments are supplied, ‘trap’ prints the actions associated | |
3898 | with each trapped signal as a set of ‘trap’ commands that can be | |
3899 | reused as shell input to restore the current signal dispositions. | |
3900 | ||
3901 | If ACTION is not present and ‘-p’ has been supplied, ‘trap’ | |
3902 | displays the trap commands associated with each SIGSPEC, or, if no | |
3903 | SIGSPECs are supplied, for all trapped signals, as a set of ‘trap’ | |
3904 | commands that can be reused as shell input to restore the current | |
3905 | signal dispositions. The ‘-P’ option behaves similarly, but | |
3906 | displays only the actions associated with each SIGSPEC argument. | |
3907 | ‘-P’ requires at least one SIGSPEC argument. The ‘-P’ or ‘-p’ | |
3908 | options may be used in a subshell environment (e.g., command | |
3909 | substitution) and, as long as they are used before ‘trap’ is used | |
3910 | to change a signal's handling, will display the state of its | |
3911 | parent's traps. | |
3912 | ||
3913 | The ‘-l’ option prints a list of signal names and their | |
3914 | corresponding numbers. Each SIGSPEC is either a signal name or a | |
3915 | signal number. Signal names are case insensitive and the ‘SIG’ | |
3916 | prefix is optional. If ‘-l’ is supplied with no SIGSPEC arguments, | |
3917 | it prints a list of valid signal names. | |
3918 | ||
3919 | If a SIGSPEC is ‘0’ or ‘EXIT’, ACTION is executed when the shell | |
3920 | exits. If a SIGSPEC is ‘DEBUG’, ACTION is executed before every | |
3921 | simple command, ‘for’ command, ‘case’ command, ‘select’ command, (( | |
3922 | arithmetic command, [[ conditional command, arithmetic ‘for’ | |
3923 | command, and before the first command executes in a shell function. | |
3924 | Refer to the description of the ‘extdebug’ shell option (*note The | |
3925 | Shopt Builtin::) for details of its effect on the ‘DEBUG’ trap. If | |
3926 | a SIGSPEC is ‘RETURN’, ACTION is executed each time a shell | |
3927 | function or a script executed with the ‘.’ or ‘source’ builtins | |
3928 | finishes executing. | |
3929 | ||
3930 | If a SIGSPEC is ‘ERR’, ACTION is executed whenever a pipeline | |
3931 | (which may consist of a single simple command), a list, or a | |
3932 | compound command returns a non-zero exit status, subject to the | |
3933 | following conditions. The ‘ERR’ trap is not executed if the failed | |
3934 | command is part of the command list immediately following an | |
3935 | ‘until’ or ‘while’ reserved word, part of the test following the | |
3936 | ‘if’ or ‘elif’ reserved words, part of a command executed in a ‘&&’ | |
3937 | or ‘||’ list except the command following the final ‘&&’ or ‘||’, | |
3938 | any command in a pipeline but the last, (subject to the state of | |
3939 | the ‘pipefail’ shell option), or if the command's return status is | |
3940 | being inverted using ‘!’. These are the same conditions obeyed by | |
3941 | the ‘errexit’ (‘-e’) option. | |
3942 | ||
3943 | When the shell is not interactive, signals ignored upon entry to a | |
3944 | non-interactive shell cannot be trapped or reset. Interactive | |
3945 | shells permit trapping signals ignored on entry. Trapped signals | |
3946 | that are not being ignored are reset to their original values in a | |
3947 | subshell or subshell environment when one is created. | |
3948 | ||
3949 | The return status is zero unless a SIGSPEC does not specify a valid | |
3950 | signal; non-zero otherwise. | |
3951 | ||
3952 | ‘true’ | |
3953 | true | |
3954 | ||
3955 | Does nothing, returns a 0 status. | |
3956 | ||
3957 | ‘umask’ | |
3958 | umask [-p] [-S] [MODE] | |
3959 | ||
3960 | Set the shell process's file creation mask to MODE. If MODE begins | |
3961 | with a digit, it is interpreted as an octal number; if not, it is | |
3962 | interpreted as a symbolic mode mask similar to that accepted by the | |
3963 | ‘chmod’ command. If MODE is omitted, ‘umask’ prints the current | |
3964 | value of the mask. If the ‘-S’ option is supplied without a MODE | |
3965 | argument, ‘umask’ prints the mask in a symbolic format; the default | |
3966 | output is an octal number. If the ‘-p’ option is supplied, and | |
3967 | MODE is omitted, the output is in a form that may be reused as | |
3968 | input. The return status is zero if the mode is successfully | |
3969 | changed or if no MODE argument is supplied, and non-zero otherwise. | |
3970 | ||
3971 | Note that when the mode is interpreted as an octal number, each | |
3972 | number of the umask is subtracted from ‘7’. Thus, a umask of ‘022’ | |
3973 | results in permissions of ‘755’. | |
3974 | ||
3975 | ‘unset’ | |
3976 | unset [-fnv] [NAME] | |
3977 | ||
3978 | Remove each variable or function NAME. If the ‘-v’ option is | |
3979 | given, each NAME refers to a shell variable and that variable is | |
3980 | removed. If the ‘-f’ option is given, the NAMEs refer to shell | |
3981 | functions, and the function definition is removed. If the ‘-n’ | |
3982 | option is supplied, and NAME is a variable with the ‘nameref’ | |
3983 | attribute, NAME will be unset rather than the variable it | |
3984 | references. ‘-n’ has no effect if the ‘-f’ option is supplied. If | |
3985 | no options are supplied, each NAME refers to a variable; if there | |
3986 | is no variable by that name, a function with that name, if any, is | |
3987 | unset. Readonly variables and functions may not be unset. When | |
3988 | variables or functions are removed, they are also removed from the | |
3989 | environment passed to subsequent commands. Some shell variables | |
3990 | may not be unset. Some shell variables lose their special behavior | |
3991 | if they are unset; such behavior is noted in the description of the | |
3992 | individual variables. The return status is zero unless a NAME is | |
3993 | readonly or may not be unset. | |
3994 | ||
3995 | \1f | |
3996 | File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands | |
3997 | ||
3998 | 4.2 Bash Builtin Commands | |
3999 | ========================= | |
4000 | ||
4001 | This section describes builtin commands which are unique to or have been | |
4002 | extended in Bash. Some of these commands are specified in the POSIX | |
4003 | standard. | |
4004 | ||
4005 | ‘alias’ | |
4006 | alias [-p] [NAME[=VALUE] ...] | |
4007 | ||
4008 | Without arguments or with the ‘-p’ option, ‘alias’ prints the list | |
4009 | of aliases on the standard output in a form that allows them to be | |
4010 | reused as input. If arguments are supplied, define an alias for | |
4011 | each NAME whose VALUE is given. If no VALUE is given, print the | |
4012 | name and value of the alias NAME. A trailing space in VALUE causes | |
4013 | the next word to be checked for alias substitution when the alias | |
4014 | is expanded during command parsing. ‘alias’ returns true unless a | |
4015 | NAME is given (without a corresponding =VALUE) for which no alias | |
4016 | has been defined. Aliases are described in *note Aliases::. | |
4017 | ||
4018 | ‘bind’ | |
4019 | bind [-m KEYMAP] [-lsvSVX] | |
4020 | bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ] | |
4021 | bind [-m KEYMAP] -f FILENAME | |
4022 | bind [-m KEYMAP] -x KEYSEQ[: ]SHELL-COMMAND | |
4023 | bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME | |
4024 | bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND | |
4025 | bind [-m KEYMAP] -p|-P [READLINE-COMMAND] | |
4026 | bind READLINE-COMMAND-LINE | |
4027 | ||
4028 | Display current Readline (*note Command Line Editing::) key and | |
4029 | function bindings, bind a key sequence to a Readline function or | |
4030 | macro or to a shell command, or set a Readline variable. Each | |
4031 | non-option argument is a key binding or command as it would appear | |
4032 | in a Readline initialization file (*note Readline Init File::), but | |
4033 | each binding or command must be passed as a separate argument; | |
4034 | e.g., ‘"\C-x\C-r":re-read-init-file’. | |
4035 | ||
4036 | In the following descriptions, options that display output in a | |
4037 | form available to be re-read format their output as commands that | |
4038 | would appear in a Readline initialization file or that would be | |
4039 | supplied as individual arguments to a ‘bind’ command. | |
4040 | ||
4041 | Options, if supplied, have the following meanings: | |
4042 | ||
4043 | ‘-m KEYMAP’ | |
4044 | Use KEYMAP as the keymap to be affected by the subsequent | |
4045 | bindings. Acceptable KEYMAP names are ‘emacs’, | |
4046 | ‘emacs-standard’, ‘emacs-meta’, ‘emacs-ctlx’, ‘vi’, ‘vi-move’, | |
4047 | ‘vi-command’, and ‘vi-insert’. ‘vi’ is equivalent to | |
4048 | ‘vi-command’ (‘vi-move’ is also a synonym); ‘emacs’ is | |
4049 | equivalent to ‘emacs-standard’. | |
4050 | ||
4051 | ‘-l’ | |
4052 | List the names of all Readline functions. | |
4053 | ||
4054 | ‘-p’ | |
4055 | Display Readline function names and bindings in such a way | |
4056 | that they can be used as an argument to a subsequent ‘bind’ | |
4057 | command or in a Readline initialization file. If arguments | |
4058 | remain after option processing, ‘bind’ treats them as readline | |
4059 | command names and restricts output to those names. | |
4060 | ||
4061 | ‘-P’ | |
4062 | List current Readline function names and bindings. If | |
4063 | arguments remain after option processing, ‘bind’ treats them | |
4064 | as readline command names and restricts output to those names. | |
4065 | ||
4066 | ‘-s’ | |
4067 | Display Readline key sequences bound to macros and the strings | |
4068 | they output in such a way that they can be used as an argument | |
4069 | to a subsequent ‘bind’ command or in a Readline initialization | |
4070 | file. | |
4071 | ||
4072 | ‘-S’ | |
4073 | Display Readline key sequences bound to macros and the strings | |
4074 | they output. | |
4075 | ||
4076 | ‘-v’ | |
4077 | Display Readline variable names and values in such a way that | |
4078 | they can be used as an argument to a subsequent ‘bind’ command | |
4079 | or in a Readline initialization file. | |
4080 | ||
4081 | ‘-V’ | |
4082 | List current Readline variable names and values. | |
4083 | ||
4084 | ‘-f FILENAME’ | |
4085 | Read key bindings from FILENAME. | |
4086 | ||
4087 | ‘-q FUNCTION’ | |
4088 | Display key sequences that invoke the named Readline FUNCTION. | |
4089 | ||
4090 | ‘-u FUNCTION’ | |
4091 | Unbind all key sequences bound to the named Readline FUNCTION. | |
4092 | ||
4093 | ‘-r KEYSEQ’ | |
4094 | Remove any current binding for KEYSEQ. | |
4095 | ||
4096 | ‘-x KEYSEQ:SHELL-COMMAND’ | |
4097 | Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered. | |
4098 | The separator between KEYSEQ and SHELL-COMMAND is either | |
4099 | whitespace or a colon optionally followed by whitespace. If | |
4100 | the separator is whitespace, SHELL-COMMAND must be enclosed in | |
4101 | double quotes and Readline expands any of its special | |
4102 | backslash-escapes in SHELL-COMMAND before saving it. If the | |
4103 | separator is a colon, any enclosing double quotes are | |
4104 | optional, and Readline does not expand the command string | |
4105 | before saving it. Since the entire key binding expression | |
4106 | must be a single argument, it should be enclosed in single | |
4107 | quotes. When SHELL-COMMAND is executed, the shell sets the | |
4108 | ‘READLINE_LINE’ variable to the contents of the Readline line | |
4109 | buffer and the ‘READLINE_POINT’ and ‘READLINE_MARK’ variables | |
4110 | to the current location of the insertion point and the saved | |
4111 | insertion point (the MARK), respectively. The shell assigns | |
4112 | any numeric argument the user supplied to the | |
4113 | ‘READLINE_ARGUMENT’ variable. If there was no argument, that | |
4114 | variable is not set. If the executed command changes the | |
4115 | value of any of ‘READLINE_LINE’, ‘READLINE_POINT’, or | |
4116 | ‘READLINE_MARK’, those new values will be reflected in the | |
4117 | editing state. | |
4118 | ||
4119 | ‘-X’ | |
4120 | List all key sequences bound to shell commands and the | |
4121 | associated commands in a format that can be reused as an | |
4122 | argument to a subsequent ‘bind’ command. | |
4123 | ||
4124 | The return status is zero unless an invalid option is supplied or | |
4125 | an error occurs. | |
4126 | ||
4127 | ‘builtin’ | |
4128 | builtin [SHELL-BUILTIN [ARGS]] | |
4129 | ||
4130 | Execute the specified shell builtin SHELL-BUILTIN, passing it ARGS, | |
4131 | and return its exit status. This is useful when defining a shell | |
4132 | function with the same name as a shell builtin, retaining the | |
4133 | functionality of the builtin within the function. The return | |
4134 | status is non-zero if SHELL-BUILTIN is not a shell builtin command. | |
4135 | ||
4136 | ‘caller’ | |
4137 | caller [EXPR] | |
4138 | ||
4139 | Returns the context of any active subroutine call (a shell function | |
4140 | or a script executed with the ‘.’ or ‘source’ builtins). | |
4141 | ||
4142 | Without EXPR, ‘caller’ displays the line number and source filename | |
4143 | of the current subroutine call. If a non-negative integer is | |
4144 | supplied as EXPR, ‘caller’ displays the line number, subroutine | |
4145 | name, and source file corresponding to that position in the current | |
4146 | execution call stack. This extra information may be used, for | |
4147 | example, to print a stack trace. The current frame is frame 0. | |
4148 | ||
4149 | The return value is 0 unless the shell is not executing a | |
4150 | subroutine call or EXPR does not correspond to a valid position in | |
4151 | the call stack. | |
4152 | ||
4153 | ‘command’ | |
4154 | command [-pVv] COMMAND [ARGUMENTS ...] | |
4155 | ||
4156 | The ‘command’ builtin runs COMMAND with ARGUMENTS ignoring any | |
4157 | shell function named COMMAND. Only shell builtin commands or | |
4158 | commands found by searching the ‘PATH’ are executed. If there is a | |
4159 | shell function named ‘ls’, running ‘command ls’ within the function | |
4160 | will execute the external command ‘ls’ instead of calling the | |
4161 | function recursively. The ‘-p’ option means to use a default value | |
4162 | for ‘PATH’ that is guaranteed to find all of the standard | |
4163 | utilities. The return status in this case is 127 if COMMAND cannot | |
4164 | be found or an error occurred, and the exit status of COMMAND | |
4165 | otherwise. | |
4166 | ||
4167 | If either the ‘-V’ or ‘-v’ option is supplied, ‘command’ prints a | |
4168 | description of COMMAND. The ‘-v’ option displays a single word | |
4169 | indicating the command or file name used to invoke COMMAND; the | |
4170 | ‘-V’ option produces a more verbose description. In this case, the | |
4171 | return status is zero if COMMAND is found, and non-zero if not. | |
4172 | ||
4173 | ‘declare’ | |
4174 | declare [-aAfFgiIlnrtux] [-p] [NAME[=VALUE] ...] | |
4175 | ||
4176 | Declare variables and give them attributes. If no NAMEs are given, | |
4177 | then display the values of variables or shell functions instead. | |
4178 | ||
4179 | The ‘-p’ option will display the attributes and values of each | |
4180 | NAME. When ‘-p’ is used with NAME arguments, additional options, | |
4181 | other than ‘-f’ and ‘-F’, are ignored. | |
4182 | ||
4183 | When ‘-p’ is supplied without NAME arguments, ‘declare’ will | |
4184 | display the attributes and values of all variables having the | |
4185 | attributes specified by the additional options. If no other | |
4186 | options are supplied with ‘-p’, ‘declare’ will display the | |
4187 | attributes and values of all shell variables. The ‘-f’ option | |
4188 | restricts the display to shell functions. | |
4189 | ||
4190 | The ‘-F’ option inhibits the display of function definitions; only | |
4191 | the function name and attributes are printed. If the ‘extdebug’ | |
4192 | shell option is enabled using ‘shopt’ (*note The Shopt Builtin::), | |
4193 | the source file name and line number where each NAME is defined are | |
4194 | displayed as well. ‘-F’ implies ‘-f’. | |
4195 | ||
4196 | The ‘-g’ option forces variables to be created or modified at the | |
4197 | global scope, even when ‘declare’ is executed in a shell function. | |
4198 | It is ignored in when ‘declare’ is not executed in a shell | |
4199 | function. | |
4200 | ||
4201 | The ‘-I’ option causes local variables to inherit the attributes | |
4202 | (except the ‘nameref’ attribute) and value of any existing variable | |
4203 | with the same NAME at a surrounding scope. If there is no existing | |
4204 | variable, the local variable is initially unset. | |
4205 | ||
4206 | The following options can be used to restrict output to variables | |
4207 | with the specified attributes or to give variables attributes: | |
4208 | ||
4209 | ‘-a’ | |
4210 | Each NAME is an indexed array variable (*note Arrays::). | |
4211 | ||
4212 | ‘-A’ | |
4213 | Each NAME is an associative array variable (*note Arrays::). | |
4214 | ||
4215 | ‘-f’ | |
4216 | Each NAME refers to a shell function. | |
4217 | ||
4218 | ‘-i’ | |
4219 | The variable is to be treated as an integer; arithmetic | |
4220 | evaluation (*note Shell Arithmetic::) is performed when the | |
4221 | variable is assigned a value. | |
4222 | ||
4223 | ‘-l’ | |
4224 | When the variable is assigned a value, all upper-case | |
4225 | characters are converted to lower-case. The upper-case | |
4226 | attribute is disabled. | |
4227 | ||
4228 | ‘-n’ | |
4229 | Give each NAME the ‘nameref’ attribute, making it a name | |
4230 | reference to another variable. That other variable is defined | |
4231 | by the value of NAME. All references, assignments, and | |
4232 | attribute modifications to NAME, except for those using or | |
4233 | changing the ‘-n’ attribute itself, are performed on the | |
4234 | variable referenced by NAME's value. The nameref attribute | |
4235 | cannot be applied to array variables. | |
4236 | ||
4237 | ‘-r’ | |
4238 | Make NAMEs readonly. These names cannot then be assigned | |
4239 | values by subsequent assignment statements or unset. | |
4240 | ||
4241 | ‘-t’ | |
4242 | Give each NAME the ‘trace’ attribute. Traced functions | |
4243 | inherit the ‘DEBUG’ and ‘RETURN’ traps from the calling shell. | |
4244 | The trace attribute has no special meaning for variables. | |
4245 | ||
4246 | ‘-u’ | |
4247 | When the variable is assigned a value, all lower-case | |
4248 | characters are converted to upper-case. The lower-case | |
4249 | attribute is disabled. | |
4250 | ||
4251 | ‘-x’ | |
4252 | Mark each NAME for export to subsequent commands via the | |
4253 | environment. | |
4254 | ||
4255 | Using ‘+’ instead of ‘-’ turns off the specified attribute instead, | |
4256 | with the exceptions that ‘+a’ and ‘+A’ may not be used to destroy | |
4257 | array variables and ‘+r’ will not remove the readonly attribute. | |
4258 | ||
4259 | When used in a function, ‘declare’ makes each NAME local, as with | |
4260 | the ‘local’ command, unless the ‘-g’ option is supplied. If a | |
4261 | variable name is followed by =VALUE, the value of the variable is | |
4262 | set to VALUE. | |
4263 | ||
4264 | When using ‘-a’ or ‘-A’ and the compound assignment syntax to | |
4265 | create array variables, additional attributes do not take effect | |
4266 | until subsequent assignments. | |
4267 | ||
4268 | The return status is zero unless an invalid option is encountered, | |
4269 | an attempt is made to define a function using ‘-f foo=bar’, an | |
4270 | attempt is made to assign a value to a readonly variable, an | |
4271 | attempt is made to assign a value to an array variable without | |
4272 | using the compound assignment syntax (*note Arrays::), one of the | |
4273 | NAMEs is not a valid shell variable name, an attempt is made to | |
4274 | turn off readonly status for a readonly variable, an attempt is | |
4275 | made to turn off array status for an array variable, or an attempt | |
4276 | is made to display a non-existent function with ‘-f’. | |
4277 | ||
4278 | ‘echo’ | |
4279 | echo [-neE] [ARG ...] | |
4280 | ||
4281 | Output the ARGs, separated by spaces, terminated with a newline. | |
4282 | The return status is 0 unless a write error occurs. If ‘-n’ is | |
4283 | specified, the trailing newline is not printed. | |
4284 | ||
4285 | If the ‘-e’ option is given, ‘echo’ interprets the following | |
4286 | backslash-escaped characters. The ‘-E’ option disables | |
4287 | interpretation of these escape characters, even on systems where | |
4288 | they are interpreted by default. The ‘xpg_echo’ shell option | |
4289 | determines whether or not ‘echo’ interprets any options and expands | |
4290 | these escape characters. ‘echo’ does not interpret ‘--’ to mean | |
4291 | the end of options. | |
4292 | ||
4293 | ‘echo’ interprets the following escape sequences: | |
4294 | ‘\a’ | |
4295 | alert (bell) | |
4296 | ‘\b’ | |
4297 | backspace | |
4298 | ‘\c’ | |
4299 | suppress further output | |
4300 | ‘\e’ | |
4301 | ‘\E’ | |
4302 | escape | |
4303 | ‘\f’ | |
4304 | form feed | |
4305 | ‘\n’ | |
4306 | new line | |
4307 | ‘\r’ | |
4308 | carriage return | |
4309 | ‘\t’ | |
4310 | horizontal tab | |
4311 | ‘\v’ | |
4312 | vertical tab | |
4313 | ‘\\’ | |
4314 | backslash | |
4315 | ‘\0NNN’ | |
4316 | The eight-bit character whose value is the octal value NNN | |
4317 | (zero to three octal digits). | |
4318 | ‘\xHH’ | |
4319 | The eight-bit character whose value is the hexadecimal value | |
4320 | HH (one or two hex digits). | |
4321 | ‘\uHHHH’ | |
4322 | The Unicode (ISO/IEC 10646) character whose value is the | |
4323 | hexadecimal value HHHH (one to four hex digits). | |
4324 | ‘\UHHHHHHHH’ | |
4325 | The Unicode (ISO/IEC 10646) character whose value is the | |
4326 | hexadecimal value HHHHHHHH (one to eight hex digits). | |
4327 | ||
4328 | ‘echo’ writes any unrecognized backslash-escaped characters | |
4329 | unchanged. | |
4330 | ||
4331 | ‘enable’ | |
4332 | enable [-a] [-dnps] [-f FILENAME] [NAME ...] | |
4333 | ||
4334 | Enable and disable builtin shell commands. Disabling a builtin | |
4335 | allows an executable file which has the same name as a shell | |
4336 | builtin to be executed without specifying a full pathname, even | |
4337 | though the shell normally searches for builtins before files. | |
4338 | ||
4339 | If ‘-n’ is supplied, the NAMEs are disabled. Otherwise NAMEs are | |
4340 | enabled. For example, to use the ‘test’ binary found using ‘$PATH’ | |
4341 | instead of the shell builtin version, type ‘enable -n test’. | |
4342 | ||
4343 | If the ‘-p’ option is supplied, or no NAME arguments are supplied, | |
4344 | print a list of shell builtins. With no other arguments, the list | |
4345 | consists of all enabled shell builtins. The ‘-n’ option means to | |
4346 | print only disabled builtins. The ‘-a’ option means to list each | |
4347 | builtin with an indication of whether or not it is enabled. The | |
4348 | ‘-s’ option means to restrict ‘enable’ to the POSIX special | |
4349 | builtins. | |
4350 | ||
4351 | The ‘-f’ option means to load the new builtin command NAME from | |
4352 | shared object FILENAME, on systems that support dynamic loading. | |
4353 | If FILENAME does not contain a slash. Bash will use the value of | |
4354 | the ‘BASH_LOADABLES_PATH’ variable as a colon-separated list of | |
4355 | directories in which to search for FILENAME. The default for | |
4356 | ‘BASH_LOADABLES_PATH’ is system-dependent, and may include "." to | |
4357 | force a search of the current directory. The ‘-d’ option will | |
4358 | delete a builtin loaded with ‘-f’. If ‘-s’ is used with ‘-f’, the | |
4359 | new builtin becomes a POSIX special builtin (*note Special | |
4360 | Builtins::). | |
4361 | ||
4362 | If no options are supplied and a NAME is not a shell builtin, | |
4363 | ‘enable’ will attempt to load NAME from a shared object named NAME, | |
4364 | as if the command were ‘enable -f NAME NAME’. | |
4365 | ||
4366 | The return status is zero unless a NAME is not a shell builtin or | |
4367 | there is an error loading a new builtin from a shared object. | |
4368 | ||
4369 | ‘help’ | |
4370 | help [-dms] [PATTERN] | |
4371 | ||
4372 | Display helpful information about builtin commands. If PATTERN is | |
4373 | specified, ‘help’ gives detailed help on all commands matching | |
4374 | PATTERN as described below; otherwise it displays a list of all | |
4375 | builtins and shell compound commands. | |
4376 | ||
4377 | Options, if supplied, have the following meanings: | |
4378 | ||
4379 | ‘-d’ | |
4380 | Display a short description of each PATTERN | |
4381 | ‘-m’ | |
4382 | Display the description of each PATTERN in a manpage-like | |
4383 | format | |
4384 | ‘-s’ | |
4385 | Display only a short usage synopsis for each PATTERN | |
4386 | ||
4387 | If PATTERN contains pattern matching characters (*note Pattern | |
4388 | Matching::) it's treated as a shell pattern and ‘help’ prints the | |
4389 | description of each help topic matching PATTERN. | |
4390 | ||
4391 | If not, and PATTERN exactly matches the name of a help topic, | |
4392 | ‘help’ prints the description associated with that topic. | |
4393 | Otherwise, ‘help’ performs prefix matching and prints the | |
4394 | descriptions of all matching help topics. | |
4395 | ||
4396 | The return status is zero unless no command matches PATTERN. | |
4397 | ||
4398 | ‘let’ | |
4399 | let EXPRESSION [EXPRESSION ...] | |
4400 | ||
4401 | The ‘let’ builtin allows arithmetic to be performed on shell | |
4402 | variables. Each EXPRESSION is evaluated as an arithmetic | |
4403 | expression according to the rules given below in *note Shell | |
4404 | Arithmetic::. If the last EXPRESSION evaluates to 0, ‘let’ returns | |
4405 | 1; otherwise ‘let’ returns 0. | |
4406 | ||
4407 | ‘local’ | |
4408 | local [OPTION] NAME[=VALUE] ... | |
4409 | ||
4410 | For each argument, create a local variable named NAME, and assign | |
4411 | it VALUE. The OPTION can be any of the options accepted by | |
4412 | ‘declare’. ‘local’ can only be used within a function; it makes | |
4413 | the variable NAME have a visible scope restricted to that function | |
4414 | and its children. It is an error to use ‘local’ when not within a | |
4415 | function. | |
4416 | ||
4417 | If NAME is ‘-’, it makes the set of shell options local to the | |
4418 | function in which ‘local’ is invoked: any shell options changed | |
4419 | using the ‘set’ builtin inside the function after the call to | |
4420 | ‘local’ are restored to their original values when the function | |
4421 | returns. The restore is performed as if a series of ‘set’ commands | |
4422 | were executed to restore the values that were in place before the | |
4423 | function. | |
4424 | ||
4425 | With no operands, ‘local’ writes a list of local variables to the | |
4426 | standard output. | |
4427 | ||
4428 | The return status is zero unless ‘local’ is used outside a | |
4429 | function, an invalid NAME is supplied, or NAME is a readonly | |
4430 | variable. | |
4431 | ||
4432 | ‘logout’ | |
4433 | logout [N] | |
4434 | ||
4435 | Exit a login shell, returning a status of N to the shell's parent. | |
4436 | ||
4437 | ‘mapfile’ | |
4438 | mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] | |
4439 | [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY] | |
4440 | ||
4441 | Read lines from the standard input, or from file descriptor FD if | |
4442 | the ‘-u’ option is supplied, into the indexed array variable ARRAY. | |
4443 | The variable ‘MAPFILE’ is the default ARRAY. Options, if supplied, | |
4444 | have the following meanings: | |
4445 | ||
4446 | ‘-d’ | |
4447 | Use the first character of DELIM to terminate each input line, | |
4448 | rather than newline. If DELIM is the empty string, ‘mapfile’ | |
4449 | will terminate a line when it reads a NUL character. | |
4450 | ‘-n’ | |
4451 | Copy at most COUNT lines. If COUNT is 0, copy all lines. | |
4452 | ‘-O’ | |
4453 | Begin assigning to ARRAY at index ORIGIN. The default index | |
4454 | is 0. | |
4455 | ‘-s’ | |
4456 | Discard the first COUNT lines read. | |
4457 | ‘-t’ | |
4458 | Remove a trailing DELIM (default newline) from each line read. | |
4459 | ‘-u’ | |
4460 | Read lines from file descriptor FD instead of the standard | |
4461 | input. | |
4462 | ‘-C’ | |
4463 | Evaluate CALLBACK each time QUANTUM lines are read. The ‘-c’ | |
4464 | option specifies QUANTUM. | |
4465 | ‘-c’ | |
4466 | Specify the number of lines read between each call to | |
4467 | CALLBACK. | |
4468 | ||
4469 | If ‘-C’ is specified without ‘-c’, the default quantum is 5000. | |
4470 | When CALLBACK is evaluated, it is supplied the index of the next | |
4471 | array element to be assigned and the line to be assigned to that | |
4472 | element as additional arguments. CALLBACK is evaluated after the | |
4473 | line is read but before the array element is assigned. | |
4474 | ||
4475 | If not supplied with an explicit origin, ‘mapfile’ will clear ARRAY | |
4476 | before assigning to it. | |
4477 | ||
4478 | ‘mapfile’ returns zero unless an invalid option or option argument | |
4479 | is supplied, ARRAY is invalid or unassignable, or if ARRAY is not | |
4480 | an indexed array. | |
4481 | ||
4482 | ‘printf’ | |
4483 | printf [-v VAR] FORMAT [ARGUMENTS] | |
4484 | ||
4485 | Write the formatted ARGUMENTS to the standard output under the | |
4486 | control of the FORMAT. The ‘-v’ option assigns the output to the | |
4487 | variable VAR rather than printing it to the standard output. | |
4488 | ||
4489 | The FORMAT is a character string which contains three types of | |
4490 | objects: plain characters, which are simply copied to standard | |
4491 | output, character escape sequences, which are converted and copied | |
4492 | to the standard output, and format specifications, each of which | |
4493 | causes printing of the next successive ARGUMENT. In addition to | |
4494 | the standard ‘printf(3)’ format characters ‘cCsSndiouxXeEfFgGaA’, | |
4495 | ‘printf’ interprets the following additional format specifiers: | |
4496 | ||
4497 | ‘%b’ | |
4498 | Causes ‘printf’ to expand backslash escape sequences in the | |
4499 | corresponding ARGUMENT in the same way as ‘echo -e’ (*note | |
4500 | Bash Builtins::). | |
4501 | ‘%q’ | |
4502 | Causes ‘printf’ to output the corresponding ARGUMENT in a | |
4503 | format that can be reused as shell input. ‘%q’ and ‘%Q’P use | |
4504 | the ANSI-C quoting style (*note ANSI-C Quoting::) if any | |
4505 | characters in the argument string require it, and backslash | |
4506 | quoting otherwise. If the format string uses the ‘printf’ | |
4507 | _alternate form_, these two formats quote the argument string | |
4508 | using single quotes. | |
4509 | ||
4510 | ‘%Q’ | |
4511 | like ‘%q’, but applies any supplied precision to the ARGUMENT | |
4512 | before quoting it. | |
4513 | ||
4514 | ‘%(DATEFMT)T’ | |
4515 | Causes ‘printf’ to output the date-time string resulting from | |
4516 | using DATEFMT as a format string for ‘strftime’(3). The | |
4517 | corresponding ARGUMENT is an integer representing the number | |
4518 | of seconds since the epoch. This format specifier recognizes | |
4519 | Two special argument values: -1 represents the current time, | |
4520 | and -2 represents the time the shell was invoked. If no | |
4521 | argument is specified, conversion behaves as if -1 had been | |
4522 | supplied. This is an exception to the usual ‘printf’ | |
4523 | behavior. | |
4524 | ||
4525 | The %b, %q, and %T format specifiers all use the field width and | |
4526 | precision arguments from the format specification and write that | |
4527 | many bytes from (or use that wide a field for) the expanded | |
4528 | argument, which usually contains more characters than the original. | |
4529 | ||
4530 | The %n format specifier accepts a corresponding argument that is | |
4531 | treated as a shell variable name. | |
4532 | ||
4533 | The %s and %c format specifiers accept an l (long) modifier, which | |
4534 | forces them to convert the argument string to a wide-character | |
4535 | string and apply any supplied field width and precision in terms of | |
4536 | characters, not bytes. The %S and %C format specifiers are | |
4537 | equivalent to %ls and %lc, respectively. | |
4538 | ||
4539 | Arguments to non-string format specifiers are treated as C language | |
4540 | constants, except that a leading plus or minus sign is allowed, and | |
4541 | if the leading character is a single or double quote, the value is | |
4542 | the numeric value of the following character, using the current | |
4543 | locale. | |
4544 | ||
4545 | The FORMAT is reused as necessary to consume all of the ARGUMENTS. | |
4546 | If the FORMAT requires more ARGUMENTS than are supplied, the extra | |
4547 | format specifications behave as if a zero value or null string, as | |
4548 | appropriate, had been supplied. The return value is zero on | |
4549 | success, non-zero if an invalid option is supplied or a write or | |
4550 | assignment error occurs. | |
4551 | ||
4552 | ‘read’ | |
4553 | read [-Eers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] | |
4554 | [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...] | |
4555 | ||
4556 | Read one line from the standard input, or from the file descriptor | |
4557 | FD supplied as an argument to the ‘-u’ option, split it into words | |
4558 | as described above in *note Word Splitting::, and assign the first | |
4559 | word to the first NAME, the second word to the second NAME, and so | |
4560 | on. If there are more words than names, the remaining words and | |
4561 | their intervening delimiters are assigned to the last NAME. If | |
4562 | there are fewer words read from the input stream than names, the | |
4563 | remaining names are assigned empty values. The characters in the | |
4564 | value of the ‘IFS’ variable are used to split the line into words | |
4565 | using the same rules the shell uses for expansion (described above | |
4566 | in *note Word Splitting::). The backslash character ‘\’ removes | |
4567 | any special meaning for the next character read and is used for | |
4568 | line continuation. | |
4569 | ||
4570 | Options, if supplied, have the following meanings: | |
4571 | ||
4572 | ‘-a ANAME’ | |
4573 | The words are assigned to sequential indices of the array | |
4574 | variable ANAME, starting at 0. All elements are removed from | |
4575 | ANAME before the assignment. Other NAME arguments are | |
4576 | ignored. | |
4577 | ||
4578 | ‘-d DELIM’ | |
4579 | The first character of DELIM terminates the input line, rather | |
4580 | than newline. If DELIM is the empty string, ‘read’ will | |
4581 | terminate a line when it reads a NUL character. | |
4582 | ||
4583 | ‘-e’ | |
4584 | If the standard input is coming from a terminal, ‘read’ uses | |
4585 | Readline (*note Command Line Editing::) to obtain the line. | |
4586 | Readline uses the current (or default, if line editing was not | |
4587 | previously active) editing settings, but uses Readline's | |
4588 | default filename completion. | |
4589 | ||
4590 | ‘-E’ | |
4591 | If the standard input is coming from a terminal, ‘read’ uses | |
4592 | Readline (*note Command Line Editing::) to obtain the line. | |
4593 | Readline uses the current (or default, if line editing was not | |
4594 | previously active) editing settings, but uses Bash's default | |
4595 | completion, including programmable completion. | |
4596 | ||
4597 | ‘-i TEXT’ | |
4598 | If Readline is being used to read the line, ‘read’ places TEXT | |
4599 | into the editing buffer before editing begins. | |
4600 | ||
4601 | ‘-n NCHARS’ | |
4602 | ‘read’ returns after reading NCHARS characters rather than | |
4603 | waiting for a complete line of input, unless it encounters EOF | |
4604 | or ‘read’ times out, but honors a delimiter if it reads fewer | |
4605 | than NCHARS characters before the delimiter. | |
4606 | ||
4607 | ‘-N NCHARS’ | |
4608 | ‘read’ returns after reading exactly NCHARS characters rather | |
4609 | than waiting for a complete line of input, unless it | |
4610 | encounters EOF or ‘read’ times out. Delimiter characters in | |
4611 | the input are not treated specially and do not cause ‘read’ to | |
4612 | return until it has read NCHARS characters. The result is not | |
4613 | split on the characters in ‘IFS’; the intent is that the | |
4614 | variable is assigned exactly the characters read (with the | |
4615 | exception of backslash; see the ‘-r’ option below). | |
4616 | ||
4617 | ‘-p PROMPT’ | |
4618 | Display PROMPT, without a trailing newline, before attempting | |
4619 | to read any input, but only if input is coming from a | |
4620 | terminal. | |
4621 | ||
4622 | ‘-r’ | |
4623 | If this option is given, backslash does not act as an escape | |
4624 | character. The backslash is considered to be part of the | |
4625 | line. In particular, a backslash-newline pair may not then be | |
4626 | used as a line continuation. | |
4627 | ||
4628 | ‘-s’ | |
4629 | Silent mode. If input is coming from a terminal, characters | |
4630 | are not echoed. | |
4631 | ||
4632 | ‘-t TIMEOUT’ | |
4633 | Cause ‘read’ to time out and return failure if it does not | |
4634 | read a complete line of input (or a specified number of | |
4635 | characters) within TIMEOUT seconds. TIMEOUT may be a decimal | |
4636 | number with a fractional portion following the decimal point. | |
4637 | This option is only effective if ‘read’ is reading input from | |
4638 | a terminal, pipe, or other special file; it has no effect when | |
4639 | reading from regular files. If ‘read’ times out, it saves any | |
4640 | partial input read into the specified variable NAME, and | |
4641 | returns a status greater than 128. If TIMEOUT is 0, ‘read’ | |
4642 | returns immediately, without trying to read any data. In this | |
4643 | case, the exit status is 0 if input is available on the | |
4644 | specified file descriptor, or the read will return EOF, | |
4645 | non-zero otherwise. | |
4646 | ||
4647 | ‘-u FD’ | |
4648 | Read input from file descriptor FD instead of the standard | |
4649 | input. | |
4650 | ||
4651 | Other than the case where DELIM is the empty string, ‘read’ ignores | |
4652 | any NUL characters in the input. | |
4653 | ||
4654 | If no NAMEs are supplied, ‘read’ assigns the line read, without the | |
4655 | ending delimiter but otherwise unmodified, to the variable ‘REPLY’. | |
4656 | ||
4657 | The exit status is zero, unless end-of-file is encountered, ‘read’ | |
4658 | times out (in which case the status is greater than 128), a | |
4659 | variable assignment error (such as assigning to a readonly | |
4660 | variable) occurs, or an invalid file descriptor is supplied as the | |
4661 | argument to ‘-u’. | |
4662 | ||
4663 | ‘readarray’ | |
4664 | readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] | |
4665 | [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY] | |
4666 | ||
4667 | Read lines from the standard input into the indexed array variable | |
4668 | ARRAY, or from file descriptor FD if the ‘-u’ option is supplied. | |
4669 | ||
4670 | A synonym for ‘mapfile’. | |
4671 | ||
4672 | ‘source’ | |
4673 | source [-p PATH] FILENAME [ARGUMENTS] | |
4674 | ||
4675 | A synonym for ‘.’ (*note Bourne Shell Builtins::). | |
4676 | ||
4677 | ‘type’ | |
4678 | type [-afptP] [NAME ...] | |
4679 | ||
4680 | Indicate how each NAME would be interpreted if used as a command | |
4681 | name. | |
4682 | ||
4683 | If the ‘-t’ option is used, ‘type’ prints a single word which is | |
4684 | one of ‘alias’, ‘keyword’, ‘function’, ‘builtin’, or ‘file’, if | |
4685 | NAME is an alias, shell reserved word, shell function, shell | |
4686 | builtin, or executable file, respectively. If the NAME is not | |
4687 | found, ‘type’ prints nothing and returns a failure status. | |
4688 | ||
4689 | If the ‘-p’ option is used, ‘type’ either returns the name of the | |
4690 | executable file that would be found by searching ‘$PATH’ for | |
4691 | ‘name’, or nothing if ‘-t’ would not return ‘file’. | |
4692 | ||
4693 | The ‘-P’ option forces a path search for each NAME, even if ‘-t’ | |
4694 | would not return ‘file’. | |
4695 | ||
4696 | If a NAME is present in the table of hashed commands, options ‘-p’ | |
4697 | and ‘-P’ print the hashed value, which is not necessarily the file | |
4698 | that appears first in ‘$PATH’. | |
4699 | ||
4700 | If the ‘-a’ option is used, ‘type’ returns all of the places that | |
4701 | contain a command named NAME. This includes aliases, reserved | |
4702 | words, functions, and builtins, but the path search options (‘-p’ | |
4703 | and ‘-P’) can be supplied to restrict the output to executable | |
4704 | files. If ‘-a’ is supplied with ‘-p’, ‘type’ does not look in the | |
4705 | table of hashed commands, and only performs a ‘PATH’ search for | |
4706 | NAME. | |
4707 | ||
4708 | If the ‘-f’ option is used, ‘type’ does not attempt to find shell | |
4709 | functions, as with the ‘command’ builtin. | |
4710 | ||
4711 | The return status is zero if all of the NAMEs are found, non-zero | |
4712 | if any are not found. | |
4713 | ||
4714 | ‘typeset’ | |
4715 | typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...] | |
4716 | ||
4717 | The ‘typeset’ command is supplied for compatibility with the Korn | |
4718 | shell. It is a synonym for the ‘declare’ builtin command. | |
4719 | ||
4720 | ‘ulimit’ | |
4721 | ulimit [-HS] -a | |
4722 | ulimit [-HS] [-bcdefiklmnpqrstuvxPRT] [LIMIT] | |
4723 | ||
4724 | ‘ulimit’ provides control over the resources available to the shell | |
4725 | and to processes it starts, on systems that allow such control. If | |
4726 | an option is given, it is interpreted as follows: | |
4727 | ||
4728 | ‘-S’ | |
4729 | Change and report the soft limit associated with a resource. | |
4730 | ||
4731 | ‘-H’ | |
4732 | Change and report the hard limit associated with a resource. | |
4733 | ||
4734 | ‘-a’ | |
4735 | Report all current limits; no limits are set. | |
4736 | ||
4737 | ‘-b’ | |
4738 | The maximum socket buffer size. | |
4739 | ||
4740 | ‘-c’ | |
4741 | The maximum size of core files created. | |
4742 | ||
4743 | ‘-d’ | |
4744 | The maximum size of a process's data segment. | |
4745 | ||
4746 | ‘-e’ | |
4747 | The maximum scheduling priority ("nice"). | |
4748 | ||
4749 | ‘-f’ | |
4750 | The maximum size of files written by the shell and its | |
4751 | children. | |
4752 | ||
4753 | ‘-i’ | |
4754 | The maximum number of pending signals. | |
4755 | ||
4756 | ‘-k’ | |
4757 | The maximum number of kqueues that may be allocated. | |
4758 | ||
4759 | ‘-l’ | |
4760 | The maximum size that may be locked into memory. | |
4761 | ||
4762 | ‘-m’ | |
4763 | The maximum resident set size (many systems do not honor this | |
4764 | limit). | |
4765 | ||
4766 | ‘-n’ | |
4767 | The maximum number of open file descriptors (most systems do | |
4768 | not allow this value to be set). | |
4769 | ||
4770 | ‘-p’ | |
4771 | The pipe buffer size. | |
4772 | ||
4773 | ‘-q’ | |
4774 | The maximum number of bytes in POSIX message queues. | |
4775 | ||
4776 | ‘-r’ | |
4777 | The maximum real-time scheduling priority. | |
4778 | ||
4779 | ‘-s’ | |
4780 | The maximum stack size. | |
4781 | ||
4782 | ‘-t’ | |
4783 | The maximum amount of cpu time in seconds. | |
4784 | ||
4785 | ‘-u’ | |
4786 | The maximum number of processes available to a single user. | |
4787 | ||
4788 | ‘-v’ | |
4789 | The maximum amount of virtual memory available to the shell, | |
4790 | and, on some systems, to its children. | |
4791 | ||
4792 | ‘-x’ | |
4793 | The maximum number of file locks. | |
4794 | ||
4795 | ‘-P’ | |
4796 | The maximum number of pseudoterminals. | |
4797 | ||
4798 | ‘-R’ | |
4799 | The maximum time a real-time process can run before blocking, | |
4800 | in microseconds. | |
4801 | ||
4802 | ‘-T’ | |
4803 | The maximum number of threads. | |
4804 | ||
4805 | If LIMIT is supplied, and the ‘-a’ option is not used, LIMIT is the | |
4806 | new value of the specified resource. The special LIMIT values | |
4807 | ‘hard’, ‘soft’, and ‘unlimited’ stand for the current hard limit, | |
4808 | the current soft limit, and no limit, respectively. A hard limit | |
4809 | cannot be increased by a non-root user once it is set; a soft limit | |
4810 | may be increased up to the value of the hard limit. Otherwise, | |
4811 | ‘ulimit’ prints the current value of the soft limit for the | |
4812 | specified resource, unless the ‘-H’ option is supplied. When more | |
4813 | than one resource is specified, the limit name and unit, if | |
4814 | appropriate, are printed before the value. When setting new | |
4815 | limits, if neither ‘-H’ nor ‘-S’ is supplied, ‘ulimit’ sets both | |
4816 | the hard and soft limits. If no option is supplied, then ‘-f’ is | |
4817 | assumed. | |
4818 | ||
4819 | Values are in 1024-byte increments, except for ‘-t’, which is in | |
4820 | seconds; ‘-R’, which is in microseconds; ‘-p’, which is in units of | |
4821 | 512-byte blocks; ‘-P’, ‘-T’, ‘-b’, ‘-k’, ‘-n’ and ‘-u’, which are | |
4822 | unscaled values; and, when in POSIX mode (*note Bash POSIX Mode::), | |
4823 | ‘-c’ and ‘-f’, which are in 512-byte increments. | |
4824 | ||
4825 | The return status is zero unless an invalid option or argument is | |
4826 | supplied, or an error occurs while setting a new limit. | |
4827 | ||
4828 | ‘unalias’ | |
4829 | unalias [-a] [NAME ... ] | |
4830 | ||
4831 | Remove each NAME from the list of aliases. If ‘-a’ is supplied, | |
4832 | remove all aliases. The return value is true unless a supplied | |
4833 | NAME is not a defined alias. Aliases are described in *note | |
4834 | Aliases::. | |
4835 | ||
4836 | \1f | |
4837 | File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands | |
4838 | ||
4839 | 4.3 Modifying Shell Behavior | |
4840 | ============================ | |
4841 | ||
4842 | * Menu: | |
4843 | ||
4844 | * The Set Builtin:: Change the values of shell attributes and | |
4845 | positional parameters. | |
4846 | * The Shopt Builtin:: Modify shell optional behavior. | |
4847 | ||
4848 | \1f | |
4849 | File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior | |
4850 | ||
4851 | 4.3.1 The Set Builtin | |
4852 | --------------------- | |
4853 | ||
4854 | This builtin is so complicated that it deserves its own section. ‘set’ | |
4855 | allows you to change the values of shell options and set the positional | |
4856 | parameters, or to display the names and values of shell variables. | |
4857 | ||
4858 | ‘set’ | |
4859 | set [-abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [--] [-] [ARGUMENT ...] | |
4860 | set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [--] [-] [ARGUMENT ...] | |
4861 | set -o | |
4862 | set +o | |
4863 | ||
4864 | If no options or arguments are supplied, ‘set’ displays the names | |
4865 | and values of all shell variables and functions, sorted according | |
4866 | to the current locale, in a format that may be reused as input for | |
4867 | setting or resetting the currently-set variables. Read-only | |
4868 | variables cannot be reset. In POSIX mode, only shell variables are | |
4869 | listed. | |
4870 | ||
4871 | When options are supplied, they set or unset shell attributes. Any | |
4872 | arguments remaining after option processing replace the positional | |
4873 | parameters. | |
4874 | ||
4875 | Options, if specified, have the following meanings: | |
4876 | ||
4877 | ‘-a’ | |
4878 | Each variable or function that is created or modified is given | |
4879 | the export attribute and marked for export to the environment | |
4880 | of subsequent commands. | |
4881 | ||
4882 | ‘-b’ | |
4883 | Cause the status of terminated background jobs to be reported | |
4884 | immediately, rather than before printing the next primary | |
4885 | prompt or, under some circumstances, when a foreground command | |
4886 | exits. This is effective only when job control is enabled. | |
4887 | ||
4888 | ‘-e’ | |
4889 | Exit immediately if a pipeline (*note Pipelines::), which may | |
4890 | consist of a single simple command (*note Simple Commands::), | |
4891 | a list (*note Lists::), or a compound command (*note Compound | |
4892 | Commands::) returns a non-zero status. The shell does not | |
4893 | exit if the command that fails is part of the command list | |
4894 | immediately following a ‘while’ or ‘until’ reserved word, part | |
4895 | of the test in an ‘if’ statement, part of any command executed | |
4896 | in a ‘&&’ or ‘||’ list except the command following the final | |
4897 | ‘&&’ or ‘||’, any command in a pipeline but the last (subject | |
4898 | to the state of the ‘pipefail’ shell option), or if the | |
4899 | command's return status is being inverted with ‘!’. If a | |
4900 | compound command other than a subshell returns a non-zero | |
4901 | status because a command failed while ‘-e’ was being ignored, | |
4902 | the shell does not exit. A trap on ‘ERR’, if set, is executed | |
4903 | before the shell exits. | |
4904 | ||
4905 | This option applies to the shell environment and each subshell | |
4906 | environment separately (*note Command Execution | |
4907 | Environment::), and may cause subshells to exit before | |
4908 | executing all the commands in the subshell. | |
4909 | ||
4910 | If a compound command or shell function executes in a context | |
4911 | where ‘-e’ is being ignored, none of the commands executed | |
4912 | within the compound command or function body will be affected | |
4913 | by the ‘-e’ setting, even if ‘-e’ is set and a command returns | |
4914 | a failure status. If a compound command or shell function | |
4915 | sets ‘-e’ while executing in a context where ‘-e’ is ignored, | |
4916 | that setting will not have any effect until the compound | |
4917 | command or the command containing the function call completes. | |
4918 | ||
4919 | ‘-f’ | |
4920 | Disable filename expansion (globbing). | |
4921 | ||
4922 | ‘-h’ | |
4923 | Locate and remember (hash) commands as they are looked up for | |
4924 | execution. This option is enabled by default. | |
4925 | ||
4926 | ‘-k’ | |
4927 | All arguments in the form of assignment statements are placed | |
4928 | in the environment for a command, not just those that precede | |
4929 | the command name. | |
4930 | ||
4931 | ‘-m’ | |
4932 | Job control is enabled (*note Job Control::). All processes | |
4933 | run in a separate process group. When a background job | |
4934 | completes, the shell prints a line containing its exit status. | |
4935 | ||
4936 | ‘-n’ | |
4937 | Read commands but do not execute them. This may be used to | |
4938 | check a script for syntax errors. This option is ignored by | |
4939 | interactive shells. | |
4940 | ||
4941 | ‘-o OPTION-NAME’ | |
4942 | ||
4943 | Set the option corresponding to OPTION-NAME. If ‘-o’ is | |
4944 | supplied with no OPTION-NAME, ‘set’ prints the current shell | |
4945 | options settings. If ‘+o’ is supplied with no OPTION-NAME, | |
4946 | ‘set’ prints a series of ‘set’ commands to recreate the | |
4947 | current option settings on the standard output. Valid option | |
4948 | names are: | |
4949 | ||
4950 | ‘allexport’ | |
4951 | Same as ‘-a’. | |
4952 | ||
4953 | ‘braceexpand’ | |
4954 | Same as ‘-B’. | |
4955 | ||
4956 | ‘emacs’ | |
4957 | Use an ‘emacs’-style line editing interface (*note | |
4958 | Command Line Editing::). This also affects the editing | |
4959 | interface used for ‘read -e’. | |
4960 | ||
4961 | ‘errexit’ | |
4962 | Same as ‘-e’. | |
4963 | ||
4964 | ‘errtrace’ | |
4965 | Same as ‘-E’. | |
4966 | ||
4967 | ‘functrace’ | |
4968 | Same as ‘-T’. | |
4969 | ||
4970 | ‘hashall’ | |
4971 | Same as ‘-h’. | |
4972 | ||
4973 | ‘histexpand’ | |
4974 | Same as ‘-H’. | |
4975 | ||
4976 | ‘history’ | |
4977 | Enable command history, as described in *note Bash | |
4978 | History Facilities::. This option is on by default in | |
4979 | interactive shells. | |
4980 | ||
4981 | ‘ignoreeof’ | |
4982 | An interactive shell will not exit upon reading EOF. | |
4983 | ||
4984 | ‘keyword’ | |
4985 | Same as ‘-k’. | |
4986 | ||
4987 | ‘monitor’ | |
4988 | Same as ‘-m’. | |
4989 | ||
4990 | ‘noclobber’ | |
4991 | Same as ‘-C’. | |
4992 | ||
4993 | ‘noexec’ | |
4994 | Same as ‘-n’. | |
4995 | ||
4996 | ‘noglob’ | |
4997 | Same as ‘-f’. | |
4998 | ||
4999 | ‘nolog’ | |
5000 | Currently ignored. | |
5001 | ||
5002 | ‘notify’ | |
5003 | Same as ‘-b’. | |
5004 | ||
5005 | ‘nounset’ | |
5006 | Same as ‘-u’. | |
5007 | ||
5008 | ‘onecmd’ | |
5009 | Same as ‘-t’. | |
5010 | ||
5011 | ‘physical’ | |
5012 | Same as ‘-P’. | |
5013 | ||
5014 | ‘pipefail’ | |
5015 | If set, the return value of a pipeline is the value of | |
5016 | the last (rightmost) command to exit with a non-zero | |
5017 | status, or zero if all commands in the pipeline exit | |
5018 | successfully. This option is disabled by default. | |
5019 | ||
5020 | ‘posix’ | |
5021 | Enable POSIX mode; change the behavior of Bash where the | |
5022 | default operation differs from the POSIX standard to | |
5023 | match the standard (*note Bash POSIX Mode::). This is | |
5024 | intended to make Bash behave as a strict superset of that | |
5025 | standard. | |
5026 | ||
5027 | ‘privileged’ | |
5028 | Same as ‘-p’. | |
5029 | ||
5030 | ‘verbose’ | |
5031 | Same as ‘-v’. | |
5032 | ||
5033 | ‘vi’ | |
5034 | Use a ‘vi’-style line editing interface. This also | |
5035 | affects the editing interface used for ‘read -e’. | |
5036 | ||
5037 | ‘xtrace’ | |
5038 | Same as ‘-x’. | |
5039 | ||
5040 | ‘-p’ | |
5041 | Turn on privileged mode. In this mode, the ‘$BASH_ENV’ and | |
5042 | ‘$ENV’ files are not processed, shell functions are not | |
5043 | inherited from the environment, and the ‘SHELLOPTS’, | |
5044 | ‘BASHOPTS’, ‘CDPATH’ and ‘GLOBIGNORE’ variables, if they | |
5045 | appear in the environment, are ignored. If the shell is | |
5046 | started with the effective user (group) id not equal to the | |
5047 | real user (group) id, and the ‘-p’ option is not supplied, | |
5048 | these actions are taken and the effective user id is set to | |
5049 | the real user id. If the ‘-p’ option is supplied at startup, | |
5050 | the effective user id is not reset. Turning this option off | |
5051 | causes the effective user and group ids to be set to the real | |
5052 | user and group ids. | |
5053 | ||
5054 | ‘-r’ | |
5055 | Enable restricted shell mode (*note The Restricted Shell::). | |
5056 | This option cannot be unset once it has been set. | |
5057 | ||
5058 | ‘-t’ | |
5059 | Exit after reading and executing one command. | |
5060 | ||
5061 | ‘-u’ | |
5062 | Treat unset variables and parameters other than the special | |
5063 | parameters ‘@’ or ‘*’, or array variables subscripted with ‘@’ | |
5064 | or ‘*’, as an error when performing parameter expansion. An | |
5065 | error message will be written to the standard error, and a | |
5066 | non-interactive shell will exit. | |
5067 | ||
5068 | ‘-v’ | |
5069 | Print shell input lines to standard error as they are read. | |
5070 | ||
5071 | ‘-x’ | |
5072 | Print a trace of simple commands, ‘for’ commands, ‘case’ | |
5073 | commands, ‘select’ commands, and arithmetic ‘for’ commands and | |
5074 | their arguments or associated word lists to the standard error | |
5075 | after they are expanded and before they are executed. The | |
5076 | shell prints the expanded value of the ‘PS4’ variable before | |
5077 | the command and its expanded arguments. | |
5078 | ||
5079 | ‘-B’ | |
5080 | The shell will perform brace expansion (*note Brace | |
5081 | Expansion::). This option is on by default. | |
5082 | ||
5083 | ‘-C’ | |
5084 | Prevent output redirection using ‘>’, ‘>&’, and ‘<>’ from | |
5085 | overwriting existing files. Using the redirection operator | |
5086 | ‘>|’ instead of ‘>’ will override this and force the creation | |
5087 | of an output file. | |
5088 | ||
5089 | ‘-E’ | |
5090 | If set, any trap on ‘ERR’ is inherited by shell functions, | |
5091 | command substitutions, and commands executed in a subshell | |
5092 | environment. The ‘ERR’ trap is normally not inherited in such | |
5093 | cases. | |
5094 | ||
5095 | ‘-H’ | |
5096 | Enable ‘!’ style history substitution (*note History | |
5097 | Interaction::). This option is on by default for interactive | |
5098 | shells. | |
5099 | ||
5100 | ‘-P’ | |
5101 | If set, Bash does not resolve symbolic links when executing | |
5102 | commands such as ‘cd’ which change the current directory. It | |
5103 | uses the physical directory structure instead. By default, | |
5104 | Bash follows the logical chain of directories when performing | |
5105 | commands which change the current directory. | |
5106 | ||
5107 | For example, if ‘/usr/sys’ is a symbolic link to | |
5108 | ‘/usr/local/sys’ then: | |
5109 | $ cd /usr/sys; echo $PWD | |
5110 | /usr/sys | |
5111 | $ cd ..; pwd | |
5112 | /usr | |
5113 | ||
5114 | If ‘set -P’ is on, then: | |
5115 | $ cd /usr/sys; echo $PWD | |
5116 | /usr/local/sys | |
5117 | $ cd ..; pwd | |
5118 | /usr/local | |
5119 | ||
5120 | ‘-T’ | |
5121 | If set, any traps on ‘DEBUG’ and ‘RETURN’ are inherited by | |
5122 | shell functions, command substitutions, and commands executed | |
5123 | in a subshell environment. The ‘DEBUG’ and ‘RETURN’ traps are | |
5124 | normally not inherited in such cases. | |
5125 | ||
5126 | ‘--’ | |
5127 | If no arguments follow this option, unset the positional | |
5128 | parameters. Otherwise, the positional parameters are set to | |
5129 | the ARGUMENTS, even if some of them begin with a ‘-’. | |
5130 | ||
5131 | ‘-’ | |
5132 | Signal the end of options, and assign all remaining ARGUMENTS | |
5133 | to the positional parameters. The ‘-x’ and ‘-v’ options are | |
5134 | turned off. If there are no arguments, the positional | |
5135 | parameters remain unchanged. | |
5136 | ||
5137 | Using ‘+’ rather than ‘-’ causes these options to be turned off. | |
5138 | The options can also be used upon invocation of the shell. The | |
5139 | current set of options may be found in ‘$-’. | |
5140 | ||
5141 | The remaining N ARGUMENTS are positional parameters and are | |
5142 | assigned, in order, to ‘$1’, ‘$2’, ... ‘$N’. The special parameter | |
5143 | ‘#’ is set to N. | |
5144 | ||
5145 | The return status is always zero unless an invalid option is | |
5146 | supplied. | |
5147 | ||
5148 | \1f | |
5149 | File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior | |
5150 | ||
5151 | 4.3.2 The Shopt Builtin | |
5152 | ----------------------- | |
5153 | ||
5154 | This builtin allows you to change additional optional shell behavior. | |
5155 | ||
5156 | ‘shopt’ | |
5157 | shopt [-pqsu] [-o] [OPTNAME ...] | |
5158 | ||
5159 | Toggle the values of settings controlling optional shell behavior. | |
5160 | The settings can be either those listed below, or, if the ‘-o’ | |
5161 | option is used, those available with the ‘-o’ option to the ‘set’ | |
5162 | builtin command (*note The Set Builtin::). | |
5163 | ||
5164 | With no options, or with the ‘-p’ option, display a list of all | |
5165 | settable options, with an indication of whether or not each is set; | |
5166 | if any OPTNAMEs are supplied, the output is restricted to those | |
5167 | options. The ‘-p’ option displays output in a form that may be | |
5168 | reused as input. | |
5169 | ||
5170 | Other options have the following meanings: | |
5171 | ||
5172 | ‘-s’ | |
5173 | Enable (set) each OPTNAME. | |
5174 | ||
5175 | ‘-u’ | |
5176 | Disable (unset) each OPTNAME. | |
5177 | ||
5178 | ‘-q’ | |
5179 | Suppresses normal output; the return status indicates whether | |
5180 | the OPTNAME is set or unset. If multiple OPTNAME arguments | |
5181 | are supplied with ‘-q’, the return status is zero if all | |
5182 | OPTNAMEs are enabled; non-zero otherwise. | |
5183 | ||
5184 | ‘-o’ | |
5185 | Restricts the values of OPTNAME to be those defined for the | |
5186 | ‘-o’ option to the ‘set’ builtin (*note The Set Builtin::). | |
5187 | ||
5188 | If either ‘-s’ or ‘-u’ is used with no OPTNAME arguments, ‘shopt’ | |
5189 | shows only those options which are set or unset, respectively. | |
5190 | ||
5191 | Unless otherwise noted, the ‘shopt’ options are disabled (off) by | |
5192 | default. | |
5193 | ||
5194 | The return status when listing options is zero if all OPTNAMEs are | |
5195 | enabled, non-zero otherwise. When setting or unsetting options, | |
5196 | the return status is zero unless an OPTNAME is not a valid shell | |
5197 | option. | |
5198 | ||
5199 | The list of ‘shopt’ options is: | |
5200 | ||
5201 | ‘array_expand_once’ | |
5202 | If set, the shell suppresses multiple evaluation of | |
5203 | associative and indexed array subscripts during arithmetic | |
5204 | expression evaluation, while executing builtins that can | |
5205 | perform variable assignments, and while executing builtins | |
5206 | that perform array dereferencing. | |
5207 | ||
5208 | ‘assoc_expand_once’ | |
5209 | Deprecated; a synonym for ‘array_expand_once’. | |
5210 | ||
5211 | ‘autocd’ | |
5212 | If set, a command name that is the name of a directory is | |
5213 | executed as if it were the argument to the ‘cd’ command. This | |
5214 | option is only used by interactive shells. | |
5215 | ||
5216 | ‘bash_source_fullpath’ | |
5217 | If set, filenames added to the ‘BASH_SOURCE’ array variable | |
5218 | are converted to full pathnames (*note Bash Variables::). | |
5219 | ||
5220 | ‘cdable_vars’ | |
5221 | If this is set, an argument to the ‘cd’ builtin command that | |
5222 | is not a directory is assumed to be the name of a variable | |
5223 | whose value is the directory to change to. | |
5224 | ||
5225 | ‘cdspell’ | |
5226 | If set, the ‘cd’ command attempts to correct minor errors in | |
5227 | the spelling of a directory component. Minor errors include | |
5228 | transposed characters, a missing character, and one extra | |
5229 | character. If ‘cd’ corrects the directory name, it prints the | |
5230 | corrected filename, and the command proceeds. This option is | |
5231 | only used by interactive shells. | |
5232 | ||
5233 | ‘checkhash’ | |
5234 | If this is set, Bash checks that a command found in the hash | |
5235 | table exists before trying to execute it. If a hashed command | |
5236 | no longer exists, Bash performs a normal path search. | |
5237 | ||
5238 | ‘checkjobs’ | |
5239 | If set, Bash lists the status of any stopped and running jobs | |
5240 | before exiting an interactive shell. If any jobs are running, | |
5241 | Bash defers the exit until a second exit is attempted without | |
5242 | an intervening command (*note Job Control::). The shell | |
5243 | always postpones exiting if any jobs are stopped. | |
5244 | ||
5245 | ‘checkwinsize’ | |
5246 | If set, Bash checks the window size after each external | |
5247 | (non-builtin) command and, if necessary, updates the values of | |
5248 | ‘LINES’ and ‘COLUMNS’, using the file descriptor associated | |
5249 | with stderr if it is a terminal. This option is enabled by | |
5250 | default. | |
5251 | ||
5252 | ‘cmdhist’ | |
5253 | If set, Bash attempts to save all lines of a multiple-line | |
5254 | command in the same history entry. This allows easy | |
5255 | re-editing of multi-line commands. This option is enabled by | |
5256 | default, but only has an effect if command history is enabled | |
5257 | (*note Bash History Facilities::). | |
5258 | ||
5259 | ‘compat31’ | |
5260 | ‘compat32’ | |
5261 | ‘compat40’ | |
5262 | ‘compat41’ | |
5263 | ‘compat42’ | |
5264 | ‘compat43’ | |
5265 | ‘compat44’ | |
5266 | These control aspects of the shell's compatibility mode (*note | |
5267 | Shell Compatibility Mode::). | |
5268 | ||
5269 | ‘complete_fullquote’ | |
5270 | If set, Bash quotes all shell metacharacters in filenames and | |
5271 | directory names when performing completion. If not set, Bash | |
5272 | removes metacharacters such as the dollar sign from the set of | |
5273 | characters that will be quoted in completed filenames when | |
5274 | these metacharacters appear in shell variable references in | |
5275 | words to be completed. This means that dollar signs in | |
5276 | variable names that expand to directories will not be quoted; | |
5277 | however, any dollar signs appearing in filenames will not be | |
5278 | quoted, either. This is active only when Bash is using | |
5279 | backslashes to quote completed filenames. This variable is | |
5280 | set by default, which is the default Bash behavior in versions | |
5281 | through 4.2. | |
5282 | ||
5283 | ‘direxpand’ | |
5284 | If set, Bash replaces directory names with the results of word | |
5285 | expansion when performing filename completion. This changes | |
5286 | the contents of the Readline editing buffer. If not set, Bash | |
5287 | attempts to preserve what the user typed. | |
5288 | ||
5289 | ‘dirspell’ | |
5290 | If set, Bash attempts spelling correction on directory names | |
5291 | during word completion if the directory name initially | |
5292 | supplied does not exist. | |
5293 | ||
5294 | ‘dotglob’ | |
5295 | If set, Bash includes filenames beginning with a ‘.’ in the | |
5296 | results of filename expansion. The filenames ‘.’ and ‘..’ | |
5297 | must always be matched explicitly, even if ‘dotglob’ is set. | |
5298 | ||
5299 | ‘execfail’ | |
5300 | If this is set, a non-interactive shell will not exit if it | |
5301 | cannot execute the file specified as an argument to the ‘exec’ | |
5302 | builtin. An interactive shell does not exit if ‘exec’ fails. | |
5303 | ||
5304 | ‘expand_aliases’ | |
5305 | If set, aliases are expanded as described below under Aliases, | |
5306 | *note Aliases::. This option is enabled by default for | |
5307 | interactive shells. | |
5308 | ||
5309 | ‘extdebug’ | |
5310 | If set at shell invocation, or in a shell startup file, | |
5311 | arrange to execute the debugger profile before the shell | |
5312 | starts, identical to the ‘--debugger’ option. If set after | |
5313 | invocation, behavior intended for use by debuggers is enabled: | |
5314 | ||
5315 | 1. The ‘-F’ option to the ‘declare’ builtin (*note Bash | |
5316 | Builtins::) displays the source file name and line number | |
5317 | corresponding to each function name supplied as an | |
5318 | argument. | |
5319 | ||
5320 | 2. If the command run by the ‘DEBUG’ trap returns a non-zero | |
5321 | value, the next command is skipped and not executed. | |
5322 | ||
5323 | 3. If the command run by the ‘DEBUG’ trap returns a value of | |
5324 | 2, and the shell is executing in a subroutine (a shell | |
5325 | function or a shell script executed by the ‘.’ or | |
5326 | ‘source’ builtins), the shell simulates a call to | |
5327 | ‘return’. | |
5328 | ||
5329 | 4. ‘BASH_ARGC’ and ‘BASH_ARGV’ are updated as described in | |
5330 | their descriptions (*note Bash Variables::). | |
5331 | ||
5332 | 5. Function tracing is enabled: command substitution, shell | |
5333 | functions, and subshells invoked with ‘( COMMAND )’ | |
5334 | inherit the ‘DEBUG’ and ‘RETURN’ traps. | |
5335 | ||
5336 | 6. Error tracing is enabled: command substitution, shell | |
5337 | functions, and subshells invoked with ‘( COMMAND )’ | |
5338 | inherit the ‘ERR’ trap. | |
5339 | ||
5340 | ‘extglob’ | |
5341 | If set, enable the extended pattern matching features | |
5342 | described above (*note Pattern Matching::). | |
5343 | ||
5344 | ‘extquote’ | |
5345 | If set, ‘$'STRING'’ and ‘$"STRING"’ quoting is performed | |
5346 | within ‘${PARAMETER}’ expansions enclosed in double quotes. | |
5347 | This option is enabled by default. | |
5348 | ||
5349 | ‘failglob’ | |
5350 | If set, patterns which fail to match filenames during filename | |
5351 | expansion result in an expansion error. | |
5352 | ||
5353 | ‘force_fignore’ | |
5354 | If set, the suffixes specified by the ‘FIGNORE’ shell variable | |
5355 | cause words to be ignored when performing word completion even | |
5356 | if the ignored words are the only possible completions. *Note | |
5357 | Bash Variables::, for a description of ‘FIGNORE’. This option | |
5358 | is enabled by default. | |
5359 | ||
5360 | ‘globasciiranges’ | |
5361 | If set, range expressions used in pattern matching bracket | |
5362 | expressions (*note Pattern Matching::) behave as if in the | |
5363 | traditional C locale when performing comparisons. That is, | |
5364 | pattern matching does not take the current locale's collating | |
5365 | sequence into account, so ‘b’ will not collate between ‘A’ and | |
5366 | ‘B’, and upper-case and lower-case ASCII characters will | |
5367 | collate together. | |
5368 | ||
5369 | ‘globskipdots’ | |
5370 | If set, filename expansion will never match the filenames ‘.’ | |
5371 | and ‘..’, even if the pattern begins with a ‘.’. This option | |
5372 | is enabled by default. | |
5373 | ||
5374 | ‘globstar’ | |
5375 | If set, the pattern ‘**’ used in a filename expansion context | |
5376 | will match all files and zero or more directories and | |
5377 | subdirectories. If the pattern is followed by a ‘/’, only | |
5378 | directories and subdirectories match. | |
5379 | ||
5380 | ‘gnu_errfmt’ | |
5381 | If set, shell error messages are written in the standard GNU | |
5382 | error message format. | |
5383 | ||
5384 | ‘histappend’ | |
5385 | If set, the history list is appended to the file named by the | |
5386 | value of the ‘HISTFILE’ variable when the shell exits, rather | |
5387 | than overwriting the file. | |
5388 | ||
5389 | ‘histreedit’ | |
5390 | If set, and Readline is being used, the user is given the | |
5391 | opportunity to re-edit a failed history substitution. | |
5392 | ||
5393 | ‘histverify’ | |
5394 | If set, and Readline is being used, the results of history | |
5395 | substitution are not immediately passed to the shell parser. | |
5396 | Instead, the resulting line is loaded into the Readline | |
5397 | editing buffer, allowing further modification. | |
5398 | ||
5399 | ‘hostcomplete’ | |
5400 | If set, and Readline is being used, Bash will attempt to | |
5401 | perform hostname completion when a word containing a ‘@’ is | |
5402 | being completed (*note Commands For Completion::). This | |
5403 | option is enabled by default. | |
5404 | ||
5405 | ‘huponexit’ | |
5406 | If set, Bash will send ‘SIGHUP’ to all jobs when an | |
5407 | interactive login shell exits (*note Signals::). | |
5408 | ||
5409 | ‘inherit_errexit’ | |
5410 | If set, command substitution inherits the value of the | |
5411 | ‘errexit’ option, instead of unsetting it in the subshell | |
5412 | environment. This option is enabled when POSIX mode is | |
5413 | enabled. | |
5414 | ||
5415 | ‘interactive_comments’ | |
5416 | In an interactive shell, a word beginning with ‘#’ causes that | |
5417 | word and all remaining characters on that line to be ignored, | |
5418 | as in a non-interactive shell. This option is enabled by | |
5419 | default. | |
5420 | ||
5421 | ‘lastpipe’ | |
5422 | If set, and job control is not active, the shell runs the last | |
5423 | command of a pipeline not executed in the background in the | |
5424 | current shell environment. | |
5425 | ||
5426 | ‘lithist’ | |
5427 | If enabled, and the ‘cmdhist’ option is enabled, multi-line | |
5428 | commands are saved to the history with embedded newlines | |
5429 | rather than using semicolon separators where possible. | |
5430 | ||
5431 | ‘localvar_inherit’ | |
5432 | If set, local variables inherit the value and attributes of a | |
5433 | variable of the same name that exists at a previous scope | |
5434 | before any new value is assigned. The ‘nameref’ attribute is | |
5435 | not inherited. | |
5436 | ||
5437 | ‘localvar_unset’ | |
5438 | If set, calling ‘unset’ on local variables in previous | |
5439 | function scopes marks them so subsequent lookups find them | |
5440 | unset until that function returns. This is identical to the | |
5441 | behavior of unsetting local variables at the current function | |
5442 | scope. | |
5443 | ||
5444 | ‘login_shell’ | |
5445 | The shell sets this option if it is started as a login shell | |
5446 | (*note Invoking Bash::). The value may not be changed. | |
5447 | ||
5448 | ‘mailwarn’ | |
5449 | If set, and a file that Bash is checking for mail has been | |
5450 | accessed since the last time it was checked, Bash displays the | |
5451 | message ‘"The mail in MAILFILE has been read"’. | |
5452 | ||
5453 | ‘no_empty_cmd_completion’ | |
5454 | If set, and Readline is being used, Bash does not search the | |
5455 | ‘PATH’ for possible completions when completion is attempted | |
5456 | on an empty line. | |
5457 | ||
5458 | ‘nocaseglob’ | |
5459 | If set, Bash matches filenames in a case-insensitive fashion | |
5460 | when performing filename expansion. | |
5461 | ||
5462 | ‘nocasematch’ | |
5463 | If set, Bash matches patterns in a case-insensitive fashion | |
5464 | when performing matching while executing ‘case’ or ‘[[’ | |
5465 | conditional commands (*note Conditional Constructs::, when | |
5466 | performing pattern substitution word expansions, or when | |
5467 | filtering possible completions as part of programmable | |
5468 | completion. | |
5469 | ||
5470 | ‘noexpand_translation’ | |
5471 | If set, Bash encloses the translated results of $"..." quoting | |
5472 | in single quotes instead of double quotes. If the string is | |
5473 | not translated, this has no effect. | |
5474 | ||
5475 | ‘nullglob’ | |
5476 | If set, filename expansion patterns which match no files | |
5477 | (*note Filename Expansion::) expand to nothing and are | |
5478 | removed, rather than expanding to themselves. | |
5479 | ||
5480 | ‘patsub_replacement’ | |
5481 | If set, Bash expands occurrences of ‘&’ in the replacement | |
5482 | string of pattern substitution to the text matched by the | |
5483 | pattern, as described above (*note Shell Parameter | |
5484 | Expansion::). This option is enabled by default. | |
5485 | ||
5486 | ‘progcomp’ | |
5487 | If set, enable the programmable completion facilities (*note | |
5488 | Programmable Completion::). This option is enabled by | |
5489 | default. | |
5490 | ||
5491 | ‘progcomp_alias’ | |
5492 | If set, and programmable completion is enabled, Bash treats a | |
5493 | command name that doesn't have any completions as a possible | |
5494 | alias and attempts alias expansion. If it has an alias, Bash | |
5495 | attempts programmable completion using the command word | |
5496 | resulting from the expanded alias. | |
5497 | ||
5498 | ‘promptvars’ | |
5499 | If set, prompt strings undergo parameter expansion, command | |
5500 | substitution, arithmetic expansion, and quote removal after | |
5501 | being expanded as described below (*note Controlling the | |
5502 | Prompt::). This option is enabled by default. | |
5503 | ||
5504 | ‘restricted_shell’ | |
5505 | The shell sets this option if it is started in restricted mode | |
5506 | (*note The Restricted Shell::). The value may not be changed. | |
5507 | This is not reset when the startup files are executed, | |
5508 | allowing the startup files to discover whether or not a shell | |
5509 | is restricted. | |
5510 | ||
5511 | ‘shift_verbose’ | |
5512 | If this is set, the ‘shift’ builtin prints an error message | |
5513 | when the shift count exceeds the number of positional | |
5514 | parameters. | |
5515 | ||
5516 | ‘sourcepath’ | |
5517 | If set, the ‘.’ (‘source’) builtin uses the value of ‘PATH’ to | |
5518 | find the directory containing the file supplied as an argument | |
5519 | when the ‘-p’ option is not supplied. This option is enabled | |
5520 | by default. | |
5521 | ||
5522 | ‘varredir_close’ | |
5523 | If set, the shell automatically closes file descriptors | |
5524 | assigned using the ‘{varname}’ redirection syntax (*note | |
5525 | Redirections::) instead of leaving them open when the command | |
5526 | completes. | |
5527 | ||
5528 | ‘xpg_echo’ | |
5529 | If set, the ‘echo’ builtin expands backslash-escape sequences | |
5530 | by default. If the ‘posix’ shell option (*note The Set | |
5531 | Builtin::) is also enabled, ‘echo’ does not interpret any | |
5532 | options. | |
5533 | ||
5534 | \1f | |
5535 | File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands | |
5536 | ||
5537 | 4.4 Special Builtins | |
5538 | ==================== | |
5539 | ||
5540 | For historical reasons, the POSIX standard has classified several | |
5541 | builtin commands as _special_. When Bash is executing in POSIX mode, | |
5542 | the special builtins differ from other builtin commands in three | |
5543 | respects: | |
5544 | ||
5545 | 1. Special builtins are found before shell functions during command | |
5546 | lookup. | |
5547 | ||
5548 | 2. If a special builtin returns an error status, a non-interactive | |
5549 | shell exits. | |
5550 | ||
5551 | 3. Assignment statements preceding the command stay in effect in the | |
5552 | shell environment after the command completes. | |
5553 | ||
5554 | When Bash is not executing in POSIX mode, these builtins behave no | |
5555 | differently than the rest of the Bash builtin commands. The Bash POSIX | |
5556 | mode is described in *note Bash POSIX Mode::. | |
5557 | ||
5558 | These are the POSIX special builtins: | |
5559 | break : . source continue eval exec exit export readonly return set | |
5560 | shift times trap unset | |
5561 | ||
5562 | \1f | |
5563 | File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top | |
5564 | ||
5565 | 5 Shell Variables | |
5566 | ***************** | |
5567 | ||
5568 | * Menu: | |
5569 | ||
5570 | * Bourne Shell Variables:: Variables which Bash uses in the same way | |
5571 | as the Bourne Shell. | |
5572 | * Bash Variables:: List of variables that exist in Bash. | |
5573 | ||
5574 | This chapter describes the shell variables that Bash uses. Bash | |
5575 | automatically assigns default values to a number of variables. | |
5576 | ||
5577 | \1f | |
5578 | File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables | |
5579 | ||
5580 | 5.1 Bourne Shell Variables | |
5581 | ========================== | |
5582 | ||
5583 | Bash uses certain shell variables in the same way as the Bourne shell. | |
5584 | In some cases, Bash assigns a default value to the variable. | |
5585 | ||
5586 | ‘CDPATH’ | |
5587 | A colon-separated list of directories used as a search path for the | |
5588 | ‘cd’ builtin command. | |
5589 | ||
5590 | ‘HOME’ | |
5591 | The current user's home directory; the default for the ‘cd’ builtin | |
5592 | command. The value of this variable is also used by tilde | |
5593 | expansion (*note Tilde Expansion::). | |
5594 | ||
5595 | ‘IFS’ | |
5596 | A list of characters that separate fields; used when the shell | |
5597 | splits words as part of expansion and by the ‘read’ builtin to | |
5598 | split lines into words. *Note Word Splitting::, for a description | |
5599 | of word splitting. | |
5600 | ||
5601 | ‘MAIL’ | |
5602 | If the value is set to a filename or directory name and the | |
5603 | ‘MAILPATH’ variable is not set, Bash informs the user of the | |
5604 | arrival of mail in the specified file or Maildir-format directory. | |
5605 | ||
5606 | ‘MAILPATH’ | |
5607 | A colon-separated list of filenames which the shell periodically | |
5608 | checks for new mail. Each list entry can specify the message that | |
5609 | is printed when new mail arrives in the mail file by separating the | |
5610 | filename from the message with a ‘?’. When used in the text of the | |
5611 | message, ‘$_’ expands to the name of the current mail file. | |
5612 | ||
5613 | ‘OPTARG’ | |
5614 | The value of the last option argument processed by the ‘getopts’ | |
5615 | builtin. | |
5616 | ||
5617 | ‘OPTIND’ | |
5618 | The index of the next argument to be processed by the ‘getopts’ | |
5619 | builtin. | |
5620 | ||
5621 | ‘PATH’ | |
5622 | A colon-separated list of directories in which the shell looks for | |
5623 | commands. A zero-length (null) directory name in the value of | |
5624 | ‘PATH’ indicates the current directory. A null directory name may | |
5625 | appear as two adjacent colons, or as an initial or trailing colon. | |
5626 | The default path is system-dependent, and is set by the | |
5627 | administrator who installs ‘bash’. A common value is | |
5628 | "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin". | |
5629 | ||
5630 | ‘PS1’ | |
5631 | The primary prompt string. The default value is ‘\s-\v\$ ’. *Note | |
5632 | Controlling the Prompt::, for the complete list of escape sequences | |
5633 | that are expanded before ‘PS1’ is displayed. | |
5634 | ||
5635 | ‘PS2’ | |
5636 | The secondary prompt string. The default value is ‘> ’. ‘PS2’ is | |
5637 | expanded in the same way as ‘PS1’ before being displayed. | |
5638 | ||
5639 | \1f | |
5640 | File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables | |
5641 | ||
5642 | 5.2 Bash Variables | |
5643 | ================== | |
5644 | ||
5645 | These variables are set or used by Bash, but other shells do not | |
5646 | normally treat them specially. | |
5647 | ||
5648 | A few variables used by Bash are described in different chapters: | |
5649 | variables for controlling the job control facilities (*note Job Control | |
5650 | Variables::). | |
5651 | ||
5652 | ‘_’ | |
5653 | ($_, an underscore.) This has a number of meanings depending on | |
5654 | context. At shell startup, $_ set to the pathname used to invoke | |
5655 | the shell or shell script being executed as passed in the | |
5656 | environment or argument list. Subsequently, it expands to the last | |
5657 | argument to the previous simple command executed in the foreground, | |
5658 | after expansion. It is also set to the full pathname used to | |
5659 | invoke each command executed and placed in the environment exported | |
5660 | to that command. When checking mail, $_ expands to the name of the | |
5661 | mail file. | |
5662 | ||
5663 | ‘BASH’ | |
5664 | The full pathname used to execute the current instance of Bash. | |
5665 | ||
5666 | ‘BASHOPTS’ | |
5667 | A colon-separated list of enabled shell options. Each word in the | |
5668 | list is a valid argument for the ‘-s’ option to the ‘shopt’ builtin | |
5669 | command (*note The Shopt Builtin::). The options appearing in | |
5670 | ‘BASHOPTS’ are those reported as ‘on’ by ‘shopt’. If this variable | |
5671 | is in the environment when Bash starts up, the shell enables each | |
5672 | option in the list before reading any startup files. If this | |
5673 | variable is exported, child shells will enable each option in the | |
5674 | list. This variable is readonly. | |
5675 | ||
5676 | ‘BASHPID’ | |
5677 | Expands to the process ID of the current Bash process. This | |
5678 | differs from ‘$$’ under certain circumstances, such as subshells | |
5679 | that do not require Bash to be re-initialized. Assignments to | |
5680 | ‘BASHPID’ have no effect. If ‘BASHPID’ is unset, it loses its | |
5681 | special properties, even if it is subsequently reset. | |
5682 | ||
5683 | ‘BASH_ALIASES’ | |
5684 | An associative array variable whose members correspond to the | |
5685 | internal list of aliases as maintained by the ‘alias’ builtin. | |
5686 | (*note Bourne Shell Builtins::). Elements added to this array | |
5687 | appear in the alias list; however, unsetting array elements | |
5688 | currently does not cause aliases to be removed from the alias list. | |
5689 | If ‘BASH_ALIASES’ is unset, it loses its special properties, even | |
5690 | if it is subsequently reset. | |
5691 | ||
5692 | ‘BASH_ARGC’ | |
5693 | An array variable whose values are the number of parameters in each | |
5694 | frame of the current Bash execution call stack. The number of | |
5695 | parameters to the current subroutine (shell function or script | |
5696 | executed with ‘.’ or ‘source’) is at the top of the stack. When a | |
5697 | subroutine is executed, the number of parameters passed is pushed | |
5698 | onto ‘BASH_ARGC’. The shell sets ‘BASH_ARGC’ only when in extended | |
5699 | debugging mode (see *note The Shopt Builtin:: for a description of | |
5700 | the ‘extdebug’ option to the ‘shopt’ builtin). Setting ‘extdebug’ | |
5701 | after the shell has started to execute a subroutine, or referencing | |
5702 | this variable when ‘extdebug’ is not set, may result in | |
5703 | inconsistent values. Assignments to ‘BASH_ARGC’ have no effect, | |
5704 | and it may not be unset. | |
5705 | ||
5706 | ‘BASH_ARGV’ | |
5707 | An array variable containing all of the parameters in the current | |
5708 | Bash execution call stack. The final parameter of the last | |
5709 | subroutine call is at the top of the stack; the first parameter of | |
5710 | the initial call is at the bottom. When a subroutine is executed, | |
5711 | the shell pushes the supplied parameters onto ‘BASH_ARGV’. The | |
5712 | shell sets ‘BASH_ARGV’ only when in extended debugging mode (see | |
5713 | *note The Shopt Builtin:: for a description of the ‘extdebug’ | |
5714 | option to the ‘shopt’ builtin). Setting ‘extdebug’ after the shell | |
5715 | has started to execute a script, or referencing this variable when | |
5716 | ‘extdebug’ is not set, may result in inconsistent values. | |
5717 | Assignments to ‘BASH_ARGV’ have no effect, and it may not be unset. | |
5718 | ||
5719 | ‘BASH_ARGV0’ | |
5720 | When referenced, this variable expands to the name of the shell or | |
5721 | shell script (identical to ‘$0’; *Note Special Parameters::, for | |
5722 | the description of special parameter 0). Assigning a value to | |
5723 | ‘BASH_ARGV0’ sets ‘$0’ to the same value. If ‘BASH_ARGV0’ is | |
5724 | unset, it loses its special properties, even if it is subsequently | |
5725 | reset. | |
5726 | ||
5727 | ‘BASH_CMDS’ | |
5728 | An associative array variable whose members correspond to the | |
5729 | internal hash table of commands as maintained by the ‘hash’ builtin | |
5730 | (*note Bourne Shell Builtins::). Adding elements to this array | |
5731 | makes them appear in the hash table; however, unsetting array | |
5732 | elements currently does not remove command names from the hash | |
5733 | table. If ‘BASH_CMDS’ is unset, it loses its special properties, | |
5734 | even if it is subsequently reset. | |
5735 | ||
5736 | ‘BASH_COMMAND’ | |
5737 | Expands to the command currently being executed or about to be | |
5738 | executed, unless the shell is executing a command as the result of | |
5739 | a trap, in which case it is the command executing at the time of | |
5740 | the trap. If ‘BASH_COMMAND’ is unset, it loses its special | |
5741 | properties, even if it is subsequently reset. | |
5742 | ||
5743 | ‘BASH_COMPAT’ | |
5744 | The value is used to set the shell's compatibility level. *Note | |
5745 | Shell Compatibility Mode::, for a description of the various | |
5746 | compatibility levels and their effects. The value may be a decimal | |
5747 | number (e.g., 4.2) or an integer (e.g., 42) corresponding to the | |
5748 | desired compatibility level. If ‘BASH_COMPAT’ is unset or set to | |
5749 | the empty string, the compatibility level is set to the default for | |
5750 | the current version. If ‘BASH_COMPAT’ is set to a value that is | |
5751 | not one of the valid compatibility levels, the shell prints an | |
5752 | error message and sets the compatibility level to the default for | |
5753 | the current version. A subset of the valid values correspond to | |
5754 | the compatibility levels described below (*note Shell Compatibility | |
5755 | Mode::). For example, 4.2 and 42 are valid values that correspond | |
5756 | to the ‘compat42’ ‘shopt’ option and set the compatibility level to | |
5757 | 42. The current version is also a valid value. | |
5758 | ||
5759 | ‘BASH_ENV’ | |
5760 | If this variable is set when Bash is invoked to execute a shell | |
5761 | script, its value is expanded and used as the name of a startup | |
5762 | file to read before executing the script. Bash does not use ‘PATH’ | |
5763 | to search for the resultant filename. *Note Bash Startup Files::. | |
5764 | ||
5765 | ‘BASH_EXECUTION_STRING’ | |
5766 | The command argument to the ‘-c’ invocation option. | |
5767 | ||
5768 | ‘BASH_LINENO’ | |
5769 | An array variable whose members are the line numbers in source | |
5770 | files where each corresponding member of ‘FUNCNAME’ was invoked. | |
5771 | ‘${BASH_LINENO[$i]}’ is the line number in the source file | |
5772 | (‘${BASH_SOURCE[$i+1]}’) where ‘${FUNCNAME[$i]}’ was called (or | |
5773 | ‘${BASH_LINENO[$i-1]}’ if referenced within another shell | |
5774 | function). Use ‘LINENO’ to obtain the current line number. | |
5775 | Assignments to ‘BASH_LINENO’ have no effect, and it may not be | |
5776 | unset. | |
5777 | ||
5778 | ‘BASH_LOADABLES_PATH’ | |
5779 | A colon-separated list of directories in which the ‘enable’ command | |
5780 | looks for dynamically loadable builtins. | |
5781 | ||
5782 | ‘BASH_MONOSECONDS’ | |
5783 | Each time this variable is referenced, it expands to the value | |
5784 | returned by the system's monotonic clock, if one is available. If | |
5785 | there is no monotonic clock, this is equivalent to ‘EPOCHSECONDS’. | |
5786 | If ‘BASH_MONOSECONDS’ is unset, it loses its special properties, | |
5787 | even if it is subsequently reset. | |
5788 | ||
5789 | ‘BASH_REMATCH’ | |
5790 | An array variable whose members are assigned by the ‘=~’ binary | |
5791 | operator to the ‘[[’ conditional command (*note Conditional | |
5792 | Constructs::). The element with index 0 is the portion of the | |
5793 | string matching the entire regular expression. The element with | |
5794 | index N is the portion of the string matching the Nth parenthesized | |
5795 | subexpression. | |
5796 | ||
5797 | ‘BASH_SOURCE’ | |
5798 | An array variable whose members are the source filenames where the | |
5799 | corresponding shell function names in the ‘FUNCNAME’ array variable | |
5800 | are defined. The shell function ‘${FUNCNAME[$i]}’ is defined in | |
5801 | the file ‘${BASH_SOURCE[$i]}’ and called from | |
5802 | ‘${BASH_SOURCE[$i+1]}’ Assignments to ‘BASH_SOURCE’ have no effect, | |
5803 | and it may not be unset. | |
5804 | ||
5805 | ‘BASH_SUBSHELL’ | |
5806 | Incremented by one within each subshell or subshell environment | |
5807 | when the shell begins executing in that environment. The initial | |
5808 | value is 0. If ‘BASH_SUBSHELL’ is unset, it loses its special | |
5809 | properties, even if it is subsequently reset. | |
5810 | ||
5811 | ‘BASH_TRAPSIG’ | |
5812 | Set to the signal number corresponding to the trap action being | |
5813 | executed during its execution. See the description of ‘trap’ | |
5814 | (*note Bourne Shell Builtins::) for information about signal | |
5815 | numbers and trap execution. | |
5816 | ||
5817 | ‘BASH_VERSINFO’ | |
5818 | A readonly array variable (*note Arrays::) whose members hold | |
5819 | version information for this instance of Bash. The values assigned | |
5820 | to the array members are as follows: | |
5821 | ||
5822 | ‘BASH_VERSINFO[0]’ | |
5823 | The major version number (the “release”). | |
5824 | ||
5825 | ‘BASH_VERSINFO[1]’ | |
5826 | The minor version number (the “version”). | |
5827 | ||
5828 | ‘BASH_VERSINFO[2]’ | |
5829 | The patch level. | |
5830 | ||
5831 | ‘BASH_VERSINFO[3]’ | |
5832 | The build version. | |
5833 | ||
5834 | ‘BASH_VERSINFO[4]’ | |
5835 | The release status (e.g., ‘beta’). | |
5836 | ||
5837 | ‘BASH_VERSINFO[5]’ | |
5838 | The value of ‘MACHTYPE’. | |
5839 | ||
5840 | ‘BASH_VERSION’ | |
5841 | Expands to a string describing the version of this instance of Bash | |
5842 | (e.g., 5.2.37(3)-release). | |
5843 | ||
5844 | ‘BASH_XTRACEFD’ | |
5845 | If set to an integer corresponding to a valid file descriptor, Bash | |
5846 | writes the trace output generated when ‘set -x’ is enabled to that | |
5847 | file descriptor, instead of the standard error. This allows | |
5848 | tracing output to be separated from diagnostic and error messages. | |
5849 | The file descriptor is closed when ‘BASH_XTRACEFD’ is unset or | |
5850 | assigned a new value. Unsetting ‘BASH_XTRACEFD’ or assigning it | |
5851 | the empty string causes the trace output to be sent to the standard | |
5852 | error. Note that setting ‘BASH_XTRACEFD’ to 2 (the standard error | |
5853 | file descriptor) and then unsetting it will result in the standard | |
5854 | error being closed. | |
5855 | ||
5856 | ‘CHILD_MAX’ | |
5857 | Set the number of exited child status values for the shell to | |
5858 | remember. Bash will not allow this value to be decreased below a | |
5859 | POSIX-mandated minimum, and there is a maximum value (currently | |
5860 | 8192) that this may not exceed. The minimum value is | |
5861 | system-dependent. | |
5862 | ||
5863 | ‘COLUMNS’ | |
5864 | Used by the ‘select’ command to determine the terminal width when | |
5865 | printing selection lists. Automatically set if the ‘checkwinsize’ | |
5866 | option is enabled (*note The Shopt Builtin::), or in an interactive | |
5867 | shell upon receipt of a ‘SIGWINCH’. | |
5868 | ||
5869 | ‘COMP_CWORD’ | |
5870 | An index into ‘${COMP_WORDS}’ of the word containing the current | |
5871 | cursor position. This variable is available only in shell | |
5872 | functions invoked by the programmable completion facilities (*note | |
5873 | Programmable Completion::). | |
5874 | ||
5875 | ‘COMP_KEY’ | |
5876 | The key (or final key of a key sequence) used to invoke the current | |
5877 | completion function. This variable is available only in shell | |
5878 | functions and external commands invoked by the programmable | |
5879 | completion facilities (*note Programmable Completion::). | |
5880 | ||
5881 | ‘COMP_LINE’ | |
5882 | The current command line. This variable is available only in shell | |
5883 | functions and external commands invoked by the programmable | |
5884 | completion facilities (*note Programmable Completion::). | |
5885 | ||
5886 | ‘COMP_POINT’ | |
5887 | The index of the current cursor position relative to the beginning | |
5888 | of the current command. If the current cursor position is at the | |
5889 | end of the current command, the value of this variable is equal to | |
5890 | ‘${#COMP_LINE}’. This variable is available only in shell | |
5891 | functions and external commands invoked by the programmable | |
5892 | completion facilities (*note Programmable Completion::). | |
5893 | ||
5894 | ‘COMP_TYPE’ | |
5895 | Set to an integer value corresponding to the type of attempted | |
5896 | completion that caused a completion function to be called: <TAB>, | |
5897 | for normal completion, ‘?’, for listing completions after | |
5898 | successive tabs, ‘!’, for listing alternatives on partial word | |
5899 | completion, ‘@’, to list completions if the word is not unmodified, | |
5900 | or ‘%’, for menu completion. This variable is available only in | |
5901 | shell functions and external commands invoked by the programmable | |
5902 | completion facilities (*note Programmable Completion::). | |
5903 | ||
5904 | ‘COMP_WORDBREAKS’ | |
5905 | The set of characters that the Readline library treats as word | |
5906 | separators when performing word completion. If ‘COMP_WORDBREAKS’ | |
5907 | is unset, it loses its special properties, even if it is | |
5908 | subsequently reset. | |
5909 | ||
5910 | ‘COMP_WORDS’ | |
5911 | An array variable consisting of the individual words in the current | |
5912 | command line. The line is split into words as Readline would split | |
5913 | it, using ‘COMP_WORDBREAKS’ as described above. This variable is | |
5914 | available only in shell functions invoked by the programmable | |
5915 | completion facilities (*note Programmable Completion::). | |
5916 | ||
5917 | ‘COMPREPLY’ | |
5918 | An array variable from which Bash reads the possible completions | |
5919 | generated by a shell function invoked by the programmable | |
5920 | completion facility (*note Programmable Completion::). Each array | |
5921 | element contains one possible completion. | |
5922 | ||
5923 | ‘COPROC’ | |
5924 | An array variable created to hold the file descriptors for output | |
5925 | from and input to an unnamed coprocess (*note Coprocesses::). | |
5926 | ||
5927 | ‘DIRSTACK’ | |
5928 | An array variable containing the current contents of the directory | |
5929 | stack. Directories appear in the stack in the order they are | |
5930 | displayed by the ‘dirs’ builtin. Assigning to members of this | |
5931 | array variable may be used to modify directories already in the | |
5932 | stack, but the ‘pushd’ and ‘popd’ builtins must be used to add and | |
5933 | remove directories. Assigning to this variable does not change the | |
5934 | current directory. If ‘DIRSTACK’ is unset, it loses its special | |
5935 | properties, even if it is subsequently reset. | |
5936 | ||
5937 | ‘EMACS’ | |
5938 | If Bash finds this variable in the environment when the shell | |
5939 | starts, and its value is ‘t’, Bash assumes that the shell is | |
5940 | running in an Emacs shell buffer and disables line editing. | |
5941 | ||
5942 | ‘ENV’ | |
5943 | Expanded and executed similarly to ‘BASH_ENV’ (*note Bash Startup | |
5944 | Files::) when an interactive shell is invoked in POSIX mode (*note | |
5945 | Bash POSIX Mode::). | |
5946 | ||
5947 | ‘EPOCHREALTIME’ | |
5948 | Each time this parameter is referenced, it expands to the number of | |
5949 | seconds since the Unix Epoch as a floating-point value with | |
5950 | micro-second granularity (see the documentation for the C library | |
5951 | function ‘time’ for the definition of Epoch). Assignments to | |
5952 | ‘EPOCHREALTIME’ are ignored. If ‘EPOCHREALTIME’ is unset, it loses | |
5953 | its special properties, even if it is subsequently reset. | |
5954 | ||
5955 | ‘EPOCHSECONDS’ | |
5956 | Each time this parameter is referenced, it expands to the number of | |
5957 | seconds since the Unix Epoch (see the documentation for the C | |
5958 | library function ‘time’ for the definition of Epoch). Assignments | |
5959 | to ‘EPOCHSECONDS’ are ignored. If ‘EPOCHSECONDS’ is unset, it | |
5960 | loses its special properties, even if it is subsequently reset. | |
5961 | ||
5962 | ‘EUID’ | |
5963 | The numeric effective user id of the current user. This variable | |
5964 | is readonly. | |
5965 | ||
5966 | ‘EXECIGNORE’ | |
5967 | A colon-separated list of shell patterns (*note Pattern Matching::) | |
5968 | defining the set of filenames to be ignored by command search using | |
5969 | ‘PATH’. Files whose full pathnames match one of these patterns are | |
5970 | not considered executable files for the purposes of completion and | |
5971 | command execution via ‘PATH’ lookup. This does not affect the | |
5972 | behavior of the ‘[’, ‘test’, and ‘[[’ commands. Full pathnames in | |
5973 | the command hash table are not subject to ‘EXECIGNORE’. Use this | |
5974 | variable to ignore shared library files that have the executable | |
5975 | bit set, but are not executable files. The pattern matching honors | |
5976 | the setting of the ‘extglob’ shell option. | |
5977 | ||
5978 | ‘FCEDIT’ | |
5979 | The editor used as a default by the ‘fc’ builtin command. | |
5980 | ||
5981 | ‘FIGNORE’ | |
5982 | A colon-separated list of suffixes to ignore when performing | |
5983 | filename completion. A filename whose suffix matches one of the | |
5984 | entries in ‘FIGNORE’ is excluded from the list of matched | |
5985 | filenames. A sample value is ‘.o:~’ | |
5986 | ||
5987 | ‘FUNCNAME’ | |
5988 | An array variable containing the names of all shell functions | |
5989 | currently in the execution call stack. The element with index 0 is | |
5990 | the name of any currently-executing shell function. The | |
5991 | bottom-most element (the one with the highest index) is ‘"main"’. | |
5992 | This variable exists only when a shell function is executing. | |
5993 | Assignments to ‘FUNCNAME’ have no effect. If ‘FUNCNAME’ is unset, | |
5994 | it loses its special properties, even if it is subsequently reset. | |
5995 | ||
5996 | This variable can be used with ‘BASH_LINENO’ and ‘BASH_SOURCE’. | |
5997 | Each element of ‘FUNCNAME’ has corresponding elements in | |
5998 | ‘BASH_LINENO’ and ‘BASH_SOURCE’ to describe the call stack. For | |
5999 | instance, ‘${FUNCNAME[$i]}’ was called from the file | |
6000 | ‘${BASH_SOURCE[$i+1]}’ at line number ‘${BASH_LINENO[$i]}’. The | |
6001 | ‘caller’ builtin displays the current call stack using this | |
6002 | information. | |
6003 | ||
6004 | ‘FUNCNEST’ | |
6005 | A numeric value greater than 0 defines a maximum function nesting | |
6006 | level. Function invocations that exceed this nesting level cause | |
6007 | the current command to abort. | |
6008 | ||
6009 | ‘GLOBIGNORE’ | |
6010 | A colon-separated list of patterns defining the set of file names | |
6011 | to be ignored by filename expansion. If a file name matched by a | |
6012 | filename expansion pattern also matches one of the patterns in | |
6013 | ‘GLOBIGNORE’, it is removed from the list of matches. The pattern | |
6014 | matching honors the setting of the ‘extglob’ shell option. | |
6015 | ||
6016 | ‘GLOBSORT’ | |
6017 | Controls how the results of filename expansion are sorted. The | |
6018 | value of this variable specifies the sort criteria and sort order | |
6019 | for the results of filename expansion. If this variable is unset | |
6020 | or set to the null string, filename expansion uses the historical | |
6021 | behavior of sorting by name, in ascending lexicographic order as | |
6022 | determined by the ‘LC_COLLATE’ shell variable. | |
6023 | ||
6024 | If set, a valid value begins with an optional ‘+’, which is | |
6025 | ignored, or ‘-’, which reverses the sort order from ascending to | |
6026 | descending, followed by a sort specifier. The valid sort | |
6027 | specifiers are ‘name’, ‘numeric’, ‘size’, ‘mtime’, ‘atime’, | |
6028 | ‘ctime’, and ‘blocks’, which sort the files on name, names in | |
6029 | numeric rather than lexicographic order, file size, modification | |
6030 | time, access time, inode change time, and number of blocks, | |
6031 | respectively. If any of the non-name keys compare as equal (e.g., | |
6032 | if two files are the same size), sorting uses the name as a | |
6033 | secondary sort key. | |
6034 | ||
6035 | For example, a value of ‘-mtime’ sorts the results in descending | |
6036 | order by modification time (newest first). | |
6037 | ||
6038 | The ‘numeric’ specifier treats names consisting solely of digits as | |
6039 | numbers and sorts them using their numeric value (so "2" sorts | |
6040 | before "10", for example). When using ‘numeric’, names containing | |
6041 | non-digits sort after all the all-digit names and are sorted by | |
6042 | name using the traditional behavior. | |
6043 | ||
6044 | A sort specifier of ‘nosort’ disables sorting completely; Bash | |
6045 | returns the results in the order they are read from the file | |
6046 | system, ignoring any leading ‘-’. | |
6047 | ||
6048 | If the sort specifier is missing, it defaults to NAME, so a value | |
6049 | of ‘+’ is equivalent to the null string, and a value of ‘-’ sorts | |
6050 | by name in descending order. | |
6051 | ||
6052 | Any invalid value restores the historical sorting behavior. | |
6053 | ||
6054 | ‘GROUPS’ | |
6055 | An array variable containing the list of groups of which the | |
6056 | current user is a member. Assignments to ‘GROUPS’ have no effect. | |
6057 | If ‘GROUPS’ is unset, it loses its special properties, even if it | |
6058 | is subsequently reset. | |
6059 | ||
6060 | ‘histchars’ | |
6061 | The two or three characters which control history expansion, quick | |
6062 | substitution, and tokenization (*note History Interaction::). The | |
6063 | first character is the “history expansion” character, the character | |
6064 | which begins a history expansion, normally ‘!’. The second | |
6065 | character is the “quick substitution” character, normally ‘^’. | |
6066 | When it appears as the first character on the line, history | |
6067 | substitution repeats the previous command, replacing one string | |
6068 | with another. The optional third character is the “history | |
6069 | comment” character, normally ‘#’, which indicates that the | |
6070 | remainder of the line is a comment when it appears as the first | |
6071 | character of a word. The history comment character disables | |
6072 | history substitution for the remaining words on the line. It does | |
6073 | not necessarily cause the shell parser to treat the rest of the | |
6074 | line as a comment. | |
6075 | ||
6076 | ‘HISTCMD’ | |
6077 | The history number, or index in the history list, of the current | |
6078 | command. Assignments to ‘HISTCMD’ have no effect. If ‘HISTCMD’ is | |
6079 | unset, it loses its special properties, even if it is subsequently | |
6080 | reset. | |
6081 | ||
6082 | ‘HISTCONTROL’ | |
6083 | A colon-separated list of values controlling how commands are saved | |
6084 | on the history list. If the list of values includes ‘ignorespace’, | |
6085 | lines which begin with a space character are not saved in the | |
6086 | history list. A value of ‘ignoredups’ causes lines which match the | |
6087 | previous history entry not to be saved. A value of ‘ignoreboth’ is | |
6088 | shorthand for ‘ignorespace’ and ‘ignoredups’. A value of | |
6089 | ‘erasedups’ causes all previous lines matching the current line to | |
6090 | be removed from the history list before that line is saved. Any | |
6091 | value not in the above list is ignored. If ‘HISTCONTROL’ is unset, | |
6092 | or does not include a valid value, Bash saves all lines read by the | |
6093 | shell parser on the history list, subject to the value of | |
6094 | ‘HISTIGNORE’. If the first line of a multi-line compound command | |
6095 | was saved, the second and subsequent lines are not tested, and are | |
6096 | added to the history regardless of the value of ‘HISTCONTROL’. If | |
6097 | the first line was not saved, the second and subsequent lines of | |
6098 | the command are not saved either. | |
6099 | ||
6100 | ‘HISTFILE’ | |
6101 | The name of the file to which the command history is saved. Bash | |
6102 | assigns a default value of ‘~/.bash_history’. If ‘HISTFILE’ is | |
6103 | unset or null, the shell does not save the command history when it | |
6104 | exits. | |
6105 | ||
6106 | ‘HISTFILESIZE’ | |
6107 | The maximum number of lines contained in the history file. When | |
6108 | this variable is assigned a value, the history file is truncated, | |
6109 | if necessary, to contain no more than the number of history entries | |
6110 | that total no more than that number of lines by removing the oldest | |
6111 | entries. If the history list contains multi-line entries, the | |
6112 | history file may contain more lines than this maximum to avoid | |
6113 | leaving partial history entries. The history file is also | |
6114 | truncated to this size after writing it when a shell exits or by | |
6115 | the ‘history’ builtin. If the value is 0, the history file is | |
6116 | truncated to zero size. Non-numeric values and numeric values less | |
6117 | than zero inhibit truncation. The shell sets the default value to | |
6118 | the value of ‘HISTSIZE’ after reading any startup files. | |
6119 | ||
6120 | ‘HISTIGNORE’ | |
6121 | A colon-separated list of patterns used to decide which command | |
6122 | lines should be saved on the history list. If a command line | |
6123 | matches one of the patterns in the value of ‘HISTIGNORE’, it is not | |
6124 | saved on the history list. Each pattern is anchored at the | |
6125 | beginning of the line and must match the complete line (Bash does | |
6126 | not implicitly append a ‘*’). Each pattern is tested against the | |
6127 | line after the checks specified by ‘HISTCONTROL’ are applied. In | |
6128 | addition to the normal shell pattern matching characters, ‘&’ | |
6129 | matches the previous history line. A backslash escapes the ‘&’; | |
6130 | the backslash is removed before attempting a match. If the first | |
6131 | line of a multi-line compound command was saved, the second and | |
6132 | subsequent lines are not tested, and are added to the history | |
6133 | regardless of the value of ‘HISTIGNORE’. If the first line was not | |
6134 | saved, the second and subsequent lines of the command are not saved | |
6135 | either. The pattern matching honors the setting of the ‘extglob’ | |
6136 | shell option. | |
6137 | ||
6138 | ‘HISTIGNORE’ subsumes some of the function of ‘HISTCONTROL’. A | |
6139 | pattern of ‘&’ is identical to ‘ignoredups’, and a pattern of ‘[ | |
6140 | ]*’ is identical to ‘ignorespace’. Combining these two patterns, | |
6141 | separating them with a colon, provides the functionality of | |
6142 | ‘ignoreboth’. | |
6143 | ||
6144 | ‘HISTSIZE’ | |
6145 | The maximum number of commands to remember on the history list. If | |
6146 | the value is 0, commands are not saved in the history list. | |
6147 | Numeric values less than zero result in every command being saved | |
6148 | on the history list (there is no limit). The shell sets the | |
6149 | default value to 500 after reading any startup files. | |
6150 | ||
6151 | ‘HISTTIMEFORMAT’ | |
6152 | If this variable is set and not null, its value is used as a format | |
6153 | string for ‘strftime’(3) to print the time stamp associated with | |
6154 | each history entry displayed by the ‘history’ builtin. If this | |
6155 | variable is set, the shell writes time stamps to the history file | |
6156 | so they may be preserved across shell sessions. This uses the | |
6157 | history comment character to distinguish timestamps from other | |
6158 | history lines. | |
6159 | ||
6160 | ‘HOSTFILE’ | |
6161 | Contains the name of a file in the same format as ‘/etc/hosts’ that | |
6162 | should be read when the shell needs to complete a hostname. The | |
6163 | list of possible hostname completions may be changed while the | |
6164 | shell is running; the next time hostname completion is attempted | |
6165 | after the value is changed, Bash adds the contents of the new file | |
6166 | to the existing list. If ‘HOSTFILE’ is set, but has no value, or | |
6167 | does not name a readable file, Bash attempts to read ‘/etc/hosts’ | |
6168 | to obtain the list of possible hostname completions. When | |
6169 | ‘HOSTFILE’ is unset, Bash clears the hostname list. | |
6170 | ||
6171 | ‘HOSTNAME’ | |
6172 | The name of the current host. | |
6173 | ||
6174 | ‘HOSTTYPE’ | |
6175 | A string describing the machine Bash is running on. | |
6176 | ||
6177 | ‘IGNOREEOF’ | |
6178 | Controls the action of the shell on receipt of an ‘EOF’ character | |
6179 | as the sole input. If set, the value is the number of consecutive | |
6180 | ‘EOF’ characters that can be read as the first character on an | |
6181 | input line before Bash exits. If the variable is set but does not | |
6182 | have a numeric value, or the value is null, then the default is 10. | |
6183 | If the variable is unset, then ‘EOF’ signifies the end of input to | |
6184 | the shell. This is only in effect for interactive shells. | |
6185 | ||
6186 | ‘INPUTRC’ | |
6187 | The name of the Readline initialization file, overriding the | |
6188 | default of ‘~/.inputrc’. | |
6189 | ||
6190 | ‘INSIDE_EMACS’ | |
6191 | If Bash finds this variable in the environment when the shell | |
6192 | starts, it assumes that the shell is running in an Emacs shell | |
6193 | buffer and may disable line editing depending on the value of | |
6194 | ‘TERM’. | |
6195 | ||
6196 | ‘LANG’ | |
6197 | Used to determine the locale category for any category not | |
6198 | specifically selected with a variable starting with ‘LC_’. | |
6199 | ||
6200 | ‘LC_ALL’ | |
6201 | This variable overrides the value of ‘LANG’ and any other ‘LC_’ | |
6202 | variable specifying a locale category. | |
6203 | ||
6204 | ‘LC_COLLATE’ | |
6205 | This variable determines the collation order used when sorting the | |
6206 | results of filename expansion, and determines the behavior of range | |
6207 | expressions, equivalence classes, and collating sequences within | |
6208 | filename expansion and pattern matching (*note Filename | |
6209 | Expansion::). | |
6210 | ||
6211 | ‘LC_CTYPE’ | |
6212 | This variable determines the interpretation of characters and the | |
6213 | behavior of character classes within filename expansion and pattern | |
6214 | matching (*note Filename Expansion::). | |
6215 | ||
6216 | ‘LC_MESSAGES’ | |
6217 | This variable determines the locale used to translate double-quoted | |
6218 | strings preceded by a ‘$’ (*note Locale Translation::). | |
6219 | ||
6220 | ‘LC_NUMERIC’ | |
6221 | This variable determines the locale category used for number | |
6222 | formatting. | |
6223 | ||
6224 | ‘LC_TIME’ | |
6225 | This variable determines the locale category used for data and time | |
6226 | formatting. | |
6227 | ||
6228 | ‘LINENO’ | |
6229 | The line number in the script or shell function currently | |
6230 | executing. Line numbers start with 1. When not in a script or | |
6231 | function, the value is not guaranteed to be meaningful. If | |
6232 | ‘LINENO’ is unset, it loses its special properties, even if it is | |
6233 | subsequently reset. | |
6234 | ||
6235 | ‘LINES’ | |
6236 | Used by the ‘select’ command to determine the column length for | |
6237 | printing selection lists. Automatically set if the ‘checkwinsize’ | |
6238 | option is enabled (*note The Shopt Builtin::), or in an interactive | |
6239 | shell upon receipt of a ‘SIGWINCH’. | |
6240 | ||
6241 | ‘MACHTYPE’ | |
6242 | A string that fully describes the system type on which Bash is | |
6243 | executing, in the standard GNU CPU-COMPANY-SYSTEM format. | |
6244 | ||
6245 | ‘MAILCHECK’ | |
6246 | How often (in seconds) that the shell should check for mail in the | |
6247 | files specified in the ‘MAILPATH’ or ‘MAIL’ variables. The default | |
6248 | is 60 seconds. When it is time to check for mail, the shell does | |
6249 | so before displaying the primary prompt. If this variable is | |
6250 | unset, or set to a value that is not a number greater than or equal | |
6251 | to zero, the shell disables mail checking. | |
6252 | ||
6253 | ‘MAPFILE’ | |
6254 | An array variable created to hold the text read by the ‘mapfile’ | |
6255 | builtin when no variable name is supplied. | |
6256 | ||
6257 | ‘OLDPWD’ | |
6258 | The previous working directory as set by the ‘cd’ builtin. | |
6259 | ||
6260 | ‘OPTERR’ | |
6261 | If set to the value 1, Bash displays error messages generated by | |
6262 | the ‘getopts’ builtin command. ‘OPTERR’ is initialized to 1 each | |
6263 | time the shell is invoked. | |
6264 | ||
6265 | ‘OSTYPE’ | |
6266 | A string describing the operating system Bash is running on. | |
6267 | ||
6268 | ‘PIPESTATUS’ | |
6269 | An array variable (*note Arrays::) containing a list of exit status | |
6270 | values from the commands in the most-recently-executed foreground | |
6271 | pipeline, which may consist of only a simple command (*note Shell | |
6272 | Commands::). Bash sets ‘PIPESTATUS’ after executing multi-element | |
6273 | pipelines, timed and negated pipelines, simple commands, subshells | |
6274 | created with the ‘(’ operator, the ‘[[’ and ‘((’ compound commands, | |
6275 | and after error conditions that result in the shell aborting | |
6276 | command execution. | |
6277 | ||
6278 | ‘POSIXLY_CORRECT’ | |
6279 | If this variable is in the environment when Bash starts, the shell | |
6280 | enters POSIX mode (*note Bash POSIX Mode::) before reading the | |
6281 | startup files, as if the ‘--posix’ invocation option had been | |
6282 | supplied. If it is set while the shell is running, Bash enables | |
6283 | POSIX mode, as if the command | |
6284 | set -o posix | |
6285 | had been executed. When the shell enters POSIX mode, it sets this | |
6286 | variable if it was not already set. | |
6287 | ||
6288 | ‘PPID’ | |
6289 | The process ID of the shell's parent process. This variable is | |
6290 | readonly. | |
6291 | ||
6292 | ‘PROMPT_COMMAND’ | |
6293 | If this variable is set, and is an array, the value of each set | |
6294 | element is interpreted as a command to execute before printing the | |
6295 | primary prompt (‘$PS1’). If this is set but not an array variable, | |
6296 | its value is used as a command to execute instead. | |
6297 | ||
6298 | ‘PROMPT_DIRTRIM’ | |
6299 | If set to a number greater than zero, the value is used as the | |
6300 | number of trailing directory components to retain when expanding | |
6301 | the ‘\w’ and ‘\W’ prompt string escapes (*note Controlling the | |
6302 | Prompt::). Characters removed are replaced with an ellipsis. | |
6303 | ||
6304 | ‘PS0’ | |
6305 | The value of this parameter is expanded like ‘PS1’ and displayed by | |
6306 | interactive shells after reading a command and before the command | |
6307 | is executed. | |
6308 | ||
6309 | ‘PS3’ | |
6310 | The value of this variable is used as the prompt for the ‘select’ | |
6311 | command. If this variable is not set, the ‘select’ command prompts | |
6312 | with ‘#? ’ | |
6313 | ||
6314 | ‘PS4’ | |
6315 | The value of this parameter is expanded like ‘PS1’ and the expanded | |
6316 | value is the prompt printed before the command line is echoed when | |
6317 | the ‘-x’ option is set (*note The Set Builtin::). The first | |
6318 | character of the expanded value is replicated multiple times, as | |
6319 | necessary, to indicate multiple levels of indirection. The default | |
6320 | is ‘+ ’. | |
6321 | ||
6322 | ‘PWD’ | |
6323 | The current working directory as set by the ‘cd’ builtin. | |
6324 | ||
6325 | ‘RANDOM’ | |
6326 | Each time this parameter is referenced, it expands to a random | |
6327 | integer between 0 and 32767. Assigning a value to ‘RANDOM’ | |
6328 | initializes (seeds) the sequence of random numbers. Seeding the | |
6329 | random number generator with the same constant value produces the | |
6330 | same sequence of values. If ‘RANDOM’ is unset, it loses its | |
6331 | special properties, even if it is subsequently reset. | |
6332 | ||
6333 | ‘READLINE_ARGUMENT’ | |
6334 | Any numeric argument given to a Readline command that was defined | |
6335 | using ‘bind -x’ (*note Bash Builtins:: when it was invoked. | |
6336 | ||
6337 | ‘READLINE_LINE’ | |
6338 | The contents of the Readline line buffer, for use with ‘bind -x’ | |
6339 | (*note Bash Builtins::). | |
6340 | ||
6341 | ‘READLINE_MARK’ | |
6342 | The position of the “mark” (saved insertion point) in the Readline | |
6343 | line buffer, for use with ‘bind -x’ (*note Bash Builtins::). The | |
6344 | characters between the insertion point and the mark are often | |
6345 | called the “region”. | |
6346 | ||
6347 | ‘READLINE_POINT’ | |
6348 | The position of the insertion point in the Readline line buffer, | |
6349 | for use with ‘bind -x’ (*note Bash Builtins::). | |
6350 | ||
6351 | ‘REPLY’ | |
6352 | The default variable for the ‘read’ builtin; set to the line read | |
6353 | when ‘read’ is not supplied a variable name argument. | |
6354 | ||
6355 | ‘SECONDS’ | |
6356 | This variable expands to the number of seconds since the shell was | |
6357 | started. Assignment to this variable resets the count to the value | |
6358 | assigned, and the expanded value becomes the value assigned plus | |
6359 | the number of seconds since the assignment. The number of seconds | |
6360 | at shell invocation and the current time are always determined by | |
6361 | querying the system clock at one-second resolution. If ‘SECONDS’ | |
6362 | is unset, it loses its special properties, even if it is | |
6363 | subsequently reset. | |
6364 | ||
6365 | ‘SHELL’ | |
6366 | This environment variable expands to the full pathname to the | |
6367 | shell. If it is not set when the shell starts, Bash assigns to it | |
6368 | the full pathname of the current user's login shell. | |
6369 | ||
6370 | ‘SHELLOPTS’ | |
6371 | A colon-separated list of enabled shell options. Each word in the | |
6372 | list is a valid argument for the ‘-o’ option to the ‘set’ builtin | |
6373 | command (*note The Set Builtin::). The options appearing in | |
6374 | ‘SHELLOPTS’ are those reported as ‘on’ by ‘set -o’. If this | |
6375 | variable is in the environment when Bash starts up, the shell | |
6376 | enables each option in the list before reading any startup files. | |
6377 | If this variable is exported, child shells will enable each option | |
6378 | in the list. This variable is readonly. | |
6379 | ||
6380 | ‘SHLVL’ | |
6381 | Incremented by one each time a new instance of Bash is started. | |
6382 | This is intended to be a count of how deeply your Bash shells are | |
6383 | nested. | |
6384 | ||
6385 | ‘SRANDOM’ | |
6386 | This variable expands to a 32-bit pseudo-random number each time it | |
6387 | is referenced. The random number generator is not linear on | |
6388 | systems that support ‘/dev/urandom’ or ‘arc4random’, so each | |
6389 | returned number has no relationship to the numbers preceding it. | |
6390 | The random number generator cannot be seeded, so assignments to | |
6391 | this variable have no effect. If ‘SRANDOM’ is unset, it loses its | |
6392 | special properties, even if it is subsequently reset. | |
6393 | ||
6394 | ‘TIMEFORMAT’ | |
6395 | The value of this parameter is used as a format string specifying | |
6396 | how the timing information for pipelines prefixed with the ‘time’ | |
6397 | reserved word should be displayed. The ‘%’ character introduces an | |
6398 | escape sequence that is expanded to a time value or other | |
6399 | information. The escape sequences and their meanings are as | |
6400 | follows; the brackets denote optional portions. | |
6401 | ||
6402 | ‘%%’ | |
6403 | A literal ‘%’. | |
6404 | ||
6405 | ‘%[P][l]R’ | |
6406 | The elapsed time in seconds. | |
6407 | ||
6408 | ‘%[P][l]U’ | |
6409 | The number of CPU seconds spent in user mode. | |
6410 | ||
6411 | ‘%[P][l]S’ | |
6412 | The number of CPU seconds spent in system mode. | |
6413 | ||
6414 | ‘%P’ | |
6415 | The CPU percentage, computed as (%U + %S) / %R. | |
6416 | ||
6417 | The optional P is a digit specifying the precision, the number of | |
6418 | fractional digits after a decimal point. A value of 0 causes no | |
6419 | decimal point or fraction to be output. ‘time’ prints at most six | |
6420 | digits after the decimal point; values of P greater than 6 are | |
6421 | changed to 6. If P is not specified, ‘time’ prints three digits | |
6422 | after the decimal point. | |
6423 | ||
6424 | The optional ‘l’ specifies a longer format, including minutes, of | |
6425 | the form MMmSS.FFs. The value of P determines whether or not the | |
6426 | fraction is included. | |
6427 | ||
6428 | If this variable is not set, Bash acts as if it had the value | |
6429 | $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS' | |
6430 | If the value is null, Bash does not display any timing information. | |
6431 | A trailing newline is added when the format string is displayed. | |
6432 | ||
6433 | ‘TMOUT’ | |
6434 | If set to a value greater than zero, the ‘read’ builtin uses the | |
6435 | value as its default timeout (*note Bash Builtins::). The ‘select’ | |
6436 | command (*note Conditional Constructs::) terminates if input does | |
6437 | not arrive after ‘TMOUT’ seconds when input is coming from a | |
6438 | terminal. | |
6439 | ||
6440 | In an interactive shell, the value is interpreted as the number of | |
6441 | seconds to wait for a line of input after issuing the primary | |
6442 | prompt. Bash terminates after waiting for that number of seconds | |
6443 | if a complete line of input does not arrive. | |
6444 | ||
6445 | ‘TMPDIR’ | |
6446 | If set, Bash uses its value as the name of a directory in which | |
6447 | Bash creates temporary files for the shell's use. | |
6448 | ||
6449 | ‘UID’ | |
6450 | The numeric real user id of the current user. This variable is | |
6451 | readonly. | |
6452 | ||
6453 | \1f | |
6454 | File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top | |
6455 | ||
6456 | 6 Bash Features | |
6457 | *************** | |
6458 | ||
6459 | This chapter describes features unique to Bash. | |
6460 | ||
6461 | * Menu: | |
6462 | ||
6463 | * Invoking Bash:: Command line options that you can give | |
6464 | to Bash. | |
6465 | * Bash Startup Files:: When and how Bash executes scripts. | |
6466 | * Interactive Shells:: What an interactive shell is. | |
6467 | * Bash Conditional Expressions:: Primitives used in composing expressions for | |
6468 | the ‘test’ builtin. | |
6469 | * Shell Arithmetic:: Arithmetic on shell variables. | |
6470 | * Aliases:: Substituting one command for another. | |
6471 | * Arrays:: Array Variables. | |
6472 | * The Directory Stack:: History of visited directories. | |
6473 | * Controlling the Prompt:: Customizing the various prompt strings. | |
6474 | * The Restricted Shell:: A more controlled mode of shell execution. | |
6475 | * Bash POSIX Mode:: Making Bash behave more closely to what | |
6476 | the POSIX standard specifies. | |
6477 | * Shell Compatibility Mode:: How Bash supports behavior that was present | |
6478 | in earlier versions and has changed. | |
6479 | ||
6480 | \1f | |
6481 | File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features | |
6482 | ||
6483 | 6.1 Invoking Bash | |
6484 | ================= | |
6485 | ||
6486 | bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] | |
6487 | [-O SHOPT_OPTION] [ARGUMENT ...] | |
6488 | bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] | |
6489 | [-O SHOPT_OPTION] -c STRING [ARGUMENT ...] | |
6490 | bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] | |
6491 | [-O SHOPT_OPTION] [ARGUMENT ...] | |
6492 | ||
6493 | All of the single-character options used with the ‘set’ builtin | |
6494 | (*note The Set Builtin::) can be used as options when the shell is | |
6495 | invoked. In addition, there are several multi-character options that | |
6496 | you can use. These options must appear on the command line before the | |
6497 | single-character options to be recognized. | |
6498 | ||
6499 | ‘--debugger’ | |
6500 | Arrange for the debugger profile to be executed before the shell | |
6501 | starts. Turns on extended debugging mode (see *note The Shopt | |
6502 | Builtin:: for a description of the ‘extdebug’ option to the ‘shopt’ | |
6503 | builtin). | |
6504 | ||
6505 | ‘--dump-po-strings’ | |
6506 | Print a list of all double-quoted strings preceded by ‘$’ on the | |
6507 | standard output in the GNU ‘gettext’ PO (portable object) file | |
6508 | format. Equivalent to ‘-D’ except for the output format. | |
6509 | ||
6510 | ‘--dump-strings’ | |
6511 | Equivalent to ‘-D’. | |
6512 | ||
6513 | ‘--help’ | |
6514 | Display a usage message on standard output and exit successfully. | |
6515 | ||
6516 | ‘--init-file FILENAME’ | |
6517 | ‘--rcfile FILENAME’ | |
6518 | Execute commands from FILENAME (instead of ‘~/.bashrc’) in an | |
6519 | interactive shell. | |
6520 | ||
6521 | ‘--login’ | |
6522 | Equivalent to ‘-l’. | |
6523 | ||
6524 | ‘--noediting’ | |
6525 | Do not use the GNU Readline library (*note Command Line Editing::) | |
6526 | to read command lines when the shell is interactive. | |
6527 | ||
6528 | ‘--noprofile’ | |
6529 | Don't load the system-wide startup file ‘/etc/profile’ or any of | |
6530 | the personal initialization files ‘~/.bash_profile’, | |
6531 | ‘~/.bash_login’, or ‘~/.profile’ when Bash is invoked as a login | |
6532 | shell. | |
6533 | ||
6534 | ‘--norc’ | |
6535 | Don't read the ‘~/.bashrc’ initialization file in an interactive | |
6536 | shell. This is on by default if the shell is invoked as ‘sh’. | |
6537 | ||
6538 | ‘--posix’ | |
6539 | Enable POSIX mode; change the behavior of Bash where the default | |
6540 | operation differs from the POSIX standard to match the standard. | |
6541 | This is intended to make Bash behave as a strict superset of that | |
6542 | standard. *Note Bash POSIX Mode::, for a description of the Bash | |
6543 | POSIX mode. | |
6544 | ||
6545 | ‘--restricted’ | |
6546 | Equivalent to ‘-r’. Make the shell a restricted shell (*note The | |
6547 | Restricted Shell::). | |
6548 | ||
6549 | ‘--verbose’ | |
6550 | Equivalent to ‘-v’. Print shell input lines as they're read. | |
6551 | ||
6552 | ‘--version’ | |
6553 | Show version information for this instance of Bash on the standard | |
6554 | output and exit successfully. | |
6555 | ||
6556 | There are several single-character options that may be supplied at | |
6557 | invocation which are not available with the ‘set’ builtin. | |
6558 | ||
6559 | ‘-c’ | |
6560 | Read and execute commands from the first non-option argument | |
6561 | COMMAND_STRING, then exit. If there are arguments after the | |
6562 | COMMAND_STRING, the first argument is assigned to ‘$0’ and any | |
6563 | remaining arguments are assigned to the positional parameters. The | |
6564 | assignment to ‘$0’ sets the name of the shell, which is used in | |
6565 | warning and error messages. | |
6566 | ||
6567 | ‘-i’ | |
6568 | Force the shell to run interactively. Interactive shells are | |
6569 | described in *note Interactive Shells::. | |
6570 | ||
6571 | ‘-l’ | |
6572 | Make this shell act as if it had been directly invoked by login. | |
6573 | When the shell is interactive, this is equivalent to starting a | |
6574 | login shell with ‘exec -l bash’. When the shell is not | |
6575 | interactive, it will read and execute the login shell startup | |
6576 | files. ‘exec bash -l’ or ‘exec bash --login’ will replace the | |
6577 | current shell with a Bash login shell. *Note Bash Startup Files::, | |
6578 | for a description of the special behavior of a login shell. | |
6579 | ||
6580 | ‘-r’ | |
6581 | Make the shell a restricted shell (*note The Restricted Shell::). | |
6582 | ||
6583 | ‘-s’ | |
6584 | If this option is present, or if no arguments remain after option | |
6585 | processing, then Bash reads commands from the standard input. This | |
6586 | option allows the positional parameters to be set when invoking an | |
6587 | interactive shell or when reading input through a pipe. | |
6588 | ||
6589 | ‘-D’ | |
6590 | Print a list of all double-quoted strings preceded by ‘$’ on the | |
6591 | standard output. These are the strings that are subject to | |
6592 | language translation when the current locale is not ‘C’ or ‘POSIX’ | |
6593 | (*note Locale Translation::). This implies the ‘-n’ option; no | |
6594 | commands will be executed. | |
6595 | ||
6596 | ‘[-+]O [SHOPT_OPTION]’ | |
6597 | SHOPT_OPTION is one of the shell options accepted by the ‘shopt’ | |
6598 | builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present, | |
6599 | ‘-O’ sets the value of that option; ‘+O’ unsets it. If | |
6600 | SHOPT_OPTION is not supplied, Bash prints the names and values of | |
6601 | the shell options accepted by ‘shopt’ on the standard output. If | |
6602 | the invocation option is ‘+O’, the output is displayed in a format | |
6603 | that may be reused as input. | |
6604 | ||
6605 | ‘--’ | |
6606 | A ‘--’ signals the end of options and disables further option | |
6607 | processing. Any arguments after the ‘--’ are treated as a shell | |
6608 | script filename (*note Shell Scripts::) and arguments passed to | |
6609 | that script. | |
6610 | ||
6611 | ‘-’ | |
6612 | Equivalent to ‘--’. | |
6613 | ||
6614 | A “login shell” is one whose first character of argument zero is ‘-’, | |
6615 | or one invoked with the ‘--login’ option. | |
6616 | ||
6617 | An “interactive shell” is one started without non-option arguments, | |
6618 | unless ‘-s’ is specified, without specifying the ‘-c’ option, and whose | |
6619 | standard input and standard error are both connected to terminals (as | |
6620 | determined by isatty(3)), or one started with the ‘-i’ option. *Note | |
6621 | Interactive Shells::, for more information. | |
6622 | ||
6623 | If arguments remain after option processing, and neither the ‘-c’ nor | |
6624 | the ‘-s’ option has been supplied, the first argument is treated as the | |
6625 | name of a file containing shell commands (*note Shell Scripts::). When | |
6626 | Bash is invoked in this fashion, ‘$0’ is set to the name of the file, | |
6627 | and the positional parameters are set to the remaining arguments. Bash | |
6628 | reads and executes commands from this file, then exits. Bash's exit | |
6629 | status is the exit status of the last command executed in the script. | |
6630 | If no commands are executed, the exit status is 0. Bash first attempts | |
6631 | to open the file in the current directory, and, if no file is found, | |
6632 | searches the directories in ‘PATH’ for the script. | |
6633 | ||
6634 | \1f | |
6635 | File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features | |
6636 | ||
6637 | 6.2 Bash Startup Files | |
6638 | ====================== | |
6639 | ||
6640 | This section describes how Bash executes its startup files. If any of | |
6641 | the files exist but cannot be read, Bash reports an error. Tildes are | |
6642 | expanded in filenames as described above under Tilde Expansion (*note | |
6643 | Tilde Expansion::). | |
6644 | ||
6645 | Interactive shells are described in *note Interactive Shells::. | |
6646 | ||
6647 | Invoked as an interactive login shell, or with ‘--login’ | |
6648 | ........................................................ | |
6649 | ||
6650 | When Bash is invoked as an interactive login shell, or as a | |
6651 | non-interactive shell with the ‘--login’ option, it first reads and | |
6652 | executes commands from the file ‘/etc/profile’, if that file exists. | |
6653 | After reading that file, it looks for ‘~/.bash_profile’, | |
6654 | ‘~/.bash_login’, and ‘~/.profile’, in that order, and reads and executes | |
6655 | commands from the first one that exists and is readable. The | |
6656 | ‘--noprofile’ option inhibits this behavior. | |
6657 | ||
6658 | When an interactive login shell exits, or a non-interactive login | |
6659 | shell executes the ‘exit’ builtin command, Bash reads and executes | |
6660 | commands from the file ‘~/.bash_logout’, if it exists. | |
6661 | ||
6662 | Invoked as an interactive non-login shell | |
6663 | ......................................... | |
6664 | ||
6665 | When Bash runs as an interactive shell that is not a login shell, it | |
6666 | reads and executes commands from ‘~/.bashrc’, if that file exists. The | |
6667 | ‘--norc’ option inhibits this behavior. The ‘--rcfile FILE’ option | |
6668 | causes Bash to use FILE instead of ‘~/.bashrc’. | |
6669 | ||
6670 | So, typically, your ‘~/.bash_profile’ contains the line | |
6671 | if [ -f ~/.bashrc ]; then . ~/.bashrc; fi | |
6672 | after (or before) any login-specific initializations. | |
6673 | ||
6674 | Invoked non-interactively | |
6675 | ......................... | |
6676 | ||
6677 | When Bash is started non-interactively, to run a shell script, for | |
6678 | example, it looks for the variable ‘BASH_ENV’ in the environment, | |
6679 | expands its value if it appears there, and uses the expanded value as | |
6680 | the name of a file to read and execute. Bash behaves as if the | |
6681 | following command were executed: | |
6682 | if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi | |
6683 | but does not the value of the ‘PATH’ variable to search for the | |
6684 | filename. | |
6685 | ||
6686 | As noted above, if a non-interactive shell is invoked with the | |
6687 | ‘--login’ option, Bash attempts to read and execute commands from the | |
6688 | login shell startup files. | |
6689 | ||
6690 | Invoked with name ‘sh’ | |
6691 | ...................... | |
6692 | ||
6693 | If Bash is invoked with the name ‘sh’, it tries to mimic the startup | |
6694 | behavior of historical versions of ‘sh’ as closely as possible, while | |
6695 | conforming to the POSIX standard as well. | |
6696 | ||
6697 | When invoked as an interactive login shell, or as a non-interactive | |
6698 | shell with the ‘--login’ option, it first attempts to read and execute | |
6699 | commands from ‘/etc/profile’ and ‘~/.profile’, in that order. The | |
6700 | ‘--noprofile’ option inhibits this behavior. | |
6701 | ||
6702 | When invoked as an interactive shell with the name ‘sh’, Bash looks | |
6703 | for the variable ‘ENV’, expands its value if it is defined, and uses the | |
6704 | expanded value as the name of a file to read and execute. Since a shell | |
6705 | invoked as ‘sh’ does not attempt to read and execute commands from any | |
6706 | other startup files, the ‘--rcfile’ option has no effect. | |
6707 | ||
6708 | A non-interactive shell invoked with the name ‘sh’ does not attempt | |
6709 | to read any other startup files. | |
6710 | ||
6711 | When invoked as ‘sh’, Bash enters POSIX mode after reading the | |
6712 | startup files. | |
6713 | ||
6714 | Invoked in POSIX mode | |
6715 | ..................... | |
6716 | ||
6717 | When Bash is started in POSIX mode, as with the ‘--posix’ command line | |
6718 | option, it follows the POSIX standard for startup files. In this mode, | |
6719 | interactive shells expand the ‘ENV’ variable and read and execute | |
6720 | commands from the file whose name is the expanded value. No other | |
6721 | startup files are read. | |
6722 | ||
6723 | Invoked by remote shell daemon | |
6724 | .............................. | |
6725 | ||
6726 | Bash attempts to determine when it is being run with its standard input | |
6727 | connected to a network connection, as when executed by the historical | |
6728 | and rarely-seen remote shell daemon, usually ‘rshd’, or the secure shell | |
6729 | daemon ‘sshd’. If Bash determines it is being run non-interactively in | |
6730 | this fashion, it reads and executes commands from ‘~/.bashrc’, if that | |
6731 | file exists and is readable. Bash does not read this file if invoked as | |
6732 | ‘sh’. The ‘--norc’ option inhibits this behavior, and the ‘--rcfile’ | |
6733 | option makes Bash use a different file instead of ‘~/.bashrc’, but | |
6734 | neither ‘rshd’ nor ‘sshd’ generally invoke the shell with those options | |
6735 | or allow them to be specified. | |
6736 | ||
6737 | Invoked with unequal effective and real UID/GIDs | |
6738 | ................................................ | |
6739 | ||
6740 | If Bash is started with the effective user (group) id not equal to the | |
6741 | real user (group) id, and the ‘-p’ option is not supplied, no startup | |
6742 | files are read, shell functions are not inherited from the environment, | |
6743 | the ‘SHELLOPTS’, ‘BASHOPTS’, ‘CDPATH’, and ‘GLOBIGNORE’ variables, if | |
6744 | they appear in the environment, are ignored, and the effective user id | |
6745 | is set to the real user id. If the ‘-p’ option is supplied at | |
6746 | invocation, the startup behavior is the same, but the effective user id | |
6747 | is not reset. | |
6748 | ||
6749 | \1f | |
6750 | File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features | |
6751 | ||
6752 | 6.3 Interactive Shells | |
6753 | ====================== | |
6754 | ||
6755 | * Menu: | |
6756 | ||
6757 | * What is an Interactive Shell?:: What determines whether a shell is Interactive. | |
6758 | * Is this Shell Interactive?:: How to tell if a shell is interactive. | |
6759 | * Interactive Shell Behavior:: What changes in an interactive shell? | |
6760 | ||
6761 | \1f | |
6762 | File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells | |
6763 | ||
6764 | 6.3.1 What is an Interactive Shell? | |
6765 | ----------------------------------- | |
6766 | ||
6767 | An interactive shell is one started without non-option arguments (unless | |
6768 | ‘-s’ is specified) and without specifying the ‘-c’ option, whose input | |
6769 | and error output are both connected to terminals (as determined by | |
6770 | ‘isatty(3)’), or one started with the ‘-i’ option. | |
6771 | ||
6772 | An interactive shell generally reads from and writes to a user's | |
6773 | terminal. | |
6774 | ||
6775 | The ‘-s’ invocation option may be used to set the positional | |
6776 | parameters when an interactive shell starts. | |
6777 | ||
6778 | \1f | |
6779 | File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells | |
6780 | ||
6781 | 6.3.2 Is this Shell Interactive? | |
6782 | -------------------------------- | |
6783 | ||
6784 | To determine within a startup script whether or not Bash is running | |
6785 | interactively, test the value of the ‘-’ special parameter. It contains | |
6786 | ‘i’ when the shell is interactive. For example: | |
6787 | ||
6788 | case "$-" in | |
6789 | *i*) echo This shell is interactive ;; | |
6790 | *) echo This shell is not interactive ;; | |
6791 | esac | |
6792 | ||
6793 | Alternatively, startup scripts may examine the variable ‘PS1’; it is | |
6794 | unset in non-interactive shells, and set in interactive shells. Thus: | |
6795 | ||
6796 | if [ -z "$PS1" ]; then | |
6797 | echo This shell is not interactive | |
6798 | else | |
6799 | echo This shell is interactive | |
6800 | fi | |
6801 | ||
6802 | \1f | |
6803 | File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells | |
6804 | ||
6805 | 6.3.3 Interactive Shell Behavior | |
6806 | -------------------------------- | |
6807 | ||
6808 | When the shell is running interactively, it changes its behavior in | |
6809 | several ways. | |
6810 | ||
6811 | 1. Bash reads and executes startup files as described in *note Bash | |
6812 | Startup Files::. | |
6813 | ||
6814 | 2. Job Control (*note Job Control::) is enabled by default. When job | |
6815 | control is in effect, Bash ignores the keyboard-generated job | |
6816 | control signals ‘SIGTTIN’, ‘SIGTTOU’, and ‘SIGTSTP’. | |
6817 | ||
6818 | 3. Bash executes the values of the set elements of the | |
6819 | ‘PROMPT_COMMAND’ array variable as commands before printing the | |
6820 | primary prompt, ‘$PS1’ (*note Bash Variables::). | |
6821 | ||
6822 | 4. Bash expands and displays ‘PS1’ before reading the first line of a | |
6823 | command, and expands and displays ‘PS2’ before reading the second | |
6824 | and subsequent lines of a multi-line command. Bash expands and | |
6825 | displays ‘PS0’ after it reads a command but before executing it. | |
6826 | See *note Controlling the Prompt::, for a complete list of prompt | |
6827 | string escape sequences. | |
6828 | ||
6829 | 5. Bash uses Readline (*note Command Line Editing::) to read commands | |
6830 | from the user's terminal. | |
6831 | ||
6832 | 6. Bash inspects the value of the ‘ignoreeof’ option to ‘set -o’ | |
6833 | instead of exiting immediately when it receives an ‘EOF’ on its | |
6834 | standard input when reading a command (*note The Set Builtin::). | |
6835 | ||
6836 | 7. Bash enables Command history (*note Bash History Facilities::) and | |
6837 | history expansion (*note History Interaction::) by default. When a | |
6838 | shell with history enabled exits, Bash saves the command history to | |
6839 | the file named by ‘$HISTFILE’. | |
6840 | ||
6841 | 8. Alias expansion (*note Aliases::) is performed by default. | |
6842 | ||
6843 | 9. In the absence of any traps, Bash ignores ‘SIGTERM’ (*note | |
6844 | Signals::). | |
6845 | ||
6846 | 10. In the absence of any traps, ‘SIGINT’ is caught and handled (*note | |
6847 | Signals::). ‘SIGINT’ will interrupt some shell builtins. | |
6848 | ||
6849 | 11. An interactive login shell sends a ‘SIGHUP’ to all jobs on exit if | |
6850 | the ‘huponexit’ shell option has been enabled (*note Signals::). | |
6851 | ||
6852 | 12. The ‘-n’ option has no effect, whether at invocation or when using | |
6853 | ‘set -n’ (*note The Set Builtin::). | |
6854 | ||
6855 | 13. Bash will check for mail periodically, depending on the values of | |
6856 | the ‘MAIL’, ‘MAILPATH’, and ‘MAILCHECK’ shell variables (*note Bash | |
6857 | Variables::). | |
6858 | ||
6859 | 14. The shell will not exit on expansion errors due to references to | |
6860 | unbound shell variables after ‘set -u’ has been enabled (*note The | |
6861 | Set Builtin::). | |
6862 | ||
6863 | 15. The shell will not exit on expansion errors caused by VAR being | |
6864 | unset or null in ‘${VAR:?WORD}’ expansions (*note Shell Parameter | |
6865 | Expansion::). | |
6866 | ||
6867 | 16. Redirection errors encountered by shell builtins will not cause | |
6868 | the shell to exit. | |
6869 | ||
6870 | 17. When running in POSIX mode, a special builtin returning an error | |
6871 | status will not cause the shell to exit (*note Bash POSIX Mode::). | |
6872 | ||
6873 | 18. A failed ‘exec’ will not cause the shell to exit (*note Bourne | |
6874 | Shell Builtins::). | |
6875 | ||
6876 | 19. Parser syntax errors will not cause the shell to exit. | |
6877 | ||
6878 | 20. If the ‘cdspell’ shell option is enabled, the shell will attempt | |
6879 | simple spelling correction for directory arguments to the ‘cd’ | |
6880 | builtin (see the description of the ‘cdspell’ option to the ‘shopt’ | |
6881 | builtin in *note The Shopt Builtin::). The ‘cdspell’ option is | |
6882 | only effective in interactive shells. | |
6883 | ||
6884 | 21. The shell will check the value of the ‘TMOUT’ variable and exit if | |
6885 | a command is not read within the specified number of seconds after | |
6886 | printing ‘$PS1’ (*note Bash Variables::). | |
6887 | ||
6888 | \1f | |
6889 | File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features | |
6890 | ||
6891 | 6.4 Bash Conditional Expressions | |
6892 | ================================ | |
6893 | ||
6894 | Conditional expressions are used by the ‘[[’ compound command (*note | |
6895 | Conditional Constructs::) and the ‘test’ and ‘[’ builtin commands (*note | |
6896 | Bourne Shell Builtins::). The ‘test’ and ‘[’ commands determine their | |
6897 | behavior based on the number of arguments; see the descriptions of those | |
6898 | commands for any other command-specific actions. | |
6899 | ||
6900 | Expressions may be unary or binary, and are formed from the primaries | |
6901 | listed below. Unary expressions are often used to examine the status of | |
6902 | a file or shell variable. Binary operators are used for string, | |
6903 | numeric, and file attribute comparisons. | |
6904 | ||
6905 | Bash handles several filenames specially when they are used in | |
6906 | expressions. If the operating system on which Bash is running provides | |
6907 | these special files, Bash uses them; otherwise it emulates them | |
6908 | internally with this behavior: If the FILE argument to one of the | |
6909 | primaries is of the form ‘/dev/fd/N’, then Bash checks file descriptor | |
6910 | N. If the FILE argument to one of the primaries is one of ‘/dev/stdin’, | |
6911 | ‘/dev/stdout’, or ‘/dev/stderr’, Bash checks file descriptor 0, 1, or 2, | |
6912 | respectively. | |
6913 | ||
6914 | When used with ‘[[’, the ‘<’ and ‘>’ operators sort lexicographically | |
6915 | using the current locale. The ‘test’ command uses ASCII ordering. | |
6916 | ||
6917 | Unless otherwise specified, primaries that operate on files follow | |
6918 | symbolic links and operate on the target of the link, rather than the | |
6919 | link itself. | |
6920 | ||
6921 | ‘-a FILE’ | |
6922 | True if FILE exists. | |
6923 | ||
6924 | ‘-b FILE’ | |
6925 | True if FILE exists and is a block special file. | |
6926 | ||
6927 | ‘-c FILE’ | |
6928 | True if FILE exists and is a character special file. | |
6929 | ||
6930 | ‘-d FILE’ | |
6931 | True if FILE exists and is a directory. | |
6932 | ||
6933 | ‘-e FILE’ | |
6934 | True if FILE exists. | |
6935 | ||
6936 | ‘-f FILE’ | |
6937 | True if FILE exists and is a regular file. | |
6938 | ||
6939 | ‘-g FILE’ | |
6940 | True if FILE exists and its set-group-id bit is set. | |
6941 | ||
6942 | ‘-h FILE’ | |
6943 | True if FILE exists and is a symbolic link. | |
6944 | ||
6945 | ‘-k FILE’ | |
6946 | True if FILE exists and its "sticky" bit is set. | |
6947 | ||
6948 | ‘-p FILE’ | |
6949 | True if FILE exists and is a named pipe (FIFO). | |
6950 | ||
6951 | ‘-r FILE’ | |
6952 | True if FILE exists and is readable. | |
6953 | ||
6954 | ‘-s FILE’ | |
6955 | True if FILE exists and has a size greater than zero. | |
6956 | ||
6957 | ‘-t FD’ | |
6958 | True if file descriptor FD is open and refers to a terminal. | |
6959 | ||
6960 | ‘-u FILE’ | |
6961 | True if FILE exists and its set-user-id bit is set. | |
6962 | ||
6963 | ‘-w FILE’ | |
6964 | True if FILE exists and is writable. | |
6965 | ||
6966 | ‘-x FILE’ | |
6967 | True if FILE exists and is executable. | |
6968 | ||
6969 | ‘-G FILE’ | |
6970 | True if FILE exists and is owned by the effective group id. | |
6971 | ||
6972 | ‘-L FILE’ | |
6973 | True if FILE exists and is a symbolic link. | |
6974 | ||
6975 | ‘-N FILE’ | |
6976 | True if FILE exists and has been modified since it was last | |
6977 | accessed. | |
6978 | ||
6979 | ‘-O FILE’ | |
6980 | True if FILE exists and is owned by the effective user id. | |
6981 | ||
6982 | ‘-S FILE’ | |
6983 | True if FILE exists and is a socket. | |
6984 | ||
6985 | ‘FILE1 -ef FILE2’ | |
6986 | True if FILE1 and FILE2 refer to the same device and inode numbers. | |
6987 | ||
6988 | ‘FILE1 -nt FILE2’ | |
6989 | True if FILE1 is newer (according to modification date) than FILE2, | |
6990 | or if FILE1 exists and FILE2 does not. | |
6991 | ||
6992 | ‘FILE1 -ot FILE2’ | |
6993 | True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 | |
6994 | does not. | |
6995 | ||
6996 | ‘-o OPTNAME’ | |
6997 | True if the shell option OPTNAME is enabled. The list of options | |
6998 | appears in the description of the ‘-o’ option to the ‘set’ builtin | |
6999 | (*note The Set Builtin::). | |
7000 | ||
7001 | ‘-v VARNAME’ | |
7002 | True if the shell variable VARNAME is set (has been assigned a | |
7003 | value). If VARNAME is an indexed array variable name subscripted | |
7004 | by ‘@’ or ‘*’, this returns true if the array has any set elements. | |
7005 | If VARNAME is an associative array variable name subscripted by ‘@’ | |
7006 | or ‘*’, this returns true if an element with that key is set. | |
7007 | ||
7008 | ‘-R VARNAME’ | |
7009 | True if the shell variable VARNAME is set and is a name reference. | |
7010 | ||
7011 | ‘-z STRING’ | |
7012 | True if the length of STRING is zero. | |
7013 | ||
7014 | ‘-n STRING’ | |
7015 | ‘STRING’ | |
7016 | True if the length of STRING is non-zero. | |
7017 | ||
7018 | ‘STRING1 == STRING2’ | |
7019 | ‘STRING1 = STRING2’ | |
7020 | True if the strings are equal. When used with the ‘[[’ command, | |
7021 | this performs pattern matching as described above (*note | |
7022 | Conditional Constructs::). | |
7023 | ||
7024 | ‘=’ should be used with the ‘test’ command for POSIX conformance. | |
7025 | ||
7026 | ‘STRING1 != STRING2’ | |
7027 | True if the strings are not equal. | |
7028 | ||
7029 | ‘STRING1 < STRING2’ | |
7030 | True if STRING1 sorts before STRING2 lexicographically. | |
7031 | ||
7032 | ‘STRING1 > STRING2’ | |
7033 | True if STRING1 sorts after STRING2 lexicographically. | |
7034 | ||
7035 | ‘ARG1 OP ARG2’ | |
7036 | ‘OP’ is one of ‘-eq’, ‘-ne’, ‘-lt’, ‘-le’, ‘-gt’, or ‘-ge’. These | |
7037 | arithmetic binary operators return true if ARG1 is equal to, not | |
7038 | equal to, less than, less than or equal to, greater than, or | |
7039 | greater than or equal to ARG2, respectively. ARG1 and ARG2 may be | |
7040 | positive or negative integers. When used with the ‘[[’ command, | |
7041 | ARG1 and ARG2 are evaluated as arithmetic expressions (*note Shell | |
7042 | Arithmetic::). Since the expansions the ‘[[’ command performs on | |
7043 | ARG1 and ARG2 can potentially result in empty strings, arithmetic | |
7044 | expression evaluation treats those as expressions that evaluate to | |
7045 | 0. | |
7046 | ||
7047 | \1f | |
7048 | File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features | |
7049 | ||
7050 | 6.5 Shell Arithmetic | |
7051 | ==================== | |
7052 | ||
7053 | The shell allows arithmetic expressions to be evaluated, as one of the | |
7054 | shell expansions or by using the ‘((’ compound command, the ‘let’ and | |
7055 | ‘declare’ builtins, the arithmetic ‘for’ command, the ‘[[’ conditional | |
7056 | command, or the ‘-i’ option to the ‘declare’ builtin. | |
7057 | ||
7058 | Evaluation is done in the largest fixed-width integers available, | |
7059 | with no check for overflow, though division by 0 is trapped and flagged | |
7060 | as an error. The operators and their precedence, associativity, and | |
7061 | values are the same as in the C language. The following list of | |
7062 | operators is grouped into levels of equal-precedence operators. The | |
7063 | levels are listed in order of decreasing precedence. | |
7064 | ||
7065 | ‘ID++ ID--’ | |
7066 | variable post-increment and post-decrement | |
7067 | ||
7068 | ‘++ID --ID’ | |
7069 | variable pre-increment and pre-decrement | |
7070 | ||
7071 | ‘- +’ | |
7072 | unary minus and plus | |
7073 | ||
7074 | ‘! ~’ | |
7075 | logical and bitwise negation | |
7076 | ||
7077 | ‘**’ | |
7078 | exponentiation | |
7079 | ||
7080 | ‘* / %’ | |
7081 | multiplication, division, remainder | |
7082 | ||
7083 | ‘+ -’ | |
7084 | addition, subtraction | |
7085 | ||
7086 | ‘<< >>’ | |
7087 | left and right bitwise shifts | |
7088 | ||
7089 | ‘<= >= < >’ | |
7090 | comparison | |
7091 | ||
7092 | ‘== !=’ | |
7093 | equality and inequality | |
7094 | ||
7095 | ‘&’ | |
7096 | bitwise AND | |
7097 | ||
7098 | ‘^’ | |
7099 | bitwise exclusive OR | |
7100 | ||
7101 | ‘|’ | |
7102 | bitwise OR | |
7103 | ||
7104 | ‘&&’ | |
7105 | logical AND | |
7106 | ||
7107 | ‘||’ | |
7108 | logical OR | |
7109 | ||
7110 | ‘expr ? if-true-expr : if-false-expr’ | |
7111 | conditional operator | |
7112 | ||
7113 | ‘= *= /= %= += -= <<= >>= &= ^= |=’ | |
7114 | assignment | |
7115 | ||
7116 | ‘expr1 , expr2’ | |
7117 | comma | |
7118 | ||
7119 | Shell variables are allowed as operands; parameter expansion is | |
7120 | performed before the expression is evaluated. Within an expression, | |
7121 | shell variables may also be referenced by name without using the | |
7122 | parameter expansion syntax. This means you can use X, where X is a | |
7123 | shell variable name, in an arithmetic expression, and the shell will | |
7124 | evaluate its value as an expression and use the result. A shell | |
7125 | variable that is null or unset evaluates to 0 when referenced by name in | |
7126 | an expression. | |
7127 | ||
7128 | The value of a variable is evaluated as an arithmetic expression when | |
7129 | it is referenced, or when a variable which has been given the ‘integer’ | |
7130 | attribute using ‘declare -i’ is assigned a value. A null value | |
7131 | evaluates to 0. A shell variable need not have its ‘integer’ attribute | |
7132 | turned on to be used in an expression. | |
7133 | ||
7134 | Integer constants follow the C language definition, without suffixes | |
7135 | or character constants. Constants with a leading 0 are interpreted as | |
7136 | octal numbers. A leading ‘0x’ or ‘0X’ denotes hexadecimal. Otherwise, | |
7137 | numbers take the form [BASE‘#’]N, where the optional BASE is a decimal | |
7138 | number between 2 and 64 representing the arithmetic base, and N is a | |
7139 | number in that base. If BASE‘#’ is omitted, then base 10 is used. When | |
7140 | specifying N, if a non-digit is required, the digits greater than 9 are | |
7141 | represented by the lowercase letters, the uppercase letters, ‘@’, and | |
7142 | ‘_’, in that order. If BASE is less than or equal to 36, lowercase and | |
7143 | uppercase letters may be used interchangeably to represent numbers | |
7144 | between 10 and 35. | |
7145 | ||
7146 | Operators are evaluated in precedence order. Sub-expressions in | |
7147 | parentheses are evaluated first and may override the precedence rules | |
7148 | above. | |
7149 | ||
7150 | \1f | |
7151 | File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features | |
7152 | ||
7153 | 6.6 Aliases | |
7154 | =========== | |
7155 | ||
7156 | “Aliases” allow a string to be substituted for a word that is in a | |
7157 | position in the input where it can be the first word of a simple | |
7158 | command. Aliases have names and corresponding values that are set and | |
7159 | unset using the ‘alias’ and ‘unalias’ builtin commands (*note Shell | |
7160 | Builtin Commands::). | |
7161 | ||
7162 | If the shell reads an unquoted word in the right position, it checks | |
7163 | the word to see if it matches an alias name. If it matches, the shell | |
7164 | replaces the word with the alias value, and reads that value as if it | |
7165 | had been read instead of the word. The shell doesn't look at any | |
7166 | characters following the word before attempting alias substitution. | |
7167 | ||
7168 | The characters ‘/’, ‘$’, ‘`’, ‘=’ and any of the shell metacharacters | |
7169 | or quoting characters listed above may not appear in an alias name. The | |
7170 | replacement text may contain any valid shell input, including shell | |
7171 | metacharacters. The first word of the replacement text is tested for | |
7172 | aliases, but a word that is identical to an alias being expanded is not | |
7173 | expanded a second time. This means that one may alias ‘ls’ to ‘"ls | |
7174 | -F"’, for instance, and Bash does not try to recursively expand the | |
7175 | replacement text. | |
7176 | ||
7177 | If the last character of the alias value is a ‘blank’, then the shell | |
7178 | checks the next command word following the alias for alias expansion. | |
7179 | ||
7180 | Aliases are created and listed with the ‘alias’ command, and removed | |
7181 | with the ‘unalias’ command. | |
7182 | ||
7183 | There is no mechanism for using arguments in the replacement text, as | |
7184 | in ‘csh’. If arguments are needed, use a shell function (*note Shell | |
7185 | Functions::) instead. | |
7186 | ||
7187 | Aliases are not expanded when the shell is not interactive, unless | |
7188 | the ‘expand_aliases’ shell option is set using ‘shopt’ (*note The Shopt | |
7189 | Builtin::). | |
7190 | ||
7191 | The rules concerning the definition and use of aliases are somewhat | |
7192 | confusing. Bash always reads at least one complete line of input, and | |
7193 | all lines that make up a compound command, before executing any of the | |
7194 | commands on that line or the compound command. Aliases are expanded | |
7195 | when a command is read, not when it is executed. Therefore, an alias | |
7196 | definition appearing on the same line as another command does not take | |
7197 | effect until the shell reads the next line of input, and an alias | |
7198 | definition in a compound command does not take effect until the shell | |
7199 | parses and executes the entire compound command. The commands following | |
7200 | the alias definition on that line, or in the rest of a compound command, | |
7201 | are not affected by the new alias. This behavior is also an issue when | |
7202 | functions are executed. Aliases are expanded when a function definition | |
7203 | is read, not when the function is executed, because a function | |
7204 | definition is itself a command. As a consequence, aliases defined in a | |
7205 | function are not available until after that function is executed. To be | |
7206 | safe, always put alias definitions on a separate line, and do not use | |
7207 | ‘alias’ in compound commands. | |
7208 | ||
7209 | For almost every purpose, shell functions are preferable to aliases. | |
7210 | ||
7211 | \1f | |
7212 | File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features | |
7213 | ||
7214 | 6.7 Arrays | |
7215 | ========== | |
7216 | ||
7217 | Bash provides one-dimensional indexed and associative array variables. | |
7218 | Any variable may be used as an indexed array; the ‘declare’ builtin | |
7219 | explicitly declares an array. There is no maximum limit on the size of | |
7220 | an array, nor any requirement that members be indexed or assigned | |
7221 | contiguously. Indexed arrays are referenced using arithmetic | |
7222 | expressions that must expand to an integer (*note Shell Arithmetic::)) | |
7223 | and are zero-based; associative arrays use arbitrary strings. Unless | |
7224 | otherwise noted, indexed array indices must be non-negative integers. | |
7225 | ||
7226 | The shell performs parameter and variable expansion, arithmetic | |
7227 | expansion, command substitution, and quote removal on indexed array | |
7228 | subscripts. Since this can potentially result in empty strings, | |
7229 | subscript indexing treats those as expressions that evaluate to 0. | |
7230 | ||
7231 | The shell performs tilde expansion, parameter and variable expansion, | |
7232 | arithmetic expansion, command substitution, and quote removal on | |
7233 | associative array subscripts. Empty strings cannot be used as | |
7234 | associative array keys. | |
7235 | ||
7236 | Bash automatically creates an indexed array if any variable is | |
7237 | assigned to using the syntax | |
7238 | NAME[SUBSCRIPT]=VALUE | |
7239 | ||
7240 | The SUBSCRIPT is treated as an arithmetic expression that must evaluate | |
7241 | to a number greater than or equal to zero. To explicitly declare an | |
7242 | indexed array, use | |
7243 | declare -a NAME | |
7244 | (*note Bash Builtins::). The syntax | |
7245 | declare -a NAME[SUBSCRIPT] | |
7246 | is also accepted; the SUBSCRIPT is ignored. | |
7247 | ||
7248 | Associative arrays are created using | |
7249 | declare -A NAME | |
7250 | ||
7251 | Attributes may be specified for an array variable using the ‘declare’ | |
7252 | and ‘readonly’ builtins. Each attribute applies to all members of an | |
7253 | array. | |
7254 | ||
7255 | Arrays are assigned using compound assignments of the form | |
7256 | NAME=(VALUE1 VALUE2 ... ) | |
7257 | where each VALUE may be of the form ‘[SUBSCRIPT]=’STRING. Indexed array | |
7258 | assignments do not require anything but STRING. | |
7259 | ||
7260 | Each VALUE in the list undergoes the shell expansions described above | |
7261 | (*note Shell Expansions::), but VALUEs that are valid variable | |
7262 | assignments including the brackets and subscript do not undergo brace | |
7263 | expansion and word splitting, as with individual variable assignments. | |
7264 | ||
7265 | When assigning to indexed arrays, if the optional subscript is | |
7266 | supplied, that index is assigned to; otherwise the index of the element | |
7267 | assigned is the last index assigned to by the statement plus one. | |
7268 | Indexing starts at zero. | |
7269 | ||
7270 | When assigning to an associative array, the words in a compound | |
7271 | assignment may be either assignment statements, for which the subscript | |
7272 | is required, or a list of words that is interpreted as a sequence of | |
7273 | alternating keys and values: NAME=(KEY1 VALUE1 KEY2 VALUE2 ... ). These | |
7274 | are treated identically to NAME=( [KEY1]=VALUE1 [KEY2]=VALUE2 ... ). | |
7275 | The first word in the list determines how the remaining words are | |
7276 | interpreted; all assignments in a list must be of the same type. When | |
7277 | using key/value pairs, the keys may not be missing or empty; a final | |
7278 | missing value is treated like the empty string. | |
7279 | ||
7280 | This syntax is also accepted by the ‘declare’ builtin. Individual | |
7281 | array elements may be assigned to using the ‘NAME[SUBSCRIPT]=VALUE’ | |
7282 | syntax introduced above. | |
7283 | ||
7284 | When assigning to an indexed array, if NAME is subscripted by a | |
7285 | negative number, that number is interpreted as relative to one greater | |
7286 | than the maximum index of NAME, so negative indices count back from the | |
7287 | end of the array, and an index of -1 references the last element. | |
7288 | ||
7289 | The ‘+=’ operator appends to an array variable when assigning using | |
7290 | the compound assignment syntax; see *note Shell Parameters:: above. | |
7291 | ||
7292 | An array element is referenced using ‘${NAME[SUBSCRIPT]}’. The | |
7293 | braces are required to avoid conflicts with the shell's filename | |
7294 | expansion operators. If the SUBSCRIPT is ‘@’ or ‘*’, the word expands | |
7295 | to all members of the array NAME, unless otherwise noted in the | |
7296 | description of a builtin or word expansion. These subscripts differ | |
7297 | only when the word appears within double quotes. If the word is | |
7298 | double-quoted, ‘${NAME[*]}’ expands to a single word with the value of | |
7299 | each array member separated by the first character of the ‘IFS’ | |
7300 | variable, and ‘${NAME[@]}’ expands each element of NAME to a separate | |
7301 | word. When there are no array members, ‘${NAME[@]}’ expands to nothing. | |
7302 | If the double-quoted expansion occurs within a word, the expansion of | |
7303 | the first parameter is joined with the beginning part of the expansion | |
7304 | of the original word, and the expansion of the last parameter is joined | |
7305 | with the last part of the expansion of the original word. This is | |
7306 | analogous to the expansion of the special parameters ‘@’ and ‘*’. | |
7307 | ||
7308 | ‘${#NAME[SUBSCRIPT]}’ expands to the length of ‘${NAME[SUBSCRIPT]}’. | |
7309 | If SUBSCRIPT is ‘@’ or ‘*’, the expansion is the number of elements in | |
7310 | the array. | |
7311 | ||
7312 | If the SUBSCRIPT used to reference an element of an indexed array | |
7313 | evaluates to a number less than zero, it is interpreted as relative to | |
7314 | one greater than the maximum index of the array, so negative indices | |
7315 | count back from the end of the array, and an index of -1 refers to the | |
7316 | last element. | |
7317 | ||
7318 | Referencing an array variable without a subscript is equivalent to | |
7319 | referencing with a subscript of 0. Any reference to a variable using a | |
7320 | valid subscript is valid; Bash creates an array if necessary. | |
7321 | ||
7322 | An array variable is considered set if a subscript has been assigned | |
7323 | a value. The null string is a valid value. | |
7324 | ||
7325 | It is possible to obtain the keys (indices) of an array as well as | |
7326 | the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned | |
7327 | in array variable NAME. The treatment when in double quotes is similar | |
7328 | to the expansion of the special parameters ‘@’ and ‘*’ within double | |
7329 | quotes. | |
7330 | ||
7331 | The ‘unset’ builtin is used to destroy arrays. ‘unset | |
7332 | NAME[SUBSCRIPT]’ unsets the array element at index SUBSCRIPT. Negative | |
7333 | subscripts to indexed arrays are interpreted as described above. | |
7334 | Unsetting the last element of an array variable does not unset the | |
7335 | variable. ‘unset NAME’, where NAME is an array, removes the entire | |
7336 | array. ‘unset NAME[SUBSCRIPT]’ behaves differently depending on the | |
7337 | array type when SUBSCRIPT is ‘*’ or ‘@’. When NAME is an associative | |
7338 | array, it removes the element with key ‘*’ or ‘@’. If NAME is an | |
7339 | indexed array, ‘unset’ removes all of the elements, but does not remove | |
7340 | the array itself. | |
7341 | ||
7342 | When using a variable name with a subscript as an argument to a | |
7343 | command, such as with ‘unset’, without using the word expansion syntax | |
7344 | described above (e.g., unset a[4]), the argument is subject to the | |
7345 | shell's filename expansion. Quote the argument if pathname expansion is | |
7346 | not desired (e.g., unset 'a[4]'). | |
7347 | ||
7348 | The ‘declare’, ‘local’, and ‘readonly’ builtins each accept a ‘-a’ | |
7349 | option to specify an indexed array and a ‘-A’ option to specify an | |
7350 | associative array. If both options are supplied, ‘-A’ takes precedence. | |
7351 | The ‘read’ builtin accepts a ‘-a’ option to assign a list of words read | |
7352 | from the standard input to an array, and can read values from the | |
7353 | standard input into individual array elements. The ‘set’ and ‘declare’ | |
7354 | builtins display array values in a way that allows them to be reused as | |
7355 | input. Other builtins accept array name arguments as well (e.g., | |
7356 | ‘mapfile’); see the descriptions of individual builtins for details. | |
7357 | The shell provides a number of builtin array variables. | |
7358 | ||
7359 | \1f | |
7360 | File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features | |
7361 | ||
7362 | 6.8 The Directory Stack | |
7363 | ======================= | |
7364 | ||
7365 | * Menu: | |
7366 | ||
7367 | * Directory Stack Builtins:: Bash builtin commands to manipulate | |
7368 | the directory stack. | |
7369 | ||
7370 | The directory stack is a list of recently-visited directories. The | |
7371 | ‘pushd’ builtin adds directories to the stack as it changes the current | |
7372 | directory, and the ‘popd’ builtin removes specified directories from the | |
7373 | stack and changes the current directory to the directory removed. The | |
7374 | ‘dirs’ builtin displays the contents of the directory stack. The | |
7375 | current directory is always the "top" of the directory stack. | |
7376 | ||
7377 | The contents of the directory stack are also visible as the value of | |
7378 | the ‘DIRSTACK’ shell variable. | |
7379 | ||
7380 | \1f | |
7381 | File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack | |
7382 | ||
7383 | 6.8.1 Directory Stack Builtins | |
7384 | ------------------------------ | |
7385 | ||
7386 | ‘dirs’ | |
7387 | dirs [-clpv] [+N | -N] | |
7388 | ||
7389 | Without options, display the list of currently remembered | |
7390 | directories. Directories are added to the list with the ‘pushd’ | |
7391 | command; the ‘popd’ command removes directories from the list. The | |
7392 | current directory is always the first directory in the stack. | |
7393 | ||
7394 | Options, if supplied, have the following meanings: | |
7395 | ||
7396 | ‘-c’ | |
7397 | Clears the directory stack by deleting all of the elements. | |
7398 | ‘-l’ | |
7399 | Produces a listing using full pathnames; the default listing | |
7400 | format uses a tilde to denote the home directory. | |
7401 | ‘-p’ | |
7402 | Causes ‘dirs’ to print the directory stack with one entry per | |
7403 | line. | |
7404 | ‘-v’ | |
7405 | Causes ‘dirs’ to print the directory stack with one entry per | |
7406 | line, prefixing each entry with its index in the stack. | |
7407 | ‘+N’ | |
7408 | Displays the Nth directory (counting from the left of the list | |
7409 | printed by ‘dirs’ when invoked without options), starting with | |
7410 | zero. | |
7411 | ‘-N’ | |
7412 | Displays the Nth directory (counting from the right of the | |
7413 | list printed by ‘dirs’ when invoked without options), starting | |
7414 | with zero. | |
7415 | ||
7416 | ‘popd’ | |
7417 | popd [-n] [+N | -N] | |
7418 | ||
7419 | Remove elements from the directory stack. The elements are | |
7420 | numbered from 0 starting at the first directory listed by ‘dirs’; | |
7421 | that is, ‘popd’ is equivalent to ‘popd +0’. | |
7422 | ||
7423 | When no arguments are given, ‘popd’ removes the top directory from | |
7424 | the stack and changes to the new top directory. | |
7425 | ||
7426 | Arguments, if supplied, have the following meanings: | |
7427 | ||
7428 | ‘-n’ | |
7429 | Suppress the normal change of directory when removing | |
7430 | directories from the stack, only manipulate the stack. | |
7431 | ‘+N’ | |
7432 | Remove the Nth directory (counting from the left of the list | |
7433 | printed by ‘dirs’), starting with zero, from the stack. | |
7434 | ‘-N’ | |
7435 | Remove the Nth directory (counting from the right of the list | |
7436 | printed by ‘dirs’), starting with zero, from the stack. | |
7437 | ||
7438 | If the top element of the directory stack is modified, and the ‘-n’ | |
7439 | option was not supplied, ‘popd’ uses the ‘cd’ builtin to change to | |
7440 | the directory at the top of the stack. If the ‘cd’ fails, ‘popd’ | |
7441 | returns a non-zero value. | |
7442 | ||
7443 | Otherwise, ‘popd’ returns an unsuccessful status if an invalid | |
7444 | option is specified, the directory stack is empty, or N specifies a | |
7445 | non-existent directory stack entry. | |
7446 | ||
7447 | If the ‘popd’ command is successful, Bash runs ‘dirs’ to show the | |
7448 | final contents of the directory stack, and the return status is 0. | |
7449 | ||
7450 | ‘pushd’ | |
7451 | pushd [-n] [+N | -N | DIR] | |
7452 | ||
7453 | Add a directory to the top of the directory stack, or rotate the | |
7454 | stack, making the new top of the stack the current working | |
7455 | directory. With no arguments, ‘pushd’ exchanges the top two | |
7456 | elements of the directory stack. | |
7457 | ||
7458 | Arguments, if supplied, have the following meanings: | |
7459 | ||
7460 | ‘-n’ | |
7461 | Suppress the normal change of directory when rotating or | |
7462 | adding directories to the stack, only manipulate the stack. | |
7463 | ‘+N’ | |
7464 | Rotate the stack so that the Nth directory (counting from the | |
7465 | left of the list printed by ‘dirs’, starting with zero) is at | |
7466 | the top. | |
7467 | ‘-N’ | |
7468 | Rotate the stack so that the Nth directory (counting from the | |
7469 | right of the list printed by ‘dirs’, starting with zero) is at | |
7470 | the top. | |
7471 | ‘DIR’ | |
7472 | Make DIR be the top of the stack. | |
7473 | ||
7474 | After the stack has been modified, if the ‘-n’ option was not | |
7475 | supplied, ‘pushd’ uses the ‘cd’ builtin to change to the directory | |
7476 | at the top of the stack. If the ‘cd’ fails, ‘pushd’ returns a | |
7477 | non-zero value. | |
7478 | ||
7479 | Otherwise, if no arguments are supplied, ‘pushd’ returns zero | |
7480 | unless the directory stack is empty. When rotating the directory | |
7481 | stack, ‘pushd’ returns zero unless the directory stack is empty or | |
7482 | N specifies a non-existent directory stack element. | |
7483 | ||
7484 | If the ‘pushd’ command is successful, Bash runs ‘dirs’ to show the | |
7485 | final contents of the directory stack. | |
7486 | ||
7487 | \1f | |
7488 | File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features | |
7489 | ||
7490 | 6.9 Controlling the Prompt | |
7491 | ========================== | |
7492 | ||
7493 | In addition, the following table describes the special characters which | |
7494 | can appear in the prompt variables ‘PS0’, ‘PS1’, ‘PS2’, and ‘PS4’: | |
7495 | ||
7496 | ‘\a’ | |
7497 | A bell character. | |
7498 | ‘\d’ | |
7499 | The date, in "Weekday Month Date" format (e.g., "Tue May 26"). | |
7500 | ‘\D{FORMAT}’ | |
7501 | The FORMAT is passed to ‘strftime’(3) and the result is inserted | |
7502 | into the prompt string; an empty FORMAT results in a | |
7503 | locale-specific time representation. The braces are required. | |
7504 | ‘\e’ | |
7505 | An escape character. | |
7506 | ‘\h’ | |
7507 | The hostname, up to the first ‘.’. | |
7508 | ‘\H’ | |
7509 | The hostname. | |
7510 | ‘\j’ | |
7511 | The number of jobs currently managed by the shell. | |
7512 | ‘\l’ | |
7513 | The basename of the shell's terminal device name (e.g., "ttys0"). | |
7514 | ‘\n’ | |
7515 | A newline. | |
7516 | ‘\r’ | |
7517 | A carriage return. | |
7518 | ‘\s’ | |
7519 | The name of the shell: the basename of ‘$0’ (the portion following | |
7520 | the final slash). | |
7521 | ‘\t’ | |
7522 | The time, in 24-hour HH:MM:SS format. | |
7523 | ‘\T’ | |
7524 | The time, in 12-hour HH:MM:SS format. | |
7525 | ‘\@’ | |
7526 | The time, in 12-hour am/pm format. | |
7527 | ‘\A’ | |
7528 | The time, in 24-hour HH:MM format. | |
7529 | ‘\u’ | |
7530 | The username of the current user. | |
7531 | ‘\v’ | |
7532 | The Bash version (e.g., 2.00). | |
7533 | ‘\V’ | |
7534 | The Bash release, version + patchlevel (e.g., 2.00.0). | |
7535 | ‘\w’ | |
7536 | The value of the ‘PWD’ shell variable (‘$PWD’), with ‘$HOME’ | |
7537 | abbreviated with a tilde (uses the ‘$PROMPT_DIRTRIM’ variable). | |
7538 | ‘\W’ | |
7539 | The basename of ‘$PWD’, with ‘$HOME’ abbreviated with a tilde. | |
7540 | ‘\!’ | |
7541 | The history number of this command. | |
7542 | ‘\#’ | |
7543 | The command number of this command. | |
7544 | ‘\$’ | |
7545 | If the effective uid is 0, ‘#’, otherwise ‘$’. | |
7546 | ‘\NNN’ | |
7547 | The character whose ASCII code is the octal value NNN. | |
7548 | ‘\\’ | |
7549 | A backslash. | |
7550 | ‘\[’ | |
7551 | Begin a sequence of non-printing characters. Thiss could be used | |
7552 | to embed a terminal control sequence into the prompt. | |
7553 | ‘\]’ | |
7554 | End a sequence of non-printing characters. | |
7555 | ||
7556 | The command number and the history number are usually different: the | |
7557 | history number of a command is its position in the history list, which | |
7558 | may include commands restored from the history file (*note Bash History | |
7559 | Facilities::), while the command number is the position in the sequence | |
7560 | of commands executed during the current shell session. | |
7561 | ||
7562 | After the string is decoded, it is expanded via parameter expansion, | |
7563 | command substitution, arithmetic expansion, and quote removal, subject | |
7564 | to the value of the ‘promptvars’ shell option (*note The Shopt | |
7565 | Builtin::). This can have unwanted side effects if escaped portions of | |
7566 | the string appear within command substitution or contain characters | |
7567 | special to word expansion. | |
7568 | ||
7569 | \1f | |
7570 | File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features | |
7571 | ||
7572 | 6.10 The Restricted Shell | |
7573 | ========================= | |
7574 | ||
7575 | If Bash is started with the name ‘rbash’, or the ‘--restricted’ or ‘-r’ | |
7576 | option is supplied at invocation, the shell becomes RESTRICTED. A | |
7577 | restricted shell is used to set up an environment more controlled than | |
7578 | the standard shell. A restricted shell behaves identically to ‘bash’ | |
7579 | with the exception that the following are disallowed or not performed: | |
7580 | ||
7581 | • Changing directories with the ‘cd’ builtin. | |
7582 | • Setting or unsetting the values of the ‘SHELL’, ‘PATH’, ‘HISTFILE’, | |
7583 | ‘ENV’, or ‘BASH_ENV’ variables. | |
7584 | • Specifying command names containing slashes. | |
7585 | • Specifying a filename containing a slash as an argument to the ‘.’ | |
7586 | builtin command. | |
7587 | • Using the ‘-p’ option to the ‘.’ builtin command to specify a | |
7588 | search path. | |
7589 | • Specifying a filename containing a slash as an argument to the | |
7590 | ‘history’ builtin command. | |
7591 | • Specifying a filename containing a slash as an argument to the ‘-p’ | |
7592 | option to the ‘hash’ builtin command. | |
7593 | • Importing function definitions from the shell environment at | |
7594 | startup. | |
7595 | • Parsing the value of ‘SHELLOPTS’ from the shell environment at | |
7596 | startup. | |
7597 | • Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’ | |
7598 | redirection operators. | |
7599 | • Using the ‘exec’ builtin to replace the shell with another command. | |
7600 | • Adding or deleting builtin commands with the ‘-f’ and ‘-d’ options | |
7601 | to the ‘enable’ builtin. | |
7602 | • Using the ‘enable’ builtin command to enable disabled shell | |
7603 | builtins. | |
7604 | • Specifying the ‘-p’ option to the ‘command’ builtin. | |
7605 | • Turning off restricted mode with ‘set +r’ or ‘shopt -u | |
7606 | restricted_shell’. | |
7607 | ||
7608 | These restrictions are enforced after any startup files are read. | |
7609 | ||
7610 | When a command that is found to be a shell script is executed (*note | |
7611 | Shell Scripts::), ‘rbash’ turns off any restrictions in the shell | |
7612 | spawned to execute the script. | |
7613 | ||
7614 | The restricted shell mode is only one component of a useful | |
7615 | restricted environment. It should be accompanied by setting ‘PATH’ to a | |
7616 | value that allows execution of only a few verified commands (commands | |
7617 | that allow shell escapes are particularly vulnerable), changing the | |
7618 | current directory to a non-writable directory other than ‘$HOME’ after | |
7619 | login, not allowing the restricted shell to execute shell scripts, and | |
7620 | cleaning the environment of variables that cause some commands to modify | |
7621 | their behavior (e.g., ‘VISUAL’ or ‘PAGER’). | |
7622 | ||
7623 | Modern systems provide more secure ways to implement a restricted | |
7624 | environment, such as ‘jails’, ‘zones’, or ‘containers’. | |
7625 | ||
7626 | \1f | |
7627 | File: bashref.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features | |
7628 | ||
7629 | 6.11 Bash and POSIX | |
7630 | =================== | |
7631 | ||
7632 | 6.11.1 What is POSIX? | |
7633 | --------------------- | |
7634 | ||
7635 | POSIX is the name for a family of standards based on Unix. A number of | |
7636 | Unix services, tools, and functions are part of the standard, ranging | |
7637 | from the basic system calls and C library functions to common | |
7638 | applications and tools to system administration and management. | |
7639 | ||
7640 | The POSIX Shell and Utilities standard was originally developed by | |
7641 | IEEE Working Group 1003.2 (POSIX.2). The first edition of the 1003.2 | |
7642 | standard was published in 1992. It was merged with the original IEEE | |
7643 | 1003.1 Working Group and is currently maintained by the Austin Group (a | |
7644 | joint working group of the IEEE, The Open Group and ISO/IEC SC22/WG15). | |
7645 | Today the Shell and Utilities are a volume within the set of documents | |
7646 | that make up IEEE Std 1003.1-2024, and thus the former POSIX.2 (from | |
7647 | 1992) is now part of the current unified POSIX standard. | |
7648 | ||
7649 | The Shell and Utilities volume concentrates on the command | |
7650 | interpreter interface and utility programs commonly executed from the | |
7651 | command line or by other programs. The standard is freely available on | |
7652 | the web at | |
7653 | <https://pubs.opengroup.org/onlinepubs/9799919799/utilities/contents.html>. | |
7654 | ||
7655 | Bash is concerned with the aspects of the shell's behavior defined by | |
7656 | the POSIX Shell and Utilities volume. The shell command language has of | |
7657 | course been standardized, including the basic flow control and program | |
7658 | execution constructs, I/O redirection and pipelines, argument handling, | |
7659 | variable expansion, and quoting. | |
7660 | ||
7661 | The special builtins, which must be implemented as part of the shell | |
7662 | to provide the desired functionality, are specified as being part of the | |
7663 | shell; examples of these are ‘eval’ and ‘export’. Other utilities | |
7664 | appear in the sections of POSIX not devoted to the shell which are | |
7665 | commonly (and in some cases must be) implemented as builtin commands, | |
7666 | such as ‘read’ and ‘test’. POSIX also specifies aspects of the shell's | |
7667 | interactive behavior, including job control and command line editing. | |
7668 | Only vi-style line editing commands have been standardized; emacs | |
7669 | editing commands were left out due to objections. | |
7670 | ||
7671 | 6.11.2 Bash POSIX Mode | |
7672 | ---------------------- | |
7673 | ||
7674 | Although Bash is an implementation of the POSIX shell specification, | |
7675 | there are areas where the Bash default behavior differs from the | |
7676 | specification. The Bash “posix mode” changes the Bash behavior in these | |
7677 | areas so that it conforms more strictly to the standard. | |
7678 | ||
7679 | Starting Bash with the ‘--posix’ command-line option or executing | |
7680 | ‘set -o posix’ while Bash is running will cause Bash to conform more | |
7681 | closely to the POSIX standard by changing the behavior to match that | |
7682 | specified by POSIX in areas where the Bash default differs. | |
7683 | ||
7684 | When invoked as ‘sh’, Bash enters POSIX mode after reading the | |
7685 | startup files. | |
7686 | ||
7687 | The following list is what's changed when POSIX mode is in effect: | |
7688 | ||
7689 | 1. Bash ensures that the ‘POSIXLY_CORRECT’ variable is set. | |
7690 | ||
7691 | 2. Bash reads and executes the POSIX startup files (‘$ENV’) rather | |
7692 | than the normal Bash files (*note Bash Startup Files::. | |
7693 | ||
7694 | 3. Alias expansion is always enabled, even in non-interactive shells. | |
7695 | ||
7696 | 4. Reserved words appearing in a context where reserved words are | |
7697 | recognized do not undergo alias expansion. | |
7698 | ||
7699 | 5. Alias expansion is performed when initially parsing a command | |
7700 | substitution. The default (non-posix) mode generally defers it, | |
7701 | when enabled, until the command substitution is executed. This | |
7702 | means that command substitution will not expand aliases that are | |
7703 | defined after the command substitution is initially parsed (e.g., | |
7704 | as part of a function definition). | |
7705 | ||
7706 | 6. The ‘time’ reserved word may be used by itself as a simple command. | |
7707 | When used in this way, it displays timing statistics for the shell | |
7708 | and its completed children. The ‘TIMEFORMAT’ variable controls the | |
7709 | format of the timing information. | |
7710 | ||
7711 | 7. The parser does not recognize ‘time’ as a reserved word if the next | |
7712 | token begins with a ‘-’. | |
7713 | ||
7714 | 8. When parsing and expanding a ${...} expansion that appears within | |
7715 | double quotes, single quotes are no longer special and cannot be | |
7716 | used to quote a closing brace or other special character, unless | |
7717 | the operator is one of those defined to perform pattern removal. | |
7718 | In this case, they do not have to appear as matched pairs. | |
7719 | ||
7720 | 9. Redirection operators do not perform filename expansion on the word | |
7721 | in a redirection unless the shell is interactive. | |
7722 | ||
7723 | 10. Redirection operators do not perform word splitting on the word in | |
7724 | a redirection. | |
7725 | ||
7726 | 11. Function names may not be the same as one of the POSIX special | |
7727 | builtins. | |
7728 | ||
7729 | 12. Tilde expansion is only performed on assignments preceding a | |
7730 | command name, rather than on all assignment statements on the line. | |
7731 | ||
7732 | 13. While variable indirection is available, it may not be applied to | |
7733 | the ‘#’ and ‘?’ special parameters. | |
7734 | ||
7735 | 14. Expanding the ‘*’ special parameter in a pattern context where the | |
7736 | expansion is double-quoted does not treat the ‘$*’ as if it were | |
7737 | double-quoted. | |
7738 | ||
7739 | 15. A double quote character (‘"’) is treated specially when it | |
7740 | appears in a backquoted command substitution in the body of a | |
7741 | here-document that undergoes expansion. That means, for example, | |
7742 | that a backslash preceding a double quote character will escape it | |
7743 | and the backslash will be removed. | |
7744 | ||
7745 | 16. Command substitutions don't set the ‘?’ special parameter. The | |
7746 | exit status of a simple command without a command word is still the | |
7747 | exit status of the last command substitution that occurred while | |
7748 | evaluating the variable assignments and redirections in that | |
7749 | command, but that does not happen until after all of the | |
7750 | assignments and redirections. | |
7751 | ||
7752 | 17. Literal tildes that appear as the first character in elements of | |
7753 | the ‘PATH’ variable are not expanded as described above under *note | |
7754 | Tilde Expansion::. | |
7755 | ||
7756 | 18. Command lookup finds POSIX special builtins before shell | |
7757 | functions, including output printed by the ‘type’ and ‘command’ | |
7758 | builtins. | |
7759 | ||
7760 | 19. Even if a shell function whose name contains a slash was defined | |
7761 | before entering POSIX mode, the shell will not execute a function | |
7762 | whose name contains one or more slashes. | |
7763 | ||
7764 | 20. When a command in the hash table no longer exists, Bash will | |
7765 | re-search ‘$PATH’ to find the new location. This is also available | |
7766 | with ‘shopt -s checkhash’. | |
7767 | ||
7768 | 21. Bash will not insert a command without the execute bit set into | |
7769 | the command hash table, even if it returns it as a (last-ditch) | |
7770 | result from a ‘$PATH’ search. | |
7771 | ||
7772 | 22. The message printed by the job control code and builtins when a | |
7773 | job exits with a non-zero status is 'Done(status)'. | |
7774 | ||
7775 | 23. The message printed by the job control code and builtins when a | |
7776 | job is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for | |
7777 | example, ‘SIGTSTP’. | |
7778 | ||
7779 | 24. If the shell is interactive, Bash does not perform job | |
7780 | notifications between executing commands in lists separated by ‘;’ | |
7781 | or newline. Non-interactive shells print status messages after a | |
7782 | foreground job in a list completes. | |
7783 | ||
7784 | 25. If the shell is interactive, Bash waits until the next prompt | |
7785 | before printing the status of a background job that changes status | |
7786 | or a foreground job that terminates due to a signal. | |
7787 | Non-interactive shells print status messages after a foreground job | |
7788 | completes. | |
7789 | ||
7790 | 26. Bash permanently removes jobs from the jobs table after notifying | |
7791 | the user of their termination via the ‘wait’ or ‘jobs’ builtins. | |
7792 | It removes the job from the jobs list after notifying the user of | |
7793 | its termination, but the status is still available via ‘wait’, as | |
7794 | long as ‘wait’ is supplied a PID argument. | |
7795 | ||
7796 | 27. The ‘vi’ editing mode will invoke the ‘vi’ editor directly when | |
7797 | the ‘v’ command is run, instead of checking ‘$VISUAL’ and | |
7798 | ‘$EDITOR’. | |
7799 | ||
7800 | 28. Prompt expansion enables the POSIX ‘PS1’ and ‘PS2’ expansions of | |
7801 | ‘!’ to the history number and ‘!!’ to ‘!’, and Bash performs | |
7802 | parameter expansion on the values of ‘PS1’ and ‘PS2’ regardless of | |
7803 | the setting of the ‘promptvars’ option. | |
7804 | ||
7805 | 29. The default history file is ‘~/.sh_history’ (this is the default | |
7806 | value the shell assigns to ‘$HISTFILE’). | |
7807 | ||
7808 | 30. The ‘!’ character does not introduce history expansion within a | |
7809 | double-quoted string, even if the ‘histexpand’ option is enabled. | |
7810 | ||
7811 | 31. When printing shell function definitions (e.g., by ‘type’), Bash | |
7812 | does not print the ‘function’ reserved word unless necessary. | |
7813 | ||
7814 | 32. Non-interactive shells exit if a syntax error in an arithmetic | |
7815 | expansion results in an invalid expression. | |
7816 | ||
7817 | 33. Non-interactive shells exit if a parameter expansion error occurs. | |
7818 | ||
7819 | 34. If a POSIX special builtin returns an error status, a | |
7820 | non-interactive shell exits. The fatal errors are those listed in | |
7821 | the POSIX standard, and include things like passing incorrect | |
7822 | options, redirection errors, variable assignment errors for | |
7823 | assignments preceding the command name, and so on. | |
7824 | ||
7825 | 35. A non-interactive shell exits with an error status if a variable | |
7826 | assignment error occurs when no command name follows the assignment | |
7827 | statements. A variable assignment error occurs, for example, when | |
7828 | trying to assign a value to a readonly variable. | |
7829 | ||
7830 | 36. A non-interactive shell exits with an error status if a variable | |
7831 | assignment error occurs in an assignment statement preceding a | |
7832 | special builtin, but not with any other simple command. For any | |
7833 | other simple command, the shell aborts execution of that command, | |
7834 | and execution continues at the top level ("the shell shall not | |
7835 | perform any further processing of the command in which the error | |
7836 | occurred"). | |
7837 | ||
7838 | 37. A non-interactive shell exits with an error status if the | |
7839 | iteration variable in a ‘for’ statement or the selection variable | |
7840 | in a ‘select’ statement is a readonly variable or has an invalid | |
7841 | name. | |
7842 | ||
7843 | 38. Non-interactive shells exit if FILENAME in ‘.’ FILENAME is not | |
7844 | found. | |
7845 | ||
7846 | 39. Non-interactive shells exit if there is a syntax error in a script | |
7847 | read with the ‘.’ or ‘source’ builtins, or in a string processed by | |
7848 | the ‘eval’ builtin. | |
7849 | ||
7850 | 40. Non-interactive shells exit if the ‘export’, ‘readonly’ or ‘unset’ | |
7851 | builtin commands get an argument that is not a valid identifier, | |
7852 | and they are not operating on shell functions. These errors force | |
7853 | an exit because these are special builtins. | |
7854 | ||
7855 | 41. Assignment statements preceding POSIX special builtins persist in | |
7856 | the shell environment after the builtin completes. | |
7857 | ||
7858 | 42. The ‘command’ builtin does not prevent builtins that take | |
7859 | assignment statements as arguments from expanding them as | |
7860 | assignment statements; when not in POSIX mode, declaration commands | |
7861 | lose their assignment statement expansion properties when preceded | |
7862 | by ‘command’. | |
7863 | ||
7864 | 43. Enabling POSIX mode has the effect of setting the | |
7865 | ‘inherit_errexit’ option, so subshells spawned to execute command | |
7866 | substitutions inherit the value of the ‘-e’ option from the parent | |
7867 | shell. When the ‘inherit_errexit’ option is not enabled, Bash | |
7868 | clears the ‘-e’ option in such subshells. | |
7869 | ||
7870 | 44. Enabling POSIX mode has the effect of setting the ‘shift_verbose’ | |
7871 | option, so numeric arguments to ‘shift’ that exceed the number of | |
7872 | positional parameters will result in an error message. | |
7873 | ||
7874 | 45. Enabling POSIX mode has the effect of setting the | |
7875 | ‘interactive_comments’ option (*note Comments::). | |
7876 | ||
7877 | 46. The ‘.’ and ‘source’ builtins do not search the current directory | |
7878 | for the filename argument if it is not found by searching ‘PATH’. | |
7879 | ||
7880 | 47. When the ‘alias’ builtin displays alias definitions, it does not | |
7881 | display them with a leading ‘alias ’ unless the ‘-p’ option is | |
7882 | supplied. | |
7883 | ||
7884 | 48. The ‘bg’ builtin uses the required format to describe each job | |
7885 | placed in the background, which does not include an indication of | |
7886 | whether the job is the current or previous job. | |
7887 | ||
7888 | 49. When the ‘cd’ builtin is invoked in logical mode, and the pathname | |
7889 | constructed from ‘$PWD’ and the directory name supplied as an | |
7890 | argument does not refer to an existing directory, ‘cd’ will fail | |
7891 | instead of falling back to physical mode. | |
7892 | ||
7893 | 50. When the ‘cd’ builtin cannot change a directory because the length | |
7894 | of the pathname constructed from ‘$PWD’ and the directory name | |
7895 | supplied as an argument exceeds ‘PATH_MAX’ when canonicalized, ‘cd’ | |
7896 | will attempt to use the supplied directory name. | |
7897 | ||
7898 | 51. When the ‘xpg_echo’ option is enabled, Bash does not attempt to | |
7899 | interpret any arguments to ‘echo’ as options. ‘echo’ displays each | |
7900 | argument after converting escape sequences. | |
7901 | ||
7902 | 52. The ‘export’ and ‘readonly’ builtin commands display their output | |
7903 | in the format required by POSIX. | |
7904 | ||
7905 | 53. When listing the history, the ‘fc’ builtin does not include an | |
7906 | indication of whether or not a history entry has been modified. | |
7907 | ||
7908 | 54. The default editor used by ‘fc’ is ‘ed’. | |
7909 | ||
7910 | 55. ‘fc’ treats extra arguments as an error instead of ignoring them. | |
7911 | ||
7912 | 56. If there are too many arguments supplied to ‘fc -s’, ‘fc’ prints | |
7913 | an error message and returns failure. | |
7914 | ||
7915 | 57. The output of ‘kill -l’ prints all the signal names on a single | |
7916 | line, separated by spaces, without the ‘SIG’ prefix. | |
7917 | ||
7918 | 58. The ‘kill’ builtin does not accept signal names with a ‘SIG’ | |
7919 | prefix. | |
7920 | ||
7921 | 59. The ‘kill’ builtin returns a failure status if any of the pid or | |
7922 | job arguments are invalid or if sending the specified signal to any | |
7923 | of them fails. In default mode, ‘kill’ returns success if the | |
7924 | signal was successfully sent to any of the specified processes. | |
7925 | ||
7926 | 60. The ‘printf’ builtin uses ‘double’ (via ‘strtod’) to convert | |
7927 | arguments corresponding to floating point conversion specifiers, | |
7928 | instead of ‘long double’ if it's available. The ‘L’ length | |
7929 | modifier forces ‘printf’ to use ‘long double’ if it's available. | |
7930 | ||
7931 | 61. The ‘pwd’ builtin verifies that the value it prints is the same as | |
7932 | the current directory, even if it is not asked to check the file | |
7933 | system with the ‘-P’ option. | |
7934 | ||
7935 | 62. The ‘read’ builtin may be interrupted by a signal for which a trap | |
7936 | has been set. If Bash receives a trapped signal while executing | |
7937 | ‘read’, the trap handler executes and ‘read’ returns an exit status | |
7938 | greater than 128. | |
7939 | ||
7940 | 63. When the ‘set’ builtin is invoked without options, it does not | |
7941 | display shell function names and definitions. | |
7942 | ||
7943 | 64. When the ‘set’ builtin is invoked without options, it displays | |
7944 | variable values without quotes, unless they contain shell | |
7945 | metacharacters, even if the result contains nonprinting characters. | |
7946 | ||
7947 | 65. The ‘test’ builtin compares strings using the current locale when | |
7948 | evaluating the ‘<’ and ‘>’ binary operators. | |
7949 | ||
7950 | 66. The ‘test’ builtin's ‘-t’ unary primary requires an argument. | |
7951 | Historical versions of ‘test’ made the argument optional in certain | |
7952 | cases, and Bash attempts to accommodate those for backwards | |
7953 | compatibility. | |
7954 | ||
7955 | 67. The ‘trap’ builtin displays signal names without the leading | |
7956 | ‘SIG’. | |
7957 | ||
7958 | 68. The ‘trap’ builtin doesn't check the first argument for a possible | |
7959 | signal specification and revert the signal handling to the original | |
7960 | disposition if it is, unless that argument consists solely of | |
7961 | digits and is a valid signal number. If users want to reset the | |
7962 | handler for a given signal to the original disposition, they should | |
7963 | use ‘-’ as the first argument. | |
7964 | ||
7965 | 69. ‘trap -p’ without arguments displays signals whose dispositions | |
7966 | are set to SIG_DFL and those that were ignored when the shell | |
7967 | started, not just trapped signals. | |
7968 | ||
7969 | 70. The ‘type’ and ‘command’ builtins will not report a non-executable | |
7970 | file as having been found, though the shell will attempt to execute | |
7971 | such a file if it is the only so-named file found in ‘$PATH’. | |
7972 | ||
7973 | 71. The ‘ulimit’ builtin uses a block size of 512 bytes for the ‘-c’ | |
7974 | and ‘-f’ options. | |
7975 | ||
7976 | 72. The ‘unset’ builtin with the ‘-v’ option specified returns a fatal | |
7977 | error if it attempts to unset a ‘readonly’ or ‘non-unsettable’ | |
7978 | variable, which causes a non-interactive shell to exit. | |
7979 | ||
7980 | 73. When asked to unset a variable that appears in an assignment | |
7981 | statement preceding the command, the ‘unset’ builtin attempts to | |
7982 | unset a variable of the same name in the current or previous scope | |
7983 | as well. This implements the required "if an assigned variable is | |
7984 | further modified by the utility, the modifications made by the | |
7985 | utility shall persist" behavior. | |
7986 | ||
7987 | 74. The arrival of ‘SIGCHLD’ when a trap is set on ‘SIGCHLD’ does not | |
7988 | interrupt the ‘wait’ builtin and cause it to return immediately. | |
7989 | The trap command is run once for each child that exits. | |
7990 | ||
7991 | 75. Bash removes an exited background process's status from the list | |
7992 | of such statuses after the ‘wait’ builtin returns it. | |
7993 | ||
7994 | There is additional POSIX behavior that Bash does not implement by | |
7995 | default even when in POSIX mode. Specifically: | |
7996 | ||
7997 | 1. POSIX requires that word splitting be byte-oriented. That is, each | |
7998 | _byte_ in the value of ‘IFS’ potentially splits a word, even if | |
7999 | that byte is part of a multibyte character in ‘IFS’ or part of | |
8000 | multibyte character in the word. Bash allows multibyte characters | |
8001 | in the value of ‘IFS’, treating a valid multibyte character as a | |
8002 | single delimiter, and will not split a valid multibyte character | |
8003 | even if one of the bytes composing that character appears in ‘IFS’. | |
8004 | This is POSIX interpretation 1560, further modified by issue 1924. | |
8005 | ||
8006 | 2. The ‘fc’ builtin checks ‘$EDITOR’ as a program to edit history | |
8007 | entries if ‘FCEDIT’ is unset, rather than defaulting directly to | |
8008 | ‘ed’. ‘fc’ uses ‘ed’ if ‘EDITOR’ is unset. | |
8009 | ||
8010 | 3. As noted above, Bash requires the ‘xpg_echo’ option to be enabled | |
8011 | for the ‘echo’ builtin to be fully conformant. | |
8012 | ||
8013 | Bash can be configured to be POSIX-conformant by default, by | |
8014 | specifying the ‘--enable-strict-posix-default’ to ‘configure’ when | |
8015 | building (*note Optional Features::). | |
8016 | ||
8017 | \1f | |
8018 | File: bashref.info, Node: Shell Compatibility Mode, Prev: Bash POSIX Mode, Up: Bash Features | |
8019 | ||
8020 | 6.12 Shell Compatibility Mode | |
8021 | ============================= | |
8022 | ||
8023 | Bash-4.0 introduced the concept of a “shell compatibility level”, | |
8024 | specified as a set of options to the shopt builtin (‘compat31’, | |
8025 | ‘compat32’, ‘compat40’, ‘compat41’, and so on). There is only one | |
8026 | current compatibility level - each option is mutually exclusive. The | |
8027 | compatibility level is intended to allow users to select behavior from | |
8028 | previous versions that is incompatible with newer versions while they | |
8029 | migrate scripts to use current features and behavior. It's intended to | |
8030 | be a temporary solution. | |
8031 | ||
8032 | This section does not mention behavior that is standard for a | |
8033 | particular version (e.g., setting ‘compat32’ means that quoting the | |
8034 | right hand side of the regexp matching operator quotes special regexp | |
8035 | characters in the word, which is default behavior in bash-3.2 and | |
8036 | subsequent versions). | |
8037 | ||
8038 | If a user enables, say, ‘compat32’, it may affect the behavior of | |
8039 | other compatibility levels up to and including the current compatibility | |
8040 | level. The idea is that each compatibility level controls behavior that | |
8041 | changed in that version of Bash, but that behavior may have been present | |
8042 | in earlier versions. For instance, the change to use locale-based | |
8043 | comparisons with the ‘[[’ command came in bash-4.1, and earlier versions | |
8044 | used ASCII-based comparisons, so enabling ‘compat32’ will enable | |
8045 | ASCII-based comparisons as well. That granularity may not be sufficient | |
8046 | for all uses, and as a result users should employ compatibility levels | |
8047 | carefully. Read the documentation for a particular feature to find out | |
8048 | the current behavior. | |
8049 | ||
8050 | Bash-4.3 introduced a new shell variable: ‘BASH_COMPAT’. The value | |
8051 | assigned to this variable (a decimal version number like 4.2, or an | |
8052 | integer corresponding to the ‘compat’NN option, like 42) determines the | |
8053 | compatibility level. | |
8054 | ||
8055 | Starting with bash-4.4, Bash began deprecating older compatibility | |
8056 | levels. Eventually, the options will be removed in favor of | |
8057 | ‘BASH_COMPAT’. | |
8058 | ||
8059 | Bash-5.0 was the final version for which there was an individual | |
8060 | shopt option for the previous version. ‘BASH_COMPAT’ is the only | |
8061 | mechanism to control the compatibility level in versions newer than | |
8062 | bash-5.0. | |
8063 | ||
8064 | The following table describes the behavior changes controlled by each | |
8065 | compatibility level setting. The ‘compat’NN tag is used as shorthand | |
8066 | for setting the compatibility level to NN using one of the following | |
8067 | mechanisms. For versions prior to bash-5.0, the compatibility level may | |
8068 | be set using the corresponding ‘compat’NN shopt option. For bash-4.3 | |
8069 | and later versions, the ‘BASH_COMPAT’ variable is preferred, and it is | |
8070 | required for bash-5.1 and later versions. | |
8071 | ||
8072 | ‘compat31’ | |
8073 | • Quoting the rhs of the ‘[[’ command's regexp matching operator | |
8074 | (=~) has no special effect | |
8075 | ||
8076 | ‘compat40’ | |
8077 | • The ‘<’ and ‘>’ operators to the ‘[[’ command do not consider | |
8078 | the current locale when comparing strings; they use ASCII | |
8079 | ordering. Bash versions prior to bash-4.1 use ASCII collation | |
8080 | and strcmp(3); bash-4.1 and later use the current locale's | |
8081 | collation sequence and strcoll(3). | |
8082 | ||
8083 | ‘compat41’ | |
8084 | • In POSIX mode, ‘time’ may be followed by options and still be | |
8085 | recognized as a reserved word (this is POSIX interpretation | |
8086 | 267). | |
8087 | • In POSIX mode, the parser requires that an even number of | |
8088 | single quotes occur in the WORD portion of a double-quoted | |
8089 | ${...} parameter expansion and treats them specially, so that | |
8090 | characters within the single quotes are considered quoted | |
8091 | (this is POSIX interpretation 221). | |
8092 | ||
8093 | ‘compat42’ | |
8094 | • The replacement string in double-quoted pattern substitution | |
8095 | does not undergo quote removal, as it does in versions after | |
8096 | bash-4.2. | |
8097 | • In POSIX mode, single quotes are considered special when | |
8098 | expanding the WORD portion of a double-quoted ${...} parameter | |
8099 | expansion and can be used to quote a closing brace or other | |
8100 | special character (this is part of POSIX interpretation 221); | |
8101 | in later versions, single quotes are not special within | |
8102 | double-quoted word expansions. | |
8103 | ||
8104 | ‘compat43’ | |
8105 | • Word expansion errors are considered non-fatal errors that | |
8106 | cause the current command to fail, even in POSIX mode (the | |
8107 | default behavior is to make them fatal errors that cause the | |
8108 | shell to exit). | |
8109 | • When executing a shell function, the loop state | |
8110 | (while/until/etc.) is not reset, so ‘break’ or ‘continue’ in | |
8111 | that function will break or continue loops in the calling | |
8112 | context. Bash-4.4 and later reset the loop state to prevent | |
8113 | this. | |
8114 | ||
8115 | ‘compat44’ | |
8116 | • The shell sets up the values used by ‘BASH_ARGV’ and | |
8117 | ‘BASH_ARGC’ so they can expand to the shell's positional | |
8118 | parameters even if extended debugging mode is not enabled. | |
8119 | • A subshell inherits loops from its parent context, so ‘break’ | |
8120 | or ‘continue’ will cause the subshell to exit. Bash-5.0 and | |
8121 | later reset the loop state to prevent the exit. | |
8122 | • Variable assignments preceding builtins like ‘export’ and | |
8123 | ‘readonly’ that set attributes continue to affect variables | |
8124 | with the same name in the calling environment even if the | |
8125 | shell is not in POSIX mode. | |
8126 | ||
8127 | ‘compat50 (set using BASH_COMPAT)’ | |
8128 | • Bash-5.1 changed the way ‘$RANDOM’ is generated to introduce | |
8129 | slightly more randomness. If the shell compatibility level is | |
8130 | set to 50 or lower, it reverts to the method from bash-5.0 and | |
8131 | previous versions, so seeding the random number generator by | |
8132 | assigning a value to ‘RANDOM’ will produce the same sequence | |
8133 | as in bash-5.0. | |
8134 | • If the command hash table is empty, Bash versions prior to | |
8135 | bash-5.1 printed an informational message to that effect, even | |
8136 | when producing output that can be reused as input. Bash-5.1 | |
8137 | suppresses that message when the ‘-l’ option is supplied. | |
8138 | ||
8139 | ‘compat51 (set using BASH_COMPAT)’ | |
8140 | • The ‘unset’ builtin will unset the array ‘a’ given an argument | |
8141 | like ‘a[@]’. Bash-5.2 will unset an element with key ‘@’ | |
8142 | (associative arrays) or remove all the elements without | |
8143 | unsetting the array (indexed arrays). | |
8144 | • Arithmetic commands ( ((...)) ) and the expressions in an | |
8145 | arithmetic for statement can be expanded more than once. | |
8146 | • Expressions used as arguments to arithmetic operators in the | |
8147 | ‘[[’ conditional command can be expanded more than once. | |
8148 | • The expressions in substring parameter brace expansion can be | |
8149 | expanded more than once. | |
8150 | • The expressions in the $(( ... )) word expansion can be | |
8151 | expanded more than once. | |
8152 | • Arithmetic expressions used as indexed array subscripts can be | |
8153 | expanded more than once. | |
8154 | • ‘test -v’, when given an argument of ‘A[@]’, where A is an | |
8155 | existing associative array, will return true if the array has | |
8156 | any set elements. Bash-5.2 will look for and report on a key | |
8157 | named ‘@’. | |
8158 | • the ${PARAMETER[:]=VALUE} word expansion will return VALUE, | |
8159 | before any variable-specific transformations have been | |
8160 | performed (e.g., converting to lowercase). Bash-5.2 will | |
8161 | return the final value assigned to the variable. | |
8162 | • Parsing command substitutions will behave as if extended | |
8163 | globbing (*note The Shopt Builtin::) is enabled, so that | |
8164 | parsing a command substitution containing an extglob pattern | |
8165 | (say, as part of a shell function) will not fail. This | |
8166 | assumes the intent is to enable extglob before the command is | |
8167 | executed and word expansions are performed. It will fail at | |
8168 | word expansion time if extglob hasn't been enabled by the time | |
8169 | the command is executed. | |
8170 | ||
8171 | ‘compat52 (set using BASH_COMPAT)’ | |
8172 | • The ‘test’ builtin uses its historical algorithm to parse | |
8173 | parenthesized subexpressions when given five or more | |
8174 | arguments. | |
8175 | • If the ‘-p’ or ‘-P’ option is supplied to the ‘bind’ builtin, | |
8176 | ‘bind’ treats any arguments remaining after option processing | |
8177 | as bindable command names, and displays any key sequences | |
8178 | bound to those commands, instead of treating the arguments as | |
8179 | key sequences to bind. | |
8180 | • Interactive shells will notify the user of completed jobs | |
8181 | while sourcing a script. Newer versions defer notification | |
8182 | until script execution completes. | |
8183 | ||
8184 | \1f | |
8185 | File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top | |
8186 | ||
8187 | 7 Job Control | |
8188 | ************* | |
8189 | ||
8190 | This chapter discusses what job control is, how it works, and how Bash | |
8191 | allows you to access its facilities. | |
8192 | ||
8193 | * Menu: | |
8194 | ||
8195 | * Job Control Basics:: How job control works. | |
8196 | * Job Control Builtins:: Bash builtin commands used to interact | |
8197 | with job control. | |
8198 | * Job Control Variables:: Variables Bash uses to customize job | |
8199 | control. | |
8200 | ||
8201 | \1f | |
8202 | File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control | |
8203 | ||
8204 | 7.1 Job Control Basics | |
8205 | ====================== | |
8206 | ||
8207 | Job control refers to the ability to selectively stop (suspend) the | |
8208 | execution of processes and continue (resume) their execution at a later | |
8209 | point. A user typically employs this facility via an interactive | |
8210 | interface supplied jointly by the operating system kernel's terminal | |
8211 | driver and Bash. | |
8212 | ||
8213 | The shell associates a JOB with each pipeline. It keeps a table of | |
8214 | currently executing jobs, which the ‘jobs’ command will display. Each | |
8215 | job has a “job number”, which ‘jobs’ displays between brackets. Job | |
8216 | numbers start at 1. When Bash starts a job asynchronously, it prints a | |
8217 | line that looks like: | |
8218 | [1] 25647 | |
8219 | indicating that this job is job number 1 and that the process ID of the | |
8220 | last process in the pipeline associated with this job is 25647. All of | |
8221 | the processes in a single pipeline are members of the same job. Bash | |
8222 | uses the JOB abstraction as the basis for job control. | |
8223 | ||
8224 | To facilitate the implementation of the user interface to job | |
8225 | control, each process has a “process group ID”, and the operating system | |
8226 | maintains the notion of a current terminal process group ID. This | |
8227 | terminal process group ID is associated with the “controlling terminal”. | |
8228 | ||
8229 | Processes that have the same process group ID are said to be part of | |
8230 | the same “process group”. Members of the foreground process group | |
8231 | (processes whose process group ID is equal to the current terminal | |
8232 | process group ID) receive keyboard-generated signals such as ‘SIGINT’. | |
8233 | Processes in the foreground process group are said to be foreground | |
8234 | processes. Background processes are those whose process group ID | |
8235 | differs from the controlling terminal's; such processes are immune to | |
8236 | keyboard-generated signals. Only foreground processes are allowed to | |
8237 | read from or, if the user so specifies with ‘stty tostop’, write to the | |
8238 | controlling terminal. The system sends a ‘SIGTTIN’ (‘SIGTTOU’) signal | |
8239 | to background processes which attempt to read from (write to when | |
8240 | ‘tostop’ is in effect) the terminal, which, unless caught, suspends the | |
8241 | process. | |
8242 | ||
8243 | If the operating system on which Bash is running supports job | |
8244 | control, Bash contains facilities to use it. Typing the “suspend” | |
8245 | character (typically ‘^Z’, Control-Z) while a process is running stops | |
8246 | that process and returns control to Bash. Typing the “delayed suspend” | |
8247 | character (typically ‘^Y’, Control-Y) causes the process to stop when it | |
8248 | attempts to read input from the terminal, and returns control to Bash. | |
8249 | The user then manipulates the state of this job, using the ‘bg’ command | |
8250 | to continue it in the background, the ‘fg’ command to continue it in the | |
8251 | foreground, or the ‘kill’ command to kill it. The suspend character | |
8252 | takes effect immediately, and has the additional side effect of | |
8253 | discarding any pending output and typeahead. If you want to force a | |
8254 | background process to stop, or stop a process that's not associated with | |
8255 | your terminal session, send it the ‘SIGSTOP’ signal using ‘kill’. | |
8256 | ||
8257 | There are a number of ways to refer to a job in the shell. The ‘%’ | |
8258 | character introduces a “job specification” (jobspec). | |
8259 | ||
8260 | Job number ‘n’ may be referred to as ‘%n’. A job may also be | |
8261 | referred to using a prefix of the name used to start it, or using a | |
8262 | substring that appears in its command line. For example, ‘%ce’ refers | |
8263 | to a job whose command name begins with ‘ce’. Using ‘%?ce’, on the | |
8264 | other hand, refers to any job containing the string ‘ce’ in its command | |
8265 | line. If the prefix or substring matches more than one job, Bash | |
8266 | reports an error. | |
8267 | ||
8268 | The symbols ‘%%’ and ‘%+’ refer to the shell's notion of the “current | |
8269 | job”. A single ‘%’ (with no accompanying job specification) also refers | |
8270 | to the current job. ‘%-’ refers to the “previous job”. When a job | |
8271 | starts in the background, a job stops while in the foreground, or a job | |
8272 | is resumed in the background, it becomes the current job. The job that | |
8273 | was the current job becomes the previous job. When the current job | |
8274 | terminates, the previous job becomes the current job. If there is only | |
8275 | a single job, ‘%+’ and ‘%-’ can both be used to refer to that job. In | |
8276 | output pertaining to jobs (e.g., the output of the ‘jobs’ command), the | |
8277 | current job is always marked with a ‘+’, and the previous job with a | |
8278 | ‘-’. | |
8279 | ||
8280 | Simply naming a job can be used to bring it into the foreground: ‘%1’ | |
8281 | is a synonym for ‘fg %1’, bringing job 1 from the background into the | |
8282 | foreground. Similarly, ‘%1 &’ resumes job 1 in the background, | |
8283 | equivalent to ‘bg %1’. | |
8284 | ||
8285 | The shell learns immediately whenever a job changes state. Normally, | |
8286 | Bash waits until it is about to print a prompt before notifying the user | |
8287 | about changes in a job's status so as to not interrupt any other output, | |
8288 | though it will notify of changes in a job's status after a foreground | |
8289 | command in a list completes, before executing the next command in the | |
8290 | list. If the ‘-b’ option to the ‘set’ builtin is enabled, Bash reports | |
8291 | status changes immediately (*note The Set Builtin::). Bash executes any | |
8292 | trap on ‘SIGCHLD’ for each child process that terminates. | |
8293 | ||
8294 | When a job terminates and Bash notifies the user about it, Bash | |
8295 | removes the job from the jobs table. It will not appear in ‘jobs’ | |
8296 | output, but ‘wait’ will report its exit status, as long as it's supplied | |
8297 | the process ID associated with the job as an argument. When the table | |
8298 | is empty, job numbers start over at 1. | |
8299 | ||
8300 | If a user attempts to exit Bash while jobs are stopped, (or running, | |
8301 | if the ‘checkjobs’ option is enabled - see *note The Shopt Builtin::), | |
8302 | the shell prints a warning message, and if the ‘checkjobs’ option is | |
8303 | enabled, lists the jobs and their statuses. The ‘jobs’ command may then | |
8304 | be used to inspect their status. If the user immediately attempts to | |
8305 | exit again, without an intervening command, Bash does not print another | |
8306 | warning, and terminates any stopped jobs. | |
8307 | ||
8308 | When the shell is waiting for a job or process using the ‘wait’ | |
8309 | builtin, and job control is enabled, ‘wait’ will return when the job | |
8310 | changes state. The ‘-f’ option causes ‘wait’ to wait until the job or | |
8311 | process terminates before returning. | |
8312 | ||
8313 | \1f | |
8314 | File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control | |
8315 | ||
8316 | 7.2 Job Control Builtins | |
8317 | ======================== | |
8318 | ||
8319 | ‘bg’ | |
8320 | bg [JOBSPEC ...] | |
8321 | ||
8322 | Resume each suspended job JOBSPEC in the background, as if it had | |
8323 | been started with ‘&’. If JOBSPEC is not supplied, the shell uses | |
8324 | its notion of the current job. ‘bg’ returns zero unless it is run | |
8325 | when job control is not enabled, or, when run with job control | |
8326 | enabled, any JOBSPEC was not found or specifies a job that was | |
8327 | started without job control. | |
8328 | ||
8329 | ‘fg’ | |
8330 | fg [JOBSPEC] | |
8331 | ||
8332 | Resume the job JOBSPEC in the foreground and make it the current | |
8333 | job. If JOBSPEC is not supplied, ‘fg’ resumes the current job. | |
8334 | The return status is that of the command placed into the | |
8335 | foreground, or non-zero if run when job control is disabled or, | |
8336 | when run with job control enabled, JOBSPEC does not specify a valid | |
8337 | job or JOBSPEC specifies a job that was started without job | |
8338 | control. | |
8339 | ||
8340 | ‘jobs’ | |
8341 | jobs [-lnprs] [JOBSPEC] | |
8342 | jobs -x COMMAND [ARGUMENTS] | |
8343 | ||
8344 | The first form lists the active jobs. The options have the | |
8345 | following meanings: | |
8346 | ||
8347 | ‘-l’ | |
8348 | List process IDs in addition to the normal information. | |
8349 | ||
8350 | ‘-n’ | |
8351 | Display information only about jobs that have changed status | |
8352 | since the user was last notified of their status. | |
8353 | ||
8354 | ‘-p’ | |
8355 | List only the process ID of the job's process group leader. | |
8356 | ||
8357 | ‘-r’ | |
8358 | Display only running jobs. | |
8359 | ||
8360 | ‘-s’ | |
8361 | Display only stopped jobs. | |
8362 | ||
8363 | If JOBSPEC is supplied, ‘jobs’ restricts output to information | |
8364 | about that job. If JOBSPEC is not supplied, ‘jobs’ lists the | |
8365 | status of all jobs. The return status is zero unless an invalid | |
8366 | option is encountered or an invalid JOBSPEC is supplied. | |
8367 | ||
8368 | If the ‘-x’ option is supplied, ‘jobs’ replaces any JOBSPEC found | |
8369 | in COMMAND or ARGUMENTS with the corresponding process group ID, | |
8370 | and executes COMMAND, passing it ARGUMENTs, returning its exit | |
8371 | status. | |
8372 | ||
8373 | ‘kill’ | |
8374 | kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] ID [...] | |
8375 | kill -l|-L [EXIT_STATUS] | |
8376 | ||
8377 | Send a signal specified by SIGSPEC or SIGNUM to the processes named | |
8378 | by each ID. Each ID may be a job specification JOBSPEC or process | |
8379 | ID PID. SIGSPEC is either a case-insensitive signal name such as | |
8380 | ‘SIGINT’ (with or without the ‘SIG’ prefix) or a signal number; | |
8381 | SIGNUM is a signal number. If SIGSPEC and SIGNUM are not present, | |
8382 | ‘kill’ sends ‘SIGTERM’. | |
8383 | ||
8384 | The ‘-l’ option lists the signal names. If any arguments are | |
8385 | supplied when ‘-l’ is supplied, ‘kill’ lists the names of the | |
8386 | signals corresponding to the arguments, and the return status is | |
8387 | zero. EXIT_STATUS is a number specifying a signal number or the | |
8388 | exit status of a process terminated by a signal; if it is supplied, | |
8389 | ‘kill’ prints the name of the signal that caused the process to | |
8390 | terminate. ‘kill’ assumes that process exit statuses are greater | |
8391 | than 128; anything less than that is a signal number. The ‘-L’ | |
8392 | option is equivalent to ‘-l’. | |
8393 | ||
8394 | The return status is zero if at least one signal was successfully | |
8395 | sent, or non-zero if an error occurs or an invalid option is | |
8396 | encountered. | |
8397 | ||
8398 | ‘wait’ | |
8399 | wait [-fn] [-p VARNAME] [ID ...] | |
8400 | ||
8401 | Wait until the child process specified by each ID exits and return | |
8402 | the exit status of the last ID. Each ID may be a process ID PID or | |
8403 | a job specification JOBSPEC; if a jobspec is supplied, ‘wait’ waits | |
8404 | for all processes in the job. | |
8405 | ||
8406 | If no options or IDs are supplied, ‘wait’ waits for all running | |
8407 | background jobs and the last-executed process substitution, if its | |
8408 | process id is the same as $!, and the return status is zero. | |
8409 | ||
8410 | If the ‘-n’ option is supplied, ‘wait’ waits for any one of the IDs | |
8411 | or, if no IDs are supplied, any job or process substitution, to | |
8412 | complete and returns its exit status. If none of the supplied IDs | |
8413 | is a child of the shell, or if no arguments are supplied and the | |
8414 | shell has no unwaited-for children, the exit status is 127. | |
8415 | ||
8416 | If the ‘-p’ option is supplied, ‘wait’ assigns the process or job | |
8417 | identifier of the job for which the exit status is returned to the | |
8418 | variable VARNAME named by the option argument. The variable, which | |
8419 | cannot be readonly, will be unset initially, before any assignment. | |
8420 | This is useful only when used with the ‘-n’ option. | |
8421 | ||
8422 | Supplying the ‘-f’ option, when job control is enabled, forces | |
8423 | ‘wait’ to wait for each ID to terminate before returning its | |
8424 | status, instead of returning when it changes status. | |
8425 | ||
8426 | If none of the IDs specify one of the shell's an active child | |
8427 | processes, the return status is 127. If ‘wait’ is interrupted by a | |
8428 | signal, any VARNAME will remain unset, and the return status will | |
8429 | be greater than 128, as described above (*note Signals::). | |
8430 | Otherwise, the return status is the exit status of the last ID. | |
8431 | ||
8432 | ‘disown’ | |
8433 | disown [-ar] [-h] [ID ...] | |
8434 | ||
8435 | Without options, remove each ID from the table of active jobs. | |
8436 | Each ID may be a job specification JOBSPEC or a process ID PID; if | |
8437 | ID is a PID, ‘disown’ uses the job containing PID as JOBSPEC. | |
8438 | ||
8439 | If the ‘-h’ option is supplied, ‘disown’ does not remove the jobs | |
8440 | corresponding to each ‘id’ from the jobs table, but rather marks | |
8441 | them so the shell does not send ‘SIGHUP’ to the job if the shell | |
8442 | receives a ‘SIGHUP’. | |
8443 | ||
8444 | If no ID is supplied, the ‘-a’ option means to remove or mark all | |
8445 | jobs; the ‘-r’ option without an ID argument removes or marks | |
8446 | running jobs. If no ID is supplied, and neither the ‘-a’ nor the | |
8447 | ‘-r’ option is supplied, ‘disown’ removes or marks the current job. | |
8448 | ||
8449 | The return value is 0 unless an ID does not specify a valid job. | |
8450 | ||
8451 | ‘suspend’ | |
8452 | suspend [-f] | |
8453 | ||
8454 | Suspend the execution of this shell until it receives a ‘SIGCONT’ | |
8455 | signal. A login shell, or a shell without job control enabled, | |
8456 | cannot be suspended; the ‘-f’ option will override this and force | |
8457 | the suspension. The return status is 0 unless the shell is a login | |
8458 | shell or job control is not enabled and ‘-f’ is not supplied. | |
8459 | ||
8460 | When job control is not active, the ‘kill’ and ‘wait’ builtins do not | |
8461 | accept JOBSPEC arguments. They must be supplied process IDs. | |
8462 | ||
8463 | \1f | |
8464 | File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control | |
8465 | ||
8466 | 7.3 Job Control Variables | |
8467 | ========================= | |
8468 | ||
8469 | ‘auto_resume’ | |
8470 | This variable controls how the shell interacts with the user and | |
8471 | job control. If this variable exists then simple commands | |
8472 | consisting of only a single word, without redirections, are treated | |
8473 | as candidates for resumption of an existing job. There is no | |
8474 | ambiguity allowed; if there is more than one job beginning with or | |
8475 | containing the word, then this selects the most recently accessed | |
8476 | job. The name of a stopped job, in this context, is the command | |
8477 | line used to start it, as displayed by ‘jobs’. If this variable is | |
8478 | set to the value ‘exact’, the word must match the name of a stopped | |
8479 | job exactly; if set to ‘substring’, the word needs to match a | |
8480 | substring of the name of a stopped job. The ‘substring’ value | |
8481 | provides functionality analogous to the ‘%?string’ job ID (*note | |
8482 | Job Control Basics::). If set to any other value (e.g., ‘prefix’), | |
8483 | the word must be a prefix of a stopped job's name; this provides | |
8484 | functionality analogous to the ‘%string’ job ID. | |
8485 | ||
8486 | \1f | |
8487 | File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top | |
8488 | ||
8489 | 8 Command Line Editing | |
8490 | ********************** | |
8491 | ||
8492 | This chapter describes the basic features of the GNU command line | |
8493 | editing interface. Command line editing is provided by the Readline | |
8494 | library, which is used by several different programs, including Bash. | |
8495 | Command line editing is enabled by default when using an interactive | |
8496 | shell, unless the ‘--noediting’ option is supplied at shell invocation. | |
8497 | Line editing is also used when using the ‘-e’ option to the ‘read’ | |
8498 | builtin command (*note Bash Builtins::). By default, the line editing | |
8499 | commands are similar to those of Emacs; a vi-style line editing | |
8500 | interface is also available. Line editing can be enabled at any time | |
8501 | using the ‘-o emacs’ or ‘-o vi’ options to the ‘set’ builtin command | |
8502 | (*note The Set Builtin::), or disabled using the ‘+o emacs’ or ‘+o vi’ | |
8503 | options to ‘set’. | |
8504 | ||
8505 | * Menu: | |
8506 | ||
8507 | * Introduction and Notation:: Notation used in this text. | |
8508 | * Readline Interaction:: The minimum set of commands for editing a line. | |
8509 | * Readline Init File:: Customizing Readline from a user's view. | |
8510 | * Bindable Readline Commands:: A description of most of the Readline commands | |
8511 | available for binding | |
8512 | * Readline vi Mode:: A short description of how to make Readline | |
8513 | behave like the vi editor. | |
8514 | * Programmable Completion:: How to specify the possible completions for | |
8515 | a specific command. | |
8516 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
8517 | complete arguments for a particular command. | |
8518 | * A Programmable Completion Example:: An example shell function for | |
8519 | generating possible completions. | |
8520 | ||
8521 | \1f | |
8522 | File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing | |
8523 | ||
8524 | 8.1 Introduction to Line Editing | |
8525 | ================================ | |
8526 | ||
8527 | The following paragraphs use Emacs style to describe the notation used | |
8528 | to represent keystrokes. | |
8529 | ||
8530 | The text ‘C-k’ is read as 'Control-K' and describes the character | |
8531 | produced when the <k> key is pressed while the Control key is depressed. | |
8532 | ||
8533 | The text ‘M-k’ is read as 'Meta-K' and describes the character | |
8534 | produced when the Meta key (if you have one) is depressed, and the <k> | |
8535 | key is pressed (a “meta character”), then both are released. The Meta | |
8536 | key is labeled <ALT> or <Option> on many keyboards. On keyboards with | |
8537 | two keys labeled <ALT> (usually to either side of the space bar), the | |
8538 | <ALT> on the left side is generally set to work as a Meta key. One of | |
8539 | the <ALT> keys may also be configured as some other modifier, such as a | |
8540 | Compose key for typing accented characters. | |
8541 | ||
8542 | On some keyboards, the Meta key modifier produces characters with the | |
8543 | eighth bit (0200) set. You can use the ‘enable-meta-key’ variable to | |
8544 | control whether or not it does this, if the keyboard allows it. On many | |
8545 | others, the terminal or terminal emulator converts the metafied key to a | |
8546 | key sequence beginning with <ESC> as described in the next paragraph. | |
8547 | ||
8548 | If you do not have a Meta or <ALT> key, or another key working as a | |
8549 | Meta key, you can generally achieve the latter effect by typing <ESC> | |
8550 | _first_, and then typing <k>. The <ESC> character is known as the “meta | |
8551 | prefix”). | |
8552 | ||
8553 | Either process is known as “metafying” the <k> key. | |
8554 | ||
8555 | If your Meta key produces a key sequence with the <ESC> meta prefix, | |
8556 | you can make ‘M-key’ key bindings you specify (see ‘Key Bindings’ in | |
8557 | *note Readline Init File Syntax::) do the same thing by setting the | |
8558 | ‘force-meta-prefix’ variable. | |
8559 | ||
8560 | The text ‘M-C-k’ is read as 'Meta-Control-k' and describes the | |
8561 | character produced by metafying ‘C-k’. | |
8562 | ||
8563 | In addition, several keys have their own names. Specifically, <DEL>, | |
8564 | <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen | |
8565 | in this text, or in an init file (*note Readline Init File::). If your | |
8566 | keyboard lacks a <LFD> key, typing <C-j> will output the appropriate | |
8567 | character. The <RET> key may be labeled <Return> or <Enter> on some | |
8568 | keyboards. | |
8569 | ||
8570 | \1f | |
8571 | File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing | |
8572 | ||
8573 | 8.2 Readline Interaction | |
8574 | ======================== | |
8575 | ||
8576 | Often during an interactive session you type in a long line of text, | |
8577 | only to notice that the first word on the line is misspelled. The | |
8578 | Readline library gives you a set of commands for manipulating the text | |
8579 | as you type it in, allowing you to just fix your typo, and not forcing | |
8580 | you to retype the majority of the line. Using these editing commands, | |
8581 | you move the cursor to the place that needs correction, and delete or | |
8582 | insert the text of the corrections. Then, when you are satisfied with | |
8583 | the line, you simply press <RET>. You do not have to be at the end of | |
8584 | the line to press <RET>; the entire line is accepted regardless of the | |
8585 | location of the cursor within the line. | |
8586 | ||
8587 | * Menu: | |
8588 | ||
8589 | * Readline Bare Essentials:: The least you need to know about Readline. | |
8590 | * Readline Movement Commands:: Moving about the input line. | |
8591 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
8592 | * Readline Arguments:: Giving numeric arguments to commands. | |
8593 | * Searching:: Searching through previous lines. | |
8594 | ||
8595 | \1f | |
8596 | File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction | |
8597 | ||
8598 | 8.2.1 Readline Bare Essentials | |
8599 | ------------------------------ | |
8600 | ||
8601 | In order to enter characters into the line, simply type them. The typed | |
8602 | character appears where the cursor was, and then the cursor moves one | |
8603 | space to the right. If you mistype a character, you can use your erase | |
8604 | character to back up and delete the mistyped character. | |
8605 | ||
8606 | Sometimes you may mistype a character, and not notice the error until | |
8607 | you have typed several other characters. In that case, you can type | |
8608 | ‘C-b’ to move the cursor to the left, and then correct your mistake. | |
8609 | Afterwards, you can move the cursor to the right with ‘C-f’. | |
8610 | ||
8611 | When you add text in the middle of a line, you will notice that | |
8612 | characters to the right of the cursor are 'pushed over' to make room for | |
8613 | the text that you have inserted. Likewise, when you delete text behind | |
8614 | the cursor, characters to the right of the cursor are 'pulled back' to | |
8615 | fill in the blank space created by the removal of the text. These are | |
8616 | the bare essentials for editing the text of an input line: | |
8617 | ||
8618 | ‘C-b’ | |
8619 | Move back one character. | |
8620 | ‘C-f’ | |
8621 | Move forward one character. | |
8622 | <DEL> or <Backspace> | |
8623 | Delete the character to the left of the cursor. | |
8624 | ‘C-d’ | |
8625 | Delete the character underneath the cursor. | |
8626 | Printing characters | |
8627 | Insert the character into the line at the cursor. | |
8628 | ‘C-_’ or ‘C-x C-u’ | |
8629 | Undo the last editing command. You can undo all the way back to an | |
8630 | empty line. | |
8631 | ||
8632 | Depending on your configuration, the <Backspace> key might be set to | |
8633 | delete the character to the left of the cursor and the <DEL> key set to | |
8634 | delete the character underneath the cursor, like ‘C-d’, rather than the | |
8635 | character to the left of the cursor. | |
8636 | ||
8637 | \1f | |
8638 | File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction | |
8639 | ||
8640 | 8.2.2 Readline Movement Commands | |
8641 | -------------------------------- | |
8642 | ||
8643 | The above table describes the most basic keystrokes that you need in | |
8644 | order to do editing of the input line. For your convenience, many other | |
8645 | commands are available in addition to ‘C-b’, ‘C-f’, ‘C-d’, and <DEL>. | |
8646 | Here are some commands for moving more rapidly within the line. | |
8647 | ||
8648 | ‘C-a’ | |
8649 | Move to the start of the line. | |
8650 | ‘C-e’ | |
8651 | Move to the end of the line. | |
8652 | ‘M-f’ | |
8653 | Move forward a word, where a word is composed of letters and | |
8654 | digits. | |
8655 | ‘M-b’ | |
8656 | Move backward a word. | |
8657 | ‘C-l’ | |
8658 | Clear the screen, reprinting the current line at the top. | |
8659 | ||
8660 | Notice how ‘C-f’ moves forward a character, while ‘M-f’ moves forward | |
8661 | a word. It is a loose convention that control keystrokes operate on | |
8662 | characters while meta keystrokes operate on words. | |
8663 | ||
8664 | \1f | |
8665 | File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction | |
8666 | ||
8667 | 8.2.3 Readline Killing Commands | |
8668 | ------------------------------- | |
8669 | ||
8670 | “Killing” text means to delete the text from the line, but to save it | |
8671 | away for later use, usually by “yanking” (re-inserting) it back into the | |
8672 | line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.) | |
8673 | ||
8674 | If the description for a command says that it 'kills' text, then you | |
8675 | can be sure that you can get the text back in a different (or the same) | |
8676 | place later. | |
8677 | ||
8678 | When you use a kill command, the text is saved in a “kill-ring”. Any | |
8679 | number of consecutive kills save all of the killed text together, so | |
8680 | that when you yank it back, you get it all. The kill ring is not line | |
8681 | specific; the text that you killed on a previously typed line is | |
8682 | available to be yanked back later, when you are typing another line. | |
8683 | ||
8684 | Here is the list of commands for killing text. | |
8685 | ||
8686 | ‘C-k’ | |
8687 | Kill the text from the current cursor position to the end of the | |
8688 | line. | |
8689 | ||
8690 | ‘M-d’ | |
8691 | Kill from the cursor to the end of the current word, or, if between | |
8692 | words, to the end of the next word. Word boundaries are the same | |
8693 | as those used by ‘M-f’. | |
8694 | ||
8695 | ‘M-<DEL>’ | |
8696 | Kill from the cursor to the start of the current word, or, if | |
8697 | between words, to the start of the previous word. Word boundaries | |
8698 | are the same as those used by ‘M-b’. | |
8699 | ||
8700 | ‘C-w’ | |
8701 | Kill from the cursor to the previous whitespace. This is different | |
8702 | than ‘M-<DEL>’ because the word boundaries differ. | |
8703 | ||
8704 | Here is how to “yank” the text back into the line. Yanking means to | |
8705 | copy the most-recently-killed text from the kill buffer into the line at | |
8706 | the current cursor position. | |
8707 | ||
8708 | ‘C-y’ | |
8709 | Yank the most recently killed text back into the buffer at the | |
8710 | cursor. | |
8711 | ||
8712 | ‘M-y’ | |
8713 | Rotate the kill-ring, and yank the new top. You can only do this | |
8714 | if the prior command is ‘C-y’ or ‘M-y’. | |
8715 | ||
8716 | \1f | |
8717 | File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction | |
8718 | ||
8719 | 8.2.4 Readline Arguments | |
8720 | ------------------------ | |
8721 | ||
8722 | You can pass numeric arguments to Readline commands. Sometimes the | |
8723 | argument acts as a repeat count, other times it is the sign of the | |
8724 | argument that is significant. If you pass a negative argument to a | |
8725 | command which normally acts in a forward direction, that command will | |
8726 | act in a backward direction. For example, to kill text back to the | |
8727 | start of the line, you might type ‘M-- C-k’. | |
8728 | ||
8729 | The general way to pass numeric arguments to a command is to type | |
8730 | meta digits before the command. If the first 'digit' typed is a minus | |
8731 | sign (‘-’), then the sign of the argument will be negative. Once you | |
8732 | have typed one meta digit to get the argument started, you can type the | |
8733 | remainder of the digits, and then the command. For example, to give the | |
8734 | ‘C-d’ command an argument of 10, you could type ‘M-1 0 C-d’, which will | |
8735 | delete the next ten characters on the input line. | |
8736 | ||
8737 | \1f | |
8738 | File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction | |
8739 | ||
8740 | 8.2.5 Searching for Commands in the History | |
8741 | ------------------------------------------- | |
8742 | ||
8743 | Readline provides commands for searching through the command history | |
8744 | (*note Bash History Facilities::) for lines containing a specified | |
8745 | string. There are two search modes: “incremental” and | |
8746 | “non-incremental”. | |
8747 | ||
8748 | Incremental searches begin before the user has finished typing the | |
8749 | search string. As each character of the search string is typed, | |
8750 | Readline displays the next entry from the history matching the string | |
8751 | typed so far. An incremental search requires only as many characters as | |
8752 | needed to find the desired history entry. When using emacs editing | |
8753 | mode, type ‘C-r’ to search backward in the history for a particular | |
8754 | string. Typing ‘C-s’ searches forward through the history. The | |
8755 | characters present in the value of the ‘isearch-terminators’ variable | |
8756 | are used to terminate an incremental search. If that variable has not | |
8757 | been assigned a value, the <ESC> and ‘C-j’ characters terminate an | |
8758 | incremental search. ‘C-g’ aborts an incremental search and restores the | |
8759 | original line. When the search is terminated, the history entry | |
8760 | containing the search string becomes the current line. | |
8761 | ||
8762 | To find other matching entries in the history list, type ‘C-r’ or | |
8763 | ‘C-s’ as appropriate. This searches backward or forward in the history | |
8764 | for the next entry matching the search string typed so far. Any other | |
8765 | key sequence bound to a Readline command terminates the search and | |
8766 | executes that command. For instance, a <RET> terminates the search and | |
8767 | accepts the line, thereby executing the command from the history list. | |
8768 | A movement command will terminate the search, make the last line found | |
8769 | the current line, and begin editing. | |
8770 | ||
8771 | Readline remembers the last incremental search string. If two ‘C-r’s | |
8772 | are typed without any intervening characters defining a new search | |
8773 | string, Readline uses any remembered search string. | |
8774 | ||
8775 | Non-incremental searches read the entire search string before | |
8776 | starting to search for matching history entries. The search string may | |
8777 | be typed by the user or be part of the contents of the current line. | |
8778 | ||
8779 | \1f | |
8780 | File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing | |
8781 | ||
8782 | 8.3 Readline Init File | |
8783 | ====================== | |
8784 | ||
8785 | Although the Readline library comes with a set of Emacs-like keybindings | |
8786 | installed by default, it is possible to use a different set of | |
8787 | keybindings. Any user can customize programs that use Readline by | |
8788 | putting commands in an “inputrc” file, conventionally in their home | |
8789 | directory. The name of this file is taken from the value of the shell | |
8790 | variable ‘INPUTRC’. If that variable is unset, the default is | |
8791 | ‘~/.inputrc’. If that file does not exist or cannot be read, Readline | |
8792 | looks for ‘/etc/inputrc’. The ‘bind’ builtin command can also be used | |
8793 | to set Readline keybindings and variables. *Note Bash Builtins::. | |
8794 | ||
8795 | When a program that uses the Readline library starts up, Readline | |
8796 | reads the init file and sets any variables and key bindings it contains. | |
8797 | ||
8798 | In addition, the ‘C-x C-r’ command re-reads this init file, thus | |
8799 | incorporating any changes that you might have made to it. | |
8800 | ||
8801 | * Menu: | |
8802 | ||
8803 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
8804 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
8805 | * Sample Init File:: An example inputrc file. | |
8806 | ||
8807 | \1f | |
8808 | File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File | |
8809 | ||
8810 | 8.3.1 Readline Init File Syntax | |
8811 | ------------------------------- | |
8812 | ||
8813 | There are only a few basic constructs allowed in the Readline init file. | |
8814 | Blank lines are ignored. Lines beginning with a ‘#’ are comments. | |
8815 | Lines beginning with a ‘$’ indicate conditional constructs (*note | |
8816 | Conditional Init Constructs::). Other lines denote variable settings | |
8817 | and key bindings. | |
8818 | ||
8819 | Variable Settings | |
8820 | You can modify the run-time behavior of Readline by altering the | |
8821 | values of variables in Readline using the ‘set’ command within the | |
8822 | init file. The syntax is simple: | |
8823 | ||
8824 | set VARIABLE VALUE | |
8825 | ||
8826 | Here, for example, is how to change from the default Emacs-like key | |
8827 | binding to use ‘vi’ line editing commands: | |
8828 | ||
8829 | set editing-mode vi | |
8830 | ||
8831 | Variable names and values, where appropriate, are recognized | |
8832 | without regard to case. Unrecognized variable names are ignored. | |
8833 | ||
8834 | Boolean variables (those that can be set to on or off) are set to | |
8835 | on if the value is null or empty, ON (case-insensitive), or 1. Any | |
8836 | other value results in the variable being set to off. | |
8837 | ||
8838 | The ‘bind -V’ command lists the current Readline variable names and | |
8839 | values. *Note Bash Builtins::. | |
8840 | ||
8841 | A great deal of run-time behavior is changeable with the following | |
8842 | variables. | |
8843 | ||
8844 | ‘active-region-start-color’ | |
8845 | A string variable that controls the text color and background | |
8846 | when displaying the text in the active region (see the | |
8847 | description of ‘enable-active-region’ below). This string | |
8848 | must not take up any physical character positions on the | |
8849 | display, so it should consist only of terminal escape | |
8850 | sequences. It is output to the terminal before displaying the | |
8851 | text in the active region. This variable is reset to the | |
8852 | default value whenever the terminal type changes. The default | |
8853 | value is the string that puts the terminal in standout mode, | |
8854 | as obtained from the terminal's terminfo description. A | |
8855 | sample value might be ‘\e[01;33m’. | |
8856 | ||
8857 | ‘active-region-end-color’ | |
8858 | A string variable that "undoes" the effects of | |
8859 | ‘active-region-start-color’ and restores "normal" terminal | |
8860 | display appearance after displaying text in the active region. | |
8861 | This string must not take up any physical character positions | |
8862 | on the display, so it should consist only of terminal escape | |
8863 | sequences. It is output to the terminal after displaying the | |
8864 | text in the active region. This variable is reset to the | |
8865 | default value whenever the terminal type changes. The default | |
8866 | value is the string that restores the terminal from standout | |
8867 | mode, as obtained from the terminal's terminfo description. A | |
8868 | sample value might be ‘\e[0m’. | |
8869 | ||
8870 | ‘bell-style’ | |
8871 | Controls what happens when Readline wants to ring the terminal | |
8872 | bell. If set to ‘none’, Readline never rings the bell. If | |
8873 | set to ‘visible’, Readline uses a visible bell if one is | |
8874 | available. If set to ‘audible’ (the default), Readline | |
8875 | attempts to ring the terminal's bell. | |
8876 | ||
8877 | ‘bind-tty-special-chars’ | |
8878 | If set to ‘on’ (the default), Readline attempts to bind the | |
8879 | control characters that are treated specially by the kernel's | |
8880 | terminal driver to their Readline equivalents. These override | |
8881 | the default Readline bindings described here. Type ‘stty -a’ | |
8882 | at a Bash prompt to see your current terminal settings, | |
8883 | including the special control characters (usually ‘cchars’). | |
8884 | ||
8885 | ‘blink-matching-paren’ | |
8886 | If set to ‘on’, Readline attempts to briefly move the cursor | |
8887 | to an opening parenthesis when a closing parenthesis is | |
8888 | inserted. The default is ‘off’. | |
8889 | ||
8890 | ‘colored-completion-prefix’ | |
8891 | If set to ‘on’, when listing completions, Readline displays | |
8892 | the common prefix of the set of possible completions using a | |
8893 | different color. The color definitions are taken from the | |
8894 | value of the ‘LS_COLORS’ environment variable. If there is a | |
8895 | color definition in ‘LS_COLORS’ for the custom suffix | |
8896 | ‘readline-colored-completion-prefix’, Readline uses this color | |
8897 | for the common prefix instead of its default. The default is | |
8898 | ‘off’. | |
8899 | ||
8900 | ‘colored-stats’ | |
8901 | If set to ‘on’, Readline displays possible completions using | |
8902 | different colors to indicate their file type. The color | |
8903 | definitions are taken from the value of the ‘LS_COLORS’ | |
8904 | environment variable. The default is ‘off’. | |
8905 | ||
8906 | ‘comment-begin’ | |
8907 | The string to insert at the beginning of the line by the | |
8908 | ‘insert-comment’ command. The default value is ‘"#"’. | |
8909 | ||
8910 | ‘completion-display-width’ | |
8911 | The number of screen columns used to display possible matches | |
8912 | when performing completion. The value is ignored if it is | |
8913 | less than 0 or greater than the terminal screen width. A | |
8914 | value of 0 causes matches to be displayed one per line. The | |
8915 | default value is -1. | |
8916 | ||
8917 | ‘completion-ignore-case’ | |
8918 | If set to ‘on’, Readline performs filename matching and | |
8919 | completion in a case-insensitive fashion. The default value | |
8920 | is ‘off’. | |
8921 | ||
8922 | ‘completion-map-case’ | |
8923 | If set to ‘on’, and COMPLETION-IGNORE-CASE is enabled, | |
8924 | Readline treats hyphens (‘-’) and underscores (‘_’) as | |
8925 | equivalent when performing case-insensitive filename matching | |
8926 | and completion. The default value is ‘off’. | |
8927 | ||
8928 | ‘completion-prefix-display-length’ | |
8929 | The maximum length in characters of the common prefix of a | |
8930 | list of possible completions that is displayed without | |
8931 | modification. When set to a value greater than zero, Readline | |
8932 | replaces common prefixes longer than this value with an | |
8933 | ellipsis when displaying possible completions. If a | |
8934 | completion begins with a period, and Readline is completing | |
8935 | filenames, it uses three underscores instead of an ellipsis. | |
8936 | ||
8937 | ‘completion-query-items’ | |
8938 | The number of possible completions that determines when the | |
8939 | user is asked whether the list of possibilities should be | |
8940 | displayed. If the number of possible completions is greater | |
8941 | than or equal to this value, Readline asks whether or not the | |
8942 | user wishes to view them; otherwise, Readline simply lists the | |
8943 | completions. This variable must be set to an integer value | |
8944 | greater than or equal to zero. A zero value means Readline | |
8945 | should never ask; negative values are treated as zero. The | |
8946 | default limit is ‘100’. | |
8947 | ||
8948 | ‘convert-meta’ | |
8949 | If set to ‘on’, Readline converts characters it reads that | |
8950 | have the eighth bit set to an ASCII key sequence by clearing | |
8951 | the eighth bit and prefixing an <ESC> character, converting | |
8952 | them to a meta-prefixed key sequence. The default value is | |
8953 | ‘on’, but Readline sets it to ‘off’ if the locale contains | |
8954 | characters whose encodings may include bytes with the eighth | |
8955 | bit set. This variable is dependent on the ‘LC_CTYPE’ locale | |
8956 | category, and may change if the locale changes. This variable | |
8957 | also affects key bindings; see the description of | |
8958 | ‘force-meta-prefix’ below. | |
8959 | ||
8960 | ‘disable-completion’ | |
8961 | If set to ‘On’, Readline inhibits word completion. Completion | |
8962 | characters are inserted into the line as if they had been | |
8963 | mapped to ‘self-insert’. The default is ‘off’. | |
8964 | ||
8965 | ‘echo-control-characters’ | |
8966 | When set to ‘on’, on operating systems that indicate they | |
8967 | support it, Readline echoes a character corresponding to a | |
8968 | signal generated from the keyboard. The default is ‘on’. | |
8969 | ||
8970 | ‘editing-mode’ | |
8971 | The ‘editing-mode’ variable controls the default set of key | |
8972 | bindings. By default, Readline starts up in emacs editing | |
8973 | mode, where the keystrokes are most similar to Emacs. This | |
8974 | variable can be set to either ‘emacs’ or ‘vi’. | |
8975 | ||
8976 | ‘emacs-mode-string’ | |
8977 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is | |
8978 | displayed immediately before the last line of the primary | |
8979 | prompt when emacs editing mode is active. The value is | |
8980 | expanded like a key binding, so the standard set of meta- and | |
8981 | control- prefixes and backslash escape sequences is available. | |
8982 | The ‘\1’ and ‘\2’ escapes begin and end sequences of | |
8983 | non-printing characters, which can be used to embed a terminal | |
8984 | control sequence into the mode string. The default is ‘@’. | |
8985 | ||
8986 | ‘enable-active-region’ | |
8987 | “point” is the current cursor position, and “mark” refers to a | |
8988 | saved cursor position (*note Commands For Moving::). The text | |
8989 | between the point and mark is referred to as the “region”. | |
8990 | When this variable is set to ‘On’, Readline allows certain | |
8991 | commands to designate the region as “active”. When the region | |
8992 | is active, Readline highlights the text in the region using | |
8993 | the value of the ‘active-region-start-color’, which defaults | |
8994 | to the string that enables the terminal's standout mode. The | |
8995 | active region shows the text inserted by bracketed-paste and | |
8996 | any matching text found by incremental and non-incremental | |
8997 | history searches. The default is ‘On’. | |
8998 | ||
8999 | ‘enable-bracketed-paste’ | |
9000 | When set to ‘On’, Readline configures the terminal to insert | |
9001 | each paste into the editing buffer as a single string of | |
9002 | characters, instead of treating each character as if it had | |
9003 | been read from the keyboard. This is called putting the | |
9004 | terminal into “bracketed paste mode”; it prevents Readline | |
9005 | from executing any editing commands bound to key sequences | |
9006 | appearing in the pasted text. The default is ‘On’. | |
9007 | ||
9008 | ‘enable-keypad’ | |
9009 | When set to ‘on’, Readline tries to enable the application | |
9010 | keypad when it is called. Some systems need this to enable | |
9011 | the arrow keys. The default is ‘off’. | |
9012 | ||
9013 | ‘enable-meta-key’ | |
9014 | When set to ‘on’, Readline tries to enable any meta modifier | |
9015 | key the terminal claims to support when it is called. On many | |
9016 | terminals, the Meta key is used to send eight-bit characters; | |
9017 | this variable checks for the terminal capability that | |
9018 | indicates the terminal can enable and disable a mode that sets | |
9019 | the eighth bit of a character (0200) if the Meta key is held | |
9020 | down when the character is typed (a meta character). The | |
9021 | default is ‘on’. | |
9022 | ||
9023 | ‘expand-tilde’ | |
9024 | If set to ‘on’, Readline attempts tilde expansion when it | |
9025 | attempts word completion. The default is ‘off’. | |
9026 | ||
9027 | ‘force-meta-prefix’ | |
9028 | If set to ‘on’, Readline modifies its behavior when binding | |
9029 | key sequences containing ‘\M-’ or ‘Meta-’ (see ‘Key Bindings’ | |
9030 | in *note Readline Init File Syntax::) by converting a key | |
9031 | sequence of the form ‘\M-’C or ‘Meta-’C to the two-character | |
9032 | sequence ‘ESC’ C (adding the meta prefix). If | |
9033 | ‘force-meta-prefix’ is set to ‘off’ (the default), Readline | |
9034 | uses the value of the ‘convert-meta’ variable to determine | |
9035 | whether to perform this conversion: if ‘convert-meta’ is ‘on’, | |
9036 | Readline performs the conversion described above; if it is | |
9037 | ‘off’, Readline converts C to a meta character by setting the | |
9038 | eighth bit (0200). The default is ‘off’. | |
9039 | ||
9040 | ‘history-preserve-point’ | |
9041 | If set to ‘on’, the history code attempts to place the point | |
9042 | (the current cursor position) at the same location on each | |
9043 | history line retrieved with ‘previous-history’ or | |
9044 | ‘next-history’. The default is ‘off’. | |
9045 | ||
9046 | ‘history-size’ | |
9047 | Set the maximum number of history entries saved in the history | |
9048 | list. If set to zero, any existing history entries are | |
9049 | deleted and no new entries are saved. If set to a value less | |
9050 | than zero, the number of history entries is not limited. By | |
9051 | default, Bash sets the maximum number of history entries to | |
9052 | the value of the ‘HISTSIZE’ shell variable. If you try to set | |
9053 | HISTORY-SIZE to a non-numeric value, the maximum number of | |
9054 | history entries will be set to 500. | |
9055 | ||
9056 | ‘horizontal-scroll-mode’ | |
9057 | Setting this variable to ‘on’ means that the text of the lines | |
9058 | being edited will scroll horizontally on a single screen line | |
9059 | when the lines are longer than the width of the screen, | |
9060 | instead of wrapping onto a new screen line. This variable is | |
9061 | automatically set to ‘on’ for terminals of height 1. By | |
9062 | default, this variable is set to ‘off’. | |
9063 | ||
9064 | ‘input-meta’ | |
9065 | If set to ‘on’, Readline enables eight-bit input (that is, it | |
9066 | does not clear the eighth bit in the characters it reads), | |
9067 | regardless of what the terminal claims it can support. The | |
9068 | default value is ‘off’, but Readline sets it to ‘on’ if the | |
9069 | locale contains characters whose encodings may include bytes | |
9070 | with the eighth bit set. This variable is dependent on the | |
9071 | ‘LC_CTYPE’ locale category, and its value may change if the | |
9072 | locale changes. The name ‘meta-flag’ is a synonym for | |
9073 | ‘input-meta’. | |
9074 | ||
9075 | ‘isearch-terminators’ | |
9076 | The string of characters that should terminate an incremental | |
9077 | search without subsequently executing the character as a | |
9078 | command (*note Searching::). If this variable has not been | |
9079 | given a value, the characters <ESC> and ‘C-j’ terminate an | |
9080 | incremental search. | |
9081 | ||
9082 | ‘keymap’ | |
9083 | Sets Readline's idea of the current keymap for key binding | |
9084 | commands. Built-in ‘keymap’ names are ‘emacs’, | |
9085 | ‘emacs-standard’, ‘emacs-meta’, ‘emacs-ctlx’, ‘vi’, ‘vi-move’, | |
9086 | ‘vi-command’, and ‘vi-insert’. ‘vi’ is equivalent to | |
9087 | ‘vi-command’ (‘vi-move’ is also a synonym); ‘emacs’ is | |
9088 | equivalent to ‘emacs-standard’. Applications may add | |
9089 | additional names. The default value is ‘emacs’; the value of | |
9090 | the ‘editing-mode’ variable also affects the default keymap. | |
9091 | ||
9092 | ‘keyseq-timeout’ | |
9093 | Specifies the duration Readline will wait for a character when | |
9094 | reading an ambiguous key sequence (one that can form a | |
9095 | complete key sequence using the input read so far, or can take | |
9096 | additional input to complete a longer key sequence). If | |
9097 | Readline doesn't receive any input within the timeout, it uses | |
9098 | the shorter but complete key sequence. Readline uses this | |
9099 | value to determine whether or not input is available on the | |
9100 | current input source (‘rl_instream’ by default). The value is | |
9101 | specified in milliseconds, so a value of 1000 means that | |
9102 | Readline will wait one second for additional input. If this | |
9103 | variable is set to a value less than or equal to zero, or to a | |
9104 | non-numeric value, Readline waits until another key is pressed | |
9105 | to decide which key sequence to complete. The default value | |
9106 | is ‘500’. | |
9107 | ||
9108 | ‘mark-directories’ | |
9109 | If set to ‘on’, completed directory names have a slash | |
9110 | appended. The default is ‘on’. | |
9111 | ||
9112 | ‘mark-modified-lines’ | |
9113 | When this variable is set to ‘on’, Readline displays an | |
9114 | asterisk (‘*’) at the start of history lines which have been | |
9115 | modified. This variable is ‘off’ by default. | |
9116 | ||
9117 | ‘mark-symlinked-directories’ | |
9118 | If set to ‘on’, completed names which are symbolic links to | |
9119 | directories have a slash appended, subject to the value of | |
9120 | ‘mark-directories’. The default is ‘off’. | |
9121 | ||
9122 | ‘match-hidden-files’ | |
9123 | This variable, when set to ‘on’, forces Readline to match | |
9124 | files whose names begin with a ‘.’ (hidden files) when | |
9125 | performing filename completion. If set to ‘off’, the user | |
9126 | must include the leading ‘.’ in the filename to be completed. | |
9127 | This variable is ‘on’ by default. | |
9128 | ||
9129 | ‘menu-complete-display-prefix’ | |
9130 | If set to ‘on’, menu completion displays the common prefix of | |
9131 | the list of possible completions (which may be empty) before | |
9132 | cycling through the list. The default is ‘off’. | |
9133 | ||
9134 | ‘output-meta’ | |
9135 | If set to ‘on’, Readline displays characters with the eighth | |
9136 | bit set directly rather than as a meta-prefixed escape | |
9137 | sequence. The default is ‘off’, but Readline sets it to ‘on’ | |
9138 | if the locale contains characters whose encodings may include | |
9139 | bytes with the eighth bit set. This variable is dependent on | |
9140 | the ‘LC_CTYPE’ locale category, and its value may change if | |
9141 | the locale changes. | |
9142 | ||
9143 | ‘page-completions’ | |
9144 | If set to ‘on’, Readline uses an internal pager resembling | |
9145 | more(1) to display a screenful of possible completions at a | |
9146 | time. This variable is ‘on’ by default. | |
9147 | ||
9148 | ‘prefer-visible-bell’ | |
9149 | See ‘bell-style’. | |
9150 | ||
9151 | ‘print-completions-horizontally’ | |
9152 | If set to ‘on’, Readline displays completions with matches | |
9153 | sorted horizontally in alphabetical order, rather than down | |
9154 | the screen. The default is ‘off’. | |
9155 | ||
9156 | ‘revert-all-at-newline’ | |
9157 | If set to ‘on’, Readline will undo all changes to history | |
9158 | lines before returning when executing ‘accept-line’. By | |
9159 | default, history lines may be modified and retain individual | |
9160 | undo lists across calls to ‘readline()’. The default is | |
9161 | ‘off’. | |
9162 | ||
9163 | ‘search-ignore-case’ | |
9164 | If set to ‘on’, Readline performs incremental and | |
9165 | non-incremental history list searches in a case-insensitive | |
9166 | fashion. The default value is ‘off’. | |
9167 | ||
9168 | ‘show-all-if-ambiguous’ | |
9169 | This alters the default behavior of the completion functions. | |
9170 | If set to ‘on’, words which have more than one possible | |
9171 | completion cause the matches to be listed immediately instead | |
9172 | of ringing the bell. The default value is ‘off’. | |
9173 | ||
9174 | ‘show-all-if-unmodified’ | |
9175 | This alters the default behavior of the completion functions | |
9176 | in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to | |
9177 | ‘on’, words which have more than one possible completion | |
9178 | without any possible partial completion (the possible | |
9179 | completions don't share a common prefix) cause the matches to | |
9180 | be listed immediately instead of ringing the bell. The | |
9181 | default value is ‘off’. | |
9182 | ||
9183 | ‘show-mode-in-prompt’ | |
9184 | If set to ‘on’, add a string to the beginning of the prompt | |
9185 | indicating the editing mode: emacs, vi command, or vi | |
9186 | insertion. The mode strings are user-settable (e.g., | |
9187 | EMACS-MODE-STRING). The default value is ‘off’. | |
9188 | ||
9189 | ‘skip-completed-text’ | |
9190 | If set to ‘on’, this alters the default completion behavior | |
9191 | when inserting a single match into the line. It's only active | |
9192 | when performing completion in the middle of a word. If | |
9193 | enabled, Readline does not insert characters from the | |
9194 | completion that match characters after point in the word being | |
9195 | completed, so portions of the word following the cursor are | |
9196 | not duplicated. For instance, if this is enabled, attempting | |
9197 | completion when the cursor is after the first ‘e’ in | |
9198 | ‘Makefile’ will result in ‘Makefile’ rather than | |
9199 | ‘Makefilefile’, assuming there is a single possible | |
9200 | completion. The default value is ‘off’. | |
9201 | ||
9202 | ‘vi-cmd-mode-string’ | |
9203 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is | |
9204 | displayed immediately before the last line of the primary | |
9205 | prompt when vi editing mode is active and in command mode. | |
9206 | The value is expanded like a key binding, so the standard set | |
9207 | of meta- and control- prefixes and backslash escape sequences | |
9208 | is available. The ‘\1’ and ‘\2’ escapes begin and end | |
9209 | sequences of non-printing characters, which can be used to | |
9210 | embed a terminal control sequence into the mode string. The | |
9211 | default is ‘(cmd)’. | |
9212 | ||
9213 | ‘vi-ins-mode-string’ | |
9214 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is | |
9215 | displayed immediately before the last line of the primary | |
9216 | prompt when vi editing mode is active and in insertion mode. | |
9217 | The value is expanded like a key binding, so the standard set | |
9218 | of meta- and control- prefixes and backslash escape sequences | |
9219 | is available. The ‘\1’ and ‘\2’ escapes begin and end | |
9220 | sequences of non-printing characters, which can be used to | |
9221 | embed a terminal control sequence into the mode string. The | |
9222 | default is ‘(ins)’. | |
9223 | ||
9224 | ‘visible-stats’ | |
9225 | If set to ‘on’, a character denoting a file's type is appended | |
9226 | to the filename when listing possible completions. The | |
9227 | default is ‘off’. | |
9228 | ||
9229 | Key Bindings | |
9230 | The syntax for controlling key bindings in the init file is simple. | |
9231 | First you need to find the name of the command that you want to | |
9232 | change. The following sections contain tables of the command name, | |
9233 | the default keybinding, if any, and a short description of what the | |
9234 | command does. | |
9235 | ||
9236 | Once you know the name of the command, simply place on a line in | |
9237 | the init file the name of the key you wish to bind the command to, | |
9238 | a colon, and then the name of the command. There can be no space | |
9239 | between the key name and the colon - that will be interpreted as | |
9240 | part of the key name. The name of the key can be expressed in | |
9241 | different ways, depending on what you find most comfortable. | |
9242 | ||
9243 | In addition to command names, Readline allows keys to be bound to a | |
9244 | string that is inserted when the key is pressed (a MACRO). The | |
9245 | difference between a macro and a command is that a macro is | |
9246 | enclosed in single or double quotes. | |
9247 | ||
9248 | The ‘bind -p’ command displays Readline function names and bindings | |
9249 | in a format that can be put directly into an initialization file. | |
9250 | *Note Bash Builtins::. | |
9251 | ||
9252 | KEYNAME: FUNCTION-NAME or MACRO | |
9253 | KEYNAME is the name of a key spelled out in English. For | |
9254 | example: | |
9255 | Control-u: universal-argument | |
9256 | Meta-Rubout: backward-kill-word | |
9257 | Control-o: "> output" | |
9258 | ||
9259 | In the example above, ‘C-u’ is bound to the function | |
9260 | ‘universal-argument’, ‘M-DEL’ is bound to the function | |
9261 | ‘backward-kill-word’, and ‘C-o’ is bound to run the macro | |
9262 | expressed on the right hand side (that is, to insert the text | |
9263 | ‘> output’ into the line). | |
9264 | ||
9265 | This key binding syntax recognizes a number of symbolic | |
9266 | character names: DEL, ESC, ESCAPE, LFD, NEWLINE, RET, RETURN, | |
9267 | RUBOUT (a destructive backspace), SPACE, SPC, and TAB. | |
9268 | ||
9269 | "KEYSEQ": FUNCTION-NAME or MACRO | |
9270 | KEYSEQ differs from KEYNAME above in that strings denoting an | |
9271 | entire key sequence can be specified, by placing the key | |
9272 | sequence in double quotes. Some GNU Emacs style key escapes | |
9273 | can be used, as in the following example, but none of the | |
9274 | special character names are recognized. | |
9275 | ||
9276 | "\C-u": universal-argument | |
9277 | "\C-x\C-r": re-read-init-file | |
9278 | "\e[11~": "Function Key 1" | |
9279 | ||
9280 | In the above example, ‘C-u’ is again bound to the function | |
9281 | ‘universal-argument’ (just as it was in the first example), | |
9282 | ‘‘C-x’ ‘C-r’’ is bound to the function ‘re-read-init-file’, | |
9283 | and ‘<ESC> <[> <1> <1> <~>’ is bound to insert the text | |
9284 | ‘Function Key 1’. | |
9285 | ||
9286 | The following GNU Emacs style escape sequences are available when | |
9287 | specifying key sequences: | |
9288 | ||
9289 | ‘\C-’ | |
9290 | A control prefix. | |
9291 | ‘\M-’ | |
9292 | Adding the meta prefix or converting the following character | |
9293 | to a meta character, as described above under | |
9294 | ‘force-meta-prefix’ (see ‘Variable Settings’ in *note Readline | |
9295 | Init File Syntax::). | |
9296 | ‘\e’ | |
9297 | An escape character. | |
9298 | ‘\\’ | |
9299 | Backslash. | |
9300 | ‘\"’ | |
9301 | <">, a double quotation mark. | |
9302 | ‘\'’ | |
9303 | <'>, a single quote or apostrophe. | |
9304 | ||
9305 | In addition to the GNU Emacs style escape sequences, a second set | |
9306 | of backslash escapes is available: | |
9307 | ||
9308 | ‘\a’ | |
9309 | alert (bell) | |
9310 | ‘\b’ | |
9311 | backspace | |
9312 | ‘\d’ | |
9313 | delete | |
9314 | ‘\f’ | |
9315 | form feed | |
9316 | ‘\n’ | |
9317 | newline | |
9318 | ‘\r’ | |
9319 | carriage return | |
9320 | ‘\t’ | |
9321 | horizontal tab | |
9322 | ‘\v’ | |
9323 | vertical tab | |
9324 | ‘\NNN’ | |
9325 | The eight-bit character whose value is the octal value NNN | |
9326 | (one to three digits). | |
9327 | ‘\xHH’ | |
9328 | The eight-bit character whose value is the hexadecimal value | |
9329 | HH (one or two hex digits). | |
9330 | ||
9331 | When entering the text of a macro, single or double quotes must be | |
9332 | used to indicate a macro definition. Unquoted text is assumed to | |
9333 | be a function name. The backslash escapes described above are | |
9334 | expanded in the macro body. Backslash will quote any other | |
9335 | character in the macro text, including ‘"’ and ‘'’. For example, | |
9336 | the following binding will make ‘‘C-x’ \’ insert a single ‘\’ into | |
9337 | the line: | |
9338 | "\C-x\\": "\\" | |
9339 | ||
9340 | \1f | |
9341 | File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File | |
9342 | ||
9343 | 8.3.2 Conditional Init Constructs | |
9344 | --------------------------------- | |
9345 | ||
9346 | Readline implements a facility similar in spirit to the conditional | |
9347 | compilation features of the C preprocessor which allows key bindings and | |
9348 | variable settings to be performed as the result of tests. There are | |
9349 | four parser directives available. | |
9350 | ||
9351 | ‘$if’ | |
9352 | The ‘$if’ construct allows bindings to be made based on the editing | |
9353 | mode, the terminal being used, or the application using Readline. | |
9354 | The text of the test, after any comparison operator, extends to the | |
9355 | end of the line; unless otherwise noted, no characters are required | |
9356 | to isolate it. | |
9357 | ||
9358 | ‘mode’ | |
9359 | The ‘mode=’ form of the ‘$if’ directive is used to test | |
9360 | whether Readline is in ‘emacs’ or ‘vi’ mode. This may be used | |
9361 | in conjunction with the ‘set keymap’ command, for instance, to | |
9362 | set bindings in the ‘emacs-standard’ and ‘emacs-ctlx’ keymaps | |
9363 | only if Readline is starting out in ‘emacs’ mode. | |
9364 | ||
9365 | ‘term’ | |
9366 | The ‘term=’ form may be used to include terminal-specific key | |
9367 | bindings, perhaps to bind the key sequences output by the | |
9368 | terminal's function keys. The word on the right side of the | |
9369 | ‘=’ is tested against both the full name of the terminal and | |
9370 | the portion of the terminal name before the first ‘-’. This | |
9371 | allows ‘xterm’ to match both ‘xterm’ and ‘xterm-256color’, for | |
9372 | instance. | |
9373 | ||
9374 | ‘version’ | |
9375 | The ‘version’ test may be used to perform comparisons against | |
9376 | specific Readline versions. The ‘version’ expands to the | |
9377 | current Readline version. The set of comparison operators | |
9378 | includes ‘=’ (and ‘==’), ‘!=’, ‘<=’, ‘>=’, ‘<’, and ‘>’. The | |
9379 | version number supplied on the right side of the operator | |
9380 | consists of a major version number, an optional decimal point, | |
9381 | and an optional minor version (e.g., ‘7.1’). If the minor | |
9382 | version is omitted, it defaults to ‘0’. The operator may be | |
9383 | separated from the string ‘version’ and from the version | |
9384 | number argument by whitespace. The following example sets a | |
9385 | variable if the Readline version being used is 7.0 or newer: | |
9386 | $if version >= 7.0 | |
9387 | set show-mode-in-prompt on | |
9388 | $endif | |
9389 | ||
9390 | ‘application’ | |
9391 | The APPLICATION construct is used to include | |
9392 | application-specific settings. Each program using the | |
9393 | Readline library sets the APPLICATION NAME, and you can test | |
9394 | for a particular value. This could be used to bind key | |
9395 | sequences to functions useful for a specific program. For | |
9396 | instance, the following command adds a key sequence that | |
9397 | quotes the current or previous word in Bash: | |
9398 | $if Bash | |
9399 | # Quote the current or previous word | |
9400 | "\C-xq": "\eb\"\ef\"" | |
9401 | $endif | |
9402 | ||
9403 | ‘variable’ | |
9404 | The VARIABLE construct provides simple equality tests for | |
9405 | Readline variables and values. The permitted comparison | |
9406 | operators are ‘=’, ‘==’, and ‘!=’. The variable name must be | |
9407 | separated from the comparison operator by whitespace; the | |
9408 | operator may be separated from the value on the right hand | |
9409 | side by whitespace. String and boolean variables may be | |
9410 | tested. Boolean variables must be tested against the values | |
9411 | ON and OFF. The following example is equivalent to the | |
9412 | ‘mode=emacs’ test described above: | |
9413 | $if editing-mode == emacs | |
9414 | set show-mode-in-prompt on | |
9415 | $endif | |
9416 | ||
9417 | ‘$else’ | |
9418 | Commands in this branch of the ‘$if’ directive are executed if the | |
9419 | test fails. | |
9420 | ||
9421 | ‘$endif’ | |
9422 | This command, as seen in the previous example, terminates an ‘$if’ | |
9423 | command. | |
9424 | ||
9425 | ‘$include’ | |
9426 | This directive takes a single filename as an argument and reads | |
9427 | commands and key bindings from that file. For example, the | |
9428 | following directive reads from ‘/etc/inputrc’: | |
9429 | $include /etc/inputrc | |
9430 | ||
9431 | \1f | |
9432 | File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File | |
9433 | ||
9434 | 8.3.3 Sample Init File | |
9435 | ---------------------- | |
9436 | ||
9437 | Here is an example of an INPUTRC file. This illustrates key binding, | |
9438 | variable assignment, and conditional syntax. | |
9439 | ||
9440 | # This file controls the behavior of line input editing for | |
9441 | # programs that use the GNU Readline library. Existing | |
9442 | # programs include FTP, Bash, and GDB. | |
9443 | # | |
9444 | # You can re-read the inputrc file with C-x C-r. | |
9445 | # Lines beginning with '#' are comments. | |
9446 | # | |
9447 | # First, include any system-wide bindings and variable | |
9448 | # assignments from /etc/Inputrc | |
9449 | $include /etc/Inputrc | |
9450 | ||
9451 | # | |
9452 | # Set various bindings for emacs mode. | |
9453 | ||
9454 | set editing-mode emacs | |
9455 | ||
9456 | $if mode=emacs | |
9457 | ||
9458 | Meta-Control-h: backward-kill-word Text after the function name is ignored | |
9459 | ||
9460 | # | |
9461 | # Arrow keys in keypad mode | |
9462 | # | |
9463 | #"\M-OD": backward-char | |
9464 | #"\M-OC": forward-char | |
9465 | #"\M-OA": previous-history | |
9466 | #"\M-OB": next-history | |
9467 | # | |
9468 | # Arrow keys in ANSI mode | |
9469 | # | |
9470 | "\M-[D": backward-char | |
9471 | "\M-[C": forward-char | |
9472 | "\M-[A": previous-history | |
9473 | "\M-[B": next-history | |
9474 | # | |
9475 | # Arrow keys in 8 bit keypad mode | |
9476 | # | |
9477 | #"\M-\C-OD": backward-char | |
9478 | #"\M-\C-OC": forward-char | |
9479 | #"\M-\C-OA": previous-history | |
9480 | #"\M-\C-OB": next-history | |
9481 | # | |
9482 | # Arrow keys in 8 bit ANSI mode | |
9483 | # | |
9484 | #"\M-\C-[D": backward-char | |
9485 | #"\M-\C-[C": forward-char | |
9486 | #"\M-\C-[A": previous-history | |
9487 | #"\M-\C-[B": next-history | |
9488 | ||
9489 | C-q: quoted-insert | |
9490 | ||
9491 | $endif | |
9492 | ||
9493 | # An old-style binding. This happens to be the default. | |
9494 | TAB: complete | |
9495 | ||
9496 | # Macros that are convenient for shell interaction | |
9497 | $if Bash | |
9498 | # edit the path | |
9499 | "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f" | |
9500 | # prepare to type a quoted word -- | |
9501 | # insert open and close double quotes | |
9502 | # and move to just after the open quote | |
9503 | "\C-x\"": "\"\"\C-b" | |
9504 | # insert a backslash (testing backslash escapes | |
9505 | # in sequences and macros) | |
9506 | "\C-x\\": "\\" | |
9507 | # Quote the current or previous word | |
9508 | "\C-xq": "\eb\"\ef\"" | |
9509 | # Add a binding to refresh the line, which is unbound | |
9510 | "\C-xr": redraw-current-line | |
9511 | # Edit variable on current line. | |
9512 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
9513 | $endif | |
9514 | ||
9515 | # use a visible bell if one is available | |
9516 | set bell-style visible | |
9517 | ||
9518 | # don't strip characters to 7 bits when reading | |
9519 | set input-meta on | |
9520 | ||
9521 | # allow iso-latin1 characters to be inserted rather | |
9522 | # than converted to prefix-meta sequences | |
9523 | set convert-meta off | |
9524 | ||
9525 | # display characters with the eighth bit set directly | |
9526 | # rather than as meta-prefixed characters | |
9527 | set output-meta on | |
9528 | ||
9529 | # if there are 150 or more possible completions for a word, | |
9530 | # ask whether or not the user wants to see all of them | |
9531 | set completion-query-items 150 | |
9532 | ||
9533 | # For FTP | |
9534 | $if Ftp | |
9535 | "\C-xg": "get \M-?" | |
9536 | "\C-xt": "put \M-?" | |
9537 | "\M-.": yank-last-arg | |
9538 | $endif | |
9539 | ||
9540 | \1f | |
9541 | File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing | |
9542 | ||
9543 | 8.4 Bindable Readline Commands | |
9544 | ============================== | |
9545 | ||
9546 | * Menu: | |
9547 | ||
9548 | * Commands For Moving:: Moving about the line. | |
9549 | * Commands For History:: Getting at previous lines. | |
9550 | * Commands For Text:: Commands for changing text. | |
9551 | * Commands For Killing:: Commands for killing and yanking. | |
9552 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
9553 | * Commands For Completion:: Getting Readline to do the typing for you. | |
9554 | * Keyboard Macros:: Saving and re-executing typed characters | |
9555 | * Miscellaneous Commands:: Other miscellaneous commands. | |
9556 | ||
9557 | This section describes Readline commands that may be bound to key | |
9558 | sequences. You can list your key bindings by executing ‘bind -P’ or, | |
9559 | for a more terse format, suitable for an INPUTRC file, ‘bind -p’. | |
9560 | (*Note Bash Builtins::.) Command names without an accompanying key | |
9561 | sequence are unbound by default. | |
9562 | ||
9563 | In the following descriptions, “point” refers to the current cursor | |
9564 | position, and “mark” refers to a cursor position saved by the ‘set-mark’ | |
9565 | command. The text between the point and mark is referred to as the | |
9566 | “region”. Readline has the concept of an _active region_: when the | |
9567 | region is active, Readline redisplay highlights the region using the | |
9568 | value of the ‘active-region-start-color’ variable. The | |
9569 | ‘enable-active-region’ variable turns this on and off. Several commands | |
9570 | set the region to active; those are noted below. | |
9571 | ||
9572 | \1f | |
9573 | File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands | |
9574 | ||
9575 | 8.4.1 Commands For Moving | |
9576 | ------------------------- | |
9577 | ||
9578 | ‘beginning-of-line (C-a)’ | |
9579 | Move to the start of the current line. This may also be bound to | |
9580 | the Home key on some keyboards. | |
9581 | ||
9582 | ‘end-of-line (C-e)’ | |
9583 | Move to the end of the line. This may also be bound to the End key | |
9584 | on some keyboards. | |
9585 | ||
9586 | ‘forward-char (C-f)’ | |
9587 | Move forward a character. This may also be bound to the right | |
9588 | arrow key on some keyboards. | |
9589 | ||
9590 | ‘backward-char (C-b)’ | |
9591 | Move back a character. This may also be bound to the left arrow | |
9592 | key on some keyboards. | |
9593 | ||
9594 | ‘forward-word (M-f)’ | |
9595 | Move forward to the end of the next word. Words are composed of | |
9596 | letters and digits. | |
9597 | ||
9598 | ‘backward-word (M-b)’ | |
9599 | Move back to the start of the current or previous word. Words are | |
9600 | composed of letters and digits. | |
9601 | ||
9602 | ‘shell-forward-word (M-C-f)’ | |
9603 | Move forward to the end of the next word. Words are delimited by | |
9604 | non-quoted shell metacharacters. | |
9605 | ||
9606 | ‘shell-backward-word (M-C-b)’ | |
9607 | Move back to the start of the current or previous word. Words are | |
9608 | delimited by non-quoted shell metacharacters. | |
9609 | ||
9610 | ‘previous-screen-line ()’ | |
9611 | Attempt to move point to the same physical screen column on the | |
9612 | previous physical screen line. This will not have the desired | |
9613 | effect if the current Readline line does not take up more than one | |
9614 | physical line or if point is not greater than the length of the | |
9615 | prompt plus the screen width. | |
9616 | ||
9617 | ‘next-screen-line ()’ | |
9618 | Attempt to move point to the same physical screen column on the | |
9619 | next physical screen line. This will not have the desired effect | |
9620 | if the current Readline line does not take up more than one | |
9621 | physical line or if the length of the current Readline line is not | |
9622 | greater than the length of the prompt plus the screen width. | |
9623 | ||
9624 | ‘clear-display (M-C-l)’ | |
9625 | Clear the screen and, if possible, the terminal's scrollback | |
9626 | buffer, then redraw the current line, leaving the current line at | |
9627 | the top of the screen. | |
9628 | ||
9629 | ‘clear-screen (C-l)’ | |
9630 | Clear the screen, then redraw the current line, leaving the current | |
9631 | line at the top of the screen. If given a numeric argument, this | |
9632 | refreshes the current line without clearing the screen. | |
9633 | ||
9634 | ‘redraw-current-line ()’ | |
9635 | Refresh the current line. By default, this is unbound. | |
9636 | ||
9637 | \1f | |
9638 | File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands | |
9639 | ||
9640 | 8.4.2 Commands For Manipulating The History | |
9641 | ------------------------------------------- | |
9642 | ||
9643 | ‘accept-line (Newline or Return)’ | |
9644 | Accept the line regardless of where the cursor is. If this line is | |
9645 | non-empty, add it to the history list according to the setting of | |
9646 | the ‘HISTCONTROL’ and ‘HISTIGNORE’ variables. If this line is a | |
9647 | modified history line, then restore the history line to its | |
9648 | original state. | |
9649 | ||
9650 | ‘previous-history (C-p)’ | |
9651 | Move 'back' through the history list, fetching the previous | |
9652 | command. This may also be bound to the up arrow key on some | |
9653 | keyboards. | |
9654 | ||
9655 | ‘next-history (C-n)’ | |
9656 | Move 'forward' through the history list, fetching the next command. | |
9657 | This may also be bound to the down arrow key on some keyboards. | |
9658 | ||
9659 | ‘beginning-of-history (M-<)’ | |
9660 | Move to the first line in the history. | |
9661 | ||
9662 | ‘end-of-history (M->)’ | |
9663 | Move to the end of the input history, i.e., the line currently | |
9664 | being entered. | |
9665 | ||
9666 | ‘reverse-search-history (C-r)’ | |
9667 | Search backward starting at the current line and moving 'up' | |
9668 | through the history as necessary. This is an incremental search. | |
9669 | This command sets the region to the matched text and activates the | |
9670 | region. | |
9671 | ||
9672 | ‘forward-search-history (C-s)’ | |
9673 | Search forward starting at the current line and moving 'down' | |
9674 | through the history as necessary. This is an incremental search. | |
9675 | This command sets the region to the matched text and activates the | |
9676 | region. | |
9677 | ||
9678 | ‘non-incremental-reverse-search-history (M-p)’ | |
9679 | Search backward starting at the current line and moving 'up' | |
9680 | through the history as necessary using a non-incremental search for | |
9681 | a string supplied by the user. The search string may match | |
9682 | anywhere in a history line. | |
9683 | ||
9684 | ‘non-incremental-forward-search-history (M-n)’ | |
9685 | Search forward starting at the current line and moving 'down' | |
9686 | through the history as necessary using a non-incremental search for | |
9687 | a string supplied by the user. The search string may match | |
9688 | anywhere in a history line. | |
9689 | ||
9690 | ‘history-search-backward ()’ | |
9691 | Search backward through the history for the string of characters | |
9692 | between the start of the current line and the point. The search | |
9693 | string must match at the beginning of a history line. This is a | |
9694 | non-incremental search. By default, this command is unbound, but | |
9695 | may be bound to the Page Down key on some keyboards. | |
9696 | ||
9697 | ‘history-search-forward ()’ | |
9698 | Search forward through the history for the string of characters | |
9699 | between the start of the current line and the point. The search | |
9700 | string must match at the beginning of a history line. This is a | |
9701 | non-incremental search. By default, this command is unbound, but | |
9702 | may be bound to the Page Up key on some keyboards. | |
9703 | ||
9704 | ‘history-substring-search-backward ()’ | |
9705 | Search backward through the history for the string of characters | |
9706 | between the start of the current line and the point. The search | |
9707 | string may match anywhere in a history line. This is a | |
9708 | non-incremental search. By default, this command is unbound. | |
9709 | ||
9710 | ‘history-substring-search-forward ()’ | |
9711 | Search forward through the history for the string of characters | |
9712 | between the start of the current line and the point. The search | |
9713 | string may match anywhere in a history line. This is a | |
9714 | non-incremental search. By default, this command is unbound. | |
9715 | ||
9716 | ‘yank-nth-arg (M-C-y)’ | |
9717 | Insert the first argument to the previous command (usually the | |
9718 | second word on the previous line) at point. With an argument N, | |
9719 | insert the Nth word from the previous command (the words in the | |
9720 | previous command begin with word 0). A negative argument inserts | |
9721 | the Nth word from the end of the previous command. Once the | |
9722 | argument N is computed, this uses the history expansion facilities | |
9723 | to extract the Nth word, as if the ‘!N’ history expansion had been | |
9724 | specified. | |
9725 | ||
9726 | ‘yank-last-arg (M-. or M-_)’ | |
9727 | Insert last argument to the previous command (the last word of the | |
9728 | previous history entry). With a numeric argument, behave exactly | |
9729 | like ‘yank-nth-arg’. Successive calls to ‘yank-last-arg’ move back | |
9730 | through the history list, inserting the last word (or the word | |
9731 | specified by the argument to the first call) of each line in turn. | |
9732 | Any numeric argument supplied to these successive calls determines | |
9733 | the direction to move through the history. A negative argument | |
9734 | switches the direction through the history (back or forward). This | |
9735 | uses the history expansion facilities to extract the last word, as | |
9736 | if the ‘!$’ history expansion had been specified. | |
9737 | ||
9738 | ‘operate-and-get-next (C-o)’ | |
9739 | Accept the current line for return to the calling application as if | |
9740 | a newline had been entered, and fetch the next line relative to the | |
9741 | current line from the history for editing. A numeric argument, if | |
9742 | supplied, specifies the history entry to use instead of the current | |
9743 | line. | |
9744 | ||
9745 | ‘fetch-history ()’ | |
9746 | With a numeric argument, fetch that entry from the history list and | |
9747 | make it the current line. Without an argument, move back to the | |
9748 | first entry in the history list. | |
9749 | ||
9750 | \1f | |
9751 | File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands | |
9752 | ||
9753 | 8.4.3 Commands For Changing Text | |
9754 | -------------------------------- | |
9755 | ||
9756 | ‘end-of-file (usually C-d)’ | |
9757 | The character indicating end-of-file as set, for example, by | |
9758 | ‘stty’. If this character is read when there are no characters on | |
9759 | the line, and point is at the beginning of the line, Readline | |
9760 | interprets it as the end of input and returns EOF. | |
9761 | ||
9762 | ‘delete-char (C-d)’ | |
9763 | Delete the character at point. If this function is bound to the | |
9764 | same character as the tty EOF character, as ‘C-d’ commonly is, see | |
9765 | above for the effects. This may also be bound to the Delete key on | |
9766 | some keyboards. | |
9767 | ||
9768 | ‘backward-delete-char (Rubout)’ | |
9769 | Delete the character behind the cursor. A numeric argument means | |
9770 | to kill the characters, saving them on the kill ring, instead of | |
9771 | deleting them. | |
9772 | ||
9773 | ‘forward-backward-delete-char ()’ | |
9774 | Delete the character under the cursor, unless the cursor is at the | |
9775 | end of the line, in which case the character behind the cursor is | |
9776 | deleted. By default, this is not bound to a key. | |
9777 | ||
9778 | ‘quoted-insert (C-q or C-v)’ | |
9779 | Add the next character typed to the line verbatim. This is how to | |
9780 | insert key sequences like ‘C-q’, for example. | |
9781 | ||
9782 | ‘self-insert (a, b, A, 1, !, ...)’ | |
9783 | Insert the character typed. | |
9784 | ||
9785 | ‘bracketed-paste-begin ()’ | |
9786 | This function is intended to be bound to the "bracketed paste" | |
9787 | escape sequence sent by some terminals, and such a binding is | |
9788 | assigned by default. It allows Readline to insert the pasted text | |
9789 | as a single unit without treating each character as if it had been | |
9790 | read from the keyboard. The characters are inserted as if each one | |
9791 | was bound to ‘self-insert’ instead of executing any editing | |
9792 | commands. | |
9793 | ||
9794 | Bracketed paste sets the region (the characters between point and | |
9795 | the mark) to the inserted text. It sets the _active region_. | |
9796 | ||
9797 | ‘transpose-chars (C-t)’ | |
9798 | Drag the character before the cursor forward over the character at | |
9799 | the cursor, moving the cursor forward as well. If the insertion | |
9800 | point is at the end of the line, then this transposes the last two | |
9801 | characters of the line. Negative arguments have no effect. | |
9802 | ||
9803 | ‘transpose-words (M-t)’ | |
9804 | Drag the word before point past the word after point, moving point | |
9805 | past that word as well. If the insertion point is at the end of | |
9806 | the line, this transposes the last two words on the line. | |
9807 | ||
9808 | ‘shell-transpose-words (M-C-t)’ | |
9809 | Drag the word before point past the word after point, moving point | |
9810 | past that word as well. If the insertion point is at the end of | |
9811 | the line, this transposes the last two words on the line. Word | |
9812 | boundaries are the same as ‘shell-forward-word’ and | |
9813 | ‘shell-backward-word’. | |
9814 | ||
9815 | ‘upcase-word (M-u)’ | |
9816 | Uppercase the current (or following) word. With a negative | |
9817 | argument, uppercase the previous word, but do not move the cursor. | |
9818 | ||
9819 | ‘downcase-word (M-l)’ | |
9820 | Lowercase the current (or following) word. With a negative | |
9821 | argument, lowercase the previous word, but do not move the cursor. | |
9822 | ||
9823 | ‘capitalize-word (M-c)’ | |
9824 | Capitalize the current (or following) word. With a negative | |
9825 | argument, capitalize the previous word, but do not move the cursor. | |
9826 | ||
9827 | ‘overwrite-mode ()’ | |
9828 | Toggle overwrite mode. With an explicit positive numeric argument, | |
9829 | switches to overwrite mode. With an explicit non-positive numeric | |
9830 | argument, switches to insert mode. This command affects only | |
9831 | ‘emacs’ mode; ‘vi’ mode does overwrite differently. Each call to | |
9832 | ‘readline()’ starts in insert mode. | |
9833 | ||
9834 | In overwrite mode, characters bound to ‘self-insert’ replace the | |
9835 | text at point rather than pushing the text to the right. | |
9836 | Characters bound to ‘backward-delete-char’ replace the character | |
9837 | before point with a space. | |
9838 | ||
9839 | By default, this command is unbound, but may be bound to the Insert | |
9840 | key on some keyboards. | |
9841 | ||
9842 | \1f | |
9843 | File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands | |
9844 | ||
9845 | 8.4.4 Killing And Yanking | |
9846 | ------------------------- | |
9847 | ||
9848 | ‘kill-line (C-k)’ | |
9849 | Kill the text from point to the end of the current line. With a | |
9850 | negative numeric argument, kill backward from the cursor to the | |
9851 | beginning of the line. | |
9852 | ||
9853 | ‘backward-kill-line (C-x Rubout)’ | |
9854 | Kill backward from the cursor to the beginning of the current line. | |
9855 | With a negative numeric argument, kill forward from the cursor to | |
9856 | the end of the line. | |
9857 | ||
9858 | ‘unix-line-discard (C-u)’ | |
9859 | Kill backward from the cursor to the beginning of the current line. | |
9860 | ||
9861 | ‘kill-whole-line ()’ | |
9862 | Kill all characters on the current line, no matter where point is. | |
9863 | By default, this is unbound. | |
9864 | ||
9865 | ‘kill-word (M-d)’ | |
9866 | Kill from point to the end of the current word, or if between | |
9867 | words, to the end of the next word. Word boundaries are the same | |
9868 | as ‘forward-word’. | |
9869 | ||
9870 | ‘backward-kill-word (M-<DEL>)’ | |
9871 | Kill the word behind point. Word boundaries are the same as | |
9872 | ‘backward-word’. | |
9873 | ||
9874 | ‘shell-kill-word (M-C-d)’ | |
9875 | Kill from point to the end of the current word, or if between | |
9876 | words, to the end of the next word. Word boundaries are the same | |
9877 | as ‘shell-forward-word’. | |
9878 | ||
9879 | ‘shell-backward-kill-word ()’ | |
9880 | Kill the word behind point. Word boundaries are the same as | |
9881 | ‘shell-backward-word’. | |
9882 | ||
9883 | ‘unix-word-rubout (C-w)’ | |
9884 | Kill the word behind point, using white space as a word boundary, | |
9885 | saving the killed text on the kill-ring. | |
9886 | ||
9887 | ‘unix-filename-rubout ()’ | |
9888 | Kill the word behind point, using white space and the slash | |
9889 | character as the word boundaries, saving the killed text on the | |
9890 | kill-ring. | |
9891 | ||
9892 | ‘delete-horizontal-space ()’ | |
9893 | Delete all spaces and tabs around point. By default, this is | |
9894 | unbound. | |
9895 | ||
9896 | ‘kill-region ()’ | |
9897 | Kill the text in the current region. By default, this command is | |
9898 | unbound. | |
9899 | ||
9900 | ‘copy-region-as-kill ()’ | |
9901 | Copy the text in the region to the kill buffer, so it can be yanked | |
9902 | right away. By default, this command is unbound. | |
9903 | ||
9904 | ‘copy-backward-word ()’ | |
9905 | Copy the word before point to the kill buffer. The word boundaries | |
9906 | are the same as ‘backward-word’. By default, this command is | |
9907 | unbound. | |
9908 | ||
9909 | ‘copy-forward-word ()’ | |
9910 | Copy the word following point to the kill buffer. The word | |
9911 | boundaries are the same as ‘forward-word’. By default, this | |
9912 | command is unbound. | |
9913 | ||
9914 | ‘yank (C-y)’ | |
9915 | Yank the top of the kill ring into the buffer at point. | |
9916 | ||
9917 | ‘yank-pop (M-y)’ | |
9918 | Rotate the kill-ring, and yank the new top. You can only do this | |
9919 | if the prior command is ‘yank’ or ‘yank-pop’. | |
9920 | ||
9921 | \1f | |
9922 | File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands | |
9923 | ||
9924 | 8.4.5 Specifying Numeric Arguments | |
9925 | ---------------------------------- | |
9926 | ||
9927 | ‘digit-argument (M-0, M-1, ... M--)’ | |
9928 | Add this digit to the argument already accumulating, or start a new | |
9929 | argument. ‘M--’ starts a negative argument. | |
9930 | ||
9931 | ‘universal-argument ()’ | |
9932 | This is another way to specify an argument. If this command is | |
9933 | followed by one or more digits, optionally with a leading minus | |
9934 | sign, those digits define the argument. If the command is followed | |
9935 | by digits, executing ‘universal-argument’ again ends the numeric | |
9936 | argument, but is otherwise ignored. As a special case, if this | |
9937 | command is immediately followed by a character that is neither a | |
9938 | digit nor minus sign, the argument count for the next command is | |
9939 | multiplied by four. The argument count is initially one, so | |
9940 | executing this function the first time makes the argument count | |
9941 | four, a second time makes the argument count sixteen, and so on. | |
9942 | By default, this is not bound to a key. | |
9943 | ||
9944 | \1f | |
9945 | File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands | |
9946 | ||
9947 | 8.4.6 Letting Readline Type For You | |
9948 | ----------------------------------- | |
9949 | ||
9950 | ‘complete (<TAB>)’ | |
9951 | Attempt to perform completion on the text before point. The actual | |
9952 | completion performed is application-specific. Bash attempts | |
9953 | completion by first checking for any programmable completions for | |
9954 | the command word (*note Programmable Completion::), otherwise | |
9955 | treating the text as a variable (if the text begins with ‘$’), | |
9956 | username (if the text begins with ‘~’), hostname (if the text | |
9957 | begins with ‘@’), or command (including aliases, functions, and | |
9958 | builtins) in turn. If none of these produces a match, it falls | |
9959 | back to filename completion. | |
9960 | ||
9961 | ‘possible-completions (M-?)’ | |
9962 | List the possible completions of the text before point. When | |
9963 | displaying completions, Readline sets the number of columns used | |
9964 | for display to the value of ‘completion-display-width’, the value | |
9965 | of the environment variable ‘COLUMNS’, or the screen width, in that | |
9966 | order. | |
9967 | ||
9968 | ‘insert-completions (M-*)’ | |
9969 | Insert all completions of the text before point that would have | |
9970 | been generated by ‘possible-completions’, separated by a space. | |
9971 | ||
9972 | ‘menu-complete ()’ | |
9973 | Similar to ‘complete’, but replaces the word to be completed with a | |
9974 | single match from the list of possible completions. Repeatedly | |
9975 | executing ‘menu-complete’ steps through the list of possible | |
9976 | completions, inserting each match in turn. At the end of the list | |
9977 | of completions, ‘menu-complete’ rings the bell (subject to the | |
9978 | setting of ‘bell-style’) and restores the original text. An | |
9979 | argument of N moves N positions forward in the list of matches; a | |
9980 | negative argument moves backward through the list. This command is | |
9981 | intended to be bound to <TAB>, but is unbound by default. | |
9982 | ||
9983 | ‘menu-complete-backward ()’ | |
9984 | Identical to ‘menu-complete’, but moves backward through the list | |
9985 | of possible completions, as if ‘menu-complete’ had been given a | |
9986 | negative argument. This command is unbound by default. | |
9987 | ||
9988 | ‘export-completions ()’ | |
9989 | Perform completion on the word before point as described above and | |
9990 | write the list of possible completions to Readline's output stream | |
9991 | using the following format, writing information on separate lines: | |
9992 | ||
9993 | • the number of matches N; | |
9994 | • the word being completed; | |
9995 | • S:E, where S and E are the start and end offsets of the word | |
9996 | in the Readline line buffer; then | |
9997 | • each match, one per line | |
9998 | ||
9999 | If there are no matches, the first line will be "0", and this | |
10000 | command does not print any output after the S:E. If there is only | |
10001 | a single match, this prints a single line containing it. If there | |
10002 | is more than one match, this prints the common prefix of the | |
10003 | matches, which may be empty, on the first line after the S:E, then | |
10004 | the matches on subsequent lines. In this case, N will include the | |
10005 | first line with the common prefix. | |
10006 | ||
10007 | The user or application should be able to accommodate the | |
10008 | possibility of a blank line. The intent is that the user or | |
10009 | application reads N lines after the line containing S:E to obtain | |
10010 | the match list. This command is unbound by default. | |
10011 | ||
10012 | ‘delete-char-or-list ()’ | |
10013 | Deletes the character under the cursor if not at the beginning or | |
10014 | end of the line (like ‘delete-char’). At the end of the line, it | |
10015 | behaves identically to ‘possible-completions’. This command is | |
10016 | unbound by default. | |
10017 | ||
10018 | ‘complete-filename (M-/)’ | |
10019 | Attempt filename completion on the text before point. | |
10020 | ||
10021 | ‘possible-filename-completions (C-x /)’ | |
10022 | List the possible completions of the text before point, treating it | |
10023 | as a filename. | |
10024 | ||
10025 | ‘complete-username (M-~)’ | |
10026 | Attempt completion on the text before point, treating it as a | |
10027 | username. | |
10028 | ||
10029 | ‘possible-username-completions (C-x ~)’ | |
10030 | List the possible completions of the text before point, treating it | |
10031 | as a username. | |
10032 | ||
10033 | ‘complete-variable (M-$)’ | |
10034 | Attempt completion on the text before point, treating it as a shell | |
10035 | variable. | |
10036 | ||
10037 | ‘possible-variable-completions (C-x $)’ | |
10038 | List the possible completions of the text before point, treating it | |
10039 | as a shell variable. | |
10040 | ||
10041 | ‘complete-hostname (M-@)’ | |
10042 | Attempt completion on the text before point, treating it as a | |
10043 | hostname. | |
10044 | ||
10045 | ‘possible-hostname-completions (C-x @)’ | |
10046 | List the possible completions of the text before point, treating it | |
10047 | as a hostname. | |
10048 | ||
10049 | ‘complete-command (M-!)’ | |
10050 | Attempt completion on the text before point, treating it as a | |
10051 | command name. Command completion attempts to match the text | |
10052 | against aliases, reserved words, shell functions, shell builtins, | |
10053 | and finally executable filenames, in that order. | |
10054 | ||
10055 | ‘possible-command-completions (C-x !)’ | |
10056 | List the possible completions of the text before point, treating it | |
10057 | as a command name. | |
10058 | ||
10059 | ‘dynamic-complete-history (M-<TAB>)’ | |
10060 | Attempt completion on the text before point, comparing the text | |
10061 | against history list entries for possible completion matches. | |
10062 | ||
10063 | ‘dabbrev-expand ()’ | |
10064 | Attempt menu completion on the text before point, comparing the | |
10065 | text against lines from the history list for possible completion | |
10066 | matches. | |
10067 | ||
10068 | ‘complete-into-braces (M-{)’ | |
10069 | Perform filename completion and insert the list of possible | |
10070 | completions enclosed within braces so the list is available to the | |
10071 | shell (*note Brace Expansion::). | |
10072 | ||
10073 | \1f | |
10074 | File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands | |
10075 | ||
10076 | 8.4.7 Keyboard Macros | |
10077 | --------------------- | |
10078 | ||
10079 | ‘start-kbd-macro (C-x ()’ | |
10080 | Begin saving the characters typed into the current keyboard macro. | |
10081 | ||
10082 | ‘end-kbd-macro (C-x ))’ | |
10083 | Stop saving the characters typed into the current keyboard macro | |
10084 | and save the definition. | |
10085 | ||
10086 | ‘call-last-kbd-macro (C-x e)’ | |
10087 | Re-execute the last keyboard macro defined, by making the | |
10088 | characters in the macro appear as if typed at the keyboard. | |
10089 | ||
10090 | ‘print-last-kbd-macro ()’ | |
10091 | Print the last keyboard macro defined in a format suitable for the | |
10092 | INPUTRC file. | |
10093 | ||
10094 | \1f | |
10095 | File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands | |
10096 | ||
10097 | 8.4.8 Some Miscellaneous Commands | |
10098 | --------------------------------- | |
10099 | ||
10100 | ‘re-read-init-file (C-x C-r)’ | |
10101 | Read in the contents of the INPUTRC file, and incorporate any | |
10102 | bindings or variable assignments found there. | |
10103 | ||
10104 | ‘abort (C-g)’ | |
10105 | Abort the current editing command and ring the terminal's bell | |
10106 | (subject to the setting of ‘bell-style’). | |
10107 | ||
10108 | ‘do-lowercase-version (M-A, M-B, M-X, ...)’ | |
10109 | If the metafied character X is upper case, run the command that is | |
10110 | bound to the corresponding metafied lower case character. The | |
10111 | behavior is undefined if X is already lower case. | |
10112 | ||
10113 | ‘prefix-meta (<ESC>)’ | |
10114 | Metafy the next character typed. Typing ‘<ESC> f’ is equivalent to | |
10115 | typing ‘M-f’. | |
10116 | ||
10117 | ‘undo (C-_ or C-x C-u)’ | |
10118 | Incremental undo, separately remembered for each line. | |
10119 | ||
10120 | ‘revert-line (M-r)’ | |
10121 | Undo all changes made to this line. This is like executing the | |
10122 | ‘undo’ command enough times to get back to the initial state. | |
10123 | ||
10124 | ‘tilde-expand (M-&)’ | |
10125 | Perform tilde expansion on the current word. | |
10126 | ||
10127 | ‘set-mark (C-@)’ | |
10128 | Set the mark to the point. If a numeric argument is supplied, set | |
10129 | the mark to that position. | |
10130 | ||
10131 | ‘exchange-point-and-mark (C-x C-x)’ | |
10132 | Swap the point with the mark. Set the current cursor position to | |
10133 | the saved position, then set the mark to the old cursor position. | |
10134 | ||
10135 | ‘character-search (C-])’ | |
10136 | Read a character and move point to the next occurrence of that | |
10137 | character. A negative argument searches for previous occurrences. | |
10138 | ||
10139 | ‘character-search-backward (M-C-])’ | |
10140 | Read a character and move point to the previous occurrence of that | |
10141 | character. A negative argument searches for subsequent | |
10142 | occurrences. | |
10143 | ||
10144 | ‘skip-csi-sequence ()’ | |
10145 | Read enough characters to consume a multi-key sequence such as | |
10146 | those defined for keys like Home and End. CSI sequences begin with | |
10147 | a Control Sequence Indicator (CSI), usually ‘ESC [’. If this | |
10148 | sequence is bound to "\e[", keys producing CSI sequences have no | |
10149 | effect unless explicitly bound to a Readline command, instead of | |
10150 | inserting stray characters into the editing buffer. This is | |
10151 | unbound by default, but usually bound to ‘ESC [’. | |
10152 | ||
10153 | ‘insert-comment (M-#)’ | |
10154 | Without a numeric argument, insert the value of the ‘comment-begin’ | |
10155 | variable at the beginning of the current line. If a numeric | |
10156 | argument is supplied, this command acts as a toggle: if the | |
10157 | characters at the beginning of the line do not match the value of | |
10158 | ‘comment-begin’, insert the value; otherwise delete the characters | |
10159 | in ‘comment-begin’ from the beginning of the line. In either case, | |
10160 | the line is accepted as if a newline had been typed. The default | |
10161 | value of ‘comment-begin’ causes this command to make the current | |
10162 | line a shell comment. If a numeric argument causes the comment | |
10163 | character to be removed, the line will be executed by the shell. | |
10164 | ||
10165 | ‘dump-functions ()’ | |
10166 | Print all of the functions and their key bindings to the Readline | |
10167 | output stream. If a numeric argument is supplied, the output is | |
10168 | formatted in such a way that it can be made part of an INPUTRC | |
10169 | file. This command is unbound by default. | |
10170 | ||
10171 | ‘dump-variables ()’ | |
10172 | Print all of the settable variables and their values to the | |
10173 | Readline output stream. If a numeric argument is supplied, the | |
10174 | output is formatted in such a way that it can be made part of an | |
10175 | INPUTRC file. This command is unbound by default. | |
10176 | ||
10177 | ‘dump-macros ()’ | |
10178 | Print all of the Readline key sequences bound to macros and the | |
10179 | strings they output to the Readline output stream. If a numeric | |
10180 | argument is supplied, the output is formatted in such a way that it | |
10181 | can be made part of an INPUTRC file. This command is unbound by | |
10182 | default. | |
10183 | ||
10184 | ‘execute-named-command (M-x)’ | |
10185 | Read a bindable Readline command name from the input and execute | |
10186 | the function to which it's bound, as if the key sequence to which | |
10187 | it was bound appeared in the input. If this function is supplied | |
10188 | with a numeric argument, it passes that argument to the function it | |
10189 | executes. | |
10190 | ||
10191 | ‘spell-correct-word (C-x s)’ | |
10192 | Perform spelling correction on the current word, treating it as a | |
10193 | directory or filename, in the same way as the ‘cdspell’ shell | |
10194 | option. Word boundaries are the same as those used by | |
10195 | ‘shell-forward-word’. | |
10196 | ||
10197 | ‘glob-complete-word (M-g)’ | |
10198 | Treat the word before point as a pattern for pathname expansion, | |
10199 | with an asterisk implicitly appended, then use the pattern to | |
10200 | generate a list of matching file names for possible completions. | |
10201 | ||
10202 | ‘glob-expand-word (C-x *)’ | |
10203 | Treat the word before point as a pattern for pathname expansion, | |
10204 | and insert the list of matching file names, replacing the word. If | |
10205 | a numeric argument is supplied, append a ‘*’ before pathname | |
10206 | expansion. | |
10207 | ||
10208 | ‘glob-list-expansions (C-x g)’ | |
10209 | Display the list of expansions that would have been generated by | |
10210 | ‘glob-expand-word’, and redisplay the line. If a numeric argument | |
10211 | is supplied, append a ‘*’ before pathname expansion. | |
10212 | ||
10213 | ‘shell-expand-line (M-C-e)’ | |
10214 | Expand the line by performing shell word expansions. This performs | |
10215 | alias and history expansion, $'STRING' and $"STRING" quoting, tilde | |
10216 | expansion, parameter and variable expansion, arithmetic expansion, | |
10217 | command and process substitution, word splitting, and quote | |
10218 | removal. An explicit argument suppresses command and process | |
10219 | substitution. | |
10220 | ||
10221 | ‘history-expand-line (M-^)’ | |
10222 | Perform history expansion on the current line. | |
10223 | ||
10224 | ‘magic-space ()’ | |
10225 | Perform history expansion on the current line and insert a space | |
10226 | (*note History Interaction::). | |
10227 | ||
10228 | ‘alias-expand-line ()’ | |
10229 | Perform alias expansion on the current line (*note Aliases::). | |
10230 | ||
10231 | ‘history-and-alias-expand-line ()’ | |
10232 | Perform history and alias expansion on the current line. | |
10233 | ||
10234 | ‘insert-last-argument (M-. or M-_)’ | |
10235 | A synonym for ‘yank-last-arg’. | |
10236 | ||
10237 | ‘edit-and-execute-command (C-x C-e)’ | |
10238 | Invoke an editor on the current command line, and execute the | |
10239 | result as shell commands. Bash attempts to invoke ‘$VISUAL’, | |
10240 | ‘$EDITOR’, and ‘emacs’ as the editor, in that order. | |
10241 | ||
10242 | ‘display-shell-version (C-x C-v)’ | |
10243 | Display version information about the current instance of Bash. | |
10244 | ||
10245 | \1f | |
10246 | File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing | |
10247 | ||
10248 | 8.5 Readline vi Mode | |
10249 | ==================== | |
10250 | ||
10251 | While the Readline library does not have a full set of ‘vi’ editing | |
10252 | functions, it does contain enough to allow simple editing of the line. | |
10253 | The Readline ‘vi’ mode behaves as specified in the ‘sh’ description in | |
10254 | the POSIX standard. | |
10255 | ||
10256 | You can use the ‘set -o emacs’ and ‘set -o vi’ commands (*note The | |
10257 | Set Builtin::) to switch interactively between ‘emacs’ and ‘vi’ editing | |
10258 | modes, The Readline default is ‘emacs’ mode. | |
10259 | ||
10260 | When you enter a line in ‘vi’ mode, you are already placed in | |
10261 | 'insertion' mode, as if you had typed an ‘i’. Pressing <ESC> switches | |
10262 | you into 'command' mode, where you can edit the text of the line with | |
10263 | the standard ‘vi’ movement keys, move to previous history lines with ‘k’ | |
10264 | and subsequent lines with ‘j’, and so forth. | |
10265 | ||
10266 | \1f | |
10267 | File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing | |
10268 | ||
10269 | 8.6 Programmable Completion | |
10270 | =========================== | |
10271 | ||
10272 | When the user attempts word completion for a command or an argument to a | |
10273 | command for which a completion specification (a “compspec”) has been | |
10274 | defined using the ‘complete’ builtin (*note Programmable Completion | |
10275 | Builtins::), Readline invokes the programmable completion facilities. | |
10276 | ||
10277 | First, Bash identifies the command name. If a compspec has been | |
10278 | defined for that command, the compspec is used to generate the list of | |
10279 | possible completions for the word. If the command word is the empty | |
10280 | string (completion attempted at the beginning of an empty line), Bash | |
10281 | uses any compspec defined with the ‘-E’ option to ‘complete’. The ‘-I’ | |
10282 | option to ‘complete’ indicates that the command word is the first | |
10283 | non-assignment word on the line, or after a command delimiter such as | |
10284 | ‘;’ or ‘|’. This usually indicates command name completion. | |
10285 | ||
10286 | If the command word is a full pathname, Bash searches for a compspec | |
10287 | for the full pathname first. If there is no compspec for the full | |
10288 | pathname, Bash attempts to find a compspec for the portion following the | |
10289 | final slash. If those searches do not result in a compspec, or if there | |
10290 | is no compspec for the command word, Bash uses any compspec defined with | |
10291 | the ‘-D’ option to ‘complete’ as the default. If there is no default | |
10292 | compspec, Bash performs alias expansion on the command word as a final | |
10293 | resort, and attempts to find a compspec for the command word resulting | |
10294 | from any successful expansion. | |
10295 | ||
10296 | If a compspec is not found, Bash performs its default completion | |
10297 | described above (*note Commands For Completion::). Otherwise, once a | |
10298 | compspec has been found, Bash uses it to generate the list of matching | |
10299 | words. | |
10300 | ||
10301 | First, Bash performs the ACTIONS specified by the compspec. This | |
10302 | only returns matches which are prefixes of the word being completed. | |
10303 | When the ‘-f’ or ‘-d’ option is used for filename or directory name | |
10304 | completion, Bash uses shell the variable ‘FIGNORE’ to filter the | |
10305 | matches. *Note Bash Variables::, for a description of ‘FIGNORE’. | |
10306 | ||
10307 | Next, programmable completion generates matches specified by a | |
10308 | pathname expansion pattern supplied as an argument to the ‘-G’ option. | |
10309 | The words generated by the pattern need not match the word being | |
10310 | completed. Bash uses the ‘FIGNORE’ variable to filter the matches, but | |
10311 | does not use the ‘GLOBIGNORE’ shell variable. | |
10312 | ||
10313 | Next, completion considers the string specified as the argument to | |
10314 | the ‘-W’ option. The string is first split using the characters in the | |
10315 | ‘IFS’ special variable as delimiters. This honors shell quoting within | |
10316 | the string, in order to provide a mechanism for the words to contain | |
10317 | shell metacharacters or characters in the value of ‘IFS’. Each word is | |
10318 | then expanded using brace expansion, tilde expansion, parameter and | |
10319 | variable expansion, command substitution, and arithmetic expansion, as | |
10320 | described above (*note Shell Expansions::). The results are split using | |
10321 | the rules described above (*note Word Splitting::). The results of the | |
10322 | expansion are prefix-matched against the word being completed, and the | |
10323 | matching words become possible completions. | |
10324 | ||
10325 | After these matches have been generated, Bash executes any shell | |
10326 | function or command specified with the ‘-F’ and ‘-C’ options. When the | |
10327 | command or function is invoked, Bash assigns values to the ‘COMP_LINE’, | |
10328 | ‘COMP_POINT’, ‘COMP_KEY’, and ‘COMP_TYPE’ variables as described above | |
10329 | (*note Bash Variables::). If a shell function is being invoked, Bash | |
10330 | also sets the ‘COMP_WORDS’ and ‘COMP_CWORD’ variables. When the | |
10331 | function or command is invoked, the first argument ($1) is the name of | |
10332 | the command whose arguments are being completed, the second argument | |
10333 | ($2) is the word being completed, and the third argument ($3) is the | |
10334 | word preceding the word being completed on the current command line. | |
10335 | There is no filtering of the generated completions against the word | |
10336 | being completed; the function or command has complete freedom in | |
10337 | generating the matches and they do not need to match a prefix of the | |
10338 | word. | |
10339 | ||
10340 | Any function specified with ‘-F’ is invoked first. The function may | |
10341 | use any of the shell facilities, including the ‘compgen’ and ‘compopt’ | |
10342 | builtins described below (*note Programmable Completion Builtins::), to | |
10343 | generate the matches. It must put the possible completions in the | |
10344 | ‘COMPREPLY’ array variable, one per array element. | |
10345 | ||
10346 | Next, any command specified with the ‘-C’ option is invoked in an | |
10347 | environment equivalent to command substitution. It should print a list | |
10348 | of completions, one per line, to the standard output. Backslash will | |
10349 | escape a newline, if necessary. These are added to the set of possible | |
10350 | completions. | |
10351 | ||
10352 | After generating all of the possible completions, Bash applies any | |
10353 | filter specified with the ‘-X’ option to the completions in the list. | |
10354 | The filter is a pattern as used for pathname expansion; a ‘&’ in the | |
10355 | pattern is replaced with the text of the word being completed. A | |
10356 | literal ‘&’ may be escaped with a backslash; the backslash is removed | |
10357 | before attempting a match. Any completion that matches the pattern is | |
10358 | removed from the list. A leading ‘!’ negates the pattern; in this case | |
10359 | Bash removes any completion that does not match the pattern. If the | |
10360 | ‘nocasematch’ shell option is enabled (see the description of ‘shopt’ in | |
10361 | *note The Shopt Builtin::), Bash performs the match without regard to | |
10362 | the case of alphabetic characters. | |
10363 | ||
10364 | Finally, programmable completion adds any prefix and suffix specified | |
10365 | with the ‘-P’ and ‘-S’ options, respectively, to each completion, and | |
10366 | returns the result to Readline as the list of possible completions. | |
10367 | ||
10368 | If the previously-applied actions do not generate any matches, and | |
10369 | the ‘-o dirnames’ option was supplied to ‘complete’ when the compspec | |
10370 | was defined, Bash attempts directory name completion. | |
10371 | ||
10372 | If the ‘-o plusdirs’ option was supplied to ‘complete’ when the | |
10373 | compspec was defined, Bash attempts directory name completion and adds | |
10374 | any matches to the set of possible completions. | |
10375 | ||
10376 | By default, if a compspec is found, whatever it generates is returned | |
10377 | to the completion code as the full set of possible completions. The | |
10378 | default Bash completions and the Readline default of filename completion | |
10379 | are disabled. If the ‘-o bashdefault’ option was supplied to ‘complete’ | |
10380 | when the compspec was defined, and the compspec generates no matches, | |
10381 | Bash attempts its default completions. If the compspec and, if | |
10382 | attempted, the default Bash completions generate no matches, and the ‘-o | |
10383 | default’ option was supplied to ‘complete’ when the compspec was | |
10384 | defined, programmable completion performs Readline's default completion. | |
10385 | ||
10386 | The options supplied to ‘complete’ and ‘compopt’ can control how | |
10387 | Readline treats the completions. For instance, the ‘-o fullquote’ | |
10388 | option tells Readline to quote the matches as if they were filenames. | |
10389 | See the description of ‘complete’ (*note Programmable Completion | |
10390 | Builtins::) for details. | |
10391 | ||
10392 | When a compspec indicates that it wants directory name completion, | |
10393 | the programmable completion functions force Readline to append a slash | |
10394 | to completed names which are symbolic links to directories, subject to | |
10395 | the value of the MARK-DIRECTORIES Readline variable, regardless of the | |
10396 | setting of the MARK-SYMLINKED-DIRECTORIES Readline variable. | |
10397 | ||
10398 | There is some support for dynamically modifying completions. This is | |
10399 | most useful when used in combination with a default completion specified | |
10400 | with ‘-D’. It's possible for shell functions executed as completion | |
10401 | functions to indicate that completion should be retried by returning an | |
10402 | exit status of 124. If a shell function returns 124, and changes the | |
10403 | compspec associated with the command on which completion is being | |
10404 | attempted (supplied as the first argument when the function is | |
10405 | executed), programmable completion restarts from the beginning, with an | |
10406 | attempt to find a new compspec for that command. This can be used to | |
10407 | build a set of completions dynamically as completion is attempted, | |
10408 | rather than loading them all at once. | |
10409 | ||
10410 | For instance, assuming that there is a library of compspecs, each | |
10411 | kept in a file corresponding to the name of the command, the following | |
10412 | default completion function would load completions dynamically: | |
10413 | ||
10414 | _completion_loader() | |
10415 | { | |
10416 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 | |
10417 | } | |
10418 | complete -D -F _completion_loader -o bashdefault -o default | |
10419 | ||
10420 | \1f | |
10421 | File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing | |
10422 | ||
10423 | 8.7 Programmable Completion Builtins | |
10424 | ==================================== | |
10425 | ||
10426 | Three builtin commands are available to manipulate the programmable | |
10427 | completion facilities: one to specify how the arguments to a particular | |
10428 | command are to be completed, and two to modify the completion as it is | |
10429 | happening. | |
10430 | ||
10431 | ‘compgen’ | |
10432 | compgen [-V VARNAME] [OPTION] [WORD] | |
10433 | ||
10434 | Generate possible completion matches for WORD according to the | |
10435 | OPTIONs, which may be any option accepted by the ‘complete’ builtin | |
10436 | with the exceptions of ‘-p’, ‘-r’, ‘-D’, ‘-E’, and ‘-I’, and write | |
10437 | the matches to the standard output. | |
10438 | ||
10439 | If the ‘-V’ option is supplied, ‘compgen’ stores the generated | |
10440 | completions into the indexed array variable VARNAME instead of | |
10441 | writing them to the standard output. | |
10442 | ||
10443 | When using the ‘-F’ or ‘-C’ options, the various shell variables | |
10444 | set by the programmable completion facilities, while available, | |
10445 | will not have useful values. | |
10446 | ||
10447 | The matches will be generated in the same way as if the | |
10448 | programmable completion code had generated them directly from a | |
10449 | completion specification with the same flags. If WORD is | |
10450 | specified, only those completions matching WORD will be displayed | |
10451 | or stored. | |
10452 | ||
10453 | The return value is true unless an invalid option is supplied, or | |
10454 | no matches were generated. | |
10455 | ||
10456 | ‘complete’ | |
10457 | complete [-abcdefgjksuv] [-o COMP-OPTION] [-DEI] [-A ACTION] | |
10458 | [-G GLOBPAT] [-W WORDLIST] [-F FUNCTION] [-C COMMAND] | |
10459 | [-X FILTERPAT] [-P PREFIX] [-S SUFFIX] NAME [NAME ...] | |
10460 | complete -pr [-DEI] [NAME ...] | |
10461 | ||
10462 | Specify how arguments to each NAME should be completed. | |
10463 | ||
10464 | If the ‘-p’ option is supplied, or if no options or NAMEs are | |
10465 | supplied, print existing completion specifications in a way that | |
10466 | allows them to be reused as input. The ‘-r’ option removes a | |
10467 | completion specification for each NAME, or, if no NAMEs are | |
10468 | supplied, all completion specifications. | |
10469 | ||
10470 | The ‘-D’ option indicates that other supplied options and actions | |
10471 | should apply to the "default" command completion; that is, | |
10472 | completion attempted on a command for which no completion has | |
10473 | previously been defined. The ‘-E’ option indicates that other | |
10474 | supplied options and actions should apply to "empty" command | |
10475 | completion; that is, completion attempted on a blank line. The | |
10476 | ‘-I’ option indicates that other supplied options and actions | |
10477 | should apply to completion on the initial non-assignment word on | |
10478 | the line, or after a command delimiter such as ‘;’ or ‘|’, which is | |
10479 | usually command name completion. If multiple options are supplied, | |
10480 | the ‘-D’ option takes precedence over ‘-E’, and both take | |
10481 | precedence over ‘-I’. If any of ‘-D’, ‘-E’, or ‘-I’ are supplied, | |
10482 | any other NAME arguments are ignored; these completions only apply | |
10483 | to the case specified by the option. | |
10484 | ||
10485 | The process of applying these completion specifications when word | |
10486 | completion is attempted is described above (*note Programmable | |
10487 | Completion::). | |
10488 | ||
10489 | Other options, if specified, have the following meanings. The | |
10490 | arguments to the ‘-G’, ‘-W’, and ‘-X’ options (and, if necessary, | |
10491 | the ‘-P’ and ‘-S’ options) should be quoted to protect them from | |
10492 | expansion before the ‘complete’ builtin is invoked. | |
10493 | ||
10494 | ‘-o COMP-OPTION’ | |
10495 | The COMP-OPTION controls several aspects of the compspec's | |
10496 | behavior beyond the simple generation of completions. | |
10497 | COMP-OPTION may be one of: | |
10498 | ||
10499 | ‘bashdefault’ | |
10500 | Perform the rest of the default Bash completions if the | |
10501 | compspec generates no matches. | |
10502 | ||
10503 | ‘default’ | |
10504 | Use Readline's default filename completion if the | |
10505 | compspec generates no matches. | |
10506 | ||
10507 | ‘dirnames’ | |
10508 | Perform directory name completion if the compspec | |
10509 | generates no matches. | |
10510 | ||
10511 | ‘filenames’ | |
10512 | Tell Readline that the compspec generates filenames, so | |
10513 | it can perform any filename-specific processing (such as | |
10514 | adding a slash to directory names, quoting special | |
10515 | characters, or suppressing trailing spaces). This option | |
10516 | is intended to be used with shell functions specified | |
10517 | with ‘-F’. | |
10518 | ||
10519 | ‘fullquote’ | |
10520 | Tell Readline to quote all the completed words even if | |
10521 | they are not filenames. | |
10522 | ||
10523 | ‘noquote’ | |
10524 | Tell Readline not to quote the completed words if they | |
10525 | are filenames (quoting filenames is the default). | |
10526 | ||
10527 | ‘nosort’ | |
10528 | Tell Readline not to sort the list of possible | |
10529 | completions alphabetically. | |
10530 | ||
10531 | ‘nospace’ | |
10532 | Tell Readline not to append a space (the default) to | |
10533 | words completed at the end of the line. | |
10534 | ||
10535 | ‘plusdirs’ | |
10536 | After generating any matches defined by the compspec, | |
10537 | attempt directory name completion and add any matches to | |
10538 | the results of the other actions. | |
10539 | ||
10540 | ‘-A ACTION’ | |
10541 | The ACTION may be one of the following to generate a list of | |
10542 | possible completions: | |
10543 | ||
10544 | ‘alias’ | |
10545 | Alias names. May also be specified as ‘-a’. | |
10546 | ||
10547 | ‘arrayvar’ | |
10548 | Array variable names. | |
10549 | ||
10550 | ‘binding’ | |
10551 | Readline key binding names (*note Bindable Readline | |
10552 | Commands::). | |
10553 | ||
10554 | ‘builtin’ | |
10555 | Names of shell builtin commands. May also be specified | |
10556 | as ‘-b’. | |
10557 | ||
10558 | ‘command’ | |
10559 | Command names. May also be specified as ‘-c’. | |
10560 | ||
10561 | ‘directory’ | |
10562 | Directory names. May also be specified as ‘-d’. | |
10563 | ||
10564 | ‘disabled’ | |
10565 | Names of disabled shell builtins. | |
10566 | ||
10567 | ‘enabled’ | |
10568 | Names of enabled shell builtins. | |
10569 | ||
10570 | ‘export’ | |
10571 | Names of exported shell variables. May also be specified | |
10572 | as ‘-e’. | |
10573 | ||
10574 | ‘file’ | |
10575 | File and directory names, similar to Readline's filename | |
10576 | completion. May also be specified as ‘-f’. | |
10577 | ||
10578 | ‘function’ | |
10579 | Names of shell functions. | |
10580 | ||
10581 | ‘group’ | |
10582 | Group names. May also be specified as ‘-g’. | |
10583 | ||
10584 | ‘helptopic’ | |
10585 | Help topics as accepted by the ‘help’ builtin (*note Bash | |
10586 | Builtins::). | |
10587 | ||
10588 | ‘hostname’ | |
10589 | Hostnames, as taken from the file specified by the | |
10590 | ‘HOSTFILE’ shell variable (*note Bash Variables::). | |
10591 | ||
10592 | ‘job’ | |
10593 | Job names, if job control is active. May also be | |
10594 | specified as ‘-j’. | |
10595 | ||
10596 | ‘keyword’ | |
10597 | Shell reserved words. May also be specified as ‘-k’. | |
10598 | ||
10599 | ‘running’ | |
10600 | Names of running jobs, if job control is active. | |
10601 | ||
10602 | ‘service’ | |
10603 | Service names. May also be specified as ‘-s’. | |
10604 | ||
10605 | ‘setopt’ | |
10606 | Valid arguments for the ‘-o’ option to the ‘set’ builtin | |
10607 | (*note The Set Builtin::). | |
10608 | ||
10609 | ‘shopt’ | |
10610 | Shell option names as accepted by the ‘shopt’ builtin | |
10611 | (*note Bash Builtins::). | |
10612 | ||
10613 | ‘signal’ | |
10614 | Signal names. | |
10615 | ||
10616 | ‘stopped’ | |
10617 | Names of stopped jobs, if job control is active. | |
10618 | ||
10619 | ‘user’ | |
10620 | User names. May also be specified as ‘-u’. | |
10621 | ||
10622 | ‘variable’ | |
10623 | Names of all shell variables. May also be specified as | |
10624 | ‘-v’. | |
10625 | ||
10626 | ‘-C COMMAND’ | |
10627 | COMMAND is executed in a subshell environment, and its output | |
10628 | is used as the possible completions. Arguments are passed as | |
10629 | with the ‘-F’ option. | |
10630 | ||
10631 | ‘-F FUNCTION’ | |
10632 | The shell function FUNCTION is executed in the current shell | |
10633 | environment. When it is executed, the first argument ($1) is | |
10634 | the name of the command whose arguments are being completed, | |
10635 | the second argument ($2) is the word being completed, and the | |
10636 | third argument ($3) is the word preceding the word being | |
10637 | completed, as described above (*note Programmable | |
10638 | Completion::). When ‘function’ finishes, programmable | |
10639 | completion retrieves the possible completions from the value | |
10640 | of the ‘COMPREPLY’ array variable. | |
10641 | ||
10642 | ‘-G GLOBPAT’ | |
10643 | Expand the filename expansion pattern GLOBPAT to generate the | |
10644 | possible completions. | |
10645 | ||
10646 | ‘-P PREFIX’ | |
10647 | Add PREFIX to the beginning of each possible completion after | |
10648 | all other options have been applied. | |
10649 | ||
10650 | ‘-S SUFFIX’ | |
10651 | Append SUFFIX to each possible completion after all other | |
10652 | options have been applied. | |
10653 | ||
10654 | ‘-W WORDLIST’ | |
10655 | Split the WORDLIST using the characters in the ‘IFS’ special | |
10656 | variable as delimiters, and expand each resulting word. Shell | |
10657 | quoting is honored within WORDLIST in order to provide a | |
10658 | mechanism for the words to contain shell metacharacters or | |
10659 | characters in the value of ‘IFS’. The possible completions | |
10660 | are the members of the resultant list which match a prefix of | |
10661 | the word being completed. | |
10662 | ||
10663 | ‘-X FILTERPAT’ | |
10664 | FILTERPAT is a pattern as used for filename expansion. It is | |
10665 | applied to the list of possible completions generated by the | |
10666 | preceding options and arguments, and each completion matching | |
10667 | FILTERPAT is removed from the list. A leading ‘!’ in | |
10668 | FILTERPAT negates the pattern; in this case, any completion | |
10669 | not matching FILTERPAT is removed. | |
10670 | ||
10671 | The return value is true unless an invalid option is supplied, an | |
10672 | option other than ‘-p’, ‘-r’, ‘-D’, ‘-E’, or ‘-I’ is supplied | |
10673 | without a NAME argument, an attempt is made to remove a completion | |
10674 | specification for a NAME for which no specification exists, or an | |
10675 | error occurs adding a completion specification. | |
10676 | ||
10677 | ‘compopt’ | |
10678 | compopt [-o OPTION] [-DEI] [+o OPTION] [NAME] | |
10679 | Modify completion options for each NAME according to the OPTIONs, | |
10680 | or for the currently-executing completion if no NAMEs are supplied. | |
10681 | If no OPTIONs are given, display the completion options for each | |
10682 | NAME or the current completion. The possible values of OPTION are | |
10683 | those valid for the ‘complete’ builtin described above. | |
10684 | ||
10685 | The ‘-D’ option indicates that other supplied options should apply | |
10686 | to the "default" command completion; the ‘-E’ option indicates that | |
10687 | other supplied options should apply to "empty" command completion; | |
10688 | and the ‘-I’ option indicates that other supplied options should | |
10689 | apply to completion on the initial word on the line. These are | |
10690 | determined in the same way as the ‘complete’ builtin. | |
10691 | ||
10692 | If multiple options are supplied, the ‘-D’ option takes precedence | |
10693 | over ‘-E’, and both take precedence over ‘-I’ | |
10694 | ||
10695 | The return value is true unless an invalid option is supplied, an | |
10696 | attempt is made to modify the options for a NAME for which no | |
10697 | completion specification exists, or an output error occurs. | |
10698 | ||
10699 | \1f | |
10700 | File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing | |
10701 | ||
10702 | 8.8 A Programmable Completion Example | |
10703 | ===================================== | |
10704 | ||
10705 | The most common way to obtain additional completion functionality beyond | |
10706 | the default actions ‘complete’ and ‘compgen’ provide is to use a shell | |
10707 | function and bind it to a particular command using ‘complete -F’. | |
10708 | ||
10709 | The following function provides completions for the ‘cd’ builtin. It | |
10710 | is a reasonably good example of what shell functions must do when used | |
10711 | for completion. This function uses the word passed as ‘$2’ to determine | |
10712 | the directory name to complete. You can also use the ‘COMP_WORDS’ array | |
10713 | variable; the current word is indexed by the ‘COMP_CWORD’ variable. | |
10714 | ||
10715 | The function relies on the ‘complete’ and ‘compgen’ builtins to do | |
10716 | much of the work, adding only the things that the Bash ‘cd’ does beyond | |
10717 | accepting basic directory names: tilde expansion (*note Tilde | |
10718 | Expansion::), searching directories in $CDPATH, which is described above | |
10719 | (*note Bourne Shell Builtins::), and basic support for the ‘cdable_vars’ | |
10720 | shell option (*note The Shopt Builtin::). ‘_comp_cd’ modifies the value | |
10721 | of IFS so that it contains only a newline to accommodate file names | |
10722 | containing spaces and tabs - ‘compgen’ prints the possible completions | |
10723 | it generates one per line. | |
10724 | ||
10725 | Possible completions go into the COMPREPLY array variable, one | |
10726 | completion per array element. The programmable completion system | |
10727 | retrieves the completions from there when the function returns. | |
10728 | ||
10729 | # A completion function for the cd builtin | |
10730 | # based on the cd completion function from the bash_completion package | |
10731 | _comp_cd() | |
10732 | { | |
10733 | local IFS=$' \t\n' # normalize IFS | |
10734 | local cur _skipdot _cdpath | |
10735 | local i j k | |
10736 | ||
10737 | # Tilde expansion, which also expands tilde to full pathname | |
10738 | case "$2" in | |
10739 | \~*) eval cur="$2" ;; | |
10740 | *) cur=$2 ;; | |
10741 | esac | |
10742 | ||
10743 | # no cdpath or absolute pathname -- straight directory completion | |
10744 | if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then | |
10745 | # compgen prints paths one per line; could also use while loop | |
10746 | IFS=$'\n' | |
10747 | COMPREPLY=( $(compgen -d -- "$cur") ) | |
10748 | IFS=$' \t\n' | |
10749 | # CDPATH+directories in the current directory if not in CDPATH | |
10750 | else | |
10751 | IFS=$'\n' | |
10752 | _skipdot=false | |
10753 | # preprocess CDPATH to convert null directory names to . | |
10754 | _cdpath=${CDPATH/#:/.:} | |
10755 | _cdpath=${_cdpath//::/:.:} | |
10756 | _cdpath=${_cdpath/%:/:.} | |
10757 | for i in ${_cdpath//:/$'\n'}; do | |
10758 | if [[ $i -ef . ]]; then _skipdot=true; fi | |
10759 | k="${#COMPREPLY[@]}" | |
10760 | for j in $( compgen -d -- "$i/$cur" ); do | |
10761 | COMPREPLY[k++]=${j#$i/} # cut off directory | |
10762 | done | |
10763 | done | |
10764 | $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") ) | |
10765 | IFS=$' \t\n' | |
10766 | fi | |
10767 | ||
10768 | # variable names if appropriate shell option set and no completions | |
10769 | if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then | |
10770 | COMPREPLY=( $(compgen -v -- "$cur") ) | |
10771 | fi | |
10772 | ||
10773 | return 0 | |
10774 | } | |
10775 | ||
10776 | We install the completion function using the ‘-F’ option to | |
10777 | ‘complete’: | |
10778 | ||
10779 | # Tell readline to quote appropriate and append slashes to directories; | |
10780 | # use the bash default completion for other arguments | |
10781 | complete -o filenames -o nospace -o bashdefault -F _comp_cd cd | |
10782 | ||
10783 | Since we'd like Bash and Readline to take care of some of the other | |
10784 | details for us, we use several other options to tell Bash and Readline | |
10785 | what to do. The ‘-o filenames’ option tells Readline that the possible | |
10786 | completions should be treated as filenames, and quoted appropriately. | |
10787 | That option will also cause Readline to append a slash to filenames it | |
10788 | can determine are directories (which is why we might want to extend | |
10789 | ‘_comp_cd’ to append a slash if we're using directories found via | |
10790 | CDPATH: Readline can't tell those completions are directories). The ‘-o | |
10791 | nospace’ option tells Readline to not append a space character to the | |
10792 | directory name, in case we want to append to it. The ‘-o bashdefault’ | |
10793 | option brings in the rest of the "Bash default" completions - possible | |
10794 | completions that Bash adds to the default Readline set. These include | |
10795 | things like command name completion, variable completion for words | |
10796 | beginning with ‘$’ or ‘${’, completions containing pathname expansion | |
10797 | patterns (*note Filename Expansion::), and so on. | |
10798 | ||
10799 | Once installed using ‘complete’, ‘_comp_cd’ will be called every time | |
10800 | we attempt word completion for a ‘cd’ command. | |
10801 | ||
10802 | Many more examples - an extensive collection of completions for most | |
10803 | of the common GNU, Unix, and Linux commands - are available as part of | |
10804 | the bash_completion project. This is installed by default on many | |
10805 | GNU/Linux distributions. Originally written by Ian Macdonald, the | |
10806 | project now lives at <https://github.com/scop/bash-completion/>. There | |
10807 | are ports for other systems such as Solaris and Mac OS X. | |
10808 | ||
10809 | An older version of the bash_completion package is distributed with | |
10810 | bash in the ‘examples/complete’ subdirectory. | |
10811 | ||
10812 | \1f | |
10813 | File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top | |
10814 | ||
10815 | 9 Using History Interactively | |
10816 | ***************************** | |
10817 | ||
10818 | This chapter describes how to use the GNU History Library interactively, | |
10819 | from a user's standpoint. It should be considered a user's guide. For | |
10820 | information on using the GNU History Library in other programs, see the | |
10821 | GNU Readline Library Manual. | |
10822 | ||
10823 | * Menu: | |
10824 | ||
10825 | * Bash History Facilities:: How Bash lets you manipulate your command | |
10826 | history. | |
10827 | * Bash History Builtins:: The Bash builtin commands that manipulate | |
10828 | the command history. | |
10829 | * History Interaction:: What it feels like using History as a user. | |
10830 | ||
10831 | \1f | |
10832 | File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively | |
10833 | ||
10834 | 9.1 Bash History Facilities | |
10835 | =========================== | |
10836 | ||
10837 | When the ‘-o history’ option to the ‘set’ builtin is enabled (*note The | |
10838 | Set Builtin::), the shell provides access to the “command history”, the | |
10839 | list of commands previously typed. The value of the ‘HISTSIZE’ shell | |
10840 | variable is used as the number of commands to save in a history list: | |
10841 | the shell saves the text of the last ‘$HISTSIZE’ commands (default 500). | |
10842 | The shell stores each command in the history list prior to parameter and | |
10843 | variable expansion but after history expansion is performed, subject to | |
10844 | the values of the shell variables ‘HISTIGNORE’ and ‘HISTCONTROL’. | |
10845 | ||
10846 | When the shell starts up, Bash initializes the history list by | |
10847 | reading history entries from the file named by the ‘HISTFILE’ variable | |
10848 | (default ‘~/.bash_history’). This is referred to as the “history file”. | |
10849 | The history file is truncated, if necessary, to contain no more than the | |
10850 | number of history entries specified by the value of the ‘HISTFILESIZE’ | |
10851 | variable. If ‘HISTFILESIZE’ is unset, or set to null, a non-numeric | |
10852 | value, or a numeric value less than zero, the history file is not | |
10853 | truncated. | |
10854 | ||
10855 | When the history file is read, lines beginning with the history | |
10856 | comment character followed immediately by a digit are interpreted as | |
10857 | timestamps for the following history entry. These timestamps are | |
10858 | optionally displayed depending on the value of the ‘HISTTIMEFORMAT’ | |
10859 | variable (*note Bash Variables::). When present, history timestamps | |
10860 | delimit history entries, making multi-line entries possible. | |
10861 | ||
10862 | When a shell with history enabled exits, Bash copies the last | |
10863 | ‘$HISTSIZE’ entries from the history list to the file named by | |
10864 | ‘$HISTFILE’. If the ‘histappend’ shell option is set (*note Bash | |
10865 | Builtins::), Bash appends the entries to the history file, otherwise it | |
10866 | overwrites the history file. If ‘HISTFILE’ is unset or null, or if the | |
10867 | history file is unwritable, the history is not saved. After saving the | |
10868 | history, Bash truncates the history file to contain no more than | |
10869 | ‘$HISTFILESIZE’ lines as described above. | |
10870 | ||
10871 | If the ‘HISTTIMEFORMAT’ variable is set, the shell writes the | |
10872 | timestamp information associated with each history entry to the history | |
10873 | file, marked with the history comment character, so timestamps are | |
10874 | preserved across shell sessions. When the history file is read, lines | |
10875 | beginning with the history comment character followed immediately by a | |
10876 | digit are interpreted as timestamps for the following history entry. As | |
10877 | above, when using ‘HISTTIMEFORMAT’, the timestamps delimit multi-line | |
10878 | history entries. | |
10879 | ||
10880 | The ‘fc’ builtin command will list or edit and re-execute a portion | |
10881 | of the history list. The ‘history’ builtin can display or modify the | |
10882 | history list and manipulate the history file. When using command-line | |
10883 | editing, search commands are available in each editing mode that provide | |
10884 | access to the history list (*note Commands For History::). | |
10885 | ||
10886 | The shell allows control over which commands are saved on the history | |
10887 | list. The ‘HISTCONTROL’ and ‘HISTIGNORE’ variables are used to save | |
10888 | only a subset of the commands entered. If the ‘cmdhist’ shell option is | |
10889 | enabled, the shell attempts to save each line of a multi-line command in | |
10890 | the same history entry, adding semicolons where necessary to preserve | |
10891 | syntactic correctness. The ‘lithist’ shell option modifies ‘cmdhist’ by | |
10892 | saving the command with embedded newlines instead of semicolons. The | |
10893 | ‘shopt’ builtin is used to set these options. *Note The Shopt | |
10894 | Builtin::, for a description of ‘shopt’. | |
10895 | ||
10896 | \1f | |
10897 | File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively | |
10898 | ||
10899 | 9.2 Bash History Builtins | |
10900 | ========================= | |
10901 | ||
10902 | Bash provides two builtin commands which manipulate the history list and | |
10903 | history file. | |
10904 | ||
10905 | ‘fc’ | |
10906 | fc [-e ENAME] [-lnr] [FIRST] [LAST] | |
10907 | fc -s [PAT=REP] [COMMAND] | |
10908 | ||
10909 | The first form selects a range of commands from FIRST to LAST from | |
10910 | the history list and displays or edits and re-executes them. Both | |
10911 | FIRST and LAST may be specified as a string (to locate the most | |
10912 | recent command beginning with that string) or as a number (an index | |
10913 | into the history list, where a negative number is used as an offset | |
10914 | from the current command number). | |
10915 | ||
10916 | When listing, a FIRST or LAST of 0 is equivalent to -1 and -0 is | |
10917 | equivalent to the current command (usually the ‘fc’ command); | |
10918 | otherwise 0 is equivalent to -1 and -0 is invalid. | |
10919 | ||
10920 | If LAST is not specified, it is set to the current command for | |
10921 | listing and to FIRST otherwise. If FIRST is not specified, it is | |
10922 | set to the previous command for editing and −16 for listing. | |
10923 | ||
10924 | If the ‘-l’ flag is supplied, the commands are listed on standard | |
10925 | output. The ‘-n’ flag suppresses the command numbers when listing. | |
10926 | The ‘-r’ flag reverses the order of the listing. | |
10927 | ||
10928 | Otherwise, ‘fc’ invokes the editor named by ENAME on a file | |
10929 | containing those commands. If ENAME is not supplied, ‘fc’ uses the | |
10930 | value of the following variable expansion: | |
10931 | ‘${FCEDIT:-${EDITOR:-vi}}’. This says to use the value of the | |
10932 | ‘FCEDIT’ variable if set, or the value of the ‘EDITOR’ variable if | |
10933 | that is set, or ‘vi’ if neither is set. When editing is complete, | |
10934 | ‘fc’ reads the file of edited commands and echoes and executes | |
10935 | them. | |
10936 | ||
10937 | In the second form, ‘fc’ re-executes COMMAND after replacing each | |
10938 | instance of PAT in the selected command with REP. COMMAND is | |
10939 | interpreted the same as FIRST above. | |
10940 | ||
10941 | A useful alias to use with the ‘fc’ command is ‘r='fc -s'’, so that | |
10942 | typing ‘r cc’ runs the last command beginning with ‘cc’ and typing | |
10943 | ‘r’ re-executes the last command (*note Aliases::). | |
10944 | ||
10945 | If the first form is used, the return value is zero unless an | |
10946 | invalid option is encountered or FIRST or LAST specify history | |
10947 | lines out of range. When editing and re-executing a file of | |
10948 | commands, the return value is the value of the last command | |
10949 | executed or failure if an error occurs with the temporary file. If | |
10950 | the second form is used, the return status is that of the | |
10951 | re-executed command, unless COMMAND does not specify a valid | |
10952 | history entry, in which case ‘fc’ returns a non-zero status. | |
10953 | ||
10954 | ‘history’ | |
10955 | history [N] | |
10956 | history -c | |
10957 | history -d OFFSET | |
10958 | history -d START-END | |
10959 | history [-anrw] [FILENAME] | |
10960 | history -ps ARG | |
10961 | ||
10962 | With no options, display the history list with numbers. Entries | |
10963 | prefixed with a ‘*’ have been modified. An argument of N lists | |
10964 | only the last N entries. If the shell variable ‘HISTTIMEFORMAT’ is | |
10965 | set and not null, it is used as a format string for ‘strftime’(3) | |
10966 | to display the time stamp associated with each displayed history | |
10967 | entry. If ‘history’ uses ‘HISTTIMEFORMAT’, it does not print an | |
10968 | intervening space between the formatted time stamp and the history | |
10969 | entry. | |
10970 | ||
10971 | Options, if supplied, have the following meanings: | |
10972 | ||
10973 | ‘-c’ | |
10974 | Clear the history list. This may be combined with the other | |
10975 | options to replace the history list. | |
10976 | ||
10977 | ‘-d OFFSET’ | |
10978 | Delete the history entry at position OFFSET. If OFFSET is | |
10979 | positive, it should be specified as it appears when the | |
10980 | history is displayed. If OFFSET is negative, it is | |
10981 | interpreted as relative to one greater than the last history | |
10982 | position, so negative indices count back from the end of the | |
10983 | history, and an index of ‘-1’ refers to the current ‘history | |
10984 | -d’ command. | |
10985 | ||
10986 | ‘-d START-END’ | |
10987 | Delete the range of history entries between positions START | |
10988 | and END, inclusive. Positive and negative values for START | |
10989 | and END are interpreted as described above. | |
10990 | ||
10991 | ‘-a’ | |
10992 | Append the "new" history lines to the history file. These are | |
10993 | history lines entered since the beginning of the current Bash | |
10994 | session, but not already appended to the history file. | |
10995 | ||
10996 | ‘-n’ | |
10997 | Read the history lines not already read from the history file | |
10998 | and add them to the current history list. These are lines | |
10999 | appended to the history file since the beginning of the | |
11000 | current Bash session. | |
11001 | ||
11002 | ‘-r’ | |
11003 | Read the history file and append its contents to the history | |
11004 | list. | |
11005 | ||
11006 | ‘-w’ | |
11007 | Write the current history list to the history file, | |
11008 | overwriting the history file. | |
11009 | ||
11010 | ‘-p’ | |
11011 | Perform history substitution on the ARGs and display the | |
11012 | result on the standard output, without storing the results in | |
11013 | the history list. | |
11014 | ||
11015 | ‘-s’ | |
11016 | Add the ARGs to the end of the history list as a single entry. | |
11017 | The last command in the history list is removed before adding | |
11018 | the ARGs. | |
11019 | ||
11020 | If a FILENAME argument is supplied with any of the ‘-w’, ‘-r’, | |
11021 | ‘-a’, or ‘-n’ options, Bash uses FILENAME as the history file. If | |
11022 | not, it uses the value of the ‘HISTFILE’ variable. If ‘HISTFILE’ | |
11023 | is unset or null, these options have no effect. | |
11024 | ||
11025 | If the ‘HISTTIMEFORMAT’ variable is set, ‘history’ writes the time | |
11026 | stamp information associated with each history entry to the history | |
11027 | file, marked with the history comment character as described above. | |
11028 | When the history file is read, lines beginning with the history | |
11029 | comment character followed immediately by a digit are interpreted | |
11030 | as timestamps for the following history entry. | |
11031 | ||
11032 | The return value is 0 unless an invalid option is encountered, an | |
11033 | error occurs while reading or writing the history file, an invalid | |
11034 | OFFSET or range is supplied as an argument to ‘-d’, or the history | |
11035 | expansion supplied as an argument to ‘-p’ fails. | |
11036 | ||
11037 | \1f | |
11038 | File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively | |
11039 | ||
11040 | 9.3 History Expansion | |
11041 | ===================== | |
11042 | ||
11043 | The shell provides a history expansion feature that is similar to the | |
11044 | history expansion provided by ‘csh’ (also referred to as history | |
11045 | substitution where appropriate). This section describes the syntax used | |
11046 | to manipulate the history information. | |
11047 | ||
11048 | History expansion is enabled by default for interactive shells, and | |
11049 | can be disabled using the ‘+H’ option to the ‘set’ builtin command | |
11050 | (*note The Set Builtin::). Non-interactive shells do not perform | |
11051 | history expansion by default, but it can be enabled with ‘set -H’. | |
11052 | ||
11053 | History expansions introduce words from the history list into the | |
11054 | input stream, making it easy to repeat commands, insert the arguments to | |
11055 | a previous command into the current input line, or fix errors in | |
11056 | previous commands quickly. | |
11057 | ||
11058 | History expansion is performed immediately after a complete line is | |
11059 | read, before the shell breaks it into words, and is performed on each | |
11060 | line individually. Bash attempts to inform the history expansion | |
11061 | functions about quoting still in effect from previous lines. | |
11062 | ||
11063 | History expansion takes place in two parts. The first is to | |
11064 | determine which entry from the history list should be used during | |
11065 | substitution. The second is to select portions of that entry to include | |
11066 | into the current one. | |
11067 | ||
11068 | The entry selected from the history is called the “event”, and the | |
11069 | portions of that entry that are acted upon are “words”. Various | |
11070 | “modifiers” are available to manipulate the selected words. The entry | |
11071 | is split into words in the same fashion that Bash does when reading | |
11072 | input, so that several words surrounded by quotes are considered one | |
11073 | word. The “event designator” selects the event, the optional “word | |
11074 | designator” selects words from the event, and various optional | |
11075 | “modifiers” are available to manipulate the selected words. | |
11076 | ||
11077 | History expansions are introduced by the appearance of the history | |
11078 | expansion character, which is ‘!’ by default. History expansions may | |
11079 | appear anywhere in the input, but do not nest. | |
11080 | ||
11081 | History expansion implements shell-like quoting conventions: a | |
11082 | backslash can be used to remove the special handling for the next | |
11083 | character; single quotes enclose verbatim sequences of characters, and | |
11084 | can be used to inhibit history expansion; and characters enclosed within | |
11085 | double quotes may be subject to history expansion, since backslash can | |
11086 | escape the history expansion character, but single quotes may not, since | |
11087 | they are not treated specially within double quotes. | |
11088 | ||
11089 | When using the shell, only ‘\’ and ‘'’ may be used to escape the | |
11090 | history expansion character, but the history expansion character is also | |
11091 | treated as quoted if it immediately precedes the closing double quote in | |
11092 | a double-quoted string. | |
11093 | ||
11094 | Several characters inhibit history expansion if found immediately | |
11095 | following the history expansion character, even if it is unquoted: | |
11096 | space, tab, newline, carriage return, ‘=’, and the other shell | |
11097 | metacharacters. | |
11098 | ||
11099 | There is a special abbreviation for substitution, active when the | |
11100 | QUICK SUBSTITUTION character (described above under ‘histchars’) is the | |
11101 | first character on the line. It selects the previous history list | |
11102 | entry, using an event designator equivalent to ‘!!’, and substitutes one | |
11103 | string for another in that entry. It is described below (*note Event | |
11104 | Designators::). This is the only history expansion that does not begin | |
11105 | with the history expansion character. | |
11106 | ||
11107 | Several shell options settable with the ‘shopt’ builtin (*note The | |
11108 | Shopt Builtin::) modify history expansion behavior If the ‘histverify’ | |
11109 | shell option is enabled, and Readline is being used, history | |
11110 | substitutions are not immediately passed to the shell parser. Instead, | |
11111 | the expanded line is reloaded into the Readline editing buffer for | |
11112 | further modification. If Readline is being used, and the ‘histreedit’ | |
11113 | shell option is enabled, a failed history expansion is reloaded into the | |
11114 | Readline editing buffer for correction. | |
11115 | ||
11116 | The ‘-p’ option to the ‘history’ builtin command shows what a history | |
11117 | expansion will do before using it. The ‘-s’ option to the ‘history’ | |
11118 | builtin may be used to add commands to the end of the history list | |
11119 | without actually executing them, so that they are available for | |
11120 | subsequent recall. This is most useful in conjunction with Readline. | |
11121 | ||
11122 | The shell allows control of the various characters used by the | |
11123 | history expansion mechanism with the ‘histchars’ variable, as explained | |
11124 | above (*note Bash Variables::). The shell uses the history comment | |
11125 | character to mark history timestamps when writing the history file. | |
11126 | ||
11127 | * Menu: | |
11128 | ||
11129 | * Event Designators:: How to specify which history line to use. | |
11130 | * Word Designators:: Specifying which words are of interest. | |
11131 | * Modifiers:: Modifying the results of substitution. | |
11132 | ||
11133 | \1f | |
11134 | File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction | |
11135 | ||
11136 | 9.3.1 Event Designators | |
11137 | ----------------------- | |
11138 | ||
11139 | An event designator is a reference to an entry in the history list. The | |
11140 | event designator consists of the portion of the word beginning with the | |
11141 | history expansion character, and ending with the word designator if one | |
11142 | is present, or the end of the word. Unless the reference is absolute, | |
11143 | events are relative to the current position in the history list. | |
11144 | ||
11145 | ‘!’ | |
11146 | Start a history substitution, except when followed by a space, tab, | |
11147 | the end of the line, ‘=’, or the rest of the shell metacharacters | |
11148 | defined above (*note Definitions::). | |
11149 | ||
11150 | ‘!N’ | |
11151 | Refer to history list entry N. | |
11152 | ||
11153 | ‘!-N’ | |
11154 | Refer to the history entry minus N. | |
11155 | ||
11156 | ‘!!’ | |
11157 | Refer to the previous entry. This is a synonym for ‘!-1’. | |
11158 | ||
11159 | ‘!STRING’ | |
11160 | Refer to the most recent command preceding the current position in | |
11161 | the history list starting with STRING. | |
11162 | ||
11163 | ‘!?STRING[?]’ | |
11164 | Refer to the most recent command preceding the current position in | |
11165 | the history list containing STRING. The trailing ‘?’ may be | |
11166 | omitted if the STRING is followed immediately by a newline. If | |
11167 | STRING is missing, this uses the string from the most recent | |
11168 | search; it is an error if there is no previous search string. | |
11169 | ||
11170 | ‘^STRING1^STRING2^’ | |
11171 | Quick Substitution. Repeat the last command, replacing STRING1 | |
11172 | with STRING2. Equivalent to ‘!!:s^STRING1^STRING2^’. | |
11173 | ||
11174 | ‘!#’ | |
11175 | The entire command line typed so far. | |
11176 | ||
11177 | \1f | |
11178 | File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction | |
11179 | ||
11180 | 9.3.2 Word Designators | |
11181 | ---------------------- | |
11182 | ||
11183 | Word designators are used to select desired words from the event. They | |
11184 | are optional; if the word designator isn't supplied, the history | |
11185 | expansion uses the entire event. A ‘:’ separates the event | |
11186 | specification from the word designator. It may be omitted if the word | |
11187 | designator begins with a ‘^’, ‘$’, ‘*’, ‘-’, or ‘%’. Words are numbered | |
11188 | from the beginning of the line, with the first word being denoted by 0 | |
11189 | (zero). That first word is usually the command word, and the arguments | |
11190 | begin with the second word. Words are inserted into the current line | |
11191 | separated by single spaces. | |
11192 | ||
11193 | For example, | |
11194 | ||
11195 | ‘!!’ | |
11196 | designates the preceding command. When you type this, the | |
11197 | preceding command is repeated in toto. | |
11198 | ||
11199 | ‘!!:$’ | |
11200 | designates the last word of the preceding command. This may be | |
11201 | shortened to ‘!$’. | |
11202 | ||
11203 | ‘!fi:2’ | |
11204 | designates the second argument of the most recent command starting | |
11205 | with the letters ‘fi’. | |
11206 | ||
11207 | Here are the word designators: | |
11208 | ||
11209 | ‘0 (zero)’ | |
11210 | The ‘0’th word. For the shell, and many other, applications, this | |
11211 | is the command word. | |
11212 | ||
11213 | ‘N’ | |
11214 | The Nth word. | |
11215 | ||
11216 | ‘^’ | |
11217 | The first argument: word 1. | |
11218 | ||
11219 | ‘$’ | |
11220 | The last word. This is usually the last argument, but expands to | |
11221 | the zeroth word if there is only one word in the line. | |
11222 | ||
11223 | ‘%’ | |
11224 | The first word matched by the most recent ‘?STRING?’ search, if the | |
11225 | search string begins with a character that is part of a word. By | |
11226 | default, searches begin at the end of each line and proceed to the | |
11227 | beginning, so the first word matched is the one closest to the end | |
11228 | of the line. | |
11229 | ||
11230 | ‘X-Y’ | |
11231 | A range of words; ‘-Y’ abbreviates ‘0-Y’. | |
11232 | ||
11233 | ‘*’ | |
11234 | All of the words, except the ‘0’th. This is a synonym for ‘1-$’. | |
11235 | It is not an error to use ‘*’ if there is just one word in the | |
11236 | event; it expands to the empty string in that case. | |
11237 | ||
11238 | ‘X*’ | |
11239 | Abbreviates ‘X-$’. | |
11240 | ||
11241 | ‘X-’ | |
11242 | Abbreviates ‘X-$’ like ‘X*’, but omits the last word. If ‘x’ is | |
11243 | missing, it defaults to 0. | |
11244 | ||
11245 | If a word designator is supplied without an event specification, the | |
11246 | previous command is used as the event, equivalent to ‘!!’. | |
11247 | ||
11248 | \1f | |
11249 | File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction | |
11250 | ||
11251 | 9.3.3 Modifiers | |
11252 | --------------- | |
11253 | ||
11254 | After the optional word designator, you can add a sequence of one or | |
11255 | more of the following modifiers, each preceded by a ‘:’. These modify, | |
11256 | or edit, the word or words selected from the history event. | |
11257 | ||
11258 | ‘h’ | |
11259 | Remove a trailing filename component, leaving only the head. | |
11260 | ||
11261 | ‘t’ | |
11262 | Remove all leading filename components, leaving the tail. | |
11263 | ||
11264 | ‘r’ | |
11265 | Remove a trailing suffix of the form ‘.SUFFIX’, leaving the | |
11266 | basename. | |
11267 | ||
11268 | ‘e’ | |
11269 | Remove all but the trailing suffix. | |
11270 | ||
11271 | ‘p’ | |
11272 | Print the new command but do not execute it. | |
11273 | ||
11274 | ‘q’ | |
11275 | Quote the substituted words, escaping further substitutions. | |
11276 | ||
11277 | ‘x’ | |
11278 | Quote the substituted words as with ‘q’, but break into words at | |
11279 | spaces, tabs, and newlines. The ‘q’ and ‘x’ modifiers are mutually | |
11280 | exclusive; expansion uses the last one supplied. | |
11281 | ||
11282 | ‘s/OLD/NEW/’ | |
11283 | Substitute NEW for the first occurrence of OLD in the event line. | |
11284 | Any character may be used as the delimiter in place of ‘/’. The | |
11285 | delimiter may be quoted in OLD and NEW with a single backslash. If | |
11286 | ‘&’ appears in NEW, it is replaced with OLD. A single backslash | |
11287 | quotes the ‘&’ in OLD and NEW. If OLD is null, it is set to the | |
11288 | last OLD substituted, or, if no previous history substitutions took | |
11289 | place, the last STRING in a !?STRING‘[?]’ search. If NEW is null, | |
11290 | each matching OLD is deleted. The final delimiter is optional if | |
11291 | it is the last character on the input line. | |
11292 | ||
11293 | ‘&’ | |
11294 | Repeat the previous substitution. | |
11295 | ||
11296 | ‘g’ | |
11297 | ‘a’ | |
11298 | Cause changes to be applied over the entire event line. This is | |
11299 | used in conjunction with ‘s’, as in ‘gs/OLD/NEW/’, or with ‘&’. | |
11300 | ||
11301 | ‘G’ | |
11302 | Apply the following ‘s’ or ‘&’ modifier once to each word in the | |
11303 | event. | |
11304 | ||
11305 | \1f | |
11306 | File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top | |
11307 | ||
11308 | 10 Installing Bash | |
11309 | ****************** | |
11310 | ||
11311 | This chapter provides basic instructions for installing Bash on the | |
11312 | various supported platforms. The distribution supports the GNU | |
11313 | operating systems, nearly every version of Unix, and several non-Unix | |
11314 | systems such as BeOS and Interix. Other independent ports exist for | |
11315 | Windows platforms. | |
11316 | ||
11317 | * Menu: | |
11318 | ||
11319 | * Basic Installation:: Installation instructions. | |
11320 | * Compilers and Options:: How to set special options for various | |
11321 | systems. | |
11322 | * Compiling For Multiple Architectures:: How to compile Bash for more | |
11323 | than one kind of system from | |
11324 | the same source tree. | |
11325 | * Installation Names:: How to set the various paths used by the installation. | |
11326 | * Specifying the System Type:: How to configure Bash for a particular system. | |
11327 | * Sharing Defaults:: How to share default configuration values among GNU | |
11328 | programs. | |
11329 | * Operation Controls:: Options recognized by the configuration program. | |
11330 | * Optional Features:: How to enable and disable optional features when | |
11331 | building Bash. | |
11332 | ||
11333 | \1f | |
11334 | File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash | |
11335 | ||
11336 | 10.1 Basic Installation | |
11337 | ======================= | |
11338 | ||
11339 | These are installation instructions for Bash. | |
11340 | ||
11341 | The simplest way to compile Bash is: | |
11342 | ||
11343 | 1. ‘cd’ to the directory containing the source code and type | |
11344 | ‘./configure’ to configure Bash for your system. If you're using | |
11345 | ‘csh’ on an old version of System V, you might need to type ‘sh | |
11346 | ./configure’ instead to prevent ‘csh’ from trying to execute | |
11347 | ‘configure’ itself. | |
11348 | ||
11349 | Running ‘configure’ takes some time. While running, it prints | |
11350 | messages telling which features it is checking for. | |
11351 | ||
11352 | 2. Type ‘make’ to compile Bash and build the ‘bashbug’ bug reporting | |
11353 | script. | |
11354 | ||
11355 | 3. Optionally, type ‘make tests’ to run the Bash test suite. | |
11356 | ||
11357 | 4. Type ‘make install’ to install ‘bash’ and ‘bashbug’. This will | |
11358 | also install the manual pages and Info file, message translation | |
11359 | files, some supplemental documentation, a number of example | |
11360 | loadable builtin commands, and a set of header files for developing | |
11361 | loadable builtins. You may need additional privileges to install | |
11362 | ‘bash’ to your desired destination, which may require ‘sudo make | |
11363 | install’. More information about controlling the locations where | |
11364 | ‘bash’ and other files are installed is below (*note Installation | |
11365 | Names::). | |
11366 | ||
11367 | The ‘configure’ shell script attempts to guess correct values for | |
11368 | various system-dependent variables used during compilation. It uses | |
11369 | those values to create a ‘Makefile’ in each directory of the package | |
11370 | (the top directory, the ‘builtins’, ‘doc’, ‘po’, and ‘support’ | |
11371 | directories, each directory under ‘lib’, and several others). It also | |
11372 | creates a ‘config.h’ file containing system-dependent definitions. | |
11373 | Finally, it creates a shell script named ‘config.status’ that you can | |
11374 | run in the future to recreate the current configuration, a file | |
11375 | ‘config.cache’ that saves the results of its tests to speed up | |
11376 | reconfiguring, and a file ‘config.log’ containing compiler output | |
11377 | (useful mainly for debugging ‘configure’). If at some point | |
11378 | ‘config.cache’ contains results you don't want to keep, you may remove | |
11379 | or edit it. | |
11380 | ||
11381 | To find out more about the options and arguments that the ‘configure’ | |
11382 | script understands, type | |
11383 | ||
11384 | bash-4.2$ ./configure --help | |
11385 | ||
11386 | at the Bash prompt in your Bash source directory. | |
11387 | ||
11388 | If you want to build Bash in a directory separate from the source | |
11389 | directory - to build for multiple architectures, for example - just use | |
11390 | the full path to the configure script. The following commands will | |
11391 | build Bash in a directory under ‘/usr/local/build’ from the source code | |
11392 | in ‘/usr/local/src/bash-4.4’: | |
11393 | ||
11394 | mkdir /usr/local/build/bash-4.4 | |
11395 | cd /usr/local/build/bash-4.4 | |
11396 | bash /usr/local/src/bash-4.4/configure | |
11397 | make | |
11398 | ||
11399 | See *note Compiling For Multiple Architectures:: for more information | |
11400 | about building in a directory separate from the source. | |
11401 | ||
11402 | If you need to do unusual things to compile Bash, please try to | |
11403 | figure out how ‘configure’ could check whether or not to do them, and | |
11404 | mail diffs or instructions to <bash-maintainers@gnu.org> so they can be | |
11405 | considered for the next release. | |
11406 | ||
11407 | The file ‘configure.ac’ is used to create ‘configure’ by a program | |
11408 | called Autoconf. You only need ‘configure.ac’ if you want to change it | |
11409 | or regenerate ‘configure’ using a newer version of Autoconf. If you do | |
11410 | this, make sure you are using Autoconf version 2.69 or newer. | |
11411 | ||
11412 | You can remove the program binaries and object files from the source | |
11413 | code directory by typing ‘make clean’. To also remove the files that | |
11414 | ‘configure’ created (so you can compile Bash for a different kind of | |
11415 | computer), type ‘make distclean’. | |
11416 | ||
11417 | \1f | |
11418 | File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash | |
11419 | ||
11420 | 10.2 Compilers and Options | |
11421 | ========================== | |
11422 | ||
11423 | Some systems require unusual options for compilation or linking that the | |
11424 | ‘configure’ script does not know about. You can give ‘configure’ | |
11425 | initial values for variables by setting them in the environment. Using | |
11426 | a Bourne-compatible shell, you can do that on the command line like | |
11427 | this: | |
11428 | ||
11429 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure | |
11430 | ||
11431 | On systems that have the ‘env’ program, you can do it like this: | |
11432 | ||
11433 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure | |
11434 | ||
11435 | The configuration process uses GCC to build Bash if it is available. | |
11436 | ||
11437 | \1f | |
11438 | File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash | |
11439 | ||
11440 | 10.3 Compiling For Multiple Architectures | |
11441 | ========================================= | |
11442 | ||
11443 | You can compile Bash for more than one kind of computer at the same | |
11444 | time, by placing the object files for each architecture in their own | |
11445 | directory. To do this, you must use a version of ‘make’ that supports | |
11446 | the ‘VPATH’ variable, such as GNU ‘make’. ‘cd’ to the directory where | |
11447 | you want the object files and executables to go and run the ‘configure’ | |
11448 | script from the source directory (*note Basic Installation::). You may | |
11449 | need to supply the ‘--srcdir=PATH’ argument to tell ‘configure’ where | |
11450 | the source files are. ‘configure’ automatically checks for the source | |
11451 | code in the directory that ‘configure’ is in and in ‘..’. | |
11452 | ||
11453 | If you have to use a ‘make’ that does not support the ‘VPATH’ | |
11454 | variable, you can compile Bash for one architecture at a time in the | |
11455 | source code directory. After you have installed Bash for one | |
11456 | architecture, use ‘make distclean’ before reconfiguring for another | |
11457 | architecture. | |
11458 | ||
11459 | Alternatively, if your system supports symbolic links, you can use | |
11460 | the ‘support/mkclone’ script to create a build tree which has symbolic | |
11461 | links back to each file in the source directory. Here's an example that | |
11462 | creates a build directory in the current directory from a source | |
11463 | directory ‘/usr/gnu/src/bash-2.0’: | |
11464 | ||
11465 | bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 . | |
11466 | ||
11467 | The ‘mkclone’ script requires Bash, so you must have already built Bash | |
11468 | for at least one architecture before you can create build directories | |
11469 | for other architectures. | |
11470 | ||
11471 | \1f | |
11472 | File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash | |
11473 | ||
11474 | 10.4 Installation Names | |
11475 | ======================= | |
11476 | ||
11477 | By default, ‘make install’ will install into ‘/usr/local/bin’, | |
11478 | ‘/usr/local/man’, etc.; that is, the “installation prefix” defaults to | |
11479 | ‘/usr/local’. You can specify an installation prefix other than | |
11480 | ‘/usr/local’ by giving ‘configure’ the option ‘--prefix=PATH’, or by | |
11481 | specifying a value for the ‘prefix’ ‘make’ variable when running ‘make | |
11482 | install’ (e.g., ‘make install prefix=PATH’). The ‘prefix’ variable | |
11483 | provides a default for ‘exec_prefix’ and other variables used when | |
11484 | installing Bash. | |
11485 | ||
11486 | You can specify separate installation prefixes for | |
11487 | architecture-specific files and architecture-independent files. If you | |
11488 | give ‘configure’ the option ‘--exec-prefix=PATH’, ‘make install’ will | |
11489 | use PATH as the prefix for installing programs and libraries. | |
11490 | Documentation and other data files will still use the regular prefix. | |
11491 | ||
11492 | If you would like to change the installation locations for a single | |
11493 | run, you can specify these variables as arguments to ‘make’: ‘make | |
11494 | install exec_prefix=/’ will install ‘bash’ and ‘bashbug’ into ‘/bin’ | |
11495 | instead of the default ‘/usr/local/bin’. | |
11496 | ||
11497 | If you want to see the files Bash will install and where it will | |
11498 | install them without changing anything on your system, specify the | |
11499 | variable ‘DESTDIR’ as an argument to ‘make’. Its value should be the | |
11500 | absolute directory path you'd like to use as the root of your sample | |
11501 | installation tree. For example, | |
11502 | ||
11503 | mkdir /fs1/bash-install | |
11504 | make install DESTDIR=/fs1/bash-install | |
11505 | ||
11506 | will install ‘bash’ into ‘/fs1/bash-install/usr/local/bin/bash’, the | |
11507 | documentation into directories within | |
11508 | ‘/fs1/bash-install/usr/local/share’, the example loadable builtins into | |
11509 | ‘/fs1/bash-install/usr/local/lib/bash’, and so on. You can use the | |
11510 | usual ‘exec_prefix’ and ‘prefix’ variables to alter the directory paths | |
11511 | beneath the value of ‘DESTDIR’. | |
11512 | ||
11513 | The GNU Makefile standards provide a more complete description of | |
11514 | these variables and their effects. | |
11515 | ||
11516 | \1f | |
11517 | File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash | |
11518 | ||
11519 | 10.5 Specifying the System Type | |
11520 | =============================== | |
11521 | ||
11522 | There may be some features ‘configure’ can not figure out automatically, | |
11523 | but needs to determine by the type of host Bash will run on. Usually | |
11524 | ‘configure’ can figure that out, but if it prints a message saying it | |
11525 | can not guess the host type, give it the ‘--host=TYPE’ option. ‘TYPE’ | |
11526 | can either be a short name for the system type, such as ‘sun4’, or a | |
11527 | canonical name with three fields: ‘CPU-COMPANY-SYSTEM’ (e.g., | |
11528 | ‘i386-unknown-freebsd4.2’). | |
11529 | ||
11530 | See the file ‘support/config.sub’ for the possible values of each | |
11531 | field. | |
11532 | ||
11533 | \1f | |
11534 | File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash | |
11535 | ||
11536 | 10.6 Sharing Defaults | |
11537 | ===================== | |
11538 | ||
11539 | If you want to set default values for ‘configure’ scripts to share, you | |
11540 | can create a site shell script called ‘config.site’ that gives default | |
11541 | values for variables like ‘CC’, ‘cache_file’, and ‘prefix’. ‘configure’ | |
11542 | looks for ‘PREFIX/share/config.site’ if it exists, then | |
11543 | ‘PREFIX/etc/config.site’ if it exists. Or, you can set the | |
11544 | ‘CONFIG_SITE’ environment variable to the location of the site script. | |
11545 | A warning: the Bash ‘configure’ looks for a site script, but not all | |
11546 | ‘configure’ scripts do. | |
11547 | ||
11548 | \1f | |
11549 | File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash | |
11550 | ||
11551 | 10.7 Operation Controls | |
11552 | ======================= | |
11553 | ||
11554 | ‘configure’ recognizes the following options to control how it operates. | |
11555 | ||
11556 | ‘--cache-file=FILE’ | |
11557 | Use and save the results of the tests in FILE instead of | |
11558 | ‘./config.cache’. Set FILE to ‘/dev/null’ to disable caching, for | |
11559 | debugging ‘configure’. | |
11560 | ||
11561 | ‘--help’ | |
11562 | Print a summary of the options to ‘configure’, and exit. | |
11563 | ||
11564 | ‘--quiet’ | |
11565 | ‘--silent’ | |
11566 | ‘-q’ | |
11567 | Do not print messages saying which checks are being made. | |
11568 | ||
11569 | ‘--srcdir=DIR’ | |
11570 | Look for the Bash source code in directory DIR. Usually | |
11571 | ‘configure’ can determine that directory automatically. | |
11572 | ||
11573 | ‘--version’ | |
11574 | Print the version of Autoconf used to generate the ‘configure’ | |
11575 | script, and exit. | |
11576 | ||
11577 | ‘configure’ also accepts some other, not widely used, boilerplate | |
11578 | options. ‘configure --help’ prints the complete list. | |
11579 | ||
11580 | \1f | |
11581 | File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash | |
11582 | ||
11583 | 10.8 Optional Features | |
11584 | ====================== | |
11585 | ||
11586 | The Bash ‘configure’ has a number of ‘--enable-FEATURE’ options, where | |
11587 | FEATURE indicates an optional part of Bash. There are also several | |
11588 | ‘--with-PACKAGE’ options, where PACKAGE is something like ‘bash-malloc’ | |
11589 | or ‘afs’. To turn off the default use of a package, use | |
11590 | ‘--without-PACKAGE’. To configure Bash without a feature that is | |
11591 | enabled by default, use ‘--disable-FEATURE’. | |
11592 | ||
11593 | Here is a complete list of the ‘--enable-’ and ‘--with-’ options that | |
11594 | the Bash ‘configure’ recognizes. | |
11595 | ||
11596 | ‘--with-afs’ | |
11597 | Define if you are using the Andrew File System from Transarc. | |
11598 | ||
11599 | ‘--with-bash-malloc’ | |
11600 | Use the Bash version of ‘malloc’ in the directory ‘lib/malloc’. | |
11601 | This is not the same ‘malloc’ that appears in GNU libc, but a | |
11602 | custom version originally derived from the 4.2 BSD ‘malloc’. This | |
11603 | ‘malloc’ is very fast, but wastes some space on each allocation, | |
11604 | though it uses several techniques to minimize the waste. This | |
11605 | option is enabled by default. The ‘NOTES’ file contains a list of | |
11606 | systems for which this should be turned off, and ‘configure’ | |
11607 | disables this option automatically for a number of systems. | |
11608 | ||
11609 | ‘--with-curses’ | |
11610 | Use the curses library instead of the termcap library. ‘configure’ | |
11611 | usually chooses this automatically, since most systems include the | |
11612 | termcap functions in the curses library. | |
11613 | ||
11614 | ‘--with-gnu-malloc’ | |
11615 | A synonym for ‘--with-bash-malloc’. | |
11616 | ||
11617 | ‘--with-installed-readline[=PREFIX]’ | |
11618 | Define this to make Bash link with a locally-installed version of | |
11619 | Readline rather than the version in ‘lib/readline’. This works | |
11620 | only with Readline 5.0 and later versions. If PREFIX is ‘yes’ or | |
11621 | not supplied, ‘configure’ uses the values of the make variables | |
11622 | ‘includedir’ and ‘libdir’, which are subdirectories of ‘prefix’ by | |
11623 | default, to find the installed version of Readline if it is not in | |
11624 | the standard system include and library directories. If PREFIX is | |
11625 | ‘no’, Bash links with the version in ‘lib/readline’. If PREFIX is | |
11626 | set to any other value, ‘configure’ treats it as a directory | |
11627 | pathname and looks for the installed version of Readline in | |
11628 | subdirectories of that directory (include files in PREFIX/‘include’ | |
11629 | and the library in PREFIX/‘lib’). The Bash default is to link with | |
11630 | a static library built in the ‘lib/readline’ subdirectory of the | |
11631 | build directory. | |
11632 | ||
11633 | ‘--with-libintl-prefix[=PREFIX]’ | |
11634 | Define this to make Bash link with a locally-installed version of | |
11635 | the libintl library instead of the version in ‘lib/intl’. | |
11636 | ||
11637 | ‘--with-libiconv-prefix[=PREFIX]’ | |
11638 | Define this to make Bash look for libiconv in PREFIX instead of the | |
11639 | standard system locations. The Bash distribution does not include | |
11640 | this library. | |
11641 | ||
11642 | ‘--enable-minimal-config’ | |
11643 | This produces a shell with minimal features, closer to the | |
11644 | historical Bourne shell. | |
11645 | ||
11646 | There are several ‘--enable-’ options that alter how Bash is | |
11647 | compiled, linked, and installed, rather than changing run-time features. | |
11648 | ||
11649 | ‘--enable-largefile’ | |
11650 | Enable support for large files | |
11651 | (http://www.unix.org/version2/whatsnew/lfs20mar.html) if the | |
11652 | operating system requires special compiler options to build | |
11653 | programs which can access large files. This is enabled by default, | |
11654 | if the operating system provides large file support. | |
11655 | ||
11656 | ‘--enable-profiling’ | |
11657 | This builds a Bash binary that produces profiling information to be | |
11658 | processed by ‘gprof’ each time it is executed. | |
11659 | ||
11660 | ‘--enable-separate-helpfiles’ | |
11661 | Use external files for the documentation displayed by the ‘help’ | |
11662 | builtin instead of storing the text internally. | |
11663 | ||
11664 | ‘--enable-static-link’ | |
11665 | This causes Bash to be linked statically, if ‘gcc’ is being used. | |
11666 | This could be used to build a version to use as root's shell. | |
11667 | ||
11668 | The ‘minimal-config’ option can be used to disable all of the | |
11669 | following options, but it is processed first, so individual options may | |
11670 | be enabled using ‘enable-FEATURE’. | |
11671 | ||
11672 | All of the following options except for ‘alt-array-implementation’, | |
11673 | ‘disabled-builtins’, ‘direxpand-default’, ‘strict-posix-default’, and | |
11674 | ‘xpg-echo-default’ are enabled by default, unless the operating system | |
11675 | does not provide the necessary support. | |
11676 | ||
11677 | ‘--enable-alias’ | |
11678 | Allow alias expansion and include the ‘alias’ and ‘unalias’ | |
11679 | builtins (*note Aliases::). | |
11680 | ||
11681 | ‘--enable-alt-array-implementation’ | |
11682 | This builds Bash using an alternate implementation of arrays (*note | |
11683 | Arrays::) that provides faster access at the expense of using more | |
11684 | memory (sometimes many times more, depending on how sparse an array | |
11685 | is). | |
11686 | ||
11687 | ‘--enable-arith-for-command’ | |
11688 | Include support for the alternate form of the ‘for’ command that | |
11689 | behaves like the C language ‘for’ statement (*note Looping | |
11690 | Constructs::). | |
11691 | ||
11692 | ‘--enable-array-variables’ | |
11693 | Include support for one-dimensional array shell variables (*note | |
11694 | Arrays::). | |
11695 | ||
11696 | ‘--enable-bang-history’ | |
11697 | Include support for ‘csh’-like history substitution (*note History | |
11698 | Interaction::). | |
11699 | ||
11700 | ‘--enable-bash-source-fullpath-default’ | |
11701 | Set the default value of the ‘bash_source_fullpath’ shell option | |
11702 | described above under *note The Shopt Builtin:: to be enabled. | |
11703 | This controls how filenames are assigned to the ‘BASH_SOURCE’ array | |
11704 | variable. | |
11705 | ||
11706 | ‘--enable-brace-expansion’ | |
11707 | Include ‘csh’-like brace expansion ( ‘b{a,b}c’ ↦ ‘bac bbc’ ). See | |
11708 | *note Brace Expansion::, for a complete description. | |
11709 | ||
11710 | ‘--enable-casemod-attributes’ | |
11711 | Include support for case-modifying attributes in the ‘declare’ | |
11712 | builtin and assignment statements. Variables with the ‘uppercase’ | |
11713 | attribute, for example, will have their values converted to | |
11714 | uppercase upon assignment. | |
11715 | ||
11716 | ‘--enable-casemod-expansion’ | |
11717 | Include support for case-modifying word expansions. | |
11718 | ||
11719 | ‘--enable-command-timing’ | |
11720 | Include support for recognizing ‘time’ as a reserved word and for | |
11721 | displaying timing statistics for the pipeline following ‘time’ | |
11722 | (*note Pipelines::). This allows timing pipelines, shell compound | |
11723 | commands, shell builtins, and shell functions, which an external | |
11724 | command cannot do easily. | |
11725 | ||
11726 | ‘--enable-cond-command’ | |
11727 | Include support for the ‘[[’ conditional command. (*note | |
11728 | Conditional Constructs::). | |
11729 | ||
11730 | ‘--enable-cond-regexp’ | |
11731 | Include support for matching POSIX regular expressions using the | |
11732 | ‘=~’ binary operator in the ‘[[’ conditional command. (*note | |
11733 | Conditional Constructs::). | |
11734 | ||
11735 | ‘--enable-coprocesses’ | |
11736 | Include support for coprocesses and the ‘coproc’ reserved word | |
11737 | (*note Pipelines::). | |
11738 | ||
11739 | ‘--enable-debugger’ | |
11740 | Include support for the Bash debugger (distributed separately). | |
11741 | ||
11742 | ‘--enable-dev-fd-stat-broken’ | |
11743 | If calling ‘stat’ on /dev/fd/N returns different results than | |
11744 | calling ‘fstat’ on file descriptor N, supply this option to enable | |
11745 | a workaround. This has implications for conditional commands that | |
11746 | test file attributes. | |
11747 | ||
11748 | ‘--enable-direxpand-default’ | |
11749 | Cause the ‘direxpand’ shell option (*note The Shopt Builtin::) to | |
11750 | be enabled by default when the shell starts. It is normally | |
11751 | disabled by default. | |
11752 | ||
11753 | ‘--enable-directory-stack’ | |
11754 | Include support for a ‘csh’-like directory stack and the ‘pushd’, | |
11755 | ‘popd’, and ‘dirs’ builtins (*note The Directory Stack::). | |
11756 | ||
11757 | ‘--enable-disabled-builtins’ | |
11758 | Allow builtin commands to be invoked via ‘builtin xxx’ even after | |
11759 | ‘xxx’ has been disabled using ‘enable -n xxx’. See *note Bash | |
11760 | Builtins::, for details of the ‘builtin’ and ‘enable’ builtin | |
11761 | commands. | |
11762 | ||
11763 | ‘--enable-dparen-arithmetic’ | |
11764 | Include support for the ‘((...))’ command (*note Conditional | |
11765 | Constructs::). | |
11766 | ||
11767 | ‘--enable-extended-glob’ | |
11768 | Include support for the extended pattern matching features | |
11769 | described above under *note Pattern Matching::. | |
11770 | ||
11771 | ‘--enable-extended-glob-default’ | |
11772 | Set the default value of the ‘extglob’ shell option described above | |
11773 | under *note The Shopt Builtin:: to be enabled. | |
11774 | ||
11775 | ‘--enable-function-import’ | |
11776 | Include support for importing function definitions exported by | |
11777 | another instance of the shell from the environment. This option is | |
11778 | enabled by default. | |
11779 | ||
11780 | ‘--enable-glob-asciiranges-default’ | |
11781 | Set the default value of the ‘globasciiranges’ shell option | |
11782 | described above under *note The Shopt Builtin:: to be enabled. | |
11783 | This controls the behavior of character ranges when used in pattern | |
11784 | matching bracket expressions. | |
11785 | ||
11786 | ‘--enable-help-builtin’ | |
11787 | Include the ‘help’ builtin, which displays help on shell builtins | |
11788 | and variables (*note Bash Builtins::). | |
11789 | ||
11790 | ‘--enable-history’ | |
11791 | Include command history and the ‘fc’ and ‘history’ builtin commands | |
11792 | (*note Bash History Facilities::). | |
11793 | ||
11794 | ‘--enable-job-control’ | |
11795 | This enables the job control features (*note Job Control::), if the | |
11796 | operating system supports them. | |
11797 | ||
11798 | ‘--enable-multibyte’ | |
11799 | This enables support for multibyte characters if the operating | |
11800 | system provides the necessary support. | |
11801 | ||
11802 | ‘--enable-net-redirections’ | |
11803 | This enables the special handling of filenames of the form | |
11804 | ‘/dev/tcp/HOST/PORT’ and ‘/dev/udp/HOST/PORT’ when used in | |
11805 | redirections (*note Redirections::). | |
11806 | ||
11807 | ‘--enable-process-substitution’ | |
11808 | This enables process substitution (*note Process Substitution::) if | |
11809 | the operating system provides the necessary support. | |
11810 | ||
11811 | ‘--enable-progcomp’ | |
11812 | Enable the programmable completion facilities (*note Programmable | |
11813 | Completion::). If Readline is not enabled, this option has no | |
11814 | effect. | |
11815 | ||
11816 | ‘--enable-prompt-string-decoding’ | |
11817 | Turn on the interpretation of a number of backslash-escaped | |
11818 | characters in the ‘$PS0’, ‘$PS1’, ‘$PS2’, and ‘$PS4’ prompt | |
11819 | strings. See *note Controlling the Prompt::, for a complete list | |
11820 | of prompt string escape sequences. | |
11821 | ||
11822 | ‘--enable-readline’ | |
11823 | Include support for command-line editing and history with the Bash | |
11824 | version of the Readline library (*note Command Line Editing::). | |
11825 | ||
11826 | ‘--enable-restricted’ | |
11827 | Include support for a “restricted shell”. If this is enabled, Bash | |
11828 | enters a restricted mode when called as ‘rbash’. See *note The | |
11829 | Restricted Shell::, for a description of restricted mode. | |
11830 | ||
11831 | ‘--enable-select’ | |
11832 | Include the ‘select’ compound command, which allows generation of | |
11833 | simple menus (*note Conditional Constructs::). | |
11834 | ||
11835 | ‘--enable-single-help-strings’ | |
11836 | Store the text displayed by the ‘help’ builtin as a single string | |
11837 | for each help topic. This aids in translating the text to | |
11838 | different languages. You may need to disable this if your compiler | |
11839 | cannot handle very long string literals. | |
11840 | ||
11841 | ‘--enable-strict-posix-default’ | |
11842 | Make Bash POSIX-conformant by default (*note Bash POSIX Mode::). | |
11843 | ||
11844 | ‘--enable-translatable-strings’ | |
11845 | Enable support for ‘$"STRING"’ translatable strings (*note Locale | |
11846 | Translation::). | |
11847 | ||
11848 | ‘--enable-usg-echo-default’ | |
11849 | A synonym for ‘--enable-xpg-echo-default’. | |
11850 | ||
11851 | ‘--enable-xpg-echo-default’ | |
11852 | Make the ‘echo’ builtin expand backslash-escaped characters by | |
11853 | default, without requiring the ‘-e’ option. This sets the default | |
11854 | value of the ‘xpg_echo’ shell option to ‘on’, which makes the Bash | |
11855 | ‘echo’ behave more like the version specified in the Single Unix | |
11856 | Specification, version 3. *Note Bash Builtins::, for a description | |
11857 | of the escape sequences that ‘echo’ recognizes. | |
11858 | ||
11859 | The file ‘config-top.h’ contains C Preprocessor ‘#define’ statements | |
11860 | for options which are not settable from ‘configure’. Some of these are | |
11861 | not meant to be changed; beware of the consequences if you do. Read the | |
11862 | comments associated with each definition for more information about its | |
11863 | effect. | |
11864 | ||
11865 | \1f | |
11866 | File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top | |
11867 | ||
11868 | Appendix A Reporting Bugs | |
11869 | ************************* | |
11870 | ||
11871 | Please report all bugs you find in Bash. But first, you should make | |
11872 | sure that it really is a bug, and that it appears in the latest version | |
11873 | of Bash. The latest released version of Bash is always available for | |
11874 | FTP from <ftp://ftp.gnu.org/pub/gnu/bash/> and from | |
11875 | <http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz>. | |
11876 | ||
11877 | Once you have determined that a bug actually exists, use the | |
11878 | ‘bashbug’ command to submit a bug report or use the form at the Bash | |
11879 | project page (https://savannah.gnu.org/projects/bash/). If you have a | |
11880 | fix, you are encouraged to submit that as well! Suggestions and | |
11881 | 'philosophical' bug reports may be mailed to <bug-bash@gnu.org> or | |
11882 | <help-bash@gnu.org>. | |
11883 | ||
11884 | All bug reports should include: | |
11885 | • The version number of Bash. | |
11886 | • The hardware and operating system. | |
11887 | • The compiler used to compile Bash. | |
11888 | • A description of the bug behavior. | |
11889 | • A short script or 'recipe' which exercises the bug and may be used | |
11890 | to reproduce it. | |
11891 | ||
11892 | ‘bashbug’ inserts the first three items automatically into the template | |
11893 | it provides for filing a bug report. | |
11894 | ||
11895 | Please send all reports concerning this manual to <bug-bash@gnu.org>. | |
11896 | ||
11897 | \1f | |
11898 | File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top | |
11899 | ||
11900 | Appendix B Major Differences From The Bourne Shell | |
11901 | ************************************************** | |
11902 | ||
11903 | Bash implements essentially the same grammar, parameter and variable | |
11904 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the | |
11905 | POSIX standard as the specification of how these features are to be | |
11906 | implemented and how they should behave. There are some differences | |
11907 | between the traditional Bourne shell and Bash; this section quickly | |
11908 | details the differences of significance. A number of these differences | |
11909 | are explained in greater depth in previous sections. This section uses | |
11910 | the version of ‘sh’ included in SVR4.2 (the last version of the | |
11911 | historical Bourne shell) as the baseline reference. | |
11912 | ||
11913 | • Bash is POSIX-conformant, even where the POSIX specification | |
11914 | differs from traditional ‘sh’ behavior (*note Bash POSIX Mode::). | |
11915 | ||
11916 | • Bash has multi-character invocation options (*note Invoking | |
11917 | Bash::). | |
11918 | ||
11919 | • The Bash restricted mode is more useful (*note The Restricted | |
11920 | Shell::); the SVR4.2 shell restricted mode is too limited. | |
11921 | ||
11922 | • Bash has command-line editing (*note Command Line Editing::) and | |
11923 | the ‘bind’ builtin. | |
11924 | ||
11925 | • Bash provides a programmable word completion mechanism (*note | |
11926 | Programmable Completion::), and builtin commands ‘complete’, | |
11927 | ‘compgen’, and ‘compopt’, to manipulate it. | |
11928 | ||
11929 | • Bash decodes a number of backslash-escape sequences in the prompt | |
11930 | string variables (‘PS0’, ‘PS1’, ‘PS2’, and ‘PS4’) (*note | |
11931 | Controlling the Prompt::). | |
11932 | ||
11933 | • Bash expands and displays the ‘PS0’ prompt string variable. | |
11934 | ||
11935 | • Bash runs commands from the ‘PROMPT_COMMAND’ array variable before | |
11936 | issuing each primary prompt. | |
11937 | ||
11938 | • Bash has command history (*note Bash History Facilities::) and the | |
11939 | ‘history’ and ‘fc’ builtins to manipulate it. The Bash history | |
11940 | list maintains timestamp information and uses the value of the | |
11941 | ‘HISTTIMEFORMAT’ variable to display it. | |
11942 | ||
11943 | • Bash implements ‘csh’-like history expansion (*note History | |
11944 | Interaction::). | |
11945 | ||
11946 | • Bash supports the ‘$'...'’ quoting syntax, which expands ANSI-C | |
11947 | backslash-escaped characters in the text between the single quotes | |
11948 | (*note ANSI-C Quoting::). | |
11949 | ||
11950 | • Bash supports the ‘$"..."’ quoting syntax and performs | |
11951 | locale-specific translation of the characters between the double | |
11952 | quotes. The ‘-D’, ‘--dump-strings’, and ‘--dump-po-strings’ | |
11953 | invocation options list the translatable strings found in a script | |
11954 | (*note Locale Translation::). | |
11955 | ||
11956 | • Bash includes brace expansion (*note Brace Expansion::) and tilde | |
11957 | expansion (*note Tilde Expansion::). | |
11958 | ||
11959 | • Bash implements command aliases and the ‘alias’ and ‘unalias’ | |
11960 | builtins (*note Aliases::). | |
11961 | ||
11962 | • Bash implements the ‘!’ reserved word to negate the return value of | |
11963 | a pipeline (*note Pipelines::). This is very useful when an ‘if’ | |
11964 | statement needs to act only if a test fails. The Bash ‘-o | |
11965 | pipefail’ option to ‘set’ will cause a pipeline to return a failure | |
11966 | status if any command fails (*note The Set Builtin::). | |
11967 | ||
11968 | • Bash has the ‘time’ reserved word and command timing (*note | |
11969 | Pipelines::). The display of the timing statistics may be | |
11970 | controlled with the ‘TIMEFORMAT’ variable. | |
11971 | ||
11972 | • Bash provides coprocesses and the ‘coproc’ reserved word (*note | |
11973 | Coprocesses::). | |
11974 | ||
11975 | • Bash implements the ‘for (( EXPR1 ; EXPR2 ; EXPR3 ))’ arithmetic | |
11976 | for command, similar to the C language (*note Looping | |
11977 | Constructs::). | |
11978 | ||
11979 | • Bash includes the ‘select’ compound command, which allows the | |
11980 | generation of simple menus (*note Conditional Constructs::). | |
11981 | ||
11982 | • Bash includes the ‘[[’ compound command, which makes conditional | |
11983 | testing part of the shell grammar (*note Conditional Constructs::), | |
11984 | including optional regular expression matching. | |
11985 | ||
11986 | • Bash provides optional case-insensitive matching for the ‘case’ and | |
11987 | ‘[[’ constructs (*note Conditional Constructs::). | |
11988 | ||
11989 | • Bash provides additional ‘case’ statement action list terminators: | |
11990 | ‘;&’ and ‘;;&’ (*note Conditional Constructs::). | |
11991 | ||
11992 | • Bash provides shell arithmetic, the ‘((’ compound command (*note | |
11993 | Conditional Constructs::), the ‘let’ builtin, and arithmetic | |
11994 | expansion (*note Shell Arithmetic::). | |
11995 | ||
11996 | • Bash has one-dimensional array variables (*note Arrays::), and the | |
11997 | appropriate variable expansions and assignment syntax to use them. | |
11998 | Several of the Bash builtins take options to act on arrays. Bash | |
11999 | provides a number of built-in array variables. | |
12000 | ||
12001 | • Variables present in the shell's initial environment are | |
12002 | automatically exported to child processes (*note Command Execution | |
12003 | Environment::). The Bourne shell does not normally do this unless | |
12004 | the variables are explicitly marked using the ‘export’ command. | |
12005 | ||
12006 | • Bash can expand positional parameters beyond ‘$9’ using ‘${NUM}’ | |
12007 | (*note Shell Parameter Expansion::). | |
12008 | ||
12009 | • Bash supports the ‘+=’ assignment operator, which appends to the | |
12010 | value of the variable named on the left hand side (*note Shell | |
12011 | Parameters::). | |
12012 | ||
12013 | • Bash includes the POSIX pattern removal ‘%’, ‘#’, ‘%%’ and ‘##’ | |
12014 | expansions to remove leading or trailing substrings from variable | |
12015 | values (*note Shell Parameter Expansion::). | |
12016 | ||
12017 | • The expansion ‘${#xx}’, which returns the length of ‘${xx}’, is | |
12018 | supported (*note Shell Parameter Expansion::). | |
12019 | ||
12020 | • The expansion ‘${var:’OFFSET‘[:’LENGTH‘]}’, which expands to the | |
12021 | substring of ‘var’'s value of length LENGTH, beginning at OFFSET, | |
12022 | is present (*note Shell Parameter Expansion::). | |
12023 | ||
12024 | • The expansion ‘${VAR/[/]’PATTERN‘[/’REPLACEMENT‘]}’, which matches | |
12025 | PATTERN and replaces it with REPLACEMENT in the value of VAR, is | |
12026 | available (*note Shell Parameter Expansion::), with a mechanism to | |
12027 | use the matched text in REPLACEMENT. | |
12028 | ||
12029 | • The expansion ‘${!PREFIX*}’ expansion, which expands to the names | |
12030 | of all shell variables whose names begin with PREFIX, is available | |
12031 | (*note Shell Parameter Expansion::). | |
12032 | ||
12033 | • Bash has indirect variable expansion using ‘${!word}’ (*note Shell | |
12034 | Parameter Expansion::) and implements the ‘nameref’ variable | |
12035 | attribute for automatic indirect variable expansion. | |
12036 | ||
12037 | • Bash includes a set of parameter transformation word expansions of | |
12038 | the form ‘${var@X}’, where ‘X’ specifies the transformation (*note | |
12039 | Shell Parameter Expansion::). | |
12040 | ||
12041 | • The POSIX ‘$()’ form of command substitution is implemented (*note | |
12042 | Command Substitution::), and preferred to the Bourne shell's ‘``’ | |
12043 | (which is also implemented for backwards compatibility). | |
12044 | ||
12045 | • Bash implements a variant of command substitution that runs the | |
12046 | enclosed command in the current shell execution environment: ‘${ | |
12047 | COMMAND;}’ or ‘${|COMMAND;}’ (*note Command Substitution::). | |
12048 | ||
12049 | • Bash has process substitution (*note Process Substitution::). | |
12050 | ||
12051 | • Bash automatically assigns variables that provide information about | |
12052 | the current user (‘UID’, ‘EUID’, and ‘GROUPS’), the current host | |
12053 | (‘HOSTTYPE’, ‘OSTYPE’, ‘MACHTYPE’, and ‘HOSTNAME’), and the | |
12054 | instance of Bash that is running (‘BASH’, ‘BASH_VERSION’, and | |
12055 | ‘BASH_VERSINFO’). *Note Bash Variables::, for details. | |
12056 | ||
12057 | • Bash uses many variables to provide functionality and customize | |
12058 | shell behavior that the Bourne shell does not. Examples include | |
12059 | ‘RANDOM’, ‘SRANDOM’, ‘EPOCHSECONDS’, ‘EPOCHREALTIME’, ‘TIMEFORMAT’, | |
12060 | ‘BASHPID’, ‘BASH_XTRACEFD’, ‘GLOBIGNORE’, ‘HISTIGNORE’, and | |
12061 | ‘BASH_VERSION’. *Note Bash Variables::, for a complete list. | |
12062 | ||
12063 | • Bash uses the ‘GLOBSORT’ shell variable to control how to sort the | |
12064 | results of filename expansion (*note Filename Expansion::). | |
12065 | ||
12066 | • Bash uses the ‘IFS’ variable to split only the results of | |
12067 | expansion, not all words (*note Word Splitting::). This closes a | |
12068 | longstanding shell security hole. | |
12069 | ||
12070 | • The filename expansion bracket expression code uses ‘!’ and ‘^’ to | |
12071 | negate the set of characters between the brackets (*note Filename | |
12072 | Expansion::). The Bourne shell uses only ‘!’. | |
12073 | ||
12074 | • Bash implements the full set of POSIX filename expansion operators, | |
12075 | including character classes, equivalence classes, and collating | |
12076 | symbols (*note Filename Expansion::). | |
12077 | ||
12078 | • Bash implements extended pattern matching features when the | |
12079 | ‘extglob’ shell option is enabled (*note Pattern Matching::). | |
12080 | ||
12081 | • The ‘globstar’ shell option extends filename expansion to | |
12082 | recursively scan directories and subdirectories for matching | |
12083 | filenames (*note Pattern Matching::). | |
12084 | ||
12085 | • It is possible to have a variable and a function with the same | |
12086 | name; ‘sh’ does not separate the two name spaces. | |
12087 | ||
12088 | • Bash functions are permitted to have local variables using the | |
12089 | ‘local’ builtin, and thus users can write useful recursive | |
12090 | functions (*note Bash Builtins::). | |
12091 | ||
12092 | • Bash performs filename expansion on filenames specified as operands | |
12093 | to input and output redirection operators (*note Redirections::). | |
12094 | ||
12095 | • Bash contains the ‘<>’ redirection operator, allowing a file to be | |
12096 | opened for both reading and writing, and the ‘&>’ redirection | |
12097 | operator, for directing standard output and standard error to the | |
12098 | same file (*note Redirections::). | |
12099 | ||
12100 | • Bash includes the ‘<<<’ redirection operator, allowing a string to | |
12101 | be used as the standard input to a command (*note Redirections::). | |
12102 | ||
12103 | • Bash implements the ‘[n]<&WORD’ and ‘[n]>&WORD’ redirection | |
12104 | operators, which move one file descriptor to another. | |
12105 | ||
12106 | • Bash treats a number of filenames specially when they are used in | |
12107 | redirection operators (*note Redirections::). | |
12108 | ||
12109 | • Bash provides the {VAR}<WORD capability to have the shell allocate | |
12110 | file descriptors for redirections and assign them to VAR (*note | |
12111 | Redirections::). This works with multiple redirection operators. | |
12112 | ||
12113 | • Bash can open network connections to arbitrary machines and | |
12114 | services with the redirection operators (*note Redirections::). | |
12115 | ||
12116 | • The ‘noclobber’ option is available to avoid overwriting existing | |
12117 | files with output redirection (*note The Set Builtin::). The ‘>|’ | |
12118 | redirection operator may be used to override ‘noclobber’. | |
12119 | ||
12120 | • Variable assignments preceding commands affect only that command, | |
12121 | even builtins and functions (*note Environment::). In ‘sh’, all | |
12122 | variable assignments preceding commands are global unless the | |
12123 | command is executed from the file system. | |
12124 | ||
12125 | • Bash includes a number of features to support a separate debugger | |
12126 | for shell scripts: variables (‘BASH_ARGC’, ‘BASH_ARGV’, | |
12127 | ‘BASH_LINENO’, ‘BASH_SOURCE’), the ‘DEBUG’, ‘RETURN’, and ‘ERR’ | |
12128 | traps, ‘declare -F’, and the ‘caller’ builtin. | |
12129 | ||
12130 | • Bash implements a ‘csh’-like directory stack, and provides the | |
12131 | ‘pushd’, ‘popd’, and ‘dirs’ builtins to manipulate it (*note The | |
12132 | Directory Stack::). Bash also makes the directory stack visible as | |
12133 | the value of the ‘DIRSTACK’ shell variable. | |
12134 | ||
12135 | • Bash allows a function to override a builtin with the same name, | |
12136 | and provides access to that builtin's functionality within the | |
12137 | function via the ‘builtin’ and ‘command’ builtins (*note Bash | |
12138 | Builtins::). | |
12139 | ||
12140 | • Bash includes the ‘caller’ builtin (*note Bash Builtins::), which | |
12141 | displays the context of any active subroutine call (a shell | |
12142 | function or a script executed with the ‘.’ or ‘source’ builtins). | |
12143 | This supports the Bash debugger. | |
12144 | ||
12145 | • The Bash ‘cd’ and ‘pwd’ builtins (*note Bourne Shell Builtins::) | |
12146 | each take ‘-L’ and ‘-P’ options to switch between logical and | |
12147 | physical modes. | |
12148 | ||
12149 | • The ‘command’ builtin allows selectively skipping shell functions | |
12150 | when performing command lookup (*note Bash Builtins::). | |
12151 | ||
12152 | • Bash uses the ‘declare’ builtin to modify the full set of variable | |
12153 | and function attributes, and to assign values to variables. | |
12154 | ||
12155 | • The ‘disown’ builtin can remove a job from the internal shell job | |
12156 | table (*note Job Control Builtins::) or suppress sending ‘SIGHUP’ | |
12157 | to a job when the shell exits as the result of a ‘SIGHUP’. | |
12158 | ||
12159 | • The ‘enable’ builtin (*note Bash Builtins::) can enable or disable | |
12160 | individual builtins and implements support for dynamically loading | |
12161 | builtin commands from shared objects. | |
12162 | ||
12163 | • The Bash ‘exec’ builtin takes additional options that allow users | |
12164 | to control the contents of the environment passed to the executed | |
12165 | command, and what the zeroth argument to the command is to be | |
12166 | (*note Bourne Shell Builtins::). | |
12167 | ||
12168 | • Shell functions may be exported to children via the environment | |
12169 | using ‘export -f’ (*note Shell Functions::). | |
12170 | ||
12171 | • The Bash ‘export’ and ‘readonly’ builtins (*note Bourne Shell | |
12172 | Builtins:: can take a ‘-f’ option to act on shell functions, a ‘-p’ | |
12173 | option to display variables with various attributes set in a format | |
12174 | that can be used as shell input, a ‘-n’ option to remove various | |
12175 | variable attributes, and ‘name=value’ arguments to set variable | |
12176 | attributes and values simultaneously. | |
12177 | ||
12178 | • The Bash ‘hash’ builtin allows a name to be associated with an | |
12179 | arbitrary filename, even when that filename cannot be found by | |
12180 | searching the ‘$PATH’, using ‘hash -p’ (*note Bourne Shell | |
12181 | Builtins::). | |
12182 | ||
12183 | • Bash includes a ‘help’ builtin for quick reference to shell | |
12184 | facilities (*note Bash Builtins::). | |
12185 | ||
12186 | • Bash includes the ‘mapfile’ builtin to quickly read the contents of | |
12187 | a file into an indexed array variable (*note Bash Builtins::). | |
12188 | ||
12189 | • The ‘printf’ builtin is available to display formatted output | |
12190 | (*note Bash Builtins::), and has additional custom format | |
12191 | specifiers and an option to assign the formatted output directly to | |
12192 | a shell variable. | |
12193 | ||
12194 | • The Bash ‘read’ builtin (*note Bash Builtins::) will read a line | |
12195 | ending in ‘\’ with the ‘-r’ option, and will use the ‘REPLY’ | |
12196 | variable as a default if no non-option arguments are supplied. | |
12197 | ||
12198 | • The ‘read’ builtin (*note Bash Builtins::) accepts a prompt string | |
12199 | with the ‘-p’ option and will use Readline to obtain the line when | |
12200 | given the ‘-e’ or ‘-E’ options, with the ability to insert text | |
12201 | into the line using the ‘-i’ option. The ‘read’ builtin also has | |
12202 | additional options to control input: the ‘-s’ option will turn off | |
12203 | echoing of input characters as they are read, the ‘-t’ option will | |
12204 | allow ‘read’ to time out if input does not arrive within a | |
12205 | specified number of seconds, the ‘-n’ option will allow reading | |
12206 | only a specified number of characters rather than a full line, and | |
12207 | the ‘-d’ option will read until a particular character rather than | |
12208 | newline. | |
12209 | ||
12210 | • The ‘return’ builtin may be used to abort execution of scripts | |
12211 | executed with the ‘.’ or ‘source’ builtins (*note Bourne Shell | |
12212 | Builtins::). | |
12213 | ||
12214 | • Bash has much more optional behavior controllable with the ‘set’ | |
12215 | builtin (*note The Set Builtin::). | |
12216 | ||
12217 | • The ‘-x’ (‘xtrace’) option displays commands other than simple | |
12218 | commands when performing an execution trace (*note The Set | |
12219 | Builtin::). | |
12220 | ||
12221 | • Bash includes the ‘shopt’ builtin, for finer control of shell | |
12222 | optional capabilities (*note The Shopt Builtin::), and allows these | |
12223 | options to be set and unset at shell invocation (*note Invoking | |
12224 | Bash::). | |
12225 | ||
12226 | • The ‘test’ builtin (*note Bourne Shell Builtins::) is slightly | |
12227 | different, as it implements the POSIX algorithm, which specifies | |
12228 | the behavior based on the number of arguments. | |
12229 | ||
12230 | • The ‘trap’ builtin (*note Bourne Shell Builtins::) allows a ‘DEBUG’ | |
12231 | pseudo-signal specification, similar to ‘EXIT’. Commands specified | |
12232 | with a ‘DEBUG’ trap are executed before every simple command, ‘for’ | |
12233 | command, ‘case’ command, ‘select’ command, every arithmetic ‘for’ | |
12234 | command, and before the first command executes in a shell function. | |
12235 | The ‘DEBUG’ trap is not inherited by shell functions unless the | |
12236 | function has been given the ‘trace’ attribute or the ‘functrace’ | |
12237 | option has been enabled using the ‘shopt’ builtin. The ‘extdebug’ | |
12238 | shell option has additional effects on the ‘DEBUG’ trap. | |
12239 | ||
12240 | The ‘trap’ builtin (*note Bourne Shell Builtins::) allows an ‘ERR’ | |
12241 | pseudo-signal specification, similar to ‘EXIT’ and ‘DEBUG’. | |
12242 | Commands specified with an ‘ERR’ trap are executed after a simple | |
12243 | command fails, with a few exceptions. The ‘ERR’ trap is not | |
12244 | inherited by shell functions unless the ‘-o errtrace’ option to the | |
12245 | ‘set’ builtin is enabled. | |
12246 | ||
12247 | The ‘trap’ builtin (*note Bourne Shell Builtins::) allows a | |
12248 | ‘RETURN’ pseudo-signal specification, similar to ‘EXIT’ and | |
12249 | ‘DEBUG’. Commands specified with a ‘RETURN’ trap are executed | |
12250 | before execution resumes after a shell function or a shell script | |
12251 | executed with ‘.’ or ‘source’ returns. The ‘RETURN’ trap is not | |
12252 | inherited by shell functions unless the function has been given the | |
12253 | ‘trace’ attribute or the ‘functrace’ option has been enabled using | |
12254 | the ‘shopt’ builtin. | |
12255 | ||
12256 | • The Bash ‘type’ builtin is more extensive and gives more | |
12257 | information about the names it finds (*note Bash Builtins::). | |
12258 | ||
12259 | • The ‘ulimit’ builtin provides control over many more per-process | |
12260 | resources (*note Bash Builtins::). | |
12261 | ||
12262 | • The Bash ‘umask’ builtin uses the ‘-p’ option to display the output | |
12263 | in the form of a ‘umask’ command that may be reused as input (*note | |
12264 | Bourne Shell Builtins::). | |
12265 | ||
12266 | • The Bash ‘wait’ builtin has a ‘-n’ option to wait for the next | |
12267 | child to exit, possibly selecting from a list of supplied jobs, and | |
12268 | the ‘-p’ option to store information about a terminated child | |
12269 | process in a shell variable. | |
12270 | ||
12271 | • The SVR4.2 shell behaves differently when invoked as ‘jsh’ (it | |
12272 | turns on job control). | |
12273 | ||
12274 | • The SVR4.2 shell has two privilege-related builtins (‘mldmode’ and | |
12275 | ‘priv’) not present in Bash. | |
12276 | ||
12277 | • Bash does not have the ‘stop’ or ‘newgrp’ builtins. | |
12278 | ||
12279 | • Bash does not use the ‘SHACCT’ variable or perform shell | |
12280 | accounting. | |
12281 | ||
12282 | • The SVR4.2 ‘sh’ uses a ‘TIMEOUT’ variable like Bash uses ‘TMOUT’. | |
12283 | ||
12284 | More features unique to Bash may be found in *note Bash Features::. | |
12285 | ||
12286 | B.1 Implementation Differences From The SVR4.2 Shell | |
12287 | ==================================================== | |
12288 | ||
12289 | Since Bash is a completely new implementation, it does not suffer from | |
12290 | many of the limitations of the SVR4.2 shell. For instance: | |
12291 | ||
12292 | • Bash does not fork a subshell when redirecting into or out of a | |
12293 | shell control structure such as an ‘if’ or ‘while’ statement. | |
12294 | ||
12295 | • Bash does not allow unbalanced quotes. The SVR4.2 shell will | |
12296 | silently insert a needed closing quote at ‘EOF’ under certain | |
12297 | circumstances. This can be the cause of some hard-to-find errors. | |
12298 | ||
12299 | • The SVR4.2 shell uses a baroque memory management scheme based on | |
12300 | trapping ‘SIGSEGV’. If the shell is started from a process with | |
12301 | ‘SIGSEGV’ blocked (e.g., by using the ‘system()’ C library function | |
12302 | call), it misbehaves badly. | |
12303 | ||
12304 | • In a questionable attempt at security, the SVR4.2 shell, when | |
12305 | invoked without the ‘-p’ option, will alter its real and effective | |
12306 | UID and GID if they are less than some magic threshold value, | |
12307 | commonly 100. This can lead to unexpected results. | |
12308 | ||
12309 | • The SVR4.2 shell does not allow users to trap ‘SIGSEGV’, ‘SIGALRM’, | |
12310 | or ‘SIGCHLD’. | |
12311 | ||
12312 | • The SVR4.2 shell does not allow the ‘IFS’, ‘MAILCHECK’, ‘PATH’, | |
12313 | ‘PS1’, or ‘PS2’ variables to be unset. | |
12314 | ||
12315 | • The SVR4.2 shell treats ‘^’ as the undocumented equivalent of ‘|’. | |
12316 | ||
12317 | • Bash allows multiple option arguments when it is invoked (‘-x -v’); | |
12318 | the SVR4.2 shell allows only one option argument (‘-xv’). In fact, | |
12319 | some versions of the shell dump core if the second argument begins | |
12320 | with a ‘-’. | |
12321 | ||
12322 | • The SVR4.2 shell exits a script if any builtin fails; Bash exits a | |
12323 | script only if one of the POSIX special builtins fails, and only | |
12324 | for certain failures, as enumerated in the POSIX standard. | |
12325 | ||
12326 | • If the ‘lastpipe’ option is enabled, and job control is not active, | |
12327 | Bash runs the last element of a pipeline in the current shell | |
12328 | execution environment. | |
12329 | ||
12330 | \1f | |
12331 | File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top | |
12332 | ||
12333 | Appendix C GNU Free Documentation License | |
12334 | ***************************************** | |
12335 | ||
12336 | Version 1.3, 3 November 2008 | |
12337 | ||
12338 | Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. | |
12339 | <http://fsf.org/> | |
12340 | ||
12341 | Everyone is permitted to copy and distribute verbatim copies | |
12342 | of this license document, but changing it is not allowed. | |
12343 | ||
12344 | 0. PREAMBLE | |
12345 | ||
12346 | The purpose of this License is to make a manual, textbook, or other | |
12347 | functional and useful document “free” in the sense of freedom: to | |
12348 | assure everyone the effective freedom to copy and redistribute it, | |
12349 | with or without modifying it, either commercially or | |
12350 | noncommercially. Secondarily, this License preserves for the | |
12351 | author and publisher a way to get credit for their work, while not | |
12352 | being considered responsible for modifications made by others. | |
12353 | ||
12354 | This License is a kind of "copyleft", which means that derivative | |
12355 | works of the document must themselves be free in the same sense. | |
12356 | It complements the GNU General Public License, which is a copyleft | |
12357 | license designed for free software. | |
12358 | ||
12359 | We have designed this License in order to use it for manuals for | |
12360 | free software, because free software needs free documentation: a | |
12361 | free program should come with manuals providing the same freedoms | |
12362 | that the software does. But this License is not limited to | |
12363 | software manuals; it can be used for any textual work, regardless | |
12364 | of subject matter or whether it is published as a printed book. We | |
12365 | recommend this License principally for works whose purpose is | |
12366 | instruction or reference. | |
12367 | ||
12368 | 1. APPLICABILITY AND DEFINITIONS | |
12369 | ||
12370 | This License applies to any manual or other work, in any medium, | |
12371 | that contains a notice placed by the copyright holder saying it can | |
12372 | be distributed under the terms of this License. Such a notice | |
12373 | grants a world-wide, royalty-free license, unlimited in duration, | |
12374 | to use that work under the conditions stated herein. The | |
12375 | "Document", below, refers to any such manual or work. Any member | |
12376 | of the public is a licensee, and is addressed as "you". You accept | |
12377 | the license if you copy, modify or distribute the work in a way | |
12378 | requiring permission under copyright law. | |
12379 | ||
12380 | A "Modified Version" of the Document means any work containing the | |
12381 | Document or a portion of it, either copied verbatim, or with | |
12382 | modifications and/or translated into another language. | |
12383 | ||
12384 | A "Secondary Section" is a named appendix or a front-matter section | |
12385 | of the Document that deals exclusively with the relationship of the | |
12386 | publishers or authors of the Document to the Document's overall | |
12387 | subject (or to related matters) and contains nothing that could | |
12388 | fall directly within that overall subject. (Thus, if the Document | |
12389 | is in part a textbook of mathematics, a Secondary Section may not | |
12390 | explain any mathematics.) The relationship could be a matter of | |
12391 | historical connection with the subject or with related matters, or | |
12392 | of legal, commercial, philosophical, ethical or political position | |
12393 | regarding them. | |
12394 | ||
12395 | The "Invariant Sections" are certain Secondary Sections whose | |
12396 | titles are designated, as being those of Invariant Sections, in the | |
12397 | notice that says that the Document is released under this License. | |
12398 | If a section does not fit the above definition of Secondary then it | |
12399 | is not allowed to be designated as Invariant. The Document may | |
12400 | contain zero Invariant Sections. If the Document does not identify | |
12401 | any Invariant Sections then there are none. | |
12402 | ||
12403 | The "Cover Texts" are certain short passages of text that are | |
12404 | listed, as Front-Cover Texts or Back-Cover Texts, in the notice | |
12405 | that says that the Document is released under this License. A | |
12406 | Front-Cover Text may be at most 5 words, and a Back-Cover Text may | |
12407 | be at most 25 words. | |
12408 | ||
12409 | A "Transparent" copy of the Document means a machine-readable copy, | |
12410 | represented in a format whose specification is available to the | |
12411 | general public, that is suitable for revising the document | |
12412 | straightforwardly with generic text editors or (for images composed | |
12413 | of pixels) generic paint programs or (for drawings) some widely | |
12414 | available drawing editor, and that is suitable for input to text | |
12415 | formatters or for automatic translation to a variety of formats | |
12416 | suitable for input to text formatters. A copy made in an otherwise | |
12417 | Transparent file format whose markup, or absence of markup, has | |
12418 | been arranged to thwart or discourage subsequent modification by | |
12419 | readers is not Transparent. An image format is not Transparent if | |
12420 | used for any substantial amount of text. A copy that is not | |
12421 | "Transparent" is called "Opaque". | |
12422 | ||
12423 | Examples of suitable formats for Transparent copies include plain | |
12424 | ASCII without markup, Texinfo input format, LaTeX input format, | |
12425 | SGML or XML using a publicly available DTD, and standard-conforming | |
12426 | simple HTML, PostScript or PDF designed for human modification. | |
12427 | Examples of transparent image formats include PNG, XCF and JPG. | |
12428 | Opaque formats include proprietary formats that can be read and | |
12429 | edited only by proprietary word processors, SGML or XML for which | |
12430 | the DTD and/or processing tools are not generally available, and | |
12431 | the machine-generated HTML, PostScript or PDF produced by some word | |
12432 | processors for output purposes only. | |
12433 | ||
12434 | The "Title Page" means, for a printed book, the title page itself, | |
12435 | plus such following pages as are needed to hold, legibly, the | |
12436 | material this License requires to appear in the title page. For | |
12437 | works in formats which do not have any title page as such, "Title | |
12438 | Page" means the text near the most prominent appearance of the | |
12439 | work's title, preceding the beginning of the body of the text. | |
12440 | ||
12441 | The "publisher" means any person or entity that distributes copies | |
12442 | of the Document to the public. | |
12443 | ||
12444 | A section "Entitled XYZ" means a named subunit of the Document | |
12445 | whose title either is precisely XYZ or contains XYZ in parentheses | |
12446 | following text that translates XYZ in another language. (Here XYZ | |
12447 | stands for a specific section name mentioned below, such as | |
12448 | "Acknowledgements", "Dedications", "Endorsements", or "History".) | |
12449 | To "Preserve the Title" of such a section when you modify the | |
12450 | Document means that it remains a section "Entitled XYZ" according | |
12451 | to this definition. | |
12452 | ||
12453 | The Document may include Warranty Disclaimers next to the notice | |
12454 | which states that this License applies to the Document. These | |
12455 | Warranty Disclaimers are considered to be included by reference in | |
12456 | this License, but only as regards disclaiming warranties: any other | |
12457 | implication that these Warranty Disclaimers may have is void and | |
12458 | has no effect on the meaning of this License. | |
12459 | ||
12460 | 2. VERBATIM COPYING | |
12461 | ||
12462 | You may copy and distribute the Document in any medium, either | |
12463 | commercially or noncommercially, provided that this License, the | |
12464 | copyright notices, and the license notice saying this License | |
12465 | applies to the Document are reproduced in all copies, and that you | |
12466 | add no other conditions whatsoever to those of this License. You | |
12467 | may not use technical measures to obstruct or control the reading | |
12468 | or further copying of the copies you make or distribute. However, | |
12469 | you may accept compensation in exchange for copies. If you | |
12470 | distribute a large enough number of copies you must also follow the | |
12471 | conditions in section 3. | |
12472 | ||
12473 | You may also lend copies, under the same conditions stated above, | |
12474 | and you may publicly display copies. | |
12475 | ||
12476 | 3. COPYING IN QUANTITY | |
12477 | ||
12478 | If you publish printed copies (or copies in media that commonly | |
12479 | have printed covers) of the Document, numbering more than 100, and | |
12480 | the Document's license notice requires Cover Texts, you must | |
12481 | enclose the copies in covers that carry, clearly and legibly, all | |
12482 | these Cover Texts: Front-Cover Texts on the front cover, and | |
12483 | Back-Cover Texts on the back cover. Both covers must also clearly | |
12484 | and legibly identify you as the publisher of these copies. The | |
12485 | front cover must present the full title with all words of the title | |
12486 | equally prominent and visible. You may add other material on the | |
12487 | covers in addition. Copying with changes limited to the covers, as | |
12488 | long as they preserve the title of the Document and satisfy these | |
12489 | conditions, can be treated as verbatim copying in other respects. | |
12490 | ||
12491 | If the required texts for either cover are too voluminous to fit | |
12492 | legibly, you should put the first ones listed (as many as fit | |
12493 | reasonably) on the actual cover, and continue the rest onto | |
12494 | adjacent pages. | |
12495 | ||
12496 | If you publish or distribute Opaque copies of the Document | |
12497 | numbering more than 100, you must either include a machine-readable | |
12498 | Transparent copy along with each Opaque copy, or state in or with | |
12499 | each Opaque copy a computer-network location from which the general | |
12500 | network-using public has access to download using public-standard | |
12501 | network protocols a complete Transparent copy of the Document, free | |
12502 | of added material. If you use the latter option, you must take | |
12503 | reasonably prudent steps, when you begin distribution of Opaque | |
12504 | copies in quantity, to ensure that this Transparent copy will | |
12505 | remain thus accessible at the stated location until at least one | |
12506 | year after the last time you distribute an Opaque copy (directly or | |
12507 | through your agents or retailers) of that edition to the public. | |
12508 | ||
12509 | It is requested, but not required, that you contact the authors of | |
12510 | the Document well before redistributing any large number of copies, | |
12511 | to give them a chance to provide you with an updated version of the | |
12512 | Document. | |
12513 | ||
12514 | 4. MODIFICATIONS | |
12515 | ||
12516 | You may copy and distribute a Modified Version of the Document | |
12517 | under the conditions of sections 2 and 3 above, provided that you | |
12518 | release the Modified Version under precisely this License, with the | |
12519 | Modified Version filling the role of the Document, thus licensing | |
12520 | distribution and modification of the Modified Version to whoever | |
12521 | possesses a copy of it. In addition, you must do these things in | |
12522 | the Modified Version: | |
12523 | ||
12524 | A. Use in the Title Page (and on the covers, if any) a title | |
12525 | distinct from that of the Document, and from those of previous | |
12526 | versions (which should, if there were any, be listed in the | |
12527 | History section of the Document). You may use the same title | |
12528 | as a previous version if the original publisher of that | |
12529 | version gives permission. | |
12530 | ||
12531 | B. List on the Title Page, as authors, one or more persons or | |
12532 | entities responsible for authorship of the modifications in | |
12533 | the Modified Version, together with at least five of the | |
12534 | principal authors of the Document (all of its principal | |
12535 | authors, if it has fewer than five), unless they release you | |
12536 | from this requirement. | |
12537 | ||
12538 | C. State on the Title page the name of the publisher of the | |
12539 | Modified Version, as the publisher. | |
12540 | ||
12541 | D. Preserve all the copyright notices of the Document. | |
12542 | ||
12543 | E. Add an appropriate copyright notice for your modifications | |
12544 | adjacent to the other copyright notices. | |
12545 | ||
12546 | F. Include, immediately after the copyright notices, a license | |
12547 | notice giving the public permission to use the Modified | |
12548 | Version under the terms of this License, in the form shown in | |
12549 | the Addendum below. | |
12550 | ||
12551 | G. Preserve in that license notice the full lists of Invariant | |
12552 | Sections and required Cover Texts given in the Document's | |
12553 | license notice. | |
12554 | ||
12555 | H. Include an unaltered copy of this License. | |
12556 | ||
12557 | I. Preserve the section Entitled "History", Preserve its Title, | |
12558 | and add to it an item stating at least the title, year, new | |
12559 | authors, and publisher of the Modified Version as given on the | |
12560 | Title Page. If there is no section Entitled "History" in the | |
12561 | Document, create one stating the title, year, authors, and | |
12562 | publisher of the Document as given on its Title Page, then add | |
12563 | an item describing the Modified Version as stated in the | |
12564 | previous sentence. | |
12565 | ||
12566 | J. Preserve the network location, if any, given in the Document | |
12567 | for public access to a Transparent copy of the Document, and | |
12568 | likewise the network locations given in the Document for | |
12569 | previous versions it was based on. These may be placed in the | |
12570 | "History" section. You may omit a network location for a work | |
12571 | that was published at least four years before the Document | |
12572 | itself, or if the original publisher of the version it refers | |
12573 | to gives permission. | |
12574 | ||
12575 | K. For any section Entitled "Acknowledgements" or "Dedications", | |
12576 | Preserve the Title of the section, and preserve in the section | |
12577 | all the substance and tone of each of the contributor | |
12578 | acknowledgements and/or dedications given therein. | |
12579 | ||
12580 | L. Preserve all the Invariant Sections of the Document, unaltered | |
12581 | in their text and in their titles. Section numbers or the | |
12582 | equivalent are not considered part of the section titles. | |
12583 | ||
12584 | M. Delete any section Entitled "Endorsements". Such a section | |
12585 | may not be included in the Modified Version. | |
12586 | ||
12587 | N. Do not retitle any existing section to be Entitled | |
12588 | "Endorsements" or to conflict in title with any Invariant | |
12589 | Section. | |
12590 | ||
12591 | O. Preserve any Warranty Disclaimers. | |
12592 | ||
12593 | If the Modified Version includes new front-matter sections or | |
12594 | appendices that qualify as Secondary Sections and contain no | |
12595 | material copied from the Document, you may at your option designate | |
12596 | some or all of these sections as invariant. To do this, add their | |
12597 | titles to the list of Invariant Sections in the Modified Version's | |
12598 | license notice. These titles must be distinct from any other | |
12599 | section titles. | |
12600 | ||
12601 | You may add a section Entitled "Endorsements", provided it contains | |
12602 | nothing but endorsements of your Modified Version by various | |
12603 | parties--for example, statements of peer review or that the text | |
12604 | has been approved by an organization as the authoritative | |
12605 | definition of a standard. | |
12606 | ||
12607 | You may add a passage of up to five words as a Front-Cover Text, | |
12608 | and a passage of up to 25 words as a Back-Cover Text, to the end of | |
12609 | the list of Cover Texts in the Modified Version. Only one passage | |
12610 | of Front-Cover Text and one of Back-Cover Text may be added by (or | |
12611 | through arrangements made by) any one entity. If the Document | |
12612 | already includes a cover text for the same cover, previously added | |
12613 | by you or by arrangement made by the same entity you are acting on | |
12614 | behalf of, you may not add another; but you may replace the old | |
12615 | one, on explicit permission from the previous publisher that added | |
12616 | the old one. | |
12617 | ||
12618 | The author(s) and publisher(s) of the Document do not by this | |
12619 | License give permission to use their names for publicity for or to | |
12620 | assert or imply endorsement of any Modified Version. | |
12621 | ||
12622 | 5. COMBINING DOCUMENTS | |
12623 | ||
12624 | You may combine the Document with other documents released under | |
12625 | this License, under the terms defined in section 4 above for | |
12626 | modified versions, provided that you include in the combination all | |
12627 | of the Invariant Sections of all of the original documents, | |
12628 | unmodified, and list them all as Invariant Sections of your | |
12629 | combined work in its license notice, and that you preserve all | |
12630 | their Warranty Disclaimers. | |
12631 | ||
12632 | The combined work need only contain one copy of this License, and | |
12633 | multiple identical Invariant Sections may be replaced with a single | |
12634 | copy. If there are multiple Invariant Sections with the same name | |
12635 | but different contents, make the title of each such section unique | |
12636 | by adding at the end of it, in parentheses, the name of the | |
12637 | original author or publisher of that section if known, or else a | |
12638 | unique number. Make the same adjustment to the section titles in | |
12639 | the list of Invariant Sections in the license notice of the | |
12640 | combined work. | |
12641 | ||
12642 | In the combination, you must combine any sections Entitled | |
12643 | "History" in the various original documents, forming one section | |
12644 | Entitled "History"; likewise combine any sections Entitled | |
12645 | "Acknowledgements", and any sections Entitled "Dedications". You | |
12646 | must delete all sections Entitled "Endorsements." | |
12647 | ||
12648 | 6. COLLECTIONS OF DOCUMENTS | |
12649 | ||
12650 | You may make a collection consisting of the Document and other | |
12651 | documents released under this License, and replace the individual | |
12652 | copies of this License in the various documents with a single copy | |
12653 | that is included in the collection, provided that you follow the | |
12654 | rules of this License for verbatim copying of each of the documents | |
12655 | in all other respects. | |
12656 | ||
12657 | You may extract a single document from such a collection, and | |
12658 | distribute it individually under this License, provided you insert | |
12659 | a copy of this License into the extracted document, and follow this | |
12660 | License in all other respects regarding verbatim copying of that | |
12661 | document. | |
12662 | ||
12663 | 7. AGGREGATION WITH INDEPENDENT WORKS | |
12664 | ||
12665 | A compilation of the Document or its derivatives with other | |
12666 | separate and independent documents or works, in or on a volume of a | |
12667 | storage or distribution medium, is called an "aggregate" if the | |
12668 | copyright resulting from the compilation is not used to limit the | |
12669 | legal rights of the compilation's users beyond what the individual | |
12670 | works permit. When the Document is included in an aggregate, this | |
12671 | License does not apply to the other works in the aggregate which | |
12672 | are not themselves derivative works of the Document. | |
12673 | ||
12674 | If the Cover Text requirement of section 3 is applicable to these | |
12675 | copies of the Document, then if the Document is less than one half | |
12676 | of the entire aggregate, the Document's Cover Texts may be placed | |
12677 | on covers that bracket the Document within the aggregate, or the | |
12678 | electronic equivalent of covers if the Document is in electronic | |
12679 | form. Otherwise they must appear on printed covers that bracket | |
12680 | the whole aggregate. | |
12681 | ||
12682 | 8. TRANSLATION | |
12683 | ||
12684 | Translation is considered a kind of modification, so you may | |
12685 | distribute translations of the Document under the terms of section | |
12686 | 4. Replacing Invariant Sections with translations requires special | |
12687 | permission from their copyright holders, but you may include | |
12688 | translations of some or all Invariant Sections in addition to the | |
12689 | original versions of these Invariant Sections. You may include a | |
12690 | translation of this License, and all the license notices in the | |
12691 | Document, and any Warranty Disclaimers, provided that you also | |
12692 | include the original English version of this License and the | |
12693 | original versions of those notices and disclaimers. In case of a | |
12694 | disagreement between the translation and the original version of | |
12695 | this License or a notice or disclaimer, the original version will | |
12696 | prevail. | |
12697 | ||
12698 | If a section in the Document is Entitled "Acknowledgements", | |
12699 | "Dedications", or "History", the requirement (section 4) to | |
12700 | Preserve its Title (section 1) will typically require changing the | |
12701 | actual title. | |
12702 | ||
12703 | 9. TERMINATION | |
12704 | ||
12705 | You may not copy, modify, sublicense, or distribute the Document | |
12706 | except as expressly provided under this License. Any attempt | |
12707 | otherwise to copy, modify, sublicense, or distribute it is void, | |
12708 | and will automatically terminate your rights under this License. | |
12709 | ||
12710 | However, if you cease all violation of this License, then your | |
12711 | license from a particular copyright holder is reinstated (a) | |
12712 | provisionally, unless and until the copyright holder explicitly and | |
12713 | finally terminates your license, and (b) permanently, if the | |
12714 | copyright holder fails to notify you of the violation by some | |
12715 | reasonable means prior to 60 days after the cessation. | |
12716 | ||
12717 | Moreover, your license from a particular copyright holder is | |
12718 | reinstated permanently if the copyright holder notifies you of the | |
12719 | violation by some reasonable means, this is the first time you have | |
12720 | received notice of violation of this License (for any work) from | |
12721 | that copyright holder, and you cure the violation prior to 30 days | |
12722 | after your receipt of the notice. | |
12723 | ||
12724 | Termination of your rights under this section does not terminate | |
12725 | the licenses of parties who have received copies or rights from you | |
12726 | under this License. If your rights have been terminated and not | |
12727 | permanently reinstated, receipt of a copy of some or all of the | |
12728 | same material does not give you any rights to use it. | |
12729 | ||
12730 | 10. FUTURE REVISIONS OF THIS LICENSE | |
12731 | ||
12732 | The Free Software Foundation may publish new, revised versions of | |
12733 | the GNU Free Documentation License from time to time. Such new | |
12734 | versions will be similar in spirit to the present version, but may | |
12735 | differ in detail to address new problems or concerns. See | |
12736 | <http://www.gnu.org/copyleft/>. | |
12737 | ||
12738 | Each version of the License is given a distinguishing version | |
12739 | number. If the Document specifies that a particular numbered | |
12740 | version of this License "or any later version" applies to it, you | |
12741 | have the option of following the terms and conditions either of | |
12742 | that specified version or of any later version that has been | |
12743 | published (not as a draft) by the Free Software Foundation. If the | |
12744 | Document does not specify a version number of this License, you may | |
12745 | choose any version ever published (not as a draft) by the Free | |
12746 | Software Foundation. If the Document specifies that a proxy can | |
12747 | decide which future versions of this License can be used, that | |
12748 | proxy's public statement of acceptance of a version permanently | |
12749 | authorizes you to choose that version for the Document. | |
12750 | ||
12751 | 11. RELICENSING | |
12752 | ||
12753 | "Massive Multiauthor Collaboration Site" (or "MMC Site") means any | |
12754 | World Wide Web server that publishes copyrightable works and also | |
12755 | provides prominent facilities for anybody to edit those works. A | |
12756 | public wiki that anybody can edit is an example of such a server. | |
12757 | A "Massive Multiauthor Collaboration" (or "MMC") contained in the | |
12758 | site means any set of copyrightable works thus published on the MMC | |
12759 | site. | |
12760 | ||
12761 | "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 | |
12762 | license published by Creative Commons Corporation, a not-for-profit | |
12763 | corporation with a principal place of business in San Francisco, | |
12764 | California, as well as future copyleft versions of that license | |
12765 | published by that same organization. | |
12766 | ||
12767 | "Incorporate" means to publish or republish a Document, in whole or | |
12768 | in part, as part of another Document. | |
12769 | ||
12770 | An MMC is "eligible for relicensing" if it is licensed under this | |
12771 | License, and if all works that were first published under this | |
12772 | License somewhere other than this MMC, and subsequently | |
12773 | incorporated in whole or in part into the MMC, (1) had no cover | |
12774 | texts or invariant sections, and (2) were thus incorporated prior | |
12775 | to November 1, 2008. | |
12776 | ||
12777 | The operator of an MMC Site may republish an MMC contained in the | |
12778 | site under CC-BY-SA on the same site at any time before August 1, | |
12779 | 2009, provided the MMC is eligible for relicensing. | |
12780 | ||
12781 | ADDENDUM: How to use this License for your documents | |
12782 | ==================================================== | |
12783 | ||
12784 | To use this License in a document you have written, include a copy of | |
12785 | the License in the document and put the following copyright and license | |
12786 | notices just after the title page: | |
12787 | ||
12788 | Copyright (C) YEAR YOUR NAME. | |
12789 | Permission is granted to copy, distribute and/or modify this document | |
12790 | under the terms of the GNU Free Documentation License, Version 1.3 | |
12791 | or any later version published by the Free Software Foundation; | |
12792 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover | |
12793 | Texts. A copy of the license is included in the section entitled ``GNU | |
12794 | Free Documentation License''. | |
12795 | ||
12796 | If you have Invariant Sections, Front-Cover Texts and Back-Cover | |
12797 | Texts, replace the "with...Texts." line with this: | |
12798 | ||
12799 | with the Invariant Sections being LIST THEIR TITLES, with | |
12800 | the Front-Cover Texts being LIST, and with the Back-Cover Texts | |
12801 | being LIST. | |
12802 | ||
12803 | If you have Invariant Sections without Cover Texts, or some other | |
12804 | combination of the three, merge those two alternatives to suit the | |
12805 | situation. | |
12806 | ||
12807 | If your document contains nontrivial examples of program code, we | |
12808 | recommend releasing these examples in parallel under your choice of free | |
12809 | software license, such as the GNU General Public License, to permit | |
12810 | their use in free software. | |
12811 | ||
12812 | \1f | |
12813 | File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top | |
12814 | ||
12815 | Appendix D Indexes | |
12816 | ****************** | |
12817 | ||
12818 | * Menu: | |
12819 | ||
12820 | * Builtin Index:: Index of Bash builtin commands. | |
12821 | * Reserved Word Index:: Index of Bash reserved words. | |
12822 | * Variable Index:: Quick reference helps you find the | |
12823 | variable you want. | |
12824 | * Function Index:: Index of bindable Readline functions. | |
12825 | * Concept Index:: General index for concepts described in | |
12826 | this manual. | |
12827 | ||
12828 | \1f | |
12829 | File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes | |
12830 | ||
12831 | D.1 Index of Shell Builtin Commands | |
12832 | =================================== | |
12833 | ||
12834 | \0\b[index\0\b] | |
12835 | * Menu: | |
12836 | ||
12837 | * :: Bourne Shell Builtins. | |
12838 | (line 11) | |
12839 | * .: Bourne Shell Builtins. | |
12840 | (line 17) | |
12841 | * [: Bourne Shell Builtins. | |
12842 | (line 339) | |
12843 | * alias: Bash Builtins. (line 11) | |
12844 | * bg: Job Control Builtins. | |
12845 | (line 7) | |
12846 | * bind: Bash Builtins. (line 24) | |
12847 | * break: Bourne Shell Builtins. | |
12848 | (line 47) | |
12849 | * builtin: Bash Builtins. (line 133) | |
12850 | * caller: Bash Builtins. (line 142) | |
12851 | * cd: Bourne Shell Builtins. | |
12852 | (line 55) | |
12853 | * command: Bash Builtins. (line 159) | |
12854 | * compgen: Programmable Completion Builtins. | |
12855 | (line 12) | |
12856 | * complete: Programmable Completion Builtins. | |
12857 | (line 37) | |
12858 | * compopt: Programmable Completion Builtins. | |
12859 | (line 258) | |
12860 | * continue: Bourne Shell Builtins. | |
12861 | (line 106) | |
12862 | * declare: Bash Builtins. (line 179) | |
12863 | * dirs: Directory Stack Builtins. | |
12864 | (line 7) | |
12865 | * disown: Job Control Builtins. | |
12866 | (line 120) | |
12867 | * echo: Bash Builtins. (line 284) | |
12868 | * enable: Bash Builtins. (line 337) | |
12869 | * eval: Bourne Shell Builtins. | |
12870 | (line 115) | |
12871 | * exec: Bourne Shell Builtins. | |
12872 | (line 123) | |
12873 | * exit: Bourne Shell Builtins. | |
12874 | (line 145) | |
12875 | * export: Bourne Shell Builtins. | |
12876 | (line 152) | |
12877 | * false: Bourne Shell Builtins. | |
12878 | (line 175) | |
12879 | * fc: Bash History Builtins. | |
12880 | (line 10) | |
12881 | * fg: Job Control Builtins. | |
12882 | (line 17) | |
12883 | * getopts: Bourne Shell Builtins. | |
12884 | (line 180) | |
12885 | * hash: Bourne Shell Builtins. | |
12886 | (line 232) | |
12887 | * help: Bash Builtins. (line 375) | |
12888 | * history: Bash History Builtins. | |
12889 | (line 59) | |
12890 | * jobs: Job Control Builtins. | |
12891 | (line 28) | |
12892 | * kill: Job Control Builtins. | |
12893 | (line 61) | |
12894 | * let: Bash Builtins. (line 404) | |
12895 | * local: Bash Builtins. (line 413) | |
12896 | * logout: Bash Builtins. (line 438) | |
12897 | * mapfile: Bash Builtins. (line 443) | |
12898 | * popd: Directory Stack Builtins. | |
12899 | (line 37) | |
12900 | * printf: Bash Builtins. (line 488) | |
12901 | * pushd: Directory Stack Builtins. | |
12902 | (line 71) | |
12903 | * pwd: Bourne Shell Builtins. | |
12904 | (line 264) | |
12905 | * read: Bash Builtins. (line 558) | |
12906 | * readarray: Bash Builtins. (line 669) | |
12907 | * readonly: Bourne Shell Builtins. | |
12908 | (line 276) | |
12909 | * return: Bourne Shell Builtins. | |
12910 | (line 301) | |
12911 | * set: The Set Builtin. (line 11) | |
12912 | * shift: Bourne Shell Builtins. | |
12913 | (line 326) | |
12914 | * shopt: The Shopt Builtin. (line 9) | |
12915 | * source: Bash Builtins. (line 678) | |
12916 | * suspend: Job Control Builtins. | |
12917 | (line 139) | |
12918 | * test: Bourne Shell Builtins. | |
12919 | (line 339) | |
12920 | * times: Bourne Shell Builtins. | |
12921 | (line 439) | |
12922 | * trap: Bourne Shell Builtins. | |
12923 | (line 445) | |
12924 | * true: Bourne Shell Builtins. | |
12925 | (line 511) | |
12926 | * type: Bash Builtins. (line 683) | |
12927 | * typeset: Bash Builtins. (line 720) | |
12928 | * ulimit: Bash Builtins. (line 726) | |
12929 | * umask: Bourne Shell Builtins. | |
12930 | (line 516) | |
12931 | * unalias: Bash Builtins. (line 834) | |
12932 | * unset: Bourne Shell Builtins. | |
12933 | (line 534) | |
12934 | * wait: Job Control Builtins. | |
12935 | (line 86) | |
12936 | ||
12937 | \1f | |
12938 | File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes | |
12939 | ||
12940 | D.2 Index of Shell Reserved Words | |
12941 | ================================= | |
12942 | ||
12943 | \0\b[index\0\b] | |
12944 | * Menu: | |
12945 | ||
12946 | * !: Pipelines. (line 9) | |
12947 | * [[: Conditional Constructs. | |
12948 | (line 128) | |
12949 | * ]]: Conditional Constructs. | |
12950 | (line 128) | |
12951 | * {: Command Grouping. (line 21) | |
12952 | * }: Command Grouping. (line 21) | |
12953 | * case: Conditional Constructs. | |
12954 | (line 28) | |
12955 | * do: Looping Constructs. (line 12) | |
12956 | * done: Looping Constructs. (line 12) | |
12957 | * elif: Conditional Constructs. | |
12958 | (line 7) | |
12959 | * else: Conditional Constructs. | |
12960 | (line 7) | |
12961 | * esac: Conditional Constructs. | |
12962 | (line 28) | |
12963 | * fi: Conditional Constructs. | |
12964 | (line 7) | |
12965 | * for: Looping Constructs. (line 32) | |
12966 | * function: Shell Functions. (line 13) | |
12967 | * if: Conditional Constructs. | |
12968 | (line 7) | |
12969 | * in: Conditional Constructs. | |
12970 | (line 28) | |
12971 | * select: Conditional Constructs. | |
12972 | (line 84) | |
12973 | * then: Conditional Constructs. | |
12974 | (line 7) | |
12975 | * time: Pipelines. (line 9) | |
12976 | * until: Looping Constructs. (line 12) | |
12977 | * while: Looping Constructs. (line 22) | |
12978 | ||
12979 | \1f | |
12980 | File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes | |
12981 | ||
12982 | D.3 Parameter and Variable Index | |
12983 | ================================ | |
12984 | ||
12985 | \0\b[index\0\b] | |
12986 | * Menu: | |
12987 | ||
12988 | * _: Bash Variables. (line 13) | |
12989 | * -: Special Parameters. (line 48) | |
12990 | * !: Special Parameters. (line 57) | |
12991 | * ?: Special Parameters. (line 44) | |
12992 | * @: Special Parameters. (line 23) | |
12993 | * *: Special Parameters. (line 10) | |
12994 | * #: Special Parameters. (line 41) | |
12995 | * $: Special Parameters. (line 53) | |
12996 | * $_: Bash Variables. (line 14) | |
12997 | * $-: Special Parameters. (line 49) | |
12998 | * $!: Special Parameters. (line 58) | |
12999 | * $?: Special Parameters. (line 45) | |
13000 | * $@: Special Parameters. (line 24) | |
13001 | * $*: Special Parameters. (line 11) | |
13002 | * $#: Special Parameters. (line 42) | |
13003 | * $$: Special Parameters. (line 54) | |
13004 | * $0: Special Parameters. (line 63) | |
13005 | * 0: Special Parameters. (line 62) | |
13006 | * active-region-end-color: Readline Init File Syntax. | |
13007 | (line 51) | |
13008 | * active-region-start-color: Readline Init File Syntax. | |
13009 | (line 38) | |
13010 | * auto_resume: Job Control Variables. | |
13011 | (line 6) | |
13012 | * BASH: Bash Variables. (line 24) | |
13013 | * BASH_ALIASES: Bash Variables. (line 44) | |
13014 | * BASH_ARGC: Bash Variables. (line 53) | |
13015 | * BASH_ARGV: Bash Variables. (line 67) | |
13016 | * BASH_ARGV0: Bash Variables. (line 80) | |
13017 | * BASH_CMDS: Bash Variables. (line 88) | |
13018 | * BASH_COMMAND: Bash Variables. (line 97) | |
13019 | * BASH_COMPAT: Bash Variables. (line 104) | |
13020 | * BASH_ENV: Bash Variables. (line 120) | |
13021 | * BASH_EXECUTION_STRING: Bash Variables. (line 126) | |
13022 | * BASH_LINENO: Bash Variables. (line 129) | |
13023 | * BASH_LOADABLES_PATH: Bash Variables. (line 139) | |
13024 | * BASH_MONOSECONDS: Bash Variables. (line 143) | |
13025 | * BASH_REMATCH: Bash Variables. (line 150) | |
13026 | * BASH_SOURCE: Bash Variables. (line 158) | |
13027 | * BASH_SUBSHELL: Bash Variables. (line 166) | |
13028 | * BASH_TRAPSIG: Bash Variables. (line 172) | |
13029 | * BASH_VERSINFO: Bash Variables. (line 178) | |
13030 | * BASH_VERSION: Bash Variables. (line 201) | |
13031 | * BASH_XTRACEFD: Bash Variables. (line 205) | |
13032 | * BASHOPTS: Bash Variables. (line 27) | |
13033 | * BASHPID: Bash Variables. (line 37) | |
13034 | * bell-style: Readline Init File Syntax. | |
13035 | (line 64) | |
13036 | * bind-tty-special-chars: Readline Init File Syntax. | |
13037 | (line 71) | |
13038 | * blink-matching-paren: Readline Init File Syntax. | |
13039 | (line 79) | |
13040 | * CDPATH: Bourne Shell Variables. | |
13041 | (line 9) | |
13042 | * CHILD_MAX: Bash Variables. (line 217) | |
13043 | * colored-completion-prefix: Readline Init File Syntax. | |
13044 | (line 84) | |
13045 | * colored-stats: Readline Init File Syntax. | |
13046 | (line 94) | |
13047 | * COLUMNS: Bash Variables. (line 224) | |
13048 | * comment-begin: Readline Init File Syntax. | |
13049 | (line 100) | |
13050 | * COMP_CWORD: Bash Variables. (line 230) | |
13051 | * COMP_KEY: Bash Variables. (line 236) | |
13052 | * COMP_LINE: Bash Variables. (line 242) | |
13053 | * COMP_POINT: Bash Variables. (line 247) | |
13054 | * COMP_TYPE: Bash Variables. (line 255) | |
13055 | * COMP_WORDBREAKS: Bash Variables. (line 265) | |
13056 | * COMP_WORDS: Bash Variables. (line 271) | |
13057 | * completion-display-width: Readline Init File Syntax. | |
13058 | (line 104) | |
13059 | * completion-ignore-case: Readline Init File Syntax. | |
13060 | (line 111) | |
13061 | * completion-map-case: Readline Init File Syntax. | |
13062 | (line 116) | |
13063 | * completion-prefix-display-length: Readline Init File Syntax. | |
13064 | (line 122) | |
13065 | * completion-query-items: Readline Init File Syntax. | |
13066 | (line 131) | |
13067 | * COMPREPLY: Bash Variables. (line 278) | |
13068 | * convert-meta: Readline Init File Syntax. | |
13069 | (line 142) | |
13070 | * COPROC: Bash Variables. (line 284) | |
13071 | * DIRSTACK: Bash Variables. (line 288) | |
13072 | * disable-completion: Readline Init File Syntax. | |
13073 | (line 154) | |
13074 | * echo-control-characters: Readline Init File Syntax. | |
13075 | (line 159) | |
13076 | * editing-mode: Readline Init File Syntax. | |
13077 | (line 164) | |
13078 | * EMACS: Bash Variables. (line 298) | |
13079 | * emacs-mode-string: Readline Init File Syntax. | |
13080 | (line 170) | |
13081 | * enable-active-region The: Readline Init File Syntax. | |
13082 | (line 180) | |
13083 | * enable-bracketed-paste: Readline Init File Syntax. | |
13084 | (line 193) | |
13085 | * enable-keypad: Readline Init File Syntax. | |
13086 | (line 202) | |
13087 | * enable-meta-key: Readline Init File Syntax. | |
13088 | (line 207) | |
13089 | * ENV: Bash Variables. (line 303) | |
13090 | * EPOCHREALTIME: Bash Variables. (line 308) | |
13091 | * EPOCHSECONDS: Bash Variables. (line 316) | |
13092 | * EUID: Bash Variables. (line 323) | |
13093 | * EXECIGNORE: Bash Variables. (line 327) | |
13094 | * expand-tilde: Readline Init File Syntax. | |
13095 | (line 217) | |
13096 | * FCEDIT: Bash Variables. (line 339) | |
13097 | * FIGNORE: Bash Variables. (line 342) | |
13098 | * force-meta-prefix: Readline Init File Syntax. | |
13099 | (line 221) | |
13100 | * FUNCNAME: Bash Variables. (line 348) | |
13101 | * FUNCNEST: Bash Variables. (line 365) | |
13102 | * GLOBIGNORE: Bash Variables. (line 370) | |
13103 | * GLOBSORT: Bash Variables. (line 377) | |
13104 | * GROUPS: Bash Variables. (line 415) | |
13105 | * histchars: Bash Variables. (line 421) | |
13106 | * HISTCMD: Bash Variables. (line 437) | |
13107 | * HISTCONTROL: Bash Variables. (line 443) | |
13108 | * HISTFILE: Bash Variables. (line 461) | |
13109 | * HISTFILESIZE: Bash Variables. (line 467) | |
13110 | * HISTIGNORE: Bash Variables. (line 481) | |
13111 | * history-preserve-point: Readline Init File Syntax. | |
13112 | (line 234) | |
13113 | * history-size: Readline Init File Syntax. | |
13114 | (line 240) | |
13115 | * HISTSIZE: Bash Variables. (line 505) | |
13116 | * HISTTIMEFORMAT: Bash Variables. (line 512) | |
13117 | * HOME: Bourne Shell Variables. | |
13118 | (line 13) | |
13119 | * horizontal-scroll-mode: Readline Init File Syntax. | |
13120 | (line 250) | |
13121 | * HOSTFILE: Bash Variables. (line 521) | |
13122 | * HOSTNAME: Bash Variables. (line 532) | |
13123 | * HOSTTYPE: Bash Variables. (line 535) | |
13124 | * IFS: Bourne Shell Variables. | |
13125 | (line 18) | |
13126 | * IGNOREEOF: Bash Variables. (line 538) | |
13127 | * input-meta: Readline Init File Syntax. | |
13128 | (line 258) | |
13129 | * INPUTRC: Bash Variables. (line 547) | |
13130 | * INSIDE_EMACS: Bash Variables. (line 551) | |
13131 | * isearch-terminators: Readline Init File Syntax. | |
13132 | (line 269) | |
13133 | * keymap: Readline Init File Syntax. | |
13134 | (line 276) | |
13135 | * LANG: Creating Internationalized Scripts. | |
13136 | (line 51) | |
13137 | * LANG <1>: Bash Variables. (line 557) | |
13138 | * LC_ALL: Bash Variables. (line 561) | |
13139 | * LC_COLLATE: Bash Variables. (line 565) | |
13140 | * LC_CTYPE: Bash Variables. (line 572) | |
13141 | * LC_MESSAGES: Creating Internationalized Scripts. | |
13142 | (line 51) | |
13143 | * LC_MESSAGES <1>: Bash Variables. (line 577) | |
13144 | * LC_NUMERIC: Bash Variables. (line 581) | |
13145 | * LC_TIME: Bash Variables. (line 585) | |
13146 | * LINENO: Bash Variables. (line 589) | |
13147 | * LINES: Bash Variables. (line 596) | |
13148 | * MACHTYPE: Bash Variables. (line 602) | |
13149 | * MAIL: Bourne Shell Variables. | |
13150 | (line 24) | |
13151 | * MAILCHECK: Bash Variables. (line 606) | |
13152 | * MAILPATH: Bourne Shell Variables. | |
13153 | (line 29) | |
13154 | * MAPFILE: Bash Variables. (line 614) | |
13155 | * mark-modified-lines: Readline Init File Syntax. | |
13156 | (line 306) | |
13157 | * mark-symlinked-directories: Readline Init File Syntax. | |
13158 | (line 311) | |
13159 | * match-hidden-files: Readline Init File Syntax. | |
13160 | (line 316) | |
13161 | * menu-complete-display-prefix: Readline Init File Syntax. | |
13162 | (line 323) | |
13163 | * meta-flag: Readline Init File Syntax. | |
13164 | (line 258) | |
13165 | * OLDPWD: Bash Variables. (line 618) | |
13166 | * OPTARG: Bourne Shell Variables. | |
13167 | (line 36) | |
13168 | * OPTERR: Bash Variables. (line 621) | |
13169 | * OPTIND: Bourne Shell Variables. | |
13170 | (line 40) | |
13171 | * OSTYPE: Bash Variables. (line 626) | |
13172 | * output-meta: Readline Init File Syntax. | |
13173 | (line 328) | |
13174 | * page-completions: Readline Init File Syntax. | |
13175 | (line 337) | |
13176 | * PATH: Bourne Shell Variables. | |
13177 | (line 44) | |
13178 | * PIPESTATUS: Bash Variables. (line 629) | |
13179 | * POSIXLY_CORRECT: Bash Variables. (line 639) | |
13180 | * PPID: Bash Variables. (line 649) | |
13181 | * PROMPT_COMMAND: Bash Variables. (line 653) | |
13182 | * PROMPT_DIRTRIM: Bash Variables. (line 659) | |
13183 | * PS0: Bash Variables. (line 665) | |
13184 | * PS1: Bourne Shell Variables. | |
13185 | (line 53) | |
13186 | * PS2: Bourne Shell Variables. | |
13187 | (line 58) | |
13188 | * PS3: Bash Variables. (line 670) | |
13189 | * PS4: Bash Variables. (line 675) | |
13190 | * PWD: Bash Variables. (line 683) | |
13191 | * RANDOM: Bash Variables. (line 686) | |
13192 | * READLINE_ARGUMENT: Bash Variables. (line 694) | |
13193 | * READLINE_LINE: Bash Variables. (line 698) | |
13194 | * READLINE_MARK: Bash Variables. (line 702) | |
13195 | * READLINE_POINT: Bash Variables. (line 708) | |
13196 | * REPLY: Bash Variables. (line 712) | |
13197 | * revert-all-at-newline: Readline Init File Syntax. | |
13198 | (line 350) | |
13199 | * search-ignore-case: Readline Init File Syntax. | |
13200 | (line 357) | |
13201 | * SECONDS: Bash Variables. (line 716) | |
13202 | * SHELL: Bash Variables. (line 726) | |
13203 | * SHELLOPTS: Bash Variables. (line 731) | |
13204 | * SHLVL: Bash Variables. (line 741) | |
13205 | * show-all-if-ambiguous: Readline Init File Syntax. | |
13206 | (line 362) | |
13207 | * show-all-if-unmodified: Readline Init File Syntax. | |
13208 | (line 368) | |
13209 | * show-mode-in-prompt: Readline Init File Syntax. | |
13210 | (line 377) | |
13211 | * skip-completed-text: Readline Init File Syntax. | |
13212 | (line 383) | |
13213 | * SRANDOM: Bash Variables. (line 746) | |
13214 | * TEXTDOMAIN: Creating Internationalized Scripts. | |
13215 | (line 51) | |
13216 | * TEXTDOMAINDIR: Creating Internationalized Scripts. | |
13217 | (line 51) | |
13218 | * TIMEFORMAT: Bash Variables. (line 755) | |
13219 | * TMOUT: Bash Variables. (line 794) | |
13220 | * TMPDIR: Bash Variables. (line 806) | |
13221 | * UID: Bash Variables. (line 810) | |
13222 | * vi-cmd-mode-string: Readline Init File Syntax. | |
13223 | (line 396) | |
13224 | * vi-ins-mode-string: Readline Init File Syntax. | |
13225 | (line 407) | |
13226 | * visible-stats: Readline Init File Syntax. | |
13227 | (line 418) | |
13228 | ||
13229 | \1f | |
13230 | File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes | |
13231 | ||
13232 | D.4 Function Index | |
13233 | ================== | |
13234 | ||
13235 | \0\b[index\0\b] | |
13236 | * Menu: | |
13237 | ||
13238 | * abort (C-g): Miscellaneous Commands. | |
13239 | (line 10) | |
13240 | * accept-line (Newline or Return): Commands For History. | |
13241 | (line 6) | |
13242 | * alias-expand-line (): Miscellaneous Commands. | |
13243 | (line 134) | |
13244 | * backward-char (C-b): Commands For Moving. (line 18) | |
13245 | * backward-delete-char (Rubout): Commands For Text. (line 18) | |
13246 | * backward-kill-line (C-x Rubout): Commands For Killing. | |
13247 | (line 11) | |
13248 | * backward-kill-word (M-<DEL>): Commands For Killing. | |
13249 | (line 28) | |
13250 | * backward-word (M-b): Commands For Moving. (line 26) | |
13251 | * beginning-of-history (M-<): Commands For History. | |
13252 | (line 22) | |
13253 | * beginning-of-line (C-a): Commands For Moving. (line 6) | |
13254 | * bracketed-paste-begin (): Commands For Text. (line 35) | |
13255 | * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13) | |
13256 | * capitalize-word (M-c): Commands For Text. (line 73) | |
13257 | * character-search (C-]): Miscellaneous Commands. | |
13258 | (line 41) | |
13259 | * character-search-backward (M-C-]): Miscellaneous Commands. | |
13260 | (line 45) | |
13261 | * clear-display (M-C-l): Commands For Moving. (line 52) | |
13262 | * clear-screen (C-l): Commands For Moving. (line 57) | |
13263 | * complete (<TAB>): Commands For Completion. | |
13264 | (line 6) | |
13265 | * complete-command (M-!): Commands For Completion. | |
13266 | (line 105) | |
13267 | * complete-filename (M-/): Commands For Completion. | |
13268 | (line 74) | |
13269 | * complete-hostname (M-@): Commands For Completion. | |
13270 | (line 97) | |
13271 | * complete-into-braces (M-{): Commands For Completion. | |
13272 | (line 124) | |
13273 | * complete-username (M-~): Commands For Completion. | |
13274 | (line 81) | |
13275 | * complete-variable (M-$): Commands For Completion. | |
13276 | (line 89) | |
13277 | * copy-backward-word (): Commands For Killing. | |
13278 | (line 62) | |
13279 | * copy-forward-word (): Commands For Killing. | |
13280 | (line 67) | |
13281 | * copy-region-as-kill (): Commands For Killing. | |
13282 | (line 58) | |
13283 | * dabbrev-expand (): Commands For Completion. | |
13284 | (line 119) | |
13285 | * delete-char (C-d): Commands For Text. (line 12) | |
13286 | * delete-char-or-list (): Commands For Completion. | |
13287 | (line 68) | |
13288 | * delete-horizontal-space (): Commands For Killing. | |
13289 | (line 50) | |
13290 | * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) | |
13291 | * display-shell-version (C-x C-v): Miscellaneous Commands. | |
13292 | (line 148) | |
13293 | * do-lowercase-version (M-A, M-B, M-X, ...): Miscellaneous Commands. | |
13294 | (line 14) | |
13295 | * downcase-word (M-l): Commands For Text. (line 69) | |
13296 | * dump-functions (): Miscellaneous Commands. | |
13297 | (line 71) | |
13298 | * dump-macros (): Miscellaneous Commands. | |
13299 | (line 83) | |
13300 | * dump-variables (): Miscellaneous Commands. | |
13301 | (line 77) | |
13302 | * dynamic-complete-history (M-<TAB>): Commands For Completion. | |
13303 | (line 115) | |
13304 | * edit-and-execute-command (C-x C-e): Miscellaneous Commands. | |
13305 | (line 143) | |
13306 | * end-kbd-macro (C-x )): Keyboard Macros. (line 9) | |
13307 | * end-of-file (usually C-d): Commands For Text. (line 6) | |
13308 | * end-of-history (M->): Commands For History. | |
13309 | (line 25) | |
13310 | * end-of-line (C-e): Commands For Moving. (line 10) | |
13311 | * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. | |
13312 | (line 37) | |
13313 | * execute-named-command (M-x): Miscellaneous Commands. | |
13314 | (line 90) | |
13315 | * export-completions (): Commands For Completion. | |
13316 | (line 44) | |
13317 | * fetch-history (): Commands For History. | |
13318 | (line 108) | |
13319 | * forward-backward-delete-char (): Commands For Text. (line 23) | |
13320 | * forward-char (C-f): Commands For Moving. (line 14) | |
13321 | * forward-search-history (C-s): Commands For History. | |
13322 | (line 35) | |
13323 | * forward-word (M-f): Commands For Moving. (line 22) | |
13324 | * glob-complete-word (M-g): Miscellaneous Commands. | |
13325 | (line 103) | |
13326 | * glob-expand-word (C-x *): Miscellaneous Commands. | |
13327 | (line 108) | |
13328 | * glob-list-expansions (C-x g): Miscellaneous Commands. | |
13329 | (line 114) | |
13330 | * history-and-alias-expand-line (): Miscellaneous Commands. | |
13331 | (line 137) | |
13332 | * history-expand-line (M-^): Miscellaneous Commands. | |
13333 | (line 127) | |
13334 | * history-search-backward (): Commands For History. | |
13335 | (line 53) | |
13336 | * history-search-forward (): Commands For History. | |
13337 | (line 60) | |
13338 | * history-substring-search-backward (): Commands For History. | |
13339 | (line 67) | |
13340 | * history-substring-search-forward (): Commands For History. | |
13341 | (line 73) | |
13342 | * insert-comment (M-#): Miscellaneous Commands. | |
13343 | (line 59) | |
13344 | * insert-completions (M-*): Commands For Completion. | |
13345 | (line 24) | |
13346 | * insert-last-argument (M-. or M-_): Miscellaneous Commands. | |
13347 | (line 140) | |
13348 | * kill-line (C-k): Commands For Killing. | |
13349 | (line 6) | |
13350 | * kill-region (): Commands For Killing. | |
13351 | (line 54) | |
13352 | * kill-whole-line (): Commands For Killing. | |
13353 | (line 19) | |
13354 | * kill-word (M-d): Commands For Killing. | |
13355 | (line 23) | |
13356 | * magic-space (): Miscellaneous Commands. | |
13357 | (line 130) | |
13358 | * menu-complete (): Commands For Completion. | |
13359 | (line 28) | |
13360 | * menu-complete-backward (): Commands For Completion. | |
13361 | (line 39) | |
13362 | * next-history (C-n): Commands For History. | |
13363 | (line 18) | |
13364 | * next-screen-line (): Commands For Moving. (line 45) | |
13365 | * non-incremental-forward-search-history (M-n): Commands For History. | |
13366 | (line 47) | |
13367 | * non-incremental-reverse-search-history (M-p): Commands For History. | |
13368 | (line 41) | |
13369 | * operate-and-get-next (C-o): Commands For History. | |
13370 | (line 101) | |
13371 | * overwrite-mode (): Commands For Text. (line 77) | |
13372 | * possible-command-completions (C-x !): Commands For Completion. | |
13373 | (line 111) | |
13374 | * possible-completions (M-?): Commands For Completion. | |
13375 | (line 17) | |
13376 | * possible-filename-completions (C-x /): Commands For Completion. | |
13377 | (line 77) | |
13378 | * possible-hostname-completions (C-x @): Commands For Completion. | |
13379 | (line 101) | |
13380 | * possible-username-completions (C-x ~): Commands For Completion. | |
13381 | (line 85) | |
13382 | * possible-variable-completions (C-x $): Commands For Completion. | |
13383 | (line 93) | |
13384 | * prefix-meta (<ESC>): Miscellaneous Commands. | |
13385 | (line 19) | |
13386 | * previous-history (C-p): Commands For History. | |
13387 | (line 13) | |
13388 | * previous-screen-line (): Commands For Moving. (line 38) | |
13389 | * print-last-kbd-macro (): Keyboard Macros. (line 17) | |
13390 | * quoted-insert (C-q or C-v): Commands For Text. (line 28) | |
13391 | * re-read-init-file (C-x C-r): Miscellaneous Commands. | |
13392 | (line 6) | |
13393 | * redraw-current-line (): Commands For Moving. (line 62) | |
13394 | * reverse-search-history (C-r): Commands For History. | |
13395 | (line 29) | |
13396 | * revert-line (M-r): Miscellaneous Commands. | |
13397 | (line 26) | |
13398 | * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 32) | |
13399 | * set-mark (C-@): Miscellaneous Commands. | |
13400 | (line 33) | |
13401 | * shell-backward-kill-word (): Commands For Killing. | |
13402 | (line 37) | |
13403 | * shell-backward-word (M-C-b): Commands For Moving. (line 34) | |
13404 | * shell-expand-line (M-C-e): Miscellaneous Commands. | |
13405 | (line 119) | |
13406 | * shell-forward-word (M-C-f): Commands For Moving. (line 30) | |
13407 | * shell-kill-word (M-C-d): Commands For Killing. | |
13408 | (line 32) | |
13409 | * shell-transpose-words (M-C-t): Commands For Text. (line 58) | |
13410 | * skip-csi-sequence (): Miscellaneous Commands. | |
13411 | (line 50) | |
13412 | * spell-correct-word (C-x s): Miscellaneous Commands. | |
13413 | (line 97) | |
13414 | * start-kbd-macro (C-x (): Keyboard Macros. (line 6) | |
13415 | * tilde-expand (M-&): Miscellaneous Commands. | |
13416 | (line 30) | |
13417 | * transpose-chars (C-t): Commands For Text. (line 47) | |
13418 | * transpose-words (M-t): Commands For Text. (line 53) | |
13419 | * undo (C-_ or C-x C-u): Miscellaneous Commands. | |
13420 | (line 23) | |
13421 | * universal-argument (): Numeric Arguments. (line 10) | |
13422 | * unix-filename-rubout (): Commands For Killing. | |
13423 | (line 45) | |
13424 | * unix-line-discard (C-u): Commands For Killing. | |
13425 | (line 16) | |
13426 | * unix-word-rubout (C-w): Commands For Killing. | |
13427 | (line 41) | |
13428 | * upcase-word (M-u): Commands For Text. (line 65) | |
13429 | * yank (C-y): Commands For Killing. | |
13430 | (line 72) | |
13431 | * yank-last-arg (M-. or M-_): Commands For History. | |
13432 | (line 89) | |
13433 | * yank-nth-arg (M-C-y): Commands For History. | |
13434 | (line 79) | |
13435 | * yank-pop (M-y): Commands For Killing. | |
13436 | (line 75) | |
13437 | ||
13438 | \1f | |
13439 | File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes | |
13440 | ||
13441 | D.5 Concept Index | |
13442 | ================= | |
13443 | ||
13444 | \0\b[index\0\b] | |
13445 | * Menu: | |
13446 | ||
13447 | * alias expansion: Aliases. (line 6) | |
13448 | * arithmetic evaluation: Shell Arithmetic. (line 6) | |
13449 | * arithmetic expansion: Arithmetic Expansion. | |
13450 | (line 6) | |
13451 | * arithmetic operators: Shell Arithmetic. (line 18) | |
13452 | * arithmetic, shell: Shell Arithmetic. (line 6) | |
13453 | * arrays: Arrays. (line 6) | |
13454 | * background: Job Control Basics. (line 6) | |
13455 | * Bash configuration: Basic Installation. (line 6) | |
13456 | * Bash installation: Basic Installation. (line 6) | |
13457 | * binary arithmetic operators: Shell Arithmetic. (line 18) | |
13458 | * bitwise arithmetic operators: Shell Arithmetic. (line 18) | |
13459 | * Bourne shell: Basic Shell Features. | |
13460 | (line 6) | |
13461 | * brace expansion: Brace Expansion. (line 6) | |
13462 | * builtin: Definitions. (line 21) | |
13463 | * command editing: Readline Bare Essentials. | |
13464 | (line 6) | |
13465 | * command execution: Command Search and Execution. | |
13466 | (line 6) | |
13467 | * command expansion: Simple Command Expansion. | |
13468 | (line 6) | |
13469 | * command history: Bash History Facilities. | |
13470 | (line 6) | |
13471 | * command search: Command Search and Execution. | |
13472 | (line 6) | |
13473 | * command substitution: Command Substitution. | |
13474 | (line 6) | |
13475 | * command timing: Pipelines. (line 9) | |
13476 | * commands, compound: Compound Commands. (line 6) | |
13477 | * commands, conditional: Conditional Constructs. | |
13478 | (line 6) | |
13479 | * commands, grouping: Command Grouping. (line 6) | |
13480 | * commands, lists: Lists. (line 6) | |
13481 | * commands, looping: Looping Constructs. (line 6) | |
13482 | * commands, pipelines: Pipelines. (line 6) | |
13483 | * commands, shell: Shell Commands. (line 6) | |
13484 | * commands, simple: Simple Commands. (line 6) | |
13485 | * comments, shell: Comments. (line 6) | |
13486 | * Compatibility Level: Shell Compatibility Mode. | |
13487 | (line 6) | |
13488 | * Compatibility Mode: Shell Compatibility Mode. | |
13489 | (line 6) | |
13490 | * completion builtins: Programmable Completion Builtins. | |
13491 | (line 6) | |
13492 | * conditional arithmetic operator: Shell Arithmetic. (line 18) | |
13493 | * configuration: Basic Installation. (line 6) | |
13494 | * control operator: Definitions. (line 25) | |
13495 | * coprocess: Coprocesses. (line 6) | |
13496 | * directory stack: The Directory Stack. (line 6) | |
13497 | * dollar-single quote quoting: ANSI-C Quoting. (line 6) | |
13498 | * editing command lines: Readline Bare Essentials. | |
13499 | (line 6) | |
13500 | * environment: Environment. (line 6) | |
13501 | * evaluation, arithmetic: Shell Arithmetic. (line 6) | |
13502 | * event designators: Event Designators. (line 6) | |
13503 | * execution environment: Command Execution Environment. | |
13504 | (line 6) | |
13505 | * exit status: Definitions. (line 30) | |
13506 | * exit status <1>: Exit Status. (line 6) | |
13507 | * expansion: Shell Expansions. (line 6) | |
13508 | * expansion, arithmetic: Arithmetic Expansion. | |
13509 | (line 6) | |
13510 | * expansion, brace: Brace Expansion. (line 6) | |
13511 | * expansion, filename: Filename Expansion. (line 9) | |
13512 | * expansion, parameter: Shell Parameter Expansion. | |
13513 | (line 6) | |
13514 | * expansion, pathname: Filename Expansion. (line 9) | |
13515 | * expansion, tilde: Tilde Expansion. (line 6) | |
13516 | * expressions, arithmetic: Shell Arithmetic. (line 6) | |
13517 | * expressions, conditional: Bash Conditional Expressions. | |
13518 | (line 6) | |
13519 | * field: Definitions. (line 34) | |
13520 | * filename: Definitions. (line 39) | |
13521 | * filename expansion: Filename Expansion. (line 9) | |
13522 | * foreground: Job Control Basics. (line 6) | |
13523 | * functions, shell: Shell Functions. (line 6) | |
13524 | * history builtins: Bash History Builtins. | |
13525 | (line 6) | |
13526 | * history events: Event Designators. (line 10) | |
13527 | * history expansion: History Interaction. (line 6) | |
13528 | * history list: Bash History Facilities. | |
13529 | (line 6) | |
13530 | * History, how to use: A Programmable Completion Example. | |
13531 | (line 113) | |
13532 | * identifier: Definitions. (line 55) | |
13533 | * initialization file, readline: Readline Init File. (line 6) | |
13534 | * installation: Basic Installation. (line 6) | |
13535 | * interaction, readline: Readline Interaction. | |
13536 | (line 6) | |
13537 | * interactive shell: Invoking Bash. (line 137) | |
13538 | * interactive shell <1>: Interactive Shells. (line 6) | |
13539 | * internationalization: Locale Translation. (line 6) | |
13540 | * internationalized scripts: Creating Internationalized Scripts. | |
13541 | (line 3) | |
13542 | * job: Definitions. (line 42) | |
13543 | * job control: Definitions. (line 46) | |
13544 | * job control <1>: Job Control Basics. (line 6) | |
13545 | * kill ring: Readline Killing Commands. | |
13546 | (line 18) | |
13547 | * killing text: Readline Killing Commands. | |
13548 | (line 6) | |
13549 | * localization: Locale Translation. (line 6) | |
13550 | * login shell: Invoking Bash. (line 134) | |
13551 | * matching, pattern: Pattern Matching. (line 6) | |
13552 | * metacharacter: Definitions. (line 50) | |
13553 | * name: Definitions. (line 55) | |
13554 | * native languages: Locale Translation. (line 6) | |
13555 | * notation, readline: Readline Bare Essentials. | |
13556 | (line 6) | |
13557 | * operator, shell: Definitions. (line 61) | |
13558 | * parameter expansion: Shell Parameter Expansion. | |
13559 | (line 6) | |
13560 | * parameters: Shell Parameters. (line 6) | |
13561 | * parameters, positional: Positional Parameters. | |
13562 | (line 6) | |
13563 | * parameters, special: Special Parameters. (line 6) | |
13564 | * pathname expansion: Filename Expansion. (line 9) | |
13565 | * pattern matching: Pattern Matching. (line 6) | |
13566 | * pipeline: Pipelines. (line 6) | |
13567 | * POSIX: Definitions. (line 9) | |
13568 | * POSIX description: Bash POSIX Mode. (line 9) | |
13569 | * POSIX Mode: Bash POSIX Mode. (line 48) | |
13570 | * process group: Definitions. (line 66) | |
13571 | * process group ID: Definitions. (line 70) | |
13572 | * process substitution: Process Substitution. | |
13573 | (line 6) | |
13574 | * programmable completion: Programmable Completion. | |
13575 | (line 6) | |
13576 | * prompting: Controlling the Prompt. | |
13577 | (line 6) | |
13578 | * quoting: Quoting. (line 6) | |
13579 | * quoting, ANSI: ANSI-C Quoting. (line 6) | |
13580 | * Readline, how to use: Job Control Variables. | |
13581 | (line 23) | |
13582 | * redirection: Redirections. (line 6) | |
13583 | * reserved word: Definitions. (line 74) | |
13584 | * reserved words: Reserved Words. (line 6) | |
13585 | * restricted shell: The Restricted Shell. | |
13586 | (line 6) | |
13587 | * return status: Definitions. (line 79) | |
13588 | * shell arithmetic: Shell Arithmetic. (line 6) | |
13589 | * shell function: Shell Functions. (line 6) | |
13590 | * shell script: Shell Scripts. (line 6) | |
13591 | * shell variable: Shell Parameters. (line 6) | |
13592 | * shell, interactive: Interactive Shells. (line 6) | |
13593 | * signal: Definitions. (line 82) | |
13594 | * signal handling: Signals. (line 6) | |
13595 | * special builtin: Definitions. (line 86) | |
13596 | * special builtin <1>: Special Builtins. (line 6) | |
13597 | * startup files: Bash Startup Files. (line 6) | |
13598 | * string translations: Creating Internationalized Scripts. | |
13599 | (line 3) | |
13600 | * suspending jobs: Job Control Basics. (line 6) | |
13601 | * tilde expansion: Tilde Expansion. (line 6) | |
13602 | * token: Definitions. (line 90) | |
13603 | * translation, native languages: Locale Translation. (line 6) | |
13604 | * unary arithmetic operators: Shell Arithmetic. (line 18) | |
13605 | * variable, shell: Shell Parameters. (line 6) | |
13606 | * variables, readline: Readline Init File Syntax. | |
13607 | (line 37) | |
13608 | * word: Definitions. (line 94) | |
13609 | * word splitting: Word Splitting. (line 6) | |
13610 | * yanking text: Readline Killing Commands. | |
13611 | (line 6) | |
13612 | ||
13613 | \1f | |
13614 | Tag Table: | |
13615 | Node: Top\7f894 | |
13616 | Node: Introduction\7f2828 | |
13617 | Node: What is Bash?\7f3044 | |
13618 | Node: What is a shell?\7f4180 | |
13619 | Node: Definitions\7f6793 | |
13620 | Node: Basic Shell Features\7f10123 | |
13621 | Node: Shell Syntax\7f11350 | |
13622 | Node: Shell Operation\7f12380 | |
13623 | Node: Quoting\7f13674 | |
13624 | Node: Escape Character\7f15015 | |
13625 | Node: Single Quotes\7f15553 | |
13626 | Node: Double Quotes\7f15905 | |
13627 | Node: ANSI-C Quoting\7f17253 | |
13628 | Node: Locale Translation\7f18650 | |
13629 | Node: Creating Internationalized Scripts\7f20056 | |
13630 | Node: Comments\7f24257 | |
13631 | Node: Shell Commands\7f25027 | |
13632 | Node: Reserved Words\7f25969 | |
13633 | Node: Simple Commands\7f26837 | |
13634 | Node: Pipelines\7f27502 | |
13635 | Node: Lists\7f30761 | |
13636 | Node: Compound Commands\7f32636 | |
13637 | Node: Looping Constructs\7f33648 | |
13638 | Node: Conditional Constructs\7f36200 | |
13639 | Node: Command Grouping\7f51273 | |
13640 | Node: Coprocesses\7f52768 | |
13641 | Node: GNU Parallel\7f55457 | |
13642 | Node: Shell Functions\7f56378 | |
13643 | Node: Shell Parameters\7f64829 | |
13644 | Node: Positional Parameters\7f69733 | |
13645 | Node: Special Parameters\7f70826 | |
13646 | Node: Shell Expansions\7f74290 | |
13647 | Node: Brace Expansion\7f76482 | |
13648 | Node: Tilde Expansion\7f79821 | |
13649 | Node: Shell Parameter Expansion\7f82779 | |
13650 | Node: Command Substitution\7f103425 | |
13651 | Node: Arithmetic Expansion\7f106957 | |
13652 | Node: Process Substitution\7f108136 | |
13653 | Node: Word Splitting\7f109247 | |
13654 | Node: Filename Expansion\7f111694 | |
13655 | Node: Pattern Matching\7f114921 | |
13656 | Node: Quote Removal\7f120647 | |
13657 | Node: Redirections\7f120954 | |
13658 | Node: Executing Commands\7f131220 | |
13659 | Node: Simple Command Expansion\7f131890 | |
13660 | Node: Command Search and Execution\7f134001 | |
13661 | Node: Command Execution Environment\7f136448 | |
13662 | Node: Environment\7f139899 | |
13663 | Node: Exit Status\7f141805 | |
13664 | Node: Signals\7f143866 | |
13665 | Node: Shell Scripts\7f148798 | |
13666 | Node: Shell Builtin Commands\7f152099 | |
13667 | Node: Bourne Shell Builtins\7f154213 | |
13668 | Node: Bash Builtins\7f180863 | |
13669 | Node: Modifying Shell Behavior\7f217790 | |
13670 | Node: The Set Builtin\7f218135 | |
13671 | Node: The Shopt Builtin\7f230132 | |
13672 | Node: Special Builtins\7f247187 | |
13673 | Node: Shell Variables\7f248179 | |
13674 | Node: Bourne Shell Variables\7f248616 | |
13675 | Node: Bash Variables\7f251127 | |
13676 | Node: Bash Features\7f290254 | |
13677 | Node: Invoking Bash\7f291271 | |
13678 | Node: Bash Startup Files\7f297858 | |
13679 | Node: Interactive Shells\7f303103 | |
13680 | Node: What is an Interactive Shell?\7f303514 | |
13681 | Node: Is this Shell Interactive?\7f304179 | |
13682 | Node: Interactive Shell Behavior\7f305006 | |
13683 | Node: Bash Conditional Expressions\7f308770 | |
13684 | Node: Shell Arithmetic\7f314190 | |
13685 | Node: Aliases\7f317522 | |
13686 | Node: Arrays\7f320659 | |
13687 | Node: The Directory Stack\7f328250 | |
13688 | Node: Directory Stack Builtins\7f329050 | |
13689 | Node: Controlling the Prompt\7f333498 | |
13690 | Node: The Restricted Shell\7f336386 | |
13691 | Node: Bash POSIX Mode\7f339271 | |
13692 | Node: Shell Compatibility Mode\7f358220 | |
13693 | Node: Job Control\7f367230 | |
13694 | Node: Job Control Basics\7f367690 | |
13695 | Node: Job Control Builtins\7f374061 | |
13696 | Node: Job Control Variables\7f380746 | |
13697 | Node: Command Line Editing\7f381980 | |
13698 | Node: Introduction and Notation\7f383686 | |
13699 | Node: Readline Interaction\7f386041 | |
13700 | Node: Readline Bare Essentials\7f387232 | |
13701 | Node: Readline Movement Commands\7f389043 | |
13702 | Node: Readline Killing Commands\7f390042 | |
13703 | Node: Readline Arguments\7f392068 | |
13704 | Node: Searching\7f393128 | |
13705 | Node: Readline Init File\7f395374 | |
13706 | Node: Readline Init File Syntax\7f396680 | |
13707 | Node: Conditional Init Constructs\7f423508 | |
13708 | Node: Sample Init File\7f427896 | |
13709 | Node: Bindable Readline Commands\7f431019 | |
13710 | Node: Commands For Moving\7f432560 | |
13711 | Node: Commands For History\7f435027 | |
13712 | Node: Commands For Text\7f440420 | |
13713 | Node: Commands For Killing\7f444548 | |
13714 | Node: Numeric Arguments\7f447339 | |
13715 | Node: Commands For Completion\7f448494 | |
13716 | Node: Keyboard Macros\7f454193 | |
13717 | Node: Miscellaneous Commands\7f454897 | |
13718 | Node: Readline vi Mode\7f461467 | |
13719 | Node: Programmable Completion\7f462447 | |
13720 | Node: Programmable Completion Builtins\7f471187 | |
13721 | Node: A Programmable Completion Example\7f482927 | |
13722 | Node: Using History Interactively\7f488275 | |
13723 | Node: Bash History Facilities\7f488959 | |
13724 | Node: Bash History Builtins\7f492697 | |
13725 | Node: History Interaction\7f499171 | |
13726 | Node: Event Designators\7f504124 | |
13727 | Node: Word Designators\7f505705 | |
13728 | Node: Modifiers\7f508100 | |
13729 | Node: Installing Bash\7f510040 | |
13730 | Node: Basic Installation\7f511159 | |
13731 | Node: Compilers and Options\7f515038 | |
13732 | Node: Compiling For Multiple Architectures\7f515791 | |
13733 | Node: Installation Names\7f517547 | |
13734 | Node: Specifying the System Type\7f519784 | |
13735 | Node: Sharing Defaults\7f520533 | |
13736 | Node: Operation Controls\7f521250 | |
13737 | Node: Optional Features\7f522272 | |
13738 | Node: Reporting Bugs\7f534655 | |
13739 | Node: Major Differences From The Bourne Shell\7f536015 | |
13740 | Node: GNU Free Documentation License\7f557444 | |
13741 | Node: Indexes\7f582624 | |
13742 | Node: Builtin Index\7f583078 | |
13743 | Node: Reserved Word Index\7f590179 | |
13744 | Node: Variable Index\7f592627 | |
13745 | Node: Function Index\7f610043 | |
13746 | Node: Concept Index\7f624041 | |
13747 | \1f | |
13748 | End Tag Table | |
13749 | ||
13750 | \1f | |
13751 | Local Variables: | |
13752 | coding: utf-8 | |
13753 | End: |