]>
Commit | Line | Data |
---|---|---|
74091dd4 | 1 | This is bashref.info, produced by makeinfo version 6.8 from |
a0c0a00f | 2 | bashref.texi. |
e8ce775d | 3 | |
a0c0a00f | 4 | This text is a brief description of the features that are present in the |
74091dd4 | 5 | Bash shell (version 5.2, 19 September 2022). |
ccc6cda3 | 6 | |
74091dd4 CR |
7 | This is Edition 5.2, last updated 19 September 2022, of 'The GNU Bash |
8 | Reference Manual', for 'Bash', Version 5.2. | |
ccc6cda3 | 9 | |
74091dd4 | 10 | Copyright (C) 1988-2022 Free Software Foundation, Inc. |
ccc6cda3 | 11 | |
b80f6443 JA |
12 | Permission is granted to copy, distribute and/or modify this |
13 | document under the terms of the GNU Free Documentation License, | |
0001803f | 14 | Version 1.3 or any later version published by the Free Software |
ac50fbac CR |
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". | |
b80f6443 JA |
18 | INFO-DIR-SECTION Basics |
19 | START-INFO-DIR-ENTRY | |
20 | * Bash: (bash). The GNU Bourne-Again SHell. | |
21 | END-INFO-DIR-ENTRY | |
ccc6cda3 JA |
22 | |
23 | \1f | |
24 | File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir) | |
25 | ||
26 | Bash Features | |
27 | ************* | |
28 | ||
a0c0a00f | 29 | This text is a brief description of the features that are present in the |
74091dd4 | 30 | Bash shell (version 5.2, 19 September 2022). The Bash home page is |
a0c0a00f | 31 | <http://www.gnu.org/software/bash/>. |
ccc6cda3 | 32 | |
74091dd4 CR |
33 | This is Edition 5.2, last updated 19 September 2022, of 'The GNU Bash |
34 | Reference Manual', for 'Bash', Version 5.2. | |
ccc6cda3 JA |
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 | |
a0c0a00f CR |
38 | borrowed concepts from are the Bourne Shell ('sh'), the Korn Shell |
39 | ('ksh'), and the C-shell ('csh' and its successor, 'tcsh'). The | |
ac50fbac CR |
40 | following menu breaks the features up into categories, noting which |
41 | features were inspired by other shells and which are specific to Bash. | |
ccc6cda3 JA |
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. | |
ccc6cda3 JA |
50 | * Definitions:: Some definitions used in the rest of this |
51 | manual. | |
ccc6cda3 | 52 | * Basic Shell Features:: The shell "building blocks". |
bb70624e | 53 | * Shell Builtin Commands:: Commands that are a part of the shell. |
bb70624e | 54 | * Shell Variables:: Variables used or set by Bash. |
ccc6cda3 | 55 | * Bash Features:: Features found only in Bash. |
95732b49 JA |
56 | * Job Control:: What job control is and how Bash allows you |
57 | to use it. | |
ccc6cda3 JA |
58 | * Command Line Editing:: Chapter describing the command line |
59 | editing features. | |
3185942a | 60 | * Using History Interactively:: Command History Expansion |
ccc6cda3 | 61 | * Installing Bash:: How to build and install Bash on your system. |
ccc6cda3 | 62 | * Reporting Bugs:: How to report bugs in Bash. |
bb70624e JA |
63 | * Major Differences From The Bourne Shell:: A terse list of the differences |
64 | between Bash and historical | |
65 | versions of /bin/sh. | |
3185942a JA |
66 | * GNU Free Documentation License:: Copying and sharing this documentation. |
67 | * Indexes:: Various indexes for this manual. | |
ccc6cda3 JA |
68 | |
69 | \1f | |
a0c0a00f | 70 | File: bashref.info, Node: Introduction, Next: Definitions, Up: Top |
ccc6cda3 | 71 | |
b80f6443 JA |
72 | 1 Introduction |
73 | ************** | |
ccc6cda3 JA |
74 | |
75 | * Menu: | |
76 | ||
77 | * What is Bash?:: A short description of Bash. | |
ccc6cda3 JA |
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 | ||
b80f6443 JA |
83 | 1.1 What is Bash? |
84 | ================= | |
ccc6cda3 | 85 | |
b80f6443 | 86 | Bash is the shell, or command language interpreter, for the GNU |
a0c0a00f | 87 | operating system. The name is an acronym for the 'Bourne-Again SHell', |
bb70624e | 88 | a pun on Stephen Bourne, the author of the direct ancestor of the |
a0c0a00f CR |
89 | current Unix shell 'sh', which appeared in the Seventh Edition Bell Labs |
90 | Research version of Unix. | |
ccc6cda3 | 91 | |
a0c0a00f CR |
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. | |
ccc6cda3 | 98 | |
bb70624e | 99 | While the GNU operating system provides other shells, including a |
a0c0a00f | 100 | version of 'csh', Bash is the default shell. Like other GNU software, |
bb70624e JA |
101 | Bash is quite portable. It currently runs on nearly every version of |
102 | Unix and a few other operating systems - independently-supported ports | |
b80f6443 | 103 | exist for MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 JA |
104 | |
105 | \1f | |
106 | File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction | |
107 | ||
b80f6443 JA |
108 | 1.2 What is a shell? |
109 | ==================== | |
110 | ||
a0c0a00f CR |
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. | |
ccc6cda3 | 114 | |
b80f6443 JA |
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 | |
3185942a | 118 | features allow these utilities to be combined. Files containing |
cce855bc | 119 | commands can be created, and become commands themselves. These new |
bb70624e | 120 | commands have the same status as system commands in directories such as |
a0c0a00f | 121 | '/bin', allowing users or groups to establish custom environments to |
b80f6443 JA |
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. | |
ccc6cda3 | 127 | |
bb70624e | 128 | A shell allows execution of GNU commands, both synchronously and |
cce855bc JA |
129 | asynchronously. The shell waits for synchronous commands to complete |
130 | before accepting more input; asynchronous commands continue to execute | |
131 | in parallel with the shell while it reads and executes additional | |
132 | commands. The "redirection" constructs permit fine-grained control of | |
bb70624e | 133 | the input and output of those commands. Moreover, the shell allows |
b80f6443 | 134 | control over the contents of commands' environments. |
bb70624e JA |
135 | |
136 | Shells also provide a small set of built-in commands ("builtins") | |
137 | implementing functionality impossible or inconvenient to obtain via | |
a0c0a00f | 138 | separate utilities. For example, 'cd', 'break', 'continue', and 'exec' |
ac50fbac | 139 | cannot be implemented outside of the shell because they directly |
a0c0a00f | 140 | manipulate the shell itself. The 'history', 'getopts', 'kill', or 'pwd' |
ac50fbac CR |
141 | builtins, among others, could be implemented in separate utilities, but |
142 | they are more convenient to use as builtin commands. All of the shell | |
143 | builtins are described in subsequent sections. | |
ccc6cda3 JA |
144 | |
145 | While executing commands is essential, most of the power (and | |
146 | complexity) of shells is due to their embedded programming languages. | |
a0c0a00f CR |
147 | Like any high-level language, the shell provides variables, flow control |
148 | constructs, quoting, and functions. | |
ccc6cda3 | 149 | |
bb70624e JA |
150 | Shells offer features geared specifically for interactive use rather |
151 | than to augment the programming language. These interactive features | |
b80f6443 JA |
152 | include job control, command line editing, command history and aliases. |
153 | Each of these features is described in this manual. | |
ccc6cda3 JA |
154 | |
155 | \1f | |
156 | File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top | |
157 | ||
b80f6443 JA |
158 | 2 Definitions |
159 | ************* | |
ccc6cda3 | 160 | |
b80f6443 | 161 | These definitions are used throughout the remainder of this manual. |
ccc6cda3 | 162 | |
a0c0a00f CR |
163 | 'POSIX' |
164 | A family of open system standards based on Unix. Bash is primarily | |
165 | concerned with the Shell and Utilities portion of the POSIX 1003.1 | |
166 | standard. | |
ccc6cda3 | 167 | |
a0c0a00f | 168 | 'blank' |
ccc6cda3 JA |
169 | A space or tab character. |
170 | ||
a0c0a00f | 171 | 'builtin' |
ccc6cda3 JA |
172 | A command that is implemented internally by the shell itself, |
173 | rather than by an executable program somewhere in the file system. | |
174 | ||
a0c0a00f CR |
175 | 'control operator' |
176 | A 'token' that performs a control function. It is a 'newline' or | |
177 | one of the following: '||', '&&', '&', ';', ';;', ';&', ';;&', '|', | |
178 | '|&', '(', or ')'. | |
ccc6cda3 | 179 | |
a0c0a00f | 180 | 'exit status' |
f73dda09 JA |
181 | The value returned by a command to its caller. The value is |
182 | restricted to eight bits, so the maximum value is 255. | |
ccc6cda3 | 183 | |
a0c0a00f | 184 | 'field' |
ccc6cda3 | 185 | A unit of text that is the result of one of the shell expansions. |
a0c0a00f CR |
186 | After expansion, when executing a command, the resulting fields are |
187 | used as the command name and arguments. | |
ccc6cda3 | 188 | |
a0c0a00f | 189 | 'filename' |
ccc6cda3 JA |
190 | A string of characters used to identify a file. |
191 | ||
a0c0a00f | 192 | 'job' |
ccc6cda3 JA |
193 | A set of processes comprising a pipeline, and any processes |
194 | descended from it, that are all in the same process group. | |
195 | ||
a0c0a00f | 196 | 'job control' |
d166f048 JA |
197 | A mechanism by which users can selectively stop (suspend) and |
198 | restart (resume) execution of processes. | |
ccc6cda3 | 199 | |
a0c0a00f | 200 | 'metacharacter' |
ccc6cda3 | 201 | A character that, when unquoted, separates words. A metacharacter |
a0c0a00f CR |
202 | is a 'space', 'tab', 'newline', or one of the following characters: |
203 | '|', '&', ';', '(', ')', '<', or '>'. | |
ccc6cda3 | 204 | |
a0c0a00f CR |
205 | 'name' |
206 | A 'word' consisting solely of letters, numbers, and underscores, | |
207 | and beginning with a letter or underscore. 'Name's are used as | |
ccc6cda3 | 208 | shell variable and function names. Also referred to as an |
a0c0a00f | 209 | 'identifier'. |
ccc6cda3 | 210 | |
a0c0a00f CR |
211 | 'operator' |
212 | A 'control operator' or a 'redirection operator'. *Note | |
3185942a | 213 | Redirections::, for a list of redirection operators. Operators |
a0c0a00f | 214 | contain at least one unquoted 'metacharacter'. |
ccc6cda3 | 215 | |
a0c0a00f | 216 | 'process group' |
ccc6cda3 JA |
217 | A collection of related processes each having the same process |
218 | group ID. | |
219 | ||
a0c0a00f CR |
220 | 'process group ID' |
221 | A unique identifier that represents a 'process group' during its | |
ccc6cda3 JA |
222 | lifetime. |
223 | ||
a0c0a00f CR |
224 | 'reserved word' |
225 | A 'word' that has a special meaning to the shell. Most reserved | |
226 | words introduce shell flow control constructs, such as 'for' and | |
227 | 'while'. | |
ccc6cda3 | 228 | |
a0c0a00f CR |
229 | 'return status' |
230 | A synonym for 'exit status'. | |
ccc6cda3 | 231 | |
a0c0a00f | 232 | 'signal' |
bb70624e | 233 | A mechanism by which a process may be notified by the kernel of an |
ccc6cda3 JA |
234 | event occurring in the system. |
235 | ||
a0c0a00f | 236 | 'special builtin' |
ccc6cda3 | 237 | A shell builtin command that has been classified as special by the |
0628567a | 238 | POSIX standard. |
ccc6cda3 | 239 | |
a0c0a00f CR |
240 | 'token' |
241 | A sequence of characters considered a single unit by the shell. It | |
242 | is either a 'word' or an 'operator'. | |
ccc6cda3 | 243 | |
a0c0a00f CR |
244 | 'word' |
245 | A sequence of characters treated as a unit by the shell. Words may | |
246 | not include unquoted 'metacharacters'. | |
ccc6cda3 JA |
247 | |
248 | \1f | |
bb70624e | 249 | File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top |
ccc6cda3 | 250 | |
b80f6443 JA |
251 | 3 Basic Shell Features |
252 | ********************** | |
ccc6cda3 | 253 | |
a0c0a00f CR |
254 | Bash is an acronym for 'Bourne-Again SHell'. The Bourne shell is the |
255 | traditional Unix shell originally written by Stephen Bourne. All of the | |
256 | Bourne shell builtin commands are available in Bash, The rules for | |
b80f6443 | 257 | evaluation and quoting are taken from the POSIX specification for the |
a0c0a00f | 258 | 'standard' Unix shell. |
ccc6cda3 | 259 | |
a0c0a00f | 260 | This chapter briefly summarizes the shell's 'building blocks': |
ccc6cda3 JA |
261 | commands, control structures, shell functions, shell parameters, shell |
262 | expansions, redirections, which are a way to direct input and output | |
263 | from and to named files, and how the shell executes commands. | |
264 | ||
265 | * Menu: | |
266 | ||
267 | * Shell Syntax:: What your input means to the shell. | |
cce855bc | 268 | * Shell Commands:: The types of commands you can use. |
ccc6cda3 | 269 | * Shell Functions:: Grouping commands by name. |
b80f6443 JA |
270 | * Shell Parameters:: How the shell stores values. |
271 | * Shell Expansions:: How Bash expands parameters and the various | |
ccc6cda3 JA |
272 | expansions available. |
273 | * Redirections:: A way to control where input and output go. | |
274 | * Executing Commands:: What happens when you run a command. | |
275 | * Shell Scripts:: Executing files of shell commands. | |
276 | ||
277 | \1f | |
cce855bc | 278 | File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 279 | |
b80f6443 JA |
280 | 3.1 Shell Syntax |
281 | ================ | |
ccc6cda3 JA |
282 | |
283 | * Menu: | |
284 | ||
285 | * Shell Operation:: The basic operation of the shell. | |
ccc6cda3 | 286 | * Quoting:: How to remove the special meaning from characters. |
ccc6cda3 JA |
287 | * Comments:: How to specify comments. |
288 | ||
a0c0a00f | 289 | When the shell reads input, it proceeds through a sequence of |
bb70624e | 290 | operations. If the input indicates the beginning of a comment, the |
a0c0a00f | 291 | shell ignores the comment symbol ('#'), and the rest of that line. |
bb70624e | 292 | |
a0c0a00f | 293 | Otherwise, roughly speaking, the shell reads its input and divides |
bb70624e JA |
294 | the input into words and operators, employing the quoting rules to |
295 | select which meanings to assign various words and characters. | |
296 | ||
297 | The shell then parses these tokens into commands and other | |
298 | constructs, removes the special meaning of certain words or characters, | |
299 | expands others, redirects input and output as needed, executes the | |
300 | specified command, waits for the command's exit status, and makes that | |
301 | exit status available for further inspection or processing. | |
302 | ||
ccc6cda3 JA |
303 | \1f |
304 | File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax | |
305 | ||
b80f6443 JA |
306 | 3.1.1 Shell Operation |
307 | --------------------- | |
ccc6cda3 | 308 | |
b80f6443 | 309 | The following is a brief description of the shell's operation when it |
ccc6cda3 JA |
310 | reads and executes a command. Basically, the shell does the following: |
311 | ||
28ef6c31 | 312 | 1. Reads its input from a file (*note Shell Scripts::), from a string |
a0c0a00f | 313 | supplied as an argument to the '-c' invocation option (*note |
28ef6c31 | 314 | Invoking Bash::), or from the user's terminal. |
ccc6cda3 JA |
315 | |
316 | 2. Breaks the input into words and operators, obeying the quoting | |
3185942a | 317 | rules described in *note Quoting::. These tokens are separated by |
a0c0a00f CR |
318 | 'metacharacters'. Alias expansion is performed by this step (*note |
319 | Aliases::). | |
ccc6cda3 | 320 | |
cce855bc | 321 | 3. Parses the tokens into simple and compound commands (*note Shell |
28ef6c31 | 322 | Commands::). |
ccc6cda3 | 323 | |
28ef6c31 | 324 | 4. Performs the various shell expansions (*note Shell Expansions::), |
ccc6cda3 | 325 | breaking the expanded tokens into lists of filenames (*note |
28ef6c31 | 326 | Filename Expansion::) and commands and arguments. |
ccc6cda3 | 327 | |
28ef6c31 | 328 | 5. Performs any necessary redirections (*note Redirections::) and |
ccc6cda3 JA |
329 | removes the redirection operators and their operands from the |
330 | argument list. | |
331 | ||
28ef6c31 | 332 | 6. Executes the command (*note Executing Commands::). |
ccc6cda3 JA |
333 | |
334 | 7. Optionally waits for the command to complete and collects its exit | |
28ef6c31 | 335 | status (*note Exit Status::). |
ccc6cda3 | 336 | |
ccc6cda3 JA |
337 | \1f |
338 | File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax | |
339 | ||
b80f6443 JA |
340 | 3.1.2 Quoting |
341 | ------------- | |
ccc6cda3 JA |
342 | |
343 | * Menu: | |
344 | ||
345 | * Escape Character:: How to remove the special meaning from a single | |
346 | character. | |
347 | * Single Quotes:: How to inhibit all interpretation of a sequence | |
348 | of characters. | |
349 | * Double Quotes:: How to suppress most of the interpretation of a | |
350 | sequence of characters. | |
351 | * ANSI-C Quoting:: How to expand ANSI-C sequences in quoted strings. | |
ccc6cda3 JA |
352 | * Locale Translation:: How to translate strings into different languages. |
353 | ||
a0c0a00f CR |
354 | Quoting is used to remove the special meaning of certain characters or |
355 | words to the shell. Quoting can be used to disable special treatment | |
356 | for special characters, to prevent reserved words from being recognized | |
357 | as such, and to prevent parameter expansion. | |
ccc6cda3 | 358 | |
28ef6c31 | 359 | Each of the shell metacharacters (*note Definitions::) has special |
cce855bc | 360 | meaning to the shell and must be quoted if it is to represent itself. |
95732b49 | 361 | When the command history expansion facilities are being used (*note |
74091dd4 | 362 | History Interaction::), the "history expansion" character, usually '!', |
95732b49 JA |
363 | must be quoted to prevent history expansion. *Note Bash History |
364 | Facilities::, for more details concerning history expansion. | |
b80f6443 | 365 | |
74091dd4 | 366 | There are three quoting mechanisms: the "escape character", single |
b80f6443 | 367 | quotes, and double quotes. |
ccc6cda3 JA |
368 | |
369 | \1f | |
370 | File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting | |
371 | ||
b80f6443 JA |
372 | 3.1.2.1 Escape Character |
373 | ........................ | |
ccc6cda3 | 374 | |
a0c0a00f CR |
375 | A non-quoted backslash '\' is the Bash escape character. It preserves |
376 | the literal value of the next character that follows, with the exception | |
377 | of 'newline'. If a '\newline' pair appears, and the backslash itself is | |
378 | not quoted, the '\newline' is treated as a line continuation (that is, | |
379 | it is removed from the input stream and effectively ignored). | |
ccc6cda3 JA |
380 | |
381 | \1f | |
382 | File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting | |
383 | ||
b80f6443 JA |
384 | 3.1.2.2 Single Quotes |
385 | ..................... | |
ccc6cda3 | 386 | |
a0c0a00f | 387 | Enclosing characters in single quotes (''') preserves the literal value |
b80f6443 | 388 | of each character within the quotes. A single quote may not occur |
bb70624e | 389 | between single quotes, even when preceded by a backslash. |
ccc6cda3 JA |
390 | |
391 | \1f | |
392 | File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting | |
393 | ||
b80f6443 JA |
394 | 3.1.2.3 Double Quotes |
395 | ..................... | |
ccc6cda3 | 396 | |
a0c0a00f CR |
397 | Enclosing characters in double quotes ('"') preserves the literal value |
398 | of all characters within the quotes, with the exception of '$', '`', | |
399 | '\', and, when history expansion is enabled, '!'. When the shell is in | |
400 | POSIX mode (*note Bash POSIX Mode::), the '!' has no special meaning | |
401 | within double quotes, even when history expansion is enabled. The | |
402 | characters '$' and '`' retain their special meaning within double quotes | |
403 | (*note Shell Expansions::). The backslash retains its special meaning | |
404 | only when followed by one of the following characters: '$', '`', '"', | |
405 | '\', or 'newline'. Within double quotes, backslashes that are followed | |
406 | by one of these characters are removed. Backslashes preceding | |
407 | characters without a special meaning are left unmodified. A double | |
408 | quote may be quoted within double quotes by preceding it with a | |
409 | backslash. If enabled, history expansion will be performed unless an | |
410 | '!' appearing in double quotes is escaped using a backslash. The | |
411 | backslash preceding the '!' is not removed. | |
412 | ||
413 | The special parameters '*' and '@' have special meaning when in | |
28ef6c31 | 414 | double quotes (*note Shell Parameter Expansion::). |
ccc6cda3 JA |
415 | |
416 | \1f | |
417 | File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting | |
418 | ||
b80f6443 JA |
419 | 3.1.2.4 ANSI-C Quoting |
420 | ...................... | |
ccc6cda3 | 421 | |
74091dd4 CR |
422 | Character sequences of the form $'STRING' are treated as a special kind |
423 | of single quotes. The sequence expands to STRING, with | |
424 | backslash-escaped characters in STRING replaced as specified by the ANSI | |
425 | C standard. Backslash escape sequences, if present, are decoded as | |
426 | follows: | |
ccc6cda3 | 427 | |
a0c0a00f | 428 | '\a' |
ccc6cda3 | 429 | alert (bell) |
a0c0a00f | 430 | '\b' |
ccc6cda3 | 431 | backspace |
a0c0a00f CR |
432 | '\e' |
433 | '\E' | |
ccc6cda3 | 434 | an escape character (not ANSI C) |
a0c0a00f | 435 | '\f' |
ccc6cda3 | 436 | form feed |
a0c0a00f | 437 | '\n' |
ccc6cda3 | 438 | newline |
a0c0a00f | 439 | '\r' |
ccc6cda3 | 440 | carriage return |
a0c0a00f | 441 | '\t' |
ccc6cda3 | 442 | horizontal tab |
a0c0a00f | 443 | '\v' |
ccc6cda3 | 444 | vertical tab |
a0c0a00f | 445 | '\\' |
ccc6cda3 | 446 | backslash |
a0c0a00f | 447 | '\'' |
bb70624e | 448 | single quote |
a0c0a00f | 449 | '\"' |
0001803f | 450 | double quote |
a0c0a00f CR |
451 | '\?' |
452 | question mark | |
453 | '\NNN' | |
f73dda09 | 454 | the eight-bit character whose value is the octal value NNN (one to |
d233b485 | 455 | three octal digits) |
a0c0a00f | 456 | '\xHH' |
f73dda09 JA |
457 | the eight-bit character whose value is the hexadecimal value HH |
458 | (one or two hex digits) | |
a0c0a00f | 459 | '\uHHHH' |
495aee44 CR |
460 | the Unicode (ISO/IEC 10646) character whose value is the |
461 | hexadecimal value HHHH (one to four hex digits) | |
a0c0a00f | 462 | '\UHHHHHHHH' |
495aee44 CR |
463 | the Unicode (ISO/IEC 10646) character whose value is the |
464 | hexadecimal value HHHHHHHH (one to eight hex digits) | |
a0c0a00f | 465 | '\cX' |
7117c2d2 JA |
466 | a control-X character |
467 | ||
a0c0a00f CR |
468 | The expanded result is single-quoted, as if the dollar sign had not been |
469 | present. | |
ccc6cda3 JA |
470 | |
471 | \1f | |
472 | File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting | |
473 | ||
b80f6443 JA |
474 | 3.1.2.5 Locale-Specific Translation |
475 | ................................... | |
ccc6cda3 | 476 | |
74091dd4 | 477 | * Menu: |
ccc6cda3 | 478 | |
74091dd4 CR |
479 | * Creating Internationalized Scripts:: How to use translations and different |
480 | languages in your scripts. | |
481 | ||
482 | Prefixing a double-quoted string with a dollar sign ('$'), such as | |
483 | $"hello, world", will cause the string to be translated according to the | |
484 | current locale. The 'gettext' infrastructure performs the lookup and | |
485 | translation, using the 'LC_MESSAGES', 'TEXTDOMAINDIR', and 'TEXTDOMAIN' | |
486 | shell variables, as explained below. See the gettext documentation for | |
487 | additional details not covered here. If the current locale is 'C' or | |
488 | 'POSIX', if there are no translations available, of if the string is not | |
489 | translated, the dollar sign is ignored. Since this is a form of double | |
490 | quoting, the string remains double-quoted by default, whether or not it | |
491 | is translated and replaced. If the 'noexpand_translation' option is | |
492 | enabled using the 'shopt' builtin (*note The Shopt Builtin::), | |
493 | translated strings are single-quoted instead of double-quoted. | |
494 | ||
495 | The rest of this section is a brief overview of how you use gettext | |
496 | to create translations for strings in a shell script named SCRIPTNAME. | |
497 | There are more details in the gettext documentation. | |
498 | ||
499 | \1f | |
500 | File: bashref.info, Node: Creating Internationalized Scripts, Up: Locale Translation | |
501 | ||
502 | Once you've marked the strings in your script that you want to translate | |
503 | using $"...", you create a gettext "template" file using the command | |
504 | ||
505 | bash --dump-po-strings SCRIPTNAME > DOMAIN.pot | |
506 | ||
507 | The DOMAIN is your "message domain". It's just an arbitrary string | |
508 | that's used to identify the files gettext needs, like a package or | |
509 | script name. It needs to be unique among all the message domains on | |
510 | systems where you install the translations, so gettext knows which | |
511 | translations correspond to your script. You'll use the template file to | |
512 | create translations for each target language. The template file | |
513 | conventionally has the suffix '.pot'. | |
514 | ||
515 | You copy this template file to a separate file for each target | |
516 | language you want to support (called "PO" files, which use the suffix | |
517 | '.po'). PO files use various naming conventions, but when you are | |
518 | working to translate a template file into a particular language, you | |
519 | first copy the template file to a file whose name is the language you | |
520 | want to target, with the '.po' suffix. For instance, the Spanish | |
521 | translations of your strings would be in a file named 'es.po', and to | |
522 | get started using a message domain named "example," you would run | |
523 | ||
524 | cp example.pot es.po | |
525 | ||
526 | Ultimately, PO files are often named DOMAIN.po and installed in | |
527 | directories that contain multiple translation files for a particular | |
528 | language. | |
529 | ||
530 | Whichever naming convention you choose, you will need to translate | |
531 | the strings in the PO files into the appropriate languages. This has to | |
532 | be done manually. | |
533 | ||
534 | When you have the translations and PO files complete, you'll use the | |
535 | gettext tools to produce what are called "MO" files, which are compiled | |
536 | versions of the PO files the gettext tools use to look up translations | |
537 | efficiently. MO files are also called "message catalog" files. You use | |
538 | the 'msgfmt' program to do this. For instance, if you had a file with | |
539 | Spanish translations, you could run | |
540 | ||
541 | msgfmt -o es.mo es.po | |
542 | ||
543 | to produce the corresponding MO file. | |
544 | ||
545 | Once you have the MO files, you decide where to install them and use | |
546 | the 'TEXTDOMAINDIR' shell variable to tell the gettext tools where they | |
547 | are. Make sure to use the same message domain to name the MO files as | |
548 | you did for the PO files when you install them. | |
549 | ||
550 | Your users will use the 'LANG' or 'LC_MESSAGES' shell variables to | |
551 | select the desired language. | |
552 | ||
553 | You set the 'TEXTDOMAIN' variable to the script's message domain. As | |
554 | above, you use the message domain to name your translation files. | |
555 | ||
556 | You, or possibly your users, set the 'TEXTDOMAINDIR' variable to the | |
557 | name of a directory where the message catalog files are stored. If you | |
558 | install the message files into the system's standard message catalog | |
559 | directory, you don't need to worry about this variable. | |
560 | ||
561 | The directory where the message catalog files are stored varies | |
562 | between systems. Some use the message catalog selected by the | |
563 | 'LC_MESSAGES' shell variable. Others create the name of the message | |
564 | catalog from the value of the 'TEXTDOMAIN' shell variable, possibly | |
565 | adding the '.mo' suffix. If you use the 'TEXTDOMAIN' variable, you may | |
566 | need to set the 'TEXTDOMAINDIR' variable to the location of the message | |
567 | catalog files, as above. It's common to use both variables in this | |
568 | fashion: '$TEXTDOMAINDIR'/'$LC_MESSAGES'/LC_MESSAGES/'$TEXTDOMAIN'.mo. | |
569 | ||
570 | If you used that last convention, and you wanted to store the message | |
571 | catalog files with Spanish (es) and Esperanto (eo) translations into a | |
572 | local directory you use for custom translation files, you could run | |
573 | ||
574 | TEXTDOMAIN=example | |
575 | TEXTDOMAINDIR=/usr/local/share/locale | |
576 | ||
577 | cp es.mo ${TEXTDOMAINDIR}/es/LC_MESSAGES/${TEXTDOMAIN}.mo | |
578 | cp eo.mo ${TEXTDOMAINDIR}/eo/LC_MESSAGES/${TEXTDOMAIN}.mo | |
579 | ||
580 | When all of this is done, and the message catalog files containing | |
581 | the compiled translations are installed in the correct location, your | |
582 | users will be able to see translated strings in any of the supported | |
583 | languages by setting the 'LANG' or 'LC_MESSAGES' environment variables | |
584 | before running your script. | |
28ef6c31 | 585 | |
ccc6cda3 JA |
586 | \1f |
587 | File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax | |
588 | ||
b80f6443 JA |
589 | 3.1.3 Comments |
590 | -------------- | |
ccc6cda3 | 591 | |
b80f6443 | 592 | In a non-interactive shell, or an interactive shell in which the |
a0c0a00f CR |
593 | 'interactive_comments' option to the 'shopt' builtin is enabled (*note |
594 | The Shopt Builtin::), a word beginning with '#' causes that word and all | |
595 | remaining characters on that line to be ignored. An interactive shell | |
596 | without the 'interactive_comments' option enabled does not allow | |
597 | comments. The 'interactive_comments' option is on by default in | |
bb70624e JA |
598 | interactive shells. *Note Interactive Shells::, for a description of |
599 | what makes a shell interactive. | |
cce855bc JA |
600 | |
601 | \1f | |
602 | File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features | |
603 | ||
b80f6443 JA |
604 | 3.2 Shell Commands |
605 | ================== | |
cce855bc | 606 | |
a0c0a00f | 607 | A simple shell command such as 'echo a b c' consists of the command |
bb70624e JA |
608 | itself followed by arguments, separated by spaces. |
609 | ||
610 | More complex shell commands are composed of simple commands arranged | |
611 | together in a variety of ways: in a pipeline in which the output of one | |
612 | command becomes the input of a second, in a loop or conditional | |
613 | construct, or in some other grouping. | |
614 | ||
cce855bc JA |
615 | * Menu: |
616 | ||
8868edaf | 617 | * Reserved Words:: Words that have special meaning to the shell. |
cce855bc JA |
618 | * Simple Commands:: The most common type of command. |
619 | * Pipelines:: Connecting the input and output of several | |
620 | commands. | |
621 | * Lists:: How to execute commands sequentially. | |
b80f6443 | 622 | * Compound Commands:: Shell commands for control flow. |
3185942a | 623 | * Coprocesses:: Two-way communication between commands. |
495aee44 | 624 | * GNU Parallel:: Running commands in parallel. |
ccc6cda3 JA |
625 | |
626 | \1f | |
8868edaf | 627 | File: bashref.info, Node: Reserved Words, Next: Simple Commands, Up: Shell Commands |
ccc6cda3 | 628 | |
8868edaf CR |
629 | 3.2.1 Reserved Words |
630 | -------------------- | |
631 | ||
632 | Reserved words are words that have special meaning to the shell. They | |
633 | are used to begin and end the shell's compound commands. | |
634 | ||
635 | The following words are recognized as reserved when unquoted and the | |
636 | first word of a command (see below for exceptions): | |
637 | ||
638 | 'if' 'then' 'elif' 'else' 'fi' 'time' | |
639 | 'for' 'in' 'until' 'while' 'do' 'done' | |
640 | 'case' 'esac' 'coproc''select''function' | |
641 | '{' '}' '[[' ']]' '!' | |
642 | ||
643 | 'in' is recognized as a reserved word if it is the third word of a | |
644 | 'case' or 'select' command. 'in' and 'do' are recognized as reserved | |
645 | words if they are the third word in a 'for' command. | |
646 | ||
647 | \1f | |
648 | File: bashref.info, Node: Simple Commands, Next: Pipelines, Prev: Reserved Words, Up: Shell Commands | |
649 | ||
650 | 3.2.2 Simple Commands | |
b80f6443 | 651 | --------------------- |
ccc6cda3 | 652 | |
b80f6443 | 653 | A simple command is the kind of command encountered most often. It's |
a0c0a00f CR |
654 | just a sequence of words separated by 'blank's, terminated by one of the |
655 | shell's control operators (*note Definitions::). The first word | |
656 | generally specifies a command to be executed, with the rest of the words | |
657 | being that command's arguments. | |
ccc6cda3 | 658 | |
28ef6c31 | 659 | The return status (*note Exit Status::) of a simple command is its |
a0c0a00f CR |
660 | exit status as provided by the POSIX 1003.1 'waitpid' function, or 128+N |
661 | if the command was terminated by signal N. | |
ccc6cda3 JA |
662 | |
663 | \1f | |
cce855bc | 664 | File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands |
ccc6cda3 | 665 | |
8868edaf | 666 | 3.2.3 Pipelines |
b80f6443 | 667 | --------------- |
ccc6cda3 | 668 | |
a0c0a00f CR |
669 | A 'pipeline' is a sequence of one or more commands separated by one of |
670 | the control operators '|' or '|&'. | |
ccc6cda3 JA |
671 | |
672 | The format for a pipeline is | |
ac50fbac | 673 | [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ... |
ccc6cda3 | 674 | |
f73dda09 | 675 | The output of each command in the pipeline is connected via a pipe to |
a0c0a00f CR |
676 | the input of the next command. That is, each command reads the previous |
677 | command's output. This connection is performed before any redirections | |
74091dd4 | 678 | specified by COMMAND1. |
3185942a | 679 | |
a0c0a00f | 680 | If '|&' is used, COMMAND1's standard error, in addition to its |
ac50fbac | 681 | standard output, is connected to COMMAND2's standard input through the |
a0c0a00f | 682 | pipe; it is shorthand for '2>&1 |'. This implicit redirection of the |
ac50fbac | 683 | standard error to the standard output is performed after any |
74091dd4 | 684 | redirections specified by COMMAND1. |
ccc6cda3 | 685 | |
a0c0a00f | 686 | The reserved word 'time' causes timing statistics to be printed for |
cce855bc JA |
687 | the pipeline once it finishes. The statistics currently consist of |
688 | elapsed (wall-clock) time and user and system time consumed by the | |
a0c0a00f | 689 | command's execution. The '-p' option changes the output format to that |
495aee44 | 690 | specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX |
a0c0a00f CR |
691 | Mode::), it does not recognize 'time' as a reserved word if the next |
692 | token begins with a '-'. The 'TIMEFORMAT' variable may be set to a | |
495aee44 CR |
693 | format string that specifies how the timing information should be |
694 | displayed. *Note Bash Variables::, for a description of the available | |
a0c0a00f CR |
695 | formats. The use of 'time' as a reserved word permits the timing of |
696 | shell builtins, shell functions, and pipelines. An external 'time' | |
495aee44 CR |
697 | command cannot time these easily. |
698 | ||
a0c0a00f CR |
699 | When the shell is in POSIX mode (*note Bash POSIX Mode::), 'time' may |
700 | be followed by a newline. In this case, the shell displays the total | |
701 | user and system time consumed by the shell and its children. The | |
702 | 'TIMEFORMAT' variable may be used to specify the format of the time | |
495aee44 | 703 | information. |
cce855bc | 704 | |
28ef6c31 | 705 | If the pipeline is not executed asynchronously (*note Lists::), the |
cce855bc | 706 | shell waits for all commands in the pipeline to complete. |
ccc6cda3 | 707 | |
74091dd4 CR |
708 | Each command in a multi-command pipeline, where pipes are created, is |
709 | executed in its own "subshell", which is a separate process (*note | |
710 | Command Execution Environment::). If the 'lastpipe' option is enabled | |
711 | using the 'shopt' builtin (*note The Shopt Builtin::), the last element | |
712 | of a pipeline may be run by the shell process when job control is not | |
713 | active. | |
d233b485 CR |
714 | |
715 | The exit status of a pipeline is the exit status of the last command | |
716 | in the pipeline, unless the 'pipefail' option is enabled (*note The Set | |
717 | Builtin::). If 'pipefail' is enabled, the pipeline's return status is | |
718 | the value of the last (rightmost) command to exit with a non-zero | |
719 | status, or zero if all commands exit successfully. If the reserved word | |
720 | '!' precedes the pipeline, the exit status is the logical negation of | |
721 | the exit status as described above. The shell waits for all commands in | |
722 | the pipeline to terminate before returning a value. | |
ccc6cda3 JA |
723 | |
724 | \1f | |
b80f6443 | 725 | File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands |
ccc6cda3 | 726 | |
8868edaf | 727 | 3.2.4 Lists of Commands |
b80f6443 | 728 | ----------------------- |
ccc6cda3 | 729 | |
a0c0a00f CR |
730 | A 'list' is a sequence of one or more pipelines separated by one of the |
731 | operators ';', '&', '&&', or '||', and optionally terminated by one of | |
732 | ';', '&', or a 'newline'. | |
ccc6cda3 | 733 | |
a0c0a00f CR |
734 | Of these list operators, '&&' and '||' have equal precedence, |
735 | followed by ';' and '&', which have equal precedence. | |
ccc6cda3 | 736 | |
a0c0a00f | 737 | A sequence of one or more newlines may appear in a 'list' to delimit |
7117c2d2 JA |
738 | commands, equivalent to a semicolon. |
739 | ||
a0c0a00f | 740 | If a command is terminated by the control operator '&', the shell |
cce855bc | 741 | executes the command asynchronously in a subshell. This is known as |
74091dd4 CR |
742 | executing the command in the "background", and these are referred to as |
743 | "asynchronous" commands. The shell does not wait for the command to | |
d233b485 CR |
744 | finish, and the return status is 0 (true). When job control is not |
745 | active (*note Job Control::), the standard input for asynchronous | |
746 | commands, in the absence of any explicit redirections, is redirected | |
747 | from '/dev/null'. | |
cce855bc | 748 | |
a0c0a00f | 749 | Commands separated by a ';' are executed sequentially; the shell |
cce855bc JA |
750 | waits for each command to terminate in turn. The return status is the |
751 | exit status of the last command executed. | |
ccc6cda3 | 752 | |
3185942a | 753 | AND and OR lists are sequences of one or more pipelines separated by |
a0c0a00f CR |
754 | the control operators '&&' and '||', respectively. AND and OR lists are |
755 | executed with left associativity. | |
3185942a JA |
756 | |
757 | An AND list has the form | |
bb70624e | 758 | COMMAND1 && COMMAND2 |
ccc6cda3 | 759 | |
a0c0a00f | 760 | COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of |
d233b485 | 761 | zero (success). |
ccc6cda3 JA |
762 | |
763 | An OR list has the form | |
bb70624e | 764 | COMMAND1 || COMMAND2 |
ccc6cda3 | 765 | |
bb70624e | 766 | COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit |
ccc6cda3 JA |
767 | status. |
768 | ||
769 | The return status of AND and OR lists is the exit status of the last | |
770 | command executed in the list. | |
771 | ||
772 | \1f | |
3185942a | 773 | File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands |
ccc6cda3 | 774 | |
8868edaf | 775 | 3.2.5 Compound Commands |
b80f6443 | 776 | ----------------------- |
ccc6cda3 | 777 | |
b80f6443 JA |
778 | * Menu: |
779 | ||
780 | * Looping Constructs:: Shell commands for iterative action. | |
781 | * Conditional Constructs:: Shell commands for conditional execution. | |
782 | * Command Grouping:: Ways to group commands. | |
783 | ||
d233b485 CR |
784 | Compound commands are the shell programming language constructs. Each |
785 | construct begins with a reserved word or control operator and is | |
786 | terminated by a corresponding reserved word or operator. Any | |
787 | redirections (*note Redirections::) associated with a compound command | |
788 | apply to all commands within that compound command unless explicitly | |
789 | overridden. | |
b80f6443 | 790 | |
ac50fbac CR |
791 | In most cases a list of commands in a compound command's description |
792 | may be separated from the rest of the command by one or more newlines, | |
793 | and may be followed by a newline in place of a semicolon. | |
794 | ||
b80f6443 JA |
795 | Bash provides looping constructs, conditional commands, and |
796 | mechanisms to group commands and execute them as a unit. | |
797 | ||
798 | \1f | |
799 | File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands | |
800 | ||
8868edaf | 801 | 3.2.5.1 Looping Constructs |
b80f6443 JA |
802 | .......................... |
803 | ||
804 | Bash supports the following looping constructs. | |
ccc6cda3 | 805 | |
a0c0a00f | 806 | Note that wherever a ';' appears in the description of a command's |
cce855bc JA |
807 | syntax, it may be replaced with one or more newlines. |
808 | ||
a0c0a00f CR |
809 | 'until' |
810 | The syntax of the 'until' command is: | |
ac50fbac | 811 | |
ccc6cda3 | 812 | until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done |
ac50fbac | 813 | |
cce855bc JA |
814 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
815 | status which is not zero. The return status is the exit status of | |
816 | the last command executed in CONSEQUENT-COMMANDS, or zero if none | |
817 | was executed. | |
ccc6cda3 | 818 | |
a0c0a00f CR |
819 | 'while' |
820 | The syntax of the 'while' command is: | |
ac50fbac | 821 | |
ccc6cda3 JA |
822 | while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done |
823 | ||
cce855bc JA |
824 | Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit |
825 | status of zero. The return status is the exit status of the last | |
826 | command executed in CONSEQUENT-COMMANDS, or zero if none was | |
827 | executed. | |
ccc6cda3 | 828 | |
a0c0a00f CR |
829 | 'for' |
830 | The syntax of the 'for' command is: | |
ccc6cda3 | 831 | |
0001803f | 832 | for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done |
ac50fbac | 833 | |
d233b485 CR |
834 | Expand WORDS (*note Shell Expansions::), and execute COMMANDS once |
835 | for each member in the resultant list, with NAME bound to the | |
836 | current member. If 'in WORDS' is not present, the 'for' command | |
837 | executes the COMMANDS once for each positional parameter that is | |
838 | set, as if 'in "$@"' had been specified (*note Special | |
839 | Parameters::). | |
840 | ||
841 | The return status is the exit status of the last command that | |
842 | executes. If there are no items in the expansion of WORDS, no | |
843 | commands are executed, and the return status is zero. | |
bb70624e | 844 | |
a0c0a00f | 845 | An alternate form of the 'for' command is also supported: |
bb70624e JA |
846 | |
847 | for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done | |
ac50fbac | 848 | |
bb70624e | 849 | First, the arithmetic expression EXPR1 is evaluated according to |
28ef6c31 | 850 | the rules described below (*note Shell Arithmetic::). The |
bb70624e JA |
851 | arithmetic expression EXPR2 is then evaluated repeatedly until it |
852 | evaluates to zero. Each time EXPR2 evaluates to a non-zero value, | |
853 | COMMANDS are executed and the arithmetic expression EXPR3 is | |
854 | evaluated. If any expression is omitted, it behaves as if it | |
855 | evaluates to 1. The return value is the exit status of the last | |
495aee44 | 856 | command in COMMANDS that is executed, or false if any of the |
bb70624e | 857 | expressions is invalid. |
ccc6cda3 | 858 | |
a0c0a00f | 859 | The 'break' and 'continue' builtins (*note Bourne Shell Builtins::) |
ccc6cda3 JA |
860 | may be used to control loop execution. |
861 | ||
862 | \1f | |
b80f6443 | 863 | File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands |
ccc6cda3 | 864 | |
8868edaf | 865 | 3.2.5.2 Conditional Constructs |
b80f6443 | 866 | .............................. |
ccc6cda3 | 867 | |
a0c0a00f CR |
868 | 'if' |
869 | The syntax of the 'if' command is: | |
ccc6cda3 JA |
870 | |
871 | if TEST-COMMANDS; then | |
872 | CONSEQUENT-COMMANDS; | |
873 | [elif MORE-TEST-COMMANDS; then | |
874 | MORE-CONSEQUENTS;] | |
875 | [else ALTERNATE-CONSEQUENTS;] | |
876 | fi | |
877 | ||
cce855bc JA |
878 | The TEST-COMMANDS list is executed, and if its return status is |
879 | zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS | |
a0c0a00f | 880 | returns a non-zero status, each 'elif' list is executed in turn, |
cce855bc | 881 | and if its exit status is zero, the corresponding MORE-CONSEQUENTS |
a0c0a00f | 882 | is executed and the command completes. If 'else |
cce855bc | 883 | ALTERNATE-CONSEQUENTS' is present, and the final command in the |
a0c0a00f | 884 | final 'if' or 'elif' clause has a non-zero exit status, then |
cce855bc | 885 | ALTERNATE-CONSEQUENTS is executed. The return status is the exit |
a0c0a00f CR |
886 | status of the last command executed, or zero if no condition tested |
887 | true. | |
ccc6cda3 | 888 | |
a0c0a00f CR |
889 | 'case' |
890 | The syntax of the 'case' command is: | |
ccc6cda3 | 891 | |
d233b485 CR |
892 | case WORD in |
893 | [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... | |
894 | esac | |
ccc6cda3 | 895 | |
a0c0a00f | 896 | 'case' will selectively execute the COMMAND-LIST corresponding to |
d233b485 CR |
897 | the first PATTERN that matches WORD. The match is performed |
898 | according to the rules described below in *note Pattern Matching::. | |
899 | If the 'nocasematch' shell option (see the description of 'shopt' | |
900 | in *note The Shopt Builtin::) is enabled, the match is performed | |
901 | without regard to the case of alphabetic characters. The '|' is | |
902 | used to separate multiple patterns, and the ')' operator terminates | |
903 | a pattern list. A list of patterns and an associated command-list | |
904 | is known as a CLAUSE. | |
3185942a | 905 | |
a0c0a00f CR |
906 | Each clause must be terminated with ';;', ';&', or ';;&'. The WORD |
907 | undergoes tilde expansion, parameter expansion, command | |
d233b485 CR |
908 | substitution, arithmetic expansion, and quote removal (*note Shell |
909 | Parameter Expansion::) before matching is attempted. Each PATTERN | |
910 | undergoes tilde expansion, parameter expansion, command | |
74091dd4 CR |
911 | substitution, arithmetic expansion, process substitution, and quote |
912 | removal. | |
cce855bc | 913 | |
a0c0a00f CR |
914 | There may be an arbitrary number of 'case' clauses, each terminated |
915 | by a ';;', ';&', or ';;&'. The first pattern that matches | |
ac50fbac | 916 | determines the command-list that is executed. It's a common idiom |
a0c0a00f | 917 | to use '*' as the final pattern to define the default case, since |
ac50fbac | 918 | that pattern will always match. |
ccc6cda3 | 919 | |
a0c0a00f | 920 | Here is an example using 'case' in a script that could be used to |
ccc6cda3 JA |
921 | describe one interesting feature of an animal: |
922 | ||
923 | echo -n "Enter the name of an animal: " | |
924 | read ANIMAL | |
925 | echo -n "The $ANIMAL has " | |
926 | case $ANIMAL in | |
927 | horse | dog | cat) echo -n "four";; | |
928 | man | kangaroo ) echo -n "two";; | |
929 | *) echo -n "an unknown number of";; | |
930 | esac | |
931 | echo " legs." | |
932 | ||
a0c0a00f CR |
933 | |
934 | If the ';;' operator is used, no subsequent matches are attempted | |
935 | after the first pattern match. Using ';&' in place of ';;' causes | |
936 | execution to continue with the COMMAND-LIST associated with the | |
937 | next clause, if any. Using ';;&' in place of ';;' causes the shell | |
938 | to test the patterns in the next clause, if any, and execute any | |
8868edaf CR |
939 | associated COMMAND-LIST on a successful match, continuing the case |
940 | statement execution as if the pattern list had not matched. | |
3185942a | 941 | |
cce855bc JA |
942 | The return status is zero if no PATTERN is matched. Otherwise, the |
943 | return status is the exit status of the COMMAND-LIST executed. | |
944 | ||
a0c0a00f CR |
945 | 'select' |
946 | ||
947 | The 'select' construct allows the easy generation of menus. It has | |
948 | almost the same syntax as the 'for' command: | |
cce855bc JA |
949 | |
950 | select NAME [in WORDS ...]; do COMMANDS; done | |
951 | ||
a0c0a00f | 952 | The list of words following 'in' is expanded, generating a list of |
74091dd4 CR |
953 | items, and the set of expanded words is printed on the standard |
954 | error output stream, each preceded by a number. If the 'in WORDS' | |
955 | is omitted, the positional parameters are printed, as if 'in "$@"' | |
956 | had been specified. 'select' then displays the 'PS3' prompt and | |
957 | reads a line from the standard input. If the line consists of a | |
958 | number corresponding to one of the displayed words, then the value | |
959 | of NAME is set to that word. If the line is empty, the words and | |
960 | prompt are displayed again. If 'EOF' is read, the 'select' command | |
961 | completes and returns 1. Any other value read causes NAME to be | |
962 | set to null. The line read is saved in the variable 'REPLY'. | |
a0c0a00f CR |
963 | |
964 | The COMMANDS are executed after each selection until a 'break' | |
965 | command is executed, at which point the 'select' command completes. | |
cce855bc JA |
966 | |
967 | Here is an example that allows the user to pick a filename from the | |
968 | current directory, and displays the name and index of the file | |
969 | selected. | |
970 | ||
971 | select fname in *; | |
972 | do | |
973 | echo you picked $fname \($REPLY\) | |
974 | break; | |
975 | done | |
976 | ||
a0c0a00f | 977 | '((...))' |
ccc6cda3 JA |
978 | (( EXPRESSION )) |
979 | ||
cce855bc | 980 | The arithmetic EXPRESSION is evaluated according to the rules |
74091dd4 CR |
981 | described below (*note Shell Arithmetic::). The EXPRESSION |
982 | undergoes the same expansions as if it were within double quotes, | |
983 | but double quote characters in EXPRESSION are not treated specially | |
984 | are removed. If the value of the expression is non-zero, the | |
985 | return status is 0; otherwise the return status is 1. | |
cce855bc | 986 | |
a0c0a00f | 987 | '[[...]]' |
cce855bc JA |
988 | [[ EXPRESSION ]] |
989 | ||
990 | Return a status of 0 or 1 depending on the evaluation of the | |
a0c0a00f CR |
991 | conditional expression EXPRESSION. Expressions are composed of the |
992 | primaries described below in *note Bash Conditional Expressions::. | |
74091dd4 CR |
993 | The words between the '[[' and ']]' do not undergo word splitting |
994 | and filename expansion. The shell performs tilde expansion, | |
995 | parameter and variable expansion, arithmetic expansion, command | |
996 | substitution, process substitution, and quote removal on those | |
997 | words (the expansions that would occur if the words were enclosed | |
998 | in double quotes). Conditional operators such as '-f' must be | |
999 | unquoted to be recognized as primaries. | |
a0c0a00f CR |
1000 | |
1001 | When used with '[[', the '<' and '>' operators sort | |
0001803f CR |
1002 | lexicographically using the current locale. |
1003 | ||
a0c0a00f | 1004 | When the '==' and '!=' operators are used, the string to the right |
cce855bc | 1005 | of the operator is considered a pattern and matched according to |
ac50fbac | 1006 | the rules described below in *note Pattern Matching::, as if the |
a0c0a00f CR |
1007 | 'extglob' shell option were enabled. The '=' operator is identical |
1008 | to '=='. If the 'nocasematch' shell option (see the description of | |
1009 | 'shopt' in *note The Shopt Builtin::) is enabled, the match is | |
1010 | performed without regard to the case of alphabetic characters. The | |
1011 | return value is 0 if the string matches ('==') or does not match | |
74091dd4 CR |
1012 | ('!=') the pattern, and 1 otherwise. |
1013 | ||
1014 | If you quote any part of the pattern, using any of the shell's | |
1015 | quoting mechanisms, the quoted portion is matched literally. This | |
1016 | means every character in the quoted portion matches itself, instead | |
1017 | of having any special pattern matching meaning. | |
a0c0a00f CR |
1018 | |
1019 | An additional binary operator, '=~', is available, with the same | |
74091dd4 | 1020 | precedence as '==' and '!='. When you use '=~', the string to the |
d233b485 | 1021 | right of the operator is considered a POSIX extended regular |
74091dd4 CR |
1022 | expression pattern and matched accordingly (using the POSIX |
1023 | 'regcomp' and 'regexec' interfaces usually described in regex(3)). | |
1024 | The return value is 0 if the string matches the pattern, and 1 if | |
1025 | it does not. If the regular expression is syntactically incorrect, | |
1026 | the conditional expression returns 2. If the 'nocasematch' shell | |
1027 | option (see the description of 'shopt' in *note The Shopt | |
1028 | Builtin::) is enabled, the match is performed without regard to the | |
1029 | case of alphabetic characters. | |
1030 | ||
1031 | You can quote any part of the pattern to force the quoted portion | |
1032 | to be matched literally instead of as a regular expression (see | |
1033 | above). If the pattern is stored in a shell variable, quoting the | |
1034 | variable expansion forces the entire pattern to be matched | |
1035 | literally. | |
1036 | ||
1037 | The pattern will match if it matches any part of the string. If | |
1038 | you want to force the pattern to match the entire string, anchor | |
1039 | the pattern using the '^' and '$' regular expression operators. | |
ac50fbac CR |
1040 | |
1041 | For example, the following will match a line (stored in the shell | |
74091dd4 CR |
1042 | variable 'line') if there is a sequence of characters anywhere in |
1043 | the value consisting of any number, including zero, of characters | |
1044 | in the 'space' character class, immediately followed by zero or one | |
1045 | instances of 'a', then a 'b': | |
1046 | ||
8868edaf | 1047 | [[ $line =~ [[:space:]]*(a)?b ]] |
ac50fbac | 1048 | |
74091dd4 CR |
1049 | That means values for 'line' like 'aab', ' aaaaaab', 'xaby', and ' |
1050 | ab' will all match, as will a line containing a 'b' anywhere in its | |
1051 | value. | |
1052 | ||
1053 | If you want to match a character that's special to the regular | |
1054 | expression grammar ('^$|[]()\.*+?'), it has to be quoted to remove | |
1055 | its special meaning. This means that in the pattern 'xxx.txt', the | |
1056 | '.' matches any character in the string (its usual regular | |
1057 | expression meaning), but in the pattern '"xxx.txt"', it can only | |
1058 | match a literal '.'. | |
1059 | ||
1060 | Likewise, if you want to include a character in your pattern that | |
1061 | has a special meaning to the regular expression grammar, you must | |
1062 | make sure it's not quoted. If you want to anchor a pattern at the | |
1063 | beginning or end of the string, for instance, you cannot quote the | |
1064 | '^' or '$' characters using any form of shell quoting. | |
1065 | ||
1066 | If you want to match 'initial string' at the start of a line, the | |
1067 | following will work: | |
1068 | [[ $line =~ ^"initial string" ]] | |
1069 | but this will not: | |
1070 | [[ $line =~ "^initial string" ]] | |
1071 | because in the second example the '^' is quoted and doesn't have | |
1072 | its usual special meaning. | |
1073 | ||
1074 | It is sometimes difficult to specify a regular expression properly | |
1075 | without using quotes, or to keep track of the quoting used by | |
1076 | regular expressions while paying attention to shell quoting and the | |
1077 | shell's quote removal. Storing the regular expression in a shell | |
1078 | variable is often a useful way to avoid problems with quoting | |
1079 | characters that are special to the shell. For example, the | |
1080 | following is equivalent to the pattern used above: | |
1081 | ||
8868edaf | 1082 | pattern='[[:space:]]*(a)?b' |
ac50fbac CR |
1083 | [[ $line =~ $pattern ]] |
1084 | ||
a0c0a00f | 1085 | Shell programmers should take special care with backslashes, since |
74091dd4 CR |
1086 | backslashes are used by both the shell and regular expressions to |
1087 | remove the special meaning from the following character. This | |
1088 | means that after the shell's word expansions complete (*note Shell | |
1089 | Expansions::), any backslashes remaining in parts of the pattern | |
1090 | that were originally not quoted can remove the special meaning of | |
1091 | pattern characters. If any part of the pattern is quoted, the | |
1092 | shell does its best to ensure that the regular expression treats | |
1093 | those remaining backslashes as literal, if they appeared in a | |
1094 | quoted portion. | |
1095 | ||
1096 | The following two sets of commands are _not_ equivalent: | |
1097 | ||
ac50fbac CR |
1098 | pattern='\.' |
1099 | ||
1100 | [[ . =~ $pattern ]] | |
1101 | [[ . =~ \. ]] | |
1102 | ||
1103 | [[ . =~ "$pattern" ]] | |
1104 | [[ . =~ '\.' ]] | |
1105 | ||
1106 | The first two matches will succeed, but the second two will not, | |
a0c0a00f | 1107 | because in the second two the backslash will be part of the pattern |
74091dd4 CR |
1108 | to be matched. In the first two examples, the pattern passed to |
1109 | the regular expression parser is '\.'. The backslash removes the | |
1110 | special meaning from '.', so the literal '.' matches. In the | |
1111 | second two examples, the pattern passed to the regular expression | |
1112 | parser has the backslash quoted (e.g., '\\\.'), which will not | |
1113 | match the string, since it does not contain a backslash. If the | |
a0c0a00f CR |
1114 | string in the first examples were anything other than '.', say 'a', |
1115 | the pattern would not match, because the quoted '.' in the pattern | |
1116 | loses its special meaning of matching any single character. | |
b80f6443 | 1117 | |
74091dd4 CR |
1118 | Bracket expressions in regular expressions can be sources of errors |
1119 | as well, since characters that are normally special in regular | |
1120 | expressions lose their special meanings between brackets. However, | |
1121 | you can use bracket expressions to match special pattern characters | |
1122 | without quoting them, so they are sometimes useful for this | |
1123 | purpose. | |
1124 | ||
1125 | Though it might seem like a strange way to write it, the following | |
1126 | pattern will match a '.' in the string: | |
1127 | ||
1128 | [[ . =~ [.] ]] | |
1129 | ||
1130 | The shell performs any word expansions before passing the pattern | |
1131 | to the regular expression functions, so you can assume that the | |
1132 | shell's quoting takes precedence. As noted above, the regular | |
1133 | expression parser will interpret any unquoted backslashes remaining | |
1134 | in the pattern after shell expansion according to its own rules. | |
1135 | The intention is to avoid making shell programmers quote things | |
1136 | twice as much as possible, so shell quoting should be sufficient to | |
1137 | quote special pattern characters where that's necessary. | |
1138 | ||
1139 | The array variable 'BASH_REMATCH' records which parts of the string | |
1140 | matched the pattern. The element of 'BASH_REMATCH' with index 0 | |
1141 | contains the portion of the string matching the entire regular | |
1142 | expression. Substrings matched by parenthesized subexpressions | |
1143 | within the regular expression are saved in the remaining | |
1144 | 'BASH_REMATCH' indices. The element of 'BASH_REMATCH' with index N | |
1145 | is the portion of the string matching the Nth parenthesized | |
1146 | subexpression. | |
1147 | ||
1148 | Bash sets 'BASH_REMATCH' in the global scope; declaring it as a | |
1149 | local variable will lead to unexpected results. | |
1150 | ||
cce855bc JA |
1151 | Expressions may be combined using the following operators, listed |
1152 | in decreasing order of precedence: | |
1153 | ||
a0c0a00f CR |
1154 | '( EXPRESSION )' |
1155 | Returns the value of EXPRESSION. This may be used to override | |
1156 | the normal precedence of operators. | |
cce855bc | 1157 | |
a0c0a00f | 1158 | '! EXPRESSION' |
cce855bc JA |
1159 | True if EXPRESSION is false. |
1160 | ||
a0c0a00f | 1161 | 'EXPRESSION1 && EXPRESSION2' |
cce855bc JA |
1162 | True if both EXPRESSION1 and EXPRESSION2 are true. |
1163 | ||
a0c0a00f | 1164 | 'EXPRESSION1 || EXPRESSION2' |
cce855bc | 1165 | True if either EXPRESSION1 or EXPRESSION2 is true. |
ac50fbac | 1166 | |
a0c0a00f CR |
1167 | The '&&' and '||' operators do not evaluate EXPRESSION2 if the |
1168 | value of EXPRESSION1 is sufficient to determine the return value of | |
1169 | the entire conditional expression. | |
ccc6cda3 JA |
1170 | |
1171 | \1f | |
b80f6443 | 1172 | File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands |
ccc6cda3 | 1173 | |
8868edaf | 1174 | 3.2.5.3 Grouping Commands |
b80f6443 | 1175 | ......................... |
ccc6cda3 | 1176 | |
b80f6443 JA |
1177 | Bash provides two ways to group a list of commands to be executed as a |
1178 | unit. When commands are grouped, redirections may be applied to the | |
a0c0a00f CR |
1179 | entire command list. For example, the output of all the commands in the |
1180 | list may be redirected to a single stream. | |
ccc6cda3 | 1181 | |
a0c0a00f | 1182 | '()' |
ccc6cda3 JA |
1183 | ( LIST ) |
1184 | ||
74091dd4 CR |
1185 | Placing a list of commands between parentheses forces the shell to |
1186 | create a subshell (*note Command Execution Environment::), and each | |
1187 | of the commands in LIST is executed in that subshell environment. | |
b80f6443 JA |
1188 | Since the LIST is executed in a subshell, variable assignments do |
1189 | not remain in effect after the subshell completes. | |
ccc6cda3 | 1190 | |
a0c0a00f | 1191 | '{}' |
ccc6cda3 JA |
1192 | { LIST; } |
1193 | ||
1194 | Placing a list of commands between curly braces causes the list to | |
1195 | be executed in the current shell context. No subshell is created. | |
cce855bc | 1196 | The semicolon (or newline) following LIST is required. |
ccc6cda3 JA |
1197 | |
1198 | In addition to the creation of a subshell, there is a subtle | |
1199 | difference between these two constructs due to historical reasons. The | |
74091dd4 CR |
1200 | braces are reserved words, so they must be separated from the LIST by |
1201 | 'blank's or other shell metacharacters. The parentheses are operators, | |
1202 | and are recognized as separate tokens by the shell even if they are not | |
1203 | separated from the LIST by whitespace. | |
ccc6cda3 JA |
1204 | |
1205 | The exit status of both of these constructs is the exit status of | |
1206 | LIST. | |
1207 | ||
3185942a | 1208 | \1f |
495aee44 | 1209 | File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands |
3185942a | 1210 | |
8868edaf | 1211 | 3.2.6 Coprocesses |
3185942a JA |
1212 | ----------------- |
1213 | ||
a0c0a00f | 1214 | A 'coprocess' is a shell command preceded by the 'coproc' reserved word. |
3185942a | 1215 | A coprocess is executed asynchronously in a subshell, as if the command |
a0c0a00f | 1216 | had been terminated with the '&' control operator, with a two-way pipe |
3185942a JA |
1217 | established between the executing shell and the coprocess. |
1218 | ||
74091dd4 CR |
1219 | The syntax for a coprocess is: |
1220 | ||
ac50fbac | 1221 | coproc [NAME] COMMAND [REDIRECTIONS] |
3185942a | 1222 | |
74091dd4 CR |
1223 | This creates a coprocess named NAME. COMMAND may be either a simple |
1224 | command (*note Simple Commands::) or a compound command (*note Compound | |
1225 | Commands::). NAME is a shell variable name. If NAME is not supplied, | |
1226 | the default name is 'COPROC'. | |
1227 | ||
1228 | The recommended form to use for a coprocess is | |
1229 | ||
1230 | coproc NAME { COMMAND; } | |
1231 | ||
1232 | This form is recommended because simple commands result in the coprocess | |
1233 | always being named 'COPROC', and it is simpler to use and more complete | |
1234 | than the other compound commands. | |
1235 | ||
1236 | There are other forms of coprocesses: | |
1237 | ||
1238 | coproc NAME COMPOUND-COMMAND | |
1239 | coproc COMPOUND-COMMAND | |
1240 | coproc SIMPLE-COMMAND | |
1241 | ||
1242 | If COMMAND is a compound command, NAME is optional. The word following | |
1243 | 'coproc' determines whether that word is interpreted as a variable name: | |
1244 | it is interpreted as NAME if it is not a reserved word that introduces a | |
1245 | compound command. If COMMAND is a simple command, NAME is not allowed; | |
1246 | this is to avoid confusion between NAME and the first word of the simple | |
1247 | command. | |
3185942a | 1248 | |
ac50fbac | 1249 | When the coprocess is executed, the shell creates an array variable |
74091dd4 CR |
1250 | (*note Arrays::) named NAME in the context of the executing shell. The |
1251 | standard output of COMMAND is connected via a pipe to a file descriptor | |
1252 | in the executing shell, and that file descriptor is assigned to NAME[0]. | |
1253 | The standard input of COMMAND is connected via a pipe to a file | |
3185942a | 1254 | descriptor in the executing shell, and that file descriptor is assigned |
74091dd4 CR |
1255 | to NAME[1]. This pipe is established before any redirections specified |
1256 | by the command (*note Redirections::). The file descriptors can be | |
1257 | utilized as arguments to shell commands and redirections using standard | |
1258 | word expansions. Other than those created to execute command and | |
1259 | process substitutions, the file descriptors are not available in | |
a0c0a00f | 1260 | subshells. |
3185942a | 1261 | |
495aee44 | 1262 | The process ID of the shell spawned to execute the coprocess is |
74091dd4 | 1263 | available as the value of the variable 'NAME_PID'. The 'wait' builtin |
3185942a JA |
1264 | command may be used to wait for the coprocess to terminate. |
1265 | ||
ac50fbac | 1266 | Since the coprocess is created as an asynchronous command, the |
a0c0a00f | 1267 | 'coproc' command always returns success. The return status of a |
ac50fbac | 1268 | coprocess is the exit status of COMMAND. |
3185942a | 1269 | |
495aee44 CR |
1270 | \1f |
1271 | File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands | |
1272 | ||
8868edaf | 1273 | 3.2.7 GNU Parallel |
495aee44 CR |
1274 | ------------------ |
1275 | ||
ac50fbac CR |
1276 | There are ways to run commands in parallel that are not built into Bash. |
1277 | GNU Parallel is a tool to do just that. | |
1278 | ||
1279 | GNU Parallel, as its name suggests, can be used to build and run | |
495aee44 CR |
1280 | commands in parallel. You may run the same command with different |
1281 | arguments, whether they are filenames, usernames, hostnames, or lines | |
ac50fbac CR |
1282 | read from files. GNU Parallel provides shorthand references to many of |
1283 | the most common operations (input lines, various portions of the input | |
1284 | line, different ways to specify the input source, and so on). Parallel | |
a0c0a00f | 1285 | can replace 'xargs' or feed commands from its input sources to several |
ac50fbac | 1286 | different instances of Bash. |
495aee44 | 1287 | |
74091dd4 CR |
1288 | For a complete description, refer to the GNU Parallel documentation, |
1289 | which is available at | |
1290 | <https://www.gnu.org/software/parallel/parallel_tutorial.html>. | |
ac50fbac | 1291 | |
ccc6cda3 | 1292 | \1f |
cce855bc | 1293 | File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features |
ccc6cda3 | 1294 | |
b80f6443 JA |
1295 | 3.3 Shell Functions |
1296 | =================== | |
ccc6cda3 | 1297 | |
b80f6443 JA |
1298 | Shell functions are a way to group commands for later execution using a |
1299 | single name for the group. They are executed just like a "regular" | |
1300 | command. When the name of a shell function is used as a simple command | |
1301 | name, the list of commands associated with that function name is | |
a0c0a00f CR |
1302 | executed. Shell functions are executed in the current shell context; no |
1303 | new process is created to interpret them. | |
ccc6cda3 | 1304 | |
a0c0a00f | 1305 | Functions are declared using this syntax: |
8868edaf | 1306 | FNAME () COMPOUND-COMMAND [ REDIRECTIONS ] |
495aee44 | 1307 | |
ac50fbac CR |
1308 | or |
1309 | ||
8868edaf | 1310 | function FNAME [()] COMPOUND-COMMAND [ REDIRECTIONS ] |
ccc6cda3 | 1311 | |
8868edaf | 1312 | This defines a shell function named FNAME. The reserved word |
a0c0a00f | 1313 | 'function' is optional. If the 'function' reserved word is supplied, |
74091dd4 CR |
1314 | the parentheses are optional. The "body" of the function is the |
1315 | compound command COMPOUND-COMMAND (*note Compound Commands::). That | |
1316 | command is usually a LIST enclosed between { and }, but may be any | |
1317 | compound command listed above. If the 'function' reserved word is used, | |
1318 | but the parentheses are not supplied, the braces are recommended. | |
8868edaf | 1319 | COMPOUND-COMMAND is executed whenever FNAME is specified as the name of |
74091dd4 CR |
1320 | a simple command. When the shell is in POSIX mode (*note Bash POSIX |
1321 | Mode::), FNAME must be a valid shell name and may not be the same as one | |
1322 | of the special builtins (*note Special Builtins::). In default mode, a | |
8868edaf CR |
1323 | function name can be any unquoted shell word that does not contain '$'. |
1324 | Any redirections (*note Redirections::) associated with the shell | |
1325 | function are performed when the function is executed. A function | |
1326 | definition may be deleted using the '-f' option to the 'unset' builtin | |
1327 | (*note Bourne Shell Builtins::). | |
0628567a | 1328 | |
b80f6443 JA |
1329 | The exit status of a function definition is zero unless a syntax |
1330 | error occurs or a readonly function with the same name already exists. | |
1331 | When executed, the exit status of a function is the exit status of the | |
1332 | last command executed in the body. | |
1333 | ||
1334 | Note that for historical reasons, in the most common usage the curly | |
a0c0a00f CR |
1335 | braces that surround the body of the function must be separated from the |
1336 | body by 'blank's or newlines. This is because the braces are reserved | |
1337 | words and are only recognized as such when they are separated from the | |
1338 | command list by whitespace or another shell metacharacter. Also, when | |
1339 | using the braces, the LIST must be terminated by a semicolon, a '&', or | |
1340 | a newline. | |
1341 | ||
1342 | When a function is executed, the arguments to the function become the | |
1343 | positional parameters during its execution (*note Positional | |
1344 | Parameters::). The special parameter '#' that expands to the number of | |
b80f6443 | 1345 | positional parameters is updated to reflect the change. Special |
a0c0a00f | 1346 | parameter '0' is unchanged. The first element of the 'FUNCNAME' |
b80f6443 | 1347 | variable is set to the name of the function while the function is |
0001803f CR |
1348 | executing. |
1349 | ||
1350 | All other aspects of the shell execution environment are identical | |
a0c0a00f CR |
1351 | between a function and its caller with these exceptions: the 'DEBUG' and |
1352 | 'RETURN' traps are not inherited unless the function has been given the | |
1353 | 'trace' attribute using the 'declare' builtin or the '-o functrace' | |
1354 | option has been enabled with the 'set' builtin, (in which case all | |
1355 | functions inherit the 'DEBUG' and 'RETURN' traps), and the 'ERR' trap is | |
1356 | not inherited unless the '-o errtrace' shell option has been enabled. | |
1357 | *Note Bourne Shell Builtins::, for the description of the 'trap' | |
0001803f | 1358 | builtin. |
ccc6cda3 | 1359 | |
a0c0a00f | 1360 | The 'FUNCNEST' variable, if set to a numeric value greater than 0, |
495aee44 CR |
1361 | defines a maximum function nesting level. Function invocations that |
1362 | exceed the limit cause the entire command to abort. | |
1363 | ||
a0c0a00f CR |
1364 | If the builtin command 'return' is executed in a function, the |
1365 | function completes and execution resumes with the next command after the | |
1366 | function call. Any command associated with the 'RETURN' trap is | |
b80f6443 | 1367 | executed before execution resumes. When a function completes, the |
a0c0a00f CR |
1368 | values of the positional parameters and the special parameter '#' are |
1369 | restored to the values they had prior to the function's execution. If a | |
1370 | numeric argument is given to 'return', that is the function's return | |
1371 | status; otherwise the function's return status is the exit status of the | |
1372 | last command executed before the 'return'. | |
ccc6cda3 | 1373 | |
a0c0a00f | 1374 | Variables local to the function may be declared with the 'local' |
74091dd4 CR |
1375 | builtin ("local variables"). Ordinarily, variables and their values are |
1376 | shared between a function and its caller. These variables are visible | |
1377 | only to the function and the commands it invokes. This is particularly | |
1378 | important when a shell function calls other functions. | |
1379 | ||
1380 | In the following description, the "current scope" is a currently- | |
1381 | executing function. Previous scopes consist of that function's caller | |
1382 | and so on, back to the "global" scope, where the shell is not executing | |
1383 | any shell function. Consequently, a local variable at the current local | |
1384 | scope is a variable declared using the 'local' or 'declare' builtins in | |
1385 | the function that is currently executing. | |
d233b485 CR |
1386 | |
1387 | Local variables "shadow" variables with the same name declared at | |
1388 | previous scopes. For instance, a local variable declared in a function | |
1389 | hides a global variable of the same name: references and assignments | |
1390 | refer to the local variable, leaving the global variable unmodified. | |
1391 | When the function returns, the global variable is once again visible. | |
1392 | ||
74091dd4 | 1393 | The shell uses "dynamic scoping" to control a variable's visibility |
d233b485 CR |
1394 | within functions. With dynamic scoping, visible variables and their |
1395 | values are a result of the sequence of function calls that caused | |
1396 | execution to reach the current function. The value of a variable that a | |
1397 | function sees depends on its value within its caller, if any, whether | |
1398 | that caller is the "global" scope or another shell function. This is | |
1399 | also the value that a local variable declaration "shadows", and the | |
1400 | value that is restored when the function returns. | |
1401 | ||
74091dd4 CR |
1402 | For example, if a variable 'var' is declared as local in function |
1403 | 'func1', and 'func1' calls another function 'func2', references to 'var' | |
1404 | made from within 'func2' will resolve to the local variable 'var' from | |
1405 | 'func1', shadowing any global variable named 'var'. | |
d233b485 CR |
1406 | |
1407 | The following script demonstrates this behavior. When executed, the | |
1408 | script displays | |
1409 | ||
1410 | In func2, var = func1 local | |
1411 | ||
1412 | func1() | |
1413 | { | |
1414 | local var='func1 local' | |
1415 | func2 | |
1416 | } | |
1417 | ||
1418 | func2() | |
1419 | { | |
1420 | echo "In func2, var = $var" | |
1421 | } | |
1422 | ||
1423 | var=global | |
1424 | func1 | |
1425 | ||
1426 | The 'unset' builtin also acts using the same dynamic scope: if a | |
1427 | variable is local to the current scope, 'unset' will unset it; otherwise | |
1428 | the unset will refer to the variable found in any calling scope as | |
1429 | described above. If a variable at the current local scope is unset, it | |
74091dd4 CR |
1430 | will remain so (appearing as unset) until it is reset in that scope or |
1431 | until the function returns. Once the function returns, any instance of | |
1432 | the variable at a previous scope will become visible. If the unset acts | |
1433 | on a variable at a previous scope, any instance of a variable with that | |
1434 | name that had been shadowed will become visible (see below how | |
1435 | 'localvar_unset'shell option changes this behavior). | |
ccc6cda3 | 1436 | |
a0c0a00f CR |
1437 | Function names and definitions may be listed with the '-f' option to |
1438 | the 'declare' ('typeset') builtin command (*note Bash Builtins::). The | |
1439 | '-F' option to 'declare' or 'typeset' will list the function names only | |
1440 | (and optionally the source file and line number, if the 'extdebug' shell | |
74091dd4 CR |
1441 | option is enabled). Functions may be exported so that child shell |
1442 | processes (those created when executing a separate shell invocation) | |
a0c0a00f | 1443 | automatically have them defined with the '-f' option to the 'export' |
d233b485 | 1444 | builtin (*note Bourne Shell Builtins::). |
b80f6443 | 1445 | |
a0c0a00f | 1446 | Functions may be recursive. The 'FUNCNEST' variable may be used to |
495aee44 CR |
1447 | limit the depth of the function call stack and restrict the number of |
1448 | function invocations. By default, no limit is placed on the number of | |
a0c0a00f | 1449 | recursive calls. |
ccc6cda3 JA |
1450 | |
1451 | \1f | |
1452 | File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features | |
1453 | ||
b80f6443 JA |
1454 | 3.4 Shell Parameters |
1455 | ==================== | |
ccc6cda3 JA |
1456 | |
1457 | * Menu: | |
1458 | ||
1459 | * Positional Parameters:: The shell's command-line arguments. | |
b80f6443 | 1460 | * Special Parameters:: Parameters denoted by special characters. |
ccc6cda3 | 1461 | |
74091dd4 CR |
1462 | A "parameter" is an entity that stores values. It can be a 'name', a |
1463 | number, or one of the special characters listed below. A "variable" is | |
1464 | a parameter denoted by a 'name'. A variable has a 'value' and zero or | |
1465 | more 'attributes'. Attributes are assigned using the 'declare' builtin | |
1466 | command (see the description of the 'declare' builtin in *note Bash | |
1467 | Builtins::). | |
ccc6cda3 JA |
1468 | |
1469 | A parameter is set if it has been assigned a value. The null string | |
1470 | is a valid value. Once a variable is set, it may be unset only by using | |
a0c0a00f | 1471 | the 'unset' builtin command. |
ccc6cda3 JA |
1472 | |
1473 | A variable may be assigned to by a statement of the form | |
1474 | NAME=[VALUE] | |
a0c0a00f | 1475 | If VALUE is not given, the variable is assigned the null string. All |
ccc6cda3 | 1476 | VALUEs undergo tilde expansion, parameter and variable expansion, |
74091dd4 CR |
1477 | command substitution, arithmetic expansion, and quote removal (*note |
1478 | Shell Parameter Expansion::). If the variable has its 'integer' | |
1479 | attribute set, then VALUE is evaluated as an arithmetic expression even | |
1480 | if the '$((...))' expansion is not used (*note Arithmetic Expansion::). | |
1481 | Word splitting and filename expansion are not performed. Assignment | |
1482 | statements may also appear as arguments to the 'alias', 'declare', | |
1483 | 'typeset', 'export', 'readonly', and 'local' builtin commands | |
1484 | ("declaration" commands). When in POSIX mode (*note Bash POSIX Mode::), | |
1485 | these builtins may appear in a command after one or more instances of | |
1486 | the 'command' builtin and retain these assignment statement properties. | |
ccc6cda3 | 1487 | |
95732b49 | 1488 | In the context where an assignment statement is assigning a value to |
a0c0a00f CR |
1489 | a shell variable or array index (*note Arrays::), the '+=' operator can |
1490 | be used to append to or add to the variable's previous value. This | |
1491 | includes arguments to builtin commands such as 'declare' that accept | |
74091dd4 CR |
1492 | assignment statements (declaration commands). When '+=' is applied to a |
1493 | variable for which the 'integer' attribute has been set, VALUE is | |
a0c0a00f CR |
1494 | evaluated as an arithmetic expression and added to the variable's |
1495 | current value, which is also evaluated. When '+=' is applied to an | |
1496 | array variable using compound assignment (*note Arrays::), the | |
1497 | variable's value is not unset (as it is when using '='), and new values | |
1498 | are appended to the array beginning at one greater than the array's | |
1499 | maximum index (for indexed arrays), or added as additional key-value | |
1500 | pairs in an associative array. When applied to a string-valued | |
1501 | variable, VALUE is expanded and appended to the variable's value. | |
1502 | ||
74091dd4 | 1503 | A variable can be assigned the 'nameref' attribute using the '-n' |
a0c0a00f | 1504 | option to the 'declare' or 'local' builtin commands (*note Bash |
74091dd4 | 1505 | Builtins::) to create a "nameref", or a reference to another variable. |
ac50fbac | 1506 | This allows variables to be manipulated indirectly. Whenever the |
a0c0a00f CR |
1507 | nameref variable is referenced, assigned to, unset, or has its |
1508 | attributes modified (other than using or changing the nameref attribute | |
1509 | itself), the operation is actually performed on the variable specified | |
1510 | by the nameref variable's value. A nameref is commonly used within | |
1511 | shell functions to refer to a variable whose name is passed as an | |
1512 | argument to the function. For instance, if a variable name is passed to | |
1513 | a shell function as its first argument, running | |
ac50fbac | 1514 | declare -n ref=$1 |
74091dd4 | 1515 | inside the function creates a nameref variable 'ref' whose value is the |
a0c0a00f | 1516 | variable name passed as the first argument. References and assignments |
74091dd4 | 1517 | to 'ref', and changes to its attributes, are treated as references, |
a0c0a00f CR |
1518 | assignments, and attribute modifications to the variable whose name was |
1519 | passed as '$1'. | |
ac50fbac | 1520 | |
a0c0a00f | 1521 | If the control variable in a 'for' loop has the nameref attribute, |
ac50fbac CR |
1522 | the list of words can be a list of shell variables, and a name reference |
1523 | will be established for each word in the list, in turn, when the loop is | |
a0c0a00f | 1524 | executed. Array variables cannot be given the nameref attribute. |
ac50fbac | 1525 | However, nameref variables can reference array variables and subscripted |
a0c0a00f CR |
1526 | array variables. Namerefs can be unset using the '-n' option to the |
1527 | 'unset' builtin (*note Bourne Shell Builtins::). Otherwise, if 'unset' | |
ac50fbac CR |
1528 | is executed with the name of a nameref variable as an argument, the |
1529 | variable referenced by the nameref variable will be unset. | |
1530 | ||
ccc6cda3 JA |
1531 | \1f |
1532 | File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters | |
1533 | ||
b80f6443 JA |
1534 | 3.4.1 Positional Parameters |
1535 | --------------------------- | |
ccc6cda3 | 1536 | |
74091dd4 | 1537 | A "positional parameter" is a parameter denoted by one or more digits, |
a0c0a00f | 1538 | other than the single digit '0'. Positional parameters are assigned |
ccc6cda3 | 1539 | from the shell's arguments when it is invoked, and may be reassigned |
a0c0a00f CR |
1540 | using the 'set' builtin command. Positional parameter 'N' may be |
1541 | referenced as '${N}', or as '$N' when 'N' consists of a single digit. | |
bb70624e | 1542 | Positional parameters may not be assigned to with assignment statements. |
a0c0a00f | 1543 | The 'set' and 'shift' builtins are used to set and unset them (*note |
28ef6c31 JA |
1544 | Shell Builtin Commands::). The positional parameters are temporarily |
1545 | replaced when a shell function is executed (*note Shell Functions::). | |
ccc6cda3 | 1546 | |
a0c0a00f CR |
1547 | When a positional parameter consisting of more than a single digit is |
1548 | expanded, it must be enclosed in braces. | |
ccc6cda3 JA |
1549 | |
1550 | \1f | |
1551 | File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters | |
1552 | ||
b80f6443 JA |
1553 | 3.4.2 Special Parameters |
1554 | ------------------------ | |
ccc6cda3 | 1555 | |
b80f6443 | 1556 | The shell treats several parameters specially. These parameters may |
ccc6cda3 JA |
1557 | only be referenced; assignment to them is not allowed. |
1558 | ||
a0c0a00f CR |
1559 | '*' |
1560 | ($*) Expands to the positional parameters, starting from one. When | |
1561 | the expansion is not within double quotes, each positional | |
ac50fbac CR |
1562 | parameter expands to a separate word. In contexts where it is |
1563 | performed, those words are subject to further word splitting and | |
8868edaf | 1564 | filename expansion. When the expansion occurs within double |
ac50fbac | 1565 | quotes, it expands to a single word with the value of each |
a0c0a00f CR |
1566 | parameter separated by the first character of the 'IFS' special |
1567 | variable. That is, '"$*"' is equivalent to '"$1C$2C..."', where C | |
1568 | is the first character of the value of the 'IFS' variable. If | |
1569 | 'IFS' is unset, the parameters are separated by spaces. If 'IFS' | |
ac50fbac | 1570 | is null, the parameters are joined without intervening separators. |
ccc6cda3 | 1571 | |
a0c0a00f | 1572 | '@' |
d233b485 CR |
1573 | ($@) Expands to the positional parameters, starting from one. In |
1574 | contexts where word splitting is performed, this expands each | |
1575 | positional parameter to a separate word; if not within double | |
1576 | quotes, these words are subject to word splitting. In contexts | |
1577 | where word splitting is not performed, this expands to a single | |
1578 | word with each positional parameter separated by a space. When the | |
1579 | expansion occurs within double quotes, and word splitting is | |
1580 | performed, each parameter expands to a separate word. That is, | |
1581 | '"$@"' is equivalent to '"$1" "$2" ...'. If the double-quoted | |
1582 | expansion occurs within a word, the expansion of the first | |
1583 | parameter is joined with the beginning part of the original word, | |
1584 | and the expansion of the last parameter is joined with the last | |
1585 | part of the original word. When there are no positional | |
1586 | parameters, '"$@"' and '$@' expand to nothing (i.e., they are | |
1587 | removed). | |
a0c0a00f CR |
1588 | |
1589 | '#' | |
ac50fbac | 1590 | ($#) Expands to the number of positional parameters in decimal. |
ccc6cda3 | 1591 | |
a0c0a00f CR |
1592 | '?' |
1593 | ($?) Expands to the exit status of the most recently executed | |
ac50fbac | 1594 | foreground pipeline. |
ccc6cda3 | 1595 | |
a0c0a00f | 1596 | '-' |
ac50fbac | 1597 | ($-, a hyphen.) Expands to the current option flags as specified |
a0c0a00f CR |
1598 | upon invocation, by the 'set' builtin command, or those set by the |
1599 | shell itself (such as the '-i' option). | |
ccc6cda3 | 1600 | |
a0c0a00f | 1601 | '$' |
74091dd4 CR |
1602 | ($$) Expands to the process ID of the shell. In a subshell, it |
1603 | expands to the process ID of the invoking shell, not the subshell. | |
ccc6cda3 | 1604 | |
a0c0a00f CR |
1605 | '!' |
1606 | ($!) Expands to the process ID of the job most recently placed | |
1607 | into the background, whether executed as an asynchronous command or | |
1608 | using the 'bg' builtin (*note Job Control Builtins::). | |
1609 | ||
1610 | '0' | |
1611 | ($0) Expands to the name of the shell or shell script. This is set | |
1612 | at shell initialization. If Bash is invoked with a file of | |
1613 | commands (*note Shell Scripts::), '$0' is set to the name of that | |
1614 | file. If Bash is started with the '-c' option (*note Invoking | |
1615 | Bash::), then '$0' is set to the first argument after the string to | |
1616 | be executed, if one is present. Otherwise, it is set to the | |
ac50fbac | 1617 | filename used to invoke Bash, as given by argument zero. |
ccc6cda3 | 1618 | |
ccc6cda3 JA |
1619 | \1f |
1620 | File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features | |
1621 | ||
b80f6443 JA |
1622 | 3.5 Shell Expansions |
1623 | ==================== | |
ccc6cda3 | 1624 | |
b80f6443 | 1625 | Expansion is performed on the command line after it has been split into |
a0c0a00f | 1626 | 'token's. There are seven kinds of expansion performed: |
ac50fbac | 1627 | |
ccc6cda3 | 1628 | * brace expansion |
ccc6cda3 | 1629 | * tilde expansion |
ccc6cda3 | 1630 | * parameter and variable expansion |
ccc6cda3 | 1631 | * command substitution |
ccc6cda3 | 1632 | * arithmetic expansion |
ccc6cda3 | 1633 | * word splitting |
ccc6cda3 JA |
1634 | * filename expansion |
1635 | ||
1636 | * Menu: | |
1637 | ||
cce855bc JA |
1638 | * Brace Expansion:: Expansion of expressions within braces. |
1639 | * Tilde Expansion:: Expansion of the ~ character. | |
ccc6cda3 JA |
1640 | * Shell Parameter Expansion:: How Bash expands variables to their values. |
1641 | * Command Substitution:: Using the output of a command as an argument. | |
cce855bc | 1642 | * Arithmetic Expansion:: How to use arithmetic in shell expansions. |
ccc6cda3 JA |
1643 | * Process Substitution:: A way to write and read to and from a |
1644 | command. | |
1645 | * Word Splitting:: How the results of expansion are split into separate | |
1646 | arguments. | |
1647 | * Filename Expansion:: A shorthand for specifying filenames matching patterns. | |
1648 | * Quote Removal:: How and when quote characters are removed from | |
1649 | words. | |
1650 | ||
ac50fbac CR |
1651 | The order of expansions is: brace expansion; tilde expansion, |
1652 | parameter and variable expansion, arithmetic expansion, and command | |
1653 | substitution (done in a left-to-right fashion); word splitting; and | |
1654 | filename expansion. | |
ccc6cda3 JA |
1655 | |
1656 | On systems that can support it, there is an additional expansion | |
74091dd4 CR |
1657 | available: "process substitution". This is performed at the same time |
1658 | as tilde, parameter, variable, and arithmetic expansion and command | |
ac50fbac | 1659 | substitution. |
ccc6cda3 | 1660 | |
a0c0a00f | 1661 | After these expansions are performed, quote characters present in the |
74091dd4 CR |
1662 | original word are removed unless they have been quoted themselves |
1663 | ("quote removal"). | |
a0c0a00f | 1664 | |
ccc6cda3 | 1665 | Only brace expansion, word splitting, and filename expansion can |
d233b485 | 1666 | increase the number of words of the expansion; other expansions expand a |
ccc6cda3 | 1667 | single word to a single word. The only exceptions to this are the |
d233b485 CR |
1668 | expansions of '"$@"' and '$*' (*note Special Parameters::), and |
1669 | '"${NAME[@]}"' and '${NAME[*]}' (*note Arrays::). | |
ccc6cda3 | 1670 | |
a0c0a00f | 1671 | After all expansions, 'quote removal' (*note Quote Removal::) is |
ccc6cda3 JA |
1672 | performed. |
1673 | ||
1674 | \1f | |
cce855bc JA |
1675 | File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions |
1676 | ||
b80f6443 JA |
1677 | 3.5.1 Brace Expansion |
1678 | --------------------- | |
cce855bc | 1679 | |
b80f6443 | 1680 | Brace expansion is a mechanism by which arbitrary strings may be |
74091dd4 | 1681 | generated. This mechanism is similar to "filename expansion" (*note |
ac50fbac | 1682 | Filename Expansion::), but the filenames generated need not exist. |
cce855bc | 1683 | Patterns to be brace expanded take the form of an optional PREAMBLE, |
ac50fbac | 1684 | followed by either a series of comma-separated strings or a sequence |
b80f6443 JA |
1685 | expression between a pair of braces, followed by an optional POSTSCRIPT. |
1686 | The preamble is prefixed to each string contained within the braces, and | |
1687 | the postscript is then appended to each resulting string, expanding left | |
1688 | to right. | |
cce855bc JA |
1689 | |
1690 | Brace expansions may be nested. The results of each expanded string | |
1691 | are not sorted; left to right order is preserved. For example, | |
1692 | bash$ echo a{d,c,b}e | |
1693 | ade ace abe | |
1694 | ||
a0c0a00f | 1695 | A sequence expression takes the form '{X..Y[..INCR]}', where X and Y |
74091dd4 CR |
1696 | are either integers or letters, and INCR, an optional increment, is an |
1697 | integer. When integers are supplied, the expression expands to each | |
1698 | number between X and Y, inclusive. Supplied integers may be prefixed | |
1699 | with '0' to force each term to have the same width. When either X or Y | |
1700 | begins with a zero, the shell attempts to force all generated terms to | |
1701 | contain the same number of digits, zero-padding where necessary. When | |
1702 | letters are supplied, the expression expands to each character | |
1703 | lexicographically between X and Y, inclusive, using the default C | |
1704 | locale. Note that both X and Y must be of the same type (integer or | |
1705 | letter). When the increment is supplied, it is used as the difference | |
1706 | between each term. The default increment is 1 or -1 as appropriate. | |
b80f6443 | 1707 | |
cce855bc JA |
1708 | Brace expansion is performed before any other expansions, and any |
1709 | characters special to other expansions are preserved in the result. It | |
1710 | is strictly textual. Bash does not apply any syntactic interpretation | |
d233b485 | 1711 | to the context of the expansion or the text between the braces. |
cce855bc JA |
1712 | |
1713 | A correctly-formed brace expansion must contain unquoted opening and | |
b80f6443 JA |
1714 | closing braces, and at least one unquoted comma or a valid sequence |
1715 | expression. Any incorrectly formed brace expansion is left unchanged. | |
1716 | ||
a0c0a00f | 1717 | A { or ',' may be quoted with a backslash to prevent its being |
b80f6443 | 1718 | considered part of a brace expression. To avoid conflicts with |
a0c0a00f | 1719 | parameter expansion, the string '${' is not considered eligible for |
8868edaf | 1720 | brace expansion, and inhibits brace expansion until the closing '}'. |
cce855bc JA |
1721 | |
1722 | This construct is typically used as shorthand when the common prefix | |
1723 | of the strings to be generated is longer than in the above example: | |
1724 | mkdir /usr/local/src/bash/{old,new,dist,bugs} | |
1725 | or | |
1726 | chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}} | |
1727 | ||
1728 | \1f | |
1729 | File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions | |
1730 | ||
b80f6443 JA |
1731 | 3.5.2 Tilde Expansion |
1732 | --------------------- | |
cce855bc | 1733 | |
a0c0a00f | 1734 | If a word begins with an unquoted tilde character ('~'), all of the |
cce855bc | 1735 | characters up to the first unquoted slash (or all characters, if there |
74091dd4 | 1736 | is no unquoted slash) are considered a "tilde-prefix". If none of the |
cce855bc | 1737 | characters in the tilde-prefix are quoted, the characters in the |
74091dd4 | 1738 | tilde-prefix following the tilde are treated as a possible "login name". |
cce855bc | 1739 | If this login name is the null string, the tilde is replaced with the |
a0c0a00f | 1740 | value of the 'HOME' shell variable. If 'HOME' is unset, the home |
cce855bc JA |
1741 | directory of the user executing the shell is substituted instead. |
1742 | Otherwise, the tilde-prefix is replaced with the home directory | |
1743 | associated with the specified login name. | |
1744 | ||
a0c0a00f CR |
1745 | If the tilde-prefix is '~+', the value of the shell variable 'PWD' |
1746 | replaces the tilde-prefix. If the tilde-prefix is '~-', the value of | |
1747 | the shell variable 'OLDPWD', if it is set, is substituted. | |
cce855bc JA |
1748 | |
1749 | If the characters following the tilde in the tilde-prefix consist of | |
a0c0a00f | 1750 | a number N, optionally prefixed by a '+' or a '-', the tilde-prefix is |
cce855bc | 1751 | replaced with the corresponding element from the directory stack, as it |
a0c0a00f | 1752 | would be displayed by the 'dirs' builtin invoked with the characters |
cce855bc | 1753 | following tilde in the tilde-prefix as an argument (*note The Directory |
28ef6c31 | 1754 | Stack::). If the tilde-prefix, sans the tilde, consists of a number |
a0c0a00f | 1755 | without a leading '+' or '-', '+' is assumed. |
cce855bc JA |
1756 | |
1757 | If the login name is invalid, or the tilde expansion fails, the word | |
1758 | is left unchanged. | |
1759 | ||
1760 | Each variable assignment is checked for unquoted tilde-prefixes | |
a0c0a00f | 1761 | immediately following a ':' or the first '='. In these cases, tilde |
ac50fbac | 1762 | expansion is also performed. Consequently, one may use filenames with |
a0c0a00f CR |
1763 | tildes in assignments to 'PATH', 'MAILPATH', and 'CDPATH', and the shell |
1764 | assigns the expanded value. | |
cce855bc JA |
1765 | |
1766 | The following table shows how Bash treats unquoted tilde-prefixes: | |
1767 | ||
a0c0a00f CR |
1768 | '~' |
1769 | The value of '$HOME' | |
1770 | '~/foo' | |
1771 | '$HOME/foo' | |
cce855bc | 1772 | |
a0c0a00f CR |
1773 | '~fred/foo' |
1774 | The subdirectory 'foo' of the home directory of the user 'fred' | |
cce855bc | 1775 | |
a0c0a00f CR |
1776 | '~+/foo' |
1777 | '$PWD/foo' | |
cce855bc | 1778 | |
a0c0a00f CR |
1779 | '~-/foo' |
1780 | '${OLDPWD-'~-'}/foo' | |
cce855bc | 1781 | |
a0c0a00f CR |
1782 | '~N' |
1783 | The string that would be displayed by 'dirs +N' | |
cce855bc | 1784 | |
a0c0a00f CR |
1785 | '~+N' |
1786 | The string that would be displayed by 'dirs +N' | |
cce855bc | 1787 | |
a0c0a00f CR |
1788 | '~-N' |
1789 | The string that would be displayed by 'dirs -N' | |
cce855bc | 1790 | |
d233b485 CR |
1791 | Bash also performs tilde expansion on words satisfying the conditions |
1792 | of variable assignments (*note Shell Parameters::) when they appear as | |
1793 | arguments to simple commands. Bash does not do this, except for the | |
74091dd4 | 1794 | declaration commands listed above, when in POSIX mode. |
d233b485 | 1795 | |
cce855bc JA |
1796 | \1f |
1797 | File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions | |
ccc6cda3 | 1798 | |
b80f6443 JA |
1799 | 3.5.3 Shell Parameter Expansion |
1800 | ------------------------------- | |
ccc6cda3 | 1801 | |
a0c0a00f | 1802 | The '$' character introduces parameter expansion, command substitution, |
b80f6443 JA |
1803 | or arithmetic expansion. The parameter name or symbol to be expanded |
1804 | may be enclosed in braces, which are optional but serve to protect the | |
1805 | variable to be expanded from characters immediately following it which | |
1806 | could be interpreted as part of the name. | |
ccc6cda3 | 1807 | |
a0c0a00f | 1808 | When braces are used, the matching ending brace is the first '}' not |
cce855bc JA |
1809 | escaped by a backslash or within a quoted string, and not within an |
1810 | embedded arithmetic expansion, command substitution, or parameter | |
1811 | expansion. | |
1812 | ||
ccc6cda3 | 1813 | The basic form of parameter expansion is ${PARAMETER}. The value of |
ac50fbac CR |
1814 | PARAMETER is substituted. The PARAMETER is a shell parameter as |
1815 | described above (*note Shell Parameters::) or an array reference (*note | |
1816 | Arrays::). The braces are required when PARAMETER is a positional | |
1817 | parameter with more than one digit, or when PARAMETER is followed by a | |
1818 | character that is not to be interpreted as part of its name. | |
1819 | ||
a0c0a00f | 1820 | If the first character of PARAMETER is an exclamation point (!), and |
74091dd4 | 1821 | PARAMETER is not a nameref, it introduces a level of indirection. Bash |
d233b485 CR |
1822 | uses the value formed by expanding the rest of PARAMETER as the new |
1823 | PARAMETER; this is then expanded and that value is used in the rest of | |
1824 | the expansion, rather than the expansion of the original PARAMETER. | |
1825 | This is known as 'indirect expansion'. The value is subject to tilde | |
1826 | expansion, parameter expansion, command substitution, and arithmetic | |
1827 | expansion. If PARAMETER is a nameref, this expands to the name of the | |
1828 | variable referenced by PARAMETER instead of performing the complete | |
1829 | indirect expansion. The exceptions to this are the expansions of | |
1830 | ${!PREFIX*} and ${!NAME[@]} described below. The exclamation point must | |
1831 | immediately follow the left brace in order to introduce indirection. | |
ccc6cda3 JA |
1832 | |
1833 | In each of the cases below, WORD is subject to tilde expansion, | |
1834 | parameter expansion, command substitution, and arithmetic expansion. | |
bb70624e | 1835 | |
17345e5a | 1836 | When not performing substring expansion, using the form described |
a0c0a00f | 1837 | below (e.g., ':-'), Bash tests for a parameter that is unset or null. |
ac50fbac CR |
1838 | Omitting the colon results in a test only for a parameter that is unset. |
1839 | Put another way, if the colon is included, the operator tests for both | |
17345e5a JA |
1840 | PARAMETER's existence and that its value is not null; if the colon is |
1841 | omitted, the operator tests only for existence. | |
ccc6cda3 | 1842 | |
a0c0a00f | 1843 | '${PARAMETER:-WORD}' |
ccc6cda3 JA |
1844 | If PARAMETER is unset or null, the expansion of WORD is |
1845 | substituted. Otherwise, the value of PARAMETER is substituted. | |
1846 | ||
74091dd4 CR |
1847 | $ v=123 |
1848 | $ echo ${v-unset} | |
1849 | 123 | |
1850 | ||
a0c0a00f CR |
1851 | '${PARAMETER:=WORD}' |
1852 | If PARAMETER is unset or null, the expansion of WORD is assigned to | |
1853 | PARAMETER. The value of PARAMETER is then substituted. Positional | |
1854 | parameters and special parameters may not be assigned to in this | |
1855 | way. | |
ccc6cda3 | 1856 | |
74091dd4 CR |
1857 | $ var= |
1858 | $ : ${var:=DEFAULT} | |
1859 | $ echo $var | |
1860 | DEFAULT | |
1861 | ||
a0c0a00f | 1862 | '${PARAMETER:?WORD}' |
ccc6cda3 JA |
1863 | If PARAMETER is null or unset, the expansion of WORD (or a message |
1864 | to that effect if WORD is not present) is written to the standard | |
1865 | error and the shell, if it is not interactive, exits. Otherwise, | |
1866 | the value of PARAMETER is substituted. | |
1867 | ||
74091dd4 CR |
1868 | $ var= |
1869 | $ : ${var:?var is unset or null} | |
1870 | bash: var: var is unset or null | |
1871 | ||
a0c0a00f | 1872 | '${PARAMETER:+WORD}' |
ccc6cda3 JA |
1873 | If PARAMETER is null or unset, nothing is substituted, otherwise |
1874 | the expansion of WORD is substituted. | |
1875 | ||
74091dd4 CR |
1876 | $ var=123 |
1877 | $ echo ${var:+var is set and not null} | |
1878 | var is set and not null | |
1879 | ||
a0c0a00f CR |
1880 | '${PARAMETER:OFFSET}' |
1881 | '${PARAMETER:OFFSET:LENGTH}' | |
ac50fbac CR |
1882 | This is referred to as Substring Expansion. It expands to up to |
1883 | LENGTH characters of the value of PARAMETER starting at the | |
74091dd4 CR |
1884 | character specified by OFFSET. If PARAMETER is '@' or '*', an |
1885 | indexed array subscripted by '@' or '*', or an associative array | |
1886 | name, the results differ as described below. If LENGTH is omitted, | |
1887 | it expands to the substring of the value of PARAMETER starting at | |
1888 | the character specified by OFFSET and extending to the end of the | |
ac50fbac CR |
1889 | value. LENGTH and OFFSET are arithmetic expressions (*note Shell |
1890 | Arithmetic::). | |
ccc6cda3 | 1891 | |
ccc6cda3 | 1892 | If OFFSET evaluates to a number less than zero, the value is used |
ac50fbac CR |
1893 | as an offset in characters from the end of the value of PARAMETER. |
1894 | If LENGTH evaluates to a number less than zero, it is interpreted | |
1895 | as an offset in characters from the end of the value of PARAMETER | |
1896 | rather than a number of characters, and the expansion is the | |
1897 | characters between OFFSET and that result. Note that a negative | |
1898 | offset must be separated from the colon by at least one space to | |
a0c0a00f | 1899 | avoid being confused with the ':-' expansion. |
ac50fbac CR |
1900 | |
1901 | Here are some examples illustrating substring expansion on | |
1902 | parameters and subscripted arrays: | |
1903 | ||
1904 | $ string=01234567890abcdefgh | |
1905 | $ echo ${string:7} | |
1906 | 7890abcdefgh | |
1907 | $ echo ${string:7:0} | |
d233b485 | 1908 | |
ac50fbac CR |
1909 | $ echo ${string:7:2} |
1910 | 78 | |
1911 | $ echo ${string:7:-2} | |
1912 | 7890abcdef | |
1913 | $ echo ${string: -7} | |
1914 | bcdefgh | |
1915 | $ echo ${string: -7:0} | |
d233b485 | 1916 | |
ac50fbac CR |
1917 | $ echo ${string: -7:2} |
1918 | bc | |
1919 | $ echo ${string: -7:-2} | |
1920 | bcdef | |
1921 | $ set -- 01234567890abcdefgh | |
1922 | $ echo ${1:7} | |
1923 | 7890abcdefgh | |
1924 | $ echo ${1:7:0} | |
d233b485 | 1925 | |
ac50fbac CR |
1926 | $ echo ${1:7:2} |
1927 | 78 | |
1928 | $ echo ${1:7:-2} | |
1929 | 7890abcdef | |
1930 | $ echo ${1: -7} | |
1931 | bcdefgh | |
1932 | $ echo ${1: -7:0} | |
d233b485 | 1933 | |
ac50fbac CR |
1934 | $ echo ${1: -7:2} |
1935 | bc | |
1936 | $ echo ${1: -7:-2} | |
1937 | bcdef | |
1938 | $ array[0]=01234567890abcdefgh | |
1939 | $ echo ${array[0]:7} | |
1940 | 7890abcdefgh | |
1941 | $ echo ${array[0]:7:0} | |
d233b485 | 1942 | |
ac50fbac CR |
1943 | $ echo ${array[0]:7:2} |
1944 | 78 | |
1945 | $ echo ${array[0]:7:-2} | |
1946 | 7890abcdef | |
1947 | $ echo ${array[0]: -7} | |
1948 | bcdefgh | |
1949 | $ echo ${array[0]: -7:0} | |
d233b485 | 1950 | |
ac50fbac CR |
1951 | $ echo ${array[0]: -7:2} |
1952 | bc | |
1953 | $ echo ${array[0]: -7:-2} | |
1954 | bcdef | |
1955 | ||
74091dd4 CR |
1956 | If PARAMETER is '@' or '*', the result is LENGTH positional |
1957 | parameters beginning at OFFSET. A negative OFFSET is taken | |
1958 | relative to one greater than the greatest positional parameter, so | |
1959 | an offset of -1 evaluates to the last positional parameter. It is | |
1960 | an expansion error if LENGTH evaluates to a number less than zero. | |
ac50fbac CR |
1961 | |
1962 | The following examples illustrate substring expansion using | |
1963 | positional parameters: | |
1964 | ||
1965 | $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
1966 | $ echo ${@:7} | |
1967 | 7 8 9 0 a b c d e f g h | |
1968 | $ echo ${@:7:0} | |
d233b485 | 1969 | |
ac50fbac CR |
1970 | $ echo ${@:7:2} |
1971 | 7 8 | |
1972 | $ echo ${@:7:-2} | |
1973 | bash: -2: substring expression < 0 | |
1974 | $ echo ${@: -7:2} | |
1975 | b c | |
1976 | $ echo ${@:0} | |
1977 | ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
1978 | $ echo ${@:0:2} | |
1979 | ./bash 1 | |
1980 | $ echo ${@: -7:0} | |
d233b485 | 1981 | |
a0c0a00f CR |
1982 | |
1983 | If PARAMETER is an indexed array name subscripted by '@' or '*', | |
ac50fbac | 1984 | the result is the LENGTH members of the array beginning with |
a0c0a00f CR |
1985 | '${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to one |
1986 | greater than the maximum index of the specified array. It is an | |
1987 | expansion error if LENGTH evaluates to a number less than zero. | |
ac50fbac CR |
1988 | |
1989 | These examples show how you can use substring expansion with | |
1990 | indexed arrays: | |
1991 | ||
1992 | $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h) | |
1993 | $ echo ${array[@]:7} | |
1994 | 7 8 9 0 a b c d e f g h | |
1995 | $ echo ${array[@]:7:2} | |
1996 | 7 8 | |
1997 | $ echo ${array[@]: -7:2} | |
1998 | b c | |
1999 | $ echo ${array[@]: -7:-2} | |
2000 | bash: -2: substring expression < 0 | |
2001 | $ echo ${array[@]:0} | |
2002 | 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h | |
2003 | $ echo ${array[@]:0:2} | |
2004 | 0 1 | |
2005 | $ echo ${array[@]: -7:0} | |
d233b485 | 2006 | |
a0c0a00f | 2007 | |
ac50fbac CR |
2008 | Substring expansion applied to an associative array produces |
2009 | undefined results. | |
2010 | ||
95732b49 | 2011 | Substring indexing is zero-based unless the positional parameters |
3185942a | 2012 | are used, in which case the indexing starts at 1 by default. If |
8868edaf | 2013 | OFFSET is 0, and the positional parameters are used, '$0' is |
3185942a | 2014 | prefixed to the list. |
ccc6cda3 | 2015 | |
a0c0a00f CR |
2016 | '${!PREFIX*}' |
2017 | '${!PREFIX@}' | |
bb70624e | 2018 | Expands to the names of variables whose names begin with PREFIX, |
a0c0a00f CR |
2019 | separated by the first character of the 'IFS' special variable. |
2020 | When '@' is used and the expansion appears within double quotes, | |
3185942a | 2021 | each variable name expands to a separate word. |
bb70624e | 2022 | |
a0c0a00f CR |
2023 | '${!NAME[@]}' |
2024 | '${!NAME[*]}' | |
b80f6443 JA |
2025 | If NAME is an array variable, expands to the list of array indices |
2026 | (keys) assigned in NAME. If NAME is not an array, expands to 0 if | |
a0c0a00f CR |
2027 | NAME is set and null otherwise. When '@' is used and the expansion |
2028 | appears within double quotes, each key expands to a separate word. | |
b80f6443 | 2029 | |
a0c0a00f | 2030 | '${#PARAMETER}' |
cce855bc | 2031 | The length in characters of the expanded value of PARAMETER is |
a0c0a00f CR |
2032 | substituted. If PARAMETER is '*' or '@', the value substituted is |
2033 | the number of positional parameters. If PARAMETER is an array name | |
2034 | subscripted by '*' or '@', the value substituted is the number of | |
2035 | elements in the array. If PARAMETER is an indexed array name | |
2036 | subscripted by a negative number, that number is interpreted as | |
2037 | relative to one greater than the maximum index of PARAMETER, so | |
2038 | negative indices count back from the end of the array, and an index | |
2039 | of -1 references the last element. | |
2040 | ||
2041 | '${PARAMETER#WORD}' | |
2042 | '${PARAMETER##WORD}' | |
d233b485 CR |
2043 | The WORD is expanded to produce a pattern and matched according to |
2044 | the rules described below (*note Pattern Matching::). If the | |
2045 | pattern matches the beginning of the expanded value of PARAMETER, | |
2046 | then the result of the expansion is the expanded value of PARAMETER | |
2047 | with the shortest matching pattern (the '#' case) or the longest | |
2048 | matching pattern (the '##' case) deleted. If PARAMETER is '@' or | |
2049 | '*', the pattern removal operation is applied to each positional | |
2050 | parameter in turn, and the expansion is the resultant list. If | |
2051 | PARAMETER is an array variable subscripted with '@' or '*', the | |
2052 | pattern removal operation is applied to each member of the array in | |
2053 | turn, and the expansion is the resultant list. | |
a0c0a00f CR |
2054 | |
2055 | '${PARAMETER%WORD}' | |
2056 | '${PARAMETER%%WORD}' | |
d233b485 CR |
2057 | The WORD is expanded to produce a pattern and matched according to |
2058 | the rules described below (*note Pattern Matching::). If the | |
8868edaf CR |
2059 | pattern matches a trailing portion of the expanded value of |
2060 | PARAMETER, then the result of the expansion is the value of | |
2061 | PARAMETER with the shortest matching pattern (the '%' case) or the | |
2062 | longest matching pattern (the '%%' case) deleted. If PARAMETER is | |
2063 | '@' or '*', the pattern removal operation is applied to each | |
2064 | positional parameter in turn, and the expansion is the resultant | |
2065 | list. If PARAMETER is an array variable subscripted with '@' or | |
2066 | '*', the pattern removal operation is applied to each member of the | |
2067 | array in turn, and the expansion is the resultant list. | |
a0c0a00f CR |
2068 | |
2069 | '${PARAMETER/PATTERN/STRING}' | |
74091dd4 CR |
2070 | '${PARAMETER//PATTERN/STRING}' |
2071 | '${PARAMETER/#PATTERN/STRING}' | |
2072 | '${PARAMETER/%PATTERN/STRING}' | |
ccc6cda3 JA |
2073 | The PATTERN is expanded to produce a pattern just as in filename |
2074 | expansion. PARAMETER is expanded and the longest match of PATTERN | |
74091dd4 CR |
2075 | against its value is replaced with STRING. STRING undergoes tilde |
2076 | expansion, parameter and variable expansion, arithmetic expansion, | |
2077 | command and process substitution, and quote removal. The match is | |
2078 | performed according to the rules described below (*note Pattern | |
2079 | Matching::). | |
2080 | ||
2081 | In the first form above, only the first match is replaced. If | |
2082 | there are two slashes separating PARAMETER and PATTERN (the second | |
2083 | form above), all matches of PATTERN are replaced with STRING. If | |
2084 | PATTERN is preceded by '#' (the third form above), it must match at | |
2085 | the beginning of the expanded value of PARAMETER. If PATTERN is | |
2086 | preceded by '%' (the fourth form above), it must match at the end | |
2087 | of the expanded value of PARAMETER. If the expansion of STRING is | |
2088 | null, matches of PATTERN are deleted. If STRING is null, matches | |
2089 | of PATTERN are deleted and the '/' following PATTERN may be | |
2090 | omitted. | |
2091 | ||
2092 | If the 'patsub_replacement' shell option is enabled using 'shopt', | |
2093 | any unquoted instances of '&' in STRING are replaced with the | |
2094 | matching portion of PATTERN. This is intended to duplicate a | |
2095 | common 'sed' idiom. | |
2096 | ||
2097 | Quoting any part of STRING inhibits replacement in the expansion of | |
2098 | the quoted portion, including replacement strings stored in shell | |
2099 | variables. Backslash will escape '&' in STRING; the backslash is | |
2100 | removed in order to permit a literal '&' in the replacement string. | |
2101 | Users should take care if STRING is double-quoted to avoid unwanted | |
2102 | interactions between the backslash and double-quoting, since | |
2103 | backslash has special meaning within double quotes. Pattern | |
2104 | substitution performs the check for unquoted '&' after expanding | |
2105 | STRING, so users should ensure to properly quote any occurrences of | |
2106 | '&' they want to be taken literally in the replacement and ensure | |
2107 | any instances of '&' they want to be replaced are unquoted. | |
2108 | ||
2109 | For instance, | |
2110 | ||
2111 | var=abcdef | |
2112 | rep='& ' | |
2113 | echo ${var/abc/& } | |
2114 | echo "${var/abc/& }" | |
2115 | echo ${var/abc/$rep} | |
2116 | echo "${var/abc/$rep}" | |
2117 | ||
2118 | will display four lines of "abc def", while | |
2119 | ||
2120 | var=abcdef | |
2121 | rep='& ' | |
2122 | echo ${var/abc/\& } | |
2123 | echo "${var/abc/\& }" | |
2124 | echo ${var/abc/"& "} | |
2125 | echo ${var/abc/"$rep"} | |
2126 | ||
2127 | will display four lines of "& def". Like the pattern removal | |
2128 | operators, double quotes surrounding the replacement string quote | |
2129 | the expanded characters, while double quotes enclosing the entire | |
2130 | parameter substitution do not, since the expansion is performed in | |
2131 | a context that doesn't take any enclosing double quotes into | |
2132 | account. | |
2133 | ||
2134 | Since backslash can escape '&', it can also escape a backslash in | |
2135 | the replacement string. This means that '\\' will insert a literal | |
2136 | backslash into the replacement, so these two 'echo' commands | |
2137 | ||
2138 | var=abcdef | |
2139 | rep='\\&xyz' | |
2140 | echo ${var/abc/\\&xyz} | |
2141 | echo ${var/abc/$rep} | |
2142 | ||
2143 | will both output '\abcxyzdef'. | |
2144 | ||
2145 | It should rarely be necessary to enclose only STRING in double | |
2146 | quotes. | |
2147 | ||
2148 | If the 'nocasematch' shell option (see the description of 'shopt' | |
2149 | in *note The Shopt Builtin::) is enabled, the match is performed | |
2150 | without regard to the case of alphabetic characters. If PARAMETER | |
2151 | is '@' or '*', the substitution operation is applied to each | |
2152 | positional parameter in turn, and the expansion is the resultant | |
2153 | list. If PARAMETER is an array variable subscripted with '@' or | |
2154 | '*', the substitution operation is applied to each member of the | |
2155 | array in turn, and the expansion is the resultant list. | |
a0c0a00f CR |
2156 | |
2157 | '${PARAMETER^PATTERN}' | |
2158 | '${PARAMETER^^PATTERN}' | |
2159 | '${PARAMETER,PATTERN}' | |
2160 | '${PARAMETER,,PATTERN}' | |
3185942a JA |
2161 | This expansion modifies the case of alphabetic characters in |
2162 | PARAMETER. The PATTERN is expanded to produce a pattern just as in | |
ac50fbac CR |
2163 | filename expansion. Each character in the expanded value of |
2164 | PARAMETER is tested against PATTERN, and, if it matches the | |
2165 | pattern, its case is converted. The pattern should not attempt to | |
74091dd4 CR |
2166 | match more than one character. |
2167 | ||
2168 | The '^' operator converts lowercase letters matching PATTERN to | |
2169 | uppercase; the ',' operator converts matching uppercase letters to | |
2170 | lowercase. The '^^' and ',,' expansions convert each matched | |
2171 | character in the expanded value; the '^' and ',' expansions match | |
2172 | and convert only the first character in the expanded value. If | |
2173 | PATTERN is omitted, it is treated like a '?', which matches every | |
2174 | character. | |
2175 | ||
2176 | If PARAMETER is '@' or '*', the case modification operation is | |
2177 | applied to each positional parameter in turn, and the expansion is | |
2178 | the resultant list. If PARAMETER is an array variable subscripted | |
2179 | with '@' or '*', the case modification operation is applied to each | |
2180 | member of the array in turn, and the expansion is the resultant | |
2181 | list. | |
b80f6443 | 2182 | |
a0c0a00f CR |
2183 | '${PARAMETER@OPERATOR}' |
2184 | The expansion is either a transformation of the value of PARAMETER | |
2185 | or information about PARAMETER itself, depending on the value of | |
2186 | OPERATOR. Each OPERATOR is a single letter: | |
2187 | ||
8868edaf CR |
2188 | 'U' |
2189 | The expansion is a string that is the value of PARAMETER with | |
2190 | lowercase alphabetic characters converted to uppercase. | |
2191 | 'u' | |
2192 | The expansion is a string that is the value of PARAMETER with | |
2193 | the first character converted to uppercase, if it is | |
2194 | alphabetic. | |
2195 | 'L' | |
2196 | The expansion is a string that is the value of PARAMETER with | |
2197 | uppercase alphabetic characters converted to lowercase. | |
a0c0a00f CR |
2198 | 'Q' |
2199 | The expansion is a string that is the value of PARAMETER | |
2200 | quoted in a format that can be reused as input. | |
2201 | 'E' | |
2202 | The expansion is a string that is the value of PARAMETER with | |
2203 | backslash escape sequences expanded as with the '$'...'' | |
d233b485 | 2204 | quoting mechanism. |
a0c0a00f CR |
2205 | 'P' |
2206 | The expansion is a string that is the result of expanding the | |
2207 | value of PARAMETER as if it were a prompt string (*note | |
2208 | Controlling the Prompt::). | |
2209 | 'A' | |
2210 | The expansion is a string in the form of an assignment | |
2211 | statement or 'declare' command that, if evaluated, will | |
2212 | recreate PARAMETER with its attributes and value. | |
8868edaf CR |
2213 | 'K' |
2214 | Produces a possibly-quoted version of the value of PARAMETER, | |
2215 | except that it prints the values of indexed and associative | |
2216 | arrays as a sequence of quoted key-value pairs (*note | |
2217 | Arrays::). | |
a0c0a00f CR |
2218 | 'a' |
2219 | The expansion is a string consisting of flag values | |
2220 | representing PARAMETER's attributes. | |
74091dd4 CR |
2221 | 'k' |
2222 | Like the 'K' transformation, but expands the keys and values | |
2223 | of indexed and associative arrays to separate words after word | |
2224 | splitting. | |
a0c0a00f CR |
2225 | |
2226 | If PARAMETER is '@' or '*', the operation is applied to each | |
2227 | positional parameter in turn, and the expansion is the resultant | |
2228 | list. If PARAMETER is an array variable subscripted with '@' or | |
2229 | '*', the operation is applied to each member of the array in turn, | |
2230 | and the expansion is the resultant list. | |
2231 | ||
2232 | The result of the expansion is subject to word splitting and | |
8868edaf | 2233 | filename expansion as described below. |
a0c0a00f | 2234 | |
ccc6cda3 | 2235 | \1f |
cce855bc | 2236 | File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions |
ccc6cda3 | 2237 | |
b80f6443 JA |
2238 | 3.5.4 Command Substitution |
2239 | -------------------------- | |
ccc6cda3 | 2240 | |
b80f6443 | 2241 | Command substitution allows the output of a command to replace the |
bb70624e JA |
2242 | command itself. Command substitution occurs when a command is enclosed |
2243 | as follows: | |
ccc6cda3 | 2244 | $(COMMAND) |
a0c0a00f | 2245 | or |
ccc6cda3 JA |
2246 | `COMMAND` |
2247 | ||
a0c0a00f CR |
2248 | Bash performs the expansion by executing COMMAND in a subshell |
2249 | environment and replacing the command substitution with the standard | |
2250 | output of the command, with any trailing newlines deleted. Embedded | |
2251 | newlines are not deleted, but they may be removed during word splitting. | |
2252 | The command substitution '$(cat FILE)' can be replaced by the equivalent | |
2253 | but faster '$(< FILE)'. | |
ccc6cda3 JA |
2254 | |
2255 | When the old-style backquote form of substitution is used, backslash | |
a0c0a00f | 2256 | retains its literal meaning except when followed by '$', '`', or '\'. |
cce855bc | 2257 | The first backquote not preceded by a backslash terminates the command |
a0c0a00f | 2258 | substitution. When using the '$(COMMAND)' form, all characters between |
cce855bc | 2259 | the parentheses make up the command; none are treated specially. |
ccc6cda3 | 2260 | |
cce855bc JA |
2261 | Command substitutions may be nested. To nest when using the |
2262 | backquoted form, escape the inner backquotes with backslashes. | |
ccc6cda3 JA |
2263 | |
2264 | If the substitution appears within double quotes, word splitting and | |
2265 | filename expansion are not performed on the results. | |
2266 | ||
2267 | \1f | |
cce855bc JA |
2268 | File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions |
2269 | ||
b80f6443 JA |
2270 | 3.5.5 Arithmetic Expansion |
2271 | -------------------------- | |
cce855bc | 2272 | |
b80f6443 | 2273 | Arithmetic expansion allows the evaluation of an arithmetic expression |
a0c0a00f CR |
2274 | and the substitution of the result. The format for arithmetic expansion |
2275 | is: | |
cce855bc JA |
2276 | |
2277 | $(( EXPRESSION )) | |
2278 | ||
74091dd4 CR |
2279 | The EXPRESSION undergoes the same expansions as if it were within |
2280 | double quotes, but double quote characters in EXPRESSION are not treated | |
2281 | specially and are removed. All tokens in the expression undergo | |
2282 | parameter and variable expansion, command substitution, and quote | |
2283 | removal. The result is treated as the arithmetic expression to be | |
2284 | evaluated. Arithmetic expansions may be nested. | |
cce855bc JA |
2285 | |
2286 | The evaluation is performed according to the rules listed below | |
a0c0a00f CR |
2287 | (*note Shell Arithmetic::). If the expression is invalid, Bash prints a |
2288 | message indicating failure to the standard error and no substitution | |
cce855bc JA |
2289 | occurs. |
2290 | ||
2291 | \1f | |
2292 | File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions | |
ccc6cda3 | 2293 | |
b80f6443 JA |
2294 | 3.5.6 Process Substitution |
2295 | -------------------------- | |
ccc6cda3 | 2296 | |
a0c0a00f CR |
2297 | Process substitution allows a process's input or output to be referred |
2298 | to using a filename. It takes the form of | |
ccc6cda3 | 2299 | <(LIST) |
a0c0a00f | 2300 | or |
ccc6cda3 | 2301 | >(LIST) |
a0c0a00f CR |
2302 | The process LIST is run asynchronously, and its input or output appears |
2303 | as a filename. This filename is passed as an argument to the current | |
2304 | command as the result of the expansion. If the '>(LIST)' form is used, | |
2305 | writing to the file will provide input for LIST. If the '<(LIST)' form | |
2306 | is used, the file passed as an argument should be read to obtain the | |
2307 | output of LIST. Note that no space may appear between the '<' or '>' | |
2308 | and the left parenthesis, otherwise the construct would be interpreted | |
2309 | as a redirection. Process substitution is supported on systems that | |
2310 | support named pipes (FIFOs) or the '/dev/fd' method of naming open | |
2311 | files. | |
ccc6cda3 | 2312 | |
cce855bc JA |
2313 | When available, process substitution is performed simultaneously with |
2314 | parameter and variable expansion, command substitution, and arithmetic | |
2315 | expansion. | |
ccc6cda3 JA |
2316 | |
2317 | \1f | |
2318 | File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions | |
2319 | ||
b80f6443 JA |
2320 | 3.5.7 Word Splitting |
2321 | -------------------- | |
ccc6cda3 | 2322 | |
b80f6443 | 2323 | The shell scans the results of parameter expansion, command |
ccc6cda3 JA |
2324 | substitution, and arithmetic expansion that did not occur within double |
2325 | quotes for word splitting. | |
2326 | ||
a0c0a00f CR |
2327 | The shell treats each character of '$IFS' as a delimiter, and splits |
2328 | the results of the other expansions into words using these characters as | |
2329 | field terminators. If 'IFS' is unset, or its value is exactly | |
2330 | '<space><tab><newline>', the default, then sequences of ' <space>', | |
2331 | '<tab>', and '<newline>' at the beginning and end of the results of the | |
2332 | previous expansions are ignored, and any sequence of 'IFS' characters | |
2333 | not at the beginning or end serves to delimit words. If 'IFS' has a | |
ac50fbac | 2334 | value other than the default, then sequences of the whitespace |
a0c0a00f CR |
2335 | characters 'space', 'tab', and 'newline' are ignored at the beginning |
2336 | and end of the word, as long as the whitespace character is in the value | |
2337 | of 'IFS' (an 'IFS' whitespace character). Any character in 'IFS' that | |
2338 | is not 'IFS' whitespace, along with any adjacent 'IFS' whitespace | |
2339 | characters, delimits a field. A sequence of 'IFS' whitespace characters | |
2340 | is also treated as a delimiter. If the value of 'IFS' is null, no word | |
ac50fbac | 2341 | splitting occurs. |
ccc6cda3 | 2342 | |
a0c0a00f CR |
2343 | Explicit null arguments ('""' or '''') are retained and passed to |
2344 | commands as empty strings. Unquoted implicit null arguments, resulting | |
2345 | from the expansion of parameters that have no values, are removed. If a | |
2346 | parameter with no value is expanded within double quotes, a null | |
2347 | argument results and is retained and passed to a command as an empty | |
2348 | string. When a quoted null argument appears as part of a word whose | |
2349 | expansion is non-null, the null argument is removed. That is, the word | |
2350 | '-d''' becomes '-d' after word splitting and null argument removal. | |
ccc6cda3 JA |
2351 | |
2352 | Note that if no expansion occurs, no splitting is performed. | |
2353 | ||
2354 | \1f | |
2355 | File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions | |
2356 | ||
b80f6443 JA |
2357 | 3.5.8 Filename Expansion |
2358 | ------------------------ | |
ccc6cda3 | 2359 | |
cce855bc JA |
2360 | * Menu: |
2361 | ||
2362 | * Pattern Matching:: How the shell matches patterns. | |
2363 | ||
a0c0a00f CR |
2364 | After word splitting, unless the '-f' option has been set (*note The Set |
2365 | Builtin::), Bash scans each word for the characters '*', '?', and '['. | |
8868edaf CR |
2366 | If one of these characters appears, and is not quoted, then the word is |
2367 | regarded as a PATTERN, and replaced with an alphabetically sorted list | |
2368 | of filenames matching the pattern (*note Pattern Matching::). If no | |
2369 | matching filenames are found, and the shell option 'nullglob' is | |
2370 | disabled, the word is left unchanged. If the 'nullglob' option is set, | |
2371 | and no matches are found, the word is removed. If the 'failglob' shell | |
2372 | option is set, and no matches are found, an error message is printed and | |
2373 | the command is not executed. If the shell option 'nocaseglob' is | |
2374 | enabled, the match is performed without regard to the case of alphabetic | |
2375 | characters. | |
a0c0a00f CR |
2376 | |
2377 | When a pattern is used for filename expansion, the character '.' at | |
2378 | the start of a filename or immediately following a slash must be matched | |
74091dd4 CR |
2379 | explicitly, unless the shell option 'dotglob' is set. In order to match |
2380 | the filenames '.' and '..', the pattern must begin with '.' (for | |
2381 | example, '.?'), even if 'dotglob' is set. If the 'globskipdots' shell | |
2382 | option is enabled, the filenames '.' and '..' are never matched, even if | |
2383 | the pattern begins with a '.'. When not matching filenames, the '.' | |
2384 | character is not treated specially. | |
d233b485 CR |
2385 | |
2386 | When matching a filename, the slash character must always be matched | |
2387 | explicitly by a slash in the pattern, but in other matching contexts it | |
2388 | can be matched by a special pattern character as described below (*note | |
2389 | Pattern Matching::). | |
a0c0a00f CR |
2390 | |
2391 | See the description of 'shopt' in *note The Shopt Builtin::, for a | |
74091dd4 CR |
2392 | description of the 'nocaseglob', 'nullglob', 'globskipdots', 'failglob', |
2393 | and 'dotglob' options. | |
ccc6cda3 | 2394 | |
a0c0a00f | 2395 | The 'GLOBIGNORE' shell variable may be used to restrict the set of |
d233b485 CR |
2396 | file names matching a pattern. If 'GLOBIGNORE' is set, each matching |
2397 | file name that also matches one of the patterns in 'GLOBIGNORE' is | |
a0c0a00f CR |
2398 | removed from the list of matches. If the 'nocaseglob' option is set, |
2399 | the matching against the patterns in 'GLOBIGNORE' is performed without | |
2400 | regard to case. The filenames '.' and '..' are always ignored when | |
2401 | 'GLOBIGNORE' is set and not null. However, setting 'GLOBIGNORE' to a | |
2402 | non-null value has the effect of enabling the 'dotglob' shell option, so | |
2403 | all other filenames beginning with a '.' will match. To get the old | |
2404 | behavior of ignoring filenames beginning with a '.', make '.*' one of | |
2405 | the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when | |
2406 | 'GLOBIGNORE' is unset. | |
ccc6cda3 | 2407 | |
cce855bc JA |
2408 | \1f |
2409 | File: bashref.info, Node: Pattern Matching, Up: Filename Expansion | |
2410 | ||
b80f6443 JA |
2411 | 3.5.8.1 Pattern Matching |
2412 | ........................ | |
cce855bc | 2413 | |
b80f6443 JA |
2414 | Any character that appears in a pattern, other than the special pattern |
2415 | characters described below, matches itself. The NUL character may not | |
2416 | occur in a pattern. A backslash escapes the following character; the | |
2417 | escaping backslash is discarded when matching. The special pattern | |
2418 | characters must be quoted if they are to be matched literally. | |
cce855bc | 2419 | |
ccc6cda3 | 2420 | The special pattern characters have the following meanings: |
a0c0a00f CR |
2421 | '*' |
2422 | Matches any string, including the null string. When the 'globstar' | |
2423 | shell option is enabled, and '*' is used in a filename expansion | |
2424 | context, two adjacent '*'s used as a single pattern will match all | |
2425 | files and zero or more directories and subdirectories. If followed | |
2426 | by a '/', two adjacent '*'s will match only directories and | |
2427 | subdirectories. | |
2428 | '?' | |
ccc6cda3 | 2429 | Matches any single character. |
a0c0a00f | 2430 | '[...]' |
ccc6cda3 | 2431 | Matches any one of the enclosed characters. A pair of characters |
28ef6c31 | 2432 | separated by a hyphen denotes a RANGE EXPRESSION; any character |
ac50fbac | 2433 | that falls between those two characters, inclusive, using the |
28ef6c31 | 2434 | current locale's collating sequence and character set, is matched. |
a0c0a00f CR |
2435 | If the first character following the '[' is a '!' or a '^' then any |
2436 | character not enclosed is matched. A '-' may be matched by | |
2437 | including it as the first or last character in the set. A ']' may | |
28ef6c31 | 2438 | be matched by including it as the first character in the set. The |
74091dd4 CR |
2439 | sorting order of characters in range expressions, and the |
2440 | characters included in the range, are determined by the current | |
2441 | locale and the values of the 'LC_COLLATE' and 'LC_ALL' shell | |
2442 | variables, if set. | |
28ef6c31 | 2443 | |
a0c0a00f CR |
2444 | For example, in the default C locale, '[a-dx-z]' is equivalent to |
2445 | '[abcdxyz]'. Many locales sort characters in dictionary order, and | |
2446 | in these locales '[a-dx-z]' is typically not equivalent to | |
74091dd4 | 2447 | '[abcdxyz]'; it might be equivalent to '[aBbCcDdxYyZz]', for |
28ef6c31 JA |
2448 | example. To obtain the traditional interpretation of ranges in |
2449 | bracket expressions, you can force the use of the C locale by | |
a0c0a00f CR |
2450 | setting the 'LC_COLLATE' or 'LC_ALL' environment variable to the |
2451 | value 'C', or enable the 'globasciiranges' shell option. | |
ccc6cda3 | 2452 | |
74091dd4 | 2453 | Within '[' and ']', "character classes" can be specified using the |
a0c0a00f | 2454 | syntax '[:'CLASS':]', where CLASS is one of the following classes |
0628567a | 2455 | defined in the POSIX standard: |
cce855bc | 2456 | alnum alpha ascii blank cntrl digit graph lower |
7117c2d2 | 2457 | print punct space upper word xdigit |
cce855bc | 2458 | A character class matches any character belonging to that class. |
a0c0a00f CR |
2459 | The 'word' character class matches letters, digits, and the |
2460 | character '_'. | |
cce855bc | 2461 | |
74091dd4 CR |
2462 | Within '[' and ']', an "equivalence class" can be specified using |
2463 | the syntax '[='C'=]', which matches all characters with the same | |
cce855bc JA |
2464 | collation weight (as defined by the current locale) as the |
2465 | character C. | |
2466 | ||
a0c0a00f CR |
2467 | Within '[' and ']', the syntax '[.'SYMBOL'.]' matches the collating |
2468 | symbol SYMBOL. | |
cce855bc | 2469 | |
a0c0a00f | 2470 | If the 'extglob' shell option is enabled using the 'shopt' builtin, |
74091dd4 CR |
2471 | the shell recognizes several extended pattern matching operators. In |
2472 | the following description, a PATTERN-LIST is a list of one or more | |
2473 | patterns separated by a '|'. When matching filenames, the 'dotglob' | |
2474 | shell option determines the set of filenames that are tested, as | |
2475 | described above. Composite patterns may be formed using one or more of | |
2476 | the following sub-patterns: | |
cce855bc | 2477 | |
a0c0a00f | 2478 | '?(PATTERN-LIST)' |
cce855bc JA |
2479 | Matches zero or one occurrence of the given patterns. |
2480 | ||
a0c0a00f | 2481 | '*(PATTERN-LIST)' |
cce855bc JA |
2482 | Matches zero or more occurrences of the given patterns. |
2483 | ||
a0c0a00f | 2484 | '+(PATTERN-LIST)' |
cce855bc JA |
2485 | Matches one or more occurrences of the given patterns. |
2486 | ||
a0c0a00f | 2487 | '@(PATTERN-LIST)' |
95732b49 | 2488 | Matches one of the given patterns. |
cce855bc | 2489 | |
a0c0a00f | 2490 | '!(PATTERN-LIST)' |
cce855bc JA |
2491 | Matches anything except one of the given patterns. |
2492 | ||
74091dd4 CR |
2493 | The 'extglob' option changes the behavior of the parser, since the |
2494 | parentheses are normally treated as operators with syntactic meaning. | |
2495 | To ensure that extended matching patterns are parsed correctly, make | |
2496 | sure that 'extglob' is enabled before parsing constructs containing the | |
2497 | patterns, including shell functions and command substitutions. | |
2498 | ||
2499 | When matching filenames, the 'dotglob' shell option determines the | |
2500 | set of filenames that are tested: when 'dotglob' is enabled, the set of | |
2501 | filenames includes all files beginning with '.', but the filenames '.' | |
2502 | and '..' must be matched by a pattern or sub-pattern that begins with a | |
2503 | dot; when it is disabled, the set does not include any filenames | |
2504 | beginning with "." unless the pattern or sub-pattern begins with a '.'. | |
2505 | As above, '.' only has a special meaning when matching filenames. | |
2506 | ||
d233b485 CR |
2507 | Complicated extended pattern matching against long strings is slow, |
2508 | especially when the patterns contain alternations and the strings | |
2509 | contain multiple matches. Using separate matches against shorter | |
2510 | strings, or using arrays of strings instead of a single long string, may | |
2511 | be faster. | |
2512 | ||
ccc6cda3 JA |
2513 | \1f |
2514 | File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions | |
2515 | ||
b80f6443 JA |
2516 | 3.5.9 Quote Removal |
2517 | ------------------- | |
ccc6cda3 | 2518 | |
b80f6443 | 2519 | After the preceding expansions, all unquoted occurrences of the |
a0c0a00f | 2520 | characters '\', ''', and '"' that did not result from one of the above |
ccc6cda3 JA |
2521 | expansions are removed. |
2522 | ||
2523 | \1f | |
2524 | File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features | |
2525 | ||
b80f6443 JA |
2526 | 3.6 Redirections |
2527 | ================ | |
ccc6cda3 | 2528 | |
74091dd4 CR |
2529 | Before a command is executed, its input and output may be "redirected" |
2530 | using a special notation interpreted by the shell. "Redirection" allows | |
ac50fbac CR |
2531 | commands' file handles to be duplicated, opened, closed, made to refer |
2532 | to different files, and can change the files the command reads from and | |
2533 | writes to. Redirection may also be used to modify file handles in the | |
2534 | current shell execution environment. The following redirection | |
2535 | operators may precede or appear anywhere within a simple command or may | |
2536 | follow a command. Redirections are processed in the order they appear, | |
2537 | from left to right. | |
ccc6cda3 | 2538 | |
a0c0a00f CR |
2539 | Each redirection that may be preceded by a file descriptor number may |
2540 | instead be preceded by a word of the form {VARNAME}. In this case, for | |
2541 | each redirection operator except >&- and <&-, the shell will allocate a | |
2542 | file descriptor greater than 10 and assign it to {VARNAME}. If >&- or | |
2543 | <&- is preceded by {VARNAME}, the value of VARNAME defines the file | |
d233b485 CR |
2544 | descriptor to close. If {VARNAME} is supplied, the redirection persists |
2545 | beyond the scope of the command, allowing the shell programmer to manage | |
74091dd4 CR |
2546 | the file descriptor's lifetime manually. The 'varredir_close' shell |
2547 | option manages this behavior (*note The Shopt Builtin::). | |
0001803f | 2548 | |
ccc6cda3 | 2549 | In the following descriptions, if the file descriptor number is |
a0c0a00f CR |
2550 | omitted, and the first character of the redirection operator is '<', the |
2551 | redirection refers to the standard input (file descriptor 0). If the | |
2552 | first character of the redirection operator is '>', the redirection | |
ccc6cda3 JA |
2553 | refers to the standard output (file descriptor 1). |
2554 | ||
cce855bc JA |
2555 | The word following the redirection operator in the following |
2556 | descriptions, unless otherwise noted, is subjected to brace expansion, | |
2557 | tilde expansion, parameter expansion, command substitution, arithmetic | |
a0c0a00f CR |
2558 | expansion, quote removal, filename expansion, and word splitting. If it |
2559 | expands to more than one word, Bash reports an error. | |
ccc6cda3 | 2560 | |
a0c0a00f CR |
2561 | Note that the order of redirections is significant. For example, the |
2562 | command | |
ccc6cda3 | 2563 | ls > DIRLIST 2>&1 |
a0c0a00f | 2564 | directs both standard output (file descriptor 1) and standard error |
bb70624e | 2565 | (file descriptor 2) to the file DIRLIST, while the command |
ccc6cda3 | 2566 | ls 2>&1 > DIRLIST |
a0c0a00f CR |
2567 | directs only the standard output to file DIRLIST, because the standard |
2568 | error was made a copy of the standard output before the standard output | |
2569 | was redirected to DIRLIST. | |
ccc6cda3 | 2570 | |
bb70624e | 2571 | Bash handles several filenames specially when they are used in |
a0c0a00f CR |
2572 | redirections, as described in the following table. If the operating |
2573 | system on which Bash is running provides these special files, bash will | |
2574 | use them; otherwise it will emulate them internally with the behavior | |
2575 | described below. | |
bb70624e | 2576 | |
a0c0a00f | 2577 | '/dev/fd/FD' |
bb70624e JA |
2578 | If FD is a valid integer, file descriptor FD is duplicated. |
2579 | ||
a0c0a00f | 2580 | '/dev/stdin' |
bb70624e JA |
2581 | File descriptor 0 is duplicated. |
2582 | ||
a0c0a00f | 2583 | '/dev/stdout' |
bb70624e JA |
2584 | File descriptor 1 is duplicated. |
2585 | ||
a0c0a00f | 2586 | '/dev/stderr' |
bb70624e JA |
2587 | File descriptor 2 is duplicated. |
2588 | ||
a0c0a00f | 2589 | '/dev/tcp/HOST/PORT' |
bb70624e | 2590 | If HOST is a valid hostname or Internet address, and PORT is an |
ac50fbac CR |
2591 | integer port number or service name, Bash attempts to open the |
2592 | corresponding TCP socket. | |
bb70624e | 2593 | |
a0c0a00f | 2594 | '/dev/udp/HOST/PORT' |
bb70624e | 2595 | If HOST is a valid hostname or Internet address, and PORT is an |
ac50fbac CR |
2596 | integer port number or service name, Bash attempts to open the |
2597 | corresponding UDP socket. | |
b80f6443 | 2598 | |
cce855bc JA |
2599 | A failure to open or create a file causes the redirection to fail. |
2600 | ||
95732b49 JA |
2601 | Redirections using file descriptors greater than 9 should be used |
2602 | with care, as they may conflict with file descriptors the shell uses | |
2603 | internally. | |
2604 | ||
b80f6443 JA |
2605 | 3.6.1 Redirecting Input |
2606 | ----------------------- | |
ccc6cda3 | 2607 | |
b80f6443 | 2608 | Redirection of input causes the file whose name results from the |
a0c0a00f CR |
2609 | expansion of WORD to be opened for reading on file descriptor 'n', or |
2610 | the standard input (file descriptor 0) if 'n' is not specified. | |
ccc6cda3 JA |
2611 | |
2612 | The general format for redirecting input is: | |
7117c2d2 | 2613 | [N]<WORD |
ccc6cda3 | 2614 | |
b80f6443 JA |
2615 | 3.6.2 Redirecting Output |
2616 | ------------------------ | |
ccc6cda3 | 2617 | |
b80f6443 | 2618 | Redirection of output causes the file whose name results from the |
7117c2d2 JA |
2619 | expansion of WORD to be opened for writing on file descriptor N, or the |
2620 | standard output (file descriptor 1) if N is not specified. If the file | |
2621 | does not exist it is created; if it does exist it is truncated to zero | |
2622 | size. | |
ccc6cda3 JA |
2623 | |
2624 | The general format for redirecting output is: | |
7117c2d2 | 2625 | [N]>[|]WORD |
ccc6cda3 | 2626 | |
a0c0a00f CR |
2627 | If the redirection operator is '>', and the 'noclobber' option to the |
2628 | 'set' builtin has been enabled, the redirection will fail if the file | |
2629 | whose name results from the expansion of WORD exists and is a regular | |
2630 | file. If the redirection operator is '>|', or the redirection operator | |
2631 | is '>' and the 'noclobber' option is not enabled, the redirection is | |
2632 | attempted even if the file named by WORD exists. | |
ccc6cda3 | 2633 | |
b80f6443 JA |
2634 | 3.6.3 Appending Redirected Output |
2635 | --------------------------------- | |
ccc6cda3 | 2636 | |
a0c0a00f CR |
2637 | Redirection of output in this fashion causes the file whose name results |
2638 | from the expansion of WORD to be opened for appending on file descriptor | |
2639 | N, or the standard output (file descriptor 1) if N is not specified. If | |
2640 | the file does not exist it is created. | |
ccc6cda3 JA |
2641 | |
2642 | The general format for appending output is: | |
7117c2d2 | 2643 | [N]>>WORD |
ccc6cda3 | 2644 | |
b80f6443 JA |
2645 | 3.6.4 Redirecting Standard Output and Standard Error |
2646 | ---------------------------------------------------- | |
ccc6cda3 | 2647 | |
3185942a JA |
2648 | This construct allows both the standard output (file descriptor 1) and |
2649 | the standard error output (file descriptor 2) to be redirected to the | |
2650 | file whose name is the expansion of WORD. | |
ccc6cda3 JA |
2651 | |
2652 | There are two formats for redirecting standard output and standard | |
2653 | error: | |
2654 | &>WORD | |
a0c0a00f | 2655 | and |
ccc6cda3 | 2656 | >&WORD |
a0c0a00f | 2657 | Of the two forms, the first is preferred. This is semantically |
ccc6cda3 JA |
2658 | equivalent to |
2659 | >WORD 2>&1 | |
a0c0a00f | 2660 | When using the second form, WORD may not expand to a number or '-'. |
ac50fbac CR |
2661 | If it does, other redirection operators apply (see Duplicating File |
2662 | Descriptors below) for compatibility reasons. | |
ccc6cda3 | 2663 | |
3185942a JA |
2664 | 3.6.5 Appending Standard Output and Standard Error |
2665 | -------------------------------------------------- | |
2666 | ||
2667 | This construct allows both the standard output (file descriptor 1) and | |
a0c0a00f CR |
2668 | the standard error output (file descriptor 2) to be appended to the file |
2669 | whose name is the expansion of WORD. | |
3185942a JA |
2670 | |
2671 | The format for appending standard output and standard error is: | |
2672 | &>>WORD | |
a0c0a00f | 2673 | This is semantically equivalent to |
3185942a | 2674 | >>WORD 2>&1 |
ac50fbac | 2675 | (see Duplicating File Descriptors below). |
3185942a JA |
2676 | |
2677 | 3.6.6 Here Documents | |
b80f6443 | 2678 | -------------------- |
ccc6cda3 | 2679 | |
b80f6443 | 2680 | This type of redirection instructs the shell to read input from the |
ccc6cda3 JA |
2681 | current source until a line containing only WORD (with no trailing |
2682 | blanks) is seen. All of the lines read up to that point are then used | |
a0c0a00f CR |
2683 | as the standard input (or file descriptor N if N is specified) for a |
2684 | command. | |
ccc6cda3 | 2685 | |
7117c2d2 | 2686 | The format of here-documents is: |
a0c0a00f | 2687 | [N]<<[-]WORD |
ccc6cda3 JA |
2688 | HERE-DOCUMENT |
2689 | DELIMITER | |
2690 | ||
a0c0a00f CR |
2691 | No parameter and variable expansion, command substitution, arithmetic |
2692 | expansion, or filename expansion is performed on WORD. If any part of | |
2693 | WORD is quoted, the DELIMITER is the result of quote removal on WORD, | |
2694 | and the lines in the here-document are not expanded. If WORD is | |
2695 | unquoted, all lines of the here-document are subjected to parameter | |
2696 | expansion, command substitution, and arithmetic expansion, the character | |
2697 | sequence '\newline' is ignored, and '\' must be used to quote the | |
2698 | characters '\', '$', and '`'. | |
ccc6cda3 | 2699 | |
a0c0a00f CR |
2700 | If the redirection operator is '<<-', then all leading tab characters |
2701 | are stripped from input lines and the line containing DELIMITER. This | |
2702 | allows here-documents within shell scripts to be indented in a natural | |
2703 | fashion. | |
ccc6cda3 | 2704 | |
3185942a | 2705 | 3.6.7 Here Strings |
b80f6443 | 2706 | ------------------ |
7117c2d2 | 2707 | |
b80f6443 | 2708 | A variant of here documents, the format is: |
a0c0a00f | 2709 | [N]<<< WORD |
7117c2d2 | 2710 | |
d233b485 | 2711 | The WORD undergoes tilde expansion, parameter and variable expansion, |
8868edaf | 2712 | command substitution, arithmetic expansion, and quote removal. Filename |
d233b485 CR |
2713 | expansion and word splitting are not performed. The result is supplied |
2714 | as a single string, with a newline appended, to the command on its | |
2715 | standard input (or file descriptor N if N is specified). | |
7117c2d2 | 2716 | |
3185942a | 2717 | 3.6.8 Duplicating File Descriptors |
b80f6443 | 2718 | ---------------------------------- |
ccc6cda3 | 2719 | |
b80f6443 | 2720 | The redirection operator |
7117c2d2 | 2721 | [N]<&WORD |
a0c0a00f CR |
2722 | is used to duplicate input file descriptors. If WORD expands to one or |
2723 | more digits, the file descriptor denoted by N is made to be a copy of | |
2724 | that file descriptor. If the digits in WORD do not specify a file | |
cce855bc | 2725 | descriptor open for input, a redirection error occurs. If WORD |
a0c0a00f | 2726 | evaluates to '-', file descriptor N is closed. If N is not specified, |
7117c2d2 | 2727 | the standard input (file descriptor 0) is used. |
ccc6cda3 JA |
2728 | |
2729 | The operator | |
7117c2d2 | 2730 | [N]>&WORD |
a0c0a00f | 2731 | is used similarly to duplicate output file descriptors. If N is not |
cce855bc JA |
2732 | specified, the standard output (file descriptor 1) is used. If the |
2733 | digits in WORD do not specify a file descriptor open for output, a | |
a0c0a00f CR |
2734 | redirection error occurs. If WORD evaluates to '-', file descriptor N |
2735 | is closed. As a special case, if N is omitted, and WORD does not expand | |
2736 | to one or more digits or '-', the standard output and standard error are | |
2737 | redirected as described previously. | |
7117c2d2 | 2738 | |
3185942a | 2739 | 3.6.9 Moving File Descriptors |
b80f6443 | 2740 | ----------------------------- |
7117c2d2 | 2741 | |
b80f6443 | 2742 | The redirection operator |
7117c2d2 | 2743 | [N]<&DIGIT- |
a0c0a00f CR |
2744 | moves the file descriptor DIGIT to file descriptor N, or the standard |
2745 | input (file descriptor 0) if N is not specified. DIGIT is closed after | |
2746 | being duplicated to N. | |
7117c2d2 JA |
2747 | |
2748 | Similarly, the redirection operator | |
2749 | [N]>&DIGIT- | |
a0c0a00f CR |
2750 | moves the file descriptor DIGIT to file descriptor N, or the standard |
2751 | output (file descriptor 1) if N is not specified. | |
7117c2d2 | 2752 | |
3185942a JA |
2753 | 3.6.10 Opening File Descriptors for Reading and Writing |
2754 | ------------------------------------------------------- | |
ccc6cda3 | 2755 | |
b80f6443 | 2756 | The redirection operator |
7117c2d2 | 2757 | [N]<>WORD |
a0c0a00f | 2758 | causes the file whose name is the expansion of WORD to be opened for |
7117c2d2 JA |
2759 | both reading and writing on file descriptor N, or on file descriptor 0 |
2760 | if N is not specified. If the file does not exist, it is created. | |
ccc6cda3 JA |
2761 | |
2762 | \1f | |
2763 | File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features | |
2764 | ||
b80f6443 JA |
2765 | 3.7 Executing Commands |
2766 | ====================== | |
ccc6cda3 JA |
2767 | |
2768 | * Menu: | |
2769 | ||
cce855bc JA |
2770 | * Simple Command Expansion:: How Bash expands simple commands before |
2771 | executing them. | |
ccc6cda3 | 2772 | * Command Search and Execution:: How Bash finds commands and runs them. |
cce855bc JA |
2773 | * Command Execution Environment:: The environment in which Bash |
2774 | executes commands that are not | |
2775 | shell builtins. | |
ccc6cda3 | 2776 | * Environment:: The environment given to a command. |
ccc6cda3 JA |
2777 | * Exit Status:: The status returned by commands and how Bash |
2778 | interprets it. | |
ccc6cda3 JA |
2779 | * Signals:: What happens when Bash or a command it runs |
2780 | receives a signal. | |
2781 | ||
2782 | \1f | |
cce855bc JA |
2783 | File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands |
2784 | ||
b80f6443 JA |
2785 | 3.7.1 Simple Command Expansion |
2786 | ------------------------------ | |
cce855bc | 2787 | |
b80f6443 | 2788 | When a simple command is executed, the shell performs the following |
8868edaf CR |
2789 | expansions, assignments, and redirections, from left to right, in the |
2790 | following order. | |
cce855bc JA |
2791 | |
2792 | 1. The words that the parser has marked as variable assignments (those | |
2793 | preceding the command name) and redirections are saved for later | |
2794 | processing. | |
2795 | ||
2796 | 2. The words that are not variable assignments or redirections are | |
28ef6c31 | 2797 | expanded (*note Shell Expansions::). If any words remain after |
cce855bc JA |
2798 | expansion, the first word is taken to be the name of the command |
2799 | and the remaining words are the arguments. | |
2800 | ||
2801 | 3. Redirections are performed as described above (*note | |
28ef6c31 | 2802 | Redirections::). |
cce855bc | 2803 | |
a0c0a00f | 2804 | 4. The text after the '=' in each variable assignment undergoes tilde |
cce855bc JA |
2805 | expansion, parameter expansion, command substitution, arithmetic |
2806 | expansion, and quote removal before being assigned to the variable. | |
2807 | ||
2808 | If no command name results, the variable assignments affect the | |
74091dd4 CR |
2809 | current shell environment. In the case of such a command (one that |
2810 | consists only of assignment statements and redirections), assignment | |
2811 | statements are performed before redirections. Otherwise, the variables | |
2812 | are added to the environment of the executed command and do not affect | |
2813 | the current shell environment. If any of the assignments attempts to | |
2814 | assign a value to a readonly variable, an error occurs, and the command | |
2815 | exits with a non-zero status. | |
cce855bc JA |
2816 | |
2817 | If no command name results, redirections are performed, but do not | |
2818 | affect the current shell environment. A redirection error causes the | |
2819 | command to exit with a non-zero status. | |
2820 | ||
2821 | If there is a command name left after expansion, execution proceeds | |
2822 | as described below. Otherwise, the command exits. If one of the | |
2823 | expansions contained a command substitution, the exit status of the | |
2824 | command is the exit status of the last command substitution performed. | |
2825 | If there were no command substitutions, the command exits with a status | |
2826 | of zero. | |
2827 | ||
2828 | \1f | |
2829 | File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands | |
ccc6cda3 | 2830 | |
b80f6443 JA |
2831 | 3.7.2 Command Search and Execution |
2832 | ---------------------------------- | |
ccc6cda3 | 2833 | |
b80f6443 | 2834 | After a command has been split into words, if it results in a simple |
ccc6cda3 JA |
2835 | command and an optional list of arguments, the following actions are |
2836 | taken. | |
2837 | ||
2838 | 1. If the command name contains no slashes, the shell attempts to | |
2839 | locate it. If there exists a shell function by that name, that | |
3185942a | 2840 | function is invoked as described in *note Shell Functions::. |
ccc6cda3 | 2841 | |
a0c0a00f CR |
2842 | 2. If the name does not match a function, the shell searches for it in |
2843 | the list of shell builtins. If a match is found, that builtin is | |
2844 | invoked. | |
2845 | ||
2846 | 3. If the name is neither a shell function nor a builtin, and contains | |
2847 | no slashes, Bash searches each element of '$PATH' for a directory | |
2848 | containing an executable file by that name. Bash uses a hash table | |
2849 | to remember the full pathnames of executable files to avoid | |
2850 | multiple 'PATH' searches (see the description of 'hash' in *note | |
2851 | Bourne Shell Builtins::). A full search of the directories in | |
2852 | '$PATH' is performed only if the command is not found in the hash | |
2853 | table. If the search is unsuccessful, the shell searches for a | |
2854 | defined shell function named 'command_not_found_handle'. If that | |
d233b485 CR |
2855 | function exists, it is invoked in a separate execution environment |
2856 | with the original command and the original command's arguments as | |
2857 | its arguments, and the function's exit status becomes the exit | |
2858 | status of that subshell. If that function is not defined, the | |
2859 | shell prints an error message and returns an exit status of 127. | |
a0c0a00f CR |
2860 | |
2861 | 4. If the search is successful, or if the command name contains one or | |
2862 | more slashes, the shell executes the named program in a separate | |
2863 | execution environment. Argument 0 is set to the name given, and | |
2864 | the remaining arguments to the command are set to the arguments | |
2865 | supplied, if any. | |
ccc6cda3 JA |
2866 | |
2867 | 5. If this execution fails because the file is not in executable | |
cce855bc | 2868 | format, and the file is not a directory, it is assumed to be a |
74091dd4 CR |
2869 | "shell script" and the shell executes it as described in *note |
2870 | Shell Scripts::. | |
cce855bc JA |
2871 | |
2872 | 6. If the command was not begun asynchronously, the shell waits for | |
2873 | the command to complete and collects its exit status. | |
2874 | ||
cce855bc JA |
2875 | \1f |
2876 | File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands | |
2877 | ||
b80f6443 JA |
2878 | 3.7.3 Command Execution Environment |
2879 | ----------------------------------- | |
cce855bc | 2880 | |
74091dd4 CR |
2881 | The shell has an "execution environment", which consists of the |
2882 | following: | |
cce855bc JA |
2883 | |
2884 | * open files inherited by the shell at invocation, as modified by | |
a0c0a00f | 2885 | redirections supplied to the 'exec' builtin |
cce855bc | 2886 | |
a0c0a00f | 2887 | * the current working directory as set by 'cd', 'pushd', or 'popd', |
cce855bc JA |
2888 | or inherited by the shell at invocation |
2889 | ||
a0c0a00f CR |
2890 | * the file creation mode mask as set by 'umask' or inherited from the |
2891 | shell's parent | |
cce855bc | 2892 | |
a0c0a00f | 2893 | * current traps set by 'trap' |
cce855bc | 2894 | |
a0c0a00f | 2895 | * shell parameters that are set by variable assignment or with 'set' |
cce855bc JA |
2896 | or inherited from the shell's parent in the environment |
2897 | ||
2898 | * shell functions defined during execution or inherited from the | |
2899 | shell's parent in the environment | |
2900 | ||
2901 | * options enabled at invocation (either by default or with | |
a0c0a00f | 2902 | command-line arguments) or by 'set' |
cce855bc | 2903 | |
a0c0a00f | 2904 | * options enabled by 'shopt' (*note The Shopt Builtin::) |
cce855bc | 2905 | |
a0c0a00f | 2906 | * shell aliases defined with 'alias' (*note Aliases::) |
cce855bc JA |
2907 | |
2908 | * various process IDs, including those of background jobs (*note | |
a0c0a00f | 2909 | Lists::), the value of '$$', and the value of '$PPID' |
28ef6c31 | 2910 | |
a0c0a00f CR |
2911 | When a simple command other than a builtin or shell function is to be |
2912 | executed, it is invoked in a separate execution environment that | |
cce855bc JA |
2913 | consists of the following. Unless otherwise noted, the values are |
2914 | inherited from the shell. | |
2915 | ||
2916 | * the shell's open files, plus any modifications and additions | |
2917 | specified by redirections to the command | |
2918 | ||
2919 | * the current working directory | |
2920 | ||
2921 | * the file creation mode mask | |
2922 | ||
b80f6443 JA |
2923 | * shell variables and functions marked for export, along with |
2924 | variables exported for the command, passed in the environment | |
2925 | (*note Environment::) | |
cce855bc JA |
2926 | |
2927 | * traps caught by the shell are reset to the values inherited from | |
2928 | the shell's parent, and traps ignored by the shell are ignored | |
2929 | ||
2930 | A command invoked in this separate environment cannot affect the | |
2931 | shell's execution environment. | |
2932 | ||
74091dd4 CR |
2933 | A "subshell" is a copy of the shell process. |
2934 | ||
b80f6443 JA |
2935 | Command substitution, commands grouped with parentheses, and |
2936 | asynchronous commands are invoked in a subshell environment that is a | |
2937 | duplicate of the shell environment, except that traps caught by the | |
2938 | shell are reset to the values that the shell inherited from its parent | |
2939 | at invocation. Builtin commands that are invoked as part of a pipeline | |
2940 | are also executed in a subshell environment. Changes made to the | |
2941 | subshell environment cannot affect the shell's execution environment. | |
ccc6cda3 | 2942 | |
17345e5a | 2943 | Subshells spawned to execute command substitutions inherit the value |
a0c0a00f CR |
2944 | of the '-e' option from the parent shell. When not in POSIX mode, Bash |
2945 | clears the '-e' option in such subshells. | |
17345e5a | 2946 | |
a0c0a00f CR |
2947 | If a command is followed by a '&' and job control is not active, the |
2948 | default standard input for the command is the empty file '/dev/null'. | |
f73dda09 JA |
2949 | Otherwise, the invoked command inherits the file descriptors of the |
2950 | calling shell as modified by redirections. | |
2951 | ||
ccc6cda3 | 2952 | \1f |
cce855bc | 2953 | File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands |
ccc6cda3 | 2954 | |
b80f6443 JA |
2955 | 3.7.4 Environment |
2956 | ----------------- | |
ccc6cda3 | 2957 | |
b80f6443 | 2958 | When a program is invoked it is given an array of strings called the |
74091dd4 | 2959 | "environment". This is a list of name-value pairs, of the form |
a0c0a00f | 2960 | 'name=value'. |
ccc6cda3 | 2961 | |
bb70624e | 2962 | Bash provides several ways to manipulate the environment. On |
ccc6cda3 | 2963 | invocation, the shell scans its own environment and creates a parameter |
74091dd4 | 2964 | for each name found, automatically marking it for 'export' to child |
a0c0a00f CR |
2965 | processes. Executed commands inherit the environment. The 'export' and |
2966 | 'declare -x' commands allow parameters and functions to be added to and | |
2967 | deleted from the environment. If the value of a parameter in the | |
ccc6cda3 JA |
2968 | environment is modified, the new value becomes part of the environment, |
2969 | replacing the old. The environment inherited by any executed command | |
2970 | consists of the shell's initial environment, whose values may be | |
a0c0a00f CR |
2971 | modified in the shell, less any pairs removed by the 'unset' and 'export |
2972 | -n' commands, plus any additions via the 'export' and 'declare -x' | |
2973 | commands. | |
ccc6cda3 JA |
2974 | |
2975 | The environment for any simple command or function may be augmented | |
2976 | temporarily by prefixing it with parameter assignments, as described in | |
3185942a | 2977 | *note Shell Parameters::. These assignment statements affect only the |
ccc6cda3 JA |
2978 | environment seen by that command. |
2979 | ||
a0c0a00f | 2980 | If the '-k' option is set (*note The Set Builtin::), then all |
ccc6cda3 JA |
2981 | parameter assignments are placed in the environment for a command, not |
2982 | just those that precede the command name. | |
2983 | ||
a0c0a00f | 2984 | When Bash invokes an external command, the variable '$_' is set to |
ac50fbac | 2985 | the full pathname of the command and passed to that command in its |
ccc6cda3 JA |
2986 | environment. |
2987 | ||
2988 | \1f | |
2989 | File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands | |
2990 | ||
b80f6443 JA |
2991 | 3.7.5 Exit Status |
2992 | ----------------- | |
ccc6cda3 | 2993 | |
3185942a | 2994 | The exit status of an executed command is the value returned by the |
74091dd4 CR |
2995 | 'waitpid' system call or equivalent function. Exit statuses fall |
2996 | between 0 and 255, though, as explained below, the shell may use values | |
2997 | above 125 specially. Exit statuses from shell builtins and compound | |
2998 | commands are also limited to this range. Under certain circumstances, | |
2999 | the shell will use special values to indicate specific failure modes. | |
3185942a JA |
3000 | |
3001 | For the shell's purposes, a command which exits with a zero exit | |
3002 | status has succeeded. A non-zero exit status indicates failure. This | |
cce855bc JA |
3003 | seemingly counter-intuitive scheme is used so there is one well-defined |
3004 | way to indicate success and a variety of ways to indicate various | |
a0c0a00f CR |
3005 | failure modes. When a command terminates on a fatal signal whose number |
3006 | is N, Bash uses the value 128+N as the exit status. | |
ccc6cda3 JA |
3007 | |
3008 | If a command is not found, the child process created to execute it | |
3009 | returns a status of 127. If a command is found but is not executable, | |
3010 | the return status is 126. | |
3011 | ||
cce855bc JA |
3012 | If a command fails because of an error during expansion or |
3013 | redirection, the exit status is greater than zero. | |
3014 | ||
ccc6cda3 | 3015 | The exit status is used by the Bash conditional commands (*note |
28ef6c31 JA |
3016 | Conditional Constructs::) and some of the list constructs (*note |
3017 | Lists::). | |
ccc6cda3 JA |
3018 | |
3019 | All of the Bash builtins return an exit status of zero if they | |
3020 | succeed and a non-zero status on failure, so they may be used by the | |
cce855bc | 3021 | conditional and list constructs. All builtins return an exit status of |
a0c0a00f CR |
3022 | 2 to indicate incorrect usage, generally invalid options or missing |
3023 | arguments. | |
ccc6cda3 | 3024 | |
74091dd4 CR |
3025 | The exit status of the last command is available in the special |
3026 | parameter $? (*note Special Parameters::). | |
3027 | ||
ccc6cda3 JA |
3028 | \1f |
3029 | File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands | |
3030 | ||
b80f6443 JA |
3031 | 3.7.6 Signals |
3032 | ------------- | |
ccc6cda3 | 3033 | |
b80f6443 | 3034 | When Bash is interactive, in the absence of any traps, it ignores |
a0c0a00f CR |
3035 | 'SIGTERM' (so that 'kill 0' does not kill an interactive shell), and |
3036 | 'SIGINT' is caught and handled (so that the 'wait' builtin is | |
3037 | interruptible). When Bash receives a 'SIGINT', it breaks out of any | |
3038 | executing loops. In all cases, Bash ignores 'SIGQUIT'. If job control | |
3039 | is in effect (*note Job Control::), Bash ignores 'SIGTTIN', 'SIGTTOU', | |
3040 | and 'SIGTSTP'. | |
ccc6cda3 | 3041 | |
b80f6443 JA |
3042 | Non-builtin commands started by Bash have signal handlers set to the |
3043 | values inherited by the shell from its parent. When job control is not | |
a0c0a00f | 3044 | in effect, asynchronous commands ignore 'SIGINT' and 'SIGQUIT' in |
b80f6443 JA |
3045 | addition to these inherited handlers. Commands run as a result of |
3046 | command substitution ignore the keyboard-generated job control signals | |
a0c0a00f | 3047 | 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'. |
ccc6cda3 | 3048 | |
a0c0a00f CR |
3049 | The shell exits by default upon receipt of a 'SIGHUP'. Before |
3050 | exiting, an interactive shell resends the 'SIGHUP' to all jobs, running | |
3051 | or stopped. Stopped jobs are sent 'SIGCONT' to ensure that they receive | |
3052 | the 'SIGHUP'. To prevent the shell from sending the 'SIGHUP' signal to | |
f73dda09 | 3053 | a particular job, it should be removed from the jobs table with the |
a0c0a00f CR |
3054 | 'disown' builtin (*note Job Control Builtins::) or marked to not receive |
3055 | 'SIGHUP' using 'disown -h'. | |
cce855bc | 3056 | |
a0c0a00f CR |
3057 | If the 'huponexit' shell option has been set with 'shopt' (*note The |
3058 | Shopt Builtin::), Bash sends a 'SIGHUP' to all jobs when an interactive | |
3059 | login shell exits. | |
cce855bc | 3060 | |
b80f6443 JA |
3061 | If Bash is waiting for a command to complete and receives a signal |
3062 | for which a trap has been set, the trap will not be executed until the | |
a0c0a00f CR |
3063 | command completes. When Bash is waiting for an asynchronous command via |
3064 | the 'wait' builtin, the reception of a signal for which a trap has been | |
3065 | set will cause the 'wait' builtin to return immediately with an exit | |
3066 | status greater than 128, immediately after which the trap is executed. | |
ccc6cda3 | 3067 | |
74091dd4 CR |
3068 | When job control is not enabled, and Bash is waiting for a foreground |
3069 | command to complete, the shell receives keyboard-generated signals such | |
3070 | as 'SIGINT' (usually generated by '^C') that users commonly intend to | |
3071 | send to that command. This happens because the shell and the command | |
3072 | are in the same process group as the terminal, and '^C' sends 'SIGINT' | |
3073 | to all processes in that process group. See *note Job Control::, for a | |
3074 | more in-depth discussion of process groups. | |
3075 | ||
3076 | When Bash is running without job control enabled and receives | |
3077 | 'SIGINT' while waiting for a foreground command, it waits until that | |
3078 | foreground command terminates and then decides what to do about the | |
3079 | 'SIGINT': | |
3080 | ||
3081 | 1. If the command terminates due to the 'SIGINT', Bash concludes that | |
3082 | the user meant to end the entire script, and acts on the 'SIGINT' | |
3083 | (e.g., by running a 'SIGINT' trap or exiting itself); | |
3084 | ||
3085 | 2. If the pipeline does not terminate due to 'SIGINT', the program | |
3086 | handled the 'SIGINT' itself and did not treat it as a fatal signal. | |
3087 | In that case, Bash does not treat 'SIGINT' as a fatal signal, | |
3088 | either, instead assuming that the 'SIGINT' was used as part of the | |
3089 | program's normal operation (e.g., 'emacs' uses it to abort editing | |
3090 | commands) or deliberately discarded. However, Bash will run any | |
3091 | trap set on 'SIGINT', as it does with any other trapped signal it | |
3092 | receives while it is waiting for the foreground command to | |
3093 | complete, for compatibility. | |
3094 | ||
ccc6cda3 JA |
3095 | \1f |
3096 | File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features | |
3097 | ||
b80f6443 JA |
3098 | 3.8 Shell Scripts |
3099 | ================= | |
ccc6cda3 | 3100 | |
b80f6443 JA |
3101 | A shell script is a text file containing shell commands. When such a |
3102 | file is used as the first non-option argument when invoking Bash, and | |
a0c0a00f | 3103 | neither the '-c' nor '-s' option is supplied (*note Invoking Bash::), |
ccc6cda3 | 3104 | Bash reads and executes commands from the file, then exits. This mode |
f73dda09 JA |
3105 | of operation creates a non-interactive shell. The shell first searches |
3106 | for the file in the current directory, and looks in the directories in | |
a0c0a00f | 3107 | '$PATH' if not found there. |
f73dda09 | 3108 | |
a0c0a00f | 3109 | When Bash runs a shell script, it sets the special parameter '0' to |
f73dda09 JA |
3110 | the name of the file, rather than the name of the shell, and the |
3111 | positional parameters are set to the remaining arguments, if any are | |
3112 | given. If no additional arguments are supplied, the positional | |
3113 | parameters are unset. | |
ccc6cda3 | 3114 | |
a0c0a00f CR |
3115 | A shell script may be made executable by using the 'chmod' command to |
3116 | turn on the execute bit. When Bash finds such a file while searching | |
74091dd4 CR |
3117 | the '$PATH' for a command, it creates a new instance of itself to |
3118 | execute it. In other words, executing | |
ccc6cda3 | 3119 | filename ARGUMENTS |
a0c0a00f | 3120 | is equivalent to executing |
ccc6cda3 JA |
3121 | bash filename ARGUMENTS |
3122 | ||
a0c0a00f | 3123 | if 'filename' is an executable shell script. This subshell |
ccc6cda3 | 3124 | reinitializes itself, so that the effect is as if a new shell had been |
cce855bc | 3125 | invoked to interpret the script, with the exception that the locations |
a0c0a00f | 3126 | of commands remembered by the parent (see the description of 'hash' in |
3185942a | 3127 | *note Bourne Shell Builtins::) are retained by the child. |
ccc6cda3 | 3128 | |
bb70624e JA |
3129 | Most versions of Unix make this a part of the operating system's |
3130 | command execution mechanism. If the first line of a script begins with | |
a0c0a00f | 3131 | the two characters '#!', the remainder of the line specifies an |
8868edaf CR |
3132 | interpreter for the program and, depending on the operating system, one |
3133 | or more optional arguments for that interpreter. Thus, you can specify | |
3134 | Bash, 'awk', Perl, or some other interpreter and write the rest of the | |
3135 | script file in that language. | |
bb70624e | 3136 | |
8868edaf CR |
3137 | The arguments to the interpreter consist of one or more optional |
3138 | arguments following the interpreter name on the first line of the script | |
bb70624e | 3139 | file, followed by the name of the script file, followed by the rest of |
8868edaf CR |
3140 | the arguments supplied to the script. The details of how the |
3141 | interpreter line is split into an interpreter name and a set of | |
3142 | arguments vary across systems. Bash will perform this action on | |
3143 | operating systems that do not handle it themselves. Note that some | |
3144 | older versions of Unix limit the interpreter name and a single argument | |
3145 | to a maximum of 32 characters, so it's not portable to assume that using | |
3146 | more than one argument will work. | |
bb70624e | 3147 | |
a0c0a00f CR |
3148 | Bash scripts often begin with '#! /bin/bash' (assuming that Bash has |
3149 | been installed in '/bin'), since this ensures that Bash will be used to | |
8868edaf CR |
3150 | interpret the script, even if it is executed under another shell. It's |
3151 | a common idiom to use 'env' to find 'bash' even if it's been installed | |
3152 | in another directory: '#!/usr/bin/env bash' will find the first | |
3153 | occurrence of 'bash' in '$PATH'. | |
ccc6cda3 JA |
3154 | |
3155 | \1f | |
bb70624e | 3156 | File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top |
ccc6cda3 | 3157 | |
b80f6443 JA |
3158 | 4 Shell Builtin Commands |
3159 | ************************ | |
ccc6cda3 JA |
3160 | |
3161 | * Menu: | |
3162 | ||
3163 | * Bourne Shell Builtins:: Builtin commands inherited from the Bourne | |
3164 | Shell. | |
bb70624e | 3165 | * Bash Builtins:: Table of builtins specific to Bash. |
3185942a JA |
3166 | * Modifying Shell Behavior:: Builtins to modify shell attributes and |
3167 | optional behavior. | |
bb70624e | 3168 | * Special Builtins:: Builtin commands classified specially by |
0628567a | 3169 | POSIX. |
bb70624e | 3170 | |
a0c0a00f CR |
3171 | Builtin commands are contained within the shell itself. When the name |
3172 | of a builtin command is used as the first word of a simple command | |
28ef6c31 | 3173 | (*note Simple Commands::), the shell executes the command directly, |
bb70624e JA |
3174 | without invoking another program. Builtin commands are necessary to |
3175 | implement functionality impossible or inconvenient to obtain with | |
3176 | separate utilities. | |
ccc6cda3 | 3177 | |
0628567a | 3178 | This section briefly describes the builtins which Bash inherits from |
a0c0a00f CR |
3179 | the Bourne Shell, as well as the builtin commands which are unique to or |
3180 | have been extended in Bash. | |
bb70624e | 3181 | |
a0c0a00f | 3182 | Several builtin commands are described in other chapters: builtin |
bb70624e | 3183 | commands which provide the Bash interface to the job control facilities |
28ef6c31 JA |
3184 | (*note Job Control Builtins::), the directory stack (*note Directory |
3185 | Stack Builtins::), the command history (*note Bash History Builtins::), | |
3186 | and the programmable completion facilities (*note Programmable | |
3187 | Completion Builtins::). | |
bb70624e JA |
3188 | |
3189 | Many of the builtins have been extended by POSIX or Bash. | |
ccc6cda3 | 3190 | |
b80f6443 | 3191 | Unless otherwise noted, each builtin command documented as accepting |
a0c0a00f | 3192 | options preceded by '-' accepts '--' to signify the end of the options. |
d233b485 CR |
3193 | The ':', 'true', 'false', and 'test'/'[' builtins do not accept options |
3194 | and do not treat '--' specially. The 'exit', 'logout', 'return', | |
3195 | 'break', 'continue', 'let', and 'shift' builtins accept and process | |
3196 | arguments beginning with '-' without requiring '--'. Other builtins | |
3197 | that accept arguments but are not specified as accepting options | |
3198 | interpret arguments beginning with '-' as invalid options and require | |
3199 | '--' to prevent this interpretation. | |
b80f6443 | 3200 | |
ccc6cda3 | 3201 | \1f |
bb70624e | 3202 | File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 3203 | |
b80f6443 JA |
3204 | 4.1 Bourne Shell Builtins |
3205 | ========================= | |
ccc6cda3 | 3206 | |
b80f6443 | 3207 | The following shell builtin commands are inherited from the Bourne |
0628567a | 3208 | Shell. These commands are implemented as specified by the POSIX |
ccc6cda3 JA |
3209 | standard. |
3210 | ||
a0c0a00f | 3211 | ': (a colon)' |
ccc6cda3 | 3212 | : [ARGUMENTS] |
ac50fbac | 3213 | |
ccc6cda3 | 3214 | Do nothing beyond expanding ARGUMENTS and performing redirections. |
cce855bc | 3215 | The return status is zero. |
ccc6cda3 | 3216 | |
a0c0a00f | 3217 | '. (a period)' |
b72432fd | 3218 | . FILENAME [ARGUMENTS] |
ac50fbac | 3219 | |
a0c0a00f CR |
3220 | Read and execute commands from the FILENAME argument in the current |
3221 | shell context. If FILENAME does not contain a slash, the 'PATH' | |
74091dd4 CR |
3222 | variable is used to find FILENAME, but FILENAME does not need to be |
3223 | executable. When Bash is not in POSIX mode, it searches the | |
3224 | current directory if FILENAME is not found in '$PATH'. If any | |
3225 | ARGUMENTS are supplied, they become the positional parameters when | |
3226 | FILENAME is executed. Otherwise the positional parameters are | |
3227 | unchanged. If the '-T' option is enabled, '.' inherits any trap on | |
3228 | 'DEBUG'; if it is not, any 'DEBUG' trap string is saved and | |
3229 | restored around the call to '.', and '.' unsets the 'DEBUG' trap | |
3230 | while it executes. If '-T' is not set, and the sourced file | |
3231 | changes the 'DEBUG' trap, the new value is retained when '.' | |
3232 | completes. The return status is the exit status of the last | |
3233 | command executed, or zero if no commands are executed. If FILENAME | |
3234 | is not found, or cannot be read, the return status is non-zero. | |
3235 | This builtin is equivalent to 'source'. | |
a0c0a00f CR |
3236 | |
3237 | 'break' | |
ccc6cda3 | 3238 | break [N] |
ac50fbac | 3239 | |
a0c0a00f CR |
3240 | Exit from a 'for', 'while', 'until', or 'select' loop. If N is |
3241 | supplied, the Nth enclosing loop is exited. N must be greater than | |
3242 | or equal to 1. The return status is zero unless N is not greater | |
3243 | than or equal to 1. | |
ccc6cda3 | 3244 | |
a0c0a00f | 3245 | 'cd' |
ac50fbac CR |
3246 | cd [-L|[-P [-e]] [-@] [DIRECTORY] |
3247 | ||
a0c0a00f | 3248 | Change the current working directory to DIRECTORY. If DIRECTORY is |
74091dd4 CR |
3249 | not supplied, the value of the 'HOME' shell variable is used. If |
3250 | the shell variable 'CDPATH' exists, it is used as a search path: | |
3251 | each directory name in 'CDPATH' is searched for DIRECTORY, with | |
a0c0a00f CR |
3252 | alternative directory names in 'CDPATH' separated by a colon (':'). |
3253 | If DIRECTORY begins with a slash, 'CDPATH' is not used. | |
b80f6443 | 3254 | |
a0c0a00f CR |
3255 | The '-P' option means to not follow symbolic links: symbolic links |
3256 | are resolved while 'cd' is traversing DIRECTORY and before | |
3257 | processing an instance of '..' in DIRECTORY. | |
ac50fbac | 3258 | |
a0c0a00f CR |
3259 | By default, or when the '-L' option is supplied, symbolic links in |
3260 | DIRECTORY are resolved after 'cd' processes an instance of '..' in | |
ac50fbac CR |
3261 | DIRECTORY. |
3262 | ||
a0c0a00f | 3263 | If '..' appears in DIRECTORY, it is processed by removing the |
ac50fbac CR |
3264 | immediately preceding pathname component, back to a slash or the |
3265 | beginning of DIRECTORY. | |
3266 | ||
a0c0a00f | 3267 | If the '-e' option is supplied with '-P' and the current working |
ac50fbac | 3268 | directory cannot be successfully determined after a successful |
a0c0a00f | 3269 | directory change, 'cd' will return an unsuccessful status. |
ac50fbac | 3270 | |
a0c0a00f | 3271 | On systems that support it, the '-@' option presents the extended |
ac50fbac CR |
3272 | attributes associated with a file as a directory. |
3273 | ||
a0c0a00f | 3274 | If DIRECTORY is '-', it is converted to '$OLDPWD' before the |
ac50fbac | 3275 | directory change is attempted. |
b80f6443 | 3276 | |
a0c0a00f | 3277 | If a non-empty directory name from 'CDPATH' is used, or if '-' is |
b80f6443 JA |
3278 | the first argument, and the directory change is successful, the |
3279 | absolute pathname of the new working directory is written to the | |
3280 | standard output. | |
3281 | ||
74091dd4 CR |
3282 | If the directory change is successful, 'cd' sets the value of the |
3283 | 'PWD' environment variable to the new directory name, and sets the | |
3284 | 'OLDPWD' environment variable to the value of the current working | |
3285 | directory before the change. | |
3286 | ||
b80f6443 JA |
3287 | The return status is zero if the directory is successfully changed, |
3288 | non-zero otherwise. | |
ccc6cda3 | 3289 | |
a0c0a00f | 3290 | 'continue' |
ccc6cda3 | 3291 | continue [N] |
ac50fbac | 3292 | |
a0c0a00f CR |
3293 | Resume the next iteration of an enclosing 'for', 'while', 'until', |
3294 | or 'select' loop. If N is supplied, the execution of the Nth | |
cce855bc JA |
3295 | enclosing loop is resumed. N must be greater than or equal to 1. |
3296 | The return status is zero unless N is not greater than or equal to | |
3297 | 1. | |
ccc6cda3 | 3298 | |
a0c0a00f | 3299 | 'eval' |
ccc6cda3 | 3300 | eval [ARGUMENTS] |
ac50fbac | 3301 | |
ccc6cda3 | 3302 | The arguments are concatenated together into a single command, |
cce855bc | 3303 | which is then read and executed, and its exit status returned as |
a0c0a00f CR |
3304 | the exit status of 'eval'. If there are no arguments or only empty |
3305 | arguments, the return status is zero. | |
ccc6cda3 | 3306 | |
a0c0a00f | 3307 | 'exec' |
cce855bc | 3308 | exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]] |
ac50fbac | 3309 | |
cce855bc | 3310 | If COMMAND is supplied, it replaces the shell without creating a |
a0c0a00f | 3311 | new process. If the '-l' option is supplied, the shell places a |
3185942a | 3312 | dash at the beginning of the zeroth argument passed to COMMAND. |
a0c0a00f CR |
3313 | This is what the 'login' program does. The '-c' option causes |
3314 | COMMAND to be executed with an empty environment. If '-a' is | |
3185942a | 3315 | supplied, the shell passes NAME as the zeroth argument to COMMAND. |
ac50fbac | 3316 | If COMMAND cannot be executed for some reason, a non-interactive |
a0c0a00f | 3317 | shell exits, unless the 'execfail' shell option is enabled. In |
ac50fbac | 3318 | that case, it returns failure. An interactive shell returns |
d233b485 CR |
3319 | failure if the file cannot be executed. A subshell exits |
3320 | unconditionally if 'exec' fails. If no COMMAND is specified, | |
3321 | redirections may be used to affect the current shell environment. | |
3322 | If there are no redirection errors, the return status is zero; | |
3323 | otherwise the return status is non-zero. | |
ccc6cda3 | 3324 | |
a0c0a00f | 3325 | 'exit' |
ccc6cda3 | 3326 | exit [N] |
ac50fbac | 3327 | |
bb70624e JA |
3328 | Exit the shell, returning a status of N to the shell's parent. If |
3329 | N is omitted, the exit status is that of the last command executed. | |
a0c0a00f | 3330 | Any trap on 'EXIT' is executed before the shell terminates. |
ccc6cda3 | 3331 | |
a0c0a00f | 3332 | 'export' |
ccc6cda3 | 3333 | export [-fn] [-p] [NAME[=VALUE]] |
ac50fbac | 3334 | |
ccc6cda3 | 3335 | Mark each NAME to be passed to child processes in the environment. |
a0c0a00f CR |
3336 | If the '-f' option is supplied, the NAMEs refer to shell functions; |
3337 | otherwise the names refer to shell variables. The '-n' option | |
74091dd4 | 3338 | means to no longer mark each NAME for export. If no NAMEs are |
a0c0a00f CR |
3339 | supplied, or if the '-p' option is given, a list of names of all |
3340 | exported variables is displayed. The '-p' option displays output | |
3341 | in a form that may be reused as input. If a variable name is | |
3342 | followed by =VALUE, the value of the variable is set to VALUE. | |
3343 | ||
3344 | The return status is zero unless an invalid option is supplied, one | |
3345 | of the names is not a valid shell variable name, or '-f' is | |
b80f6443 | 3346 | supplied with a name that is not a shell function. |
ccc6cda3 | 3347 | |
a0c0a00f | 3348 | 'getopts' |
8868edaf | 3349 | getopts OPTSTRING NAME [ARG ...] |
ac50fbac | 3350 | |
a0c0a00f | 3351 | 'getopts' is used by shell scripts to parse positional parameters. |
bb70624e JA |
3352 | OPTSTRING contains the option characters to be recognized; if a |
3353 | character is followed by a colon, the option is expected to have an | |
ac50fbac | 3354 | argument, which should be separated from it by whitespace. The |
a0c0a00f CR |
3355 | colon (':') and question mark ('?') may not be used as option |
3356 | characters. Each time it is invoked, 'getopts' places the next | |
3357 | option in the shell variable NAME, initializing NAME if it does not | |
3358 | exist, and the index of the next argument to be processed into the | |
3359 | variable 'OPTIND'. 'OPTIND' is initialized to 1 each time the | |
bb70624e | 3360 | shell or a shell script is invoked. When an option requires an |
a0c0a00f CR |
3361 | argument, 'getopts' places that argument into the variable |
3362 | 'OPTARG'. The shell does not reset 'OPTIND' automatically; it must | |
3363 | be manually reset between multiple calls to 'getopts' within the | |
3364 | same shell invocation if a new set of parameters is to be used. | |
ccc6cda3 | 3365 | |
a0c0a00f CR |
3366 | When the end of options is encountered, 'getopts' exits with a |
3367 | return value greater than zero. 'OPTIND' is set to the index of | |
3368 | the first non-option argument, and NAME is set to '?'. | |
cce855bc | 3369 | |
a0c0a00f | 3370 | 'getopts' normally parses the positional parameters, but if more |
8868edaf CR |
3371 | arguments are supplied as ARG values, 'getopts' parses those |
3372 | instead. | |
cce855bc | 3373 | |
a0c0a00f | 3374 | 'getopts' can report errors in two ways. If the first character of |
ccc6cda3 | 3375 | OPTSTRING is a colon, SILENT error reporting is used. In normal |
ac50fbac | 3376 | operation, diagnostic messages are printed when invalid options or |
a0c0a00f | 3377 | missing option arguments are encountered. If the variable 'OPTERR' |
cce855bc | 3378 | is set to 0, no error messages will be displayed, even if the first |
a0c0a00f | 3379 | character of 'optstring' is not a colon. |
ccc6cda3 | 3380 | |
a0c0a00f CR |
3381 | If an invalid option is seen, 'getopts' places '?' into NAME and, |
3382 | if not silent, prints an error message and unsets 'OPTARG'. If | |
3383 | 'getopts' is silent, the option character found is placed in | |
3384 | 'OPTARG' and no diagnostic message is printed. | |
ccc6cda3 | 3385 | |
a0c0a00f CR |
3386 | If a required argument is not found, and 'getopts' is not silent, a |
3387 | question mark ('?') is placed in NAME, 'OPTARG' is unset, and a | |
3388 | diagnostic message is printed. If 'getopts' is silent, then a | |
3389 | colon (':') is placed in NAME and 'OPTARG' is set to the option | |
ccc6cda3 JA |
3390 | character found. |
3391 | ||
a0c0a00f | 3392 | 'hash' |
0628567a | 3393 | hash [-r] [-p FILENAME] [-dt] [NAME] |
ac50fbac | 3394 | |
a0c0a00f | 3395 | Each time 'hash' is invoked, it remembers the full pathnames of the |
495aee44 | 3396 | commands specified as NAME arguments, so they need not be searched |
a0c0a00f CR |
3397 | for on subsequent invocations. The commands are found by searching |
3398 | through the directories listed in '$PATH'. Any | |
3399 | previously-remembered pathname is discarded. The '-p' option | |
495aee44 | 3400 | inhibits the path search, and FILENAME is used as the location of |
a0c0a00f CR |
3401 | NAME. The '-r' option causes the shell to forget all remembered |
3402 | locations. The '-d' option causes the shell to forget the | |
3403 | remembered location of each NAME. If the '-t' option is supplied, | |
495aee44 | 3404 | the full pathname to which each NAME corresponds is printed. If |
d233b485 | 3405 | multiple NAME arguments are supplied with '-t', the NAME is printed |
a0c0a00f | 3406 | before the hashed full pathname. The '-l' option causes output to |
495aee44 | 3407 | be displayed in a format that may be reused as input. If no |
a0c0a00f CR |
3408 | arguments are given, or if only '-l' is supplied, information about |
3409 | remembered commands is printed. The return status is zero unless a | |
3410 | NAME is not found or an invalid option is supplied. | |
ccc6cda3 | 3411 | |
a0c0a00f | 3412 | 'pwd' |
ccc6cda3 | 3413 | pwd [-LP] |
ac50fbac | 3414 | |
bb70624e | 3415 | Print the absolute pathname of the current working directory. If |
a0c0a00f CR |
3416 | the '-P' option is supplied, the pathname printed will not contain |
3417 | symbolic links. If the '-L' option is supplied, the pathname | |
bb70624e JA |
3418 | printed may contain symbolic links. The return status is zero |
3419 | unless an error is encountered while determining the name of the | |
3420 | current directory or an invalid option is supplied. | |
ccc6cda3 | 3421 | |
a0c0a00f | 3422 | 'readonly' |
ac50fbac CR |
3423 | readonly [-aAf] [-p] [NAME[=VALUE]] ... |
3424 | ||
cce855bc | 3425 | Mark each NAME as readonly. The values of these names may not be |
a0c0a00f CR |
3426 | changed by subsequent assignment. If the '-f' option is supplied, |
3427 | each NAME refers to a shell function. The '-a' option means each | |
3428 | NAME refers to an indexed array variable; the '-A' option means | |
3429 | each NAME refers to an associative array variable. If both options | |
3430 | are supplied, '-A' takes precedence. If no NAME arguments are | |
3431 | given, or if the '-p' option is supplied, a list of all readonly | |
3432 | names is printed. The other options may be used to restrict the | |
3433 | output to a subset of the set of readonly names. The '-p' option | |
3434 | causes output to be displayed in a format that may be reused as | |
3435 | input. If a variable name is followed by =VALUE, the value of the | |
3436 | variable is set to VALUE. The return status is zero unless an | |
3437 | invalid option is supplied, one of the NAME arguments is not a | |
3438 | valid shell variable or function name, or the '-f' option is | |
ac50fbac | 3439 | supplied with a name that is not a shell function. |
ccc6cda3 | 3440 | |
a0c0a00f | 3441 | 'return' |
ccc6cda3 | 3442 | return [N] |
ac50fbac CR |
3443 | |
3444 | Cause a shell function to stop executing and return the value N to | |
3445 | its caller. If N is not supplied, the return value is the exit | |
a0c0a00f CR |
3446 | status of the last command executed in the function. If 'return' |
3447 | is executed by a trap handler, the last command used to determine | |
3448 | the status is the last command executed before the trap handler. | |
d233b485 | 3449 | If 'return' is executed during a 'DEBUG' trap, the last command |
a0c0a00f CR |
3450 | used to determine the status is the last command executed by the |
3451 | trap handler before 'return' was invoked. 'return' may also be | |
3452 | used to terminate execution of a script being executed with the '.' | |
3453 | ('source') builtin, returning either N or the exit status of the | |
3454 | last command executed within the script as the exit status of the | |
3455 | script. If N is supplied, the return value is its least | |
3456 | significant 8 bits. Any command associated with the 'RETURN' trap | |
3457 | is executed before execution resumes after the function or script. | |
3458 | The return status is non-zero if 'return' is supplied a non-numeric | |
3459 | argument or is used outside a function and not during the execution | |
3460 | of a script by '.' or 'source'. | |
3461 | ||
3462 | 'shift' | |
ccc6cda3 | 3463 | shift [N] |
ac50fbac | 3464 | |
cce855bc | 3465 | Shift the positional parameters to the left by N. The positional |
a0c0a00f | 3466 | parameters from N+1 ... '$#' are renamed to '$1' ... '$#'-N. |
8868edaf CR |
3467 | Parameters represented by the numbers '$#' down to '$#'-N+1 are |
3468 | unset. N must be a non-negative number less than or equal to '$#'. | |
3469 | If N is zero or greater than '$#', the positional parameters are | |
3470 | not changed. If N is not supplied, it is assumed to be 1. The | |
3471 | return status is zero unless N is greater than '$#' or less than | |
3472 | zero, non-zero otherwise. | |
ccc6cda3 | 3473 | |
a0c0a00f CR |
3474 | 'test' |
3475 | '[' | |
ac50fbac CR |
3476 | test EXPR |
3477 | ||
a0c0a00f | 3478 | Evaluate a conditional expression EXPR and return a status of 0 |
ac50fbac CR |
3479 | (true) or 1 (false). Each operator and operand must be a separate |
3480 | argument. Expressions are composed of the primaries described | |
a0c0a00f | 3481 | below in *note Bash Conditional Expressions::. 'test' does not |
ac50fbac | 3482 | accept any options, nor does it accept and ignore an argument of |
a0c0a00f | 3483 | '--' as signifying the end of options. |
cce855bc | 3484 | |
a0c0a00f CR |
3485 | When the '[' form is used, the last argument to the command must be |
3486 | a ']'. | |
bb70624e | 3487 | |
cce855bc | 3488 | Expressions may be combined using the following operators, listed |
3185942a | 3489 | in decreasing order of precedence. The evaluation depends on the |
495aee44 CR |
3490 | number of arguments; see below. Operator precedence is used when |
3491 | there are five or more arguments. | |
cce855bc | 3492 | |
a0c0a00f | 3493 | '! EXPR' |
cce855bc JA |
3494 | True if EXPR is false. |
3495 | ||
a0c0a00f | 3496 | '( EXPR )' |
cce855bc JA |
3497 | Returns the value of EXPR. This may be used to override the |
3498 | normal precedence of operators. | |
3499 | ||
a0c0a00f | 3500 | 'EXPR1 -a EXPR2' |
cce855bc JA |
3501 | True if both EXPR1 and EXPR2 are true. |
3502 | ||
a0c0a00f | 3503 | 'EXPR1 -o EXPR2' |
cce855bc JA |
3504 | True if either EXPR1 or EXPR2 is true. |
3505 | ||
a0c0a00f | 3506 | The 'test' and '[' builtins evaluate conditional expressions using |
cce855bc JA |
3507 | a set of rules based on the number of arguments. |
3508 | ||
a0c0a00f | 3509 | 0 arguments |
cce855bc JA |
3510 | The expression is false. |
3511 | ||
a0c0a00f | 3512 | 1 argument |
d233b485 | 3513 | The expression is true if, and only if, the argument is not |
cce855bc JA |
3514 | null. |
3515 | ||
a0c0a00f CR |
3516 | 2 arguments |
3517 | If the first argument is '!', the expression is true if and | |
3518 | only if the second argument is null. If the first argument is | |
3519 | one of the unary conditional operators (*note Bash Conditional | |
3520 | Expressions::), the expression is true if the unary test is | |
3521 | true. If the first argument is not a valid unary operator, | |
3522 | the expression is false. | |
cce855bc | 3523 | |
a0c0a00f | 3524 | 3 arguments |
d233b485 CR |
3525 | The following conditions are applied in the order listed. |
3526 | ||
3527 | 1. If the second argument is one of the binary conditional | |
3528 | operators (*note Bash Conditional Expressions::), the | |
3529 | result of the expression is the result of the binary test | |
3530 | using the first and third arguments as operands. The | |
3531 | '-a' and '-o' operators are considered binary operators | |
3532 | when there are three arguments. | |
3533 | 2. If the first argument is '!', the value is the negation | |
3534 | of the two-argument test using the second and third | |
3535 | arguments. | |
3536 | 3. If the first argument is exactly '(' and the third | |
3537 | argument is exactly ')', the result is the one-argument | |
3538 | test of the second argument. | |
3539 | 4. Otherwise, the expression is false. | |
a0c0a00f CR |
3540 | |
3541 | 4 arguments | |
74091dd4 CR |
3542 | The following conditions are applied in the order listed. |
3543 | ||
3544 | 1. If the first argument is '!', the result is the negation | |
3545 | of the three-argument expression composed of the | |
3546 | remaining arguments. | |
3547 | 2. If the first argument is exactly '(' and the fourth | |
3548 | argument is exactly ')', the result is the two-argument | |
3549 | test of the second and third arguments. | |
3550 | 3. Otherwise, the expression is parsed and evaluated | |
3551 | according to precedence using the rules listed above. | |
cce855bc | 3552 | |
a0c0a00f | 3553 | 5 or more arguments |
cce855bc JA |
3554 | The expression is parsed and evaluated according to precedence |
3555 | using the rules listed above. | |
ccc6cda3 | 3556 | |
a0c0a00f | 3557 | When used with 'test' or '[', the '<' and '>' operators sort |
495aee44 CR |
3558 | lexicographically using ASCII ordering. |
3559 | ||
a0c0a00f | 3560 | 'times' |
ccc6cda3 | 3561 | times |
ac50fbac | 3562 | |
ccc6cda3 | 3563 | Print out the user and system times used by the shell and its |
cce855bc | 3564 | children. The return status is zero. |
ccc6cda3 | 3565 | |
a0c0a00f | 3566 | 'trap' |
d166f048 | 3567 | trap [-lp] [ARG] [SIGSPEC ...] |
ac50fbac | 3568 | |
ccc6cda3 | 3569 | The commands in ARG are to be read and executed when the shell |
b80f6443 | 3570 | receives signal SIGSPEC. If ARG is absent (and there is a single |
a0c0a00f | 3571 | SIGSPEC) or equal to '-', each specified signal's disposition is |
b80f6443 JA |
3572 | reset to the value it had when the shell was started. If ARG is |
3573 | the null string, then the signal specified by each SIGSPEC is | |
3574 | ignored by the shell and commands it invokes. If ARG is not | |
a0c0a00f | 3575 | present and '-p' has been supplied, the shell displays the trap |
b80f6443 | 3576 | commands associated with each SIGSPEC. If no arguments are |
a0c0a00f | 3577 | supplied, or only '-p' is given, 'trap' prints the list of commands |
b80f6443 | 3578 | associated with each signal number in a form that may be reused as |
a0c0a00f | 3579 | shell input. The '-l' option causes the shell to print a list of |
b80f6443 JA |
3580 | signal names and their corresponding numbers. Each SIGSPEC is |
3581 | either a signal name or a signal number. Signal names are case | |
a0c0a00f CR |
3582 | insensitive and the 'SIG' prefix is optional. |
3583 | ||
3584 | If a SIGSPEC is '0' or 'EXIT', ARG is executed when the shell | |
3585 | exits. If a SIGSPEC is 'DEBUG', the command ARG is executed before | |
3586 | every simple command, 'for' command, 'case' command, 'select' | |
3587 | command, every arithmetic 'for' command, and before the first | |
3588 | command executes in a shell function. Refer to the description of | |
3589 | the 'extdebug' option to the 'shopt' builtin (*note The Shopt | |
3590 | Builtin::) for details of its effect on the 'DEBUG' trap. If a | |
3591 | SIGSPEC is 'RETURN', the command ARG is executed each time a shell | |
3592 | function or a script executed with the '.' or 'source' builtins | |
3593 | finishes executing. | |
3594 | ||
3595 | If a SIGSPEC is 'ERR', the command ARG is executed whenever a | |
3596 | pipeline (which may consist of a single simple command), a list, or | |
3597 | a compound command returns a non-zero exit status, subject to the | |
3598 | following conditions. The 'ERR' trap is not executed if the failed | |
3599 | command is part of the command list immediately following an | |
3600 | 'until' or 'while' keyword, part of the test following the 'if' or | |
3601 | 'elif' reserved words, part of a command executed in a '&&' or '||' | |
3602 | list except the command following the final '&&' or '||', any | |
ac50fbac | 3603 | command in a pipeline but the last, or if the command's return |
a0c0a00f CR |
3604 | status is being inverted using '!'. These are the same conditions |
3605 | obeyed by the 'errexit' ('-e') option. | |
ccc6cda3 JA |
3606 | |
3607 | Signals ignored upon entry to the shell cannot be trapped or reset. | |
0628567a | 3608 | Trapped signals that are not being ignored are reset to their |
0001803f CR |
3609 | original values in a subshell or subshell environment when one is |
3610 | created. | |
ccc6cda3 | 3611 | |
a0c0a00f CR |
3612 | The return status is zero unless a SIGSPEC does not specify a valid |
3613 | signal. | |
cce855bc | 3614 | |
a0c0a00f | 3615 | 'umask' |
cce855bc | 3616 | umask [-p] [-S] [MODE] |
ac50fbac | 3617 | |
a0c0a00f CR |
3618 | Set the shell process's file creation mask to MODE. If MODE begins |
3619 | with a digit, it is interpreted as an octal number; if not, it is | |
3620 | interpreted as a symbolic mode mask similar to that accepted by the | |
3621 | 'chmod' command. If MODE is omitted, the current value of the mask | |
3622 | is printed. If the '-S' option is supplied without a MODE | |
3623 | argument, the mask is printed in a symbolic format. If the '-p' | |
3624 | option is supplied, and MODE is omitted, the output is in a form | |
3625 | that may be reused as input. The return status is zero if the mode | |
3626 | is successfully changed or if no MODE argument is supplied, and | |
3627 | non-zero otherwise. | |
ccc6cda3 | 3628 | |
bb70624e | 3629 | Note that when the mode is interpreted as an octal number, each |
a0c0a00f CR |
3630 | number of the umask is subtracted from '7'. Thus, a umask of '022' |
3631 | results in permissions of '755'. | |
bb70624e | 3632 | |
a0c0a00f | 3633 | 'unset' |
ac50fbac CR |
3634 | unset [-fnv] [NAME] |
3635 | ||
a0c0a00f | 3636 | Remove each variable or function NAME. If the '-v' option is |
ac50fbac | 3637 | given, each NAME refers to a shell variable and that variable is |
a0c0a00f CR |
3638 | removed. If the '-f' option is given, the NAMEs refer to shell |
3639 | functions, and the function definition is removed. If the '-n' | |
74091dd4 | 3640 | option is supplied, and NAME is a variable with the 'nameref' |
ac50fbac | 3641 | attribute, NAME will be unset rather than the variable it |
a0c0a00f CR |
3642 | references. '-n' has no effect if the '-f' option is supplied. If |
3643 | no options are supplied, each NAME refers to a variable; if there | |
8868edaf CR |
3644 | is no variable by that name, a function with that name, if any, is |
3645 | unset. Readonly variables and functions may not be unset. Some | |
3646 | shell variables lose their special behavior if they are unset; such | |
3647 | behavior is noted in the description of the individual variables. | |
74091dd4 CR |
3648 | The return status is zero unless a NAME is readonly or may not be |
3649 | unset. | |
ccc6cda3 JA |
3650 | |
3651 | \1f | |
3185942a | 3652 | File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 3653 | |
b80f6443 JA |
3654 | 4.2 Bash Builtin Commands |
3655 | ========================= | |
ccc6cda3 | 3656 | |
a0c0a00f CR |
3657 | This section describes builtin commands which are unique to or have been |
3658 | extended in Bash. Some of these commands are specified in the POSIX | |
3659 | standard. | |
ccc6cda3 | 3660 | |
a0c0a00f | 3661 | 'alias' |
ac50fbac | 3662 | alias [-p] [NAME[=VALUE] ...] |
ccc6cda3 | 3663 | |
a0c0a00f | 3664 | Without arguments or with the '-p' option, 'alias' prints the list |
bb70624e JA |
3665 | of aliases on the standard output in a form that allows them to be |
3666 | reused as input. If arguments are supplied, an alias is defined | |
3667 | for each NAME whose VALUE is given. If no VALUE is given, the name | |
3185942a | 3668 | and value of the alias is printed. Aliases are described in *note |
bb70624e | 3669 | Aliases::. |
ccc6cda3 | 3670 | |
a0c0a00f | 3671 | 'bind' |
ac50fbac | 3672 | bind [-m KEYMAP] [-lpsvPSVX] |
bb70624e JA |
3673 | bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ] |
3674 | bind [-m KEYMAP] -f FILENAME | |
3675 | bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND | |
3676 | bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME | |
a0c0a00f | 3677 | bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND |
74091dd4 | 3678 | bind READLINE-COMMAND-LINE |
ccc6cda3 | 3679 | |
28ef6c31 | 3680 | Display current Readline (*note Command Line Editing::) key and |
7117c2d2 JA |
3681 | function bindings, bind a key sequence to a Readline function or |
3682 | macro, or set a Readline variable. Each non-option argument is a | |
a0c0a00f CR |
3683 | command as it would appear in a Readline initialization file (*note |
3684 | Readline Init File::), but each binding or command must be passed | |
3685 | as a separate argument; e.g., '"\C-x\C-r":re-read-init-file'. | |
3185942a JA |
3686 | |
3687 | Options, if supplied, have the following meanings: | |
ccc6cda3 | 3688 | |
a0c0a00f | 3689 | '-m KEYMAP' |
bb70624e | 3690 | Use KEYMAP as the keymap to be affected by the subsequent |
a0c0a00f CR |
3691 | bindings. Acceptable KEYMAP names are 'emacs', |
3692 | 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move', | |
3693 | 'vi-command', and 'vi-insert'. 'vi' is equivalent to | |
3694 | 'vi-command' ('vi-move' is also a synonym); 'emacs' is | |
3695 | equivalent to 'emacs-standard'. | |
cce855bc | 3696 | |
a0c0a00f | 3697 | '-l' |
bb70624e | 3698 | List the names of all Readline functions. |
cce855bc | 3699 | |
a0c0a00f | 3700 | '-p' |
bb70624e | 3701 | Display Readline function names and bindings in such a way |
a0c0a00f CR |
3702 | that they can be used as input or in a Readline initialization |
3703 | file. | |
cce855bc | 3704 | |
a0c0a00f | 3705 | '-P' |
bb70624e | 3706 | List current Readline function names and bindings. |
cce855bc | 3707 | |
a0c0a00f | 3708 | '-v' |
bb70624e JA |
3709 | Display Readline variable names and values in such a way that |
3710 | they can be used as input or in a Readline initialization | |
3711 | file. | |
ccc6cda3 | 3712 | |
a0c0a00f | 3713 | '-V' |
bb70624e | 3714 | List current Readline variable names and values. |
ccc6cda3 | 3715 | |
a0c0a00f CR |
3716 | '-s' |
3717 | Display Readline key sequences bound to macros and the strings | |
3718 | they output in such a way that they can be used as input or in | |
3719 | a Readline initialization file. | |
ccc6cda3 | 3720 | |
a0c0a00f CR |
3721 | '-S' |
3722 | Display Readline key sequences bound to macros and the strings | |
3723 | they output. | |
ccc6cda3 | 3724 | |
a0c0a00f | 3725 | '-f FILENAME' |
bb70624e | 3726 | Read key bindings from FILENAME. |
ccc6cda3 | 3727 | |
a0c0a00f | 3728 | '-q FUNCTION' |
bb70624e | 3729 | Query about which keys invoke the named FUNCTION. |
ccc6cda3 | 3730 | |
a0c0a00f | 3731 | '-u FUNCTION' |
bb70624e | 3732 | Unbind all keys bound to the named FUNCTION. |
ccc6cda3 | 3733 | |
a0c0a00f | 3734 | '-r KEYSEQ' |
bb70624e | 3735 | Remove any current binding for KEYSEQ. |
ccc6cda3 | 3736 | |
a0c0a00f | 3737 | '-x KEYSEQ:SHELL-COMMAND' |
bb70624e | 3738 | Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered. |
3185942a | 3739 | When SHELL-COMMAND is executed, the shell sets the |
a0c0a00f | 3740 | 'READLINE_LINE' variable to the contents of the Readline line |
8868edaf CR |
3741 | buffer and the 'READLINE_POINT' and 'READLINE_MARK' variables |
3742 | to the current location of the insertion point and the saved | |
74091dd4 CR |
3743 | insertion point (the MARK), respectively. The shell assigns |
3744 | any numeric argument the user supplied to the | |
3745 | 'READLINE_ARGUMENT' variable. If there was no argument, that | |
3746 | variable is not set. If the executed command changes the | |
3747 | value of any of 'READLINE_LINE', 'READLINE_POINT', or | |
3748 | 'READLINE_MARK', those new values will be reflected in the | |
3749 | editing state. | |
b80f6443 | 3750 | |
a0c0a00f | 3751 | '-X' |
ac50fbac CR |
3752 | List all key sequences bound to shell commands and the |
3753 | associated commands in a format that can be reused as input. | |
3754 | ||
bb70624e JA |
3755 | The return status is zero unless an invalid option is supplied or |
3756 | an error occurs. | |
ccc6cda3 | 3757 | |
a0c0a00f | 3758 | 'builtin' |
bb70624e | 3759 | builtin [SHELL-BUILTIN [ARGS]] |
ac50fbac | 3760 | |
bb70624e | 3761 | Run a shell builtin, passing it ARGS, and return its exit status. |
a0c0a00f CR |
3762 | This is useful when defining a shell function with the same name as |
3763 | a shell builtin, retaining the functionality of the builtin within | |
3764 | the function. The return status is non-zero if SHELL-BUILTIN is | |
3765 | not a shell builtin command. | |
ccc6cda3 | 3766 | |
a0c0a00f | 3767 | 'caller' |
b80f6443 | 3768 | caller [EXPR] |
ac50fbac | 3769 | |
a0c0a00f CR |
3770 | Returns the context of any active subroutine call (a shell function |
3771 | or a script executed with the '.' or 'source' builtins). | |
b80f6443 | 3772 | |
a0c0a00f CR |
3773 | Without EXPR, 'caller' displays the line number and source filename |
3774 | of the current subroutine call. If a non-negative integer is | |
3775 | supplied as EXPR, 'caller' displays the line number, subroutine | |
3776 | name, and source file corresponding to that position in the current | |
3777 | execution call stack. This extra information may be used, for | |
3778 | example, to print a stack trace. The current frame is frame 0. | |
b80f6443 JA |
3779 | |
3780 | The return value is 0 unless the shell is not executing a | |
3781 | subroutine call or EXPR does not correspond to a valid position in | |
3782 | the call stack. | |
3783 | ||
a0c0a00f | 3784 | 'command' |
bb70624e | 3785 | command [-pVv] COMMAND [ARGUMENTS ...] |
ac50fbac | 3786 | |
bb70624e JA |
3787 | Runs COMMAND with ARGUMENTS ignoring any shell function named |
3788 | COMMAND. Only shell builtin commands or commands found by | |
a0c0a00f CR |
3789 | searching the 'PATH' are executed. If there is a shell function |
3790 | named 'ls', running 'command ls' within the function will execute | |
3791 | the external command 'ls' instead of calling the function | |
3792 | recursively. The '-p' option means to use a default value for | |
3793 | 'PATH' that is guaranteed to find all of the standard utilities. | |
3794 | The return status in this case is 127 if COMMAND cannot be found or | |
3795 | an error occurred, and the exit status of COMMAND otherwise. | |
3796 | ||
3797 | If either the '-V' or '-v' option is supplied, a description of | |
3798 | COMMAND is printed. The '-v' option causes a single word | |
bb70624e | 3799 | indicating the command or file name used to invoke COMMAND to be |
a0c0a00f CR |
3800 | displayed; the '-V' option produces a more verbose description. In |
3801 | this case, the return status is zero if COMMAND is found, and | |
bb70624e | 3802 | non-zero if not. |
ccc6cda3 | 3803 | |
a0c0a00f | 3804 | 'declare' |
8868edaf | 3805 | declare [-aAfFgiIlnrtux] [-p] [NAME[=VALUE] ...] |
ccc6cda3 | 3806 | |
a0c0a00f CR |
3807 | Declare variables and give them attributes. If no NAMEs are given, |
3808 | then display the values of variables instead. | |
ccc6cda3 | 3809 | |
a0c0a00f CR |
3810 | The '-p' option will display the attributes and values of each |
3811 | NAME. When '-p' is used with NAME arguments, additional options, | |
3812 | other than '-f' and '-F', are ignored. | |
3185942a | 3813 | |
a0c0a00f | 3814 | When '-p' is supplied without NAME arguments, 'declare' will |
3185942a JA |
3815 | display the attributes and values of all variables having the |
3816 | attributes specified by the additional options. If no other | |
a0c0a00f CR |
3817 | options are supplied with '-p', 'declare' will display the |
3818 | attributes and values of all shell variables. The '-f' option will | |
3819 | restrict the display to shell functions. | |
3820 | ||
3821 | The '-F' option inhibits the display of function definitions; only | |
3822 | the function name and attributes are printed. If the 'extdebug' | |
3823 | shell option is enabled using 'shopt' (*note The Shopt Builtin::), | |
3824 | the source file name and line number where each NAME is defined are | |
3825 | displayed as well. '-F' implies '-f'. | |
3826 | ||
3827 | The '-g' option forces variables to be created or modified at the | |
3828 | global scope, even when 'declare' is executed in a shell function. | |
ac50fbac | 3829 | It is ignored in all other cases. |
495aee44 | 3830 | |
8868edaf | 3831 | The '-I' option causes local variables to inherit the attributes |
74091dd4 | 3832 | (except the 'nameref' attribute) and value of any existing variable |
8868edaf CR |
3833 | with the same NAME at a surrounding scope. If there is no existing |
3834 | variable, the local variable is initially unset. | |
3835 | ||
495aee44 CR |
3836 | The following options can be used to restrict output to variables |
3837 | with the specified attributes or to give variables attributes: | |
ccc6cda3 | 3838 | |
a0c0a00f | 3839 | '-a' |
3185942a JA |
3840 | Each NAME is an indexed array variable (*note Arrays::). |
3841 | ||
a0c0a00f | 3842 | '-A' |
3185942a | 3843 | Each NAME is an associative array variable (*note Arrays::). |
ccc6cda3 | 3844 | |
a0c0a00f | 3845 | '-f' |
bb70624e | 3846 | Use function names only. |
ccc6cda3 | 3847 | |
a0c0a00f | 3848 | '-i' |
bb70624e | 3849 | The variable is to be treated as an integer; arithmetic |
28ef6c31 | 3850 | evaluation (*note Shell Arithmetic::) is performed when the |
bb70624e | 3851 | variable is assigned a value. |
ccc6cda3 | 3852 | |
a0c0a00f | 3853 | '-l' |
3185942a JA |
3854 | When the variable is assigned a value, all upper-case |
3855 | characters are converted to lower-case. The upper-case | |
3856 | attribute is disabled. | |
3857 | ||
a0c0a00f | 3858 | '-n' |
74091dd4 | 3859 | Give each NAME the 'nameref' attribute, making it a name |
a0c0a00f CR |
3860 | reference to another variable. That other variable is defined |
3861 | by the value of NAME. All references, assignments, and | |
3862 | attribute modifications to NAME, except for those using or | |
3863 | changing the '-n' attribute itself, are performed on the | |
3864 | variable referenced by NAME's value. The nameref attribute | |
3865 | cannot be applied to array variables. | |
3866 | ||
3867 | '-r' | |
bb70624e JA |
3868 | Make NAMEs readonly. These names cannot then be assigned |
3869 | values by subsequent assignment statements or unset. | |
ccc6cda3 | 3870 | |
a0c0a00f CR |
3871 | '-t' |
3872 | Give each NAME the 'trace' attribute. Traced functions | |
3873 | inherit the 'DEBUG' and 'RETURN' traps from the calling shell. | |
95732b49 | 3874 | The trace attribute has no special meaning for variables. |
7117c2d2 | 3875 | |
a0c0a00f | 3876 | '-u' |
3185942a JA |
3877 | When the variable is assigned a value, all lower-case |
3878 | characters are converted to upper-case. The lower-case | |
3879 | attribute is disabled. | |
3880 | ||
a0c0a00f | 3881 | '-x' |
bb70624e JA |
3882 | Mark each NAME for export to subsequent commands via the |
3883 | environment. | |
ccc6cda3 | 3884 | |
a0c0a00f | 3885 | Using '+' instead of '-' turns off the attribute instead, with the |
d233b485 CR |
3886 | exceptions that '+a' and '+A' may not be used to destroy array |
3887 | variables and '+r' will not remove the readonly attribute. When | |
3888 | used in a function, 'declare' makes each NAME local, as with the | |
3889 | 'local' command, unless the '-g' option is used. If a variable | |
3890 | name is followed by =VALUE, the value of the variable is set to | |
3891 | VALUE. | |
ccc6cda3 | 3892 | |
a0c0a00f | 3893 | When using '-a' or '-A' and the compound assignment syntax to |
ac50fbac CR |
3894 | create array variables, additional attributes do not take effect |
3895 | until subsequent assignments. | |
3896 | ||
bb70624e | 3897 | The return status is zero unless an invalid option is encountered, |
a0c0a00f | 3898 | an attempt is made to define a function using '-f foo=bar', an |
bb70624e JA |
3899 | attempt is made to assign a value to a readonly variable, an |
3900 | attempt is made to assign a value to an array variable without | |
28ef6c31 | 3901 | using the compound assignment syntax (*note Arrays::), one of the |
74091dd4 | 3902 | NAMEs is not a valid shell variable name, an attempt is made to |
bb70624e JA |
3903 | turn off readonly status for a readonly variable, an attempt is |
3904 | made to turn off array status for an array variable, or an attempt | |
a0c0a00f | 3905 | is made to display a non-existent function with '-f'. |
ccc6cda3 | 3906 | |
a0c0a00f | 3907 | 'echo' |
bb70624e | 3908 | echo [-neE] [ARG ...] |
ac50fbac | 3909 | |
bb70624e | 3910 | Output the ARGs, separated by spaces, terminated with a newline. |
a0c0a00f CR |
3911 | The return status is 0 unless a write error occurs. If '-n' is |
3912 | specified, the trailing newline is suppressed. If the '-e' option | |
ac50fbac | 3913 | is given, interpretation of the following backslash-escaped |
a0c0a00f CR |
3914 | characters is enabled. The '-E' option disables the interpretation |
3915 | of these escape characters, even on systems where they are | |
3916 | interpreted by default. The 'xpg_echo' shell option may be used to | |
3917 | dynamically determine whether or not 'echo' expands these escape | |
3918 | characters by default. 'echo' does not interpret '--' to mean the | |
3919 | end of options. | |
3920 | ||
3921 | 'echo' interprets the following escape sequences: | |
3922 | '\a' | |
bb70624e | 3923 | alert (bell) |
a0c0a00f | 3924 | '\b' |
bb70624e | 3925 | backspace |
a0c0a00f | 3926 | '\c' |
3185942a | 3927 | suppress further output |
a0c0a00f CR |
3928 | '\e' |
3929 | '\E' | |
bb70624e | 3930 | escape |
a0c0a00f | 3931 | '\f' |
bb70624e | 3932 | form feed |
a0c0a00f | 3933 | '\n' |
bb70624e | 3934 | new line |
a0c0a00f | 3935 | '\r' |
bb70624e | 3936 | carriage return |
a0c0a00f | 3937 | '\t' |
bb70624e | 3938 | horizontal tab |
a0c0a00f | 3939 | '\v' |
bb70624e | 3940 | vertical tab |
a0c0a00f | 3941 | '\\' |
bb70624e | 3942 | backslash |
a0c0a00f | 3943 | '\0NNN' |
7117c2d2 JA |
3944 | the eight-bit character whose value is the octal value NNN |
3945 | (zero to three octal digits) | |
a0c0a00f | 3946 | '\xHH' |
f73dda09 JA |
3947 | the eight-bit character whose value is the hexadecimal value |
3948 | HH (one or two hex digits) | |
a0c0a00f | 3949 | '\uHHHH' |
495aee44 CR |
3950 | the Unicode (ISO/IEC 10646) character whose value is the |
3951 | hexadecimal value HHHH (one to four hex digits) | |
a0c0a00f | 3952 | '\UHHHHHHHH' |
495aee44 CR |
3953 | the Unicode (ISO/IEC 10646) character whose value is the |
3954 | hexadecimal value HHHHHHHH (one to eight hex digits) | |
3955 | ||
a0c0a00f | 3956 | 'enable' |
3185942a | 3957 | enable [-a] [-dnps] [-f FILENAME] [NAME ...] |
ac50fbac | 3958 | |
bb70624e | 3959 | Enable and disable builtin shell commands. Disabling a builtin |
a0c0a00f CR |
3960 | allows a disk command which has the same name as a shell builtin to |
3961 | be executed without specifying a full pathname, even though the | |
3962 | shell normally searches for builtins before disk commands. If '-n' | |
3963 | is used, the NAMEs become disabled. Otherwise NAMEs are enabled. | |
3964 | For example, to use the 'test' binary found via '$PATH' instead of | |
3965 | the shell builtin version, type 'enable -n test'. | |
3966 | ||
3967 | If the '-p' option is supplied, or no NAME arguments appear, a list | |
3968 | of shell builtins is printed. With no other arguments, the list | |
3969 | consists of all enabled shell builtins. The '-a' option means to | |
3970 | list each builtin with an indication of whether or not it is | |
3971 | enabled. | |
3972 | ||
3973 | The '-f' option means to load the new builtin command NAME from | |
bb70624e | 3974 | shared object FILENAME, on systems that support dynamic loading. |
74091dd4 CR |
3975 | Bash will use the value of the 'BASH_LOADABLES_PATH' variable as a |
3976 | colon-separated list of directories in which to search for | |
3977 | FILENAME. The default is system-dependent. The '-d' option will | |
3978 | delete a builtin loaded with '-f'. | |
ccc6cda3 | 3979 | |
bb70624e | 3980 | If there are no options, a list of the shell builtins is displayed. |
a0c0a00f CR |
3981 | The '-s' option restricts 'enable' to the POSIX special builtins. |
3982 | If '-s' is used with '-f', the new builtin becomes a special | |
28ef6c31 | 3983 | builtin (*note Special Builtins::). |
ccc6cda3 | 3984 | |
74091dd4 CR |
3985 | If no options are supplied and a NAME is not a shell builtin, |
3986 | 'enable' will attempt to load NAME from a shared object named NAME, | |
3987 | as if the command were 'enable -f NAME NAME'. | |
3988 | ||
bb70624e JA |
3989 | The return status is zero unless a NAME is not a shell builtin or |
3990 | there is an error loading a new builtin from a shared object. | |
ccc6cda3 | 3991 | |
a0c0a00f | 3992 | 'help' |
3185942a | 3993 | help [-dms] [PATTERN] |
ac50fbac | 3994 | |
bb70624e | 3995 | Display helpful information about builtin commands. If PATTERN is |
a0c0a00f | 3996 | specified, 'help' gives detailed help on all commands matching |
3185942a JA |
3997 | PATTERN, otherwise a list of the builtins is printed. |
3998 | ||
3999 | Options, if supplied, have the following meanings: | |
4000 | ||
a0c0a00f | 4001 | '-d' |
3185942a | 4002 | Display a short description of each PATTERN |
a0c0a00f | 4003 | '-m' |
3185942a JA |
4004 | Display the description of each PATTERN in a manpage-like |
4005 | format | |
a0c0a00f | 4006 | '-s' |
3185942a JA |
4007 | Display only a short usage synopsis for each PATTERN |
4008 | ||
4009 | The return status is zero unless no command matches PATTERN. | |
ccc6cda3 | 4010 | |
a0c0a00f | 4011 | 'let' |
ac50fbac CR |
4012 | let EXPRESSION [EXPRESSION ...] |
4013 | ||
a0c0a00f | 4014 | The 'let' builtin allows arithmetic to be performed on shell |
bb70624e | 4015 | variables. Each EXPRESSION is evaluated according to the rules |
3185942a | 4016 | given below in *note Shell Arithmetic::. If the last EXPRESSION |
a0c0a00f | 4017 | evaluates to 0, 'let' returns 1; otherwise 0 is returned. |
ccc6cda3 | 4018 | |
a0c0a00f | 4019 | 'local' |
b80f6443 | 4020 | local [OPTION] NAME[=VALUE] ... |
ac50fbac | 4021 | |
bb70624e JA |
4022 | For each argument, a local variable named NAME is created, and |
4023 | assigned VALUE. The OPTION can be any of the options accepted by | |
a0c0a00f | 4024 | 'declare'. 'local' can only be used within a function; it makes |
bb70624e | 4025 | the variable NAME have a visible scope restricted to that function |
a0c0a00f CR |
4026 | and its children. If NAME is '-', the set of shell options is made |
4027 | local to the function in which 'local' is invoked: shell options | |
4028 | changed using the 'set' builtin inside the function are restored to | |
8868edaf CR |
4029 | their original values when the function returns. The restore is |
4030 | effected as if a series of 'set' commands were executed to restore | |
4031 | the values that were in place before the function. The return | |
4032 | status is zero unless 'local' is used outside a function, an | |
4033 | invalid NAME is supplied, or NAME is a readonly variable. | |
a0c0a00f CR |
4034 | |
4035 | 'logout' | |
bb70624e | 4036 | logout [N] |
ac50fbac | 4037 | |
bb70624e | 4038 | Exit a login shell, returning a status of N to the shell's parent. |
ccc6cda3 | 4039 | |
a0c0a00f | 4040 | 'mapfile' |
d233b485 CR |
4041 | mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] |
4042 | [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY] | |
ac50fbac | 4043 | |
0001803f | 4044 | Read lines from the standard input into the indexed array variable |
a0c0a00f CR |
4045 | ARRAY, or from file descriptor FD if the '-u' option is supplied. |
4046 | The variable 'MAPFILE' is the default ARRAY. Options, if supplied, | |
4047 | have the following meanings: | |
ac50fbac | 4048 | |
a0c0a00f CR |
4049 | '-d' |
4050 | The first character of DELIM is used to terminate each input | |
d233b485 CR |
4051 | line, rather than newline. If DELIM is the empty string, |
4052 | 'mapfile' will terminate a line when it reads a NUL character. | |
a0c0a00f | 4053 | '-n' |
3185942a JA |
4054 | Copy at most COUNT lines. If COUNT is 0, all lines are |
4055 | copied. | |
a0c0a00f | 4056 | '-O' |
3185942a JA |
4057 | Begin assigning to ARRAY at index ORIGIN. The default index |
4058 | is 0. | |
a0c0a00f | 4059 | '-s' |
3185942a | 4060 | Discard the first COUNT lines read. |
a0c0a00f CR |
4061 | '-t' |
4062 | Remove a trailing DELIM (default newline) from each line read. | |
4063 | '-u' | |
3185942a JA |
4064 | Read lines from file descriptor FD instead of the standard |
4065 | input. | |
a0c0a00f | 4066 | '-C' |
d233b485 | 4067 | Evaluate CALLBACK each time QUANTUM lines are read. The '-c' |
a0c0a00f CR |
4068 | option specifies QUANTUM. |
4069 | '-c' | |
3185942a JA |
4070 | Specify the number of lines read between each call to |
4071 | CALLBACK. | |
4072 | ||
a0c0a00f CR |
4073 | If '-C' is specified without '-c', the default quantum is 5000. |
4074 | When CALLBACK is evaluated, it is supplied the index of the next | |
495aee44 CR |
4075 | array element to be assigned and the line to be assigned to that |
4076 | element as additional arguments. CALLBACK is evaluated after the | |
4077 | line is read but before the array element is assigned. | |
3185942a | 4078 | |
a0c0a00f | 4079 | If not supplied with an explicit origin, 'mapfile' will clear ARRAY |
3185942a JA |
4080 | before assigning to it. |
4081 | ||
a0c0a00f CR |
4082 | 'mapfile' returns successfully unless an invalid option or option |
4083 | argument is supplied, ARRAY is invalid or unassignable, or ARRAY is | |
4084 | not an indexed array. | |
3185942a | 4085 | |
a0c0a00f | 4086 | 'printf' |
3185942a | 4087 | printf [-v VAR] FORMAT [ARGUMENTS] |
ac50fbac | 4088 | |
bb70624e | 4089 | Write the formatted ARGUMENTS to the standard output under the |
a0c0a00f | 4090 | control of the FORMAT. The '-v' option causes the output to be |
495aee44 CR |
4091 | assigned to the variable VAR rather than being printed to the |
4092 | standard output. | |
4093 | ||
4094 | The FORMAT is a character string which contains three types of | |
4095 | objects: plain characters, which are simply copied to standard | |
4096 | output, character escape sequences, which are converted and copied | |
4097 | to the standard output, and format specifications, each of which | |
4098 | causes printing of the next successive ARGUMENT. In addition to | |
a0c0a00f CR |
4099 | the standard 'printf(1)' formats, 'printf' interprets the following |
4100 | extensions: | |
4101 | ||
4102 | '%b' | |
4103 | Causes 'printf' to expand backslash escape sequences in the | |
4104 | corresponding ARGUMENT in the same way as 'echo -e' (*note | |
4105 | Bash Builtins::). | |
4106 | '%q' | |
4107 | Causes 'printf' to output the corresponding ARGUMENT in a | |
495aee44 | 4108 | format that can be reused as shell input. |
74091dd4 CR |
4109 | '%Q' |
4110 | like '%q', but applies any supplied precision to the ARGUMENT | |
4111 | before quoting it. | |
a0c0a00f CR |
4112 | '%(DATEFMT)T' |
4113 | Causes 'printf' to output the date-time string resulting from | |
4114 | using DATEFMT as a format string for 'strftime'(3). The | |
495aee44 CR |
4115 | corresponding ARGUMENT is an integer representing the number |
4116 | of seconds since the epoch. Two special argument values may | |
a0c0a00f CR |
4117 | be used: -1 represents the current time, and -2 represents the |
4118 | time the shell was invoked. If no argument is specified, | |
ac50fbac | 4119 | conversion behaves as if -1 had been given. This is an |
a0c0a00f | 4120 | exception to the usual 'printf' behavior. |
495aee44 | 4121 | |
8868edaf CR |
4122 | The %b, %q, and %T directives all use the field width and precision |
4123 | arguments from the format specification and write that many bytes | |
4124 | from (or use that wide a field for) the expanded argument, which | |
4125 | usually contains more characters than the original. | |
4126 | ||
a0c0a00f CR |
4127 | Arguments to non-string format specifiers are treated as C language |
4128 | constants, except that a leading plus or minus sign is allowed, and | |
4129 | if the leading character is a single or double quote, the value is | |
4130 | the ASCII value of the following character. | |
95732b49 | 4131 | |
bb70624e JA |
4132 | The FORMAT is reused as necessary to consume all of the ARGUMENTS. |
4133 | If the FORMAT requires more ARGUMENTS than are supplied, the extra | |
4134 | format specifications behave as if a zero value or null string, as | |
4135 | appropriate, had been supplied. The return value is zero on | |
4136 | success, non-zero on failure. | |
ccc6cda3 | 4137 | |
a0c0a00f | 4138 | 'read' |
ac50fbac CR |
4139 | read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS] |
4140 | [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...] | |
4141 | ||
7117c2d2 | 4142 | One line is read from the standard input, or from the file |
a0c0a00f CR |
4143 | descriptor FD supplied as an argument to the '-u' option, split |
4144 | into words as described above in *note Word Splitting::, and the | |
7117c2d2 | 4145 | first word is assigned to the first NAME, the second word to the |
a0c0a00f CR |
4146 | second NAME, and so on. If there are more words than names, the |
4147 | remaining words and their intervening delimiters are assigned to | |
4148 | the last NAME. If there are fewer words read from the input stream | |
4149 | than names, the remaining names are assigned empty values. The | |
4150 | characters in the value of the 'IFS' variable are used to split the | |
4151 | line into words using the same rules the shell uses for expansion | |
4152 | (described above in *note Word Splitting::). The backslash | |
4153 | character '\' may be used to remove any special meaning for the | |
8868edaf | 4154 | next character read and for line continuation. |
3185942a JA |
4155 | |
4156 | Options, if supplied, have the following meanings: | |
ccc6cda3 | 4157 | |
a0c0a00f | 4158 | '-a ANAME' |
bb70624e JA |
4159 | The words are assigned to sequential indices of the array |
4160 | variable ANAME, starting at 0. All elements are removed from | |
4161 | ANAME before the assignment. Other NAME arguments are | |
4162 | ignored. | |
ccc6cda3 | 4163 | |
a0c0a00f | 4164 | '-d DELIM' |
bb70624e | 4165 | The first character of DELIM is used to terminate the input |
d233b485 CR |
4166 | line, rather than newline. If DELIM is the empty string, |
4167 | 'read' will terminate a line when it reads a NUL character. | |
ccc6cda3 | 4168 | |
a0c0a00f | 4169 | '-e' |
28ef6c31 | 4170 | Readline (*note Command Line Editing::) is used to obtain the |
3185942a | 4171 | line. Readline uses the current (or default, if line editing |
d233b485 CR |
4172 | was not previously active) editing settings, but uses |
4173 | Readline's default filename completion. | |
3185942a | 4174 | |
a0c0a00f | 4175 | '-i TEXT' |
3185942a JA |
4176 | If Readline is being used to read the line, TEXT is placed |
4177 | into the editing buffer before editing begins. | |
ccc6cda3 | 4178 | |
a0c0a00f CR |
4179 | '-n NCHARS' |
4180 | 'read' returns after reading NCHARS characters rather than | |
4181 | waiting for a complete line of input, but honors a delimiter | |
0001803f CR |
4182 | if fewer than NCHARS characters are read before the delimiter. |
4183 | ||
a0c0a00f CR |
4184 | '-N NCHARS' |
4185 | 'read' returns after reading exactly NCHARS characters rather | |
0001803f | 4186 | than waiting for a complete line of input, unless EOF is |
a0c0a00f | 4187 | encountered or 'read' times out. Delimiter characters |
0001803f | 4188 | encountered in the input are not treated specially and do not |
a0c0a00f CR |
4189 | cause 'read' to return until NCHARS characters are read. The |
4190 | result is not split on the characters in 'IFS'; the intent is | |
4191 | that the variable is assigned exactly the characters read | |
4192 | (with the exception of backslash; see the '-r' option below). | |
cce855bc | 4193 | |
a0c0a00f | 4194 | '-p PROMPT' |
bb70624e JA |
4195 | Display PROMPT, without a trailing newline, before attempting |
4196 | to read any input. The prompt is displayed only if input is | |
4197 | coming from a terminal. | |
ccc6cda3 | 4198 | |
a0c0a00f | 4199 | '-r' |
bb70624e JA |
4200 | If this option is given, backslash does not act as an escape |
4201 | character. The backslash is considered to be part of the | |
d233b485 CR |
4202 | line. In particular, a backslash-newline pair may not then be |
4203 | used as a line continuation. | |
ccc6cda3 | 4204 | |
a0c0a00f | 4205 | '-s' |
bb70624e JA |
4206 | Silent mode. If input is coming from a terminal, characters |
4207 | are not echoed. | |
cce855bc | 4208 | |
a0c0a00f CR |
4209 | '-t TIMEOUT' |
4210 | Cause 'read' to time out and return failure if a complete line | |
4211 | of input (or a specified number of characters) is not read | |
4212 | within TIMEOUT seconds. TIMEOUT may be a decimal number with | |
4213 | a fractional portion following the decimal point. This option | |
4214 | is only effective if 'read' is reading input from a terminal, | |
4215 | pipe, or other special file; it has no effect when reading | |
4216 | from regular files. If 'read' times out, 'read' saves any | |
4217 | partial input read into the specified variable NAME. If | |
4218 | TIMEOUT is 0, 'read' returns immediately, without trying to | |
8868edaf | 4219 | read any data. The exit status is 0 if input is available on |
74091dd4 CR |
4220 | the specified file descriptor, or the read will return EOF, |
4221 | non-zero otherwise. The exit status is greater than 128 if | |
4222 | the timeout is exceeded. | |
cce855bc | 4223 | |
a0c0a00f | 4224 | '-u FD' |
7117c2d2 JA |
4225 | Read input from file descriptor FD. |
4226 | ||
8868edaf CR |
4227 | If no NAMEs are supplied, the line read, without the ending |
4228 | delimiter but otherwise unmodified, is assigned to the variable | |
4229 | 'REPLY'. The exit status is zero, unless end-of-file is | |
4230 | encountered, 'read' times out (in which case the status is greater | |
4231 | than 128), a variable assignment error (such as assigning to a | |
4232 | readonly variable) occurs, or an invalid file descriptor is | |
4233 | supplied as the argument to '-u'. | |
4234 | ||
a0c0a00f | 4235 | 'readarray' |
d233b485 CR |
4236 | readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] |
4237 | [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY] | |
ac50fbac | 4238 | |
0001803f | 4239 | Read lines from the standard input into the indexed array variable |
a0c0a00f | 4240 | ARRAY, or from file descriptor FD if the '-u' option is supplied. |
17345e5a | 4241 | |
a0c0a00f | 4242 | A synonym for 'mapfile'. |
17345e5a | 4243 | |
a0c0a00f | 4244 | 'source' |
3185942a | 4245 | source FILENAME |
ac50fbac | 4246 | |
a0c0a00f | 4247 | A synonym for '.' (*note Bourne Shell Builtins::). |
cce855bc | 4248 | |
a0c0a00f | 4249 | 'type' |
3185942a | 4250 | type [-afptP] [NAME ...] |
ac50fbac | 4251 | |
3185942a JA |
4252 | For each NAME, indicate how it would be interpreted if used as a |
4253 | command name. | |
ccc6cda3 | 4254 | |
a0c0a00f CR |
4255 | If the '-t' option is used, 'type' prints a single word which is |
4256 | one of 'alias', 'function', 'builtin', 'file' or 'keyword', if NAME | |
4257 | is an alias, shell function, shell builtin, disk file, or shell | |
4258 | reserved word, respectively. If the NAME is not found, then | |
4259 | nothing is printed, and 'type' returns a failure status. | |
ccc6cda3 | 4260 | |
a0c0a00f CR |
4261 | If the '-p' option is used, 'type' either returns the name of the |
4262 | disk file that would be executed, or nothing if '-t' would not | |
4263 | return 'file'. | |
ccc6cda3 | 4264 | |
a0c0a00f CR |
4265 | The '-P' option forces a path search for each NAME, even if '-t' |
4266 | would not return 'file'. | |
ccc6cda3 | 4267 | |
a0c0a00f CR |
4268 | If a command is hashed, '-p' and '-P' print the hashed value, which |
4269 | is not necessarily the file that appears first in '$PATH'. | |
ccc6cda3 | 4270 | |
a0c0a00f | 4271 | If the '-a' option is used, 'type' returns all of the places that |
3185942a | 4272 | contain an executable named FILE. This includes aliases and |
a0c0a00f | 4273 | functions, if and only if the '-p' option is not also used. |
ccc6cda3 | 4274 | |
a0c0a00f CR |
4275 | If the '-f' option is used, 'type' does not attempt to find shell |
4276 | functions, as with the 'command' builtin. | |
ccc6cda3 | 4277 | |
74091dd4 | 4278 | The return status is zero if all of the NAMEs are found, non-zero |
3185942a | 4279 | if any are not found. |
ccc6cda3 | 4280 | |
a0c0a00f | 4281 | 'typeset' |
ac50fbac CR |
4282 | typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...] |
4283 | ||
a0c0a00f CR |
4284 | The 'typeset' command is supplied for compatibility with the Korn |
4285 | shell. It is a synonym for the 'declare' builtin command. | |
ccc6cda3 | 4286 | |
a0c0a00f | 4287 | 'ulimit' |
8868edaf CR |
4288 | ulimit [-HS] -a |
4289 | ulimit [-HS] [-bcdefiklmnpqrstuvxPRT] [LIMIT] | |
ac50fbac | 4290 | |
a0c0a00f | 4291 | 'ulimit' provides control over the resources available to processes |
3185942a JA |
4292 | started by the shell, on systems that allow such control. If an |
4293 | option is given, it is interpreted as follows: | |
ac50fbac | 4294 | |
a0c0a00f | 4295 | '-S' |
3185942a | 4296 | Change and report the soft limit associated with a resource. |
ccc6cda3 | 4297 | |
a0c0a00f | 4298 | '-H' |
3185942a | 4299 | Change and report the hard limit associated with a resource. |
ccc6cda3 | 4300 | |
a0c0a00f | 4301 | '-a' |
8868edaf | 4302 | All current limits are reported; no limits are set. |
cce855bc | 4303 | |
a0c0a00f | 4304 | '-b' |
3185942a | 4305 | The maximum socket buffer size. |
cce855bc | 4306 | |
a0c0a00f | 4307 | '-c' |
3185942a | 4308 | The maximum size of core files created. |
ccc6cda3 | 4309 | |
a0c0a00f | 4310 | '-d' |
3185942a | 4311 | The maximum size of a process's data segment. |
ccc6cda3 | 4312 | |
a0c0a00f | 4313 | '-e' |
3185942a | 4314 | The maximum scheduling priority ("nice"). |
b80f6443 | 4315 | |
a0c0a00f | 4316 | '-f' |
3185942a JA |
4317 | The maximum size of files written by the shell and its |
4318 | children. | |
b80f6443 | 4319 | |
a0c0a00f | 4320 | '-i' |
3185942a | 4321 | The maximum number of pending signals. |
b80f6443 | 4322 | |
a0c0a00f CR |
4323 | '-k' |
4324 | The maximum number of kqueues that may be allocated. | |
4325 | ||
4326 | '-l' | |
3185942a | 4327 | The maximum size that may be locked into memory. |
b80f6443 | 4328 | |
a0c0a00f | 4329 | '-m' |
0001803f CR |
4330 | The maximum resident set size (many systems do not honor this |
4331 | limit). | |
95732b49 | 4332 | |
a0c0a00f | 4333 | '-n' |
0001803f CR |
4334 | The maximum number of open file descriptors (most systems do |
4335 | not allow this value to be set). | |
95732b49 | 4336 | |
a0c0a00f | 4337 | '-p' |
3185942a | 4338 | The pipe buffer size. |
95732b49 | 4339 | |
a0c0a00f | 4340 | '-q' |
3185942a | 4341 | The maximum number of bytes in POSIX message queues. |
ccc6cda3 | 4342 | |
a0c0a00f | 4343 | '-r' |
3185942a | 4344 | The maximum real-time scheduling priority. |
b80f6443 | 4345 | |
a0c0a00f | 4346 | '-s' |
3185942a | 4347 | The maximum stack size. |
b80f6443 | 4348 | |
a0c0a00f | 4349 | '-t' |
3185942a | 4350 | The maximum amount of cpu time in seconds. |
b80f6443 | 4351 | |
a0c0a00f | 4352 | '-u' |
3185942a | 4353 | The maximum number of processes available to a single user. |
b80f6443 | 4354 | |
a0c0a00f | 4355 | '-v' |
495aee44 CR |
4356 | The maximum amount of virtual memory available to the shell, |
4357 | and, on some systems, to its children. | |
ccc6cda3 | 4358 | |
a0c0a00f | 4359 | '-x' |
3185942a | 4360 | The maximum number of file locks. |
ccc6cda3 | 4361 | |
a0c0a00f CR |
4362 | '-P' |
4363 | The maximum number of pseudoterminals. | |
4364 | ||
8868edaf CR |
4365 | '-R' |
4366 | The maximum time a real-time process can run before blocking, | |
4367 | in microseconds. | |
4368 | ||
a0c0a00f | 4369 | '-T' |
3185942a | 4370 | The maximum number of threads. |
0628567a | 4371 | |
a0c0a00f | 4372 | If LIMIT is given, and the '-a' option is not used, LIMIT is the |
ac50fbac | 4373 | new value of the specified resource. The special LIMIT values |
a0c0a00f | 4374 | 'hard', 'soft', and 'unlimited' stand for the current hard limit, |
ac50fbac | 4375 | the current soft limit, and no limit, respectively. A hard limit |
a0c0a00f CR |
4376 | cannot be increased by a non-root user once it is set; a soft limit |
4377 | may be increased up to the value of the hard limit. Otherwise, the | |
4378 | current value of the soft limit for the specified resource is | |
8868edaf CR |
4379 | printed, unless the '-H' option is supplied. When more than one |
4380 | resource is specified, the limit name and unit, if appropriate, are | |
4381 | printed before the value. When setting new limits, if neither '-H' | |
4382 | nor '-S' is supplied, both the hard and soft limits are set. If no | |
4383 | option is given, then '-f' is assumed. Values are in 1024-byte | |
4384 | increments, except for '-t', which is in seconds; '-R', which is in | |
4385 | microseconds; '-p', which is in units of 512-byte blocks; '-P', | |
4386 | '-T', '-b', '-k', '-n' and '-u', which are unscaled values; and, | |
4387 | when in POSIX Mode (*note Bash POSIX Mode::), '-c' and '-f', which | |
4388 | are in 512-byte increments. | |
ccc6cda3 | 4389 | |
f73dda09 JA |
4390 | The return status is zero unless an invalid option or argument is |
4391 | supplied, or an error occurs while setting a new limit. | |
ccc6cda3 | 4392 | |
a0c0a00f | 4393 | 'unalias' |
bb70624e | 4394 | unalias [-a] [NAME ... ] |
ccc6cda3 | 4395 | |
a0c0a00f | 4396 | Remove each NAME from the list of aliases. If '-a' is supplied, |
3185942a | 4397 | all aliases are removed. Aliases are described in *note Aliases::. |
ccc6cda3 | 4398 | |
bb70624e | 4399 | \1f |
3185942a | 4400 | File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands |
ccc6cda3 | 4401 | |
3185942a JA |
4402 | 4.3 Modifying Shell Behavior |
4403 | ============================ | |
4404 | ||
4405 | * Menu: | |
ccc6cda3 | 4406 | |
3185942a JA |
4407 | * The Set Builtin:: Change the values of shell attributes and |
4408 | positional parameters. | |
4409 | * The Shopt Builtin:: Modify shell optional behavior. | |
4410 | ||
4411 | \1f | |
4412 | File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior | |
4413 | ||
4414 | 4.3.1 The Set Builtin | |
4415 | --------------------- | |
4416 | ||
a0c0a00f | 4417 | This builtin is so complicated that it deserves its own section. 'set' |
3185942a JA |
4418 | allows you to change the values of shell options and set the positional |
4419 | parameters, or to display the names and values of shell variables. | |
ccc6cda3 | 4420 | |
a0c0a00f | 4421 | 'set' |
74091dd4 CR |
4422 | set [-abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [--] [-] [ARGUMENT ...] |
4423 | set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [--] [-] [ARGUMENT ...] | |
ccc6cda3 | 4424 | |
a0c0a00f | 4425 | If no options or arguments are supplied, 'set' displays the names |
bb70624e | 4426 | and values of all shell variables and functions, sorted according |
95732b49 JA |
4427 | to the current locale, in a format that may be reused as input for |
4428 | setting or resetting the currently-set variables. Read-only | |
a0c0a00f CR |
4429 | variables cannot be reset. In POSIX mode, only shell variables are |
4430 | listed. | |
ccc6cda3 | 4431 | |
bb70624e JA |
4432 | When options are supplied, they set or unset shell attributes. |
4433 | Options, if specified, have the following meanings: | |
ccc6cda3 | 4434 | |
a0c0a00f CR |
4435 | '-a' |
4436 | Each variable or function that is created or modified is given | |
4437 | the export attribute and marked for export to the environment | |
4438 | of subsequent commands. | |
ccc6cda3 | 4439 | |
a0c0a00f | 4440 | '-b' |
bb70624e JA |
4441 | Cause the status of terminated background jobs to be reported |
4442 | immediately, rather than before printing the next primary | |
4443 | prompt. | |
ccc6cda3 | 4444 | |
a0c0a00f | 4445 | '-e' |
0001803f CR |
4446 | Exit immediately if a pipeline (*note Pipelines::), which may |
4447 | consist of a single simple command (*note Simple Commands::), | |
ac50fbac CR |
4448 | a list (*note Lists::), or a compound command (*note Compound |
4449 | Commands::) returns a non-zero status. The shell does not | |
4450 | exit if the command that fails is part of the command list | |
a0c0a00f CR |
4451 | immediately following a 'while' or 'until' keyword, part of |
4452 | the test in an 'if' statement, part of any command executed in | |
4453 | a '&&' or '||' list except the command following the final | |
4454 | '&&' or '||', any command in a pipeline but the last, or if | |
4455 | the command's return status is being inverted with '!'. If a | |
ac50fbac | 4456 | compound command other than a subshell returns a non-zero |
a0c0a00f CR |
4457 | status because a command failed while '-e' was being ignored, |
4458 | the shell does not exit. A trap on 'ERR', if set, is executed | |
4459 | before the shell exits. | |
ccc6cda3 | 4460 | |
a0c0a00f CR |
4461 | This option applies to the shell environment and each subshell |
4462 | environment separately (*note Command Execution | |
0001803f CR |
4463 | Environment::), and may cause subshells to exit before |
4464 | executing all the commands in the subshell. | |
4465 | ||
ac50fbac | 4466 | If a compound command or shell function executes in a context |
a0c0a00f | 4467 | where '-e' is being ignored, none of the commands executed |
ac50fbac | 4468 | within the compound command or function body will be affected |
a0c0a00f CR |
4469 | by the '-e' setting, even if '-e' is set and a command returns |
4470 | a failure status. If a compound command or shell function | |
4471 | sets '-e' while executing in a context where '-e' is ignored, | |
4472 | that setting will not have any effect until the compound | |
4473 | command or the command containing the function call completes. | |
4474 | ||
4475 | '-f' | |
0001803f | 4476 | Disable filename expansion (globbing). |
ccc6cda3 | 4477 | |
a0c0a00f | 4478 | '-h' |
bb70624e JA |
4479 | Locate and remember (hash) commands as they are looked up for |
4480 | execution. This option is enabled by default. | |
ccc6cda3 | 4481 | |
a0c0a00f | 4482 | '-k' |
bb70624e JA |
4483 | All arguments in the form of assignment statements are placed |
4484 | in the environment for a command, not just those that precede | |
4485 | the command name. | |
ccc6cda3 | 4486 | |
a0c0a00f | 4487 | '-m' |
ac50fbac CR |
4488 | Job control is enabled (*note Job Control::). All processes |
4489 | run in a separate process group. When a background job | |
4490 | completes, the shell prints a line containing its exit status. | |
b72432fd | 4491 | |
a0c0a00f CR |
4492 | '-n' |
4493 | Read commands but do not execute them. This may be used to | |
bb70624e JA |
4494 | check a script for syntax errors. This option is ignored by |
4495 | interactive shells. | |
ccc6cda3 | 4496 | |
a0c0a00f CR |
4497 | '-o OPTION-NAME' |
4498 | ||
bb70624e | 4499 | Set the option corresponding to OPTION-NAME: |
ccc6cda3 | 4500 | |
a0c0a00f CR |
4501 | 'allexport' |
4502 | Same as '-a'. | |
ccc6cda3 | 4503 | |
a0c0a00f CR |
4504 | 'braceexpand' |
4505 | Same as '-B'. | |
ccc6cda3 | 4506 | |
a0c0a00f CR |
4507 | 'emacs' |
4508 | Use an 'emacs'-style line editing interface (*note | |
3185942a | 4509 | Command Line Editing::). This also affects the editing |
a0c0a00f | 4510 | interface used for 'read -e'. |
ccc6cda3 | 4511 | |
a0c0a00f CR |
4512 | 'errexit' |
4513 | Same as '-e'. | |
d166f048 | 4514 | |
a0c0a00f CR |
4515 | 'errtrace' |
4516 | Same as '-E'. | |
b80f6443 | 4517 | |
a0c0a00f CR |
4518 | 'functrace' |
4519 | Same as '-T'. | |
b80f6443 | 4520 | |
a0c0a00f CR |
4521 | 'hashall' |
4522 | Same as '-h'. | |
d166f048 | 4523 | |
a0c0a00f CR |
4524 | 'histexpand' |
4525 | Same as '-H'. | |
ccc6cda3 | 4526 | |
a0c0a00f | 4527 | 'history' |
3185942a | 4528 | Enable command history, as described in *note Bash |
bb70624e JA |
4529 | History Facilities::. This option is on by default in |
4530 | interactive shells. | |
ccc6cda3 | 4531 | |
a0c0a00f | 4532 | 'ignoreeof' |
bb70624e | 4533 | An interactive shell will not exit upon reading EOF. |
ccc6cda3 | 4534 | |
a0c0a00f CR |
4535 | 'keyword' |
4536 | Same as '-k'. | |
ccc6cda3 | 4537 | |
a0c0a00f CR |
4538 | 'monitor' |
4539 | Same as '-m'. | |
ccc6cda3 | 4540 | |
a0c0a00f CR |
4541 | 'noclobber' |
4542 | Same as '-C'. | |
ccc6cda3 | 4543 | |
a0c0a00f CR |
4544 | 'noexec' |
4545 | Same as '-n'. | |
ccc6cda3 | 4546 | |
a0c0a00f CR |
4547 | 'noglob' |
4548 | Same as '-f'. | |
ccc6cda3 | 4549 | |
a0c0a00f | 4550 | 'nolog' |
f73dda09 JA |
4551 | Currently ignored. |
4552 | ||
a0c0a00f CR |
4553 | 'notify' |
4554 | Same as '-b'. | |
ccc6cda3 | 4555 | |
a0c0a00f CR |
4556 | 'nounset' |
4557 | Same as '-u'. | |
ccc6cda3 | 4558 | |
a0c0a00f CR |
4559 | 'onecmd' |
4560 | Same as '-t'. | |
ccc6cda3 | 4561 | |
a0c0a00f CR |
4562 | 'physical' |
4563 | Same as '-P'. | |
ccc6cda3 | 4564 | |
a0c0a00f | 4565 | 'pipefail' |
b80f6443 JA |
4566 | If set, the return value of a pipeline is the value of |
4567 | the last (rightmost) command to exit with a non-zero | |
4568 | status, or zero if all commands in the pipeline exit | |
4569 | successfully. This option is disabled by default. | |
4570 | ||
a0c0a00f | 4571 | 'posix' |
3185942a JA |
4572 | Change the behavior of Bash where the default operation |
4573 | differs from the POSIX standard to match the standard | |
a0c0a00f CR |
4574 | (*note Bash POSIX Mode::). This is intended to make Bash |
4575 | behave as a strict superset of that standard. | |
3185942a | 4576 | |
a0c0a00f CR |
4577 | 'privileged' |
4578 | Same as '-p'. | |
3185942a | 4579 | |
a0c0a00f CR |
4580 | 'verbose' |
4581 | Same as '-v'. | |
3185942a | 4582 | |
a0c0a00f CR |
4583 | 'vi' |
4584 | Use a 'vi'-style line editing interface. This also | |
4585 | affects the editing interface used for 'read -e'. | |
3185942a | 4586 | |
a0c0a00f CR |
4587 | 'xtrace' |
4588 | Same as '-x'. | |
3185942a | 4589 | |
a0c0a00f CR |
4590 | '-p' |
4591 | Turn on privileged mode. In this mode, the '$BASH_ENV' and | |
4592 | '$ENV' files are not processed, shell functions are not | |
4593 | inherited from the environment, and the 'SHELLOPTS', | |
4594 | 'BASHOPTS', 'CDPATH' and 'GLOBIGNORE' variables, if they | |
0001803f CR |
4595 | appear in the environment, are ignored. If the shell is |
4596 | started with the effective user (group) id not equal to the | |
a0c0a00f | 4597 | real user (group) id, and the '-p' option is not supplied, |
0001803f | 4598 | these actions are taken and the effective user id is set to |
a0c0a00f | 4599 | the real user id. If the '-p' option is supplied at startup, |
0001803f CR |
4600 | the effective user id is not reset. Turning this option off |
4601 | causes the effective user and group ids to be set to the real | |
4602 | user and group ids. | |
3185942a | 4603 | |
74091dd4 CR |
4604 | '-r' |
4605 | Enable restricted shell mode. This option cannot be unset | |
4606 | once it has been set. | |
4607 | ||
a0c0a00f | 4608 | '-t' |
3185942a JA |
4609 | Exit after reading and executing one command. |
4610 | ||
a0c0a00f | 4611 | '-u' |
0001803f | 4612 | Treat unset variables and parameters other than the special |
74091dd4 CR |
4613 | parameters '@' or '*', or array variables subscripted with '@' |
4614 | or '*', as an error when performing parameter expansion. An | |
4615 | error message will be written to the standard error, and a | |
4616 | non-interactive shell will exit. | |
3185942a | 4617 | |
a0c0a00f | 4618 | '-v' |
3185942a JA |
4619 | Print shell input lines as they are read. |
4620 | ||
a0c0a00f CR |
4621 | '-x' |
4622 | Print a trace of simple commands, 'for' commands, 'case' | |
4623 | commands, 'select' commands, and arithmetic 'for' commands and | |
4624 | their arguments or associated word lists after they are | |
4625 | expanded and before they are executed. The value of the 'PS4' | |
3185942a JA |
4626 | variable is expanded and the resultant value is printed before |
4627 | the command and its expanded arguments. | |
4628 | ||
a0c0a00f | 4629 | '-B' |
3185942a JA |
4630 | The shell will perform brace expansion (*note Brace |
4631 | Expansion::). This option is on by default. | |
4632 | ||
a0c0a00f CR |
4633 | '-C' |
4634 | Prevent output redirection using '>', '>&', and '<>' from | |
3185942a JA |
4635 | overwriting existing files. |
4636 | ||
a0c0a00f CR |
4637 | '-E' |
4638 | If set, any trap on 'ERR' is inherited by shell functions, | |
3185942a | 4639 | command substitutions, and commands executed in a subshell |
a0c0a00f CR |
4640 | environment. The 'ERR' trap is normally not inherited in such |
4641 | cases. | |
3185942a | 4642 | |
a0c0a00f CR |
4643 | '-H' |
4644 | Enable '!' style history substitution (*note History | |
3185942a JA |
4645 | Interaction::). This option is on by default for interactive |
4646 | shells. | |
4647 | ||
a0c0a00f CR |
4648 | '-P' |
4649 | If set, do not resolve symbolic links when performing commands | |
4650 | such as 'cd' which change the current directory. The physical | |
4651 | directory is used instead. By default, Bash follows the | |
4652 | logical chain of directories when performing commands which | |
4653 | change the current directory. | |
3185942a | 4654 | |
a0c0a00f CR |
4655 | For example, if '/usr/sys' is a symbolic link to |
4656 | '/usr/local/sys' then: | |
3185942a JA |
4657 | $ cd /usr/sys; echo $PWD |
4658 | /usr/sys | |
4659 | $ cd ..; pwd | |
4660 | /usr | |
4661 | ||
a0c0a00f | 4662 | If 'set -P' is on, then: |
3185942a JA |
4663 | $ cd /usr/sys; echo $PWD |
4664 | /usr/local/sys | |
4665 | $ cd ..; pwd | |
4666 | /usr/local | |
4667 | ||
a0c0a00f CR |
4668 | '-T' |
4669 | If set, any trap on 'DEBUG' and 'RETURN' are inherited by | |
3185942a | 4670 | shell functions, command substitutions, and commands executed |
a0c0a00f CR |
4671 | in a subshell environment. The 'DEBUG' and 'RETURN' traps are |
4672 | normally not inherited in such cases. | |
3185942a | 4673 | |
a0c0a00f | 4674 | '--' |
3185942a JA |
4675 | If no arguments follow this option, then the positional |
4676 | parameters are unset. Otherwise, the positional parameters | |
4677 | are set to the ARGUMENTS, even if some of them begin with a | |
a0c0a00f | 4678 | '-'. |
3185942a | 4679 | |
a0c0a00f CR |
4680 | '-' |
4681 | Signal the end of options, cause all remaining ARGUMENTS to be | |
4682 | assigned to the positional parameters. The '-x' and '-v' | |
3185942a JA |
4683 | options are turned off. If there are no arguments, the |
4684 | positional parameters remain unchanged. | |
4685 | ||
a0c0a00f | 4686 | Using '+' rather than '-' causes these options to be turned off. |
3185942a | 4687 | The options can also be used upon invocation of the shell. The |
a0c0a00f | 4688 | current set of options may be found in '$-'. |
3185942a JA |
4689 | |
4690 | The remaining N ARGUMENTS are positional parameters and are | |
a0c0a00f CR |
4691 | assigned, in order, to '$1', '$2', ... '$N'. The special parameter |
4692 | '#' is set to N. | |
3185942a JA |
4693 | |
4694 | The return status is always zero unless an invalid option is | |
4695 | supplied. | |
4696 | ||
4697 | \1f | |
4698 | File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior | |
4699 | ||
4700 | 4.3.2 The Shopt Builtin | |
4701 | ----------------------- | |
4702 | ||
4703 | This builtin allows you to change additional shell optional behavior. | |
4704 | ||
a0c0a00f | 4705 | 'shopt' |
3185942a | 4706 | shopt [-pqsu] [-o] [OPTNAME ...] |
ac50fbac CR |
4707 | |
4708 | Toggle the values of settings controlling optional shell behavior. | |
a0c0a00f CR |
4709 | The settings can be either those listed below, or, if the '-o' |
4710 | option is used, those available with the '-o' option to the 'set' | |
ac50fbac | 4711 | builtin command (*note The Set Builtin::). With no options, or |
a0c0a00f | 4712 | with the '-p' option, a list of all settable options is displayed, |
74091dd4 | 4713 | with an indication of whether or not each is set; if OPTNAMEs are |
d233b485 CR |
4714 | supplied, the output is restricted to those options. The '-p' |
4715 | option causes output to be displayed in a form that may be reused | |
4716 | as input. Other options have the following meanings: | |
3185942a | 4717 | |
a0c0a00f | 4718 | '-s' |
3185942a JA |
4719 | Enable (set) each OPTNAME. |
4720 | ||
a0c0a00f | 4721 | '-u' |
3185942a JA |
4722 | Disable (unset) each OPTNAME. |
4723 | ||
a0c0a00f | 4724 | '-q' |
3185942a JA |
4725 | Suppresses normal output; the return status indicates whether |
4726 | the OPTNAME is set or unset. If multiple OPTNAME arguments | |
74091dd4 | 4727 | are given with '-q', the return status is zero if all OPTNAMEs |
a0c0a00f | 4728 | are enabled; non-zero otherwise. |
3185942a | 4729 | |
a0c0a00f | 4730 | '-o' |
3185942a | 4731 | Restricts the values of OPTNAME to be those defined for the |
a0c0a00f | 4732 | '-o' option to the 'set' builtin (*note The Set Builtin::). |
3185942a | 4733 | |
a0c0a00f | 4734 | If either '-s' or '-u' is used with no OPTNAME arguments, 'shopt' |
ac50fbac | 4735 | shows only those options which are set or unset, respectively. |
3185942a | 4736 | |
a0c0a00f | 4737 | Unless otherwise noted, the 'shopt' options are disabled (off) by |
3185942a JA |
4738 | default. |
4739 | ||
74091dd4 | 4740 | The return status when listing options is zero if all OPTNAMEs are |
3185942a JA |
4741 | enabled, non-zero otherwise. When setting or unsetting options, |
4742 | the return status is zero unless an OPTNAME is not a valid shell | |
4743 | option. | |
4744 | ||
a0c0a00f CR |
4745 | The list of 'shopt' options is: |
4746 | ||
d233b485 CR |
4747 | 'assoc_expand_once' |
4748 | If set, the shell suppresses multiple evaluation of | |
4749 | associative array subscripts during arithmetic expression | |
4750 | evaluation, while executing builtins that can perform variable | |
4751 | assignments, and while executing builtins that perform array | |
4752 | dereferencing. | |
4753 | ||
a0c0a00f | 4754 | 'autocd' |
3185942a | 4755 | If set, a command name that is the name of a directory is |
a0c0a00f CR |
4756 | executed as if it were the argument to the 'cd' command. This |
4757 | option is only used by interactive shells. | |
3185942a | 4758 | |
a0c0a00f CR |
4759 | 'cdable_vars' |
4760 | If this is set, an argument to the 'cd' builtin command that | |
3185942a JA |
4761 | is not a directory is assumed to be the name of a variable |
4762 | whose value is the directory to change to. | |
4763 | ||
a0c0a00f | 4764 | 'cdspell' |
3185942a | 4765 | If set, minor errors in the spelling of a directory component |
a0c0a00f | 4766 | in a 'cd' command will be corrected. The errors checked for |
3185942a JA |
4767 | are transposed characters, a missing character, and a |
4768 | character too many. If a correction is found, the corrected | |
4769 | path is printed, and the command proceeds. This option is | |
4770 | only used by interactive shells. | |
4771 | ||
a0c0a00f | 4772 | 'checkhash' |
3185942a | 4773 | If this is set, Bash checks that a command found in the hash |
a0c0a00f CR |
4774 | table exists before trying to execute it. If a hashed command |
4775 | no longer exists, a normal path search is performed. | |
3185942a | 4776 | |
a0c0a00f | 4777 | 'checkjobs' |
3185942a | 4778 | If set, Bash lists the status of any stopped and running jobs |
a0c0a00f CR |
4779 | before exiting an interactive shell. If any jobs are running, |
4780 | this causes the exit to be deferred until a second exit is | |
4781 | attempted without an intervening command (*note Job | |
3185942a JA |
4782 | Control::). The shell always postpones exiting if any jobs |
4783 | are stopped. | |
4784 | ||
a0c0a00f | 4785 | 'checkwinsize' |
d233b485 CR |
4786 | If set, Bash checks the window size after each external |
4787 | (non-builtin) command and, if necessary, updates the values of | |
4788 | 'LINES' and 'COLUMNS'. This option is enabled by default. | |
3185942a | 4789 | |
a0c0a00f | 4790 | 'cmdhist' |
3185942a JA |
4791 | If set, Bash attempts to save all lines of a multiple-line |
4792 | command in the same history entry. This allows easy | |
d233b485 CR |
4793 | re-editing of multi-line commands. This option is enabled by |
4794 | default, but only has an effect if command history is enabled | |
4795 | (*note Bash History Facilities::). | |
3185942a | 4796 | |
a0c0a00f | 4797 | 'compat31' |
a0c0a00f | 4798 | 'compat32' |
a0c0a00f | 4799 | 'compat40' |
a0c0a00f | 4800 | 'compat41' |
a0c0a00f | 4801 | 'compat42' |
a0c0a00f | 4802 | 'compat43' |
d233b485 | 4803 | 'compat44' |
8868edaf CR |
4804 | These control aspects of the shell's compatibility mode (*note |
4805 | Shell Compatibility Mode::). | |
d233b485 | 4806 | |
a0c0a00f | 4807 | 'complete_fullquote' |
ac50fbac CR |
4808 | If set, Bash quotes all shell metacharacters in filenames and |
4809 | directory names when performing completion. If not set, Bash | |
4810 | removes metacharacters such as the dollar sign from the set of | |
4811 | characters that will be quoted in completed filenames when | |
4812 | these metacharacters appear in shell variable references in | |
4813 | words to be completed. This means that dollar signs in | |
4814 | variable names that expand to directories will not be quoted; | |
4815 | however, any dollar signs appearing in filenames will not be | |
4816 | quoted, either. This is active only when bash is using | |
4817 | backslashes to quote completed filenames. This variable is | |
a0c0a00f CR |
4818 | set by default, which is the default Bash behavior in versions |
4819 | through 4.2. | |
ac50fbac | 4820 | |
a0c0a00f CR |
4821 | 'direxpand' |
4822 | If set, Bash replaces directory names with the results of word | |
4823 | expansion when performing filename completion. This changes | |
74091dd4 | 4824 | the contents of the Readline editing buffer. If not set, Bash |
a0c0a00f | 4825 | attempts to preserve what the user typed. |
ac50fbac | 4826 | |
a0c0a00f | 4827 | 'dirspell' |
3185942a JA |
4828 | If set, Bash attempts spelling correction on directory names |
4829 | during word completion if the directory name initially | |
4830 | supplied does not exist. | |
4831 | ||
a0c0a00f CR |
4832 | 'dotglob' |
4833 | If set, Bash includes filenames beginning with a '.' in the | |
d233b485 CR |
4834 | results of filename expansion. The filenames '.' and '..' |
4835 | must always be matched explicitly, even if 'dotglob' is set. | |
3185942a | 4836 | |
a0c0a00f | 4837 | 'execfail' |
3185942a | 4838 | If this is set, a non-interactive shell will not exit if it |
a0c0a00f CR |
4839 | cannot execute the file specified as an argument to the 'exec' |
4840 | builtin command. An interactive shell does not exit if 'exec' | |
3185942a JA |
4841 | fails. |
4842 | ||
a0c0a00f | 4843 | 'expand_aliases' |
3185942a JA |
4844 | If set, aliases are expanded as described below under Aliases, |
4845 | *note Aliases::. This option is enabled by default for | |
4846 | interactive shells. | |
4847 | ||
a0c0a00f | 4848 | 'extdebug' |
8868edaf CR |
4849 | If set at shell invocation, or in a shell startup file, |
4850 | arrange to execute the debugger profile before the shell | |
4851 | starts, identical to the '--debugger' option. If set after | |
4852 | invocation, behavior intended for use by debuggers is enabled: | |
3185942a | 4853 | |
a0c0a00f CR |
4854 | 1. The '-F' option to the 'declare' builtin (*note Bash |
4855 | Builtins::) displays the source file name and line number | |
4856 | corresponding to each function name supplied as an | |
4857 | argument. | |
3185942a | 4858 | |
a0c0a00f CR |
4859 | 2. If the command run by the 'DEBUG' trap returns a non-zero |
4860 | value, the next command is skipped and not executed. | |
3185942a | 4861 | |
a0c0a00f CR |
4862 | 3. If the command run by the 'DEBUG' trap returns a value of |
4863 | 2, and the shell is executing in a subroutine (a shell | |
4864 | function or a shell script executed by the '.' or | |
4865 | 'source' builtins), the shell simulates a call to | |
4866 | 'return'. | |
3185942a | 4867 | |
a0c0a00f | 4868 | 4. 'BASH_ARGC' and 'BASH_ARGV' are updated as described in |
3185942a JA |
4869 | their descriptions (*note Bash Variables::). |
4870 | ||
a0c0a00f CR |
4871 | 5. Function tracing is enabled: command substitution, shell |
4872 | functions, and subshells invoked with '( COMMAND )' | |
4873 | inherit the 'DEBUG' and 'RETURN' traps. | |
3185942a | 4874 | |
a0c0a00f CR |
4875 | 6. Error tracing is enabled: command substitution, shell |
4876 | functions, and subshells invoked with '( COMMAND )' | |
4877 | inherit the 'ERR' trap. | |
3185942a | 4878 | |
a0c0a00f | 4879 | 'extglob' |
3185942a JA |
4880 | If set, the extended pattern matching features described above |
4881 | (*note Pattern Matching::) are enabled. | |
4882 | ||
a0c0a00f CR |
4883 | 'extquote' |
4884 | If set, '$'STRING'' and '$"STRING"' quoting is performed | |
4885 | within '${PARAMETER}' expansions enclosed in double quotes. | |
3185942a JA |
4886 | This option is enabled by default. |
4887 | ||
a0c0a00f CR |
4888 | 'failglob' |
4889 | If set, patterns which fail to match filenames during filename | |
4890 | expansion result in an expansion error. | |
3185942a | 4891 | |
a0c0a00f CR |
4892 | 'force_fignore' |
4893 | If set, the suffixes specified by the 'FIGNORE' shell variable | |
4894 | cause words to be ignored when performing word completion even | |
4895 | if the ignored words are the only possible completions. *Note | |
4896 | Bash Variables::, for a description of 'FIGNORE'. This option | |
4897 | is enabled by default. | |
3185942a | 4898 | |
a0c0a00f | 4899 | 'globasciiranges' |
ac50fbac CR |
4900 | If set, range expressions used in pattern matching bracket |
4901 | expressions (*note Pattern Matching::) behave as if in the | |
4902 | traditional C locale when performing comparisons. That is, | |
4903 | the current locale's collating sequence is not taken into | |
a0c0a00f | 4904 | account, so 'b' will not collate between 'A' and 'B', and |
ac50fbac CR |
4905 | upper-case and lower-case ASCII characters will collate |
4906 | together. | |
4907 | ||
74091dd4 CR |
4908 | 'globskipdots' |
4909 | If set, filename expansion will never match the filenames '.' | |
4910 | and '..', even if the pattern begins with a '.'. This option | |
4911 | is enabled by default. | |
4912 | ||
a0c0a00f CR |
4913 | 'globstar' |
4914 | If set, the pattern '**' used in a filename expansion context | |
ac50fbac | 4915 | will match all files and zero or more directories and |
a0c0a00f | 4916 | subdirectories. If the pattern is followed by a '/', only |
3185942a | 4917 | directories and subdirectories match. |
ccc6cda3 | 4918 | |
a0c0a00f | 4919 | 'gnu_errfmt' |
3185942a JA |
4920 | If set, shell error messages are written in the standard GNU |
4921 | error message format. | |
ccc6cda3 | 4922 | |
a0c0a00f | 4923 | 'histappend' |
3185942a | 4924 | If set, the history list is appended to the file named by the |
a0c0a00f | 4925 | value of the 'HISTFILE' variable when the shell exits, rather |
3185942a | 4926 | than overwriting the file. |
cce855bc | 4927 | |
a0c0a00f | 4928 | 'histreedit' |
3185942a JA |
4929 | If set, and Readline is being used, a user is given the |
4930 | opportunity to re-edit a failed history substitution. | |
ccc6cda3 | 4931 | |
a0c0a00f | 4932 | 'histverify' |
3185942a JA |
4933 | If set, and Readline is being used, the results of history |
4934 | substitution are not immediately passed to the shell parser. | |
4935 | Instead, the resulting line is loaded into the Readline | |
4936 | editing buffer, allowing further modification. | |
cce855bc | 4937 | |
a0c0a00f | 4938 | 'hostcomplete' |
3185942a | 4939 | If set, and Readline is being used, Bash will attempt to |
a0c0a00f | 4940 | perform hostname completion when a word containing a '@' is |
3185942a JA |
4941 | being completed (*note Commands For Completion::). This |
4942 | option is enabled by default. | |
ccc6cda3 | 4943 | |
a0c0a00f CR |
4944 | 'huponexit' |
4945 | If set, Bash will send 'SIGHUP' to all jobs when an | |
3185942a | 4946 | interactive login shell exits (*note Signals::). |
ccc6cda3 | 4947 | |
a0c0a00f CR |
4948 | 'inherit_errexit' |
4949 | If set, command substitution inherits the value of the | |
4950 | 'errexit' option, instead of unsetting it in the subshell | |
4951 | environment. This option is enabled when POSIX mode is | |
4952 | enabled. | |
4953 | ||
4954 | 'interactive_comments' | |
4955 | Allow a word beginning with '#' to cause that word and all | |
3185942a JA |
4956 | remaining characters on that line to be ignored in an |
4957 | interactive shell. This option is enabled by default. | |
ccc6cda3 | 4958 | |
a0c0a00f CR |
4959 | 'lastpipe' |
4960 | If set, and job control is not active, the shell runs the last | |
4961 | command of a pipeline not executed in the background in the | |
4962 | current shell environment. | |
495aee44 | 4963 | |
a0c0a00f CR |
4964 | 'lithist' |
4965 | If enabled, and the 'cmdhist' option is enabled, multi-line | |
3185942a JA |
4966 | commands are saved to the history with embedded newlines |
4967 | rather than using semicolon separators where possible. | |
ccc6cda3 | 4968 | |
d233b485 CR |
4969 | 'localvar_inherit' |
4970 | If set, local variables inherit the value and attributes of a | |
4971 | variable of the same name that exists at a previous scope | |
74091dd4 | 4972 | before any new value is assigned. The 'nameref' attribute is |
d233b485 CR |
4973 | not inherited. |
4974 | ||
4975 | 'localvar_unset' | |
4976 | If set, calling 'unset' on local variables in previous | |
4977 | function scopes marks them so subsequent lookups find them | |
4978 | unset until that function returns. This is identical to the | |
4979 | behavior of unsetting local variables at the current function | |
4980 | scope. | |
4981 | ||
a0c0a00f | 4982 | 'login_shell' |
3185942a JA |
4983 | The shell sets this option if it is started as a login shell |
4984 | (*note Invoking Bash::). The value may not be changed. | |
ccc6cda3 | 4985 | |
a0c0a00f | 4986 | 'mailwarn' |
3185942a | 4987 | If set, and a file that Bash is checking for mail has been |
a0c0a00f CR |
4988 | accessed since the last time it was checked, the message '"The |
4989 | mail in MAILFILE has been read"' is displayed. | |
ccc6cda3 | 4990 | |
a0c0a00f | 4991 | 'no_empty_cmd_completion' |
3185942a | 4992 | If set, and Readline is being used, Bash will not attempt to |
a0c0a00f | 4993 | search the 'PATH' for possible completions when completion is |
3185942a | 4994 | attempted on an empty line. |
ccc6cda3 | 4995 | |
a0c0a00f | 4996 | 'nocaseglob' |
3185942a JA |
4997 | If set, Bash matches filenames in a case-insensitive fashion |
4998 | when performing filename expansion. | |
b80f6443 | 4999 | |
a0c0a00f | 5000 | 'nocasematch' |
3185942a | 5001 | If set, Bash matches patterns in a case-insensitive fashion |
a0c0a00f | 5002 | when performing matching while executing 'case' or '[[' |
74091dd4 CR |
5003 | conditional commands (*note Conditional Constructs::, when |
5004 | performing pattern substitution word expansions, or when | |
5005 | filtering possible completions as part of programmable | |
5006 | completion. | |
5007 | ||
5008 | 'noexpand_translation' | |
5009 | If set, Bash encloses the translated results of $"..." | |
5010 | quoting in single quotes instead of double quotes. If the | |
5011 | string is not translated, this has no effect. | |
ccc6cda3 | 5012 | |
a0c0a00f | 5013 | 'nullglob' |
3185942a JA |
5014 | If set, Bash allows filename patterns which match no files to |
5015 | expand to a null string, rather than themselves. | |
ccc6cda3 | 5016 | |
74091dd4 CR |
5017 | 'patsub_replacement' |
5018 | If set, Bash expands occurrences of '&' in the replacement | |
5019 | string of pattern substitution to the text matched by the | |
5020 | pattern, as described above (*note Shell Parameter | |
5021 | Expansion::). This option is enabled by default. | |
5022 | ||
a0c0a00f | 5023 | 'progcomp' |
3185942a JA |
5024 | If set, the programmable completion facilities (*note |
5025 | Programmable Completion::) are enabled. This option is | |
5026 | enabled by default. | |
ccc6cda3 | 5027 | |
d233b485 CR |
5028 | 'progcomp_alias' |
5029 | If set, and programmable completion is enabled, Bash treats a | |
5030 | command name that doesn't have any completions as a possible | |
5031 | alias and attempts alias expansion. If it has an alias, Bash | |
5032 | attempts programmable completion using the command word | |
5033 | resulting from the expanded alias. | |
5034 | ||
a0c0a00f | 5035 | 'promptvars' |
3185942a JA |
5036 | If set, prompt strings undergo parameter expansion, command |
5037 | substitution, arithmetic expansion, and quote removal after | |
ac50fbac CR |
5038 | being expanded as described below (*note Controlling the |
5039 | Prompt::). This option is enabled by default. | |
ccc6cda3 | 5040 | |
a0c0a00f | 5041 | 'restricted_shell' |
3185942a JA |
5042 | The shell sets this option if it is started in restricted mode |
5043 | (*note The Restricted Shell::). The value may not be changed. | |
5044 | This is not reset when the startup files are executed, | |
5045 | allowing the startup files to discover whether or not a shell | |
5046 | is restricted. | |
b80f6443 | 5047 | |
a0c0a00f CR |
5048 | 'shift_verbose' |
5049 | If this is set, the 'shift' builtin prints an error message | |
3185942a JA |
5050 | when the shift count exceeds the number of positional |
5051 | parameters. | |
ccc6cda3 | 5052 | |
a0c0a00f | 5053 | 'sourcepath' |
74091dd4 CR |
5054 | If set, the '.' ('source') builtin uses the value of 'PATH' to |
5055 | find the directory containing the file supplied as an | |
5056 | argument. This option is enabled by default. | |
5057 | ||
5058 | 'varredir_close' | |
5059 | If set, the shell automatically closes file descriptors | |
5060 | assigned using the '{varname}' redirection syntax (*note | |
5061 | Redirections::) instead of leaving them open when the command | |
5062 | completes. | |
ccc6cda3 | 5063 | |
a0c0a00f CR |
5064 | 'xpg_echo' |
5065 | If set, the 'echo' builtin expands backslash-escape sequences | |
3185942a | 5066 | by default. |
cce855bc | 5067 | |
bb70624e | 5068 | \1f |
3185942a | 5069 | File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands |
ccc6cda3 | 5070 | |
b80f6443 JA |
5071 | 4.4 Special Builtins |
5072 | ==================== | |
ccc6cda3 | 5073 | |
0628567a JA |
5074 | For historical reasons, the POSIX standard has classified several |
5075 | builtin commands as _special_. When Bash is executing in POSIX mode, | |
5076 | the special builtins differ from other builtin commands in three | |
bb70624e | 5077 | respects: |
ccc6cda3 | 5078 | |
bb70624e JA |
5079 | 1. Special builtins are found before shell functions during command |
5080 | lookup. | |
ccc6cda3 | 5081 | |
bb70624e JA |
5082 | 2. If a special builtin returns an error status, a non-interactive |
5083 | shell exits. | |
ccc6cda3 | 5084 | |
bb70624e JA |
5085 | 3. Assignment statements preceding the command stay in effect in the |
5086 | shell environment after the command completes. | |
ccc6cda3 | 5087 | |
bb70624e JA |
5088 | When Bash is not executing in POSIX mode, these builtins behave no |
5089 | differently than the rest of the Bash builtin commands. The Bash POSIX | |
3185942a | 5090 | mode is described in *note Bash POSIX Mode::. |
ccc6cda3 | 5091 | |
bb70624e JA |
5092 | These are the POSIX special builtins: |
5093 | break : . continue eval exec exit export readonly return set | |
5094 | shift trap unset | |
ccc6cda3 | 5095 | |
bb70624e JA |
5096 | \1f |
5097 | File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top | |
cce855bc | 5098 | |
b80f6443 JA |
5099 | 5 Shell Variables |
5100 | ***************** | |
ccc6cda3 | 5101 | |
bb70624e | 5102 | * Menu: |
ccc6cda3 | 5103 | |
bb70624e JA |
5104 | * Bourne Shell Variables:: Variables which Bash uses in the same way |
5105 | as the Bourne Shell. | |
5106 | * Bash Variables:: List of variables that exist in Bash. | |
ccc6cda3 | 5107 | |
a0c0a00f | 5108 | This chapter describes the shell variables that Bash uses. Bash |
bb70624e | 5109 | automatically assigns default values to a number of variables. |
cce855bc | 5110 | |
bb70624e JA |
5111 | \1f |
5112 | File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables | |
ccc6cda3 | 5113 | |
b80f6443 JA |
5114 | 5.1 Bourne Shell Variables |
5115 | ========================== | |
cce855bc | 5116 | |
b80f6443 JA |
5117 | Bash uses certain shell variables in the same way as the Bourne shell. |
5118 | In some cases, Bash assigns a default value to the variable. | |
cce855bc | 5119 | |
a0c0a00f CR |
5120 | 'CDPATH' |
5121 | A colon-separated list of directories used as a search path for the | |
5122 | 'cd' builtin command. | |
ccc6cda3 | 5123 | |
a0c0a00f CR |
5124 | 'HOME' |
5125 | The current user's home directory; the default for the 'cd' builtin | |
bb70624e | 5126 | command. The value of this variable is also used by tilde |
28ef6c31 | 5127 | expansion (*note Tilde Expansion::). |
ccc6cda3 | 5128 | |
a0c0a00f | 5129 | 'IFS' |
bb70624e JA |
5130 | A list of characters that separate fields; used when the shell |
5131 | splits words as part of expansion. | |
ccc6cda3 | 5132 | |
a0c0a00f | 5133 | 'MAIL' |
495aee44 | 5134 | If this parameter is set to a filename or directory name and the |
a0c0a00f | 5135 | 'MAILPATH' variable is not set, Bash informs the user of the |
495aee44 | 5136 | arrival of mail in the specified file or Maildir-format directory. |
cce855bc | 5137 | |
a0c0a00f | 5138 | 'MAILPATH' |
bb70624e JA |
5139 | A colon-separated list of filenames which the shell periodically |
5140 | checks for new mail. Each list entry can specify the message that | |
a0c0a00f CR |
5141 | is printed when new mail arrives in the mail file by separating the |
5142 | filename from the message with a '?'. When used in the text of the | |
5143 | message, '$_' expands to the name of the current mail file. | |
cce855bc | 5144 | |
a0c0a00f CR |
5145 | 'OPTARG' |
5146 | The value of the last option argument processed by the 'getopts' | |
bb70624e | 5147 | builtin. |
ccc6cda3 | 5148 | |
a0c0a00f CR |
5149 | 'OPTIND' |
5150 | The index of the last option argument processed by the 'getopts' | |
bb70624e | 5151 | builtin. |
ccc6cda3 | 5152 | |
a0c0a00f | 5153 | 'PATH' |
bb70624e | 5154 | A colon-separated list of directories in which the shell looks for |
b80f6443 | 5155 | commands. A zero-length (null) directory name in the value of |
a0c0a00f | 5156 | 'PATH' indicates the current directory. A null directory name may |
b80f6443 | 5157 | appear as two adjacent colons, or as an initial or trailing colon. |
ccc6cda3 | 5158 | |
a0c0a00f CR |
5159 | 'PS1' |
5160 | The primary prompt string. The default value is '\s-\v\$ '. *Note | |
5161 | Controlling the Prompt::, for the complete list of escape sequences | |
5162 | that are expanded before 'PS1' is displayed. | |
ccc6cda3 | 5163 | |
a0c0a00f | 5164 | 'PS2' |
d233b485 CR |
5165 | The secondary prompt string. The default value is '> '. 'PS2' is |
5166 | expanded in the same way as 'PS1' before being displayed. | |
b80f6443 | 5167 | |
bb70624e JA |
5168 | \1f |
5169 | File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables | |
ccc6cda3 | 5170 | |
b80f6443 JA |
5171 | 5.2 Bash Variables |
5172 | ================== | |
ccc6cda3 | 5173 | |
b80f6443 | 5174 | These variables are set or used by Bash, but other shells do not |
bb70624e | 5175 | normally treat them specially. |
ccc6cda3 | 5176 | |
bb70624e JA |
5177 | A few variables used by Bash are described in different chapters: |
5178 | variables for controlling the job control facilities (*note Job Control | |
28ef6c31 | 5179 | Variables::). |
ccc6cda3 | 5180 | |
8868edaf CR |
5181 | '_' |
5182 | ($_, an underscore.) At shell startup, set to the pathname used to | |
5183 | invoke the shell or shell script being executed as passed in the | |
5184 | environment or argument list. Subsequently, expands to the last | |
5185 | argument to the previous simple command executed in the foreground, | |
5186 | after expansion. Also set to the full pathname used to invoke each | |
5187 | command executed and placed in the environment exported to that | |
5188 | command. When checking mail, this parameter holds the name of the | |
5189 | mail file. | |
5190 | ||
a0c0a00f | 5191 | 'BASH' |
bb70624e | 5192 | The full pathname used to execute the current instance of Bash. |
ccc6cda3 | 5193 | |
a0c0a00f | 5194 | 'BASHOPTS' |
0001803f | 5195 | A colon-separated list of enabled shell options. Each word in the |
a0c0a00f CR |
5196 | list is a valid argument for the '-s' option to the 'shopt' builtin |
5197 | command (*note The Shopt Builtin::). The options appearing in | |
5198 | 'BASHOPTS' are those reported as 'on' by 'shopt'. If this variable | |
5199 | is in the environment when Bash starts up, each shell option in the | |
5200 | list will be enabled before reading any startup files. This | |
5201 | variable is readonly. | |
5202 | ||
5203 | 'BASHPID' | |
495aee44 | 5204 | Expands to the process ID of the current Bash process. This |
a0c0a00f | 5205 | differs from '$$' under certain circumstances, such as subshells |
d233b485 CR |
5206 | that do not require Bash to be re-initialized. Assignments to |
5207 | 'BASHPID' have no effect. If 'BASHPID' is unset, it loses its | |
5208 | special properties, even if it is subsequently reset. | |
3185942a | 5209 | |
a0c0a00f | 5210 | 'BASH_ALIASES' |
3185942a | 5211 | An associative array variable whose members correspond to the |
a0c0a00f | 5212 | internal list of aliases as maintained by the 'alias' builtin. |
3185942a | 5213 | (*note Bourne Shell Builtins::). Elements added to this array |
a0c0a00f CR |
5214 | appear in the alias list; however, unsetting array elements |
5215 | currently does not cause aliases to be removed from the alias list. | |
5216 | If 'BASH_ALIASES' is unset, it loses its special properties, even | |
5217 | if it is subsequently reset. | |
3185942a | 5218 | |
a0c0a00f | 5219 | 'BASH_ARGC' |
b80f6443 JA |
5220 | An array variable whose values are the number of parameters in each |
5221 | frame of the current bash execution call stack. The number of | |
5222 | parameters to the current subroutine (shell function or script | |
a0c0a00f | 5223 | executed with '.' or 'source') is at the top of the stack. When a |
b80f6443 | 5224 | subroutine is executed, the number of parameters passed is pushed |
a0c0a00f CR |
5225 | onto 'BASH_ARGC'. The shell sets 'BASH_ARGC' only when in extended |
5226 | debugging mode (see *note The Shopt Builtin:: for a description of | |
d233b485 CR |
5227 | the 'extdebug' option to the 'shopt' builtin). Setting 'extdebug' |
5228 | after the shell has started to execute a script, or referencing | |
5229 | this variable when 'extdebug' is not set, may result in | |
5230 | inconsistent values. | |
b80f6443 | 5231 | |
a0c0a00f | 5232 | 'BASH_ARGV' |
b80f6443 JA |
5233 | An array variable containing all of the parameters in the current |
5234 | bash execution call stack. The final parameter of the last | |
5235 | subroutine call is at the top of the stack; the first parameter of | |
5236 | the initial call is at the bottom. When a subroutine is executed, | |
a0c0a00f CR |
5237 | the parameters supplied are pushed onto 'BASH_ARGV'. The shell |
5238 | sets 'BASH_ARGV' only when in extended debugging mode (see *note | |
5239 | The Shopt Builtin:: for a description of the 'extdebug' option to | |
d233b485 CR |
5240 | the 'shopt' builtin). Setting 'extdebug' after the shell has |
5241 | started to execute a script, or referencing this variable when | |
5242 | 'extdebug' is not set, may result in inconsistent values. | |
5243 | ||
5244 | 'BASH_ARGV0' | |
5245 | When referenced, this variable expands to the name of the shell or | |
5246 | shell script (identical to '$0'; *Note Special Parameters::, for | |
5247 | the description of special parameter 0). Assignment to | |
5248 | 'BASH_ARGV0' causes the value assigned to also be assigned to '$0'. | |
5249 | If 'BASH_ARGV0' is unset, it loses its special properties, even if | |
5250 | it is subsequently reset. | |
3185942a | 5251 | |
a0c0a00f | 5252 | 'BASH_CMDS' |
3185942a | 5253 | An associative array variable whose members correspond to the |
a0c0a00f | 5254 | internal hash table of commands as maintained by the 'hash' builtin |
3185942a | 5255 | (*note Bourne Shell Builtins::). Elements added to this array |
a0c0a00f CR |
5256 | appear in the hash table; however, unsetting array elements |
5257 | currently does not cause command names to be removed from the hash | |
5258 | table. If 'BASH_CMDS' is unset, it loses its special properties, | |
5259 | even if it is subsequently reset. | |
b80f6443 | 5260 | |
a0c0a00f | 5261 | 'BASH_COMMAND' |
b80f6443 | 5262 | The command currently being executed or about to be executed, |
a0c0a00f | 5263 | unless the shell is executing a command as the result of a trap, in |
8868edaf CR |
5264 | which case it is the command executing at the time of the trap. If |
5265 | 'BASH_COMMAND' is unset, it loses its special properties, even if | |
5266 | it is subsequently reset. | |
b80f6443 | 5267 | |
a0c0a00f | 5268 | 'BASH_COMPAT' |
ac50fbac | 5269 | The value is used to set the shell's compatibility level. *Note |
8868edaf CR |
5270 | Shell Compatibility Mode::, for a description of the various |
5271 | compatibility levels and their effects. The value may be a decimal | |
5272 | number (e.g., 4.2) or an integer (e.g., 42) corresponding to the | |
5273 | desired compatibility level. If 'BASH_COMPAT' is unset or set to | |
5274 | the empty string, the compatibility level is set to the default for | |
5275 | the current version. If 'BASH_COMPAT' is set to a value that is | |
5276 | not one of the valid compatibility levels, the shell prints an | |
5277 | error message and sets the compatibility level to the default for | |
5278 | the current version. The valid values correspond to the | |
5279 | compatibility levels described below (*note Shell Compatibility | |
5280 | Mode::). For example, 4.2 and 42 are valid values that correspond | |
5281 | to the 'compat42' 'shopt' option and set the compatibility level to | |
5282 | 42. The current version is also a valid value. | |
a0c0a00f CR |
5283 | |
5284 | 'BASH_ENV' | |
bb70624e JA |
5285 | If this variable is set when Bash is invoked to execute a shell |
5286 | script, its value is expanded and used as the name of a startup | |
5287 | file to read before executing the script. *Note Bash Startup | |
5288 | Files::. | |
ccc6cda3 | 5289 | |
a0c0a00f CR |
5290 | 'BASH_EXECUTION_STRING' |
5291 | The command argument to the '-c' invocation option. | |
b80f6443 | 5292 | |
a0c0a00f | 5293 | 'BASH_LINENO' |
b80f6443 | 5294 | An array variable whose members are the line numbers in source |
74091dd4 | 5295 | files where each corresponding member of 'FUNCNAME' was invoked. |
a0c0a00f CR |
5296 | '${BASH_LINENO[$i]}' is the line number in the source file |
5297 | ('${BASH_SOURCE[$i+1]}') where '${FUNCNAME[$i]}' was called (or | |
5298 | '${BASH_LINENO[$i-1]}' if referenced within another shell | |
5299 | function). Use 'LINENO' to obtain the current line number. | |
5300 | ||
5301 | 'BASH_LOADABLES_PATH' | |
5302 | A colon-separated list of directories in which the shell looks for | |
5303 | dynamically loadable builtins specified by the 'enable' command. | |
5304 | ||
5305 | 'BASH_REMATCH' | |
5306 | An array variable whose members are assigned by the '=~' binary | |
5307 | operator to the '[[' conditional command (*note Conditional | |
b80f6443 JA |
5308 | Constructs::). The element with index 0 is the portion of the |
5309 | string matching the entire regular expression. The element with | |
a0c0a00f | 5310 | index N is the portion of the string matching the Nth parenthesized |
8868edaf | 5311 | subexpression. |
b80f6443 | 5312 | |
a0c0a00f | 5313 | 'BASH_SOURCE' |
495aee44 | 5314 | An array variable whose members are the source filenames where the |
a0c0a00f CR |
5315 | corresponding shell function names in the 'FUNCNAME' array variable |
5316 | are defined. The shell function '${FUNCNAME[$i]}' is defined in | |
5317 | the file '${BASH_SOURCE[$i]}' and called from | |
5318 | '${BASH_SOURCE[$i+1]}' | |
b80f6443 | 5319 | |
a0c0a00f | 5320 | 'BASH_SUBSHELL' |
ac50fbac CR |
5321 | Incremented by one within each subshell or subshell environment |
5322 | when the shell begins executing in that environment. The initial | |
8868edaf CR |
5323 | value is 0. If 'BASH_SUBSHELL' is unset, it loses its special |
5324 | properties, even if it is subsequently reset. | |
ccc6cda3 | 5325 | |
a0c0a00f | 5326 | 'BASH_VERSINFO' |
28ef6c31 | 5327 | A readonly array variable (*note Arrays::) whose members hold |
a0c0a00f CR |
5328 | version information for this instance of Bash. The values assigned |
5329 | to the array members are as follows: | |
ccc6cda3 | 5330 | |
a0c0a00f | 5331 | 'BASH_VERSINFO[0]' |
74091dd4 | 5332 | The major version number (the "release"). |
ccc6cda3 | 5333 | |
a0c0a00f | 5334 | 'BASH_VERSINFO[1]' |
74091dd4 | 5335 | The minor version number (the "version"). |
ccc6cda3 | 5336 | |
a0c0a00f | 5337 | 'BASH_VERSINFO[2]' |
bb70624e | 5338 | The patch level. |
ccc6cda3 | 5339 | |
a0c0a00f | 5340 | 'BASH_VERSINFO[3]' |
bb70624e | 5341 | The build version. |
ccc6cda3 | 5342 | |
a0c0a00f | 5343 | 'BASH_VERSINFO[4]' |
74091dd4 | 5344 | The release status (e.g., 'beta1'). |
ccc6cda3 | 5345 | |
a0c0a00f CR |
5346 | 'BASH_VERSINFO[5]' |
5347 | The value of 'MACHTYPE'. | |
ccc6cda3 | 5348 | |
a0c0a00f | 5349 | 'BASH_VERSION' |
b80f6443 JA |
5350 | The version number of the current instance of Bash. |
5351 | ||
a0c0a00f | 5352 | 'BASH_XTRACEFD' |
0001803f | 5353 | If set to an integer corresponding to a valid file descriptor, Bash |
a0c0a00f | 5354 | will write the trace output generated when 'set -x' is enabled to |
0001803f CR |
5355 | that file descriptor. This allows tracing output to be separated |
5356 | from diagnostic and error messages. The file descriptor is closed | |
a0c0a00f CR |
5357 | when 'BASH_XTRACEFD' is unset or assigned a new value. Unsetting |
5358 | 'BASH_XTRACEFD' or assigning it the empty string causes the trace | |
0001803f | 5359 | output to be sent to the standard error. Note that setting |
a0c0a00f | 5360 | 'BASH_XTRACEFD' to 2 (the standard error file descriptor) and then |
0001803f CR |
5361 | unsetting it will result in the standard error being closed. |
5362 | ||
a0c0a00f | 5363 | 'CHILD_MAX' |
ac50fbac CR |
5364 | Set the number of exited child status values for the shell to |
5365 | remember. Bash will not allow this value to be decreased below a | |
5366 | POSIX-mandated minimum, and there is a maximum value (currently | |
5367 | 8192) that this may not exceed. The minimum value is | |
5368 | system-dependent. | |
5369 | ||
a0c0a00f CR |
5370 | 'COLUMNS' |
5371 | Used by the 'select' command to determine the terminal width when | |
5372 | printing selection lists. Automatically set if the 'checkwinsize' | |
5373 | option is enabled (*note The Shopt Builtin::), or in an interactive | |
5374 | shell upon receipt of a 'SIGWINCH'. | |
bb70624e | 5375 | |
a0c0a00f CR |
5376 | 'COMP_CWORD' |
5377 | An index into '${COMP_WORDS}' of the word containing the current | |
bb70624e JA |
5378 | cursor position. This variable is available only in shell |
5379 | functions invoked by the programmable completion facilities (*note | |
28ef6c31 | 5380 | Programmable Completion::). |
bb70624e | 5381 | |
a0c0a00f CR |
5382 | 'COMP_LINE' |
5383 | The current command line. This variable is available only in shell | |
5384 | functions and external commands invoked by the programmable | |
28ef6c31 | 5385 | completion facilities (*note Programmable Completion::). |
bb70624e | 5386 | |
a0c0a00f | 5387 | 'COMP_POINT' |
bb70624e JA |
5388 | The index of the current cursor position relative to the beginning |
5389 | of the current command. If the current cursor position is at the | |
5390 | end of the current command, the value of this variable is equal to | |
a0c0a00f | 5391 | '${#COMP_LINE}'. This variable is available only in shell |
bb70624e | 5392 | functions and external commands invoked by the programmable |
28ef6c31 | 5393 | completion facilities (*note Programmable Completion::). |
bb70624e | 5394 | |
a0c0a00f | 5395 | 'COMP_TYPE' |
3185942a | 5396 | Set to an integer value corresponding to the type of completion |
74091dd4 CR |
5397 | attempted that caused a completion function to be called: <TAB>, |
5398 | for normal completion, '?', for listing completions after | |
5399 | successive tabs, '!', for listing alternatives on partial word | |
5400 | completion, '@', to list completions if the word is not unmodified, | |
5401 | or '%', for menu completion. This variable is available only in | |
5402 | shell functions and external commands invoked by the programmable | |
3185942a JA |
5403 | completion facilities (*note Programmable Completion::). |
5404 | ||
a0c0a00f | 5405 | 'COMP_KEY' |
3185942a JA |
5406 | The key (or final key of a key sequence) used to invoke the current |
5407 | completion function. | |
5408 | ||
a0c0a00f | 5409 | 'COMP_WORDBREAKS' |
b80f6443 | 5410 | The set of characters that the Readline library treats as word |
a0c0a00f | 5411 | separators when performing word completion. If 'COMP_WORDBREAKS' |
b80f6443 JA |
5412 | is unset, it loses its special properties, even if it is |
5413 | subsequently reset. | |
5414 | ||
a0c0a00f CR |
5415 | 'COMP_WORDS' |
5416 | An array variable consisting of the individual words in the current | |
5417 | command line. The line is split into words as Readline would split | |
5418 | it, using 'COMP_WORDBREAKS' as described above. This variable is | |
5419 | available only in shell functions invoked by the programmable | |
5420 | completion facilities (*note Programmable Completion::). | |
f73dda09 | 5421 | |
a0c0a00f | 5422 | 'COMPREPLY' |
bb70624e JA |
5423 | An array variable from which Bash reads the possible completions |
5424 | generated by a shell function invoked by the programmable | |
ac50fbac CR |
5425 | completion facility (*note Programmable Completion::). Each array |
5426 | element contains one possible completion. | |
ccc6cda3 | 5427 | |
a0c0a00f | 5428 | 'COPROC' |
495aee44 CR |
5429 | An array variable created to hold the file descriptors for output |
5430 | from and input to an unnamed coprocess (*note Coprocesses::). | |
5431 | ||
a0c0a00f | 5432 | 'DIRSTACK' |
bb70624e JA |
5433 | An array variable containing the current contents of the directory |
5434 | stack. Directories appear in the stack in the order they are | |
a0c0a00f | 5435 | displayed by the 'dirs' builtin. Assigning to members of this |
bb70624e | 5436 | array variable may be used to modify directories already in the |
a0c0a00f | 5437 | stack, but the 'pushd' and 'popd' builtins must be used to add and |
bb70624e | 5438 | remove directories. Assignment to this variable will not change |
a0c0a00f | 5439 | the current directory. If 'DIRSTACK' is unset, it loses its |
bb70624e | 5440 | special properties, even if it is subsequently reset. |
cce855bc | 5441 | |
a0c0a00f | 5442 | 'EMACS' |
b80f6443 | 5443 | If Bash finds this variable in the environment when the shell |
a0c0a00f | 5444 | starts with value 't', it assumes that the shell is running in an |
495aee44 CR |
5445 | Emacs shell buffer and disables line editing. |
5446 | ||
a0c0a00f | 5447 | 'ENV' |
74091dd4 | 5448 | Expanded and executed similarly to 'BASH_ENV' (*note Bash Startup |
8868edaf CR |
5449 | Files::) when an interactive shell is invoked in POSIX Mode (*note |
5450 | Bash POSIX Mode::). | |
b80f6443 | 5451 | |
d233b485 CR |
5452 | 'EPOCHREALTIME' |
5453 | Each time this parameter is referenced, it expands to the number of | |
5454 | seconds since the Unix Epoch as a floating point value with | |
5455 | micro-second granularity (see the documentation for the C library | |
74091dd4 | 5456 | function 'time' for the definition of Epoch). Assignments to |
d233b485 CR |
5457 | 'EPOCHREALTIME' are ignored. If 'EPOCHREALTIME' is unset, it loses |
5458 | its special properties, even if it is subsequently reset. | |
5459 | ||
5460 | 'EPOCHSECONDS' | |
5461 | Each time this parameter is referenced, it expands to the number of | |
5462 | seconds since the Unix Epoch (see the documentation for the C | |
74091dd4 CR |
5463 | library function 'time' for the definition of Epoch). Assignments |
5464 | to 'EPOCHSECONDS' are ignored. If 'EPOCHSECONDS' is unset, it | |
5465 | loses its special properties, even if it is subsequently reset. | |
d233b485 | 5466 | |
a0c0a00f | 5467 | 'EUID' |
bb70624e JA |
5468 | The numeric effective user id of the current user. This variable |
5469 | is readonly. | |
cce855bc | 5470 | |
a0c0a00f CR |
5471 | 'EXECIGNORE' |
5472 | A colon-separated list of shell patterns (*note Pattern Matching::) | |
5473 | defining the list of filenames to be ignored by command search | |
5474 | using 'PATH'. Files whose full pathnames match one of these | |
5475 | patterns are not considered executable files for the purposes of | |
5476 | completion and command execution via 'PATH' lookup. This does not | |
5477 | affect the behavior of the '[', 'test', and '[[' commands. Full | |
5478 | pathnames in the command hash table are not subject to | |
5479 | 'EXECIGNORE'. Use this variable to ignore shared library files | |
5480 | that have the executable bit set, but are not executable files. | |
5481 | The pattern matching honors the setting of the 'extglob' shell | |
5482 | option. | |
5483 | ||
5484 | 'FCEDIT' | |
5485 | The editor used as a default by the '-e' option to the 'fc' builtin | |
5486 | command. | |
ccc6cda3 | 5487 | |
a0c0a00f | 5488 | 'FIGNORE' |
bb70624e | 5489 | A colon-separated list of suffixes to ignore when performing |
ac50fbac | 5490 | filename completion. A filename whose suffix matches one of the |
a0c0a00f CR |
5491 | entries in 'FIGNORE' is excluded from the list of matched |
5492 | filenames. A sample value is '.o:~' | |
ccc6cda3 | 5493 | |
a0c0a00f | 5494 | 'FUNCNAME' |
b80f6443 | 5495 | An array variable containing the names of all shell functions |
a0c0a00f CR |
5496 | currently in the execution call stack. The element with index 0 is |
5497 | the name of any currently-executing shell function. The | |
5498 | bottom-most element (the one with the highest index) is '"main"'. | |
495aee44 | 5499 | This variable exists only when a shell function is executing. |
a0c0a00f CR |
5500 | Assignments to 'FUNCNAME' have no effect. If 'FUNCNAME' is unset, |
5501 | it loses its special properties, even if it is subsequently reset. | |
5502 | ||
5503 | This variable can be used with 'BASH_LINENO' and 'BASH_SOURCE'. | |
5504 | Each element of 'FUNCNAME' has corresponding elements in | |
5505 | 'BASH_LINENO' and 'BASH_SOURCE' to describe the call stack. For | |
5506 | instance, '${FUNCNAME[$i]}' was called from the file | |
5507 | '${BASH_SOURCE[$i+1]}' at line number '${BASH_LINENO[$i]}'. The | |
5508 | 'caller' builtin displays the current call stack using this | |
495aee44 CR |
5509 | information. |
5510 | ||
a0c0a00f | 5511 | 'FUNCNEST' |
495aee44 CR |
5512 | If set to a numeric value greater than 0, defines a maximum |
5513 | function nesting level. Function invocations that exceed this | |
5514 | nesting level will cause the current command to abort. | |
f73dda09 | 5515 | |
a0c0a00f | 5516 | 'GLOBIGNORE' |
d233b485 CR |
5517 | A colon-separated list of patterns defining the set of file names |
5518 | to be ignored by filename expansion. If a file name matched by a | |
bb70624e | 5519 | filename expansion pattern also matches one of the patterns in |
a0c0a00f CR |
5520 | 'GLOBIGNORE', it is removed from the list of matches. The pattern |
5521 | matching honors the setting of the 'extglob' shell option. | |
ccc6cda3 | 5522 | |
a0c0a00f | 5523 | 'GROUPS' |
bb70624e | 5524 | An array variable containing the list of groups of which the |
a0c0a00f CR |
5525 | current user is a member. Assignments to 'GROUPS' have no effect. |
5526 | If 'GROUPS' is unset, it loses its special properties, even if it | |
5527 | is subsequently reset. | |
ccc6cda3 | 5528 | |
a0c0a00f | 5529 | 'histchars' |
bb70624e | 5530 | Up to three characters which control history expansion, quick |
28ef6c31 | 5531 | substitution, and tokenization (*note History Interaction::). The |
74091dd4 | 5532 | first character is the "history expansion" character, that is, the |
28ef6c31 | 5533 | character which signifies the start of a history expansion, |
a0c0a00f CR |
5534 | normally '!'. The second character is the character which |
5535 | signifies 'quick substitution' when seen as the first character on | |
5536 | a line, normally '^'. The optional third character is the | |
bb70624e | 5537 | character which indicates that the remainder of the line is a |
a0c0a00f | 5538 | comment when found as the first character of a word, usually '#'. |
bb70624e JA |
5539 | The history comment character causes history substitution to be |
5540 | skipped for the remaining words on the line. It does not | |
a0c0a00f CR |
5541 | necessarily cause the shell parser to treat the rest of the line as |
5542 | a comment. | |
cce855bc | 5543 | |
a0c0a00f | 5544 | 'HISTCMD' |
bb70624e | 5545 | The history number, or index in the history list, of the current |
8868edaf CR |
5546 | command. Assignments to 'HISTCMD' are ignored. If 'HISTCMD' is |
5547 | unset, it loses its special properties, even if it is subsequently | |
5548 | reset. | |
ccc6cda3 | 5549 | |
a0c0a00f CR |
5550 | 'HISTCONTROL' |
5551 | A colon-separated list of values controlling how commands are saved | |
5552 | on the history list. If the list of values includes 'ignorespace', | |
5553 | lines which begin with a space character are not saved in the | |
5554 | history list. A value of 'ignoredups' causes lines which match the | |
5555 | previous history entry to not be saved. A value of 'ignoreboth' is | |
5556 | shorthand for 'ignorespace' and 'ignoredups'. A value of | |
5557 | 'erasedups' causes all previous lines matching the current line to | |
5558 | be removed from the history list before that line is saved. Any | |
5559 | value not in the above list is ignored. If 'HISTCONTROL' is unset, | |
5560 | or does not include a valid value, all lines read by the shell | |
5561 | parser are saved on the history list, subject to the value of | |
5562 | 'HISTIGNORE'. The second and subsequent lines of a multi-line | |
5563 | compound command are not tested, and are added to the history | |
5564 | regardless of the value of 'HISTCONTROL'. | |
5565 | ||
5566 | 'HISTFILE' | |
f73dda09 | 5567 | The name of the file to which the command history is saved. The |
a0c0a00f | 5568 | default value is '~/.bash_history'. |
f73dda09 | 5569 | |
a0c0a00f | 5570 | 'HISTFILESIZE' |
f73dda09 JA |
5571 | The maximum number of lines contained in the history file. When |
5572 | this variable is assigned a value, the history file is truncated, | |
ac50fbac | 5573 | if necessary, to contain no more than that number of lines by |
a0c0a00f CR |
5574 | removing the oldest entries. The history file is also truncated to |
5575 | this size after writing it when a shell exits. If the value is 0, | |
5576 | the history file is truncated to zero size. Non-numeric values and | |
5577 | numeric values less than zero inhibit truncation. The shell sets | |
5578 | the default value to the value of 'HISTSIZE' after reading any | |
5579 | startup files. | |
5580 | ||
5581 | 'HISTIGNORE' | |
bb70624e JA |
5582 | A colon-separated list of patterns used to decide which command |
5583 | lines should be saved on the history list. Each pattern is | |
5584 | anchored at the beginning of the line and must match the complete | |
a0c0a00f CR |
5585 | line (no implicit '*' is appended). Each pattern is tested against |
5586 | the line after the checks specified by 'HISTCONTROL' are applied. | |
5587 | In addition to the normal shell pattern matching characters, '&' | |
5588 | matches the previous history line. '&' may be escaped using a | |
5589 | backslash; the backslash is removed before attempting a match. The | |
5590 | second and subsequent lines of a multi-line compound command are | |
5591 | not tested, and are added to the history regardless of the value of | |
5592 | 'HISTIGNORE'. The pattern matching honors the setting of the | |
5593 | 'extglob' shell option. | |
5594 | ||
5595 | 'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of | |
5596 | '&' is identical to 'ignoredups', and a pattern of '[ ]*' is | |
5597 | identical to 'ignorespace'. Combining these two patterns, | |
bb70624e | 5598 | separating them with a colon, provides the functionality of |
a0c0a00f | 5599 | 'ignoreboth'. |
ccc6cda3 | 5600 | |
a0c0a00f CR |
5601 | 'HISTSIZE' |
5602 | The maximum number of commands to remember on the history list. If | |
5603 | the value is 0, commands are not saved in the history list. | |
ac50fbac CR |
5604 | Numeric values less than zero result in every command being saved |
5605 | on the history list (there is no limit). The shell sets the | |
5606 | default value to 500 after reading any startup files. | |
b72432fd | 5607 | |
a0c0a00f CR |
5608 | 'HISTTIMEFORMAT' |
5609 | If this variable is set and not null, its value is used as a format | |
74091dd4 | 5610 | string for 'strftime' to print the time stamp associated with each |
a0c0a00f CR |
5611 | history entry displayed by the 'history' builtin. If this variable |
5612 | is set, time stamps are written to the history file so they may be | |
5613 | preserved across shell sessions. This uses the history comment | |
5614 | character to distinguish timestamps from other history lines. | |
5615 | ||
5616 | 'HOSTFILE' | |
5617 | Contains the name of a file in the same format as '/etc/hosts' that | |
bb70624e JA |
5618 | should be read when the shell needs to complete a hostname. The |
5619 | list of possible hostname completions may be changed while the | |
5620 | shell is running; the next time hostname completion is attempted | |
5621 | after the value is changed, Bash adds the contents of the new file | |
a0c0a00f CR |
5622 | to the existing list. If 'HOSTFILE' is set, but has no value, or |
5623 | does not name a readable file, Bash attempts to read '/etc/hosts' | |
0001803f | 5624 | to obtain the list of possible hostname completions. When |
a0c0a00f | 5625 | 'HOSTFILE' is unset, the hostname list is cleared. |
cce855bc | 5626 | |
a0c0a00f | 5627 | 'HOSTNAME' |
bb70624e | 5628 | The name of the current host. |
cce855bc | 5629 | |
a0c0a00f | 5630 | 'HOSTTYPE' |
bb70624e | 5631 | A string describing the machine Bash is running on. |
ccc6cda3 | 5632 | |
a0c0a00f CR |
5633 | 'IGNOREEOF' |
5634 | Controls the action of the shell on receipt of an 'EOF' character | |
bb70624e | 5635 | as the sole input. If set, the value denotes the number of |
a0c0a00f | 5636 | consecutive 'EOF' characters that can be read as the first |
bb70624e | 5637 | character on an input line before the shell will exit. If the |
d233b485 | 5638 | variable exists but does not have a numeric value, or has no value, |
a0c0a00f CR |
5639 | then the default is 10. If the variable does not exist, then 'EOF' |
5640 | signifies the end of input to the shell. This is only in effect | |
5641 | for interactive shells. | |
ccc6cda3 | 5642 | |
a0c0a00f | 5643 | 'INPUTRC' |
bb70624e | 5644 | The name of the Readline initialization file, overriding the |
a0c0a00f | 5645 | default of '~/.inputrc'. |
ccc6cda3 | 5646 | |
d233b485 CR |
5647 | 'INSIDE_EMACS' |
5648 | If Bash finds this variable in the environment when the shell | |
5649 | starts, it assumes that the shell is running in an Emacs shell | |
5650 | buffer and may disable line editing depending on the value of | |
5651 | 'TERM'. | |
5652 | ||
a0c0a00f | 5653 | 'LANG' |
bb70624e | 5654 | Used to determine the locale category for any category not |
a0c0a00f | 5655 | specifically selected with a variable starting with 'LC_'. |
ccc6cda3 | 5656 | |
a0c0a00f CR |
5657 | 'LC_ALL' |
5658 | This variable overrides the value of 'LANG' and any other 'LC_' | |
bb70624e | 5659 | variable specifying a locale category. |
cce855bc | 5660 | |
a0c0a00f | 5661 | 'LC_COLLATE' |
bb70624e | 5662 | This variable determines the collation order used when sorting the |
a0c0a00f CR |
5663 | results of filename expansion, and determines the behavior of range |
5664 | expressions, equivalence classes, and collating sequences within | |
5665 | filename expansion and pattern matching (*note Filename | |
28ef6c31 | 5666 | Expansion::). |
ccc6cda3 | 5667 | |
a0c0a00f | 5668 | 'LC_CTYPE' |
bb70624e JA |
5669 | This variable determines the interpretation of characters and the |
5670 | behavior of character classes within filename expansion and pattern | |
28ef6c31 | 5671 | matching (*note Filename Expansion::). |
ccc6cda3 | 5672 | |
a0c0a00f | 5673 | 'LC_MESSAGES' |
bb70624e | 5674 | This variable determines the locale used to translate double-quoted |
a0c0a00f | 5675 | strings preceded by a '$' (*note Locale Translation::). |
ccc6cda3 | 5676 | |
a0c0a00f | 5677 | 'LC_NUMERIC' |
bb70624e JA |
5678 | This variable determines the locale category used for number |
5679 | formatting. | |
ccc6cda3 | 5680 | |
a0c0a00f CR |
5681 | 'LC_TIME' |
5682 | This variable determines the locale category used for data and time | |
5683 | formatting. | |
5684 | ||
5685 | 'LINENO' | |
f73dda09 | 5686 | The line number in the script or shell function currently |
8868edaf CR |
5687 | executing. If 'LINENO' is unset, it loses its special properties, |
5688 | even if it is subsequently reset. | |
f73dda09 | 5689 | |
a0c0a00f CR |
5690 | 'LINES' |
5691 | Used by the 'select' command to determine the column length for | |
5692 | printing selection lists. Automatically set if the 'checkwinsize' | |
5693 | option is enabled (*note The Shopt Builtin::), or in an interactive | |
5694 | shell upon receipt of a 'SIGWINCH'. | |
28ef6c31 | 5695 | |
a0c0a00f | 5696 | 'MACHTYPE' |
bb70624e JA |
5697 | A string that fully describes the system type on which Bash is |
5698 | executing, in the standard GNU CPU-COMPANY-SYSTEM format. | |
ccc6cda3 | 5699 | |
a0c0a00f | 5700 | 'MAILCHECK' |
bb70624e | 5701 | How often (in seconds) that the shell should check for mail in the |
a0c0a00f CR |
5702 | files specified in the 'MAILPATH' or 'MAIL' variables. The default |
5703 | is 60 seconds. When it is time to check for mail, the shell does | |
5704 | so before displaying the primary prompt. If this variable is | |
5705 | unset, or set to a value that is not a number greater than or equal | |
5706 | to zero, the shell disables mail checking. | |
5707 | ||
5708 | 'MAPFILE' | |
5709 | An array variable created to hold the text read by the 'mapfile' | |
495aee44 CR |
5710 | builtin when no variable name is supplied. |
5711 | ||
a0c0a00f CR |
5712 | 'OLDPWD' |
5713 | The previous working directory as set by the 'cd' builtin. | |
ccc6cda3 | 5714 | |
a0c0a00f | 5715 | 'OPTERR' |
bb70624e | 5716 | If set to the value 1, Bash displays error messages generated by |
a0c0a00f | 5717 | the 'getopts' builtin command. |
ccc6cda3 | 5718 | |
a0c0a00f | 5719 | 'OSTYPE' |
bb70624e | 5720 | A string describing the operating system Bash is running on. |
ccc6cda3 | 5721 | |
a0c0a00f CR |
5722 | 'PIPESTATUS' |
5723 | An array variable (*note Arrays::) containing a list of exit status | |
5724 | values from the processes in the most-recently-executed foreground | |
5725 | pipeline (which may contain only a single command). | |
ccc6cda3 | 5726 | |
a0c0a00f | 5727 | 'POSIXLY_CORRECT' |
ac50fbac CR |
5728 | If this variable is in the environment when Bash starts, the shell |
5729 | enters POSIX mode (*note Bash POSIX Mode::) before reading the | |
a0c0a00f | 5730 | startup files, as if the '--posix' invocation option had been |
ac50fbac | 5731 | supplied. If it is set while the shell is running, Bash enables |
f73dda09 | 5732 | POSIX mode, as if the command |
a0c0a00f | 5733 | set -o posix |
d233b485 CR |
5734 | had been executed. When the shell enters POSIX mode, it sets this |
5735 | variable if it was not already set. | |
f73dda09 | 5736 | |
a0c0a00f | 5737 | 'PPID' |
bb70624e JA |
5738 | The process ID of the shell's parent process. This variable is |
5739 | readonly. | |
ccc6cda3 | 5740 | |
a0c0a00f | 5741 | 'PROMPT_COMMAND' |
8868edaf CR |
5742 | If this variable is set, and is an array, the value of each set |
5743 | element is interpreted as a command to execute before printing the | |
5744 | primary prompt ('$PS1'). If this is set but not an array variable, | |
5745 | its value is used as a command to execute instead. | |
ccc6cda3 | 5746 | |
a0c0a00f | 5747 | 'PROMPT_DIRTRIM' |
3185942a JA |
5748 | If set to a number greater than zero, the value is used as the |
5749 | number of trailing directory components to retain when expanding | |
a0c0a00f | 5750 | the '\w' and '\W' prompt string escapes (*note Controlling the |
3185942a JA |
5751 | Prompt::). Characters removed are replaced with an ellipsis. |
5752 | ||
a0c0a00f | 5753 | 'PS0' |
8868edaf | 5754 | The value of this parameter is expanded like 'PS1' and displayed by |
a0c0a00f CR |
5755 | interactive shells after reading a command and before the command |
5756 | is executed. | |
5757 | ||
5758 | 'PS3' | |
5759 | The value of this variable is used as the prompt for the 'select' | |
5760 | command. If this variable is not set, the 'select' command prompts | |
5761 | with '#? ' | |
ccc6cda3 | 5762 | |
a0c0a00f | 5763 | 'PS4' |
74091dd4 | 5764 | The value of this parameter is expanded like 'PS1' and the expanded |
d233b485 CR |
5765 | value is the prompt printed before the command line is echoed when |
5766 | the '-x' option is set (*note The Set Builtin::). The first | |
5767 | character of the expanded value is replicated multiple times, as | |
5768 | necessary, to indicate multiple levels of indirection. The default | |
5769 | is '+ '. | |
ccc6cda3 | 5770 | |
a0c0a00f CR |
5771 | 'PWD' |
5772 | The current working directory as set by the 'cd' builtin. | |
ccc6cda3 | 5773 | |
a0c0a00f | 5774 | 'RANDOM' |
8868edaf CR |
5775 | Each time this parameter is referenced, it expands to a random |
5776 | integer between 0 and 32767. Assigning a value to this variable | |
5777 | seeds the random number generator. If 'RANDOM' is unset, it loses | |
5778 | its special properties, even if it is subsequently reset. | |
cce855bc | 5779 | |
74091dd4 CR |
5780 | 'READLINE_ARGUMENT' |
5781 | Any numeric argument given to a Readline command that was defined | |
5782 | using 'bind -x' (*note Bash Builtins:: when it was invoked. | |
5783 | ||
a0c0a00f CR |
5784 | 'READLINE_LINE' |
5785 | The contents of the Readline line buffer, for use with 'bind -x' | |
495aee44 CR |
5786 | (*note Bash Builtins::). |
5787 | ||
8868edaf | 5788 | 'READLINE_MARK' |
74091dd4 | 5789 | The position of the "mark" (saved insertion point) in the Readline |
8868edaf CR |
5790 | line buffer, for use with 'bind -x' (*note Bash Builtins::). The |
5791 | characters between the insertion point and the mark are often | |
74091dd4 | 5792 | called the "region". |
8868edaf | 5793 | |
a0c0a00f | 5794 | 'READLINE_POINT' |
495aee44 | 5795 | The position of the insertion point in the Readline line buffer, |
a0c0a00f | 5796 | for use with 'bind -x' (*note Bash Builtins::). |
495aee44 | 5797 | |
a0c0a00f CR |
5798 | 'REPLY' |
5799 | The default variable for the 'read' builtin. | |
ccc6cda3 | 5800 | |
a0c0a00f | 5801 | 'SECONDS' |
bb70624e | 5802 | This variable expands to the number of seconds since the shell was |
a0c0a00f CR |
5803 | started. Assignment to this variable resets the count to the value |
5804 | assigned, and the expanded value becomes the value assigned plus | |
8868edaf | 5805 | the number of seconds since the assignment. The number of seconds |
74091dd4 | 5806 | at shell invocation and the current time are always determined by |
8868edaf CR |
5807 | querying the system clock. If 'SECONDS' is unset, it loses its |
5808 | special properties, even if it is subsequently reset. | |
ccc6cda3 | 5809 | |
a0c0a00f | 5810 | 'SHELL' |
8868edaf CR |
5811 | This environment variable expands to the full pathname to the |
5812 | shell. If it is not set when the shell starts, Bash assigns to it | |
5813 | the full pathname of the current user's login shell. | |
b80f6443 | 5814 | |
a0c0a00f | 5815 | 'SHELLOPTS' |
bb70624e | 5816 | A colon-separated list of enabled shell options. Each word in the |
a0c0a00f | 5817 | list is a valid argument for the '-o' option to the 'set' builtin |
28ef6c31 | 5818 | command (*note The Set Builtin::). The options appearing in |
a0c0a00f | 5819 | 'SHELLOPTS' are those reported as 'on' by 'set -o'. If this |
bb70624e JA |
5820 | variable is in the environment when Bash starts up, each shell |
5821 | option in the list will be enabled before reading any startup | |
5822 | files. This variable is readonly. | |
ccc6cda3 | 5823 | |
a0c0a00f | 5824 | 'SHLVL' |
bb70624e JA |
5825 | Incremented by one each time a new instance of Bash is started. |
5826 | This is intended to be a count of how deeply your Bash shells are | |
5827 | nested. | |
cce855bc | 5828 | |
8868edaf CR |
5829 | 'SRANDOM' |
5830 | This variable expands to a 32-bit pseudo-random number each time it | |
5831 | is referenced. The random number generator is not linear on | |
5832 | systems that support '/dev/urandom' or 'arc4random', so each | |
5833 | returned number has no relationship to the numbers preceding it. | |
5834 | The random number generator cannot be seeded, so assignments to | |
5835 | this variable have no effect. If 'SRANDOM' is unset, it loses its | |
5836 | special properties, even if it is subsequently reset. | |
5837 | ||
a0c0a00f | 5838 | 'TIMEFORMAT' |
bb70624e | 5839 | The value of this parameter is used as a format string specifying |
a0c0a00f CR |
5840 | how the timing information for pipelines prefixed with the 'time' |
5841 | reserved word should be displayed. The '%' character introduces an | |
bb70624e JA |
5842 | escape sequence that is expanded to a time value or other |
5843 | information. The escape sequences and their meanings are as | |
5844 | follows; the braces denote optional portions. | |
cce855bc | 5845 | |
a0c0a00f CR |
5846 | '%%' |
5847 | A literal '%'. | |
ccc6cda3 | 5848 | |
a0c0a00f | 5849 | '%[P][l]R' |
bb70624e | 5850 | The elapsed time in seconds. |
ccc6cda3 | 5851 | |
a0c0a00f | 5852 | '%[P][l]U' |
bb70624e | 5853 | The number of CPU seconds spent in user mode. |
ccc6cda3 | 5854 | |
a0c0a00f | 5855 | '%[P][l]S' |
bb70624e | 5856 | The number of CPU seconds spent in system mode. |
ccc6cda3 | 5857 | |
a0c0a00f | 5858 | '%P' |
bb70624e | 5859 | The CPU percentage, computed as (%U + %S) / %R. |
ccc6cda3 | 5860 | |
bb70624e JA |
5861 | The optional P is a digit specifying the precision, the number of |
5862 | fractional digits after a decimal point. A value of 0 causes no | |
a0c0a00f CR |
5863 | decimal point or fraction to be output. At most three places after |
5864 | the decimal point may be specified; values of P greater than 3 are | |
5865 | changed to 3. If P is not specified, the value 3 is used. | |
ccc6cda3 | 5866 | |
a0c0a00f | 5867 | The optional 'l' specifies a longer format, including minutes, of |
bb70624e JA |
5868 | the form MMmSS.FFs. The value of P determines whether or not the |
5869 | fraction is included. | |
ccc6cda3 | 5870 | |
bb70624e | 5871 | If this variable is not set, Bash acts as if it had the value |
a0c0a00f | 5872 | $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS' |
bb70624e JA |
5873 | If the value is null, no timing information is displayed. A |
5874 | trailing newline is added when the format string is displayed. | |
ccc6cda3 | 5875 | |
a0c0a00f CR |
5876 | 'TMOUT' |
5877 | If set to a value greater than zero, 'TMOUT' is treated as the | |
5878 | default timeout for the 'read' builtin (*note Bash Builtins::). | |
5879 | The 'select' command (*note Conditional Constructs::) terminates if | |
5880 | input does not arrive after 'TMOUT' seconds when input is coming | |
7117c2d2 JA |
5881 | from a terminal. |
5882 | ||
3185942a | 5883 | In an interactive shell, the value is interpreted as the number of |
ac50fbac CR |
5884 | seconds to wait for a line of input after issuing the primary |
5885 | prompt. Bash terminates after waiting for that number of seconds | |
5886 | if a complete line of input does not arrive. | |
ccc6cda3 | 5887 | |
a0c0a00f | 5888 | 'TMPDIR' |
95732b49 JA |
5889 | If set, Bash uses its value as the name of a directory in which |
5890 | Bash creates temporary files for the shell's use. | |
5891 | ||
a0c0a00f | 5892 | 'UID' |
bb70624e JA |
5893 | The numeric real user id of the current user. This variable is |
5894 | readonly. | |
ccc6cda3 | 5895 | |
bb70624e JA |
5896 | \1f |
5897 | File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top | |
ccc6cda3 | 5898 | |
b80f6443 JA |
5899 | 6 Bash Features |
5900 | *************** | |
ccc6cda3 | 5901 | |
ac50fbac | 5902 | This chapter describes features unique to Bash. |
ccc6cda3 | 5903 | |
bb70624e | 5904 | * Menu: |
ccc6cda3 | 5905 | |
bb70624e JA |
5906 | * Invoking Bash:: Command line options that you can give |
5907 | to Bash. | |
5908 | * Bash Startup Files:: When and how Bash executes scripts. | |
5909 | * Interactive Shells:: What an interactive shell is. | |
5910 | * Bash Conditional Expressions:: Primitives used in composing expressions for | |
a0c0a00f | 5911 | the 'test' builtin. |
bb70624e JA |
5912 | * Shell Arithmetic:: Arithmetic on shell variables. |
5913 | * Aliases:: Substituting one command for another. | |
5914 | * Arrays:: Array Variables. | |
5915 | * The Directory Stack:: History of visited directories. | |
ac50fbac | 5916 | * Controlling the Prompt:: Customizing the various prompt strings. |
bb70624e JA |
5917 | * The Restricted Shell:: A more controlled mode of shell execution. |
5918 | * Bash POSIX Mode:: Making Bash behave more closely to what | |
5919 | the POSIX standard specifies. | |
8868edaf CR |
5920 | * Shell Compatibility Mode:: How Bash supports behavior that was present |
5921 | in earlier versions and has changed. | |
ccc6cda3 | 5922 | |
bb70624e JA |
5923 | \1f |
5924 | File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features | |
ccc6cda3 | 5925 | |
b80f6443 JA |
5926 | 6.1 Invoking Bash |
5927 | ================= | |
ccc6cda3 | 5928 | |
d233b485 CR |
5929 | bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] |
5930 | [-O SHOPT_OPTION] [ARGUMENT ...] | |
5931 | bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] | |
5932 | [-O SHOPT_OPTION] -c STRING [ARGUMENT ...] | |
5933 | bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] | |
5934 | [-O SHOPT_OPTION] [ARGUMENT ...] | |
ccc6cda3 | 5935 | |
a0c0a00f | 5936 | All of the single-character options used with the 'set' builtin |
495aee44 CR |
5937 | (*note The Set Builtin::) can be used as options when the shell is |
5938 | invoked. In addition, there are several multi-character options that | |
5939 | you can use. These options must appear on the command line before the | |
5940 | single-character options to be recognized. | |
ccc6cda3 | 5941 | |
a0c0a00f | 5942 | '--debugger' |
b80f6443 | 5943 | Arrange for the debugger profile to be executed before the shell |
3185942a | 5944 | starts. Turns on extended debugging mode (see *note The Shopt |
a0c0a00f | 5945 | Builtin:: for a description of the 'extdebug' option to the 'shopt' |
495aee44 | 5946 | builtin). |
b80f6443 | 5947 | |
a0c0a00f CR |
5948 | '--dump-po-strings' |
5949 | A list of all double-quoted strings preceded by '$' is printed on | |
5950 | the standard output in the GNU 'gettext' PO (portable object) file | |
5951 | format. Equivalent to '-D' except for the output format. | |
ccc6cda3 | 5952 | |
a0c0a00f CR |
5953 | '--dump-strings' |
5954 | Equivalent to '-D'. | |
ccc6cda3 | 5955 | |
a0c0a00f | 5956 | '--help' |
3185942a | 5957 | Display a usage message on standard output and exit successfully. |
ccc6cda3 | 5958 | |
a0c0a00f CR |
5959 | '--init-file FILENAME' |
5960 | '--rcfile FILENAME' | |
5961 | Execute commands from FILENAME (instead of '~/.bashrc') in an | |
28ef6c31 JA |
5962 | interactive shell. |
5963 | ||
a0c0a00f CR |
5964 | '--login' |
5965 | Equivalent to '-l'. | |
ccc6cda3 | 5966 | |
a0c0a00f | 5967 | '--noediting' |
28ef6c31 | 5968 | Do not use the GNU Readline library (*note Command Line Editing::) |
a0c0a00f | 5969 | to read command lines when the shell is interactive. |
ccc6cda3 | 5970 | |
a0c0a00f CR |
5971 | '--noprofile' |
5972 | Don't load the system-wide startup file '/etc/profile' or any of | |
5973 | the personal initialization files '~/.bash_profile', | |
5974 | '~/.bash_login', or '~/.profile' when Bash is invoked as a login | |
bb70624e | 5975 | shell. |
ccc6cda3 | 5976 | |
a0c0a00f CR |
5977 | '--norc' |
5978 | Don't read the '~/.bashrc' initialization file in an interactive | |
5979 | shell. This is on by default if the shell is invoked as 'sh'. | |
ccc6cda3 | 5980 | |
a0c0a00f | 5981 | '--posix' |
bb70624e | 5982 | Change the behavior of Bash where the default operation differs |
a0c0a00f CR |
5983 | from the POSIX standard to match the standard. This is intended to |
5984 | make Bash behave as a strict superset of that standard. *Note Bash | |
5985 | POSIX Mode::, for a description of the Bash POSIX mode. | |
ccc6cda3 | 5986 | |
a0c0a00f | 5987 | '--restricted' |
28ef6c31 | 5988 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 5989 | |
a0c0a00f CR |
5990 | '--verbose' |
5991 | Equivalent to '-v'. Print shell input lines as they're read. | |
ccc6cda3 | 5992 | |
a0c0a00f | 5993 | '--version' |
bb70624e JA |
5994 | Show version information for this instance of Bash on the standard |
5995 | output and exit successfully. | |
ccc6cda3 | 5996 | |
bb70624e | 5997 | There are several single-character options that may be supplied at |
a0c0a00f | 5998 | invocation which are not available with the 'set' builtin. |
ccc6cda3 | 5999 | |
a0c0a00f CR |
6000 | '-c' |
6001 | Read and execute commands from the first non-option argument | |
6002 | COMMAND_STRING, then exit. If there are arguments after the | |
6003 | COMMAND_STRING, the first argument is assigned to '$0' and any | |
6004 | remaining arguments are assigned to the positional parameters. The | |
6005 | assignment to '$0' sets the name of the shell, which is used in | |
6006 | warning and error messages. | |
ccc6cda3 | 6007 | |
a0c0a00f | 6008 | '-i' |
bb70624e | 6009 | Force the shell to run interactively. Interactive shells are |
3185942a | 6010 | described in *note Interactive Shells::. |
ccc6cda3 | 6011 | |
a0c0a00f | 6012 | '-l' |
7117c2d2 JA |
6013 | Make this shell act as if it had been directly invoked by login. |
6014 | When the shell is interactive, this is equivalent to starting a | |
a0c0a00f CR |
6015 | login shell with 'exec -l bash'. When the shell is not |
6016 | interactive, the login shell startup files will be executed. 'exec | |
6017 | bash -l' or 'exec bash --login' will replace the current shell with | |
6018 | a Bash login shell. *Note Bash Startup Files::, for a description | |
6019 | of the special behavior of a login shell. | |
7117c2d2 | 6020 | |
a0c0a00f | 6021 | '-r' |
28ef6c31 | 6022 | Make the shell a restricted shell (*note The Restricted Shell::). |
ccc6cda3 | 6023 | |
a0c0a00f | 6024 | '-s' |
bb70624e JA |
6025 | If this option is present, or if no arguments remain after option |
6026 | processing, then commands are read from the standard input. This | |
6027 | option allows the positional parameters to be set when invoking an | |
d233b485 | 6028 | interactive shell or when reading input through a pipe. |
ccc6cda3 | 6029 | |
a0c0a00f CR |
6030 | '-D' |
6031 | A list of all double-quoted strings preceded by '$' is printed on | |
95732b49 | 6032 | the standard output. These are the strings that are subject to |
a0c0a00f CR |
6033 | language translation when the current locale is not 'C' or 'POSIX' |
6034 | (*note Locale Translation::). This implies the '-n' option; no | |
bb70624e | 6035 | commands will be executed. |
ccc6cda3 | 6036 | |
a0c0a00f CR |
6037 | '[-+]O [SHOPT_OPTION]' |
6038 | SHOPT_OPTION is one of the shell options accepted by the 'shopt' | |
3185942a | 6039 | builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present, |
a0c0a00f | 6040 | '-O' sets the value of that option; '+O' unsets it. If |
f73dda09 | 6041 | SHOPT_OPTION is not supplied, the names and values of the shell |
a0c0a00f CR |
6042 | options accepted by 'shopt' are printed on the standard output. If |
6043 | the invocation option is '+O', the output is displayed in a format | |
6044 | that may be reused as input. | |
f73dda09 | 6045 | |
a0c0a00f CR |
6046 | '--' |
6047 | A '--' signals the end of options and disables further option | |
6048 | processing. Any arguments after the '--' are treated as filenames | |
bb70624e | 6049 | and arguments. |
ccc6cda3 | 6050 | |
a0c0a00f CR |
6051 | A _login_ shell is one whose first character of argument zero is '-', |
6052 | or one invoked with the '--login' option. | |
f73dda09 | 6053 | |
28ef6c31 | 6054 | An _interactive_ shell is one started without non-option arguments, |
a0c0a00f | 6055 | unless '-s' is specified, without specifying the '-c' option, and whose |
bb70624e | 6056 | input and output are both connected to terminals (as determined by |
a0c0a00f | 6057 | 'isatty(3)'), or one started with the '-i' option. *Note Interactive |
28ef6c31 | 6058 | Shells::, for more information. |
ccc6cda3 | 6059 | |
a0c0a00f CR |
6060 | If arguments remain after option processing, and neither the '-c' nor |
6061 | the '-s' option has been supplied, the first argument is assumed to be | |
6062 | the name of a file containing shell commands (*note Shell Scripts::). | |
6063 | When Bash is invoked in this fashion, '$0' is set to the name of the | |
28ef6c31 JA |
6064 | file, and the positional parameters are set to the remaining arguments. |
6065 | Bash reads and executes commands from this file, then exits. Bash's | |
6066 | exit status is the exit status of the last command executed in the | |
6067 | script. If no commands are executed, the exit status is 0. | |
ccc6cda3 | 6068 | |
bb70624e JA |
6069 | \1f |
6070 | File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features | |
ccc6cda3 | 6071 | |
b80f6443 JA |
6072 | 6.2 Bash Startup Files |
6073 | ====================== | |
ccc6cda3 | 6074 | |
3185942a | 6075 | This section describes how Bash executes its startup files. If any of |
b80f6443 | 6076 | the files exist but cannot be read, Bash reports an error. Tildes are |
ac50fbac | 6077 | expanded in filenames as described above under Tilde Expansion (*note |
b80f6443 | 6078 | Tilde Expansion::). |
ccc6cda3 | 6079 | |
3185942a | 6080 | Interactive shells are described in *note Interactive Shells::. |
ccc6cda3 | 6081 | |
a0c0a00f | 6082 | Invoked as an interactive login shell, or with '--login' |
bb70624e | 6083 | ........................................................ |
cce855bc | 6084 | |
b80f6443 | 6085 | When Bash is invoked as an interactive login shell, or as a |
a0c0a00f CR |
6086 | non-interactive shell with the '--login' option, it first reads and |
6087 | executes commands from the file '/etc/profile', if that file exists. | |
6088 | After reading that file, it looks for '~/.bash_profile', | |
6089 | '~/.bash_login', and '~/.profile', in that order, and reads and executes | |
6090 | commands from the first one that exists and is readable. The | |
6091 | '--noprofile' option may be used when the shell is started to inhibit | |
bb70624e | 6092 | this behavior. |
ccc6cda3 | 6093 | |
a0c0a00f CR |
6094 | When an interactive login shell exits, or a non-interactive login |
6095 | shell executes the 'exit' builtin command, Bash reads and executes | |
6096 | commands from the file '~/.bash_logout', if it exists. | |
ccc6cda3 | 6097 | |
bb70624e JA |
6098 | Invoked as an interactive non-login shell |
6099 | ......................................... | |
ccc6cda3 | 6100 | |
b80f6443 | 6101 | When an interactive shell that is not a login shell is started, Bash |
a0c0a00f CR |
6102 | reads and executes commands from '~/.bashrc', if that file exists. This |
6103 | may be inhibited by using the '--norc' option. The '--rcfile FILE' | |
6104 | option will force Bash to read and execute commands from FILE instead of | |
6105 | '~/.bashrc'. | |
ccc6cda3 | 6106 | |
a0c0a00f CR |
6107 | So, typically, your '~/.bash_profile' contains the line |
6108 | if [ -f ~/.bashrc ]; then . ~/.bashrc; fi | |
6109 | after (or before) any login-specific initializations. | |
ccc6cda3 | 6110 | |
bb70624e JA |
6111 | Invoked non-interactively |
6112 | ......................... | |
ccc6cda3 | 6113 | |
b80f6443 | 6114 | When Bash is started non-interactively, to run a shell script, for |
a0c0a00f | 6115 | example, it looks for the variable 'BASH_ENV' in the environment, |
bb70624e JA |
6116 | expands its value if it appears there, and uses the expanded value as |
6117 | the name of a file to read and execute. Bash behaves as if the | |
6118 | following command were executed: | |
a0c0a00f CR |
6119 | if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi |
6120 | but the value of the 'PATH' variable is not used to search for the | |
ac50fbac | 6121 | filename. |
ccc6cda3 | 6122 | |
28ef6c31 | 6123 | As noted above, if a non-interactive shell is invoked with the |
a0c0a00f | 6124 | '--login' option, Bash attempts to read and execute commands from the |
28ef6c31 JA |
6125 | login shell startup files. |
6126 | ||
a0c0a00f | 6127 | Invoked with name 'sh' |
bb70624e | 6128 | ...................... |
ccc6cda3 | 6129 | |
a0c0a00f CR |
6130 | If Bash is invoked with the name 'sh', it tries to mimic the startup |
6131 | behavior of historical versions of 'sh' as closely as possible, while | |
bb70624e | 6132 | conforming to the POSIX standard as well. |
ccc6cda3 | 6133 | |
bb70624e | 6134 | When invoked as an interactive login shell, or as a non-interactive |
a0c0a00f CR |
6135 | shell with the '--login' option, it first attempts to read and execute |
6136 | commands from '/etc/profile' and '~/.profile', in that order. The | |
6137 | '--noprofile' option may be used to inhibit this behavior. When invoked | |
6138 | as an interactive shell with the name 'sh', Bash looks for the variable | |
6139 | 'ENV', expands its value if it is defined, and uses the expanded value | |
6140 | as the name of a file to read and execute. Since a shell invoked as | |
6141 | 'sh' does not attempt to read and execute commands from any other | |
6142 | startup files, the '--rcfile' option has no effect. A non-interactive | |
6143 | shell invoked with the name 'sh' does not attempt to read any other | |
6144 | startup files. | |
6145 | ||
6146 | When invoked as 'sh', Bash enters POSIX mode after the startup files | |
bb70624e | 6147 | are read. |
b72432fd | 6148 | |
bb70624e JA |
6149 | Invoked in POSIX mode |
6150 | ..................... | |
ccc6cda3 | 6151 | |
a0c0a00f | 6152 | When Bash is started in POSIX mode, as with the '--posix' command line |
b80f6443 | 6153 | option, it follows the POSIX standard for startup files. In this mode, |
a0c0a00f | 6154 | interactive shells expand the 'ENV' variable and commands are read and |
b80f6443 JA |
6155 | executed from the file whose name is the expanded value. No other |
6156 | startup files are read. | |
ccc6cda3 | 6157 | |
bb70624e JA |
6158 | Invoked by remote shell daemon |
6159 | .............................. | |
ccc6cda3 | 6160 | |
3185942a | 6161 | Bash attempts to determine when it is being run with its standard input |
74091dd4 CR |
6162 | connected to a network connection, as when executed by the historical |
6163 | remote shell daemon, usually 'rshd', or the secure shell daemon 'sshd'. | |
6164 | If Bash determines it is being run non-interactively in this fashion, it | |
6165 | reads and executes commands from '~/.bashrc', if that file exists and is | |
6166 | readable. It will not do this if invoked as 'sh'. The '--norc' option | |
6167 | may be used to inhibit this behavior, and the '--rcfile' option may be | |
6168 | used to force another file to be read, but neither 'rshd' nor 'sshd' | |
6169 | generally invoke the shell with those options or allow them to be | |
6170 | specified. | |
ccc6cda3 | 6171 | |
bb70624e JA |
6172 | Invoked with unequal effective and real UID/GIDs |
6173 | ................................................ | |
6174 | ||
b80f6443 | 6175 | If Bash is started with the effective user (group) id not equal to the |
a0c0a00f | 6176 | real user (group) id, and the '-p' option is not supplied, no startup |
b80f6443 | 6177 | files are read, shell functions are not inherited from the environment, |
a0c0a00f | 6178 | the 'SHELLOPTS', 'BASHOPTS', 'CDPATH', and 'GLOBIGNORE' variables, if |
0001803f | 6179 | they appear in the environment, are ignored, and the effective user id |
a0c0a00f | 6180 | is set to the real user id. If the '-p' option is supplied at |
0001803f CR |
6181 | invocation, the startup behavior is the same, but the effective user id |
6182 | is not reset. | |
bb70624e JA |
6183 | |
6184 | \1f | |
6185 | File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features | |
6186 | ||
b80f6443 JA |
6187 | 6.3 Interactive Shells |
6188 | ====================== | |
bb70624e JA |
6189 | |
6190 | * Menu: | |
6191 | ||
6192 | * What is an Interactive Shell?:: What determines whether a shell is Interactive. | |
6193 | * Is this Shell Interactive?:: How to tell if a shell is interactive. | |
74091dd4 | 6194 | * Interactive Shell Behavior:: What changes in an interactive shell? |
bb70624e JA |
6195 | |
6196 | \1f | |
6197 | File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells | |
6198 | ||
b80f6443 JA |
6199 | 6.3.1 What is an Interactive Shell? |
6200 | ----------------------------------- | |
bb70624e | 6201 | |
74091dd4 CR |
6202 | An interactive shell is one started without non-option arguments (unless |
6203 | '-s' is specified) and without specifying the '-c' option, whose input | |
a0c0a00f CR |
6204 | and error output are both connected to terminals (as determined by |
6205 | 'isatty(3)'), or one started with the '-i' option. | |
bb70624e JA |
6206 | |
6207 | An interactive shell generally reads from and writes to a user's | |
6208 | terminal. | |
6209 | ||
a0c0a00f | 6210 | The '-s' invocation option may be used to set the positional |
bb70624e JA |
6211 | parameters when an interactive shell is started. |
6212 | ||
6213 | \1f | |
6214 | File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells | |
6215 | ||
b80f6443 JA |
6216 | 6.3.2 Is this Shell Interactive? |
6217 | -------------------------------- | |
bb70624e | 6218 | |
b80f6443 | 6219 | To determine within a startup script whether or not Bash is running |
a0c0a00f CR |
6220 | interactively, test the value of the '-' special parameter. It contains |
6221 | 'i' when the shell is interactive. For example: | |
bb70624e JA |
6222 | |
6223 | case "$-" in | |
6224 | *i*) echo This shell is interactive ;; | |
6225 | *) echo This shell is not interactive ;; | |
6226 | esac | |
6227 | ||
a0c0a00f | 6228 | Alternatively, startup scripts may examine the variable 'PS1'; it is |
28ef6c31 | 6229 | unset in non-interactive shells, and set in interactive shells. Thus: |
bb70624e JA |
6230 | |
6231 | if [ -z "$PS1" ]; then | |
6232 | echo This shell is not interactive | |
6233 | else | |
6234 | echo This shell is interactive | |
6235 | fi | |
6236 | ||
6237 | \1f | |
6238 | File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells | |
6239 | ||
b80f6443 JA |
6240 | 6.3.3 Interactive Shell Behavior |
6241 | -------------------------------- | |
bb70624e | 6242 | |
b80f6443 | 6243 | When the shell is running interactively, it changes its behavior in |
bb70624e JA |
6244 | several ways. |
6245 | ||
3185942a | 6246 | 1. Startup files are read and executed as described in *note Bash |
bb70624e JA |
6247 | Startup Files::. |
6248 | ||
28ef6c31 | 6249 | 2. Job Control (*note Job Control::) is enabled by default. When job |
bb70624e | 6250 | control is in effect, Bash ignores the keyboard-generated job |
a0c0a00f | 6251 | control signals 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'. |
bb70624e | 6252 | |
a0c0a00f CR |
6253 | 3. Bash expands and displays 'PS1' before reading the first line of a |
6254 | command, and expands and displays 'PS2' before reading the second | |
d233b485 CR |
6255 | and subsequent lines of a multi-line command. Bash expands and |
6256 | displays 'PS0' after it reads a command but before executing it. | |
6257 | See *note Controlling the Prompt::, for a complete list of prompt | |
6258 | string escape sequences. | |
bb70624e | 6259 | |
8868edaf | 6260 | 4. Bash executes the values of the set elements of the |
74091dd4 | 6261 | 'PROMPT_COMMAND' array variable as commands before printing the |
8868edaf | 6262 | primary prompt, '$PS1' (*note Bash Variables::). |
bb70624e | 6263 | |
28ef6c31 | 6264 | 5. Readline (*note Command Line Editing::) is used to read commands |
bb70624e JA |
6265 | from the user's terminal. |
6266 | ||
a0c0a00f CR |
6267 | 6. Bash inspects the value of the 'ignoreeof' option to 'set -o' |
6268 | instead of exiting immediately when it receives an 'EOF' on its | |
28ef6c31 | 6269 | standard input when reading a command (*note The Set Builtin::). |
bb70624e | 6270 | |
28ef6c31 JA |
6271 | 7. Command history (*note Bash History Facilities::) and history |
6272 | expansion (*note History Interaction::) are enabled by default. | |
a0c0a00f | 6273 | Bash will save the command history to the file named by '$HISTFILE' |
ac50fbac | 6274 | when a shell with history enabled exits. |
bb70624e | 6275 | |
28ef6c31 | 6276 | 8. Alias expansion (*note Aliases::) is performed by default. |
bb70624e | 6277 | |
a0c0a00f | 6278 | 9. In the absence of any traps, Bash ignores 'SIGTERM' (*note |
28ef6c31 | 6279 | Signals::). |
bb70624e | 6280 | |
d233b485 CR |
6281 | 10. In the absence of any traps, 'SIGINT' is caught and handled (*note |
6282 | Signals::). 'SIGINT' will interrupt some shell builtins. | |
bb70624e | 6283 | |
a0c0a00f CR |
6284 | 11. An interactive login shell sends a 'SIGHUP' to all jobs on exit if |
6285 | the 'huponexit' shell option has been enabled (*note Signals::). | |
bb70624e | 6286 | |
a0c0a00f | 6287 | 12. The '-n' invocation option is ignored, and 'set -n' has no effect |
28ef6c31 | 6288 | (*note The Set Builtin::). |
bb70624e | 6289 | |
a0c0a00f CR |
6290 | 13. Bash will check for mail periodically, depending on the values of |
6291 | the 'MAIL', 'MAILPATH', and 'MAILCHECK' shell variables (*note Bash | |
6292 | Variables::). | |
bb70624e | 6293 | |
a0c0a00f CR |
6294 | 14. Expansion errors due to references to unbound shell variables |
6295 | after 'set -u' has been enabled will not cause the shell to exit | |
6296 | (*note The Set Builtin::). | |
bb70624e | 6297 | |
a0c0a00f CR |
6298 | 15. The shell will not exit on expansion errors caused by VAR being |
6299 | unset or null in '${VAR:?WORD}' expansions (*note Shell Parameter | |
28ef6c31 | 6300 | Expansion::). |
bb70624e | 6301 | |
a0c0a00f CR |
6302 | 16. Redirection errors encountered by shell builtins will not cause |
6303 | the shell to exit. | |
bb70624e | 6304 | |
a0c0a00f | 6305 | 17. When running in POSIX mode, a special builtin returning an error |
28ef6c31 | 6306 | status will not cause the shell to exit (*note Bash POSIX Mode::). |
bb70624e | 6307 | |
a0c0a00f | 6308 | 18. A failed 'exec' will not cause the shell to exit (*note Bourne |
28ef6c31 | 6309 | Shell Builtins::). |
bb70624e | 6310 | |
a0c0a00f | 6311 | 19. Parser syntax errors will not cause the shell to exit. |
bb70624e | 6312 | |
74091dd4 CR |
6313 | 20. If the 'cdspell' shell option is enabled, the shell will attempt |
6314 | simple spelling correction for directory arguments to the 'cd' | |
6315 | builtin (see the description of the 'cdspell' option to the 'shopt' | |
6316 | builtin in *note The Shopt Builtin::). The 'cdspell' option is | |
6317 | only effective in interactive shells. | |
bb70624e | 6318 | |
a0c0a00f | 6319 | 21. The shell will check the value of the 'TMOUT' variable and exit if |
bb70624e | 6320 | a command is not read within the specified number of seconds after |
a0c0a00f | 6321 | printing '$PS1' (*note Bash Variables::). |
bb70624e JA |
6322 | |
6323 | \1f | |
6324 | File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features | |
6325 | ||
b80f6443 JA |
6326 | 6.4 Bash Conditional Expressions |
6327 | ================================ | |
bb70624e | 6328 | |
74091dd4 CR |
6329 | Conditional expressions are used by the '[[' compound command (*note |
6330 | Conditional Constructs::) and the 'test' and '[' builtin commands (*note | |
6331 | Bourne Shell Builtins::). The 'test' and '[' commands determine their | |
6332 | behavior based on the number of arguments; see the descriptions of those | |
6333 | commands for any other command-specific actions. | |
d233b485 CR |
6334 | |
6335 | Expressions may be unary or binary, and are formed from the following | |
6336 | primaries. Unary expressions are often used to examine the status of a | |
6337 | file. There are string operators and numeric comparison operators as | |
6338 | well. Bash handles several filenames specially when they are used in | |
6339 | expressions. If the operating system on which Bash is running provides | |
6340 | these special files, Bash will use them; otherwise it will emulate them | |
6341 | internally with this behavior: If the FILE argument to one of the | |
6342 | primaries is of the form '/dev/fd/N', then file descriptor N is checked. | |
6343 | If the FILE argument to one of the primaries is one of '/dev/stdin', | |
6344 | '/dev/stdout', or '/dev/stderr', file descriptor 0, 1, or 2, | |
6345 | respectively, is checked. | |
bb70624e | 6346 | |
a0c0a00f CR |
6347 | When used with '[[', the '<' and '>' operators sort lexicographically |
6348 | using the current locale. The 'test' command uses ASCII ordering. | |
0001803f | 6349 | |
95732b49 JA |
6350 | Unless otherwise specified, primaries that operate on files follow |
6351 | symbolic links and operate on the target of the link, rather than the | |
6352 | link itself. | |
6353 | ||
a0c0a00f | 6354 | '-a FILE' |
bb70624e JA |
6355 | True if FILE exists. |
6356 | ||
a0c0a00f | 6357 | '-b FILE' |
bb70624e JA |
6358 | True if FILE exists and is a block special file. |
6359 | ||
a0c0a00f | 6360 | '-c FILE' |
bb70624e JA |
6361 | True if FILE exists and is a character special file. |
6362 | ||
a0c0a00f | 6363 | '-d FILE' |
bb70624e JA |
6364 | True if FILE exists and is a directory. |
6365 | ||
a0c0a00f | 6366 | '-e FILE' |
bb70624e JA |
6367 | True if FILE exists. |
6368 | ||
a0c0a00f | 6369 | '-f FILE' |
bb70624e JA |
6370 | True if FILE exists and is a regular file. |
6371 | ||
a0c0a00f | 6372 | '-g FILE' |
bb70624e JA |
6373 | True if FILE exists and its set-group-id bit is set. |
6374 | ||
a0c0a00f | 6375 | '-h FILE' |
bb70624e JA |
6376 | True if FILE exists and is a symbolic link. |
6377 | ||
a0c0a00f | 6378 | '-k FILE' |
bb70624e JA |
6379 | True if FILE exists and its "sticky" bit is set. |
6380 | ||
a0c0a00f | 6381 | '-p FILE' |
bb70624e JA |
6382 | True if FILE exists and is a named pipe (FIFO). |
6383 | ||
a0c0a00f | 6384 | '-r FILE' |
bb70624e JA |
6385 | True if FILE exists and is readable. |
6386 | ||
a0c0a00f | 6387 | '-s FILE' |
bb70624e JA |
6388 | True if FILE exists and has a size greater than zero. |
6389 | ||
a0c0a00f | 6390 | '-t FD' |
bb70624e | 6391 | True if file descriptor FD is open and refers to a terminal. |
ccc6cda3 | 6392 | |
a0c0a00f | 6393 | '-u FILE' |
ccc6cda3 JA |
6394 | True if FILE exists and its set-user-id bit is set. |
6395 | ||
a0c0a00f | 6396 | '-w FILE' |
ccc6cda3 JA |
6397 | True if FILE exists and is writable. |
6398 | ||
a0c0a00f | 6399 | '-x FILE' |
ccc6cda3 JA |
6400 | True if FILE exists and is executable. |
6401 | ||
a0c0a00f | 6402 | '-G FILE' |
ccc6cda3 JA |
6403 | True if FILE exists and is owned by the effective group id. |
6404 | ||
a0c0a00f | 6405 | '-L FILE' |
cce855bc JA |
6406 | True if FILE exists and is a symbolic link. |
6407 | ||
a0c0a00f | 6408 | '-N FILE' |
495aee44 CR |
6409 | True if FILE exists and has been modified since it was last read. |
6410 | ||
a0c0a00f | 6411 | '-O FILE' |
495aee44 CR |
6412 | True if FILE exists and is owned by the effective user id. |
6413 | ||
a0c0a00f | 6414 | '-S FILE' |
cce855bc JA |
6415 | True if FILE exists and is a socket. |
6416 | ||
a0c0a00f | 6417 | 'FILE1 -ef FILE2' |
495aee44 | 6418 | True if FILE1 and FILE2 refer to the same device and inode numbers. |
cce855bc | 6419 | |
a0c0a00f CR |
6420 | 'FILE1 -nt FILE2' |
6421 | True if FILE1 is newer (according to modification date) than FILE2, | |
6422 | or if FILE1 exists and FILE2 does not. | |
ccc6cda3 | 6423 | |
a0c0a00f | 6424 | 'FILE1 -ot FILE2' |
7117c2d2 JA |
6425 | True if FILE1 is older than FILE2, or if FILE2 exists and FILE1 |
6426 | does not. | |
ccc6cda3 | 6427 | |
a0c0a00f | 6428 | '-o OPTNAME' |
495aee44 | 6429 | True if the shell option OPTNAME is enabled. The list of options |
a0c0a00f | 6430 | appears in the description of the '-o' option to the 'set' builtin |
28ef6c31 | 6431 | (*note The Set Builtin::). |
ccc6cda3 | 6432 | |
a0c0a00f | 6433 | '-v VARNAME' |
495aee44 CR |
6434 | True if the shell variable VARNAME is set (has been assigned a |
6435 | value). | |
6436 | ||
a0c0a00f | 6437 | '-R VARNAME' |
ac50fbac CR |
6438 | True if the shell variable VARNAME is set and is a name reference. |
6439 | ||
a0c0a00f | 6440 | '-z STRING' |
ccc6cda3 JA |
6441 | True if the length of STRING is zero. |
6442 | ||
a0c0a00f CR |
6443 | '-n STRING' |
6444 | 'STRING' | |
ccc6cda3 JA |
6445 | True if the length of STRING is non-zero. |
6446 | ||
a0c0a00f CR |
6447 | 'STRING1 == STRING2' |
6448 | 'STRING1 = STRING2' | |
6449 | True if the strings are equal. When used with the '[[' command, | |
ac50fbac CR |
6450 | this performs pattern matching as described above (*note |
6451 | Conditional Constructs::). | |
6452 | ||
a0c0a00f | 6453 | '=' should be used with the 'test' command for POSIX conformance. |
ccc6cda3 | 6454 | |
a0c0a00f | 6455 | 'STRING1 != STRING2' |
ccc6cda3 JA |
6456 | True if the strings are not equal. |
6457 | ||
a0c0a00f | 6458 | 'STRING1 < STRING2' |
0001803f | 6459 | True if STRING1 sorts before STRING2 lexicographically. |
ccc6cda3 | 6460 | |
a0c0a00f | 6461 | 'STRING1 > STRING2' |
0001803f | 6462 | True if STRING1 sorts after STRING2 lexicographically. |
ccc6cda3 | 6463 | |
a0c0a00f CR |
6464 | 'ARG1 OP ARG2' |
6465 | 'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'. These | |
ccc6cda3 JA |
6466 | arithmetic binary operators return true if ARG1 is equal to, not |
6467 | equal to, less than, less than or equal to, greater than, or | |
6468 | greater than or equal to ARG2, respectively. ARG1 and ARG2 may be | |
d233b485 CR |
6469 | positive or negative integers. When used with the '[[' command, |
6470 | ARG1 and ARG2 are evaluated as arithmetic expressions (*note Shell | |
6471 | Arithmetic::). | |
ccc6cda3 | 6472 | |
ccc6cda3 | 6473 | \1f |
bb70624e | 6474 | File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features |
ccc6cda3 | 6475 | |
b80f6443 JA |
6476 | 6.5 Shell Arithmetic |
6477 | ==================== | |
ccc6cda3 | 6478 | |
b80f6443 | 6479 | The shell allows arithmetic expressions to be evaluated, as one of the |
a0c0a00f CR |
6480 | shell expansions or by using the '((' compound command, the 'let' |
6481 | builtin, or the '-i' option to the 'declare' builtin. | |
ccc6cda3 | 6482 | |
7117c2d2 JA |
6483 | Evaluation is done in fixed-width integers with no check for |
6484 | overflow, though division by 0 is trapped and flagged as an error. The | |
b80f6443 JA |
6485 | operators and their precedence, associativity, and values are the same |
6486 | as in the C language. The following list of operators is grouped into | |
a0c0a00f CR |
6487 | levels of equal-precedence operators. The levels are listed in order of |
6488 | decreasing precedence. | |
cce855bc | 6489 | |
a0c0a00f | 6490 | 'ID++ ID--' |
bb70624e | 6491 | variable post-increment and post-decrement |
d166f048 | 6492 | |
a0c0a00f | 6493 | '++ID --ID' |
bb70624e | 6494 | variable pre-increment and pre-decrement |
ccc6cda3 | 6495 | |
a0c0a00f | 6496 | '- +' |
bb70624e | 6497 | unary minus and plus |
ccc6cda3 | 6498 | |
a0c0a00f | 6499 | '! ~' |
bb70624e | 6500 | logical and bitwise negation |
ccc6cda3 | 6501 | |
a0c0a00f | 6502 | '**' |
bb70624e | 6503 | exponentiation |
ccc6cda3 | 6504 | |
a0c0a00f | 6505 | '* / %' |
bb70624e | 6506 | multiplication, division, remainder |
ccc6cda3 | 6507 | |
a0c0a00f | 6508 | '+ -' |
bb70624e | 6509 | addition, subtraction |
ccc6cda3 | 6510 | |
a0c0a00f | 6511 | '<< >>' |
bb70624e | 6512 | left and right bitwise shifts |
cce855bc | 6513 | |
a0c0a00f | 6514 | '<= >= < >' |
bb70624e | 6515 | comparison |
cce855bc | 6516 | |
a0c0a00f | 6517 | '== !=' |
bb70624e | 6518 | equality and inequality |
cce855bc | 6519 | |
a0c0a00f | 6520 | '&' |
bb70624e | 6521 | bitwise AND |
cce855bc | 6522 | |
a0c0a00f | 6523 | '^' |
bb70624e | 6524 | bitwise exclusive OR |
cce855bc | 6525 | |
a0c0a00f | 6526 | '|' |
bb70624e | 6527 | bitwise OR |
cce855bc | 6528 | |
a0c0a00f | 6529 | '&&' |
bb70624e | 6530 | logical AND |
ccc6cda3 | 6531 | |
a0c0a00f | 6532 | '||' |
bb70624e | 6533 | logical OR |
ccc6cda3 | 6534 | |
a0c0a00f | 6535 | 'expr ? expr : expr' |
b80f6443 | 6536 | conditional operator |
cce855bc | 6537 | |
a0c0a00f | 6538 | '= *= /= %= += -= <<= >>= &= ^= |=' |
bb70624e | 6539 | assignment |
ccc6cda3 | 6540 | |
a0c0a00f | 6541 | 'expr1 , expr2' |
bb70624e | 6542 | comma |
ccc6cda3 | 6543 | |
bb70624e JA |
6544 | Shell variables are allowed as operands; parameter expansion is |
6545 | performed before the expression is evaluated. Within an expression, | |
6546 | shell variables may also be referenced by name without using the | |
b80f6443 JA |
6547 | parameter expansion syntax. A shell variable that is null or unset |
6548 | evaluates to 0 when referenced by name without using the parameter | |
a0c0a00f CR |
6549 | expansion syntax. The value of a variable is evaluated as an arithmetic |
6550 | expression when it is referenced, or when a variable which has been | |
74091dd4 CR |
6551 | given the 'integer' attribute using 'declare -i' is assigned a value. A |
6552 | null value evaluates to 0. A shell variable need not have its 'integer' | |
a0c0a00f | 6553 | attribute turned on to be used in an expression. |
ccc6cda3 | 6554 | |
8868edaf CR |
6555 | Integer constants follow the C language definition, without suffixes |
6556 | or character constants. Constants with a leading 0 are interpreted as | |
6557 | octal numbers. A leading '0x' or '0X' denotes hexadecimal. Otherwise, | |
6558 | numbers take the form [BASE'#']N, where the optional BASE is a decimal | |
6559 | number between 2 and 64 representing the arithmetic base, and N is a | |
6560 | number in that base. If BASE'#' is omitted, then base 10 is used. When | |
6561 | specifying N, if a non-digit is required, the digits greater than 9 are | |
6562 | represented by the lowercase letters, the uppercase letters, '@', and | |
6563 | '_', in that order. If BASE is less than or equal to 36, lowercase and | |
6564 | uppercase letters may be used interchangeably to represent numbers | |
6565 | between 10 and 35. | |
ccc6cda3 | 6566 | |
bb70624e JA |
6567 | Operators are evaluated in order of precedence. Sub-expressions in |
6568 | parentheses are evaluated first and may override the precedence rules | |
6569 | above. | |
ccc6cda3 | 6570 | |
bb70624e JA |
6571 | \1f |
6572 | File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features | |
ccc6cda3 | 6573 | |
b80f6443 JA |
6574 | 6.6 Aliases |
6575 | =========== | |
ccc6cda3 | 6576 | |
74091dd4 | 6577 | "Aliases" allow a string to be substituted for a word when it is used as |
b80f6443 | 6578 | the first word of a simple command. The shell maintains a list of |
a0c0a00f CR |
6579 | aliases that may be set and unset with the 'alias' and 'unalias' builtin |
6580 | commands. | |
cce855bc JA |
6581 | |
6582 | The first word of each simple command, if unquoted, is checked to see | |
6583 | if it has an alias. If so, that word is replaced by the text of the | |
a0c0a00f | 6584 | alias. The characters '/', '$', '`', '=' and any of the shell |
b80f6443 JA |
6585 | metacharacters or quoting characters listed above may not appear in an |
6586 | alias name. The replacement text may contain any valid shell input, | |
6587 | including shell metacharacters. The first word of the replacement text | |
6588 | is tested for aliases, but a word that is identical to an alias being | |
6589 | expanded is not expanded a second time. This means that one may alias | |
a0c0a00f | 6590 | 'ls' to '"ls -F"', for instance, and Bash does not try to recursively |
ac50fbac | 6591 | expand the replacement text. If the last character of the alias value |
74091dd4 | 6592 | is a 'blank', then the next command word following the alias is also |
ac50fbac | 6593 | checked for alias expansion. |
cce855bc | 6594 | |
a0c0a00f CR |
6595 | Aliases are created and listed with the 'alias' command, and removed |
6596 | with the 'unalias' command. | |
cce855bc | 6597 | |
a0c0a00f | 6598 | There is no mechanism for using arguments in the replacement text, as |
74091dd4 CR |
6599 | in 'csh'. If arguments are needed, use a shell function (*note Shell |
6600 | Functions::). | |
cce855bc JA |
6601 | |
6602 | Aliases are not expanded when the shell is not interactive, unless | |
a0c0a00f | 6603 | the 'expand_aliases' shell option is set using 'shopt' (*note The Shopt |
3185942a | 6604 | Builtin::). |
ccc6cda3 | 6605 | |
cce855bc | 6606 | The rules concerning the definition and use of aliases are somewhat |
d233b485 CR |
6607 | confusing. Bash always reads at least one complete line of input, and |
6608 | all lines that make up a compound command, before executing any of the | |
6609 | commands on that line or the compound command. Aliases are expanded | |
6610 | when a command is read, not when it is executed. Therefore, an alias | |
a0c0a00f CR |
6611 | definition appearing on the same line as another command does not take |
6612 | effect until the next line of input is read. The commands following the | |
6613 | alias definition on that line are not affected by the new alias. This | |
6614 | behavior is also an issue when functions are executed. Aliases are | |
6615 | expanded when a function definition is read, not when the function is | |
6616 | executed, because a function definition is itself a command. As a | |
6617 | consequence, aliases defined in a function are not available until after | |
6618 | that function is executed. To be safe, always put alias definitions on | |
6619 | a separate line, and do not use 'alias' in compound commands. | |
ccc6cda3 | 6620 | |
bb70624e | 6621 | For almost every purpose, shell functions are preferred over aliases. |
ccc6cda3 JA |
6622 | |
6623 | \1f | |
cce855bc | 6624 | File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features |
ccc6cda3 | 6625 | |
b80f6443 JA |
6626 | 6.7 Arrays |
6627 | ========== | |
ccc6cda3 | 6628 | |
3185942a | 6629 | Bash provides one-dimensional indexed and associative array variables. |
a0c0a00f CR |
6630 | Any variable may be used as an indexed array; the 'declare' builtin will |
6631 | explicitly declare an array. There is no maximum limit on the size of | |
6632 | an array, nor any requirement that members be indexed or assigned | |
6633 | contiguously. Indexed arrays are referenced using integers (including | |
6634 | arithmetic expressions (*note Shell Arithmetic::)) and are zero-based; | |
6635 | associative arrays use arbitrary strings. Unless otherwise noted, | |
6636 | indexed array indices must be non-negative integers. | |
6637 | ||
6638 | An indexed array is created automatically if any variable is assigned | |
6639 | to using the syntax | |
ac50fbac | 6640 | NAME[SUBSCRIPT]=VALUE |
ccc6cda3 JA |
6641 | |
6642 | The SUBSCRIPT is treated as an arithmetic expression that must evaluate | |
ac50fbac | 6643 | to a number. To explicitly declare an array, use |
ccc6cda3 | 6644 | declare -a NAME |
a0c0a00f | 6645 | The syntax |
ccc6cda3 | 6646 | declare -a NAME[SUBSCRIPT] |
a0c0a00f | 6647 | is also accepted; the SUBSCRIPT is ignored. |
3185942a | 6648 | |
ac50fbac | 6649 | Associative arrays are created using |
8868edaf | 6650 | declare -A NAME |
3185942a | 6651 | |
a0c0a00f CR |
6652 | Attributes may be specified for an array variable using the 'declare' |
6653 | and 'readonly' builtins. Each attribute applies to all members of an | |
6654 | array. | |
ccc6cda3 JA |
6655 | |
6656 | Arrays are assigned to using compound assignments of the form | |
ac50fbac | 6657 | NAME=(VALUE1 VALUE2 ... ) |
8868edaf | 6658 | where each VALUE may be of the form '[SUBSCRIPT]='STRING. Indexed array |
ac50fbac CR |
6659 | assignments do not require anything but STRING. When assigning to |
6660 | indexed arrays, if the optional subscript is supplied, that index is | |
3185942a JA |
6661 | assigned to; otherwise the index of the element assigned is the last |
6662 | index assigned to by the statement plus one. Indexing starts at zero. | |
6663 | ||
8868edaf CR |
6664 | Each VALUE in the list undergoes all the shell expansions described |
6665 | above (*note Shell Expansions::). | |
6666 | ||
6667 | When assigning to an associative array, the words in a compound | |
6668 | assignment may be either assignment statements, for which the subscript | |
6669 | is required, or a list of words that is interpreted as a sequence of | |
6670 | alternating keys and values: NAME=(KEY1 VALUE1 KEY2 VALUE2 ... ). These | |
6671 | are treated identically to NAME=( [KEY1]=VALUE1 [KEY2]=VALUE2 ... ). | |
6672 | The first word in the list determines how the remaining words are | |
6673 | interpreted; all assignments in a list must be of the same type. When | |
6674 | using key/value pairs, the keys may not be missing or empty; a final | |
6675 | missing value is treated like the empty string. | |
3185942a | 6676 | |
a0c0a00f CR |
6677 | This syntax is also accepted by the 'declare' builtin. Individual |
6678 | array elements may be assigned to using the 'NAME[SUBSCRIPT]=VALUE' | |
3185942a | 6679 | syntax introduced above. |
ccc6cda3 | 6680 | |
ac50fbac CR |
6681 | When assigning to an indexed array, if NAME is subscripted by a |
6682 | negative number, that number is interpreted as relative to one greater | |
6683 | than the maximum index of NAME, so negative indices count back from the | |
6684 | end of the array, and an index of -1 references the last element. | |
6685 | ||
74091dd4 CR |
6686 | The '+=' operator will append to an array variable when assigning |
6687 | using the compound assignment syntax; see *note Shell Parameters:: | |
6688 | above. | |
6689 | ||
a0c0a00f | 6690 | Any element of an array may be referenced using '${NAME[SUBSCRIPT]}'. |
ac50fbac | 6691 | The braces are required to avoid conflicts with the shell's filename |
a0c0a00f CR |
6692 | expansion operators. If the SUBSCRIPT is '@' or '*', the word expands |
6693 | to all members of the array NAME. These subscripts differ only when the | |
6694 | word appears within double quotes. If the word is double-quoted, | |
6695 | '${NAME[*]}' expands to a single word with the value of each array | |
6696 | member separated by the first character of the 'IFS' variable, and | |
6697 | '${NAME[@]}' expands each element of NAME to a separate word. When | |
6698 | there are no array members, '${NAME[@]}' expands to nothing. If the | |
6699 | double-quoted expansion occurs within a word, the expansion of the first | |
6700 | parameter is joined with the beginning part of the original word, and | |
6701 | the expansion of the last parameter is joined with the last part of the | |
6702 | original word. This is analogous to the expansion of the special | |
6703 | parameters '@' and '*'. '${#NAME[SUBSCRIPT]}' expands to the length of | |
6704 | '${NAME[SUBSCRIPT]}'. If SUBSCRIPT is '@' or '*', the expansion is the | |
6705 | number of elements in the array. If the SUBSCRIPT used to reference an | |
6706 | element of an indexed array evaluates to a number less than zero, it is | |
6707 | interpreted as relative to one greater than the maximum index of the | |
6708 | array, so negative indices count back from the end of the array, and an | |
6709 | index of -1 refers to the last element. | |
6710 | ||
6711 | Referencing an array variable without a subscript is equivalent to | |
6712 | referencing with a subscript of 0. Any reference to a variable using a | |
6713 | valid subscript is legal, and 'bash' will create an array if necessary. | |
ccc6cda3 | 6714 | |
0001803f CR |
6715 | An array variable is considered set if a subscript has been assigned |
6716 | a value. The null string is a valid value. | |
6717 | ||
ac50fbac CR |
6718 | It is possible to obtain the keys (indices) of an array as well as |
6719 | the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned | |
6720 | in array variable NAME. The treatment when in double quotes is similar | |
a0c0a00f | 6721 | to the expansion of the special parameters '@' and '*' within double |
ac50fbac CR |
6722 | quotes. |
6723 | ||
a0c0a00f | 6724 | The 'unset' builtin is used to destroy arrays. 'unset |
ac50fbac CR |
6725 | NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT. |
6726 | Negative subscripts to indexed arrays are interpreted as described | |
d233b485 CR |
6727 | above. Unsetting the last element of an array variable does not unset |
6728 | the variable. 'unset NAME', where NAME is an array, removes the entire | |
74091dd4 CR |
6729 | array. 'unset NAME[SUBSCRIPT]' behaves differently depending on the |
6730 | array type when given a subscript of '*' or '@'. When NAME is an | |
6731 | associative array, it removes the element with key '*' or '@'. If NAME | |
6732 | is an indexed array, 'unset' removes all of the elements, but does not | |
6733 | remove the array itself. | |
d233b485 CR |
6734 | |
6735 | When using a variable name with a subscript as an argument to a | |
6736 | command, such as with 'unset', without using the word expansion syntax | |
6737 | described above, the argument is subject to the shell's filename | |
6738 | expansion. If filename expansion is not desired, the argument should be | |
6739 | quoted. | |
ccc6cda3 | 6740 | |
a0c0a00f CR |
6741 | The 'declare', 'local', and 'readonly' builtins each accept a '-a' |
6742 | option to specify an indexed array and a '-A' option to specify an | |
6743 | associative array. If both options are supplied, '-A' takes precedence. | |
6744 | The 'read' builtin accepts a '-a' option to assign a list of words read | |
ac50fbac | 6745 | from the standard input to an array, and can read values from the |
a0c0a00f | 6746 | standard input into individual array elements. The 'set' and 'declare' |
ac50fbac CR |
6747 | builtins display array values in a way that allows them to be reused as |
6748 | input. | |
ccc6cda3 JA |
6749 | |
6750 | \1f | |
ac50fbac | 6751 | File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features |
cce855bc | 6752 | |
b80f6443 JA |
6753 | 6.8 The Directory Stack |
6754 | ======================= | |
cce855bc | 6755 | |
bb70624e JA |
6756 | * Menu: |
6757 | ||
6758 | * Directory Stack Builtins:: Bash builtin commands to manipulate | |
6759 | the directory stack. | |
6760 | ||
a0c0a00f CR |
6761 | The directory stack is a list of recently-visited directories. The |
6762 | 'pushd' builtin adds directories to the stack as it changes the current | |
6763 | directory, and the 'popd' builtin removes specified directories from the | |
6764 | stack and changes the current directory to the directory removed. The | |
6765 | 'dirs' builtin displays the contents of the directory stack. The | |
6766 | current directory is always the "top" of the directory stack. | |
cce855bc JA |
6767 | |
6768 | The contents of the directory stack are also visible as the value of | |
a0c0a00f | 6769 | the 'DIRSTACK' shell variable. |
cce855bc | 6770 | |
bb70624e JA |
6771 | \1f |
6772 | File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack | |
6773 | ||
b80f6443 JA |
6774 | 6.8.1 Directory Stack Builtins |
6775 | ------------------------------ | |
bb70624e | 6776 | |
a0c0a00f | 6777 | 'dirs' |
ac50fbac CR |
6778 | dirs [-clpv] [+N | -N] |
6779 | ||
cce855bc | 6780 | Display the list of currently remembered directories. Directories |
a0c0a00f CR |
6781 | are added to the list with the 'pushd' command; the 'popd' command |
6782 | removes directories from the list. The current directory is always | |
6783 | the first directory in the stack. | |
cce855bc | 6784 | |
a0c0a00f | 6785 | '-c' |
cce855bc | 6786 | Clears the directory stack by deleting all of the elements. |
a0c0a00f | 6787 | '-l' |
ac50fbac CR |
6788 | Produces a listing using full pathnames; the default listing |
6789 | format uses a tilde to denote the home directory. | |
a0c0a00f CR |
6790 | '-p' |
6791 | Causes 'dirs' to print the directory stack with one entry per | |
cce855bc | 6792 | line. |
a0c0a00f CR |
6793 | '-v' |
6794 | Causes 'dirs' to print the directory stack with one entry per | |
cce855bc | 6795 | line, prefixing each entry with its index in the stack. |
a0c0a00f CR |
6796 | '+N' |
6797 | Displays the Nth directory (counting from the left of the list | |
6798 | printed by 'dirs' when invoked without options), starting with | |
6799 | zero. | |
6800 | '-N' | |
ac50fbac | 6801 | Displays the Nth directory (counting from the right of the |
a0c0a00f | 6802 | list printed by 'dirs' when invoked without options), starting |
ac50fbac CR |
6803 | with zero. |
6804 | ||
a0c0a00f | 6805 | 'popd' |
ac50fbac | 6806 | popd [-n] [+N | -N] |
cce855bc | 6807 | |
74091dd4 CR |
6808 | Removes elements from the directory stack. The elements are |
6809 | numbered from 0 starting at the first directory listed by 'dirs'; | |
6810 | that is, 'popd' is equivalent to 'popd +0'. | |
6811 | ||
a0c0a00f | 6812 | When no arguments are given, 'popd' removes the top directory from |
74091dd4 CR |
6813 | the stack and changes to the new top directory. |
6814 | ||
6815 | Arguments, if supplied, have the following meanings: | |
ac50fbac | 6816 | |
a0c0a00f | 6817 | '-n' |
ac50fbac CR |
6818 | Suppresses the normal change of directory when removing |
6819 | directories from the stack, so that only the stack is | |
6820 | manipulated. | |
a0c0a00f | 6821 | '+N' |
cce855bc | 6822 | Removes the Nth directory (counting from the left of the list |
74091dd4 | 6823 | printed by 'dirs'), starting with zero, from the stack. |
a0c0a00f CR |
6824 | '-N' |
6825 | Removes the Nth directory (counting from the right of the list | |
74091dd4 CR |
6826 | printed by 'dirs'), starting with zero, from the stack. |
6827 | ||
6828 | If the top element of the directory stack is modified, and the '-n' | |
6829 | option was not supplied, 'popd' uses the 'cd' builtin to change to | |
6830 | the directory at the top of the stack. If the 'cd' fails, 'popd' | |
6831 | returns a non-zero value. | |
6832 | ||
6833 | Otherwise, 'popd' returns an unsuccessful status if an invalid | |
6834 | option is encountered, the directory stack is empty, or a | |
6835 | non-existent directory stack entry is specified. | |
6836 | ||
6837 | If the 'popd' command is successful, Bash runs 'dirs' to show the | |
6838 | final contents of the directory stack, and the return status is 0. | |
cce855bc | 6839 | |
a0c0a00f | 6840 | 'pushd' |
ac50fbac | 6841 | pushd [-n] [+N | -N | DIR] |
cce855bc | 6842 | |
74091dd4 CR |
6843 | Adds a directory to the top of the directory stack, or rotates the |
6844 | stack, making the new top of the stack the current working | |
6845 | directory. With no arguments, 'pushd' exchanges the top two | |
6846 | elements of the directory stack. | |
6847 | ||
6848 | Arguments, if supplied, have the following meanings: | |
cce855bc | 6849 | |
a0c0a00f CR |
6850 | '-n' |
6851 | Suppresses the normal change of directory when rotating or | |
6852 | adding directories to the stack, so that only the stack is | |
3185942a | 6853 | manipulated. |
a0c0a00f | 6854 | '+N' |
cce855bc | 6855 | Brings the Nth directory (counting from the left of the list |
a0c0a00f | 6856 | printed by 'dirs', starting with zero) to the top of the list |
cce855bc | 6857 | by rotating the stack. |
a0c0a00f | 6858 | '-N' |
cce855bc | 6859 | Brings the Nth directory (counting from the right of the list |
a0c0a00f | 6860 | printed by 'dirs', starting with zero) to the top of the list |
cce855bc | 6861 | by rotating the stack. |
a0c0a00f | 6862 | 'DIR' |
74091dd4 CR |
6863 | Makes DIR be the top of the stack. |
6864 | ||
6865 | After the stack has been modified, if the '-n' option was not | |
6866 | supplied, 'pushd' uses the 'cd' builtin to change to the directory | |
6867 | at the top of the stack. If the 'cd' fails, 'pushd' returns a | |
6868 | non-zero value. | |
6869 | ||
6870 | Otherwise, if no arguments are supplied, 'pushd' returns 0 unless | |
6871 | the directory stack is empty. When rotating the directory stack, | |
6872 | 'pushd' returns 0 unless the directory stack is empty or a | |
6873 | non-existent directory stack element is specified. | |
6874 | ||
6875 | If the 'pushd' command is successful, Bash runs 'dirs' to show the | |
6876 | final contents of the directory stack. | |
b80f6443 | 6877 | |
cce855bc | 6878 | \1f |
ac50fbac | 6879 | File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features |
ccc6cda3 | 6880 | |
b80f6443 JA |
6881 | 6.9 Controlling the Prompt |
6882 | ========================== | |
ccc6cda3 | 6883 | |
74091dd4 | 6884 | Bash examines the value of the array variable 'PROMPT_COMMAND' just |
8868edaf | 6885 | before printing each primary prompt. If any elements in |
74091dd4 | 6886 | 'PROMPT_COMMAND' are set and non-null, Bash executes each value, in |
8868edaf | 6887 | numeric order, just as if it had been typed on the command line. |
ccc6cda3 JA |
6888 | |
6889 | In addition, the following table describes the special characters | |
d233b485 | 6890 | which can appear in the prompt variables 'PS0', 'PS1', 'PS2', and 'PS4': |
ccc6cda3 | 6891 | |
a0c0a00f | 6892 | '\a' |
cce855bc | 6893 | A bell character. |
a0c0a00f | 6894 | '\d' |
cce855bc | 6895 | The date, in "Weekday Month Date" format (e.g., "Tue May 26"). |
a0c0a00f CR |
6896 | '\D{FORMAT}' |
6897 | The FORMAT is passed to 'strftime'(3) and the result is inserted | |
7117c2d2 JA |
6898 | into the prompt string; an empty FORMAT results in a |
6899 | locale-specific time representation. The braces are required. | |
a0c0a00f | 6900 | '\e' |
cce855bc | 6901 | An escape character. |
a0c0a00f CR |
6902 | '\h' |
6903 | The hostname, up to the first '.'. | |
6904 | '\H' | |
cce855bc | 6905 | The hostname. |
a0c0a00f | 6906 | '\j' |
bb70624e | 6907 | The number of jobs currently managed by the shell. |
a0c0a00f | 6908 | '\l' |
bb70624e | 6909 | The basename of the shell's terminal device name. |
a0c0a00f | 6910 | '\n' |
cce855bc | 6911 | A newline. |
a0c0a00f | 6912 | '\r' |
cce855bc | 6913 | A carriage return. |
a0c0a00f CR |
6914 | '\s' |
6915 | The name of the shell, the basename of '$0' (the portion following | |
ccc6cda3 | 6916 | the final slash). |
a0c0a00f | 6917 | '\t' |
cce855bc | 6918 | The time, in 24-hour HH:MM:SS format. |
a0c0a00f | 6919 | '\T' |
cce855bc | 6920 | The time, in 12-hour HH:MM:SS format. |
a0c0a00f | 6921 | '\@' |
cce855bc | 6922 | The time, in 12-hour am/pm format. |
a0c0a00f | 6923 | '\A' |
f73dda09 | 6924 | The time, in 24-hour HH:MM format. |
a0c0a00f | 6925 | '\u' |
cce855bc | 6926 | The username of the current user. |
a0c0a00f | 6927 | '\v' |
cce855bc | 6928 | The version of Bash (e.g., 2.00) |
a0c0a00f | 6929 | '\V' |
cce855bc | 6930 | The release of Bash, version + patchlevel (e.g., 2.00.0) |
a0c0a00f | 6931 | '\w' |
74091dd4 CR |
6932 | The value of the 'PWD' shell variable ('$PWD'), with '$HOME' |
6933 | abbreviated with a tilde (uses the '$PROMPT_DIRTRIM' variable). | |
a0c0a00f CR |
6934 | '\W' |
6935 | The basename of '$PWD', with '$HOME' abbreviated with a tilde. | |
6936 | '\!' | |
cce855bc | 6937 | The history number of this command. |
a0c0a00f | 6938 | '\#' |
cce855bc | 6939 | The command number of this command. |
a0c0a00f CR |
6940 | '\$' |
6941 | If the effective uid is 0, '#', otherwise '$'. | |
6942 | '\NNN' | |
cce855bc | 6943 | The character whose ASCII code is the octal value NNN. |
a0c0a00f | 6944 | '\\' |
cce855bc | 6945 | A backslash. |
a0c0a00f | 6946 | '\[' |
cce855bc | 6947 | Begin a sequence of non-printing characters. This could be used to |
ccc6cda3 | 6948 | embed a terminal control sequence into the prompt. |
a0c0a00f | 6949 | '\]' |
cce855bc | 6950 | End a sequence of non-printing characters. |
ccc6cda3 | 6951 | |
bb70624e JA |
6952 | The command number and the history number are usually different: the |
6953 | history number of a command is its position in the history list, which | |
6954 | may include commands restored from the history file (*note Bash History | |
28ef6c31 JA |
6955 | Facilities::), while the command number is the position in the sequence |
6956 | of commands executed during the current shell session. | |
bb70624e JA |
6957 | |
6958 | After the string is decoded, it is expanded via parameter expansion, | |
6959 | command substitution, arithmetic expansion, and quote removal, subject | |
d233b485 | 6960 | to the value of the 'promptvars' shell option (*note The Shopt |
8868edaf CR |
6961 | Builtin::). This can have unwanted side effects if escaped portions of |
6962 | the string appear within command substitution or contain characters | |
6963 | special to word expansion. | |
bb70624e | 6964 | |
ccc6cda3 | 6965 | \1f |
ac50fbac | 6966 | File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features |
ccc6cda3 | 6967 | |
b80f6443 JA |
6968 | 6.10 The Restricted Shell |
6969 | ========================= | |
ccc6cda3 | 6970 | |
a0c0a00f | 6971 | If Bash is started with the name 'rbash', or the '--restricted' or '-r' |
b80f6443 | 6972 | option is supplied at invocation, the shell becomes restricted. A |
ccc6cda3 | 6973 | restricted shell is used to set up an environment more controlled than |
a0c0a00f | 6974 | the standard shell. A restricted shell behaves identically to 'bash' |
7117c2d2 JA |
6975 | with the exception that the following are disallowed or not performed: |
6976 | ||
a0c0a00f | 6977 | * Changing directories with the 'cd' builtin. |
8868edaf CR |
6978 | * Setting or unsetting the values of the 'SHELL', 'PATH', 'HISTFILE', |
6979 | 'ENV', or 'BASH_ENV' variables. | |
ccc6cda3 | 6980 | * Specifying command names containing slashes. |
a0c0a00f | 6981 | * Specifying a filename containing a slash as an argument to the '.' |
ccc6cda3 | 6982 | builtin command. |
8868edaf CR |
6983 | * Specifying a filename containing a slash as an argument to the |
6984 | 'history' builtin command. | |
a0c0a00f CR |
6985 | * Specifying a filename containing a slash as an argument to the '-p' |
6986 | option to the 'hash' builtin command. | |
ccc6cda3 JA |
6987 | * Importing function definitions from the shell environment at |
6988 | startup. | |
a0c0a00f | 6989 | * Parsing the value of 'SHELLOPTS' from the shell environment at |
cce855bc | 6990 | startup. |
a0c0a00f | 6991 | * Redirecting output using the '>', '>|', '<>', '>&', '&>', and '>>' |
ccc6cda3 | 6992 | redirection operators. |
a0c0a00f CR |
6993 | * Using the 'exec' builtin to replace the shell with another command. |
6994 | * Adding or deleting builtin commands with the '-f' and '-d' options | |
6995 | to the 'enable' builtin. | |
6996 | * Using the 'enable' builtin command to enable disabled shell | |
7117c2d2 | 6997 | builtins. |
a0c0a00f | 6998 | * Specifying the '-p' option to the 'command' builtin. |
74091dd4 CR |
6999 | * Turning off restricted mode with 'set +r' or 'shopt -u |
7000 | restricted_shell'. | |
ccc6cda3 | 7001 | |
7117c2d2 JA |
7002 | These restrictions are enforced after any startup files are read. |
7003 | ||
7004 | When a command that is found to be a shell script is executed (*note | |
a0c0a00f | 7005 | Shell Scripts::), 'rbash' turns off any restrictions in the shell |
7117c2d2 JA |
7006 | spawned to execute the script. |
7007 | ||
8868edaf CR |
7008 | The restricted shell mode is only one component of a useful |
7009 | restricted environment. It should be accompanied by setting 'PATH' to a | |
7010 | value that allows execution of only a few verified commands (commands | |
74091dd4 CR |
7011 | that allow shell escapes are particularly vulnerable), changing the |
7012 | current directory to a non-writable directory other than '$HOME' after | |
7013 | login, not allowing the restricted shell to execute shell scripts, and | |
7014 | cleaning the environment of variables that cause some commands to modify | |
7015 | their behavior (e.g., 'VISUAL' or 'PAGER'). | |
8868edaf CR |
7016 | |
7017 | Modern systems provide more secure ways to implement a restricted | |
7018 | environment, such as 'jails', 'zones', or 'containers'. | |
7019 | ||
ccc6cda3 | 7020 | \1f |
8868edaf | 7021 | File: bashref.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features |
ccc6cda3 | 7022 | |
b80f6443 JA |
7023 | 6.11 Bash POSIX Mode |
7024 | ==================== | |
ccc6cda3 | 7025 | |
a0c0a00f | 7026 | Starting Bash with the '--posix' command-line option or executing 'set |
b80f6443 | 7027 | -o posix' while Bash is running will cause Bash to conform more closely |
0628567a JA |
7028 | to the POSIX standard by changing the behavior to match that specified |
7029 | by POSIX in areas where the Bash default differs. | |
ccc6cda3 | 7030 | |
a0c0a00f | 7031 | When invoked as 'sh', Bash enters POSIX mode after reading the |
7117c2d2 JA |
7032 | startup files. |
7033 | ||
a0c0a00f | 7034 | The following list is what's changed when 'POSIX mode' is in effect: |
ccc6cda3 | 7035 | |
d233b485 CR |
7036 | 1. Bash ensures that the 'POSIXLY_CORRECT' variable is set. |
7037 | ||
7038 | 2. When a command in the hash table no longer exists, Bash will | |
a0c0a00f CR |
7039 | re-search '$PATH' to find the new location. This is also available |
7040 | with 'shopt -s checkhash'. | |
ccc6cda3 | 7041 | |
8868edaf CR |
7042 | 3. Bash will not insert a command without the execute bit set into the |
7043 | command hash table, even if it returns it as a (last-ditch) result | |
7044 | from a '$PATH' search. | |
ccc6cda3 | 7045 | |
d233b485 | 7046 | 4. The message printed by the job control code and builtins when a job |
8868edaf CR |
7047 | exits with a non-zero status is 'Done(status)'. |
7048 | ||
7049 | 5. The message printed by the job control code and builtins when a job | |
a0c0a00f CR |
7050 | is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for example, |
7051 | 'SIGTSTP'. | |
ccc6cda3 | 7052 | |
8868edaf | 7053 | 6. Alias expansion is always enabled, even in non-interactive shells. |
95732b49 | 7054 | |
8868edaf | 7055 | 7. Reserved words appearing in a context where reserved words are |
95732b49 | 7056 | recognized do not undergo alias expansion. |
ccc6cda3 | 7057 | |
74091dd4 CR |
7058 | 8. Alias expansion is performed when initially parsing a command |
7059 | substitution. The default mode generally defers it, when enabled, | |
7060 | until the command substitution is executed. This means that | |
7061 | command substitution will not expand aliases that are defined after | |
7062 | the command substitution is initially parsed (e.g., as part of a | |
7063 | function definition). | |
7064 | ||
7065 | 9. The POSIX 'PS1' and 'PS2' expansions of '!' to the history number | |
a0c0a00f CR |
7066 | and '!!' to '!' are enabled, and parameter expansion is performed |
7067 | on the values of 'PS1' and 'PS2' regardless of the setting of the | |
7068 | 'promptvars' option. | |
ccc6cda3 | 7069 | |
74091dd4 | 7070 | 10. The POSIX startup files are executed ('$ENV') rather than the |
0628567a | 7071 | normal Bash files. |
ccc6cda3 | 7072 | |
74091dd4 | 7073 | 11. Tilde expansion is only performed on assignments preceding a |
ccc6cda3 JA |
7074 | command name, rather than on all assignment statements on the line. |
7075 | ||
74091dd4 | 7076 | 12. The default history file is '~/.sh_history' (this is the default |
a0c0a00f | 7077 | value of '$HISTFILE'). |
b80f6443 | 7078 | |
74091dd4 | 7079 | 13. Redirection operators do not perform filename expansion on the |
a0c0a00f | 7080 | word in the redirection unless the shell is interactive. |
495aee44 | 7081 | |
74091dd4 | 7082 | 14. Redirection operators do not perform word splitting on the word in |
bb70624e JA |
7083 | the redirection. |
7084 | ||
74091dd4 | 7085 | 15. Function names must be valid shell 'name's. That is, they may not |
ccc6cda3 | 7086 | contain characters other than letters, digits, and underscores, and |
cce855bc | 7087 | may not start with a digit. Declaring a function with an invalid |
ccc6cda3 JA |
7088 | name causes a fatal syntax error in non-interactive shells. |
7089 | ||
74091dd4 | 7090 | 16. Function names may not be the same as one of the POSIX special |
ac50fbac CR |
7091 | builtins. |
7092 | ||
74091dd4 | 7093 | 17. POSIX special builtins are found before shell functions during |
0628567a | 7094 | command lookup. |
ccc6cda3 | 7095 | |
74091dd4 | 7096 | 18. When printing shell function definitions (e.g., by 'type'), Bash |
a0c0a00f CR |
7097 | does not print the 'function' keyword. |
7098 | ||
74091dd4 | 7099 | 19. Literal tildes that appear as the first character in elements of |
a0c0a00f CR |
7100 | the 'PATH' variable are not expanded as described above under *note |
7101 | Tilde Expansion::. | |
7102 | ||
74091dd4 | 7103 | 20. The 'time' reserved word may be used by itself as a command. When |
495aee44 | 7104 | used in this way, it displays timing statistics for the shell and |
a0c0a00f | 7105 | its completed children. The 'TIMEFORMAT' variable controls the |
495aee44 CR |
7106 | format of the timing information. |
7107 | ||
74091dd4 | 7108 | 21. When parsing and expanding a ${...} expansion that appears within |
495aee44 CR |
7109 | double quotes, single quotes are no longer special and cannot be |
7110 | used to quote a closing brace or other special character, unless | |
7111 | the operator is one of those defined to perform pattern removal. | |
7112 | In this case, they do not have to appear as matched pairs. | |
7113 | ||
74091dd4 | 7114 | 22. The parser does not recognize 'time' as a reserved word if the |
a0c0a00f | 7115 | next token begins with a '-'. |
495aee44 | 7116 | |
74091dd4 | 7117 | 23. The '!' character does not introduce history expansion within a |
a0c0a00f CR |
7118 | double-quoted string, even if the 'histexpand' option is enabled. |
7119 | ||
74091dd4 | 7120 | 24. If a POSIX special builtin returns an error status, a |
ccc6cda3 | 7121 | non-interactive shell exits. The fatal errors are those listed in |
0628567a | 7122 | the POSIX standard, and include things like passing incorrect |
ccc6cda3 JA |
7123 | options, redirection errors, variable assignment errors for |
7124 | assignments preceding the command name, and so on. | |
7125 | ||
74091dd4 | 7126 | 25. A non-interactive shell exits with an error status if a variable |
ccc6cda3 JA |
7127 | assignment error occurs when no command name follows the assignment |
7128 | statements. A variable assignment error occurs, for example, when | |
cce855bc | 7129 | trying to assign a value to a readonly variable. |
ccc6cda3 | 7130 | |
74091dd4 | 7131 | 26. A non-interactive shell exits with an error status if a variable |
495aee44 | 7132 | assignment error occurs in an assignment statement preceding a |
74091dd4 CR |
7133 | special builtin, but not with any other simple command. For any |
7134 | other simple command, the shell aborts execution of that command, | |
7135 | and execution continues at the top level ("the shell shall not | |
7136 | perform any further processing of the command in which the error | |
7137 | occurred"). | |
495aee44 | 7138 | |
74091dd4 | 7139 | 27. A non-interactive shell exits with an error status if the |
a0c0a00f CR |
7140 | iteration variable in a 'for' statement or the selection variable |
7141 | in a 'select' statement is a readonly variable. | |
ccc6cda3 | 7142 | |
74091dd4 | 7143 | 28. Non-interactive shells exit if FILENAME in '.' FILENAME is not |
a0c0a00f | 7144 | found. |
ccc6cda3 | 7145 | |
74091dd4 | 7146 | 29. Non-interactive shells exit if a syntax error in an arithmetic |
a0c0a00f CR |
7147 | expansion results in an invalid expression. |
7148 | ||
74091dd4 | 7149 | 30. Non-interactive shells exit if a parameter expansion error occurs. |
a0c0a00f | 7150 | |
74091dd4 | 7151 | 31. Non-interactive shells exit if there is a syntax error in a script |
a0c0a00f CR |
7152 | read with the '.' or 'source' builtins, or in a string processed by |
7153 | the 'eval' builtin. | |
7154 | ||
74091dd4 | 7155 | 32. While variable indirection is available, it may not be applied to |
a0c0a00f CR |
7156 | the '#' and '?' special parameters. |
7157 | ||
74091dd4 CR |
7158 | 33. Expanding the '*' special parameter in a pattern context where the |
7159 | expansion is double-quoted does not treat the '$*' as if it were | |
7160 | double-quoted. | |
ac50fbac | 7161 | |
74091dd4 | 7162 | 34. Assignment statements preceding POSIX special builtins persist in |
0628567a | 7163 | the shell environment after the builtin completes. |
ccc6cda3 | 7164 | |
74091dd4 | 7165 | 35. The 'command' builtin does not prevent builtins that take |
a0c0a00f CR |
7166 | assignment statements as arguments from expanding them as |
7167 | assignment statements; when not in POSIX mode, assignment builtins | |
7168 | lose their assignment statement expansion properties when preceded | |
7169 | by 'command'. | |
7170 | ||
74091dd4 | 7171 | 36. The 'bg' builtin uses the required format to describe each job |
a0c0a00f CR |
7172 | placed in the background, which does not include an indication of |
7173 | whether the job is the current or previous job. | |
7174 | ||
74091dd4 | 7175 | 37. The output of 'kill -l' prints all the signal names on a single |
a0c0a00f CR |
7176 | line, separated by spaces, without the 'SIG' prefix. |
7177 | ||
74091dd4 | 7178 | 38. The 'kill' builtin does not accept signal names with a 'SIG' |
a0c0a00f CR |
7179 | prefix. |
7180 | ||
74091dd4 | 7181 | 39. The 'export' and 'readonly' builtin commands display their output |
0628567a | 7182 | in the format required by POSIX. |
d166f048 | 7183 | |
74091dd4 | 7184 | 40. The 'trap' builtin displays signal names without the leading |
a0c0a00f | 7185 | 'SIG'. |
28ef6c31 | 7186 | |
74091dd4 | 7187 | 41. The 'trap' builtin doesn't check the first argument for a possible |
b80f6443 | 7188 | signal specification and revert the signal handling to the original |
95732b49 JA |
7189 | disposition if it is, unless that argument consists solely of |
7190 | digits and is a valid signal number. If users want to reset the | |
a0c0a00f CR |
7191 | handler for a given signal to the original disposition, they should |
7192 | use '-' as the first argument. | |
28ef6c31 | 7193 | |
74091dd4 | 7194 | 42. 'trap -p' displays signals whose dispositions are set to SIG_DFL |
8868edaf CR |
7195 | and those that were ignored when the shell started. |
7196 | ||
74091dd4 | 7197 | 43. The '.' and 'source' builtins do not search the current directory |
a0c0a00f | 7198 | for the filename argument if it is not found by searching 'PATH'. |
28ef6c31 | 7199 | |
74091dd4 | 7200 | 44. Enabling POSIX mode has the effect of setting the |
a0c0a00f CR |
7201 | 'inherit_errexit' option, so subshells spawned to execute command |
7202 | substitutions inherit the value of the '-e' option from the parent | |
7203 | shell. When the 'inherit_errexit' option is not enabled, Bash | |
7204 | clears the '-e' option in such subshells. | |
28ef6c31 | 7205 | |
74091dd4 | 7206 | 45. Enabling POSIX mode has the effect of setting the 'shift_verbose' |
d233b485 CR |
7207 | option, so numeric arguments to 'shift' that exceed the number of |
7208 | positional parameters will result in an error message. | |
7209 | ||
74091dd4 | 7210 | 46. When the 'alias' builtin displays alias definitions, it does not |
a0c0a00f | 7211 | display them with a leading 'alias ' unless the '-p' option is |
b80f6443 JA |
7212 | supplied. |
7213 | ||
74091dd4 | 7214 | 47. When the 'set' builtin is invoked without options, it does not |
28ef6c31 JA |
7215 | display shell function names and definitions. |
7216 | ||
74091dd4 | 7217 | 48. When the 'set' builtin is invoked without options, it displays |
f73dda09 JA |
7218 | variable values without quotes, unless they contain shell |
7219 | metacharacters, even if the result contains nonprinting characters. | |
ccc6cda3 | 7220 | |
74091dd4 | 7221 | 49. When the 'cd' builtin is invoked in logical mode, and the pathname |
a0c0a00f CR |
7222 | constructed from '$PWD' and the directory name supplied as an |
7223 | argument does not refer to an existing directory, 'cd' will fail | |
74091dd4 | 7224 | instead of falling back to physical mode. |
7117c2d2 | 7225 | |
74091dd4 | 7226 | 50. When the 'cd' builtin cannot change a directory because the length |
d233b485 | 7227 | of the pathname constructed from '$PWD' and the directory name |
74091dd4 | 7228 | supplied as an argument exceeds 'PATH_MAX' when all symbolic links |
d233b485 CR |
7229 | are expanded, 'cd' will fail instead of attempting to use only the |
7230 | supplied directory name. | |
7231 | ||
74091dd4 | 7232 | 51. The 'pwd' builtin verifies that the value it prints is the same as |
95732b49 | 7233 | the current directory, even if it is not asked to check the file |
a0c0a00f | 7234 | system with the '-P' option. |
95732b49 | 7235 | |
74091dd4 | 7236 | 52. When listing the history, the 'fc' builtin does not include an |
95732b49 JA |
7237 | indication of whether or not a history entry has been modified. |
7238 | ||
74091dd4 | 7239 | 53. The default editor used by 'fc' is 'ed'. |
95732b49 | 7240 | |
74091dd4 | 7241 | 54. The 'type' and 'command' builtins will not report a non-executable |
a0c0a00f CR |
7242 | file as having been found, though the shell will attempt to execute |
7243 | such a file if it is the only so-named file found in '$PATH'. | |
ccc6cda3 | 7244 | |
74091dd4 | 7245 | 55. The 'vi' editing mode will invoke the 'vi' editor directly when |
a0c0a00f CR |
7246 | the 'v' command is run, instead of checking '$VISUAL' and |
7247 | '$EDITOR'. | |
ccc6cda3 | 7248 | |
74091dd4 | 7249 | 56. When the 'xpg_echo' option is enabled, Bash does not attempt to |
a0c0a00f | 7250 | interpret any arguments to 'echo' as options. Each argument is |
95732b49 | 7251 | displayed, after escape characters are converted. |
28ef6c31 | 7252 | |
74091dd4 | 7253 | 57. The 'ulimit' builtin uses a block size of 512 bytes for the '-c' |
a0c0a00f | 7254 | and '-f' options. |
3185942a | 7255 | |
74091dd4 | 7256 | 58. The arrival of 'SIGCHLD' when a trap is set on 'SIGCHLD' does not |
a0c0a00f | 7257 | interrupt the 'wait' builtin and cause it to return immediately. |
0001803f CR |
7258 | The trap command is run once for each child that exits. |
7259 | ||
74091dd4 | 7260 | 59. The 'read' builtin may be interrupted by a signal for which a trap |
ac50fbac | 7261 | has been set. If Bash receives a trapped signal while executing |
a0c0a00f CR |
7262 | 'read', the trap handler executes and 'read' returns an exit status |
7263 | greater than 128. | |
28ef6c31 | 7264 | |
74091dd4 CR |
7265 | 60. The 'printf' builtin uses 'double' (via 'strtod') to convert |
7266 | arguments corresponding to floating point conversion specifiers, | |
7267 | instead of 'long double' if it's available. The 'L' length | |
7268 | modifier forces 'printf' to use 'long double' if it's available. | |
7269 | ||
7270 | 61. Bash removes an exited background process's status from the list | |
a0c0a00f | 7271 | of such statuses after the 'wait' builtin is used to obtain it. |
95732b49 | 7272 | |
a0c0a00f CR |
7273 | There is other POSIX behavior that Bash does not implement by default |
7274 | even when in POSIX mode. Specifically: | |
95732b49 | 7275 | |
a0c0a00f CR |
7276 | 1. The 'fc' builtin checks '$EDITOR' as a program to edit history |
7277 | entries if 'FCEDIT' is unset, rather than defaulting directly to | |
7278 | 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset. | |
95732b49 | 7279 | |
a0c0a00f CR |
7280 | 2. As noted above, Bash requires the 'xpg_echo' option to be enabled |
7281 | for the 'echo' builtin to be fully conformant. | |
95732b49 JA |
7282 | |
7283 | Bash can be configured to be POSIX-conformant by default, by | |
a0c0a00f | 7284 | specifying the '--enable-strict-posix-default' to 'configure' when |
95732b49 | 7285 | building (*note Optional Features::). |
28ef6c31 | 7286 | |
8868edaf CR |
7287 | \1f |
7288 | File: bashref.info, Node: Shell Compatibility Mode, Prev: Bash POSIX Mode, Up: Bash Features | |
7289 | ||
7290 | 6.12 Shell Compatibility Mode | |
7291 | ============================= | |
7292 | ||
74091dd4 | 7293 | Bash-4.0 introduced the concept of a "shell compatibility level", |
8868edaf CR |
7294 | specified as a set of options to the shopt builtin ('compat31', |
7295 | 'compat32', 'compat40', 'compat41', and so on). There is only one | |
7296 | current compatibility level - each option is mutually exclusive. The | |
7297 | compatibility level is intended to allow users to select behavior from | |
7298 | previous versions that is incompatible with newer versions while they | |
7299 | migrate scripts to use current features and behavior. It's intended to | |
7300 | be a temporary solution. | |
7301 | ||
7302 | This section does not mention behavior that is standard for a | |
7303 | particular version (e.g., setting 'compat32' means that quoting the rhs | |
7304 | of the regexp matching operator quotes special regexp characters in the | |
74091dd4 | 7305 | word, which is default behavior in bash-3.2 and subsequent versions). |
8868edaf CR |
7306 | |
7307 | If a user enables, say, 'compat32', it may affect the behavior of | |
7308 | other compatibility levels up to and including the current compatibility | |
7309 | level. The idea is that each compatibility level controls behavior that | |
7310 | changed in that version of Bash, but that behavior may have been present | |
7311 | in earlier versions. For instance, the change to use locale-based | |
7312 | comparisons with the '[[' command came in bash-4.1, and earlier versions | |
7313 | used ASCII-based comparisons, so enabling 'compat32' will enable | |
7314 | ASCII-based comparisons as well. That granularity may not be sufficient | |
7315 | for all uses, and as a result users should employ compatibility levels | |
7316 | carefully. Read the documentation for a particular feature to find out | |
7317 | the current behavior. | |
7318 | ||
7319 | Bash-4.3 introduced a new shell variable: 'BASH_COMPAT'. The value | |
7320 | assigned to this variable (a decimal version number like 4.2, or an | |
7321 | integer corresponding to the 'compat'NN option, like 42) determines the | |
7322 | compatibility level. | |
7323 | ||
7324 | Starting with bash-4.4, Bash has begun deprecating older | |
7325 | compatibility levels. Eventually, the options will be removed in favor | |
7326 | of 'BASH_COMPAT'. | |
7327 | ||
7328 | Bash-5.0 is the final version for which there will be an individual | |
7329 | shopt option for the previous version. Users should use 'BASH_COMPAT' | |
7330 | on bash-5.0 and later versions. | |
7331 | ||
7332 | The following table describes the behavior changes controlled by each | |
7333 | compatibility level setting. The 'compat'NN tag is used as shorthand | |
7334 | for setting the compatibility level to NN using one of the following | |
7335 | mechanisms. For versions prior to bash-5.0, the compatibility level may | |
7336 | be set using the corresponding 'compat'NN shopt option. For bash-4.3 | |
7337 | and later versions, the 'BASH_COMPAT' variable is preferred, and it is | |
7338 | required for bash-5.1 and later versions. | |
7339 | ||
7340 | 'compat31' | |
7341 | * quoting the rhs of the '[[' command's regexp matching operator | |
7342 | (=~) has no special effect | |
7343 | ||
7344 | 'compat32' | |
7345 | * interrupting a command list such as "a ; b ; c" causes the | |
7346 | execution of the next command in the list (in bash-4.0 and | |
7347 | later versions, the shell acts as if it received the | |
7348 | interrupt, so interrupting one command in a list aborts the | |
7349 | execution of the entire list) | |
7350 | ||
7351 | 'compat40' | |
7352 | * the '<' and '>' operators to the '[[' command do not consider | |
7353 | the current locale when comparing strings; they use ASCII | |
7354 | ordering. Bash versions prior to bash-4.1 use ASCII collation | |
7355 | and strcmp(3); bash-4.1 and later use the current locale's | |
7356 | collation sequence and strcoll(3). | |
7357 | ||
7358 | 'compat41' | |
7359 | * in posix mode, 'time' may be followed by options and still be | |
7360 | recognized as a reserved word (this is POSIX interpretation | |
7361 | 267) | |
7362 | * in posix mode, the parser requires that an even number of | |
7363 | single quotes occur in the WORD portion of a double-quoted | |
7364 | ${...} parameter expansion and treats them specially, so that | |
7365 | characters within the single quotes are considered quoted | |
7366 | (this is POSIX interpretation 221) | |
7367 | ||
7368 | 'compat42' | |
7369 | * the replacement string in double-quoted pattern substitution | |
7370 | does not undergo quote removal, as it does in versions after | |
7371 | bash-4.2 | |
7372 | * in posix mode, single quotes are considered special when | |
7373 | expanding the WORD portion of a double-quoted ${...} parameter | |
7374 | expansion and can be used to quote a closing brace or other | |
7375 | special character (this is part of POSIX interpretation 221); | |
7376 | in later versions, single quotes are not special within | |
7377 | double-quoted word expansions | |
7378 | ||
7379 | 'compat43' | |
7380 | * the shell does not print a warning message if an attempt is | |
7381 | made to use a quoted compound assignment as an argument to | |
74091dd4 CR |
7382 | declare (e.g., declare -a foo='(1 2)'). Later versions warn |
7383 | that this usage is deprecated | |
8868edaf CR |
7384 | * word expansion errors are considered non-fatal errors that |
7385 | cause the current command to fail, even in posix mode (the | |
7386 | default behavior is to make them fatal errors that cause the | |
7387 | shell to exit) | |
7388 | * when executing a shell function, the loop state | |
7389 | (while/until/etc.) is not reset, so 'break' or 'continue' in | |
7390 | that function will break or continue loops in the calling | |
7391 | context. Bash-4.4 and later reset the loop state to prevent | |
7392 | this | |
7393 | ||
7394 | 'compat44' | |
7395 | * the shell sets up the values used by 'BASH_ARGV' and | |
7396 | 'BASH_ARGC' so they can expand to the shell's positional | |
7397 | parameters even if extended debugging mode is not enabled | |
7398 | * a subshell inherits loops from its parent context, so 'break' | |
7399 | or 'continue' will cause the subshell to exit. Bash-5.0 and | |
7400 | later reset the loop state to prevent the exit | |
7401 | * variable assignments preceding builtins like 'export' and | |
7402 | 'readonly' that set attributes continue to affect variables | |
7403 | with the same name in the calling environment even if the | |
7404 | shell is not in posix mode | |
7405 | ||
7406 | 'compat50 (set using BASH_COMPAT)' | |
7407 | * Bash-5.1 changed the way '$RANDOM' is generated to introduce | |
7408 | slightly more randomness. If the shell compatibility level is | |
7409 | set to 50 or lower, it reverts to the method from bash-5.0 and | |
7410 | previous versions, so seeding the random number generator by | |
7411 | assigning a value to 'RANDOM' will produce the same sequence | |
7412 | as in bash-5.0 | |
7413 | * If the command hash table is empty, Bash versions prior to | |
7414 | bash-5.1 printed an informational message to that effect, even | |
7415 | when producing output that can be reused as input. Bash-5.1 | |
7416 | suppresses that message when the '-l' option is supplied. | |
7417 | ||
74091dd4 CR |
7418 | 'compat51 (set using BASH_COMPAT)' |
7419 | * The 'unset' builtin will unset the array 'a' given an argument | |
7420 | like 'a[@]'. Bash-5.2 will unset an element with key '@' | |
7421 | (associative arrays) or remove all the elements without | |
7422 | unsetting the array (indexed arrays) | |
7423 | * arithmetic commands ( ((...)) ) and the expressions in an | |
7424 | arithmetic for statement can be expanded more than once | |
7425 | * expressions used as arguments to arithmetic operators in the | |
7426 | '[[' conditional command can be expanded more than once | |
7427 | * the expressions in substring parameter brace expansion can be | |
7428 | expanded more than once | |
7429 | * the expressions in the $(( ... )) word expansion can be | |
7430 | expanded more than once | |
7431 | * arithmetic expressions used as indexed array subscripts can be | |
7432 | expanded more than once | |
7433 | * 'test -v', when given an argument of 'A[@]', where A is an | |
7434 | existing associative array, will return true if the array has | |
7435 | any set elements. Bash-5.2 will look for and report on a key | |
7436 | named '@' | |
7437 | * the ${PARAMETER[:]=VALUE} word expansion will return VALUE, | |
7438 | before any variable-specific transformations have been | |
7439 | performed (e.g., converting to lowercase). Bash-5.2 will | |
7440 | return the final value assigned to the variable. | |
7441 | * Parsing command substitutions will behave as if extended glob | |
7442 | (*note The Shopt Builtin::) is enabled, so that parsing a | |
7443 | command substitution containing an extglob pattern (say, as | |
7444 | part of a shell function) will not fail. This assumes the | |
7445 | intent is to enable extglob before the command is executed and | |
7446 | word expansions are performed. It will fail at word expansion | |
7447 | time if extglob hasn't been enabled by the time the command is | |
7448 | executed. | |
7449 | ||
ccc6cda3 | 7450 | \1f |
3185942a | 7451 | File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top |
ccc6cda3 | 7452 | |
b80f6443 JA |
7453 | 7 Job Control |
7454 | ************* | |
ccc6cda3 | 7455 | |
b80f6443 JA |
7456 | This chapter discusses what job control is, how it works, and how Bash |
7457 | allows you to access its facilities. | |
ccc6cda3 JA |
7458 | |
7459 | * Menu: | |
7460 | ||
7461 | * Job Control Basics:: How job control works. | |
7462 | * Job Control Builtins:: Bash builtin commands used to interact | |
7463 | with job control. | |
7464 | * Job Control Variables:: Variables Bash uses to customize job | |
7465 | control. | |
7466 | ||
7467 | \1f | |
7468 | File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control | |
7469 | ||
b80f6443 JA |
7470 | 7.1 Job Control Basics |
7471 | ====================== | |
ccc6cda3 | 7472 | |
b80f6443 | 7473 | Job control refers to the ability to selectively stop (suspend) the |
ccc6cda3 JA |
7474 | execution of processes and continue (resume) their execution at a later |
7475 | point. A user typically employs this facility via an interactive | |
0001803f CR |
7476 | interface supplied jointly by the operating system kernel's terminal |
7477 | driver and Bash. | |
ccc6cda3 JA |
7478 | |
7479 | The shell associates a JOB with each pipeline. It keeps a table of | |
a0c0a00f | 7480 | currently executing jobs, which may be listed with the 'jobs' command. |
cce855bc | 7481 | When Bash starts a job asynchronously, it prints a line that looks like: |
ccc6cda3 | 7482 | [1] 25647 |
a0c0a00f CR |
7483 | indicating that this job is job number 1 and that the process ID of the |
7484 | last process in the pipeline associated with this job is 25647. All of | |
7485 | the processes in a single pipeline are members of the same job. Bash | |
7486 | uses the JOB abstraction as the basis for job control. | |
ccc6cda3 JA |
7487 | |
7488 | To facilitate the implementation of the user interface to job | |
bb70624e JA |
7489 | control, the operating system maintains the notion of a current terminal |
7490 | process group ID. Members of this process group (processes whose | |
7491 | process group ID is equal to the current terminal process group ID) | |
a0c0a00f | 7492 | receive keyboard-generated signals such as 'SIGINT'. These processes |
bb70624e JA |
7493 | are said to be in the foreground. Background processes are those whose |
7494 | process group ID differs from the terminal's; such processes are immune | |
a0c0a00f CR |
7495 | to keyboard-generated signals. Only foreground processes are allowed to |
7496 | read from or, if the user so specifies with 'stty tostop', write to the | |
7497 | terminal. Background processes which attempt to read from (write to | |
7498 | when 'stty tostop' is in effect) the terminal are sent a 'SIGTTIN' | |
7499 | ('SIGTTOU') signal by the kernel's terminal driver, which, unless | |
0001803f | 7500 | caught, suspends the process. |
ccc6cda3 JA |
7501 | |
7502 | If the operating system on which Bash is running supports job | |
74091dd4 | 7503 | control, Bash contains facilities to use it. Typing the "suspend" |
a0c0a00f | 7504 | character (typically '^Z', Control-Z) while a process is running causes |
cce855bc | 7505 | that process to be stopped and returns control to Bash. Typing the |
74091dd4 CR |
7506 | "delayed suspend" character (typically '^Y', Control-Y) causes the |
7507 | process to be stopped when it attempts to read input from the terminal, | |
7508 | and control to be returned to Bash. The user then manipulates the state | |
7509 | of this job, using the 'bg' command to continue it in the background, | |
7510 | the 'fg' command to continue it in the foreground, or the 'kill' command | |
7511 | to kill it. A '^Z' takes effect immediately, and has the additional | |
7512 | side effect of causing pending output and typeahead to be discarded. | |
ccc6cda3 JA |
7513 | |
7514 | There are a number of ways to refer to a job in the shell. The | |
74091dd4 | 7515 | character '%' introduces a job specification ("jobspec"). |
a0c0a00f CR |
7516 | |
7517 | Job number 'n' may be referred to as '%n'. The symbols '%%' and '%+' | |
7518 | refer to the shell's notion of the current job, which is the last job | |
7519 | stopped while it was in the foreground or started in the background. A | |
7520 | single '%' (with no accompanying job specification) also refers to the | |
7521 | current job. The previous job may be referenced using '%-'. If there | |
7522 | is only a single job, '%+' and '%-' can both be used to refer to that | |
7523 | job. In output pertaining to jobs (e.g., the output of the 'jobs' | |
7524 | command), the current job is always flagged with a '+', and the previous | |
7525 | job with a '-'. | |
bb70624e JA |
7526 | |
7527 | A job may also be referred to using a prefix of the name used to | |
7528 | start it, or using a substring that appears in its command line. For | |
8868edaf CR |
7529 | example, '%ce' refers to a stopped job whose command name begins with |
7530 | 'ce'. Using '%?ce', on the other hand, refers to any job containing the | |
7531 | string 'ce' in its command line. If the prefix or substring matches | |
7532 | more than one job, Bash reports an error. | |
a0c0a00f CR |
7533 | |
7534 | Simply naming a job can be used to bring it into the foreground: '%1' | |
7535 | is a synonym for 'fg %1', bringing job 1 from the background into the | |
7536 | foreground. Similarly, '%1 &' resumes job 1 in the background, | |
7537 | equivalent to 'bg %1' | |
7538 | ||
7539 | The shell learns immediately whenever a job changes state. Normally, | |
7540 | Bash waits until it is about to print a prompt before reporting changes | |
7541 | in a job's status so as to not interrupt any other output. If the '-b' | |
7542 | option to the 'set' builtin is enabled, Bash reports such changes | |
7543 | immediately (*note The Set Builtin::). Any trap on 'SIGCHLD' is | |
7544 | executed for each child process that exits. | |
ccc6cda3 | 7545 | |
3185942a | 7546 | If an attempt to exit Bash is made while jobs are stopped, (or |
a0c0a00f CR |
7547 | running, if the 'checkjobs' option is enabled - see *note The Shopt |
7548 | Builtin::), the shell prints a warning message, and if the 'checkjobs' | |
7549 | option is enabled, lists the jobs and their statuses. The 'jobs' | |
cce855bc JA |
7550 | command may then be used to inspect their status. If a second attempt |
7551 | to exit is made without an intervening command, Bash does not print | |
3185942a | 7552 | another warning, and any stopped jobs are terminated. |
ccc6cda3 | 7553 | |
d233b485 CR |
7554 | When the shell is waiting for a job or process using the 'wait' |
7555 | builtin, and job control is enabled, 'wait' will return when the job | |
8868edaf CR |
7556 | changes state. The '-f' option causes 'wait' to wait until the job or |
7557 | process terminates before returning. | |
d233b485 | 7558 | |
ccc6cda3 JA |
7559 | \1f |
7560 | File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control | |
7561 | ||
b80f6443 JA |
7562 | 7.2 Job Control Builtins |
7563 | ======================== | |
ccc6cda3 | 7564 | |
a0c0a00f | 7565 | 'bg' |
95732b49 | 7566 | bg [JOBSPEC ...] |
ac50fbac | 7567 | |
95732b49 | 7568 | Resume each suspended job JOBSPEC in the background, as if it had |
a0c0a00f CR |
7569 | been started with '&'. If JOBSPEC is not supplied, the current job |
7570 | is used. The return status is zero unless it is run when job | |
95732b49 JA |
7571 | control is not enabled, or, when run with job control enabled, any |
7572 | JOBSPEC was not found or specifies a job that was started without | |
7573 | job control. | |
ccc6cda3 | 7574 | |
a0c0a00f | 7575 | 'fg' |
ccc6cda3 | 7576 | fg [JOBSPEC] |
ac50fbac | 7577 | |
cce855bc JA |
7578 | Resume the job JOBSPEC in the foreground and make it the current |
7579 | job. If JOBSPEC is not supplied, the current job is used. The | |
a0c0a00f CR |
7580 | return status is that of the command placed into the foreground, or |
7581 | non-zero if run when job control is disabled or, when run with job | |
7582 | control enabled, JOBSPEC does not specify a valid job or JOBSPEC | |
7583 | specifies a job that was started without job control. | |
ccc6cda3 | 7584 | |
a0c0a00f | 7585 | 'jobs' |
bb70624e | 7586 | jobs [-lnprs] [JOBSPEC] |
cce855bc | 7587 | jobs -x COMMAND [ARGUMENTS] |
ccc6cda3 JA |
7588 | |
7589 | The first form lists the active jobs. The options have the | |
7590 | following meanings: | |
7591 | ||
a0c0a00f | 7592 | '-l' |
cce855bc | 7593 | List process IDs in addition to the normal information. |
ccc6cda3 | 7594 | |
a0c0a00f | 7595 | '-n' |
ccc6cda3 | 7596 | Display information only about jobs that have changed status |
cce855bc | 7597 | since the user was last notified of their status. |
ccc6cda3 | 7598 | |
a0c0a00f | 7599 | '-p' |
ccc6cda3 JA |
7600 | List only the process ID of the job's process group leader. |
7601 | ||
a0c0a00f | 7602 | '-r' |
ac50fbac | 7603 | Display only running jobs. |
ccc6cda3 | 7604 | |
a0c0a00f | 7605 | '-s' |
ac50fbac | 7606 | Display only stopped jobs. |
ccc6cda3 | 7607 | |
a0c0a00f CR |
7608 | If JOBSPEC is given, output is restricted to information about that |
7609 | job. If JOBSPEC is not supplied, the status of all jobs is listed. | |
ccc6cda3 | 7610 | |
a0c0a00f | 7611 | If the '-x' option is supplied, 'jobs' replaces any JOBSPEC found |
ccc6cda3 JA |
7612 | in COMMAND or ARGUMENTS with the corresponding process group ID, |
7613 | and executes COMMAND, passing it ARGUMENTs, returning its exit | |
7614 | status. | |
7615 | ||
a0c0a00f | 7616 | 'kill' |
cce855bc | 7617 | kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID |
a0c0a00f | 7618 | kill -l|-L [EXIT_STATUS] |
ac50fbac | 7619 | |
ccc6cda3 | 7620 | Send a signal specified by SIGSPEC or SIGNUM to the process named |
cce855bc | 7621 | by job specification JOBSPEC or process ID PID. SIGSPEC is either |
a0c0a00f CR |
7622 | a case-insensitive signal name such as 'SIGINT' (with or without |
7623 | the 'SIG' prefix) or a signal number; SIGNUM is a signal number. | |
7624 | If SIGSPEC and SIGNUM are not present, 'SIGTERM' is used. The '-l' | |
7625 | option lists the signal names. If any arguments are supplied when | |
7626 | '-l' is given, the names of the signals corresponding to the | |
b80f6443 JA |
7627 | arguments are listed, and the return status is zero. EXIT_STATUS |
7628 | is a number specifying a signal number or the exit status of a | |
a0c0a00f CR |
7629 | process terminated by a signal. The '-L' option is equivalent to |
7630 | '-l'. The return status is zero if at least one signal was | |
7631 | successfully sent, or non-zero if an error occurs or an invalid | |
7632 | option is encountered. | |
ccc6cda3 | 7633 | |
a0c0a00f | 7634 | 'wait' |
8868edaf | 7635 | wait [-fn] [-p VARNAME] [JOBSPEC or PID ...] |
ac50fbac | 7636 | |
95732b49 JA |
7637 | Wait until the child process specified by each process ID PID or |
7638 | job specification JOBSPEC exits and return the exit status of the | |
7639 | last command waited for. If a job spec is given, all processes in | |
8868edaf CR |
7640 | the job are waited for. If no arguments are given, 'wait' waits |
7641 | for all running background jobs and the last-executed process | |
7642 | substitution, if its process id is the same as $!, and the return | |
7643 | status is zero. If the '-n' option is supplied, 'wait' waits for a | |
74091dd4 | 7644 | single job from the list of PIDs or JOBSPECs or, if no arguments |
8868edaf CR |
7645 | are supplied, any job, to complete and returns its exit status. If |
7646 | none of the supplied arguments is a child of the shell, or if no | |
7647 | arguments are supplied and the shell has no unwaited-for children, | |
7648 | the exit status is 127. If the '-p' option is supplied, the | |
7649 | process or job identifier of the job for which the exit status is | |
7650 | returned is assigned to the variable VARNAME named by the option | |
7651 | argument. The variable will be unset initially, before any | |
7652 | assignment. This is useful only when the '-n' option is supplied. | |
7653 | Supplying the '-f' option, when job control is enabled, forces | |
7654 | 'wait' to wait for each PID or JOBSPEC to terminate before | |
74091dd4 | 7655 | returning its status, instead of returning when it changes status. |
8868edaf | 7656 | If neither JOBSPEC nor PID specifies an active child process of the |
74091dd4 CR |
7657 | shell, the return status is 127. If 'wait' is interrupted by a |
7658 | signal, the return status will be greater than 128, as described | |
7659 | above (*note Signals::). Otherwise, the return status is the exit | |
7660 | status of the last process or job waited for. | |
ccc6cda3 | 7661 | |
a0c0a00f CR |
7662 | 'disown' |
7663 | disown [-ar] [-h] [JOBSPEC ... | PID ... ] | |
ac50fbac CR |
7664 | |
7665 | Without options, remove each JOBSPEC from the table of active jobs. | |
a0c0a00f CR |
7666 | If the '-h' option is given, the job is not removed from the table, |
7667 | but is marked so that 'SIGHUP' is not sent to the job if the shell | |
7668 | receives a 'SIGHUP'. If JOBSPEC is not present, and neither the | |
7669 | '-a' nor the '-r' option is supplied, the current job is used. If | |
7670 | no JOBSPEC is supplied, the '-a' option means to remove or mark all | |
7671 | jobs; the '-r' option without a JOBSPEC argument restricts | |
ac50fbac | 7672 | operation to running jobs. |
ccc6cda3 | 7673 | |
a0c0a00f | 7674 | 'suspend' |
ccc6cda3 | 7675 | suspend [-f] |
ac50fbac | 7676 | |
a0c0a00f | 7677 | Suspend the execution of this shell until it receives a 'SIGCONT' |
74091dd4 CR |
7678 | signal. A login shell, or a shell without job control enabled, |
7679 | cannot be suspended; the '-f' option can be used to override this | |
7680 | and force the suspension. The return status is 0 unless the shell | |
7681 | is a login shell or job control is not enabled and '-f' is not | |
7682 | supplied. | |
ccc6cda3 | 7683 | |
a0c0a00f CR |
7684 | When job control is not active, the 'kill' and 'wait' builtins do not |
7685 | accept JOBSPEC arguments. They must be supplied process IDs. | |
ccc6cda3 JA |
7686 | |
7687 | \1f | |
7688 | File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control | |
7689 | ||
b80f6443 JA |
7690 | 7.3 Job Control Variables |
7691 | ========================= | |
ccc6cda3 | 7692 | |
a0c0a00f | 7693 | 'auto_resume' |
ccc6cda3 JA |
7694 | This variable controls how the shell interacts with the user and |
7695 | job control. If this variable exists then single word simple | |
cce855bc JA |
7696 | commands without redirections are treated as candidates for |
7697 | resumption of an existing job. There is no ambiguity allowed; if | |
7698 | there is more than one job beginning with the string typed, then | |
7699 | the most recently accessed job will be selected. The name of a | |
a0c0a00f CR |
7700 | stopped job, in this context, is the command line used to start it. |
7701 | If this variable is set to the value 'exact', the string supplied | |
7702 | must match the name of a stopped job exactly; if set to | |
7703 | 'substring', the string supplied needs to match a substring of the | |
7704 | name of a stopped job. The 'substring' value provides | |
7705 | functionality analogous to the '%?' job ID (*note Job Control | |
28ef6c31 JA |
7706 | Basics::). If set to any other value, the supplied string must be |
7707 | a prefix of a stopped job's name; this provides functionality | |
a0c0a00f | 7708 | analogous to the '%' job ID. |
b80f6443 | 7709 | |
ccc6cda3 | 7710 | \1f |
3185942a | 7711 | File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top |
ccc6cda3 | 7712 | |
b80f6443 JA |
7713 | 8 Command Line Editing |
7714 | ********************** | |
ccc6cda3 | 7715 | |
b80f6443 | 7716 | This chapter describes the basic features of the GNU command line |
bb70624e JA |
7717 | editing interface. Command line editing is provided by the Readline |
7718 | library, which is used by several different programs, including Bash. | |
3185942a | 7719 | Command line editing is enabled by default when using an interactive |
a0c0a00f CR |
7720 | shell, unless the '--noediting' option is supplied at shell invocation. |
7721 | Line editing is also used when using the '-e' option to the 'read' | |
3185942a | 7722 | builtin command (*note Bash Builtins::). By default, the line editing |
495aee44 | 7723 | commands are similar to those of Emacs. A vi-style line editing |
3185942a | 7724 | interface is also available. Line editing can be enabled at any time |
a0c0a00f CR |
7725 | using the '-o emacs' or '-o vi' options to the 'set' builtin command |
7726 | (*note The Set Builtin::), or disabled using the '+o emacs' or '+o vi' | |
7727 | options to 'set'. | |
ccc6cda3 JA |
7728 | |
7729 | * Menu: | |
7730 | ||
bb70624e JA |
7731 | * Introduction and Notation:: Notation used in this text. |
7732 | * Readline Interaction:: The minimum set of commands for editing a line. | |
7733 | * Readline Init File:: Customizing Readline from a user's view. | |
7734 | * Bindable Readline Commands:: A description of most of the Readline commands | |
7735 | available for binding | |
7736 | * Readline vi Mode:: A short description of how to make Readline | |
7737 | behave like the vi editor. | |
bb70624e JA |
7738 | * Programmable Completion:: How to specify the possible completions for |
7739 | a specific command. | |
7740 | * Programmable Completion Builtins:: Builtin commands to specify how to | |
7741 | complete arguments for a particular command. | |
ac50fbac CR |
7742 | * A Programmable Completion Example:: An example shell function for |
7743 | generating possible completions. | |
ccc6cda3 JA |
7744 | |
7745 | \1f | |
bb70624e | 7746 | File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing |
ccc6cda3 | 7747 | |
b80f6443 JA |
7748 | 8.1 Introduction to Line Editing |
7749 | ================================ | |
ccc6cda3 | 7750 | |
b80f6443 | 7751 | The following paragraphs describe the notation used to represent |
bb70624e | 7752 | keystrokes. |
ccc6cda3 | 7753 | |
a0c0a00f | 7754 | The text 'C-k' is read as 'Control-K' and describes the character |
bb70624e | 7755 | produced when the <k> key is pressed while the Control key is depressed. |
ccc6cda3 | 7756 | |
a0c0a00f | 7757 | The text 'M-k' is read as 'Meta-K' and describes the character |
bb70624e JA |
7758 | produced when the Meta key (if you have one) is depressed, and the <k> |
7759 | key is pressed. The Meta key is labeled <ALT> on many keyboards. On | |
7760 | keyboards with two keys labeled <ALT> (usually to either side of the | |
7761 | space bar), the <ALT> on the left side is generally set to work as a | |
7762 | Meta key. The <ALT> key on the right may also be configured to work as | |
7763 | a Meta key or may be configured as some other modifier, such as a | |
7764 | Compose key for typing accented characters. | |
7765 | ||
7766 | If you do not have a Meta or <ALT> key, or another key working as a | |
7767 | Meta key, the identical keystroke can be generated by typing <ESC> | |
28ef6c31 JA |
7768 | _first_, and then typing <k>. Either process is known as "metafying" |
7769 | the <k> key. | |
bb70624e | 7770 | |
a0c0a00f CR |
7771 | The text 'M-C-k' is read as 'Meta-Control-k' and describes the |
7772 | character produced by "metafying" 'C-k'. | |
bb70624e | 7773 | |
a0c0a00f CR |
7774 | In addition, several keys have their own names. Specifically, <DEL>, |
7775 | <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen | |
7776 | in this text, or in an init file (*note Readline Init File::). If your | |
7777 | keyboard lacks a <LFD> key, typing <C-j> will produce the desired | |
7778 | character. The <RET> key may be labeled <Return> or <Enter> on some | |
7779 | keyboards. | |
ccc6cda3 JA |
7780 | |
7781 | \1f | |
bb70624e | 7782 | File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing |
cce855bc | 7783 | |
b80f6443 JA |
7784 | 8.2 Readline Interaction |
7785 | ======================== | |
cce855bc | 7786 | |
b80f6443 | 7787 | Often during an interactive session you type in a long line of text, |
bb70624e JA |
7788 | only to notice that the first word on the line is misspelled. The |
7789 | Readline library gives you a set of commands for manipulating the text | |
7790 | as you type it in, allowing you to just fix your typo, and not forcing | |
7791 | you to retype the majority of the line. Using these editing commands, | |
7792 | you move the cursor to the place that needs correction, and delete or | |
7793 | insert the text of the corrections. Then, when you are satisfied with | |
28ef6c31 JA |
7794 | the line, you simply press <RET>. You do not have to be at the end of |
7795 | the line to press <RET>; the entire line is accepted regardless of the | |
7796 | location of the cursor within the line. | |
cce855bc | 7797 | |
bb70624e | 7798 | * Menu: |
cce855bc | 7799 | |
bb70624e JA |
7800 | * Readline Bare Essentials:: The least you need to know about Readline. |
7801 | * Readline Movement Commands:: Moving about the input line. | |
7802 | * Readline Killing Commands:: How to delete text, and how to get it back! | |
7803 | * Readline Arguments:: Giving numeric arguments to commands. | |
7804 | * Searching:: Searching through previous lines. | |
cce855bc | 7805 | |
bb70624e JA |
7806 | \1f |
7807 | File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction | |
cce855bc | 7808 | |
b80f6443 JA |
7809 | 8.2.1 Readline Bare Essentials |
7810 | ------------------------------ | |
cce855bc | 7811 | |
b80f6443 JA |
7812 | In order to enter characters into the line, simply type them. The typed |
7813 | character appears where the cursor was, and then the cursor moves one | |
7814 | space to the right. If you mistype a character, you can use your erase | |
7815 | character to back up and delete the mistyped character. | |
cce855bc | 7816 | |
a0c0a00f CR |
7817 | Sometimes you may mistype a character, and not notice the error until |
7818 | you have typed several other characters. In that case, you can type | |
7819 | 'C-b' to move the cursor to the left, and then correct your mistake. | |
7820 | Afterwards, you can move the cursor to the right with 'C-f'. | |
cce855bc | 7821 | |
bb70624e | 7822 | When you add text in the middle of a line, you will notice that |
a0c0a00f CR |
7823 | characters to the right of the cursor are 'pushed over' to make room for |
7824 | the text that you have inserted. Likewise, when you delete text behind | |
7825 | the cursor, characters to the right of the cursor are 'pulled back' to | |
7826 | fill in the blank space created by the removal of the text. A list of | |
7827 | the bare essentials for editing the text of an input line follows. | |
cce855bc | 7828 | |
a0c0a00f CR |
7829 | 'C-b' |
7830 | Move back one character. | |
7831 | 'C-f' | |
bb70624e | 7832 | Move forward one character. |
bb70624e JA |
7833 | <DEL> or <Backspace> |
7834 | Delete the character to the left of the cursor. | |
a0c0a00f | 7835 | 'C-d' |
bb70624e | 7836 | Delete the character underneath the cursor. |
bb70624e JA |
7837 | Printing characters |
7838 | Insert the character into the line at the cursor. | |
a0c0a00f | 7839 | 'C-_' or 'C-x C-u' |
bb70624e JA |
7840 | Undo the last editing command. You can undo all the way back to an |
7841 | empty line. | |
cce855bc | 7842 | |
74091dd4 CR |
7843 | (Depending on your configuration, the <Backspace> key might be set to |
7844 | delete the character to the left of the cursor and the <DEL> key set to | |
7845 | delete the character underneath the cursor, like 'C-d', rather than the | |
bb70624e | 7846 | character to the left of the cursor.) |
cce855bc JA |
7847 | |
7848 | \1f | |
bb70624e | 7849 | File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction |
ccc6cda3 | 7850 | |
b80f6443 JA |
7851 | 8.2.2 Readline Movement Commands |
7852 | -------------------------------- | |
ccc6cda3 | 7853 | |
b80f6443 | 7854 | The above table describes the most basic keystrokes that you need in |
a0c0a00f CR |
7855 | order to do editing of the input line. For your convenience, many other |
7856 | commands have been added in addition to 'C-b', 'C-f', 'C-d', and <DEL>. | |
7857 | Here are some commands for moving more rapidly about the line. | |
ccc6cda3 | 7858 | |
a0c0a00f | 7859 | 'C-a' |
bb70624e | 7860 | Move to the start of the line. |
a0c0a00f | 7861 | 'C-e' |
bb70624e | 7862 | Move to the end of the line. |
a0c0a00f | 7863 | 'M-f' |
bb70624e JA |
7864 | Move forward a word, where a word is composed of letters and |
7865 | digits. | |
a0c0a00f | 7866 | 'M-b' |
bb70624e | 7867 | Move backward a word. |
a0c0a00f | 7868 | 'C-l' |
bb70624e | 7869 | Clear the screen, reprinting the current line at the top. |
ccc6cda3 | 7870 | |
a0c0a00f CR |
7871 | Notice how 'C-f' moves forward a character, while 'M-f' moves forward |
7872 | a word. It is a loose convention that control keystrokes operate on | |
7873 | characters while meta keystrokes operate on words. | |
ccc6cda3 JA |
7874 | |
7875 | \1f | |
bb70624e | 7876 | File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction |
ccc6cda3 | 7877 | |
b80f6443 JA |
7878 | 8.2.3 Readline Killing Commands |
7879 | ------------------------------- | |
ccc6cda3 | 7880 | |
b80f6443 | 7881 | "Killing" text means to delete the text from the line, but to save it |
a0c0a00f CR |
7882 | away for later use, usually by "yanking" (re-inserting) it back into the |
7883 | line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.) | |
ccc6cda3 | 7884 | |
a0c0a00f | 7885 | If the description for a command says that it 'kills' text, then you |
bb70624e JA |
7886 | can be sure that you can get the text back in a different (or the same) |
7887 | place later. | |
ccc6cda3 | 7888 | |
a0c0a00f CR |
7889 | When you use a kill command, the text is saved in a "kill-ring". Any |
7890 | number of consecutive kills save all of the killed text together, so | |
bb70624e JA |
7891 | that when you yank it back, you get it all. The kill ring is not line |
7892 | specific; the text that you killed on a previously typed line is | |
a0c0a00f | 7893 | available to be yanked back later, when you are typing another line. |
ccc6cda3 | 7894 | |
bb70624e | 7895 | Here is the list of commands for killing text. |
ccc6cda3 | 7896 | |
a0c0a00f | 7897 | 'C-k' |
bb70624e JA |
7898 | Kill the text from the current cursor position to the end of the |
7899 | line. | |
ccc6cda3 | 7900 | |
a0c0a00f | 7901 | 'M-d' |
bb70624e JA |
7902 | Kill from the cursor to the end of the current word, or, if between |
7903 | words, to the end of the next word. Word boundaries are the same | |
a0c0a00f | 7904 | as those used by 'M-f'. |
ccc6cda3 | 7905 | |
a0c0a00f | 7906 | 'M-<DEL>' |
74091dd4 CR |
7907 | Kill from the cursor to the start of the current word, or, if |
7908 | between words, to the start of the previous word. Word boundaries | |
7909 | are the same as those used by 'M-b'. | |
ccc6cda3 | 7910 | |
a0c0a00f CR |
7911 | 'C-w' |
7912 | Kill from the cursor to the previous whitespace. This is different | |
7913 | than 'M-<DEL>' because the word boundaries differ. | |
b80f6443 | 7914 | |
cce855bc JA |
7915 | Here is how to "yank" the text back into the line. Yanking means to |
7916 | copy the most-recently-killed text from the kill buffer. | |
ccc6cda3 | 7917 | |
a0c0a00f | 7918 | 'C-y' |
ccc6cda3 JA |
7919 | Yank the most recently killed text back into the buffer at the |
7920 | cursor. | |
7921 | ||
a0c0a00f | 7922 | 'M-y' |
ccc6cda3 | 7923 | Rotate the kill-ring, and yank the new top. You can only do this |
a0c0a00f | 7924 | if the prior command is 'C-y' or 'M-y'. |
ccc6cda3 JA |
7925 | |
7926 | \1f | |
7927 | File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction | |
7928 | ||
b80f6443 JA |
7929 | 8.2.4 Readline Arguments |
7930 | ------------------------ | |
ccc6cda3 | 7931 | |
b80f6443 | 7932 | You can pass numeric arguments to Readline commands. Sometimes the |
ccc6cda3 JA |
7933 | argument acts as a repeat count, other times it is the sign of the |
7934 | argument that is significant. If you pass a negative argument to a | |
7935 | command which normally acts in a forward direction, that command will | |
7936 | act in a backward direction. For example, to kill text back to the | |
a0c0a00f | 7937 | start of the line, you might type 'M-- C-k'. |
ccc6cda3 JA |
7938 | |
7939 | The general way to pass numeric arguments to a command is to type | |
a0c0a00f CR |
7940 | meta digits before the command. If the first 'digit' typed is a minus |
7941 | sign ('-'), then the sign of the argument will be negative. Once you | |
cce855bc | 7942 | have typed one meta digit to get the argument started, you can type the |
a0c0a00f CR |
7943 | remainder of the digits, and then the command. For example, to give the |
7944 | 'C-d' command an argument of 10, you could type 'M-1 0 C-d', which will | |
7945 | delete the next ten characters on the input line. | |
ccc6cda3 JA |
7946 | |
7947 | \1f | |
7948 | File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction | |
7949 | ||
b80f6443 JA |
7950 | 8.2.5 Searching for Commands in the History |
7951 | ------------------------------------------- | |
ccc6cda3 | 7952 | |
b80f6443 | 7953 | Readline provides commands for searching through the command history |
28ef6c31 | 7954 | (*note Bash History Facilities::) for lines containing a specified |
a0c0a00f | 7955 | string. There are two search modes: "incremental" and |
28ef6c31 | 7956 | "non-incremental". |
ccc6cda3 JA |
7957 | |
7958 | Incremental searches begin before the user has finished typing the | |
7959 | search string. As each character of the search string is typed, | |
cce855bc | 7960 | Readline displays the next entry from the history matching the string |
a0c0a00f CR |
7961 | typed so far. An incremental search requires only as many characters as |
7962 | needed to find the desired history entry. To search backward in the | |
7963 | history for a particular string, type 'C-r'. Typing 'C-s' searches | |
7964 | forward through the history. The characters present in the value of the | |
7965 | 'isearch-terminators' variable are used to terminate an incremental | |
bb70624e | 7966 | search. If that variable has not been assigned a value, the <ESC> and |
a0c0a00f CR |
7967 | 'C-J' characters will terminate an incremental search. 'C-g' will abort |
7968 | an incremental search and restore the original line. When the search is | |
7969 | terminated, the history entry containing the search string becomes the | |
7970 | current line. | |
7971 | ||
7972 | To find other matching entries in the history list, type 'C-r' or | |
7973 | 'C-s' as appropriate. This will search backward or forward in the | |
7974 | history for the next entry matching the search string typed so far. Any | |
7975 | other key sequence bound to a Readline command will terminate the search | |
7976 | and execute that command. For instance, a <RET> will terminate the | |
7977 | search and accept the line, thereby executing the command from the | |
28ef6c31 JA |
7978 | history list. A movement command will terminate the search, make the |
7979 | last line found the current line, and begin editing. | |
ccc6cda3 | 7980 | |
a0c0a00f CR |
7981 | Readline remembers the last incremental search string. If two 'C-r's |
7982 | are typed without any intervening characters defining a new search | |
7983 | string, any remembered search string is used. | |
f73dda09 | 7984 | |
ccc6cda3 JA |
7985 | Non-incremental searches read the entire search string before |
7986 | starting to search for matching history lines. The search string may be | |
cce855bc | 7987 | typed by the user or be part of the contents of the current line. |
ccc6cda3 JA |
7988 | |
7989 | \1f | |
7990 | File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing | |
7991 | ||
b80f6443 JA |
7992 | 8.3 Readline Init File |
7993 | ====================== | |
ccc6cda3 | 7994 | |
a0c0a00f CR |
7995 | Although the Readline library comes with a set of Emacs-like keybindings |
7996 | installed by default, it is possible to use a different set of | |
7997 | keybindings. Any user can customize programs that use Readline by | |
74091dd4 | 7998 | putting commands in an "inputrc" file, conventionally in their home |
bb70624e | 7999 | directory. The name of this file is taken from the value of the shell |
a0c0a00f CR |
8000 | variable 'INPUTRC'. If that variable is unset, the default is |
8001 | '~/.inputrc'. If that file does not exist or cannot be read, the | |
8868edaf CR |
8002 | ultimate default is '/etc/inputrc'. The 'bind' builtin command can also |
8003 | be used to set Readline keybindings and variables. *Note Bash | |
8004 | Builtins::. | |
ccc6cda3 JA |
8005 | |
8006 | When a program which uses the Readline library starts up, the init | |
8007 | file is read, and the key bindings are set. | |
8008 | ||
a0c0a00f | 8009 | In addition, the 'C-x C-r' command re-reads this init file, thus |
ccc6cda3 JA |
8010 | incorporating any changes that you might have made to it. |
8011 | ||
8012 | * Menu: | |
8013 | ||
8014 | * Readline Init File Syntax:: Syntax for the commands in the inputrc file. | |
8015 | ||
8016 | * Conditional Init Constructs:: Conditional key bindings in the inputrc file. | |
8017 | ||
8018 | * Sample Init File:: An example inputrc file. | |
8019 | ||
8020 | \1f | |
8021 | File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File | |
8022 | ||
b80f6443 JA |
8023 | 8.3.1 Readline Init File Syntax |
8024 | ------------------------------- | |
ccc6cda3 | 8025 | |
a0c0a00f CR |
8026 | There are only a few basic constructs allowed in the Readline init file. |
8027 | Blank lines are ignored. Lines beginning with a '#' are comments. | |
8028 | Lines beginning with a '$' indicate conditional constructs (*note | |
8029 | Conditional Init Constructs::). Other lines denote variable settings | |
8030 | and key bindings. | |
ccc6cda3 JA |
8031 | |
8032 | Variable Settings | |
cce855bc | 8033 | You can modify the run-time behavior of Readline by altering the |
a0c0a00f | 8034 | values of variables in Readline using the 'set' command within the |
28ef6c31 JA |
8035 | init file. The syntax is simple: |
8036 | ||
8037 | set VARIABLE VALUE | |
8038 | ||
a0c0a00f CR |
8039 | Here, for example, is how to change from the default Emacs-like key |
8040 | binding to use 'vi' line editing commands: | |
ccc6cda3 JA |
8041 | |
8042 | set editing-mode vi | |
8043 | ||
28ef6c31 | 8044 | Variable names and values, where appropriate, are recognized |
95732b49 JA |
8045 | without regard to case. Unrecognized variable names are ignored. |
8046 | ||
8047 | Boolean variables (those that can be set to on or off) are set to | |
a0c0a00f CR |
8048 | on if the value is null or empty, ON (case-insensitive), or 1. Any |
8049 | other value results in the variable being set to off. | |
28ef6c31 | 8050 | |
a0c0a00f CR |
8051 | The 'bind -V' command lists the current Readline variable names and |
8052 | values. *Note Bash Builtins::. | |
bb70624e | 8053 | |
cce855bc JA |
8054 | A great deal of run-time behavior is changeable with the following |
8055 | variables. | |
ccc6cda3 | 8056 | |
74091dd4 CR |
8057 | 'active-region-start-color' |
8058 | A string variable that controls the text color and background | |
8059 | when displaying the text in the active region (see the | |
8060 | description of 'enable-active-region' below). This string | |
8061 | must not take up any physical character positions on the | |
8062 | display, so it should consist only of terminal escape | |
8063 | sequences. It is output to the terminal before displaying the | |
8064 | text in the active region. This variable is reset to the | |
8065 | default value whenever the terminal type changes. The default | |
8066 | value is the string that puts the terminal in standout mode, | |
8067 | as obtained from the terminal's terminfo description. A | |
8068 | sample value might be '\e[01;33m'. | |
8069 | ||
8070 | 'active-region-end-color' | |
8071 | A string variable that "undoes" the effects of | |
8072 | 'active-region-start-color' and restores "normal" terminal | |
8073 | display appearance after displaying text in the active region. | |
8074 | This string must not take up any physical character positions | |
8075 | on the display, so it should consist only of terminal escape | |
8076 | sequences. It is output to the terminal after displaying the | |
8077 | text in the active region. This variable is reset to the | |
8078 | default value whenever the terminal type changes. The default | |
8079 | value is the string that restores the terminal from standout | |
8080 | mode, as obtained from the terminal's terminfo description. A | |
8081 | sample value might be '\e[0m'. | |
8082 | ||
a0c0a00f CR |
8083 | 'bell-style' |
8084 | Controls what happens when Readline wants to ring the terminal | |
8085 | bell. If set to 'none', Readline never rings the bell. If | |
8086 | set to 'visible', Readline uses a visible bell if one is | |
8087 | available. If set to 'audible' (the default), Readline | |
8088 | attempts to ring the terminal's bell. | |
8089 | ||
8090 | 'bind-tty-special-chars' | |
8091 | If set to 'on' (the default), Readline attempts to bind the | |
8092 | control characters treated specially by the kernel's terminal | |
8093 | driver to their Readline equivalents. | |
8094 | ||
8095 | 'blink-matching-paren' | |
8096 | If set to 'on', Readline attempts to briefly move the cursor | |
8097 | to an opening parenthesis when a closing parenthesis is | |
8098 | inserted. The default is 'off'. | |
8099 | ||
8100 | 'colored-completion-prefix' | |
8101 | If set to 'on', when listing completions, Readline displays | |
8102 | the common prefix of the set of possible completions using a | |
8103 | different color. The color definitions are taken from the | |
74091dd4 CR |
8104 | value of the 'LS_COLORS' environment variable. If there is a |
8105 | color definition in 'LS_COLORS' for the custom suffix | |
8106 | 'readline-colored-completion-prefix', Readline uses this color | |
8107 | for the common prefix instead of its default. The default is | |
a0c0a00f CR |
8108 | 'off'. |
8109 | ||
8110 | 'colored-stats' | |
8111 | If set to 'on', Readline displays possible completions using | |
ac50fbac | 8112 | different colors to indicate their file type. The color |
a0c0a00f CR |
8113 | definitions are taken from the value of the 'LS_COLORS' |
8114 | environment variable. The default is 'off'. | |
ac50fbac | 8115 | |
a0c0a00f | 8116 | 'comment-begin' |
ccc6cda3 | 8117 | The string to insert at the beginning of the line when the |
a0c0a00f CR |
8118 | 'insert-comment' command is executed. The default value is |
8119 | '"#"'. | |
ccc6cda3 | 8120 | |
a0c0a00f | 8121 | 'completion-display-width' |
495aee44 CR |
8122 | The number of screen columns used to display possible matches |
8123 | when performing completion. The value is ignored if it is | |
8124 | less than 0 or greater than the terminal screen width. A | |
8125 | value of 0 will cause matches to be displayed one per line. | |
8126 | The default value is -1. | |
8127 | ||
a0c0a00f CR |
8128 | 'completion-ignore-case' |
8129 | If set to 'on', Readline performs filename matching and | |
cce855bc | 8130 | completion in a case-insensitive fashion. The default value |
a0c0a00f | 8131 | is 'off'. |
cce855bc | 8132 | |
a0c0a00f CR |
8133 | 'completion-map-case' |
8134 | If set to 'on', and COMPLETION-IGNORE-CASE is enabled, | |
8135 | Readline treats hyphens ('-') and underscores ('_') as | |
495aee44 | 8136 | equivalent when performing case-insensitive filename matching |
d233b485 | 8137 | and completion. The default value is 'off'. |
495aee44 | 8138 | |
a0c0a00f | 8139 | 'completion-prefix-display-length' |
3185942a JA |
8140 | The length in characters of the common prefix of a list of |
8141 | possible completions that is displayed without modification. | |
8142 | When set to a value greater than zero, common prefixes longer | |
8143 | than this value are replaced with an ellipsis when displaying | |
8144 | possible completions. | |
8145 | ||
a0c0a00f | 8146 | 'completion-query-items' |
ccc6cda3 | 8147 | The number of possible completions that determines when the |
b80f6443 JA |
8148 | user is asked whether the list of possibilities should be |
8149 | displayed. If the number of possible completions is greater | |
8868edaf CR |
8150 | than or equal to this value, Readline will ask whether or not |
8151 | the user wishes to view them; otherwise, they are simply | |
8152 | listed. This variable must be set to an integer value greater | |
74091dd4 CR |
8153 | than or equal to zero. A zero value means Readline should |
8154 | never ask; negative values are treated as zero. The default | |
8155 | limit is '100'. | |
ccc6cda3 | 8156 | |
a0c0a00f CR |
8157 | 'convert-meta' |
8158 | If set to 'on', Readline will convert characters with the | |
cce855bc | 8159 | eighth bit set to an ASCII key sequence by stripping the |
bb70624e | 8160 | eighth bit and prefixing an <ESC> character, converting them |
a0c0a00f CR |
8161 | to a meta-prefixed key sequence. The default value is 'on', |
8162 | but will be set to 'off' if the locale is one that contains | |
74091dd4 CR |
8163 | eight-bit characters. This variable is dependent on the |
8164 | 'LC_CTYPE' locale category, and may change if the locale is | |
8165 | changed. | |
ccc6cda3 | 8166 | |
a0c0a00f CR |
8167 | 'disable-completion' |
8168 | If set to 'On', Readline will inhibit word completion. | |
8169 | Completion characters will be inserted into the line as if | |
8170 | they had been mapped to 'self-insert'. The default is 'off'. | |
ccc6cda3 | 8171 | |
a0c0a00f CR |
8172 | 'echo-control-characters' |
8173 | When set to 'on', on operating systems that indicate they | |
74091dd4 | 8174 | support it, Readline echoes a character corresponding to a |
a0c0a00f | 8175 | signal generated from the keyboard. The default is 'on'. |
0001803f | 8176 | |
a0c0a00f CR |
8177 | 'editing-mode' |
8178 | The 'editing-mode' variable controls which default set of key | |
8179 | bindings is used. By default, Readline starts up in Emacs | |
8180 | editing mode, where the keystrokes are most similar to Emacs. | |
8181 | This variable can be set to either 'emacs' or 'vi'. | |
8182 | ||
8183 | 'emacs-mode-string' | |
d233b485 CR |
8184 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is |
8185 | displayed immediately before the last line of the primary | |
8186 | prompt when emacs editing mode is active. The value is | |
8187 | expanded like a key binding, so the standard set of meta- and | |
8188 | control prefixes and backslash escape sequences is available. | |
8189 | Use the '\1' and '\2' escapes to begin and end sequences of | |
8190 | non-printing characters, which can be used to embed a terminal | |
8191 | control sequence into the mode string. The default is '@'. | |
a0c0a00f | 8192 | |
74091dd4 CR |
8193 | 'enable-active-region' |
8194 | The "point" is the current cursor position, and "mark" refers | |
8195 | to a saved cursor position (*note Commands For Moving::). The | |
8196 | text between the point and mark is referred to as the | |
8197 | "region". When this variable is set to 'On', Readline allows | |
8198 | certain commands to designate the region as "active". When | |
8199 | the region is active, Readline highlights the text in the | |
8200 | region using the value of the 'active-region-start-color', | |
8201 | which defaults to the string that enables the terminal's | |
8202 | standout mode. The active region shows the text inserted by | |
8203 | bracketed-paste and any matching text found by incremental and | |
8204 | non-incremental history searches. The default is 'On'. | |
8205 | ||
a0c0a00f | 8206 | 'enable-bracketed-paste' |
74091dd4 CR |
8207 | When set to 'On', Readline configures the terminal to insert |
8208 | each paste into the editing buffer as a single string of | |
8209 | characters, instead of treating each character as if it had | |
8210 | been read from the keyboard. This is called putting the | |
8211 | terminal into "bracketed paste mode"; it prevents Readline | |
8212 | from executing any editing commands bound to key sequences | |
8213 | appearing in the pasted text. The default is 'On'. | |
a0c0a00f CR |
8214 | |
8215 | 'enable-keypad' | |
8216 | When set to 'on', Readline will try to enable the application | |
ccc6cda3 | 8217 | keypad when it is called. Some systems need this to enable |
a0c0a00f | 8218 | the arrow keys. The default is 'off'. |
ccc6cda3 | 8219 | |
a0c0a00f CR |
8220 | 'enable-meta-key' |
8221 | When set to 'on', Readline will try to enable any meta | |
8222 | modifier key the terminal claims to support when it is called. | |
8223 | On many terminals, the meta key is used to send eight-bit | |
8224 | characters. The default is 'on'. | |
0001803f | 8225 | |
a0c0a00f CR |
8226 | 'expand-tilde' |
8227 | If set to 'on', tilde expansion is performed when Readline | |
8228 | attempts word completion. The default is 'off'. | |
ccc6cda3 | 8229 | |
a0c0a00f CR |
8230 | 'history-preserve-point' |
8231 | If set to 'on', the history code attempts to place the point | |
3185942a | 8232 | (the current cursor position) at the same location on each |
a0c0a00f CR |
8233 | history line retrieved with 'previous-history' or |
8234 | 'next-history'. The default is 'off'. | |
8235 | ||
8236 | 'history-size' | |
8237 | Set the maximum number of history entries saved in the history | |
8238 | list. If set to zero, any existing history entries are | |
8239 | deleted and no new entries are saved. If set to a value less | |
8240 | than zero, the number of history entries is not limited. By | |
8241 | default, the number of history entries is not limited. If an | |
8242 | attempt is made to set HISTORY-SIZE to a non-numeric value, | |
8243 | the maximum number of history entries will be set to 500. | |
8244 | ||
8245 | 'horizontal-scroll-mode' | |
8246 | This variable can be set to either 'on' or 'off'. Setting it | |
8247 | to 'on' means that the text of the lines being edited will | |
ccc6cda3 JA |
8248 | scroll horizontally on a single screen line when they are |
8249 | longer than the width of the screen, instead of wrapping onto | |
8868edaf CR |
8250 | a new screen line. This variable is automatically set to 'on' |
8251 | for terminals of height 1. By default, this variable is set | |
8252 | to 'off'. | |
ccc6cda3 | 8253 | |
a0c0a00f CR |
8254 | 'input-meta' |
8255 | If set to 'on', Readline will enable eight-bit input (it will | |
28ef6c31 | 8256 | not clear the eighth bit in the characters it reads), |
b72432fd | 8257 | regardless of what the terminal claims it can support. The |
a0c0a00f CR |
8258 | default value is 'off', but Readline will set it to 'on' if |
8259 | the locale contains eight-bit characters. The name | |
74091dd4 CR |
8260 | 'meta-flag' is a synonym for this variable. This variable is |
8261 | dependent on the 'LC_CTYPE' locale category, and may change if | |
8262 | the locale is changed. | |
b72432fd | 8263 | |
a0c0a00f | 8264 | 'isearch-terminators' |
b72432fd JA |
8265 | The string of characters that should terminate an incremental |
8266 | search without subsequently executing the character as a | |
28ef6c31 | 8267 | command (*note Searching::). If this variable has not been |
a0c0a00f | 8268 | given a value, the characters <ESC> and 'C-J' will terminate |
b72432fd JA |
8269 | an incremental search. |
8270 | ||
a0c0a00f | 8271 | 'keymap' |
ccc6cda3 | 8272 | Sets Readline's idea of the current keymap for key binding |
d233b485 | 8273 | commands. Built-in 'keymap' names are 'emacs', |
a0c0a00f CR |
8274 | 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move', |
8275 | 'vi-command', and 'vi-insert'. 'vi' is equivalent to | |
8276 | 'vi-command' ('vi-move' is also a synonym); 'emacs' is | |
d233b485 CR |
8277 | equivalent to 'emacs-standard'. Applications may add |
8278 | additional names. The default value is 'emacs'. The value of | |
8279 | the 'editing-mode' variable also affects the default keymap. | |
a0c0a00f CR |
8280 | |
8281 | 'keyseq-timeout' | |
8282 | Specifies the duration Readline will wait for a character when | |
8283 | reading an ambiguous key sequence (one that can form a | |
8284 | complete key sequence using the input read so far, or can take | |
8285 | additional input to complete a longer key sequence). If no | |
8286 | input is received within the timeout, Readline will use the | |
8287 | shorter but complete key sequence. Readline uses this value | |
8288 | to determine whether or not input is available on the current | |
8289 | input source ('rl_instream' by default). The value is | |
8290 | specified in milliseconds, so a value of 1000 means that | |
ac50fbac CR |
8291 | Readline will wait one second for additional input. If this |
8292 | variable is set to a value less than or equal to zero, or to a | |
8293 | non-numeric value, Readline will wait until another key is | |
a0c0a00f CR |
8294 | pressed to decide which key sequence to complete. The default |
8295 | value is '500'. | |
ac50fbac | 8296 | |
a0c0a00f CR |
8297 | 'mark-directories' |
8298 | If set to 'on', completed directory names have a slash | |
8299 | appended. The default is 'on'. | |
ccc6cda3 | 8300 | |
a0c0a00f CR |
8301 | 'mark-modified-lines' |
8302 | This variable, when set to 'on', causes Readline to display an | |
8303 | asterisk ('*') at the start of history lines which have been | |
8304 | modified. This variable is 'off' by default. | |
ccc6cda3 | 8305 | |
a0c0a00f CR |
8306 | 'mark-symlinked-directories' |
8307 | If set to 'on', completed names which are symbolic links to | |
7117c2d2 | 8308 | directories have a slash appended (subject to the value of |
a0c0a00f | 8309 | 'mark-directories'). The default is 'off'. |
7117c2d2 | 8310 | |
a0c0a00f CR |
8311 | 'match-hidden-files' |
8312 | This variable, when set to 'on', causes Readline to match | |
8313 | files whose names begin with a '.' (hidden files) when | |
8314 | performing filename completion. If set to 'off', the leading | |
8315 | '.' must be supplied by the user in the filename to be | |
8316 | completed. This variable is 'on' by default. | |
495aee44 | 8317 | |
a0c0a00f CR |
8318 | 'menu-complete-display-prefix' |
8319 | If set to 'on', menu completion displays the common prefix of | |
495aee44 | 8320 | the list of possible completions (which may be empty) before |
a0c0a00f | 8321 | cycling through the list. The default is 'off'. |
f73dda09 | 8322 | |
a0c0a00f CR |
8323 | 'output-meta' |
8324 | If set to 'on', Readline will display characters with the | |
ccc6cda3 | 8325 | eighth bit set directly rather than as a meta-prefixed escape |
a0c0a00f | 8326 | sequence. The default is 'off', but Readline will set it to |
74091dd4 CR |
8327 | 'on' if the locale contains eight-bit characters. This |
8328 | variable is dependent on the 'LC_CTYPE' locale category, and | |
8329 | may change if the locale is changed. | |
ccc6cda3 | 8330 | |
a0c0a00f CR |
8331 | 'page-completions' |
8332 | If set to 'on', Readline uses an internal 'more'-like pager to | |
8333 | display a screenful of possible completions at a time. This | |
8334 | variable is 'on' by default. | |
7117c2d2 | 8335 | |
a0c0a00f CR |
8336 | 'print-completions-horizontally' |
8337 | If set to 'on', Readline will display completions with matches | |
cce855bc | 8338 | sorted horizontally in alphabetical order, rather than down |
a0c0a00f | 8339 | the screen. The default is 'off'. |
cce855bc | 8340 | |
a0c0a00f CR |
8341 | 'revert-all-at-newline' |
8342 | If set to 'on', Readline will undo all changes to history | |
8343 | lines before returning when 'accept-line' is executed. By | |
3185942a | 8344 | default, history lines may be modified and retain individual |
74091dd4 CR |
8345 | undo lists across calls to 'readline()'. The default is |
8346 | 'off'. | |
3185942a | 8347 | |
a0c0a00f | 8348 | 'show-all-if-ambiguous' |
ccc6cda3 | 8349 | This alters the default behavior of the completion functions. |
a0c0a00f | 8350 | If set to 'on', words which have more than one possible |
ccc6cda3 | 8351 | completion cause the matches to be listed immediately instead |
a0c0a00f | 8352 | of ringing the bell. The default value is 'off'. |
ccc6cda3 | 8353 | |
a0c0a00f | 8354 | 'show-all-if-unmodified' |
b80f6443 JA |
8355 | This alters the default behavior of the completion functions |
8356 | in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to | |
a0c0a00f | 8357 | 'on', words which have more than one possible completion |
b80f6443 JA |
8358 | without any possible partial completion (the possible |
8359 | completions don't share a common prefix) cause the matches to | |
8360 | be listed immediately instead of ringing the bell. The | |
a0c0a00f CR |
8361 | default value is 'off'. |
8362 | ||
8363 | 'show-mode-in-prompt' | |
d233b485 | 8364 | If set to 'on', add a string to the beginning of the prompt |
a0c0a00f | 8365 | indicating the editing mode: emacs, vi command, or vi |
d233b485 CR |
8366 | insertion. The mode strings are user-settable (e.g., |
8367 | EMACS-MODE-STRING). The default value is 'off'. | |
a0c0a00f CR |
8368 | |
8369 | 'skip-completed-text' | |
8370 | If set to 'on', this alters the default completion behavior | |
8371 | when inserting a single match into the line. It's only active | |
8372 | when performing completion in the middle of a word. If | |
74091dd4 | 8373 | enabled, Readline does not insert characters from the |
a0c0a00f CR |
8374 | completion that match characters after point in the word being |
8375 | completed, so portions of the word following the cursor are | |
8376 | not duplicated. For instance, if this is enabled, attempting | |
8377 | completion when the cursor is after the 'e' in 'Makefile' will | |
8378 | result in 'Makefile' rather than 'Makefilefile', assuming | |
8379 | there is a single possible completion. The default value is | |
8380 | 'off'. | |
8381 | ||
8382 | 'vi-cmd-mode-string' | |
d233b485 CR |
8383 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is |
8384 | displayed immediately before the last line of the primary | |
8385 | prompt when vi editing mode is active and in command mode. | |
8386 | The value is expanded like a key binding, so the standard set | |
8387 | of meta- and control prefixes and backslash escape sequences | |
8388 | is available. Use the '\1' and '\2' escapes to begin and end | |
8389 | sequences of non-printing characters, which can be used to | |
8390 | embed a terminal control sequence into the mode string. The | |
8391 | default is '(cmd)'. | |
a0c0a00f CR |
8392 | |
8393 | 'vi-ins-mode-string' | |
d233b485 CR |
8394 | If the SHOW-MODE-IN-PROMPT variable is enabled, this string is |
8395 | displayed immediately before the last line of the primary | |
8396 | prompt when vi editing mode is active and in insertion mode. | |
8397 | The value is expanded like a key binding, so the standard set | |
8398 | of meta- and control prefixes and backslash escape sequences | |
8399 | is available. Use the '\1' and '\2' escapes to begin and end | |
8400 | sequences of non-printing characters, which can be used to | |
8401 | embed a terminal control sequence into the mode string. The | |
8402 | default is '(ins)'. | |
a0c0a00f CR |
8403 | |
8404 | 'visible-stats' | |
8405 | If set to 'on', a character denoting a file's type is appended | |
8406 | to the filename when listing possible completions. The | |
8407 | default is 'off'. | |
b80f6443 | 8408 | |
ccc6cda3 | 8409 | Key Bindings |
a0c0a00f CR |
8410 | The syntax for controlling key bindings in the init file is simple. |
8411 | First you need to find the name of the command that you want to | |
8412 | change. The following sections contain tables of the command name, | |
8413 | the default keybinding, if any, and a short description of what the | |
8414 | command does. | |
ccc6cda3 | 8415 | |
28ef6c31 JA |
8416 | Once you know the name of the command, simply place on a line in |
8417 | the init file the name of the key you wish to bind the command to, | |
0628567a JA |
8418 | a colon, and then the name of the command. There can be no space |
8419 | between the key name and the colon - that will be interpreted as | |
8420 | part of the key name. The name of the key can be expressed in | |
8421 | different ways, depending on what you find most comfortable. | |
28ef6c31 | 8422 | |
74091dd4 | 8423 | In addition to command names, Readline allows keys to be bound to a |
a0c0a00f | 8424 | string that is inserted when the key is pressed (a MACRO). |
ccc6cda3 | 8425 | |
a0c0a00f | 8426 | The 'bind -p' command displays Readline function names and bindings |
74091dd4 | 8427 | in a format that can be put directly into an initialization file. |
a0c0a00f | 8428 | *Note Bash Builtins::. |
bb70624e | 8429 | |
a0c0a00f | 8430 | KEYNAME: FUNCTION-NAME or MACRO |
ccc6cda3 JA |
8431 | KEYNAME is the name of a key spelled out in English. For |
8432 | example: | |
8433 | Control-u: universal-argument | |
8434 | Meta-Rubout: backward-kill-word | |
8435 | Control-o: "> output" | |
8436 | ||
d233b485 | 8437 | In the example above, 'C-u' is bound to the function |
a0c0a00f CR |
8438 | 'universal-argument', 'M-DEL' is bound to the function |
8439 | 'backward-kill-word', and 'C-o' is bound to run the macro | |
ccc6cda3 | 8440 | expressed on the right hand side (that is, to insert the text |
a0c0a00f | 8441 | '> output' into the line). |
ccc6cda3 | 8442 | |
28ef6c31 JA |
8443 | A number of symbolic character names are recognized while |
8444 | processing this key binding syntax: DEL, ESC, ESCAPE, LFD, | |
8445 | NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB. | |
8446 | ||
a0c0a00f | 8447 | "KEYSEQ": FUNCTION-NAME or MACRO |
ccc6cda3 JA |
8448 | KEYSEQ differs from KEYNAME above in that strings denoting an |
8449 | entire key sequence can be specified, by placing the key | |
8450 | sequence in double quotes. Some GNU Emacs style key escapes | |
8451 | can be used, as in the following example, but the special | |
8452 | character names are not recognized. | |
8453 | ||
8454 | "\C-u": universal-argument | |
8455 | "\C-x\C-r": re-read-init-file | |
8456 | "\e[11~": "Function Key 1" | |
8457 | ||
a0c0a00f CR |
8458 | In the above example, 'C-u' is again bound to the function |
8459 | 'universal-argument' (just as it was in the first example), | |
8460 | ''C-x' 'C-r'' is bound to the function 're-read-init-file', | |
8461 | and '<ESC> <[> <1> <1> <~>' is bound to insert the text | |
8462 | 'Function Key 1'. | |
b80f6443 | 8463 | |
cce855bc JA |
8464 | The following GNU Emacs style escape sequences are available when |
8465 | specifying key sequences: | |
8466 | ||
a0c0a00f | 8467 | '\C-' |
cce855bc | 8468 | control prefix |
a0c0a00f | 8469 | '\M-' |
cce855bc | 8470 | meta prefix |
a0c0a00f | 8471 | '\e' |
cce855bc | 8472 | an escape character |
a0c0a00f | 8473 | '\\' |
cce855bc | 8474 | backslash |
a0c0a00f | 8475 | '\"' |
bb70624e | 8476 | <">, a double quotation mark |
a0c0a00f | 8477 | '\'' |
bb70624e | 8478 | <'>, a single quote or apostrophe |
cce855bc JA |
8479 | |
8480 | In addition to the GNU Emacs style escape sequences, a second set | |
8481 | of backslash escapes is available: | |
ccc6cda3 | 8482 | |
a0c0a00f | 8483 | '\a' |
cce855bc | 8484 | alert (bell) |
a0c0a00f | 8485 | '\b' |
cce855bc | 8486 | backspace |
a0c0a00f | 8487 | '\d' |
cce855bc | 8488 | delete |
a0c0a00f | 8489 | '\f' |
cce855bc | 8490 | form feed |
a0c0a00f | 8491 | '\n' |
cce855bc | 8492 | newline |
a0c0a00f | 8493 | '\r' |
cce855bc | 8494 | carriage return |
a0c0a00f | 8495 | '\t' |
cce855bc | 8496 | horizontal tab |
a0c0a00f | 8497 | '\v' |
cce855bc | 8498 | vertical tab |
a0c0a00f | 8499 | '\NNN' |
f73dda09 | 8500 | the eight-bit character whose value is the octal value NNN |
cce855bc | 8501 | (one to three digits) |
a0c0a00f | 8502 | '\xHH' |
f73dda09 JA |
8503 | the eight-bit character whose value is the hexadecimal value |
8504 | HH (one or two hex digits) | |
8505 | ||
cce855bc JA |
8506 | When entering the text of a macro, single or double quotes must be |
8507 | used to indicate a macro definition. Unquoted text is assumed to | |
8508 | be a function name. In the macro body, the backslash escapes | |
8509 | described above are expanded. Backslash will quote any other | |
a0c0a00f CR |
8510 | character in the macro text, including '"' and '''. For example, |
8511 | the following binding will make ''C-x' \' insert a single '\' into | |
cce855bc JA |
8512 | the line: |
8513 | "\C-x\\": "\\" | |
ccc6cda3 JA |
8514 | |
8515 | \1f | |
8516 | File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File | |
8517 | ||
b80f6443 JA |
8518 | 8.3.2 Conditional Init Constructs |
8519 | --------------------------------- | |
ccc6cda3 | 8520 | |
b80f6443 | 8521 | Readline implements a facility similar in spirit to the conditional |
a0c0a00f CR |
8522 | compilation features of the C preprocessor which allows key bindings and |
8523 | variable settings to be performed as the result of tests. There are | |
8524 | four parser directives used. | |
8525 | ||
8526 | '$if' | |
8527 | The '$if' construct allows bindings to be made based on the editing | |
8528 | mode, the terminal being used, or the application using Readline. | |
d233b485 CR |
8529 | The text of the test, after any comparison operator, extends to the |
8530 | end of the line; unless otherwise noted, no characters are required | |
8531 | to isolate it. | |
a0c0a00f CR |
8532 | |
8533 | 'mode' | |
8534 | The 'mode=' form of the '$if' directive is used to test | |
8535 | whether Readline is in 'emacs' or 'vi' mode. This may be used | |
8536 | in conjunction with the 'set keymap' command, for instance, to | |
8537 | set bindings in the 'emacs-standard' and 'emacs-ctlx' keymaps | |
8538 | only if Readline is starting out in 'emacs' mode. | |
8539 | ||
8540 | 'term' | |
8541 | The 'term=' form may be used to include terminal-specific key | |
ccc6cda3 JA |
8542 | bindings, perhaps to bind the key sequences output by the |
8543 | terminal's function keys. The word on the right side of the | |
a0c0a00f CR |
8544 | '=' is tested against both the full name of the terminal and |
8545 | the portion of the terminal name before the first '-'. This | |
8546 | allows 'sun' to match both 'sun' and 'sun-cmd', for instance. | |
ccc6cda3 | 8547 | |
d233b485 CR |
8548 | 'version' |
8549 | The 'version' test may be used to perform comparisons against | |
8550 | specific Readline versions. The 'version' expands to the | |
8551 | current Readline version. The set of comparison operators | |
8552 | includes '=' (and '=='), '!=', '<=', '>=', '<', and '>'. The | |
8553 | version number supplied on the right side of the operator | |
8554 | consists of a major version number, an optional decimal point, | |
8555 | and an optional minor version (e.g., '7.1'). If the minor | |
8556 | version is omitted, it is assumed to be '0'. The operator may | |
8557 | be separated from the string 'version' and from the version | |
8558 | number argument by whitespace. The following example sets a | |
8559 | variable if the Readline version being used is 7.0 or newer: | |
8560 | $if version >= 7.0 | |
8561 | set show-mode-in-prompt on | |
8562 | $endif | |
8563 | ||
a0c0a00f | 8564 | 'application' |
ccc6cda3 JA |
8565 | The APPLICATION construct is used to include |
8566 | application-specific settings. Each program using the | |
8567 | Readline library sets the APPLICATION NAME, and you can test | |
28ef6c31 JA |
8568 | for a particular value. This could be used to bind key |
8569 | sequences to functions useful for a specific program. For | |
8570 | instance, the following command adds a key sequence that | |
8571 | quotes the current or previous word in Bash: | |
ccc6cda3 JA |
8572 | $if Bash |
8573 | # Quote the current or previous word | |
8574 | "\C-xq": "\eb\"\ef\"" | |
8575 | $endif | |
8576 | ||
d233b485 CR |
8577 | 'variable' |
8578 | The VARIABLE construct provides simple equality tests for | |
8579 | Readline variables and values. The permitted comparison | |
8580 | operators are '=', '==', and '!='. The variable name must be | |
8581 | separated from the comparison operator by whitespace; the | |
8582 | operator may be separated from the value on the right hand | |
8583 | side by whitespace. Both string and boolean variables may be | |
8584 | tested. Boolean variables must be tested against the values | |
8585 | ON and OFF. The following example is equivalent to the | |
8586 | 'mode=emacs' test described above: | |
8587 | $if editing-mode == emacs | |
8588 | set show-mode-in-prompt on | |
8589 | $endif | |
8590 | ||
a0c0a00f CR |
8591 | '$endif' |
8592 | This command, as seen in the previous example, terminates an '$if' | |
cce855bc | 8593 | command. |
ccc6cda3 | 8594 | |
a0c0a00f CR |
8595 | '$else' |
8596 | Commands in this branch of the '$if' directive are executed if the | |
ccc6cda3 JA |
8597 | test fails. |
8598 | ||
a0c0a00f | 8599 | '$include' |
cce855bc | 8600 | This directive takes a single filename as an argument and reads |
28ef6c31 | 8601 | commands and bindings from that file. For example, the following |
a0c0a00f | 8602 | directive reads from '/etc/inputrc': |
cce855bc JA |
8603 | $include /etc/inputrc |
8604 | ||
ccc6cda3 JA |
8605 | \1f |
8606 | File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File | |
8607 | ||
b80f6443 JA |
8608 | 8.3.3 Sample Init File |
8609 | ---------------------- | |
ccc6cda3 | 8610 | |
b80f6443 JA |
8611 | Here is an example of an INPUTRC file. This illustrates key binding, |
8612 | variable assignment, and conditional syntax. | |
ccc6cda3 | 8613 | |
ccc6cda3 | 8614 | # This file controls the behaviour of line input editing for |
7117c2d2 JA |
8615 | # programs that use the GNU Readline library. Existing |
8616 | # programs include FTP, Bash, and GDB. | |
ccc6cda3 JA |
8617 | # |
8618 | # You can re-read the inputrc file with C-x C-r. | |
8619 | # Lines beginning with '#' are comments. | |
cce855bc | 8620 | # |
ac50fbac | 8621 | # First, include any system-wide bindings and variable |
7117c2d2 | 8622 | # assignments from /etc/Inputrc |
cce855bc | 8623 | $include /etc/Inputrc |
b80f6443 | 8624 | |
ccc6cda3 JA |
8625 | # |
8626 | # Set various bindings for emacs mode. | |
b80f6443 | 8627 | |
ccc6cda3 | 8628 | set editing-mode emacs |
b80f6443 | 8629 | |
ccc6cda3 | 8630 | $if mode=emacs |
b80f6443 | 8631 | |
ccc6cda3 | 8632 | Meta-Control-h: backward-kill-word Text after the function name is ignored |
b80f6443 | 8633 | |
ccc6cda3 JA |
8634 | # |
8635 | # Arrow keys in keypad mode | |
8636 | # | |
d166f048 JA |
8637 | #"\M-OD": backward-char |
8638 | #"\M-OC": forward-char | |
8639 | #"\M-OA": previous-history | |
8640 | #"\M-OB": next-history | |
ccc6cda3 JA |
8641 | # |
8642 | # Arrow keys in ANSI mode | |
8643 | # | |
d166f048 JA |
8644 | "\M-[D": backward-char |
8645 | "\M-[C": forward-char | |
8646 | "\M-[A": previous-history | |
8647 | "\M-[B": next-history | |
ccc6cda3 JA |
8648 | # |
8649 | # Arrow keys in 8 bit keypad mode | |
8650 | # | |
d166f048 JA |
8651 | #"\M-\C-OD": backward-char |
8652 | #"\M-\C-OC": forward-char | |
8653 | #"\M-\C-OA": previous-history | |
8654 | #"\M-\C-OB": next-history | |
ccc6cda3 JA |
8655 | # |
8656 | # Arrow keys in 8 bit ANSI mode | |
8657 | # | |
d166f048 JA |
8658 | #"\M-\C-[D": backward-char |
8659 | #"\M-\C-[C": forward-char | |
8660 | #"\M-\C-[A": previous-history | |
8661 | #"\M-\C-[B": next-history | |
b80f6443 | 8662 | |
ccc6cda3 | 8663 | C-q: quoted-insert |
b80f6443 | 8664 | |
ccc6cda3 | 8665 | $endif |
b80f6443 | 8666 | |
ccc6cda3 JA |
8667 | # An old-style binding. This happens to be the default. |
8668 | TAB: complete | |
b80f6443 | 8669 | |
ccc6cda3 JA |
8670 | # Macros that are convenient for shell interaction |
8671 | $if Bash | |
8672 | # edit the path | |
8673 | "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f" | |
7117c2d2 JA |
8674 | # prepare to type a quoted word -- |
8675 | # insert open and close double quotes | |
ccc6cda3 JA |
8676 | # and move to just after the open quote |
8677 | "\C-x\"": "\"\"\C-b" | |
7117c2d2 JA |
8678 | # insert a backslash (testing backslash escapes |
8679 | # in sequences and macros) | |
ccc6cda3 JA |
8680 | "\C-x\\": "\\" |
8681 | # Quote the current or previous word | |
8682 | "\C-xq": "\eb\"\ef\"" | |
8683 | # Add a binding to refresh the line, which is unbound | |
8684 | "\C-xr": redraw-current-line | |
8685 | # Edit variable on current line. | |
8686 | "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y=" | |
8687 | $endif | |
b80f6443 | 8688 | |
ccc6cda3 JA |
8689 | # use a visible bell if one is available |
8690 | set bell-style visible | |
b80f6443 | 8691 | |
ccc6cda3 JA |
8692 | # don't strip characters to 7 bits when reading |
8693 | set input-meta on | |
b80f6443 | 8694 | |
7117c2d2 JA |
8695 | # allow iso-latin1 characters to be inserted rather |
8696 | # than converted to prefix-meta sequences | |
ccc6cda3 | 8697 | set convert-meta off |
b80f6443 | 8698 | |
7117c2d2 JA |
8699 | # display characters with the eighth bit set directly |
8700 | # rather than as meta-prefixed characters | |
ccc6cda3 | 8701 | set output-meta on |
b80f6443 | 8702 | |
8868edaf CR |
8703 | # if there are 150 or more possible completions for a word, |
8704 | # ask whether or not the user wants to see all of them | |
ccc6cda3 | 8705 | set completion-query-items 150 |
b80f6443 | 8706 | |
ccc6cda3 JA |
8707 | # For FTP |
8708 | $if Ftp | |
8709 | "\C-xg": "get \M-?" | |
8710 | "\C-xt": "put \M-?" | |
8711 | "\M-.": yank-last-arg | |
8712 | $endif | |
8713 | ||
8714 | \1f | |
bb70624e JA |
8715 | File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing |
8716 | ||
b80f6443 JA |
8717 | 8.4 Bindable Readline Commands |
8718 | ============================== | |
bb70624e JA |
8719 | |
8720 | * Menu: | |
8721 | ||
8722 | * Commands For Moving:: Moving about the line. | |
8723 | * Commands For History:: Getting at previous lines. | |
8724 | * Commands For Text:: Commands for changing text. | |
8725 | * Commands For Killing:: Commands for killing and yanking. | |
8726 | * Numeric Arguments:: Specifying numeric arguments, repeat counts. | |
8727 | * Commands For Completion:: Getting Readline to do the typing for you. | |
8728 | * Keyboard Macros:: Saving and re-executing typed characters | |
8729 | * Miscellaneous Commands:: Other miscellaneous commands. | |
8730 | ||
a0c0a00f CR |
8731 | This section describes Readline commands that may be bound to key |
8732 | sequences. You can list your key bindings by executing 'bind -P' or, | |
8733 | for a more terse format, suitable for an INPUTRC file, 'bind -p'. | |
28ef6c31 JA |
8734 | (*Note Bash Builtins::.) Command names without an accompanying key |
8735 | sequence are unbound by default. | |
bb70624e | 8736 | |
28ef6c31 | 8737 | In the following descriptions, "point" refers to the current cursor |
a0c0a00f CR |
8738 | position, and "mark" refers to a cursor position saved by the 'set-mark' |
8739 | command. The text between the point and mark is referred to as the | |
8740 | "region". | |
bb70624e JA |
8741 | |
8742 | \1f | |
8743 | File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands | |
8744 | ||
b80f6443 JA |
8745 | 8.4.1 Commands For Moving |
8746 | ------------------------- | |
bb70624e | 8747 | |
a0c0a00f | 8748 | 'beginning-of-line (C-a)' |
bb70624e JA |
8749 | Move to the start of the current line. |
8750 | ||
a0c0a00f | 8751 | 'end-of-line (C-e)' |
bb70624e JA |
8752 | Move to the end of the line. |
8753 | ||
a0c0a00f | 8754 | 'forward-char (C-f)' |
bb70624e JA |
8755 | Move forward a character. |
8756 | ||
a0c0a00f | 8757 | 'backward-char (C-b)' |
bb70624e JA |
8758 | Move back a character. |
8759 | ||
a0c0a00f | 8760 | 'forward-word (M-f)' |
bb70624e JA |
8761 | Move forward to the end of the next word. Words are composed of |
8762 | letters and digits. | |
8763 | ||
a0c0a00f | 8764 | 'backward-word (M-b)' |
bb70624e JA |
8765 | Move back to the start of the current or previous word. Words are |
8766 | composed of letters and digits. | |
8767 | ||
8868edaf | 8768 | 'shell-forward-word (M-C-f)' |
3185942a JA |
8769 | Move forward to the end of the next word. Words are delimited by |
8770 | non-quoted shell metacharacters. | |
8771 | ||
8868edaf | 8772 | 'shell-backward-word (M-C-b)' |
3185942a JA |
8773 | Move back to the start of the current or previous word. Words are |
8774 | delimited by non-quoted shell metacharacters. | |
8775 | ||
d233b485 CR |
8776 | 'previous-screen-line ()' |
8777 | Attempt to move point to the same physical screen column on the | |
8778 | previous physical screen line. This will not have the desired | |
8779 | effect if the current Readline line does not take up more than one | |
8780 | physical line or if point is not greater than the length of the | |
8781 | prompt plus the screen width. | |
8782 | ||
8783 | 'next-screen-line ()' | |
8784 | Attempt to move point to the same physical screen column on the | |
8785 | next physical screen line. This will not have the desired effect | |
8786 | if the current Readline line does not take up more than one | |
8787 | physical line or if the length of the current Readline line is not | |
8788 | greater than the length of the prompt plus the screen width. | |
8789 | ||
8868edaf CR |
8790 | 'clear-display (M-C-l)' |
8791 | Clear the screen and, if possible, the terminal's scrollback | |
8792 | buffer, then redraw the current line, leaving the current line at | |
8793 | the top of the screen. | |
8794 | ||
a0c0a00f | 8795 | 'clear-screen (C-l)' |
8868edaf | 8796 | Clear the screen, then redraw the current line, leaving the current |
bb70624e JA |
8797 | line at the top of the screen. |
8798 | ||
a0c0a00f | 8799 | 'redraw-current-line ()' |
bb70624e JA |
8800 | Refresh the current line. By default, this is unbound. |
8801 | ||
8802 | \1f | |
8803 | File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands | |
8804 | ||
b80f6443 JA |
8805 | 8.4.2 Commands For Manipulating The History |
8806 | ------------------------------------------- | |
bb70624e | 8807 | |
a0c0a00f | 8808 | 'accept-line (Newline or Return)' |
bb70624e JA |
8809 | Accept the line regardless of where the cursor is. If this line is |
8810 | non-empty, add it to the history list according to the setting of | |
a0c0a00f | 8811 | the 'HISTCONTROL' and 'HISTIGNORE' variables. If this line is a |
28ef6c31 JA |
8812 | modified history line, then restore the history line to its |
8813 | original state. | |
bb70624e | 8814 | |
a0c0a00f CR |
8815 | 'previous-history (C-p)' |
8816 | Move 'back' through the history list, fetching the previous | |
28ef6c31 | 8817 | command. |
bb70624e | 8818 | |
a0c0a00f CR |
8819 | 'next-history (C-n)' |
8820 | Move 'forward' through the history list, fetching the next command. | |
bb70624e | 8821 | |
a0c0a00f | 8822 | 'beginning-of-history (M-<)' |
bb70624e JA |
8823 | Move to the first line in the history. |
8824 | ||
a0c0a00f | 8825 | 'end-of-history (M->)' |
bb70624e JA |
8826 | Move to the end of the input history, i.e., the line currently |
8827 | being entered. | |
8828 | ||
a0c0a00f CR |
8829 | 'reverse-search-history (C-r)' |
8830 | Search backward starting at the current line and moving 'up' | |
bb70624e | 8831 | through the history as necessary. This is an incremental search. |
8868edaf CR |
8832 | This command sets the region to the matched text and activates the |
8833 | mark. | |
bb70624e | 8834 | |
a0c0a00f CR |
8835 | 'forward-search-history (C-s)' |
8836 | Search forward starting at the current line and moving 'down' | |
8837 | through the history as necessary. This is an incremental search. | |
8868edaf CR |
8838 | This command sets the region to the matched text and activates the |
8839 | mark. | |
bb70624e | 8840 | |
a0c0a00f CR |
8841 | 'non-incremental-reverse-search-history (M-p)' |
8842 | Search backward starting at the current line and moving 'up' | |
8843 | through the history as necessary using a non-incremental search for | |
8844 | a string supplied by the user. The search string may match | |
8845 | anywhere in a history line. | |
bb70624e | 8846 | |
a0c0a00f CR |
8847 | 'non-incremental-forward-search-history (M-n)' |
8848 | Search forward starting at the current line and moving 'down' | |
8849 | through the history as necessary using a non-incremental search for | |
8850 | a string supplied by the user. The search string may match | |
8851 | anywhere in a history line. | |
bb70624e | 8852 | |
a0c0a00f | 8853 | 'history-search-forward ()' |
bb70624e | 8854 | Search forward through the history for the string of characters |
ac50fbac CR |
8855 | between the start of the current line and the point. The search |
8856 | string must match at the beginning of a history line. This is a | |
bb70624e JA |
8857 | non-incremental search. By default, this command is unbound. |
8858 | ||
a0c0a00f | 8859 | 'history-search-backward ()' |
bb70624e | 8860 | Search backward through the history for the string of characters |
ac50fbac CR |
8861 | between the start of the current line and the point. The search |
8862 | string must match at the beginning of a history line. This is a | |
8863 | non-incremental search. By default, this command is unbound. | |
8864 | ||
d233b485 | 8865 | 'history-substring-search-forward ()' |
ac50fbac CR |
8866 | Search forward through the history for the string of characters |
8867 | between the start of the current line and the point. The search | |
8868 | string may match anywhere in a history line. This is a | |
8869 | non-incremental search. By default, this command is unbound. | |
8870 | ||
d233b485 | 8871 | 'history-substring-search-backward ()' |
ac50fbac CR |
8872 | Search backward through the history for the string of characters |
8873 | between the start of the current line and the point. The search | |
8874 | string may match anywhere in a history line. This is a | |
bb70624e JA |
8875 | non-incremental search. By default, this command is unbound. |
8876 | ||
a0c0a00f | 8877 | 'yank-nth-arg (M-C-y)' |
bb70624e | 8878 | Insert the first argument to the previous command (usually the |
28ef6c31 JA |
8879 | second word on the previous line) at point. With an argument N, |
8880 | insert the Nth word from the previous command (the words in the | |
8881 | previous command begin with word 0). A negative argument inserts | |
95732b49 | 8882 | the Nth word from the end of the previous command. Once the |
a0c0a00f | 8883 | argument N is computed, the argument is extracted as if the '!N' |
95732b49 | 8884 | history expansion had been specified. |
bb70624e | 8885 | |
a0c0a00f | 8886 | 'yank-last-arg (M-. or M-_)' |
bb70624e | 8887 | Insert last argument to the previous command (the last word of the |
495aee44 | 8888 | previous history entry). With a numeric argument, behave exactly |
a0c0a00f CR |
8889 | like 'yank-nth-arg'. Successive calls to 'yank-last-arg' move back |
8890 | through the history list, inserting the last word (or the word | |
8891 | specified by the argument to the first call) of each line in turn. | |
8892 | Any numeric argument supplied to these successive calls determines | |
8893 | the direction to move through the history. A negative argument | |
8894 | switches the direction through the history (back or forward). The | |
8895 | history expansion facilities are used to extract the last argument, | |
8896 | as if the '!$' history expansion had been specified. | |
b80f6443 | 8897 | |
8868edaf CR |
8898 | 'operate-and-get-next (C-o)' |
8899 | Accept the current line for return to the calling application as if | |
8900 | a newline had been entered, and fetch the next line relative to the | |
8901 | current line from the history for editing. A numeric argument, if | |
8902 | supplied, specifies the history entry to use instead of the current | |
8903 | line. | |
8904 | ||
74091dd4 CR |
8905 | 'fetch-history ()' |
8906 | With a numeric argument, fetch that entry from the history list and | |
8907 | make it the current line. Without an argument, move back to the | |
8908 | first entry in the history list. | |
8909 | ||
bb70624e JA |
8910 | \1f |
8911 | File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands | |
8912 | ||
b80f6443 JA |
8913 | 8.4.3 Commands For Changing Text |
8914 | -------------------------------- | |
bb70624e | 8915 | |
a0c0a00f | 8916 | 'end-of-file (usually C-d)' |
ac50fbac | 8917 | The character indicating end-of-file as set, for example, by |
a0c0a00f | 8918 | 'stty'. If this character is read when there are no characters on |
ac50fbac CR |
8919 | the line, and point is at the beginning of the line, Readline |
8920 | interprets it as the end of input and returns EOF. | |
8921 | ||
a0c0a00f | 8922 | 'delete-char (C-d)' |
ac50fbac | 8923 | Delete the character at point. If this function is bound to the |
a0c0a00f | 8924 | same character as the tty EOF character, as 'C-d' commonly is, see |
ac50fbac | 8925 | above for the effects. |
bb70624e | 8926 | |
a0c0a00f | 8927 | 'backward-delete-char (Rubout)' |
bb70624e JA |
8928 | Delete the character behind the cursor. A numeric argument means |
8929 | to kill the characters instead of deleting them. | |
8930 | ||
a0c0a00f | 8931 | 'forward-backward-delete-char ()' |
bb70624e JA |
8932 | Delete the character under the cursor, unless the cursor is at the |
8933 | end of the line, in which case the character behind the cursor is | |
8934 | deleted. By default, this is not bound to a key. | |
8935 | ||
a0c0a00f | 8936 | 'quoted-insert (C-q or C-v)' |
bb70624e | 8937 | Add the next character typed to the line verbatim. This is how to |
a0c0a00f | 8938 | insert key sequences like 'C-q', for example. |
bb70624e | 8939 | |
a0c0a00f | 8940 | 'self-insert (a, b, A, 1, !, ...)' |
bb70624e JA |
8941 | Insert yourself. |
8942 | ||
a0c0a00f CR |
8943 | 'bracketed-paste-begin ()' |
8944 | This function is intended to be bound to the "bracketed paste" | |
8945 | escape sequence sent by some terminals, and such a binding is | |
8946 | assigned by default. It allows Readline to insert the pasted text | |
8947 | as a single unit without treating each character as if it had been | |
8948 | read from the keyboard. The characters are inserted as if each one | |
d233b485 | 8949 | was bound to 'self-insert' instead of executing any editing |
a0c0a00f CR |
8950 | commands. |
8951 | ||
8868edaf CR |
8952 | Bracketed paste sets the region (the characters between point and |
8953 | the mark) to the inserted text. It uses the concept of an _active | |
8954 | mark_: when the mark is active, Readline redisplay uses the | |
8955 | terminal's standout mode to denote the region. | |
8956 | ||
a0c0a00f | 8957 | 'transpose-chars (C-t)' |
bb70624e JA |
8958 | Drag the character before the cursor forward over the character at |
8959 | the cursor, moving the cursor forward as well. If the insertion | |
8960 | point is at the end of the line, then this transposes the last two | |
8961 | characters of the line. Negative arguments have no effect. | |
8962 | ||
a0c0a00f | 8963 | 'transpose-words (M-t)' |
bb70624e | 8964 | Drag the word before point past the word after point, moving point |
f73dda09 JA |
8965 | past that word as well. If the insertion point is at the end of |
8966 | the line, this transposes the last two words on the line. | |
bb70624e | 8967 | |
a0c0a00f | 8968 | 'upcase-word (M-u)' |
bb70624e JA |
8969 | Uppercase the current (or following) word. With a negative |
8970 | argument, uppercase the previous word, but do not move the cursor. | |
8971 | ||
a0c0a00f | 8972 | 'downcase-word (M-l)' |
bb70624e JA |
8973 | Lowercase the current (or following) word. With a negative |
8974 | argument, lowercase the previous word, but do not move the cursor. | |
8975 | ||
a0c0a00f | 8976 | 'capitalize-word (M-c)' |
bb70624e JA |
8977 | Capitalize the current (or following) word. With a negative |
8978 | argument, capitalize the previous word, but do not move the cursor. | |
8979 | ||
a0c0a00f | 8980 | 'overwrite-mode ()' |
7117c2d2 JA |
8981 | Toggle overwrite mode. With an explicit positive numeric argument, |
8982 | switches to overwrite mode. With an explicit non-positive numeric | |
8983 | argument, switches to insert mode. This command affects only | |
a0c0a00f CR |
8984 | 'emacs' mode; 'vi' mode does overwrite differently. Each call to |
8985 | 'readline()' starts in insert mode. | |
7117c2d2 | 8986 | |
a0c0a00f | 8987 | In overwrite mode, characters bound to 'self-insert' replace the |
7117c2d2 | 8988 | text at point rather than pushing the text to the right. |
a0c0a00f | 8989 | Characters bound to 'backward-delete-char' replace the character |
7117c2d2 JA |
8990 | before point with a space. |
8991 | ||
8992 | By default, this command is unbound. | |
8993 | ||
bb70624e JA |
8994 | \1f |
8995 | File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands | |
8996 | ||
b80f6443 JA |
8997 | 8.4.4 Killing And Yanking |
8998 | ------------------------- | |
bb70624e | 8999 | |
a0c0a00f | 9000 | 'kill-line (C-k)' |
8868edaf CR |
9001 | Kill the text from point to the end of the line. With a negative |
9002 | numeric argument, kill backward from the cursor to the beginning of | |
9003 | the current line. | |
bb70624e | 9004 | |
a0c0a00f CR |
9005 | 'backward-kill-line (C-x Rubout)' |
9006 | Kill backward from the cursor to the beginning of the current line. | |
8868edaf CR |
9007 | With a negative numeric argument, kill forward from the cursor to |
9008 | the end of the current line. | |
bb70624e | 9009 | |
a0c0a00f | 9010 | 'unix-line-discard (C-u)' |
bb70624e JA |
9011 | Kill backward from the cursor to the beginning of the current line. |
9012 | ||
a0c0a00f | 9013 | 'kill-whole-line ()' |
28ef6c31 JA |
9014 | Kill all characters on the current line, no matter where point is. |
9015 | By default, this is unbound. | |
bb70624e | 9016 | |
a0c0a00f | 9017 | 'kill-word (M-d)' |
bb70624e JA |
9018 | Kill from point to the end of the current word, or if between |
9019 | words, to the end of the next word. Word boundaries are the same | |
a0c0a00f | 9020 | as 'forward-word'. |
bb70624e | 9021 | |
a0c0a00f | 9022 | 'backward-kill-word (M-<DEL>)' |
bb70624e | 9023 | Kill the word behind point. Word boundaries are the same as |
a0c0a00f | 9024 | 'backward-word'. |
bb70624e | 9025 | |
8868edaf | 9026 | 'shell-kill-word (M-C-d)' |
3185942a JA |
9027 | Kill from point to the end of the current word, or if between |
9028 | words, to the end of the next word. Word boundaries are the same | |
a0c0a00f | 9029 | as 'shell-forward-word'. |
3185942a | 9030 | |
a0c0a00f | 9031 | 'shell-backward-kill-word ()' |
3185942a | 9032 | Kill the word behind point. Word boundaries are the same as |
a0c0a00f | 9033 | 'shell-backward-word'. |
3185942a | 9034 | |
8868edaf CR |
9035 | 'shell-transpose-words (M-C-t)' |
9036 | Drag the word before point past the word after point, moving point | |
9037 | past that word as well. If the insertion point is at the end of | |
9038 | the line, this transposes the last two words on the line. Word | |
9039 | boundaries are the same as 'shell-forward-word' and | |
9040 | 'shell-backward-word'. | |
9041 | ||
a0c0a00f | 9042 | 'unix-word-rubout (C-w)' |
bb70624e JA |
9043 | Kill the word behind point, using white space as a word boundary. |
9044 | The killed text is saved on the kill-ring. | |
9045 | ||
a0c0a00f | 9046 | 'unix-filename-rubout ()' |
b80f6443 JA |
9047 | Kill the word behind point, using white space and the slash |
9048 | character as the word boundaries. The killed text is saved on the | |
9049 | kill-ring. | |
9050 | ||
a0c0a00f | 9051 | 'delete-horizontal-space ()' |
bb70624e JA |
9052 | Delete all spaces and tabs around point. By default, this is |
9053 | unbound. | |
9054 | ||
a0c0a00f | 9055 | 'kill-region ()' |
bb70624e JA |
9056 | Kill the text in the current region. By default, this command is |
9057 | unbound. | |
9058 | ||
a0c0a00f | 9059 | 'copy-region-as-kill ()' |
bb70624e JA |
9060 | Copy the text in the region to the kill buffer, so it can be yanked |
9061 | right away. By default, this command is unbound. | |
9062 | ||
a0c0a00f CR |
9063 | 'copy-backward-word ()' |
9064 | Copy the word before point to the kill buffer. The word boundaries | |
9065 | are the same as 'backward-word'. By default, this command is | |
9066 | unbound. | |
bb70624e | 9067 | |
a0c0a00f | 9068 | 'copy-forward-word ()' |
bb70624e | 9069 | Copy the word following point to the kill buffer. The word |
a0c0a00f | 9070 | boundaries are the same as 'forward-word'. By default, this |
bb70624e JA |
9071 | command is unbound. |
9072 | ||
a0c0a00f | 9073 | 'yank (C-y)' |
28ef6c31 | 9074 | Yank the top of the kill ring into the buffer at point. |
bb70624e | 9075 | |
a0c0a00f | 9076 | 'yank-pop (M-y)' |
bb70624e | 9077 | Rotate the kill-ring, and yank the new top. You can only do this |
a0c0a00f | 9078 | if the prior command is 'yank' or 'yank-pop'. |
bb70624e JA |
9079 | |
9080 | \1f | |
9081 | File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands | |
9082 | ||
b80f6443 JA |
9083 | 8.4.5 Specifying Numeric Arguments |
9084 | ---------------------------------- | |
bb70624e | 9085 | |
a0c0a00f | 9086 | 'digit-argument (M-0, M-1, ... M--)' |
bb70624e | 9087 | Add this digit to the argument already accumulating, or start a new |
a0c0a00f | 9088 | argument. 'M--' starts a negative argument. |
bb70624e | 9089 | |
a0c0a00f | 9090 | 'universal-argument ()' |
bb70624e JA |
9091 | This is another way to specify an argument. If this command is |
9092 | followed by one or more digits, optionally with a leading minus | |
a0c0a00f CR |
9093 | sign, those digits define the argument. If the command is followed |
9094 | by digits, executing 'universal-argument' again ends the numeric | |
9095 | argument, but is otherwise ignored. As a special case, if this | |
9096 | command is immediately followed by a character that is neither a | |
9097 | digit nor minus sign, the argument count for the next command is | |
9098 | multiplied by four. The argument count is initially one, so | |
9099 | executing this function the first time makes the argument count | |
9100 | four, a second time makes the argument count sixteen, and so on. | |
9101 | By default, this is not bound to a key. | |
bb70624e JA |
9102 | |
9103 | \1f | |
9104 | File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands | |
9105 | ||
b80f6443 JA |
9106 | 8.4.6 Letting Readline Type For You |
9107 | ----------------------------------- | |
bb70624e | 9108 | |
a0c0a00f CR |
9109 | 'complete (<TAB>)' |
9110 | Attempt to perform completion on the text before point. The actual | |
9111 | completion performed is application-specific. Bash attempts | |
9112 | completion treating the text as a variable (if the text begins with | |
9113 | '$'), username (if the text begins with '~'), hostname (if the text | |
9114 | begins with '@'), or command (including aliases and functions) in | |
9115 | turn. If none of these produces a match, filename completion is | |
9116 | attempted. | |
bb70624e | 9117 | |
a0c0a00f | 9118 | 'possible-completions (M-?)' |
495aee44 CR |
9119 | List the possible completions of the text before point. When |
9120 | displaying completions, Readline sets the number of columns used | |
a0c0a00f CR |
9121 | for display to the value of 'completion-display-width', the value |
9122 | of the environment variable 'COLUMNS', or the screen width, in that | |
9123 | order. | |
bb70624e | 9124 | |
a0c0a00f | 9125 | 'insert-completions (M-*)' |
bb70624e | 9126 | Insert all completions of the text before point that would have |
a0c0a00f | 9127 | been generated by 'possible-completions'. |
bb70624e | 9128 | |
a0c0a00f CR |
9129 | 'menu-complete ()' |
9130 | Similar to 'complete', but replaces the word to be completed with a | |
9131 | single match from the list of possible completions. Repeated | |
9132 | execution of 'menu-complete' steps through the list of possible | |
bb70624e | 9133 | completions, inserting each match in turn. At the end of the list |
28ef6c31 | 9134 | of completions, the bell is rung (subject to the setting of |
a0c0a00f | 9135 | 'bell-style') and the original text is restored. An argument of N |
28ef6c31 JA |
9136 | moves N positions forward in the list of matches; a negative |
9137 | argument may be used to move backward through the list. This | |
9138 | command is intended to be bound to <TAB>, but is unbound by | |
bb70624e JA |
9139 | default. |
9140 | ||
a0c0a00f CR |
9141 | 'menu-complete-backward ()' |
9142 | Identical to 'menu-complete', but moves backward through the list | |
9143 | of possible completions, as if 'menu-complete' had been given a | |
0001803f CR |
9144 | negative argument. |
9145 | ||
a0c0a00f | 9146 | 'delete-char-or-list ()' |
bb70624e | 9147 | Deletes the character under the cursor if not at the beginning or |
a0c0a00f CR |
9148 | end of the line (like 'delete-char'). If at the end of the line, |
9149 | behaves identically to 'possible-completions'. This command is | |
bb70624e JA |
9150 | unbound by default. |
9151 | ||
a0c0a00f | 9152 | 'complete-filename (M-/)' |
bb70624e JA |
9153 | Attempt filename completion on the text before point. |
9154 | ||
a0c0a00f CR |
9155 | 'possible-filename-completions (C-x /)' |
9156 | List the possible completions of the text before point, treating it | |
9157 | as a filename. | |
bb70624e | 9158 | |
a0c0a00f | 9159 | 'complete-username (M-~)' |
bb70624e JA |
9160 | Attempt completion on the text before point, treating it as a |
9161 | username. | |
9162 | ||
a0c0a00f CR |
9163 | 'possible-username-completions (C-x ~)' |
9164 | List the possible completions of the text before point, treating it | |
9165 | as a username. | |
bb70624e | 9166 | |
a0c0a00f CR |
9167 | 'complete-variable (M-$)' |
9168 | Attempt completion on the text before point, treating it as a shell | |
9169 | variable. | |
bb70624e | 9170 | |
a0c0a00f CR |
9171 | 'possible-variable-completions (C-x $)' |
9172 | List the possible completions of the text before point, treating it | |
9173 | as a shell variable. | |
bb70624e | 9174 | |
a0c0a00f | 9175 | 'complete-hostname (M-@)' |
bb70624e JA |
9176 | Attempt completion on the text before point, treating it as a |
9177 | hostname. | |
9178 | ||
a0c0a00f CR |
9179 | 'possible-hostname-completions (C-x @)' |
9180 | List the possible completions of the text before point, treating it | |
9181 | as a hostname. | |
bb70624e | 9182 | |
a0c0a00f | 9183 | 'complete-command (M-!)' |
bb70624e JA |
9184 | Attempt completion on the text before point, treating it as a |
9185 | command name. Command completion attempts to match the text | |
9186 | against aliases, reserved words, shell functions, shell builtins, | |
9187 | and finally executable filenames, in that order. | |
9188 | ||
a0c0a00f CR |
9189 | 'possible-command-completions (C-x !)' |
9190 | List the possible completions of the text before point, treating it | |
9191 | as a command name. | |
bb70624e | 9192 | |
a0c0a00f | 9193 | 'dynamic-complete-history (M-<TAB>)' |
bb70624e JA |
9194 | Attempt completion on the text before point, comparing the text |
9195 | against lines from the history list for possible completion | |
9196 | matches. | |
9197 | ||
a0c0a00f | 9198 | 'dabbrev-expand ()' |
3185942a JA |
9199 | Attempt menu completion on the text before point, comparing the |
9200 | text against lines from the history list for possible completion | |
9201 | matches. | |
9202 | ||
a0c0a00f | 9203 | 'complete-into-braces (M-{)' |
bb70624e JA |
9204 | Perform filename completion and insert the list of possible |
9205 | completions enclosed within braces so the list is available to the | |
28ef6c31 | 9206 | shell (*note Brace Expansion::). |
bb70624e JA |
9207 | |
9208 | \1f | |
9209 | File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands | |
9210 | ||
b80f6443 JA |
9211 | 8.4.7 Keyboard Macros |
9212 | --------------------- | |
bb70624e | 9213 | |
a0c0a00f | 9214 | 'start-kbd-macro (C-x ()' |
bb70624e JA |
9215 | Begin saving the characters typed into the current keyboard macro. |
9216 | ||
a0c0a00f | 9217 | 'end-kbd-macro (C-x ))' |
bb70624e JA |
9218 | Stop saving the characters typed into the current keyboard macro |
9219 | and save the definition. | |
9220 | ||
a0c0a00f | 9221 | 'call-last-kbd-macro (C-x e)' |
bb70624e JA |
9222 | Re-execute the last keyboard macro defined, by making the |
9223 | characters in the macro appear as if typed at the keyboard. | |
9224 | ||
a0c0a00f | 9225 | 'print-last-kbd-macro ()' |
74091dd4 | 9226 | Print the last keyboard macro defined in a format suitable for the |
ac50fbac CR |
9227 | INPUTRC file. |
9228 | ||
bb70624e JA |
9229 | \1f |
9230 | File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands | |
9231 | ||
b80f6443 JA |
9232 | 8.4.8 Some Miscellaneous Commands |
9233 | --------------------------------- | |
bb70624e | 9234 | |
a0c0a00f | 9235 | 're-read-init-file (C-x C-r)' |
bb70624e JA |
9236 | Read in the contents of the INPUTRC file, and incorporate any |
9237 | bindings or variable assignments found there. | |
9238 | ||
a0c0a00f | 9239 | 'abort (C-g)' |
bb70624e | 9240 | Abort the current editing command and ring the terminal's bell |
a0c0a00f | 9241 | (subject to the setting of 'bell-style'). |
bb70624e | 9242 | |
d233b485 CR |
9243 | 'do-lowercase-version (M-A, M-B, M-X, ...)' |
9244 | If the metafied character X is upper case, run the command that is | |
9245 | bound to the corresponding metafied lower case character. The | |
9246 | behavior is undefined if X is already lower case. | |
bb70624e | 9247 | |
a0c0a00f | 9248 | 'prefix-meta (<ESC>)' |
28ef6c31 | 9249 | Metafy the next character typed. This is for keyboards without a |
a0c0a00f | 9250 | meta key. Typing '<ESC> f' is equivalent to typing 'M-f'. |
bb70624e | 9251 | |
a0c0a00f | 9252 | 'undo (C-_ or C-x C-u)' |
bb70624e JA |
9253 | Incremental undo, separately remembered for each line. |
9254 | ||
a0c0a00f | 9255 | 'revert-line (M-r)' |
bb70624e | 9256 | Undo all changes made to this line. This is like executing the |
a0c0a00f | 9257 | 'undo' command enough times to get back to the beginning. |
bb70624e | 9258 | |
a0c0a00f | 9259 | 'tilde-expand (M-&)' |
bb70624e JA |
9260 | Perform tilde expansion on the current word. |
9261 | ||
a0c0a00f | 9262 | 'set-mark (C-@)' |
28ef6c31 JA |
9263 | Set the mark to the point. If a numeric argument is supplied, the |
9264 | mark is set to that position. | |
bb70624e | 9265 | |
a0c0a00f | 9266 | 'exchange-point-and-mark (C-x C-x)' |
bb70624e JA |
9267 | Swap the point with the mark. The current cursor position is set |
9268 | to the saved position, and the old cursor position is saved as the | |
9269 | mark. | |
9270 | ||
a0c0a00f | 9271 | 'character-search (C-])' |
bb70624e | 9272 | A character is read and point is moved to the next occurrence of |
74091dd4 | 9273 | that character. A negative argument searches for previous |
bb70624e JA |
9274 | occurrences. |
9275 | ||
a0c0a00f | 9276 | 'character-search-backward (M-C-])' |
bb70624e | 9277 | A character is read and point is moved to the previous occurrence |
74091dd4 | 9278 | of that character. A negative argument searches for subsequent |
bb70624e JA |
9279 | occurrences. |
9280 | ||
a0c0a00f | 9281 | 'skip-csi-sequence ()' |
0001803f CR |
9282 | Read enough characters to consume a multi-key sequence such as |
9283 | those defined for keys like Home and End. Such sequences begin | |
9284 | with a Control Sequence Indicator (CSI), usually ESC-[. If this | |
a0c0a00f | 9285 | sequence is bound to "\e[", keys producing such sequences will have |
74091dd4 | 9286 | no effect unless explicitly bound to a Readline command, instead of |
a0c0a00f CR |
9287 | inserting stray characters into the editing buffer. This is |
9288 | unbound by default, but usually bound to ESC-[. | |
0001803f | 9289 | |
a0c0a00f CR |
9290 | 'insert-comment (M-#)' |
9291 | Without a numeric argument, the value of the 'comment-begin' | |
7117c2d2 | 9292 | variable is inserted at the beginning of the current line. If a |
a0c0a00f CR |
9293 | numeric argument is supplied, this command acts as a toggle: if the |
9294 | characters at the beginning of the line do not match the value of | |
9295 | 'comment-begin', the value is inserted, otherwise the characters in | |
9296 | 'comment-begin' are deleted from the beginning of the line. In | |
9297 | either case, the line is accepted as if a newline had been typed. | |
9298 | The default value of 'comment-begin' causes this command to make | |
9299 | the current line a shell comment. If a numeric argument causes the | |
9300 | comment character to be removed, the line will be executed by the | |
9301 | shell. | |
9302 | ||
9303 | 'dump-functions ()' | |
bb70624e JA |
9304 | Print all of the functions and their key bindings to the Readline |
9305 | output stream. If a numeric argument is supplied, the output is | |
9306 | formatted in such a way that it can be made part of an INPUTRC | |
9307 | file. This command is unbound by default. | |
9308 | ||
a0c0a00f | 9309 | 'dump-variables ()' |
bb70624e JA |
9310 | Print all of the settable variables and their values to the |
9311 | Readline output stream. If a numeric argument is supplied, the | |
9312 | output is formatted in such a way that it can be made part of an | |
9313 | INPUTRC file. This command is unbound by default. | |
9314 | ||
a0c0a00f | 9315 | 'dump-macros ()' |
bb70624e | 9316 | Print all of the Readline key sequences bound to macros and the |
a0c0a00f CR |
9317 | strings they output. If a numeric argument is supplied, the output |
9318 | is formatted in such a way that it can be made part of an INPUTRC | |
9319 | file. This command is unbound by default. | |
bb70624e | 9320 | |
74091dd4 CR |
9321 | 'spell-correct-word (C-x s)' |
9322 | Perform spelling correction on the current word, treating it as a | |
9323 | directory or filename, in the same way as the 'cdspell' shell | |
9324 | option. Word boundaries are the same as those used by | |
9325 | 'shell-forward-word'. | |
9326 | ||
a0c0a00f | 9327 | 'glob-complete-word (M-g)' |
7117c2d2 JA |
9328 | The word before point is treated as a pattern for pathname |
9329 | expansion, with an asterisk implicitly appended. This pattern is | |
9330 | used to generate a list of matching file names for possible | |
9331 | completions. | |
9332 | ||
a0c0a00f | 9333 | 'glob-expand-word (C-x *)' |
bb70624e JA |
9334 | The word before point is treated as a pattern for pathname |
9335 | expansion, and the list of matching file names is inserted, | |
a0c0a00f | 9336 | replacing the word. If a numeric argument is supplied, a '*' is |
7117c2d2 | 9337 | appended before pathname expansion. |
bb70624e | 9338 | |
a0c0a00f | 9339 | 'glob-list-expansions (C-x g)' |
bb70624e | 9340 | The list of expansions that would have been generated by |
a0c0a00f CR |
9341 | 'glob-expand-word' is displayed, and the line is redrawn. If a |
9342 | numeric argument is supplied, a '*' is appended before pathname | |
7117c2d2 | 9343 | expansion. |
bb70624e | 9344 | |
a0c0a00f | 9345 | 'display-shell-version (C-x C-v)' |
bb70624e JA |
9346 | Display version information about the current instance of Bash. |
9347 | ||
a0c0a00f CR |
9348 | 'shell-expand-line (M-C-e)' |
9349 | Expand the line as the shell does. This performs alias and history | |
9350 | expansion as well as all of the shell word expansions (*note Shell | |
9351 | Expansions::). | |
bb70624e | 9352 | |
a0c0a00f | 9353 | 'history-expand-line (M-^)' |
bb70624e JA |
9354 | Perform history expansion on the current line. |
9355 | ||
a0c0a00f | 9356 | 'magic-space ()' |
bb70624e | 9357 | Perform history expansion on the current line and insert a space |
28ef6c31 | 9358 | (*note History Interaction::). |
bb70624e | 9359 | |
a0c0a00f | 9360 | 'alias-expand-line ()' |
28ef6c31 | 9361 | Perform alias expansion on the current line (*note Aliases::). |
bb70624e | 9362 | |
a0c0a00f | 9363 | 'history-and-alias-expand-line ()' |
bb70624e JA |
9364 | Perform history and alias expansion on the current line. |
9365 | ||
a0c0a00f CR |
9366 | 'insert-last-argument (M-. or M-_)' |
9367 | A synonym for 'yank-last-arg'. | |
bb70624e | 9368 | |
d233b485 | 9369 | 'edit-and-execute-command (C-x C-e)' |
7117c2d2 | 9370 | Invoke an editor on the current command line, and execute the |
a0c0a00f CR |
9371 | result as shell commands. Bash attempts to invoke '$VISUAL', |
9372 | '$EDITOR', and 'emacs' as the editor, in that order. | |
b80f6443 | 9373 | |
bb70624e JA |
9374 | \1f |
9375 | File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing | |
9376 | ||
b80f6443 JA |
9377 | 8.5 Readline vi Mode |
9378 | ==================== | |
bb70624e | 9379 | |
a0c0a00f | 9380 | While the Readline library does not have a full set of 'vi' editing |
bb70624e | 9381 | functions, it does contain enough to allow simple editing of the line. |
a0c0a00f | 9382 | The Readline 'vi' mode behaves as specified in the POSIX standard. |
bb70624e | 9383 | |
a0c0a00f CR |
9384 | In order to switch interactively between 'emacs' and 'vi' editing |
9385 | modes, use the 'set -o emacs' and 'set -o vi' commands (*note The Set | |
9386 | Builtin::). The Readline default is 'emacs' mode. | |
bb70624e | 9387 | |
a0c0a00f CR |
9388 | When you enter a line in 'vi' mode, you are already placed in |
9389 | 'insertion' mode, as if you had typed an 'i'. Pressing <ESC> switches | |
9390 | you into 'command' mode, where you can edit the text of the line with | |
9391 | the standard 'vi' movement keys, move to previous history lines with 'k' | |
9392 | and subsequent lines with 'j', and so forth. | |
bb70624e JA |
9393 | |
9394 | \1f | |
9395 | File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing | |
9396 | ||
b80f6443 JA |
9397 | 8.6 Programmable Completion |
9398 | =========================== | |
bb70624e | 9399 | |
a0c0a00f CR |
9400 | When word completion is attempted for an argument to a command for which |
9401 | a completion specification (a COMPSPEC) has been defined using the | |
9402 | 'complete' builtin (*note Programmable Completion Builtins::), the | |
bb70624e JA |
9403 | programmable completion facilities are invoked. |
9404 | ||
9405 | First, the command name is identified. If a compspec has been | |
9406 | defined for that command, the compspec is used to generate the list of | |
0001803f CR |
9407 | possible completions for the word. If the command word is the empty |
9408 | string (completion attempted at the beginning of an empty line), any | |
a0c0a00f | 9409 | compspec defined with the '-E' option to 'complete' is used. If the |
0001803f CR |
9410 | command word is a full pathname, a compspec for the full pathname is |
9411 | searched for first. If no compspec is found for the full pathname, an | |
9412 | attempt is made to find a compspec for the portion following the final | |
9413 | slash. If those searches do not result in a compspec, any compspec | |
d233b485 CR |
9414 | defined with the '-D' option to 'complete' is used as the default. If |
9415 | there is no default compspec, Bash attempts alias expansion on the | |
9416 | command word as a final resort, and attempts to find a compspec for the | |
9417 | command word from any successful expansion | |
bb70624e JA |
9418 | |
9419 | Once a compspec has been found, it is used to generate the list of | |
9420 | matching words. If a compspec is not found, the default Bash completion | |
28ef6c31 | 9421 | described above (*note Commands For Completion::) is performed. |
bb70624e JA |
9422 | |
9423 | First, the actions specified by the compspec are used. Only matches | |
9424 | which are prefixed by the word being completed are returned. When the | |
a0c0a00f CR |
9425 | '-f' or '-d' option is used for filename or directory name completion, |
9426 | the shell variable 'FIGNORE' is used to filter the matches. *Note Bash | |
9427 | Variables::, for a description of 'FIGNORE'. | |
9428 | ||
9429 | Any completions specified by a filename expansion pattern to the '-G' | |
9430 | option are generated next. The words generated by the pattern need not | |
9431 | match the word being completed. The 'GLOBIGNORE' shell variable is not | |
9432 | used to filter the matches, but the 'FIGNORE' shell variable is used. | |
9433 | ||
9434 | Next, the string specified as the argument to the '-W' option is | |
9435 | considered. The string is first split using the characters in the 'IFS' | |
d233b485 CR |
9436 | special variable as delimiters. Shell quoting is honored within the |
9437 | string, in order to provide a mechanism for the words to contain shell | |
9438 | metacharacters or characters in the value of 'IFS'. Each word is then | |
9439 | expanded using brace expansion, tilde expansion, parameter and variable | |
9440 | expansion, command substitution, and arithmetic expansion, as described | |
9441 | above (*note Shell Expansions::). The results are split using the rules | |
9442 | described above (*note Word Splitting::). The results of the expansion | |
9443 | are prefix-matched against the word being completed, and the matching | |
9444 | words become the possible completions. | |
bb70624e JA |
9445 | |
9446 | After these matches have been generated, any shell function or | |
a0c0a00f CR |
9447 | command specified with the '-F' and '-C' options is invoked. When the |
9448 | command or function is invoked, the 'COMP_LINE', 'COMP_POINT', | |
9449 | 'COMP_KEY', and 'COMP_TYPE' variables are assigned values as described | |
3185942a | 9450 | above (*note Bash Variables::). If a shell function is being invoked, |
a0c0a00f | 9451 | the 'COMP_WORDS' and 'COMP_CWORD' variables are also set. When the |
ac50fbac CR |
9452 | function or command is invoked, the first argument ($1) is the name of |
9453 | the command whose arguments are being completed, the second argument | |
9454 | ($2) is the word being completed, and the third argument ($3) is the | |
a0c0a00f CR |
9455 | word preceding the word being completed on the current command line. No |
9456 | filtering of the generated completions against the word being completed | |
9457 | is performed; the function or command has complete freedom in generating | |
9458 | the matches. | |
bb70624e | 9459 | |
a0c0a00f CR |
9460 | Any function specified with '-F' is invoked first. The function may |
9461 | use any of the shell facilities, including the 'compgen' and 'compopt' | |
3185942a JA |
9462 | builtins described below (*note Programmable Completion Builtins::), to |
9463 | generate the matches. It must put the possible completions in the | |
a0c0a00f | 9464 | 'COMPREPLY' array variable, one per array element. |
bb70624e | 9465 | |
a0c0a00f | 9466 | Next, any command specified with the '-C' option is invoked in an |
bb70624e JA |
9467 | environment equivalent to command substitution. It should print a list |
9468 | of completions, one per line, to the standard output. Backslash may be | |
9469 | used to escape a newline, if necessary. | |
9470 | ||
9471 | After all of the possible completions are generated, any filter | |
a0c0a00f CR |
9472 | specified with the '-X' option is applied to the list. The filter is a |
9473 | pattern as used for pathname expansion; a '&' in the pattern is replaced | |
9474 | with the text of the word being completed. A literal '&' may be escaped | |
9475 | with a backslash; the backslash is removed before attempting a match. | |
9476 | Any completion that matches the pattern will be removed from the list. | |
9477 | A leading '!' negates the pattern; in this case any completion not | |
9478 | matching the pattern will be removed. If the 'nocasematch' shell option | |
9479 | (see the description of 'shopt' in *note The Shopt Builtin::) is | |
9480 | enabled, the match is performed without regard to the case of alphabetic | |
9481 | characters. | |
9482 | ||
9483 | Finally, any prefix and suffix specified with the '-P' and '-S' | |
bb70624e JA |
9484 | options are added to each member of the completion list, and the result |
9485 | is returned to the Readline completion code as the list of possible | |
9486 | completions. | |
9487 | ||
28ef6c31 | 9488 | If the previously-applied actions do not generate any matches, and |
a0c0a00f | 9489 | the '-o dirnames' option was supplied to 'complete' when the compspec |
28ef6c31 JA |
9490 | was defined, directory name completion is attempted. |
9491 | ||
a0c0a00f | 9492 | If the '-o plusdirs' option was supplied to 'complete' when the |
b80f6443 JA |
9493 | compspec was defined, directory name completion is attempted and any |
9494 | matches are added to the results of the other actions. | |
9495 | ||
a0c0a00f CR |
9496 | By default, if a compspec is found, whatever it generates is returned |
9497 | to the completion code as the full set of possible completions. The | |
9498 | default Bash completions are not attempted, and the Readline default of | |
9499 | filename completion is disabled. If the '-o bashdefault' option was | |
9500 | supplied to 'complete' when the compspec was defined, the default Bash | |
b80f6443 | 9501 | completions are attempted if the compspec generates no matches. If the |
a0c0a00f CR |
9502 | '-o default' option was supplied to 'complete' when the compspec was |
9503 | defined, Readline's default completion will be performed if the compspec | |
9504 | (and, if attempted, the default Bash completions) generate no matches. | |
bb70624e | 9505 | |
7117c2d2 JA |
9506 | When a compspec indicates that directory name completion is desired, |
9507 | the programmable completion functions force Readline to append a slash | |
9508 | to completed names which are symbolic links to directories, subject to | |
9509 | the value of the MARK-DIRECTORIES Readline variable, regardless of the | |
9510 | setting of the MARK-SYMLINKED-DIRECTORIES Readline variable. | |
9511 | ||
0001803f CR |
9512 | There is some support for dynamically modifying completions. This is |
9513 | most useful when used in combination with a default completion specified | |
a0c0a00f | 9514 | with '-D'. It's possible for shell functions executed as completion |
0001803f CR |
9515 | handlers to indicate that completion should be retried by returning an |
9516 | exit status of 124. If a shell function returns 124, and changes the | |
9517 | compspec associated with the command on which completion is being | |
9518 | attempted (supplied as the first argument when the function is | |
9519 | executed), programmable completion restarts from the beginning, with an | |
495aee44 | 9520 | attempt to find a new compspec for that command. This allows a set of |
0001803f CR |
9521 | completions to be built dynamically as completion is attempted, rather |
9522 | than being loaded all at once. | |
9523 | ||
9524 | For instance, assuming that there is a library of compspecs, each | |
9525 | kept in a file corresponding to the name of the command, the following | |
9526 | default completion function would load completions dynamically: | |
9527 | ||
9528 | _completion_loader() | |
9529 | { | |
ac50fbac | 9530 | . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124 |
0001803f | 9531 | } |
ac50fbac | 9532 | complete -D -F _completion_loader -o bashdefault -o default |
0001803f | 9533 | |
bb70624e | 9534 | \1f |
ac50fbac | 9535 | File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing |
bb70624e | 9536 | |
b80f6443 JA |
9537 | 8.7 Programmable Completion Builtins |
9538 | ==================================== | |
bb70624e | 9539 | |
ac50fbac CR |
9540 | Three builtin commands are available to manipulate the programmable |
9541 | completion facilities: one to specify how the arguments to a particular | |
9542 | command are to be completed, and two to modify the completion as it is | |
9543 | happening. | |
bb70624e | 9544 | |
a0c0a00f CR |
9545 | 'compgen' |
9546 | compgen [OPTION] [WORD] | |
bb70624e JA |
9547 | |
9548 | Generate possible completion matches for WORD according to the | |
a0c0a00f CR |
9549 | OPTIONs, which may be any option accepted by the 'complete' builtin |
9550 | with the exception of '-p' and '-r', and write the matches to the | |
9551 | standard output. When using the '-F' or '-C' options, the various | |
9552 | shell variables set by the programmable completion facilities, | |
9553 | while available, will not have useful values. | |
bb70624e JA |
9554 | |
9555 | The matches will be generated in the same way as if the | |
9556 | programmable completion code had generated them directly from a | |
9557 | completion specification with the same flags. If WORD is | |
9558 | specified, only those completions matching WORD will be displayed. | |
9559 | ||
9560 | The return value is true unless an invalid option is supplied, or | |
9561 | no matches were generated. | |
9562 | ||
a0c0a00f | 9563 | 'complete' |
d233b485 CR |
9564 | complete [-abcdefgjksuv] [-o COMP-OPTION] [-DEI] [-A ACTION] [-G GLOBPAT] |
9565 | [-W WORDLIST] [-F FUNCTION] [-C COMMAND] [-X FILTERPAT] | |
a0c0a00f | 9566 | [-P PREFIX] [-S SUFFIX] NAME [NAME ...] |
d233b485 | 9567 | complete -pr [-DEI] [NAME ...] |
bb70624e JA |
9568 | |
9569 | Specify how arguments to each NAME should be completed. If the | |
a0c0a00f | 9570 | '-p' option is supplied, or if no options are supplied, existing |
bb70624e | 9571 | completion specifications are printed in a way that allows them to |
a0c0a00f | 9572 | be reused as input. The '-r' option removes a completion |
bb70624e | 9573 | specification for each NAME, or, if no NAMEs are supplied, all |
d233b485 CR |
9574 | completion specifications. The '-D' option indicates that other |
9575 | supplied options and actions should apply to the "default" command | |
a0c0a00f CR |
9576 | completion; that is, completion attempted on a command for which no |
9577 | completion has previously been defined. The '-E' option indicates | |
d233b485 | 9578 | that other supplied options and actions should apply to "empty" |
a0c0a00f | 9579 | command completion; that is, completion attempted on a blank line. |
d233b485 | 9580 | The '-I' option indicates that other supplied options and actions |
8868edaf CR |
9581 | should apply to completion on the initial non-assignment word on |
9582 | the line, or after a command delimiter such as ';' or '|', which is | |
d233b485 CR |
9583 | usually command name completion. If multiple options are supplied, |
9584 | the '-D' option takes precedence over '-E', and both take | |
9585 | precedence over '-I'. If any of '-D', '-E', or '-I' are supplied, | |
9586 | any other NAME arguments are ignored; these completions only apply | |
9587 | to the case specified by the option. | |
bb70624e JA |
9588 | |
9589 | The process of applying these completion specifications when word | |
9590 | completion is attempted is described above (*note Programmable | |
d233b485 | 9591 | Completion::). |
bb70624e JA |
9592 | |
9593 | Other options, if specified, have the following meanings. The | |
a0c0a00f CR |
9594 | arguments to the '-G', '-W', and '-X' options (and, if necessary, |
9595 | the '-P' and '-S' options) should be quoted to protect them from | |
9596 | expansion before the 'complete' builtin is invoked. | |
bb70624e | 9597 | |
a0c0a00f | 9598 | '-o COMP-OPTION' |
28ef6c31 JA |
9599 | The COMP-OPTION controls several aspects of the compspec's |
9600 | behavior beyond the simple generation of completions. | |
9601 | COMP-OPTION may be one of: | |
9602 | ||
a0c0a00f | 9603 | 'bashdefault' |
b80f6443 JA |
9604 | Perform the rest of the default Bash completions if the |
9605 | compspec generates no matches. | |
9606 | ||
a0c0a00f | 9607 | 'default' |
7117c2d2 JA |
9608 | Use Readline's default filename completion if the |
9609 | compspec generates no matches. | |
28ef6c31 | 9610 | |
a0c0a00f | 9611 | 'dirnames' |
28ef6c31 JA |
9612 | Perform directory name completion if the compspec |
9613 | generates no matches. | |
9614 | ||
a0c0a00f | 9615 | 'filenames' |
28ef6c31 | 9616 | Tell Readline that the compspec generates filenames, so |
b80f6443 | 9617 | it can perform any filename-specific processing (like |
d233b485 | 9618 | adding a slash to directory names, quoting special |
a0c0a00f CR |
9619 | characters, or suppressing trailing spaces). This option |
9620 | is intended to be used with shell functions specified | |
9621 | with '-F'. | |
28ef6c31 | 9622 | |
a0c0a00f | 9623 | 'noquote' |
ac50fbac CR |
9624 | Tell Readline not to quote the completed words if they |
9625 | are filenames (quoting filenames is the default). | |
9626 | ||
a0c0a00f CR |
9627 | 'nosort' |
9628 | Tell Readline not to sort the list of possible | |
9629 | completions alphabetically. | |
9630 | ||
9631 | 'nospace' | |
7117c2d2 JA |
9632 | Tell Readline not to append a space (the default) to |
9633 | words completed at the end of the line. | |
9634 | ||
a0c0a00f | 9635 | 'plusdirs' |
95732b49 JA |
9636 | After any matches defined by the compspec are generated, |
9637 | directory name completion is attempted and any matches | |
9638 | are added to the results of the other actions. | |
9639 | ||
a0c0a00f | 9640 | '-A ACTION' |
bb70624e JA |
9641 | The ACTION may be one of the following to generate a list of |
9642 | possible completions: | |
9643 | ||
a0c0a00f CR |
9644 | 'alias' |
9645 | Alias names. May also be specified as '-a'. | |
bb70624e | 9646 | |
a0c0a00f | 9647 | 'arrayvar' |
bb70624e JA |
9648 | Array variable names. |
9649 | ||
a0c0a00f | 9650 | 'binding' |
bb70624e | 9651 | Readline key binding names (*note Bindable Readline |
28ef6c31 | 9652 | Commands::). |
bb70624e | 9653 | |
a0c0a00f | 9654 | 'builtin' |
bb70624e | 9655 | Names of shell builtin commands. May also be specified |
a0c0a00f | 9656 | as '-b'. |
bb70624e | 9657 | |
a0c0a00f CR |
9658 | 'command' |
9659 | Command names. May also be specified as '-c'. | |
bb70624e | 9660 | |
a0c0a00f CR |
9661 | 'directory' |
9662 | Directory names. May also be specified as '-d'. | |
bb70624e | 9663 | |
a0c0a00f | 9664 | 'disabled' |
bb70624e JA |
9665 | Names of disabled shell builtins. |
9666 | ||
a0c0a00f | 9667 | 'enabled' |
bb70624e JA |
9668 | Names of enabled shell builtins. |
9669 | ||
a0c0a00f CR |
9670 | 'export' |
9671 | Names of exported shell variables. May also be specified | |
9672 | as '-e'. | |
bb70624e | 9673 | |
a0c0a00f CR |
9674 | 'file' |
9675 | File names. May also be specified as '-f'. | |
bb70624e | 9676 | |
a0c0a00f | 9677 | 'function' |
bb70624e JA |
9678 | Names of shell functions. |
9679 | ||
a0c0a00f CR |
9680 | 'group' |
9681 | Group names. May also be specified as '-g'. | |
f73dda09 | 9682 | |
a0c0a00f CR |
9683 | 'helptopic' |
9684 | Help topics as accepted by the 'help' builtin (*note Bash | |
9685 | Builtins::). | |
bb70624e | 9686 | |
a0c0a00f | 9687 | 'hostname' |
bb70624e | 9688 | Hostnames, as taken from the file specified by the |
a0c0a00f | 9689 | 'HOSTFILE' shell variable (*note Bash Variables::). |
bb70624e | 9690 | |
a0c0a00f | 9691 | 'job' |
bb70624e | 9692 | Job names, if job control is active. May also be |
a0c0a00f | 9693 | specified as '-j'. |
bb70624e | 9694 | |
a0c0a00f CR |
9695 | 'keyword' |
9696 | Shell reserved words. May also be specified as '-k'. | |
bb70624e | 9697 | |
a0c0a00f | 9698 | 'running' |
bb70624e JA |
9699 | Names of running jobs, if job control is active. |
9700 | ||
a0c0a00f CR |
9701 | 'service' |
9702 | Service names. May also be specified as '-s'. | |
7117c2d2 | 9703 | |
a0c0a00f CR |
9704 | 'setopt' |
9705 | Valid arguments for the '-o' option to the 'set' builtin | |
28ef6c31 | 9706 | (*note The Set Builtin::). |
bb70624e | 9707 | |
a0c0a00f CR |
9708 | 'shopt' |
9709 | Shell option names as accepted by the 'shopt' builtin | |
28ef6c31 | 9710 | (*note Bash Builtins::). |
bb70624e | 9711 | |
a0c0a00f | 9712 | 'signal' |
bb70624e JA |
9713 | Signal names. |
9714 | ||
a0c0a00f | 9715 | 'stopped' |
bb70624e JA |
9716 | Names of stopped jobs, if job control is active. |
9717 | ||
a0c0a00f CR |
9718 | 'user' |
9719 | User names. May also be specified as '-u'. | |
bb70624e | 9720 | |
a0c0a00f | 9721 | 'variable' |
bb70624e | 9722 | Names of all shell variables. May also be specified as |
a0c0a00f | 9723 | '-v'. |
bb70624e | 9724 | |
a0c0a00f | 9725 | '-C COMMAND' |
bb70624e | 9726 | COMMAND is executed in a subshell environment, and its output |
74091dd4 CR |
9727 | is used as the possible completions. Arguments are passed as |
9728 | with the '-F' option. | |
bb70624e | 9729 | |
a0c0a00f | 9730 | '-F FUNCTION' |
bb70624e | 9731 | The shell function FUNCTION is executed in the current shell |
ac50fbac CR |
9732 | environment. When it is executed, $1 is the name of the |
9733 | command whose arguments are being completed, $2 is the word | |
9734 | being completed, and $3 is the word preceding the word being | |
9735 | completed, as described above (*note Programmable | |
a0c0a00f CR |
9736 | Completion::). When it finishes, the possible completions are |
9737 | retrieved from the value of the 'COMPREPLY' array variable. | |
bb70624e | 9738 | |
a0c0a00f | 9739 | '-G GLOBPAT' |
495aee44 CR |
9740 | The filename expansion pattern GLOBPAT is expanded to generate |
9741 | the possible completions. | |
bb70624e | 9742 | |
a0c0a00f | 9743 | '-P PREFIX' |
bb70624e JA |
9744 | PREFIX is added at the beginning of each possible completion |
9745 | after all other options have been applied. | |
9746 | ||
a0c0a00f CR |
9747 | '-S SUFFIX' |
9748 | SUFFIX is appended to each possible completion after all other | |
9749 | options have been applied. | |
bb70624e | 9750 | |
a0c0a00f CR |
9751 | '-W WORDLIST' |
9752 | The WORDLIST is split using the characters in the 'IFS' | |
495aee44 CR |
9753 | special variable as delimiters, and each resultant word is |
9754 | expanded. The possible completions are the members of the | |
9755 | resultant list which match the word being completed. | |
9756 | ||
a0c0a00f | 9757 | '-X FILTERPAT' |
495aee44 CR |
9758 | FILTERPAT is a pattern as used for filename expansion. It is |
9759 | applied to the list of possible completions generated by the | |
9760 | preceding options and arguments, and each completion matching | |
a0c0a00f | 9761 | FILTERPAT is removed from the list. A leading '!' in |
495aee44 CR |
9762 | FILTERPAT negates the pattern; in this case, any completion |
9763 | not matching FILTERPAT is removed. | |
9764 | ||
bb70624e | 9765 | The return value is true unless an invalid option is supplied, an |
a0c0a00f CR |
9766 | option other than '-p' or '-r' is supplied without a NAME argument, |
9767 | an attempt is made to remove a completion specification for a NAME | |
9768 | for which no specification exists, or an error occurs adding a | |
9769 | completion specification. | |
bb70624e | 9770 | |
a0c0a00f | 9771 | 'compopt' |
d233b485 | 9772 | compopt [-o OPTION] [-DEI] [+o OPTION] [NAME] |
3185942a | 9773 | Modify completion options for each NAME according to the OPTIONs, |
495aee44 | 9774 | or for the currently-executing completion if no NAMEs are supplied. |
3185942a JA |
9775 | If no OPTIONs are given, display the completion options for each |
9776 | NAME or the current completion. The possible values of OPTION are | |
a0c0a00f | 9777 | those valid for the 'complete' builtin described above. The '-D' |
d233b485 | 9778 | option indicates that other supplied options should apply to the |
0001803f CR |
9779 | "default" command completion; that is, completion attempted on a |
9780 | command for which no completion has previously been defined. The | |
d233b485 | 9781 | '-E' option indicates that other supplied options should apply to |
0001803f | 9782 | "empty" command completion; that is, completion attempted on a |
d233b485 | 9783 | blank line. The '-I' option indicates that other supplied options |
8868edaf CR |
9784 | should apply to completion on the initial non-assignment word on |
9785 | the line, or after a command delimiter such as ';' or '|', which is | |
d233b485 | 9786 | usually command name completion. |
0001803f | 9787 | |
d233b485 CR |
9788 | If multiple options are supplied, the '-D' option takes precedence |
9789 | over '-E', and both take precedence over '-I' | |
3185942a JA |
9790 | |
9791 | The return value is true unless an invalid option is supplied, an | |
9792 | attempt is made to modify the options for a NAME for which no | |
9793 | completion specification exists, or an output error occurs. | |
9794 | ||
ac50fbac CR |
9795 | \1f |
9796 | File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing | |
9797 | ||
9798 | 8.8 A Programmable Completion Example | |
9799 | ===================================== | |
9800 | ||
9801 | The most common way to obtain additional completion functionality beyond | |
a0c0a00f CR |
9802 | the default actions 'complete' and 'compgen' provide is to use a shell |
9803 | function and bind it to a particular command using 'complete -F'. | |
ac50fbac | 9804 | |
a0c0a00f CR |
9805 | The following function provides completions for the 'cd' builtin. It |
9806 | is a reasonably good example of what shell functions must do when used | |
d233b485 CR |
9807 | for completion. This function uses the word passed as '$2' to determine |
9808 | the directory name to complete. You can also use the 'COMP_WORDS' array | |
9809 | variable; the current word is indexed by the 'COMP_CWORD' variable. | |
ac50fbac | 9810 | |
a0c0a00f CR |
9811 | The function relies on the 'complete' and 'compgen' builtins to do |
9812 | much of the work, adding only the things that the Bash 'cd' does beyond | |
ac50fbac CR |
9813 | accepting basic directory names: tilde expansion (*note Tilde |
9814 | Expansion::), searching directories in $CDPATH, which is described above | |
a0c0a00f CR |
9815 | (*note Bourne Shell Builtins::), and basic support for the 'cdable_vars' |
9816 | shell option (*note The Shopt Builtin::). '_comp_cd' modifies the value | |
9817 | of IFS so that it contains only a newline to accommodate file names | |
9818 | containing spaces and tabs - 'compgen' prints the possible completions | |
9819 | it generates one per line. | |
ac50fbac CR |
9820 | |
9821 | Possible completions go into the COMPREPLY array variable, one | |
9822 | completion per array element. The programmable completion system | |
9823 | retrieves the completions from there when the function returns. | |
9824 | ||
9825 | # A completion function for the cd builtin | |
9826 | # based on the cd completion function from the bash_completion package | |
9827 | _comp_cd() | |
9828 | { | |
9829 | local IFS=$' \t\n' # normalize IFS | |
9830 | local cur _skipdot _cdpath | |
9831 | local i j k | |
9832 | ||
d233b485 | 9833 | # Tilde expansion, which also expands tilde to full pathname |
ac50fbac CR |
9834 | case "$2" in |
9835 | \~*) eval cur="$2" ;; | |
9836 | *) cur=$2 ;; | |
9837 | esac | |
9838 | ||
9839 | # no cdpath or absolute pathname -- straight directory completion | |
9840 | if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then | |
9841 | # compgen prints paths one per line; could also use while loop | |
9842 | IFS=$'\n' | |
9843 | COMPREPLY=( $(compgen -d -- "$cur") ) | |
9844 | IFS=$' \t\n' | |
9845 | # CDPATH+directories in the current directory if not in CDPATH | |
9846 | else | |
9847 | IFS=$'\n' | |
9848 | _skipdot=false | |
9849 | # preprocess CDPATH to convert null directory names to . | |
9850 | _cdpath=${CDPATH/#:/.:} | |
9851 | _cdpath=${_cdpath//::/:.:} | |
9852 | _cdpath=${_cdpath/%:/:.} | |
9853 | for i in ${_cdpath//:/$'\n'}; do | |
9854 | if [[ $i -ef . ]]; then _skipdot=true; fi | |
9855 | k="${#COMPREPLY[@]}" | |
9856 | for j in $( compgen -d -- "$i/$cur" ); do | |
9857 | COMPREPLY[k++]=${j#$i/} # cut off directory | |
9858 | done | |
9859 | done | |
9860 | $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") ) | |
9861 | IFS=$' \t\n' | |
9862 | fi | |
9863 | ||
9864 | # variable names if appropriate shell option set and no completions | |
9865 | if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then | |
9866 | COMPREPLY=( $(compgen -v -- "$cur") ) | |
9867 | fi | |
9868 | ||
9869 | return 0 | |
9870 | } | |
9871 | ||
a0c0a00f CR |
9872 | We install the completion function using the '-F' option to |
9873 | 'complete': | |
ac50fbac CR |
9874 | |
9875 | # Tell readline to quote appropriate and append slashes to directories; | |
9876 | # use the bash default completion for other arguments | |
9877 | complete -o filenames -o nospace -o bashdefault -F _comp_cd cd | |
9878 | ||
9879 | Since we'd like Bash and Readline to take care of some of the other | |
9880 | details for us, we use several other options to tell Bash and Readline | |
a0c0a00f | 9881 | what to do. The '-o filenames' option tells Readline that the possible |
ac50fbac CR |
9882 | completions should be treated as filenames, and quoted appropriately. |
9883 | That option will also cause Readline to append a slash to filenames it | |
9884 | can determine are directories (which is why we might want to extend | |
a0c0a00f CR |
9885 | '_comp_cd' to append a slash if we're using directories found via |
9886 | CDPATH: Readline can't tell those completions are directories). The '-o | |
9887 | nospace' option tells Readline to not append a space character to the | |
9888 | directory name, in case we want to append to it. The '-o bashdefault' | |
9889 | option brings in the rest of the "Bash default" completions - possible | |
74091dd4 | 9890 | completions that Bash adds to the default Readline set. These include |
a0c0a00f | 9891 | things like command name completion, variable completion for words |
8868edaf CR |
9892 | beginning with '$' or '${', completions containing pathname expansion |
9893 | patterns (*note Filename Expansion::), and so on. | |
a0c0a00f CR |
9894 | |
9895 | Once installed using 'complete', '_comp_cd' will be called every time | |
9896 | we attempt word completion for a 'cd' command. | |
ac50fbac CR |
9897 | |
9898 | Many more examples - an extensive collection of completions for most | |
9899 | of the common GNU, Unix, and Linux commands - are available as part of | |
9900 | the bash_completion project. This is installed by default on many | |
9901 | GNU/Linux distributions. Originally written by Ian Macdonald, the | |
8868edaf | 9902 | project now lives at <https://github.com/scop/bash-completion/>. There |
a0c0a00f | 9903 | are ports for other systems such as Solaris and Mac OS X. |
ac50fbac CR |
9904 | |
9905 | An older version of the bash_completion package is distributed with | |
a0c0a00f | 9906 | bash in the 'examples/complete' subdirectory. |
ac50fbac | 9907 | |
bb70624e | 9908 | \1f |
3185942a | 9909 | File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top |
bb70624e | 9910 | |
b80f6443 JA |
9911 | 9 Using History Interactively |
9912 | ***************************** | |
bb70624e | 9913 | |
a0c0a00f CR |
9914 | This chapter describes how to use the GNU History Library interactively, |
9915 | from a user's standpoint. It should be considered a user's guide. For | |
9916 | information on using the GNU History Library in other programs, see the | |
9917 | GNU Readline Library Manual. | |
bb70624e JA |
9918 | |
9919 | * Menu: | |
9920 | ||
9921 | * Bash History Facilities:: How Bash lets you manipulate your command | |
9922 | history. | |
9923 | * Bash History Builtins:: The Bash builtin commands that manipulate | |
9924 | the command history. | |
9925 | * History Interaction:: What it feels like using History as a user. | |
9926 | ||
9927 | \1f | |
9928 | File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively | |
9929 | ||
b80f6443 JA |
9930 | 9.1 Bash History Facilities |
9931 | =========================== | |
bb70624e | 9932 | |
a0c0a00f | 9933 | When the '-o history' option to the 'set' builtin is enabled (*note The |
b80f6443 | 9934 | Set Builtin::), the shell provides access to the "command history", the |
a0c0a00f | 9935 | list of commands previously typed. The value of the 'HISTSIZE' shell |
b80f6443 | 9936 | variable is used as the number of commands to save in a history list. |
a0c0a00f | 9937 | The text of the last '$HISTSIZE' commands (default 500) is saved. The |
b80f6443 JA |
9938 | shell stores each command in the history list prior to parameter and |
9939 | variable expansion but after history expansion is performed, subject to | |
a0c0a00f | 9940 | the values of the shell variables 'HISTIGNORE' and 'HISTCONTROL'. |
bb70624e JA |
9941 | |
9942 | When the shell starts up, the history is initialized from the file | |
a0c0a00f CR |
9943 | named by the 'HISTFILE' variable (default '~/.bash_history'). The file |
9944 | named by the value of 'HISTFILE' is truncated, if necessary, to contain | |
bb70624e | 9945 | no more than the number of lines specified by the value of the |
a0c0a00f CR |
9946 | 'HISTFILESIZE' variable. When a shell with history enabled exits, the |
9947 | last '$HISTSIZE' lines are copied from the history list to the file | |
9948 | named by '$HISTFILE'. If the 'histappend' shell option is set (*note | |
ac50fbac | 9949 | Bash Builtins::), the lines are appended to the history file, otherwise |
a0c0a00f | 9950 | the history file is overwritten. If 'HISTFILE' is unset, or if the |
ac50fbac | 9951 | history file is unwritable, the history is not saved. After saving the |
bb70624e | 9952 | history, the history file is truncated to contain no more than |
a0c0a00f | 9953 | '$HISTFILESIZE' lines. If 'HISTFILESIZE' is unset, or set to null, a |
ac50fbac CR |
9954 | non-numeric value, or a numeric value less than zero, the history file |
9955 | is not truncated. | |
bb70624e | 9956 | |
a0c0a00f CR |
9957 | If the 'HISTTIMEFORMAT' is set, the time stamp information associated |
9958 | with each history entry is written to the history file, marked with the | |
9959 | history comment character. When the history file is read, lines | |
9960 | beginning with the history comment character followed immediately by a | |
9961 | digit are interpreted as timestamps for the following history entry. | |
b80f6443 | 9962 | |
a0c0a00f CR |
9963 | The builtin command 'fc' may be used to list or edit and re-execute a |
9964 | portion of the history list. The 'history' builtin may be used to | |
bb70624e JA |
9965 | display or modify the history list and manipulate the history file. |
9966 | When using command-line editing, search commands are available in each | |
a0c0a00f CR |
9967 | editing mode that provide access to the history list (*note Commands For |
9968 | History::). | |
bb70624e JA |
9969 | |
9970 | The shell allows control over which commands are saved on the history | |
a0c0a00f CR |
9971 | list. The 'HISTCONTROL' and 'HISTIGNORE' variables may be set to cause |
9972 | the shell to save only a subset of the commands entered. The 'cmdhist' | |
bb70624e JA |
9973 | shell option, if enabled, causes the shell to attempt to save each line |
9974 | of a multi-line command in the same history entry, adding semicolons | |
a0c0a00f | 9975 | where necessary to preserve syntactic correctness. The 'lithist' shell |
bb70624e | 9976 | option causes the shell to save the command with embedded newlines |
a0c0a00f | 9977 | instead of semicolons. The 'shopt' builtin is used to set these |
d233b485 | 9978 | options. *Note The Shopt Builtin::, for a description of 'shopt'. |
bb70624e JA |
9979 | |
9980 | \1f | |
9981 | File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively | |
9982 | ||
b80f6443 JA |
9983 | 9.2 Bash History Builtins |
9984 | ========================= | |
bb70624e | 9985 | |
a0c0a00f CR |
9986 | Bash provides two builtin commands which manipulate the history list and |
9987 | history file. | |
bb70624e | 9988 | |
a0c0a00f CR |
9989 | 'fc' |
9990 | fc [-e ENAME] [-lnr] [FIRST] [LAST] | |
9991 | fc -s [PAT=REP] [COMMAND] | |
bb70624e | 9992 | |
ac50fbac CR |
9993 | The first form selects a range of commands from FIRST to LAST from |
9994 | the history list and displays or edits and re-executes them. Both | |
9995 | FIRST and LAST may be specified as a string (to locate the most | |
a0c0a00f CR |
9996 | recent command beginning with that string) or as a number (an index |
9997 | into the history list, where a negative number is used as an offset | |
8868edaf CR |
9998 | from the current command number). |
9999 | ||
10000 | When listing, a FIRST or LAST of 0 is equivalent to -1 and -0 is | |
10001 | equivalent to the current command (usually the 'fc' command); | |
10002 | otherwise 0 is equivalent to -1 and -0 is invalid. | |
10003 | ||
10004 | If LAST is not specified, it is set to FIRST. If FIRST is not | |
10005 | specified, it is set to the previous command for editing and -16 | |
10006 | for listing. If the '-l' flag is given, the commands are listed on | |
10007 | standard output. The '-n' flag suppresses the command numbers when | |
10008 | listing. The '-r' flag reverses the order of the listing. | |
10009 | Otherwise, the editor given by ENAME is invoked on a file | |
10010 | containing those commands. If ENAME is not given, the value of the | |
10011 | following variable expansion is used: '${FCEDIT:-${EDITOR:-vi}}'. | |
10012 | This says to use the value of the 'FCEDIT' variable if set, or the | |
10013 | value of the 'EDITOR' variable if that is set, or 'vi' if neither | |
10014 | is set. When editing is complete, the edited commands are echoed | |
10015 | and executed. | |
bb70624e JA |
10016 | |
10017 | In the second form, COMMAND is re-executed after each instance of | |
ac50fbac | 10018 | PAT in the selected command is replaced by REP. COMMAND is |
8868edaf | 10019 | interpreted the same as FIRST above. |
bb70624e | 10020 | |
a0c0a00f CR |
10021 | A useful alias to use with the 'fc' command is 'r='fc -s'', so that |
10022 | typing 'r cc' runs the last command beginning with 'cc' and typing | |
10023 | 'r' re-executes the last command (*note Aliases::). | |
bb70624e | 10024 | |
a0c0a00f | 10025 | 'history' |
bb70624e JA |
10026 | history [N] |
10027 | history -c | |
10028 | history -d OFFSET | |
d233b485 | 10029 | history -d START-END |
bb70624e JA |
10030 | history [-anrw] [FILENAME] |
10031 | history -ps ARG | |
10032 | ||
a0c0a00f CR |
10033 | With no options, display the history list with line numbers. Lines |
10034 | prefixed with a '*' have been modified. An argument of N lists | |
10035 | only the last N lines. If the shell variable 'HISTTIMEFORMAT' is | |
10036 | set and not null, it is used as a format string for STRFTIME to | |
10037 | display the time stamp associated with each displayed history | |
10038 | entry. No intervening blank is printed between the formatted time | |
10039 | stamp and the history line. | |
b80f6443 JA |
10040 | |
10041 | Options, if supplied, have the following meanings: | |
bb70624e | 10042 | |
a0c0a00f | 10043 | '-c' |
bb70624e JA |
10044 | Clear the history list. This may be combined with the other |
10045 | options to replace the history list completely. | |
10046 | ||
a0c0a00f | 10047 | '-d OFFSET' |
d233b485 CR |
10048 | Delete the history entry at position OFFSET. If OFFSET is |
10049 | positive, it should be specified as it appears when the | |
10050 | history is displayed. If OFFSET is negative, it is | |
10051 | interpreted as relative to one greater than the last history | |
10052 | position, so negative indices count back from the end of the | |
10053 | history, and an index of '-1' refers to the current 'history | |
10054 | -d' command. | |
10055 | ||
10056 | '-d START-END' | |
74091dd4 CR |
10057 | Delete the range of history entries between positions START |
10058 | and END, inclusive. Positive and negative values for START | |
10059 | and END are interpreted as described above. | |
bb70624e | 10060 | |
a0c0a00f CR |
10061 | '-a' |
10062 | Append the new history lines to the history file. These are | |
10063 | history lines entered since the beginning of the current Bash | |
10064 | session, but not already appended to the history file. | |
bb70624e | 10065 | |
a0c0a00f | 10066 | '-n' |
bb70624e | 10067 | Append the history lines not already read from the history |
a0c0a00f CR |
10068 | file to the current history list. These are lines appended to |
10069 | the history file since the beginning of the current Bash | |
bb70624e JA |
10070 | session. |
10071 | ||
a0c0a00f | 10072 | '-r' |
ac50fbac CR |
10073 | Read the history file and append its contents to the history |
10074 | list. | |
bb70624e | 10075 | |
a0c0a00f | 10076 | '-w' |
ac50fbac | 10077 | Write out the current history list to the history file. |
bb70624e | 10078 | |
a0c0a00f | 10079 | '-p' |
bb70624e JA |
10080 | Perform history substitution on the ARGs and display the |
10081 | result on the standard output, without storing the results in | |
10082 | the history list. | |
10083 | ||
a0c0a00f | 10084 | '-s' |
bb70624e JA |
10085 | The ARGs are added to the end of the history list as a single |
10086 | entry. | |
10087 | ||
74091dd4 CR |
10088 | If a FILENAME argument is supplied when any of the '-w', '-r', |
10089 | '-a', or '-n' options is used, Bash uses FILENAME as the history | |
10090 | file. If not, then the value of the 'HISTFILE' variable is used. | |
10091 | ||
10092 | The return value is 0 unless an invalid option is encountered, an | |
10093 | error occurs while reading or writing the history file, an invalid | |
10094 | OFFSET or range is supplied as an argument to '-d', or the history | |
10095 | expansion supplied as an argument to '-p' fails. | |
b80f6443 | 10096 | |
bb70624e JA |
10097 | \1f |
10098 | File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively | |
ccc6cda3 | 10099 | |
b80f6443 JA |
10100 | 9.3 History Expansion |
10101 | ===================== | |
ccc6cda3 | 10102 | |
b80f6443 | 10103 | The History library provides a history expansion feature that is similar |
a0c0a00f | 10104 | to the history expansion provided by 'csh'. This section describes the |
b80f6443 | 10105 | syntax used to manipulate the history information. |
ccc6cda3 | 10106 | |
bb70624e | 10107 | History expansions introduce words from the history list into the |
a0c0a00f CR |
10108 | input stream, making it easy to repeat commands, insert the arguments to |
10109 | a previous command into the current input line, or fix errors in | |
bb70624e | 10110 | previous commands quickly. |
ccc6cda3 | 10111 | |
a0c0a00f | 10112 | History expansion is performed immediately after a complete line is |
d233b485 CR |
10113 | read, before the shell breaks it into words, and is performed on each |
10114 | line individually. Bash attempts to inform the history expansion | |
10115 | functions about quoting still in effect from previous lines. | |
a0c0a00f | 10116 | |
bb70624e JA |
10117 | History expansion takes place in two parts. The first is to |
10118 | determine which line from the history list should be used during | |
10119 | substitution. The second is to select portions of that line for | |
10120 | inclusion into the current one. The line selected from the history is | |
10121 | called the "event", and the portions of that line that are acted upon | |
a0c0a00f CR |
10122 | are called "words". Various "modifiers" are available to manipulate the |
10123 | selected words. The line is broken into words in the same fashion that | |
10124 | Bash does, so that several words surrounded by quotes are considered one | |
10125 | word. History expansions are introduced by the appearance of the | |
d233b485 CR |
10126 | history expansion character, which is '!' by default. |
10127 | ||
10128 | History expansion implements shell-like quoting conventions: a | |
10129 | backslash can be used to remove the special handling for the next | |
10130 | character; single quotes enclose verbatim sequences of characters, and | |
10131 | can be used to inhibit history expansion; and characters enclosed within | |
10132 | double quotes may be subject to history expansion, since backslash can | |
10133 | escape the history expansion character, but single quotes may not, since | |
10134 | they are not treated specially within double quotes. | |
10135 | ||
10136 | When using the shell, only '\' and ''' may be used to escape the | |
10137 | history expansion character, but the history expansion character is also | |
10138 | treated as quoted if it immediately precedes the closing double quote in | |
10139 | a double-quoted string. | |
10140 | ||
10141 | Several shell options settable with the 'shopt' builtin (*note The | |
10142 | Shopt Builtin::) may be used to tailor the behavior of history | |
10143 | expansion. If the 'histverify' shell option is enabled, and Readline is | |
10144 | being used, history substitutions are not immediately passed to the | |
10145 | shell parser. Instead, the expanded line is reloaded into the Readline | |
10146 | editing buffer for further modification. If Readline is being used, and | |
10147 | the 'histreedit' shell option is enabled, a failed history expansion | |
10148 | will be reloaded into the Readline editing buffer for correction. The | |
10149 | '-p' option to the 'history' builtin command may be used to see what a | |
a0c0a00f CR |
10150 | history expansion will do before using it. The '-s' option to the |
10151 | 'history' builtin may be used to add commands to the end of the history | |
10152 | list without actually executing them, so that they are available for | |
10153 | subsequent recall. This is most useful in conjunction with Readline. | |
bb70624e JA |
10154 | |
10155 | The shell allows control of the various characters used by the | |
a0c0a00f | 10156 | history expansion mechanism with the 'histchars' variable, as explained |
3185942a JA |
10157 | above (*note Bash Variables::). The shell uses the history comment |
10158 | character to mark history timestamps when writing the history file. | |
bb70624e JA |
10159 | |
10160 | * Menu: | |
10161 | ||
10162 | * Event Designators:: How to specify which history line to use. | |
10163 | * Word Designators:: Specifying which words are of interest. | |
10164 | * Modifiers:: Modifying the results of substitution. | |
ccc6cda3 JA |
10165 | |
10166 | \1f | |
bb70624e | 10167 | File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction |
ccc6cda3 | 10168 | |
b80f6443 JA |
10169 | 9.3.1 Event Designators |
10170 | ----------------------- | |
ccc6cda3 | 10171 | |
b80f6443 | 10172 | An event designator is a reference to a command line entry in the |
495aee44 | 10173 | history list. Unless the reference is absolute, events are relative to |
a0c0a00f | 10174 | the current position in the history list. |
ccc6cda3 | 10175 | |
a0c0a00f | 10176 | '!' |
bb70624e | 10177 | Start a history substitution, except when followed by a space, tab, |
a0c0a00f CR |
10178 | the end of the line, '=' or '(' (when the 'extglob' shell option is |
10179 | enabled using the 'shopt' builtin). | |
ccc6cda3 | 10180 | |
a0c0a00f | 10181 | '!N' |
bb70624e | 10182 | Refer to command line N. |
ccc6cda3 | 10183 | |
a0c0a00f | 10184 | '!-N' |
bb70624e | 10185 | Refer to the command N lines back. |
ccc6cda3 | 10186 | |
a0c0a00f CR |
10187 | '!!' |
10188 | Refer to the previous command. This is a synonym for '!-1'. | |
ccc6cda3 | 10189 | |
a0c0a00f | 10190 | '!STRING' |
495aee44 CR |
10191 | Refer to the most recent command preceding the current position in |
10192 | the history list starting with STRING. | |
ccc6cda3 | 10193 | |
a0c0a00f | 10194 | '!?STRING[?]' |
495aee44 | 10195 | Refer to the most recent command preceding the current position in |
a0c0a00f | 10196 | the history list containing STRING. The trailing '?' may be |
8868edaf CR |
10197 | omitted if the STRING is followed immediately by a newline. If |
10198 | STRING is missing, the string from the most recent search is used; | |
10199 | it is an error if there is no previous search string. | |
ccc6cda3 | 10200 | |
a0c0a00f | 10201 | '^STRING1^STRING2^' |
bb70624e | 10202 | Quick Substitution. Repeat the last command, replacing STRING1 |
8868edaf | 10203 | with STRING2. Equivalent to '!!:s^STRING1^STRING2^'. |
bb70624e | 10204 | |
a0c0a00f | 10205 | '!#' |
bb70624e | 10206 | The entire command line typed so far. |
ccc6cda3 JA |
10207 | |
10208 | \1f | |
bb70624e | 10209 | File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction |
ccc6cda3 | 10210 | |
b80f6443 JA |
10211 | 9.3.2 Word Designators |
10212 | ---------------------- | |
ccc6cda3 | 10213 | |
a0c0a00f CR |
10214 | Word designators are used to select desired words from the event. A ':' |
10215 | separates the event specification from the word designator. It may be | |
10216 | omitted if the word designator begins with a '^', '$', '*', '-', or '%'. | |
10217 | Words are numbered from the beginning of the line, with the first word | |
10218 | being denoted by 0 (zero). Words are inserted into the current line | |
10219 | separated by single spaces. | |
ccc6cda3 | 10220 | |
bb70624e | 10221 | For example, |
ccc6cda3 | 10222 | |
a0c0a00f | 10223 | '!!' |
bb70624e JA |
10224 | designates the preceding command. When you type this, the |
10225 | preceding command is repeated in toto. | |
ccc6cda3 | 10226 | |
a0c0a00f | 10227 | '!!:$' |
bb70624e | 10228 | designates the last argument of the preceding command. This may be |
a0c0a00f | 10229 | shortened to '!$'. |
ccc6cda3 | 10230 | |
a0c0a00f | 10231 | '!fi:2' |
bb70624e | 10232 | designates the second argument of the most recent command starting |
a0c0a00f | 10233 | with the letters 'fi'. |
ccc6cda3 | 10234 | |
bb70624e | 10235 | Here are the word designators: |
ccc6cda3 | 10236 | |
a0c0a00f CR |
10237 | '0 (zero)' |
10238 | The '0'th word. For many applications, this is the command word. | |
ccc6cda3 | 10239 | |
a0c0a00f | 10240 | 'N' |
bb70624e | 10241 | The Nth word. |
ccc6cda3 | 10242 | |
a0c0a00f | 10243 | '^' |
bb70624e | 10244 | The first argument; that is, word 1. |
ccc6cda3 | 10245 | |
a0c0a00f | 10246 | '$' |
bb70624e | 10247 | The last argument. |
ccc6cda3 | 10248 | |
a0c0a00f | 10249 | '%' |
8868edaf CR |
10250 | The first word matched by the most recent '?STRING?' search, if the |
10251 | search string begins with a character that is part of a word. | |
ccc6cda3 | 10252 | |
a0c0a00f CR |
10253 | 'X-Y' |
10254 | A range of words; '-Y' abbreviates '0-Y'. | |
ccc6cda3 | 10255 | |
a0c0a00f CR |
10256 | '*' |
10257 | All of the words, except the '0'th. This is a synonym for '1-$'. | |
10258 | It is not an error to use '*' if there is just one word in the | |
bb70624e JA |
10259 | event; the empty string is returned in that case. |
10260 | ||
a0c0a00f CR |
10261 | 'X*' |
10262 | Abbreviates 'X-$' | |
bb70624e | 10263 | |
a0c0a00f | 10264 | 'X-' |
8868edaf CR |
10265 | Abbreviates 'X-$' like 'X*', but omits the last word. If 'x' is |
10266 | missing, it defaults to 0. | |
b80f6443 | 10267 | |
bb70624e JA |
10268 | If a word designator is supplied without an event specification, the |
10269 | previous command is used as the event. | |
ccc6cda3 JA |
10270 | |
10271 | \1f | |
bb70624e | 10272 | File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction |
ccc6cda3 | 10273 | |
b80f6443 JA |
10274 | 9.3.3 Modifiers |
10275 | --------------- | |
ccc6cda3 | 10276 | |
b80f6443 | 10277 | After the optional word designator, you can add a sequence of one or |
8868edaf CR |
10278 | more of the following modifiers, each preceded by a ':'. These modify, |
10279 | or edit, the word or words selected from the history event. | |
ccc6cda3 | 10280 | |
a0c0a00f | 10281 | 'h' |
bb70624e | 10282 | Remove a trailing pathname component, leaving only the head. |
ccc6cda3 | 10283 | |
a0c0a00f | 10284 | 't' |
3185942a | 10285 | Remove all leading pathname components, leaving the tail. |
bb70624e | 10286 | |
a0c0a00f CR |
10287 | 'r' |
10288 | Remove a trailing suffix of the form '.SUFFIX', leaving the | |
bb70624e JA |
10289 | basename. |
10290 | ||
a0c0a00f | 10291 | 'e' |
bb70624e JA |
10292 | Remove all but the trailing suffix. |
10293 | ||
a0c0a00f | 10294 | 'p' |
bb70624e JA |
10295 | Print the new command but do not execute it. |
10296 | ||
a0c0a00f | 10297 | 'q' |
bb70624e JA |
10298 | Quote the substituted words, escaping further substitutions. |
10299 | ||
a0c0a00f CR |
10300 | 'x' |
10301 | Quote the substituted words as with 'q', but break into words at | |
8868edaf CR |
10302 | spaces, tabs, and newlines. The 'q' and 'x' modifiers are mutually |
10303 | exclusive; the last one supplied is used. | |
bb70624e | 10304 | |
a0c0a00f | 10305 | 's/OLD/NEW/' |
bb70624e | 10306 | Substitute NEW for the first occurrence of OLD in the event line. |
8868edaf CR |
10307 | Any character may be used as the delimiter in place of '/'. The |
10308 | delimiter may be quoted in OLD and NEW with a single backslash. If | |
10309 | '&' appears in NEW, it is replaced by OLD. A single backslash will | |
10310 | quote the '&'. If OLD is null, it is set to the last OLD | |
10311 | substituted, or, if no previous history substitutions took place, | |
74091dd4 | 10312 | the last STRING in a !?STRING'[?]' search. If NEW is null, each |
8868edaf CR |
10313 | matching OLD is deleted. The final delimiter is optional if it is |
10314 | the last character on the input line. | |
bb70624e | 10315 | |
a0c0a00f | 10316 | '&' |
bb70624e JA |
10317 | Repeat the previous substitution. |
10318 | ||
a0c0a00f CR |
10319 | 'g' |
10320 | 'a' | |
bb70624e | 10321 | Cause changes to be applied over the entire event line. Used in |
a0c0a00f | 10322 | conjunction with 's', as in 'gs/OLD/NEW/', or with '&'. |
b80f6443 | 10323 | |
a0c0a00f | 10324 | 'G' |
8868edaf CR |
10325 | Apply the following 's' or '&' modifier once to each word in the |
10326 | event. | |
b80f6443 | 10327 | |
bb70624e | 10328 | \1f |
3185942a | 10329 | File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top |
bb70624e | 10330 | |
b80f6443 JA |
10331 | 10 Installing Bash |
10332 | ****************** | |
b72432fd | 10333 | |
b80f6443 | 10334 | This chapter provides basic instructions for installing Bash on the |
bb70624e JA |
10335 | various supported platforms. The distribution supports the GNU |
10336 | operating systems, nearly every version of Unix, and several non-Unix | |
10337 | systems such as BeOS and Interix. Other independent ports exist for | |
b80f6443 | 10338 | MS-DOS, OS/2, and Windows platforms. |
ccc6cda3 | 10339 | |
bb70624e | 10340 | * Menu: |
ccc6cda3 | 10341 | |
bb70624e | 10342 | * Basic Installation:: Installation instructions. |
bb70624e JA |
10343 | * Compilers and Options:: How to set special options for various |
10344 | systems. | |
bb70624e JA |
10345 | * Compiling For Multiple Architectures:: How to compile Bash for more |
10346 | than one kind of system from | |
10347 | the same source tree. | |
bb70624e | 10348 | * Installation Names:: How to set the various paths used by the installation. |
bb70624e | 10349 | * Specifying the System Type:: How to configure Bash for a particular system. |
bb70624e JA |
10350 | * Sharing Defaults:: How to share default configuration values among GNU |
10351 | programs. | |
bb70624e | 10352 | * Operation Controls:: Options recognized by the configuration program. |
bb70624e JA |
10353 | * Optional Features:: How to enable and disable optional features when |
10354 | building Bash. | |
ccc6cda3 | 10355 | |
bb70624e JA |
10356 | \1f |
10357 | File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 10358 | |
b80f6443 JA |
10359 | 10.1 Basic Installation |
10360 | ======================= | |
ccc6cda3 | 10361 | |
b80f6443 | 10362 | These are installation instructions for Bash. |
ccc6cda3 | 10363 | |
bb70624e | 10364 | The simplest way to compile Bash is: |
ccc6cda3 | 10365 | |
a0c0a00f CR |
10366 | 1. 'cd' to the directory containing the source code and type |
10367 | './configure' to configure Bash for your system. If you're using | |
10368 | 'csh' on an old version of System V, you might need to type 'sh | |
10369 | ./configure' instead to prevent 'csh' from trying to execute | |
10370 | 'configure' itself. | |
ccc6cda3 | 10371 | |
a0c0a00f | 10372 | Running 'configure' takes some time. While running, it prints |
bb70624e | 10373 | messages telling which features it is checking for. |
ccc6cda3 | 10374 | |
a0c0a00f | 10375 | 2. Type 'make' to compile Bash and build the 'bashbug' bug reporting |
bb70624e | 10376 | script. |
ccc6cda3 | 10377 | |
a0c0a00f | 10378 | 3. Optionally, type 'make tests' to run the Bash test suite. |
ccc6cda3 | 10379 | |
a0c0a00f | 10380 | 4. Type 'make install' to install 'bash' and 'bashbug'. This will |
74091dd4 CR |
10381 | also install the manual pages and Info file, message translation |
10382 | files, some supplemental documentation, a number of example | |
10383 | loadable builtin commands, and a set of header files for developing | |
10384 | loadable builtins. You may need additional privileges to install | |
10385 | 'bash' to your desired destination, so 'sudo make install' might be | |
10386 | required. More information about controlling the locations where | |
10387 | 'bash' and other files are installed is below (*note Installation | |
10388 | Names::). | |
ccc6cda3 | 10389 | |
a0c0a00f | 10390 | The 'configure' shell script attempts to guess correct values for |
bb70624e | 10391 | various system-dependent variables used during compilation. It uses |
a0c0a00f | 10392 | those values to create a 'Makefile' in each directory of the package |
74091dd4 CR |
10393 | (the top directory, the 'builtins', 'doc', 'po', and 'support' |
10394 | directories, each directory under 'lib', and several others). It also | |
10395 | creates a 'config.h' file containing system-dependent definitions. | |
10396 | Finally, it creates a shell script named 'config.status' that you can | |
10397 | run in the future to recreate the current configuration, a file | |
10398 | 'config.cache' that saves the results of its tests to speed up | |
10399 | reconfiguring, and a file 'config.log' containing compiler output | |
10400 | (useful mainly for debugging 'configure'). If at some point | |
10401 | 'config.cache' contains results you don't want to keep, you may remove | |
10402 | or edit it. | |
a0c0a00f CR |
10403 | |
10404 | To find out more about the options and arguments that the 'configure' | |
10405 | script understands, type | |
ccc6cda3 | 10406 | |
d233b485 | 10407 | bash-4.2$ ./configure --help |
ccc6cda3 | 10408 | |
bb70624e | 10409 | at the Bash prompt in your Bash source directory. |
ccc6cda3 | 10410 | |
d233b485 CR |
10411 | If you want to build Bash in a directory separate from the source |
10412 | directory - to build for multiple architectures, for example - just use | |
10413 | the full path to the configure script. The following commands will | |
10414 | build bash in a directory under '/usr/local/build' from the source code | |
10415 | in '/usr/local/src/bash-4.4': | |
10416 | ||
10417 | mkdir /usr/local/build/bash-4.4 | |
10418 | cd /usr/local/build/bash-4.4 | |
10419 | bash /usr/local/src/bash-4.4/configure | |
10420 | make | |
10421 | ||
10422 | See *note Compiling For Multiple Architectures:: for more information | |
10423 | about building in a directory separate from the source. | |
10424 | ||
bb70624e | 10425 | If you need to do unusual things to compile Bash, please try to |
a0c0a00f | 10426 | figure out how 'configure' could check whether or not to do them, and |
bb70624e JA |
10427 | mail diffs or instructions to <bash-maintainers@gnu.org> so they can be |
10428 | considered for the next release. | |
ccc6cda3 | 10429 | |
a0c0a00f CR |
10430 | The file 'configure.ac' is used to create 'configure' by a program |
10431 | called Autoconf. You only need 'configure.ac' if you want to change it | |
10432 | or regenerate 'configure' using a newer version of Autoconf. If you do | |
74091dd4 | 10433 | this, make sure you are using Autoconf version 2.69 or newer. |
ccc6cda3 | 10434 | |
bb70624e | 10435 | You can remove the program binaries and object files from the source |
a0c0a00f CR |
10436 | code directory by typing 'make clean'. To also remove the files that |
10437 | 'configure' created (so you can compile Bash for a different kind of | |
10438 | computer), type 'make distclean'. | |
ccc6cda3 | 10439 | |
bb70624e JA |
10440 | \1f |
10441 | File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash | |
ccc6cda3 | 10442 | |
b80f6443 JA |
10443 | 10.2 Compilers and Options |
10444 | ========================== | |
ccc6cda3 | 10445 | |
a0c0a00f CR |
10446 | Some systems require unusual options for compilation or linking that the |
10447 | 'configure' script does not know about. You can give 'configure' | |
bb70624e JA |
10448 | initial values for variables by setting them in the environment. Using |
10449 | a Bourne-compatible shell, you can do that on the command line like | |
10450 | this: | |
ccc6cda3 | 10451 | |
bb70624e | 10452 | CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure |
ccc6cda3 | 10453 | |
a0c0a00f | 10454 | On systems that have the 'env' program, you can do it like this: |
cce855bc | 10455 | |
bb70624e | 10456 | env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure |
b72432fd | 10457 | |
bb70624e | 10458 | The configuration process uses GCC to build Bash if it is available. |
ccc6cda3 | 10459 | |
bb70624e JA |
10460 | \1f |
10461 | File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash | |
ccc6cda3 | 10462 | |
b80f6443 JA |
10463 | 10.3 Compiling For Multiple Architectures |
10464 | ========================================= | |
ccc6cda3 | 10465 | |
b80f6443 | 10466 | You can compile Bash for more than one kind of computer at the same |
bb70624e | 10467 | time, by placing the object files for each architecture in their own |
a0c0a00f CR |
10468 | directory. To do this, you must use a version of 'make' that supports |
10469 | the 'VPATH' variable, such as GNU 'make'. 'cd' to the directory where | |
10470 | you want the object files and executables to go and run the 'configure' | |
d233b485 CR |
10471 | script from the source directory (*note Basic Installation::). You may |
10472 | need to supply the '--srcdir=PATH' argument to tell 'configure' where | |
10473 | the source files are. 'configure' automatically checks for the source | |
10474 | code in the directory that 'configure' is in and in '..'. | |
ccc6cda3 | 10475 | |
74091dd4 | 10476 | If you have to use a 'make' that does not support the 'VPATH' |
bb70624e JA |
10477 | variable, you can compile Bash for one architecture at a time in the |
10478 | source code directory. After you have installed Bash for one | |
a0c0a00f | 10479 | architecture, use 'make distclean' before reconfiguring for another |
bb70624e | 10480 | architecture. |
ccc6cda3 | 10481 | |
bb70624e | 10482 | Alternatively, if your system supports symbolic links, you can use |
a0c0a00f CR |
10483 | the 'support/mkclone' script to create a build tree which has symbolic |
10484 | links back to each file in the source directory. Here's an example that | |
10485 | creates a build directory in the current directory from a source | |
10486 | directory '/usr/gnu/src/bash-2.0': | |
ccc6cda3 | 10487 | |
bb70624e | 10488 | bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 . |
ccc6cda3 | 10489 | |
a0c0a00f | 10490 | The 'mkclone' script requires Bash, so you must have already built Bash |
bb70624e JA |
10491 | for at least one architecture before you can create build directories |
10492 | for other architectures. | |
ccc6cda3 | 10493 | |
bb70624e JA |
10494 | \1f |
10495 | File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash | |
ccc6cda3 | 10496 | |
b80f6443 JA |
10497 | 10.4 Installation Names |
10498 | ======================= | |
ccc6cda3 | 10499 | |
a0c0a00f | 10500 | By default, 'make install' will install into '/usr/local/bin', |
74091dd4 CR |
10501 | '/usr/local/man', etc.; that is, the "installation prefix" defaults to |
10502 | '/usr/local'. You can specify an installation prefix other than | |
10503 | '/usr/local' by giving 'configure' the option '--prefix=PATH', or by | |
10504 | specifying a value for the 'prefix' 'make' variable when running 'make | |
10505 | install' (e.g., 'make install prefix=PATH'). The 'prefix' variable | |
10506 | provides a default for 'exec_prefix' and other variables used when | |
10507 | installing bash. | |
ccc6cda3 | 10508 | |
bb70624e JA |
10509 | You can specify separate installation prefixes for |
10510 | architecture-specific files and architecture-independent files. If you | |
a0c0a00f | 10511 | give 'configure' the option '--exec-prefix=PATH', 'make install' will |
bb70624e JA |
10512 | use PATH as the prefix for installing programs and libraries. |
10513 | Documentation and other data files will still use the regular prefix. | |
ccc6cda3 | 10514 | |
74091dd4 CR |
10515 | If you would like to change the installation locations for a single |
10516 | run, you can specify these variables as arguments to 'make': 'make | |
10517 | install exec_prefix=/' will install 'bash' and 'bashbug' into '/bin' | |
10518 | instead of the default '/usr/local/bin'. | |
10519 | ||
10520 | If you want to see the files bash will install and where it will | |
10521 | install them without changing anything on your system, specify the | |
10522 | variable 'DESTDIR' as an argument to 'make'. Its value should be the | |
10523 | absolute directory path you'd like to use as the root of your sample | |
10524 | installation tree. For example, | |
10525 | ||
10526 | mkdir /fs1/bash-install | |
10527 | make install DESTDIR=/fs1/bash-install | |
10528 | ||
10529 | will install 'bash' into '/fs1/bash-install/usr/local/bin/bash', the | |
10530 | documentation into directories within | |
10531 | '/fs1/bash-install/usr/local/share', the example loadable builtins into | |
10532 | '/fs1/bash-install/usr/local/lib/bash', and so on. You can use the | |
10533 | usual 'exec_prefix' and 'prefix' variables to alter the directory paths | |
10534 | beneath the value of 'DESTDIR'. | |
10535 | ||
10536 | The GNU Makefile standards provide a more complete description of | |
10537 | these variables and their effects. | |
10538 | ||
ccc6cda3 | 10539 | \1f |
bb70624e | 10540 | File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash |
ccc6cda3 | 10541 | |
b80f6443 JA |
10542 | 10.5 Specifying the System Type |
10543 | =============================== | |
ccc6cda3 | 10544 | |
a0c0a00f | 10545 | There may be some features 'configure' can not figure out automatically, |
74091dd4 | 10546 | but needs to determine by the type of host Bash will run on. Usually |
a0c0a00f CR |
10547 | 'configure' can figure that out, but if it prints a message saying it |
10548 | can not guess the host type, give it the '--host=TYPE' option. 'TYPE' | |
10549 | can either be a short name for the system type, such as 'sun4', or a | |
10550 | canonical name with three fields: 'CPU-COMPANY-SYSTEM' (e.g., | |
10551 | 'i386-unknown-freebsd4.2'). | |
ccc6cda3 | 10552 | |
a0c0a00f | 10553 | See the file 'support/config.sub' for the possible values of each |
bb70624e | 10554 | field. |
ccc6cda3 | 10555 | |
bb70624e JA |
10556 | \1f |
10557 | File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash | |
10558 | ||
b80f6443 JA |
10559 | 10.6 Sharing Defaults |
10560 | ===================== | |
bb70624e | 10561 | |
a0c0a00f CR |
10562 | If you want to set default values for 'configure' scripts to share, you |
10563 | can create a site shell script called 'config.site' that gives default | |
10564 | values for variables like 'CC', 'cache_file', and 'prefix'. 'configure' | |
10565 | looks for 'PREFIX/share/config.site' if it exists, then | |
10566 | 'PREFIX/etc/config.site' if it exists. Or, you can set the | |
10567 | 'CONFIG_SITE' environment variable to the location of the site script. | |
10568 | A warning: the Bash 'configure' looks for a site script, but not all | |
10569 | 'configure' scripts do. | |
ccc6cda3 JA |
10570 | |
10571 | \1f | |
bb70624e | 10572 | File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash |
ccc6cda3 | 10573 | |
b80f6443 JA |
10574 | 10.7 Operation Controls |
10575 | ======================= | |
ccc6cda3 | 10576 | |
a0c0a00f | 10577 | 'configure' recognizes the following options to control how it operates. |
ccc6cda3 | 10578 | |
a0c0a00f | 10579 | '--cache-file=FILE' |
bb70624e | 10580 | Use and save the results of the tests in FILE instead of |
a0c0a00f CR |
10581 | './config.cache'. Set FILE to '/dev/null' to disable caching, for |
10582 | debugging 'configure'. | |
ccc6cda3 | 10583 | |
a0c0a00f CR |
10584 | '--help' |
10585 | Print a summary of the options to 'configure', and exit. | |
ccc6cda3 | 10586 | |
a0c0a00f CR |
10587 | '--quiet' |
10588 | '--silent' | |
10589 | '-q' | |
bb70624e | 10590 | Do not print messages saying which checks are being made. |
ccc6cda3 | 10591 | |
a0c0a00f | 10592 | '--srcdir=DIR' |
bb70624e | 10593 | Look for the Bash source code in directory DIR. Usually |
a0c0a00f | 10594 | 'configure' can determine that directory automatically. |
ccc6cda3 | 10595 | |
a0c0a00f CR |
10596 | '--version' |
10597 | Print the version of Autoconf used to generate the 'configure' | |
bb70624e | 10598 | script, and exit. |
ccc6cda3 | 10599 | |
a0c0a00f CR |
10600 | 'configure' also accepts some other, not widely used, boilerplate |
10601 | options. 'configure --help' prints the complete list. | |
ccc6cda3 | 10602 | |
bb70624e JA |
10603 | \1f |
10604 | File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash | |
ccc6cda3 | 10605 | |
b80f6443 JA |
10606 | 10.8 Optional Features |
10607 | ====================== | |
ccc6cda3 | 10608 | |
a0c0a00f | 10609 | The Bash 'configure' has a number of '--enable-FEATURE' options, where |
b80f6443 | 10610 | FEATURE indicates an optional part of Bash. There are also several |
a0c0a00f CR |
10611 | '--with-PACKAGE' options, where PACKAGE is something like 'bash-malloc' |
10612 | or 'purify'. To turn off the default use of a package, use | |
10613 | '--without-PACKAGE'. To configure Bash without a feature that is | |
10614 | enabled by default, use '--disable-FEATURE'. | |
ccc6cda3 | 10615 | |
a0c0a00f CR |
10616 | Here is a complete list of the '--enable-' and '--with-' options that |
10617 | the Bash 'configure' recognizes. | |
ccc6cda3 | 10618 | |
a0c0a00f | 10619 | '--with-afs' |
bb70624e | 10620 | Define if you are using the Andrew File System from Transarc. |
ccc6cda3 | 10621 | |
a0c0a00f CR |
10622 | '--with-bash-malloc' |
10623 | Use the Bash version of 'malloc' in the directory 'lib/malloc'. | |
10624 | This is not the same 'malloc' that appears in GNU libc, but an | |
10625 | older version originally derived from the 4.2 BSD 'malloc'. This | |
10626 | 'malloc' is very fast, but wastes some space on each allocation. | |
10627 | This option is enabled by default. The 'NOTES' file contains a | |
95732b49 | 10628 | list of systems for which this should be turned off, and |
a0c0a00f | 10629 | 'configure' disables this option automatically for a number of |
95732b49 | 10630 | systems. |
ccc6cda3 | 10631 | |
a0c0a00f | 10632 | '--with-curses' |
bb70624e JA |
10633 | Use the curses library instead of the termcap library. This should |
10634 | be supplied if your system has an inadequate or incomplete termcap | |
10635 | database. | |
ccc6cda3 | 10636 | |
a0c0a00f CR |
10637 | '--with-gnu-malloc' |
10638 | A synonym for '--with-bash-malloc'. | |
ccc6cda3 | 10639 | |
a0c0a00f | 10640 | '--with-installed-readline[=PREFIX]' |
bb70624e | 10641 | Define this to make Bash link with a locally-installed version of |
a0c0a00f CR |
10642 | Readline rather than the version in 'lib/readline'. This works |
10643 | only with Readline 5.0 and later versions. If PREFIX is 'yes' or | |
10644 | not supplied, 'configure' uses the values of the make variables | |
10645 | 'includedir' and 'libdir', which are subdirectories of 'prefix' by | |
f73dda09 JA |
10646 | default, to find the installed version of Readline if it is not in |
10647 | the standard system include and library directories. If PREFIX is | |
a0c0a00f CR |
10648 | 'no', Bash links with the version in 'lib/readline'. If PREFIX is |
10649 | set to any other value, 'configure' treats it as a directory | |
f73dda09 | 10650 | pathname and looks for the installed version of Readline in |
a0c0a00f CR |
10651 | subdirectories of that directory (include files in PREFIX/'include' |
10652 | and the library in PREFIX/'lib'). | |
ccc6cda3 | 10653 | |
74091dd4 CR |
10654 | '--with-libintl-prefix[=PREFIX]' |
10655 | Define this to make Bash link with a locally-installed version of | |
10656 | the libintl library instead of the version in 'lib/intl'. | |
10657 | ||
10658 | '--with-libiconv-prefix[=PREFIX]' | |
10659 | Define this to make Bash look for libiconv in PREFIX instead of the | |
10660 | standard system locations. There is no version included with Bash. | |
ccc6cda3 | 10661 | |
a0c0a00f | 10662 | '--enable-minimal-config' |
bb70624e JA |
10663 | This produces a shell with minimal features, close to the |
10664 | historical Bourne shell. | |
ccc6cda3 | 10665 | |
74091dd4 CR |
10666 | There are several '--enable-' options that alter how Bash is |
10667 | compiled, linked, and installed, rather than changing run-time features. | |
ccc6cda3 | 10668 | |
a0c0a00f | 10669 | '--enable-largefile' |
f73dda09 | 10670 | Enable support for large files |
d233b485 CR |
10671 | (http://www.unix.org/version2/whatsnew/lfs20mar.html) if the |
10672 | operating system requires special compiler options to build | |
a0c0a00f CR |
10673 | programs which can access large files. This is enabled by default, |
10674 | if the operating system provides large file support. | |
f73dda09 | 10675 | |
a0c0a00f | 10676 | '--enable-profiling' |
bb70624e | 10677 | This builds a Bash binary that produces profiling information to be |
a0c0a00f | 10678 | processed by 'gprof' each time it is executed. |
cce855bc | 10679 | |
74091dd4 CR |
10680 | '--enable-separate-helpfiles' |
10681 | Use external files for the documentation displayed by the 'help' | |
10682 | builtin instead of storing the text internally. | |
10683 | ||
a0c0a00f CR |
10684 | '--enable-static-link' |
10685 | This causes Bash to be linked statically, if 'gcc' is being used. | |
bb70624e | 10686 | This could be used to build a version to use as root's shell. |
d166f048 | 10687 | |
a0c0a00f | 10688 | The 'minimal-config' option can be used to disable all of the |
bb70624e | 10689 | following options, but it is processed first, so individual options may |
a0c0a00f | 10690 | be enabled using 'enable-FEATURE'. |
d166f048 | 10691 | |
74091dd4 CR |
10692 | All of the following options except for 'alt-array-implementation', |
10693 | 'disabled-builtins', 'direxpand-default', 'strict-posix-default', and | |
10694 | 'xpg-echo-default' are enabled by default, unless the operating system | |
10695 | does not provide the necessary support. | |
ccc6cda3 | 10696 | |
a0c0a00f CR |
10697 | '--enable-alias' |
10698 | Allow alias expansion and include the 'alias' and 'unalias' | |
28ef6c31 | 10699 | builtins (*note Aliases::). |
ccc6cda3 | 10700 | |
74091dd4 CR |
10701 | '--enable-alt-array-implementation' |
10702 | This builds bash using an alternate implementation of arrays (*note | |
10703 | Arrays::) that provides faster access at the expense of using more | |
10704 | memory (sometimes many times more, depending on how sparse an array | |
10705 | is). | |
10706 | ||
a0c0a00f CR |
10707 | '--enable-arith-for-command' |
10708 | Include support for the alternate form of the 'for' command that | |
10709 | behaves like the C language 'for' statement (*note Looping | |
28ef6c31 | 10710 | Constructs::). |
ccc6cda3 | 10711 | |
a0c0a00f | 10712 | '--enable-array-variables' |
bb70624e | 10713 | Include support for one-dimensional array shell variables (*note |
28ef6c31 | 10714 | Arrays::). |
ccc6cda3 | 10715 | |
a0c0a00f CR |
10716 | '--enable-bang-history' |
10717 | Include support for 'csh'-like history substitution (*note History | |
28ef6c31 | 10718 | Interaction::). |
ccc6cda3 | 10719 | |
a0c0a00f CR |
10720 | '--enable-brace-expansion' |
10721 | Include 'csh'-like brace expansion ( 'b{a,b}c' ==> 'bac bbc' ). | |
3185942a JA |
10722 | See *note Brace Expansion::, for a complete description. |
10723 | ||
a0c0a00f CR |
10724 | '--enable-casemod-attributes' |
10725 | Include support for case-modifying attributes in the 'declare' | |
74091dd4 | 10726 | builtin and assignment statements. Variables with the 'uppercase' |
3185942a JA |
10727 | attribute, for example, will have their values converted to |
10728 | uppercase upon assignment. | |
10729 | ||
a0c0a00f | 10730 | '--enable-casemod-expansion' |
3185942a | 10731 | Include support for case-modifying word expansions. |
ccc6cda3 | 10732 | |
a0c0a00f CR |
10733 | '--enable-command-timing' |
10734 | Include support for recognizing 'time' as a reserved word and for | |
10735 | displaying timing statistics for the pipeline following 'time' | |
28ef6c31 | 10736 | (*note Pipelines::). This allows pipelines as well as shell |
bb70624e | 10737 | builtins and functions to be timed. |
ccc6cda3 | 10738 | |
a0c0a00f CR |
10739 | '--enable-cond-command' |
10740 | Include support for the '[[' conditional command. (*note | |
b80f6443 JA |
10741 | Conditional Constructs::). |
10742 | ||
a0c0a00f | 10743 | '--enable-cond-regexp' |
b80f6443 | 10744 | Include support for matching POSIX regular expressions using the |
a0c0a00f | 10745 | '=~' binary operator in the '[[' conditional command. (*note |
28ef6c31 | 10746 | Conditional Constructs::). |
ccc6cda3 | 10747 | |
a0c0a00f CR |
10748 | '--enable-coprocesses' |
10749 | Include support for coprocesses and the 'coproc' reserved word | |
3185942a JA |
10750 | (*note Pipelines::). |
10751 | ||
a0c0a00f | 10752 | '--enable-debugger' |
95732b49 JA |
10753 | Include support for the bash debugger (distributed separately). |
10754 | ||
d233b485 CR |
10755 | '--enable-dev-fd-stat-broken' |
10756 | If calling 'stat' on /dev/fd/N returns different results than | |
10757 | calling 'fstat' on file descriptor N, supply this option to enable | |
10758 | a workaround. This has implications for conditional commands that | |
10759 | test file attributes. | |
10760 | ||
a0c0a00f CR |
10761 | '--enable-direxpand-default' |
10762 | Cause the 'direxpand' shell option (*note The Shopt Builtin::) to | |
ac50fbac CR |
10763 | be enabled by default when the shell starts. It is normally |
10764 | disabled by default. | |
10765 | ||
a0c0a00f CR |
10766 | '--enable-directory-stack' |
10767 | Include support for a 'csh'-like directory stack and the 'pushd', | |
10768 | 'popd', and 'dirs' builtins (*note The Directory Stack::). | |
ccc6cda3 | 10769 | |
a0c0a00f CR |
10770 | '--enable-disabled-builtins' |
10771 | Allow builtin commands to be invoked via 'builtin xxx' even after | |
10772 | 'xxx' has been disabled using 'enable -n xxx'. See *note Bash | |
10773 | Builtins::, for details of the 'builtin' and 'enable' builtin | |
bb70624e | 10774 | commands. |
ccc6cda3 | 10775 | |
a0c0a00f CR |
10776 | '--enable-dparen-arithmetic' |
10777 | Include support for the '((...))' command (*note Conditional | |
28ef6c31 | 10778 | Constructs::). |
ccc6cda3 | 10779 | |
a0c0a00f | 10780 | '--enable-extended-glob' |
bb70624e | 10781 | Include support for the extended pattern matching features |
3185942a | 10782 | described above under *note Pattern Matching::. |
ccc6cda3 | 10783 | |
a0c0a00f | 10784 | '--enable-extended-glob-default' |
74091dd4 | 10785 | Set the default value of the 'extglob' shell option described above |
0001803f CR |
10786 | under *note The Shopt Builtin:: to be enabled. |
10787 | ||
a0c0a00f CR |
10788 | '--enable-function-import' |
10789 | Include support for importing function definitions exported by | |
10790 | another instance of the shell from the environment. This option is | |
10791 | enabled by default. | |
10792 | ||
10793 | '--enable-glob-asciirange-default' | |
74091dd4 CR |
10794 | Set the default value of the 'globasciiranges' shell option |
10795 | described above under *note The Shopt Builtin:: to be enabled. | |
10796 | This controls the behavior of character ranges when used in pattern | |
10797 | matching bracket expressions. | |
ac50fbac | 10798 | |
a0c0a00f CR |
10799 | '--enable-help-builtin' |
10800 | Include the 'help' builtin, which displays help on shell builtins | |
28ef6c31 | 10801 | and variables (*note Bash Builtins::). |
ccc6cda3 | 10802 | |
a0c0a00f CR |
10803 | '--enable-history' |
10804 | Include command history and the 'fc' and 'history' builtin commands | |
10805 | (*note Bash History Facilities::). | |
ccc6cda3 | 10806 | |
a0c0a00f CR |
10807 | '--enable-job-control' |
10808 | This enables the job control features (*note Job Control::), if the | |
10809 | operating system supports them. | |
ccc6cda3 | 10810 | |
a0c0a00f | 10811 | '--enable-multibyte' |
b80f6443 JA |
10812 | This enables support for multibyte characters if the operating |
10813 | system provides the necessary support. | |
10814 | ||
a0c0a00f | 10815 | '--enable-net-redirections' |
bb70624e | 10816 | This enables the special handling of filenames of the form |
a0c0a00f | 10817 | '/dev/tcp/HOST/PORT' and '/dev/udp/HOST/PORT' when used in |
28ef6c31 | 10818 | redirections (*note Redirections::). |
ccc6cda3 | 10819 | |
a0c0a00f | 10820 | '--enable-process-substitution' |
28ef6c31 JA |
10821 | This enables process substitution (*note Process Substitution::) if |
10822 | the operating system provides the necessary support. | |
ccc6cda3 | 10823 | |
a0c0a00f | 10824 | '--enable-progcomp' |
95732b49 JA |
10825 | Enable the programmable completion facilities (*note Programmable |
10826 | Completion::). If Readline is not enabled, this option has no | |
10827 | effect. | |
10828 | ||
a0c0a00f | 10829 | '--enable-prompt-string-decoding' |
bb70624e | 10830 | Turn on the interpretation of a number of backslash-escaped |
d233b485 | 10831 | characters in the '$PS0', '$PS1', '$PS2', and '$PS4' prompt |
ac50fbac CR |
10832 | strings. See *note Controlling the Prompt::, for a complete list |
10833 | of prompt string escape sequences. | |
ccc6cda3 | 10834 | |
a0c0a00f | 10835 | '--enable-readline' |
bb70624e | 10836 | Include support for command-line editing and history with the Bash |
28ef6c31 | 10837 | version of the Readline library (*note Command Line Editing::). |
ccc6cda3 | 10838 | |
a0c0a00f | 10839 | '--enable-restricted' |
bb70624e | 10840 | Include support for a "restricted shell". If this is enabled, |
a0c0a00f | 10841 | Bash, when called as 'rbash', enters a restricted mode. See *note |
bb70624e | 10842 | The Restricted Shell::, for a description of restricted mode. |
ccc6cda3 | 10843 | |
a0c0a00f CR |
10844 | '--enable-select' |
10845 | Include the 'select' compound command, which allows the generation | |
495aee44 | 10846 | of simple menus (*note Conditional Constructs::). |
ccc6cda3 | 10847 | |
a0c0a00f CR |
10848 | '--enable-single-help-strings' |
10849 | Store the text displayed by the 'help' builtin as a single string | |
95732b49 | 10850 | for each help topic. This aids in translating the text to |
a0c0a00f CR |
10851 | different languages. You may need to disable this if your compiler |
10852 | cannot handle very long string literals. | |
95732b49 | 10853 | |
a0c0a00f | 10854 | '--enable-strict-posix-default' |
95732b49 JA |
10855 | Make Bash POSIX-conformant by default (*note Bash POSIX Mode::). |
10856 | ||
74091dd4 CR |
10857 | '--enable-translatable-strings' |
10858 | Enable support for '$"STRING"' translatable strings (*note Locale | |
10859 | Translation::). | |
10860 | ||
a0c0a00f CR |
10861 | '--enable-usg-echo-default' |
10862 | A synonym for '--enable-xpg-echo-default'. | |
ccc6cda3 | 10863 | |
a0c0a00f CR |
10864 | '--enable-xpg-echo-default' |
10865 | Make the 'echo' builtin expand backslash-escaped characters by | |
10866 | default, without requiring the '-e' option. This sets the default | |
10867 | value of the 'xpg_echo' shell option to 'on', which makes the Bash | |
10868 | 'echo' behave more like the version specified in the Single Unix | |
10869 | Specification, version 3. *Note Bash Builtins::, for a description | |
10870 | of the escape sequences that 'echo' recognizes. | |
ccc6cda3 | 10871 | |
a0c0a00f CR |
10872 | The file 'config-top.h' contains C Preprocessor '#define' statements |
10873 | for options which are not settable from 'configure'. Some of these are | |
10874 | not meant to be changed; beware of the consequences if you do. Read the | |
10875 | comments associated with each definition for more information about its | |
10876 | effect. | |
ccc6cda3 | 10877 | |
bb70624e JA |
10878 | \1f |
10879 | File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top | |
d166f048 | 10880 | |
b80f6443 JA |
10881 | Appendix A Reporting Bugs |
10882 | ************************* | |
ccc6cda3 | 10883 | |
b80f6443 | 10884 | Please report all bugs you find in Bash. But first, you should make |
bb70624e | 10885 | sure that it really is a bug, and that it appears in the latest version |
b80f6443 | 10886 | of Bash. The latest version of Bash is always available for FTP from |
74091dd4 CR |
10887 | <ftp://ftp.gnu.org/pub/gnu/bash/> and from |
10888 | <http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz>. | |
ccc6cda3 | 10889 | |
bb70624e | 10890 | Once you have determined that a bug actually exists, use the |
a0c0a00f CR |
10891 | 'bashbug' command to submit a bug report. If you have a fix, you are |
10892 | encouraged to mail that as well! Suggestions and 'philosophical' bug | |
bb70624e | 10893 | reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet |
a0c0a00f | 10894 | newsgroup 'gnu.bash.bug'. |
ccc6cda3 | 10895 | |
bb70624e JA |
10896 | All bug reports should include: |
10897 | * The version number of Bash. | |
bb70624e | 10898 | * The hardware and operating system. |
bb70624e | 10899 | * The compiler used to compile Bash. |
bb70624e | 10900 | * A description of the bug behaviour. |
a0c0a00f | 10901 | * A short script or 'recipe' which exercises the bug and may be used |
bb70624e | 10902 | to reproduce it. |
ccc6cda3 | 10903 | |
a0c0a00f | 10904 | 'bashbug' inserts the first three items automatically into the template |
bb70624e JA |
10905 | it provides for filing a bug report. |
10906 | ||
ac50fbac | 10907 | Please send all reports concerning this manual to <bug-bash@gnu.org>. |
ccc6cda3 JA |
10908 | |
10909 | \1f | |
3185942a | 10910 | File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top |
ccc6cda3 | 10911 | |
b80f6443 JA |
10912 | Appendix B Major Differences From The Bourne Shell |
10913 | ************************************************** | |
ccc6cda3 | 10914 | |
b80f6443 | 10915 | Bash implements essentially the same grammar, parameter and variable |
bb70624e | 10916 | expansion, redirection, and quoting as the Bourne Shell. Bash uses the |
0628567a JA |
10917 | POSIX standard as the specification of how these features are to be |
10918 | implemented. There are some differences between the traditional Bourne | |
10919 | shell and Bash; this section quickly details the differences of | |
bb70624e | 10920 | significance. A number of these differences are explained in greater |
a0c0a00f | 10921 | depth in previous sections. This section uses the version of 'sh' |
95732b49 JA |
10922 | included in SVR4.2 (the last version of the historical Bourne shell) as |
10923 | the baseline reference. | |
ccc6cda3 | 10924 | |
bb70624e | 10925 | * Bash is POSIX-conformant, even where the POSIX specification |
a0c0a00f | 10926 | differs from traditional 'sh' behavior (*note Bash POSIX Mode::). |
ccc6cda3 | 10927 | |
bb70624e | 10928 | * Bash has multi-character invocation options (*note Invoking |
28ef6c31 | 10929 | Bash::). |
ccc6cda3 | 10930 | |
28ef6c31 | 10931 | * Bash has command-line editing (*note Command Line Editing::) and |
a0c0a00f | 10932 | the 'bind' builtin. |
ccc6cda3 | 10933 | |
bb70624e | 10934 | * Bash provides a programmable word completion mechanism (*note |
a0c0a00f CR |
10935 | Programmable Completion::), and builtin commands 'complete', |
10936 | 'compgen', and 'compopt', to manipulate it. | |
ccc6cda3 | 10937 | |
28ef6c31 | 10938 | * Bash has command history (*note Bash History Facilities::) and the |
a0c0a00f | 10939 | 'history' and 'fc' builtins to manipulate it. The Bash history |
b80f6443 | 10940 | list maintains timestamp information and uses the value of the |
a0c0a00f | 10941 | 'HISTTIMEFORMAT' variable to display it. |
ccc6cda3 | 10942 | |
a0c0a00f | 10943 | * Bash implements 'csh'-like history expansion (*note History |
28ef6c31 | 10944 | Interaction::). |
ccc6cda3 | 10945 | |
28ef6c31 | 10946 | * Bash has one-dimensional array variables (*note Arrays::), and the |
bb70624e JA |
10947 | appropriate variable expansions and assignment syntax to use them. |
10948 | Several of the Bash builtins take options to act on arrays. Bash | |
10949 | provides a number of built-in array variables. | |
ccc6cda3 | 10950 | |
a0c0a00f CR |
10951 | * The '$'...'' quoting syntax, which expands ANSI-C backslash-escaped |
10952 | characters in the text between the single quotes, is supported | |
10953 | (*note ANSI-C Quoting::). | |
ccc6cda3 | 10954 | |
a0c0a00f CR |
10955 | * Bash supports the '$"..."' quoting syntax to do locale-specific |
10956 | translation of the characters between the double quotes. The '-D', | |
10957 | '--dump-strings', and '--dump-po-strings' invocation options list | |
10958 | the translatable strings found in a script (*note Locale | |
28ef6c31 | 10959 | Translation::). |
ccc6cda3 | 10960 | |
a0c0a00f CR |
10961 | * Bash implements the '!' keyword to negate the return value of a |
10962 | pipeline (*note Pipelines::). Very useful when an 'if' statement | |
10963 | needs to act only if a test fails. The Bash '-o pipefail' option | |
10964 | to 'set' will cause a pipeline to return a failure status if any | |
95732b49 | 10965 | command fails. |
ccc6cda3 | 10966 | |
a0c0a00f | 10967 | * Bash has the 'time' reserved word and command timing (*note |
28ef6c31 | 10968 | Pipelines::). The display of the timing statistics may be |
a0c0a00f | 10969 | controlled with the 'TIMEFORMAT' variable. |
ccc6cda3 | 10970 | |
a0c0a00f | 10971 | * Bash implements the 'for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic |
bb70624e | 10972 | for command, similar to the C language (*note Looping |
28ef6c31 | 10973 | Constructs::). |
ccc6cda3 | 10974 | |
a0c0a00f | 10975 | * Bash includes the 'select' compound command, which allows the |
28ef6c31 | 10976 | generation of simple menus (*note Conditional Constructs::). |
ccc6cda3 | 10977 | |
a0c0a00f CR |
10978 | * Bash includes the '[[' compound command, which makes conditional |
10979 | testing part of the shell grammar (*note Conditional Constructs::), | |
10980 | including optional regular expression matching. | |
95732b49 | 10981 | |
a0c0a00f CR |
10982 | * Bash provides optional case-insensitive matching for the 'case' and |
10983 | '[[' constructs. | |
ccc6cda3 | 10984 | |
28ef6c31 JA |
10985 | * Bash includes brace expansion (*note Brace Expansion::) and tilde |
10986 | expansion (*note Tilde Expansion::). | |
ccc6cda3 | 10987 | |
a0c0a00f | 10988 | * Bash implements command aliases and the 'alias' and 'unalias' |
28ef6c31 | 10989 | builtins (*note Aliases::). |
ccc6cda3 | 10990 | |
a0c0a00f | 10991 | * Bash provides shell arithmetic, the '((' compound command (*note |
28ef6c31 JA |
10992 | Conditional Constructs::), and arithmetic expansion (*note Shell |
10993 | Arithmetic::). | |
ccc6cda3 | 10994 | |
bb70624e JA |
10995 | * Variables present in the shell's initial environment are |
10996 | automatically exported to child processes. The Bourne shell does | |
10997 | not normally do this unless the variables are explicitly marked | |
a0c0a00f | 10998 | using the 'export' command. |
ccc6cda3 | 10999 | |
a0c0a00f | 11000 | * Bash supports the '+=' assignment operator, which appends to the |
95732b49 JA |
11001 | value of the variable named on the left hand side. |
11002 | ||
a0c0a00f | 11003 | * Bash includes the POSIX pattern removal '%', '#', '%%' and '##' |
bb70624e | 11004 | expansions to remove leading or trailing substrings from variable |
28ef6c31 | 11005 | values (*note Shell Parameter Expansion::). |
ccc6cda3 | 11006 | |
a0c0a00f | 11007 | * The expansion '${#xx}', which returns the length of '${xx}', is |
28ef6c31 | 11008 | supported (*note Shell Parameter Expansion::). |
ccc6cda3 | 11009 | |
a0c0a00f CR |
11010 | * The expansion '${var:'OFFSET'[:'LENGTH']}', which expands to the |
11011 | substring of 'var''s value of length LENGTH, beginning at OFFSET, | |
28ef6c31 | 11012 | is present (*note Shell Parameter Expansion::). |
ccc6cda3 | 11013 | |
74091dd4 CR |
11014 | * The expansion '${VAR/[/]'PATTERN'[/'REPLACEMENT']}', which matches |
11015 | PATTERN and replaces it with REPLACEMENT in the value of VAR, is | |
28ef6c31 | 11016 | available (*note Shell Parameter Expansion::). |
ccc6cda3 | 11017 | |
a0c0a00f | 11018 | * The expansion '${!PREFIX*}' expansion, which expands to the names |
bb70624e | 11019 | of all shell variables whose names begin with PREFIX, is available |
28ef6c31 | 11020 | (*note Shell Parameter Expansion::). |
ccc6cda3 | 11021 | |
74091dd4 | 11022 | * Bash has indirect variable expansion using '${!word}' (*note Shell |
28ef6c31 | 11023 | Parameter Expansion::). |
ccc6cda3 | 11024 | |
a0c0a00f | 11025 | * Bash can expand positional parameters beyond '$9' using '${NUM}'. |
ccc6cda3 | 11026 | |
a0c0a00f CR |
11027 | * The POSIX '$()' form of command substitution is implemented (*note |
11028 | Command Substitution::), and preferred to the Bourne shell's '``' | |
bb70624e | 11029 | (which is also implemented for backwards compatibility). |
ccc6cda3 | 11030 | |
28ef6c31 | 11031 | * Bash has process substitution (*note Process Substitution::). |
ccc6cda3 | 11032 | |
a0c0a00f CR |
11033 | * Bash automatically assigns variables that provide information about |
11034 | the current user ('UID', 'EUID', and 'GROUPS'), the current host | |
11035 | ('HOSTTYPE', 'OSTYPE', 'MACHTYPE', and 'HOSTNAME'), and the | |
11036 | instance of Bash that is running ('BASH', 'BASH_VERSION', and | |
11037 | 'BASH_VERSINFO'). *Note Bash Variables::, for details. | |
ccc6cda3 | 11038 | |
a0c0a00f CR |
11039 | * The 'IFS' variable is used to split only the results of expansion, |
11040 | not all words (*note Word Splitting::). This closes a longstanding | |
11041 | shell security hole. | |
ccc6cda3 | 11042 | |
a0c0a00f | 11043 | * The filename expansion bracket expression code uses '!' and '^' to |
ac50fbac | 11044 | negate the set of characters between the brackets. The Bourne |
a0c0a00f | 11045 | shell uses only '!'. |
ac50fbac | 11046 | |
0628567a | 11047 | * Bash implements the full set of POSIX filename expansion operators, |
74091dd4 CR |
11048 | including character classes, equivalence classes, and collating |
11049 | symbols (*note Filename Expansion::). | |
ccc6cda3 | 11050 | |
bb70624e | 11051 | * Bash implements extended pattern matching features when the |
a0c0a00f | 11052 | 'extglob' shell option is enabled (*note Pattern Matching::). |
ccc6cda3 | 11053 | |
bb70624e | 11054 | * It is possible to have a variable and a function with the same |
a0c0a00f | 11055 | name; 'sh' does not separate the two name spaces. |
ccc6cda3 | 11056 | |
bb70624e | 11057 | * Bash functions are permitted to have local variables using the |
a0c0a00f | 11058 | 'local' builtin, and thus useful recursive functions may be written |
28ef6c31 | 11059 | (*note Bash Builtins::). |
ccc6cda3 | 11060 | |
bb70624e | 11061 | * Variable assignments preceding commands affect only that command, |
a0c0a00f | 11062 | even builtins and functions (*note Environment::). In 'sh', all |
bb70624e JA |
11063 | variable assignments preceding commands are global unless the |
11064 | command is executed from the file system. | |
ccc6cda3 | 11065 | |
bb70624e | 11066 | * Bash performs filename expansion on filenames specified as operands |
28ef6c31 | 11067 | to input and output redirection operators (*note Redirections::). |
ccc6cda3 | 11068 | |
a0c0a00f CR |
11069 | * Bash contains the '<>' redirection operator, allowing a file to be |
11070 | opened for both reading and writing, and the '&>' redirection | |
bb70624e | 11071 | operator, for directing standard output and standard error to the |
28ef6c31 | 11072 | same file (*note Redirections::). |
d166f048 | 11073 | |
a0c0a00f | 11074 | * Bash includes the '<<<' redirection operator, allowing a string to |
95732b49 JA |
11075 | be used as the standard input to a command. |
11076 | ||
a0c0a00f | 11077 | * Bash implements the '[n]<&WORD' and '[n]>&WORD' redirection |
95732b49 JA |
11078 | operators, which move one file descriptor to another. |
11079 | ||
bb70624e | 11080 | * Bash treats a number of filenames specially when they are used in |
28ef6c31 | 11081 | redirection operators (*note Redirections::). |
ccc6cda3 | 11082 | |
bb70624e | 11083 | * Bash can open network connections to arbitrary machines and |
28ef6c31 | 11084 | services with the redirection operators (*note Redirections::). |
ccc6cda3 | 11085 | |
a0c0a00f CR |
11086 | * The 'noclobber' option is available to avoid overwriting existing |
11087 | files with output redirection (*note The Set Builtin::). The '>|' | |
11088 | redirection operator may be used to override 'noclobber'. | |
ccc6cda3 | 11089 | |
a0c0a00f CR |
11090 | * The Bash 'cd' and 'pwd' builtins (*note Bourne Shell Builtins::) |
11091 | each take '-L' and '-P' options to switch between logical and | |
bb70624e | 11092 | physical modes. |
b72432fd | 11093 | |
bb70624e JA |
11094 | * Bash allows a function to override a builtin with the same name, |
11095 | and provides access to that builtin's functionality within the | |
a0c0a00f | 11096 | function via the 'builtin' and 'command' builtins (*note Bash |
28ef6c31 | 11097 | Builtins::). |
ccc6cda3 | 11098 | |
a0c0a00f | 11099 | * The 'command' builtin allows selective disabling of functions when |
28ef6c31 | 11100 | command lookup is performed (*note Bash Builtins::). |
ccc6cda3 | 11101 | |
a0c0a00f | 11102 | * Individual builtins may be enabled or disabled using the 'enable' |
28ef6c31 | 11103 | builtin (*note Bash Builtins::). |
cce855bc | 11104 | |
a0c0a00f | 11105 | * The Bash 'exec' builtin takes additional options that allow users |
bb70624e JA |
11106 | to control the contents of the environment passed to the executed |
11107 | command, and what the zeroth argument to the command is to be | |
28ef6c31 | 11108 | (*note Bourne Shell Builtins::). |
cce855bc | 11109 | |
bb70624e | 11110 | * Shell functions may be exported to children via the environment |
a0c0a00f | 11111 | using 'export -f' (*note Shell Functions::). |
cce855bc | 11112 | |
a0c0a00f CR |
11113 | * The Bash 'export', 'readonly', and 'declare' builtins can take a |
11114 | '-f' option to act on shell functions, a '-p' option to display | |
bb70624e | 11115 | variables with various attributes set in a format that can be used |
a0c0a00f CR |
11116 | as shell input, a '-n' option to remove various variable |
11117 | attributes, and 'name=value' arguments to set variable attributes | |
bb70624e | 11118 | and values simultaneously. |
ccc6cda3 | 11119 | |
a0c0a00f | 11120 | * The Bash 'hash' builtin allows a name to be associated with an |
bb70624e | 11121 | arbitrary filename, even when that filename cannot be found by |
a0c0a00f | 11122 | searching the '$PATH', using 'hash -p' (*note Bourne Shell |
28ef6c31 | 11123 | Builtins::). |
ccc6cda3 | 11124 | |
a0c0a00f | 11125 | * Bash includes a 'help' builtin for quick reference to shell |
28ef6c31 | 11126 | facilities (*note Bash Builtins::). |
ccc6cda3 | 11127 | |
a0c0a00f | 11128 | * The 'printf' builtin is available to display formatted output |
28ef6c31 | 11129 | (*note Bash Builtins::). |
ccc6cda3 | 11130 | |
a0c0a00f CR |
11131 | * The Bash 'read' builtin (*note Bash Builtins::) will read a line |
11132 | ending in '\' with the '-r' option, and will use the 'REPLY' | |
11133 | variable as a default if no non-option arguments are supplied. The | |
11134 | Bash 'read' builtin also accepts a prompt string with the '-p' | |
11135 | option and will use Readline to obtain the line when given the '-e' | |
11136 | option. The 'read' builtin also has additional options to control | |
11137 | input: the '-s' option will turn off echoing of input characters as | |
11138 | they are read, the '-t' option will allow 'read' to time out if | |
11139 | input does not arrive within a specified number of seconds, the | |
11140 | '-n' option will allow reading only a specified number of | |
11141 | characters rather than a full line, and the '-d' option will read | |
11142 | until a particular character rather than newline. | |
11143 | ||
11144 | * The 'return' builtin may be used to abort execution of scripts | |
11145 | executed with the '.' or 'source' builtins (*note Bourne Shell | |
28ef6c31 | 11146 | Builtins::). |
d166f048 | 11147 | |
a0c0a00f CR |
11148 | * Bash includes the 'shopt' builtin, for finer control of shell |
11149 | optional capabilities (*note The Shopt Builtin::), and allows these | |
11150 | options to be set and unset at shell invocation (*note Invoking | |
11151 | Bash::). | |
d166f048 | 11152 | |
a0c0a00f | 11153 | * Bash has much more optional behavior controllable with the 'set' |
28ef6c31 | 11154 | builtin (*note The Set Builtin::). |
cce855bc | 11155 | |
a0c0a00f | 11156 | * The '-x' ('xtrace') option displays commands other than simple |
b80f6443 JA |
11157 | commands when performing an execution trace (*note The Set |
11158 | Builtin::). | |
11159 | ||
a0c0a00f | 11160 | * The 'test' builtin (*note Bourne Shell Builtins::) is slightly |
bb70624e JA |
11161 | different, as it implements the POSIX algorithm, which specifies |
11162 | the behavior based on the number of arguments. | |
ccc6cda3 | 11163 | |
a0c0a00f | 11164 | * Bash includes the 'caller' builtin, which displays the context of |
b80f6443 | 11165 | any active subroutine call (a shell function or a script executed |
74091dd4 | 11166 | with the '.' or 'source' builtins). This supports the Bash |
b80f6443 JA |
11167 | debugger. |
11168 | ||
a0c0a00f CR |
11169 | * The 'trap' builtin (*note Bourne Shell Builtins::) allows a 'DEBUG' |
11170 | pseudo-signal specification, similar to 'EXIT'. Commands specified | |
11171 | with a 'DEBUG' trap are executed before every simple command, 'for' | |
11172 | command, 'case' command, 'select' command, every arithmetic 'for' | |
11173 | command, and before the first command executes in a shell function. | |
11174 | The 'DEBUG' trap is not inherited by shell functions unless the | |
11175 | function has been given the 'trace' attribute or the 'functrace' | |
11176 | option has been enabled using the 'shopt' builtin. The 'extdebug' | |
11177 | shell option has additional effects on the 'DEBUG' trap. | |
11178 | ||
11179 | The 'trap' builtin (*note Bourne Shell Builtins::) allows an 'ERR' | |
11180 | pseudo-signal specification, similar to 'EXIT' and 'DEBUG'. | |
11181 | Commands specified with an 'ERR' trap are executed after a simple | |
11182 | command fails, with a few exceptions. The 'ERR' trap is not | |
11183 | inherited by shell functions unless the '-o errtrace' option to the | |
11184 | 'set' builtin is enabled. | |
11185 | ||
11186 | The 'trap' builtin (*note Bourne Shell Builtins::) allows a | |
11187 | 'RETURN' pseudo-signal specification, similar to 'EXIT' and | |
74091dd4 | 11188 | 'DEBUG'. Commands specified with a 'RETURN' trap are executed |
b80f6443 | 11189 | before execution resumes after a shell function or a shell script |
a0c0a00f CR |
11190 | executed with '.' or 'source' returns. The 'RETURN' trap is not |
11191 | inherited by shell functions unless the function has been given the | |
11192 | 'trace' attribute or the 'functrace' option has been enabled using | |
11193 | the 'shopt' builtin. | |
f73dda09 | 11194 | |
a0c0a00f | 11195 | * The Bash 'type' builtin is more extensive and gives more |
28ef6c31 | 11196 | information about the names it finds (*note Bash Builtins::). |
cce855bc | 11197 | |
a0c0a00f CR |
11198 | * The Bash 'umask' builtin permits a '-p' option to cause the output |
11199 | to be displayed in the form of a 'umask' command that may be reused | |
11200 | as input (*note Bourne Shell Builtins::). | |
d166f048 | 11201 | |
a0c0a00f CR |
11202 | * Bash implements a 'csh'-like directory stack, and provides the |
11203 | 'pushd', 'popd', and 'dirs' builtins to manipulate it (*note The | |
11204 | Directory Stack::). Bash also makes the directory stack visible as | |
11205 | the value of the 'DIRSTACK' shell variable. | |
d166f048 | 11206 | |
bb70624e | 11207 | * Bash interprets special backslash-escaped characters in the prompt |
ac50fbac | 11208 | strings when interactive (*note Controlling the Prompt::). |
d166f048 | 11209 | |
bb70624e | 11210 | * The Bash restricted mode is more useful (*note The Restricted |
28ef6c31 | 11211 | Shell::); the SVR4.2 shell restricted mode is too limited. |
ccc6cda3 | 11212 | |
a0c0a00f | 11213 | * The 'disown' builtin can remove a job from the internal shell job |
28ef6c31 | 11214 | table (*note Job Control Builtins::) or suppress the sending of |
a0c0a00f | 11215 | 'SIGHUP' to a job when the shell exits as the result of a 'SIGHUP'. |
ccc6cda3 | 11216 | |
95732b49 JA |
11217 | * Bash includes a number of features to support a separate debugger |
11218 | for shell scripts. | |
11219 | ||
a0c0a00f CR |
11220 | * The SVR4.2 shell has two privilege-related builtins ('mldmode' and |
11221 | 'priv') not present in Bash. | |
ccc6cda3 | 11222 | |
a0c0a00f | 11223 | * Bash does not have the 'stop' or 'newgrp' builtins. |
d166f048 | 11224 | |
a0c0a00f | 11225 | * Bash does not use the 'SHACCT' variable or perform shell |
bb70624e | 11226 | accounting. |
d166f048 | 11227 | |
a0c0a00f | 11228 | * The SVR4.2 'sh' uses a 'TIMEOUT' variable like Bash uses 'TMOUT'. |
28ef6c31 | 11229 | |
3185942a | 11230 | More features unique to Bash may be found in *note Bash Features::. |
ccc6cda3 | 11231 | |
b80f6443 JA |
11232 | B.1 Implementation Differences From The SVR4.2 Shell |
11233 | ==================================================== | |
ccc6cda3 | 11234 | |
b80f6443 JA |
11235 | Since Bash is a completely new implementation, it does not suffer from |
11236 | many of the limitations of the SVR4.2 shell. For instance: | |
ccc6cda3 | 11237 | |
bb70624e | 11238 | * Bash does not fork a subshell when redirecting into or out of a |
a0c0a00f | 11239 | shell control structure such as an 'if' or 'while' statement. |
ccc6cda3 | 11240 | |
bb70624e | 11241 | * Bash does not allow unbalanced quotes. The SVR4.2 shell will |
a0c0a00f | 11242 | silently insert a needed closing quote at 'EOF' under certain |
bb70624e | 11243 | circumstances. This can be the cause of some hard-to-find errors. |
ccc6cda3 | 11244 | |
bb70624e | 11245 | * The SVR4.2 shell uses a baroque memory management scheme based on |
a0c0a00f CR |
11246 | trapping 'SIGSEGV'. If the shell is started from a process with |
11247 | 'SIGSEGV' blocked (e.g., by using the 'system()' C library function | |
11248 | call), it misbehaves badly. | |
ccc6cda3 | 11249 | |
bb70624e | 11250 | * In a questionable attempt at security, the SVR4.2 shell, when |
a0c0a00f | 11251 | invoked without the '-p' option, will alter its real and effective |
bb70624e JA |
11252 | UID and GID if they are less than some magic threshold value, |
11253 | commonly 100. This can lead to unexpected results. | |
ccc6cda3 | 11254 | |
a0c0a00f CR |
11255 | * The SVR4.2 shell does not allow users to trap 'SIGSEGV', 'SIGALRM', |
11256 | or 'SIGCHLD'. | |
ccc6cda3 | 11257 | |
a0c0a00f CR |
11258 | * The SVR4.2 shell does not allow the 'IFS', 'MAILCHECK', 'PATH', |
11259 | 'PS1', or 'PS2' variables to be unset. | |
ccc6cda3 | 11260 | |
a0c0a00f | 11261 | * The SVR4.2 shell treats '^' as the undocumented equivalent of '|'. |
ccc6cda3 | 11262 | |
a0c0a00f CR |
11263 | * Bash allows multiple option arguments when it is invoked ('-x -v'); |
11264 | the SVR4.2 shell allows only one option argument ('-xv'). In fact, | |
11265 | some versions of the shell dump core if the second argument begins | |
11266 | with a '-'. | |
ccc6cda3 | 11267 | |
bb70624e | 11268 | * The SVR4.2 shell exits a script if any builtin fails; Bash exits a |
0628567a JA |
11269 | script only if one of the POSIX special builtins fails, and only |
11270 | for certain failures, as enumerated in the POSIX standard. | |
ccc6cda3 | 11271 | |
a0c0a00f | 11272 | * The SVR4.2 shell behaves differently when invoked as 'jsh' (it |
bb70624e | 11273 | turns on job control). |
ccc6cda3 JA |
11274 | |
11275 | \1f | |
3185942a | 11276 | File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top |
b80f6443 | 11277 | |
3185942a JA |
11278 | Appendix C GNU Free Documentation License |
11279 | ***************************************** | |
b80f6443 | 11280 | |
0001803f | 11281 | Version 1.3, 3 November 2008 |
b80f6443 | 11282 | |
0001803f | 11283 | Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. |
a0c0a00f | 11284 | <http://fsf.org/> |
b80f6443 JA |
11285 | |
11286 | Everyone is permitted to copy and distribute verbatim copies | |
11287 | of this license document, but changing it is not allowed. | |
11288 | ||
11289 | 0. PREAMBLE | |
11290 | ||
11291 | The purpose of this License is to make a manual, textbook, or other | |
11292 | functional and useful document "free" in the sense of freedom: to | |
11293 | assure everyone the effective freedom to copy and redistribute it, | |
11294 | with or without modifying it, either commercially or | |
11295 | noncommercially. Secondarily, this License preserves for the | |
11296 | author and publisher a way to get credit for their work, while not | |
11297 | being considered responsible for modifications made by others. | |
11298 | ||
11299 | This License is a kind of "copyleft", which means that derivative | |
11300 | works of the document must themselves be free in the same sense. | |
11301 | It complements the GNU General Public License, which is a copyleft | |
11302 | license designed for free software. | |
11303 | ||
11304 | We have designed this License in order to use it for manuals for | |
11305 | free software, because free software needs free documentation: a | |
11306 | free program should come with manuals providing the same freedoms | |
11307 | that the software does. But this License is not limited to | |
11308 | software manuals; it can be used for any textual work, regardless | |
a0c0a00f CR |
11309 | of subject matter or whether it is published as a printed book. We |
11310 | recommend this License principally for works whose purpose is | |
b80f6443 JA |
11311 | instruction or reference. |
11312 | ||
11313 | 1. APPLICABILITY AND DEFINITIONS | |
11314 | ||
11315 | This License applies to any manual or other work, in any medium, | |
a0c0a00f CR |
11316 | that contains a notice placed by the copyright holder saying it can |
11317 | be distributed under the terms of this License. Such a notice | |
b80f6443 JA |
11318 | grants a world-wide, royalty-free license, unlimited in duration, |
11319 | to use that work under the conditions stated herein. The | |
11320 | "Document", below, refers to any such manual or work. Any member | |
a0c0a00f CR |
11321 | of the public is a licensee, and is addressed as "you". You accept |
11322 | the license if you copy, modify or distribute the work in a way | |
11323 | requiring permission under copyright law. | |
b80f6443 JA |
11324 | |
11325 | A "Modified Version" of the Document means any work containing the | |
11326 | Document or a portion of it, either copied verbatim, or with | |
11327 | modifications and/or translated into another language. | |
11328 | ||
11329 | A "Secondary Section" is a named appendix or a front-matter section | |
11330 | of the Document that deals exclusively with the relationship of the | |
11331 | publishers or authors of the Document to the Document's overall | |
11332 | subject (or to related matters) and contains nothing that could | |
11333 | fall directly within that overall subject. (Thus, if the Document | |
11334 | is in part a textbook of mathematics, a Secondary Section may not | |
11335 | explain any mathematics.) The relationship could be a matter of | |
11336 | historical connection with the subject or with related matters, or | |
11337 | of legal, commercial, philosophical, ethical or political position | |
11338 | regarding them. | |
11339 | ||
11340 | The "Invariant Sections" are certain Secondary Sections whose | |
a0c0a00f CR |
11341 | titles are designated, as being those of Invariant Sections, in the |
11342 | notice that says that the Document is released under this License. | |
11343 | If a section does not fit the above definition of Secondary then it | |
11344 | is not allowed to be designated as Invariant. The Document may | |
11345 | contain zero Invariant Sections. If the Document does not identify | |
11346 | any Invariant Sections then there are none. | |
b80f6443 JA |
11347 | |
11348 | The "Cover Texts" are certain short passages of text that are | |
11349 | listed, as Front-Cover Texts or Back-Cover Texts, in the notice | |
11350 | that says that the Document is released under this License. A | |
11351 | Front-Cover Text may be at most 5 words, and a Back-Cover Text may | |
11352 | be at most 25 words. | |
11353 | ||
11354 | A "Transparent" copy of the Document means a machine-readable copy, | |
11355 | represented in a format whose specification is available to the | |
11356 | general public, that is suitable for revising the document | |
a0c0a00f CR |
11357 | straightforwardly with generic text editors or (for images composed |
11358 | of pixels) generic paint programs or (for drawings) some widely | |
11359 | available drawing editor, and that is suitable for input to text | |
11360 | formatters or for automatic translation to a variety of formats | |
11361 | suitable for input to text formatters. A copy made in an otherwise | |
11362 | Transparent file format whose markup, or absence of markup, has | |
11363 | been arranged to thwart or discourage subsequent modification by | |
11364 | readers is not Transparent. An image format is not Transparent if | |
11365 | used for any substantial amount of text. A copy that is not | |
11366 | "Transparent" is called "Opaque". | |
b80f6443 JA |
11367 | |
11368 | Examples of suitable formats for Transparent copies include plain | |
11369 | ASCII without markup, Texinfo input format, LaTeX input format, | |
a0c0a00f CR |
11370 | SGML or XML using a publicly available DTD, and standard-conforming |
11371 | simple HTML, PostScript or PDF designed for human modification. | |
11372 | Examples of transparent image formats include PNG, XCF and JPG. | |
11373 | Opaque formats include proprietary formats that can be read and | |
11374 | edited only by proprietary word processors, SGML or XML for which | |
11375 | the DTD and/or processing tools are not generally available, and | |
11376 | the machine-generated HTML, PostScript or PDF produced by some word | |
11377 | processors for output purposes only. | |
b80f6443 JA |
11378 | |
11379 | The "Title Page" means, for a printed book, the title page itself, | |
11380 | plus such following pages as are needed to hold, legibly, the | |
11381 | material this License requires to appear in the title page. For | |
11382 | works in formats which do not have any title page as such, "Title | |
11383 | Page" means the text near the most prominent appearance of the | |
11384 | work's title, preceding the beginning of the body of the text. | |
11385 | ||
0001803f CR |
11386 | The "publisher" means any person or entity that distributes copies |
11387 | of the Document to the public. | |
11388 | ||
b80f6443 JA |
11389 | A section "Entitled XYZ" means a named subunit of the Document |
11390 | whose title either is precisely XYZ or contains XYZ in parentheses | |
11391 | following text that translates XYZ in another language. (Here XYZ | |
11392 | stands for a specific section name mentioned below, such as | |
11393 | "Acknowledgements", "Dedications", "Endorsements", or "History".) | |
11394 | To "Preserve the Title" of such a section when you modify the | |
11395 | Document means that it remains a section "Entitled XYZ" according | |
11396 | to this definition. | |
11397 | ||
11398 | The Document may include Warranty Disclaimers next to the notice | |
11399 | which states that this License applies to the Document. These | |
11400 | Warranty Disclaimers are considered to be included by reference in | |
11401 | this License, but only as regards disclaiming warranties: any other | |
11402 | implication that these Warranty Disclaimers may have is void and | |
11403 | has no effect on the meaning of this License. | |
11404 | ||
11405 | 2. VERBATIM COPYING | |
11406 | ||
11407 | You may copy and distribute the Document in any medium, either | |
11408 | commercially or noncommercially, provided that this License, the | |
11409 | copyright notices, and the license notice saying this License | |
11410 | applies to the Document are reproduced in all copies, and that you | |
11411 | add no other conditions whatsoever to those of this License. You | |
11412 | may not use technical measures to obstruct or control the reading | |
11413 | or further copying of the copies you make or distribute. However, | |
11414 | you may accept compensation in exchange for copies. If you | |
a0c0a00f CR |
11415 | distribute a large enough number of copies you must also follow the |
11416 | conditions in section 3. | |
b80f6443 JA |
11417 | |
11418 | You may also lend copies, under the same conditions stated above, | |
11419 | and you may publicly display copies. | |
11420 | ||
11421 | 3. COPYING IN QUANTITY | |
11422 | ||
11423 | If you publish printed copies (or copies in media that commonly | |
11424 | have printed covers) of the Document, numbering more than 100, and | |
11425 | the Document's license notice requires Cover Texts, you must | |
11426 | enclose the copies in covers that carry, clearly and legibly, all | |
11427 | these Cover Texts: Front-Cover Texts on the front cover, and | |
11428 | Back-Cover Texts on the back cover. Both covers must also clearly | |
11429 | and legibly identify you as the publisher of these copies. The | |
a0c0a00f CR |
11430 | front cover must present the full title with all words of the title |
11431 | equally prominent and visible. You may add other material on the | |
11432 | covers in addition. Copying with changes limited to the covers, as | |
11433 | long as they preserve the title of the Document and satisfy these | |
11434 | conditions, can be treated as verbatim copying in other respects. | |
b80f6443 JA |
11435 | |
11436 | If the required texts for either cover are too voluminous to fit | |
11437 | legibly, you should put the first ones listed (as many as fit | |
11438 | reasonably) on the actual cover, and continue the rest onto | |
11439 | adjacent pages. | |
11440 | ||
11441 | If you publish or distribute Opaque copies of the Document | |
a0c0a00f CR |
11442 | numbering more than 100, you must either include a machine-readable |
11443 | Transparent copy along with each Opaque copy, or state in or with | |
11444 | each Opaque copy a computer-network location from which the general | |
11445 | network-using public has access to download using public-standard | |
11446 | network protocols a complete Transparent copy of the Document, free | |
11447 | of added material. If you use the latter option, you must take | |
11448 | reasonably prudent steps, when you begin distribution of Opaque | |
11449 | copies in quantity, to ensure that this Transparent copy will | |
11450 | remain thus accessible at the stated location until at least one | |
11451 | year after the last time you distribute an Opaque copy (directly or | |
11452 | through your agents or retailers) of that edition to the public. | |
b80f6443 JA |
11453 | |
11454 | It is requested, but not required, that you contact the authors of | |
a0c0a00f CR |
11455 | the Document well before redistributing any large number of copies, |
11456 | to give them a chance to provide you with an updated version of the | |
11457 | Document. | |
b80f6443 JA |
11458 | |
11459 | 4. MODIFICATIONS | |
11460 | ||
11461 | You may copy and distribute a Modified Version of the Document | |
11462 | under the conditions of sections 2 and 3 above, provided that you | |
a0c0a00f CR |
11463 | release the Modified Version under precisely this License, with the |
11464 | Modified Version filling the role of the Document, thus licensing | |
11465 | distribution and modification of the Modified Version to whoever | |
11466 | possesses a copy of it. In addition, you must do these things in | |
11467 | the Modified Version: | |
b80f6443 JA |
11468 | |
11469 | A. Use in the Title Page (and on the covers, if any) a title | |
a0c0a00f CR |
11470 | distinct from that of the Document, and from those of previous |
11471 | versions (which should, if there were any, be listed in the | |
11472 | History section of the Document). You may use the same title | |
11473 | as a previous version if the original publisher of that | |
11474 | version gives permission. | |
b80f6443 JA |
11475 | |
11476 | B. List on the Title Page, as authors, one or more persons or | |
11477 | entities responsible for authorship of the modifications in | |
11478 | the Modified Version, together with at least five of the | |
11479 | principal authors of the Document (all of its principal | |
11480 | authors, if it has fewer than five), unless they release you | |
11481 | from this requirement. | |
11482 | ||
11483 | C. State on the Title page the name of the publisher of the | |
11484 | Modified Version, as the publisher. | |
11485 | ||
11486 | D. Preserve all the copyright notices of the Document. | |
11487 | ||
11488 | E. Add an appropriate copyright notice for your modifications | |
11489 | adjacent to the other copyright notices. | |
11490 | ||
11491 | F. Include, immediately after the copyright notices, a license | |
11492 | notice giving the public permission to use the Modified | |
11493 | Version under the terms of this License, in the form shown in | |
11494 | the Addendum below. | |
11495 | ||
11496 | G. Preserve in that license notice the full lists of Invariant | |
11497 | Sections and required Cover Texts given in the Document's | |
11498 | license notice. | |
11499 | ||
11500 | H. Include an unaltered copy of this License. | |
11501 | ||
11502 | I. Preserve the section Entitled "History", Preserve its Title, | |
11503 | and add to it an item stating at least the title, year, new | |
a0c0a00f CR |
11504 | authors, and publisher of the Modified Version as given on the |
11505 | Title Page. If there is no section Entitled "History" in the | |
11506 | Document, create one stating the title, year, authors, and | |
11507 | publisher of the Document as given on its Title Page, then add | |
11508 | an item describing the Modified Version as stated in the | |
11509 | previous sentence. | |
b80f6443 JA |
11510 | |
11511 | J. Preserve the network location, if any, given in the Document | |
11512 | for public access to a Transparent copy of the Document, and | |
11513 | likewise the network locations given in the Document for | |
a0c0a00f CR |
11514 | previous versions it was based on. These may be placed in the |
11515 | "History" section. You may omit a network location for a work | |
11516 | that was published at least four years before the Document | |
11517 | itself, or if the original publisher of the version it refers | |
11518 | to gives permission. | |
b80f6443 JA |
11519 | |
11520 | K. For any section Entitled "Acknowledgements" or "Dedications", | |
a0c0a00f CR |
11521 | Preserve the Title of the section, and preserve in the section |
11522 | all the substance and tone of each of the contributor | |
b80f6443 JA |
11523 | acknowledgements and/or dedications given therein. |
11524 | ||
a0c0a00f CR |
11525 | L. Preserve all the Invariant Sections of the Document, unaltered |
11526 | in their text and in their titles. Section numbers or the | |
11527 | equivalent are not considered part of the section titles. | |
b80f6443 JA |
11528 | |
11529 | M. Delete any section Entitled "Endorsements". Such a section | |
11530 | may not be included in the Modified Version. | |
11531 | ||
11532 | N. Do not retitle any existing section to be Entitled | |
11533 | "Endorsements" or to conflict in title with any Invariant | |
11534 | Section. | |
11535 | ||
11536 | O. Preserve any Warranty Disclaimers. | |
11537 | ||
11538 | If the Modified Version includes new front-matter sections or | |
11539 | appendices that qualify as Secondary Sections and contain no | |
a0c0a00f CR |
11540 | material copied from the Document, you may at your option designate |
11541 | some or all of these sections as invariant. To do this, add their | |
11542 | titles to the list of Invariant Sections in the Modified Version's | |
11543 | license notice. These titles must be distinct from any other | |
11544 | section titles. | |
b80f6443 JA |
11545 | |
11546 | You may add a section Entitled "Endorsements", provided it contains | |
11547 | nothing but endorsements of your Modified Version by various | |
11548 | parties--for example, statements of peer review or that the text | |
11549 | has been approved by an organization as the authoritative | |
11550 | definition of a standard. | |
11551 | ||
11552 | You may add a passage of up to five words as a Front-Cover Text, | |
a0c0a00f CR |
11553 | and a passage of up to 25 words as a Back-Cover Text, to the end of |
11554 | the list of Cover Texts in the Modified Version. Only one passage | |
11555 | of Front-Cover Text and one of Back-Cover Text may be added by (or | |
11556 | through arrangements made by) any one entity. If the Document | |
11557 | already includes a cover text for the same cover, previously added | |
11558 | by you or by arrangement made by the same entity you are acting on | |
11559 | behalf of, you may not add another; but you may replace the old | |
11560 | one, on explicit permission from the previous publisher that added | |
11561 | the old one. | |
b80f6443 JA |
11562 | |
11563 | The author(s) and publisher(s) of the Document do not by this | |
11564 | License give permission to use their names for publicity for or to | |
11565 | assert or imply endorsement of any Modified Version. | |
11566 | ||
11567 | 5. COMBINING DOCUMENTS | |
11568 | ||
11569 | You may combine the Document with other documents released under | |
11570 | this License, under the terms defined in section 4 above for | |
a0c0a00f CR |
11571 | modified versions, provided that you include in the combination all |
11572 | of the Invariant Sections of all of the original documents, | |
b80f6443 JA |
11573 | unmodified, and list them all as Invariant Sections of your |
11574 | combined work in its license notice, and that you preserve all | |
11575 | their Warranty Disclaimers. | |
11576 | ||
11577 | The combined work need only contain one copy of this License, and | |
11578 | multiple identical Invariant Sections may be replaced with a single | |
11579 | copy. If there are multiple Invariant Sections with the same name | |
11580 | but different contents, make the title of each such section unique | |
11581 | by adding at the end of it, in parentheses, the name of the | |
11582 | original author or publisher of that section if known, or else a | |
11583 | unique number. Make the same adjustment to the section titles in | |
11584 | the list of Invariant Sections in the license notice of the | |
11585 | combined work. | |
11586 | ||
11587 | In the combination, you must combine any sections Entitled | |
11588 | "History" in the various original documents, forming one section | |
11589 | Entitled "History"; likewise combine any sections Entitled | |
11590 | "Acknowledgements", and any sections Entitled "Dedications". You | |
11591 | must delete all sections Entitled "Endorsements." | |
11592 | ||
11593 | 6. COLLECTIONS OF DOCUMENTS | |
11594 | ||
11595 | You may make a collection consisting of the Document and other | |
11596 | documents released under this License, and replace the individual | |
11597 | copies of this License in the various documents with a single copy | |
11598 | that is included in the collection, provided that you follow the | |
a0c0a00f CR |
11599 | rules of this License for verbatim copying of each of the documents |
11600 | in all other respects. | |
b80f6443 JA |
11601 | |
11602 | You may extract a single document from such a collection, and | |
11603 | distribute it individually under this License, provided you insert | |
a0c0a00f CR |
11604 | a copy of this License into the extracted document, and follow this |
11605 | License in all other respects regarding verbatim copying of that | |
11606 | document. | |
b80f6443 JA |
11607 | |
11608 | 7. AGGREGATION WITH INDEPENDENT WORKS | |
11609 | ||
11610 | A compilation of the Document or its derivatives with other | |
a0c0a00f CR |
11611 | separate and independent documents or works, in or on a volume of a |
11612 | storage or distribution medium, is called an "aggregate" if the | |
b80f6443 JA |
11613 | copyright resulting from the compilation is not used to limit the |
11614 | legal rights of the compilation's users beyond what the individual | |
3185942a | 11615 | works permit. When the Document is included in an aggregate, this |
b80f6443 JA |
11616 | License does not apply to the other works in the aggregate which |
11617 | are not themselves derivative works of the Document. | |
11618 | ||
11619 | If the Cover Text requirement of section 3 is applicable to these | |
11620 | copies of the Document, then if the Document is less than one half | |
11621 | of the entire aggregate, the Document's Cover Texts may be placed | |
11622 | on covers that bracket the Document within the aggregate, or the | |
11623 | electronic equivalent of covers if the Document is in electronic | |
11624 | form. Otherwise they must appear on printed covers that bracket | |
11625 | the whole aggregate. | |
11626 | ||
11627 | 8. TRANSLATION | |
11628 | ||
11629 | Translation is considered a kind of modification, so you may | |
11630 | distribute translations of the Document under the terms of section | |
11631 | 4. Replacing Invariant Sections with translations requires special | |
11632 | permission from their copyright holders, but you may include | |
11633 | translations of some or all Invariant Sections in addition to the | |
11634 | original versions of these Invariant Sections. You may include a | |
11635 | translation of this License, and all the license notices in the | |
11636 | Document, and any Warranty Disclaimers, provided that you also | |
11637 | include the original English version of this License and the | |
11638 | original versions of those notices and disclaimers. In case of a | |
11639 | disagreement between the translation and the original version of | |
11640 | this License or a notice or disclaimer, the original version will | |
11641 | prevail. | |
11642 | ||
11643 | If a section in the Document is Entitled "Acknowledgements", | |
11644 | "Dedications", or "History", the requirement (section 4) to | |
11645 | Preserve its Title (section 1) will typically require changing the | |
11646 | actual title. | |
11647 | ||
11648 | 9. TERMINATION | |
11649 | ||
11650 | You may not copy, modify, sublicense, or distribute the Document | |
0001803f CR |
11651 | except as expressly provided under this License. Any attempt |
11652 | otherwise to copy, modify, sublicense, or distribute it is void, | |
11653 | and will automatically terminate your rights under this License. | |
11654 | ||
11655 | However, if you cease all violation of this License, then your | |
11656 | license from a particular copyright holder is reinstated (a) | |
a0c0a00f CR |
11657 | provisionally, unless and until the copyright holder explicitly and |
11658 | finally terminates your license, and (b) permanently, if the | |
0001803f CR |
11659 | copyright holder fails to notify you of the violation by some |
11660 | reasonable means prior to 60 days after the cessation. | |
11661 | ||
11662 | Moreover, your license from a particular copyright holder is | |
11663 | reinstated permanently if the copyright holder notifies you of the | |
11664 | violation by some reasonable means, this is the first time you have | |
11665 | received notice of violation of this License (for any work) from | |
11666 | that copyright holder, and you cure the violation prior to 30 days | |
11667 | after your receipt of the notice. | |
11668 | ||
11669 | Termination of your rights under this section does not terminate | |
a0c0a00f CR |
11670 | the licenses of parties who have received copies or rights from you |
11671 | under this License. If your rights have been terminated and not | |
11672 | permanently reinstated, receipt of a copy of some or all of the | |
11673 | same material does not give you any rights to use it. | |
b80f6443 | 11674 | |
a0c0a00f | 11675 | 10. FUTURE REVISIONS OF THIS LICENSE |
b80f6443 JA |
11676 | |
11677 | The Free Software Foundation may publish new, revised versions of | |
11678 | the GNU Free Documentation License from time to time. Such new | |
11679 | versions will be similar in spirit to the present version, but may | |
11680 | differ in detail to address new problems or concerns. See | |
a0c0a00f | 11681 | <http://www.gnu.org/copyleft/>. |
b80f6443 JA |
11682 | |
11683 | Each version of the License is given a distinguishing version | |
11684 | number. If the Document specifies that a particular numbered | |
11685 | version of this License "or any later version" applies to it, you | |
11686 | have the option of following the terms and conditions either of | |
11687 | that specified version or of any later version that has been | |
a0c0a00f CR |
11688 | published (not as a draft) by the Free Software Foundation. If the |
11689 | Document does not specify a version number of this License, you may | |
11690 | choose any version ever published (not as a draft) by the Free | |
11691 | Software Foundation. If the Document specifies that a proxy can | |
11692 | decide which future versions of this License can be used, that | |
0001803f CR |
11693 | proxy's public statement of acceptance of a version permanently |
11694 | authorizes you to choose that version for the Document. | |
11695 | ||
a0c0a00f | 11696 | 11. RELICENSING |
0001803f CR |
11697 | |
11698 | "Massive Multiauthor Collaboration Site" (or "MMC Site") means any | |
11699 | World Wide Web server that publishes copyrightable works and also | |
11700 | provides prominent facilities for anybody to edit those works. A | |
11701 | public wiki that anybody can edit is an example of such a server. | |
11702 | A "Massive Multiauthor Collaboration" (or "MMC") contained in the | |
11703 | site means any set of copyrightable works thus published on the MMC | |
11704 | site. | |
11705 | ||
11706 | "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 | |
11707 | license published by Creative Commons Corporation, a not-for-profit | |
11708 | corporation with a principal place of business in San Francisco, | |
11709 | California, as well as future copyleft versions of that license | |
11710 | published by that same organization. | |
11711 | ||
11712 | "Incorporate" means to publish or republish a Document, in whole or | |
11713 | in part, as part of another Document. | |
11714 | ||
11715 | An MMC is "eligible for relicensing" if it is licensed under this | |
11716 | License, and if all works that were first published under this | |
11717 | License somewhere other than this MMC, and subsequently | |
11718 | incorporated in whole or in part into the MMC, (1) had no cover | |
11719 | texts or invariant sections, and (2) were thus incorporated prior | |
11720 | to November 1, 2008. | |
11721 | ||
11722 | The operator of an MMC Site may republish an MMC contained in the | |
11723 | site under CC-BY-SA on the same site at any time before August 1, | |
11724 | 2009, provided the MMC is eligible for relicensing. | |
11725 | ||
3185942a JA |
11726 | ADDENDUM: How to use this License for your documents |
11727 | ==================================================== | |
b80f6443 JA |
11728 | |
11729 | To use this License in a document you have written, include a copy of | |
11730 | the License in the document and put the following copyright and license | |
11731 | notices just after the title page: | |
11732 | ||
11733 | Copyright (C) YEAR YOUR NAME. | |
11734 | Permission is granted to copy, distribute and/or modify this document | |
0001803f | 11735 | under the terms of the GNU Free Documentation License, Version 1.3 |
b80f6443 | 11736 | or any later version published by the Free Software Foundation; |
3185942a JA |
11737 | with no Invariant Sections, no Front-Cover Texts, and no Back-Cover |
11738 | Texts. A copy of the license is included in the section entitled ``GNU | |
b80f6443 JA |
11739 | Free Documentation License''. |
11740 | ||
11741 | If you have Invariant Sections, Front-Cover Texts and Back-Cover | |
a0c0a00f | 11742 | Texts, replace the "with...Texts." line with this: |
b80f6443 JA |
11743 | |
11744 | with the Invariant Sections being LIST THEIR TITLES, with | |
11745 | the Front-Cover Texts being LIST, and with the Back-Cover Texts | |
11746 | being LIST. | |
11747 | ||
11748 | If you have Invariant Sections without Cover Texts, or some other | |
11749 | combination of the three, merge those two alternatives to suit the | |
11750 | situation. | |
11751 | ||
11752 | If your document contains nontrivial examples of program code, we | |
a0c0a00f CR |
11753 | recommend releasing these examples in parallel under your choice of free |
11754 | software license, such as the GNU General Public License, to permit | |
11755 | their use in free software. | |
b80f6443 JA |
11756 | |
11757 | \1f | |
3185942a JA |
11758 | File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top |
11759 | ||
11760 | Appendix D Indexes | |
11761 | ****************** | |
11762 | ||
11763 | * Menu: | |
11764 | ||
11765 | * Builtin Index:: Index of Bash builtin commands. | |
11766 | * Reserved Word Index:: Index of Bash reserved words. | |
11767 | * Variable Index:: Quick reference helps you find the | |
11768 | variable you want. | |
11769 | * Function Index:: Index of bindable Readline functions. | |
11770 | * Concept Index:: General index for concepts described in | |
11771 | this manual. | |
11772 | ||
11773 | \1f | |
11774 | File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes | |
ccc6cda3 | 11775 | |
3185942a JA |
11776 | D.1 Index of Shell Builtin Commands |
11777 | =================================== | |
ccc6cda3 | 11778 | |
b80f6443 | 11779 | \0\b[index\0\b] |
ccc6cda3 JA |
11780 | * Menu: |
11781 | ||
e8ce775d | 11782 | * .: Bourne Shell Builtins. |
ac50fbac | 11783 | (line 17) |
e8ce775d | 11784 | * :: Bourne Shell Builtins. |
b80f6443 | 11785 | (line 11) |
e8ce775d | 11786 | * [: Bourne Shell Builtins. |
74091dd4 | 11787 | (line 275) |
b80f6443 | 11788 | * alias: Bash Builtins. (line 11) |
e8ce775d | 11789 | * bg: Job Control Builtins. |
b80f6443 JA |
11790 | (line 7) |
11791 | * bind: Bash Builtins. (line 21) | |
e8ce775d | 11792 | * break: Bourne Shell Builtins. |
74091dd4 CR |
11793 | (line 37) |
11794 | * builtin: Bash Builtins. (line 108) | |
11795 | * caller: Bash Builtins. (line 117) | |
e8ce775d | 11796 | * cd: Bourne Shell Builtins. |
74091dd4 CR |
11797 | (line 45) |
11798 | * command: Bash Builtins. (line 134) | |
bb70624e | 11799 | * compgen: Programmable Completion Builtins. |
ac50fbac | 11800 | (line 12) |
bb70624e | 11801 | * complete: Programmable Completion Builtins. |
ac50fbac | 11802 | (line 30) |
3185942a | 11803 | * compopt: Programmable Completion Builtins. |
74091dd4 | 11804 | (line 238) |
e8ce775d | 11805 | * continue: Bourne Shell Builtins. |
74091dd4 CR |
11806 | (line 90) |
11807 | * declare: Bash Builtins. (line 154) | |
bb70624e | 11808 | * dirs: Directory Stack Builtins. |
b80f6443 | 11809 | (line 7) |
e8ce775d | 11810 | * disown: Job Control Builtins. |
74091dd4 CR |
11811 | (line 104) |
11812 | * echo: Bash Builtins. (line 257) | |
11813 | * enable: Bash Builtins. (line 306) | |
e8ce775d | 11814 | * eval: Bourne Shell Builtins. |
74091dd4 | 11815 | (line 99) |
e8ce775d | 11816 | * exec: Bourne Shell Builtins. |
74091dd4 | 11817 | (line 107) |
e8ce775d | 11818 | * exit: Bourne Shell Builtins. |
74091dd4 | 11819 | (line 125) |
e8ce775d | 11820 | * export: Bourne Shell Builtins. |
74091dd4 | 11821 | (line 132) |
cce855bc | 11822 | * fc: Bash History Builtins. |
b80f6443 | 11823 | (line 10) |
e8ce775d | 11824 | * fg: Job Control Builtins. |
ac50fbac | 11825 | (line 17) |
e8ce775d | 11826 | * getopts: Bourne Shell Builtins. |
74091dd4 | 11827 | (line 148) |
e8ce775d | 11828 | * hash: Bourne Shell Builtins. |
74091dd4 CR |
11829 | (line 192) |
11830 | * help: Bash Builtins. (line 342) | |
cce855bc | 11831 | * history: Bash History Builtins. |
8868edaf | 11832 | (line 46) |
e8ce775d | 11833 | * jobs: Job Control Builtins. |
ac50fbac | 11834 | (line 27) |
e8ce775d | 11835 | * kill: Job Control Builtins. |
a0c0a00f | 11836 | (line 58) |
74091dd4 CR |
11837 | * let: Bash Builtins. (line 361) |
11838 | * local: Bash Builtins. (line 369) | |
11839 | * logout: Bash Builtins. (line 385) | |
11840 | * mapfile: Bash Builtins. (line 390) | |
bb70624e | 11841 | * popd: Directory Stack Builtins. |
a0c0a00f | 11842 | (line 35) |
74091dd4 | 11843 | * printf: Bash Builtins. (line 436) |
bb70624e | 11844 | * pushd: Directory Stack Builtins. |
74091dd4 | 11845 | (line 69) |
e8ce775d | 11846 | * pwd: Bourne Shell Builtins. |
74091dd4 CR |
11847 | (line 212) |
11848 | * read: Bash Builtins. (line 488) | |
11849 | * readarray: Bash Builtins. (line 585) | |
e8ce775d | 11850 | * readonly: Bourne Shell Builtins. |
74091dd4 | 11851 | (line 222) |
e8ce775d | 11852 | * return: Bourne Shell Builtins. |
74091dd4 | 11853 | (line 241) |
3185942a | 11854 | * set: The Set Builtin. (line 11) |
e8ce775d | 11855 | * shift: Bourne Shell Builtins. |
74091dd4 | 11856 | (line 262) |
3185942a | 11857 | * shopt: The Shopt Builtin. (line 9) |
74091dd4 | 11858 | * source: Bash Builtins. (line 594) |
e8ce775d | 11859 | * suspend: Job Control Builtins. |
74091dd4 | 11860 | (line 116) |
e8ce775d | 11861 | * test: Bourne Shell Builtins. |
74091dd4 | 11862 | (line 275) |
e8ce775d | 11863 | * times: Bourne Shell Builtins. |
74091dd4 | 11864 | (line 360) |
e8ce775d | 11865 | * trap: Bourne Shell Builtins. |
74091dd4 CR |
11866 | (line 366) |
11867 | * type: Bash Builtins. (line 599) | |
11868 | * typeset: Bash Builtins. (line 631) | |
11869 | * ulimit: Bash Builtins. (line 637) | |
e8ce775d | 11870 | * umask: Bourne Shell Builtins. |
74091dd4 CR |
11871 | (line 415) |
11872 | * unalias: Bash Builtins. (line 743) | |
e8ce775d | 11873 | * unset: Bourne Shell Builtins. |
74091dd4 | 11874 | (line 433) |
e8ce775d | 11875 | * wait: Job Control Builtins. |
ac50fbac | 11876 | (line 76) |
ccc6cda3 JA |
11877 | |
11878 | \1f | |
3185942a | 11879 | File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes |
ccc6cda3 | 11880 | |
3185942a JA |
11881 | D.2 Index of Shell Reserved Words |
11882 | ================================= | |
ccc6cda3 | 11883 | |
b80f6443 | 11884 | \0\b[index\0\b] |
ccc6cda3 JA |
11885 | * Menu: |
11886 | ||
3185942a | 11887 | * !: Pipelines. (line 9) |
cce855bc | 11888 | * [[: Conditional Constructs. |
74091dd4 | 11889 | (line 126) |
cce855bc | 11890 | * ]]: Conditional Constructs. |
74091dd4 | 11891 | (line 126) |
a0c0a00f CR |
11892 | * {: Command Grouping. (line 21) |
11893 | * }: Command Grouping. (line 21) | |
e8ce775d | 11894 | * case: Conditional Constructs. |
b80f6443 JA |
11895 | (line 28) |
11896 | * do: Looping Constructs. (line 12) | |
11897 | * done: Looping Constructs. (line 12) | |
e8ce775d | 11898 | * elif: Conditional Constructs. |
b80f6443 | 11899 | (line 7) |
e8ce775d | 11900 | * else: Conditional Constructs. |
b80f6443 | 11901 | (line 7) |
e8ce775d | 11902 | * esac: Conditional Constructs. |
b80f6443 | 11903 | (line 28) |
e8ce775d | 11904 | * fi: Conditional Constructs. |
b80f6443 | 11905 | (line 7) |
ac50fbac | 11906 | * for: Looping Constructs. (line 32) |
b80f6443 | 11907 | * function: Shell Functions. (line 13) |
e8ce775d | 11908 | * if: Conditional Constructs. |
b80f6443 | 11909 | (line 7) |
e8ce775d | 11910 | * in: Conditional Constructs. |
b80f6443 | 11911 | (line 28) |
cce855bc | 11912 | * select: Conditional Constructs. |
74091dd4 | 11913 | (line 84) |
e8ce775d | 11914 | * then: Conditional Constructs. |
b80f6443 | 11915 | (line 7) |
3185942a | 11916 | * time: Pipelines. (line 9) |
b80f6443 | 11917 | * until: Looping Constructs. (line 12) |
ac50fbac | 11918 | * while: Looping Constructs. (line 22) |
ccc6cda3 JA |
11919 | |
11920 | \1f | |
3185942a | 11921 | File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes |
ccc6cda3 | 11922 | |
3185942a JA |
11923 | D.3 Parameter and Variable Index |
11924 | ================================ | |
ccc6cda3 | 11925 | |
b80f6443 | 11926 | \0\b[index\0\b] |
ccc6cda3 JA |
11927 | * Menu: |
11928 | ||
74091dd4 | 11929 | * !: Special Parameters. (line 55) |
d233b485 CR |
11930 | * #: Special Parameters. (line 39) |
11931 | * $: Special Parameters. (line 51) | |
74091dd4 | 11932 | * $!: Special Parameters. (line 56) |
d233b485 CR |
11933 | * $#: Special Parameters. (line 40) |
11934 | * $$: Special Parameters. (line 52) | |
ac50fbac | 11935 | * $*: Special Parameters. (line 10) |
d233b485 | 11936 | * $-: Special Parameters. (line 47) |
74091dd4 | 11937 | * $0: Special Parameters. (line 61) |
d233b485 | 11938 | * $?: Special Parameters. (line 43) |
ac50fbac | 11939 | * $@: Special Parameters. (line 23) |
8868edaf | 11940 | * $_: Bash Variables. (line 14) |
b80f6443 | 11941 | * *: Special Parameters. (line 9) |
d233b485 | 11942 | * -: Special Parameters. (line 46) |
74091dd4 | 11943 | * 0: Special Parameters. (line 60) |
d233b485 | 11944 | * ?: Special Parameters. (line 42) |
ac50fbac | 11945 | * @: Special Parameters. (line 22) |
8868edaf | 11946 | * _: Bash Variables. (line 13) |
74091dd4 CR |
11947 | * active-region-end-color: Readline Init File Syntax. |
11948 | (line 51) | |
11949 | * active-region-start-color: Readline Init File Syntax. | |
11950 | (line 38) | |
e8ce775d | 11951 | * auto_resume: Job Control Variables. |
b80f6443 | 11952 | (line 6) |
8868edaf CR |
11953 | * BASH: Bash Variables. (line 23) |
11954 | * BASHOPTS: Bash Variables. (line 26) | |
11955 | * BASHPID: Bash Variables. (line 35) | |
11956 | * BASH_ALIASES: Bash Variables. (line 42) | |
11957 | * BASH_ARGC: Bash Variables. (line 51) | |
11958 | * BASH_ARGV: Bash Variables. (line 64) | |
11959 | * BASH_ARGV0: Bash Variables. (line 76) | |
11960 | * BASH_CMDS: Bash Variables. (line 84) | |
11961 | * BASH_COMMAND: Bash Variables. (line 93) | |
11962 | * BASH_COMPAT: Bash Variables. (line 100) | |
11963 | * BASH_ENV: Bash Variables. (line 116) | |
11964 | * BASH_EXECUTION_STRING: Bash Variables. (line 122) | |
11965 | * BASH_LINENO: Bash Variables. (line 125) | |
11966 | * BASH_LOADABLES_PATH: Bash Variables. (line 133) | |
11967 | * BASH_REMATCH: Bash Variables. (line 137) | |
11968 | * BASH_SOURCE: Bash Variables. (line 145) | |
11969 | * BASH_SUBSHELL: Bash Variables. (line 152) | |
11970 | * BASH_VERSINFO: Bash Variables. (line 158) | |
11971 | * BASH_VERSION: Bash Variables. (line 181) | |
11972 | * BASH_XTRACEFD: Bash Variables. (line 184) | |
e8ce775d | 11973 | * bell-style: Readline Init File Syntax. |
74091dd4 | 11974 | (line 64) |
95732b49 | 11975 | * bind-tty-special-chars: Readline Init File Syntax. |
74091dd4 | 11976 | (line 71) |
a0c0a00f | 11977 | * blink-matching-paren: Readline Init File Syntax. |
74091dd4 | 11978 | (line 76) |
e8ce775d | 11979 | * CDPATH: Bourne Shell Variables. |
b80f6443 | 11980 | (line 9) |
8868edaf | 11981 | * CHILD_MAX: Bash Variables. (line 195) |
a0c0a00f | 11982 | * colored-completion-prefix: Readline Init File Syntax. |
74091dd4 | 11983 | (line 81) |
ac50fbac | 11984 | * colored-stats: Readline Init File Syntax. |
74091dd4 | 11985 | (line 91) |
8868edaf | 11986 | * COLUMNS: Bash Variables. (line 202) |
ac50fbac | 11987 | * comment-begin: Readline Init File Syntax. |
74091dd4 | 11988 | (line 97) |
495aee44 | 11989 | * completion-display-width: Readline Init File Syntax. |
74091dd4 | 11990 | (line 102) |
495aee44 | 11991 | * completion-ignore-case: Readline Init File Syntax. |
74091dd4 | 11992 | (line 109) |
495aee44 | 11993 | * completion-map-case: Readline Init File Syntax. |
74091dd4 | 11994 | (line 114) |
ac50fbac | 11995 | * completion-prefix-display-length: Readline Init File Syntax. |
74091dd4 | 11996 | (line 120) |
3185942a | 11997 | * completion-query-items: Readline Init File Syntax. |
74091dd4 | 11998 | (line 127) |
8868edaf CR |
11999 | * COMPREPLY: Bash Variables. (line 254) |
12000 | * COMP_CWORD: Bash Variables. (line 208) | |
12001 | * COMP_KEY: Bash Variables. (line 237) | |
12002 | * COMP_LINE: Bash Variables. (line 214) | |
12003 | * COMP_POINT: Bash Variables. (line 219) | |
12004 | * COMP_TYPE: Bash Variables. (line 227) | |
12005 | * COMP_WORDBREAKS: Bash Variables. (line 241) | |
12006 | * COMP_WORDS: Bash Variables. (line 247) | |
95732b49 | 12007 | * convert-meta: Readline Init File Syntax. |
74091dd4 | 12008 | (line 138) |
8868edaf CR |
12009 | * COPROC: Bash Variables. (line 260) |
12010 | * DIRSTACK: Bash Variables. (line 264) | |
ac50fbac | 12011 | * disable-completion: Readline Init File Syntax. |
74091dd4 | 12012 | (line 148) |
a0c0a00f | 12013 | * echo-control-characters: Readline Init File Syntax. |
74091dd4 | 12014 | (line 153) |
e8ce775d | 12015 | * editing-mode: Readline Init File Syntax. |
74091dd4 | 12016 | (line 158) |
8868edaf | 12017 | * EMACS: Bash Variables. (line 274) |
a0c0a00f | 12018 | * emacs-mode-string: Readline Init File Syntax. |
74091dd4 CR |
12019 | (line 164) |
12020 | * enable-active-region: Readline Init File Syntax. | |
12021 | (line 174) | |
a0c0a00f | 12022 | * enable-bracketed-paste: Readline Init File Syntax. |
74091dd4 | 12023 | (line 187) |
e8ce775d | 12024 | * enable-keypad: Readline Init File Syntax. |
74091dd4 | 12025 | (line 196) |
8868edaf CR |
12026 | * ENV: Bash Variables. (line 279) |
12027 | * EPOCHREALTIME: Bash Variables. (line 284) | |
12028 | * EPOCHSECONDS: Bash Variables. (line 292) | |
12029 | * EUID: Bash Variables. (line 299) | |
12030 | * EXECIGNORE: Bash Variables. (line 303) | |
0001803f | 12031 | * expand-tilde: Readline Init File Syntax. |
74091dd4 | 12032 | (line 207) |
8868edaf CR |
12033 | * FCEDIT: Bash Variables. (line 316) |
12034 | * FIGNORE: Bash Variables. (line 320) | |
12035 | * FUNCNAME: Bash Variables. (line 326) | |
12036 | * FUNCNEST: Bash Variables. (line 343) | |
12037 | * GLOBIGNORE: Bash Variables. (line 348) | |
12038 | * GROUPS: Bash Variables. (line 355) | |
12039 | * histchars: Bash Variables. (line 361) | |
12040 | * HISTCMD: Bash Variables. (line 376) | |
12041 | * HISTCONTROL: Bash Variables. (line 382) | |
12042 | * HISTFILE: Bash Variables. (line 398) | |
12043 | * HISTFILESIZE: Bash Variables. (line 402) | |
12044 | * HISTIGNORE: Bash Variables. (line 413) | |
f73dda09 | 12045 | * history-preserve-point: Readline Init File Syntax. |
74091dd4 | 12046 | (line 211) |
ac50fbac | 12047 | * history-size: Readline Init File Syntax. |
74091dd4 | 12048 | (line 217) |
8868edaf CR |
12049 | * HISTSIZE: Bash Variables. (line 433) |
12050 | * HISTTIMEFORMAT: Bash Variables. (line 440) | |
e8ce775d | 12051 | * HOME: Bourne Shell Variables. |
b80f6443 | 12052 | (line 13) |
e8ce775d | 12053 | * horizontal-scroll-mode: Readline Init File Syntax. |
74091dd4 | 12054 | (line 226) |
8868edaf CR |
12055 | * HOSTFILE: Bash Variables. (line 448) |
12056 | * HOSTNAME: Bash Variables. (line 459) | |
12057 | * HOSTTYPE: Bash Variables. (line 462) | |
e8ce775d | 12058 | * IFS: Bourne Shell Variables. |
b80f6443 | 12059 | (line 18) |
8868edaf | 12060 | * IGNOREEOF: Bash Variables. (line 465) |
e8ce775d | 12061 | * input-meta: Readline Init File Syntax. |
74091dd4 | 12062 | (line 235) |
8868edaf CR |
12063 | * INPUTRC: Bash Variables. (line 475) |
12064 | * INSIDE_EMACS: Bash Variables. (line 479) | |
b72432fd | 12065 | * isearch-terminators: Readline Init File Syntax. |
74091dd4 | 12066 | (line 245) |
e8ce775d | 12067 | * keymap: Readline Init File Syntax. |
74091dd4 CR |
12068 | (line 252) |
12069 | * LANG: Creating Internationalized Scripts. | |
12070 | (line 51) | |
12071 | * LANG <1>: Bash Variables. (line 485) | |
8868edaf CR |
12072 | * LC_ALL: Bash Variables. (line 489) |
12073 | * LC_COLLATE: Bash Variables. (line 493) | |
12074 | * LC_CTYPE: Bash Variables. (line 500) | |
74091dd4 CR |
12075 | * LC_MESSAGES: Creating Internationalized Scripts. |
12076 | (line 51) | |
8868edaf CR |
12077 | * LC_MESSAGES <1>: Bash Variables. (line 505) |
12078 | * LC_NUMERIC: Bash Variables. (line 509) | |
12079 | * LC_TIME: Bash Variables. (line 513) | |
12080 | * LINENO: Bash Variables. (line 517) | |
12081 | * LINES: Bash Variables. (line 522) | |
12082 | * MACHTYPE: Bash Variables. (line 528) | |
e8ce775d | 12083 | * MAIL: Bourne Shell Variables. |
b80f6443 | 12084 | (line 22) |
8868edaf | 12085 | * MAILCHECK: Bash Variables. (line 532) |
e8ce775d | 12086 | * MAILPATH: Bourne Shell Variables. |
b80f6443 | 12087 | (line 27) |
8868edaf | 12088 | * MAPFILE: Bash Variables. (line 540) |
e8ce775d | 12089 | * mark-modified-lines: Readline Init File Syntax. |
74091dd4 | 12090 | (line 282) |
7117c2d2 | 12091 | * mark-symlinked-directories: Readline Init File Syntax. |
74091dd4 | 12092 | (line 287) |
f73dda09 | 12093 | * match-hidden-files: Readline Init File Syntax. |
74091dd4 | 12094 | (line 292) |
495aee44 | 12095 | * menu-complete-display-prefix: Readline Init File Syntax. |
74091dd4 | 12096 | (line 299) |
e8ce775d | 12097 | * meta-flag: Readline Init File Syntax. |
74091dd4 | 12098 | (line 235) |
8868edaf | 12099 | * OLDPWD: Bash Variables. (line 544) |
e8ce775d | 12100 | * OPTARG: Bourne Shell Variables. |
b80f6443 | 12101 | (line 34) |
8868edaf | 12102 | * OPTERR: Bash Variables. (line 547) |
e8ce775d | 12103 | * OPTIND: Bourne Shell Variables. |
b80f6443 | 12104 | (line 38) |
8868edaf | 12105 | * OSTYPE: Bash Variables. (line 551) |
e8ce775d | 12106 | * output-meta: Readline Init File Syntax. |
74091dd4 | 12107 | (line 304) |
7117c2d2 | 12108 | * page-completions: Readline Init File Syntax. |
74091dd4 | 12109 | (line 312) |
e8ce775d | 12110 | * PATH: Bourne Shell Variables. |
b80f6443 | 12111 | (line 42) |
8868edaf CR |
12112 | * PIPESTATUS: Bash Variables. (line 554) |
12113 | * POSIXLY_CORRECT: Bash Variables. (line 559) | |
12114 | * PPID: Bash Variables. (line 569) | |
12115 | * PROMPT_COMMAND: Bash Variables. (line 573) | |
12116 | * PROMPT_DIRTRIM: Bash Variables. (line 579) | |
12117 | * PS0: Bash Variables. (line 585) | |
e8ce775d | 12118 | * PS1: Bourne Shell Variables. |
b80f6443 | 12119 | (line 48) |
e8ce775d | 12120 | * PS2: Bourne Shell Variables. |
b80f6443 | 12121 | (line 53) |
8868edaf CR |
12122 | * PS3: Bash Variables. (line 590) |
12123 | * PS4: Bash Variables. (line 595) | |
12124 | * PWD: Bash Variables. (line 603) | |
12125 | * RANDOM: Bash Variables. (line 606) | |
74091dd4 CR |
12126 | * READLINE_ARGUMENT: Bash Variables. (line 612) |
12127 | * READLINE_LINE: Bash Variables. (line 616) | |
12128 | * READLINE_MARK: Bash Variables. (line 620) | |
12129 | * READLINE_POINT: Bash Variables. (line 626) | |
12130 | * REPLY: Bash Variables. (line 630) | |
3185942a | 12131 | * revert-all-at-newline: Readline Init File Syntax. |
74091dd4 CR |
12132 | (line 322) |
12133 | * SECONDS: Bash Variables. (line 633) | |
12134 | * SHELL: Bash Variables. (line 642) | |
12135 | * SHELLOPTS: Bash Variables. (line 647) | |
12136 | * SHLVL: Bash Variables. (line 656) | |
e8ce775d | 12137 | * show-all-if-ambiguous: Readline Init File Syntax. |
74091dd4 | 12138 | (line 329) |
b80f6443 | 12139 | * show-all-if-unmodified: Readline Init File Syntax. |
74091dd4 | 12140 | (line 335) |
ac50fbac | 12141 | * show-mode-in-prompt: Readline Init File Syntax. |
74091dd4 | 12142 | (line 344) |
0001803f | 12143 | * skip-completed-text: Readline Init File Syntax. |
74091dd4 CR |
12144 | (line 350) |
12145 | * SRANDOM: Bash Variables. (line 661) | |
12146 | * TEXTDOMAIN: Creating Internationalized Scripts. | |
12147 | (line 51) | |
12148 | * TEXTDOMAINDIR: Creating Internationalized Scripts. | |
12149 | (line 51) | |
12150 | * TIMEFORMAT: Bash Variables. (line 670) | |
12151 | * TMOUT: Bash Variables. (line 708) | |
12152 | * TMPDIR: Bash Variables. (line 720) | |
12153 | * UID: Bash Variables. (line 724) | |
a0c0a00f | 12154 | * vi-cmd-mode-string: Readline Init File Syntax. |
74091dd4 | 12155 | (line 363) |
a0c0a00f | 12156 | * vi-ins-mode-string: Readline Init File Syntax. |
74091dd4 | 12157 | (line 374) |
e8ce775d | 12158 | * visible-stats: Readline Init File Syntax. |
74091dd4 | 12159 | (line 385) |
ccc6cda3 JA |
12160 | |
12161 | \1f | |
3185942a | 12162 | File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes |
ccc6cda3 | 12163 | |
3185942a JA |
12164 | D.4 Function Index |
12165 | ================== | |
ccc6cda3 | 12166 | |
b80f6443 | 12167 | \0\b[index\0\b] |
ccc6cda3 JA |
12168 | * Menu: |
12169 | ||
e8ce775d | 12170 | * abort (C-g): Miscellaneous Commands. |
a0c0a00f CR |
12171 | (line 10) |
12172 | * accept-line (Newline or Return): Commands For History. | |
12173 | (line 6) | |
12174 | * alias-expand-line (): Miscellaneous Commands. | |
74091dd4 | 12175 | (line 131) |
a0c0a00f CR |
12176 | * backward-char (C-b): Commands For Moving. (line 15) |
12177 | * backward-delete-char (Rubout): Commands For Text. (line 17) | |
12178 | * backward-kill-line (C-x Rubout): Commands For Killing. | |
8868edaf | 12179 | (line 11) |
a0c0a00f | 12180 | * backward-kill-word (M-<DEL>): Commands For Killing. |
8868edaf | 12181 | (line 28) |
a0c0a00f CR |
12182 | * backward-word (M-b): Commands For Moving. (line 22) |
12183 | * beginning-of-history (M-<): Commands For History. | |
12184 | (line 20) | |
12185 | * beginning-of-line (C-a): Commands For Moving. (line 6) | |
12186 | * bracketed-paste-begin (): Commands For Text. (line 33) | |
12187 | * call-last-kbd-macro (C-x e): Keyboard Macros. (line 13) | |
8868edaf | 12188 | * capitalize-word (M-c): Commands For Text. (line 66) |
e8ce775d | 12189 | * character-search (C-]): Miscellaneous Commands. |
d233b485 | 12190 | (line 42) |
e8ce775d | 12191 | * character-search-backward (M-C-]): Miscellaneous Commands. |
d233b485 | 12192 | (line 47) |
8868edaf CR |
12193 | * clear-display (M-C-l): Commands For Moving. (line 48) |
12194 | * clear-screen (C-l): Commands For Moving. (line 53) | |
28ef6c31 | 12195 | * complete (<TAB>): Commands For Completion. |
a0c0a00f CR |
12196 | (line 6) |
12197 | * complete-command (M-!): Commands For Completion. | |
12198 | (line 80) | |
12199 | * complete-filename (M-/): Commands For Completion. | |
12200 | (line 49) | |
12201 | * complete-hostname (M-@): Commands For Completion. | |
12202 | (line 72) | |
12203 | * complete-into-braces (M-{): Commands For Completion. | |
12204 | (line 100) | |
12205 | * complete-username (M-~): Commands For Completion. | |
12206 | (line 56) | |
12207 | * complete-variable (M-$): Commands For Completion. | |
12208 | (line 64) | |
12209 | * copy-backward-word (): Commands For Killing. | |
8868edaf | 12210 | (line 69) |
a0c0a00f | 12211 | * copy-forward-word (): Commands For Killing. |
8868edaf | 12212 | (line 74) |
a0c0a00f | 12213 | * copy-region-as-kill (): Commands For Killing. |
8868edaf | 12214 | (line 65) |
a0c0a00f CR |
12215 | * dabbrev-expand (): Commands For Completion. |
12216 | (line 95) | |
12217 | * delete-char (C-d): Commands For Text. (line 12) | |
b72432fd | 12218 | * delete-char-or-list (): Commands For Completion. |
a0c0a00f CR |
12219 | (line 43) |
12220 | * delete-horizontal-space (): Commands For Killing. | |
8868edaf | 12221 | (line 57) |
a0c0a00f CR |
12222 | * digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6) |
12223 | * display-shell-version (C-x C-v): Miscellaneous Commands. | |
74091dd4 | 12224 | (line 116) |
d233b485 | 12225 | * do-lowercase-version (M-A, M-B, M-X, ...): Miscellaneous Commands. |
a0c0a00f | 12226 | (line 14) |
8868edaf | 12227 | * downcase-word (M-l): Commands For Text. (line 62) |
e8ce775d | 12228 | * dump-functions (): Miscellaneous Commands. |
d233b485 | 12229 | (line 74) |
e8ce775d | 12230 | * dump-macros (): Miscellaneous Commands. |
d233b485 | 12231 | (line 86) |
e8ce775d | 12232 | * dump-variables (): Miscellaneous Commands. |
d233b485 | 12233 | (line 80) |
a0c0a00f CR |
12234 | * dynamic-complete-history (M-<TAB>): Commands For Completion. |
12235 | (line 90) | |
d233b485 | 12236 | * edit-and-execute-command (C-x C-e): Miscellaneous Commands. |
74091dd4 | 12237 | (line 140) |
a0c0a00f CR |
12238 | * end-kbd-macro (C-x )): Keyboard Macros. (line 9) |
12239 | * end-of-file (usually C-d): Commands For Text. (line 6) | |
12240 | * end-of-history (M->): Commands For History. | |
12241 | (line 23) | |
12242 | * end-of-line (C-e): Commands For Moving. (line 9) | |
e8ce775d | 12243 | * exchange-point-and-mark (C-x C-x): Miscellaneous Commands. |
d233b485 | 12244 | (line 37) |
74091dd4 CR |
12245 | * fetch-history (): Commands For History. |
12246 | (line 103) | |
a0c0a00f CR |
12247 | * forward-backward-delete-char (): Commands For Text. (line 21) |
12248 | * forward-char (C-f): Commands For Moving. (line 12) | |
12249 | * forward-search-history (C-s): Commands For History. | |
8868edaf | 12250 | (line 33) |
a0c0a00f CR |
12251 | * forward-word (M-f): Commands For Moving. (line 18) |
12252 | * glob-complete-word (M-g): Miscellaneous Commands. | |
d233b485 | 12253 | (line 98) |
74091dd4 | 12254 | * glob-expand-word (C-x *): Miscellaneous Commands. |
d233b485 | 12255 | (line 104) |
74091dd4 CR |
12256 | * glob-list-expansions (C-x g): Miscellaneous Commands. |
12257 | (line 110) | |
a0c0a00f | 12258 | * history-and-alias-expand-line (): Miscellaneous Commands. |
74091dd4 | 12259 | (line 134) |
a0c0a00f | 12260 | * history-expand-line (M-^): Miscellaneous Commands. |
74091dd4 | 12261 | (line 124) |
a0c0a00f | 12262 | * history-search-backward (): Commands For History. |
8868edaf | 12263 | (line 57) |
a0c0a00f | 12264 | * history-search-forward (): Commands For History. |
8868edaf | 12265 | (line 51) |
d233b485 | 12266 | * history-substring-search-backward (): Commands For History. |
8868edaf | 12267 | (line 69) |
d233b485 | 12268 | * history-substring-search-forward (): Commands For History. |
8868edaf | 12269 | (line 63) |
e8ce775d | 12270 | * insert-comment (M-#): Miscellaneous Commands. |
d233b485 | 12271 | (line 61) |
e8ce775d | 12272 | * insert-completions (M-*): Commands For Completion. |
a0c0a00f CR |
12273 | (line 22) |
12274 | * insert-last-argument (M-. or M-_): Miscellaneous Commands. | |
74091dd4 | 12275 | (line 137) |
a0c0a00f CR |
12276 | * kill-line (C-k): Commands For Killing. |
12277 | (line 6) | |
12278 | * kill-region (): Commands For Killing. | |
8868edaf | 12279 | (line 61) |
a0c0a00f | 12280 | * kill-whole-line (): Commands For Killing. |
a0c0a00f | 12281 | (line 19) |
8868edaf CR |
12282 | * kill-word (M-d): Commands For Killing. |
12283 | (line 23) | |
a0c0a00f | 12284 | * magic-space (): Miscellaneous Commands. |
74091dd4 | 12285 | (line 127) |
cce855bc | 12286 | * menu-complete (): Commands For Completion. |
a0c0a00f | 12287 | (line 26) |
0001803f | 12288 | * menu-complete-backward (): Commands For Completion. |
a0c0a00f CR |
12289 | (line 38) |
12290 | * next-history (C-n): Commands For History. | |
12291 | (line 17) | |
d233b485 | 12292 | * next-screen-line (): Commands For Moving. (line 41) |
ccc6cda3 | 12293 | * non-incremental-forward-search-history (M-n): Commands For History. |
8868edaf | 12294 | (line 45) |
ccc6cda3 | 12295 | * non-incremental-reverse-search-history (M-p): Commands For History. |
8868edaf CR |
12296 | (line 39) |
12297 | * operate-and-get-next (C-o): Commands For History. | |
12298 | (line 96) | |
12299 | * overwrite-mode (): Commands For Text. (line 70) | |
a0c0a00f CR |
12300 | * possible-command-completions (C-x !): Commands For Completion. |
12301 | (line 86) | |
e8ce775d | 12302 | * possible-completions (M-?): Commands For Completion. |
a0c0a00f CR |
12303 | (line 15) |
12304 | * possible-filename-completions (C-x /): Commands For Completion. | |
12305 | (line 52) | |
12306 | * possible-hostname-completions (C-x @): Commands For Completion. | |
12307 | (line 76) | |
12308 | * possible-username-completions (C-x ~): Commands For Completion. | |
12309 | (line 60) | |
12310 | * possible-variable-completions (C-x $): Commands For Completion. | |
12311 | (line 68) | |
28ef6c31 | 12312 | * prefix-meta (<ESC>): Miscellaneous Commands. |
d233b485 | 12313 | (line 19) |
a0c0a00f CR |
12314 | * previous-history (C-p): Commands For History. |
12315 | (line 13) | |
d233b485 | 12316 | * previous-screen-line (): Commands For Moving. (line 34) |
a0c0a00f CR |
12317 | * print-last-kbd-macro (): Keyboard Macros. (line 17) |
12318 | * quoted-insert (C-q or C-v): Commands For Text. (line 26) | |
e8ce775d | 12319 | * re-read-init-file (C-x C-r): Miscellaneous Commands. |
a0c0a00f | 12320 | (line 6) |
8868edaf | 12321 | * redraw-current-line (): Commands For Moving. (line 57) |
a0c0a00f CR |
12322 | * reverse-search-history (C-r): Commands For History. |
12323 | (line 27) | |
e8ce775d | 12324 | * revert-line (M-r): Miscellaneous Commands. |
d233b485 | 12325 | (line 26) |
a0c0a00f | 12326 | * self-insert (a, b, A, 1, !, ...): Commands For Text. (line 30) |
e8ce775d | 12327 | * set-mark (C-@): Miscellaneous Commands. |
d233b485 | 12328 | (line 33) |
a0c0a00f | 12329 | * shell-backward-kill-word (): Commands For Killing. |
8868edaf CR |
12330 | (line 37) |
12331 | * shell-backward-word (M-C-b): Commands For Moving. (line 30) | |
a0c0a00f | 12332 | * shell-expand-line (M-C-e): Miscellaneous Commands. |
74091dd4 | 12333 | (line 119) |
8868edaf CR |
12334 | * shell-forward-word (M-C-f): Commands For Moving. (line 26) |
12335 | * shell-kill-word (M-C-d): Commands For Killing. | |
12336 | (line 32) | |
12337 | * shell-transpose-words (M-C-t): Commands For Killing. | |
12338 | (line 41) | |
0001803f | 12339 | * skip-csi-sequence (): Miscellaneous Commands. |
d233b485 | 12340 | (line 52) |
74091dd4 CR |
12341 | * spell-correct-word (C-x s): Miscellaneous Commands. |
12342 | (line 92) | |
a0c0a00f CR |
12343 | * start-kbd-macro (C-x (): Keyboard Macros. (line 6) |
12344 | * tilde-expand (M-&): Miscellaneous Commands. | |
d233b485 | 12345 | (line 30) |
8868edaf CR |
12346 | * transpose-chars (C-t): Commands For Text. (line 47) |
12347 | * transpose-words (M-t): Commands For Text. (line 53) | |
28ef6c31 | 12348 | * undo (C-_ or C-x C-u): Miscellaneous Commands. |
d233b485 | 12349 | (line 23) |
a0c0a00f CR |
12350 | * universal-argument (): Numeric Arguments. (line 10) |
12351 | * unix-filename-rubout (): Commands For Killing. | |
8868edaf | 12352 | (line 52) |
a0c0a00f | 12353 | * unix-line-discard (C-u): Commands For Killing. |
8868edaf | 12354 | (line 16) |
a0c0a00f | 12355 | * unix-word-rubout (C-w): Commands For Killing. |
8868edaf CR |
12356 | (line 48) |
12357 | * upcase-word (M-u): Commands For Text. (line 58) | |
a0c0a00f | 12358 | * yank (C-y): Commands For Killing. |
8868edaf | 12359 | (line 79) |
a0c0a00f | 12360 | * yank-last-arg (M-. or M-_): Commands For History. |
8868edaf | 12361 | (line 84) |
a0c0a00f | 12362 | * yank-nth-arg (M-C-y): Commands For History. |
8868edaf | 12363 | (line 75) |
a0c0a00f | 12364 | * yank-pop (M-y): Commands For Killing. |
8868edaf | 12365 | (line 82) |
ccc6cda3 JA |
12366 | |
12367 | \1f | |
3185942a | 12368 | File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes |
ccc6cda3 | 12369 | |
3185942a JA |
12370 | D.5 Concept Index |
12371 | ================= | |
ccc6cda3 | 12372 | |
b80f6443 | 12373 | \0\b[index\0\b] |
ccc6cda3 JA |
12374 | * Menu: |
12375 | ||
b80f6443 JA |
12376 | * alias expansion: Aliases. (line 6) |
12377 | * arithmetic evaluation: Shell Arithmetic. (line 6) | |
e8ce775d | 12378 | * arithmetic expansion: Arithmetic Expansion. |
b80f6443 JA |
12379 | (line 6) |
12380 | * arithmetic, shell: Shell Arithmetic. (line 6) | |
12381 | * arrays: Arrays. (line 6) | |
12382 | * background: Job Control Basics. (line 6) | |
12383 | * Bash configuration: Basic Installation. (line 6) | |
12384 | * Bash installation: Basic Installation. (line 6) | |
e8ce775d | 12385 | * Bourne shell: Basic Shell Features. |
b80f6443 JA |
12386 | (line 6) |
12387 | * brace expansion: Brace Expansion. (line 6) | |
0628567a | 12388 | * builtin: Definitions. (line 17) |
e8ce775d | 12389 | * command editing: Readline Bare Essentials. |
b80f6443 | 12390 | (line 6) |
e8ce775d | 12391 | * command execution: Command Search and Execution. |
b80f6443 | 12392 | (line 6) |
cce855bc | 12393 | * command expansion: Simple Command Expansion. |
b80f6443 | 12394 | (line 6) |
e8ce775d | 12395 | * command history: Bash History Facilities. |
b80f6443 | 12396 | (line 6) |
e8ce775d | 12397 | * command search: Command Search and Execution. |
b80f6443 | 12398 | (line 6) |
e8ce775d | 12399 | * command substitution: Command Substitution. |
b80f6443 | 12400 | (line 6) |
3185942a | 12401 | * command timing: Pipelines. (line 9) |
b80f6443 | 12402 | * commands, compound: Compound Commands. (line 6) |
e8ce775d | 12403 | * commands, conditional: Conditional Constructs. |
b80f6443 JA |
12404 | (line 6) |
12405 | * commands, grouping: Command Grouping. (line 6) | |
12406 | * commands, lists: Lists. (line 6) | |
12407 | * commands, looping: Looping Constructs. (line 6) | |
12408 | * commands, pipelines: Pipelines. (line 6) | |
12409 | * commands, shell: Shell Commands. (line 6) | |
12410 | * commands, simple: Simple Commands. (line 6) | |
12411 | * comments, shell: Comments. (line 6) | |
8868edaf CR |
12412 | * Compatibility Level: Shell Compatibility Mode. |
12413 | (line 6) | |
12414 | * Compatibility Mode: Shell Compatibility Mode. | |
12415 | (line 6) | |
bb70624e | 12416 | * completion builtins: Programmable Completion Builtins. |
b80f6443 JA |
12417 | (line 6) |
12418 | * configuration: Basic Installation. (line 6) | |
0628567a | 12419 | * control operator: Definitions. (line 21) |
3185942a | 12420 | * coprocess: Coprocesses. (line 6) |
b80f6443 | 12421 | * directory stack: The Directory Stack. (line 6) |
e8ce775d | 12422 | * editing command lines: Readline Bare Essentials. |
b80f6443 JA |
12423 | (line 6) |
12424 | * environment: Environment. (line 6) | |
12425 | * evaluation, arithmetic: Shell Arithmetic. (line 6) | |
12426 | * event designators: Event Designators. (line 6) | |
cce855bc | 12427 | * execution environment: Command Execution Environment. |
b80f6443 | 12428 | (line 6) |
3185942a | 12429 | * exit status: Definitions. (line 26) |
a0c0a00f | 12430 | * exit status <1>: Exit Status. (line 6) |
b80f6443 | 12431 | * expansion: Shell Expansions. (line 6) |
e8ce775d | 12432 | * expansion, arithmetic: Arithmetic Expansion. |
b80f6443 JA |
12433 | (line 6) |
12434 | * expansion, brace: Brace Expansion. (line 6) | |
12435 | * expansion, filename: Filename Expansion. (line 9) | |
e8ce775d | 12436 | * expansion, parameter: Shell Parameter Expansion. |
b80f6443 JA |
12437 | (line 6) |
12438 | * expansion, pathname: Filename Expansion. (line 9) | |
12439 | * expansion, tilde: Tilde Expansion. (line 6) | |
12440 | * expressions, arithmetic: Shell Arithmetic. (line 6) | |
e8ce775d | 12441 | * expressions, conditional: Bash Conditional Expressions. |
b80f6443 | 12442 | (line 6) |
3185942a JA |
12443 | * field: Definitions. (line 30) |
12444 | * filename: Definitions. (line 35) | |
b80f6443 JA |
12445 | * filename expansion: Filename Expansion. (line 9) |
12446 | * foreground: Job Control Basics. (line 6) | |
12447 | * functions, shell: Shell Functions. (line 6) | |
cce855bc | 12448 | * history builtins: Bash History Builtins. |
b80f6443 | 12449 | (line 6) |
495aee44 | 12450 | * history events: Event Designators. (line 8) |
b80f6443 | 12451 | * history expansion: History Interaction. (line 6) |
e8ce775d | 12452 | * history list: Bash History Facilities. |
b80f6443 | 12453 | (line 6) |
ac50fbac | 12454 | * History, how to use: A Programmable Completion Example. |
d233b485 | 12455 | (line 113) |
3185942a | 12456 | * identifier: Definitions. (line 51) |
b80f6443 JA |
12457 | * initialization file, readline: Readline Init File. (line 6) |
12458 | * installation: Basic Installation. (line 6) | |
e8ce775d | 12459 | * interaction, readline: Readline Interaction. |
b80f6443 | 12460 | (line 6) |
d233b485 | 12461 | * interactive shell: Invoking Bash. (line 131) |
b80f6443 | 12462 | * interactive shell <1>: Interactive Shells. (line 6) |
b80f6443 | 12463 | * internationalization: Locale Translation. (line 6) |
74091dd4 CR |
12464 | * internationalized scripts: Creating Internationalized Scripts. |
12465 | (line 3) | |
3185942a | 12466 | * job: Definitions. (line 38) |
3185942a | 12467 | * job control: Definitions. (line 42) |
a0c0a00f | 12468 | * job control <1>: Job Control Basics. (line 6) |
e8ce775d | 12469 | * kill ring: Readline Killing Commands. |
a0c0a00f | 12470 | (line 18) |
e8ce775d | 12471 | * killing text: Readline Killing Commands. |
b80f6443 JA |
12472 | (line 6) |
12473 | * localization: Locale Translation. (line 6) | |
d233b485 | 12474 | * login shell: Invoking Bash. (line 128) |
b80f6443 | 12475 | * matching, pattern: Pattern Matching. (line 6) |
3185942a JA |
12476 | * metacharacter: Definitions. (line 46) |
12477 | * name: Definitions. (line 51) | |
b80f6443 | 12478 | * native languages: Locale Translation. (line 6) |
e8ce775d | 12479 | * notation, readline: Readline Bare Essentials. |
b80f6443 | 12480 | (line 6) |
3185942a | 12481 | * operator, shell: Definitions. (line 57) |
e8ce775d | 12482 | * parameter expansion: Shell Parameter Expansion. |
b80f6443 JA |
12483 | (line 6) |
12484 | * parameters: Shell Parameters. (line 6) | |
e8ce775d | 12485 | * parameters, positional: Positional Parameters. |
b80f6443 JA |
12486 | (line 6) |
12487 | * parameters, special: Special Parameters. (line 6) | |
12488 | * pathname expansion: Filename Expansion. (line 9) | |
12489 | * pattern matching: Pattern Matching. (line 6) | |
12490 | * pipeline: Pipelines. (line 6) | |
12491 | * POSIX: Definitions. (line 9) | |
12492 | * POSIX Mode: Bash POSIX Mode. (line 6) | |
3185942a JA |
12493 | * process group: Definitions. (line 62) |
12494 | * process group ID: Definitions. (line 66) | |
e8ce775d | 12495 | * process substitution: Process Substitution. |
b80f6443 | 12496 | (line 6) |
bb70624e | 12497 | * programmable completion: Programmable Completion. |
b80f6443 | 12498 | (line 6) |
ac50fbac CR |
12499 | * prompting: Controlling the Prompt. |
12500 | (line 6) | |
b80f6443 JA |
12501 | * quoting: Quoting. (line 6) |
12502 | * quoting, ANSI: ANSI-C Quoting. (line 6) | |
bb70624e | 12503 | * Readline, how to use: Job Control Variables. |
a0c0a00f | 12504 | (line 23) |
b80f6443 | 12505 | * redirection: Redirections. (line 6) |
3185942a | 12506 | * reserved word: Definitions. (line 70) |
8868edaf | 12507 | * reserved words: Reserved Words. (line 6) |
e8ce775d | 12508 | * restricted shell: The Restricted Shell. |
b80f6443 | 12509 | (line 6) |
3185942a | 12510 | * return status: Definitions. (line 75) |
b80f6443 JA |
12511 | * shell arithmetic: Shell Arithmetic. (line 6) |
12512 | * shell function: Shell Functions. (line 6) | |
12513 | * shell script: Shell Scripts. (line 6) | |
12514 | * shell variable: Shell Parameters. (line 6) | |
12515 | * shell, interactive: Interactive Shells. (line 6) | |
3185942a | 12516 | * signal: Definitions. (line 78) |
b80f6443 | 12517 | * signal handling: Signals. (line 6) |
3185942a | 12518 | * special builtin: Definitions. (line 82) |
a0c0a00f | 12519 | * special builtin <1>: Special Builtins. (line 6) |
b80f6443 | 12520 | * startup files: Bash Startup Files. (line 6) |
74091dd4 CR |
12521 | * string translations: Creating Internationalized Scripts. |
12522 | (line 3) | |
b80f6443 JA |
12523 | * suspending jobs: Job Control Basics. (line 6) |
12524 | * tilde expansion: Tilde Expansion. (line 6) | |
3185942a | 12525 | * token: Definitions. (line 86) |
b80f6443 JA |
12526 | * translation, native languages: Locale Translation. (line 6) |
12527 | * variable, shell: Shell Parameters. (line 6) | |
28ef6c31 | 12528 | * variables, readline: Readline Init File Syntax. |
95732b49 | 12529 | (line 37) |
3185942a | 12530 | * word: Definitions. (line 90) |
b80f6443 | 12531 | * word splitting: Word Splitting. (line 6) |
e8ce775d | 12532 | * yanking text: Readline Killing Commands. |
b80f6443 | 12533 | (line 6) |
ccc6cda3 JA |
12534 | |
12535 | ||
12536 | \1f | |
12537 | Tag Table: | |
74091dd4 CR |
12538 | Node: Top\7f899 |
12539 | Node: Introduction\7f2821 | |
12540 | Node: What is Bash?\7f3037 | |
12541 | Node: What is a shell?\7f4151 | |
12542 | Node: Definitions\7f6689 | |
12543 | Node: Basic Shell Features\7f9640 | |
12544 | Node: Shell Syntax\7f10859 | |
12545 | Node: Shell Operation\7f11885 | |
12546 | Node: Quoting\7f13178 | |
12547 | Node: Escape Character\7f14482 | |
12548 | Node: Single Quotes\7f14967 | |
12549 | Node: Double Quotes\7f15315 | |
12550 | Node: ANSI-C Quoting\7f16593 | |
12551 | Node: Locale Translation\7f17903 | |
12552 | Node: Creating Internationalized Scripts\7f19214 | |
12553 | Node: Comments\7f23331 | |
12554 | Node: Shell Commands\7f23949 | |
12555 | Node: Reserved Words\7f24887 | |
12556 | Node: Simple Commands\7f25643 | |
12557 | Node: Pipelines\7f26297 | |
12558 | Node: Lists\7f29296 | |
12559 | Node: Compound Commands\7f31091 | |
12560 | Node: Looping Constructs\7f32103 | |
12561 | Node: Conditional Constructs\7f34598 | |
12562 | Node: Command Grouping\7f49086 | |
12563 | Node: Coprocesses\7f50564 | |
12564 | Node: GNU Parallel\7f53227 | |
12565 | Node: Shell Functions\7f54144 | |
12566 | Node: Shell Parameters\7f62029 | |
12567 | Node: Positional Parameters\7f66417 | |
12568 | Node: Special Parameters\7f67319 | |
12569 | Node: Shell Expansions\7f70533 | |
12570 | Node: Brace Expansion\7f72660 | |
12571 | Node: Tilde Expansion\7f75394 | |
12572 | Node: Shell Parameter Expansion\7f78015 | |
12573 | Node: Command Substitution\7f96366 | |
12574 | Node: Arithmetic Expansion\7f97721 | |
12575 | Node: Process Substitution\7f98689 | |
12576 | Node: Word Splitting\7f99809 | |
12577 | Node: Filename Expansion\7f101753 | |
12578 | Node: Pattern Matching\7f104502 | |
12579 | Node: Quote Removal\7f109504 | |
12580 | Node: Redirections\7f109799 | |
12581 | Node: Executing Commands\7f119459 | |
12582 | Node: Simple Command Expansion\7f120129 | |
12583 | Node: Command Search and Execution\7f122239 | |
12584 | Node: Command Execution Environment\7f124617 | |
12585 | Node: Environment\7f127652 | |
12586 | Node: Exit Status\7f129315 | |
12587 | Node: Signals\7f131099 | |
12588 | Node: Shell Scripts\7f134548 | |
12589 | Node: Shell Builtin Commands\7f137575 | |
12590 | Node: Bourne Shell Builtins\7f139613 | |
12591 | Node: Bash Builtins\7f161079 | |
12592 | Node: Modifying Shell Behavior\7f191935 | |
12593 | Node: The Set Builtin\7f192280 | |
12594 | Node: The Shopt Builtin\7f202881 | |
12595 | Node: Special Builtins\7f218793 | |
12596 | Node: Shell Variables\7f219772 | |
12597 | Node: Bourne Shell Variables\7f220209 | |
12598 | Node: Bash Variables\7f222313 | |
12599 | Node: Bash Features\7f255128 | |
12600 | Node: Invoking Bash\7f256141 | |
12601 | Node: Bash Startup Files\7f262154 | |
12602 | Node: Interactive Shells\7f267285 | |
12603 | Node: What is an Interactive Shell?\7f267696 | |
12604 | Node: Is this Shell Interactive?\7f268345 | |
12605 | Node: Interactive Shell Behavior\7f269160 | |
12606 | Node: Bash Conditional Expressions\7f272789 | |
12607 | Node: Shell Arithmetic\7f277431 | |
12608 | Node: Aliases\7f280375 | |
12609 | Node: Arrays\7f282988 | |
12610 | Node: The Directory Stack\7f289379 | |
12611 | Node: Directory Stack Builtins\7f290163 | |
12612 | Node: Controlling the Prompt\7f294423 | |
12613 | Node: The Restricted Shell\7f297388 | |
12614 | Node: Bash POSIX Mode\7f299998 | |
12615 | Node: Shell Compatibility Mode\7f311916 | |
12616 | Node: Job Control\7f320483 | |
12617 | Node: Job Control Basics\7f320943 | |
12618 | Node: Job Control Builtins\7f325945 | |
12619 | Node: Job Control Variables\7f331740 | |
12620 | Node: Command Line Editing\7f332896 | |
12621 | Node: Introduction and Notation\7f334567 | |
12622 | Node: Readline Interaction\7f336190 | |
12623 | Node: Readline Bare Essentials\7f337381 | |
12624 | Node: Readline Movement Commands\7f339170 | |
12625 | Node: Readline Killing Commands\7f340130 | |
12626 | Node: Readline Arguments\7f342051 | |
12627 | Node: Searching\7f343095 | |
12628 | Node: Readline Init File\7f345281 | |
12629 | Node: Readline Init File Syntax\7f346542 | |
12630 | Node: Conditional Init Constructs\7f370128 | |
12631 | Node: Sample Init File\7f374324 | |
12632 | Node: Bindable Readline Commands\7f377448 | |
12633 | Node: Commands For Moving\7f378652 | |
12634 | Node: Commands For History\7f380703 | |
12635 | Node: Commands For Text\7f385697 | |
12636 | Node: Commands For Killing\7f389346 | |
12637 | Node: Numeric Arguments\7f392379 | |
12638 | Node: Commands For Completion\7f393518 | |
12639 | Node: Keyboard Macros\7f397709 | |
12640 | Node: Miscellaneous Commands\7f398397 | |
12641 | Node: Readline vi Mode\7f404342 | |
12642 | Node: Programmable Completion\7f405249 | |
12643 | Node: Programmable Completion Builtins\7f413029 | |
12644 | Node: A Programmable Completion Example\7f423781 | |
12645 | Node: Using History Interactively\7f429029 | |
12646 | Node: Bash History Facilities\7f429713 | |
12647 | Node: Bash History Builtins\7f432718 | |
12648 | Node: History Interaction\7f437742 | |
12649 | Node: Event Designators\7f441362 | |
12650 | Node: Word Designators\7f442716 | |
12651 | Node: Modifiers\7f444476 | |
12652 | Node: Installing Bash\7f446284 | |
12653 | Node: Basic Installation\7f447421 | |
12654 | Node: Compilers and Options\7f451143 | |
12655 | Node: Compiling For Multiple Architectures\7f451884 | |
12656 | Node: Installation Names\7f453576 | |
12657 | Node: Specifying the System Type\7f455685 | |
12658 | Node: Sharing Defaults\7f456402 | |
12659 | Node: Operation Controls\7f457075 | |
12660 | Node: Optional Features\7f458033 | |
12661 | Node: Reporting Bugs\7f469252 | |
12662 | Node: Major Differences From The Bourne Shell\7f470527 | |
12663 | Node: GNU Free Documentation License\7f487376 | |
12664 | Node: Indexes\7f512553 | |
12665 | Node: Builtin Index\7f513007 | |
12666 | Node: Reserved Word Index\7f519834 | |
12667 | Node: Variable Index\7f522282 | |
12668 | Node: Function Index\7f539056 | |
12669 | Node: Concept Index\7f552840 | |
ccc6cda3 JA |
12670 | \1f |
12671 | End Tag Table | |
8868edaf CR |
12672 | |
12673 | \1f | |
12674 | Local Variables: | |
12675 | coding: utf-8 | |
12676 | End: |