]> git.ipfire.org Git - thirdparty/bash.git/blob - doc/bashref.info
fix for SIGINT in sourced script
[thirdparty/bash.git] / doc / bashref.info
1 This is bashref.info, produced by makeinfo version 6.1 from
2 bashref.texi.
3
4 This text is a brief description of the features that are present in the
5 Bash shell (version 4.4, 7 September 2016).
6
7 This is Edition 4.4, last updated 7 September 2016, of 'The GNU Bash
8 Reference Manual', for 'Bash', Version 4.4.
9
10 Copyright (C) 1988-2016 Free Software Foundation, Inc.
11
12 Permission is granted to copy, distribute and/or modify this
13 document under the terms of the GNU Free Documentation License,
14 Version 1.3 or any later version published by the Free Software
15 Foundation; with no Invariant Sections, no Front-Cover Texts, and
16 no Back-Cover Texts. A copy of the license is included in the
17 section entitled "GNU Free Documentation License".
18 INFO-DIR-SECTION Basics
19 START-INFO-DIR-ENTRY
20 * Bash: (bash). The GNU Bourne-Again SHell.
21 END-INFO-DIR-ENTRY
22
23 \1f
24 File: bashref.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
25
26 Bash Features
27 *************
28
29 This text is a brief description of the features that are present in the
30 Bash shell (version 4.4, 7 September 2016). The Bash home page is
31 <http://www.gnu.org/software/bash/>.
32
33 This is Edition 4.4, last updated 7 September 2016, of 'The GNU Bash
34 Reference Manual', for 'Bash', Version 4.4.
35
36 Bash contains features that appear in other popular shells, and some
37 features that only appear in Bash. Some of the shells that Bash has
38 borrowed concepts from are the Bourne Shell ('sh'), the Korn Shell
39 ('ksh'), and the C-shell ('csh' and its successor, 'tcsh'). The
40 following menu breaks the features up into categories, noting which
41 features were inspired by other shells and which are specific to Bash.
42
43 This manual is meant as a brief introduction to features found in
44 Bash. The Bash manual page should be used as the definitive reference
45 on shell behavior.
46
47 * Menu:
48
49 * Introduction:: An introduction to the shell.
50 * Definitions:: Some definitions used in the rest of this
51 manual.
52 * Basic Shell Features:: The shell "building blocks".
53 * Shell Builtin Commands:: Commands that are a part of the shell.
54 * Shell Variables:: Variables used or set by Bash.
55 * Bash Features:: Features found only in Bash.
56 * Job Control:: What job control is and how Bash allows you
57 to use it.
58 * Command Line Editing:: Chapter describing the command line
59 editing features.
60 * Using History Interactively:: Command History Expansion
61 * Installing Bash:: How to build and install Bash on your system.
62 * Reporting Bugs:: How to report bugs in Bash.
63 * Major Differences From The Bourne Shell:: A terse list of the differences
64 between Bash and historical
65 versions of /bin/sh.
66 * GNU Free Documentation License:: Copying and sharing this documentation.
67 * Indexes:: Various indexes for this manual.
68
69 \1f
70 File: bashref.info, Node: Introduction, Next: Definitions, Up: Top
71
72 1 Introduction
73 **************
74
75 * Menu:
76
77 * What is Bash?:: A short description of Bash.
78 * What is a shell?:: A brief introduction to shells.
79
80 \1f
81 File: bashref.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
82
83 1.1 What is Bash?
84 =================
85
86 Bash is the shell, or command language interpreter, for the GNU
87 operating system. The name is an acronym for the 'Bourne-Again SHell',
88 a pun on Stephen Bourne, the author of the direct ancestor of the
89 current Unix shell 'sh', which appeared in the Seventh Edition Bell Labs
90 Research version of Unix.
91
92 Bash is largely compatible with 'sh' and incorporates useful features
93 from the Korn shell 'ksh' and the C shell 'csh'. It is intended to be a
94 conformant implementation of the IEEE POSIX Shell and Tools portion of
95 the IEEE POSIX specification (IEEE Standard 1003.1). It offers
96 functional improvements over 'sh' for both interactive and programming
97 use.
98
99 While the GNU operating system provides other shells, including a
100 version of 'csh', Bash is the default shell. Like other GNU software,
101 Bash is quite portable. It currently runs on nearly every version of
102 Unix and a few other operating systems - independently-supported ports
103 exist for MS-DOS, OS/2, and Windows platforms.
104
105 \1f
106 File: bashref.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
107
108 1.2 What is a shell?
109 ====================
110
111 At its base, a shell is simply a macro processor that executes commands.
112 The term macro processor means functionality where text and symbols are
113 expanded to create larger expressions.
114
115 A Unix shell is both a command interpreter and a programming
116 language. As a command interpreter, the shell provides the user
117 interface to the rich set of GNU utilities. The programming language
118 features allow these utilities to be combined. Files containing
119 commands can be created, and become commands themselves. These new
120 commands have the same status as system commands in directories such as
121 '/bin', allowing users or groups to establish custom environments to
122 automate their common tasks.
123
124 Shells may be used interactively or non-interactively. In
125 interactive mode, they accept input typed from the keyboard. When
126 executing non-interactively, shells execute commands read from a file.
127
128 A shell allows execution of GNU commands, both synchronously and
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
133 the input and output of those commands. Moreover, the shell allows
134 control over the contents of commands' environments.
135
136 Shells also provide a small set of built-in commands ("builtins")
137 implementing functionality impossible or inconvenient to obtain via
138 separate utilities. For example, 'cd', 'break', 'continue', and 'exec'
139 cannot be implemented outside of the shell because they directly
140 manipulate the shell itself. The 'history', 'getopts', 'kill', or 'pwd'
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.
144
145 While executing commands is essential, most of the power (and
146 complexity) of shells is due to their embedded programming languages.
147 Like any high-level language, the shell provides variables, flow control
148 constructs, quoting, and functions.
149
150 Shells offer features geared specifically for interactive use rather
151 than to augment the programming language. These interactive features
152 include job control, command line editing, command history and aliases.
153 Each of these features is described in this manual.
154
155 \1f
156 File: bashref.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
157
158 2 Definitions
159 *************
160
161 These definitions are used throughout the remainder of this manual.
162
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.
167
168 'blank'
169 A space or tab character.
170
171 'builtin'
172 A command that is implemented internally by the shell itself,
173 rather than by an executable program somewhere in the file system.
174
175 'control operator'
176 A 'token' that performs a control function. It is a 'newline' or
177 one of the following: '||', '&&', '&', ';', ';;', ';&', ';;&', '|',
178 '|&', '(', or ')'.
179
180 'exit status'
181 The value returned by a command to its caller. The value is
182 restricted to eight bits, so the maximum value is 255.
183
184 'field'
185 A unit of text that is the result of one of the shell expansions.
186 After expansion, when executing a command, the resulting fields are
187 used as the command name and arguments.
188
189 'filename'
190 A string of characters used to identify a file.
191
192 'job'
193 A set of processes comprising a pipeline, and any processes
194 descended from it, that are all in the same process group.
195
196 'job control'
197 A mechanism by which users can selectively stop (suspend) and
198 restart (resume) execution of processes.
199
200 'metacharacter'
201 A character that, when unquoted, separates words. A metacharacter
202 is a 'space', 'tab', 'newline', or one of the following characters:
203 '|', '&', ';', '(', ')', '<', or '>'.
204
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
208 shell variable and function names. Also referred to as an
209 'identifier'.
210
211 'operator'
212 A 'control operator' or a 'redirection operator'. *Note
213 Redirections::, for a list of redirection operators. Operators
214 contain at least one unquoted 'metacharacter'.
215
216 'process group'
217 A collection of related processes each having the same process
218 group ID.
219
220 'process group ID'
221 A unique identifier that represents a 'process group' during its
222 lifetime.
223
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'.
228
229 'return status'
230 A synonym for 'exit status'.
231
232 'signal'
233 A mechanism by which a process may be notified by the kernel of an
234 event occurring in the system.
235
236 'special builtin'
237 A shell builtin command that has been classified as special by the
238 POSIX standard.
239
240 'token'
241 A sequence of characters considered a single unit by the shell. It
242 is either a 'word' or an 'operator'.
243
244 'word'
245 A sequence of characters treated as a unit by the shell. Words may
246 not include unquoted 'metacharacters'.
247
248 \1f
249 File: bashref.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
250
251 3 Basic Shell Features
252 **********************
253
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
257 evaluation and quoting are taken from the POSIX specification for the
258 'standard' Unix shell.
259
260 This chapter briefly summarizes the shell's 'building blocks':
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.
268 * Shell Commands:: The types of commands you can use.
269 * Shell Functions:: Grouping commands by name.
270 * Shell Parameters:: How the shell stores values.
271 * Shell Expansions:: How Bash expands parameters and the various
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
278 File: bashref.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
279
280 3.1 Shell Syntax
281 ================
282
283 * Menu:
284
285 * Shell Operation:: The basic operation of the shell.
286 * Quoting:: How to remove the special meaning from characters.
287 * Comments:: How to specify comments.
288
289 When the shell reads input, it proceeds through a sequence of
290 operations. If the input indicates the beginning of a comment, the
291 shell ignores the comment symbol ('#'), and the rest of that line.
292
293 Otherwise, roughly speaking, the shell reads its input and divides
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
303 \1f
304 File: bashref.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
305
306 3.1.1 Shell Operation
307 ---------------------
308
309 The following is a brief description of the shell's operation when it
310 reads and executes a command. Basically, the shell does the following:
311
312 1. Reads its input from a file (*note Shell Scripts::), from a string
313 supplied as an argument to the '-c' invocation option (*note
314 Invoking Bash::), or from the user's terminal.
315
316 2. Breaks the input into words and operators, obeying the quoting
317 rules described in *note Quoting::. These tokens are separated by
318 'metacharacters'. Alias expansion is performed by this step (*note
319 Aliases::).
320
321 3. Parses the tokens into simple and compound commands (*note Shell
322 Commands::).
323
324 4. Performs the various shell expansions (*note Shell Expansions::),
325 breaking the expanded tokens into lists of filenames (*note
326 Filename Expansion::) and commands and arguments.
327
328 5. Performs any necessary redirections (*note Redirections::) and
329 removes the redirection operators and their operands from the
330 argument list.
331
332 6. Executes the command (*note Executing Commands::).
333
334 7. Optionally waits for the command to complete and collects its exit
335 status (*note Exit Status::).
336
337 \1f
338 File: bashref.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
339
340 3.1.2 Quoting
341 -------------
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.
352 * Locale Translation:: How to translate strings into different languages.
353
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.
358
359 Each of the shell metacharacters (*note Definitions::) has special
360 meaning to the shell and must be quoted if it is to represent itself.
361 When the command history expansion facilities are being used (*note
362 History Interaction::), the HISTORY EXPANSION character, usually '!',
363 must be quoted to prevent history expansion. *Note Bash History
364 Facilities::, for more details concerning history expansion.
365
366 There are three quoting mechanisms: the ESCAPE CHARACTER, single
367 quotes, and double quotes.
368
369 \1f
370 File: bashref.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
371
372 3.1.2.1 Escape Character
373 ........................
374
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).
380
381 \1f
382 File: bashref.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
383
384 3.1.2.2 Single Quotes
385 .....................
386
387 Enclosing characters in single quotes (''') preserves the literal value
388 of each character within the quotes. A single quote may not occur
389 between single quotes, even when preceded by a backslash.
390
391 \1f
392 File: bashref.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
393
394 3.1.2.3 Double Quotes
395 .....................
396
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
414 double quotes (*note Shell Parameter Expansion::).
415
416 \1f
417 File: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
418
419 3.1.2.4 ANSI-C Quoting
420 ......................
421
422 Words of the form '$'STRING'' are treated specially. The word expands
423 to STRING, with backslash-escaped characters replaced as specified by
424 the ANSI C standard. Backslash escape sequences, if present, are
425 decoded as follows:
426
427 '\a'
428 alert (bell)
429 '\b'
430 backspace
431 '\e'
432 '\E'
433 an escape character (not ANSI C)
434 '\f'
435 form feed
436 '\n'
437 newline
438 '\r'
439 carriage return
440 '\t'
441 horizontal tab
442 '\v'
443 vertical tab
444 '\\'
445 backslash
446 '\''
447 single quote
448 '\"'
449 double quote
450 '\?'
451 question mark
452 '\NNN'
453 the eight-bit character whose value is the octal value NNN (one to
454 three digits)
455 '\xHH'
456 the eight-bit character whose value is the hexadecimal value HH
457 (one or two hex digits)
458 '\uHHHH'
459 the Unicode (ISO/IEC 10646) character whose value is the
460 hexadecimal value HHHH (one to four hex digits)
461 '\UHHHHHHHH'
462 the Unicode (ISO/IEC 10646) character whose value is the
463 hexadecimal value HHHHHHHH (one to eight hex digits)
464 '\cX'
465 a control-X character
466
467 The expanded result is single-quoted, as if the dollar sign had not been
468 present.
469
470 \1f
471 File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
472
473 3.1.2.5 Locale-Specific Translation
474 ...................................
475
476 A double-quoted string preceded by a dollar sign ('$') will cause the
477 string to be translated according to the current locale. If the current
478 locale is 'C' or 'POSIX', the dollar sign is ignored. If the string is
479 translated and replaced, the replacement is double-quoted.
480
481 Some systems use the message catalog selected by the 'LC_MESSAGES'
482 shell variable. Others create the name of the message catalog from the
483 value of the 'TEXTDOMAIN' shell variable, possibly adding a suffix of
484 '.mo'. If you use the 'TEXTDOMAIN' variable, you may need to set the
485 'TEXTDOMAINDIR' variable to the location of the message catalog files.
486 Still others use both variables in this fashion:
487 'TEXTDOMAINDIR'/'LC_MESSAGES'/LC_MESSAGES/'TEXTDOMAIN'.mo.
488
489 \1f
490 File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
491
492 3.1.3 Comments
493 --------------
494
495 In a non-interactive shell, or an interactive shell in which the
496 'interactive_comments' option to the 'shopt' builtin is enabled (*note
497 The Shopt Builtin::), a word beginning with '#' causes that word and all
498 remaining characters on that line to be ignored. An interactive shell
499 without the 'interactive_comments' option enabled does not allow
500 comments. The 'interactive_comments' option is on by default in
501 interactive shells. *Note Interactive Shells::, for a description of
502 what makes a shell interactive.
503
504 \1f
505 File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
506
507 3.2 Shell Commands
508 ==================
509
510 A simple shell command such as 'echo a b c' consists of the command
511 itself followed by arguments, separated by spaces.
512
513 More complex shell commands are composed of simple commands arranged
514 together in a variety of ways: in a pipeline in which the output of one
515 command becomes the input of a second, in a loop or conditional
516 construct, or in some other grouping.
517
518 * Menu:
519
520 * Simple Commands:: The most common type of command.
521 * Pipelines:: Connecting the input and output of several
522 commands.
523 * Lists:: How to execute commands sequentially.
524 * Compound Commands:: Shell commands for control flow.
525 * Coprocesses:: Two-way communication between commands.
526 * GNU Parallel:: Running commands in parallel.
527
528 \1f
529 File: bashref.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
530
531 3.2.1 Simple Commands
532 ---------------------
533
534 A simple command is the kind of command encountered most often. It's
535 just a sequence of words separated by 'blank's, terminated by one of the
536 shell's control operators (*note Definitions::). The first word
537 generally specifies a command to be executed, with the rest of the words
538 being that command's arguments.
539
540 The return status (*note Exit Status::) of a simple command is its
541 exit status as provided by the POSIX 1003.1 'waitpid' function, or 128+N
542 if the command was terminated by signal N.
543
544 \1f
545 File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
546
547 3.2.2 Pipelines
548 ---------------
549
550 A 'pipeline' is a sequence of one or more commands separated by one of
551 the control operators '|' or '|&'.
552
553 The format for a pipeline is
554 [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
555
556 The output of each command in the pipeline is connected via a pipe to
557 the input of the next command. That is, each command reads the previous
558 command's output. This connection is performed before any redirections
559 specified by the command.
560
561 If '|&' is used, COMMAND1's standard error, in addition to its
562 standard output, is connected to COMMAND2's standard input through the
563 pipe; it is shorthand for '2>&1 |'. This implicit redirection of the
564 standard error to the standard output is performed after any
565 redirections specified by the command.
566
567 The reserved word 'time' causes timing statistics to be printed for
568 the pipeline once it finishes. The statistics currently consist of
569 elapsed (wall-clock) time and user and system time consumed by the
570 command's execution. The '-p' option changes the output format to that
571 specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX
572 Mode::), it does not recognize 'time' as a reserved word if the next
573 token begins with a '-'. The 'TIMEFORMAT' variable may be set to a
574 format string that specifies how the timing information should be
575 displayed. *Note Bash Variables::, for a description of the available
576 formats. The use of 'time' as a reserved word permits the timing of
577 shell builtins, shell functions, and pipelines. An external 'time'
578 command cannot time these easily.
579
580 When the shell is in POSIX mode (*note Bash POSIX Mode::), 'time' may
581 be followed by a newline. In this case, the shell displays the total
582 user and system time consumed by the shell and its children. The
583 'TIMEFORMAT' variable may be used to specify the format of the time
584 information.
585
586 If the pipeline is not executed asynchronously (*note Lists::), the
587 shell waits for all commands in the pipeline to complete.
588
589 Each command in a pipeline is executed in its own subshell (*note
590 Command Execution Environment::). The exit status of a pipeline is the
591 exit status of the last command in the pipeline, unless the 'pipefail'
592 option is enabled (*note The Set Builtin::). If 'pipefail' is enabled,
593 the pipeline's return status is the value of the last (rightmost)
594 command to exit with a non-zero status, or zero if all commands exit
595 successfully. If the reserved word '!' precedes the pipeline, the exit
596 status is the logical negation of the exit status as described above.
597 The shell waits for all commands in the pipeline to terminate before
598 returning a value.
599
600 \1f
601 File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
602
603 3.2.3 Lists of Commands
604 -----------------------
605
606 A 'list' is a sequence of one or more pipelines separated by one of the
607 operators ';', '&', '&&', or '||', and optionally terminated by one of
608 ';', '&', or a 'newline'.
609
610 Of these list operators, '&&' and '||' have equal precedence,
611 followed by ';' and '&', which have equal precedence.
612
613 A sequence of one or more newlines may appear in a 'list' to delimit
614 commands, equivalent to a semicolon.
615
616 If a command is terminated by the control operator '&', the shell
617 executes the command asynchronously in a subshell. This is known as
618 executing the command in the BACKGROUND. The shell does not wait for
619 the command to finish, and the return status is 0 (true). When job
620 control is not active (*note Job Control::), the standard input for
621 asynchronous commands, in the absence of any explicit redirections, is
622 redirected from '/dev/null'.
623
624 Commands separated by a ';' are executed sequentially; the shell
625 waits for each command to terminate in turn. The return status is the
626 exit status of the last command executed.
627
628 AND and OR lists are sequences of one or more pipelines separated by
629 the control operators '&&' and '||', respectively. AND and OR lists are
630 executed with left associativity.
631
632 An AND list has the form
633 COMMAND1 && COMMAND2
634
635 COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of
636 zero.
637
638 An OR list has the form
639 COMMAND1 || COMMAND2
640
641 COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
642 status.
643
644 The return status of AND and OR lists is the exit status of the last
645 command executed in the list.
646
647 \1f
648 File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
649
650 3.2.4 Compound Commands
651 -----------------------
652
653 * Menu:
654
655 * Looping Constructs:: Shell commands for iterative action.
656 * Conditional Constructs:: Shell commands for conditional execution.
657 * Command Grouping:: Ways to group commands.
658
659 Compound commands are the shell programming constructs. Each construct
660 begins with a reserved word or control operator and is terminated by a
661 corresponding reserved word or operator. Any redirections (*note
662 Redirections::) associated with a compound command apply to all commands
663 within that compound command unless explicitly overridden.
664
665 In most cases a list of commands in a compound command's description
666 may be separated from the rest of the command by one or more newlines,
667 and may be followed by a newline in place of a semicolon.
668
669 Bash provides looping constructs, conditional commands, and
670 mechanisms to group commands and execute them as a unit.
671
672 \1f
673 File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
674
675 3.2.4.1 Looping Constructs
676 ..........................
677
678 Bash supports the following looping constructs.
679
680 Note that wherever a ';' appears in the description of a command's
681 syntax, it may be replaced with one or more newlines.
682
683 'until'
684 The syntax of the 'until' command is:
685
686 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
687
688 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
689 status which is not zero. The return status is the exit status of
690 the last command executed in CONSEQUENT-COMMANDS, or zero if none
691 was executed.
692
693 'while'
694 The syntax of the 'while' command is:
695
696 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
697
698 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
699 status of zero. The return status is the exit status of the last
700 command executed in CONSEQUENT-COMMANDS, or zero if none was
701 executed.
702
703 'for'
704 The syntax of the 'for' command is:
705
706 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
707
708 Expand WORDS, and execute COMMANDS once for each member in the
709 resultant list, with NAME bound to the current member. If 'in
710 WORDS' is not present, the 'for' command executes the COMMANDS once
711 for each positional parameter that is set, as if 'in "$@"' had been
712 specified (*note Special Parameters::). The return status is the
713 exit status of the last command that executes. If there are no
714 items in the expansion of WORDS, no commands are executed, and the
715 return status is zero.
716
717 An alternate form of the 'for' command is also supported:
718
719 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
720
721 First, the arithmetic expression EXPR1 is evaluated according to
722 the rules described below (*note Shell Arithmetic::). The
723 arithmetic expression EXPR2 is then evaluated repeatedly until it
724 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
725 COMMANDS are executed and the arithmetic expression EXPR3 is
726 evaluated. If any expression is omitted, it behaves as if it
727 evaluates to 1. The return value is the exit status of the last
728 command in COMMANDS that is executed, or false if any of the
729 expressions is invalid.
730
731 The 'break' and 'continue' builtins (*note Bourne Shell Builtins::)
732 may be used to control loop execution.
733
734 \1f
735 File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
736
737 3.2.4.2 Conditional Constructs
738 ..............................
739
740 'if'
741 The syntax of the 'if' command is:
742
743 if TEST-COMMANDS; then
744 CONSEQUENT-COMMANDS;
745 [elif MORE-TEST-COMMANDS; then
746 MORE-CONSEQUENTS;]
747 [else ALTERNATE-CONSEQUENTS;]
748 fi
749
750 The TEST-COMMANDS list is executed, and if its return status is
751 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
752 returns a non-zero status, each 'elif' list is executed in turn,
753 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
754 is executed and the command completes. If 'else
755 ALTERNATE-CONSEQUENTS' is present, and the final command in the
756 final 'if' or 'elif' clause has a non-zero exit status, then
757 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
758 status of the last command executed, or zero if no condition tested
759 true.
760
761 'case'
762 The syntax of the 'case' command is:
763
764 case WORD in [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]... esac
765
766 'case' will selectively execute the COMMAND-LIST corresponding to
767 the first PATTERN that matches WORD. If the 'nocasematch' shell
768 option (see the description of 'shopt' in *note The Shopt
769 Builtin::) is enabled, the match is performed without regard to the
770 case of alphabetic characters. The '|' is used to separate
771 multiple patterns, and the ')' operator terminates a pattern list.
772 A list of patterns and an associated command-list is known as a
773 CLAUSE.
774
775 Each clause must be terminated with ';;', ';&', or ';;&'. The WORD
776 undergoes tilde expansion, parameter expansion, command
777 substitution, arithmetic expansion, and quote removal before
778 matching is attempted. Each PATTERN undergoes tilde expansion,
779 parameter expansion, command substitution, and arithmetic
780 expansion.
781
782 There may be an arbitrary number of 'case' clauses, each terminated
783 by a ';;', ';&', or ';;&'. The first pattern that matches
784 determines the command-list that is executed. It's a common idiom
785 to use '*' as the final pattern to define the default case, since
786 that pattern will always match.
787
788 Here is an example using 'case' in a script that could be used to
789 describe one interesting feature of an animal:
790
791 echo -n "Enter the name of an animal: "
792 read ANIMAL
793 echo -n "The $ANIMAL has "
794 case $ANIMAL in
795 horse | dog | cat) echo -n "four";;
796 man | kangaroo ) echo -n "two";;
797 *) echo -n "an unknown number of";;
798 esac
799 echo " legs."
800
801
802 If the ';;' operator is used, no subsequent matches are attempted
803 after the first pattern match. Using ';&' in place of ';;' causes
804 execution to continue with the COMMAND-LIST associated with the
805 next clause, if any. Using ';;&' in place of ';;' causes the shell
806 to test the patterns in the next clause, if any, and execute any
807 associated COMMAND-LIST on a successful match.
808
809 The return status is zero if no PATTERN is matched. Otherwise, the
810 return status is the exit status of the COMMAND-LIST executed.
811
812 'select'
813
814 The 'select' construct allows the easy generation of menus. It has
815 almost the same syntax as the 'for' command:
816
817 select NAME [in WORDS ...]; do COMMANDS; done
818
819 The list of words following 'in' is expanded, generating a list of
820 items. The set of expanded words is printed on the standard error
821 output stream, each preceded by a number. If the 'in WORDS' is
822 omitted, the positional parameters are printed, as if 'in "$@"' had
823 been specified. The 'PS3' prompt is then displayed and a line is
824 read from the standard input. If the line consists of a number
825 corresponding to one of the displayed words, then the value of NAME
826 is set to that word. If the line is empty, the words and prompt
827 are displayed again. If 'EOF' is read, the 'select' command
828 completes. Any other value read causes NAME to be set to null.
829 The line read is saved in the variable 'REPLY'.
830
831 The COMMANDS are executed after each selection until a 'break'
832 command is executed, at which point the 'select' command completes.
833
834 Here is an example that allows the user to pick a filename from the
835 current directory, and displays the name and index of the file
836 selected.
837
838 select fname in *;
839 do
840 echo you picked $fname \($REPLY\)
841 break;
842 done
843
844 '((...))'
845 (( EXPRESSION ))
846
847 The arithmetic EXPRESSION is evaluated according to the rules
848 described below (*note Shell Arithmetic::). If the value of the
849 expression is non-zero, the return status is 0; otherwise the
850 return status is 1. This is exactly equivalent to
851 let "EXPRESSION"
852 *Note Bash Builtins::, for a full description of the 'let' builtin.
853
854 '[[...]]'
855 [[ EXPRESSION ]]
856
857 Return a status of 0 or 1 depending on the evaluation of the
858 conditional expression EXPRESSION. Expressions are composed of the
859 primaries described below in *note Bash Conditional Expressions::.
860 Word splitting and filename expansion are not performed on the
861 words between the '[[' and ']]'; tilde expansion, parameter and
862 variable expansion, arithmetic expansion, command substitution,
863 process substitution, and quote removal are performed. Conditional
864 operators such as '-f' must be unquoted to be recognized as
865 primaries.
866
867 When used with '[[', the '<' and '>' operators sort
868 lexicographically using the current locale.
869
870 When the '==' and '!=' operators are used, the string to the right
871 of the operator is considered a pattern and matched according to
872 the rules described below in *note Pattern Matching::, as if the
873 'extglob' shell option were enabled. The '=' operator is identical
874 to '=='. If the 'nocasematch' shell option (see the description of
875 'shopt' in *note The Shopt Builtin::) is enabled, the match is
876 performed without regard to the case of alphabetic characters. The
877 return value is 0 if the string matches ('==') or does not match
878 ('!=')the pattern, and 1 otherwise. Any part of the pattern may be
879 quoted to force the quoted portion to be matched as a string.
880
881 An additional binary operator, '=~', is available, with the same
882 precedence as '==' and '!='. When it is used, the string to the
883 right of the operator is considered an extended regular expression
884 and matched accordingly (as in regex3)). The return value is 0 if
885 the string matches the pattern, and 1 otherwise. If the regular
886 expression is syntactically incorrect, the conditional expression's
887 return value is 2. If the 'nocasematch' shell option (see the
888 description of 'shopt' in *note The Shopt Builtin::) is enabled,
889 the match is performed without regard to the case of alphabetic
890 characters. Any part of the pattern may be quoted to force the
891 quoted portion to be matched as a string. Bracket expressions in
892 regular expressions must be treated carefully, since normal quoting
893 characters lose their meanings between brackets. If the pattern is
894 stored in a shell variable, quoting the variable expansion forces
895 the entire pattern to be matched as a string. Substrings matched
896 by parenthesized subexpressions within the regular expression are
897 saved in the array variable 'BASH_REMATCH'. The element of
898 'BASH_REMATCH' with index 0 is the portion of the string matching
899 the entire regular expression. The element of 'BASH_REMATCH' with
900 index N is the portion of the string matching the Nth parenthesized
901 subexpression.
902
903 For example, the following will match a line (stored in the shell
904 variable LINE) if there is a sequence of characters in the value
905 consisting of any number, including zero, of space characters, zero
906 or one instances of 'a', then a 'b':
907 [[ $line =~ [[:space:]]*(a)?b ]]
908
909 That means values like 'aab' and ' aaaaaab' will match, as will a
910 line containing a 'b' anywhere in its value.
911
912 Storing the regular expression in a shell variable is often a
913 useful way to avoid problems with quoting characters that are
914 special to the shell. It is sometimes difficult to specify a
915 regular expression literally without using quotes, or to keep track
916 of the quoting used by regular expressions while paying attention
917 to the shell's quote removal. Using a shell variable to store the
918 pattern decreases these problems. For example, the following is
919 equivalent to the above:
920 pattern='[[:space:]]*(a)?b'
921 [[ $line =~ $pattern ]]
922
923 If you want to match a character that's special to the regular
924 expression grammar, it has to be quoted to remove its special
925 meaning. This means that in the pattern 'xxx.txt', the '.' matches
926 any character in the string (its usual regular expression meaning),
927 but in the pattern '"xxx.txt"' it can only match a literal '.'.
928 Shell programmers should take special care with backslashes, since
929 backslashes are used both by the shell and regular expressions to
930 remove the special meaning from the following character. The
931 following two sets of commands are _not_ equivalent:
932 pattern='\.'
933
934 [[ . =~ $pattern ]]
935 [[ . =~ \. ]]
936
937 [[ . =~ "$pattern" ]]
938 [[ . =~ '\.' ]]
939
940 The first two matches will succeed, but the second two will not,
941 because in the second two the backslash will be part of the pattern
942 to be matched. In the first two examples, the backslash removes
943 the special meaning from '.', so the literal '.' matches. If the
944 string in the first examples were anything other than '.', say 'a',
945 the pattern would not match, because the quoted '.' in the pattern
946 loses its special meaning of matching any single character.
947
948 Expressions may be combined using the following operators, listed
949 in decreasing order of precedence:
950
951 '( EXPRESSION )'
952 Returns the value of EXPRESSION. This may be used to override
953 the normal precedence of operators.
954
955 '! EXPRESSION'
956 True if EXPRESSION is false.
957
958 'EXPRESSION1 && EXPRESSION2'
959 True if both EXPRESSION1 and EXPRESSION2 are true.
960
961 'EXPRESSION1 || EXPRESSION2'
962 True if either EXPRESSION1 or EXPRESSION2 is true.
963
964 The '&&' and '||' operators do not evaluate EXPRESSION2 if the
965 value of EXPRESSION1 is sufficient to determine the return value of
966 the entire conditional expression.
967
968 \1f
969 File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
970
971 3.2.4.3 Grouping Commands
972 .........................
973
974 Bash provides two ways to group a list of commands to be executed as a
975 unit. When commands are grouped, redirections may be applied to the
976 entire command list. For example, the output of all the commands in the
977 list may be redirected to a single stream.
978
979 '()'
980 ( LIST )
981
982 Placing a list of commands between parentheses causes a subshell
983 environment to be created (*note Command Execution Environment::),
984 and each of the commands in LIST to be executed in that subshell.
985 Since the LIST is executed in a subshell, variable assignments do
986 not remain in effect after the subshell completes.
987
988 '{}'
989 { LIST; }
990
991 Placing a list of commands between curly braces causes the list to
992 be executed in the current shell context. No subshell is created.
993 The semicolon (or newline) following LIST is required.
994
995 In addition to the creation of a subshell, there is a subtle
996 difference between these two constructs due to historical reasons. The
997 braces are 'reserved words', so they must be separated from the LIST by
998 'blank's or other shell metacharacters. The parentheses are
999 'operators', and are recognized as separate tokens by the shell even if
1000 they are not separated from the LIST by whitespace.
1001
1002 The exit status of both of these constructs is the exit status of
1003 LIST.
1004
1005 \1f
1006 File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
1007
1008 3.2.5 Coprocesses
1009 -----------------
1010
1011 A 'coprocess' is a shell command preceded by the 'coproc' reserved word.
1012 A coprocess is executed asynchronously in a subshell, as if the command
1013 had been terminated with the '&' control operator, with a two-way pipe
1014 established between the executing shell and the coprocess.
1015
1016 The format for a coprocess is:
1017 coproc [NAME] COMMAND [REDIRECTIONS]
1018
1019 This creates a coprocess named NAME. If NAME is not supplied, the
1020 default name is COPROC. NAME must not be supplied if COMMAND is a
1021 simple command (*note Simple Commands::); otherwise, it is interpreted
1022 as the first word of the simple command.
1023
1024 When the coprocess is executed, the shell creates an array variable
1025 (*note Arrays::) named 'NAME' in the context of the executing shell.
1026 The standard output of COMMAND is connected via a pipe to a file
1027 descriptor in the executing shell, and that file descriptor is assigned
1028 to 'NAME'[0]. The standard input of COMMAND is connected via a pipe to
1029 a file descriptor in the executing shell, and that file descriptor is
1030 assigned to 'NAME'[1]. This pipe is established before any redirections
1031 specified by the command (*note Redirections::). The file descriptors
1032 can be utilized as arguments to shell commands and redirections using
1033 standard word expansions. The file descriptors are not available in
1034 subshells.
1035
1036 The process ID of the shell spawned to execute the coprocess is
1037 available as the value of the variable 'NAME'_PID. The 'wait' builtin
1038 command may be used to wait for the coprocess to terminate.
1039
1040 Since the coprocess is created as an asynchronous command, the
1041 'coproc' command always returns success. The return status of a
1042 coprocess is the exit status of COMMAND.
1043
1044 \1f
1045 File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1046
1047 3.2.6 GNU Parallel
1048 ------------------
1049
1050 There are ways to run commands in parallel that are not built into Bash.
1051 GNU Parallel is a tool to do just that.
1052
1053 GNU Parallel, as its name suggests, can be used to build and run
1054 commands in parallel. You may run the same command with different
1055 arguments, whether they are filenames, usernames, hostnames, or lines
1056 read from files. GNU Parallel provides shorthand references to many of
1057 the most common operations (input lines, various portions of the input
1058 line, different ways to specify the input source, and so on). Parallel
1059 can replace 'xargs' or feed commands from its input sources to several
1060 different instances of Bash.
1061
1062 For a complete description, refer to the GNU Parallel documentation.
1063 A few examples should provide a brief introduction to its use.
1064
1065 For example, it is easy to replace 'xargs' to gzip all html files in
1066 the current directory and its subdirectories:
1067 find . -type f -name '*.html' -print | parallel gzip
1068 If you need to protect special characters such as newlines in file
1069 names, use find's '-print0' option and parallel's '-0' option.
1070
1071 You can use Parallel to move files from the current directory when
1072 the number of files is too large to process with one 'mv' invocation:
1073 ls | parallel mv {} destdir
1074
1075 As you can see, the {} is replaced with each line read from standard
1076 input. While using 'ls' will work in most instances, it is not
1077 sufficient to deal with all filenames. If you need to accommodate
1078 special characters in filenames, you can use
1079
1080 find . -depth 1 \! -name '.*' -print0 | parallel -0 mv {} destdir
1081
1082 as alluded to above.
1083
1084 This will run as many 'mv' commands as there are files in the current
1085 directory. You can emulate a parallel 'xargs' by adding the '-X'
1086 option:
1087 find . -depth 1 \! -name '.*' -print0 | parallel -0 -X mv {} destdir
1088
1089 GNU Parallel can replace certain common idioms that operate on lines
1090 read from a file (in this case, filenames listed one per line):
1091 while IFS= read -r x; do
1092 do-something1 "$x" "config-$x"
1093 do-something2 < "$x"
1094 done < file | process-output
1095
1096 with a more compact syntax reminiscent of lambdas:
1097 cat list | parallel "do-something1 {} config-{} ; do-something2 < {}" | process-output
1098
1099 Parallel provides a built-in mechanism to remove filename extensions,
1100 which lends itself to batch file transformations or renaming:
1101 ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
1102 This will recompress all files in the current directory with names
1103 ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
1104 (We use 'ls' for brevity here; using 'find' as above is more robust in
1105 the face of filenames containing unexpected characters.) Parallel can
1106 take arguments from the command line; the above can also be written as
1107
1108 parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
1109
1110 If a command generates output, you may want to preserve the input
1111 order in the output. For instance, the following command
1112 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel traceroute
1113 will display as output the traceroute invocation that finishes first.
1114 Adding the '-k' option
1115 { echo foss.org.my ; echo debian.org; echo freenetproject.org; } | parallel -k traceroute
1116 will ensure that the output of 'traceroute foss.org.my' is displayed
1117 first.
1118
1119 Finally, Parallel can be used to run a sequence of shell commands in
1120 parallel, similar to 'cat file | bash'. It is not uncommon to take a
1121 list of filenames, create a series of shell commands to operate on them,
1122 and feed that list of commnds to a shell. Parallel can speed this up.
1123 Assuming that 'file' contains a list of shell commands, one per line,
1124
1125 parallel -j 10 < file
1126
1127 will evaluate the commands using the shell (since no explicit command is
1128 supplied as an argument), in blocks of ten shell jobs at a time.
1129
1130 \1f
1131 File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
1132
1133 3.3 Shell Functions
1134 ===================
1135
1136 Shell functions are a way to group commands for later execution using a
1137 single name for the group. They are executed just like a "regular"
1138 command. When the name of a shell function is used as a simple command
1139 name, the list of commands associated with that function name is
1140 executed. Shell functions are executed in the current shell context; no
1141 new process is created to interpret them.
1142
1143 Functions are declared using this syntax:
1144 NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
1145
1146 or
1147
1148 function NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
1149
1150 This defines a shell function named NAME. The reserved word
1151 'function' is optional. If the 'function' reserved word is supplied,
1152 the parentheses are optional. The BODY of the function is the compound
1153 command COMPOUND-COMMAND (*note Compound Commands::). That command is
1154 usually a LIST enclosed between { and }, but may be any compound command
1155 listed above, with one exception: If the 'function' reserved word is
1156 used, but the parentheses are not supplied, the braces are required.
1157 COMPOUND-COMMAND is executed whenever NAME is specified as the name of a
1158 command. When the shell is in POSIX mode (*note Bash POSIX Mode::),
1159 NAME may not be the same as one of the special builtins (*note Special
1160 Builtins::). Any redirections (*note Redirections::) associated with
1161 the shell function are performed when the function is executed.
1162
1163 A function definition may be deleted using the '-f' option to the
1164 'unset' builtin (*note Bourne Shell Builtins::).
1165
1166 The exit status of a function definition is zero unless a syntax
1167 error occurs or a readonly function with the same name already exists.
1168 When executed, the exit status of a function is the exit status of the
1169 last command executed in the body.
1170
1171 Note that for historical reasons, in the most common usage the curly
1172 braces that surround the body of the function must be separated from the
1173 body by 'blank's or newlines. This is because the braces are reserved
1174 words and are only recognized as such when they are separated from the
1175 command list by whitespace or another shell metacharacter. Also, when
1176 using the braces, the LIST must be terminated by a semicolon, a '&', or
1177 a newline.
1178
1179 When a function is executed, the arguments to the function become the
1180 positional parameters during its execution (*note Positional
1181 Parameters::). The special parameter '#' that expands to the number of
1182 positional parameters is updated to reflect the change. Special
1183 parameter '0' is unchanged. The first element of the 'FUNCNAME'
1184 variable is set to the name of the function while the function is
1185 executing.
1186
1187 All other aspects of the shell execution environment are identical
1188 between a function and its caller with these exceptions: the 'DEBUG' and
1189 'RETURN' traps are not inherited unless the function has been given the
1190 'trace' attribute using the 'declare' builtin or the '-o functrace'
1191 option has been enabled with the 'set' builtin, (in which case all
1192 functions inherit the 'DEBUG' and 'RETURN' traps), and the 'ERR' trap is
1193 not inherited unless the '-o errtrace' shell option has been enabled.
1194 *Note Bourne Shell Builtins::, for the description of the 'trap'
1195 builtin.
1196
1197 The 'FUNCNEST' variable, if set to a numeric value greater than 0,
1198 defines a maximum function nesting level. Function invocations that
1199 exceed the limit cause the entire command to abort.
1200
1201 If the builtin command 'return' is executed in a function, the
1202 function completes and execution resumes with the next command after the
1203 function call. Any command associated with the 'RETURN' trap is
1204 executed before execution resumes. When a function completes, the
1205 values of the positional parameters and the special parameter '#' are
1206 restored to the values they had prior to the function's execution. If a
1207 numeric argument is given to 'return', that is the function's return
1208 status; otherwise the function's return status is the exit status of the
1209 last command executed before the 'return'.
1210
1211 Variables local to the function may be declared with the 'local'
1212 builtin. These variables are visible only to the function and the
1213 commands it invokes.
1214
1215 Function names and definitions may be listed with the '-f' option to
1216 the 'declare' ('typeset') builtin command (*note Bash Builtins::). The
1217 '-F' option to 'declare' or 'typeset' will list the function names only
1218 (and optionally the source file and line number, if the 'extdebug' shell
1219 option is enabled). Functions may be exported so that subshells
1220 automatically have them defined with the '-f' option to the 'export'
1221 builtin (*note Bourne Shell Builtins::). Note that shell functions and
1222 variables with the same name may result in multiple identically-named
1223 entries in the environment passed to the shell's children. Care should
1224 be taken in cases where this may cause a problem.
1225
1226 Functions may be recursive. The 'FUNCNEST' variable may be used to
1227 limit the depth of the function call stack and restrict the number of
1228 function invocations. By default, no limit is placed on the number of
1229 recursive calls.
1230
1231 \1f
1232 File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1233
1234 3.4 Shell Parameters
1235 ====================
1236
1237 * Menu:
1238
1239 * Positional Parameters:: The shell's command-line arguments.
1240 * Special Parameters:: Parameters denoted by special characters.
1241
1242 A PARAMETER is an entity that stores values. It can be a 'name', a
1243 number, or one of the special characters listed below. A VARIABLE is a
1244 parameter denoted by a 'name'. A variable has a VALUE and zero or more
1245 ATTRIBUTES. Attributes are assigned using the 'declare' builtin command
1246 (see the description of the 'declare' builtin in *note Bash Builtins::).
1247
1248 A parameter is set if it has been assigned a value. The null string
1249 is a valid value. Once a variable is set, it may be unset only by using
1250 the 'unset' builtin command.
1251
1252 A variable may be assigned to by a statement of the form
1253 NAME=[VALUE]
1254 If VALUE is not given, the variable is assigned the null string. All
1255 VALUEs undergo tilde expansion, parameter and variable expansion,
1256 command substitution, arithmetic expansion, and quote removal (detailed
1257 below). If the variable has its 'integer' attribute set, then VALUE is
1258 evaluated as an arithmetic expression even if the '$((...))' expansion
1259 is not used (*note Arithmetic Expansion::). Word splitting is not
1260 performed, with the exception of '"$@"' as explained below. Filename
1261 expansion is not performed. Assignment statements may also appear as
1262 arguments to the 'alias', 'declare', 'typeset', 'export', 'readonly',
1263 and 'local' builtin commands (DECLARATION commands). When in POSIX mode
1264 (*note Bash POSIX Mode::), these builtins may appear in a command after
1265 one or more instances of the 'command' builtin and retain these
1266 assignment statement properties.
1267
1268 In the context where an assignment statement is assigning a value to
1269 a shell variable or array index (*note Arrays::), the '+=' operator can
1270 be used to append to or add to the variable's previous value. This
1271 includes arguments to builtin commands such as 'declare' that accept
1272 assignment statements (DECLARATION commands). When '+=' is applied to a
1273 variable for which the INTEGER attribute has been set, VALUE is
1274 evaluated as an arithmetic expression and added to the variable's
1275 current value, which is also evaluated. When '+=' is applied to an
1276 array variable using compound assignment (*note Arrays::), the
1277 variable's value is not unset (as it is when using '='), and new values
1278 are appended to the array beginning at one greater than the array's
1279 maximum index (for indexed arrays), or added as additional key-value
1280 pairs in an associative array. When applied to a string-valued
1281 variable, VALUE is expanded and appended to the variable's value.
1282
1283 A variable can be assigned the NAMEREF attribute using the '-n'
1284 option to the 'declare' or 'local' builtin commands (*note Bash
1285 Builtins::) to create a NAMEREF, or a reference to another variable.
1286 This allows variables to be manipulated indirectly. Whenever the
1287 nameref variable is referenced, assigned to, unset, or has its
1288 attributes modified (other than using or changing the nameref attribute
1289 itself), the operation is actually performed on the variable specified
1290 by the nameref variable's value. A nameref is commonly used within
1291 shell functions to refer to a variable whose name is passed as an
1292 argument to the function. For instance, if a variable name is passed to
1293 a shell function as its first argument, running
1294 declare -n ref=$1
1295 inside the function creates a nameref variable REF whose value is the
1296 variable name passed as the first argument. References and assignments
1297 to REF, and changes to its attributes, are treated as references,
1298 assignments, and attribute modifications to the variable whose name was
1299 passed as '$1'.
1300
1301 If the control variable in a 'for' loop has the nameref attribute,
1302 the list of words can be a list of shell variables, and a name reference
1303 will be established for each word in the list, in turn, when the loop is
1304 executed. Array variables cannot be given the nameref attribute.
1305 However, nameref variables can reference array variables and subscripted
1306 array variables. Namerefs can be unset using the '-n' option to the
1307 'unset' builtin (*note Bourne Shell Builtins::). Otherwise, if 'unset'
1308 is executed with the name of a nameref variable as an argument, the
1309 variable referenced by the nameref variable will be unset.
1310
1311 \1f
1312 File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1313
1314 3.4.1 Positional Parameters
1315 ---------------------------
1316
1317 A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
1318 other than the single digit '0'. Positional parameters are assigned
1319 from the shell's arguments when it is invoked, and may be reassigned
1320 using the 'set' builtin command. Positional parameter 'N' may be
1321 referenced as '${N}', or as '$N' when 'N' consists of a single digit.
1322 Positional parameters may not be assigned to with assignment statements.
1323 The 'set' and 'shift' builtins are used to set and unset them (*note
1324 Shell Builtin Commands::). The positional parameters are temporarily
1325 replaced when a shell function is executed (*note Shell Functions::).
1326
1327 When a positional parameter consisting of more than a single digit is
1328 expanded, it must be enclosed in braces.
1329
1330 \1f
1331 File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1332
1333 3.4.2 Special Parameters
1334 ------------------------
1335
1336 The shell treats several parameters specially. These parameters may
1337 only be referenced; assignment to them is not allowed.
1338
1339 '*'
1340 ($*) Expands to the positional parameters, starting from one. When
1341 the expansion is not within double quotes, each positional
1342 parameter expands to a separate word. In contexts where it is
1343 performed, those words are subject to further word splitting and
1344 pathname expansion. When the expansion occurs within double
1345 quotes, it expands to a single word with the value of each
1346 parameter separated by the first character of the 'IFS' special
1347 variable. That is, '"$*"' is equivalent to '"$1C$2C..."', where C
1348 is the first character of the value of the 'IFS' variable. If
1349 'IFS' is unset, the parameters are separated by spaces. If 'IFS'
1350 is null, the parameters are joined without intervening separators.
1351
1352 '@'
1353 ($@) Expands to the positional parameters, starting from one. When
1354 the expansion occurs within double quotes, each parameter expands
1355 to a separate word. That is, '"$@"' is equivalent to '"$1" "$2"
1356 ...'. If the double-quoted expansion occurs within a word, the
1357 expansion of the first parameter is joined with the beginning part
1358 of the original word, and the expansion of the last parameter is
1359 joined with the last part of the original word. When there are no
1360 positional parameters, '"$@"' and '$@' expand to nothing (i.e.,
1361 they are removed).
1362
1363 '#'
1364 ($#) Expands to the number of positional parameters in decimal.
1365
1366 '?'
1367 ($?) Expands to the exit status of the most recently executed
1368 foreground pipeline.
1369
1370 '-'
1371 ($-, a hyphen.) Expands to the current option flags as specified
1372 upon invocation, by the 'set' builtin command, or those set by the
1373 shell itself (such as the '-i' option).
1374
1375 '$'
1376 ($$) Expands to the process ID of the shell. In a '()' subshell,
1377 it expands to the process ID of the invoking shell, not the
1378 subshell.
1379
1380 '!'
1381 ($!) Expands to the process ID of the job most recently placed
1382 into the background, whether executed as an asynchronous command or
1383 using the 'bg' builtin (*note Job Control Builtins::).
1384
1385 '0'
1386 ($0) Expands to the name of the shell or shell script. This is set
1387 at shell initialization. If Bash is invoked with a file of
1388 commands (*note Shell Scripts::), '$0' is set to the name of that
1389 file. If Bash is started with the '-c' option (*note Invoking
1390 Bash::), then '$0' is set to the first argument after the string to
1391 be executed, if one is present. Otherwise, it is set to the
1392 filename used to invoke Bash, as given by argument zero.
1393
1394 '_'
1395 ($_, an underscore.) At shell startup, set to the absolute
1396 pathname used to invoke the shell or shell script being executed as
1397 passed in the environment or argument list. Subsequently, expands
1398 to the last argument to the previous command, after expansion.
1399 Also set to the full pathname used to invoke each command executed
1400 and placed in the environment exported to that command. When
1401 checking mail, this parameter holds the name of the mail file.
1402
1403 \1f
1404 File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1405
1406 3.5 Shell Expansions
1407 ====================
1408
1409 Expansion is performed on the command line after it has been split into
1410 'token's. There are seven kinds of expansion performed:
1411
1412 * brace expansion
1413 * tilde expansion
1414 * parameter and variable expansion
1415 * command substitution
1416 * arithmetic expansion
1417 * word splitting
1418 * filename expansion
1419
1420 * Menu:
1421
1422 * Brace Expansion:: Expansion of expressions within braces.
1423 * Tilde Expansion:: Expansion of the ~ character.
1424 * Shell Parameter Expansion:: How Bash expands variables to their values.
1425 * Command Substitution:: Using the output of a command as an argument.
1426 * Arithmetic Expansion:: How to use arithmetic in shell expansions.
1427 * Process Substitution:: A way to write and read to and from a
1428 command.
1429 * Word Splitting:: How the results of expansion are split into separate
1430 arguments.
1431 * Filename Expansion:: A shorthand for specifying filenames matching patterns.
1432 * Quote Removal:: How and when quote characters are removed from
1433 words.
1434
1435 The order of expansions is: brace expansion; tilde expansion,
1436 parameter and variable expansion, arithmetic expansion, and command
1437 substitution (done in a left-to-right fashion); word splitting; and
1438 filename expansion.
1439
1440 On systems that can support it, there is an additional expansion
1441 available: PROCESS SUBSTITUTION. This is performed at the same time as
1442 tilde, parameter, variable, and arithmetic expansion and command
1443 substitution.
1444
1445 After these expansions are performed, quote characters present in the
1446 original word are removed unless they have been quoted themselves (QUOTE
1447 REMOVAL).
1448
1449 Only brace expansion, word splitting, and filename expansion can
1450 change the number of words of the expansion; other expansions expand a
1451 single word to a single word. The only exceptions to this are the
1452 expansions of '"$@"' (*note Special Parameters::) and '"${NAME[@]}"'
1453 (*note Arrays::).
1454
1455 After all expansions, 'quote removal' (*note Quote Removal::) is
1456 performed.
1457
1458 \1f
1459 File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1460
1461 3.5.1 Brace Expansion
1462 ---------------------
1463
1464 Brace expansion is a mechanism by which arbitrary strings may be
1465 generated. This mechanism is similar to FILENAME EXPANSION (*note
1466 Filename Expansion::), but the filenames generated need not exist.
1467 Patterns to be brace expanded take the form of an optional PREAMBLE,
1468 followed by either a series of comma-separated strings or a sequence
1469 expression between a pair of braces, followed by an optional POSTSCRIPT.
1470 The preamble is prefixed to each string contained within the braces, and
1471 the postscript is then appended to each resulting string, expanding left
1472 to right.
1473
1474 Brace expansions may be nested. The results of each expanded string
1475 are not sorted; left to right order is preserved. For example,
1476 bash$ echo a{d,c,b}e
1477 ade ace abe
1478
1479 A sequence expression takes the form '{X..Y[..INCR]}', where X and Y
1480 are either integers or single characters, and INCR, an optional
1481 increment, is an integer. When integers are supplied, the expression
1482 expands to each number between X and Y, inclusive. Supplied integers
1483 may be prefixed with '0' to force each term to have the same width.
1484 When either X or Y begins with a zero, the shell attempts to force all
1485 generated terms to contain the same number of digits, zero-padding where
1486 necessary. When characters are supplied, the expression expands to each
1487 character lexicographically between X and Y, inclusive, using the
1488 default C locale. Note that both X and Y must be of the same type.
1489 When the increment is supplied, it is used as the difference between
1490 each term. The default increment is 1 or -1 as appropriate.
1491
1492 Brace expansion is performed before any other expansions, and any
1493 characters special to other expansions are preserved in the result. It
1494 is strictly textual. Bash does not apply any syntactic interpretation
1495 to the context of the expansion or the text between the braces. To
1496 avoid conflicts with parameter expansion, the string '${' is not
1497 considered eligible for brace expansion.
1498
1499 A correctly-formed brace expansion must contain unquoted opening and
1500 closing braces, and at least one unquoted comma or a valid sequence
1501 expression. Any incorrectly formed brace expansion is left unchanged.
1502
1503 A { or ',' may be quoted with a backslash to prevent its being
1504 considered part of a brace expression. To avoid conflicts with
1505 parameter expansion, the string '${' is not considered eligible for
1506 brace expansion.
1507
1508 This construct is typically used as shorthand when the common prefix
1509 of the strings to be generated is longer than in the above example:
1510 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1511 or
1512 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1513
1514 \1f
1515 File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1516
1517 3.5.2 Tilde Expansion
1518 ---------------------
1519
1520 If a word begins with an unquoted tilde character ('~'), all of the
1521 characters up to the first unquoted slash (or all characters, if there
1522 is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1523 characters in the tilde-prefix are quoted, the characters in the
1524 tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1525 If this login name is the null string, the tilde is replaced with the
1526 value of the 'HOME' shell variable. If 'HOME' is unset, the home
1527 directory of the user executing the shell is substituted instead.
1528 Otherwise, the tilde-prefix is replaced with the home directory
1529 associated with the specified login name.
1530
1531 If the tilde-prefix is '~+', the value of the shell variable 'PWD'
1532 replaces the tilde-prefix. If the tilde-prefix is '~-', the value of
1533 the shell variable 'OLDPWD', if it is set, is substituted.
1534
1535 If the characters following the tilde in the tilde-prefix consist of
1536 a number N, optionally prefixed by a '+' or a '-', the tilde-prefix is
1537 replaced with the corresponding element from the directory stack, as it
1538 would be displayed by the 'dirs' builtin invoked with the characters
1539 following tilde in the tilde-prefix as an argument (*note The Directory
1540 Stack::). If the tilde-prefix, sans the tilde, consists of a number
1541 without a leading '+' or '-', '+' is assumed.
1542
1543 If the login name is invalid, or the tilde expansion fails, the word
1544 is left unchanged.
1545
1546 Each variable assignment is checked for unquoted tilde-prefixes
1547 immediately following a ':' or the first '='. In these cases, tilde
1548 expansion is also performed. Consequently, one may use filenames with
1549 tildes in assignments to 'PATH', 'MAILPATH', and 'CDPATH', and the shell
1550 assigns the expanded value.
1551
1552 The following table shows how Bash treats unquoted tilde-prefixes:
1553
1554 '~'
1555 The value of '$HOME'
1556 '~/foo'
1557 '$HOME/foo'
1558
1559 '~fred/foo'
1560 The subdirectory 'foo' of the home directory of the user 'fred'
1561
1562 '~+/foo'
1563 '$PWD/foo'
1564
1565 '~-/foo'
1566 '${OLDPWD-'~-'}/foo'
1567
1568 '~N'
1569 The string that would be displayed by 'dirs +N'
1570
1571 '~+N'
1572 The string that would be displayed by 'dirs +N'
1573
1574 '~-N'
1575 The string that would be displayed by 'dirs -N'
1576
1577 \1f
1578 File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1579
1580 3.5.3 Shell Parameter Expansion
1581 -------------------------------
1582
1583 The '$' character introduces parameter expansion, command substitution,
1584 or arithmetic expansion. The parameter name or symbol to be expanded
1585 may be enclosed in braces, which are optional but serve to protect the
1586 variable to be expanded from characters immediately following it which
1587 could be interpreted as part of the name.
1588
1589 When braces are used, the matching ending brace is the first '}' not
1590 escaped by a backslash or within a quoted string, and not within an
1591 embedded arithmetic expansion, command substitution, or parameter
1592 expansion.
1593
1594 The basic form of parameter expansion is ${PARAMETER}. The value of
1595 PARAMETER is substituted. The PARAMETER is a shell parameter as
1596 described above (*note Shell Parameters::) or an array reference (*note
1597 Arrays::). The braces are required when PARAMETER is a positional
1598 parameter with more than one digit, or when PARAMETER is followed by a
1599 character that is not to be interpreted as part of its name.
1600
1601 If the first character of PARAMETER is an exclamation point (!), and
1602 PARAMETER is not a NAMEREF, it introduces a level of variable
1603 indirection. Bash uses the value of the variable formed from the rest
1604 of PARAMETER as the name of the variable; this variable is then expanded
1605 and that value is used in the rest of the substitution, rather than the
1606 value of PARAMETER itself. This is known as 'indirect expansion'. If
1607 PARAMETER is a nameref, this expands to the name of the variable
1608 referenced by PARAMETER instead of performing the complete indirect
1609 expansion. The exceptions to this are the expansions of ${!PREFIX*} and
1610 ${!NAME[@]} described below. The exclamation point must immediately
1611 follow the left brace in order to introduce indirection.
1612
1613 In each of the cases below, WORD is subject to tilde expansion,
1614 parameter expansion, command substitution, and arithmetic expansion.
1615
1616 When not performing substring expansion, using the form described
1617 below (e.g., ':-'), Bash tests for a parameter that is unset or null.
1618 Omitting the colon results in a test only for a parameter that is unset.
1619 Put another way, if the colon is included, the operator tests for both
1620 PARAMETER's existence and that its value is not null; if the colon is
1621 omitted, the operator tests only for existence.
1622
1623 '${PARAMETER:-WORD}'
1624 If PARAMETER is unset or null, the expansion of WORD is
1625 substituted. Otherwise, the value of PARAMETER is substituted.
1626
1627 '${PARAMETER:=WORD}'
1628 If PARAMETER is unset or null, the expansion of WORD is assigned to
1629 PARAMETER. The value of PARAMETER is then substituted. Positional
1630 parameters and special parameters may not be assigned to in this
1631 way.
1632
1633 '${PARAMETER:?WORD}'
1634 If PARAMETER is null or unset, the expansion of WORD (or a message
1635 to that effect if WORD is not present) is written to the standard
1636 error and the shell, if it is not interactive, exits. Otherwise,
1637 the value of PARAMETER is substituted.
1638
1639 '${PARAMETER:+WORD}'
1640 If PARAMETER is null or unset, nothing is substituted, otherwise
1641 the expansion of WORD is substituted.
1642
1643 '${PARAMETER:OFFSET}'
1644 '${PARAMETER:OFFSET:LENGTH}'
1645 This is referred to as Substring Expansion. It expands to up to
1646 LENGTH characters of the value of PARAMETER starting at the
1647 character specified by OFFSET. If PARAMETER is '@', an indexed
1648 array subscripted by '@' or '*', or an associative array name, the
1649 results differ as described below. If LENGTH is omitted, it
1650 expands to the substring of the value of PARAMETER starting at the
1651 character specified by OFFSET and extending to the end of the
1652 value. LENGTH and OFFSET are arithmetic expressions (*note Shell
1653 Arithmetic::).
1654
1655 If OFFSET evaluates to a number less than zero, the value is used
1656 as an offset in characters from the end of the value of PARAMETER.
1657 If LENGTH evaluates to a number less than zero, it is interpreted
1658 as an offset in characters from the end of the value of PARAMETER
1659 rather than a number of characters, and the expansion is the
1660 characters between OFFSET and that result. Note that a negative
1661 offset must be separated from the colon by at least one space to
1662 avoid being confused with the ':-' expansion.
1663
1664 Here are some examples illustrating substring expansion on
1665 parameters and subscripted arrays:
1666
1667 $ string=01234567890abcdefgh
1668 $ echo ${string:7}
1669 7890abcdefgh
1670 $ echo ${string:7:0}
1671
1672 $ echo ${string:7:2}
1673 78
1674 $ echo ${string:7:-2}
1675 7890abcdef
1676 $ echo ${string: -7}
1677 bcdefgh
1678 $ echo ${string: -7:0}
1679
1680 $ echo ${string: -7:2}
1681 bc
1682 $ echo ${string: -7:-2}
1683 bcdef
1684 $ set -- 01234567890abcdefgh
1685 $ echo ${1:7}
1686 7890abcdefgh
1687 $ echo ${1:7:0}
1688
1689 $ echo ${1:7:2}
1690 78
1691 $ echo ${1:7:-2}
1692 7890abcdef
1693 $ echo ${1: -7}
1694 bcdefgh
1695 $ echo ${1: -7:0}
1696
1697 $ echo ${1: -7:2}
1698 bc
1699 $ echo ${1: -7:-2}
1700 bcdef
1701 $ array[0]=01234567890abcdefgh
1702 $ echo ${array[0]:7}
1703 7890abcdefgh
1704 $ echo ${array[0]:7:0}
1705
1706 $ echo ${array[0]:7:2}
1707 78
1708 $ echo ${array[0]:7:-2}
1709 7890abcdef
1710 $ echo ${array[0]: -7}
1711 bcdefgh
1712 $ echo ${array[0]: -7:0}
1713
1714 $ echo ${array[0]: -7:2}
1715 bc
1716 $ echo ${array[0]: -7:-2}
1717 bcdef
1718
1719 If PARAMETER is '@', the result is LENGTH positional parameters
1720 beginning at OFFSET. A negative OFFSET is taken relative to one
1721 greater than the greatest positional parameter, so an offset of -1
1722 evaluates to the last positional parameter. It is an expansion
1723 error if LENGTH evaluates to a number less than zero.
1724
1725 The following examples illustrate substring expansion using
1726 positional parameters:
1727
1728 $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1729 $ echo ${@:7}
1730 7 8 9 0 a b c d e f g h
1731 $ echo ${@:7:0}
1732
1733 $ echo ${@:7:2}
1734 7 8
1735 $ echo ${@:7:-2}
1736 bash: -2: substring expression < 0
1737 $ echo ${@: -7:2}
1738 b c
1739 $ echo ${@:0}
1740 ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1741 $ echo ${@:0:2}
1742 ./bash 1
1743 $ echo ${@: -7:0}
1744
1745
1746 If PARAMETER is an indexed array name subscripted by '@' or '*',
1747 the result is the LENGTH members of the array beginning with
1748 '${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to one
1749 greater than the maximum index of the specified array. It is an
1750 expansion error if LENGTH evaluates to a number less than zero.
1751
1752 These examples show how you can use substring expansion with
1753 indexed arrays:
1754
1755 $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
1756 $ echo ${array[@]:7}
1757 7 8 9 0 a b c d e f g h
1758 $ echo ${array[@]:7:2}
1759 7 8
1760 $ echo ${array[@]: -7:2}
1761 b c
1762 $ echo ${array[@]: -7:-2}
1763 bash: -2: substring expression < 0
1764 $ echo ${array[@]:0}
1765 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1766 $ echo ${array[@]:0:2}
1767 0 1
1768 $ echo ${array[@]: -7:0}
1769
1770
1771 Substring expansion applied to an associative array produces
1772 undefined results.
1773
1774 Substring indexing is zero-based unless the positional parameters
1775 are used, in which case the indexing starts at 1 by default. If
1776 OFFSET is 0, and the positional parameters are used, '$@' is
1777 prefixed to the list.
1778
1779 '${!PREFIX*}'
1780 '${!PREFIX@}'
1781 Expands to the names of variables whose names begin with PREFIX,
1782 separated by the first character of the 'IFS' special variable.
1783 When '@' is used and the expansion appears within double quotes,
1784 each variable name expands to a separate word.
1785
1786 '${!NAME[@]}'
1787 '${!NAME[*]}'
1788 If NAME is an array variable, expands to the list of array indices
1789 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1790 NAME is set and null otherwise. When '@' is used and the expansion
1791 appears within double quotes, each key expands to a separate word.
1792
1793 '${#PARAMETER}'
1794 The length in characters of the expanded value of PARAMETER is
1795 substituted. If PARAMETER is '*' or '@', the value substituted is
1796 the number of positional parameters. If PARAMETER is an array name
1797 subscripted by '*' or '@', the value substituted is the number of
1798 elements in the array. If PARAMETER is an indexed array name
1799 subscripted by a negative number, that number is interpreted as
1800 relative to one greater than the maximum index of PARAMETER, so
1801 negative indices count back from the end of the array, and an index
1802 of -1 references the last element.
1803
1804 '${PARAMETER#WORD}'
1805 '${PARAMETER##WORD}'
1806 The WORD is expanded to produce a pattern just as in filename
1807 expansion (*note Filename Expansion::). If the pattern matches the
1808 beginning of the expanded value of PARAMETER, then the result of
1809 the expansion is the expanded value of PARAMETER with the shortest
1810 matching pattern (the '#' case) or the longest matching pattern
1811 (the '##' case) deleted. If PARAMETER is '@' or '*', the pattern
1812 removal operation is applied to each positional parameter in turn,
1813 and the expansion is the resultant list. If PARAMETER is an array
1814 variable subscripted with '@' or '*', the pattern removal operation
1815 is applied to each member of the array in turn, and the expansion
1816 is the resultant list.
1817
1818 '${PARAMETER%WORD}'
1819 '${PARAMETER%%WORD}'
1820 The WORD is expanded to produce a pattern just as in filename
1821 expansion. If the pattern matches a trailing portion of the
1822 expanded value of PARAMETER, then the result of the expansion is
1823 the value of PARAMETER with the shortest matching pattern (the '%'
1824 case) or the longest matching pattern (the '%%' case) deleted. If
1825 PARAMETER is '@' or '*', the pattern removal operation is applied
1826 to each positional parameter in turn, and the expansion is the
1827 resultant list. If PARAMETER is an array variable subscripted with
1828 '@' or '*', the pattern removal operation is applied to each member
1829 of the array in turn, and the expansion is the resultant list.
1830
1831 '${PARAMETER/PATTERN/STRING}'
1832
1833 The PATTERN is expanded to produce a pattern just as in filename
1834 expansion. PARAMETER is expanded and the longest match of PATTERN
1835 against its value is replaced with STRING. If PATTERN begins with
1836 '/', all matches of PATTERN are replaced with STRING. Normally
1837 only the first match is replaced. If PATTERN begins with '#', it
1838 must match at the beginning of the expanded value of PARAMETER. If
1839 PATTERN begins with '%', it must match at the end of the expanded
1840 value of PARAMETER. If STRING is null, matches of PATTERN are
1841 deleted and the '/' following PATTERN may be omitted. If the
1842 'nocasematch' shell option (see the description of 'shopt' in *note
1843 The Shopt Builtin::) is enabled, the match is performed without
1844 regard to the case of alphabetic characters. If PARAMETER is '@'
1845 or '*', the substitution operation is applied to each positional
1846 parameter in turn, and the expansion is the resultant list. If
1847 PARAMETER is an array variable subscripted with '@' or '*', the
1848 substitution operation is applied to each member of the array in
1849 turn, and the expansion is the resultant list.
1850
1851 '${PARAMETER^PATTERN}'
1852 '${PARAMETER^^PATTERN}'
1853 '${PARAMETER,PATTERN}'
1854 '${PARAMETER,,PATTERN}'
1855 This expansion modifies the case of alphabetic characters in
1856 PARAMETER. The PATTERN is expanded to produce a pattern just as in
1857 filename expansion. Each character in the expanded value of
1858 PARAMETER is tested against PATTERN, and, if it matches the
1859 pattern, its case is converted. The pattern should not attempt to
1860 match more than one character. The '^' operator converts lowercase
1861 letters matching PATTERN to uppercase; the ',' operator converts
1862 matching uppercase letters to lowercase. The '^^' and ',,'
1863 expansions convert each matched character in the expanded value;
1864 the '^' and ',' expansions match and convert only the first
1865 character in the expanded value. If PATTERN is omitted, it is
1866 treated like a '?', which matches every character. If PARAMETER is
1867 '@' or '*', the case modification operation is applied to each
1868 positional parameter in turn, and the expansion is the resultant
1869 list. If PARAMETER is an array variable subscripted with '@' or
1870 '*', the case modification operation is applied to each member of
1871 the array in turn, and the expansion is the resultant list.
1872
1873 '${PARAMETER@OPERATOR}'
1874 The expansion is either a transformation of the value of PARAMETER
1875 or information about PARAMETER itself, depending on the value of
1876 OPERATOR. Each OPERATOR is a single letter:
1877
1878 'Q'
1879 The expansion is a string that is the value of PARAMETER
1880 quoted in a format that can be reused as input.
1881 'E'
1882 The expansion is a string that is the value of PARAMETER with
1883 backslash escape sequences expanded as with the '$'...''
1884 quoting mechansim.
1885 'P'
1886 The expansion is a string that is the result of expanding the
1887 value of PARAMETER as if it were a prompt string (*note
1888 Controlling the Prompt::).
1889 'A'
1890 The expansion is a string in the form of an assignment
1891 statement or 'declare' command that, if evaluated, will
1892 recreate PARAMETER with its attributes and value.
1893 'a'
1894 The expansion is a string consisting of flag values
1895 representing PARAMETER's attributes.
1896
1897 If PARAMETER is '@' or '*', the operation is applied to each
1898 positional parameter in turn, and the expansion is the resultant
1899 list. If PARAMETER is an array variable subscripted with '@' or
1900 '*', the operation is applied to each member of the array in turn,
1901 and the expansion is the resultant list.
1902
1903 The result of the expansion is subject to word splitting and
1904 pathname expansion as described below.
1905
1906 \1f
1907 File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1908
1909 3.5.4 Command Substitution
1910 --------------------------
1911
1912 Command substitution allows the output of a command to replace the
1913 command itself. Command substitution occurs when a command is enclosed
1914 as follows:
1915 $(COMMAND)
1916 or
1917 `COMMAND`
1918
1919 Bash performs the expansion by executing COMMAND in a subshell
1920 environment and replacing the command substitution with the standard
1921 output of the command, with any trailing newlines deleted. Embedded
1922 newlines are not deleted, but they may be removed during word splitting.
1923 The command substitution '$(cat FILE)' can be replaced by the equivalent
1924 but faster '$(< FILE)'.
1925
1926 When the old-style backquote form of substitution is used, backslash
1927 retains its literal meaning except when followed by '$', '`', or '\'.
1928 The first backquote not preceded by a backslash terminates the command
1929 substitution. When using the '$(COMMAND)' form, all characters between
1930 the parentheses make up the command; none are treated specially.
1931
1932 Command substitutions may be nested. To nest when using the
1933 backquoted form, escape the inner backquotes with backslashes.
1934
1935 If the substitution appears within double quotes, word splitting and
1936 filename expansion are not performed on the results.
1937
1938 \1f
1939 File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
1940
1941 3.5.5 Arithmetic Expansion
1942 --------------------------
1943
1944 Arithmetic expansion allows the evaluation of an arithmetic expression
1945 and the substitution of the result. The format for arithmetic expansion
1946 is:
1947
1948 $(( EXPRESSION ))
1949
1950 The expression is treated as if it were within double quotes, but a
1951 double quote inside the parentheses is not treated specially. All
1952 tokens in the expression undergo parameter and variable expansion,
1953 command substitution, and quote removal. The result is treated as the
1954 arithmetic expression to be evaluated. Arithmetic expansions may be
1955 nested.
1956
1957 The evaluation is performed according to the rules listed below
1958 (*note Shell Arithmetic::). If the expression is invalid, Bash prints a
1959 message indicating failure to the standard error and no substitution
1960 occurs.
1961
1962 \1f
1963 File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
1964
1965 3.5.6 Process Substitution
1966 --------------------------
1967
1968 Process substitution allows a process's input or output to be referred
1969 to using a filename. It takes the form of
1970 <(LIST)
1971 or
1972 >(LIST)
1973 The process LIST is run asynchronously, and its input or output appears
1974 as a filename. This filename is passed as an argument to the current
1975 command as the result of the expansion. If the '>(LIST)' form is used,
1976 writing to the file will provide input for LIST. If the '<(LIST)' form
1977 is used, the file passed as an argument should be read to obtain the
1978 output of LIST. Note that no space may appear between the '<' or '>'
1979 and the left parenthesis, otherwise the construct would be interpreted
1980 as a redirection. Process substitution is supported on systems that
1981 support named pipes (FIFOs) or the '/dev/fd' method of naming open
1982 files.
1983
1984 When available, process substitution is performed simultaneously with
1985 parameter and variable expansion, command substitution, and arithmetic
1986 expansion.
1987
1988 \1f
1989 File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
1990
1991 3.5.7 Word Splitting
1992 --------------------
1993
1994 The shell scans the results of parameter expansion, command
1995 substitution, and arithmetic expansion that did not occur within double
1996 quotes for word splitting.
1997
1998 The shell treats each character of '$IFS' as a delimiter, and splits
1999 the results of the other expansions into words using these characters as
2000 field terminators. If 'IFS' is unset, or its value is exactly
2001 '<space><tab><newline>', the default, then sequences of ' <space>',
2002 '<tab>', and '<newline>' at the beginning and end of the results of the
2003 previous expansions are ignored, and any sequence of 'IFS' characters
2004 not at the beginning or end serves to delimit words. If 'IFS' has a
2005 value other than the default, then sequences of the whitespace
2006 characters 'space', 'tab', and 'newline' are ignored at the beginning
2007 and end of the word, as long as the whitespace character is in the value
2008 of 'IFS' (an 'IFS' whitespace character). Any character in 'IFS' that
2009 is not 'IFS' whitespace, along with any adjacent 'IFS' whitespace
2010 characters, delimits a field. A sequence of 'IFS' whitespace characters
2011 is also treated as a delimiter. If the value of 'IFS' is null, no word
2012 splitting occurs.
2013
2014 Explicit null arguments ('""' or '''') are retained and passed to
2015 commands as empty strings. Unquoted implicit null arguments, resulting
2016 from the expansion of parameters that have no values, are removed. If a
2017 parameter with no value is expanded within double quotes, a null
2018 argument results and is retained and passed to a command as an empty
2019 string. When a quoted null argument appears as part of a word whose
2020 expansion is non-null, the null argument is removed. That is, the word
2021 '-d''' becomes '-d' after word splitting and null argument removal.
2022
2023 Note that if no expansion occurs, no splitting is performed.
2024
2025 \1f
2026 File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
2027
2028 3.5.8 Filename Expansion
2029 ------------------------
2030
2031 * Menu:
2032
2033 * Pattern Matching:: How the shell matches patterns.
2034
2035 After word splitting, unless the '-f' option has been set (*note The Set
2036 Builtin::), Bash scans each word for the characters '*', '?', and '['.
2037 If one of these characters appears, then the word is regarded as a
2038 PATTERN, and replaced with an alphabetically sorted list of filenames
2039 matching the pattern (*note Pattern Matching::). If no matching
2040 filenames are found, and the shell option 'nullglob' is disabled, the
2041 word is left unchanged. If the 'nullglob' option is set, and no matches
2042 are found, the word is removed. If the 'failglob' shell option is set,
2043 and no matches are found, an error message is printed and the command is
2044 not executed. If the shell option 'nocaseglob' is enabled, the match is
2045 performed without regard to the case of alphabetic characters.
2046
2047 When a pattern is used for filename expansion, the character '.' at
2048 the start of a filename or immediately following a slash must be matched
2049 explicitly, unless the shell option 'dotglob' is set. When matching a
2050 filename, the slash character must always be matched explicitly. In
2051 other cases, the '.' character is not treated specially.
2052
2053 See the description of 'shopt' in *note The Shopt Builtin::, for a
2054 description of the 'nocaseglob', 'nullglob', 'failglob', and 'dotglob'
2055 options.
2056
2057 The 'GLOBIGNORE' shell variable may be used to restrict the set of
2058 filenames matching a pattern. If 'GLOBIGNORE' is set, each matching
2059 filename that also matches one of the patterns in 'GLOBIGNORE' is
2060 removed from the list of matches. If the 'nocaseglob' option is set,
2061 the matching against the patterns in 'GLOBIGNORE' is performed without
2062 regard to case. The filenames '.' and '..' are always ignored when
2063 'GLOBIGNORE' is set and not null. However, setting 'GLOBIGNORE' to a
2064 non-null value has the effect of enabling the 'dotglob' shell option, so
2065 all other filenames beginning with a '.' will match. To get the old
2066 behavior of ignoring filenames beginning with a '.', make '.*' one of
2067 the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when
2068 'GLOBIGNORE' is unset.
2069
2070 \1f
2071 File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
2072
2073 3.5.8.1 Pattern Matching
2074 ........................
2075
2076 Any character that appears in a pattern, other than the special pattern
2077 characters described below, matches itself. The NUL character may not
2078 occur in a pattern. A backslash escapes the following character; the
2079 escaping backslash is discarded when matching. The special pattern
2080 characters must be quoted if they are to be matched literally.
2081
2082 The special pattern characters have the following meanings:
2083 '*'
2084 Matches any string, including the null string. When the 'globstar'
2085 shell option is enabled, and '*' is used in a filename expansion
2086 context, two adjacent '*'s used as a single pattern will match all
2087 files and zero or more directories and subdirectories. If followed
2088 by a '/', two adjacent '*'s will match only directories and
2089 subdirectories.
2090 '?'
2091 Matches any single character.
2092 '[...]'
2093 Matches any one of the enclosed characters. A pair of characters
2094 separated by a hyphen denotes a RANGE EXPRESSION; any character
2095 that falls between those two characters, inclusive, using the
2096 current locale's collating sequence and character set, is matched.
2097 If the first character following the '[' is a '!' or a '^' then any
2098 character not enclosed is matched. A '-' may be matched by
2099 including it as the first or last character in the set. A ']' may
2100 be matched by including it as the first character in the set. The
2101 sorting order of characters in range expressions is determined by
2102 the current locale and the values of the 'LC_COLLATE' and 'LC_ALL'
2103 shell variables, if set.
2104
2105 For example, in the default C locale, '[a-dx-z]' is equivalent to
2106 '[abcdxyz]'. Many locales sort characters in dictionary order, and
2107 in these locales '[a-dx-z]' is typically not equivalent to
2108 '[abcdxyz]'; it might be equivalent to '[aBbCcDdxXyYz]', for
2109 example. To obtain the traditional interpretation of ranges in
2110 bracket expressions, you can force the use of the C locale by
2111 setting the 'LC_COLLATE' or 'LC_ALL' environment variable to the
2112 value 'C', or enable the 'globasciiranges' shell option.
2113
2114 Within '[' and ']', CHARACTER CLASSES can be specified using the
2115 syntax '[:'CLASS':]', where CLASS is one of the following classes
2116 defined in the POSIX standard:
2117 alnum alpha ascii blank cntrl digit graph lower
2118 print punct space upper word xdigit
2119 A character class matches any character belonging to that class.
2120 The 'word' character class matches letters, digits, and the
2121 character '_'.
2122
2123 Within '[' and ']', an EQUIVALENCE CLASS can be specified using the
2124 syntax '[='C'=]', which matches all characters with the same
2125 collation weight (as defined by the current locale) as the
2126 character C.
2127
2128 Within '[' and ']', the syntax '[.'SYMBOL'.]' matches the collating
2129 symbol SYMBOL.
2130
2131 If the 'extglob' shell option is enabled using the 'shopt' builtin,
2132 several extended pattern matching operators are recognized. In the
2133 following description, a PATTERN-LIST is a list of one or more patterns
2134 separated by a '|'. Composite patterns may be formed using one or more
2135 of the following sub-patterns:
2136
2137 '?(PATTERN-LIST)'
2138 Matches zero or one occurrence of the given patterns.
2139
2140 '*(PATTERN-LIST)'
2141 Matches zero or more occurrences of the given patterns.
2142
2143 '+(PATTERN-LIST)'
2144 Matches one or more occurrences of the given patterns.
2145
2146 '@(PATTERN-LIST)'
2147 Matches one of the given patterns.
2148
2149 '!(PATTERN-LIST)'
2150 Matches anything except one of the given patterns.
2151
2152 \1f
2153 File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
2154
2155 3.5.9 Quote Removal
2156 -------------------
2157
2158 After the preceding expansions, all unquoted occurrences of the
2159 characters '\', ''', and '"' that did not result from one of the above
2160 expansions are removed.
2161
2162 \1f
2163 File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
2164
2165 3.6 Redirections
2166 ================
2167
2168 Before a command is executed, its input and output may be REDIRECTED
2169 using a special notation interpreted by the shell. Redirection allows
2170 commands' file handles to be duplicated, opened, closed, made to refer
2171 to different files, and can change the files the command reads from and
2172 writes to. Redirection may also be used to modify file handles in the
2173 current shell execution environment. The following redirection
2174 operators may precede or appear anywhere within a simple command or may
2175 follow a command. Redirections are processed in the order they appear,
2176 from left to right.
2177
2178 Each redirection that may be preceded by a file descriptor number may
2179 instead be preceded by a word of the form {VARNAME}. In this case, for
2180 each redirection operator except >&- and <&-, the shell will allocate a
2181 file descriptor greater than 10 and assign it to {VARNAME}. If >&- or
2182 <&- is preceded by {VARNAME}, the value of VARNAME defines the file
2183 descriptor to close.
2184
2185 In the following descriptions, if the file descriptor number is
2186 omitted, and the first character of the redirection operator is '<', the
2187 redirection refers to the standard input (file descriptor 0). If the
2188 first character of the redirection operator is '>', the redirection
2189 refers to the standard output (file descriptor 1).
2190
2191 The word following the redirection operator in the following
2192 descriptions, unless otherwise noted, is subjected to brace expansion,
2193 tilde expansion, parameter expansion, command substitution, arithmetic
2194 expansion, quote removal, filename expansion, and word splitting. If it
2195 expands to more than one word, Bash reports an error.
2196
2197 Note that the order of redirections is significant. For example, the
2198 command
2199 ls > DIRLIST 2>&1
2200 directs both standard output (file descriptor 1) and standard error
2201 (file descriptor 2) to the file DIRLIST, while the command
2202 ls 2>&1 > DIRLIST
2203 directs only the standard output to file DIRLIST, because the standard
2204 error was made a copy of the standard output before the standard output
2205 was redirected to DIRLIST.
2206
2207 Bash handles several filenames specially when they are used in
2208 redirections, as described in the following table. If the operating
2209 system on which Bash is running provides these special files, bash will
2210 use them; otherwise it will emulate them internally with the behavior
2211 described below.
2212
2213 '/dev/fd/FD'
2214 If FD is a valid integer, file descriptor FD is duplicated.
2215
2216 '/dev/stdin'
2217 File descriptor 0 is duplicated.
2218
2219 '/dev/stdout'
2220 File descriptor 1 is duplicated.
2221
2222 '/dev/stderr'
2223 File descriptor 2 is duplicated.
2224
2225 '/dev/tcp/HOST/PORT'
2226 If HOST is a valid hostname or Internet address, and PORT is an
2227 integer port number or service name, Bash attempts to open the
2228 corresponding TCP socket.
2229
2230 '/dev/udp/HOST/PORT'
2231 If HOST is a valid hostname or Internet address, and PORT is an
2232 integer port number or service name, Bash attempts to open the
2233 corresponding UDP socket.
2234
2235 A failure to open or create a file causes the redirection to fail.
2236
2237 Redirections using file descriptors greater than 9 should be used
2238 with care, as they may conflict with file descriptors the shell uses
2239 internally.
2240
2241 3.6.1 Redirecting Input
2242 -----------------------
2243
2244 Redirection of input causes the file whose name results from the
2245 expansion of WORD to be opened for reading on file descriptor 'n', or
2246 the standard input (file descriptor 0) if 'n' is not specified.
2247
2248 The general format for redirecting input is:
2249 [N]<WORD
2250
2251 3.6.2 Redirecting Output
2252 ------------------------
2253
2254 Redirection of output causes the file whose name results from the
2255 expansion of WORD to be opened for writing on file descriptor N, or the
2256 standard output (file descriptor 1) if N is not specified. If the file
2257 does not exist it is created; if it does exist it is truncated to zero
2258 size.
2259
2260 The general format for redirecting output is:
2261 [N]>[|]WORD
2262
2263 If the redirection operator is '>', and the 'noclobber' option to the
2264 'set' builtin has been enabled, the redirection will fail if the file
2265 whose name results from the expansion of WORD exists and is a regular
2266 file. If the redirection operator is '>|', or the redirection operator
2267 is '>' and the 'noclobber' option is not enabled, the redirection is
2268 attempted even if the file named by WORD exists.
2269
2270 3.6.3 Appending Redirected Output
2271 ---------------------------------
2272
2273 Redirection of output in this fashion causes the file whose name results
2274 from the expansion of WORD to be opened for appending on file descriptor
2275 N, or the standard output (file descriptor 1) if N is not specified. If
2276 the file does not exist it is created.
2277
2278 The general format for appending output is:
2279 [N]>>WORD
2280
2281 3.6.4 Redirecting Standard Output and Standard Error
2282 ----------------------------------------------------
2283
2284 This construct allows both the standard output (file descriptor 1) and
2285 the standard error output (file descriptor 2) to be redirected to the
2286 file whose name is the expansion of WORD.
2287
2288 There are two formats for redirecting standard output and standard
2289 error:
2290 &>WORD
2291 and
2292 >&WORD
2293 Of the two forms, the first is preferred. This is semantically
2294 equivalent to
2295 >WORD 2>&1
2296 When using the second form, WORD may not expand to a number or '-'.
2297 If it does, other redirection operators apply (see Duplicating File
2298 Descriptors below) for compatibility reasons.
2299
2300 3.6.5 Appending Standard Output and Standard Error
2301 --------------------------------------------------
2302
2303 This construct allows both the standard output (file descriptor 1) and
2304 the standard error output (file descriptor 2) to be appended to the file
2305 whose name is the expansion of WORD.
2306
2307 The format for appending standard output and standard error is:
2308 &>>WORD
2309 This is semantically equivalent to
2310 >>WORD 2>&1
2311 (see Duplicating File Descriptors below).
2312
2313 3.6.6 Here Documents
2314 --------------------
2315
2316 This type of redirection instructs the shell to read input from the
2317 current source until a line containing only WORD (with no trailing
2318 blanks) is seen. All of the lines read up to that point are then used
2319 as the standard input (or file descriptor N if N is specified) for a
2320 command.
2321
2322 The format of here-documents is:
2323 [N]<<[-]WORD
2324 HERE-DOCUMENT
2325 DELIMITER
2326
2327 No parameter and variable expansion, command substitution, arithmetic
2328 expansion, or filename expansion is performed on WORD. If any part of
2329 WORD is quoted, the DELIMITER is the result of quote removal on WORD,
2330 and the lines in the here-document are not expanded. If WORD is
2331 unquoted, all lines of the here-document are subjected to parameter
2332 expansion, command substitution, and arithmetic expansion, the character
2333 sequence '\newline' is ignored, and '\' must be used to quote the
2334 characters '\', '$', and '`'.
2335
2336 If the redirection operator is '<<-', then all leading tab characters
2337 are stripped from input lines and the line containing DELIMITER. This
2338 allows here-documents within shell scripts to be indented in a natural
2339 fashion.
2340
2341 3.6.7 Here Strings
2342 ------------------
2343
2344 A variant of here documents, the format is:
2345 [N]<<< WORD
2346
2347 The WORD undergoes brace expansion, tilde expansion, parameter and
2348 variable expansion, command substitution, arithmetic expansion, and
2349 quote removal. Pathname expansion and word splitting are not performed.
2350 The result is supplied as a single string, with a newline appended, to
2351 the command on its standard input (or file descriptor N if N is
2352 specified).
2353
2354 3.6.8 Duplicating File Descriptors
2355 ----------------------------------
2356
2357 The redirection operator
2358 [N]<&WORD
2359 is used to duplicate input file descriptors. If WORD expands to one or
2360 more digits, the file descriptor denoted by N is made to be a copy of
2361 that file descriptor. If the digits in WORD do not specify a file
2362 descriptor open for input, a redirection error occurs. If WORD
2363 evaluates to '-', file descriptor N is closed. If N is not specified,
2364 the standard input (file descriptor 0) is used.
2365
2366 The operator
2367 [N]>&WORD
2368 is used similarly to duplicate output file descriptors. If N is not
2369 specified, the standard output (file descriptor 1) is used. If the
2370 digits in WORD do not specify a file descriptor open for output, a
2371 redirection error occurs. If WORD evaluates to '-', file descriptor N
2372 is closed. As a special case, if N is omitted, and WORD does not expand
2373 to one or more digits or '-', the standard output and standard error are
2374 redirected as described previously.
2375
2376 3.6.9 Moving File Descriptors
2377 -----------------------------
2378
2379 The redirection operator
2380 [N]<&DIGIT-
2381 moves the file descriptor DIGIT to file descriptor N, or the standard
2382 input (file descriptor 0) if N is not specified. DIGIT is closed after
2383 being duplicated to N.
2384
2385 Similarly, the redirection operator
2386 [N]>&DIGIT-
2387 moves the file descriptor DIGIT to file descriptor N, or the standard
2388 output (file descriptor 1) if N is not specified.
2389
2390 3.6.10 Opening File Descriptors for Reading and Writing
2391 -------------------------------------------------------
2392
2393 The redirection operator
2394 [N]<>WORD
2395 causes the file whose name is the expansion of WORD to be opened for
2396 both reading and writing on file descriptor N, or on file descriptor 0
2397 if N is not specified. If the file does not exist, it is created.
2398
2399 \1f
2400 File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2401
2402 3.7 Executing Commands
2403 ======================
2404
2405 * Menu:
2406
2407 * Simple Command Expansion:: How Bash expands simple commands before
2408 executing them.
2409 * Command Search and Execution:: How Bash finds commands and runs them.
2410 * Command Execution Environment:: The environment in which Bash
2411 executes commands that are not
2412 shell builtins.
2413 * Environment:: The environment given to a command.
2414 * Exit Status:: The status returned by commands and how Bash
2415 interprets it.
2416 * Signals:: What happens when Bash or a command it runs
2417 receives a signal.
2418
2419 \1f
2420 File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2421
2422 3.7.1 Simple Command Expansion
2423 ------------------------------
2424
2425 When a simple command is executed, the shell performs the following
2426 expansions, assignments, and redirections, from left to right.
2427
2428 1. The words that the parser has marked as variable assignments (those
2429 preceding the command name) and redirections are saved for later
2430 processing.
2431
2432 2. The words that are not variable assignments or redirections are
2433 expanded (*note Shell Expansions::). If any words remain after
2434 expansion, the first word is taken to be the name of the command
2435 and the remaining words are the arguments.
2436
2437 3. Redirections are performed as described above (*note
2438 Redirections::).
2439
2440 4. The text after the '=' in each variable assignment undergoes tilde
2441 expansion, parameter expansion, command substitution, arithmetic
2442 expansion, and quote removal before being assigned to the variable.
2443
2444 If no command name results, the variable assignments affect the
2445 current shell environment. Otherwise, the variables are added to the
2446 environment of the executed command and do not affect the current shell
2447 environment. If any of the assignments attempts to assign a value to a
2448 readonly variable, an error occurs, and the command exits with a
2449 non-zero status.
2450
2451 If no command name results, redirections are performed, but do not
2452 affect the current shell environment. A redirection error causes the
2453 command to exit with a non-zero status.
2454
2455 If there is a command name left after expansion, execution proceeds
2456 as described below. Otherwise, the command exits. If one of the
2457 expansions contained a command substitution, the exit status of the
2458 command is the exit status of the last command substitution performed.
2459 If there were no command substitutions, the command exits with a status
2460 of zero.
2461
2462 \1f
2463 File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2464
2465 3.7.2 Command Search and Execution
2466 ----------------------------------
2467
2468 After a command has been split into words, if it results in a simple
2469 command and an optional list of arguments, the following actions are
2470 taken.
2471
2472 1. If the command name contains no slashes, the shell attempts to
2473 locate it. If there exists a shell function by that name, that
2474 function is invoked as described in *note Shell Functions::.
2475
2476 2. If the name does not match a function, the shell searches for it in
2477 the list of shell builtins. If a match is found, that builtin is
2478 invoked.
2479
2480 3. If the name is neither a shell function nor a builtin, and contains
2481 no slashes, Bash searches each element of '$PATH' for a directory
2482 containing an executable file by that name. Bash uses a hash table
2483 to remember the full pathnames of executable files to avoid
2484 multiple 'PATH' searches (see the description of 'hash' in *note
2485 Bourne Shell Builtins::). A full search of the directories in
2486 '$PATH' is performed only if the command is not found in the hash
2487 table. If the search is unsuccessful, the shell searches for a
2488 defined shell function named 'command_not_found_handle'. If that
2489 function exists, it is invoked with the original command and the
2490 original command's arguments as its arguments, and the function's
2491 exit status becomes the exit status of the shell. If that function
2492 is not defined, the shell prints an error message and returns an
2493 exit status of 127.
2494
2495 4. If the search is successful, or if the command name contains one or
2496 more slashes, the shell executes the named program in a separate
2497 execution environment. Argument 0 is set to the name given, and
2498 the remaining arguments to the command are set to the arguments
2499 supplied, if any.
2500
2501 5. If this execution fails because the file is not in executable
2502 format, and the file is not a directory, it is assumed to be a
2503 SHELL SCRIPT and the shell executes it as described in *note Shell
2504 Scripts::.
2505
2506 6. If the command was not begun asynchronously, the shell waits for
2507 the command to complete and collects its exit status.
2508
2509 \1f
2510 File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2511
2512 3.7.3 Command Execution Environment
2513 -----------------------------------
2514
2515 The shell has an EXECUTION ENVIRONMENT, which consists of the following:
2516
2517 * open files inherited by the shell at invocation, as modified by
2518 redirections supplied to the 'exec' builtin
2519
2520 * the current working directory as set by 'cd', 'pushd', or 'popd',
2521 or inherited by the shell at invocation
2522
2523 * the file creation mode mask as set by 'umask' or inherited from the
2524 shell's parent
2525
2526 * current traps set by 'trap'
2527
2528 * shell parameters that are set by variable assignment or with 'set'
2529 or inherited from the shell's parent in the environment
2530
2531 * shell functions defined during execution or inherited from the
2532 shell's parent in the environment
2533
2534 * options enabled at invocation (either by default or with
2535 command-line arguments) or by 'set'
2536
2537 * options enabled by 'shopt' (*note The Shopt Builtin::)
2538
2539 * shell aliases defined with 'alias' (*note Aliases::)
2540
2541 * various process IDs, including those of background jobs (*note
2542 Lists::), the value of '$$', and the value of '$PPID'
2543
2544 When a simple command other than a builtin or shell function is to be
2545 executed, it is invoked in a separate execution environment that
2546 consists of the following. Unless otherwise noted, the values are
2547 inherited from the shell.
2548
2549 * the shell's open files, plus any modifications and additions
2550 specified by redirections to the command
2551
2552 * the current working directory
2553
2554 * the file creation mode mask
2555
2556 * shell variables and functions marked for export, along with
2557 variables exported for the command, passed in the environment
2558 (*note Environment::)
2559
2560 * traps caught by the shell are reset to the values inherited from
2561 the shell's parent, and traps ignored by the shell are ignored
2562
2563 A command invoked in this separate environment cannot affect the
2564 shell's execution environment.
2565
2566 Command substitution, commands grouped with parentheses, and
2567 asynchronous commands are invoked in a subshell environment that is a
2568 duplicate of the shell environment, except that traps caught by the
2569 shell are reset to the values that the shell inherited from its parent
2570 at invocation. Builtin commands that are invoked as part of a pipeline
2571 are also executed in a subshell environment. Changes made to the
2572 subshell environment cannot affect the shell's execution environment.
2573
2574 Subshells spawned to execute command substitutions inherit the value
2575 of the '-e' option from the parent shell. When not in POSIX mode, Bash
2576 clears the '-e' option in such subshells.
2577
2578 If a command is followed by a '&' and job control is not active, the
2579 default standard input for the command is the empty file '/dev/null'.
2580 Otherwise, the invoked command inherits the file descriptors of the
2581 calling shell as modified by redirections.
2582
2583 \1f
2584 File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2585
2586 3.7.4 Environment
2587 -----------------
2588
2589 When a program is invoked it is given an array of strings called the
2590 ENVIRONMENT. This is a list of name-value pairs, of the form
2591 'name=value'.
2592
2593 Bash provides several ways to manipulate the environment. On
2594 invocation, the shell scans its own environment and creates a parameter
2595 for each name found, automatically marking it for EXPORT to child
2596 processes. Executed commands inherit the environment. The 'export' and
2597 'declare -x' commands allow parameters and functions to be added to and
2598 deleted from the environment. If the value of a parameter in the
2599 environment is modified, the new value becomes part of the environment,
2600 replacing the old. The environment inherited by any executed command
2601 consists of the shell's initial environment, whose values may be
2602 modified in the shell, less any pairs removed by the 'unset' and 'export
2603 -n' commands, plus any additions via the 'export' and 'declare -x'
2604 commands.
2605
2606 The environment for any simple command or function may be augmented
2607 temporarily by prefixing it with parameter assignments, as described in
2608 *note Shell Parameters::. These assignment statements affect only the
2609 environment seen by that command.
2610
2611 If the '-k' option is set (*note The Set Builtin::), then all
2612 parameter assignments are placed in the environment for a command, not
2613 just those that precede the command name.
2614
2615 When Bash invokes an external command, the variable '$_' is set to
2616 the full pathname of the command and passed to that command in its
2617 environment.
2618
2619 \1f
2620 File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2621
2622 3.7.5 Exit Status
2623 -----------------
2624
2625 The exit status of an executed command is the value returned by the
2626 WAITPID system call or equivalent function. Exit statuses fall between
2627 0 and 255, though, as explained below, the shell may use values above
2628 125 specially. Exit statuses from shell builtins and compound commands
2629 are also limited to this range. Under certain circumstances, the shell
2630 will use special values to indicate specific failure modes.
2631
2632 For the shell's purposes, a command which exits with a zero exit
2633 status has succeeded. A non-zero exit status indicates failure. This
2634 seemingly counter-intuitive scheme is used so there is one well-defined
2635 way to indicate success and a variety of ways to indicate various
2636 failure modes. When a command terminates on a fatal signal whose number
2637 is N, Bash uses the value 128+N as the exit status.
2638
2639 If a command is not found, the child process created to execute it
2640 returns a status of 127. If a command is found but is not executable,
2641 the return status is 126.
2642
2643 If a command fails because of an error during expansion or
2644 redirection, the exit status is greater than zero.
2645
2646 The exit status is used by the Bash conditional commands (*note
2647 Conditional Constructs::) and some of the list constructs (*note
2648 Lists::).
2649
2650 All of the Bash builtins return an exit status of zero if they
2651 succeed and a non-zero status on failure, so they may be used by the
2652 conditional and list constructs. All builtins return an exit status of
2653 2 to indicate incorrect usage, generally invalid options or missing
2654 arguments.
2655
2656 \1f
2657 File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2658
2659 3.7.6 Signals
2660 -------------
2661
2662 When Bash is interactive, in the absence of any traps, it ignores
2663 'SIGTERM' (so that 'kill 0' does not kill an interactive shell), and
2664 'SIGINT' is caught and handled (so that the 'wait' builtin is
2665 interruptible). When Bash receives a 'SIGINT', it breaks out of any
2666 executing loops. In all cases, Bash ignores 'SIGQUIT'. If job control
2667 is in effect (*note Job Control::), Bash ignores 'SIGTTIN', 'SIGTTOU',
2668 and 'SIGTSTP'.
2669
2670 Non-builtin commands started by Bash have signal handlers set to the
2671 values inherited by the shell from its parent. When job control is not
2672 in effect, asynchronous commands ignore 'SIGINT' and 'SIGQUIT' in
2673 addition to these inherited handlers. Commands run as a result of
2674 command substitution ignore the keyboard-generated job control signals
2675 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
2676
2677 The shell exits by default upon receipt of a 'SIGHUP'. Before
2678 exiting, an interactive shell resends the 'SIGHUP' to all jobs, running
2679 or stopped. Stopped jobs are sent 'SIGCONT' to ensure that they receive
2680 the 'SIGHUP'. To prevent the shell from sending the 'SIGHUP' signal to
2681 a particular job, it should be removed from the jobs table with the
2682 'disown' builtin (*note Job Control Builtins::) or marked to not receive
2683 'SIGHUP' using 'disown -h'.
2684
2685 If the 'huponexit' shell option has been set with 'shopt' (*note The
2686 Shopt Builtin::), Bash sends a 'SIGHUP' to all jobs when an interactive
2687 login shell exits.
2688
2689 If Bash is waiting for a command to complete and receives a signal
2690 for which a trap has been set, the trap will not be executed until the
2691 command completes. When Bash is waiting for an asynchronous command via
2692 the 'wait' builtin, the reception of a signal for which a trap has been
2693 set will cause the 'wait' builtin to return immediately with an exit
2694 status greater than 128, immediately after which the trap is executed.
2695
2696 \1f
2697 File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2698
2699 3.8 Shell Scripts
2700 =================
2701
2702 A shell script is a text file containing shell commands. When such a
2703 file is used as the first non-option argument when invoking Bash, and
2704 neither the '-c' nor '-s' option is supplied (*note Invoking Bash::),
2705 Bash reads and executes commands from the file, then exits. This mode
2706 of operation creates a non-interactive shell. The shell first searches
2707 for the file in the current directory, and looks in the directories in
2708 '$PATH' if not found there.
2709
2710 When Bash runs a shell script, it sets the special parameter '0' to
2711 the name of the file, rather than the name of the shell, and the
2712 positional parameters are set to the remaining arguments, if any are
2713 given. If no additional arguments are supplied, the positional
2714 parameters are unset.
2715
2716 A shell script may be made executable by using the 'chmod' command to
2717 turn on the execute bit. When Bash finds such a file while searching
2718 the '$PATH' for a command, it spawns a subshell to execute it. In other
2719 words, executing
2720 filename ARGUMENTS
2721 is equivalent to executing
2722 bash filename ARGUMENTS
2723
2724 if 'filename' is an executable shell script. This subshell
2725 reinitializes itself, so that the effect is as if a new shell had been
2726 invoked to interpret the script, with the exception that the locations
2727 of commands remembered by the parent (see the description of 'hash' in
2728 *note Bourne Shell Builtins::) are retained by the child.
2729
2730 Most versions of Unix make this a part of the operating system's
2731 command execution mechanism. If the first line of a script begins with
2732 the two characters '#!', the remainder of the line specifies an
2733 interpreter for the program. Thus, you can specify Bash, 'awk', Perl,
2734 or some other interpreter and write the rest of the script file in that
2735 language.
2736
2737 The arguments to the interpreter consist of a single optional
2738 argument following the interpreter name on the first line of the script
2739 file, followed by the name of the script file, followed by the rest of
2740 the arguments. Bash will perform this action on operating systems that
2741 do not handle it themselves. Note that some older versions of Unix
2742 limit the interpreter name and argument to a maximum of 32 characters.
2743
2744 Bash scripts often begin with '#! /bin/bash' (assuming that Bash has
2745 been installed in '/bin'), since this ensures that Bash will be used to
2746 interpret the script, even if it is executed under another shell.
2747
2748 \1f
2749 File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
2750
2751 4 Shell Builtin Commands
2752 ************************
2753
2754 * Menu:
2755
2756 * Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2757 Shell.
2758 * Bash Builtins:: Table of builtins specific to Bash.
2759 * Modifying Shell Behavior:: Builtins to modify shell attributes and
2760 optional behavior.
2761 * Special Builtins:: Builtin commands classified specially by
2762 POSIX.
2763
2764 Builtin commands are contained within the shell itself. When the name
2765 of a builtin command is used as the first word of a simple command
2766 (*note Simple Commands::), the shell executes the command directly,
2767 without invoking another program. Builtin commands are necessary to
2768 implement functionality impossible or inconvenient to obtain with
2769 separate utilities.
2770
2771 This section briefly describes the builtins which Bash inherits from
2772 the Bourne Shell, as well as the builtin commands which are unique to or
2773 have been extended in Bash.
2774
2775 Several builtin commands are described in other chapters: builtin
2776 commands which provide the Bash interface to the job control facilities
2777 (*note Job Control Builtins::), the directory stack (*note Directory
2778 Stack Builtins::), the command history (*note Bash History Builtins::),
2779 and the programmable completion facilities (*note Programmable
2780 Completion Builtins::).
2781
2782 Many of the builtins have been extended by POSIX or Bash.
2783
2784 Unless otherwise noted, each builtin command documented as accepting
2785 options preceded by '-' accepts '--' to signify the end of the options.
2786 The ':', 'true', 'false', and 'test' builtins do not accept options and
2787 do not treat '--' specially. The 'exit', 'logout', 'return', 'break',
2788 'continue', 'let', and 'shift' builtins accept and process arguments
2789 beginning with '-' without requiring '--'. Other builtins that accept
2790 arguments but are not specified as accepting options interpret arguments
2791 beginning with '-' as invalid options and require '--' to prevent this
2792 interpretation.
2793
2794 \1f
2795 File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
2796
2797 4.1 Bourne Shell Builtins
2798 =========================
2799
2800 The following shell builtin commands are inherited from the Bourne
2801 Shell. These commands are implemented as specified by the POSIX
2802 standard.
2803
2804 ': (a colon)'
2805 : [ARGUMENTS]
2806
2807 Do nothing beyond expanding ARGUMENTS and performing redirections.
2808 The return status is zero.
2809
2810 '. (a period)'
2811 . FILENAME [ARGUMENTS]
2812
2813 Read and execute commands from the FILENAME argument in the current
2814 shell context. If FILENAME does not contain a slash, the 'PATH'
2815 variable is used to find FILENAME. When Bash is not in POSIX mode,
2816 the current directory is searched if FILENAME is not found in
2817 '$PATH'. If any ARGUMENTS are supplied, they become the positional
2818 parameters when FILENAME is executed. Otherwise the positional
2819 parameters are unchanged. If the '-T' option is enabled, 'source'
2820 inherits any trap on 'DEBUG'; if it is not, any 'DEBUG' trap string
2821 is saved and restored around the call to 'source', and 'source'
2822 unsets the 'DEBUG' trap while it executes. If '-T' is not set, and
2823 the sourced file changes the 'DEBUG' trap, the new value is
2824 retained when 'source' completes. The return status is the exit
2825 status of the last command executed, or zero if no commands are
2826 executed. If FILENAME is not found, or cannot be read, the return
2827 status is non-zero. This builtin is equivalent to 'source'.
2828
2829 'break'
2830 break [N]
2831
2832 Exit from a 'for', 'while', 'until', or 'select' loop. If N is
2833 supplied, the Nth enclosing loop is exited. N must be greater than
2834 or equal to 1. The return status is zero unless N is not greater
2835 than or equal to 1.
2836
2837 'cd'
2838 cd [-L|[-P [-e]] [-@] [DIRECTORY]
2839
2840 Change the current working directory to DIRECTORY. If DIRECTORY is
2841 not supplied, the value of the 'HOME' shell variable is used. Any
2842 additional arguments following DIRECTORY are ignored. If the shell
2843 variable 'CDPATH' exists, it is used as a search path: each
2844 directory name in 'CDPATH' is searched for DIRECTORY, with
2845 alternative directory names in 'CDPATH' separated by a colon (':').
2846 If DIRECTORY begins with a slash, 'CDPATH' is not used.
2847
2848 The '-P' option means to not follow symbolic links: symbolic links
2849 are resolved while 'cd' is traversing DIRECTORY and before
2850 processing an instance of '..' in DIRECTORY.
2851
2852 By default, or when the '-L' option is supplied, symbolic links in
2853 DIRECTORY are resolved after 'cd' processes an instance of '..' in
2854 DIRECTORY.
2855
2856 If '..' appears in DIRECTORY, it is processed by removing the
2857 immediately preceding pathname component, back to a slash or the
2858 beginning of DIRECTORY.
2859
2860 If the '-e' option is supplied with '-P' and the current working
2861 directory cannot be successfully determined after a successful
2862 directory change, 'cd' will return an unsuccessful status.
2863
2864 On systems that support it, the '-@' option presents the extended
2865 attributes associated with a file as a directory.
2866
2867 If DIRECTORY is '-', it is converted to '$OLDPWD' before the
2868 directory change is attempted.
2869
2870 If a non-empty directory name from 'CDPATH' is used, or if '-' is
2871 the first argument, and the directory change is successful, the
2872 absolute pathname of the new working directory is written to the
2873 standard output.
2874
2875 The return status is zero if the directory is successfully changed,
2876 non-zero otherwise.
2877
2878 'continue'
2879 continue [N]
2880
2881 Resume the next iteration of an enclosing 'for', 'while', 'until',
2882 or 'select' loop. If N is supplied, the execution of the Nth
2883 enclosing loop is resumed. N must be greater than or equal to 1.
2884 The return status is zero unless N is not greater than or equal to
2885 1.
2886
2887 'eval'
2888 eval [ARGUMENTS]
2889
2890 The arguments are concatenated together into a single command,
2891 which is then read and executed, and its exit status returned as
2892 the exit status of 'eval'. If there are no arguments or only empty
2893 arguments, the return status is zero.
2894
2895 'exec'
2896 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2897
2898 If COMMAND is supplied, it replaces the shell without creating a
2899 new process. If the '-l' option is supplied, the shell places a
2900 dash at the beginning of the zeroth argument passed to COMMAND.
2901 This is what the 'login' program does. The '-c' option causes
2902 COMMAND to be executed with an empty environment. If '-a' is
2903 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2904 If COMMAND cannot be executed for some reason, a non-interactive
2905 shell exits, unless the 'execfail' shell option is enabled. In
2906 that case, it returns failure. An interactive shell returns
2907 failure if the file cannot be executed. If no COMMAND is
2908 specified, redirections may be used to affect the current shell
2909 environment. If there are no redirection errors, the return status
2910 is zero; otherwise the return status is non-zero.
2911
2912 'exit'
2913 exit [N]
2914
2915 Exit the shell, returning a status of N to the shell's parent. If
2916 N is omitted, the exit status is that of the last command executed.
2917 Any trap on 'EXIT' is executed before the shell terminates.
2918
2919 'export'
2920 export [-fn] [-p] [NAME[=VALUE]]
2921
2922 Mark each NAME to be passed to child processes in the environment.
2923 If the '-f' option is supplied, the NAMEs refer to shell functions;
2924 otherwise the names refer to shell variables. The '-n' option
2925 means to no longer mark each NAME for export. If no NAMES are
2926 supplied, or if the '-p' option is given, a list of names of all
2927 exported variables is displayed. The '-p' option displays output
2928 in a form that may be reused as input. If a variable name is
2929 followed by =VALUE, the value of the variable is set to VALUE.
2930
2931 The return status is zero unless an invalid option is supplied, one
2932 of the names is not a valid shell variable name, or '-f' is
2933 supplied with a name that is not a shell function.
2934
2935 'getopts'
2936 getopts OPTSTRING NAME [ARGS]
2937
2938 'getopts' is used by shell scripts to parse positional parameters.
2939 OPTSTRING contains the option characters to be recognized; if a
2940 character is followed by a colon, the option is expected to have an
2941 argument, which should be separated from it by whitespace. The
2942 colon (':') and question mark ('?') may not be used as option
2943 characters. Each time it is invoked, 'getopts' places the next
2944 option in the shell variable NAME, initializing NAME if it does not
2945 exist, and the index of the next argument to be processed into the
2946 variable 'OPTIND'. 'OPTIND' is initialized to 1 each time the
2947 shell or a shell script is invoked. When an option requires an
2948 argument, 'getopts' places that argument into the variable
2949 'OPTARG'. The shell does not reset 'OPTIND' automatically; it must
2950 be manually reset between multiple calls to 'getopts' within the
2951 same shell invocation if a new set of parameters is to be used.
2952
2953 When the end of options is encountered, 'getopts' exits with a
2954 return value greater than zero. 'OPTIND' is set to the index of
2955 the first non-option argument, and NAME is set to '?'.
2956
2957 'getopts' normally parses the positional parameters, but if more
2958 arguments are given in ARGS, 'getopts' parses those instead.
2959
2960 'getopts' can report errors in two ways. If the first character of
2961 OPTSTRING is a colon, SILENT error reporting is used. In normal
2962 operation, diagnostic messages are printed when invalid options or
2963 missing option arguments are encountered. If the variable 'OPTERR'
2964 is set to 0, no error messages will be displayed, even if the first
2965 character of 'optstring' is not a colon.
2966
2967 If an invalid option is seen, 'getopts' places '?' into NAME and,
2968 if not silent, prints an error message and unsets 'OPTARG'. If
2969 'getopts' is silent, the option character found is placed in
2970 'OPTARG' and no diagnostic message is printed.
2971
2972 If a required argument is not found, and 'getopts' is not silent, a
2973 question mark ('?') is placed in NAME, 'OPTARG' is unset, and a
2974 diagnostic message is printed. If 'getopts' is silent, then a
2975 colon (':') is placed in NAME and 'OPTARG' is set to the option
2976 character found.
2977
2978 'hash'
2979 hash [-r] [-p FILENAME] [-dt] [NAME]
2980
2981 Each time 'hash' is invoked, it remembers the full pathnames of the
2982 commands specified as NAME arguments, so they need not be searched
2983 for on subsequent invocations. The commands are found by searching
2984 through the directories listed in '$PATH'. Any
2985 previously-remembered pathname is discarded. The '-p' option
2986 inhibits the path search, and FILENAME is used as the location of
2987 NAME. The '-r' option causes the shell to forget all remembered
2988 locations. The '-d' option causes the shell to forget the
2989 remembered location of each NAME. If the '-t' option is supplied,
2990 the full pathname to which each NAME corresponds is printed. If
2991 multiple NAME arguments are supplied with '-t' the NAME is printed
2992 before the hashed full pathname. The '-l' option causes output to
2993 be displayed in a format that may be reused as input. If no
2994 arguments are given, or if only '-l' is supplied, information about
2995 remembered commands is printed. The return status is zero unless a
2996 NAME is not found or an invalid option is supplied.
2997
2998 'pwd'
2999 pwd [-LP]
3000
3001 Print the absolute pathname of the current working directory. If
3002 the '-P' option is supplied, the pathname printed will not contain
3003 symbolic links. If the '-L' option is supplied, the pathname
3004 printed may contain symbolic links. The return status is zero
3005 unless an error is encountered while determining the name of the
3006 current directory or an invalid option is supplied.
3007
3008 'readonly'
3009 readonly [-aAf] [-p] [NAME[=VALUE]] ...
3010
3011 Mark each NAME as readonly. The values of these names may not be
3012 changed by subsequent assignment. If the '-f' option is supplied,
3013 each NAME refers to a shell function. The '-a' option means each
3014 NAME refers to an indexed array variable; the '-A' option means
3015 each NAME refers to an associative array variable. If both options
3016 are supplied, '-A' takes precedence. If no NAME arguments are
3017 given, or if the '-p' option is supplied, a list of all readonly
3018 names is printed. The other options may be used to restrict the
3019 output to a subset of the set of readonly names. The '-p' option
3020 causes output to be displayed in a format that may be reused as
3021 input. If a variable name is followed by =VALUE, the value of the
3022 variable is set to VALUE. The return status is zero unless an
3023 invalid option is supplied, one of the NAME arguments is not a
3024 valid shell variable or function name, or the '-f' option is
3025 supplied with a name that is not a shell function.
3026
3027 'return'
3028 return [N]
3029
3030 Cause a shell function to stop executing and return the value N to
3031 its caller. If N is not supplied, the return value is the exit
3032 status of the last command executed in the function. If 'return'
3033 is executed by a trap handler, the last command used to determine
3034 the status is the last command executed before the trap handler.
3035 if 'return' is executed during a 'DEBUG' trap, the last command
3036 used to determine the status is the last command executed by the
3037 trap handler before 'return' was invoked. 'return' may also be
3038 used to terminate execution of a script being executed with the '.'
3039 ('source') builtin, returning either N or the exit status of the
3040 last command executed within the script as the exit status of the
3041 script. If N is supplied, the return value is its least
3042 significant 8 bits. Any command associated with the 'RETURN' trap
3043 is executed before execution resumes after the function or script.
3044 The return status is non-zero if 'return' is supplied a non-numeric
3045 argument or is used outside a function and not during the execution
3046 of a script by '.' or 'source'.
3047
3048 'shift'
3049 shift [N]
3050
3051 Shift the positional parameters to the left by N. The positional
3052 parameters from N+1 ... '$#' are renamed to '$1' ... '$#'-N.
3053 Parameters represented by the numbers '$#' to '$#'-N+1 are unset.
3054 N must be a non-negative number less than or equal to '$#'. If N
3055 is zero or greater than '$#', the positional parameters are not
3056 changed. If N is not supplied, it is assumed to be 1. The return
3057 status is zero unless N is greater than '$#' or less than zero,
3058 non-zero otherwise.
3059
3060 'test'
3061 '['
3062 test EXPR
3063
3064 Evaluate a conditional expression EXPR and return a status of 0
3065 (true) or 1 (false). Each operator and operand must be a separate
3066 argument. Expressions are composed of the primaries described
3067 below in *note Bash Conditional Expressions::. 'test' does not
3068 accept any options, nor does it accept and ignore an argument of
3069 '--' as signifying the end of options.
3070
3071 When the '[' form is used, the last argument to the command must be
3072 a ']'.
3073
3074 Expressions may be combined using the following operators, listed
3075 in decreasing order of precedence. The evaluation depends on the
3076 number of arguments; see below. Operator precedence is used when
3077 there are five or more arguments.
3078
3079 '! EXPR'
3080 True if EXPR is false.
3081
3082 '( EXPR )'
3083 Returns the value of EXPR. This may be used to override the
3084 normal precedence of operators.
3085
3086 'EXPR1 -a EXPR2'
3087 True if both EXPR1 and EXPR2 are true.
3088
3089 'EXPR1 -o EXPR2'
3090 True if either EXPR1 or EXPR2 is true.
3091
3092 The 'test' and '[' builtins evaluate conditional expressions using
3093 a set of rules based on the number of arguments.
3094
3095 0 arguments
3096 The expression is false.
3097
3098 1 argument
3099 The expression is true if and only if the argument is not
3100 null.
3101
3102 2 arguments
3103 If the first argument is '!', the expression is true if and
3104 only if the second argument is null. If the first argument is
3105 one of the unary conditional operators (*note Bash Conditional
3106 Expressions::), the expression is true if the unary test is
3107 true. If the first argument is not a valid unary operator,
3108 the expression is false.
3109
3110 3 arguments
3111 The following conditions are applied in the order listed. If
3112 the second argument is one of the binary conditional operators
3113 (*note Bash Conditional Expressions::), the result of the
3114 expression is the result of the binary test using the first
3115 and third arguments as operands. The '-a' and '-o' operators
3116 are considered binary operators when there are three
3117 arguments. If the first argument is '!', the value is the
3118 negation of the two-argument test using the second and third
3119 arguments. If the first argument is exactly '(' and the third
3120 argument is exactly ')', the result is the one-argument test
3121 of the second argument. Otherwise, the expression is false.
3122
3123 4 arguments
3124 If the first argument is '!', the result is the negation of
3125 the three-argument expression composed of the remaining
3126 arguments. Otherwise, the expression is parsed and evaluated
3127 according to precedence using the rules listed above.
3128
3129 5 or more arguments
3130 The expression is parsed and evaluated according to precedence
3131 using the rules listed above.
3132
3133 When used with 'test' or '[', the '<' and '>' operators sort
3134 lexicographically using ASCII ordering.
3135
3136 'times'
3137 times
3138
3139 Print out the user and system times used by the shell and its
3140 children. The return status is zero.
3141
3142 'trap'
3143 trap [-lp] [ARG] [SIGSPEC ...]
3144
3145 The commands in ARG are to be read and executed when the shell
3146 receives signal SIGSPEC. If ARG is absent (and there is a single
3147 SIGSPEC) or equal to '-', each specified signal's disposition is
3148 reset to the value it had when the shell was started. If ARG is
3149 the null string, then the signal specified by each SIGSPEC is
3150 ignored by the shell and commands it invokes. If ARG is not
3151 present and '-p' has been supplied, the shell displays the trap
3152 commands associated with each SIGSPEC. If no arguments are
3153 supplied, or only '-p' is given, 'trap' prints the list of commands
3154 associated with each signal number in a form that may be reused as
3155 shell input. The '-l' option causes the shell to print a list of
3156 signal names and their corresponding numbers. Each SIGSPEC is
3157 either a signal name or a signal number. Signal names are case
3158 insensitive and the 'SIG' prefix is optional.
3159
3160 If a SIGSPEC is '0' or 'EXIT', ARG is executed when the shell
3161 exits. If a SIGSPEC is 'DEBUG', the command ARG is executed before
3162 every simple command, 'for' command, 'case' command, 'select'
3163 command, every arithmetic 'for' command, and before the first
3164 command executes in a shell function. Refer to the description of
3165 the 'extdebug' option to the 'shopt' builtin (*note The Shopt
3166 Builtin::) for details of its effect on the 'DEBUG' trap. If a
3167 SIGSPEC is 'RETURN', the command ARG is executed each time a shell
3168 function or a script executed with the '.' or 'source' builtins
3169 finishes executing.
3170
3171 If a SIGSPEC is 'ERR', the command ARG is executed whenever a
3172 pipeline (which may consist of a single simple command), a list, or
3173 a compound command returns a non-zero exit status, subject to the
3174 following conditions. The 'ERR' trap is not executed if the failed
3175 command is part of the command list immediately following an
3176 'until' or 'while' keyword, part of the test following the 'if' or
3177 'elif' reserved words, part of a command executed in a '&&' or '||'
3178 list except the command following the final '&&' or '||', any
3179 command in a pipeline but the last, or if the command's return
3180 status is being inverted using '!'. These are the same conditions
3181 obeyed by the 'errexit' ('-e') option.
3182
3183 Signals ignored upon entry to the shell cannot be trapped or reset.
3184 Trapped signals that are not being ignored are reset to their
3185 original values in a subshell or subshell environment when one is
3186 created.
3187
3188 The return status is zero unless a SIGSPEC does not specify a valid
3189 signal.
3190
3191 'umask'
3192 umask [-p] [-S] [MODE]
3193
3194 Set the shell process's file creation mask to MODE. If MODE begins
3195 with a digit, it is interpreted as an octal number; if not, it is
3196 interpreted as a symbolic mode mask similar to that accepted by the
3197 'chmod' command. If MODE is omitted, the current value of the mask
3198 is printed. If the '-S' option is supplied without a MODE
3199 argument, the mask is printed in a symbolic format. If the '-p'
3200 option is supplied, and MODE is omitted, the output is in a form
3201 that may be reused as input. The return status is zero if the mode
3202 is successfully changed or if no MODE argument is supplied, and
3203 non-zero otherwise.
3204
3205 Note that when the mode is interpreted as an octal number, each
3206 number of the umask is subtracted from '7'. Thus, a umask of '022'
3207 results in permissions of '755'.
3208
3209 'unset'
3210 unset [-fnv] [NAME]
3211
3212 Remove each variable or function NAME. If the '-v' option is
3213 given, each NAME refers to a shell variable and that variable is
3214 removed. If the '-f' option is given, the NAMEs refer to shell
3215 functions, and the function definition is removed. If the '-n'
3216 option is supplied, and NAME is a variable with the NAMEREF
3217 attribute, NAME will be unset rather than the variable it
3218 references. '-n' has no effect if the '-f' option is supplied. If
3219 no options are supplied, each NAME refers to a variable; if there
3220 is no variable by that name, any function with that name is unset.
3221 Readonly variables and functions may not be unset. The return
3222 status is zero unless a NAME is readonly.
3223
3224 \1f
3225 File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
3226
3227 4.2 Bash Builtin Commands
3228 =========================
3229
3230 This section describes builtin commands which are unique to or have been
3231 extended in Bash. Some of these commands are specified in the POSIX
3232 standard.
3233
3234 'alias'
3235 alias [-p] [NAME[=VALUE] ...]
3236
3237 Without arguments or with the '-p' option, 'alias' prints the list
3238 of aliases on the standard output in a form that allows them to be
3239 reused as input. If arguments are supplied, an alias is defined
3240 for each NAME whose VALUE is given. If no VALUE is given, the name
3241 and value of the alias is printed. Aliases are described in *note
3242 Aliases::.
3243
3244 'bind'
3245 bind [-m KEYMAP] [-lpsvPSVX]
3246 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
3247 bind [-m KEYMAP] -f FILENAME
3248 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
3249 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
3250 bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND
3251
3252 Display current Readline (*note Command Line Editing::) key and
3253 function bindings, bind a key sequence to a Readline function or
3254 macro, or set a Readline variable. Each non-option argument is a
3255 command as it would appear in a Readline initialization file (*note
3256 Readline Init File::), but each binding or command must be passed
3257 as a separate argument; e.g., '"\C-x\C-r":re-read-init-file'.
3258
3259 Options, if supplied, have the following meanings:
3260
3261 '-m KEYMAP'
3262 Use KEYMAP as the keymap to be affected by the subsequent
3263 bindings. Acceptable KEYMAP names are 'emacs',
3264 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
3265 'vi-command', and 'vi-insert'. 'vi' is equivalent to
3266 'vi-command' ('vi-move' is also a synonym); 'emacs' is
3267 equivalent to 'emacs-standard'.
3268
3269 '-l'
3270 List the names of all Readline functions.
3271
3272 '-p'
3273 Display Readline function names and bindings in such a way
3274 that they can be used as input or in a Readline initialization
3275 file.
3276
3277 '-P'
3278 List current Readline function names and bindings.
3279
3280 '-v'
3281 Display Readline variable names and values in such a way that
3282 they can be used as input or in a Readline initialization
3283 file.
3284
3285 '-V'
3286 List current Readline variable names and values.
3287
3288 '-s'
3289 Display Readline key sequences bound to macros and the strings
3290 they output in such a way that they can be used as input or in
3291 a Readline initialization file.
3292
3293 '-S'
3294 Display Readline key sequences bound to macros and the strings
3295 they output.
3296
3297 '-f FILENAME'
3298 Read key bindings from FILENAME.
3299
3300 '-q FUNCTION'
3301 Query about which keys invoke the named FUNCTION.
3302
3303 '-u FUNCTION'
3304 Unbind all keys bound to the named FUNCTION.
3305
3306 '-r KEYSEQ'
3307 Remove any current binding for KEYSEQ.
3308
3309 '-x KEYSEQ:SHELL-COMMAND'
3310 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
3311 When SHELL-COMMAND is executed, the shell sets the
3312 'READLINE_LINE' variable to the contents of the Readline line
3313 buffer and the 'READLINE_POINT' variable to the current
3314 location of the insertion point. If the executed command
3315 changes the value of 'READLINE_LINE' or 'READLINE_POINT',
3316 those new values will be reflected in the editing state.
3317
3318 '-X'
3319 List all key sequences bound to shell commands and the
3320 associated commands in a format that can be reused as input.
3321
3322 The return status is zero unless an invalid option is supplied or
3323 an error occurs.
3324
3325 'builtin'
3326 builtin [SHELL-BUILTIN [ARGS]]
3327
3328 Run a shell builtin, passing it ARGS, and return its exit status.
3329 This is useful when defining a shell function with the same name as
3330 a shell builtin, retaining the functionality of the builtin within
3331 the function. The return status is non-zero if SHELL-BUILTIN is
3332 not a shell builtin command.
3333
3334 'caller'
3335 caller [EXPR]
3336
3337 Returns the context of any active subroutine call (a shell function
3338 or a script executed with the '.' or 'source' builtins).
3339
3340 Without EXPR, 'caller' displays the line number and source filename
3341 of the current subroutine call. If a non-negative integer is
3342 supplied as EXPR, 'caller' displays the line number, subroutine
3343 name, and source file corresponding to that position in the current
3344 execution call stack. This extra information may be used, for
3345 example, to print a stack trace. The current frame is frame 0.
3346
3347 The return value is 0 unless the shell is not executing a
3348 subroutine call or EXPR does not correspond to a valid position in
3349 the call stack.
3350
3351 'command'
3352 command [-pVv] COMMAND [ARGUMENTS ...]
3353
3354 Runs COMMAND with ARGUMENTS ignoring any shell function named
3355 COMMAND. Only shell builtin commands or commands found by
3356 searching the 'PATH' are executed. If there is a shell function
3357 named 'ls', running 'command ls' within the function will execute
3358 the external command 'ls' instead of calling the function
3359 recursively. The '-p' option means to use a default value for
3360 'PATH' that is guaranteed to find all of the standard utilities.
3361 The return status in this case is 127 if COMMAND cannot be found or
3362 an error occurred, and the exit status of COMMAND otherwise.
3363
3364 If either the '-V' or '-v' option is supplied, a description of
3365 COMMAND is printed. The '-v' option causes a single word
3366 indicating the command or file name used to invoke COMMAND to be
3367 displayed; the '-V' option produces a more verbose description. In
3368 this case, the return status is zero if COMMAND is found, and
3369 non-zero if not.
3370
3371 'declare'
3372 declare [-aAfFgilnrtux] [-p] [NAME[=VALUE] ...]
3373
3374 Declare variables and give them attributes. If no NAMEs are given,
3375 then display the values of variables instead.
3376
3377 The '-p' option will display the attributes and values of each
3378 NAME. When '-p' is used with NAME arguments, additional options,
3379 other than '-f' and '-F', are ignored.
3380
3381 When '-p' is supplied without NAME arguments, 'declare' will
3382 display the attributes and values of all variables having the
3383 attributes specified by the additional options. If no other
3384 options are supplied with '-p', 'declare' will display the
3385 attributes and values of all shell variables. The '-f' option will
3386 restrict the display to shell functions.
3387
3388 The '-F' option inhibits the display of function definitions; only
3389 the function name and attributes are printed. If the 'extdebug'
3390 shell option is enabled using 'shopt' (*note The Shopt Builtin::),
3391 the source file name and line number where each NAME is defined are
3392 displayed as well. '-F' implies '-f'.
3393
3394 The '-g' option forces variables to be created or modified at the
3395 global scope, even when 'declare' is executed in a shell function.
3396 It is ignored in all other cases.
3397
3398 The following options can be used to restrict output to variables
3399 with the specified attributes or to give variables attributes:
3400
3401 '-a'
3402 Each NAME is an indexed array variable (*note Arrays::).
3403
3404 '-A'
3405 Each NAME is an associative array variable (*note Arrays::).
3406
3407 '-f'
3408 Use function names only.
3409
3410 '-i'
3411 The variable is to be treated as an integer; arithmetic
3412 evaluation (*note Shell Arithmetic::) is performed when the
3413 variable is assigned a value.
3414
3415 '-l'
3416 When the variable is assigned a value, all upper-case
3417 characters are converted to lower-case. The upper-case
3418 attribute is disabled.
3419
3420 '-n'
3421 Give each NAME the NAMEREF attribute, making it a name
3422 reference to another variable. That other variable is defined
3423 by the value of NAME. All references, assignments, and
3424 attribute modifications to NAME, except for those using or
3425 changing the '-n' attribute itself, are performed on the
3426 variable referenced by NAME's value. The nameref attribute
3427 cannot be applied to array variables.
3428
3429 '-r'
3430 Make NAMEs readonly. These names cannot then be assigned
3431 values by subsequent assignment statements or unset.
3432
3433 '-t'
3434 Give each NAME the 'trace' attribute. Traced functions
3435 inherit the 'DEBUG' and 'RETURN' traps from the calling shell.
3436 The trace attribute has no special meaning for variables.
3437
3438 '-u'
3439 When the variable is assigned a value, all lower-case
3440 characters are converted to upper-case. The lower-case
3441 attribute is disabled.
3442
3443 '-x'
3444 Mark each NAME for export to subsequent commands via the
3445 environment.
3446
3447 Using '+' instead of '-' turns off the attribute instead, with the
3448 exceptions that '+a' may not be used to destroy an array variable
3449 and '+r' will not remove the readonly attribute. When used in a
3450 function, 'declare' makes each NAME local, as with the 'local'
3451 command, unless the '-g' option is used. If a variable name is
3452 followed by =VALUE, the value of the variable is set to VALUE.
3453
3454 When using '-a' or '-A' and the compound assignment syntax to
3455 create array variables, additional attributes do not take effect
3456 until subsequent assignments.
3457
3458 The return status is zero unless an invalid option is encountered,
3459 an attempt is made to define a function using '-f foo=bar', an
3460 attempt is made to assign a value to a readonly variable, an
3461 attempt is made to assign a value to an array variable without
3462 using the compound assignment syntax (*note Arrays::), one of the
3463 NAMES is not a valid shell variable name, an attempt is made to
3464 turn off readonly status for a readonly variable, an attempt is
3465 made to turn off array status for an array variable, or an attempt
3466 is made to display a non-existent function with '-f'.
3467
3468 'echo'
3469 echo [-neE] [ARG ...]
3470
3471 Output the ARGs, separated by spaces, terminated with a newline.
3472 The return status is 0 unless a write error occurs. If '-n' is
3473 specified, the trailing newline is suppressed. If the '-e' option
3474 is given, interpretation of the following backslash-escaped
3475 characters is enabled. The '-E' option disables the interpretation
3476 of these escape characters, even on systems where they are
3477 interpreted by default. The 'xpg_echo' shell option may be used to
3478 dynamically determine whether or not 'echo' expands these escape
3479 characters by default. 'echo' does not interpret '--' to mean the
3480 end of options.
3481
3482 'echo' interprets the following escape sequences:
3483 '\a'
3484 alert (bell)
3485 '\b'
3486 backspace
3487 '\c'
3488 suppress further output
3489 '\e'
3490 '\E'
3491 escape
3492 '\f'
3493 form feed
3494 '\n'
3495 new line
3496 '\r'
3497 carriage return
3498 '\t'
3499 horizontal tab
3500 '\v'
3501 vertical tab
3502 '\\'
3503 backslash
3504 '\0NNN'
3505 the eight-bit character whose value is the octal value NNN
3506 (zero to three octal digits)
3507 '\xHH'
3508 the eight-bit character whose value is the hexadecimal value
3509 HH (one or two hex digits)
3510 '\uHHHH'
3511 the Unicode (ISO/IEC 10646) character whose value is the
3512 hexadecimal value HHHH (one to four hex digits)
3513 '\UHHHHHHHH'
3514 the Unicode (ISO/IEC 10646) character whose value is the
3515 hexadecimal value HHHHHHHH (one to eight hex digits)
3516
3517 'enable'
3518 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3519
3520 Enable and disable builtin shell commands. Disabling a builtin
3521 allows a disk command which has the same name as a shell builtin to
3522 be executed without specifying a full pathname, even though the
3523 shell normally searches for builtins before disk commands. If '-n'
3524 is used, the NAMEs become disabled. Otherwise NAMEs are enabled.
3525 For example, to use the 'test' binary found via '$PATH' instead of
3526 the shell builtin version, type 'enable -n test'.
3527
3528 If the '-p' option is supplied, or no NAME arguments appear, a list
3529 of shell builtins is printed. With no other arguments, the list
3530 consists of all enabled shell builtins. The '-a' option means to
3531 list each builtin with an indication of whether or not it is
3532 enabled.
3533
3534 The '-f' option means to load the new builtin command NAME from
3535 shared object FILENAME, on systems that support dynamic loading.
3536 The '-d' option will delete a builtin loaded with '-f'.
3537
3538 If there are no options, a list of the shell builtins is displayed.
3539 The '-s' option restricts 'enable' to the POSIX special builtins.
3540 If '-s' is used with '-f', the new builtin becomes a special
3541 builtin (*note Special Builtins::).
3542
3543 The return status is zero unless a NAME is not a shell builtin or
3544 there is an error loading a new builtin from a shared object.
3545
3546 'help'
3547 help [-dms] [PATTERN]
3548
3549 Display helpful information about builtin commands. If PATTERN is
3550 specified, 'help' gives detailed help on all commands matching
3551 PATTERN, otherwise a list of the builtins is printed.
3552
3553 Options, if supplied, have the following meanings:
3554
3555 '-d'
3556 Display a short description of each PATTERN
3557 '-m'
3558 Display the description of each PATTERN in a manpage-like
3559 format
3560 '-s'
3561 Display only a short usage synopsis for each PATTERN
3562
3563 The return status is zero unless no command matches PATTERN.
3564
3565 'let'
3566 let EXPRESSION [EXPRESSION ...]
3567
3568 The 'let' builtin allows arithmetic to be performed on shell
3569 variables. Each EXPRESSION is evaluated according to the rules
3570 given below in *note Shell Arithmetic::. If the last EXPRESSION
3571 evaluates to 0, 'let' returns 1; otherwise 0 is returned.
3572
3573 'local'
3574 local [OPTION] NAME[=VALUE] ...
3575
3576 For each argument, a local variable named NAME is created, and
3577 assigned VALUE. The OPTION can be any of the options accepted by
3578 'declare'. 'local' can only be used within a function; it makes
3579 the variable NAME have a visible scope restricted to that function
3580 and its children. If NAME is '-', the set of shell options is made
3581 local to the function in which 'local' is invoked: shell options
3582 changed using the 'set' builtin inside the function are restored to
3583 their original values when the function returns. The return status
3584 is zero unless 'local' is used outside a function, an invalid NAME
3585 is supplied, or NAME is a readonly variable.
3586
3587 'logout'
3588 logout [N]
3589
3590 Exit a login shell, returning a status of N to the shell's parent.
3591
3592 'mapfile'
3593 mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
3594 [-C CALLBACK] [-c QUANTUM] [ARRAY]
3595
3596 Read lines from the standard input into the indexed array variable
3597 ARRAY, or from file descriptor FD if the '-u' option is supplied.
3598 The variable 'MAPFILE' is the default ARRAY. Options, if supplied,
3599 have the following meanings:
3600
3601 '-d'
3602 The first character of DELIM is used to terminate each input
3603 line, rather than newline.
3604 '-n'
3605 Copy at most COUNT lines. If COUNT is 0, all lines are
3606 copied.
3607 '-O'
3608 Begin assigning to ARRAY at index ORIGIN. The default index
3609 is 0.
3610 '-s'
3611 Discard the first COUNT lines read.
3612 '-t'
3613 Remove a trailing DELIM (default newline) from each line read.
3614 '-u'
3615 Read lines from file descriptor FD instead of the standard
3616 input.
3617 '-C'
3618 Evaluate CALLBACK each time QUANTUMP lines are read. The '-c'
3619 option specifies QUANTUM.
3620 '-c'
3621 Specify the number of lines read between each call to
3622 CALLBACK.
3623
3624 If '-C' is specified without '-c', the default quantum is 5000.
3625 When CALLBACK is evaluated, it is supplied the index of the next
3626 array element to be assigned and the line to be assigned to that
3627 element as additional arguments. CALLBACK is evaluated after the
3628 line is read but before the array element is assigned.
3629
3630 If not supplied with an explicit origin, 'mapfile' will clear ARRAY
3631 before assigning to it.
3632
3633 'mapfile' returns successfully unless an invalid option or option
3634 argument is supplied, ARRAY is invalid or unassignable, or ARRAY is
3635 not an indexed array.
3636
3637 'printf'
3638 printf [-v VAR] FORMAT [ARGUMENTS]
3639
3640 Write the formatted ARGUMENTS to the standard output under the
3641 control of the FORMAT. The '-v' option causes the output to be
3642 assigned to the variable VAR rather than being printed to the
3643 standard output.
3644
3645 The FORMAT is a character string which contains three types of
3646 objects: plain characters, which are simply copied to standard
3647 output, character escape sequences, which are converted and copied
3648 to the standard output, and format specifications, each of which
3649 causes printing of the next successive ARGUMENT. In addition to
3650 the standard 'printf(1)' formats, 'printf' interprets the following
3651 extensions:
3652
3653 '%b'
3654 Causes 'printf' to expand backslash escape sequences in the
3655 corresponding ARGUMENT in the same way as 'echo -e' (*note
3656 Bash Builtins::).
3657 '%q'
3658 Causes 'printf' to output the corresponding ARGUMENT in a
3659 format that can be reused as shell input.
3660 '%(DATEFMT)T'
3661 Causes 'printf' to output the date-time string resulting from
3662 using DATEFMT as a format string for 'strftime'(3). The
3663 corresponding ARGUMENT is an integer representing the number
3664 of seconds since the epoch. Two special argument values may
3665 be used: -1 represents the current time, and -2 represents the
3666 time the shell was invoked. If no argument is specified,
3667 conversion behaves as if -1 had been given. This is an
3668 exception to the usual 'printf' behavior.
3669
3670 Arguments to non-string format specifiers are treated as C language
3671 constants, except that a leading plus or minus sign is allowed, and
3672 if the leading character is a single or double quote, the value is
3673 the ASCII value of the following character.
3674
3675 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3676 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3677 format specifications behave as if a zero value or null string, as
3678 appropriate, had been supplied. The return value is zero on
3679 success, non-zero on failure.
3680
3681 'read'
3682 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
3683 [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3684
3685 One line is read from the standard input, or from the file
3686 descriptor FD supplied as an argument to the '-u' option, split
3687 into words as described above in *note Word Splitting::, and the
3688 first word is assigned to the first NAME, the second word to the
3689 second NAME, and so on. If there are more words than names, the
3690 remaining words and their intervening delimiters are assigned to
3691 the last NAME. If there are fewer words read from the input stream
3692 than names, the remaining names are assigned empty values. The
3693 characters in the value of the 'IFS' variable are used to split the
3694 line into words using the same rules the shell uses for expansion
3695 (described above in *note Word Splitting::). The backslash
3696 character '\' may be used to remove any special meaning for the
3697 next character read and for line continuation. If no names are
3698 supplied, the line read is assigned to the variable 'REPLY'. The
3699 exit status is zero, unless end-of-file is encountered, 'read'
3700 times out (in which case the status is greater than 128), a
3701 variable assignment error (such as assigning to a readonly
3702 variable) occurs, or an invalid file descriptor is supplied as the
3703 argument to '-u'.
3704
3705 Options, if supplied, have the following meanings:
3706
3707 '-a ANAME'
3708 The words are assigned to sequential indices of the array
3709 variable ANAME, starting at 0. All elements are removed from
3710 ANAME before the assignment. Other NAME arguments are
3711 ignored.
3712
3713 '-d DELIM'
3714 The first character of DELIM is used to terminate the input
3715 line, rather than newline.
3716
3717 '-e'
3718 Readline (*note Command Line Editing::) is used to obtain the
3719 line. Readline uses the current (or default, if line editing
3720 was not previously active) editing settings.
3721
3722 '-i TEXT'
3723 If Readline is being used to read the line, TEXT is placed
3724 into the editing buffer before editing begins.
3725
3726 '-n NCHARS'
3727 'read' returns after reading NCHARS characters rather than
3728 waiting for a complete line of input, but honors a delimiter
3729 if fewer than NCHARS characters are read before the delimiter.
3730
3731 '-N NCHARS'
3732 'read' returns after reading exactly NCHARS characters rather
3733 than waiting for a complete line of input, unless EOF is
3734 encountered or 'read' times out. Delimiter characters
3735 encountered in the input are not treated specially and do not
3736 cause 'read' to return until NCHARS characters are read. The
3737 result is not split on the characters in 'IFS'; the intent is
3738 that the variable is assigned exactly the characters read
3739 (with the exception of backslash; see the '-r' option below).
3740
3741 '-p PROMPT'
3742 Display PROMPT, without a trailing newline, before attempting
3743 to read any input. The prompt is displayed only if input is
3744 coming from a terminal.
3745
3746 '-r'
3747 If this option is given, backslash does not act as an escape
3748 character. The backslash is considered to be part of the
3749 line. In particular, a backslash-newline pair may not be used
3750 as a line continuation.
3751
3752 '-s'
3753 Silent mode. If input is coming from a terminal, characters
3754 are not echoed.
3755
3756 '-t TIMEOUT'
3757 Cause 'read' to time out and return failure if a complete line
3758 of input (or a specified number of characters) is not read
3759 within TIMEOUT seconds. TIMEOUT may be a decimal number with
3760 a fractional portion following the decimal point. This option
3761 is only effective if 'read' is reading input from a terminal,
3762 pipe, or other special file; it has no effect when reading
3763 from regular files. If 'read' times out, 'read' saves any
3764 partial input read into the specified variable NAME. If
3765 TIMEOUT is 0, 'read' returns immediately, without trying to
3766 read and data. The exit status is 0 if input is available on
3767 the specified file descriptor, non-zero otherwise. The exit
3768 status is greater than 128 if the timeout is exceeded.
3769
3770 '-u FD'
3771 Read input from file descriptor FD.
3772
3773 'readarray'
3774 readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT] [-t] [-u FD]
3775 [-C CALLBACK] [-c QUANTUM] [ARRAY]
3776
3777 Read lines from the standard input into the indexed array variable
3778 ARRAY, or from file descriptor FD if the '-u' option is supplied.
3779
3780 A synonym for 'mapfile'.
3781
3782 'source'
3783 source FILENAME
3784
3785 A synonym for '.' (*note Bourne Shell Builtins::).
3786
3787 'type'
3788 type [-afptP] [NAME ...]
3789
3790 For each NAME, indicate how it would be interpreted if used as a
3791 command name.
3792
3793 If the '-t' option is used, 'type' prints a single word which is
3794 one of 'alias', 'function', 'builtin', 'file' or 'keyword', if NAME
3795 is an alias, shell function, shell builtin, disk file, or shell
3796 reserved word, respectively. If the NAME is not found, then
3797 nothing is printed, and 'type' returns a failure status.
3798
3799 If the '-p' option is used, 'type' either returns the name of the
3800 disk file that would be executed, or nothing if '-t' would not
3801 return 'file'.
3802
3803 The '-P' option forces a path search for each NAME, even if '-t'
3804 would not return 'file'.
3805
3806 If a command is hashed, '-p' and '-P' print the hashed value, which
3807 is not necessarily the file that appears first in '$PATH'.
3808
3809 If the '-a' option is used, 'type' returns all of the places that
3810 contain an executable named FILE. This includes aliases and
3811 functions, if and only if the '-p' option is not also used.
3812
3813 If the '-f' option is used, 'type' does not attempt to find shell
3814 functions, as with the 'command' builtin.
3815
3816 The return status is zero if all of the NAMES are found, non-zero
3817 if any are not found.
3818
3819 'typeset'
3820 typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...]
3821
3822 The 'typeset' command is supplied for compatibility with the Korn
3823 shell. It is a synonym for the 'declare' builtin command.
3824
3825 'ulimit'
3826 ulimit [-HSabcdefiklmnpqrstuvxPT] [LIMIT]
3827
3828 'ulimit' provides control over the resources available to processes
3829 started by the shell, on systems that allow such control. If an
3830 option is given, it is interpreted as follows:
3831
3832 '-S'
3833 Change and report the soft limit associated with a resource.
3834
3835 '-H'
3836 Change and report the hard limit associated with a resource.
3837
3838 '-a'
3839 All current limits are reported.
3840
3841 '-b'
3842 The maximum socket buffer size.
3843
3844 '-c'
3845 The maximum size of core files created.
3846
3847 '-d'
3848 The maximum size of a process's data segment.
3849
3850 '-e'
3851 The maximum scheduling priority ("nice").
3852
3853 '-f'
3854 The maximum size of files written by the shell and its
3855 children.
3856
3857 '-i'
3858 The maximum number of pending signals.
3859
3860 '-k'
3861 The maximum number of kqueues that may be allocated.
3862
3863 '-l'
3864 The maximum size that may be locked into memory.
3865
3866 '-m'
3867 The maximum resident set size (many systems do not honor this
3868 limit).
3869
3870 '-n'
3871 The maximum number of open file descriptors (most systems do
3872 not allow this value to be set).
3873
3874 '-p'
3875 The pipe buffer size.
3876
3877 '-q'
3878 The maximum number of bytes in POSIX message queues.
3879
3880 '-r'
3881 The maximum real-time scheduling priority.
3882
3883 '-s'
3884 The maximum stack size.
3885
3886 '-t'
3887 The maximum amount of cpu time in seconds.
3888
3889 '-u'
3890 The maximum number of processes available to a single user.
3891
3892 '-v'
3893 The maximum amount of virtual memory available to the shell,
3894 and, on some systems, to its children.
3895
3896 '-x'
3897 The maximum number of file locks.
3898
3899 '-P'
3900 The maximum number of pseudoterminals.
3901
3902 '-T'
3903 The maximum number of threads.
3904
3905 If LIMIT is given, and the '-a' option is not used, LIMIT is the
3906 new value of the specified resource. The special LIMIT values
3907 'hard', 'soft', and 'unlimited' stand for the current hard limit,
3908 the current soft limit, and no limit, respectively. A hard limit
3909 cannot be increased by a non-root user once it is set; a soft limit
3910 may be increased up to the value of the hard limit. Otherwise, the
3911 current value of the soft limit for the specified resource is
3912 printed, unless the '-H' option is supplied. When setting new
3913 limits, if neither '-H' nor '-S' is supplied, both the hard and
3914 soft limits are set. If no option is given, then '-f' is assumed.
3915 Values are in 1024-byte increments, except for '-t', which is in
3916 seconds; '-p', which is in units of 512-byte blocks; '-P', '-T',
3917 '-b', '-k', '-n' and '-u', which are unscaled values; and, when in
3918 POSIX Mode (*note Bash POSIX Mode::), '-c' and '-f', which are in
3919 512-byte increments.
3920
3921 The return status is zero unless an invalid option or argument is
3922 supplied, or an error occurs while setting a new limit.
3923
3924 'unalias'
3925 unalias [-a] [NAME ... ]
3926
3927 Remove each NAME from the list of aliases. If '-a' is supplied,
3928 all aliases are removed. Aliases are described in *note Aliases::.
3929
3930 \1f
3931 File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
3932
3933 4.3 Modifying Shell Behavior
3934 ============================
3935
3936 * Menu:
3937
3938 * The Set Builtin:: Change the values of shell attributes and
3939 positional parameters.
3940 * The Shopt Builtin:: Modify shell optional behavior.
3941
3942 \1f
3943 File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
3944
3945 4.3.1 The Set Builtin
3946 ---------------------
3947
3948 This builtin is so complicated that it deserves its own section. 'set'
3949 allows you to change the values of shell options and set the positional
3950 parameters, or to display the names and values of shell variables.
3951
3952 'set'
3953 set [--abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [ARGUMENT ...]
3954 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [ARGUMENT ...]
3955
3956 If no options or arguments are supplied, 'set' displays the names
3957 and values of all shell variables and functions, sorted according
3958 to the current locale, in a format that may be reused as input for
3959 setting or resetting the currently-set variables. Read-only
3960 variables cannot be reset. In POSIX mode, only shell variables are
3961 listed.
3962
3963 When options are supplied, they set or unset shell attributes.
3964 Options, if specified, have the following meanings:
3965
3966 '-a'
3967 Each variable or function that is created or modified is given
3968 the export attribute and marked for export to the environment
3969 of subsequent commands.
3970
3971 '-b'
3972 Cause the status of terminated background jobs to be reported
3973 immediately, rather than before printing the next primary
3974 prompt.
3975
3976 '-e'
3977 Exit immediately if a pipeline (*note Pipelines::), which may
3978 consist of a single simple command (*note Simple Commands::),
3979 a list (*note Lists::), or a compound command (*note Compound
3980 Commands::) returns a non-zero status. The shell does not
3981 exit if the command that fails is part of the command list
3982 immediately following a 'while' or 'until' keyword, part of
3983 the test in an 'if' statement, part of any command executed in
3984 a '&&' or '||' list except the command following the final
3985 '&&' or '||', any command in a pipeline but the last, or if
3986 the command's return status is being inverted with '!'. If a
3987 compound command other than a subshell returns a non-zero
3988 status because a command failed while '-e' was being ignored,
3989 the shell does not exit. A trap on 'ERR', if set, is executed
3990 before the shell exits.
3991
3992 This option applies to the shell environment and each subshell
3993 environment separately (*note Command Execution
3994 Environment::), and may cause subshells to exit before
3995 executing all the commands in the subshell.
3996
3997 If a compound command or shell function executes in a context
3998 where '-e' is being ignored, none of the commands executed
3999 within the compound command or function body will be affected
4000 by the '-e' setting, even if '-e' is set and a command returns
4001 a failure status. If a compound command or shell function
4002 sets '-e' while executing in a context where '-e' is ignored,
4003 that setting will not have any effect until the compound
4004 command or the command containing the function call completes.
4005
4006 '-f'
4007 Disable filename expansion (globbing).
4008
4009 '-h'
4010 Locate and remember (hash) commands as they are looked up for
4011 execution. This option is enabled by default.
4012
4013 '-k'
4014 All arguments in the form of assignment statements are placed
4015 in the environment for a command, not just those that precede
4016 the command name.
4017
4018 '-m'
4019 Job control is enabled (*note Job Control::). All processes
4020 run in a separate process group. When a background job
4021 completes, the shell prints a line containing its exit status.
4022
4023 '-n'
4024 Read commands but do not execute them. This may be used to
4025 check a script for syntax errors. This option is ignored by
4026 interactive shells.
4027
4028 '-o OPTION-NAME'
4029
4030 Set the option corresponding to OPTION-NAME:
4031
4032 'allexport'
4033 Same as '-a'.
4034
4035 'braceexpand'
4036 Same as '-B'.
4037
4038 'emacs'
4039 Use an 'emacs'-style line editing interface (*note
4040 Command Line Editing::). This also affects the editing
4041 interface used for 'read -e'.
4042
4043 'errexit'
4044 Same as '-e'.
4045
4046 'errtrace'
4047 Same as '-E'.
4048
4049 'functrace'
4050 Same as '-T'.
4051
4052 'hashall'
4053 Same as '-h'.
4054
4055 'histexpand'
4056 Same as '-H'.
4057
4058 'history'
4059 Enable command history, as described in *note Bash
4060 History Facilities::. This option is on by default in
4061 interactive shells.
4062
4063 'ignoreeof'
4064 An interactive shell will not exit upon reading EOF.
4065
4066 'keyword'
4067 Same as '-k'.
4068
4069 'monitor'
4070 Same as '-m'.
4071
4072 'noclobber'
4073 Same as '-C'.
4074
4075 'noexec'
4076 Same as '-n'.
4077
4078 'noglob'
4079 Same as '-f'.
4080
4081 'nolog'
4082 Currently ignored.
4083
4084 'notify'
4085 Same as '-b'.
4086
4087 'nounset'
4088 Same as '-u'.
4089
4090 'onecmd'
4091 Same as '-t'.
4092
4093 'physical'
4094 Same as '-P'.
4095
4096 'pipefail'
4097 If set, the return value of a pipeline is the value of
4098 the last (rightmost) command to exit with a non-zero
4099 status, or zero if all commands in the pipeline exit
4100 successfully. This option is disabled by default.
4101
4102 'posix'
4103 Change the behavior of Bash where the default operation
4104 differs from the POSIX standard to match the standard
4105 (*note Bash POSIX Mode::). This is intended to make Bash
4106 behave as a strict superset of that standard.
4107
4108 'privileged'
4109 Same as '-p'.
4110
4111 'verbose'
4112 Same as '-v'.
4113
4114 'vi'
4115 Use a 'vi'-style line editing interface. This also
4116 affects the editing interface used for 'read -e'.
4117
4118 'xtrace'
4119 Same as '-x'.
4120
4121 '-p'
4122 Turn on privileged mode. In this mode, the '$BASH_ENV' and
4123 '$ENV' files are not processed, shell functions are not
4124 inherited from the environment, and the 'SHELLOPTS',
4125 'BASHOPTS', 'CDPATH' and 'GLOBIGNORE' variables, if they
4126 appear in the environment, are ignored. If the shell is
4127 started with the effective user (group) id not equal to the
4128 real user (group) id, and the '-p' option is not supplied,
4129 these actions are taken and the effective user id is set to
4130 the real user id. If the '-p' option is supplied at startup,
4131 the effective user id is not reset. Turning this option off
4132 causes the effective user and group ids to be set to the real
4133 user and group ids.
4134
4135 '-t'
4136 Exit after reading and executing one command.
4137
4138 '-u'
4139 Treat unset variables and parameters other than the special
4140 parameters '@' or '*' as an error when performing parameter
4141 expansion. An error message will be written to the standard
4142 error, and a non-interactive shell will exit.
4143
4144 '-v'
4145 Print shell input lines as they are read.
4146
4147 '-x'
4148 Print a trace of simple commands, 'for' commands, 'case'
4149 commands, 'select' commands, and arithmetic 'for' commands and
4150 their arguments or associated word lists after they are
4151 expanded and before they are executed. The value of the 'PS4'
4152 variable is expanded and the resultant value is printed before
4153 the command and its expanded arguments.
4154
4155 '-B'
4156 The shell will perform brace expansion (*note Brace
4157 Expansion::). This option is on by default.
4158
4159 '-C'
4160 Prevent output redirection using '>', '>&', and '<>' from
4161 overwriting existing files.
4162
4163 '-E'
4164 If set, any trap on 'ERR' is inherited by shell functions,
4165 command substitutions, and commands executed in a subshell
4166 environment. The 'ERR' trap is normally not inherited in such
4167 cases.
4168
4169 '-H'
4170 Enable '!' style history substitution (*note History
4171 Interaction::). This option is on by default for interactive
4172 shells.
4173
4174 '-P'
4175 If set, do not resolve symbolic links when performing commands
4176 such as 'cd' which change the current directory. The physical
4177 directory is used instead. By default, Bash follows the
4178 logical chain of directories when performing commands which
4179 change the current directory.
4180
4181 For example, if '/usr/sys' is a symbolic link to
4182 '/usr/local/sys' then:
4183 $ cd /usr/sys; echo $PWD
4184 /usr/sys
4185 $ cd ..; pwd
4186 /usr
4187
4188 If 'set -P' is on, then:
4189 $ cd /usr/sys; echo $PWD
4190 /usr/local/sys
4191 $ cd ..; pwd
4192 /usr/local
4193
4194 '-T'
4195 If set, any trap on 'DEBUG' and 'RETURN' are inherited by
4196 shell functions, command substitutions, and commands executed
4197 in a subshell environment. The 'DEBUG' and 'RETURN' traps are
4198 normally not inherited in such cases.
4199
4200 '--'
4201 If no arguments follow this option, then the positional
4202 parameters are unset. Otherwise, the positional parameters
4203 are set to the ARGUMENTS, even if some of them begin with a
4204 '-'.
4205
4206 '-'
4207 Signal the end of options, cause all remaining ARGUMENTS to be
4208 assigned to the positional parameters. The '-x' and '-v'
4209 options are turned off. If there are no arguments, the
4210 positional parameters remain unchanged.
4211
4212 Using '+' rather than '-' causes these options to be turned off.
4213 The options can also be used upon invocation of the shell. The
4214 current set of options may be found in '$-'.
4215
4216 The remaining N ARGUMENTS are positional parameters and are
4217 assigned, in order, to '$1', '$2', ... '$N'. The special parameter
4218 '#' is set to N.
4219
4220 The return status is always zero unless an invalid option is
4221 supplied.
4222
4223 \1f
4224 File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
4225
4226 4.3.2 The Shopt Builtin
4227 -----------------------
4228
4229 This builtin allows you to change additional shell optional behavior.
4230
4231 'shopt'
4232 shopt [-pqsu] [-o] [OPTNAME ...]
4233
4234 Toggle the values of settings controlling optional shell behavior.
4235 The settings can be either those listed below, or, if the '-o'
4236 option is used, those available with the '-o' option to the 'set'
4237 builtin command (*note The Set Builtin::). With no options, or
4238 with the '-p' option, a list of all settable options is displayed,
4239 with an indication of whether or not each is set. The '-p' option
4240 causes output to be displayed in a form that may be reused as
4241 input. Other options have the following meanings:
4242
4243 '-s'
4244 Enable (set) each OPTNAME.
4245
4246 '-u'
4247 Disable (unset) each OPTNAME.
4248
4249 '-q'
4250 Suppresses normal output; the return status indicates whether
4251 the OPTNAME is set or unset. If multiple OPTNAME arguments
4252 are given with '-q', the return status is zero if all OPTNAMES
4253 are enabled; non-zero otherwise.
4254
4255 '-o'
4256 Restricts the values of OPTNAME to be those defined for the
4257 '-o' option to the 'set' builtin (*note The Set Builtin::).
4258
4259 If either '-s' or '-u' is used with no OPTNAME arguments, 'shopt'
4260 shows only those options which are set or unset, respectively.
4261
4262 Unless otherwise noted, the 'shopt' options are disabled (off) by
4263 default.
4264
4265 The return status when listing options is zero if all OPTNAMES are
4266 enabled, non-zero otherwise. When setting or unsetting options,
4267 the return status is zero unless an OPTNAME is not a valid shell
4268 option.
4269
4270 The list of 'shopt' options is:
4271
4272 'autocd'
4273 If set, a command name that is the name of a directory is
4274 executed as if it were the argument to the 'cd' command. This
4275 option is only used by interactive shells.
4276
4277 'cdable_vars'
4278 If this is set, an argument to the 'cd' builtin command that
4279 is not a directory is assumed to be the name of a variable
4280 whose value is the directory to change to.
4281
4282 'cdspell'
4283 If set, minor errors in the spelling of a directory component
4284 in a 'cd' command will be corrected. The errors checked for
4285 are transposed characters, a missing character, and a
4286 character too many. If a correction is found, the corrected
4287 path is printed, and the command proceeds. This option is
4288 only used by interactive shells.
4289
4290 'checkhash'
4291 If this is set, Bash checks that a command found in the hash
4292 table exists before trying to execute it. If a hashed command
4293 no longer exists, a normal path search is performed.
4294
4295 'checkjobs'
4296 If set, Bash lists the status of any stopped and running jobs
4297 before exiting an interactive shell. If any jobs are running,
4298 this causes the exit to be deferred until a second exit is
4299 attempted without an intervening command (*note Job
4300 Control::). The shell always postpones exiting if any jobs
4301 are stopped.
4302
4303 'checkwinsize'
4304 If set, Bash checks the window size after each command and, if
4305 necessary, updates the values of 'LINES' and 'COLUMNS'.
4306
4307 'cmdhist'
4308 If set, Bash attempts to save all lines of a multiple-line
4309 command in the same history entry. This allows easy
4310 re-editing of multi-line commands.
4311
4312 'compat31'
4313 If set, Bash changes its behavior to that of version 3.1 with
4314 respect to quoted arguments to the conditional command's '=~'
4315 operator and with respect to locale-specific string comparison
4316 when using the '[[' conditional command's '<' and '>'
4317 operators. Bash versions prior to bash-4.1 use ASCII
4318 collation and strcmp(3); bash-4.1 and later use the current
4319 locale's collation sequence and strcoll(3).
4320
4321 'compat32'
4322 If set, Bash changes its behavior to that of version 3.2 with
4323 respect to locale-specific string comparison when using the
4324 '[[' conditional command's '<' and '>' operators (see previous
4325 item) and the effect of interrupting a command list. Bash
4326 versions 3.2 and earlier continue with the next command in the
4327 list after one terminates due to an interrupt.
4328
4329 'compat40'
4330 If set, Bash changes its behavior to that of version 4.0 with
4331 respect to locale-specific string comparison when using the
4332 '[[' conditional command's '<' and '>' operators (see
4333 description of 'compat31') and the effect of interrupting a
4334 command list. Bash versions 4.0 and later interrupt the list
4335 as if the shell received the interrupt; previous versions
4336 continue with the next command in the list.
4337
4338 'compat41'
4339 If set, Bash, when in POSIX mode, treats a single quote in a
4340 double-quoted parameter expansion as a special character. The
4341 single quotes must match (an even number) and the characters
4342 between the single quotes are considered quoted. This is the
4343 behavior of POSIX mode through version 4.1. The default Bash
4344 behavior remains as in previous versions.
4345
4346 'compat42'
4347 If set, Bash does not process the replacement string in the
4348 pattern substitution word expansion using quote removal.
4349
4350 'compat43'
4351 If set, Bash does not print a warning message if an attempt is
4352 made to use a quoted compound array assignment as an argument
4353 to 'declare', makes word expansion errors non-fatal errors
4354 that cause the current command to fail (the default behavior
4355 is to make them fatal errors that cause the shell to exit),
4356 and does not reset the loop state when a shell function is
4357 executed (this allows 'break' or 'continue' in a shell
4358 function to affect loops in the caller's context).
4359
4360 'complete_fullquote'
4361 If set, Bash quotes all shell metacharacters in filenames and
4362 directory names when performing completion. If not set, Bash
4363 removes metacharacters such as the dollar sign from the set of
4364 characters that will be quoted in completed filenames when
4365 these metacharacters appear in shell variable references in
4366 words to be completed. This means that dollar signs in
4367 variable names that expand to directories will not be quoted;
4368 however, any dollar signs appearing in filenames will not be
4369 quoted, either. This is active only when bash is using
4370 backslashes to quote completed filenames. This variable is
4371 set by default, which is the default Bash behavior in versions
4372 through 4.2.
4373
4374 'direxpand'
4375 If set, Bash replaces directory names with the results of word
4376 expansion when performing filename completion. This changes
4377 the contents of the readline editing buffer. If not set, Bash
4378 attempts to preserve what the user typed.
4379
4380 'dirspell'
4381 If set, Bash attempts spelling correction on directory names
4382 during word completion if the directory name initially
4383 supplied does not exist.
4384
4385 'dotglob'
4386 If set, Bash includes filenames beginning with a '.' in the
4387 results of filename expansion.
4388
4389 'execfail'
4390 If this is set, a non-interactive shell will not exit if it
4391 cannot execute the file specified as an argument to the 'exec'
4392 builtin command. An interactive shell does not exit if 'exec'
4393 fails.
4394
4395 'expand_aliases'
4396 If set, aliases are expanded as described below under Aliases,
4397 *note Aliases::. This option is enabled by default for
4398 interactive shells.
4399
4400 'extdebug'
4401 If set at shell invocation, arrange to execute the debugger
4402 profile before the shell starts, identical to the '--debugger'
4403 option. If set after invocation, behavior intended for use by
4404 debuggers is enabled:
4405
4406 1. The '-F' option to the 'declare' builtin (*note Bash
4407 Builtins::) displays the source file name and line number
4408 corresponding to each function name supplied as an
4409 argument.
4410
4411 2. If the command run by the 'DEBUG' trap returns a non-zero
4412 value, the next command is skipped and not executed.
4413
4414 3. If the command run by the 'DEBUG' trap returns a value of
4415 2, and the shell is executing in a subroutine (a shell
4416 function or a shell script executed by the '.' or
4417 'source' builtins), the shell simulates a call to
4418 'return'.
4419
4420 4. 'BASH_ARGC' and 'BASH_ARGV' are updated as described in
4421 their descriptions (*note Bash Variables::).
4422
4423 5. Function tracing is enabled: command substitution, shell
4424 functions, and subshells invoked with '( COMMAND )'
4425 inherit the 'DEBUG' and 'RETURN' traps.
4426
4427 6. Error tracing is enabled: command substitution, shell
4428 functions, and subshells invoked with '( COMMAND )'
4429 inherit the 'ERR' trap.
4430
4431 'extglob'
4432 If set, the extended pattern matching features described above
4433 (*note Pattern Matching::) are enabled.
4434
4435 'extquote'
4436 If set, '$'STRING'' and '$"STRING"' quoting is performed
4437 within '${PARAMETER}' expansions enclosed in double quotes.
4438 This option is enabled by default.
4439
4440 'failglob'
4441 If set, patterns which fail to match filenames during filename
4442 expansion result in an expansion error.
4443
4444 'force_fignore'
4445 If set, the suffixes specified by the 'FIGNORE' shell variable
4446 cause words to be ignored when performing word completion even
4447 if the ignored words are the only possible completions. *Note
4448 Bash Variables::, for a description of 'FIGNORE'. This option
4449 is enabled by default.
4450
4451 'globasciiranges'
4452 If set, range expressions used in pattern matching bracket
4453 expressions (*note Pattern Matching::) behave as if in the
4454 traditional C locale when performing comparisons. That is,
4455 the current locale's collating sequence is not taken into
4456 account, so 'b' will not collate between 'A' and 'B', and
4457 upper-case and lower-case ASCII characters will collate
4458 together.
4459
4460 'globstar'
4461 If set, the pattern '**' used in a filename expansion context
4462 will match all files and zero or more directories and
4463 subdirectories. If the pattern is followed by a '/', only
4464 directories and subdirectories match.
4465
4466 'gnu_errfmt'
4467 If set, shell error messages are written in the standard GNU
4468 error message format.
4469
4470 'histappend'
4471 If set, the history list is appended to the file named by the
4472 value of the 'HISTFILE' variable when the shell exits, rather
4473 than overwriting the file.
4474
4475 'histreedit'
4476 If set, and Readline is being used, a user is given the
4477 opportunity to re-edit a failed history substitution.
4478
4479 'histverify'
4480 If set, and Readline is being used, the results of history
4481 substitution are not immediately passed to the shell parser.
4482 Instead, the resulting line is loaded into the Readline
4483 editing buffer, allowing further modification.
4484
4485 'hostcomplete'
4486 If set, and Readline is being used, Bash will attempt to
4487 perform hostname completion when a word containing a '@' is
4488 being completed (*note Commands For Completion::). This
4489 option is enabled by default.
4490
4491 'huponexit'
4492 If set, Bash will send 'SIGHUP' to all jobs when an
4493 interactive login shell exits (*note Signals::).
4494
4495 'inherit_errexit'
4496 If set, command substitution inherits the value of the
4497 'errexit' option, instead of unsetting it in the subshell
4498 environment. This option is enabled when POSIX mode is
4499 enabled.
4500
4501 'interactive_comments'
4502 Allow a word beginning with '#' to cause that word and all
4503 remaining characters on that line to be ignored in an
4504 interactive shell. This option is enabled by default.
4505
4506 'lastpipe'
4507 If set, and job control is not active, the shell runs the last
4508 command of a pipeline not executed in the background in the
4509 current shell environment.
4510
4511 'lithist'
4512 If enabled, and the 'cmdhist' option is enabled, multi-line
4513 commands are saved to the history with embedded newlines
4514 rather than using semicolon separators where possible.
4515
4516 'login_shell'
4517 The shell sets this option if it is started as a login shell
4518 (*note Invoking Bash::). The value may not be changed.
4519
4520 'mailwarn'
4521 If set, and a file that Bash is checking for mail has been
4522 accessed since the last time it was checked, the message '"The
4523 mail in MAILFILE has been read"' is displayed.
4524
4525 'no_empty_cmd_completion'
4526 If set, and Readline is being used, Bash will not attempt to
4527 search the 'PATH' for possible completions when completion is
4528 attempted on an empty line.
4529
4530 'nocaseglob'
4531 If set, Bash matches filenames in a case-insensitive fashion
4532 when performing filename expansion.
4533
4534 'nocasematch'
4535 If set, Bash matches patterns in a case-insensitive fashion
4536 when performing matching while executing 'case' or '[['
4537 conditional commands, when performing pattern substitution
4538 word expansions, or when filtering possible completions as
4539 part of programmable completion.
4540
4541 'nullglob'
4542 If set, Bash allows filename patterns which match no files to
4543 expand to a null string, rather than themselves.
4544
4545 'progcomp'
4546 If set, the programmable completion facilities (*note
4547 Programmable Completion::) are enabled. This option is
4548 enabled by default.
4549
4550 'promptvars'
4551 If set, prompt strings undergo parameter expansion, command
4552 substitution, arithmetic expansion, and quote removal after
4553 being expanded as described below (*note Controlling the
4554 Prompt::). This option is enabled by default.
4555
4556 'restricted_shell'
4557 The shell sets this option if it is started in restricted mode
4558 (*note The Restricted Shell::). The value may not be changed.
4559 This is not reset when the startup files are executed,
4560 allowing the startup files to discover whether or not a shell
4561 is restricted.
4562
4563 'shift_verbose'
4564 If this is set, the 'shift' builtin prints an error message
4565 when the shift count exceeds the number of positional
4566 parameters.
4567
4568 'sourcepath'
4569 If set, the 'source' builtin uses the value of 'PATH' to find
4570 the directory containing the file supplied as an argument.
4571 This option is enabled by default.
4572
4573 'xpg_echo'
4574 If set, the 'echo' builtin expands backslash-escape sequences
4575 by default.
4576
4577 The return status when listing options is zero if all OPTNAMES are
4578 enabled, non-zero otherwise. When setting or unsetting options,
4579 the return status is zero unless an OPTNAME is not a valid shell
4580 option.
4581
4582 \1f
4583 File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
4584
4585 4.4 Special Builtins
4586 ====================
4587
4588 For historical reasons, the POSIX standard has classified several
4589 builtin commands as _special_. When Bash is executing in POSIX mode,
4590 the special builtins differ from other builtin commands in three
4591 respects:
4592
4593 1. Special builtins are found before shell functions during command
4594 lookup.
4595
4596 2. If a special builtin returns an error status, a non-interactive
4597 shell exits.
4598
4599 3. Assignment statements preceding the command stay in effect in the
4600 shell environment after the command completes.
4601
4602 When Bash is not executing in POSIX mode, these builtins behave no
4603 differently than the rest of the Bash builtin commands. The Bash POSIX
4604 mode is described in *note Bash POSIX Mode::.
4605
4606 These are the POSIX special builtins:
4607 break : . continue eval exec exit export readonly return set
4608 shift trap unset
4609
4610 \1f
4611 File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
4612
4613 5 Shell Variables
4614 *****************
4615
4616 * Menu:
4617
4618 * Bourne Shell Variables:: Variables which Bash uses in the same way
4619 as the Bourne Shell.
4620 * Bash Variables:: List of variables that exist in Bash.
4621
4622 This chapter describes the shell variables that Bash uses. Bash
4623 automatically assigns default values to a number of variables.
4624
4625 \1f
4626 File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
4627
4628 5.1 Bourne Shell Variables
4629 ==========================
4630
4631 Bash uses certain shell variables in the same way as the Bourne shell.
4632 In some cases, Bash assigns a default value to the variable.
4633
4634 'CDPATH'
4635 A colon-separated list of directories used as a search path for the
4636 'cd' builtin command.
4637
4638 'HOME'
4639 The current user's home directory; the default for the 'cd' builtin
4640 command. The value of this variable is also used by tilde
4641 expansion (*note Tilde Expansion::).
4642
4643 'IFS'
4644 A list of characters that separate fields; used when the shell
4645 splits words as part of expansion.
4646
4647 'MAIL'
4648 If this parameter is set to a filename or directory name and the
4649 'MAILPATH' variable is not set, Bash informs the user of the
4650 arrival of mail in the specified file or Maildir-format directory.
4651
4652 'MAILPATH'
4653 A colon-separated list of filenames which the shell periodically
4654 checks for new mail. Each list entry can specify the message that
4655 is printed when new mail arrives in the mail file by separating the
4656 filename from the message with a '?'. When used in the text of the
4657 message, '$_' expands to the name of the current mail file.
4658
4659 'OPTARG'
4660 The value of the last option argument processed by the 'getopts'
4661 builtin.
4662
4663 'OPTIND'
4664 The index of the last option argument processed by the 'getopts'
4665 builtin.
4666
4667 'PATH'
4668 A colon-separated list of directories in which the shell looks for
4669 commands. A zero-length (null) directory name in the value of
4670 'PATH' indicates the current directory. A null directory name may
4671 appear as two adjacent colons, or as an initial or trailing colon.
4672
4673 'PS1'
4674 The primary prompt string. The default value is '\s-\v\$ '. *Note
4675 Controlling the Prompt::, for the complete list of escape sequences
4676 that are expanded before 'PS1' is displayed.
4677
4678 'PS2'
4679 The secondary prompt string. The default value is '> '.
4680
4681 \1f
4682 File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
4683
4684 5.2 Bash Variables
4685 ==================
4686
4687 These variables are set or used by Bash, but other shells do not
4688 normally treat them specially.
4689
4690 A few variables used by Bash are described in different chapters:
4691 variables for controlling the job control facilities (*note Job Control
4692 Variables::).
4693
4694 'BASH'
4695 The full pathname used to execute the current instance of Bash.
4696
4697 'BASHOPTS'
4698 A colon-separated list of enabled shell options. Each word in the
4699 list is a valid argument for the '-s' option to the 'shopt' builtin
4700 command (*note The Shopt Builtin::). The options appearing in
4701 'BASHOPTS' are those reported as 'on' by 'shopt'. If this variable
4702 is in the environment when Bash starts up, each shell option in the
4703 list will be enabled before reading any startup files. This
4704 variable is readonly.
4705
4706 'BASHPID'
4707 Expands to the process ID of the current Bash process. This
4708 differs from '$$' under certain circumstances, such as subshells
4709 that do not require Bash to be re-initialized.
4710
4711 'BASH_ALIASES'
4712 An associative array variable whose members correspond to the
4713 internal list of aliases as maintained by the 'alias' builtin.
4714 (*note Bourne Shell Builtins::). Elements added to this array
4715 appear in the alias list; however, unsetting array elements
4716 currently does not cause aliases to be removed from the alias list.
4717 If 'BASH_ALIASES' is unset, it loses its special properties, even
4718 if it is subsequently reset.
4719
4720 'BASH_ARGC'
4721 An array variable whose values are the number of parameters in each
4722 frame of the current bash execution call stack. The number of
4723 parameters to the current subroutine (shell function or script
4724 executed with '.' or 'source') is at the top of the stack. When a
4725 subroutine is executed, the number of parameters passed is pushed
4726 onto 'BASH_ARGC'. The shell sets 'BASH_ARGC' only when in extended
4727 debugging mode (see *note The Shopt Builtin:: for a description of
4728 the 'extdebug' option to the 'shopt' builtin).
4729
4730 'BASH_ARGV'
4731 An array variable containing all of the parameters in the current
4732 bash execution call stack. The final parameter of the last
4733 subroutine call is at the top of the stack; the first parameter of
4734 the initial call is at the bottom. When a subroutine is executed,
4735 the parameters supplied are pushed onto 'BASH_ARGV'. The shell
4736 sets 'BASH_ARGV' only when in extended debugging mode (see *note
4737 The Shopt Builtin:: for a description of the 'extdebug' option to
4738 the 'shopt' builtin).
4739
4740 'BASH_CMDS'
4741 An associative array variable whose members correspond to the
4742 internal hash table of commands as maintained by the 'hash' builtin
4743 (*note Bourne Shell Builtins::). Elements added to this array
4744 appear in the hash table; however, unsetting array elements
4745 currently does not cause command names to be removed from the hash
4746 table. If 'BASH_CMDS' is unset, it loses its special properties,
4747 even if it is subsequently reset.
4748
4749 'BASH_COMMAND'
4750 The command currently being executed or about to be executed,
4751 unless the shell is executing a command as the result of a trap, in
4752 which case it is the command executing at the time of the trap.
4753
4754 'BASH_COMPAT'
4755 The value is used to set the shell's compatibility level. *Note
4756 The Shopt Builtin::, for a description of the various compatibility
4757 levels and their effects. The value may be a decimal number (e.g.,
4758 4.2) or an integer (e.g., 42) corresponding to the desired
4759 compatibility level. If 'BASH_COMPAT' is unset or set to the empty
4760 string, the compatibility level is set to the default for the
4761 current version. If 'BASH_COMPAT' is set to a value that is not
4762 one of the valid compatibility levels, the shell prints an error
4763 message and sets the compatibility level to the default for the
4764 current version. The valid compatibility levels correspond to the
4765 compatibility options accepted by the 'shopt' builtin described
4766 above (for example, COMPAT42 means that 4.2 and 42 are valid
4767 values). The current version is also a valid value.
4768
4769 'BASH_ENV'
4770 If this variable is set when Bash is invoked to execute a shell
4771 script, its value is expanded and used as the name of a startup
4772 file to read before executing the script. *Note Bash Startup
4773 Files::.
4774
4775 'BASH_EXECUTION_STRING'
4776 The command argument to the '-c' invocation option.
4777
4778 'BASH_LINENO'
4779 An array variable whose members are the line numbers in source
4780 files where each corresponding member of FUNCNAME was invoked.
4781 '${BASH_LINENO[$i]}' is the line number in the source file
4782 ('${BASH_SOURCE[$i+1]}') where '${FUNCNAME[$i]}' was called (or
4783 '${BASH_LINENO[$i-1]}' if referenced within another shell
4784 function). Use 'LINENO' to obtain the current line number.
4785
4786 'BASH_LOADABLES_PATH'
4787 A colon-separated list of directories in which the shell looks for
4788 dynamically loadable builtins specified by the 'enable' command.
4789
4790 'BASH_REMATCH'
4791 An array variable whose members are assigned by the '=~' binary
4792 operator to the '[[' conditional command (*note Conditional
4793 Constructs::). The element with index 0 is the portion of the
4794 string matching the entire regular expression. The element with
4795 index N is the portion of the string matching the Nth parenthesized
4796 subexpression. This variable is read-only.
4797
4798 'BASH_SOURCE'
4799 An array variable whose members are the source filenames where the
4800 corresponding shell function names in the 'FUNCNAME' array variable
4801 are defined. The shell function '${FUNCNAME[$i]}' is defined in
4802 the file '${BASH_SOURCE[$i]}' and called from
4803 '${BASH_SOURCE[$i+1]}'
4804
4805 'BASH_SUBSHELL'
4806 Incremented by one within each subshell or subshell environment
4807 when the shell begins executing in that environment. The initial
4808 value is 0.
4809
4810 'BASH_VERSINFO'
4811 A readonly array variable (*note Arrays::) whose members hold
4812 version information for this instance of Bash. The values assigned
4813 to the array members are as follows:
4814
4815 'BASH_VERSINFO[0]'
4816 The major version number (the RELEASE).
4817
4818 'BASH_VERSINFO[1]'
4819 The minor version number (the VERSION).
4820
4821 'BASH_VERSINFO[2]'
4822 The patch level.
4823
4824 'BASH_VERSINFO[3]'
4825 The build version.
4826
4827 'BASH_VERSINFO[4]'
4828 The release status (e.g., BETA1).
4829
4830 'BASH_VERSINFO[5]'
4831 The value of 'MACHTYPE'.
4832
4833 'BASH_VERSION'
4834 The version number of the current instance of Bash.
4835
4836 'BASH_XTRACEFD'
4837 If set to an integer corresponding to a valid file descriptor, Bash
4838 will write the trace output generated when 'set -x' is enabled to
4839 that file descriptor. This allows tracing output to be separated
4840 from diagnostic and error messages. The file descriptor is closed
4841 when 'BASH_XTRACEFD' is unset or assigned a new value. Unsetting
4842 'BASH_XTRACEFD' or assigning it the empty string causes the trace
4843 output to be sent to the standard error. Note that setting
4844 'BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
4845 unsetting it will result in the standard error being closed.
4846
4847 'CHILD_MAX'
4848 Set the number of exited child status values for the shell to
4849 remember. Bash will not allow this value to be decreased below a
4850 POSIX-mandated minimum, and there is a maximum value (currently
4851 8192) that this may not exceed. The minimum value is
4852 system-dependent.
4853
4854 'COLUMNS'
4855 Used by the 'select' command to determine the terminal width when
4856 printing selection lists. Automatically set if the 'checkwinsize'
4857 option is enabled (*note The Shopt Builtin::), or in an interactive
4858 shell upon receipt of a 'SIGWINCH'.
4859
4860 'COMP_CWORD'
4861 An index into '${COMP_WORDS}' of the word containing the current
4862 cursor position. This variable is available only in shell
4863 functions invoked by the programmable completion facilities (*note
4864 Programmable Completion::).
4865
4866 'COMP_LINE'
4867 The current command line. This variable is available only in shell
4868 functions and external commands invoked by the programmable
4869 completion facilities (*note Programmable Completion::).
4870
4871 'COMP_POINT'
4872 The index of the current cursor position relative to the beginning
4873 of the current command. If the current cursor position is at the
4874 end of the current command, the value of this variable is equal to
4875 '${#COMP_LINE}'. This variable is available only in shell
4876 functions and external commands invoked by the programmable
4877 completion facilities (*note Programmable Completion::).
4878
4879 'COMP_TYPE'
4880 Set to an integer value corresponding to the type of completion
4881 attempted that caused a completion function to be called: TAB, for
4882 normal completion, '?', for listing completions after successive
4883 tabs, '!', for listing alternatives on partial word completion,
4884 '@', to list completions if the word is not unmodified, or '%', for
4885 menu completion. This variable is available only in shell
4886 functions and external commands invoked by the programmable
4887 completion facilities (*note Programmable Completion::).
4888
4889 'COMP_KEY'
4890 The key (or final key of a key sequence) used to invoke the current
4891 completion function.
4892
4893 'COMP_WORDBREAKS'
4894 The set of characters that the Readline library treats as word
4895 separators when performing word completion. If 'COMP_WORDBREAKS'
4896 is unset, it loses its special properties, even if it is
4897 subsequently reset.
4898
4899 'COMP_WORDS'
4900 An array variable consisting of the individual words in the current
4901 command line. The line is split into words as Readline would split
4902 it, using 'COMP_WORDBREAKS' as described above. This variable is
4903 available only in shell functions invoked by the programmable
4904 completion facilities (*note Programmable Completion::).
4905
4906 'COMPREPLY'
4907 An array variable from which Bash reads the possible completions
4908 generated by a shell function invoked by the programmable
4909 completion facility (*note Programmable Completion::). Each array
4910 element contains one possible completion.
4911
4912 'COPROC'
4913 An array variable created to hold the file descriptors for output
4914 from and input to an unnamed coprocess (*note Coprocesses::).
4915
4916 'DIRSTACK'
4917 An array variable containing the current contents of the directory
4918 stack. Directories appear in the stack in the order they are
4919 displayed by the 'dirs' builtin. Assigning to members of this
4920 array variable may be used to modify directories already in the
4921 stack, but the 'pushd' and 'popd' builtins must be used to add and
4922 remove directories. Assignment to this variable will not change
4923 the current directory. If 'DIRSTACK' is unset, it loses its
4924 special properties, even if it is subsequently reset.
4925
4926 'EMACS'
4927 If Bash finds this variable in the environment when the shell
4928 starts with value 't', it assumes that the shell is running in an
4929 Emacs shell buffer and disables line editing.
4930
4931 'ENV'
4932 Similar to 'BASH_ENV'; used when the shell is invoked in POSIX Mode
4933 (*note Bash POSIX Mode::).
4934
4935 'EUID'
4936 The numeric effective user id of the current user. This variable
4937 is readonly.
4938
4939 'EXECIGNORE'
4940 A colon-separated list of shell patterns (*note Pattern Matching::)
4941 defining the list of filenames to be ignored by command search
4942 using 'PATH'. Files whose full pathnames match one of these
4943 patterns are not considered executable files for the purposes of
4944 completion and command execution via 'PATH' lookup. This does not
4945 affect the behavior of the '[', 'test', and '[[' commands. Full
4946 pathnames in the command hash table are not subject to
4947 'EXECIGNORE'. Use this variable to ignore shared library files
4948 that have the executable bit set, but are not executable files.
4949 The pattern matching honors the setting of the 'extglob' shell
4950 option.
4951
4952 'FCEDIT'
4953 The editor used as a default by the '-e' option to the 'fc' builtin
4954 command.
4955
4956 'FIGNORE'
4957 A colon-separated list of suffixes to ignore when performing
4958 filename completion. A filename whose suffix matches one of the
4959 entries in 'FIGNORE' is excluded from the list of matched
4960 filenames. A sample value is '.o:~'
4961
4962 'FUNCNAME'
4963 An array variable containing the names of all shell functions
4964 currently in the execution call stack. The element with index 0 is
4965 the name of any currently-executing shell function. The
4966 bottom-most element (the one with the highest index) is '"main"'.
4967 This variable exists only when a shell function is executing.
4968 Assignments to 'FUNCNAME' have no effect. If 'FUNCNAME' is unset,
4969 it loses its special properties, even if it is subsequently reset.
4970
4971 This variable can be used with 'BASH_LINENO' and 'BASH_SOURCE'.
4972 Each element of 'FUNCNAME' has corresponding elements in
4973 'BASH_LINENO' and 'BASH_SOURCE' to describe the call stack. For
4974 instance, '${FUNCNAME[$i]}' was called from the file
4975 '${BASH_SOURCE[$i+1]}' at line number '${BASH_LINENO[$i]}'. The
4976 'caller' builtin displays the current call stack using this
4977 information.
4978
4979 'FUNCNEST'
4980 If set to a numeric value greater than 0, defines a maximum
4981 function nesting level. Function invocations that exceed this
4982 nesting level will cause the current command to abort.
4983
4984 'GLOBIGNORE'
4985 A colon-separated list of patterns defining the set of filenames to
4986 be ignored by filename expansion. If a filename matched by a
4987 filename expansion pattern also matches one of the patterns in
4988 'GLOBIGNORE', it is removed from the list of matches. The pattern
4989 matching honors the setting of the 'extglob' shell option.
4990
4991 'GROUPS'
4992 An array variable containing the list of groups of which the
4993 current user is a member. Assignments to 'GROUPS' have no effect.
4994 If 'GROUPS' is unset, it loses its special properties, even if it
4995 is subsequently reset.
4996
4997 'histchars'
4998 Up to three characters which control history expansion, quick
4999 substitution, and tokenization (*note History Interaction::). The
5000 first character is the HISTORY EXPANSION character, that is, the
5001 character which signifies the start of a history expansion,
5002 normally '!'. The second character is the character which
5003 signifies 'quick substitution' when seen as the first character on
5004 a line, normally '^'. The optional third character is the
5005 character which indicates that the remainder of the line is a
5006 comment when found as the first character of a word, usually '#'.
5007 The history comment character causes history substitution to be
5008 skipped for the remaining words on the line. It does not
5009 necessarily cause the shell parser to treat the rest of the line as
5010 a comment.
5011
5012 'HISTCMD'
5013 The history number, or index in the history list, of the current
5014 command. If 'HISTCMD' is unset, it loses its special properties,
5015 even if it is subsequently reset.
5016
5017 'HISTCONTROL'
5018 A colon-separated list of values controlling how commands are saved
5019 on the history list. If the list of values includes 'ignorespace',
5020 lines which begin with a space character are not saved in the
5021 history list. A value of 'ignoredups' causes lines which match the
5022 previous history entry to not be saved. A value of 'ignoreboth' is
5023 shorthand for 'ignorespace' and 'ignoredups'. A value of
5024 'erasedups' causes all previous lines matching the current line to
5025 be removed from the history list before that line is saved. Any
5026 value not in the above list is ignored. If 'HISTCONTROL' is unset,
5027 or does not include a valid value, all lines read by the shell
5028 parser are saved on the history list, subject to the value of
5029 'HISTIGNORE'. The second and subsequent lines of a multi-line
5030 compound command are not tested, and are added to the history
5031 regardless of the value of 'HISTCONTROL'.
5032
5033 'HISTFILE'
5034 The name of the file to which the command history is saved. The
5035 default value is '~/.bash_history'.
5036
5037 'HISTFILESIZE'
5038 The maximum number of lines contained in the history file. When
5039 this variable is assigned a value, the history file is truncated,
5040 if necessary, to contain no more than that number of lines by
5041 removing the oldest entries. The history file is also truncated to
5042 this size after writing it when a shell exits. If the value is 0,
5043 the history file is truncated to zero size. Non-numeric values and
5044 numeric values less than zero inhibit truncation. The shell sets
5045 the default value to the value of 'HISTSIZE' after reading any
5046 startup files.
5047
5048 'HISTIGNORE'
5049 A colon-separated list of patterns used to decide which command
5050 lines should be saved on the history list. Each pattern is
5051 anchored at the beginning of the line and must match the complete
5052 line (no implicit '*' is appended). Each pattern is tested against
5053 the line after the checks specified by 'HISTCONTROL' are applied.
5054 In addition to the normal shell pattern matching characters, '&'
5055 matches the previous history line. '&' may be escaped using a
5056 backslash; the backslash is removed before attempting a match. The
5057 second and subsequent lines of a multi-line compound command are
5058 not tested, and are added to the history regardless of the value of
5059 'HISTIGNORE'. The pattern matching honors the setting of the
5060 'extglob' shell option.
5061
5062 'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of
5063 '&' is identical to 'ignoredups', and a pattern of '[ ]*' is
5064 identical to 'ignorespace'. Combining these two patterns,
5065 separating them with a colon, provides the functionality of
5066 'ignoreboth'.
5067
5068 'HISTSIZE'
5069 The maximum number of commands to remember on the history list. If
5070 the value is 0, commands are not saved in the history list.
5071 Numeric values less than zero result in every command being saved
5072 on the history list (there is no limit). The shell sets the
5073 default value to 500 after reading any startup files.
5074
5075 'HISTTIMEFORMAT'
5076 If this variable is set and not null, its value is used as a format
5077 string for STRFTIME to print the time stamp associated with each
5078 history entry displayed by the 'history' builtin. If this variable
5079 is set, time stamps are written to the history file so they may be
5080 preserved across shell sessions. This uses the history comment
5081 character to distinguish timestamps from other history lines.
5082
5083 'HOSTFILE'
5084 Contains the name of a file in the same format as '/etc/hosts' that
5085 should be read when the shell needs to complete a hostname. The
5086 list of possible hostname completions may be changed while the
5087 shell is running; the next time hostname completion is attempted
5088 after the value is changed, Bash adds the contents of the new file
5089 to the existing list. If 'HOSTFILE' is set, but has no value, or
5090 does not name a readable file, Bash attempts to read '/etc/hosts'
5091 to obtain the list of possible hostname completions. When
5092 'HOSTFILE' is unset, the hostname list is cleared.
5093
5094 'HOSTNAME'
5095 The name of the current host.
5096
5097 'HOSTTYPE'
5098 A string describing the machine Bash is running on.
5099
5100 'IGNOREEOF'
5101 Controls the action of the shell on receipt of an 'EOF' character
5102 as the sole input. If set, the value denotes the number of
5103 consecutive 'EOF' characters that can be read as the first
5104 character on an input line before the shell will exit. If the
5105 variable exists but does not have a numeric value (or has no value)
5106 then the default is 10. If the variable does not exist, then 'EOF'
5107 signifies the end of input to the shell. This is only in effect
5108 for interactive shells.
5109
5110 'INPUTRC'
5111 The name of the Readline initialization file, overriding the
5112 default of '~/.inputrc'.
5113
5114 'LANG'
5115 Used to determine the locale category for any category not
5116 specifically selected with a variable starting with 'LC_'.
5117
5118 'LC_ALL'
5119 This variable overrides the value of 'LANG' and any other 'LC_'
5120 variable specifying a locale category.
5121
5122 'LC_COLLATE'
5123 This variable determines the collation order used when sorting the
5124 results of filename expansion, and determines the behavior of range
5125 expressions, equivalence classes, and collating sequences within
5126 filename expansion and pattern matching (*note Filename
5127 Expansion::).
5128
5129 'LC_CTYPE'
5130 This variable determines the interpretation of characters and the
5131 behavior of character classes within filename expansion and pattern
5132 matching (*note Filename Expansion::).
5133
5134 'LC_MESSAGES'
5135 This variable determines the locale used to translate double-quoted
5136 strings preceded by a '$' (*note Locale Translation::).
5137
5138 'LC_NUMERIC'
5139 This variable determines the locale category used for number
5140 formatting.
5141
5142 'LC_TIME'
5143 This variable determines the locale category used for data and time
5144 formatting.
5145
5146 'LINENO'
5147 The line number in the script or shell function currently
5148 executing.
5149
5150 'LINES'
5151 Used by the 'select' command to determine the column length for
5152 printing selection lists. Automatically set if the 'checkwinsize'
5153 option is enabled (*note The Shopt Builtin::), or in an interactive
5154 shell upon receipt of a 'SIGWINCH'.
5155
5156 'MACHTYPE'
5157 A string that fully describes the system type on which Bash is
5158 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
5159
5160 'MAILCHECK'
5161 How often (in seconds) that the shell should check for mail in the
5162 files specified in the 'MAILPATH' or 'MAIL' variables. The default
5163 is 60 seconds. When it is time to check for mail, the shell does
5164 so before displaying the primary prompt. If this variable is
5165 unset, or set to a value that is not a number greater than or equal
5166 to zero, the shell disables mail checking.
5167
5168 'MAPFILE'
5169 An array variable created to hold the text read by the 'mapfile'
5170 builtin when no variable name is supplied.
5171
5172 'OLDPWD'
5173 The previous working directory as set by the 'cd' builtin.
5174
5175 'OPTERR'
5176 If set to the value 1, Bash displays error messages generated by
5177 the 'getopts' builtin command.
5178
5179 'OSTYPE'
5180 A string describing the operating system Bash is running on.
5181
5182 'PIPESTATUS'
5183 An array variable (*note Arrays::) containing a list of exit status
5184 values from the processes in the most-recently-executed foreground
5185 pipeline (which may contain only a single command).
5186
5187 'POSIXLY_CORRECT'
5188 If this variable is in the environment when Bash starts, the shell
5189 enters POSIX mode (*note Bash POSIX Mode::) before reading the
5190 startup files, as if the '--posix' invocation option had been
5191 supplied. If it is set while the shell is running, Bash enables
5192 POSIX mode, as if the command
5193 set -o posix
5194 had been executed.
5195
5196 'PPID'
5197 The process ID of the shell's parent process. This variable is
5198 readonly.
5199
5200 'PROMPT_COMMAND'
5201 If set, the value is interpreted as a command to execute before the
5202 printing of each primary prompt ('$PS1').
5203
5204 'PROMPT_DIRTRIM'
5205 If set to a number greater than zero, the value is used as the
5206 number of trailing directory components to retain when expanding
5207 the '\w' and '\W' prompt string escapes (*note Controlling the
5208 Prompt::). Characters removed are replaced with an ellipsis.
5209
5210 'PS0'
5211 The value of this parameter is expanded like PS1 and displayed by
5212 interactive shells after reading a command and before the command
5213 is executed.
5214
5215 'PS3'
5216 The value of this variable is used as the prompt for the 'select'
5217 command. If this variable is not set, the 'select' command prompts
5218 with '#? '
5219
5220 'PS4'
5221 The value is the prompt printed before the command line is echoed
5222 when the '-x' option is set (*note The Set Builtin::). The first
5223 character of 'PS4' is replicated multiple times, as necessary, to
5224 indicate multiple levels of indirection. The default is '+ '.
5225
5226 'PWD'
5227 The current working directory as set by the 'cd' builtin.
5228
5229 'RANDOM'
5230 Each time this parameter is referenced, a random integer between 0
5231 and 32767 is generated. Assigning a value to this variable seeds
5232 the random number generator.
5233
5234 'READLINE_LINE'
5235 The contents of the Readline line buffer, for use with 'bind -x'
5236 (*note Bash Builtins::).
5237
5238 'READLINE_POINT'
5239 The position of the insertion point in the Readline line buffer,
5240 for use with 'bind -x' (*note Bash Builtins::).
5241
5242 'REPLY'
5243 The default variable for the 'read' builtin.
5244
5245 'SECONDS'
5246 This variable expands to the number of seconds since the shell was
5247 started. Assignment to this variable resets the count to the value
5248 assigned, and the expanded value becomes the value assigned plus
5249 the number of seconds since the assignment.
5250
5251 'SHELL'
5252 The full pathname to the shell is kept in this environment
5253 variable. If it is not set when the shell starts, Bash assigns to
5254 it the full pathname of the current user's login shell.
5255
5256 'SHELLOPTS'
5257 A colon-separated list of enabled shell options. Each word in the
5258 list is a valid argument for the '-o' option to the 'set' builtin
5259 command (*note The Set Builtin::). The options appearing in
5260 'SHELLOPTS' are those reported as 'on' by 'set -o'. If this
5261 variable is in the environment when Bash starts up, each shell
5262 option in the list will be enabled before reading any startup
5263 files. This variable is readonly.
5264
5265 'SHLVL'
5266 Incremented by one each time a new instance of Bash is started.
5267 This is intended to be a count of how deeply your Bash shells are
5268 nested.
5269
5270 'TIMEFORMAT'
5271 The value of this parameter is used as a format string specifying
5272 how the timing information for pipelines prefixed with the 'time'
5273 reserved word should be displayed. The '%' character introduces an
5274 escape sequence that is expanded to a time value or other
5275 information. The escape sequences and their meanings are as
5276 follows; the braces denote optional portions.
5277
5278 '%%'
5279 A literal '%'.
5280
5281 '%[P][l]R'
5282 The elapsed time in seconds.
5283
5284 '%[P][l]U'
5285 The number of CPU seconds spent in user mode.
5286
5287 '%[P][l]S'
5288 The number of CPU seconds spent in system mode.
5289
5290 '%P'
5291 The CPU percentage, computed as (%U + %S) / %R.
5292
5293 The optional P is a digit specifying the precision, the number of
5294 fractional digits after a decimal point. A value of 0 causes no
5295 decimal point or fraction to be output. At most three places after
5296 the decimal point may be specified; values of P greater than 3 are
5297 changed to 3. If P is not specified, the value 3 is used.
5298
5299 The optional 'l' specifies a longer format, including minutes, of
5300 the form MMmSS.FFs. The value of P determines whether or not the
5301 fraction is included.
5302
5303 If this variable is not set, Bash acts as if it had the value
5304 $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
5305 If the value is null, no timing information is displayed. A
5306 trailing newline is added when the format string is displayed.
5307
5308 'TMOUT'
5309 If set to a value greater than zero, 'TMOUT' is treated as the
5310 default timeout for the 'read' builtin (*note Bash Builtins::).
5311 The 'select' command (*note Conditional Constructs::) terminates if
5312 input does not arrive after 'TMOUT' seconds when input is coming
5313 from a terminal.
5314
5315 In an interactive shell, the value is interpreted as the number of
5316 seconds to wait for a line of input after issuing the primary
5317 prompt. Bash terminates after waiting for that number of seconds
5318 if a complete line of input does not arrive.
5319
5320 'TMPDIR'
5321 If set, Bash uses its value as the name of a directory in which
5322 Bash creates temporary files for the shell's use.
5323
5324 'UID'
5325 The numeric real user id of the current user. This variable is
5326 readonly.
5327
5328 \1f
5329 File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
5330
5331 6 Bash Features
5332 ***************
5333
5334 This chapter describes features unique to Bash.
5335
5336 * Menu:
5337
5338 * Invoking Bash:: Command line options that you can give
5339 to Bash.
5340 * Bash Startup Files:: When and how Bash executes scripts.
5341 * Interactive Shells:: What an interactive shell is.
5342 * Bash Conditional Expressions:: Primitives used in composing expressions for
5343 the 'test' builtin.
5344 * Shell Arithmetic:: Arithmetic on shell variables.
5345 * Aliases:: Substituting one command for another.
5346 * Arrays:: Array Variables.
5347 * The Directory Stack:: History of visited directories.
5348 * Controlling the Prompt:: Customizing the various prompt strings.
5349 * The Restricted Shell:: A more controlled mode of shell execution.
5350 * Bash POSIX Mode:: Making Bash behave more closely to what
5351 the POSIX standard specifies.
5352
5353 \1f
5354 File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
5355
5356 6.1 Invoking Bash
5357 =================
5358
5359 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
5360 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
5361 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION] [-O SHOPT_OPTION] [ARGUMENT ...]
5362
5363 All of the single-character options used with the 'set' builtin
5364 (*note The Set Builtin::) can be used as options when the shell is
5365 invoked. In addition, there are several multi-character options that
5366 you can use. These options must appear on the command line before the
5367 single-character options to be recognized.
5368
5369 '--debugger'
5370 Arrange for the debugger profile to be executed before the shell
5371 starts. Turns on extended debugging mode (see *note The Shopt
5372 Builtin:: for a description of the 'extdebug' option to the 'shopt'
5373 builtin).
5374
5375 '--dump-po-strings'
5376 A list of all double-quoted strings preceded by '$' is printed on
5377 the standard output in the GNU 'gettext' PO (portable object) file
5378 format. Equivalent to '-D' except for the output format.
5379
5380 '--dump-strings'
5381 Equivalent to '-D'.
5382
5383 '--help'
5384 Display a usage message on standard output and exit successfully.
5385
5386 '--init-file FILENAME'
5387 '--rcfile FILENAME'
5388 Execute commands from FILENAME (instead of '~/.bashrc') in an
5389 interactive shell.
5390
5391 '--login'
5392 Equivalent to '-l'.
5393
5394 '--noediting'
5395 Do not use the GNU Readline library (*note Command Line Editing::)
5396 to read command lines when the shell is interactive.
5397
5398 '--noprofile'
5399 Don't load the system-wide startup file '/etc/profile' or any of
5400 the personal initialization files '~/.bash_profile',
5401 '~/.bash_login', or '~/.profile' when Bash is invoked as a login
5402 shell.
5403
5404 '--norc'
5405 Don't read the '~/.bashrc' initialization file in an interactive
5406 shell. This is on by default if the shell is invoked as 'sh'.
5407
5408 '--posix'
5409 Change the behavior of Bash where the default operation differs
5410 from the POSIX standard to match the standard. This is intended to
5411 make Bash behave as a strict superset of that standard. *Note Bash
5412 POSIX Mode::, for a description of the Bash POSIX mode.
5413
5414 '--restricted'
5415 Make the shell a restricted shell (*note The Restricted Shell::).
5416
5417 '--verbose'
5418 Equivalent to '-v'. Print shell input lines as they're read.
5419
5420 '--version'
5421 Show version information for this instance of Bash on the standard
5422 output and exit successfully.
5423
5424 There are several single-character options that may be supplied at
5425 invocation which are not available with the 'set' builtin.
5426
5427 '-c'
5428 Read and execute commands from the first non-option argument
5429 COMMAND_STRING, then exit. If there are arguments after the
5430 COMMAND_STRING, the first argument is assigned to '$0' and any
5431 remaining arguments are assigned to the positional parameters. The
5432 assignment to '$0' sets the name of the shell, which is used in
5433 warning and error messages.
5434
5435 '-i'
5436 Force the shell to run interactively. Interactive shells are
5437 described in *note Interactive Shells::.
5438
5439 '-l'
5440 Make this shell act as if it had been directly invoked by login.
5441 When the shell is interactive, this is equivalent to starting a
5442 login shell with 'exec -l bash'. When the shell is not
5443 interactive, the login shell startup files will be executed. 'exec
5444 bash -l' or 'exec bash --login' will replace the current shell with
5445 a Bash login shell. *Note Bash Startup Files::, for a description
5446 of the special behavior of a login shell.
5447
5448 '-r'
5449 Make the shell a restricted shell (*note The Restricted Shell::).
5450
5451 '-s'
5452 If this option is present, or if no arguments remain after option
5453 processing, then commands are read from the standard input. This
5454 option allows the positional parameters to be set when invoking an
5455 interactive shell.
5456
5457 '-D'
5458 A list of all double-quoted strings preceded by '$' is printed on
5459 the standard output. These are the strings that are subject to
5460 language translation when the current locale is not 'C' or 'POSIX'
5461 (*note Locale Translation::). This implies the '-n' option; no
5462 commands will be executed.
5463
5464 '[-+]O [SHOPT_OPTION]'
5465 SHOPT_OPTION is one of the shell options accepted by the 'shopt'
5466 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
5467 '-O' sets the value of that option; '+O' unsets it. If
5468 SHOPT_OPTION is not supplied, the names and values of the shell
5469 options accepted by 'shopt' are printed on the standard output. If
5470 the invocation option is '+O', the output is displayed in a format
5471 that may be reused as input.
5472
5473 '--'
5474 A '--' signals the end of options and disables further option
5475 processing. Any arguments after the '--' are treated as filenames
5476 and arguments.
5477
5478 A _login_ shell is one whose first character of argument zero is '-',
5479 or one invoked with the '--login' option.
5480
5481 An _interactive_ shell is one started without non-option arguments,
5482 unless '-s' is specified, without specifying the '-c' option, and whose
5483 input and output are both connected to terminals (as determined by
5484 'isatty(3)'), or one started with the '-i' option. *Note Interactive
5485 Shells::, for more information.
5486
5487 If arguments remain after option processing, and neither the '-c' nor
5488 the '-s' option has been supplied, the first argument is assumed to be
5489 the name of a file containing shell commands (*note Shell Scripts::).
5490 When Bash is invoked in this fashion, '$0' is set to the name of the
5491 file, and the positional parameters are set to the remaining arguments.
5492 Bash reads and executes commands from this file, then exits. Bash's
5493 exit status is the exit status of the last command executed in the
5494 script. If no commands are executed, the exit status is 0.
5495
5496 \1f
5497 File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
5498
5499 6.2 Bash Startup Files
5500 ======================
5501
5502 This section describes how Bash executes its startup files. If any of
5503 the files exist but cannot be read, Bash reports an error. Tildes are
5504 expanded in filenames as described above under Tilde Expansion (*note
5505 Tilde Expansion::).
5506
5507 Interactive shells are described in *note Interactive Shells::.
5508
5509 Invoked as an interactive login shell, or with '--login'
5510 ........................................................
5511
5512 When Bash is invoked as an interactive login shell, or as a
5513 non-interactive shell with the '--login' option, it first reads and
5514 executes commands from the file '/etc/profile', if that file exists.
5515 After reading that file, it looks for '~/.bash_profile',
5516 '~/.bash_login', and '~/.profile', in that order, and reads and executes
5517 commands from the first one that exists and is readable. The
5518 '--noprofile' option may be used when the shell is started to inhibit
5519 this behavior.
5520
5521 When an interactive login shell exits, or a non-interactive login
5522 shell executes the 'exit' builtin command, Bash reads and executes
5523 commands from the file '~/.bash_logout', if it exists.
5524
5525 Invoked as an interactive non-login shell
5526 .........................................
5527
5528 When an interactive shell that is not a login shell is started, Bash
5529 reads and executes commands from '~/.bashrc', if that file exists. This
5530 may be inhibited by using the '--norc' option. The '--rcfile FILE'
5531 option will force Bash to read and execute commands from FILE instead of
5532 '~/.bashrc'.
5533
5534 So, typically, your '~/.bash_profile' contains the line
5535 if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
5536 after (or before) any login-specific initializations.
5537
5538 Invoked non-interactively
5539 .........................
5540
5541 When Bash is started non-interactively, to run a shell script, for
5542 example, it looks for the variable 'BASH_ENV' in the environment,
5543 expands its value if it appears there, and uses the expanded value as
5544 the name of a file to read and execute. Bash behaves as if the
5545 following command were executed:
5546 if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
5547 but the value of the 'PATH' variable is not used to search for the
5548 filename.
5549
5550 As noted above, if a non-interactive shell is invoked with the
5551 '--login' option, Bash attempts to read and execute commands from the
5552 login shell startup files.
5553
5554 Invoked with name 'sh'
5555 ......................
5556
5557 If Bash is invoked with the name 'sh', it tries to mimic the startup
5558 behavior of historical versions of 'sh' as closely as possible, while
5559 conforming to the POSIX standard as well.
5560
5561 When invoked as an interactive login shell, or as a non-interactive
5562 shell with the '--login' option, it first attempts to read and execute
5563 commands from '/etc/profile' and '~/.profile', in that order. The
5564 '--noprofile' option may be used to inhibit this behavior. When invoked
5565 as an interactive shell with the name 'sh', Bash looks for the variable
5566 'ENV', expands its value if it is defined, and uses the expanded value
5567 as the name of a file to read and execute. Since a shell invoked as
5568 'sh' does not attempt to read and execute commands from any other
5569 startup files, the '--rcfile' option has no effect. A non-interactive
5570 shell invoked with the name 'sh' does not attempt to read any other
5571 startup files.
5572
5573 When invoked as 'sh', Bash enters POSIX mode after the startup files
5574 are read.
5575
5576 Invoked in POSIX mode
5577 .....................
5578
5579 When Bash is started in POSIX mode, as with the '--posix' command line
5580 option, it follows the POSIX standard for startup files. In this mode,
5581 interactive shells expand the 'ENV' variable and commands are read and
5582 executed from the file whose name is the expanded value. No other
5583 startup files are read.
5584
5585 Invoked by remote shell daemon
5586 ..............................
5587
5588 Bash attempts to determine when it is being run with its standard input
5589 connected to a network connection, as when executed by the remote shell
5590 daemon, usually 'rshd', or the secure shell daemon 'sshd'. If Bash
5591 determines it is being run in this fashion, it reads and executes
5592 commands from '~/.bashrc', if that file exists and is readable. It will
5593 not do this if invoked as 'sh'. The '--norc' option may be used to
5594 inhibit this behavior, and the '--rcfile' option may be used to force
5595 another file to be read, but neither 'rshd' nor 'sshd' generally invoke
5596 the shell with those options or allow them to be specified.
5597
5598 Invoked with unequal effective and real UID/GIDs
5599 ................................................
5600
5601 If Bash is started with the effective user (group) id not equal to the
5602 real user (group) id, and the '-p' option is not supplied, no startup
5603 files are read, shell functions are not inherited from the environment,
5604 the 'SHELLOPTS', 'BASHOPTS', 'CDPATH', and 'GLOBIGNORE' variables, if
5605 they appear in the environment, are ignored, and the effective user id
5606 is set to the real user id. If the '-p' option is supplied at
5607 invocation, the startup behavior is the same, but the effective user id
5608 is not reset.
5609
5610 \1f
5611 File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
5612
5613 6.3 Interactive Shells
5614 ======================
5615
5616 * Menu:
5617
5618 * What is an Interactive Shell?:: What determines whether a shell is Interactive.
5619 * Is this Shell Interactive?:: How to tell if a shell is interactive.
5620 * Interactive Shell Behavior:: What changes in a interactive shell?
5621
5622 \1f
5623 File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
5624
5625 6.3.1 What is an Interactive Shell?
5626 -----------------------------------
5627
5628 An interactive shell is one started without non-option arguments, unless
5629 '-s' is specified, without specifying the '-c' option, and whose input
5630 and error output are both connected to terminals (as determined by
5631 'isatty(3)'), or one started with the '-i' option.
5632
5633 An interactive shell generally reads from and writes to a user's
5634 terminal.
5635
5636 The '-s' invocation option may be used to set the positional
5637 parameters when an interactive shell is started.
5638
5639 \1f
5640 File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
5641
5642 6.3.2 Is this Shell Interactive?
5643 --------------------------------
5644
5645 To determine within a startup script whether or not Bash is running
5646 interactively, test the value of the '-' special parameter. It contains
5647 'i' when the shell is interactive. For example:
5648
5649 case "$-" in
5650 *i*) echo This shell is interactive ;;
5651 *) echo This shell is not interactive ;;
5652 esac
5653
5654 Alternatively, startup scripts may examine the variable 'PS1'; it is
5655 unset in non-interactive shells, and set in interactive shells. Thus:
5656
5657 if [ -z "$PS1" ]; then
5658 echo This shell is not interactive
5659 else
5660 echo This shell is interactive
5661 fi
5662
5663 \1f
5664 File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
5665
5666 6.3.3 Interactive Shell Behavior
5667 --------------------------------
5668
5669 When the shell is running interactively, it changes its behavior in
5670 several ways.
5671
5672 1. Startup files are read and executed as described in *note Bash
5673 Startup Files::.
5674
5675 2. Job Control (*note Job Control::) is enabled by default. When job
5676 control is in effect, Bash ignores the keyboard-generated job
5677 control signals 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
5678
5679 3. Bash expands and displays 'PS1' before reading the first line of a
5680 command, and expands and displays 'PS2' before reading the second
5681 and subsequent lines of a multi-line command. Bash displays 'PS0'
5682 after it reads a command but before executing it.
5683
5684 4. Bash executes the value of the 'PROMPT_COMMAND' variable as a
5685 command before printing the primary prompt, '$PS1' (*note Bash
5686 Variables::).
5687
5688 5. Readline (*note Command Line Editing::) is used to read commands
5689 from the user's terminal.
5690
5691 6. Bash inspects the value of the 'ignoreeof' option to 'set -o'
5692 instead of exiting immediately when it receives an 'EOF' on its
5693 standard input when reading a command (*note The Set Builtin::).
5694
5695 7. Command history (*note Bash History Facilities::) and history
5696 expansion (*note History Interaction::) are enabled by default.
5697 Bash will save the command history to the file named by '$HISTFILE'
5698 when a shell with history enabled exits.
5699
5700 8. Alias expansion (*note Aliases::) is performed by default.
5701
5702 9. In the absence of any traps, Bash ignores 'SIGTERM' (*note
5703 Signals::).
5704
5705 10. In the absence of any traps, 'SIGINT' is caught and handled
5706 ((*note Signals::). 'SIGINT' will interrupt some shell builtins.
5707
5708 11. An interactive login shell sends a 'SIGHUP' to all jobs on exit if
5709 the 'huponexit' shell option has been enabled (*note Signals::).
5710
5711 12. The '-n' invocation option is ignored, and 'set -n' has no effect
5712 (*note The Set Builtin::).
5713
5714 13. Bash will check for mail periodically, depending on the values of
5715 the 'MAIL', 'MAILPATH', and 'MAILCHECK' shell variables (*note Bash
5716 Variables::).
5717
5718 14. Expansion errors due to references to unbound shell variables
5719 after 'set -u' has been enabled will not cause the shell to exit
5720 (*note The Set Builtin::).
5721
5722 15. The shell will not exit on expansion errors caused by VAR being
5723 unset or null in '${VAR:?WORD}' expansions (*note Shell Parameter
5724 Expansion::).
5725
5726 16. Redirection errors encountered by shell builtins will not cause
5727 the shell to exit.
5728
5729 17. When running in POSIX mode, a special builtin returning an error
5730 status will not cause the shell to exit (*note Bash POSIX Mode::).
5731
5732 18. A failed 'exec' will not cause the shell to exit (*note Bourne
5733 Shell Builtins::).
5734
5735 19. Parser syntax errors will not cause the shell to exit.
5736
5737 20. Simple spelling correction for directory arguments to the 'cd'
5738 builtin is enabled by default (see the description of the 'cdspell'
5739 option to the 'shopt' builtin in *note The Shopt Builtin::).
5740
5741 21. The shell will check the value of the 'TMOUT' variable and exit if
5742 a command is not read within the specified number of seconds after
5743 printing '$PS1' (*note Bash Variables::).
5744
5745 \1f
5746 File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
5747
5748 6.4 Bash Conditional Expressions
5749 ================================
5750
5751 Conditional expressions are used by the '[[' compound command and the
5752 'test' and '[' builtin commands.
5753
5754 Expressions may be unary or binary. Unary expressions are often used
5755 to examine the status of a file. There are string operators and numeric
5756 comparison operators as well. Bash handles several filenames specially
5757 when they are used in expressions. If the operating system on which
5758 Bash is running provides these special files, Bash will use them;
5759 otherwise it will emulate them internally with this behavior: If the
5760 FILE argument to one of the primaries is of the form '/dev/fd/N', then
5761 file descriptor N is checked. If the FILE argument to one of the
5762 primaries is one of '/dev/stdin', '/dev/stdout', or '/dev/stderr', file
5763 descriptor 0, 1, or 2, respectively, is checked.
5764
5765 When used with '[[', the '<' and '>' operators sort lexicographically
5766 using the current locale. The 'test' command uses ASCII ordering.
5767
5768 Unless otherwise specified, primaries that operate on files follow
5769 symbolic links and operate on the target of the link, rather than the
5770 link itself.
5771
5772 '-a FILE'
5773 True if FILE exists.
5774
5775 '-b FILE'
5776 True if FILE exists and is a block special file.
5777
5778 '-c FILE'
5779 True if FILE exists and is a character special file.
5780
5781 '-d FILE'
5782 True if FILE exists and is a directory.
5783
5784 '-e FILE'
5785 True if FILE exists.
5786
5787 '-f FILE'
5788 True if FILE exists and is a regular file.
5789
5790 '-g FILE'
5791 True if FILE exists and its set-group-id bit is set.
5792
5793 '-h FILE'
5794 True if FILE exists and is a symbolic link.
5795
5796 '-k FILE'
5797 True if FILE exists and its "sticky" bit is set.
5798
5799 '-p FILE'
5800 True if FILE exists and is a named pipe (FIFO).
5801
5802 '-r FILE'
5803 True if FILE exists and is readable.
5804
5805 '-s FILE'
5806 True if FILE exists and has a size greater than zero.
5807
5808 '-t FD'
5809 True if file descriptor FD is open and refers to a terminal.
5810
5811 '-u FILE'
5812 True if FILE exists and its set-user-id bit is set.
5813
5814 '-w FILE'
5815 True if FILE exists and is writable.
5816
5817 '-x FILE'
5818 True if FILE exists and is executable.
5819
5820 '-G FILE'
5821 True if FILE exists and is owned by the effective group id.
5822
5823 '-L FILE'
5824 True if FILE exists and is a symbolic link.
5825
5826 '-N FILE'
5827 True if FILE exists and has been modified since it was last read.
5828
5829 '-O FILE'
5830 True if FILE exists and is owned by the effective user id.
5831
5832 '-S FILE'
5833 True if FILE exists and is a socket.
5834
5835 'FILE1 -ef FILE2'
5836 True if FILE1 and FILE2 refer to the same device and inode numbers.
5837
5838 'FILE1 -nt FILE2'
5839 True if FILE1 is newer (according to modification date) than FILE2,
5840 or if FILE1 exists and FILE2 does not.
5841
5842 'FILE1 -ot FILE2'
5843 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
5844 does not.
5845
5846 '-o OPTNAME'
5847 True if the shell option OPTNAME is enabled. The list of options
5848 appears in the description of the '-o' option to the 'set' builtin
5849 (*note The Set Builtin::).
5850
5851 '-v VARNAME'
5852 True if the shell variable VARNAME is set (has been assigned a
5853 value).
5854
5855 '-R VARNAME'
5856 True if the shell variable VARNAME is set and is a name reference.
5857
5858 '-z STRING'
5859 True if the length of STRING is zero.
5860
5861 '-n STRING'
5862 'STRING'
5863 True if the length of STRING is non-zero.
5864
5865 'STRING1 == STRING2'
5866 'STRING1 = STRING2'
5867 True if the strings are equal. When used with the '[[' command,
5868 this performs pattern matching as described above (*note
5869 Conditional Constructs::).
5870
5871 '=' should be used with the 'test' command for POSIX conformance.
5872
5873 'STRING1 != STRING2'
5874 True if the strings are not equal.
5875
5876 'STRING1 < STRING2'
5877 True if STRING1 sorts before STRING2 lexicographically.
5878
5879 'STRING1 > STRING2'
5880 True if STRING1 sorts after STRING2 lexicographically.
5881
5882 'ARG1 OP ARG2'
5883 'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'. These
5884 arithmetic binary operators return true if ARG1 is equal to, not
5885 equal to, less than, less than or equal to, greater than, or
5886 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
5887 positive or negative integers.
5888
5889 \1f
5890 File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
5891
5892 6.5 Shell Arithmetic
5893 ====================
5894
5895 The shell allows arithmetic expressions to be evaluated, as one of the
5896 shell expansions or by using the '((' compound command, the 'let'
5897 builtin, or the '-i' option to the 'declare' builtin.
5898
5899 Evaluation is done in fixed-width integers with no check for
5900 overflow, though division by 0 is trapped and flagged as an error. The
5901 operators and their precedence, associativity, and values are the same
5902 as in the C language. The following list of operators is grouped into
5903 levels of equal-precedence operators. The levels are listed in order of
5904 decreasing precedence.
5905
5906 'ID++ ID--'
5907 variable post-increment and post-decrement
5908
5909 '++ID --ID'
5910 variable pre-increment and pre-decrement
5911
5912 '- +'
5913 unary minus and plus
5914
5915 '! ~'
5916 logical and bitwise negation
5917
5918 '**'
5919 exponentiation
5920
5921 '* / %'
5922 multiplication, division, remainder
5923
5924 '+ -'
5925 addition, subtraction
5926
5927 '<< >>'
5928 left and right bitwise shifts
5929
5930 '<= >= < >'
5931 comparison
5932
5933 '== !='
5934 equality and inequality
5935
5936 '&'
5937 bitwise AND
5938
5939 '^'
5940 bitwise exclusive OR
5941
5942 '|'
5943 bitwise OR
5944
5945 '&&'
5946 logical AND
5947
5948 '||'
5949 logical OR
5950
5951 'expr ? expr : expr'
5952 conditional operator
5953
5954 '= *= /= %= += -= <<= >>= &= ^= |='
5955 assignment
5956
5957 'expr1 , expr2'
5958 comma
5959
5960 Shell variables are allowed as operands; parameter expansion is
5961 performed before the expression is evaluated. Within an expression,
5962 shell variables may also be referenced by name without using the
5963 parameter expansion syntax. A shell variable that is null or unset
5964 evaluates to 0 when referenced by name without using the parameter
5965 expansion syntax. The value of a variable is evaluated as an arithmetic
5966 expression when it is referenced, or when a variable which has been
5967 given the INTEGER attribute using 'declare -i' is assigned a value. A
5968 null value evaluates to 0. A shell variable need not have its INTEGER
5969 attribute turned on to be used in an expression.
5970
5971 Constants with a leading 0 are interpreted as octal numbers. A
5972 leading '0x' or '0X' denotes hexadecimal. Otherwise, numbers take the
5973 form [BASE'#']N, where the optional BASE is a decimal number between 2
5974 and 64 representing the arithmetic base, and N is a number in that base.
5975 If BASE'#' is omitted, then base 10 is used. When specifying N, the
5976 digits greater than 9 are represented by the lowercase letters, the
5977 uppercase letters, '@', and '_', in that order. If BASE is less than or
5978 equal to 36, lowercase and uppercase letters may be used interchangeably
5979 to represent numbers between 10 and 35.
5980
5981 Operators are evaluated in order of precedence. Sub-expressions in
5982 parentheses are evaluated first and may override the precedence rules
5983 above.
5984
5985 \1f
5986 File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
5987
5988 6.6 Aliases
5989 ===========
5990
5991 ALIASES allow a string to be substituted for a word when it is used as
5992 the first word of a simple command. The shell maintains a list of
5993 aliases that may be set and unset with the 'alias' and 'unalias' builtin
5994 commands.
5995
5996 The first word of each simple command, if unquoted, is checked to see
5997 if it has an alias. If so, that word is replaced by the text of the
5998 alias. The characters '/', '$', '`', '=' and any of the shell
5999 metacharacters or quoting characters listed above may not appear in an
6000 alias name. The replacement text may contain any valid shell input,
6001 including shell metacharacters. The first word of the replacement text
6002 is tested for aliases, but a word that is identical to an alias being
6003 expanded is not expanded a second time. This means that one may alias
6004 'ls' to '"ls -F"', for instance, and Bash does not try to recursively
6005 expand the replacement text. If the last character of the alias value
6006 is a BLANK, then the next command word following the alias is also
6007 checked for alias expansion.
6008
6009 Aliases are created and listed with the 'alias' command, and removed
6010 with the 'unalias' command.
6011
6012 There is no mechanism for using arguments in the replacement text, as
6013 in 'csh'. If arguments are needed, a shell function should be used
6014 (*note Shell Functions::).
6015
6016 Aliases are not expanded when the shell is not interactive, unless
6017 the 'expand_aliases' shell option is set using 'shopt' (*note The Shopt
6018 Builtin::).
6019
6020 The rules concerning the definition and use of aliases are somewhat
6021 confusing. Bash always reads at least one complete line of input before
6022 executing any of the commands on that line. Aliases are expanded when a
6023 command is read, not when it is executed. Therefore, an alias
6024 definition appearing on the same line as another command does not take
6025 effect until the next line of input is read. The commands following the
6026 alias definition on that line are not affected by the new alias. This
6027 behavior is also an issue when functions are executed. Aliases are
6028 expanded when a function definition is read, not when the function is
6029 executed, because a function definition is itself a command. As a
6030 consequence, aliases defined in a function are not available until after
6031 that function is executed. To be safe, always put alias definitions on
6032 a separate line, and do not use 'alias' in compound commands.
6033
6034 For almost every purpose, shell functions are preferred over aliases.
6035
6036 \1f
6037 File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
6038
6039 6.7 Arrays
6040 ==========
6041
6042 Bash provides one-dimensional indexed and associative array variables.
6043 Any variable may be used as an indexed array; the 'declare' builtin will
6044 explicitly declare an array. There is no maximum limit on the size of
6045 an array, nor any requirement that members be indexed or assigned
6046 contiguously. Indexed arrays are referenced using integers (including
6047 arithmetic expressions (*note Shell Arithmetic::)) and are zero-based;
6048 associative arrays use arbitrary strings. Unless otherwise noted,
6049 indexed array indices must be non-negative integers.
6050
6051 An indexed array is created automatically if any variable is assigned
6052 to using the syntax
6053 NAME[SUBSCRIPT]=VALUE
6054
6055 The SUBSCRIPT is treated as an arithmetic expression that must evaluate
6056 to a number. To explicitly declare an array, use
6057 declare -a NAME
6058 The syntax
6059 declare -a NAME[SUBSCRIPT]
6060 is also accepted; the SUBSCRIPT is ignored.
6061
6062 Associative arrays are created using
6063 declare -A NAME.
6064
6065 Attributes may be specified for an array variable using the 'declare'
6066 and 'readonly' builtins. Each attribute applies to all members of an
6067 array.
6068
6069 Arrays are assigned to using compound assignments of the form
6070 NAME=(VALUE1 VALUE2 ... )
6071 where each VALUE is of the form '[SUBSCRIPT]='STRING. Indexed array
6072 assignments do not require anything but STRING. When assigning to
6073 indexed arrays, if the optional subscript is supplied, that index is
6074 assigned to; otherwise the index of the element assigned is the last
6075 index assigned to by the statement plus one. Indexing starts at zero.
6076
6077 When assigning to an associative array, the subscript is required.
6078
6079 This syntax is also accepted by the 'declare' builtin. Individual
6080 array elements may be assigned to using the 'NAME[SUBSCRIPT]=VALUE'
6081 syntax introduced above.
6082
6083 When assigning to an indexed array, if NAME is subscripted by a
6084 negative number, that number is interpreted as relative to one greater
6085 than the maximum index of NAME, so negative indices count back from the
6086 end of the array, and an index of -1 references the last element.
6087
6088 Any element of an array may be referenced using '${NAME[SUBSCRIPT]}'.
6089 The braces are required to avoid conflicts with the shell's filename
6090 expansion operators. If the SUBSCRIPT is '@' or '*', the word expands
6091 to all members of the array NAME. These subscripts differ only when the
6092 word appears within double quotes. If the word is double-quoted,
6093 '${NAME[*]}' expands to a single word with the value of each array
6094 member separated by the first character of the 'IFS' variable, and
6095 '${NAME[@]}' expands each element of NAME to a separate word. When
6096 there are no array members, '${NAME[@]}' expands to nothing. If the
6097 double-quoted expansion occurs within a word, the expansion of the first
6098 parameter is joined with the beginning part of the original word, and
6099 the expansion of the last parameter is joined with the last part of the
6100 original word. This is analogous to the expansion of the special
6101 parameters '@' and '*'. '${#NAME[SUBSCRIPT]}' expands to the length of
6102 '${NAME[SUBSCRIPT]}'. If SUBSCRIPT is '@' or '*', the expansion is the
6103 number of elements in the array. If the SUBSCRIPT used to reference an
6104 element of an indexed array evaluates to a number less than zero, it is
6105 interpreted as relative to one greater than the maximum index of the
6106 array, so negative indices count back from the end of the array, and an
6107 index of -1 refers to the last element.
6108
6109 Referencing an array variable without a subscript is equivalent to
6110 referencing with a subscript of 0. Any reference to a variable using a
6111 valid subscript is legal, and 'bash' will create an array if necessary.
6112
6113 An array variable is considered set if a subscript has been assigned
6114 a value. The null string is a valid value.
6115
6116 It is possible to obtain the keys (indices) of an array as well as
6117 the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned
6118 in array variable NAME. The treatment when in double quotes is similar
6119 to the expansion of the special parameters '@' and '*' within double
6120 quotes.
6121
6122 The 'unset' builtin is used to destroy arrays. 'unset
6123 NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
6124 Negative subscripts to indexed arrays are interpreted as described
6125 above. Care must be taken to avoid unwanted side effects caused by
6126 filename expansion. 'unset NAME', where NAME is an array, removes the
6127 entire array. A subscript of '*' or '@' also removes the entire array.
6128
6129 The 'declare', 'local', and 'readonly' builtins each accept a '-a'
6130 option to specify an indexed array and a '-A' option to specify an
6131 associative array. If both options are supplied, '-A' takes precedence.
6132 The 'read' builtin accepts a '-a' option to assign a list of words read
6133 from the standard input to an array, and can read values from the
6134 standard input into individual array elements. The 'set' and 'declare'
6135 builtins display array values in a way that allows them to be reused as
6136 input.
6137
6138 \1f
6139 File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
6140
6141 6.8 The Directory Stack
6142 =======================
6143
6144 * Menu:
6145
6146 * Directory Stack Builtins:: Bash builtin commands to manipulate
6147 the directory stack.
6148
6149 The directory stack is a list of recently-visited directories. The
6150 'pushd' builtin adds directories to the stack as it changes the current
6151 directory, and the 'popd' builtin removes specified directories from the
6152 stack and changes the current directory to the directory removed. The
6153 'dirs' builtin displays the contents of the directory stack. The
6154 current directory is always the "top" of the directory stack.
6155
6156 The contents of the directory stack are also visible as the value of
6157 the 'DIRSTACK' shell variable.
6158
6159 \1f
6160 File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
6161
6162 6.8.1 Directory Stack Builtins
6163 ------------------------------
6164
6165 'dirs'
6166 dirs [-clpv] [+N | -N]
6167
6168 Display the list of currently remembered directories. Directories
6169 are added to the list with the 'pushd' command; the 'popd' command
6170 removes directories from the list. The current directory is always
6171 the first directory in the stack.
6172
6173 '-c'
6174 Clears the directory stack by deleting all of the elements.
6175 '-l'
6176 Produces a listing using full pathnames; the default listing
6177 format uses a tilde to denote the home directory.
6178 '-p'
6179 Causes 'dirs' to print the directory stack with one entry per
6180 line.
6181 '-v'
6182 Causes 'dirs' to print the directory stack with one entry per
6183 line, prefixing each entry with its index in the stack.
6184 '+N'
6185 Displays the Nth directory (counting from the left of the list
6186 printed by 'dirs' when invoked without options), starting with
6187 zero.
6188 '-N'
6189 Displays the Nth directory (counting from the right of the
6190 list printed by 'dirs' when invoked without options), starting
6191 with zero.
6192
6193 'popd'
6194 popd [-n] [+N | -N]
6195
6196 When no arguments are given, 'popd' removes the top directory from
6197 the stack and performs a 'cd' to the new top directory. The
6198 elements are numbered from 0 starting at the first directory listed
6199 with 'dirs'; that is, 'popd' is equivalent to 'popd +0'.
6200
6201 '-n'
6202 Suppresses the normal change of directory when removing
6203 directories from the stack, so that only the stack is
6204 manipulated.
6205 '+N'
6206 Removes the Nth directory (counting from the left of the list
6207 printed by 'dirs'), starting with zero.
6208 '-N'
6209 Removes the Nth directory (counting from the right of the list
6210 printed by 'dirs'), starting with zero.
6211
6212 'pushd'
6213 pushd [-n] [+N | -N | DIR]
6214
6215 Save the current directory on the top of the directory stack and
6216 then 'cd' to DIR. With no arguments, 'pushd' exchanges the top two
6217 directories and makes the new top the current directory.
6218
6219 '-n'
6220 Suppresses the normal change of directory when rotating or
6221 adding directories to the stack, so that only the stack is
6222 manipulated.
6223 '+N'
6224 Brings the Nth directory (counting from the left of the list
6225 printed by 'dirs', starting with zero) to the top of the list
6226 by rotating the stack.
6227 '-N'
6228 Brings the Nth directory (counting from the right of the list
6229 printed by 'dirs', starting with zero) to the top of the list
6230 by rotating the stack.
6231 'DIR'
6232 Makes DIR be the top of the stack, making it the new current
6233 directory as if it had been supplied as an argument to the
6234 'cd' builtin.
6235
6236 \1f
6237 File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
6238
6239 6.9 Controlling the Prompt
6240 ==========================
6241
6242 The value of the variable 'PROMPT_COMMAND' is examined just before Bash
6243 prints each primary prompt. If 'PROMPT_COMMAND' is set and has a
6244 non-null value, then the value is executed just as if it had been typed
6245 on the command line.
6246
6247 In addition, the following table describes the special characters
6248 which can appear in the prompt variables 'PS1' to 'PS4':
6249
6250 '\a'
6251 A bell character.
6252 '\d'
6253 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
6254 '\D{FORMAT}'
6255 The FORMAT is passed to 'strftime'(3) and the result is inserted
6256 into the prompt string; an empty FORMAT results in a
6257 locale-specific time representation. The braces are required.
6258 '\e'
6259 An escape character.
6260 '\h'
6261 The hostname, up to the first '.'.
6262 '\H'
6263 The hostname.
6264 '\j'
6265 The number of jobs currently managed by the shell.
6266 '\l'
6267 The basename of the shell's terminal device name.
6268 '\n'
6269 A newline.
6270 '\r'
6271 A carriage return.
6272 '\s'
6273 The name of the shell, the basename of '$0' (the portion following
6274 the final slash).
6275 '\t'
6276 The time, in 24-hour HH:MM:SS format.
6277 '\T'
6278 The time, in 12-hour HH:MM:SS format.
6279 '\@'
6280 The time, in 12-hour am/pm format.
6281 '\A'
6282 The time, in 24-hour HH:MM format.
6283 '\u'
6284 The username of the current user.
6285 '\v'
6286 The version of Bash (e.g., 2.00)
6287 '\V'
6288 The release of Bash, version + patchlevel (e.g., 2.00.0)
6289 '\w'
6290 The current working directory, with '$HOME' abbreviated with a
6291 tilde (uses the '$PROMPT_DIRTRIM' variable).
6292 '\W'
6293 The basename of '$PWD', with '$HOME' abbreviated with a tilde.
6294 '\!'
6295 The history number of this command.
6296 '\#'
6297 The command number of this command.
6298 '\$'
6299 If the effective uid is 0, '#', otherwise '$'.
6300 '\NNN'
6301 The character whose ASCII code is the octal value NNN.
6302 '\\'
6303 A backslash.
6304 '\['
6305 Begin a sequence of non-printing characters. This could be used to
6306 embed a terminal control sequence into the prompt.
6307 '\]'
6308 End a sequence of non-printing characters.
6309
6310 The command number and the history number are usually different: the
6311 history number of a command is its position in the history list, which
6312 may include commands restored from the history file (*note Bash History
6313 Facilities::), while the command number is the position in the sequence
6314 of commands executed during the current shell session.
6315
6316 After the string is decoded, it is expanded via parameter expansion,
6317 command substitution, arithmetic expansion, and quote removal, subject
6318 to the value of the 'promptvars' shell option (*note Bash Builtins::).
6319
6320 \1f
6321 File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
6322
6323 6.10 The Restricted Shell
6324 =========================
6325
6326 If Bash is started with the name 'rbash', or the '--restricted' or '-r'
6327 option is supplied at invocation, the shell becomes restricted. A
6328 restricted shell is used to set up an environment more controlled than
6329 the standard shell. A restricted shell behaves identically to 'bash'
6330 with the exception that the following are disallowed or not performed:
6331
6332 * Changing directories with the 'cd' builtin.
6333 * Setting or unsetting the values of the 'SHELL', 'PATH', 'ENV', or
6334 'BASH_ENV' variables.
6335 * Specifying command names containing slashes.
6336 * Specifying a filename containing a slash as an argument to the '.'
6337 builtin command.
6338 * Specifying a filename containing a slash as an argument to the '-p'
6339 option to the 'hash' builtin command.
6340 * Importing function definitions from the shell environment at
6341 startup.
6342 * Parsing the value of 'SHELLOPTS' from the shell environment at
6343 startup.
6344 * Redirecting output using the '>', '>|', '<>', '>&', '&>', and '>>'
6345 redirection operators.
6346 * Using the 'exec' builtin to replace the shell with another command.
6347 * Adding or deleting builtin commands with the '-f' and '-d' options
6348 to the 'enable' builtin.
6349 * Using the 'enable' builtin command to enable disabled shell
6350 builtins.
6351 * Specifying the '-p' option to the 'command' builtin.
6352 * Turning off restricted mode with 'set +r' or 'set +o restricted'.
6353
6354 These restrictions are enforced after any startup files are read.
6355
6356 When a command that is found to be a shell script is executed (*note
6357 Shell Scripts::), 'rbash' turns off any restrictions in the shell
6358 spawned to execute the script.
6359
6360 \1f
6361 File: bashref.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
6362
6363 6.11 Bash POSIX Mode
6364 ====================
6365
6366 Starting Bash with the '--posix' command-line option or executing 'set
6367 -o posix' while Bash is running will cause Bash to conform more closely
6368 to the POSIX standard by changing the behavior to match that specified
6369 by POSIX in areas where the Bash default differs.
6370
6371 When invoked as 'sh', Bash enters POSIX mode after reading the
6372 startup files.
6373
6374 The following list is what's changed when 'POSIX mode' is in effect:
6375
6376 1. When a command in the hash table no longer exists, Bash will
6377 re-search '$PATH' to find the new location. This is also available
6378 with 'shopt -s checkhash'.
6379
6380 2. The message printed by the job control code and builtins when a job
6381 exits with a non-zero status is 'Done(status)'.
6382
6383 3. The message printed by the job control code and builtins when a job
6384 is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for example,
6385 'SIGTSTP'.
6386
6387 4. Alias expansion is always enabled, even in non-interactive shells.
6388
6389 5. Reserved words appearing in a context where reserved words are
6390 recognized do not undergo alias expansion.
6391
6392 6. The POSIX 'PS1' and 'PS2' expansions of '!' to the history number
6393 and '!!' to '!' are enabled, and parameter expansion is performed
6394 on the values of 'PS1' and 'PS2' regardless of the setting of the
6395 'promptvars' option.
6396
6397 7. The POSIX startup files are executed ('$ENV') rather than the
6398 normal Bash files.
6399
6400 8. Tilde expansion is only performed on assignments preceding a
6401 command name, rather than on all assignment statements on the line.
6402
6403 9. The default history file is '~/.sh_history' (this is the default
6404 value of '$HISTFILE').
6405
6406 10. Redirection operators do not perform filename expansion on the
6407 word in the redirection unless the shell is interactive.
6408
6409 11. Redirection operators do not perform word splitting on the word in
6410 the redirection.
6411
6412 12. Function names must be valid shell 'name's. That is, they may not
6413 contain characters other than letters, digits, and underscores, and
6414 may not start with a digit. Declaring a function with an invalid
6415 name causes a fatal syntax error in non-interactive shells.
6416
6417 13. Function names may not be the same as one of the POSIX special
6418 builtins.
6419
6420 14. POSIX special builtins are found before shell functions during
6421 command lookup.
6422
6423 15. When printing shell function definitions (e.g., by 'type'), Bash
6424 does not print the 'function' keyword.
6425
6426 16. Literal tildes that appear as the first character in elements of
6427 the 'PATH' variable are not expanded as described above under *note
6428 Tilde Expansion::.
6429
6430 17. The 'time' reserved word may be used by itself as a command. When
6431 used in this way, it displays timing statistics for the shell and
6432 its completed children. The 'TIMEFORMAT' variable controls the
6433 format of the timing information.
6434
6435 18. When parsing and expanding a ${...} expansion that appears within
6436 double quotes, single quotes are no longer special and cannot be
6437 used to quote a closing brace or other special character, unless
6438 the operator is one of those defined to perform pattern removal.
6439 In this case, they do not have to appear as matched pairs.
6440
6441 19. The parser does not recognize 'time' as a reserved word if the
6442 next token begins with a '-'.
6443
6444 20. The '!' character does not introduce history expansion within a
6445 double-quoted string, even if the 'histexpand' option is enabled.
6446
6447 21. If a POSIX special builtin returns an error status, a
6448 non-interactive shell exits. The fatal errors are those listed in
6449 the POSIX standard, and include things like passing incorrect
6450 options, redirection errors, variable assignment errors for
6451 assignments preceding the command name, and so on.
6452
6453 22. A non-interactive shell exits with an error status if a variable
6454 assignment error occurs when no command name follows the assignment
6455 statements. A variable assignment error occurs, for example, when
6456 trying to assign a value to a readonly variable.
6457
6458 23. A non-interactive shell exits with an error status if a variable
6459 assignment error occurs in an assignment statement preceding a
6460 special builtin, but not with any other simple command.
6461
6462 24. A non-interactive shell exits with an error status if the
6463 iteration variable in a 'for' statement or the selection variable
6464 in a 'select' statement is a readonly variable.
6465
6466 25. Non-interactive shells exit if FILENAME in '.' FILENAME is not
6467 found.
6468
6469 26. Non-interactive shells exit if a syntax error in an arithmetic
6470 expansion results in an invalid expression.
6471
6472 27. Non-interactive shells exit if a parameter expansion error occurs.
6473
6474 28. Non-interactive shells exit if there is a syntax error in a script
6475 read with the '.' or 'source' builtins, or in a string processed by
6476 the 'eval' builtin.
6477
6478 29. Process substitution is not available.
6479
6480 30. While variable indirection is available, it may not be applied to
6481 the '#' and '?' special parameters.
6482
6483 31. When expanding the '*' special parameter in a pattern context
6484 where the expansion is double-quoted does not treat the '$*' as if
6485 it were double-quoted.
6486
6487 32. Assignment statements preceding POSIX special builtins persist in
6488 the shell environment after the builtin completes.
6489
6490 33. Assignment statements preceding shell function calls persist in
6491 the shell environment after the function returns, as if a POSIX
6492 special builtin command had been executed.
6493
6494 34. The 'command' builtin does not prevent builtins that take
6495 assignment statements as arguments from expanding them as
6496 assignment statements; when not in POSIX mode, assignment builtins
6497 lose their assignment statement expansion properties when preceded
6498 by 'command'.
6499
6500 35. The 'bg' builtin uses the required format to describe each job
6501 placed in the background, which does not include an indication of
6502 whether the job is the current or previous job.
6503
6504 36. The output of 'kill -l' prints all the signal names on a single
6505 line, separated by spaces, without the 'SIG' prefix.
6506
6507 37. The 'kill' builtin does not accept signal names with a 'SIG'
6508 prefix.
6509
6510 38. The 'export' and 'readonly' builtin commands display their output
6511 in the format required by POSIX.
6512
6513 39. The 'trap' builtin displays signal names without the leading
6514 'SIG'.
6515
6516 40. The 'trap' builtin doesn't check the first argument for a possible
6517 signal specification and revert the signal handling to the original
6518 disposition if it is, unless that argument consists solely of
6519 digits and is a valid signal number. If users want to reset the
6520 handler for a given signal to the original disposition, they should
6521 use '-' as the first argument.
6522
6523 41. The '.' and 'source' builtins do not search the current directory
6524 for the filename argument if it is not found by searching 'PATH'.
6525
6526 42. Enabling POSIX mode has the effect of setting the
6527 'inherit_errexit' option, so subshells spawned to execute command
6528 substitutions inherit the value of the '-e' option from the parent
6529 shell. When the 'inherit_errexit' option is not enabled, Bash
6530 clears the '-e' option in such subshells.
6531
6532 43. When the 'alias' builtin displays alias definitions, it does not
6533 display them with a leading 'alias ' unless the '-p' option is
6534 supplied.
6535
6536 44. When the 'set' builtin is invoked without options, it does not
6537 display shell function names and definitions.
6538
6539 45. When the 'set' builtin is invoked without options, it displays
6540 variable values without quotes, unless they contain shell
6541 metacharacters, even if the result contains nonprinting characters.
6542
6543 46. When the 'cd' builtin is invoked in LOGICAL mode, and the pathname
6544 constructed from '$PWD' and the directory name supplied as an
6545 argument does not refer to an existing directory, 'cd' will fail
6546 instead of falling back to PHYSICAL mode.
6547
6548 47. The 'pwd' builtin verifies that the value it prints is the same as
6549 the current directory, even if it is not asked to check the file
6550 system with the '-P' option.
6551
6552 48. When listing the history, the 'fc' builtin does not include an
6553 indication of whether or not a history entry has been modified.
6554
6555 49. The default editor used by 'fc' is 'ed'.
6556
6557 50. The 'type' and 'command' builtins will not report a non-executable
6558 file as having been found, though the shell will attempt to execute
6559 such a file if it is the only so-named file found in '$PATH'.
6560
6561 51. The 'vi' editing mode will invoke the 'vi' editor directly when
6562 the 'v' command is run, instead of checking '$VISUAL' and
6563 '$EDITOR'.
6564
6565 52. When the 'xpg_echo' option is enabled, Bash does not attempt to
6566 interpret any arguments to 'echo' as options. Each argument is
6567 displayed, after escape characters are converted.
6568
6569 53. The 'ulimit' builtin uses a block size of 512 bytes for the '-c'
6570 and '-f' options.
6571
6572 54. The arrival of 'SIGCHLD' when a trap is set on 'SIGCHLD' does not
6573 interrupt the 'wait' builtin and cause it to return immediately.
6574 The trap command is run once for each child that exits.
6575
6576 55. The 'read' builtin may be interrupted by a signal for which a trap
6577 has been set. If Bash receives a trapped signal while executing
6578 'read', the trap handler executes and 'read' returns an exit status
6579 greater than 128.
6580
6581 56. Bash removes an exited background process's status from the list
6582 of such statuses after the 'wait' builtin is used to obtain it.
6583
6584 There is other POSIX behavior that Bash does not implement by default
6585 even when in POSIX mode. Specifically:
6586
6587 1. The 'fc' builtin checks '$EDITOR' as a program to edit history
6588 entries if 'FCEDIT' is unset, rather than defaulting directly to
6589 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset.
6590
6591 2. As noted above, Bash requires the 'xpg_echo' option to be enabled
6592 for the 'echo' builtin to be fully conformant.
6593
6594 Bash can be configured to be POSIX-conformant by default, by
6595 specifying the '--enable-strict-posix-default' to 'configure' when
6596 building (*note Optional Features::).
6597
6598 \1f
6599 File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
6600
6601 7 Job Control
6602 *************
6603
6604 This chapter discusses what job control is, how it works, and how Bash
6605 allows you to access its facilities.
6606
6607 * Menu:
6608
6609 * Job Control Basics:: How job control works.
6610 * Job Control Builtins:: Bash builtin commands used to interact
6611 with job control.
6612 * Job Control Variables:: Variables Bash uses to customize job
6613 control.
6614
6615 \1f
6616 File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
6617
6618 7.1 Job Control Basics
6619 ======================
6620
6621 Job control refers to the ability to selectively stop (suspend) the
6622 execution of processes and continue (resume) their execution at a later
6623 point. A user typically employs this facility via an interactive
6624 interface supplied jointly by the operating system kernel's terminal
6625 driver and Bash.
6626
6627 The shell associates a JOB with each pipeline. It keeps a table of
6628 currently executing jobs, which may be listed with the 'jobs' command.
6629 When Bash starts a job asynchronously, it prints a line that looks like:
6630 [1] 25647
6631 indicating that this job is job number 1 and that the process ID of the
6632 last process in the pipeline associated with this job is 25647. All of
6633 the processes in a single pipeline are members of the same job. Bash
6634 uses the JOB abstraction as the basis for job control.
6635
6636 To facilitate the implementation of the user interface to job
6637 control, the operating system maintains the notion of a current terminal
6638 process group ID. Members of this process group (processes whose
6639 process group ID is equal to the current terminal process group ID)
6640 receive keyboard-generated signals such as 'SIGINT'. These processes
6641 are said to be in the foreground. Background processes are those whose
6642 process group ID differs from the terminal's; such processes are immune
6643 to keyboard-generated signals. Only foreground processes are allowed to
6644 read from or, if the user so specifies with 'stty tostop', write to the
6645 terminal. Background processes which attempt to read from (write to
6646 when 'stty tostop' is in effect) the terminal are sent a 'SIGTTIN'
6647 ('SIGTTOU') signal by the kernel's terminal driver, which, unless
6648 caught, suspends the process.
6649
6650 If the operating system on which Bash is running supports job
6651 control, Bash contains facilities to use it. Typing the SUSPEND
6652 character (typically '^Z', Control-Z) while a process is running causes
6653 that process to be stopped and returns control to Bash. Typing the
6654 DELAYED SUSPEND character (typically '^Y', Control-Y) causes the process
6655 to be stopped when it attempts to read input from the terminal, and
6656 control to be returned to Bash. The user then manipulates the state of
6657 this job, using the 'bg' command to continue it in the background, the
6658 'fg' command to continue it in the foreground, or the 'kill' command to
6659 kill it. A '^Z' takes effect immediately, and has the additional side
6660 effect of causing pending output and typeahead to be discarded.
6661
6662 There are a number of ways to refer to a job in the shell. The
6663 character '%' introduces a job specification (JOBSPEC).
6664
6665 Job number 'n' may be referred to as '%n'. The symbols '%%' and '%+'
6666 refer to the shell's notion of the current job, which is the last job
6667 stopped while it was in the foreground or started in the background. A
6668 single '%' (with no accompanying job specification) also refers to the
6669 current job. The previous job may be referenced using '%-'. If there
6670 is only a single job, '%+' and '%-' can both be used to refer to that
6671 job. In output pertaining to jobs (e.g., the output of the 'jobs'
6672 command), the current job is always flagged with a '+', and the previous
6673 job with a '-'.
6674
6675 A job may also be referred to using a prefix of the name used to
6676 start it, or using a substring that appears in its command line. For
6677 example, '%ce' refers to a stopped 'ce' job. Using '%?ce', on the other
6678 hand, refers to any job containing the string 'ce' in its command line.
6679 If the prefix or substring matches more than one job, Bash reports an
6680 error.
6681
6682 Simply naming a job can be used to bring it into the foreground: '%1'
6683 is a synonym for 'fg %1', bringing job 1 from the background into the
6684 foreground. Similarly, '%1 &' resumes job 1 in the background,
6685 equivalent to 'bg %1'
6686
6687 The shell learns immediately whenever a job changes state. Normally,
6688 Bash waits until it is about to print a prompt before reporting changes
6689 in a job's status so as to not interrupt any other output. If the '-b'
6690 option to the 'set' builtin is enabled, Bash reports such changes
6691 immediately (*note The Set Builtin::). Any trap on 'SIGCHLD' is
6692 executed for each child process that exits.
6693
6694 If an attempt to exit Bash is made while jobs are stopped, (or
6695 running, if the 'checkjobs' option is enabled - see *note The Shopt
6696 Builtin::), the shell prints a warning message, and if the 'checkjobs'
6697 option is enabled, lists the jobs and their statuses. The 'jobs'
6698 command may then be used to inspect their status. If a second attempt
6699 to exit is made without an intervening command, Bash does not print
6700 another warning, and any stopped jobs are terminated.
6701
6702 \1f
6703 File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
6704
6705 7.2 Job Control Builtins
6706 ========================
6707
6708 'bg'
6709 bg [JOBSPEC ...]
6710
6711 Resume each suspended job JOBSPEC in the background, as if it had
6712 been started with '&'. If JOBSPEC is not supplied, the current job
6713 is used. The return status is zero unless it is run when job
6714 control is not enabled, or, when run with job control enabled, any
6715 JOBSPEC was not found or specifies a job that was started without
6716 job control.
6717
6718 'fg'
6719 fg [JOBSPEC]
6720
6721 Resume the job JOBSPEC in the foreground and make it the current
6722 job. If JOBSPEC is not supplied, the current job is used. The
6723 return status is that of the command placed into the foreground, or
6724 non-zero if run when job control is disabled or, when run with job
6725 control enabled, JOBSPEC does not specify a valid job or JOBSPEC
6726 specifies a job that was started without job control.
6727
6728 'jobs'
6729 jobs [-lnprs] [JOBSPEC]
6730 jobs -x COMMAND [ARGUMENTS]
6731
6732 The first form lists the active jobs. The options have the
6733 following meanings:
6734
6735 '-l'
6736 List process IDs in addition to the normal information.
6737
6738 '-n'
6739 Display information only about jobs that have changed status
6740 since the user was last notified of their status.
6741
6742 '-p'
6743 List only the process ID of the job's process group leader.
6744
6745 '-r'
6746 Display only running jobs.
6747
6748 '-s'
6749 Display only stopped jobs.
6750
6751 If JOBSPEC is given, output is restricted to information about that
6752 job. If JOBSPEC is not supplied, the status of all jobs is listed.
6753
6754 If the '-x' option is supplied, 'jobs' replaces any JOBSPEC found
6755 in COMMAND or ARGUMENTS with the corresponding process group ID,
6756 and executes COMMAND, passing it ARGUMENTs, returning its exit
6757 status.
6758
6759 'kill'
6760 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
6761 kill -l|-L [EXIT_STATUS]
6762
6763 Send a signal specified by SIGSPEC or SIGNUM to the process named
6764 by job specification JOBSPEC or process ID PID. SIGSPEC is either
6765 a case-insensitive signal name such as 'SIGINT' (with or without
6766 the 'SIG' prefix) or a signal number; SIGNUM is a signal number.
6767 If SIGSPEC and SIGNUM are not present, 'SIGTERM' is used. The '-l'
6768 option lists the signal names. If any arguments are supplied when
6769 '-l' is given, the names of the signals corresponding to the
6770 arguments are listed, and the return status is zero. EXIT_STATUS
6771 is a number specifying a signal number or the exit status of a
6772 process terminated by a signal. The '-L' option is equivalent to
6773 '-l'. The return status is zero if at least one signal was
6774 successfully sent, or non-zero if an error occurs or an invalid
6775 option is encountered.
6776
6777 'wait'
6778 wait [-n] [JOBSPEC or PID ...]
6779
6780 Wait until the child process specified by each process ID PID or
6781 job specification JOBSPEC exits and return the exit status of the
6782 last command waited for. If a job spec is given, all processes in
6783 the job are waited for. If no arguments are given, all currently
6784 active child processes are waited for, and the return status is
6785 zero. If the '-n' option is supplied, 'wait' waits for any job to
6786 terminate and returns its exit status. If neither JOBSPEC nor PID
6787 specifies an active child process of the shell, the return status
6788 is 127.
6789
6790 'disown'
6791 disown [-ar] [-h] [JOBSPEC ... | PID ... ]
6792
6793 Without options, remove each JOBSPEC from the table of active jobs.
6794 If the '-h' option is given, the job is not removed from the table,
6795 but is marked so that 'SIGHUP' is not sent to the job if the shell
6796 receives a 'SIGHUP'. If JOBSPEC is not present, and neither the
6797 '-a' nor the '-r' option is supplied, the current job is used. If
6798 no JOBSPEC is supplied, the '-a' option means to remove or mark all
6799 jobs; the '-r' option without a JOBSPEC argument restricts
6800 operation to running jobs.
6801
6802 'suspend'
6803 suspend [-f]
6804
6805 Suspend the execution of this shell until it receives a 'SIGCONT'
6806 signal. A login shell cannot be suspended; the '-f' option can be
6807 used to override this and force the suspension.
6808
6809 When job control is not active, the 'kill' and 'wait' builtins do not
6810 accept JOBSPEC arguments. They must be supplied process IDs.
6811
6812 \1f
6813 File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
6814
6815 7.3 Job Control Variables
6816 =========================
6817
6818 'auto_resume'
6819 This variable controls how the shell interacts with the user and
6820 job control. If this variable exists then single word simple
6821 commands without redirections are treated as candidates for
6822 resumption of an existing job. There is no ambiguity allowed; if
6823 there is more than one job beginning with the string typed, then
6824 the most recently accessed job will be selected. The name of a
6825 stopped job, in this context, is the command line used to start it.
6826 If this variable is set to the value 'exact', the string supplied
6827 must match the name of a stopped job exactly; if set to
6828 'substring', the string supplied needs to match a substring of the
6829 name of a stopped job. The 'substring' value provides
6830 functionality analogous to the '%?' job ID (*note Job Control
6831 Basics::). If set to any other value, the supplied string must be
6832 a prefix of a stopped job's name; this provides functionality
6833 analogous to the '%' job ID.
6834
6835 \1f
6836 File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
6837
6838 8 Command Line Editing
6839 **********************
6840
6841 This chapter describes the basic features of the GNU command line
6842 editing interface. Command line editing is provided by the Readline
6843 library, which is used by several different programs, including Bash.
6844 Command line editing is enabled by default when using an interactive
6845 shell, unless the '--noediting' option is supplied at shell invocation.
6846 Line editing is also used when using the '-e' option to the 'read'
6847 builtin command (*note Bash Builtins::). By default, the line editing
6848 commands are similar to those of Emacs. A vi-style line editing
6849 interface is also available. Line editing can be enabled at any time
6850 using the '-o emacs' or '-o vi' options to the 'set' builtin command
6851 (*note The Set Builtin::), or disabled using the '+o emacs' or '+o vi'
6852 options to 'set'.
6853
6854 * Menu:
6855
6856 * Introduction and Notation:: Notation used in this text.
6857 * Readline Interaction:: The minimum set of commands for editing a line.
6858 * Readline Init File:: Customizing Readline from a user's view.
6859 * Bindable Readline Commands:: A description of most of the Readline commands
6860 available for binding
6861 * Readline vi Mode:: A short description of how to make Readline
6862 behave like the vi editor.
6863 * Programmable Completion:: How to specify the possible completions for
6864 a specific command.
6865 * Programmable Completion Builtins:: Builtin commands to specify how to
6866 complete arguments for a particular command.
6867 * A Programmable Completion Example:: An example shell function for
6868 generating possible completions.
6869
6870 \1f
6871 File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
6872
6873 8.1 Introduction to Line Editing
6874 ================================
6875
6876 The following paragraphs describe the notation used to represent
6877 keystrokes.
6878
6879 The text 'C-k' is read as 'Control-K' and describes the character
6880 produced when the <k> key is pressed while the Control key is depressed.
6881
6882 The text 'M-k' is read as 'Meta-K' and describes the character
6883 produced when the Meta key (if you have one) is depressed, and the <k>
6884 key is pressed. The Meta key is labeled <ALT> on many keyboards. On
6885 keyboards with two keys labeled <ALT> (usually to either side of the
6886 space bar), the <ALT> on the left side is generally set to work as a
6887 Meta key. The <ALT> key on the right may also be configured to work as
6888 a Meta key or may be configured as some other modifier, such as a
6889 Compose key for typing accented characters.
6890
6891 If you do not have a Meta or <ALT> key, or another key working as a
6892 Meta key, the identical keystroke can be generated by typing <ESC>
6893 _first_, and then typing <k>. Either process is known as "metafying"
6894 the <k> key.
6895
6896 The text 'M-C-k' is read as 'Meta-Control-k' and describes the
6897 character produced by "metafying" 'C-k'.
6898
6899 In addition, several keys have their own names. Specifically, <DEL>,
6900 <ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen
6901 in this text, or in an init file (*note Readline Init File::). If your
6902 keyboard lacks a <LFD> key, typing <C-j> will produce the desired
6903 character. The <RET> key may be labeled <Return> or <Enter> on some
6904 keyboards.
6905
6906 \1f
6907 File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
6908
6909 8.2 Readline Interaction
6910 ========================
6911
6912 Often during an interactive session you type in a long line of text,
6913 only to notice that the first word on the line is misspelled. The
6914 Readline library gives you a set of commands for manipulating the text
6915 as you type it in, allowing you to just fix your typo, and not forcing
6916 you to retype the majority of the line. Using these editing commands,
6917 you move the cursor to the place that needs correction, and delete or
6918 insert the text of the corrections. Then, when you are satisfied with
6919 the line, you simply press <RET>. You do not have to be at the end of
6920 the line to press <RET>; the entire line is accepted regardless of the
6921 location of the cursor within the line.
6922
6923 * Menu:
6924
6925 * Readline Bare Essentials:: The least you need to know about Readline.
6926 * Readline Movement Commands:: Moving about the input line.
6927 * Readline Killing Commands:: How to delete text, and how to get it back!
6928 * Readline Arguments:: Giving numeric arguments to commands.
6929 * Searching:: Searching through previous lines.
6930
6931 \1f
6932 File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
6933
6934 8.2.1 Readline Bare Essentials
6935 ------------------------------
6936
6937 In order to enter characters into the line, simply type them. The typed
6938 character appears where the cursor was, and then the cursor moves one
6939 space to the right. If you mistype a character, you can use your erase
6940 character to back up and delete the mistyped character.
6941
6942 Sometimes you may mistype a character, and not notice the error until
6943 you have typed several other characters. In that case, you can type
6944 'C-b' to move the cursor to the left, and then correct your mistake.
6945 Afterwards, you can move the cursor to the right with 'C-f'.
6946
6947 When you add text in the middle of a line, you will notice that
6948 characters to the right of the cursor are 'pushed over' to make room for
6949 the text that you have inserted. Likewise, when you delete text behind
6950 the cursor, characters to the right of the cursor are 'pulled back' to
6951 fill in the blank space created by the removal of the text. A list of
6952 the bare essentials for editing the text of an input line follows.
6953
6954 'C-b'
6955 Move back one character.
6956 'C-f'
6957 Move forward one character.
6958 <DEL> or <Backspace>
6959 Delete the character to the left of the cursor.
6960 'C-d'
6961 Delete the character underneath the cursor.
6962 Printing characters
6963 Insert the character into the line at the cursor.
6964 'C-_' or 'C-x C-u'
6965 Undo the last editing command. You can undo all the way back to an
6966 empty line.
6967
6968 (Depending on your configuration, the <Backspace> key be set to delete
6969 the character to the left of the cursor and the <DEL> key set to delete
6970 the character underneath the cursor, like 'C-d', rather than the
6971 character to the left of the cursor.)
6972
6973 \1f
6974 File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
6975
6976 8.2.2 Readline Movement Commands
6977 --------------------------------
6978
6979 The above table describes the most basic keystrokes that you need in
6980 order to do editing of the input line. For your convenience, many other
6981 commands have been added in addition to 'C-b', 'C-f', 'C-d', and <DEL>.
6982 Here are some commands for moving more rapidly about the line.
6983
6984 'C-a'
6985 Move to the start of the line.
6986 'C-e'
6987 Move to the end of the line.
6988 'M-f'
6989 Move forward a word, where a word is composed of letters and
6990 digits.
6991 'M-b'
6992 Move backward a word.
6993 'C-l'
6994 Clear the screen, reprinting the current line at the top.
6995
6996 Notice how 'C-f' moves forward a character, while 'M-f' moves forward
6997 a word. It is a loose convention that control keystrokes operate on
6998 characters while meta keystrokes operate on words.
6999
7000 \1f
7001 File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
7002
7003 8.2.3 Readline Killing Commands
7004 -------------------------------
7005
7006 "Killing" text means to delete the text from the line, but to save it
7007 away for later use, usually by "yanking" (re-inserting) it back into the
7008 line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.)
7009
7010 If the description for a command says that it 'kills' text, then you
7011 can be sure that you can get the text back in a different (or the same)
7012 place later.
7013
7014 When you use a kill command, the text is saved in a "kill-ring". Any
7015 number of consecutive kills save all of the killed text together, so
7016 that when you yank it back, you get it all. The kill ring is not line
7017 specific; the text that you killed on a previously typed line is
7018 available to be yanked back later, when you are typing another line.
7019
7020 Here is the list of commands for killing text.
7021
7022 'C-k'
7023 Kill the text from the current cursor position to the end of the
7024 line.
7025
7026 'M-d'
7027 Kill from the cursor to the end of the current word, or, if between
7028 words, to the end of the next word. Word boundaries are the same
7029 as those used by 'M-f'.
7030
7031 'M-<DEL>'
7032 Kill from the cursor the start of the current word, or, if between
7033 words, to the start of the previous word. Word boundaries are the
7034 same as those used by 'M-b'.
7035
7036 'C-w'
7037 Kill from the cursor to the previous whitespace. This is different
7038 than 'M-<DEL>' because the word boundaries differ.
7039
7040 Here is how to "yank" the text back into the line. Yanking means to
7041 copy the most-recently-killed text from the kill buffer.
7042
7043 'C-y'
7044 Yank the most recently killed text back into the buffer at the
7045 cursor.
7046
7047 'M-y'
7048 Rotate the kill-ring, and yank the new top. You can only do this
7049 if the prior command is 'C-y' or 'M-y'.
7050
7051 \1f
7052 File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
7053
7054 8.2.4 Readline Arguments
7055 ------------------------
7056
7057 You can pass numeric arguments to Readline commands. Sometimes the
7058 argument acts as a repeat count, other times it is the sign of the
7059 argument that is significant. If you pass a negative argument to a
7060 command which normally acts in a forward direction, that command will
7061 act in a backward direction. For example, to kill text back to the
7062 start of the line, you might type 'M-- C-k'.
7063
7064 The general way to pass numeric arguments to a command is to type
7065 meta digits before the command. If the first 'digit' typed is a minus
7066 sign ('-'), then the sign of the argument will be negative. Once you
7067 have typed one meta digit to get the argument started, you can type the
7068 remainder of the digits, and then the command. For example, to give the
7069 'C-d' command an argument of 10, you could type 'M-1 0 C-d', which will
7070 delete the next ten characters on the input line.
7071
7072 \1f
7073 File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
7074
7075 8.2.5 Searching for Commands in the History
7076 -------------------------------------------
7077
7078 Readline provides commands for searching through the command history
7079 (*note Bash History Facilities::) for lines containing a specified
7080 string. There are two search modes: "incremental" and
7081 "non-incremental".
7082
7083 Incremental searches begin before the user has finished typing the
7084 search string. As each character of the search string is typed,
7085 Readline displays the next entry from the history matching the string
7086 typed so far. An incremental search requires only as many characters as
7087 needed to find the desired history entry. To search backward in the
7088 history for a particular string, type 'C-r'. Typing 'C-s' searches
7089 forward through the history. The characters present in the value of the
7090 'isearch-terminators' variable are used to terminate an incremental
7091 search. If that variable has not been assigned a value, the <ESC> and
7092 'C-J' characters will terminate an incremental search. 'C-g' will abort
7093 an incremental search and restore the original line. When the search is
7094 terminated, the history entry containing the search string becomes the
7095 current line.
7096
7097 To find other matching entries in the history list, type 'C-r' or
7098 'C-s' as appropriate. This will search backward or forward in the
7099 history for the next entry matching the search string typed so far. Any
7100 other key sequence bound to a Readline command will terminate the search
7101 and execute that command. For instance, a <RET> will terminate the
7102 search and accept the line, thereby executing the command from the
7103 history list. A movement command will terminate the search, make the
7104 last line found the current line, and begin editing.
7105
7106 Readline remembers the last incremental search string. If two 'C-r's
7107 are typed without any intervening characters defining a new search
7108 string, any remembered search string is used.
7109
7110 Non-incremental searches read the entire search string before
7111 starting to search for matching history lines. The search string may be
7112 typed by the user or be part of the contents of the current line.
7113
7114 \1f
7115 File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
7116
7117 8.3 Readline Init File
7118 ======================
7119
7120 Although the Readline library comes with a set of Emacs-like keybindings
7121 installed by default, it is possible to use a different set of
7122 keybindings. Any user can customize programs that use Readline by
7123 putting commands in an "inputrc" file, conventionally in his home
7124 directory. The name of this file is taken from the value of the shell
7125 variable 'INPUTRC'. If that variable is unset, the default is
7126 '~/.inputrc'. If that file does not exist or cannot be read, the
7127 ultimate default is '/etc/inputrc'.
7128
7129 When a program which uses the Readline library starts up, the init
7130 file is read, and the key bindings are set.
7131
7132 In addition, the 'C-x C-r' command re-reads this init file, thus
7133 incorporating any changes that you might have made to it.
7134
7135 * Menu:
7136
7137 * Readline Init File Syntax:: Syntax for the commands in the inputrc file.
7138
7139 * Conditional Init Constructs:: Conditional key bindings in the inputrc file.
7140
7141 * Sample Init File:: An example inputrc file.
7142
7143 \1f
7144 File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
7145
7146 8.3.1 Readline Init File Syntax
7147 -------------------------------
7148
7149 There are only a few basic constructs allowed in the Readline init file.
7150 Blank lines are ignored. Lines beginning with a '#' are comments.
7151 Lines beginning with a '$' indicate conditional constructs (*note
7152 Conditional Init Constructs::). Other lines denote variable settings
7153 and key bindings.
7154
7155 Variable Settings
7156 You can modify the run-time behavior of Readline by altering the
7157 values of variables in Readline using the 'set' command within the
7158 init file. The syntax is simple:
7159
7160 set VARIABLE VALUE
7161
7162 Here, for example, is how to change from the default Emacs-like key
7163 binding to use 'vi' line editing commands:
7164
7165 set editing-mode vi
7166
7167 Variable names and values, where appropriate, are recognized
7168 without regard to case. Unrecognized variable names are ignored.
7169
7170 Boolean variables (those that can be set to on or off) are set to
7171 on if the value is null or empty, ON (case-insensitive), or 1. Any
7172 other value results in the variable being set to off.
7173
7174 The 'bind -V' command lists the current Readline variable names and
7175 values. *Note Bash Builtins::.
7176
7177 A great deal of run-time behavior is changeable with the following
7178 variables.
7179
7180 'bell-style'
7181 Controls what happens when Readline wants to ring the terminal
7182 bell. If set to 'none', Readline never rings the bell. If
7183 set to 'visible', Readline uses a visible bell if one is
7184 available. If set to 'audible' (the default), Readline
7185 attempts to ring the terminal's bell.
7186
7187 'bind-tty-special-chars'
7188 If set to 'on' (the default), Readline attempts to bind the
7189 control characters treated specially by the kernel's terminal
7190 driver to their Readline equivalents.
7191
7192 'blink-matching-paren'
7193 If set to 'on', Readline attempts to briefly move the cursor
7194 to an opening parenthesis when a closing parenthesis is
7195 inserted. The default is 'off'.
7196
7197 'colored-completion-prefix'
7198 If set to 'on', when listing completions, Readline displays
7199 the common prefix of the set of possible completions using a
7200 different color. The color definitions are taken from the
7201 value of the 'LS_COLORS' environment variable. The default is
7202 'off'.
7203
7204 'colored-stats'
7205 If set to 'on', Readline displays possible completions using
7206 different colors to indicate their file type. The color
7207 definitions are taken from the value of the 'LS_COLORS'
7208 environment variable. The default is 'off'.
7209
7210 'comment-begin'
7211 The string to insert at the beginning of the line when the
7212 'insert-comment' command is executed. The default value is
7213 '"#"'.
7214
7215 'completion-display-width'
7216 The number of screen columns used to display possible matches
7217 when performing completion. The value is ignored if it is
7218 less than 0 or greater than the terminal screen width. A
7219 value of 0 will cause matches to be displayed one per line.
7220 The default value is -1.
7221
7222 'completion-ignore-case'
7223 If set to 'on', Readline performs filename matching and
7224 completion in a case-insensitive fashion. The default value
7225 is 'off'.
7226
7227 'completion-map-case'
7228 If set to 'on', and COMPLETION-IGNORE-CASE is enabled,
7229 Readline treats hyphens ('-') and underscores ('_') as
7230 equivalent when performing case-insensitive filename matching
7231 and completion.
7232
7233 'completion-prefix-display-length'
7234 The length in characters of the common prefix of a list of
7235 possible completions that is displayed without modification.
7236 When set to a value greater than zero, common prefixes longer
7237 than this value are replaced with an ellipsis when displaying
7238 possible completions.
7239
7240 'completion-query-items'
7241 The number of possible completions that determines when the
7242 user is asked whether the list of possibilities should be
7243 displayed. If the number of possible completions is greater
7244 than this value, Readline will ask the user whether or not he
7245 wishes to view them; otherwise, they are simply listed. This
7246 variable must be set to an integer value greater than or equal
7247 to 0. A negative value means Readline should never ask. The
7248 default limit is '100'.
7249
7250 'convert-meta'
7251 If set to 'on', Readline will convert characters with the
7252 eighth bit set to an ASCII key sequence by stripping the
7253 eighth bit and prefixing an <ESC> character, converting them
7254 to a meta-prefixed key sequence. The default value is 'on',
7255 but will be set to 'off' if the locale is one that contains
7256 eight-bit characters.
7257
7258 'disable-completion'
7259 If set to 'On', Readline will inhibit word completion.
7260 Completion characters will be inserted into the line as if
7261 they had been mapped to 'self-insert'. The default is 'off'.
7262
7263 'echo-control-characters'
7264 When set to 'on', on operating systems that indicate they
7265 support it, readline echoes a character corresponding to a
7266 signal generated from the keyboard. The default is 'on'.
7267
7268 'editing-mode'
7269 The 'editing-mode' variable controls which default set of key
7270 bindings is used. By default, Readline starts up in Emacs
7271 editing mode, where the keystrokes are most similar to Emacs.
7272 This variable can be set to either 'emacs' or 'vi'.
7273
7274 'emacs-mode-string'
7275 This string is displayed immediately before the last line of
7276 the primary prompt when emacs editing mode is active. The
7277 value is expanded like a key binding, so the standard set of
7278 meta- and control prefixes and backslash escape sequences is
7279 available. Use the '\1' and '\2' escapes to begin and end
7280 sequences of non-printing characters, which can be used to
7281 embed a terminal control sequence into the mode string. The
7282 default is '@'.
7283
7284 'enable-bracketed-paste'
7285 When set to 'On', Readline will configure the terminal in a
7286 way that will enable it to insert each paste into the editing
7287 buffer as a single string of characters, instead of treating
7288 each character as if it had been read from the keyboard. This
7289 can prevent pasted characters from being interpreted as
7290 editing commands. The default is 'off'.
7291
7292 'enable-keypad'
7293 When set to 'on', Readline will try to enable the application
7294 keypad when it is called. Some systems need this to enable
7295 the arrow keys. The default is 'off'.
7296
7297 'enable-meta-key'
7298 When set to 'on', Readline will try to enable any meta
7299 modifier key the terminal claims to support when it is called.
7300 On many terminals, the meta key is used to send eight-bit
7301 characters. The default is 'on'.
7302
7303 'expand-tilde'
7304 If set to 'on', tilde expansion is performed when Readline
7305 attempts word completion. The default is 'off'.
7306
7307 'history-preserve-point'
7308 If set to 'on', the history code attempts to place the point
7309 (the current cursor position) at the same location on each
7310 history line retrieved with 'previous-history' or
7311 'next-history'. The default is 'off'.
7312
7313 'history-size'
7314 Set the maximum number of history entries saved in the history
7315 list. If set to zero, any existing history entries are
7316 deleted and no new entries are saved. If set to a value less
7317 than zero, the number of history entries is not limited. By
7318 default, the number of history entries is not limited. If an
7319 attempt is made to set HISTORY-SIZE to a non-numeric value,
7320 the maximum number of history entries will be set to 500.
7321
7322 'horizontal-scroll-mode'
7323 This variable can be set to either 'on' or 'off'. Setting it
7324 to 'on' means that the text of the lines being edited will
7325 scroll horizontally on a single screen line when they are
7326 longer than the width of the screen, instead of wrapping onto
7327 a new screen line. By default, this variable is set to 'off'.
7328
7329 'input-meta'
7330 If set to 'on', Readline will enable eight-bit input (it will
7331 not clear the eighth bit in the characters it reads),
7332 regardless of what the terminal claims it can support. The
7333 default value is 'off', but Readline will set it to 'on' if
7334 the locale contains eight-bit characters. The name
7335 'meta-flag' is a synonym for this variable.
7336
7337 'isearch-terminators'
7338 The string of characters that should terminate an incremental
7339 search without subsequently executing the character as a
7340 command (*note Searching::). If this variable has not been
7341 given a value, the characters <ESC> and 'C-J' will terminate
7342 an incremental search.
7343
7344 'keymap'
7345 Sets Readline's idea of the current keymap for key binding
7346 commands. Acceptable 'keymap' names are 'emacs',
7347 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
7348 'vi-command', and 'vi-insert'. 'vi' is equivalent to
7349 'vi-command' ('vi-move' is also a synonym); 'emacs' is
7350 equivalent to 'emacs-standard'. The default value is 'emacs'.
7351 The value of the 'editing-mode' variable also affects the
7352 default keymap.
7353
7354 'keyseq-timeout'
7355 Specifies the duration Readline will wait for a character when
7356 reading an ambiguous key sequence (one that can form a
7357 complete key sequence using the input read so far, or can take
7358 additional input to complete a longer key sequence). If no
7359 input is received within the timeout, Readline will use the
7360 shorter but complete key sequence. Readline uses this value
7361 to determine whether or not input is available on the current
7362 input source ('rl_instream' by default). The value is
7363 specified in milliseconds, so a value of 1000 means that
7364 Readline will wait one second for additional input. If this
7365 variable is set to a value less than or equal to zero, or to a
7366 non-numeric value, Readline will wait until another key is
7367 pressed to decide which key sequence to complete. The default
7368 value is '500'.
7369
7370 'mark-directories'
7371 If set to 'on', completed directory names have a slash
7372 appended. The default is 'on'.
7373
7374 'mark-modified-lines'
7375 This variable, when set to 'on', causes Readline to display an
7376 asterisk ('*') at the start of history lines which have been
7377 modified. This variable is 'off' by default.
7378
7379 'mark-symlinked-directories'
7380 If set to 'on', completed names which are symbolic links to
7381 directories have a slash appended (subject to the value of
7382 'mark-directories'). The default is 'off'.
7383
7384 'match-hidden-files'
7385 This variable, when set to 'on', causes Readline to match
7386 files whose names begin with a '.' (hidden files) when
7387 performing filename completion. If set to 'off', the leading
7388 '.' must be supplied by the user in the filename to be
7389 completed. This variable is 'on' by default.
7390
7391 'menu-complete-display-prefix'
7392 If set to 'on', menu completion displays the common prefix of
7393 the list of possible completions (which may be empty) before
7394 cycling through the list. The default is 'off'.
7395
7396 'output-meta'
7397 If set to 'on', Readline will display characters with the
7398 eighth bit set directly rather than as a meta-prefixed escape
7399 sequence. The default is 'off', but Readline will set it to
7400 'on' if the locale contains eight-bit characters.
7401
7402 'page-completions'
7403 If set to 'on', Readline uses an internal 'more'-like pager to
7404 display a screenful of possible completions at a time. This
7405 variable is 'on' by default.
7406
7407 'print-completions-horizontally'
7408 If set to 'on', Readline will display completions with matches
7409 sorted horizontally in alphabetical order, rather than down
7410 the screen. The default is 'off'.
7411
7412 'revert-all-at-newline'
7413 If set to 'on', Readline will undo all changes to history
7414 lines before returning when 'accept-line' is executed. By
7415 default, history lines may be modified and retain individual
7416 undo lists across calls to 'readline'. The default is 'off'.
7417
7418 'show-all-if-ambiguous'
7419 This alters the default behavior of the completion functions.
7420 If set to 'on', words which have more than one possible
7421 completion cause the matches to be listed immediately instead
7422 of ringing the bell. The default value is 'off'.
7423
7424 'show-all-if-unmodified'
7425 This alters the default behavior of the completion functions
7426 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
7427 'on', words which have more than one possible completion
7428 without any possible partial completion (the possible
7429 completions don't share a common prefix) cause the matches to
7430 be listed immediately instead of ringing the bell. The
7431 default value is 'off'.
7432
7433 'show-mode-in-prompt'
7434 If set to 'on', add a character to the beginning of the prompt
7435 indicating the editing mode: emacs, vi command, or vi
7436 insertion. The mode strings are user-settable. The default
7437 value is 'off'.
7438
7439 'skip-completed-text'
7440 If set to 'on', this alters the default completion behavior
7441 when inserting a single match into the line. It's only active
7442 when performing completion in the middle of a word. If
7443 enabled, readline does not insert characters from the
7444 completion that match characters after point in the word being
7445 completed, so portions of the word following the cursor are
7446 not duplicated. For instance, if this is enabled, attempting
7447 completion when the cursor is after the 'e' in 'Makefile' will
7448 result in 'Makefile' rather than 'Makefilefile', assuming
7449 there is a single possible completion. The default value is
7450 'off'.
7451
7452 'vi-cmd-mode-string'
7453 This string is displayed immediately before the last line of
7454 the primary prompt when vi editing mode is active and in
7455 command mode. The value is expanded like a key binding, so
7456 the standard set of meta- and control prefixes and backslash
7457 escape sequences is available. Use the '\1' and '\2' escapes
7458 to begin and end sequences of non-printing characters, which
7459 can be used to embed a terminal control sequence into the mode
7460 string. The default is '(cmd)'.
7461
7462 'vi-ins-mode-string'
7463 This string is displayed immediately before the last line of
7464 the primary prompt when vi editing mode is active and in
7465 insertion mode. The value is expanded like a key binding, so
7466 the standard set of meta- and control prefixes and backslash
7467 escape sequences is available. Use the '\1' and '\2' escapes
7468 to begin and end sequences of non-printing characters, which
7469 can be used to embed a terminal control sequence into the mode
7470 string. The default is '(ins)'.
7471
7472 'visible-stats'
7473 If set to 'on', a character denoting a file's type is appended
7474 to the filename when listing possible completions. The
7475 default is 'off'.
7476
7477 Key Bindings
7478 The syntax for controlling key bindings in the init file is simple.
7479 First you need to find the name of the command that you want to
7480 change. The following sections contain tables of the command name,
7481 the default keybinding, if any, and a short description of what the
7482 command does.
7483
7484 Once you know the name of the command, simply place on a line in
7485 the init file the name of the key you wish to bind the command to,
7486 a colon, and then the name of the command. There can be no space
7487 between the key name and the colon - that will be interpreted as
7488 part of the key name. The name of the key can be expressed in
7489 different ways, depending on what you find most comfortable.
7490
7491 In addition to command names, readline allows keys to be bound to a
7492 string that is inserted when the key is pressed (a MACRO).
7493
7494 The 'bind -p' command displays Readline function names and bindings
7495 in a format that can put directly into an initialization file.
7496 *Note Bash Builtins::.
7497
7498 KEYNAME: FUNCTION-NAME or MACRO
7499 KEYNAME is the name of a key spelled out in English. For
7500 example:
7501 Control-u: universal-argument
7502 Meta-Rubout: backward-kill-word
7503 Control-o: "> output"
7504
7505 In the above example, 'C-u' is bound to the function
7506 'universal-argument', 'M-DEL' is bound to the function
7507 'backward-kill-word', and 'C-o' is bound to run the macro
7508 expressed on the right hand side (that is, to insert the text
7509 '> output' into the line).
7510
7511 A number of symbolic character names are recognized while
7512 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
7513 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
7514
7515 "KEYSEQ": FUNCTION-NAME or MACRO
7516 KEYSEQ differs from KEYNAME above in that strings denoting an
7517 entire key sequence can be specified, by placing the key
7518 sequence in double quotes. Some GNU Emacs style key escapes
7519 can be used, as in the following example, but the special
7520 character names are not recognized.
7521
7522 "\C-u": universal-argument
7523 "\C-x\C-r": re-read-init-file
7524 "\e[11~": "Function Key 1"
7525
7526 In the above example, 'C-u' is again bound to the function
7527 'universal-argument' (just as it was in the first example),
7528 ''C-x' 'C-r'' is bound to the function 're-read-init-file',
7529 and '<ESC> <[> <1> <1> <~>' is bound to insert the text
7530 'Function Key 1'.
7531
7532 The following GNU Emacs style escape sequences are available when
7533 specifying key sequences:
7534
7535 '\C-'
7536 control prefix
7537 '\M-'
7538 meta prefix
7539 '\e'
7540 an escape character
7541 '\\'
7542 backslash
7543 '\"'
7544 <">, a double quotation mark
7545 '\''
7546 <'>, a single quote or apostrophe
7547
7548 In addition to the GNU Emacs style escape sequences, a second set
7549 of backslash escapes is available:
7550
7551 '\a'
7552 alert (bell)
7553 '\b'
7554 backspace
7555 '\d'
7556 delete
7557 '\f'
7558 form feed
7559 '\n'
7560 newline
7561 '\r'
7562 carriage return
7563 '\t'
7564 horizontal tab
7565 '\v'
7566 vertical tab
7567 '\NNN'
7568 the eight-bit character whose value is the octal value NNN
7569 (one to three digits)
7570 '\xHH'
7571 the eight-bit character whose value is the hexadecimal value
7572 HH (one or two hex digits)
7573
7574 When entering the text of a macro, single or double quotes must be
7575 used to indicate a macro definition. Unquoted text is assumed to
7576 be a function name. In the macro body, the backslash escapes
7577 described above are expanded. Backslash will quote any other
7578 character in the macro text, including '"' and '''. For example,
7579 the following binding will make ''C-x' \' insert a single '\' into
7580 the line:
7581 "\C-x\\": "\\"
7582
7583 \1f
7584 File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
7585
7586 8.3.2 Conditional Init Constructs
7587 ---------------------------------
7588
7589 Readline implements a facility similar in spirit to the conditional
7590 compilation features of the C preprocessor which allows key bindings and
7591 variable settings to be performed as the result of tests. There are
7592 four parser directives used.
7593
7594 '$if'
7595 The '$if' construct allows bindings to be made based on the editing
7596 mode, the terminal being used, or the application using Readline.
7597 The text of the test extends to the end of the line; no characters
7598 are required to isolate it.
7599
7600 'mode'
7601 The 'mode=' form of the '$if' directive is used to test
7602 whether Readline is in 'emacs' or 'vi' mode. This may be used
7603 in conjunction with the 'set keymap' command, for instance, to
7604 set bindings in the 'emacs-standard' and 'emacs-ctlx' keymaps
7605 only if Readline is starting out in 'emacs' mode.
7606
7607 'term'
7608 The 'term=' form may be used to include terminal-specific key
7609 bindings, perhaps to bind the key sequences output by the
7610 terminal's function keys. The word on the right side of the
7611 '=' is tested against both the full name of the terminal and
7612 the portion of the terminal name before the first '-'. This
7613 allows 'sun' to match both 'sun' and 'sun-cmd', for instance.
7614
7615 'application'
7616 The APPLICATION construct is used to include
7617 application-specific settings. Each program using the
7618 Readline library sets the APPLICATION NAME, and you can test
7619 for a particular value. This could be used to bind key
7620 sequences to functions useful for a specific program. For
7621 instance, the following command adds a key sequence that
7622 quotes the current or previous word in Bash:
7623 $if Bash
7624 # Quote the current or previous word
7625 "\C-xq": "\eb\"\ef\""
7626 $endif
7627
7628 '$endif'
7629 This command, as seen in the previous example, terminates an '$if'
7630 command.
7631
7632 '$else'
7633 Commands in this branch of the '$if' directive are executed if the
7634 test fails.
7635
7636 '$include'
7637 This directive takes a single filename as an argument and reads
7638 commands and bindings from that file. For example, the following
7639 directive reads from '/etc/inputrc':
7640 $include /etc/inputrc
7641
7642 \1f
7643 File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
7644
7645 8.3.3 Sample Init File
7646 ----------------------
7647
7648 Here is an example of an INPUTRC file. This illustrates key binding,
7649 variable assignment, and conditional syntax.
7650
7651 # This file controls the behaviour of line input editing for
7652 # programs that use the GNU Readline library. Existing
7653 # programs include FTP, Bash, and GDB.
7654 #
7655 # You can re-read the inputrc file with C-x C-r.
7656 # Lines beginning with '#' are comments.
7657 #
7658 # First, include any system-wide bindings and variable
7659 # assignments from /etc/Inputrc
7660 $include /etc/Inputrc
7661
7662 #
7663 # Set various bindings for emacs mode.
7664
7665 set editing-mode emacs
7666
7667 $if mode=emacs
7668
7669 Meta-Control-h: backward-kill-word Text after the function name is ignored
7670
7671 #
7672 # Arrow keys in keypad mode
7673 #
7674 #"\M-OD": backward-char
7675 #"\M-OC": forward-char
7676 #"\M-OA": previous-history
7677 #"\M-OB": next-history
7678 #
7679 # Arrow keys in ANSI mode
7680 #
7681 "\M-[D": backward-char
7682 "\M-[C": forward-char
7683 "\M-[A": previous-history
7684 "\M-[B": next-history
7685 #
7686 # Arrow keys in 8 bit keypad mode
7687 #
7688 #"\M-\C-OD": backward-char
7689 #"\M-\C-OC": forward-char
7690 #"\M-\C-OA": previous-history
7691 #"\M-\C-OB": next-history
7692 #
7693 # Arrow keys in 8 bit ANSI mode
7694 #
7695 #"\M-\C-[D": backward-char
7696 #"\M-\C-[C": forward-char
7697 #"\M-\C-[A": previous-history
7698 #"\M-\C-[B": next-history
7699
7700 C-q: quoted-insert
7701
7702 $endif
7703
7704 # An old-style binding. This happens to be the default.
7705 TAB: complete
7706
7707 # Macros that are convenient for shell interaction
7708 $if Bash
7709 # edit the path
7710 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7711 # prepare to type a quoted word --
7712 # insert open and close double quotes
7713 # and move to just after the open quote
7714 "\C-x\"": "\"\"\C-b"
7715 # insert a backslash (testing backslash escapes
7716 # in sequences and macros)
7717 "\C-x\\": "\\"
7718 # Quote the current or previous word
7719 "\C-xq": "\eb\"\ef\""
7720 # Add a binding to refresh the line, which is unbound
7721 "\C-xr": redraw-current-line
7722 # Edit variable on current line.
7723 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
7724 $endif
7725
7726 # use a visible bell if one is available
7727 set bell-style visible
7728
7729 # don't strip characters to 7 bits when reading
7730 set input-meta on
7731
7732 # allow iso-latin1 characters to be inserted rather
7733 # than converted to prefix-meta sequences
7734 set convert-meta off
7735
7736 # display characters with the eighth bit set directly
7737 # rather than as meta-prefixed characters
7738 set output-meta on
7739
7740 # if there are more than 150 possible completions for
7741 # a word, ask the user if he wants to see all of them
7742 set completion-query-items 150
7743
7744 # For FTP
7745 $if Ftp
7746 "\C-xg": "get \M-?"
7747 "\C-xt": "put \M-?"
7748 "\M-.": yank-last-arg
7749 $endif
7750
7751 \1f
7752 File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
7753
7754 8.4 Bindable Readline Commands
7755 ==============================
7756
7757 * Menu:
7758
7759 * Commands For Moving:: Moving about the line.
7760 * Commands For History:: Getting at previous lines.
7761 * Commands For Text:: Commands for changing text.
7762 * Commands For Killing:: Commands for killing and yanking.
7763 * Numeric Arguments:: Specifying numeric arguments, repeat counts.
7764 * Commands For Completion:: Getting Readline to do the typing for you.
7765 * Keyboard Macros:: Saving and re-executing typed characters
7766 * Miscellaneous Commands:: Other miscellaneous commands.
7767
7768 This section describes Readline commands that may be bound to key
7769 sequences. You can list your key bindings by executing 'bind -P' or,
7770 for a more terse format, suitable for an INPUTRC file, 'bind -p'.
7771 (*Note Bash Builtins::.) Command names without an accompanying key
7772 sequence are unbound by default.
7773
7774 In the following descriptions, "point" refers to the current cursor
7775 position, and "mark" refers to a cursor position saved by the 'set-mark'
7776 command. The text between the point and mark is referred to as the
7777 "region".
7778
7779 \1f
7780 File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
7781
7782 8.4.1 Commands For Moving
7783 -------------------------
7784
7785 'beginning-of-line (C-a)'
7786 Move to the start of the current line.
7787
7788 'end-of-line (C-e)'
7789 Move to the end of the line.
7790
7791 'forward-char (C-f)'
7792 Move forward a character.
7793
7794 'backward-char (C-b)'
7795 Move back a character.
7796
7797 'forward-word (M-f)'
7798 Move forward to the end of the next word. Words are composed of
7799 letters and digits.
7800
7801 'backward-word (M-b)'
7802 Move back to the start of the current or previous word. Words are
7803 composed of letters and digits.
7804
7805 'shell-forward-word ()'
7806 Move forward to the end of the next word. Words are delimited by
7807 non-quoted shell metacharacters.
7808
7809 'shell-backward-word ()'
7810 Move back to the start of the current or previous word. Words are
7811 delimited by non-quoted shell metacharacters.
7812
7813 'clear-screen (C-l)'
7814 Clear the screen and redraw the current line, leaving the current
7815 line at the top of the screen.
7816
7817 'redraw-current-line ()'
7818 Refresh the current line. By default, this is unbound.
7819
7820 \1f
7821 File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
7822
7823 8.4.2 Commands For Manipulating The History
7824 -------------------------------------------
7825
7826 'accept-line (Newline or Return)'
7827 Accept the line regardless of where the cursor is. If this line is
7828 non-empty, add it to the history list according to the setting of
7829 the 'HISTCONTROL' and 'HISTIGNORE' variables. If this line is a
7830 modified history line, then restore the history line to its
7831 original state.
7832
7833 'previous-history (C-p)'
7834 Move 'back' through the history list, fetching the previous
7835 command.
7836
7837 'next-history (C-n)'
7838 Move 'forward' through the history list, fetching the next command.
7839
7840 'beginning-of-history (M-<)'
7841 Move to the first line in the history.
7842
7843 'end-of-history (M->)'
7844 Move to the end of the input history, i.e., the line currently
7845 being entered.
7846
7847 'reverse-search-history (C-r)'
7848 Search backward starting at the current line and moving 'up'
7849 through the history as necessary. This is an incremental search.
7850
7851 'forward-search-history (C-s)'
7852 Search forward starting at the current line and moving 'down'
7853 through the history as necessary. This is an incremental search.
7854
7855 'non-incremental-reverse-search-history (M-p)'
7856 Search backward starting at the current line and moving 'up'
7857 through the history as necessary using a non-incremental search for
7858 a string supplied by the user. The search string may match
7859 anywhere in a history line.
7860
7861 'non-incremental-forward-search-history (M-n)'
7862 Search forward starting at the current line and moving 'down'
7863 through the history as necessary using a non-incremental search for
7864 a string supplied by the user. The search string may match
7865 anywhere in a history line.
7866
7867 'history-search-forward ()'
7868 Search forward through the history for the string of characters
7869 between the start of the current line and the point. The search
7870 string must match at the beginning of a history line. This is a
7871 non-incremental search. By default, this command is unbound.
7872
7873 'history-search-backward ()'
7874 Search backward through the history for the string of characters
7875 between the start of the current line and the point. The search
7876 string must match at the beginning of a history line. This is a
7877 non-incremental search. By default, this command is unbound.
7878
7879 'history-substr-search-forward ()'
7880 Search forward through the history for the string of characters
7881 between the start of the current line and the point. The search
7882 string may match anywhere in a history line. This is a
7883 non-incremental search. By default, this command is unbound.
7884
7885 'history-substr-search-backward ()'
7886 Search backward through the history for the string of characters
7887 between the start of the current line and the point. The search
7888 string may match anywhere in a history line. This is a
7889 non-incremental search. By default, this command is unbound.
7890
7891 'yank-nth-arg (M-C-y)'
7892 Insert the first argument to the previous command (usually the
7893 second word on the previous line) at point. With an argument N,
7894 insert the Nth word from the previous command (the words in the
7895 previous command begin with word 0). A negative argument inserts
7896 the Nth word from the end of the previous command. Once the
7897 argument N is computed, the argument is extracted as if the '!N'
7898 history expansion had been specified.
7899
7900 'yank-last-arg (M-. or M-_)'
7901 Insert last argument to the previous command (the last word of the
7902 previous history entry). With a numeric argument, behave exactly
7903 like 'yank-nth-arg'. Successive calls to 'yank-last-arg' move back
7904 through the history list, inserting the last word (or the word
7905 specified by the argument to the first call) of each line in turn.
7906 Any numeric argument supplied to these successive calls determines
7907 the direction to move through the history. A negative argument
7908 switches the direction through the history (back or forward). The
7909 history expansion facilities are used to extract the last argument,
7910 as if the '!$' history expansion had been specified.
7911
7912 \1f
7913 File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
7914
7915 8.4.3 Commands For Changing Text
7916 --------------------------------
7917
7918 'end-of-file (usually C-d)'
7919 The character indicating end-of-file as set, for example, by
7920 'stty'. If this character is read when there are no characters on
7921 the line, and point is at the beginning of the line, Readline
7922 interprets it as the end of input and returns EOF.
7923
7924 'delete-char (C-d)'
7925 Delete the character at point. If this function is bound to the
7926 same character as the tty EOF character, as 'C-d' commonly is, see
7927 above for the effects.
7928
7929 'backward-delete-char (Rubout)'
7930 Delete the character behind the cursor. A numeric argument means
7931 to kill the characters instead of deleting them.
7932
7933 'forward-backward-delete-char ()'
7934 Delete the character under the cursor, unless the cursor is at the
7935 end of the line, in which case the character behind the cursor is
7936 deleted. By default, this is not bound to a key.
7937
7938 'quoted-insert (C-q or C-v)'
7939 Add the next character typed to the line verbatim. This is how to
7940 insert key sequences like 'C-q', for example.
7941
7942 'self-insert (a, b, A, 1, !, ...)'
7943 Insert yourself.
7944
7945 'bracketed-paste-begin ()'
7946 This function is intended to be bound to the "bracketed paste"
7947 escape sequence sent by some terminals, and such a binding is
7948 assigned by default. It allows Readline to insert the pasted text
7949 as a single unit without treating each character as if it had been
7950 read from the keyboard. The characters are inserted as if each one
7951 was bound to 'self-insert') instead of executing any editing
7952 commands.
7953
7954 'transpose-chars (C-t)'
7955 Drag the character before the cursor forward over the character at
7956 the cursor, moving the cursor forward as well. If the insertion
7957 point is at the end of the line, then this transposes the last two
7958 characters of the line. Negative arguments have no effect.
7959
7960 'transpose-words (M-t)'
7961 Drag the word before point past the word after point, moving point
7962 past that word as well. If the insertion point is at the end of
7963 the line, this transposes the last two words on the line.
7964
7965 'upcase-word (M-u)'
7966 Uppercase the current (or following) word. With a negative
7967 argument, uppercase the previous word, but do not move the cursor.
7968
7969 'downcase-word (M-l)'
7970 Lowercase the current (or following) word. With a negative
7971 argument, lowercase the previous word, but do not move the cursor.
7972
7973 'capitalize-word (M-c)'
7974 Capitalize the current (or following) word. With a negative
7975 argument, capitalize the previous word, but do not move the cursor.
7976
7977 'overwrite-mode ()'
7978 Toggle overwrite mode. With an explicit positive numeric argument,
7979 switches to overwrite mode. With an explicit non-positive numeric
7980 argument, switches to insert mode. This command affects only
7981 'emacs' mode; 'vi' mode does overwrite differently. Each call to
7982 'readline()' starts in insert mode.
7983
7984 In overwrite mode, characters bound to 'self-insert' replace the
7985 text at point rather than pushing the text to the right.
7986 Characters bound to 'backward-delete-char' replace the character
7987 before point with a space.
7988
7989 By default, this command is unbound.
7990
7991 \1f
7992 File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
7993
7994 8.4.4 Killing And Yanking
7995 -------------------------
7996
7997 'kill-line (C-k)'
7998 Kill the text from point to the end of the line.
7999
8000 'backward-kill-line (C-x Rubout)'
8001 Kill backward from the cursor to the beginning of the current line.
8002
8003 'unix-line-discard (C-u)'
8004 Kill backward from the cursor to the beginning of the current line.
8005
8006 'kill-whole-line ()'
8007 Kill all characters on the current line, no matter where point is.
8008 By default, this is unbound.
8009
8010 'kill-word (M-d)'
8011 Kill from point to the end of the current word, or if between
8012 words, to the end of the next word. Word boundaries are the same
8013 as 'forward-word'.
8014
8015 'backward-kill-word (M-<DEL>)'
8016 Kill the word behind point. Word boundaries are the same as
8017 'backward-word'.
8018
8019 'shell-kill-word ()'
8020 Kill from point to the end of the current word, or if between
8021 words, to the end of the next word. Word boundaries are the same
8022 as 'shell-forward-word'.
8023
8024 'shell-backward-kill-word ()'
8025 Kill the word behind point. Word boundaries are the same as
8026 'shell-backward-word'.
8027
8028 'unix-word-rubout (C-w)'
8029 Kill the word behind point, using white space as a word boundary.
8030 The killed text is saved on the kill-ring.
8031
8032 'unix-filename-rubout ()'
8033 Kill the word behind point, using white space and the slash
8034 character as the word boundaries. The killed text is saved on the
8035 kill-ring.
8036
8037 'delete-horizontal-space ()'
8038 Delete all spaces and tabs around point. By default, this is
8039 unbound.
8040
8041 'kill-region ()'
8042 Kill the text in the current region. By default, this command is
8043 unbound.
8044
8045 'copy-region-as-kill ()'
8046 Copy the text in the region to the kill buffer, so it can be yanked
8047 right away. By default, this command is unbound.
8048
8049 'copy-backward-word ()'
8050 Copy the word before point to the kill buffer. The word boundaries
8051 are the same as 'backward-word'. By default, this command is
8052 unbound.
8053
8054 'copy-forward-word ()'
8055 Copy the word following point to the kill buffer. The word
8056 boundaries are the same as 'forward-word'. By default, this
8057 command is unbound.
8058
8059 'yank (C-y)'
8060 Yank the top of the kill ring into the buffer at point.
8061
8062 'yank-pop (M-y)'
8063 Rotate the kill-ring, and yank the new top. You can only do this
8064 if the prior command is 'yank' or 'yank-pop'.
8065
8066 \1f
8067 File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
8068
8069 8.4.5 Specifying Numeric Arguments
8070 ----------------------------------
8071
8072 'digit-argument (M-0, M-1, ... M--)'
8073 Add this digit to the argument already accumulating, or start a new
8074 argument. 'M--' starts a negative argument.
8075
8076 'universal-argument ()'
8077 This is another way to specify an argument. If this command is
8078 followed by one or more digits, optionally with a leading minus
8079 sign, those digits define the argument. If the command is followed
8080 by digits, executing 'universal-argument' again ends the numeric
8081 argument, but is otherwise ignored. As a special case, if this
8082 command is immediately followed by a character that is neither a
8083 digit nor minus sign, the argument count for the next command is
8084 multiplied by four. The argument count is initially one, so
8085 executing this function the first time makes the argument count
8086 four, a second time makes the argument count sixteen, and so on.
8087 By default, this is not bound to a key.
8088
8089 \1f
8090 File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
8091
8092 8.4.6 Letting Readline Type For You
8093 -----------------------------------
8094
8095 'complete (<TAB>)'
8096 Attempt to perform completion on the text before point. The actual
8097 completion performed is application-specific. Bash attempts
8098 completion treating the text as a variable (if the text begins with
8099 '$'), username (if the text begins with '~'), hostname (if the text
8100 begins with '@'), or command (including aliases and functions) in
8101 turn. If none of these produces a match, filename completion is
8102 attempted.
8103
8104 'possible-completions (M-?)'
8105 List the possible completions of the text before point. When
8106 displaying completions, Readline sets the number of columns used
8107 for display to the value of 'completion-display-width', the value
8108 of the environment variable 'COLUMNS', or the screen width, in that
8109 order.
8110
8111 'insert-completions (M-*)'
8112 Insert all completions of the text before point that would have
8113 been generated by 'possible-completions'.
8114
8115 'menu-complete ()'
8116 Similar to 'complete', but replaces the word to be completed with a
8117 single match from the list of possible completions. Repeated
8118 execution of 'menu-complete' steps through the list of possible
8119 completions, inserting each match in turn. At the end of the list
8120 of completions, the bell is rung (subject to the setting of
8121 'bell-style') and the original text is restored. An argument of N
8122 moves N positions forward in the list of matches; a negative
8123 argument may be used to move backward through the list. This
8124 command is intended to be bound to <TAB>, but is unbound by
8125 default.
8126
8127 'menu-complete-backward ()'
8128 Identical to 'menu-complete', but moves backward through the list
8129 of possible completions, as if 'menu-complete' had been given a
8130 negative argument.
8131
8132 'delete-char-or-list ()'
8133 Deletes the character under the cursor if not at the beginning or
8134 end of the line (like 'delete-char'). If at the end of the line,
8135 behaves identically to 'possible-completions'. This command is
8136 unbound by default.
8137
8138 'complete-filename (M-/)'
8139 Attempt filename completion on the text before point.
8140
8141 'possible-filename-completions (C-x /)'
8142 List the possible completions of the text before point, treating it
8143 as a filename.
8144
8145 'complete-username (M-~)'
8146 Attempt completion on the text before point, treating it as a
8147 username.
8148
8149 'possible-username-completions (C-x ~)'
8150 List the possible completions of the text before point, treating it
8151 as a username.
8152
8153 'complete-variable (M-$)'
8154 Attempt completion on the text before point, treating it as a shell
8155 variable.
8156
8157 'possible-variable-completions (C-x $)'
8158 List the possible completions of the text before point, treating it
8159 as a shell variable.
8160
8161 'complete-hostname (M-@)'
8162 Attempt completion on the text before point, treating it as a
8163 hostname.
8164
8165 'possible-hostname-completions (C-x @)'
8166 List the possible completions of the text before point, treating it
8167 as a hostname.
8168
8169 'complete-command (M-!)'
8170 Attempt completion on the text before point, treating it as a
8171 command name. Command completion attempts to match the text
8172 against aliases, reserved words, shell functions, shell builtins,
8173 and finally executable filenames, in that order.
8174
8175 'possible-command-completions (C-x !)'
8176 List the possible completions of the text before point, treating it
8177 as a command name.
8178
8179 'dynamic-complete-history (M-<TAB>)'
8180 Attempt completion on the text before point, comparing the text
8181 against lines from the history list for possible completion
8182 matches.
8183
8184 'dabbrev-expand ()'
8185 Attempt menu completion on the text before point, comparing the
8186 text against lines from the history list for possible completion
8187 matches.
8188
8189 'complete-into-braces (M-{)'
8190 Perform filename completion and insert the list of possible
8191 completions enclosed within braces so the list is available to the
8192 shell (*note Brace Expansion::).
8193
8194 \1f
8195 File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
8196
8197 8.4.7 Keyboard Macros
8198 ---------------------
8199
8200 'start-kbd-macro (C-x ()'
8201 Begin saving the characters typed into the current keyboard macro.
8202
8203 'end-kbd-macro (C-x ))'
8204 Stop saving the characters typed into the current keyboard macro
8205 and save the definition.
8206
8207 'call-last-kbd-macro (C-x e)'
8208 Re-execute the last keyboard macro defined, by making the
8209 characters in the macro appear as if typed at the keyboard.
8210
8211 'print-last-kbd-macro ()'
8212 Print the last keboard macro defined in a format suitable for the
8213 INPUTRC file.
8214
8215 \1f
8216 File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
8217
8218 8.4.8 Some Miscellaneous Commands
8219 ---------------------------------
8220
8221 're-read-init-file (C-x C-r)'
8222 Read in the contents of the INPUTRC file, and incorporate any
8223 bindings or variable assignments found there.
8224
8225 'abort (C-g)'
8226 Abort the current editing command and ring the terminal's bell
8227 (subject to the setting of 'bell-style').
8228
8229 'do-uppercase-version (M-a, M-b, M-X, ...)'
8230 If the metafied character X is lowercase, run the command that is
8231 bound to the corresponding uppercase character.
8232
8233 'prefix-meta (<ESC>)'
8234 Metafy the next character typed. This is for keyboards without a
8235 meta key. Typing '<ESC> f' is equivalent to typing 'M-f'.
8236
8237 'undo (C-_ or C-x C-u)'
8238 Incremental undo, separately remembered for each line.
8239
8240 'revert-line (M-r)'
8241 Undo all changes made to this line. This is like executing the
8242 'undo' command enough times to get back to the beginning.
8243
8244 'tilde-expand (M-&)'
8245 Perform tilde expansion on the current word.
8246
8247 'set-mark (C-@)'
8248 Set the mark to the point. If a numeric argument is supplied, the
8249 mark is set to that position.
8250
8251 'exchange-point-and-mark (C-x C-x)'
8252 Swap the point with the mark. The current cursor position is set
8253 to the saved position, and the old cursor position is saved as the
8254 mark.
8255
8256 'character-search (C-])'
8257 A character is read and point is moved to the next occurrence of
8258 that character. A negative count searches for previous
8259 occurrences.
8260
8261 'character-search-backward (M-C-])'
8262 A character is read and point is moved to the previous occurrence
8263 of that character. A negative count searches for subsequent
8264 occurrences.
8265
8266 'skip-csi-sequence ()'
8267 Read enough characters to consume a multi-key sequence such as
8268 those defined for keys like Home and End. Such sequences begin
8269 with a Control Sequence Indicator (CSI), usually ESC-[. If this
8270 sequence is bound to "\e[", keys producing such sequences will have
8271 no effect unless explicitly bound to a readline command, instead of
8272 inserting stray characters into the editing buffer. This is
8273 unbound by default, but usually bound to ESC-[.
8274
8275 'insert-comment (M-#)'
8276 Without a numeric argument, the value of the 'comment-begin'
8277 variable is inserted at the beginning of the current line. If a
8278 numeric argument is supplied, this command acts as a toggle: if the
8279 characters at the beginning of the line do not match the value of
8280 'comment-begin', the value is inserted, otherwise the characters in
8281 'comment-begin' are deleted from the beginning of the line. In
8282 either case, the line is accepted as if a newline had been typed.
8283 The default value of 'comment-begin' causes this command to make
8284 the current line a shell comment. If a numeric argument causes the
8285 comment character to be removed, the line will be executed by the
8286 shell.
8287
8288 'dump-functions ()'
8289 Print all of the functions and their key bindings to the Readline
8290 output stream. If a numeric argument is supplied, the output is
8291 formatted in such a way that it can be made part of an INPUTRC
8292 file. This command is unbound by default.
8293
8294 'dump-variables ()'
8295 Print all of the settable variables and their values to the
8296 Readline output stream. If a numeric argument is supplied, the
8297 output is formatted in such a way that it can be made part of an
8298 INPUTRC file. This command is unbound by default.
8299
8300 'dump-macros ()'
8301 Print all of the Readline key sequences bound to macros and the
8302 strings they output. If a numeric argument is supplied, the output
8303 is formatted in such a way that it can be made part of an INPUTRC
8304 file. This command is unbound by default.
8305
8306 'glob-complete-word (M-g)'
8307 The word before point is treated as a pattern for pathname
8308 expansion, with an asterisk implicitly appended. This pattern is
8309 used to generate a list of matching file names for possible
8310 completions.
8311
8312 'glob-expand-word (C-x *)'
8313 The word before point is treated as a pattern for pathname
8314 expansion, and the list of matching file names is inserted,
8315 replacing the word. If a numeric argument is supplied, a '*' is
8316 appended before pathname expansion.
8317
8318 'glob-list-expansions (C-x g)'
8319 The list of expansions that would have been generated by
8320 'glob-expand-word' is displayed, and the line is redrawn. If a
8321 numeric argument is supplied, a '*' is appended before pathname
8322 expansion.
8323
8324 'display-shell-version (C-x C-v)'
8325 Display version information about the current instance of Bash.
8326
8327 'shell-expand-line (M-C-e)'
8328 Expand the line as the shell does. This performs alias and history
8329 expansion as well as all of the shell word expansions (*note Shell
8330 Expansions::).
8331
8332 'history-expand-line (M-^)'
8333 Perform history expansion on the current line.
8334
8335 'magic-space ()'
8336 Perform history expansion on the current line and insert a space
8337 (*note History Interaction::).
8338
8339 'alias-expand-line ()'
8340 Perform alias expansion on the current line (*note Aliases::).
8341
8342 'history-and-alias-expand-line ()'
8343 Perform history and alias expansion on the current line.
8344
8345 'insert-last-argument (M-. or M-_)'
8346 A synonym for 'yank-last-arg'.
8347
8348 'operate-and-get-next (C-o)'
8349 Accept the current line for execution and fetch the next line
8350 relative to the current line from the history for editing. Any
8351 argument is ignored.
8352
8353 'edit-and-execute-command (C-xC-e)'
8354 Invoke an editor on the current command line, and execute the
8355 result as shell commands. Bash attempts to invoke '$VISUAL',
8356 '$EDITOR', and 'emacs' as the editor, in that order.
8357
8358 \1f
8359 File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
8360
8361 8.5 Readline vi Mode
8362 ====================
8363
8364 While the Readline library does not have a full set of 'vi' editing
8365 functions, it does contain enough to allow simple editing of the line.
8366 The Readline 'vi' mode behaves as specified in the POSIX standard.
8367
8368 In order to switch interactively between 'emacs' and 'vi' editing
8369 modes, use the 'set -o emacs' and 'set -o vi' commands (*note The Set
8370 Builtin::). The Readline default is 'emacs' mode.
8371
8372 When you enter a line in 'vi' mode, you are already placed in
8373 'insertion' mode, as if you had typed an 'i'. Pressing <ESC> switches
8374 you into 'command' mode, where you can edit the text of the line with
8375 the standard 'vi' movement keys, move to previous history lines with 'k'
8376 and subsequent lines with 'j', and so forth.
8377
8378 \1f
8379 File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
8380
8381 8.6 Programmable Completion
8382 ===========================
8383
8384 When word completion is attempted for an argument to a command for which
8385 a completion specification (a COMPSPEC) has been defined using the
8386 'complete' builtin (*note Programmable Completion Builtins::), the
8387 programmable completion facilities are invoked.
8388
8389 First, the command name is identified. If a compspec has been
8390 defined for that command, the compspec is used to generate the list of
8391 possible completions for the word. If the command word is the empty
8392 string (completion attempted at the beginning of an empty line), any
8393 compspec defined with the '-E' option to 'complete' is used. If the
8394 command word is a full pathname, a compspec for the full pathname is
8395 searched for first. If no compspec is found for the full pathname, an
8396 attempt is made to find a compspec for the portion following the final
8397 slash. If those searches do not result in a compspec, any compspec
8398 defined with the '-D' option to 'complete' is used as the default.
8399
8400 Once a compspec has been found, it is used to generate the list of
8401 matching words. If a compspec is not found, the default Bash completion
8402 described above (*note Commands For Completion::) is performed.
8403
8404 First, the actions specified by the compspec are used. Only matches
8405 which are prefixed by the word being completed are returned. When the
8406 '-f' or '-d' option is used for filename or directory name completion,
8407 the shell variable 'FIGNORE' is used to filter the matches. *Note Bash
8408 Variables::, for a description of 'FIGNORE'.
8409
8410 Any completions specified by a filename expansion pattern to the '-G'
8411 option are generated next. The words generated by the pattern need not
8412 match the word being completed. The 'GLOBIGNORE' shell variable is not
8413 used to filter the matches, but the 'FIGNORE' shell variable is used.
8414
8415 Next, the string specified as the argument to the '-W' option is
8416 considered. The string is first split using the characters in the 'IFS'
8417 special variable as delimiters. Shell quoting is honored. Each word is
8418 then expanded using brace expansion, tilde expansion, parameter and
8419 variable expansion, command substitution, and arithmetic expansion, as
8420 described above (*note Shell Expansions::). The results are split using
8421 the rules described above (*note Word Splitting::). The results of the
8422 expansion are prefix-matched against the word being completed, and the
8423 matching words become the possible completions.
8424
8425 After these matches have been generated, any shell function or
8426 command specified with the '-F' and '-C' options is invoked. When the
8427 command or function is invoked, the 'COMP_LINE', 'COMP_POINT',
8428 'COMP_KEY', and 'COMP_TYPE' variables are assigned values as described
8429 above (*note Bash Variables::). If a shell function is being invoked,
8430 the 'COMP_WORDS' and 'COMP_CWORD' variables are also set. When the
8431 function or command is invoked, the first argument ($1) is the name of
8432 the command whose arguments are being completed, the second argument
8433 ($2) is the word being completed, and the third argument ($3) is the
8434 word preceding the word being completed on the current command line. No
8435 filtering of the generated completions against the word being completed
8436 is performed; the function or command has complete freedom in generating
8437 the matches.
8438
8439 Any function specified with '-F' is invoked first. The function may
8440 use any of the shell facilities, including the 'compgen' and 'compopt'
8441 builtins described below (*note Programmable Completion Builtins::), to
8442 generate the matches. It must put the possible completions in the
8443 'COMPREPLY' array variable, one per array element.
8444
8445 Next, any command specified with the '-C' option is invoked in an
8446 environment equivalent to command substitution. It should print a list
8447 of completions, one per line, to the standard output. Backslash may be
8448 used to escape a newline, if necessary.
8449
8450 After all of the possible completions are generated, any filter
8451 specified with the '-X' option is applied to the list. The filter is a
8452 pattern as used for pathname expansion; a '&' in the pattern is replaced
8453 with the text of the word being completed. A literal '&' may be escaped
8454 with a backslash; the backslash is removed before attempting a match.
8455 Any completion that matches the pattern will be removed from the list.
8456 A leading '!' negates the pattern; in this case any completion not
8457 matching the pattern will be removed. If the 'nocasematch' shell option
8458 (see the description of 'shopt' in *note The Shopt Builtin::) is
8459 enabled, the match is performed without regard to the case of alphabetic
8460 characters.
8461
8462 Finally, any prefix and suffix specified with the '-P' and '-S'
8463 options are added to each member of the completion list, and the result
8464 is returned to the Readline completion code as the list of possible
8465 completions.
8466
8467 If the previously-applied actions do not generate any matches, and
8468 the '-o dirnames' option was supplied to 'complete' when the compspec
8469 was defined, directory name completion is attempted.
8470
8471 If the '-o plusdirs' option was supplied to 'complete' when the
8472 compspec was defined, directory name completion is attempted and any
8473 matches are added to the results of the other actions.
8474
8475 By default, if a compspec is found, whatever it generates is returned
8476 to the completion code as the full set of possible completions. The
8477 default Bash completions are not attempted, and the Readline default of
8478 filename completion is disabled. If the '-o bashdefault' option was
8479 supplied to 'complete' when the compspec was defined, the default Bash
8480 completions are attempted if the compspec generates no matches. If the
8481 '-o default' option was supplied to 'complete' when the compspec was
8482 defined, Readline's default completion will be performed if the compspec
8483 (and, if attempted, the default Bash completions) generate no matches.
8484
8485 When a compspec indicates that directory name completion is desired,
8486 the programmable completion functions force Readline to append a slash
8487 to completed names which are symbolic links to directories, subject to
8488 the value of the MARK-DIRECTORIES Readline variable, regardless of the
8489 setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
8490
8491 There is some support for dynamically modifying completions. This is
8492 most useful when used in combination with a default completion specified
8493 with '-D'. It's possible for shell functions executed as completion
8494 handlers to indicate that completion should be retried by returning an
8495 exit status of 124. If a shell function returns 124, and changes the
8496 compspec associated with the command on which completion is being
8497 attempted (supplied as the first argument when the function is
8498 executed), programmable completion restarts from the beginning, with an
8499 attempt to find a new compspec for that command. This allows a set of
8500 completions to be built dynamically as completion is attempted, rather
8501 than being loaded all at once.
8502
8503 For instance, assuming that there is a library of compspecs, each
8504 kept in a file corresponding to the name of the command, the following
8505 default completion function would load completions dynamically:
8506
8507 _completion_loader()
8508 {
8509 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
8510 }
8511 complete -D -F _completion_loader -o bashdefault -o default
8512
8513 \1f
8514 File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing
8515
8516 8.7 Programmable Completion Builtins
8517 ====================================
8518
8519 Three builtin commands are available to manipulate the programmable
8520 completion facilities: one to specify how the arguments to a particular
8521 command are to be completed, and two to modify the completion as it is
8522 happening.
8523
8524 'compgen'
8525 compgen [OPTION] [WORD]
8526
8527 Generate possible completion matches for WORD according to the
8528 OPTIONs, which may be any option accepted by the 'complete' builtin
8529 with the exception of '-p' and '-r', and write the matches to the
8530 standard output. When using the '-F' or '-C' options, the various
8531 shell variables set by the programmable completion facilities,
8532 while available, will not have useful values.
8533
8534 The matches will be generated in the same way as if the
8535 programmable completion code had generated them directly from a
8536 completion specification with the same flags. If WORD is
8537 specified, only those completions matching WORD will be displayed.
8538
8539 The return value is true unless an invalid option is supplied, or
8540 no matches were generated.
8541
8542 'complete'
8543 complete [-abcdefgjksuv] [-o COMP-OPTION] [-DE] [-A ACTION] [-G GLOBPAT] [-W WORDLIST]
8544 [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
8545 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]
8546 complete -pr [-DE] [NAME ...]
8547
8548 Specify how arguments to each NAME should be completed. If the
8549 '-p' option is supplied, or if no options are supplied, existing
8550 completion specifications are printed in a way that allows them to
8551 be reused as input. The '-r' option removes a completion
8552 specification for each NAME, or, if no NAMEs are supplied, all
8553 completion specifications. The '-D' option indicates that the
8554 remaining options and actions should apply to the "default" command
8555 completion; that is, completion attempted on a command for which no
8556 completion has previously been defined. The '-E' option indicates
8557 that the remaining options and actions should apply to "empty"
8558 command completion; that is, completion attempted on a blank line.
8559
8560 The process of applying these completion specifications when word
8561 completion is attempted is described above (*note Programmable
8562 Completion::). The '-D' option takes precedence over '-E'.
8563
8564 Other options, if specified, have the following meanings. The
8565 arguments to the '-G', '-W', and '-X' options (and, if necessary,
8566 the '-P' and '-S' options) should be quoted to protect them from
8567 expansion before the 'complete' builtin is invoked.
8568
8569 '-o COMP-OPTION'
8570 The COMP-OPTION controls several aspects of the compspec's
8571 behavior beyond the simple generation of completions.
8572 COMP-OPTION may be one of:
8573
8574 'bashdefault'
8575 Perform the rest of the default Bash completions if the
8576 compspec generates no matches.
8577
8578 'default'
8579 Use Readline's default filename completion if the
8580 compspec generates no matches.
8581
8582 'dirnames'
8583 Perform directory name completion if the compspec
8584 generates no matches.
8585
8586 'filenames'
8587 Tell Readline that the compspec generates filenames, so
8588 it can perform any filename-specific processing (like
8589 adding a slash to directory names quoting special
8590 characters, or suppressing trailing spaces). This option
8591 is intended to be used with shell functions specified
8592 with '-F'.
8593
8594 'noquote'
8595 Tell Readline not to quote the completed words if they
8596 are filenames (quoting filenames is the default).
8597
8598 'nosort'
8599 Tell Readline not to sort the list of possible
8600 completions alphabetically.
8601
8602 'nospace'
8603 Tell Readline not to append a space (the default) to
8604 words completed at the end of the line.
8605
8606 'plusdirs'
8607 After any matches defined by the compspec are generated,
8608 directory name completion is attempted and any matches
8609 are added to the results of the other actions.
8610
8611 '-A ACTION'
8612 The ACTION may be one of the following to generate a list of
8613 possible completions:
8614
8615 'alias'
8616 Alias names. May also be specified as '-a'.
8617
8618 'arrayvar'
8619 Array variable names.
8620
8621 'binding'
8622 Readline key binding names (*note Bindable Readline
8623 Commands::).
8624
8625 'builtin'
8626 Names of shell builtin commands. May also be specified
8627 as '-b'.
8628
8629 'command'
8630 Command names. May also be specified as '-c'.
8631
8632 'directory'
8633 Directory names. May also be specified as '-d'.
8634
8635 'disabled'
8636 Names of disabled shell builtins.
8637
8638 'enabled'
8639 Names of enabled shell builtins.
8640
8641 'export'
8642 Names of exported shell variables. May also be specified
8643 as '-e'.
8644
8645 'file'
8646 File names. May also be specified as '-f'.
8647
8648 'function'
8649 Names of shell functions.
8650
8651 'group'
8652 Group names. May also be specified as '-g'.
8653
8654 'helptopic'
8655 Help topics as accepted by the 'help' builtin (*note Bash
8656 Builtins::).
8657
8658 'hostname'
8659 Hostnames, as taken from the file specified by the
8660 'HOSTFILE' shell variable (*note Bash Variables::).
8661
8662 'job'
8663 Job names, if job control is active. May also be
8664 specified as '-j'.
8665
8666 'keyword'
8667 Shell reserved words. May also be specified as '-k'.
8668
8669 'running'
8670 Names of running jobs, if job control is active.
8671
8672 'service'
8673 Service names. May also be specified as '-s'.
8674
8675 'setopt'
8676 Valid arguments for the '-o' option to the 'set' builtin
8677 (*note The Set Builtin::).
8678
8679 'shopt'
8680 Shell option names as accepted by the 'shopt' builtin
8681 (*note Bash Builtins::).
8682
8683 'signal'
8684 Signal names.
8685
8686 'stopped'
8687 Names of stopped jobs, if job control is active.
8688
8689 'user'
8690 User names. May also be specified as '-u'.
8691
8692 'variable'
8693 Names of all shell variables. May also be specified as
8694 '-v'.
8695
8696 '-C COMMAND'
8697 COMMAND is executed in a subshell environment, and its output
8698 is used as the possible completions.
8699
8700 '-F FUNCTION'
8701 The shell function FUNCTION is executed in the current shell
8702 environment. When it is executed, $1 is the name of the
8703 command whose arguments are being completed, $2 is the word
8704 being completed, and $3 is the word preceding the word being
8705 completed, as described above (*note Programmable
8706 Completion::). When it finishes, the possible completions are
8707 retrieved from the value of the 'COMPREPLY' array variable.
8708
8709 '-G GLOBPAT'
8710 The filename expansion pattern GLOBPAT is expanded to generate
8711 the possible completions.
8712
8713 '-P PREFIX'
8714 PREFIX is added at the beginning of each possible completion
8715 after all other options have been applied.
8716
8717 '-S SUFFIX'
8718 SUFFIX is appended to each possible completion after all other
8719 options have been applied.
8720
8721 '-W WORDLIST'
8722 The WORDLIST is split using the characters in the 'IFS'
8723 special variable as delimiters, and each resultant word is
8724 expanded. The possible completions are the members of the
8725 resultant list which match the word being completed.
8726
8727 '-X FILTERPAT'
8728 FILTERPAT is a pattern as used for filename expansion. It is
8729 applied to the list of possible completions generated by the
8730 preceding options and arguments, and each completion matching
8731 FILTERPAT is removed from the list. A leading '!' in
8732 FILTERPAT negates the pattern; in this case, any completion
8733 not matching FILTERPAT is removed.
8734
8735 The return value is true unless an invalid option is supplied, an
8736 option other than '-p' or '-r' is supplied without a NAME argument,
8737 an attempt is made to remove a completion specification for a NAME
8738 for which no specification exists, or an error occurs adding a
8739 completion specification.
8740
8741 'compopt'
8742 compopt [-o OPTION] [-DE] [+o OPTION] [NAME]
8743 Modify completion options for each NAME according to the OPTIONs,
8744 or for the currently-executing completion if no NAMEs are supplied.
8745 If no OPTIONs are given, display the completion options for each
8746 NAME or the current completion. The possible values of OPTION are
8747 those valid for the 'complete' builtin described above. The '-D'
8748 option indicates that the remaining options should apply to the
8749 "default" command completion; that is, completion attempted on a
8750 command for which no completion has previously been defined. The
8751 '-E' option indicates that the remaining options should apply to
8752 "empty" command completion; that is, completion attempted on a
8753 blank line.
8754
8755 The '-D' option takes precedence over '-E'.
8756
8757 The return value is true unless an invalid option is supplied, an
8758 attempt is made to modify the options for a NAME for which no
8759 completion specification exists, or an output error occurs.
8760
8761 \1f
8762 File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing
8763
8764 8.8 A Programmable Completion Example
8765 =====================================
8766
8767 The most common way to obtain additional completion functionality beyond
8768 the default actions 'complete' and 'compgen' provide is to use a shell
8769 function and bind it to a particular command using 'complete -F'.
8770
8771 The following function provides completions for the 'cd' builtin. It
8772 is a reasonably good example of what shell functions must do when used
8773 for completion. This function uses the word passsed as '$2' to
8774 determine the directory name to complete. You can also use the
8775 'COMP_WORDS' array variable; the current word is indexed by the
8776 'COMP_CWORD' variable.
8777
8778 The function relies on the 'complete' and 'compgen' builtins to do
8779 much of the work, adding only the things that the Bash 'cd' does beyond
8780 accepting basic directory names: tilde expansion (*note Tilde
8781 Expansion::), searching directories in $CDPATH, which is described above
8782 (*note Bourne Shell Builtins::), and basic support for the 'cdable_vars'
8783 shell option (*note The Shopt Builtin::). '_comp_cd' modifies the value
8784 of IFS so that it contains only a newline to accommodate file names
8785 containing spaces and tabs - 'compgen' prints the possible completions
8786 it generates one per line.
8787
8788 Possible completions go into the COMPREPLY array variable, one
8789 completion per array element. The programmable completion system
8790 retrieves the completions from there when the function returns.
8791
8792 # A completion function for the cd builtin
8793 # based on the cd completion function from the bash_completion package
8794 _comp_cd()
8795 {
8796 local IFS=$' \t\n' # normalize IFS
8797 local cur _skipdot _cdpath
8798 local i j k
8799
8800 # Tilde expansion, with side effect of expanding tilde to full pathname
8801 case "$2" in
8802 \~*) eval cur="$2" ;;
8803 *) cur=$2 ;;
8804 esac
8805
8806 # no cdpath or absolute pathname -- straight directory completion
8807 if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
8808 # compgen prints paths one per line; could also use while loop
8809 IFS=$'\n'
8810 COMPREPLY=( $(compgen -d -- "$cur") )
8811 IFS=$' \t\n'
8812 # CDPATH+directories in the current directory if not in CDPATH
8813 else
8814 IFS=$'\n'
8815 _skipdot=false
8816 # preprocess CDPATH to convert null directory names to .
8817 _cdpath=${CDPATH/#:/.:}
8818 _cdpath=${_cdpath//::/:.:}
8819 _cdpath=${_cdpath/%:/:.}
8820 for i in ${_cdpath//:/$'\n'}; do
8821 if [[ $i -ef . ]]; then _skipdot=true; fi
8822 k="${#COMPREPLY[@]}"
8823 for j in $( compgen -d -- "$i/$cur" ); do
8824 COMPREPLY[k++]=${j#$i/} # cut off directory
8825 done
8826 done
8827 $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
8828 IFS=$' \t\n'
8829 fi
8830
8831 # variable names if appropriate shell option set and no completions
8832 if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
8833 COMPREPLY=( $(compgen -v -- "$cur") )
8834 fi
8835
8836 return 0
8837 }
8838
8839 We install the completion function using the '-F' option to
8840 'complete':
8841
8842 # Tell readline to quote appropriate and append slashes to directories;
8843 # use the bash default completion for other arguments
8844 complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
8845
8846 Since we'd like Bash and Readline to take care of some of the other
8847 details for us, we use several other options to tell Bash and Readline
8848 what to do. The '-o filenames' option tells Readline that the possible
8849 completions should be treated as filenames, and quoted appropriately.
8850 That option will also cause Readline to append a slash to filenames it
8851 can determine are directories (which is why we might want to extend
8852 '_comp_cd' to append a slash if we're using directories found via
8853 CDPATH: Readline can't tell those completions are directories). The '-o
8854 nospace' option tells Readline to not append a space character to the
8855 directory name, in case we want to append to it. The '-o bashdefault'
8856 option brings in the rest of the "Bash default" completions - possible
8857 completion that Bash adds to the default Readline set. These include
8858 things like command name completion, variable completion for words
8859 beginning with '{', completions containing pathname expansion patterns
8860 (*note Filename Expansion::), and so on.
8861
8862 Once installed using 'complete', '_comp_cd' will be called every time
8863 we attempt word completion for a 'cd' command.
8864
8865 Many more examples - an extensive collection of completions for most
8866 of the common GNU, Unix, and Linux commands - are available as part of
8867 the bash_completion project. This is installed by default on many
8868 GNU/Linux distributions. Originally written by Ian Macdonald, the
8869 project now lives at <http://bash-completion.alioth.debian.org/>. There
8870 are ports for other systems such as Solaris and Mac OS X.
8871
8872 An older version of the bash_completion package is distributed with
8873 bash in the 'examples/complete' subdirectory.
8874
8875 \1f
8876 File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
8877
8878 9 Using History Interactively
8879 *****************************
8880
8881 This chapter describes how to use the GNU History Library interactively,
8882 from a user's standpoint. It should be considered a user's guide. For
8883 information on using the GNU History Library in other programs, see the
8884 GNU Readline Library Manual.
8885
8886 * Menu:
8887
8888 * Bash History Facilities:: How Bash lets you manipulate your command
8889 history.
8890 * Bash History Builtins:: The Bash builtin commands that manipulate
8891 the command history.
8892 * History Interaction:: What it feels like using History as a user.
8893
8894 \1f
8895 File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
8896
8897 9.1 Bash History Facilities
8898 ===========================
8899
8900 When the '-o history' option to the 'set' builtin is enabled (*note The
8901 Set Builtin::), the shell provides access to the "command history", the
8902 list of commands previously typed. The value of the 'HISTSIZE' shell
8903 variable is used as the number of commands to save in a history list.
8904 The text of the last '$HISTSIZE' commands (default 500) is saved. The
8905 shell stores each command in the history list prior to parameter and
8906 variable expansion but after history expansion is performed, subject to
8907 the values of the shell variables 'HISTIGNORE' and 'HISTCONTROL'.
8908
8909 When the shell starts up, the history is initialized from the file
8910 named by the 'HISTFILE' variable (default '~/.bash_history'). The file
8911 named by the value of 'HISTFILE' is truncated, if necessary, to contain
8912 no more than the number of lines specified by the value of the
8913 'HISTFILESIZE' variable. When a shell with history enabled exits, the
8914 last '$HISTSIZE' lines are copied from the history list to the file
8915 named by '$HISTFILE'. If the 'histappend' shell option is set (*note
8916 Bash Builtins::), the lines are appended to the history file, otherwise
8917 the history file is overwritten. If 'HISTFILE' is unset, or if the
8918 history file is unwritable, the history is not saved. After saving the
8919 history, the history file is truncated to contain no more than
8920 '$HISTFILESIZE' lines. If 'HISTFILESIZE' is unset, or set to null, a
8921 non-numeric value, or a numeric value less than zero, the history file
8922 is not truncated.
8923
8924 If the 'HISTTIMEFORMAT' is set, the time stamp information associated
8925 with each history entry is written to the history file, marked with the
8926 history comment character. When the history file is read, lines
8927 beginning with the history comment character followed immediately by a
8928 digit are interpreted as timestamps for the following history entry.
8929
8930 The builtin command 'fc' may be used to list or edit and re-execute a
8931 portion of the history list. The 'history' builtin may be used to
8932 display or modify the history list and manipulate the history file.
8933 When using command-line editing, search commands are available in each
8934 editing mode that provide access to the history list (*note Commands For
8935 History::).
8936
8937 The shell allows control over which commands are saved on the history
8938 list. The 'HISTCONTROL' and 'HISTIGNORE' variables may be set to cause
8939 the shell to save only a subset of the commands entered. The 'cmdhist'
8940 shell option, if enabled, causes the shell to attempt to save each line
8941 of a multi-line command in the same history entry, adding semicolons
8942 where necessary to preserve syntactic correctness. The 'lithist' shell
8943 option causes the shell to save the command with embedded newlines
8944 instead of semicolons. The 'shopt' builtin is used to set these
8945 options. *Note Bash Builtins::, for a description of 'shopt'.
8946
8947 \1f
8948 File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
8949
8950 9.2 Bash History Builtins
8951 =========================
8952
8953 Bash provides two builtin commands which manipulate the history list and
8954 history file.
8955
8956 'fc'
8957 fc [-e ENAME] [-lnr] [FIRST] [LAST]
8958 fc -s [PAT=REP] [COMMAND]
8959
8960 The first form selects a range of commands from FIRST to LAST from
8961 the history list and displays or edits and re-executes them. Both
8962 FIRST and LAST may be specified as a string (to locate the most
8963 recent command beginning with that string) or as a number (an index
8964 into the history list, where a negative number is used as an offset
8965 from the current command number). If LAST is not specified it is
8966 set to FIRST. If FIRST is not specified it is set to the previous
8967 command for editing and -16 for listing. If the '-l' flag is
8968 given, the commands are listed on standard output. The '-n' flag
8969 suppresses the command numbers when listing. The '-r' flag
8970 reverses the order of the listing. Otherwise, the editor given by
8971 ENAME is invoked on a file containing those commands. If ENAME is
8972 not given, the value of the following variable expansion is used:
8973 '${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
8974 'FCEDIT' variable if set, or the value of the 'EDITOR' variable if
8975 that is set, or 'vi' if neither is set. When editing is complete,
8976 the edited commands are echoed and executed.
8977
8978 In the second form, COMMAND is re-executed after each instance of
8979 PAT in the selected command is replaced by REP. COMMAND is
8980 intepreted the same as FIRST above.
8981
8982 A useful alias to use with the 'fc' command is 'r='fc -s'', so that
8983 typing 'r cc' runs the last command beginning with 'cc' and typing
8984 'r' re-executes the last command (*note Aliases::).
8985
8986 'history'
8987 history [N]
8988 history -c
8989 history -d OFFSET
8990 history [-anrw] [FILENAME]
8991 history -ps ARG
8992
8993 With no options, display the history list with line numbers. Lines
8994 prefixed with a '*' have been modified. An argument of N lists
8995 only the last N lines. If the shell variable 'HISTTIMEFORMAT' is
8996 set and not null, it is used as a format string for STRFTIME to
8997 display the time stamp associated with each displayed history
8998 entry. No intervening blank is printed between the formatted time
8999 stamp and the history line.
9000
9001 Options, if supplied, have the following meanings:
9002
9003 '-c'
9004 Clear the history list. This may be combined with the other
9005 options to replace the history list completely.
9006
9007 '-d OFFSET'
9008 Delete the history entry at position OFFSET. OFFSET should be
9009 specified as it appears when the history is displayed.
9010
9011 '-a'
9012 Append the new history lines to the history file. These are
9013 history lines entered since the beginning of the current Bash
9014 session, but not already appended to the history file.
9015
9016 '-n'
9017 Append the history lines not already read from the history
9018 file to the current history list. These are lines appended to
9019 the history file since the beginning of the current Bash
9020 session.
9021
9022 '-r'
9023 Read the history file and append its contents to the history
9024 list.
9025
9026 '-w'
9027 Write out the current history list to the history file.
9028
9029 '-p'
9030 Perform history substitution on the ARGs and display the
9031 result on the standard output, without storing the results in
9032 the history list.
9033
9034 '-s'
9035 The ARGs are added to the end of the history list as a single
9036 entry.
9037
9038 When any of the '-w', '-r', '-a', or '-n' options is used, if
9039 FILENAME is given, then it is used as the history file. If not,
9040 then the value of the 'HISTFILE' variable is used.
9041
9042 \1f
9043 File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
9044
9045 9.3 History Expansion
9046 =====================
9047
9048 The History library provides a history expansion feature that is similar
9049 to the history expansion provided by 'csh'. This section describes the
9050 syntax used to manipulate the history information.
9051
9052 History expansions introduce words from the history list into the
9053 input stream, making it easy to repeat commands, insert the arguments to
9054 a previous command into the current input line, or fix errors in
9055 previous commands quickly.
9056
9057 History expansion is performed immediately after a complete line is
9058 read, before the shell breaks it into words.
9059
9060 History expansion takes place in two parts. The first is to
9061 determine which line from the history list should be used during
9062 substitution. The second is to select portions of that line for
9063 inclusion into the current one. The line selected from the history is
9064 called the "event", and the portions of that line that are acted upon
9065 are called "words". Various "modifiers" are available to manipulate the
9066 selected words. The line is broken into words in the same fashion that
9067 Bash does, so that several words surrounded by quotes are considered one
9068 word. History expansions are introduced by the appearance of the
9069 history expansion character, which is '!' by default. Only '\' and '''
9070 may be used to escape the history expansion character, but the history
9071 expansion character is also treated as quoted if it immediately precedes
9072 the closing double quote in a double-quoted string.
9073
9074 Several shell options settable with the 'shopt' builtin (*note Bash
9075 Builtins::) may be used to tailor the behavior of history expansion. If
9076 the 'histverify' shell option is enabled, and Readline is being used,
9077 history substitutions are not immediately passed to the shell parser.
9078 Instead, the expanded line is reloaded into the Readline editing buffer
9079 for further modification. If Readline is being used, and the
9080 'histreedit' shell option is enabled, a failed history expansion will be
9081 reloaded into the Readline editing buffer for correction. The '-p'
9082 option to the 'history' builtin command may be used to see what a
9083 history expansion will do before using it. The '-s' option to the
9084 'history' builtin may be used to add commands to the end of the history
9085 list without actually executing them, so that they are available for
9086 subsequent recall. This is most useful in conjunction with Readline.
9087
9088 The shell allows control of the various characters used by the
9089 history expansion mechanism with the 'histchars' variable, as explained
9090 above (*note Bash Variables::). The shell uses the history comment
9091 character to mark history timestamps when writing the history file.
9092
9093 * Menu:
9094
9095 * Event Designators:: How to specify which history line to use.
9096 * Word Designators:: Specifying which words are of interest.
9097 * Modifiers:: Modifying the results of substitution.
9098
9099 \1f
9100 File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
9101
9102 9.3.1 Event Designators
9103 -----------------------
9104
9105 An event designator is a reference to a command line entry in the
9106 history list. Unless the reference is absolute, events are relative to
9107 the current position in the history list.
9108
9109 '!'
9110 Start a history substitution, except when followed by a space, tab,
9111 the end of the line, '=' or '(' (when the 'extglob' shell option is
9112 enabled using the 'shopt' builtin).
9113
9114 '!N'
9115 Refer to command line N.
9116
9117 '!-N'
9118 Refer to the command N lines back.
9119
9120 '!!'
9121 Refer to the previous command. This is a synonym for '!-1'.
9122
9123 '!STRING'
9124 Refer to the most recent command preceding the current position in
9125 the history list starting with STRING.
9126
9127 '!?STRING[?]'
9128 Refer to the most recent command preceding the current position in
9129 the history list containing STRING. The trailing '?' may be
9130 omitted if the STRING is followed immediately by a newline.
9131
9132 '^STRING1^STRING2^'
9133 Quick Substitution. Repeat the last command, replacing STRING1
9134 with STRING2. Equivalent to '!!:s/STRING1/STRING2/'.
9135
9136 '!#'
9137 The entire command line typed so far.
9138
9139 \1f
9140 File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
9141
9142 9.3.2 Word Designators
9143 ----------------------
9144
9145 Word designators are used to select desired words from the event. A ':'
9146 separates the event specification from the word designator. It may be
9147 omitted if the word designator begins with a '^', '$', '*', '-', or '%'.
9148 Words are numbered from the beginning of the line, with the first word
9149 being denoted by 0 (zero). Words are inserted into the current line
9150 separated by single spaces.
9151
9152 For example,
9153
9154 '!!'
9155 designates the preceding command. When you type this, the
9156 preceding command is repeated in toto.
9157
9158 '!!:$'
9159 designates the last argument of the preceding command. This may be
9160 shortened to '!$'.
9161
9162 '!fi:2'
9163 designates the second argument of the most recent command starting
9164 with the letters 'fi'.
9165
9166 Here are the word designators:
9167
9168 '0 (zero)'
9169 The '0'th word. For many applications, this is the command word.
9170
9171 'N'
9172 The Nth word.
9173
9174 '^'
9175 The first argument; that is, word 1.
9176
9177 '$'
9178 The last argument.
9179
9180 '%'
9181 The word matched by the most recent '?STRING?' search.
9182
9183 'X-Y'
9184 A range of words; '-Y' abbreviates '0-Y'.
9185
9186 '*'
9187 All of the words, except the '0'th. This is a synonym for '1-$'.
9188 It is not an error to use '*' if there is just one word in the
9189 event; the empty string is returned in that case.
9190
9191 'X*'
9192 Abbreviates 'X-$'
9193
9194 'X-'
9195 Abbreviates 'X-$' like 'X*', but omits the last word.
9196
9197 If a word designator is supplied without an event specification, the
9198 previous command is used as the event.
9199
9200 \1f
9201 File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
9202
9203 9.3.3 Modifiers
9204 ---------------
9205
9206 After the optional word designator, you can add a sequence of one or
9207 more of the following modifiers, each preceded by a ':'.
9208
9209 'h'
9210 Remove a trailing pathname component, leaving only the head.
9211
9212 't'
9213 Remove all leading pathname components, leaving the tail.
9214
9215 'r'
9216 Remove a trailing suffix of the form '.SUFFIX', leaving the
9217 basename.
9218
9219 'e'
9220 Remove all but the trailing suffix.
9221
9222 'p'
9223 Print the new command but do not execute it.
9224
9225 'q'
9226 Quote the substituted words, escaping further substitutions.
9227
9228 'x'
9229 Quote the substituted words as with 'q', but break into words at
9230 spaces, tabs, and newlines.
9231
9232 's/OLD/NEW/'
9233 Substitute NEW for the first occurrence of OLD in the event line.
9234 Any delimiter may be used in place of '/'. The delimiter may be
9235 quoted in OLD and NEW with a single backslash. If '&' appears in
9236 NEW, it is replaced by OLD. A single backslash will quote the '&'.
9237 The final delimiter is optional if it is the last character on the
9238 input line.
9239
9240 '&'
9241 Repeat the previous substitution.
9242
9243 'g'
9244 'a'
9245 Cause changes to be applied over the entire event line. Used in
9246 conjunction with 's', as in 'gs/OLD/NEW/', or with '&'.
9247
9248 'G'
9249 Apply the following 's' modifier once to each word in the event.
9250
9251 \1f
9252 File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
9253
9254 10 Installing Bash
9255 ******************
9256
9257 This chapter provides basic instructions for installing Bash on the
9258 various supported platforms. The distribution supports the GNU
9259 operating systems, nearly every version of Unix, and several non-Unix
9260 systems such as BeOS and Interix. Other independent ports exist for
9261 MS-DOS, OS/2, and Windows platforms.
9262
9263 * Menu:
9264
9265 * Basic Installation:: Installation instructions.
9266 * Compilers and Options:: How to set special options for various
9267 systems.
9268 * Compiling For Multiple Architectures:: How to compile Bash for more
9269 than one kind of system from
9270 the same source tree.
9271 * Installation Names:: How to set the various paths used by the installation.
9272 * Specifying the System Type:: How to configure Bash for a particular system.
9273 * Sharing Defaults:: How to share default configuration values among GNU
9274 programs.
9275 * Operation Controls:: Options recognized by the configuration program.
9276 * Optional Features:: How to enable and disable optional features when
9277 building Bash.
9278
9279 \1f
9280 File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
9281
9282 10.1 Basic Installation
9283 =======================
9284
9285 These are installation instructions for Bash.
9286
9287 The simplest way to compile Bash is:
9288
9289 1. 'cd' to the directory containing the source code and type
9290 './configure' to configure Bash for your system. If you're using
9291 'csh' on an old version of System V, you might need to type 'sh
9292 ./configure' instead to prevent 'csh' from trying to execute
9293 'configure' itself.
9294
9295 Running 'configure' takes some time. While running, it prints
9296 messages telling which features it is checking for.
9297
9298 2. Type 'make' to compile Bash and build the 'bashbug' bug reporting
9299 script.
9300
9301 3. Optionally, type 'make tests' to run the Bash test suite.
9302
9303 4. Type 'make install' to install 'bash' and 'bashbug'. This will
9304 also install the manual pages and Info file.
9305
9306 The 'configure' shell script attempts to guess correct values for
9307 various system-dependent variables used during compilation. It uses
9308 those values to create a 'Makefile' in each directory of the package
9309 (the top directory, the 'builtins', 'doc', and 'support' directories,
9310 each directory under 'lib', and several others). It also creates a
9311 'config.h' file containing system-dependent definitions. Finally, it
9312 creates a shell script named 'config.status' that you can run in the
9313 future to recreate the current configuration, a file 'config.cache' that
9314 saves the results of its tests to speed up reconfiguring, and a file
9315 'config.log' containing compiler output (useful mainly for debugging
9316 'configure'). If at some point 'config.cache' contains results you
9317 don't want to keep, you may remove or edit it.
9318
9319 To find out more about the options and arguments that the 'configure'
9320 script understands, type
9321
9322 bash-2.04$ ./configure --help
9323
9324 at the Bash prompt in your Bash source directory.
9325
9326 If you need to do unusual things to compile Bash, please try to
9327 figure out how 'configure' could check whether or not to do them, and
9328 mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
9329 considered for the next release.
9330
9331 The file 'configure.ac' is used to create 'configure' by a program
9332 called Autoconf. You only need 'configure.ac' if you want to change it
9333 or regenerate 'configure' using a newer version of Autoconf. If you do
9334 this, make sure you are using Autoconf version 2.50 or newer.
9335
9336 You can remove the program binaries and object files from the source
9337 code directory by typing 'make clean'. To also remove the files that
9338 'configure' created (so you can compile Bash for a different kind of
9339 computer), type 'make distclean'.
9340
9341 \1f
9342 File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
9343
9344 10.2 Compilers and Options
9345 ==========================
9346
9347 Some systems require unusual options for compilation or linking that the
9348 'configure' script does not know about. You can give 'configure'
9349 initial values for variables by setting them in the environment. Using
9350 a Bourne-compatible shell, you can do that on the command line like
9351 this:
9352
9353 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
9354
9355 On systems that have the 'env' program, you can do it like this:
9356
9357 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
9358
9359 The configuration process uses GCC to build Bash if it is available.
9360
9361 \1f
9362 File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
9363
9364 10.3 Compiling For Multiple Architectures
9365 =========================================
9366
9367 You can compile Bash for more than one kind of computer at the same
9368 time, by placing the object files for each architecture in their own
9369 directory. To do this, you must use a version of 'make' that supports
9370 the 'VPATH' variable, such as GNU 'make'. 'cd' to the directory where
9371 you want the object files and executables to go and run the 'configure'
9372 script from the source directory. You may need to supply the
9373 '--srcdir=PATH' argument to tell 'configure' where the source files are.
9374 'configure' automatically checks for the source code in the directory
9375 that 'configure' is in and in '..'.
9376
9377 If you have to use a 'make' that does not supports the 'VPATH'
9378 variable, you can compile Bash for one architecture at a time in the
9379 source code directory. After you have installed Bash for one
9380 architecture, use 'make distclean' before reconfiguring for another
9381 architecture.
9382
9383 Alternatively, if your system supports symbolic links, you can use
9384 the 'support/mkclone' script to create a build tree which has symbolic
9385 links back to each file in the source directory. Here's an example that
9386 creates a build directory in the current directory from a source
9387 directory '/usr/gnu/src/bash-2.0':
9388
9389 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
9390
9391 The 'mkclone' script requires Bash, so you must have already built Bash
9392 for at least one architecture before you can create build directories
9393 for other architectures.
9394
9395 \1f
9396 File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
9397
9398 10.4 Installation Names
9399 =======================
9400
9401 By default, 'make install' will install into '/usr/local/bin',
9402 '/usr/local/man', etc. You can specify an installation prefix other
9403 than '/usr/local' by giving 'configure' the option '--prefix=PATH', or
9404 by specifying a value for the 'DESTDIR' 'make' variable when running
9405 'make install'.
9406
9407 You can specify separate installation prefixes for
9408 architecture-specific files and architecture-independent files. If you
9409 give 'configure' the option '--exec-prefix=PATH', 'make install' will
9410 use PATH as the prefix for installing programs and libraries.
9411 Documentation and other data files will still use the regular prefix.
9412
9413 \1f
9414 File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
9415
9416 10.5 Specifying the System Type
9417 ===============================
9418
9419 There may be some features 'configure' can not figure out automatically,
9420 but need to determine by the type of host Bash will run on. Usually
9421 'configure' can figure that out, but if it prints a message saying it
9422 can not guess the host type, give it the '--host=TYPE' option. 'TYPE'
9423 can either be a short name for the system type, such as 'sun4', or a
9424 canonical name with three fields: 'CPU-COMPANY-SYSTEM' (e.g.,
9425 'i386-unknown-freebsd4.2').
9426
9427 See the file 'support/config.sub' for the possible values of each
9428 field.
9429
9430 \1f
9431 File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
9432
9433 10.6 Sharing Defaults
9434 =====================
9435
9436 If you want to set default values for 'configure' scripts to share, you
9437 can create a site shell script called 'config.site' that gives default
9438 values for variables like 'CC', 'cache_file', and 'prefix'. 'configure'
9439 looks for 'PREFIX/share/config.site' if it exists, then
9440 'PREFIX/etc/config.site' if it exists. Or, you can set the
9441 'CONFIG_SITE' environment variable to the location of the site script.
9442 A warning: the Bash 'configure' looks for a site script, but not all
9443 'configure' scripts do.
9444
9445 \1f
9446 File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
9447
9448 10.7 Operation Controls
9449 =======================
9450
9451 'configure' recognizes the following options to control how it operates.
9452
9453 '--cache-file=FILE'
9454 Use and save the results of the tests in FILE instead of
9455 './config.cache'. Set FILE to '/dev/null' to disable caching, for
9456 debugging 'configure'.
9457
9458 '--help'
9459 Print a summary of the options to 'configure', and exit.
9460
9461 '--quiet'
9462 '--silent'
9463 '-q'
9464 Do not print messages saying which checks are being made.
9465
9466 '--srcdir=DIR'
9467 Look for the Bash source code in directory DIR. Usually
9468 'configure' can determine that directory automatically.
9469
9470 '--version'
9471 Print the version of Autoconf used to generate the 'configure'
9472 script, and exit.
9473
9474 'configure' also accepts some other, not widely used, boilerplate
9475 options. 'configure --help' prints the complete list.
9476
9477 \1f
9478 File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
9479
9480 10.8 Optional Features
9481 ======================
9482
9483 The Bash 'configure' has a number of '--enable-FEATURE' options, where
9484 FEATURE indicates an optional part of Bash. There are also several
9485 '--with-PACKAGE' options, where PACKAGE is something like 'bash-malloc'
9486 or 'purify'. To turn off the default use of a package, use
9487 '--without-PACKAGE'. To configure Bash without a feature that is
9488 enabled by default, use '--disable-FEATURE'.
9489
9490 Here is a complete list of the '--enable-' and '--with-' options that
9491 the Bash 'configure' recognizes.
9492
9493 '--with-afs'
9494 Define if you are using the Andrew File System from Transarc.
9495
9496 '--with-bash-malloc'
9497 Use the Bash version of 'malloc' in the directory 'lib/malloc'.
9498 This is not the same 'malloc' that appears in GNU libc, but an
9499 older version originally derived from the 4.2 BSD 'malloc'. This
9500 'malloc' is very fast, but wastes some space on each allocation.
9501 This option is enabled by default. The 'NOTES' file contains a
9502 list of systems for which this should be turned off, and
9503 'configure' disables this option automatically for a number of
9504 systems.
9505
9506 '--with-curses'
9507 Use the curses library instead of the termcap library. This should
9508 be supplied if your system has an inadequate or incomplete termcap
9509 database.
9510
9511 '--with-gnu-malloc'
9512 A synonym for '--with-bash-malloc'.
9513
9514 '--with-installed-readline[=PREFIX]'
9515 Define this to make Bash link with a locally-installed version of
9516 Readline rather than the version in 'lib/readline'. This works
9517 only with Readline 5.0 and later versions. If PREFIX is 'yes' or
9518 not supplied, 'configure' uses the values of the make variables
9519 'includedir' and 'libdir', which are subdirectories of 'prefix' by
9520 default, to find the installed version of Readline if it is not in
9521 the standard system include and library directories. If PREFIX is
9522 'no', Bash links with the version in 'lib/readline'. If PREFIX is
9523 set to any other value, 'configure' treats it as a directory
9524 pathname and looks for the installed version of Readline in
9525 subdirectories of that directory (include files in PREFIX/'include'
9526 and the library in PREFIX/'lib').
9527
9528 '--with-purify'
9529 Define this to use the Purify memory allocation checker from
9530 Rational Software.
9531
9532 '--enable-minimal-config'
9533 This produces a shell with minimal features, close to the
9534 historical Bourne shell.
9535
9536 There are several '--enable-' options that alter how Bash is compiled
9537 and linked, rather than changing run-time features.
9538
9539 '--enable-largefile'
9540 Enable support for large files
9541 (http://www.sas.com/standards/large_file/x_open.20Mar96.html) if
9542 the operating system requires special compiler options to build
9543 programs which can access large files. This is enabled by default,
9544 if the operating system provides large file support.
9545
9546 '--enable-profiling'
9547 This builds a Bash binary that produces profiling information to be
9548 processed by 'gprof' each time it is executed.
9549
9550 '--enable-static-link'
9551 This causes Bash to be linked statically, if 'gcc' is being used.
9552 This could be used to build a version to use as root's shell.
9553
9554 The 'minimal-config' option can be used to disable all of the
9555 following options, but it is processed first, so individual options may
9556 be enabled using 'enable-FEATURE'.
9557
9558 All of the following options except for 'disabled-builtins',
9559 'direxpand-default', and 'xpg-echo-default' are enabled by default,
9560 unless the operating system does not provide the necessary support.
9561
9562 '--enable-alias'
9563 Allow alias expansion and include the 'alias' and 'unalias'
9564 builtins (*note Aliases::).
9565
9566 '--enable-arith-for-command'
9567 Include support for the alternate form of the 'for' command that
9568 behaves like the C language 'for' statement (*note Looping
9569 Constructs::).
9570
9571 '--enable-array-variables'
9572 Include support for one-dimensional array shell variables (*note
9573 Arrays::).
9574
9575 '--enable-bang-history'
9576 Include support for 'csh'-like history substitution (*note History
9577 Interaction::).
9578
9579 '--enable-brace-expansion'
9580 Include 'csh'-like brace expansion ( 'b{a,b}c' ==> 'bac bbc' ).
9581 See *note Brace Expansion::, for a complete description.
9582
9583 '--enable-casemod-attributes'
9584 Include support for case-modifying attributes in the 'declare'
9585 builtin and assignment statements. Variables with the UPPERCASE
9586 attribute, for example, will have their values converted to
9587 uppercase upon assignment.
9588
9589 '--enable-casemod-expansion'
9590 Include support for case-modifying word expansions.
9591
9592 '--enable-command-timing'
9593 Include support for recognizing 'time' as a reserved word and for
9594 displaying timing statistics for the pipeline following 'time'
9595 (*note Pipelines::). This allows pipelines as well as shell
9596 builtins and functions to be timed.
9597
9598 '--enable-cond-command'
9599 Include support for the '[[' conditional command. (*note
9600 Conditional Constructs::).
9601
9602 '--enable-cond-regexp'
9603 Include support for matching POSIX regular expressions using the
9604 '=~' binary operator in the '[[' conditional command. (*note
9605 Conditional Constructs::).
9606
9607 '--enable-coprocesses'
9608 Include support for coprocesses and the 'coproc' reserved word
9609 (*note Pipelines::).
9610
9611 '--enable-debugger'
9612 Include support for the bash debugger (distributed separately).
9613
9614 '--enable-direxpand-default'
9615 Cause the 'direxpand' shell option (*note The Shopt Builtin::) to
9616 be enabled by default when the shell starts. It is normally
9617 disabled by default.
9618
9619 '--enable-directory-stack'
9620 Include support for a 'csh'-like directory stack and the 'pushd',
9621 'popd', and 'dirs' builtins (*note The Directory Stack::).
9622
9623 '--enable-disabled-builtins'
9624 Allow builtin commands to be invoked via 'builtin xxx' even after
9625 'xxx' has been disabled using 'enable -n xxx'. See *note Bash
9626 Builtins::, for details of the 'builtin' and 'enable' builtin
9627 commands.
9628
9629 '--enable-dparen-arithmetic'
9630 Include support for the '((...))' command (*note Conditional
9631 Constructs::).
9632
9633 '--enable-extended-glob'
9634 Include support for the extended pattern matching features
9635 described above under *note Pattern Matching::.
9636
9637 '--enable-extended-glob-default'
9638 Set the default value of the EXTGLOB shell option described above
9639 under *note The Shopt Builtin:: to be enabled.
9640
9641 '--enable-function-import'
9642 Include support for importing function definitions exported by
9643 another instance of the shell from the environment. This option is
9644 enabled by default.
9645
9646 '--enable-glob-asciirange-default'
9647 Set the default value of the GLOBASCIIRANGES shell option described
9648 above under *note The Shopt Builtin:: to be enabled. This controls
9649 the behavior of character ranges when used in pattern matching
9650 bracket expressions.
9651
9652 '--enable-help-builtin'
9653 Include the 'help' builtin, which displays help on shell builtins
9654 and variables (*note Bash Builtins::).
9655
9656 '--enable-history'
9657 Include command history and the 'fc' and 'history' builtin commands
9658 (*note Bash History Facilities::).
9659
9660 '--enable-job-control'
9661 This enables the job control features (*note Job Control::), if the
9662 operating system supports them.
9663
9664 '--enable-multibyte'
9665 This enables support for multibyte characters if the operating
9666 system provides the necessary support.
9667
9668 '--enable-net-redirections'
9669 This enables the special handling of filenames of the form
9670 '/dev/tcp/HOST/PORT' and '/dev/udp/HOST/PORT' when used in
9671 redirections (*note Redirections::).
9672
9673 '--enable-process-substitution'
9674 This enables process substitution (*note Process Substitution::) if
9675 the operating system provides the necessary support.
9676
9677 '--enable-progcomp'
9678 Enable the programmable completion facilities (*note Programmable
9679 Completion::). If Readline is not enabled, this option has no
9680 effect.
9681
9682 '--enable-prompt-string-decoding'
9683 Turn on the interpretation of a number of backslash-escaped
9684 characters in the '$PS1', '$PS2', '$PS3', and '$PS4' prompt
9685 strings. See *note Controlling the Prompt::, for a complete list
9686 of prompt string escape sequences.
9687
9688 '--enable-readline'
9689 Include support for command-line editing and history with the Bash
9690 version of the Readline library (*note Command Line Editing::).
9691
9692 '--enable-restricted'
9693 Include support for a "restricted shell". If this is enabled,
9694 Bash, when called as 'rbash', enters a restricted mode. See *note
9695 The Restricted Shell::, for a description of restricted mode.
9696
9697 '--enable-select'
9698 Include the 'select' compound command, which allows the generation
9699 of simple menus (*note Conditional Constructs::).
9700
9701 '--enable-separate-helpfiles'
9702 Use external files for the documentation displayed by the 'help'
9703 builtin instead of storing the text internally.
9704
9705 '--enable-single-help-strings'
9706 Store the text displayed by the 'help' builtin as a single string
9707 for each help topic. This aids in translating the text to
9708 different languages. You may need to disable this if your compiler
9709 cannot handle very long string literals.
9710
9711 '--enable-strict-posix-default'
9712 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
9713
9714 '--enable-usg-echo-default'
9715 A synonym for '--enable-xpg-echo-default'.
9716
9717 '--enable-xpg-echo-default'
9718 Make the 'echo' builtin expand backslash-escaped characters by
9719 default, without requiring the '-e' option. This sets the default
9720 value of the 'xpg_echo' shell option to 'on', which makes the Bash
9721 'echo' behave more like the version specified in the Single Unix
9722 Specification, version 3. *Note Bash Builtins::, for a description
9723 of the escape sequences that 'echo' recognizes.
9724
9725 The file 'config-top.h' contains C Preprocessor '#define' statements
9726 for options which are not settable from 'configure'. Some of these are
9727 not meant to be changed; beware of the consequences if you do. Read the
9728 comments associated with each definition for more information about its
9729 effect.
9730
9731 \1f
9732 File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
9733
9734 Appendix A Reporting Bugs
9735 *************************
9736
9737 Please report all bugs you find in Bash. But first, you should make
9738 sure that it really is a bug, and that it appears in the latest version
9739 of Bash. The latest version of Bash is always available for FTP from
9740 <ftp://ftp.gnu.org/pub/gnu/bash/>.
9741
9742 Once you have determined that a bug actually exists, use the
9743 'bashbug' command to submit a bug report. If you have a fix, you are
9744 encouraged to mail that as well! Suggestions and 'philosophical' bug
9745 reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
9746 newsgroup 'gnu.bash.bug'.
9747
9748 All bug reports should include:
9749 * The version number of Bash.
9750 * The hardware and operating system.
9751 * The compiler used to compile Bash.
9752 * A description of the bug behaviour.
9753 * A short script or 'recipe' which exercises the bug and may be used
9754 to reproduce it.
9755
9756 'bashbug' inserts the first three items automatically into the template
9757 it provides for filing a bug report.
9758
9759 Please send all reports concerning this manual to <bug-bash@gnu.org>.
9760
9761 \1f
9762 File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
9763
9764 Appendix B Major Differences From The Bourne Shell
9765 **************************************************
9766
9767 Bash implements essentially the same grammar, parameter and variable
9768 expansion, redirection, and quoting as the Bourne Shell. Bash uses the
9769 POSIX standard as the specification of how these features are to be
9770 implemented. There are some differences between the traditional Bourne
9771 shell and Bash; this section quickly details the differences of
9772 significance. A number of these differences are explained in greater
9773 depth in previous sections. This section uses the version of 'sh'
9774 included in SVR4.2 (the last version of the historical Bourne shell) as
9775 the baseline reference.
9776
9777 * Bash is POSIX-conformant, even where the POSIX specification
9778 differs from traditional 'sh' behavior (*note Bash POSIX Mode::).
9779
9780 * Bash has multi-character invocation options (*note Invoking
9781 Bash::).
9782
9783 * Bash has command-line editing (*note Command Line Editing::) and
9784 the 'bind' builtin.
9785
9786 * Bash provides a programmable word completion mechanism (*note
9787 Programmable Completion::), and builtin commands 'complete',
9788 'compgen', and 'compopt', to manipulate it.
9789
9790 * Bash has command history (*note Bash History Facilities::) and the
9791 'history' and 'fc' builtins to manipulate it. The Bash history
9792 list maintains timestamp information and uses the value of the
9793 'HISTTIMEFORMAT' variable to display it.
9794
9795 * Bash implements 'csh'-like history expansion (*note History
9796 Interaction::).
9797
9798 * Bash has one-dimensional array variables (*note Arrays::), and the
9799 appropriate variable expansions and assignment syntax to use them.
9800 Several of the Bash builtins take options to act on arrays. Bash
9801 provides a number of built-in array variables.
9802
9803 * The '$'...'' quoting syntax, which expands ANSI-C backslash-escaped
9804 characters in the text between the single quotes, is supported
9805 (*note ANSI-C Quoting::).
9806
9807 * Bash supports the '$"..."' quoting syntax to do locale-specific
9808 translation of the characters between the double quotes. The '-D',
9809 '--dump-strings', and '--dump-po-strings' invocation options list
9810 the translatable strings found in a script (*note Locale
9811 Translation::).
9812
9813 * Bash implements the '!' keyword to negate the return value of a
9814 pipeline (*note Pipelines::). Very useful when an 'if' statement
9815 needs to act only if a test fails. The Bash '-o pipefail' option
9816 to 'set' will cause a pipeline to return a failure status if any
9817 command fails.
9818
9819 * Bash has the 'time' reserved word and command timing (*note
9820 Pipelines::). The display of the timing statistics may be
9821 controlled with the 'TIMEFORMAT' variable.
9822
9823 * Bash implements the 'for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
9824 for command, similar to the C language (*note Looping
9825 Constructs::).
9826
9827 * Bash includes the 'select' compound command, which allows the
9828 generation of simple menus (*note Conditional Constructs::).
9829
9830 * Bash includes the '[[' compound command, which makes conditional
9831 testing part of the shell grammar (*note Conditional Constructs::),
9832 including optional regular expression matching.
9833
9834 * Bash provides optional case-insensitive matching for the 'case' and
9835 '[[' constructs.
9836
9837 * Bash includes brace expansion (*note Brace Expansion::) and tilde
9838 expansion (*note Tilde Expansion::).
9839
9840 * Bash implements command aliases and the 'alias' and 'unalias'
9841 builtins (*note Aliases::).
9842
9843 * Bash provides shell arithmetic, the '((' compound command (*note
9844 Conditional Constructs::), and arithmetic expansion (*note Shell
9845 Arithmetic::).
9846
9847 * Variables present in the shell's initial environment are
9848 automatically exported to child processes. The Bourne shell does
9849 not normally do this unless the variables are explicitly marked
9850 using the 'export' command.
9851
9852 * Bash supports the '+=' assignment operator, which appends to the
9853 value of the variable named on the left hand side.
9854
9855 * Bash includes the POSIX pattern removal '%', '#', '%%' and '##'
9856 expansions to remove leading or trailing substrings from variable
9857 values (*note Shell Parameter Expansion::).
9858
9859 * The expansion '${#xx}', which returns the length of '${xx}', is
9860 supported (*note Shell Parameter Expansion::).
9861
9862 * The expansion '${var:'OFFSET'[:'LENGTH']}', which expands to the
9863 substring of 'var''s value of length LENGTH, beginning at OFFSET,
9864 is present (*note Shell Parameter Expansion::).
9865
9866 * The expansion '${var/[/]'PATTERN'[/'REPLACEMENT']}', which matches
9867 PATTERN and replaces it with REPLACEMENT in the value of 'var', is
9868 available (*note Shell Parameter Expansion::).
9869
9870 * The expansion '${!PREFIX*}' expansion, which expands to the names
9871 of all shell variables whose names begin with PREFIX, is available
9872 (*note Shell Parameter Expansion::).
9873
9874 * Bash has INDIRECT variable expansion using '${!word}' (*note Shell
9875 Parameter Expansion::).
9876
9877 * Bash can expand positional parameters beyond '$9' using '${NUM}'.
9878
9879 * The POSIX '$()' form of command substitution is implemented (*note
9880 Command Substitution::), and preferred to the Bourne shell's '``'
9881 (which is also implemented for backwards compatibility).
9882
9883 * Bash has process substitution (*note Process Substitution::).
9884
9885 * Bash automatically assigns variables that provide information about
9886 the current user ('UID', 'EUID', and 'GROUPS'), the current host
9887 ('HOSTTYPE', 'OSTYPE', 'MACHTYPE', and 'HOSTNAME'), and the
9888 instance of Bash that is running ('BASH', 'BASH_VERSION', and
9889 'BASH_VERSINFO'). *Note Bash Variables::, for details.
9890
9891 * The 'IFS' variable is used to split only the results of expansion,
9892 not all words (*note Word Splitting::). This closes a longstanding
9893 shell security hole.
9894
9895 * The filename expansion bracket expression code uses '!' and '^' to
9896 negate the set of characters between the brackets. The Bourne
9897 shell uses only '!'.
9898
9899 * Bash implements the full set of POSIX filename expansion operators,
9900 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
9901 SYMBOLS (*note Filename Expansion::).
9902
9903 * Bash implements extended pattern matching features when the
9904 'extglob' shell option is enabled (*note Pattern Matching::).
9905
9906 * It is possible to have a variable and a function with the same
9907 name; 'sh' does not separate the two name spaces.
9908
9909 * Bash functions are permitted to have local variables using the
9910 'local' builtin, and thus useful recursive functions may be written
9911 (*note Bash Builtins::).
9912
9913 * Variable assignments preceding commands affect only that command,
9914 even builtins and functions (*note Environment::). In 'sh', all
9915 variable assignments preceding commands are global unless the
9916 command is executed from the file system.
9917
9918 * Bash performs filename expansion on filenames specified as operands
9919 to input and output redirection operators (*note Redirections::).
9920
9921 * Bash contains the '<>' redirection operator, allowing a file to be
9922 opened for both reading and writing, and the '&>' redirection
9923 operator, for directing standard output and standard error to the
9924 same file (*note Redirections::).
9925
9926 * Bash includes the '<<<' redirection operator, allowing a string to
9927 be used as the standard input to a command.
9928
9929 * Bash implements the '[n]<&WORD' and '[n]>&WORD' redirection
9930 operators, which move one file descriptor to another.
9931
9932 * Bash treats a number of filenames specially when they are used in
9933 redirection operators (*note Redirections::).
9934
9935 * Bash can open network connections to arbitrary machines and
9936 services with the redirection operators (*note Redirections::).
9937
9938 * The 'noclobber' option is available to avoid overwriting existing
9939 files with output redirection (*note The Set Builtin::). The '>|'
9940 redirection operator may be used to override 'noclobber'.
9941
9942 * The Bash 'cd' and 'pwd' builtins (*note Bourne Shell Builtins::)
9943 each take '-L' and '-P' options to switch between logical and
9944 physical modes.
9945
9946 * Bash allows a function to override a builtin with the same name,
9947 and provides access to that builtin's functionality within the
9948 function via the 'builtin' and 'command' builtins (*note Bash
9949 Builtins::).
9950
9951 * The 'command' builtin allows selective disabling of functions when
9952 command lookup is performed (*note Bash Builtins::).
9953
9954 * Individual builtins may be enabled or disabled using the 'enable'
9955 builtin (*note Bash Builtins::).
9956
9957 * The Bash 'exec' builtin takes additional options that allow users
9958 to control the contents of the environment passed to the executed
9959 command, and what the zeroth argument to the command is to be
9960 (*note Bourne Shell Builtins::).
9961
9962 * Shell functions may be exported to children via the environment
9963 using 'export -f' (*note Shell Functions::).
9964
9965 * The Bash 'export', 'readonly', and 'declare' builtins can take a
9966 '-f' option to act on shell functions, a '-p' option to display
9967 variables with various attributes set in a format that can be used
9968 as shell input, a '-n' option to remove various variable
9969 attributes, and 'name=value' arguments to set variable attributes
9970 and values simultaneously.
9971
9972 * The Bash 'hash' builtin allows a name to be associated with an
9973 arbitrary filename, even when that filename cannot be found by
9974 searching the '$PATH', using 'hash -p' (*note Bourne Shell
9975 Builtins::).
9976
9977 * Bash includes a 'help' builtin for quick reference to shell
9978 facilities (*note Bash Builtins::).
9979
9980 * The 'printf' builtin is available to display formatted output
9981 (*note Bash Builtins::).
9982
9983 * The Bash 'read' builtin (*note Bash Builtins::) will read a line
9984 ending in '\' with the '-r' option, and will use the 'REPLY'
9985 variable as a default if no non-option arguments are supplied. The
9986 Bash 'read' builtin also accepts a prompt string with the '-p'
9987 option and will use Readline to obtain the line when given the '-e'
9988 option. The 'read' builtin also has additional options to control
9989 input: the '-s' option will turn off echoing of input characters as
9990 they are read, the '-t' option will allow 'read' to time out if
9991 input does not arrive within a specified number of seconds, the
9992 '-n' option will allow reading only a specified number of
9993 characters rather than a full line, and the '-d' option will read
9994 until a particular character rather than newline.
9995
9996 * The 'return' builtin may be used to abort execution of scripts
9997 executed with the '.' or 'source' builtins (*note Bourne Shell
9998 Builtins::).
9999
10000 * Bash includes the 'shopt' builtin, for finer control of shell
10001 optional capabilities (*note The Shopt Builtin::), and allows these
10002 options to be set and unset at shell invocation (*note Invoking
10003 Bash::).
10004
10005 * Bash has much more optional behavior controllable with the 'set'
10006 builtin (*note The Set Builtin::).
10007
10008 * The '-x' ('xtrace') option displays commands other than simple
10009 commands when performing an execution trace (*note The Set
10010 Builtin::).
10011
10012 * The 'test' builtin (*note Bourne Shell Builtins::) is slightly
10013 different, as it implements the POSIX algorithm, which specifies
10014 the behavior based on the number of arguments.
10015
10016 * Bash includes the 'caller' builtin, which displays the context of
10017 any active subroutine call (a shell function or a script executed
10018 with the '.' or 'source' builtins). This supports the bash
10019 debugger.
10020
10021 * The 'trap' builtin (*note Bourne Shell Builtins::) allows a 'DEBUG'
10022 pseudo-signal specification, similar to 'EXIT'. Commands specified
10023 with a 'DEBUG' trap are executed before every simple command, 'for'
10024 command, 'case' command, 'select' command, every arithmetic 'for'
10025 command, and before the first command executes in a shell function.
10026 The 'DEBUG' trap is not inherited by shell functions unless the
10027 function has been given the 'trace' attribute or the 'functrace'
10028 option has been enabled using the 'shopt' builtin. The 'extdebug'
10029 shell option has additional effects on the 'DEBUG' trap.
10030
10031 The 'trap' builtin (*note Bourne Shell Builtins::) allows an 'ERR'
10032 pseudo-signal specification, similar to 'EXIT' and 'DEBUG'.
10033 Commands specified with an 'ERR' trap are executed after a simple
10034 command fails, with a few exceptions. The 'ERR' trap is not
10035 inherited by shell functions unless the '-o errtrace' option to the
10036 'set' builtin is enabled.
10037
10038 The 'trap' builtin (*note Bourne Shell Builtins::) allows a
10039 'RETURN' pseudo-signal specification, similar to 'EXIT' and
10040 'DEBUG'. Commands specified with an 'RETURN' trap are executed
10041 before execution resumes after a shell function or a shell script
10042 executed with '.' or 'source' returns. The 'RETURN' trap is not
10043 inherited by shell functions unless the function has been given the
10044 'trace' attribute or the 'functrace' option has been enabled using
10045 the 'shopt' builtin.
10046
10047 * The Bash 'type' builtin is more extensive and gives more
10048 information about the names it finds (*note Bash Builtins::).
10049
10050 * The Bash 'umask' builtin permits a '-p' option to cause the output
10051 to be displayed in the form of a 'umask' command that may be reused
10052 as input (*note Bourne Shell Builtins::).
10053
10054 * Bash implements a 'csh'-like directory stack, and provides the
10055 'pushd', 'popd', and 'dirs' builtins to manipulate it (*note The
10056 Directory Stack::). Bash also makes the directory stack visible as
10057 the value of the 'DIRSTACK' shell variable.
10058
10059 * Bash interprets special backslash-escaped characters in the prompt
10060 strings when interactive (*note Controlling the Prompt::).
10061
10062 * The Bash restricted mode is more useful (*note The Restricted
10063 Shell::); the SVR4.2 shell restricted mode is too limited.
10064
10065 * The 'disown' builtin can remove a job from the internal shell job
10066 table (*note Job Control Builtins::) or suppress the sending of
10067 'SIGHUP' to a job when the shell exits as the result of a 'SIGHUP'.
10068
10069 * Bash includes a number of features to support a separate debugger
10070 for shell scripts.
10071
10072 * The SVR4.2 shell has two privilege-related builtins ('mldmode' and
10073 'priv') not present in Bash.
10074
10075 * Bash does not have the 'stop' or 'newgrp' builtins.
10076
10077 * Bash does not use the 'SHACCT' variable or perform shell
10078 accounting.
10079
10080 * The SVR4.2 'sh' uses a 'TIMEOUT' variable like Bash uses 'TMOUT'.
10081
10082 More features unique to Bash may be found in *note Bash Features::.
10083
10084 B.1 Implementation Differences From The SVR4.2 Shell
10085 ====================================================
10086
10087 Since Bash is a completely new implementation, it does not suffer from
10088 many of the limitations of the SVR4.2 shell. For instance:
10089
10090 * Bash does not fork a subshell when redirecting into or out of a
10091 shell control structure such as an 'if' or 'while' statement.
10092
10093 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
10094 silently insert a needed closing quote at 'EOF' under certain
10095 circumstances. This can be the cause of some hard-to-find errors.
10096
10097 * The SVR4.2 shell uses a baroque memory management scheme based on
10098 trapping 'SIGSEGV'. If the shell is started from a process with
10099 'SIGSEGV' blocked (e.g., by using the 'system()' C library function
10100 call), it misbehaves badly.
10101
10102 * In a questionable attempt at security, the SVR4.2 shell, when
10103 invoked without the '-p' option, will alter its real and effective
10104 UID and GID if they are less than some magic threshold value,
10105 commonly 100. This can lead to unexpected results.
10106
10107 * The SVR4.2 shell does not allow users to trap 'SIGSEGV', 'SIGALRM',
10108 or 'SIGCHLD'.
10109
10110 * The SVR4.2 shell does not allow the 'IFS', 'MAILCHECK', 'PATH',
10111 'PS1', or 'PS2' variables to be unset.
10112
10113 * The SVR4.2 shell treats '^' as the undocumented equivalent of '|'.
10114
10115 * Bash allows multiple option arguments when it is invoked ('-x -v');
10116 the SVR4.2 shell allows only one option argument ('-xv'). In fact,
10117 some versions of the shell dump core if the second argument begins
10118 with a '-'.
10119
10120 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
10121 script only if one of the POSIX special builtins fails, and only
10122 for certain failures, as enumerated in the POSIX standard.
10123
10124 * The SVR4.2 shell behaves differently when invoked as 'jsh' (it
10125 turns on job control).
10126
10127 \1f
10128 File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
10129
10130 Appendix C GNU Free Documentation License
10131 *****************************************
10132
10133 Version 1.3, 3 November 2008
10134
10135 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
10136 <http://fsf.org/>
10137
10138 Everyone is permitted to copy and distribute verbatim copies
10139 of this license document, but changing it is not allowed.
10140
10141 0. PREAMBLE
10142
10143 The purpose of this License is to make a manual, textbook, or other
10144 functional and useful document "free" in the sense of freedom: to
10145 assure everyone the effective freedom to copy and redistribute it,
10146 with or without modifying it, either commercially or
10147 noncommercially. Secondarily, this License preserves for the
10148 author and publisher a way to get credit for their work, while not
10149 being considered responsible for modifications made by others.
10150
10151 This License is a kind of "copyleft", which means that derivative
10152 works of the document must themselves be free in the same sense.
10153 It complements the GNU General Public License, which is a copyleft
10154 license designed for free software.
10155
10156 We have designed this License in order to use it for manuals for
10157 free software, because free software needs free documentation: a
10158 free program should come with manuals providing the same freedoms
10159 that the software does. But this License is not limited to
10160 software manuals; it can be used for any textual work, regardless
10161 of subject matter or whether it is published as a printed book. We
10162 recommend this License principally for works whose purpose is
10163 instruction or reference.
10164
10165 1. APPLICABILITY AND DEFINITIONS
10166
10167 This License applies to any manual or other work, in any medium,
10168 that contains a notice placed by the copyright holder saying it can
10169 be distributed under the terms of this License. Such a notice
10170 grants a world-wide, royalty-free license, unlimited in duration,
10171 to use that work under the conditions stated herein. The
10172 "Document", below, refers to any such manual or work. Any member
10173 of the public is a licensee, and is addressed as "you". You accept
10174 the license if you copy, modify or distribute the work in a way
10175 requiring permission under copyright law.
10176
10177 A "Modified Version" of the Document means any work containing the
10178 Document or a portion of it, either copied verbatim, or with
10179 modifications and/or translated into another language.
10180
10181 A "Secondary Section" is a named appendix or a front-matter section
10182 of the Document that deals exclusively with the relationship of the
10183 publishers or authors of the Document to the Document's overall
10184 subject (or to related matters) and contains nothing that could
10185 fall directly within that overall subject. (Thus, if the Document
10186 is in part a textbook of mathematics, a Secondary Section may not
10187 explain any mathematics.) The relationship could be a matter of
10188 historical connection with the subject or with related matters, or
10189 of legal, commercial, philosophical, ethical or political position
10190 regarding them.
10191
10192 The "Invariant Sections" are certain Secondary Sections whose
10193 titles are designated, as being those of Invariant Sections, in the
10194 notice that says that the Document is released under this License.
10195 If a section does not fit the above definition of Secondary then it
10196 is not allowed to be designated as Invariant. The Document may
10197 contain zero Invariant Sections. If the Document does not identify
10198 any Invariant Sections then there are none.
10199
10200 The "Cover Texts" are certain short passages of text that are
10201 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
10202 that says that the Document is released under this License. A
10203 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
10204 be at most 25 words.
10205
10206 A "Transparent" copy of the Document means a machine-readable copy,
10207 represented in a format whose specification is available to the
10208 general public, that is suitable for revising the document
10209 straightforwardly with generic text editors or (for images composed
10210 of pixels) generic paint programs or (for drawings) some widely
10211 available drawing editor, and that is suitable for input to text
10212 formatters or for automatic translation to a variety of formats
10213 suitable for input to text formatters. A copy made in an otherwise
10214 Transparent file format whose markup, or absence of markup, has
10215 been arranged to thwart or discourage subsequent modification by
10216 readers is not Transparent. An image format is not Transparent if
10217 used for any substantial amount of text. A copy that is not
10218 "Transparent" is called "Opaque".
10219
10220 Examples of suitable formats for Transparent copies include plain
10221 ASCII without markup, Texinfo input format, LaTeX input format,
10222 SGML or XML using a publicly available DTD, and standard-conforming
10223 simple HTML, PostScript or PDF designed for human modification.
10224 Examples of transparent image formats include PNG, XCF and JPG.
10225 Opaque formats include proprietary formats that can be read and
10226 edited only by proprietary word processors, SGML or XML for which
10227 the DTD and/or processing tools are not generally available, and
10228 the machine-generated HTML, PostScript or PDF produced by some word
10229 processors for output purposes only.
10230
10231 The "Title Page" means, for a printed book, the title page itself,
10232 plus such following pages as are needed to hold, legibly, the
10233 material this License requires to appear in the title page. For
10234 works in formats which do not have any title page as such, "Title
10235 Page" means the text near the most prominent appearance of the
10236 work's title, preceding the beginning of the body of the text.
10237
10238 The "publisher" means any person or entity that distributes copies
10239 of the Document to the public.
10240
10241 A section "Entitled XYZ" means a named subunit of the Document
10242 whose title either is precisely XYZ or contains XYZ in parentheses
10243 following text that translates XYZ in another language. (Here XYZ
10244 stands for a specific section name mentioned below, such as
10245 "Acknowledgements", "Dedications", "Endorsements", or "History".)
10246 To "Preserve the Title" of such a section when you modify the
10247 Document means that it remains a section "Entitled XYZ" according
10248 to this definition.
10249
10250 The Document may include Warranty Disclaimers next to the notice
10251 which states that this License applies to the Document. These
10252 Warranty Disclaimers are considered to be included by reference in
10253 this License, but only as regards disclaiming warranties: any other
10254 implication that these Warranty Disclaimers may have is void and
10255 has no effect on the meaning of this License.
10256
10257 2. VERBATIM COPYING
10258
10259 You may copy and distribute the Document in any medium, either
10260 commercially or noncommercially, provided that this License, the
10261 copyright notices, and the license notice saying this License
10262 applies to the Document are reproduced in all copies, and that you
10263 add no other conditions whatsoever to those of this License. You
10264 may not use technical measures to obstruct or control the reading
10265 or further copying of the copies you make or distribute. However,
10266 you may accept compensation in exchange for copies. If you
10267 distribute a large enough number of copies you must also follow the
10268 conditions in section 3.
10269
10270 You may also lend copies, under the same conditions stated above,
10271 and you may publicly display copies.
10272
10273 3. COPYING IN QUANTITY
10274
10275 If you publish printed copies (or copies in media that commonly
10276 have printed covers) of the Document, numbering more than 100, and
10277 the Document's license notice requires Cover Texts, you must
10278 enclose the copies in covers that carry, clearly and legibly, all
10279 these Cover Texts: Front-Cover Texts on the front cover, and
10280 Back-Cover Texts on the back cover. Both covers must also clearly
10281 and legibly identify you as the publisher of these copies. The
10282 front cover must present the full title with all words of the title
10283 equally prominent and visible. You may add other material on the
10284 covers in addition. Copying with changes limited to the covers, as
10285 long as they preserve the title of the Document and satisfy these
10286 conditions, can be treated as verbatim copying in other respects.
10287
10288 If the required texts for either cover are too voluminous to fit
10289 legibly, you should put the first ones listed (as many as fit
10290 reasonably) on the actual cover, and continue the rest onto
10291 adjacent pages.
10292
10293 If you publish or distribute Opaque copies of the Document
10294 numbering more than 100, you must either include a machine-readable
10295 Transparent copy along with each Opaque copy, or state in or with
10296 each Opaque copy a computer-network location from which the general
10297 network-using public has access to download using public-standard
10298 network protocols a complete Transparent copy of the Document, free
10299 of added material. If you use the latter option, you must take
10300 reasonably prudent steps, when you begin distribution of Opaque
10301 copies in quantity, to ensure that this Transparent copy will
10302 remain thus accessible at the stated location until at least one
10303 year after the last time you distribute an Opaque copy (directly or
10304 through your agents or retailers) of that edition to the public.
10305
10306 It is requested, but not required, that you contact the authors of
10307 the Document well before redistributing any large number of copies,
10308 to give them a chance to provide you with an updated version of the
10309 Document.
10310
10311 4. MODIFICATIONS
10312
10313 You may copy and distribute a Modified Version of the Document
10314 under the conditions of sections 2 and 3 above, provided that you
10315 release the Modified Version under precisely this License, with the
10316 Modified Version filling the role of the Document, thus licensing
10317 distribution and modification of the Modified Version to whoever
10318 possesses a copy of it. In addition, you must do these things in
10319 the Modified Version:
10320
10321 A. Use in the Title Page (and on the covers, if any) a title
10322 distinct from that of the Document, and from those of previous
10323 versions (which should, if there were any, be listed in the
10324 History section of the Document). You may use the same title
10325 as a previous version if the original publisher of that
10326 version gives permission.
10327
10328 B. List on the Title Page, as authors, one or more persons or
10329 entities responsible for authorship of the modifications in
10330 the Modified Version, together with at least five of the
10331 principal authors of the Document (all of its principal
10332 authors, if it has fewer than five), unless they release you
10333 from this requirement.
10334
10335 C. State on the Title page the name of the publisher of the
10336 Modified Version, as the publisher.
10337
10338 D. Preserve all the copyright notices of the Document.
10339
10340 E. Add an appropriate copyright notice for your modifications
10341 adjacent to the other copyright notices.
10342
10343 F. Include, immediately after the copyright notices, a license
10344 notice giving the public permission to use the Modified
10345 Version under the terms of this License, in the form shown in
10346 the Addendum below.
10347
10348 G. Preserve in that license notice the full lists of Invariant
10349 Sections and required Cover Texts given in the Document's
10350 license notice.
10351
10352 H. Include an unaltered copy of this License.
10353
10354 I. Preserve the section Entitled "History", Preserve its Title,
10355 and add to it an item stating at least the title, year, new
10356 authors, and publisher of the Modified Version as given on the
10357 Title Page. If there is no section Entitled "History" in the
10358 Document, create one stating the title, year, authors, and
10359 publisher of the Document as given on its Title Page, then add
10360 an item describing the Modified Version as stated in the
10361 previous sentence.
10362
10363 J. Preserve the network location, if any, given in the Document
10364 for public access to a Transparent copy of the Document, and
10365 likewise the network locations given in the Document for
10366 previous versions it was based on. These may be placed in the
10367 "History" section. You may omit a network location for a work
10368 that was published at least four years before the Document
10369 itself, or if the original publisher of the version it refers
10370 to gives permission.
10371
10372 K. For any section Entitled "Acknowledgements" or "Dedications",
10373 Preserve the Title of the section, and preserve in the section
10374 all the substance and tone of each of the contributor
10375 acknowledgements and/or dedications given therein.
10376
10377 L. Preserve all the Invariant Sections of the Document, unaltered
10378 in their text and in their titles. Section numbers or the
10379 equivalent are not considered part of the section titles.
10380
10381 M. Delete any section Entitled "Endorsements". Such a section
10382 may not be included in the Modified Version.
10383
10384 N. Do not retitle any existing section to be Entitled
10385 "Endorsements" or to conflict in title with any Invariant
10386 Section.
10387
10388 O. Preserve any Warranty Disclaimers.
10389
10390 If the Modified Version includes new front-matter sections or
10391 appendices that qualify as Secondary Sections and contain no
10392 material copied from the Document, you may at your option designate
10393 some or all of these sections as invariant. To do this, add their
10394 titles to the list of Invariant Sections in the Modified Version's
10395 license notice. These titles must be distinct from any other
10396 section titles.
10397
10398 You may add a section Entitled "Endorsements", provided it contains
10399 nothing but endorsements of your Modified Version by various
10400 parties--for example, statements of peer review or that the text
10401 has been approved by an organization as the authoritative
10402 definition of a standard.
10403
10404 You may add a passage of up to five words as a Front-Cover Text,
10405 and a passage of up to 25 words as a Back-Cover Text, to the end of
10406 the list of Cover Texts in the Modified Version. Only one passage
10407 of Front-Cover Text and one of Back-Cover Text may be added by (or
10408 through arrangements made by) any one entity. If the Document
10409 already includes a cover text for the same cover, previously added
10410 by you or by arrangement made by the same entity you are acting on
10411 behalf of, you may not add another; but you may replace the old
10412 one, on explicit permission from the previous publisher that added
10413 the old one.
10414
10415 The author(s) and publisher(s) of the Document do not by this
10416 License give permission to use their names for publicity for or to
10417 assert or imply endorsement of any Modified Version.
10418
10419 5. COMBINING DOCUMENTS
10420
10421 You may combine the Document with other documents released under
10422 this License, under the terms defined in section 4 above for
10423 modified versions, provided that you include in the combination all
10424 of the Invariant Sections of all of the original documents,
10425 unmodified, and list them all as Invariant Sections of your
10426 combined work in its license notice, and that you preserve all
10427 their Warranty Disclaimers.
10428
10429 The combined work need only contain one copy of this License, and
10430 multiple identical Invariant Sections may be replaced with a single
10431 copy. If there are multiple Invariant Sections with the same name
10432 but different contents, make the title of each such section unique
10433 by adding at the end of it, in parentheses, the name of the
10434 original author or publisher of that section if known, or else a
10435 unique number. Make the same adjustment to the section titles in
10436 the list of Invariant Sections in the license notice of the
10437 combined work.
10438
10439 In the combination, you must combine any sections Entitled
10440 "History" in the various original documents, forming one section
10441 Entitled "History"; likewise combine any sections Entitled
10442 "Acknowledgements", and any sections Entitled "Dedications". You
10443 must delete all sections Entitled "Endorsements."
10444
10445 6. COLLECTIONS OF DOCUMENTS
10446
10447 You may make a collection consisting of the Document and other
10448 documents released under this License, and replace the individual
10449 copies of this License in the various documents with a single copy
10450 that is included in the collection, provided that you follow the
10451 rules of this License for verbatim copying of each of the documents
10452 in all other respects.
10453
10454 You may extract a single document from such a collection, and
10455 distribute it individually under this License, provided you insert
10456 a copy of this License into the extracted document, and follow this
10457 License in all other respects regarding verbatim copying of that
10458 document.
10459
10460 7. AGGREGATION WITH INDEPENDENT WORKS
10461
10462 A compilation of the Document or its derivatives with other
10463 separate and independent documents or works, in or on a volume of a
10464 storage or distribution medium, is called an "aggregate" if the
10465 copyright resulting from the compilation is not used to limit the
10466 legal rights of the compilation's users beyond what the individual
10467 works permit. When the Document is included in an aggregate, this
10468 License does not apply to the other works in the aggregate which
10469 are not themselves derivative works of the Document.
10470
10471 If the Cover Text requirement of section 3 is applicable to these
10472 copies of the Document, then if the Document is less than one half
10473 of the entire aggregate, the Document's Cover Texts may be placed
10474 on covers that bracket the Document within the aggregate, or the
10475 electronic equivalent of covers if the Document is in electronic
10476 form. Otherwise they must appear on printed covers that bracket
10477 the whole aggregate.
10478
10479 8. TRANSLATION
10480
10481 Translation is considered a kind of modification, so you may
10482 distribute translations of the Document under the terms of section
10483 4. Replacing Invariant Sections with translations requires special
10484 permission from their copyright holders, but you may include
10485 translations of some or all Invariant Sections in addition to the
10486 original versions of these Invariant Sections. You may include a
10487 translation of this License, and all the license notices in the
10488 Document, and any Warranty Disclaimers, provided that you also
10489 include the original English version of this License and the
10490 original versions of those notices and disclaimers. In case of a
10491 disagreement between the translation and the original version of
10492 this License or a notice or disclaimer, the original version will
10493 prevail.
10494
10495 If a section in the Document is Entitled "Acknowledgements",
10496 "Dedications", or "History", the requirement (section 4) to
10497 Preserve its Title (section 1) will typically require changing the
10498 actual title.
10499
10500 9. TERMINATION
10501
10502 You may not copy, modify, sublicense, or distribute the Document
10503 except as expressly provided under this License. Any attempt
10504 otherwise to copy, modify, sublicense, or distribute it is void,
10505 and will automatically terminate your rights under this License.
10506
10507 However, if you cease all violation of this License, then your
10508 license from a particular copyright holder is reinstated (a)
10509 provisionally, unless and until the copyright holder explicitly and
10510 finally terminates your license, and (b) permanently, if the
10511 copyright holder fails to notify you of the violation by some
10512 reasonable means prior to 60 days after the cessation.
10513
10514 Moreover, your license from a particular copyright holder is
10515 reinstated permanently if the copyright holder notifies you of the
10516 violation by some reasonable means, this is the first time you have
10517 received notice of violation of this License (for any work) from
10518 that copyright holder, and you cure the violation prior to 30 days
10519 after your receipt of the notice.
10520
10521 Termination of your rights under this section does not terminate
10522 the licenses of parties who have received copies or rights from you
10523 under this License. If your rights have been terminated and not
10524 permanently reinstated, receipt of a copy of some or all of the
10525 same material does not give you any rights to use it.
10526
10527 10. FUTURE REVISIONS OF THIS LICENSE
10528
10529 The Free Software Foundation may publish new, revised versions of
10530 the GNU Free Documentation License from time to time. Such new
10531 versions will be similar in spirit to the present version, but may
10532 differ in detail to address new problems or concerns. See
10533 <http://www.gnu.org/copyleft/>.
10534
10535 Each version of the License is given a distinguishing version
10536 number. If the Document specifies that a particular numbered
10537 version of this License "or any later version" applies to it, you
10538 have the option of following the terms and conditions either of
10539 that specified version or of any later version that has been
10540 published (not as a draft) by the Free Software Foundation. If the
10541 Document does not specify a version number of this License, you may
10542 choose any version ever published (not as a draft) by the Free
10543 Software Foundation. If the Document specifies that a proxy can
10544 decide which future versions of this License can be used, that
10545 proxy's public statement of acceptance of a version permanently
10546 authorizes you to choose that version for the Document.
10547
10548 11. RELICENSING
10549
10550 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
10551 World Wide Web server that publishes copyrightable works and also
10552 provides prominent facilities for anybody to edit those works. A
10553 public wiki that anybody can edit is an example of such a server.
10554 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
10555 site means any set of copyrightable works thus published on the MMC
10556 site.
10557
10558 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
10559 license published by Creative Commons Corporation, a not-for-profit
10560 corporation with a principal place of business in San Francisco,
10561 California, as well as future copyleft versions of that license
10562 published by that same organization.
10563
10564 "Incorporate" means to publish or republish a Document, in whole or
10565 in part, as part of another Document.
10566
10567 An MMC is "eligible for relicensing" if it is licensed under this
10568 License, and if all works that were first published under this
10569 License somewhere other than this MMC, and subsequently
10570 incorporated in whole or in part into the MMC, (1) had no cover
10571 texts or invariant sections, and (2) were thus incorporated prior
10572 to November 1, 2008.
10573
10574 The operator of an MMC Site may republish an MMC contained in the
10575 site under CC-BY-SA on the same site at any time before August 1,
10576 2009, provided the MMC is eligible for relicensing.
10577
10578 ADDENDUM: How to use this License for your documents
10579 ====================================================
10580
10581 To use this License in a document you have written, include a copy of
10582 the License in the document and put the following copyright and license
10583 notices just after the title page:
10584
10585 Copyright (C) YEAR YOUR NAME.
10586 Permission is granted to copy, distribute and/or modify this document
10587 under the terms of the GNU Free Documentation License, Version 1.3
10588 or any later version published by the Free Software Foundation;
10589 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
10590 Texts. A copy of the license is included in the section entitled ``GNU
10591 Free Documentation License''.
10592
10593 If you have Invariant Sections, Front-Cover Texts and Back-Cover
10594 Texts, replace the "with...Texts." line with this:
10595
10596 with the Invariant Sections being LIST THEIR TITLES, with
10597 the Front-Cover Texts being LIST, and with the Back-Cover Texts
10598 being LIST.
10599
10600 If you have Invariant Sections without Cover Texts, or some other
10601 combination of the three, merge those two alternatives to suit the
10602 situation.
10603
10604 If your document contains nontrivial examples of program code, we
10605 recommend releasing these examples in parallel under your choice of free
10606 software license, such as the GNU General Public License, to permit
10607 their use in free software.
10608
10609 \1f
10610 File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
10611
10612 Appendix D Indexes
10613 ******************
10614
10615 * Menu:
10616
10617 * Builtin Index:: Index of Bash builtin commands.
10618 * Reserved Word Index:: Index of Bash reserved words.
10619 * Variable Index:: Quick reference helps you find the
10620 variable you want.
10621 * Function Index:: Index of bindable Readline functions.
10622 * Concept Index:: General index for concepts described in
10623 this manual.
10624
10625 \1f
10626 File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
10627
10628 D.1 Index of Shell Builtin Commands
10629 ===================================
10630
10631